1 /* $Id: session.c,v 1.4 2003/12/21 20:11:46 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: ->%s", TEXT(__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: %s: NtAcceptConnectPort failed with status=%08x",
68 return STATUS_UNSUCCESSFUL
;
70 /* OK, accept the connection */
71 Status
= NtAcceptConnectPort (
75 TRUE
, /* accept connection request */
79 if (!NT_SUCCESS(Status
))
81 debug_print(L
"PSXSS: %s: NtAcceptConnectPort failed with status=%08x", TEXT(__FUNCTION__
), Status
);
84 /* OK, now create a new PSX_SESSION object */
85 Status
= PsxCreateSession (
90 if (!NT_SUCCESS(Status
))
92 debug_print(L
"PSXSS: %s: PsxCreateSession failed with status=%08x", TEXT(__FUNCTION__
), Status
);
95 Status
= NtCompleteConnectPort (hConnectedPort
);
96 if (!NT_SUCCESS(Status
))
98 debug_print(L
"PSXSS: %s: NtCompleteConnectPort failed with status=%08x", TEXT(__FUNCTION__
), Status
);
101 debug_print (L
"PSXSS: <-%s", TEXT(__FUNCTION__
));
102 return STATUS_SUCCESS
;
104 /**********************************************************************
105 * ProcessRequest/ PRIVATE
107 PRIVATE NTSTATUS STDCALL
108 ProcessRequest (PPSX_MAX_MESSAGE pRequest
)
110 debug_print (L
"PSXSS: ->%s", TEXT(__FUNCTION__
));
111 /* TODO: Read data from the section */
112 /* TODO: send data to the process */
113 debug_print (L
"PSXSS: <-%s", TEXT(__FUNCTION__
));
114 return STATUS_NOT_IMPLEMENTED
;
116 /**********************************************************************
117 * SessionPortListener/1
120 * Listen on port \POSIX+\SessionPort and create new sessions
121 * when a new terminal emulator calls.
124 * \POSIX+\SessionPort handle.
130 SessionPortListener (PVOID pArg
)
132 ULONG ulIndex
= (ULONG
) pArg
;
134 LPC_TYPE RequestType
;
135 ULONG PortIdentifier
;
136 PSX_MAX_MESSAGE Request
;
137 PPSX_MAX_MESSAGE Reply
= NULL
;
138 BOOL NullReply
= FALSE
;
140 debug_print (L
"PSXSS: ->%s pArg=%d", TEXT(__FUNCTION__
), ulIndex
);
148 Status
= NtReplyWaitReceivePort (
149 Server
.Port
[ulIndex
].hObject
,
151 (PLPC_MESSAGE
) Reply
,
152 (PLPC_MESSAGE
) & Request
154 if (!NT_SUCCESS(Status
))
158 RequestType
= PORT_MESSAGE_TYPE(Request
);
161 case LPC_CONNECTION_REQUEST
:
162 ProcessConnectionRequest ((PLPC_MAX_MESSAGE
) & Request
);
165 case LPC_CLIENT_DIED
:
166 case LPC_PORT_CLOSED
:
167 case LPC_DEBUG_EVENT
:
168 case LPC_ERROR_EVENT
:
173 if (RequestType
!= LPC_REQUEST
)
180 Reply
->PsxHeader
.Status
= ProcessRequest (& Request
);
183 if ((STATUS_INVALID_HANDLE
== Status
) ||
184 (STATUS_OBJECT_TYPE_MISMATCH
== Status
))
189 #ifdef __PSXSS_ON_W32__
190 TerminateThread(GetCurrentThread(),Status
);
192 NtTerminateThread(NtCurrentThread(),Status
);