added install batch similar to that provided in /reactos. Removed deprecated Makefile.
[reactos.git] / posix / server / port / session.c
1 /* $Id: session.c,v 1.3 2002/10/29 04:45:58 rex Exp $
2 *
3 * PROJECT : ReactOS / POSIX+ Environment Subsystem Server
4 * FILE : reactos/subsys/psx/server/port/session.c
5 * DESCRIPTION: \POSIX+\SessionPort LPC port logic.
6 * DATE : 2002-04-04
7 * AUTHOR : Emanuele Aliberti <eal@users.sf.net>
8 *
9 * --------------------------------------------------------------------
10 *
11 * This software is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of the
14 * License, or (at your option) any later version.
15 *
16 * This software is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this software; see the file COPYING. If not, write
23 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
24 * MA 02139, USA.
25 *
26 * --------------------------------------------------------------------
27 */
28 #include <psxss.h>
29 #include <psx/lpcproto.h>
30 #include "utils.h"
31
32 /**********************************************************************
33 * ProcessConnectionRequest/ PRIVATE
34 */
35 PRIVATE NTSTATUS STDCALL
36 ProcessConnectionRequest (PLPC_MAX_MESSAGE pRequest)
37 {
38 PPSX_CONNECT_PORT_DATA pConnectData = (PPSX_CONNECT_PORT_DATA) & pRequest->Data;
39 NTSTATUS Status;
40 HANDLE hConnectedPort;
41 ULONG ulPortIdentifier;
42
43 debug_print (L"PSXSS: ->"__FUNCTION__);
44
45 /* Check if the caller is a terminal */
46 Status = PsxCheckConnectionRequest (
47 pConnectData,
48 PSX_CONNECTION_TYPE_TERMINAL
49 );
50 if (!NT_SUCCESS(Status))
51 {
52 Status = NtAcceptConnectPort (
53 & hConnectedPort,
54 NULL,
55 & pRequest->Header,
56 FALSE, /* reject connection request */
57 NULL,
58 NULL
59 );
60 if (!NT_SUCCESS(Status))
61 {
62 debug_print(
63 L"PSXSS: "__FUNCTION__": NtAcceptConnectPort failed with status=%08x",
64 Status
65 );
66 }
67 return STATUS_UNSUCCESSFUL;
68 }
69 /* OK, accept the connection */
70 Status = NtAcceptConnectPort (
71 & hConnectedPort,
72 & ulPortIdentifier,
73 & pRequest->Header,
74 TRUE, /* accept connection request */
75 NULL,
76 NULL
77 );
78 if (!NT_SUCCESS(Status))
79 {
80 debug_print(L"PSXSS: "__FUNCTION__": NtAcceptConnectPort failed with status=%08x", Status);
81 return Status;
82 }
83 /* OK, now create a new PSX_SESSION object */
84 Status = PsxCreateSession (
85 pRequest,
86 hConnectedPort,
87 ulPortIdentifier
88 );
89 if (!NT_SUCCESS(Status))
90 {
91 debug_print(L"PSXSS: "__FUNCTION__": PsxCreateSession failed with status=%08x", Status);
92 return Status;
93 }
94 Status = NtCompleteConnectPort (hConnectedPort);
95 if (!NT_SUCCESS(Status))
96 {
97 debug_print(L"PSXSS: "__FUNCTION__": NtCompleteConnectPort failed with status=%08x", Status);
98 return Status;
99 }
100 debug_print (L"PSXSS: <-"__FUNCTION__);
101 return STATUS_SUCCESS;
102 }
103 /**********************************************************************
104 * ProcessRequest/ PRIVATE
105 */
106 PRIVATE NTSTATUS STDCALL
107 ProcessRequest (PPSX_MAX_MESSAGE pRequest)
108 {
109 debug_print (L"PSXSS: ->"__FUNCTION__);
110 /* TODO: Read data from the section */
111 /* TODO: send data to the process */
112 debug_print (L"PSXSS: <-"__FUNCTION__);
113 return STATUS_NOT_IMPLEMENTED;
114 }
115 /**********************************************************************
116 * SessionPortListener/1
117 *
118 * DESCRIPTION
119 * Listen on port \POSIX+\SessionPort and create new sessions
120 * when a new terminal emulator calls.
121 *
122 * ARGUMENTS
123 * \POSIX+\SessionPort handle.
124 *
125 * RETURN VALUE
126 * None.
127 */
128 VOID STDCALL
129 SessionPortListener (PVOID pArg)
130 {
131 ULONG ulIndex = (ULONG) pArg;
132 NTSTATUS Status;
133 LPC_TYPE RequestType;
134 ULONG PortIdentifier;
135 PSX_MAX_MESSAGE Request;
136 PPSX_MAX_MESSAGE Reply = NULL;
137 BOOL NullReply = FALSE;
138
139 debug_print (L"PSXSS: ->"__FUNCTION__" pArg=%d", ulIndex);
140
141 while (TRUE)
142 {
143 Reply = NULL;
144 NullReply = FALSE;
145 while (!NullReply)
146 {
147 Status = NtReplyWaitReceivePort (
148 Server.Port[ulIndex].hObject,
149 0,
150 (PLPC_MESSAGE) Reply,
151 (PLPC_MESSAGE) & Request
152 );
153 if (!NT_SUCCESS(Status))
154 {
155 break;
156 }
157 RequestType = PORT_MESSAGE_TYPE(Request);
158 switch (RequestType)
159 {
160 case LPC_CONNECTION_REQUEST:
161 ProcessConnectionRequest ((PLPC_MAX_MESSAGE) & Request);
162 NullReply = TRUE;
163 continue;
164 case LPC_CLIENT_DIED:
165 case LPC_PORT_CLOSED:
166 case LPC_DEBUG_EVENT:
167 case LPC_ERROR_EVENT:
168 case LPC_EXCEPTION:
169 NullReply = TRUE;
170 continue;
171 default:
172 if (RequestType != LPC_REQUEST)
173 {
174 NullReply = TRUE;
175 continue;
176 }
177 }
178 Reply = & Request;
179 Reply->PsxHeader.Status = ProcessRequest (& Request);
180 NullReply = FALSE;
181 }
182 if ((STATUS_INVALID_HANDLE == Status) ||
183 (STATUS_OBJECT_TYPE_MISMATCH == Status))
184 {
185 break;
186 }
187 }
188 #ifdef __PSXSS_ON_W32__
189 TerminateThread(GetCurrentThread(),Status);
190 #else
191 NtTerminateThread(NtCurrentThread(),Status);
192 #endif
193 }
194 /* EOF */