1 /* $Id: session.c,v 1.1 2002/04/10 21:30:22 ea Exp $
3 * PROJECT : ReactOS / POSIX+ Environment Subsystem Server
4 * FILE : reactos/subsys/psx/server/port/session.c
5 * DESCRIPTION: \POSIX+\SessionPort LPC port logic.
7 * AUTHOR : Emanuele Aliberti <eal@users.sf.net>
9 * --------------------------------------------------------------------
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.
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.
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,
26 * --------------------------------------------------------------------
29 #include <psx/lpcproto.h>
32 /**********************************************************************
33 * ProcessConnectionRequest/ PRIVATE
35 PRIVATE NTSTATUS STDCALL
36 ProcessConnectionRequest (PLPC_MAX_MESSAGE pRequest
)
38 PPSX_CONNECT_PORT_DATA pConnectData
= (PPSX_CONNECT_PORT_DATA
) & pRequest
->Data
;
40 HANDLE hConnectedPort
;
41 ULONG ulPortIdentifier
;
43 debug_print (L
"PSXSS: ->"__FUNCTION__
);
45 /* Check if the caller is a terminal */
46 Status
= PsxCheckConnectionRequest (
48 PSX_CONNECTION_TYPE_TERMINAL
50 if (!NT_SUCCESS(Status
))
52 Status
= NtAcceptConnectPort (
56 FALSE
, /* reject connection request */
60 if (!NT_SUCCESS(Status
))
63 L
"PSXSS: "__FUNCTION__
": NtAcceptConnectPort failed with status=%08x",
67 return STATUS_UNSUCCESSFUL
;
69 /* OK, accept the connection */
70 Status
= NtAcceptConnectPort (
74 TRUE
, /* accept connection request */
78 if (!NT_SUCCESS(Status
))
80 debug_print(L
"PSXSS: "__FUNCTION__
": NtAcceptConnectPort failed with status=%08x", Status
);
83 /* OK, now create a new PSX_SESSION object */
84 Status
= PsxCreateSession (
89 if (!NT_SUCCESS(Status
))
91 debug_print(L
"PSXSS: "__FUNCTION__
": PsxCreateSession failed with status=%08x", Status
);
94 Status
= NtCompleteConnectPort (hConnectedPort
);
95 if (!NT_SUCCESS(Status
))
97 debug_print(L
"PSXSS: "__FUNCTION__
": NtCompleteConnectPort failed with status=%08x", Status
);
100 debug_print (L
"PSXSS: <-"__FUNCTION__
);
101 return STATUS_SUCCESS
;
103 /**********************************************************************
104 * ProcessRequest/ PRIVATE
106 PRIVATE NTSTATUS STDCALL
107 ProcessRequest (PPSX_MAX_MESSAGE pRequest
)
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
;
115 /**********************************************************************
116 * SessionPortListener/1
119 * Listen on port \POSIX+\SessionPort and create new sessions
120 * when a new terminal emulator calls.
123 * \POSIX+\SessionPort handle.
129 SessionPortListener (PVOID pArg
)
131 ULONG ulIndex
= (ULONG
) pArg
;
133 LPC_TYPE RequestType
;
134 ULONG PortIdentifier
;
135 PSX_MAX_MESSAGE Request
;
136 PPSX_MAX_MESSAGE Reply
= NULL
;
137 BOOL NullReply
= FALSE
;
139 debug_print (L
"PSXSS: ->"__FUNCTION__
" pArg=%d", ulIndex
);
147 Status
= NtReplyWaitReceivePort (
148 Server
.Port
[ulIndex
].hObject
,
150 (PLPC_MESSAGE
) Reply
,
151 (PLPC_MESSAGE
) & Request
153 if (!NT_SUCCESS(Status
))
157 RequestType
= PORT_MESSAGE_TYPE(Request
);
160 case LPC_CONNECTION_REQUEST
:
161 ProcessConnectionRequest ((PLPC_MAX_MESSAGE
) & Request
);
164 case LPC_CLIENT_DIED
:
165 case LPC_PORT_CLOSED
:
166 case LPC_DEBUG_EVENT
:
167 case LPC_ERROR_EVENT
:
172 if (RequestType
!= LPC_REQUEST
)
179 Reply
->PsxHeader
.Status
= ProcessRequest (& Request
);
182 if ((STATUS_INVALID_HANDLE
== Status
) ||
183 (STATUS_OBJECT_TYPE_MISMATCH
== Status
))
188 #ifdef __PSXSS_ON_W32__
189 TerminateThread(GetCurrentThread(),Status
);
191 NtTerminateThread(NtCurrentThread(),Status
);