Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

323 lines
8.1 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1996-1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: session.c
  6. * Content: Methods for session management
  7. *
  8. * History:
  9. * Date By Reason
  10. * ======= ======= ======
  11. * 2/27/97 myronth Created it
  12. * 3/12/97 myronth Implemented EnumSessions, Open, & Close
  13. * 3/31/97 myronth Removed dead code, Fixed EnumSessionReponse fn name
  14. * 4/3/97 myronth Changed CALLSP macro to CALL_LP
  15. * 5/8/97 myronth Drop lobby lock when calling the LP
  16. * 5/13/97 myronth Handle Credentials in Open, pass them to LP
  17. * 6/4/97 myronth Fixed PRV_Open to fail on DPOPEN_CREATE (#9491)
  18. ***************************************************************************/
  19. #include "dplobpr.h"
  20. //--------------------------------------------------------------------------
  21. //
  22. // Functions
  23. //
  24. //--------------------------------------------------------------------------
  25. #undef DPF_MODNAME
  26. #define DPF_MODNAME "PRV_Close"
  27. HRESULT DPLAPI PRV_Close(LPDPLOBBYI_DPLOBJECT this)
  28. {
  29. SPDATA_CLOSE cd;
  30. HRESULT hr = DP_OK;
  31. DPF(7, "Entering PRV_Close");
  32. DPF(9, "Parameters: 0x%08x", this);
  33. ENTER_DPLOBBY();
  34. TRY
  35. {
  36. if( !VALID_DPLOBBY_PTR( this ) )
  37. {
  38. LEAVE_DPLOBBY();
  39. return DPERR_INVALIDOBJECT;
  40. }
  41. }
  42. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  43. {
  44. LEAVE_DPLOBBY();
  45. DPF_ERR( "Exception encountered validating parameters" );
  46. return DPERR_INVALIDPARAMS;
  47. }
  48. // Setup our SPDATA structure
  49. memset(&cd, 0, sizeof(SPDATA_CLOSE));
  50. cd.dwSize = sizeof(SPDATA_CLOSE);
  51. // Call the Close method in the SP
  52. if(CALLBACK_EXISTS(Close))
  53. {
  54. cd.lpISP = PRV_GetDPLobbySPInterface(this);
  55. // Drop the lock so the lobby provider's receive thread can get back
  56. // in with other messages if they show up in the queue before our
  57. // CreatePlayer response (which always happens)
  58. LEAVE_DPLOBBY();
  59. hr = CALL_LP(this, Close, &cd);
  60. ENTER_DPLOBBY();
  61. }
  62. else
  63. {
  64. // Close is required
  65. DPF_ERR("The Lobby Provider callback for Close doesn't exist -- it's required");
  66. ASSERT(FALSE);
  67. LEAVE_DPLOBBY();
  68. return DPERR_UNAVAILABLE;
  69. }
  70. LEAVE_DPLOBBY();
  71. return hr;
  72. } // PRV_Close
  73. #undef DPF_MODNAME
  74. #define DPF_MODNAME "PRV_EnumSessions"
  75. HRESULT DPLAPI PRV_EnumSessions(LPDPLOBBYI_DPLOBJECT this,
  76. LPDPSESSIONDESC2 lpsd, DWORD dwTimeout, DWORD dwFlags)
  77. {
  78. HRESULT hr = DP_OK;
  79. SPDATA_ENUMSESSIONS esd;
  80. DPF(7, "Entering PRV_EnumSessions");
  81. DPF(9, "Parameters: 0x%08x, 0x%08x, %lu, 0x%08x",
  82. this, lpsd, dwTimeout, dwFlags);
  83. ASSERT(this);
  84. ASSERT(lpsd);
  85. ENTER_DPLOBBY();
  86. TRY
  87. {
  88. if( !VALID_DPLOBBY_PTR( this ) )
  89. {
  90. LEAVE_DPLOBBY();
  91. return DPERR_INVALIDOBJECT;
  92. }
  93. }
  94. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  95. {
  96. LEAVE_DPLOBBY();
  97. DPF_ERR( "Exception encountered validating parameters" );
  98. return DPERR_INVALIDPARAMS;
  99. }
  100. // Call the EnumSessions method in the SP
  101. if(CALLBACK_EXISTS(EnumSessions))
  102. {
  103. // Clear our stack-based structure
  104. memset(&esd, 0, sizeof(SPDATA_ENUMSESSIONS));
  105. // Set up the structure and call the callback
  106. esd.dwSize = sizeof(SPDATA_ENUMSESSIONS);
  107. esd.lpISP = PRV_GetDPLobbySPInterface(this);
  108. esd.lpsd = lpsd;
  109. esd.dwTimeout = dwTimeout;
  110. esd.dwFlags = dwFlags;
  111. // Drop the lock so the lobby provider's receive thread can get back
  112. // in with other messages if they show up in the queue before our
  113. // CreatePlayer response (which always happens)
  114. LEAVE_DPLOBBY();
  115. hr = CALL_LP(this, EnumSessions, &esd);
  116. ENTER_DPLOBBY();
  117. }
  118. else
  119. {
  120. // EnumSessions is required
  121. // REVIEW!!!! -- What error should we return here????
  122. DPF_ERR("The Lobby Provider callback for EnumSessions doesn't exist -- it's required");
  123. ASSERT(FALSE);
  124. hr = DPERR_UNAVAILABLE;
  125. }
  126. if(FAILED(hr))
  127. {
  128. DPF_ERR("Could not invoke EnumSessions in the Service Provider");
  129. }
  130. LEAVE_DPLOBBY();
  131. return hr;
  132. } // PRV_EnumSessions
  133. #undef DPF_MODNAME
  134. #define DPF_MODNAME "DPLP_EnumSessionsResponse"
  135. HRESULT DPLAPI DPLP_EnumSessionsResponse(LPDPLOBBYSP lpDPLSP,
  136. LPSPDATA_ENUMSESSIONSRESPONSE lpr)
  137. {
  138. LPDPLOBBYI_DPLOBJECT this;
  139. LPMSG_ENUMSESSIONSREPLY lpBuffer = NULL;
  140. LPBYTE lpIndex = NULL;
  141. DWORD dwNameLength, dwMessageSize;
  142. HRESULT hr = DP_OK;
  143. DPF(7, "Entering DPLP_EnumSessionsResponse");
  144. DPF(9, "Parameters: 0x%08x, 0x%08x", lpDPLSP, lpr);
  145. // Make sure the SP doesn't throw us a curve
  146. TRY
  147. {
  148. this = DPLOBJECT_FROM_INTERFACE(lpDPLSP);
  149. if( !VALID_DPLOBBY_PTR( this ) )
  150. {
  151. DPF_ERR("SP passed invalid DPLobby object!");
  152. return DPERR_INVALIDOBJECT;
  153. }
  154. // Validate the struct pointer
  155. if(!lpr)
  156. {
  157. DPF_ERR("SPDATA_ENUMSESSIONSRESPONSE structure pointer cannot be NULL");
  158. return DPERR_INVALIDPARAMS;
  159. }
  160. }
  161. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  162. {
  163. DPF_ERR( "Exception encountered validating parameters" );
  164. return DPERR_INVALIDPARAMS;
  165. }
  166. // REVIEW!!!! -- Can we put this packing code that's duplicated
  167. // from dplay into a single function???
  168. dwNameLength = WSTRLEN_BYTES(lpr->lpsd->lpszSessionName);
  169. // Calculate the size of the message to send back to dplay
  170. dwMessageSize = sizeof(MSG_ENUMSESSIONSREPLY);
  171. dwMessageSize += dwNameLength;
  172. lpBuffer = DPMEM_ALLOC(dwMessageSize);
  173. if (!lpBuffer)
  174. {
  175. DPF(2, "Unable to allocate memory for EnumSessions request");
  176. return DPERR_OUTOFMEMORY;
  177. }
  178. // Set up the message
  179. SET_MESSAGE_HDR(lpBuffer);
  180. SET_MESSAGE_COMMAND(lpBuffer, DPSP_MSG_ENUMSESSIONSREPLY);
  181. lpBuffer->dpDesc = *(lpr->lpsd);
  182. // Pack strings on end
  183. lpIndex = (LPBYTE)lpBuffer+sizeof(MSG_ENUMSESSIONSREPLY);
  184. if(dwNameLength)
  185. {
  186. memcpy(lpIndex, lpr->lpsd->lpszSessionName, dwNameLength);
  187. lpBuffer->dwNameOffset = sizeof(MSG_ENUMSESSIONSREPLY);
  188. }
  189. // set string pointers to NULL - they must be set at client
  190. lpBuffer->dpDesc.lpszPassword = NULL;
  191. lpBuffer->dpDesc.lpszSessionName = NULL;
  192. // Now send it to dplay
  193. ENTER_DPLAY();
  194. hr = HandleEnumSessionsReply(this->lpDPlayObject, (LPBYTE)lpBuffer, dwMessageSize, NULL);
  195. LEAVE_DPLAY();
  196. // Free our buffer
  197. DPMEM_FREE(lpBuffer);
  198. return hr;
  199. } // DPLP_EnumSessionsResponse
  200. #undef DPF_MODNAME
  201. #define DPF_MODNAME "PRV_Open"
  202. HRESULT DPLAPI PRV_Open(LPDPLOBBYI_DPLOBJECT this, LPDPSESSIONDESC2 lpsd,
  203. DWORD dwFlags, LPCDPCREDENTIALS lpCredentials)
  204. {
  205. SPDATA_OPEN od;
  206. HRESULT hr = DP_OK;
  207. DPF(7, "Entering PRV_Open");
  208. DPF(9, "Parameters: 0x%08x, 0x%08x, 0x%08x, 0x%08x",
  209. this, lpsd, dwFlags, lpCredentials);
  210. ENTER_DPLOBBY();
  211. TRY
  212. {
  213. if( !VALID_DPLOBBY_PTR( this ) )
  214. {
  215. LEAVE_DPLOBBY();
  216. return DPERR_INVALIDOBJECT;
  217. }
  218. // We cannot host a lobby session
  219. if(dwFlags & DPOPEN_CREATE)
  220. {
  221. DPF_ERR("Cannot host a lobby session");
  222. LEAVE_DPLOBBY();
  223. return DPERR_INVALIDFLAGS;
  224. }
  225. }
  226. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  227. {
  228. LEAVE_DPLOBBY();
  229. DPF_ERR( "Exception encountered validating parameters" );
  230. return DPERR_INVALIDPARAMS;
  231. }
  232. // Setup our SPDATA structure
  233. memset(&od, 0, sizeof(SPDATA_OPEN));
  234. od.dwSize = sizeof(SPDATA_OPEN);
  235. od.lpsd = lpsd;
  236. od.dwFlags = dwFlags;
  237. od.lpCredentials = lpCredentials;
  238. // Call the ConnectServer method in the SP
  239. if(CALLBACK_EXISTS(Open))
  240. {
  241. od.lpISP = PRV_GetDPLobbySPInterface(this);
  242. // Drop the lock so the lobby provider's receive thread can get back
  243. // in with other messages if they show up in the queue before our
  244. // CreatePlayer response (which always happens)
  245. LEAVE_DPLOBBY();
  246. hr = CALL_LP(this, Open, &od);
  247. ENTER_DPLOBBY();
  248. }
  249. else
  250. {
  251. // Open is required
  252. DPF_ERR("The Lobby Provider callback for Open doesn't exist -- it's required");
  253. ASSERT(FALSE);
  254. LEAVE_DPLOBBY();
  255. return DPERR_UNAVAILABLE;
  256. }
  257. LEAVE_DPLOBBY();
  258. return hr;
  259. } // PRV_Open