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.

376 lines
13 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: Protocol.cpp
  6. * Content: DNET protocol interface routines
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 03/01/00 ejs Created
  12. * 08/05/00 RichGr IA64: Use %p format specifier in DPFs for 32/64-bit pointers and handles.
  13. *@@END_MSINTERNAL
  14. *
  15. ***************************************************************************/
  16. #include "dncorei.h"
  17. #ifndef DPNBUILD_NOPROTOCOLTESTITF
  18. //**********************************************************************
  19. // Constant definitions
  20. //**********************************************************************
  21. //**********************************************************************
  22. // Macro definitions
  23. //**********************************************************************
  24. //**********************************************************************
  25. // Structure definitions
  26. //**********************************************************************
  27. //**********************************************************************
  28. // Variable definitions
  29. //**********************************************************************
  30. //**********************************************************************
  31. // Function prototypes
  32. //**********************************************************************
  33. typedef STDMETHODIMP ProtocolQueryInterface( IDirectPlay8Protocol* pInterface, REFIID riid, LPVOID *ppvObj );
  34. typedef STDMETHODIMP_(ULONG) ProtocolAddRef( IDirectPlay8Protocol* pInterface );
  35. typedef STDMETHODIMP_(ULONG) ProtocolRelease( IDirectPlay8Protocol* pInterface );
  36. //**********************************************************************
  37. // Function definitions
  38. //**********************************************************************
  39. // DN_ProtocolInitialize
  40. //
  41. // Initialize protocol
  42. #undef DPF_MODNAME
  43. #define DPF_MODNAME "DN_ProtocolInitialize"
  44. STDMETHODIMP DN_ProtocolInitialize(IDirectPlay8Protocol* pInterface, PVOID pvContext, PDN_PROTOCOL_INTERFACE_VTBL pfVTbl)
  45. {
  46. HRESULT hr;
  47. DIRECTNETOBJECT *pdnObject;
  48. IDirectPlay8ThreadPoolWork *pDPThreadPoolWork;
  49. DNASSERT(pInterface != NULL);
  50. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  51. DNASSERT(pdnObject != NULL);
  52. #ifdef DPNBUILD_LIBINTERFACE
  53. #if ((defined(DPNBUILD_ONLYONETHREAD)) && (! defined(DPNBUILD_MULTIPLETHREADPOOLS)))
  54. DPTPCF_GetObject(reinterpret_cast<void**>(&pDPThreadPoolWork));
  55. hr = S_OK;
  56. #else // ! DPNBUILD_ONLYONETHREAD or DPNBUILD_MULTIPLETHREADPOOLS
  57. hr = DPTPCF_CreateObject(reinterpret_cast<void**>(&pDPThreadPoolWork));
  58. #endif // ! DPNBUILD_ONLYONETHREAD or DPNBUILD_MULTIPLETHREADPOOLS
  59. #else // ! DPNBUILD_LIBINTERFACE
  60. hr = COM_CoCreateInstance(CLSID_DirectPlay8ThreadPool,
  61. NULL,
  62. CLSCTX_INPROC_SERVER,
  63. IID_IDirectPlay8ThreadPoolWork,
  64. reinterpret_cast<void**>(&pDPThreadPoolWork),
  65. FALSE);
  66. #endif // ! DPNBUILD_LIBINTERFACE
  67. if (FAILED(hr))
  68. {
  69. DPFX(DPFPREP, 0, "Couldn't CoCreate a ThreadPool object for the Protocol to use.");
  70. return hr;
  71. }
  72. #ifndef DPNBUILD_ONLYONETHREAD
  73. hr = IDirectPlay8ThreadPoolWork_RequestTotalThreadCount(pDPThreadPoolWork, 4, 0);
  74. if (FAILED(hr))
  75. {
  76. DPFX(DPFPREP, 0, "Couldn't request thread count from ThreadPool");
  77. goto Exit;
  78. }
  79. #endif // ! DPNBUILD_ONLYONETHREAD
  80. hr = DNPProtocolInitialize( pdnObject->pdnProtocolData, pvContext, pfVTbl, pDPThreadPoolWork, FALSE );
  81. #ifndef DPNBUILD_ONLYONETHREAD
  82. Exit:
  83. #endif // ! DPNBUILD_ONLYONETHREAD
  84. IDirectPlay8ThreadPoolWork_Release(pDPThreadPoolWork);
  85. pDPThreadPoolWork = NULL;
  86. return hr;
  87. }
  88. #undef DPF_MODNAME
  89. #define DPF_MODNAME "DN_ProtocolShutdown"
  90. STDMETHODIMP DN_ProtocolShutdown(IDirectPlay8Protocol* pInterface)
  91. {
  92. DIRECTNETOBJECT *pdnObject;
  93. DNASSERT(pInterface != NULL);
  94. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  95. DNASSERT(pdnObject != NULL);
  96. return DNPProtocolShutdown(pdnObject->pdnProtocolData);
  97. }
  98. #undef DPF_MODNAME
  99. #define DPF_MODNAME "DN_ProtocolAddSP"
  100. STDMETHODIMP DN_ProtocolAddSP(IDirectPlay8Protocol* pInterface, IDP8ServiceProvider* pISP, HANDLE* phSPHandle)
  101. {
  102. DIRECTNETOBJECT *pdnObject;
  103. DNASSERT(pInterface != NULL);
  104. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  105. DNASSERT(pdnObject != NULL);
  106. //Flags parameter for DNPAddServiceProvider is passed through as the
  107. //flags parameter in the SPINITIALIZEDATA structure to the SP
  108. //We pass the session type via it
  109. DWORD dwFlags;
  110. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PEER)
  111. dwFlags=SP_SESSION_TYPE_PEER;
  112. else if (pdnObject->dwFlags & DN_OBJECT_FLAG_CLIENT)
  113. dwFlags=SP_SESSION_TYPE_CLIENT;
  114. else
  115. {
  116. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_SERVER);
  117. dwFlags=SP_SESSION_TYPE_SERVER;
  118. }
  119. return DNPAddServiceProvider(pdnObject->pdnProtocolData, pISP, phSPHandle, dwFlags);
  120. }
  121. #undef DPF_MODNAME
  122. #define DPF_MODNAME "DN_ProtocolRemoveSP"
  123. STDMETHODIMP DN_ProtocolRemoveSP(IDirectPlay8Protocol* pInterface, HANDLE hSPHandle)
  124. {
  125. DIRECTNETOBJECT *pdnObject;
  126. DNASSERT(pInterface != NULL);
  127. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  128. DNASSERT(pdnObject != NULL);
  129. return DNPRemoveServiceProvider(pdnObject->pdnProtocolData, hSPHandle);
  130. }
  131. #undef DPF_MODNAME
  132. #define DPF_MODNAME "DN_ProtocolConnect"
  133. STDMETHODIMP DN_ProtocolConnect(IDirectPlay8Protocol* pInterface, IDirectPlay8Address* paLocalAddress, IDirectPlay8Address* paRemoteAddress, HANDLE hSPHandle, ULONG ulFlags, VOID* pvContext, HANDLE* phConnect)
  134. {
  135. DIRECTNETOBJECT *pdnObject;
  136. DNASSERT(pInterface != NULL);
  137. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  138. DNASSERT(pdnObject != NULL);
  139. return DNPConnect(pdnObject->pdnProtocolData, paLocalAddress, paRemoteAddress, hSPHandle, ulFlags, pvContext, NULL, 0, phConnect);
  140. }
  141. #undef DPF_MODNAME
  142. #define DPF_MODNAME "DN_ProtocolListen"
  143. STDMETHODIMP DN_ProtocolListen(IDirectPlay8Protocol* pInterface, IDirectPlay8Address* paAddress, HANDLE hSPHandle, ULONG ulFlags, VOID* pvContext, HANDLE* phListen)
  144. {
  145. DIRECTNETOBJECT *pdnObject;
  146. DNASSERT(pInterface != NULL);
  147. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  148. DNASSERT(pdnObject != NULL);
  149. return DNPListen(pdnObject->pdnProtocolData, paAddress, hSPHandle, ulFlags, pvContext, NULL, 0, phListen);
  150. }
  151. #undef DPF_MODNAME
  152. #define DPF_MODNAME "DN_ProtocolSendData"
  153. STDMETHODIMP DN_ProtocolSendData(IDirectPlay8Protocol* pInterface, HANDLE hEndpoint, UINT uiBufferCount, BUFFERDESC* pBuffers, UINT uiTimeout, ULONG ulFlags, VOID* pvContext, HANDLE* phSendHandle)
  154. {
  155. DIRECTNETOBJECT *pdnObject;
  156. DNASSERT(pInterface != NULL);
  157. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  158. DNASSERT(pdnObject != NULL);
  159. return DNPSendData(pdnObject->pdnProtocolData, hEndpoint, uiBufferCount, pBuffers, uiTimeout, ulFlags, pvContext, phSendHandle);
  160. }
  161. #undef DPF_MODNAME
  162. #define DPF_MODNAME "DN_ProtocolDisconnectEP"
  163. STDMETHODIMP DN_ProtocolDisconnectEP(IDirectPlay8Protocol* pInterface, HANDLE hEndPoint, VOID* pvContext, HANDLE* phDisconnect, DWORD dwFlags)
  164. {
  165. DIRECTNETOBJECT *pdnObject;
  166. DNASSERT(pInterface != NULL);
  167. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  168. DNASSERT(pdnObject != NULL);
  169. return DNPDisconnectEndPoint(pdnObject->pdnProtocolData, hEndPoint, pvContext, phDisconnect, dwFlags);
  170. }
  171. #undef DPF_MODNAME
  172. #define DPF_MODNAME "DN_ProtocolCancel"
  173. STDMETHODIMP DN_ProtocolCancel(IDirectPlay8Protocol* pInterface, HANDLE hCommand)
  174. {
  175. DIRECTNETOBJECT *pdnObject;
  176. DNASSERT(pInterface != NULL);
  177. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  178. DNASSERT(pdnObject != NULL);
  179. return DNPCancelCommand(pdnObject->pdnProtocolData, hCommand);
  180. }
  181. #undef DPF_MODNAME
  182. #define DPF_MODNAME "DN_ProtocolReleaseReceiveBuffer"
  183. STDMETHODIMP DN_ProtocolReleaseReceiveBuffer(IDirectPlay8Protocol* pInterface, HANDLE hBuffer)
  184. {
  185. DIRECTNETOBJECT *pdnObject;
  186. DNASSERT(pInterface != NULL);
  187. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  188. DNASSERT(pdnObject != NULL);
  189. return DNPReleaseReceiveBuffer(pdnObject->pdnProtocolData, hBuffer);
  190. }
  191. #undef DPF_MODNAME
  192. #define DPF_MODNAME "DN_ProtocolGetEPCaps"
  193. STDMETHODIMP DN_ProtocolGetEPCaps(IDirectPlay8Protocol* pInterface, HANDLE hEndpoint, VOID* pvBuffer)
  194. {
  195. DIRECTNETOBJECT *pdnObject;
  196. DNASSERT(pInterface != NULL);
  197. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  198. DNASSERT(pdnObject != NULL);
  199. return DNPGetEPCaps(pdnObject->pdnProtocolData, hEndpoint, (DPN_CONNECTION_INFO*) pvBuffer);
  200. }
  201. #undef DPF_MODNAME
  202. #define DPF_MODNAME "DN_ProtocolDebug"
  203. STDMETHODIMP DN_ProtocolDebug(IDirectPlay8Protocol* pInterface, UINT uiOpcode, HANDLE hEndpoint, VOID* pvBuffer)
  204. {
  205. DIRECTNETOBJECT *pdnObject;
  206. DNASSERT(pInterface != NULL);
  207. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  208. DNASSERT(pdnObject != NULL);
  209. return DNPDebug(pdnObject->pdnProtocolData, uiOpcode, hEndpoint, pvBuffer);
  210. }
  211. #undef DPF_MODNAME
  212. #define DPF_MODNAME "DN_ProtocolGetCaps"
  213. STDMETHODIMP DN_ProtocolGetCaps(IDirectPlay8Protocol* pInterface, DPN_CAPS* pCaps)
  214. {
  215. DIRECTNETOBJECT *pdnObject;
  216. DNASSERT(pInterface != NULL);
  217. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  218. DNASSERT(pdnObject != NULL);
  219. return DNPGetProtocolCaps(pdnObject->pdnProtocolData, pCaps);
  220. }
  221. #undef DPF_MODNAME
  222. #define DPF_MODNAME "DN_ProtocolGetCaps"
  223. STDMETHODIMP DN_ProtocolSetCaps(IDirectPlay8Protocol* pInterface, DPN_CAPS* pCaps)
  224. {
  225. DIRECTNETOBJECT *pdnObject;
  226. DNASSERT(pInterface != NULL);
  227. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  228. DNASSERT(pdnObject != NULL);
  229. return DNPSetProtocolCaps(pdnObject->pdnProtocolData, pCaps);
  230. }
  231. #undef DPF_MODNAME
  232. #define DPF_MODNAME "DN_ProtocolEnumQuery"
  233. STDMETHODIMP DN_ProtocolEnumQuery(IDirectPlay8Protocol* pInterface, IDirectPlay8Address* paHostAddress, IDirectPlay8Address* paDeviceAddress, HANDLE hSPHandle, BUFFERDESC* pBuffers, DWORD dwBufferCount, DWORD dwRetryCount, DWORD dwRetryInterval, DWORD dwTimeout, DWORD dwFlags, VOID* pvUserContext, HANDLE* phEnumHandle)
  234. {
  235. DIRECTNETOBJECT *pdnObject;
  236. DNASSERT(pInterface != NULL);
  237. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  238. DNASSERT(pdnObject != NULL);
  239. return DNPEnumQuery( pdnObject->pdnProtocolData, paHostAddress, paDeviceAddress, hSPHandle, pBuffers, dwBufferCount, dwRetryCount, dwRetryInterval, dwTimeout, dwFlags, pvUserContext, NULL, 0, phEnumHandle );
  240. }
  241. #undef DPF_MODNAME
  242. #define DPF_MODNAME "DN_ProtocolEnumRespond"
  243. STDMETHODIMP DN_ProtocolEnumRespond(IDirectPlay8Protocol* pInterface, HANDLE hSPHandle, HANDLE hQueryHandle, BUFFERDESC* pBuffers, DWORD dwBufferCount, DWORD dwFlags, VOID* pvUserContext, HANDLE* phEnumHandle)
  244. {
  245. DIRECTNETOBJECT *pdnObject;
  246. DNASSERT(pInterface != NULL);
  247. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  248. DNASSERT(pdnObject != NULL);
  249. return DNPEnumRespond( pdnObject->pdnProtocolData, hSPHandle, hQueryHandle, pBuffers, dwBufferCount, dwFlags, pvUserContext, phEnumHandle );
  250. }
  251. #undef DPF_MODNAME
  252. #define DPF_MODNAME "DN_ProtocolCrackEPD"
  253. STDMETHODIMP DN_ProtocolCrackEPD(IDirectPlay8Protocol* pInterface, HANDLE hEndPoint, long Flags, IDirectPlay8Address** ppAddr )
  254. {
  255. DIRECTNETOBJECT *pdnObject;
  256. DNASSERT(pInterface != NULL);
  257. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  258. DNASSERT(pdnObject != NULL);
  259. SPGETADDRESSINFODATA SPData;
  260. SPData.Flags = (SP_GET_ADDRESS_INFO_FLAGS)Flags;
  261. HRESULT hr = DNPCrackEndPointDescriptor( pdnObject->pdnProtocolData, hEndPoint, &SPData );
  262. *ppAddr = SPData.pAddress;
  263. return hr;
  264. }
  265. #undef DPF_MODNAME
  266. #define DPF_MODNAME "DN_ProtocolGetListenAddressInfo"
  267. STDMETHODIMP DN_ProtocolGetListenAddressInfo(IDirectPlay8Protocol* pInterface, HANDLE hCommand, long Flags, IDirectPlay8Address** ppAddr )
  268. {
  269. DIRECTNETOBJECT *pdnObject;
  270. DNASSERT(pInterface != NULL);
  271. pdnObject = (DIRECTNETOBJECT *)GET_OBJECT_FROM_INTERFACE(pInterface);
  272. DNASSERT(pdnObject != NULL);
  273. SPGETADDRESSINFODATA SPData;
  274. SPData.Flags = (SP_GET_ADDRESS_INFO_FLAGS)Flags;
  275. HRESULT hr = DNPGetListenAddressInfo( pdnObject->pdnProtocolData, hCommand, &SPData );
  276. *ppAddr = SPData.pAddress;
  277. return hr;
  278. }
  279. IDirectPlay8ProtocolVtbl DN_ProtocolVtbl =
  280. {
  281. (ProtocolQueryInterface*) DN_QueryInterface,
  282. (ProtocolAddRef*) DN_AddRef,
  283. (ProtocolRelease*) DN_Release,
  284. DN_ProtocolInitialize,
  285. DN_ProtocolShutdown,
  286. DN_ProtocolAddSP,
  287. DN_ProtocolRemoveSP,
  288. DN_ProtocolConnect,
  289. DN_ProtocolListen,
  290. DN_ProtocolSendData,
  291. DN_ProtocolDisconnectEP,
  292. DN_ProtocolCancel,
  293. DN_ProtocolReleaseReceiveBuffer,
  294. DN_ProtocolGetEPCaps,
  295. DN_ProtocolGetCaps,
  296. DN_ProtocolSetCaps,
  297. DN_ProtocolEnumQuery,
  298. DN_ProtocolEnumRespond,
  299. DN_ProtocolCrackEPD,
  300. DN_ProtocolGetListenAddressInfo,
  301. DN_ProtocolDebug,
  302. };
  303. #endif // !DPNBUILD_NOPROTOCOLTESTITF