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.

3810 lines
102 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1998-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: WSockSP.cpp
  6. * Content: Protocol-independent APIs for the DN Winsock SP
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 10/26/1998 jwo Created it.
  13. * 11/1/1998 jwo Un-subclassed everything (moved it to this generic
  14. * file from IP and IPX specific ones
  15. * 03/22/2000 jtk Updated with changes to interface names
  16. * 04/22/2000 mjn Allow all flags in DNSP_GetAddressInfo()
  17. * 08/06/2000 RichGr IA64: Use %p format specifier in DPFs for 32/64-bit pointers and handles.
  18. * 03/12/2001 mjn Prevent enum responses from being indicated up after completion
  19. ***************************************************************************/
  20. #include "dnwsocki.h"
  21. //**********************************************************************
  22. // Constant definitions
  23. //**********************************************************************
  24. //
  25. // maximum bandwidth in bits per second
  26. //
  27. #define UNKNOWN_BANDWIDTH 0
  28. #define WAIT_FOR_CLOSE_TIMEOUT 30000 // milliseconds
  29. #define ADDRESS_ENCODE_KEY 0
  30. //**********************************************************************
  31. // Macro definitions
  32. //**********************************************************************
  33. //**********************************************************************
  34. // Structure definitions
  35. //**********************************************************************
  36. //**********************************************************************
  37. // Variable definitions
  38. //**********************************************************************
  39. //**********************************************************************
  40. // Function prototypes
  41. //**********************************************************************
  42. //**********************************************************************
  43. // Function definitions
  44. //**********************************************************************
  45. //**********************************************************************
  46. /*
  47. *
  48. * DNSP_Initialize initializes the instance of the SP. It must be called
  49. * at least once before using any other functions. Further attempts
  50. * to initialize the SP are ignored.
  51. *
  52. */
  53. //**********************************************************************
  54. #undef DPF_MODNAME
  55. #define DPF_MODNAME "DNSP_Initialize"
  56. STDMETHODIMP DNSP_Initialize( IDP8ServiceProvider *pThis, SPINITIALIZEDATA *pData )
  57. {
  58. HRESULT hr;
  59. CSPData *pSPData;
  60. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pData);
  61. DNASSERT( pThis != NULL );
  62. DNASSERT( pData != NULL );
  63. //
  64. // initialize
  65. //
  66. hr = DPN_OK;
  67. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  68. // Trust protocol to call us only in the uninitialized state
  69. DNASSERT( pSPData->GetState() == SPSTATE_UNINITIALIZED );
  70. //
  71. // prevent anyone else from messing with this interface
  72. //
  73. pSPData->Lock();
  74. hr = pSPData->Startup( pData );
  75. if (hr != DPN_OK)
  76. {
  77. goto Failure;
  78. }
  79. pSPData->Unlock();
  80. IDP8ServiceProvider_AddRef( pThis );
  81. Exit:
  82. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  83. return hr;
  84. Failure:
  85. pSPData->Unlock();
  86. goto Exit;
  87. }
  88. //**********************************************************************
  89. //**********************************************************************
  90. /*
  91. *
  92. * DNSP_Close is the opposite of Initialize. Call it when you're done
  93. * using the SP
  94. *
  95. */
  96. //**********************************************************************
  97. #undef DPF_MODNAME
  98. #define DPF_MODNAME "DNSP_Close"
  99. STDMETHODIMP DNSP_Close( IDP8ServiceProvider *pThis )
  100. {
  101. HRESULT hr;
  102. CSPData *pSPData;
  103. DPFX(DPFPREP, 2, "Parameters: (0x%p)", pThis);
  104. DNASSERT( pThis != NULL );
  105. //
  106. // initialize
  107. //
  108. hr = DPN_OK;
  109. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  110. // Trust protocol to call us only in the initialized state
  111. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  112. pSPData->Shutdown();
  113. IDP8ServiceProvider_Release( pThis );
  114. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  115. return hr;
  116. }
  117. //**********************************************************************
  118. //**********************************************************************
  119. // ------------------------------
  120. // DNSP_AddRef - increment reference count
  121. //
  122. // Entry: Pointer to interface
  123. //
  124. // Exit: New reference count
  125. // ------------------------------
  126. #undef DPF_MODNAME
  127. #define DPF_MODNAME "DNSP_AddRef"
  128. STDMETHODIMP_(ULONG) DNSP_AddRef( IDP8ServiceProvider *pThis )
  129. {
  130. CSPData * pSPData;
  131. ULONG ulResult;
  132. DPFX(DPFPREP, 2, "Parameters: (0x%p)", pThis);
  133. DNASSERT( pThis != NULL );
  134. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  135. ulResult = pSPData->AddRef();
  136. DPFX(DPFPREP, 2, "Returning: [0x%u]", ulResult);
  137. return ulResult;
  138. }
  139. //**********************************************************************
  140. //**********************************************************************
  141. // ------------------------------
  142. // DNSP_Release - decrement reference count
  143. //
  144. // Entry: Pointer to interface
  145. //
  146. // Exit: New reference count
  147. // ------------------------------
  148. #undef DPF_MODNAME
  149. #define DPF_MODNAME "DNSP_Release"
  150. STDMETHODIMP_(ULONG) DNSP_Release( IDP8ServiceProvider *pThis )
  151. {
  152. CSPData * pSPData;
  153. ULONG ulResult;
  154. DPFX(DPFPREP, 2, "Parameters: (0x%p)", pThis);
  155. DNASSERT( pThis != NULL );
  156. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  157. ulResult = pSPData->DecRef();
  158. DPFX(DPFPREP, 2, "Returning: [0x%u]", ulResult);
  159. return ulResult;
  160. }
  161. //**********************************************************************
  162. //**********************************************************************
  163. /*
  164. *
  165. * DNSP_EnumQuery sends out the
  166. * specified data to the specified address. If the SP is unable to
  167. * determine the address based on the input params, it checks to see
  168. * if it's allowed to put up a dialog querying the user for address
  169. * info. If it is, it queries the user for address info.
  170. *
  171. */
  172. //**********************************************************************
  173. #undef DPF_MODNAME
  174. #define DPF_MODNAME "DNSP_EnumQuery"
  175. STDMETHODIMP DNSP_EnumQuery( IDP8ServiceProvider *pThis, SPENUMQUERYDATA *pEnumQueryData)
  176. {
  177. HRESULT hr;
  178. CEndpoint *pEndpoint;
  179. CCommandData *pCommand;
  180. BOOL fEndpointOpen;
  181. CSPData *pSPData;
  182. #ifndef DPNBUILD_NONATHELP
  183. DWORD dwTraversalMode;
  184. DWORD dwComponentSize;
  185. DWORD dwComponentType;
  186. #endif // ! DPNBUILD_NONATHELP
  187. #ifdef DBG
  188. DWORD dwAllowedFlags;
  189. DWORD dwTotalBufferSize;
  190. DWORD dwTemp;
  191. #endif // DBG
  192. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pEnumQueryData);
  193. DNASSERT( pThis != NULL );
  194. DNASSERT( pEnumQueryData != NULL );
  195. DNASSERT( pEnumQueryData->pAddressHost != NULL );
  196. DNASSERT( pEnumQueryData->pAddressDeviceInfo != NULL );
  197. #ifdef DBG
  198. dwAllowedFlags = DPNSPF_NOBROADCASTFALLBACK | DPNSPF_SESSIONDATA;
  199. #ifndef DPNBUILD_NOSPUI
  200. dwAllowedFlags |= DPNSPF_OKTOQUERY;
  201. #endif // ! DPNBUILD_NOSPUI
  202. #ifndef DPNBUILD_ONLYONEADAPTER
  203. dwAllowedFlags |= DPNSPF_ADDITIONALMULTIPLEXADAPTERS;
  204. #endif // ! DPNBUILD_ONLYONEADAPTER
  205. DNASSERT( ( pEnumQueryData->dwFlags & ~( dwAllowedFlags ) ) == 0 );
  206. if ( pEnumQueryData->dwFlags & DPNSPF_SESSIONDATA )
  207. {
  208. DNASSERT( pEnumQueryData->pvSessionData!= NULL );
  209. DNASSERT( pEnumQueryData->dwSessionDataSize > 0 );
  210. }
  211. #endif // DBG
  212. DBG_CASSERT( sizeof( pEnumQueryData->dwRetryInterval ) == sizeof( DWORD ) );
  213. #ifndef DPNBUILD_NOREGISTRY
  214. //
  215. // Make sure someone isn't getting silly.
  216. //
  217. if ( g_fIgnoreEnums )
  218. {
  219. DPFX(DPFPREP, 0, "Trying to initiate an enumeration when registry option to ignore all enums/response is set!");
  220. DNASSERT( ! "Trying to initiate an enumeration when registry option to ignore all enums/response is set!" );
  221. }
  222. #endif // ! DPNBUILD_NOREGISTRY
  223. //
  224. // initialize
  225. //
  226. hr = DPNERR_PENDING;
  227. pEndpoint = NULL;
  228. pCommand = NULL;
  229. fEndpointOpen = FALSE;
  230. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  231. DNASSERT( pSPData != NULL );
  232. pEnumQueryData->hCommand = NULL;
  233. pEnumQueryData->dwCommandDescriptor = NULL_DESCRIPTOR;
  234. DumpAddress( 8, _T("Enum destination:"), pEnumQueryData->pAddressHost );
  235. DumpAddress( 8, _T("Enuming on device:"), pEnumQueryData->pAddressDeviceInfo );
  236. // Trust protocol to call us only in the initialized state
  237. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  238. //
  239. // the user is attempting an operation that relies on the thread pool, lock
  240. // it down to prevent threads from being lost. This also performs other
  241. // first time initialization.
  242. //
  243. hr = pSPData->GetThreadPool()->PreventThreadPoolReduction();
  244. if ( hr != DPN_OK )
  245. {
  246. DPFX(DPFPREP, 0, "Failed to prevent thread pool reduction!" );
  247. goto Failure;
  248. }
  249. #ifdef DBG
  250. //
  251. // Make sure message is not too large.
  252. //
  253. dwTotalBufferSize = 0;
  254. for(dwTemp = 0; dwTemp < pEnumQueryData->dwBufferCount; dwTemp++)
  255. {
  256. dwTotalBufferSize += pEnumQueryData->pBuffers[dwTemp].dwBufferSize;
  257. }
  258. #ifdef DPNBUILD_NOREGISTRY
  259. DNASSERT(dwTotalBufferSize <= DEFAULT_MAX_ENUM_DATA_SIZE);
  260. #else // ! DPNBUILD_NOREGISTRY
  261. DNASSERT(dwTotalBufferSize <= g_dwMaxEnumDataSize);
  262. #endif // ! DPNBUILD_NOREGISTRY
  263. #endif // DBG
  264. //
  265. // create and new endpoint
  266. //
  267. pEndpoint = pSPData->GetNewEndpoint();
  268. if ( pEndpoint == NULL )
  269. {
  270. hr = DPNERR_OUTOFMEMORY;
  271. DPFX(DPFPREP, 0, "Cannot create new endpoint in DNSP_EnumQuery!" );
  272. goto Failure;
  273. }
  274. #ifndef DPNBUILD_NONATHELP
  275. //
  276. // We need to detect up front whether NAT traversal is disabled or not so we can optimize
  277. // the Open call below.
  278. //
  279. dwComponentSize = sizeof(dwTraversalMode);
  280. hr = IDirectPlay8Address_GetComponentByName(pEnumQueryData->pAddressDeviceInfo,
  281. DPNA_KEY_TRAVERSALMODE,
  282. &dwTraversalMode,
  283. &dwComponentSize,
  284. &dwComponentType);
  285. if ( hr == DPN_OK )
  286. {
  287. //
  288. // We found the component. Make sure it's the right size and type.
  289. //
  290. if ((dwComponentSize == sizeof(dwTraversalMode)) && (dwComponentType == DPNA_DATATYPE_DWORD))
  291. {
  292. switch (dwTraversalMode)
  293. {
  294. case DPNA_TRAVERSALMODE_NONE:
  295. {
  296. DPFX(DPFPREP, 1, "Found traversal mode key, value is NONE.");
  297. break;
  298. }
  299. case DPNA_TRAVERSALMODE_PORTREQUIRED:
  300. {
  301. DPFX(DPFPREP, 1, "Found traversal mode key, value is PORTREQUIRED.");
  302. break;
  303. }
  304. case DPNA_TRAVERSALMODE_PORTRECOMMENDED:
  305. {
  306. DPFX(DPFPREP, 1, "Found traversal mode key, value is PORTRECOMMENDED.");
  307. break;
  308. }
  309. default:
  310. {
  311. DPFX(DPFPREP, 0, "Ignoring correctly formed traversal mode key with invalid value %u! Using default mode %u.",
  312. dwTraversalMode, g_dwDefaultTraversalMode);
  313. dwTraversalMode = g_dwDefaultTraversalMode;
  314. break;
  315. }
  316. }
  317. }
  318. else
  319. {
  320. DPFX(DPFPREP, 0, "Traversal mode key exists, but doesn't match expected type (%u != %u) or size (%u != %u)! Using default mode %u.",
  321. dwComponentSize, sizeof(dwTraversalMode),
  322. dwComponentType, DPNA_DATATYPE_DWORD,
  323. g_dwDefaultTraversalMode);
  324. dwTraversalMode = g_dwDefaultTraversalMode;
  325. }
  326. }
  327. else
  328. {
  329. //
  330. // The key is not there, it's the wrong size (too big for our buffer
  331. // and returned BUFFERTOOSMALL), or something else bad happened.
  332. // It doesn't matter. Carry on.
  333. //
  334. DPFX(DPFPREP, 8, "Could not get traversal mode key, error = 0x%lx, component size = %u, type = %u, using default mode %u.",
  335. hr, dwComponentSize, dwComponentType, g_dwDefaultTraversalMode);
  336. dwTraversalMode = g_dwDefaultTraversalMode;
  337. }
  338. if (g_dwDefaultTraversalMode & FORCE_TRAVERSALMODE_BIT)
  339. {
  340. DPFX(DPFPREP, 1, "Forcing traversal mode %u.");
  341. dwTraversalMode = g_dwDefaultTraversalMode & (~FORCE_TRAVERSALMODE_BIT);
  342. }
  343. pEndpoint->SetUserTraversalMode(dwTraversalMode);
  344. #endif // ! DPNBUILD_NONATHELP
  345. //
  346. // get new command and initialize it
  347. //
  348. pCommand = (CCommandData*)g_CommandDataPool.Get();
  349. if ( pCommand == NULL )
  350. {
  351. hr = DPNERR_OUTOFMEMORY;
  352. DPFX(DPFPREP, 0, "Cannot get command handle for DNSP_EnumQuery!" );
  353. goto Failure;
  354. }
  355. DPFX(DPFPREP, 7, "(0x%p) Enum query command 0x%p created.",
  356. pSPData, pCommand);
  357. pEnumQueryData->hCommand = pCommand;
  358. pEnumQueryData->dwCommandDescriptor = pCommand->GetDescriptor();
  359. pCommand->SetType( COMMAND_TYPE_ENUM_QUERY );
  360. pCommand->SetState( COMMAND_STATE_PENDING );
  361. pCommand->SetEndpoint( pEndpoint );
  362. //
  363. // open endpoint with outgoing address
  364. //
  365. fEndpointOpen = TRUE;
  366. hr = pEndpoint->Open( ENDPOINT_TYPE_ENUM,
  367. pEnumQueryData->pAddressHost,
  368. ((pEnumQueryData->dwFlags & DPNSPF_SESSIONDATA) ? pEnumQueryData->pvSessionData: NULL),
  369. ((pEnumQueryData->dwFlags & DPNSPF_SESSIONDATA) ? pEnumQueryData->dwSessionDataSize : 0),
  370. NULL );
  371. switch ( hr )
  372. {
  373. //
  374. // Incomplete address passed in, query user for more information if
  375. // we're allowed. If we're on IPX (no dialog available), don't attempt
  376. // to display the dialog, skip to checking for broadcast fallback.
  377. // Since we don't have a complete address at this time,
  378. // don't bind this endpoint to the socket port!
  379. //
  380. case DPNERR_INCOMPLETEADDRESS:
  381. {
  382. #ifndef DPNBUILD_NOSPUI
  383. if ( ( ( pEnumQueryData->dwFlags & DPNSPF_OKTOQUERY ) != 0 )
  384. #if ((! defined(DPNBUILD_NOIPV6)) || (! defined(DPNBUILD_NOIPX)))
  385. #ifdef DPNBUILD_NOIPV6
  386. && (( pSPData->GetType() == AF_INET6 ) || ( pSPData->GetType() == AF_INET ))
  387. #else // ! DPNBUILD_NOIPV6
  388. && ( pSPData->GetType() == AF_INET )
  389. #endif // ! DPNBUILD_NOIPV6
  390. #endif // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  391. )
  392. {
  393. //
  394. // Copy the connect data locally and start the dialog. When the
  395. // dialog completes, the connection will attempt to complete.
  396. // Since the dialog is being popped, this command is in progress,
  397. // not pending.
  398. //
  399. DNASSERT( pSPData != NULL );
  400. pCommand->SetState( COMMAND_STATE_INPROGRESS );
  401. hr = pEndpoint->CopyEnumQueryData( pEnumQueryData );
  402. if ( hr != DPN_OK )
  403. {
  404. DPFX(DPFPREP, 0, "Failed to copy enum query data before settings dialog!" );
  405. DisplayDNError( 0, hr );
  406. goto Failure;
  407. }
  408. //
  409. // Initialize the bind type. It will get changed to DEFAULT or SPECIFIC
  410. //
  411. pEndpoint->SetCommandParametersGatewayBindType(GATEWAY_BIND_TYPE_UNKNOWN);
  412. hr = pEndpoint->ShowSettingsDialog( pSPData->GetThreadPool() );
  413. if ( hr != DPN_OK )
  414. {
  415. DPFX(DPFPREP, 0, "Problem showing settings dialog for enum query!" );
  416. DisplayDNError( 0, hr );
  417. goto Failure;
  418. }
  419. //
  420. // this endpoint has been handed off, remove our reference to it
  421. //
  422. pEndpoint = NULL;
  423. hr = DPNERR_PENDING;
  424. goto Exit;
  425. }
  426. #endif // !DPNBUILD_NOSPUI
  427. if ( pEnumQueryData->dwFlags & DPNSPF_NOBROADCASTFALLBACK )
  428. {
  429. goto Failure;
  430. }
  431. //
  432. // we're OK, we can use the broadcast address.
  433. //
  434. #if ((! defined(DPNBUILD_NONATHELP)) && (! defined(DPNBUILD_ONLYONETHREAD)))
  435. //
  436. // If NAT traversal is allowed, we may need to load and start
  437. // NAT Help, which can block. Submit a blocking job. This
  438. // will redetect the incomplete address and use broadcast (see
  439. // CEndpoint::EnumQueryBlockingJob).
  440. //
  441. if ( pEndpoint->GetUserTraversalMode() != DPNA_TRAVERSALMODE_NONE )
  442. {
  443. goto SubmitBlockingJob;
  444. }
  445. #endif // ! DPNBUILD_NONATHELP and ! DPNBUILD_ONLYONETHREAD
  446. //
  447. // Mash in the broadcast address, but actually complete the
  448. // enum on another thread.
  449. //
  450. pEndpoint->ReinitializeWithBroadcast();
  451. goto SubmitDelayedCommand;
  452. break;
  453. }
  454. #ifndef DPNBUILD_ONLYONETHREAD
  455. //
  456. // some blocking operation might occur, submit it to be run
  457. // on a background thread.
  458. //
  459. case DPNERR_TIMEDOUT:
  460. {
  461. SubmitBlockingJob:
  462. //
  463. // Copy enum data and submit job to finish off enum.
  464. //
  465. DNASSERT( pSPData != NULL );
  466. hr = pEndpoint->CopyEnumQueryData( pEnumQueryData );
  467. if ( hr != DPN_OK )
  468. {
  469. DPFX(DPFPREP, 0, "Failed to copy enum query data before blocking job!" );
  470. DisplayDNError( 0, hr );
  471. goto Failure;
  472. }
  473. //
  474. // Initialize the bind type. It will get changed to DEFAULT or SPECIFIC
  475. //
  476. pEndpoint->SetCommandParametersGatewayBindType(GATEWAY_BIND_TYPE_UNKNOWN);
  477. pEndpoint->AddRef();
  478. hr = pSPData->GetThreadPool()->SubmitBlockingJob( CEndpoint::EnumQueryBlockingJobWrapper,
  479. pEndpoint );
  480. if ( hr != DPN_OK )
  481. {
  482. pEndpoint->DecRef();
  483. DPFX(DPFPREP, 0, "Failed to submit blocking enum query job!" );
  484. DisplayDNError( 0, hr );
  485. goto Failure;
  486. }
  487. //
  488. // this endpoint has been handed off, remove our reference
  489. //
  490. pEndpoint = NULL;
  491. hr = DPNERR_PENDING;
  492. goto Exit;
  493. }
  494. #endif // ! DPNBUILD_ONLYONETHREAD
  495. //
  496. // address conversion was fine, copy connect data and finish connection
  497. // on background thread.
  498. //
  499. case DPN_OK:
  500. {
  501. SubmitDelayedCommand:
  502. //
  503. // Copy enum data and submit job to finish off enum.
  504. //
  505. DNASSERT( pSPData != NULL );
  506. hr = pEndpoint->CopyEnumQueryData( pEnumQueryData );
  507. if ( hr != DPN_OK )
  508. {
  509. DPFX(DPFPREP, 0, "Failed to copy enum query data before delayed command!" );
  510. DisplayDNError( 0, hr );
  511. goto Failure;
  512. }
  513. //
  514. // Initialize the bind type. It will get changed to DEFAULT or SPECIFIC
  515. //
  516. pEndpoint->SetCommandParametersGatewayBindType(GATEWAY_BIND_TYPE_UNKNOWN);
  517. pEndpoint->AddRef();
  518. #ifdef DPNBUILD_ONLYONEPROCESSOR
  519. hr = pSPData->GetThreadPool()->SubmitDelayedCommand( CEndpoint::EnumQueryJobCallback,
  520. pEndpoint );
  521. #else // ! DPNBUILD_ONLYONEPROCESSOR
  522. hr = pSPData->GetThreadPool()->SubmitDelayedCommand( -1, // we don't know the CPU yet, so pick any
  523. CEndpoint::EnumQueryJobCallback,
  524. pEndpoint );
  525. #endif // ! DPNBUILD_ONLYONEPROCESSOR
  526. if ( hr != DPN_OK )
  527. {
  528. pEndpoint->DecRef();
  529. DPFX(DPFPREP, 0, "Failed to set delayed enum query!" );
  530. DisplayDNError( 0, hr );
  531. goto Failure;
  532. }
  533. //
  534. // this endpoint has been handed off, remove our reference
  535. //
  536. pEndpoint = NULL;
  537. hr = DPNERR_PENDING;
  538. goto Exit;
  539. break;
  540. }
  541. default:
  542. {
  543. //
  544. // this endpoint is screwed
  545. //
  546. DPFX(DPFPREP, 0, "Problem initializing endpoint in DNSP_EnumQuery!" );
  547. DisplayDNError( 0, hr );
  548. goto Failure;
  549. break;
  550. }
  551. }
  552. Exit:
  553. DNASSERT( pEndpoint == NULL );
  554. if ( hr != DPNERR_PENDING )
  555. {
  556. // this command cannot complete synchronously!
  557. DNASSERT( hr != DPN_OK );
  558. DPFX(DPFPREP, 0, "Problem with DNSP_EnumQuery()" );
  559. DisplayDNError( 0, hr );
  560. }
  561. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  562. return hr;
  563. Failure:
  564. //
  565. // if there's an allocated command, clean up and then
  566. // return the command
  567. //
  568. if ( pCommand != NULL )
  569. {
  570. pCommand->DecRef();
  571. pCommand = NULL;
  572. pEnumQueryData->hCommand = NULL;
  573. pEnumQueryData->dwCommandDescriptor = NULL_DESCRIPTOR;
  574. }
  575. //
  576. // is there an endpoint to free?
  577. //
  578. if ( pEndpoint != NULL )
  579. {
  580. if ( fEndpointOpen != FALSE )
  581. {
  582. pEndpoint->Close( hr );
  583. fEndpointOpen = FALSE;
  584. }
  585. pSPData->CloseEndpointHandle( pEndpoint );
  586. pEndpoint = NULL;
  587. }
  588. goto Exit;
  589. }
  590. //**********************************************************************
  591. //**********************************************************************
  592. /*
  593. *
  594. * DNSP_EnumRespond sends a response to an enum request by
  595. * sending the specified data to the address provided (on
  596. * unreliable transport).
  597. *
  598. */
  599. //**********************************************************************
  600. #undef DPF_MODNAME
  601. #define DPF_MODNAME "DNSP_EnumRespond"
  602. STDMETHODIMP DNSP_EnumRespond( IDP8ServiceProvider *pThis, SPENUMRESPONDDATA *pEnumRespondData )
  603. {
  604. HRESULT hr;
  605. CEndpoint *pEndpoint;
  606. CSPData *pSPData;
  607. const ENDPOINT_ENUM_QUERY_CONTEXT *pEnumQueryContext;
  608. PREPEND_BUFFER PrependBuffer;
  609. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pEnumRespondData);
  610. DNASSERT( pThis != NULL );
  611. DNASSERT( pEnumRespondData != NULL );
  612. DNASSERT( pEnumRespondData->dwFlags == 0 );
  613. //
  614. // initialize
  615. //
  616. DBG_CASSERT( OFFSETOF( ENDPOINT_ENUM_QUERY_CONTEXT, EnumQueryData ) == 0 );
  617. pEnumQueryContext = reinterpret_cast<ENDPOINT_ENUM_QUERY_CONTEXT*>( pEnumRespondData->pQuery );
  618. pEndpoint = NULL;
  619. pEnumRespondData->hCommand = NULL;
  620. pEnumRespondData->dwCommandDescriptor = NULL_DESCRIPTOR;
  621. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  622. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  623. //
  624. // check for valid endpoint
  625. //
  626. pEndpoint = pSPData->EndpointFromHandle( pEnumQueryContext->hEndpoint );
  627. if ( pEndpoint == NULL )
  628. {
  629. hr = DPNERR_INVALIDENDPOINT;
  630. DPFX(DPFPREP, 8, "Invalid endpoint handle in DNSP_EnumRespond" );
  631. goto Failure;
  632. }
  633. //
  634. // no need to poke at the thread pool here to lock down threads because we
  635. // can only really be here if there's an enum and that enum locked down the
  636. // thread pool.
  637. //
  638. DNASSERT( pEnumQueryContext->dwEnumKey <= WORD_MAX );
  639. pEnumRespondData->pBuffers[-1].pBufferData = reinterpret_cast<BYTE*>( &PrependBuffer.EnumResponseDataHeader );
  640. pEnumRespondData->pBuffers[-1].dwBufferSize = sizeof( PrependBuffer.EnumResponseDataHeader );
  641. PrependBuffer.EnumResponseDataHeader.bSPLeadByte = SP_HEADER_LEAD_BYTE;
  642. PrependBuffer.EnumResponseDataHeader.bSPCommandByte = ENUM_RESPONSE_DATA_KIND;
  643. PrependBuffer.EnumResponseDataHeader.wEnumResponsePayload = static_cast<WORD>( pEnumQueryContext->dwEnumKey );
  644. #ifdef DPNBUILD_XNETSECURITY
  645. //
  646. // Secure transport does not allow directed replies without having a
  647. // security context established. We need to broadcast the reply.
  648. //
  649. if (pEndpoint->IsUsingXNetSecurity())
  650. {
  651. SOCKADDR_IN * psaddrin;
  652. XNADDR xnaddr;
  653. DWORD dwAddressType;
  654. #pragma BUGBUG(vanceo, "Is it possible to have a security context? How can we tell? XNetInAddrToXnAddr failing?")
  655. #pragma TODO(vanceo, "Cache title address?")
  656. dwAddressType = XNetGetTitleXnAddr(&xnaddr);
  657. if ((dwAddressType != XNET_GET_XNADDR_PENDING) &&
  658. (dwAddressType != XNET_GET_XNADDR_NONE))
  659. {
  660. DNASSERT(pEnumQueryContext->pReturnAddress->GetFamily() == AF_INET);
  661. psaddrin = (SOCKADDR_IN*) (pEnumQueryContext->pReturnAddress->GetWritableAddress());
  662. psaddrin->sin_addr.S_un.S_addr = INADDR_BROADCAST;
  663. pEnumRespondData->pBuffers[-1].dwBufferSize = sizeof( PrependBuffer.XNetSecEnumResponseDataHeader );
  664. PrependBuffer.EnumResponseDataHeader.bSPCommandByte = XNETSEC_ENUM_RESPONSE_DATA_KIND;
  665. memcpy(&PrependBuffer.XNetSecEnumResponseDataHeader.xnaddr,
  666. &xnaddr,
  667. sizeof(xnaddr));
  668. }
  669. else
  670. {
  671. DPFX(DPFPREP, 0, "Couldn't get XNAddr (type = %u)! Ignoring and trying to send unsecure response.",
  672. dwAddressType);
  673. }
  674. }
  675. #endif // DPNBUILD_XNETSECURITY
  676. #ifdef DPNBUILD_ASYNCSPSENDS
  677. pEndpoint->GetSocketPort()->SendData( (pEnumRespondData->pBuffers - 1),
  678. (pEnumRespondData->dwBufferCount + 1),
  679. pEnumQueryContext->pReturnAddress,
  680. NULL );
  681. #else // ! DPNBUILD_ASYNCSPSENDS
  682. pEndpoint->GetSocketPort()->SendData( (pEnumRespondData->pBuffers - 1),
  683. (pEnumRespondData->dwBufferCount + 1),
  684. pEnumQueryContext->pReturnAddress );
  685. #endif // ! DPNBUILD_ASYNCSPSENDS
  686. // We can only return DPNERR_PENDING or failure, so we need to separately call the completion if
  687. // we want to return DPN_OK.
  688. DPFX(DPFPREP, 5, "Endpoint 0x%p completing command synchronously (result = DPN_OK, user context = 0x%p) to interface 0x%p.",
  689. pEndpoint, pEnumRespondData->pvContext, pSPData->DP8SPCallbackInterface());
  690. hr = IDP8SPCallback_CommandComplete( pSPData->DP8SPCallbackInterface(), // pointer to callbacks
  691. NULL, // command handle
  692. DPN_OK, // return
  693. pEnumRespondData->pvContext // user cookie
  694. );
  695. DPFX(DPFPREP, 5, "Endpoint 0x%p returning from command complete [0x%lx].", pEndpoint, hr);
  696. hr = DPNERR_PENDING;
  697. pEndpoint->DecCommandRef();
  698. pEndpoint = NULL;
  699. Exit:
  700. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  701. return hr;
  702. Failure:
  703. if ( pEndpoint != NULL )
  704. {
  705. pEndpoint->DecCommandRef();
  706. pEndpoint = NULL;
  707. }
  708. goto Exit;
  709. }
  710. //**********************************************************************
  711. //**********************************************************************
  712. /*
  713. *
  714. * DNSP_Connect "connects" to the specified address. This doesn't
  715. * necessarily mean a real (TCP) connection is made. It could
  716. * just be a virtual UDP connection
  717. *
  718. */
  719. //**********************************************************************
  720. #undef DPF_MODNAME
  721. #define DPF_MODNAME "DNSP_Connect"
  722. STDMETHODIMP DNSP_Connect( IDP8ServiceProvider *pThis, SPCONNECTDATA *pConnectData )
  723. {
  724. HRESULT hr;
  725. CEndpoint *pEndpoint;
  726. CCommandData *pCommand;
  727. BOOL fEndpointOpen;
  728. CSPData *pSPData;
  729. #ifndef DPNBUILD_NONATHELP
  730. DWORD dwTraversalMode;
  731. DWORD dwComponentSize;
  732. DWORD dwComponentType;
  733. #endif // ! DPNBUILD_NONATHELP
  734. #ifdef DBG
  735. DWORD dwAllowedFlags;
  736. #endif // DBG
  737. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pConnectData);
  738. DNASSERT( pThis != NULL );
  739. DNASSERT( pConnectData != NULL );
  740. DNASSERT( pConnectData->pAddressHost != NULL );
  741. DNASSERT( pConnectData->pAddressDeviceInfo != NULL );
  742. #ifdef DBG
  743. dwAllowedFlags = DPNSPF_SESSIONDATA;
  744. #ifndef DPNBUILD_NOSPUI
  745. dwAllowedFlags |= DPNSPF_OKTOQUERY;
  746. #endif // ! DPNBUILD_NOSPUI
  747. #ifndef DPNBUILD_ONLYONEADAPTER
  748. dwAllowedFlags |= DPNSPF_ADDITIONALMULTIPLEXADAPTERS;
  749. #endif // ! DPNBUILD_ONLYONEADAPTER
  750. #ifndef DPNBUILD_NOMULTICAST
  751. dwAllowedFlags |= DPNSPF_CONNECT_MULTICAST_SEND | DPNSPF_CONNECT_MULTICAST_RECEIVE;
  752. #endif // ! DPNBUILD_NOMULTICAST
  753. DNASSERT( ( pConnectData->dwFlags & ~( dwAllowedFlags ) ) == 0 );
  754. #ifndef DPNBUILD_NOMULTICAST
  755. DNASSERT( !( ( pConnectData->dwFlags & DPNSPF_CONNECT_MULTICAST_SEND ) && ( pConnectData->dwFlags & DPNSPF_CONNECT_MULTICAST_RECEIVE ) ) );
  756. #endif // ! DPNBUILD_NOMULTICAST
  757. if ( pConnectData->dwFlags & DPNSPF_SESSIONDATA )
  758. {
  759. DNASSERT( pConnectData->pvSessionData != NULL );
  760. DNASSERT( pConnectData->dwSessionDataSize > 0 );
  761. }
  762. #endif // DBG
  763. //
  764. // initialize
  765. //
  766. hr = DPNERR_PENDING;
  767. pEndpoint = NULL;
  768. pCommand = NULL;
  769. fEndpointOpen = FALSE;
  770. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  771. pConnectData->hCommand = NULL;
  772. pConnectData->dwCommandDescriptor = NULL_DESCRIPTOR;
  773. // Trust protocol to call us only in the initialized state
  774. DNASSERT(pSPData->GetState() == SPSTATE_INITIALIZED);
  775. DumpAddress( 8, _T("Connect destination:"), pConnectData->pAddressHost );
  776. DumpAddress( 8, _T("Connecting on device:"), pConnectData->pAddressDeviceInfo );
  777. //
  778. // the user is attempting an operation that relies on the thread pool, lock
  779. // it down to prevent threads from being lost. This also performs other
  780. // first time initialization.
  781. //
  782. hr = pSPData->GetThreadPool()->PreventThreadPoolReduction();
  783. if ( hr != DPN_OK )
  784. {
  785. DPFX(DPFPREP, 0, "Failed to prevent thread pool reduction!" );
  786. goto Failure;
  787. }
  788. //
  789. // create and new endpoint
  790. //
  791. pEndpoint = pSPData->GetNewEndpoint();
  792. if ( pEndpoint == NULL )
  793. {
  794. hr = DPNERR_OUTOFMEMORY;
  795. DPFX(DPFPREP, 0, "Cannot create new endpoint in DNSP_Connect!" );
  796. goto Failure;
  797. }
  798. #ifndef DPNBUILD_NONATHELP
  799. //
  800. // We need to detect up front whether NAT traversal is disabled or not so we can optimize
  801. // the Open call below.
  802. //
  803. dwComponentSize = sizeof(dwTraversalMode);
  804. hr = IDirectPlay8Address_GetComponentByName(pConnectData->pAddressDeviceInfo,
  805. DPNA_KEY_TRAVERSALMODE,
  806. &dwTraversalMode,
  807. &dwComponentSize,
  808. &dwComponentType);
  809. if ( hr == DPN_OK )
  810. {
  811. //
  812. // We found the component. Make sure it's the right size and type.
  813. //
  814. if ((dwComponentSize == sizeof(dwTraversalMode)) && (dwComponentType == DPNA_DATATYPE_DWORD))
  815. {
  816. switch (dwTraversalMode)
  817. {
  818. case DPNA_TRAVERSALMODE_NONE:
  819. {
  820. DPFX(DPFPREP, 1, "Found traversal mode key, value is NONE.");
  821. break;
  822. }
  823. case DPNA_TRAVERSALMODE_PORTREQUIRED:
  824. {
  825. DPFX(DPFPREP, 1, "Found traversal mode key, value is PORTREQUIRED.");
  826. break;
  827. }
  828. case DPNA_TRAVERSALMODE_PORTRECOMMENDED:
  829. {
  830. DPFX(DPFPREP, 1, "Found traversal mode key, value is PORTRECOMMENDED.");
  831. break;
  832. }
  833. default:
  834. {
  835. DPFX(DPFPREP, 0, "Ignoring correctly formed traversal mode key with invalid value %u! Using default mode %u.",
  836. dwTraversalMode, g_dwDefaultTraversalMode);
  837. dwTraversalMode = g_dwDefaultTraversalMode;
  838. break;
  839. }
  840. }
  841. }
  842. else
  843. {
  844. DPFX(DPFPREP, 0, "Traversal mode key exists, but doesn't match expected type (%u != %u) or size (%u != %u)! Using default mode %u.",
  845. dwComponentSize, sizeof(dwTraversalMode),
  846. dwComponentType, DPNA_DATATYPE_DWORD,
  847. g_dwDefaultTraversalMode);
  848. dwTraversalMode = g_dwDefaultTraversalMode;
  849. }
  850. }
  851. else
  852. {
  853. //
  854. // The key is not there, it's the wrong size (too big for our buffer
  855. // and returned BUFFERTOOSMALL), or something else bad happened.
  856. // It doesn't matter. Carry on.
  857. //
  858. DPFX(DPFPREP, 8, "Could not get traversal mode key, error = 0x%lx, component size = %u, type = %u, using default mode %u.",
  859. hr, dwComponentSize, dwComponentType, g_dwDefaultTraversalMode);
  860. dwTraversalMode = g_dwDefaultTraversalMode;
  861. }
  862. if (g_dwDefaultTraversalMode & FORCE_TRAVERSALMODE_BIT)
  863. {
  864. DPFX(DPFPREP, 1, "Forcing traversal mode %u.");
  865. dwTraversalMode = g_dwDefaultTraversalMode & (~FORCE_TRAVERSALMODE_BIT);
  866. }
  867. pEndpoint->SetUserTraversalMode(dwTraversalMode);
  868. #endif // ! DPNBUILD_NONATHELP
  869. //
  870. // get new command and initialize it
  871. //
  872. pCommand = (CCommandData*)g_CommandDataPool.Get();
  873. if ( pCommand == NULL )
  874. {
  875. hr = DPNERR_OUTOFMEMORY;
  876. DPFX(DPFPREP, 0, "Cannot get command handle for DNSP_Connect!" );
  877. goto Failure;
  878. }
  879. DPFX(DPFPREP, 7, "(0x%p) Connect command 0x%p created.",
  880. pSPData, pCommand);
  881. pConnectData->hCommand = pCommand;
  882. pConnectData->dwCommandDescriptor = pCommand->GetDescriptor();
  883. #ifndef DPNBUILD_NOMULTICAST
  884. if ( pConnectData->dwFlags & DPNSPF_CONNECT_MULTICAST_SEND )
  885. {
  886. pCommand->SetType( COMMAND_TYPE_MULTICAST_SEND );
  887. }
  888. else if ( pConnectData->dwFlags & DPNSPF_CONNECT_MULTICAST_RECEIVE )
  889. {
  890. pCommand->SetType( COMMAND_TYPE_MULTICAST_RECEIVE );
  891. }
  892. else
  893. #endif // ! DPNBUILD_NOMULTICAST
  894. {
  895. pCommand->SetType( COMMAND_TYPE_CONNECT );
  896. }
  897. pCommand->SetState( COMMAND_STATE_PENDING );
  898. pCommand->SetEndpoint( pEndpoint );
  899. //
  900. // open endpoint with outgoing address
  901. //
  902. fEndpointOpen = TRUE;
  903. #ifndef DPNBUILD_NOMULTICAST
  904. if ( pConnectData->dwFlags & DPNSPF_CONNECT_MULTICAST_SEND )
  905. {
  906. hr = pEndpoint->Open( ENDPOINT_TYPE_MULTICAST_SEND,
  907. pConnectData->pAddressHost,
  908. ((pConnectData->dwFlags & DPNSPF_SESSIONDATA) ? pConnectData->pvSessionData : NULL),
  909. ((pConnectData->dwFlags & DPNSPF_SESSIONDATA) ? pConnectData->dwSessionDataSize : 0),
  910. NULL );
  911. }
  912. else if ( pConnectData->dwFlags & DPNSPF_CONNECT_MULTICAST_RECEIVE )
  913. {
  914. hr = pEndpoint->Open( ENDPOINT_TYPE_MULTICAST_RECEIVE,
  915. pConnectData->pAddressHost,
  916. ((pConnectData->dwFlags & DPNSPF_SESSIONDATA) ? pConnectData->pvSessionData : NULL),
  917. ((pConnectData->dwFlags & DPNSPF_SESSIONDATA) ? pConnectData->dwSessionDataSize : 0),
  918. NULL );
  919. }
  920. else
  921. #endif // ! DPNBUILD_NOMULTICAST
  922. {
  923. hr = pEndpoint->Open( ENDPOINT_TYPE_CONNECT,
  924. pConnectData->pAddressHost,
  925. ((pConnectData->dwFlags & DPNSPF_SESSIONDATA) ? pConnectData->pvSessionData : NULL),
  926. ((pConnectData->dwFlags & DPNSPF_SESSIONDATA) ? pConnectData->dwSessionDataSize : 0),
  927. NULL );
  928. }
  929. switch ( hr )
  930. {
  931. //
  932. // address conversion was fine, copy connect data and finish connection
  933. // on background thread.
  934. //
  935. case DPN_OK:
  936. {
  937. //
  938. // Copy connection data and submit job to finish off connection.
  939. //
  940. DNASSERT( pSPData != NULL );
  941. hr = pEndpoint->CopyConnectData( pConnectData );
  942. if ( hr != DPN_OK )
  943. {
  944. DPFX(DPFPREP, 0, "Failed to copy connect data before delayed command!" );
  945. DisplayDNError( 0, hr );
  946. goto Failure;
  947. }
  948. //
  949. // Initialize the bind type. It will get changed to DEFAULT or SPECIFIC
  950. //
  951. pEndpoint->SetCommandParametersGatewayBindType(GATEWAY_BIND_TYPE_UNKNOWN);
  952. pEndpoint->AddRef();
  953. #ifdef DPNBUILD_ONLYONEPROCESSOR
  954. hr = pSPData->GetThreadPool()->SubmitDelayedCommand( CEndpoint::ConnectJobCallback,
  955. pEndpoint );
  956. #else // ! DPNBUILD_ONLYONEPROCESSOR
  957. hr = pSPData->GetThreadPool()->SubmitDelayedCommand( -1, // we don't know the CPU yet, so pick any
  958. CEndpoint::ConnectJobCallback,
  959. pEndpoint );
  960. #endif // ! DPNBUILD_ONLYONEPROCESSOR
  961. if ( hr != DPN_OK )
  962. {
  963. pEndpoint->DecRef();
  964. DPFX(DPFPREP, 0, "Failed to set delayed connect!" );
  965. DisplayDNError( 0, hr );
  966. goto Failure;
  967. }
  968. //
  969. // this endpoint has been handed off, remove our reference to it
  970. //
  971. pEndpoint = NULL;
  972. hr = DPNERR_PENDING;
  973. goto Exit;
  974. break;
  975. }
  976. //
  977. // Incomplete address passed in, query user for more information if
  978. // we're allowed. Since we don't have a complete address at this time,
  979. // don't bind this endpoint to the socket port!
  980. //
  981. case DPNERR_INCOMPLETEADDRESS:
  982. {
  983. #ifndef DPNBUILD_NOSPUI
  984. if ( ( pConnectData->dwFlags & DPNSPF_OKTOQUERY ) != 0 )
  985. {
  986. //
  987. // Copy the connect data locally and start the dialog. When the
  988. // dialog completes, the connection will attempt to complete.
  989. // Since a dialog is being displayed, the command is in-progress,
  990. // not pending. However, you can't cancel the dialog once it's
  991. // displayed (the UI would suddenly disappear).
  992. //
  993. pCommand->SetState( COMMAND_STATE_INPROGRESS_CANNOT_CANCEL );
  994. hr = pEndpoint->CopyConnectData( pConnectData );
  995. if ( hr != DPN_OK )
  996. {
  997. DPFX(DPFPREP, 0, "Failed to copy connect data before dialog!" );
  998. DisplayDNError( 0, hr );
  999. goto Failure;
  1000. }
  1001. //
  1002. // Initialize the bind type. It will get changed to DEFAULT or SPECIFIC
  1003. //
  1004. pEndpoint->SetCommandParametersGatewayBindType(GATEWAY_BIND_TYPE_UNKNOWN);
  1005. hr = pEndpoint->ShowSettingsDialog( pSPData->GetThreadPool() );
  1006. if ( hr != DPN_OK )
  1007. {
  1008. DPFX(DPFPREP, 0, "Problem showing settings dialog for connect!" );
  1009. DisplayDNError( 0, hr );
  1010. goto Failure;
  1011. }
  1012. //
  1013. // this endpoint has been handed off, remove our reference to it
  1014. //
  1015. pEndpoint = NULL;
  1016. hr = DPNERR_PENDING;
  1017. goto Exit;
  1018. }
  1019. else
  1020. #endif // !DPNBUILD_NOSPUI
  1021. {
  1022. goto Failure;
  1023. }
  1024. break;
  1025. }
  1026. #ifndef DPNBUILD_ONLYONETHREAD
  1027. //
  1028. // some blocking operation might occur, submit it to be run
  1029. // on a background thread.
  1030. //
  1031. case DPNERR_TIMEDOUT:
  1032. {
  1033. //
  1034. // Copy connect data and submit job to finish off enum.
  1035. //
  1036. DNASSERT( pSPData != NULL );
  1037. hr = pEndpoint->CopyConnectData( pConnectData );
  1038. if ( hr != DPN_OK )
  1039. {
  1040. DPFX(DPFPREP, 0, "Failed to copy connect data before blocking job!" );
  1041. DisplayDNError( 0, hr );
  1042. goto Failure;
  1043. }
  1044. //
  1045. // Initialize the bind type. It will get changed to DEFAULT or SPECIFIC
  1046. //
  1047. pEndpoint->SetCommandParametersGatewayBindType(GATEWAY_BIND_TYPE_UNKNOWN);
  1048. pEndpoint->AddRef();
  1049. hr = pSPData->GetThreadPool()->SubmitBlockingJob( CEndpoint::ConnectBlockingJobWrapper,
  1050. pEndpoint );
  1051. if ( hr != DPN_OK )
  1052. {
  1053. pEndpoint->DecRef();
  1054. DPFX(DPFPREP, 0, "Failed to submit blocking connect job!" );
  1055. DisplayDNError( 0, hr );
  1056. goto Failure;
  1057. }
  1058. //
  1059. // this endpoint has been handed off, remove our reference
  1060. //
  1061. pEndpoint = NULL;
  1062. hr = DPNERR_PENDING;
  1063. goto Exit;
  1064. }
  1065. #endif // ! DPNBUILD_ONLYONETHREAD
  1066. default:
  1067. {
  1068. DPFX(DPFPREP, 0, "Problem initializing endpoint in DNSP_Connect!" );
  1069. DisplayDNError( 0, hr );
  1070. goto Failure;
  1071. break;
  1072. }
  1073. }
  1074. Exit:
  1075. DNASSERT( pEndpoint == NULL );
  1076. if ( hr != DPNERR_PENDING )
  1077. {
  1078. // this command cannot complete synchronously!
  1079. DNASSERT( hr != DPN_OK );
  1080. DPFX(DPFPREP, 0, "Problem with DNSP_Connect()" );
  1081. DisplayDNError( 0, hr );
  1082. }
  1083. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  1084. return hr;
  1085. Failure:
  1086. //
  1087. // if there's an allocated command, clean up and then
  1088. // return the command
  1089. //
  1090. if ( pCommand != NULL )
  1091. {
  1092. pCommand->DecRef();
  1093. pCommand = NULL;
  1094. pConnectData->hCommand = NULL;
  1095. pConnectData->dwCommandDescriptor = NULL_DESCRIPTOR;
  1096. }
  1097. //
  1098. // is there an endpoint to free?
  1099. //
  1100. if ( pEndpoint != NULL )
  1101. {
  1102. if ( fEndpointOpen != FALSE )
  1103. {
  1104. pEndpoint->Close( hr );
  1105. fEndpointOpen = FALSE;
  1106. }
  1107. pSPData->CloseEndpointHandle( pEndpoint );
  1108. pEndpoint = NULL;
  1109. }
  1110. goto Exit;
  1111. }
  1112. //**********************************************************************
  1113. //**********************************************************************
  1114. /*
  1115. *
  1116. * DNSP_Disconnect disconnects an active connection
  1117. *
  1118. */
  1119. //**********************************************************************
  1120. #undef DPF_MODNAME
  1121. #define DPF_MODNAME "DNSP_Disconnect"
  1122. STDMETHODIMP DNSP_Disconnect( IDP8ServiceProvider *pThis, SPDISCONNECTDATA *pDisconnectData )
  1123. {
  1124. HRESULT hr;
  1125. HRESULT hTempResult;
  1126. CEndpoint *pEndpoint;
  1127. CSPData *pSPData;
  1128. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pDisconnectData);
  1129. DNASSERT( pThis != NULL );
  1130. DNASSERT( pDisconnectData != NULL );
  1131. DNASSERT( pDisconnectData->dwFlags == 0 );
  1132. DNASSERT( pDisconnectData->hEndpoint != INVALID_HANDLE_VALUE && pDisconnectData->hEndpoint != 0 );
  1133. DNASSERT( pDisconnectData->dwFlags == 0 );
  1134. //
  1135. // initialize
  1136. //
  1137. hr = DPN_OK;
  1138. pEndpoint = NULL;
  1139. pDisconnectData->hCommand = NULL;
  1140. pDisconnectData->dwCommandDescriptor = NULL_DESCRIPTOR;
  1141. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  1142. //
  1143. // no need to poke at the thread pool here because there was already a connect
  1144. // issued and that connect should have locked down the thread pool.
  1145. //
  1146. // Trust protocol to call us only in the initialized state
  1147. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  1148. //
  1149. // look up the endpoint and if it's found, close its handle
  1150. //
  1151. pEndpoint = pSPData->GetEndpointAndCloseHandle( pDisconnectData->hEndpoint );
  1152. if ( pEndpoint == NULL )
  1153. {
  1154. hr = DPNERR_INVALIDENDPOINT;
  1155. goto Failure;
  1156. }
  1157. hTempResult = pEndpoint->Disconnect();
  1158. switch ( hTempResult )
  1159. {
  1160. //
  1161. // endpoint disconnected immediately
  1162. //
  1163. case DPNERR_PENDING:
  1164. case DPN_OK:
  1165. {
  1166. break;
  1167. }
  1168. //
  1169. // Other return. Since the disconnect didn't complete, we need
  1170. // to unlock the endpoint.
  1171. //
  1172. default:
  1173. {
  1174. DPFX(DPFPREP, 0, "Error reported when attempting to disconnect endpoint in DNSP_Disconnect!" );
  1175. DisplayDNError( 0, hTempResult );
  1176. DNASSERT( FALSE );
  1177. break;
  1178. }
  1179. }
  1180. Exit:
  1181. //
  1182. // remove outstanding reference from GetEndpointHandleAndClose()
  1183. //
  1184. if ( pEndpoint != NULL )
  1185. {
  1186. pEndpoint->DecRef();
  1187. pEndpoint = NULL;
  1188. }
  1189. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  1190. return hr;
  1191. Failure:
  1192. goto Exit;
  1193. }
  1194. //**********************************************************************
  1195. //**********************************************************************
  1196. /*
  1197. *
  1198. * DNSP_Listen "listens" on the specified address/port. This doesn't
  1199. * necessarily mean that a true TCP socket is used. It could just
  1200. * be a UDP port that's opened for receiving packets
  1201. *
  1202. */
  1203. //**********************************************************************
  1204. #undef DPF_MODNAME
  1205. #define DPF_MODNAME "DNSP_Listen"
  1206. STDMETHODIMP DNSP_Listen( IDP8ServiceProvider *pThis, SPLISTENDATA *pListenData)
  1207. {
  1208. HRESULT hr;
  1209. CEndpoint *pEndpoint;
  1210. CCommandData *pCommand;
  1211. IDirectPlay8Address *pDeviceAddress;
  1212. BOOL fEndpointOpen;
  1213. CSPData *pSPData;
  1214. #ifndef DPNBUILD_NONATHELP
  1215. DWORD dwTraversalMode;
  1216. DWORD dwComponentSize;
  1217. DWORD dwComponentType;
  1218. #endif // ! DPNBUILD_NONATHELP
  1219. #ifdef DBG
  1220. DWORD dwAllowedFlags;
  1221. #endif // DBG
  1222. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pListenData);
  1223. DNASSERT( pThis != NULL );
  1224. DNASSERT( pListenData != NULL );
  1225. #ifdef DBG
  1226. dwAllowedFlags = DPNSPF_BINDLISTENTOGATEWAY | DPNSPF_LISTEN_DISALLOWENUMS | DPNSPF_SESSIONDATA;
  1227. #ifndef DPNBUILD_NOSPUI
  1228. dwAllowedFlags |= DPNSPF_OKTOQUERY;
  1229. #endif // ! DPNBUILD_NOSPUI
  1230. #ifndef DPNBUILD_NOMULTICAST
  1231. dwAllowedFlags |= DPNSPF_LISTEN_MULTICAST | DPNSPF_LISTEN_ALLOWUNKNOWNSENDERS;
  1232. #endif // ! DPNBUILD_NOMULTICAST
  1233. DNASSERT( ( pListenData->dwFlags & ~( dwAllowedFlags ) ) == 0 );
  1234. if ( pListenData->dwFlags & DPNSPF_SESSIONDATA )
  1235. {
  1236. DNASSERT( pListenData->pvSessionData!= NULL );
  1237. DNASSERT( pListenData->dwSessionDataSize > 0 );
  1238. }
  1239. #endif // DBG
  1240. //
  1241. // initialize
  1242. //
  1243. hr = DPNERR_PENDING;
  1244. pEndpoint = NULL;
  1245. pCommand = NULL;
  1246. pDeviceAddress = NULL;
  1247. fEndpointOpen = FALSE;
  1248. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  1249. pListenData->hCommand = NULL;
  1250. pListenData->dwCommandDescriptor = NULL_DESCRIPTOR;
  1251. DumpAddress( 8, _T("Listening on device:"), pListenData->pAddressDeviceInfo );
  1252. //
  1253. // the user is attempting an operation that relies on the thread pool, lock
  1254. // it down to prevent threads from being lost. This also performs other
  1255. // first time initialization.
  1256. //
  1257. hr = pSPData->GetThreadPool()->PreventThreadPoolReduction();
  1258. if ( hr != DPN_OK )
  1259. {
  1260. DPFX(DPFPREP, 0, "Failed to prevent thread pool reduction!" );
  1261. goto Failure;
  1262. }
  1263. //
  1264. // AddRef the device address.
  1265. //
  1266. IDirectPlay8Address_AddRef(pListenData->pAddressDeviceInfo);
  1267. pDeviceAddress = pListenData->pAddressDeviceInfo;
  1268. // Trust protocol to call us only in the initialized state
  1269. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  1270. //
  1271. // create and new endpoint
  1272. //
  1273. pEndpoint = pSPData->GetNewEndpoint();
  1274. if ( pEndpoint == NULL )
  1275. {
  1276. hr = DPNERR_OUTOFMEMORY;
  1277. DPFX(DPFPREP, 0, "Cannot create new endpoint in DNSP_Listen!" );
  1278. goto Failure;
  1279. }
  1280. #ifndef DPNBUILD_NONATHELP
  1281. //
  1282. // We need to detect up front whether NAT traversal is disabled or not so we can optimize
  1283. // the Open call below.
  1284. //
  1285. dwComponentSize = sizeof(dwTraversalMode);
  1286. hr = IDirectPlay8Address_GetComponentByName(pListenData->pAddressDeviceInfo,
  1287. DPNA_KEY_TRAVERSALMODE,
  1288. &dwTraversalMode,
  1289. &dwComponentSize,
  1290. &dwComponentType);
  1291. if ( hr == DPN_OK )
  1292. {
  1293. //
  1294. // We found the component. Make sure it's the right size and type.
  1295. //
  1296. if ((dwComponentSize == sizeof(dwTraversalMode)) && (dwComponentType == DPNA_DATATYPE_DWORD))
  1297. {
  1298. switch (dwTraversalMode)
  1299. {
  1300. case DPNA_TRAVERSALMODE_NONE:
  1301. {
  1302. DPFX(DPFPREP, 1, "Found traversal mode key, value is NONE.");
  1303. break;
  1304. }
  1305. case DPNA_TRAVERSALMODE_PORTREQUIRED:
  1306. {
  1307. DPFX(DPFPREP, 1, "Found traversal mode key, value is PORTREQUIRED.");
  1308. break;
  1309. }
  1310. case DPNA_TRAVERSALMODE_PORTRECOMMENDED:
  1311. {
  1312. DPFX(DPFPREP, 1, "Found traversal mode key, value is PORTRECOMMENDED.");
  1313. break;
  1314. }
  1315. default:
  1316. {
  1317. DPFX(DPFPREP, 0, "Ignoring correctly formed traversal mode key with invalid value %u! Using PORTRECOMMENDED.",
  1318. dwTraversalMode);
  1319. dwTraversalMode = g_dwDefaultTraversalMode;
  1320. break;
  1321. }
  1322. }
  1323. }
  1324. else
  1325. {
  1326. DPFX(DPFPREP, 0, "Traversal mode key exists, but doesn't match expected type (%u != %u) or size (%u != %u)! Using default mode %u.",
  1327. dwComponentSize, sizeof(dwTraversalMode),
  1328. dwComponentType, DPNA_DATATYPE_DWORD,
  1329. g_dwDefaultTraversalMode);
  1330. dwTraversalMode = g_dwDefaultTraversalMode;
  1331. }
  1332. }
  1333. else
  1334. {
  1335. //
  1336. // The key is not there, it's the wrong size (too big for our buffer
  1337. // and returned BUFFERTOOSMALL), or something else bad happened.
  1338. // It doesn't matter. Carry on.
  1339. //
  1340. DPFX(DPFPREP, 8, "Could not get traversal mode key, error = 0x%lx, component size = %u, type = %u, using default mode %u.",
  1341. hr, dwComponentSize, dwComponentType, g_dwDefaultTraversalMode);
  1342. dwTraversalMode = g_dwDefaultTraversalMode;
  1343. }
  1344. if (g_dwDefaultTraversalMode & FORCE_TRAVERSALMODE_BIT)
  1345. {
  1346. DPFX(DPFPREP, 1, "Forcing traversal mode %u.");
  1347. dwTraversalMode = g_dwDefaultTraversalMode & (~FORCE_TRAVERSALMODE_BIT);
  1348. }
  1349. pEndpoint->SetUserTraversalMode(dwTraversalMode);
  1350. #endif // ! DPNBUILD_NONATHELP
  1351. //
  1352. // get new command and initialize it
  1353. //
  1354. pCommand = (CCommandData*)g_CommandDataPool.Get();
  1355. if ( pCommand == NULL )
  1356. {
  1357. hr = DPNERR_OUTOFMEMORY;
  1358. DPFX(DPFPREP, 0, "Cannot get command handle for DNSP_Listen!" );
  1359. goto Failure;
  1360. }
  1361. DPFX(DPFPREP, 7, "(0x%p) Listen command 0x%p created.",
  1362. pSPData, pCommand);
  1363. pListenData->hCommand = pCommand;
  1364. pListenData->dwCommandDescriptor = pCommand->GetDescriptor();
  1365. #ifndef DPNBUILD_NOMULTICAST
  1366. if (pListenData->dwFlags & DPNSPF_LISTEN_MULTICAST)
  1367. {
  1368. pCommand->SetType( COMMAND_TYPE_MULTICAST_LISTEN );
  1369. }
  1370. else
  1371. #endif // ! DPNBUILD_NOMULTICAST
  1372. {
  1373. pCommand->SetType( COMMAND_TYPE_LISTEN );
  1374. }
  1375. pCommand->SetState( COMMAND_STATE_PENDING );
  1376. pCommand->SetEndpoint( pEndpoint );
  1377. pCommand->SetUserContext( pListenData->pvContext );
  1378. //
  1379. // open endpoint with outgoing address
  1380. //
  1381. fEndpointOpen = TRUE;
  1382. #ifndef DPNBUILD_NOMULTICAST
  1383. if (pListenData->dwFlags & DPNSPF_LISTEN_MULTICAST)
  1384. {
  1385. //
  1386. // The device address should also contain the multicast address to be joined.
  1387. //
  1388. hr = pEndpoint->Open( ENDPOINT_TYPE_MULTICAST_LISTEN,
  1389. pDeviceAddress,
  1390. ((pListenData->dwFlags & DPNSPF_SESSIONDATA) ? pListenData->pvSessionData : NULL),
  1391. ((pListenData->dwFlags & DPNSPF_SESSIONDATA) ? pListenData->dwSessionDataSize : 0),
  1392. NULL );
  1393. }
  1394. else
  1395. #endif // ! DPNBUILD_NOMULTICAST
  1396. {
  1397. hr = pEndpoint->Open( ENDPOINT_TYPE_LISTEN,
  1398. NULL,
  1399. ((pListenData->dwFlags & DPNSPF_SESSIONDATA) ? pListenData->pvSessionData : NULL),
  1400. ((pListenData->dwFlags & DPNSPF_SESSIONDATA) ? pListenData->dwSessionDataSize : 0),
  1401. NULL );
  1402. }
  1403. switch ( hr )
  1404. {
  1405. //
  1406. // address conversion was fine, copy connect data and finish connection
  1407. // on background thread.
  1408. //
  1409. case DPN_OK:
  1410. {
  1411. //
  1412. // Copy listen data and submit job to finish off listen.
  1413. //
  1414. DNASSERT( pSPData != NULL );
  1415. hr = pEndpoint->CopyListenData( pListenData, pDeviceAddress );
  1416. if ( hr != DPN_OK )
  1417. {
  1418. DPFX(DPFPREP, 0, "Failed to copy listen data before delayed command!" );
  1419. DisplayDNError( 0, hr );
  1420. goto Failure;
  1421. }
  1422. //
  1423. // Initialize the bind type.
  1424. //
  1425. if ((pListenData->dwFlags & DPNSPF_BINDLISTENTOGATEWAY))
  1426. {
  1427. //
  1428. // This must always stay SPECIFIC_SHARED.
  1429. //
  1430. pEndpoint->SetCommandParametersGatewayBindType(GATEWAY_BIND_TYPE_SPECIFIC_SHARED);
  1431. }
  1432. else
  1433. {
  1434. //
  1435. // This will get changed to DEFAULT or SPECIFIC.
  1436. //
  1437. pEndpoint->SetCommandParametersGatewayBindType(GATEWAY_BIND_TYPE_UNKNOWN);
  1438. }
  1439. pEndpoint->AddRef();
  1440. #ifdef DPNBUILD_ONLYONEPROCESSOR
  1441. hr = pSPData->GetThreadPool()->SubmitDelayedCommand( CEndpoint::ListenJobCallback,
  1442. pEndpoint );
  1443. #else // ! DPNBUILD_ONLYONEPROCESSOR
  1444. hr = pSPData->GetThreadPool()->SubmitDelayedCommand( -1, // we don't know the CPU yet, so pick any
  1445. CEndpoint::ListenJobCallback,
  1446. pEndpoint );
  1447. #endif // ! DPNBUILD_ONLYONEPROCESSOR
  1448. if ( hr != DPN_OK )
  1449. {
  1450. pEndpoint->DecRef();
  1451. DPFX(DPFPREP, 0, "Failed to set delayed listen!" );
  1452. DisplayDNError( 0, hr );
  1453. goto Failure;
  1454. }
  1455. //
  1456. // this endpoint has been handed off, remove our reference to it
  1457. //
  1458. pEndpoint = NULL;
  1459. hr = DPNERR_PENDING;
  1460. break;
  1461. }
  1462. //
  1463. // Incomplete address passed in, query user for more information if
  1464. // we're allowed. Since we don't have a complete address at this time,
  1465. // don't bind this endpoint to the socket port!
  1466. //
  1467. case DPNERR_INCOMPLETEADDRESS:
  1468. {
  1469. //
  1470. // This SP will never encounter the case where there's not enough
  1471. // information to start listening. Either the adapter GUID is there
  1472. // or not, and we won't know until CEndpoint::CompleteListen.
  1473. //
  1474. DNASSERT( FALSE );
  1475. #ifndef DPNBUILD_NOSPUI
  1476. if ( ( pListenData->dwFlags & DPNSPF_OKTOQUERY ) != 0 )
  1477. {
  1478. //
  1479. // Copy the listen data locally and start the dialog. When the
  1480. // dialog completes, the connection will attempt to complete.
  1481. // Since this endpoint is being handed off to another thread,
  1482. // make sure it's in the unbound list. Since a dialog is being
  1483. // displayed, the command state is in progress, not pending.
  1484. //
  1485. DNASSERT( pSPData != NULL );
  1486. hr = pEndpoint->CopyListenData( pListenData, pDeviceAddress );
  1487. if ( hr != DPN_OK )
  1488. {
  1489. DPFX(DPFPREP, 0, "Failed to copy listen data before dialog!" );
  1490. DisplayDNError( 0, hr );
  1491. goto Failure;
  1492. }
  1493. //
  1494. // Initialize the bind type.
  1495. //
  1496. if ((pListenData->dwFlags & DPNSPF_BINDLISTENTOGATEWAY))
  1497. {
  1498. //
  1499. // This must always stay SPECIFIC_SHARED.
  1500. //
  1501. pEndpoint->SetCommandParametersGatewayBindType(GATEWAY_BIND_TYPE_SPECIFIC_SHARED);
  1502. }
  1503. else
  1504. {
  1505. //
  1506. // This will get changed to DEFAULT or SPECIFIC.
  1507. //
  1508. pEndpoint->SetCommandParametersGatewayBindType(GATEWAY_BIND_TYPE_UNKNOWN);
  1509. }
  1510. pCommand->SetState( COMMAND_STATE_INPROGRESS );
  1511. hr = pEndpoint->ShowSettingsDialog( pSPData->GetThreadPool() );
  1512. if ( hr != DPN_OK )
  1513. {
  1514. DPFX(DPFPREP, 0, "Problem showing settings dialog for listen!" );
  1515. DisplayDNError( 0, hr );
  1516. goto Failure;
  1517. }
  1518. //
  1519. // this endpoint has been handed off, remove our reference to it
  1520. //
  1521. pEndpoint = NULL;
  1522. hr = DPNERR_PENDING;
  1523. goto Exit;
  1524. }
  1525. else
  1526. #endif // !DPNBUILD_NOSPUI
  1527. {
  1528. goto Failure;
  1529. }
  1530. break;
  1531. }
  1532. #ifndef DPNBUILD_ONLYONETHREAD
  1533. //
  1534. // some blocking operation might occur, submit it to be run
  1535. // on a background thread.
  1536. //
  1537. case DPNERR_TIMEDOUT:
  1538. {
  1539. //
  1540. // Copy listen data and submit job to finish off enum.
  1541. //
  1542. DNASSERT( pSPData != NULL );
  1543. hr = pEndpoint->CopyListenData( pListenData, pDeviceAddress );
  1544. if ( hr != DPN_OK )
  1545. {
  1546. DPFX(DPFPREP, 0, "Failed to copy listen data before blocking job!" );
  1547. DisplayDNError( 0, hr );
  1548. goto Failure;
  1549. }
  1550. //
  1551. // Initialize the bind type.
  1552. //
  1553. if ((pListenData->dwFlags & DPNSPF_BINDLISTENTOGATEWAY))
  1554. {
  1555. //
  1556. // This must always stay SPECIFIC_SHARED.
  1557. //
  1558. pEndpoint->SetCommandParametersGatewayBindType(GATEWAY_BIND_TYPE_SPECIFIC_SHARED);
  1559. }
  1560. else
  1561. {
  1562. //
  1563. // This will get changed to DEFAULT or SPECIFIC.
  1564. //
  1565. pEndpoint->SetCommandParametersGatewayBindType(GATEWAY_BIND_TYPE_UNKNOWN);
  1566. }
  1567. pEndpoint->AddRef();
  1568. hr = pSPData->GetThreadPool()->SubmitBlockingJob( CEndpoint::ListenBlockingJobWrapper,
  1569. pEndpoint );
  1570. if ( hr != DPN_OK )
  1571. {
  1572. pEndpoint->DecRef();
  1573. DPFX(DPFPREP, 0, "Failed to submit blocking listen job!" );
  1574. DisplayDNError( 0, hr );
  1575. goto Failure;
  1576. }
  1577. //
  1578. // this endpoint has been handed off, remove our reference
  1579. //
  1580. pEndpoint = NULL;
  1581. hr = DPNERR_PENDING;
  1582. goto Exit;
  1583. }
  1584. #endif // ! DPNBUILD_ONLYONETHREAD
  1585. default:
  1586. {
  1587. DPFX(DPFPREP, 0, "Problem initializing endpoint in DNSP_Listen!" );
  1588. DisplayDNError( 0, hr );
  1589. goto Failure;
  1590. break;
  1591. }
  1592. }
  1593. Exit:
  1594. if ( pDeviceAddress != NULL )
  1595. {
  1596. IDirectPlay8Address_Release( pDeviceAddress );
  1597. pDeviceAddress = NULL;
  1598. }
  1599. DNASSERT( pEndpoint == NULL );
  1600. if ( hr != DPNERR_PENDING )
  1601. {
  1602. // this command cannot complete synchronously!
  1603. DNASSERT( hr != DPN_OK );
  1604. DPFX(DPFPREP, 0, "Problem with DNSP_Listen()" );
  1605. DisplayDNError( 0, hr );
  1606. }
  1607. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  1608. return hr;
  1609. Failure:
  1610. //
  1611. // if there's an allocated command, clean up and then
  1612. // return the command
  1613. //
  1614. if ( pCommand != NULL )
  1615. {
  1616. pCommand->DecRef();
  1617. pCommand = NULL;
  1618. pListenData->hCommand = NULL;
  1619. pListenData->dwCommandDescriptor = NULL_DESCRIPTOR;
  1620. }
  1621. //
  1622. // is there an endpoint to free?
  1623. //
  1624. if ( pEndpoint != NULL )
  1625. {
  1626. if ( fEndpointOpen != FALSE )
  1627. {
  1628. pEndpoint->Close( hr );
  1629. fEndpointOpen = FALSE;
  1630. }
  1631. pSPData->CloseEndpointHandle( pEndpoint );
  1632. pEndpoint = NULL;
  1633. }
  1634. goto Exit;
  1635. }
  1636. //**********************************************************************
  1637. //**********************************************************************
  1638. /*
  1639. *
  1640. * DNSP_SendData sends data to the specified "player"
  1641. *
  1642. * This call MUST BE HIGHLY OPTIMIZED
  1643. *
  1644. */
  1645. //**********************************************************************
  1646. #undef DPF_MODNAME
  1647. #define DPF_MODNAME "DNSP_SendData"
  1648. STDMETHODIMP DNSP_SendData( IDP8ServiceProvider *pThis, SPSENDDATA *pSendData )
  1649. {
  1650. HRESULT hr;
  1651. CEndpoint *pEndpoint;
  1652. CSPData *pSPData;
  1653. #ifdef DPNBUILD_ASYNCSPSENDS
  1654. CCommandData * pCommand = NULL;
  1655. OVERLAPPED * pOverlapped;
  1656. #endif // DPNBUILD_ASYNCSPSENDS
  1657. #ifdef DBG
  1658. DWORD dwTotalBufferSize;
  1659. DWORD dwTemp;
  1660. #endif // DBG
  1661. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pSendData);
  1662. DNASSERT( pThis != NULL );
  1663. DNASSERT( pSendData != NULL );
  1664. DNASSERT( pSendData->pBuffers != NULL );
  1665. DNASSERT( pSendData->dwBufferCount != 0 );
  1666. DNASSERT( pSendData->hEndpoint != INVALID_HANDLE_VALUE && pSendData->hEndpoint != 0 );
  1667. DNASSERT( pSendData->dwFlags == 0 );
  1668. //
  1669. // initialize
  1670. //
  1671. pEndpoint = NULL;
  1672. pSendData->hCommand = NULL;
  1673. pSendData->dwCommandDescriptor = NULL_DESCRIPTOR;
  1674. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  1675. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  1676. //
  1677. // No need to lock down the thread counts here because the user already has
  1678. // a connect or something running or they wouldn't be calling this function.
  1679. // That outstanding connect would have locked down the thread pool.
  1680. //
  1681. //
  1682. // Attempt to grab the endpoint from the handle. If this succeeds, the
  1683. // endpoint can send.
  1684. //
  1685. pEndpoint = pSPData->EndpointFromHandle( pSendData->hEndpoint );
  1686. if ( pEndpoint == NULL )
  1687. {
  1688. hr = DPNERR_INVALIDHANDLE;
  1689. DPFX(DPFPREP, 0, "Invalid endpoint handle on send!" );
  1690. goto Failure;
  1691. }
  1692. #ifdef DBG
  1693. //
  1694. // Make sure message is not too large.
  1695. //
  1696. dwTotalBufferSize = 0;
  1697. for(dwTemp = 0; dwTemp < pSendData->dwBufferCount; dwTemp++)
  1698. {
  1699. dwTotalBufferSize += pSendData->pBuffers[dwTemp].dwBufferSize;
  1700. }
  1701. #pragma TODO(vanceo, "No direct way for application to retrieve, they think max is g_dwMaxEnumDataSize")
  1702. #ifdef DPNBUILD_NOREGISTRY
  1703. DNASSERT(dwTotalBufferSize <= DEFAULT_MAX_USER_DATA_SIZE);
  1704. #else // ! DPNBUILD_NOREGISTRY
  1705. DNASSERT(dwTotalBufferSize <= g_dwMaxUserDataSize);
  1706. #endif // ! DPNBUILD_NOREGISTRY
  1707. // Protocol guarantees that the first byte will never be zero
  1708. DNASSERT(pSendData->pBuffers[ 0 ].pBufferData[ 0 ] != SP_HEADER_LEAD_BYTE);
  1709. #endif // DBG
  1710. //
  1711. // Assume user data. There's no need to prepend a buffer because the
  1712. // receiving machine will realize that it's not a 'special' message and
  1713. // will default the contents to 'user data'.
  1714. //
  1715. #ifdef DPNBUILD_ASYNCSPSENDS
  1716. #ifdef DPNBUILD_NOWINSOCK2
  1717. This won't compile because we need the Winsock2 API to perform overlapped sends
  1718. #endif // DPNBUILD_NOWINSOCK2
  1719. #ifndef DPNBUILD_ONLYWINSOCK2
  1720. DNASSERT(pEndpoint->GetSocketPort() != NULL);
  1721. DNASSERT(pEndpoint->GetSocketPort()->GetNetworkAddress() != NULL);
  1722. if ( ( LOWORD( GetWinsockVersion() ) < 2 )
  1723. #ifndef DPNBUILD_NOIPX
  1724. || ( pEndpoint->GetSocketPort()->GetNetworkAddress()->GetFamily() != AF_INET )
  1725. #endif // ! DPNBUILD_NOIPX
  1726. )
  1727. {
  1728. //
  1729. // We can't perform overlapped sends on Winsock < 2 or on 9x IPX.
  1730. //
  1731. pEndpoint->GetSocketPort()->SendData( pSendData->pBuffers,
  1732. pSendData->dwBufferCount,
  1733. pEndpoint->GetRemoteAddressPointer(),
  1734. NULL );
  1735. hr = DPN_OK;
  1736. pEndpoint->DecCommandRef();
  1737. }
  1738. else
  1739. #endif // ! DPNBUILD_ONLYWINSOCK2
  1740. {
  1741. //
  1742. // get new command and initialize it
  1743. //
  1744. pCommand = (CCommandData*)g_CommandDataPool.Get();
  1745. if ( pCommand == NULL )
  1746. {
  1747. hr = DPNERR_OUTOFMEMORY;
  1748. DPFX(DPFPREP, 0, "Cannot get command handle!" );
  1749. goto Failure;
  1750. }
  1751. DPFX(DPFPREP, 8, "(0x%p) Send command 0x%p created.",
  1752. pSPData, pCommand);
  1753. pSendData->hCommand = pCommand;
  1754. pSendData->dwCommandDescriptor = pCommand->GetDescriptor();
  1755. pCommand->SetType( COMMAND_TYPE_SEND );
  1756. pCommand->SetState( COMMAND_STATE_INPROGRESS_CANNOT_CANCEL ); // can't cancel async sends
  1757. pCommand->SetEndpoint( pEndpoint );
  1758. pCommand->SetUserContext( pSendData->pvContext );
  1759. #ifdef DPNBUILD_ONLYONEPROCESSOR
  1760. hr = IDirectPlay8ThreadPoolWork_CreateOverlapped(pSPData->GetThreadPool()->GetDPThreadPoolWork(),
  1761. -1,
  1762. CEndpoint::CompleteAsyncSend,
  1763. pCommand,
  1764. &pOverlapped,
  1765. 0);
  1766. #else // ! DPNBUILD_ONLYONEPROCESSOR
  1767. hr = IDirectPlay8ThreadPoolWork_CreateOverlapped(pSPData->GetThreadPool()->GetDPThreadPoolWork(),
  1768. pEndpoint->GetSocketPort()->GetCPU(),
  1769. CEndpoint::CompleteAsyncSend,
  1770. pCommand,
  1771. &pOverlapped,
  1772. 0);
  1773. #endif // ! DPNBUILD_ONLYONEPROCESSOR
  1774. if (hr != DPN_OK)
  1775. {
  1776. DPFX(DPFPREP, 0, "Couldn't create overlapped structure!");
  1777. goto Failure;
  1778. }
  1779. pEndpoint->GetSocketPort()->SendData( pSendData->pBuffers,
  1780. pSendData->dwBufferCount,
  1781. pEndpoint->GetRemoteAddressPointer(),
  1782. pOverlapped );
  1783. //
  1784. // Whether the submission to Winsock succeeds or fails, it should still
  1785. // fill out the overlapped structure, so we will just let the async
  1786. // completion handler do everything.
  1787. //
  1788. hr = IDirectPlay8ThreadPoolWork_SubmitIoOperation(pSPData->GetThreadPool()->GetDPThreadPoolWork(),
  1789. pOverlapped,
  1790. 0);
  1791. DNASSERT(hr == DPN_OK);
  1792. //
  1793. // Keep endpoint's command ref on send until send completes.
  1794. //
  1795. hr = DPNSUCCESS_PENDING;
  1796. }
  1797. #else // ! DPNBUILD_ASYNCSPSENDS
  1798. pEndpoint->GetSocketPort()->SendData( pSendData->pBuffers,
  1799. pSendData->dwBufferCount,
  1800. pEndpoint->GetRemoteAddressPointer() );
  1801. hr = DPN_OK;
  1802. pEndpoint->DecCommandRef();
  1803. #endif // ! DPNBUILD_ASYNCSPSENDS
  1804. pEndpoint = NULL;
  1805. Exit:
  1806. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  1807. return hr;
  1808. Failure:
  1809. #ifdef DPNBUILD_ASYNCSPSENDS
  1810. //
  1811. // if there's an allocated command, clean up and then
  1812. // return the command
  1813. //
  1814. if ( pCommand != NULL )
  1815. {
  1816. pCommand->DecRef();
  1817. pCommand = NULL;
  1818. pSendData->hCommand = NULL;
  1819. pSendData->dwCommandDescriptor = NULL_DESCRIPTOR;
  1820. }
  1821. #endif // DPNBUILD_ASYNCSPSENDS
  1822. if ( pEndpoint != NULL )
  1823. {
  1824. pEndpoint->DecCommandRef();
  1825. pEndpoint = NULL;
  1826. }
  1827. goto Exit;
  1828. }
  1829. //**********************************************************************
  1830. //**********************************************************************
  1831. /*
  1832. *
  1833. * DNSP_CancelCommand cancels a command in progress
  1834. *
  1835. */
  1836. //**********************************************************************
  1837. #undef DPF_MODNAME
  1838. #define DPF_MODNAME "DNSP_CancelCommand"
  1839. STDMETHODIMP DNSP_CancelCommand( IDP8ServiceProvider *pThis, HANDLE hCommand, DWORD dwCommandDescriptor )
  1840. {
  1841. HRESULT hr;
  1842. CCommandData *pCommandData;
  1843. BOOL fCommandLocked;
  1844. CSPData *pSPData;
  1845. CEndpoint *pEndpoint;
  1846. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p, %ld)", pThis, hCommand, dwCommandDescriptor);
  1847. DNASSERT( pThis != NULL );
  1848. DNASSERT( hCommand != NULL );
  1849. DNASSERT( dwCommandDescriptor != NULL_DESCRIPTOR );
  1850. //
  1851. // initialize
  1852. //
  1853. hr = DPN_OK;
  1854. fCommandLocked = FALSE;
  1855. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  1856. //
  1857. // No need to lock the thread pool counts because there's already some outstanding
  1858. // enum, connect or listen running that has done so.
  1859. //
  1860. // Trust protocol to call us only in the initialized state
  1861. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  1862. pCommandData = static_cast<CCommandData*>( hCommand );
  1863. pCommandData->Lock();
  1864. fCommandLocked = TRUE;
  1865. //
  1866. // make sure the right command is being cancelled
  1867. //
  1868. if ( dwCommandDescriptor != pCommandData->GetDescriptor() )
  1869. {
  1870. hr = DPNERR_INVALIDCOMMAND;
  1871. DPFX(DPFPREP, 0, "Attempt to cancel command (0x%p) with mismatched command descriptor (%u != %u)!",
  1872. hCommand, dwCommandDescriptor, pCommandData->GetDescriptor() );
  1873. goto Exit;
  1874. }
  1875. switch ( pCommandData->GetState() )
  1876. {
  1877. //
  1878. // unknown command state
  1879. //
  1880. case COMMAND_STATE_UNKNOWN:
  1881. {
  1882. hr = DPNERR_INVALIDCOMMAND;
  1883. DNASSERT( FALSE );
  1884. break;
  1885. }
  1886. //
  1887. // command is waiting to be processed, set command state to be cancelling
  1888. // and wait for someone to pick it up
  1889. //
  1890. case COMMAND_STATE_PENDING:
  1891. {
  1892. DPFX(DPFPREP, 5, "Marking command 0x%p as cancelling.", pCommandData);
  1893. pCommandData->SetState( COMMAND_STATE_CANCELLING );
  1894. break;
  1895. }
  1896. //
  1897. // command in progress, and can't be cancelled
  1898. //
  1899. case COMMAND_STATE_INPROGRESS_CANNOT_CANCEL:
  1900. {
  1901. DPFX(DPFPREP, 1, "Cannot cancel command 0x%p.", pCommandData);
  1902. hr = DPNERR_CANNOTCANCEL;
  1903. break;
  1904. }
  1905. //
  1906. // Command is already being cancelled. This is not a problem, but shouldn't
  1907. // be happening for any endpoints other than connects.
  1908. //
  1909. case COMMAND_STATE_CANCELLING:
  1910. {
  1911. DPFX(DPFPREP, 1, "Cancelled already cancelling command 0x%p.", pCommandData);
  1912. DNASSERT( pCommandData->GetEndpoint()->GetType() == ENDPOINT_TYPE_CONNECT );
  1913. DNASSERT( hr == DPN_OK );
  1914. break;
  1915. }
  1916. #ifndef DPNBUILD_ONLYONETHREAD
  1917. //
  1918. // A blocking operation is already failing, let it complete.
  1919. //
  1920. case COMMAND_STATE_FAILING:
  1921. {
  1922. DPFX(DPFPREP, 1, "Cancelled already failing command 0x%p.", pCommandData);
  1923. DNASSERT( hr == DPN_OK );
  1924. break;
  1925. }
  1926. #endif // ! DPNBUILD_ONLYONETHREAD
  1927. //
  1928. // command is in progress, find out what type of command it is
  1929. //
  1930. case COMMAND_STATE_INPROGRESS:
  1931. {
  1932. switch ( pCommandData->GetType() )
  1933. {
  1934. case COMMAND_TYPE_CONNECT:
  1935. case COMMAND_TYPE_LISTEN:
  1936. #ifndef DPNBUILD_NOMULTICAST
  1937. case COMMAND_TYPE_MULTICAST_LISTEN:
  1938. case COMMAND_TYPE_MULTICAST_SEND:
  1939. case COMMAND_TYPE_MULTICAST_RECEIVE:
  1940. #endif // ! DPNBUILD_NOMULTICAST
  1941. {
  1942. //
  1943. // Set this command to the cancel state before we shut down
  1944. // this endpoint. Make sure a reference is added to the
  1945. // endpoint so it stays around for the cancel.
  1946. //
  1947. pCommandData->SetState( COMMAND_STATE_CANCELLING );
  1948. pEndpoint = pCommandData->GetEndpoint();
  1949. pEndpoint->AddRef();
  1950. DPFX(DPFPREP, 3, "Cancelling connect/listen/multicast command 0x%p (endpoint 0x%p).",
  1951. pCommandData, pEndpoint);
  1952. pCommandData->Unlock();
  1953. fCommandLocked = FALSE;
  1954. pEndpoint->Lock();
  1955. switch ( pEndpoint->GetState() )
  1956. {
  1957. //
  1958. // endpoint is already disconnecting, no action needs to be taken
  1959. //
  1960. case ENDPOINT_STATE_DISCONNECTING:
  1961. {
  1962. DPFX(DPFPREP, 7, "Endpoint 0x%p already marked as disconnecting.",
  1963. pEndpoint);
  1964. pEndpoint->Unlock();
  1965. pEndpoint->DecRef();
  1966. goto Exit;
  1967. break;
  1968. }
  1969. //
  1970. // Endpoint is connecting. Flag it as disconnecting and
  1971. // add a reference so it doesn't disappear on us.
  1972. //
  1973. case ENDPOINT_STATE_ATTEMPTING_CONNECT:
  1974. {
  1975. DPFX(DPFPREP, 7, "Endpoint 0x%p attempting to connect, marking as disconnecting.",
  1976. pEndpoint);
  1977. #ifdef DPNBUILD_NOMULTICAST
  1978. DNASSERT(pEndpoint->GetType() == ENDPOINT_TYPE_CONNECT);
  1979. #else // ! DPNBUILD_NOMULTICAST
  1980. DNASSERT((pEndpoint->GetType() == ENDPOINT_TYPE_CONNECT) || (pEndpoint->GetType() == ENDPOINT_TYPE_MULTICAST_SEND) || (pEndpoint->GetType() == ENDPOINT_TYPE_MULTICAST_RECEIVE));
  1981. #endif // ! DPNBUILD_NOMULTICAST
  1982. pEndpoint->SetState( ENDPOINT_STATE_DISCONNECTING );
  1983. break;
  1984. }
  1985. //
  1986. // Endpoint has finished connecting. Report that the
  1987. // command is uncancellable. Sorry Charlie, we missed
  1988. // the window.
  1989. //
  1990. case ENDPOINT_STATE_CONNECT_CONNECTED:
  1991. {
  1992. #ifdef DPNBUILD_NOMULTICAST
  1993. DNASSERT(pEndpoint->GetType() == ENDPOINT_TYPE_CONNECT);
  1994. #else // ! DPNBUILD_NOMULTICAST
  1995. DNASSERT((pEndpoint->GetType() == ENDPOINT_TYPE_CONNECT) || (pEndpoint->GetType() == ENDPOINT_TYPE_MULTICAST_SEND) || (pEndpoint->GetType() == ENDPOINT_TYPE_MULTICAST_RECEIVE));
  1996. #endif // ! DPNBUILD_NOMULTICAST
  1997. DPFX(DPFPREP, 1, "Cannot cancel connect command 0x%p (endpoint 0x%p) that's already (or is about to) complete.",
  1998. pCommandData, pEndpoint);
  1999. pEndpoint->Unlock();
  2000. pEndpoint->DecRef();
  2001. hr = DPNERR_CANNOTCANCEL;
  2002. goto Exit;
  2003. break;
  2004. }
  2005. //
  2006. // Endpoint is listening. Flag it as disconnecting and
  2007. // add a reference so it doesn't disappear on us
  2008. //
  2009. case ENDPOINT_STATE_LISTEN:
  2010. {
  2011. DPFX(DPFPREP, 7, "Endpoint 0x%p listening, marking as disconnecting.",
  2012. pEndpoint);
  2013. #ifdef DPNBUILD_NOMULTICAST
  2014. DNASSERT(pEndpoint->GetType() == ENDPOINT_TYPE_LISTEN);
  2015. #else // ! DPNBUILD_NOMULTICAST
  2016. DNASSERT((pEndpoint->GetType() == ENDPOINT_TYPE_LISTEN) || (pEndpoint->GetType() == ENDPOINT_TYPE_MULTICAST_LISTEN));
  2017. #endif // ! DPNBUILD_NOMULTICAST
  2018. pEndpoint->SetState( ENDPOINT_STATE_DISCONNECTING );
  2019. break;
  2020. }
  2021. //
  2022. // other state
  2023. //
  2024. default:
  2025. {
  2026. DNASSERT( FALSE );
  2027. break;
  2028. }
  2029. }
  2030. pEndpoint->Unlock();
  2031. pEndpoint->Close( DPNERR_USERCANCEL );
  2032. pSPData->CloseEndpointHandle( pEndpoint );
  2033. pEndpoint->DecRef();
  2034. break;
  2035. }
  2036. case COMMAND_TYPE_ENUM_QUERY:
  2037. {
  2038. pEndpoint = pCommandData->GetEndpoint();
  2039. DNASSERT( pEndpoint != NULL );
  2040. DPFX(DPFPREP, 3, "Cancelling enum query command 0x%p (endpoint 0x%p).",
  2041. pCommandData, pEndpoint);
  2042. pEndpoint->AddRef();
  2043. pCommandData->SetState( COMMAND_STATE_CANCELLING );
  2044. pCommandData->Unlock();
  2045. fCommandLocked = FALSE;
  2046. pEndpoint->StopEnumCommand( DPNERR_USERCANCEL );
  2047. pEndpoint->DecRef();
  2048. break;
  2049. }
  2050. default:
  2051. {
  2052. DNASSERT( FALSE );
  2053. break;
  2054. }
  2055. }
  2056. break;
  2057. }
  2058. //
  2059. // other command state
  2060. //
  2061. default:
  2062. {
  2063. DNASSERT( FALSE );
  2064. break;
  2065. }
  2066. }
  2067. Exit:
  2068. if ( fCommandLocked != FALSE )
  2069. {
  2070. DNASSERT( pCommandData != NULL );
  2071. pCommandData->Unlock();
  2072. fCommandLocked = FALSE;
  2073. }
  2074. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  2075. return hr;
  2076. }
  2077. //**********************************************************************
  2078. //**********************************************************************
  2079. // ------------------------------
  2080. // DNSP_GetCaps - get SP capabilities
  2081. //
  2082. // Entry: Pointer to DNSP interface
  2083. // Pointer to caps data
  2084. //
  2085. // Exit: Error code
  2086. // ------------------------------
  2087. #undef DPF_MODNAME
  2088. #define DPF_MODNAME "DNSP_GetCaps"
  2089. STDMETHODIMP DNSP_GetCaps( IDP8ServiceProvider *pThis, SPGETCAPSDATA *pCapsData )
  2090. {
  2091. HRESULT hr;
  2092. CSPData *pSPData;
  2093. #ifndef DPNBUILD_ONLYONETHREAD
  2094. LONG iIOThreadCount;
  2095. #endif // ! DPNBUILD_ONLYONETHREAD
  2096. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pCapsData);
  2097. DNASSERT( pThis != NULL );
  2098. DNASSERT( pCapsData != NULL );
  2099. DNASSERT( pCapsData->dwSize == sizeof( *pCapsData ) );
  2100. DNASSERT( pCapsData->hEndpoint == INVALID_HANDLE_VALUE );
  2101. //
  2102. // initialize
  2103. //
  2104. hr = DPN_OK;
  2105. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  2106. //
  2107. // no need to tell thread pool to lock the thread count for this function.
  2108. //
  2109. // Trust protocol to call us only in the initialized state
  2110. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  2111. //
  2112. // set flags
  2113. //
  2114. pCapsData->dwFlags = DPNSPCAPS_SUPPORTSDPNSRV |
  2115. DPNSPCAPS_SUPPORTSBROADCAST |
  2116. DPNSPCAPS_SUPPORTSALLADAPTERS;
  2117. #ifndef DPNBUILD_ONLYONETHREAD
  2118. pCapsData->dwFlags |= DPNSPCAPS_SUPPORTSTHREADPOOL;
  2119. #endif // ! DPNBUILD_ONLYONETHREAD
  2120. #ifndef DPNBUILD_NOMULTICAST
  2121. #if ((! defined(DPNBUILD_NOIPV6)) || (! defined(DPNBUILD_NOIPX)))
  2122. if (pSPData->GetType() != AF_IPX)
  2123. #endif // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  2124. {
  2125. pCapsData->dwFlags |= DPNSPCAPS_SUPPORTSMULTICAST;
  2126. }
  2127. #endif // ! DPNBUILD_NOMULTICAST
  2128. //
  2129. // set frame sizes
  2130. //
  2131. #ifdef DPNBUILD_NOREGISTRY
  2132. pCapsData->dwUserFrameSize = DEFAULT_MAX_USER_DATA_SIZE;
  2133. pCapsData->dwEnumFrameSize = DEFAULT_MAX_ENUM_DATA_SIZE;
  2134. #else // ! DPNBUILD_NOREGISTRY
  2135. pCapsData->dwUserFrameSize = g_dwMaxUserDataSize;
  2136. pCapsData->dwEnumFrameSize = g_dwMaxEnumDataSize;
  2137. #endif // ! DPNBUILD_NOREGISTRY
  2138. //
  2139. // Set link speed, no need to check for endpoint because
  2140. // the link speed cannot be determined.
  2141. //
  2142. pCapsData->dwLocalLinkSpeed = UNKNOWN_BANDWIDTH;
  2143. #ifdef DPNBUILD_ONLYONETHREAD
  2144. pCapsData->dwIOThreadCount = 0;
  2145. #else // ! DPNBUILD_ONLYONETHREAD
  2146. hr = pSPData->GetThreadPool()->GetIOThreadCount( &iIOThreadCount );
  2147. if ( hr != DPN_OK )
  2148. {
  2149. DPFX(DPFPREP, 0, "DNSP_GetCaps: Failed to get thread pool count!" );
  2150. DisplayDNError( 0, hr );
  2151. goto Failure;
  2152. }
  2153. pCapsData->dwIOThreadCount = iIOThreadCount;
  2154. #endif // ! DPNBUILD_ONLYONETHREAD
  2155. //
  2156. // set enumeration defaults
  2157. //
  2158. pCapsData->dwDefaultEnumRetryCount = DEFAULT_ENUM_RETRY_COUNT;
  2159. pCapsData->dwDefaultEnumRetryInterval = DEFAULT_ENUM_RETRY_INTERVAL;
  2160. pCapsData->dwDefaultEnumTimeout = DEFAULT_ENUM_TIMEOUT;
  2161. //
  2162. // dwBuffersPerThread is ignored
  2163. //
  2164. pCapsData->dwBuffersPerThread = 1;
  2165. //
  2166. // set receive buffering information
  2167. //
  2168. pCapsData->dwSystemBufferSize = 8192;
  2169. if ( g_fWinsockReceiveBufferSizeOverridden == FALSE )
  2170. {
  2171. SOCKET TestSocket;
  2172. #if ((defined(DPNBUILD_NOIPV6)) && (defined(DPNBUILD_NOIPX)))
  2173. TestSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_IP );
  2174. #else // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  2175. switch (pSPData->GetType())
  2176. {
  2177. #ifndef DPNBUILD_NOIPV6
  2178. case AF_INET6:
  2179. {
  2180. TestSocket = socket( AF_INET6, SOCK_DGRAM, IPPROTO_IP );
  2181. break;
  2182. }
  2183. #endif // ! DPNBUILD_NOIPV6
  2184. #ifndef DPNBUILD_NOIPX
  2185. case AF_IPX:
  2186. {
  2187. TestSocket = socket( AF_IPX, SOCK_DGRAM, NSPROTO_IPX );
  2188. break;
  2189. }
  2190. #endif // ! DPNBUILD_NOIPX
  2191. default:
  2192. {
  2193. DNASSERT(pSPData->GetType() == AF_INET);
  2194. TestSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_IP );
  2195. break;
  2196. }
  2197. }
  2198. #endif // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  2199. if ( TestSocket != INVALID_SOCKET )
  2200. {
  2201. INT iBufferSize;
  2202. INT iBufferSizeSize;
  2203. INT iWSAReturn;
  2204. iBufferSizeSize = sizeof( iBufferSize );
  2205. iWSAReturn = getsockopt( TestSocket, // socket
  2206. SOL_SOCKET, // socket level option
  2207. SO_RCVBUF, // socket option
  2208. reinterpret_cast<char*>( &iBufferSize ), // pointer to destination
  2209. &iBufferSizeSize // pointer to destination size
  2210. );
  2211. if ( iWSAReturn != SOCKET_ERROR )
  2212. {
  2213. pCapsData->dwSystemBufferSize = iBufferSize;
  2214. }
  2215. else
  2216. {
  2217. DPFX(DPFPREP, 0, "Failed to get socket receive buffer options!" );
  2218. DisplayWinsockError( 0, iWSAReturn );
  2219. }
  2220. closesocket( TestSocket );
  2221. TestSocket = INVALID_SOCKET;
  2222. }
  2223. }
  2224. else
  2225. {
  2226. pCapsData->dwSystemBufferSize = g_iWinsockReceiveBufferSize;
  2227. }
  2228. #ifndef DPNBUILD_ONLYONETHREAD
  2229. Exit:
  2230. #endif // !DPNBUILD_ONLYONETHREAD
  2231. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  2232. return hr;
  2233. #ifndef DPNBUILD_ONLYONETHREAD
  2234. Failure:
  2235. goto Exit;
  2236. #endif // !DPNBUILD_ONLYONETHREAD
  2237. }
  2238. //**********************************************************************
  2239. //**********************************************************************
  2240. // ------------------------------
  2241. // DNSP_SetCaps - set SP capabilities
  2242. //
  2243. // Entry: Pointer to DNSP interface
  2244. // Pointer to caps data
  2245. //
  2246. // Exit: Error code
  2247. // ------------------------------
  2248. #undef DPF_MODNAME
  2249. #define DPF_MODNAME "DNSP_SetCaps"
  2250. STDMETHODIMP DNSP_SetCaps( IDP8ServiceProvider *pThis, SPSETCAPSDATA *pCapsData )
  2251. {
  2252. HRESULT hr;
  2253. CSPData *pSPData;
  2254. #ifndef DPNBUILD_NOREGISTRY
  2255. CRegistry RegObject;
  2256. #endif // ! DPNBUILD_NOREGISTRY
  2257. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pCapsData);
  2258. DNASSERT( pThis != NULL );
  2259. DNASSERT( pCapsData != NULL );
  2260. DNASSERT( pCapsData->dwSize == sizeof( *pCapsData ) );
  2261. //
  2262. // initialize
  2263. //
  2264. hr = DPN_OK;
  2265. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  2266. //
  2267. // no need to tell thread pool to lock the thread count for this function.
  2268. //
  2269. // Trust protocol to call us only in the initialized state
  2270. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  2271. //
  2272. // validate caps
  2273. //
  2274. if ( pCapsData->dwBuffersPerThread == 0 )
  2275. {
  2276. DPFX(DPFPREP, 0, "Failing SetCaps because dwBuffersPerThread == 0" );
  2277. hr = DPNERR_INVALIDPARAM;
  2278. goto Failure;
  2279. }
  2280. #ifndef DPNBUILD_ONLYONETHREAD
  2281. //
  2282. // change thread count, if requested
  2283. //
  2284. if ( pCapsData->dwIOThreadCount != 0 )
  2285. {
  2286. hr = pSPData->GetThreadPool()->SetIOThreadCount( pCapsData->dwIOThreadCount );
  2287. if ( hr != DPN_OK )
  2288. {
  2289. DPFX(DPFPREP, 0, "Failed to set thread pool count!" );
  2290. DisplayDNError( 0, hr );
  2291. goto Failure;
  2292. }
  2293. }
  2294. #endif // ! DPNBUILD_ONLYONETHREAD
  2295. //
  2296. // dwBuffersPerThread is ignored.
  2297. //
  2298. //
  2299. // Set the receive buffer size.
  2300. //
  2301. DBG_CASSERT( sizeof( pCapsData->dwSystemBufferSize ) == sizeof( g_iWinsockReceiveBufferSize ) );
  2302. g_fWinsockReceiveBufferSizeOverridden = TRUE;
  2303. g_iWinsockReceiveBufferSize = pCapsData->dwSystemBufferSize;
  2304. #ifndef WINCE
  2305. pSPData->SetWinsockBufferSizeOnAllSockets( g_iWinsockReceiveBufferSize );
  2306. #endif // ! WINCE
  2307. Exit:
  2308. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  2309. return hr;
  2310. Failure:
  2311. goto Exit;
  2312. }
  2313. //**********************************************************************
  2314. //**********************************************************************
  2315. // ------------------------------
  2316. // DNSP_ReturnReceiveBuffers - return receive buffers to pool
  2317. //
  2318. // Entry: Pointer to DNSP interface
  2319. // Pointer to caps data
  2320. //
  2321. // Exit: Error code
  2322. // ------------------------------
  2323. #undef DPF_MODNAME
  2324. #define DPF_MODNAME "DNSP_ReturnReceiveBuffers"
  2325. STDMETHODIMP DNSP_ReturnReceiveBuffers( IDP8ServiceProvider *pThis, SPRECEIVEDBUFFER *pReceivedBuffers )
  2326. {
  2327. SPRECEIVEDBUFFER *pBuffers;
  2328. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pReceivedBuffers);
  2329. //
  2330. // no need to tell thread pool to lock the thread count for this function.
  2331. //
  2332. DNASSERT( pThis != NULL );
  2333. DNASSERT( pReceivedBuffers != NULL );
  2334. pBuffers = pReceivedBuffers;
  2335. while ( pBuffers != NULL )
  2336. {
  2337. SPRECEIVEDBUFFER *pTemp;
  2338. CReadIOData *pReadData;
  2339. pTemp = pBuffers;
  2340. pBuffers = pBuffers->pNext;
  2341. pReadData = CReadIOData::ReadDataFromSPReceivedBuffer( pTemp );
  2342. DEBUG_ONLY( pReadData->m_fRetainedByHigherLayer = FALSE );
  2343. pReadData->DecRef();
  2344. }
  2345. //DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  2346. DPFX(DPFPREP, 2, "Returning: DPN_OK");
  2347. return DPN_OK;
  2348. }
  2349. //**********************************************************************
  2350. //**********************************************************************
  2351. // ------------------------------
  2352. // DNSP_GetAddressInfo - get address information for an endpoint
  2353. //
  2354. // Entry: Pointer to DNSP Interface
  2355. // Pointer to input data
  2356. //
  2357. // Exit: Error code
  2358. // ------------------------------
  2359. #undef DPF_MODNAME
  2360. #define DPF_MODNAME "DNSP_GetAddressInfo"
  2361. STDMETHODIMP DNSP_GetAddressInfo( IDP8ServiceProvider *pThis, SPGETADDRESSINFODATA *pGetAddressInfoData )
  2362. {
  2363. HRESULT hr;
  2364. CEndpoint *pEndpoint;
  2365. CSPData *pSPData;
  2366. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pGetAddressInfoData);
  2367. DNASSERT( pThis != NULL );
  2368. DNASSERT( pGetAddressInfoData != NULL );
  2369. DNASSERT( pGetAddressInfoData->hEndpoint != INVALID_HANDLE_VALUE && pGetAddressInfoData->hEndpoint != 0 );
  2370. #ifdef DPNBUILD_NOMULTICAST
  2371. DNASSERT( ( pGetAddressInfoData->Flags & ~( SP_GET_ADDRESS_INFO_LOCAL_ADAPTER |
  2372. SP_GET_ADDRESS_INFO_LISTEN_HOST_ADDRESSES |
  2373. SP_GET_ADDRESS_INFO_LOCAL_HOST_PUBLIC_ADDRESS |
  2374. SP_GET_ADDRESS_INFO_REMOTE_HOST ) ) == 0 );
  2375. #else // ! DPNBUILD_NOMULTICAST
  2376. DNASSERT( ( pGetAddressInfoData->Flags & ~( SP_GET_ADDRESS_INFO_LOCAL_ADAPTER |
  2377. SP_GET_ADDRESS_INFO_LISTEN_HOST_ADDRESSES |
  2378. SP_GET_ADDRESS_INFO_LOCAL_HOST_PUBLIC_ADDRESS |
  2379. SP_GET_ADDRESS_INFO_REMOTE_HOST |
  2380. SP_GET_ADDRESS_INFO_MULTICAST_GROUP ) ) == 0 );
  2381. #endif // ! DPNBUILD_NOMULTICAST
  2382. //
  2383. // initialize
  2384. //
  2385. hr = DPN_OK;
  2386. DBG_CASSERT( sizeof( pEndpoint ) == sizeof( pGetAddressInfoData->hEndpoint ) );
  2387. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  2388. // Trust protocol to call us only in the initialized state
  2389. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  2390. //
  2391. // no need to tell thread pool to lock the thread count for this function.
  2392. //
  2393. pEndpoint = pSPData->EndpointFromHandle( pGetAddressInfoData->hEndpoint );
  2394. if ( pEndpoint != NULL )
  2395. {
  2396. switch ( pGetAddressInfoData->Flags )
  2397. {
  2398. case SP_GET_ADDRESS_INFO_LOCAL_ADAPTER:
  2399. {
  2400. pGetAddressInfoData->pAddress = pEndpoint->GetLocalAdapterDP8Address( SP_ADDRESS_TYPE_DEVICE );
  2401. if (pGetAddressInfoData->pAddress == NULL)
  2402. {
  2403. DPFX(DPFPREP, 0, "Couldn't get local adapter device address!");
  2404. hr = DPNERR_OUTOFMEMORY;
  2405. }
  2406. break;
  2407. }
  2408. case SP_GET_ADDRESS_INFO_LISTEN_HOST_ADDRESSES:
  2409. {
  2410. pGetAddressInfoData->pAddress = pEndpoint->GetLocalAdapterDP8Address( SP_ADDRESS_TYPE_HOST );
  2411. if (pGetAddressInfoData->pAddress == NULL)
  2412. {
  2413. DPFX(DPFPREP, 0, "Couldn't get local adapter host address!");
  2414. hr = DPNERR_OUTOFMEMORY;
  2415. }
  2416. break;
  2417. }
  2418. case SP_GET_ADDRESS_INFO_LOCAL_HOST_PUBLIC_ADDRESS:
  2419. {
  2420. pGetAddressInfoData->pAddress = pEndpoint->GetLocalAdapterDP8Address( SP_ADDRESS_TYPE_PUBLIC_HOST_ADDRESS );
  2421. break;
  2422. }
  2423. case SP_GET_ADDRESS_INFO_REMOTE_HOST:
  2424. {
  2425. pGetAddressInfoData->pAddress = pEndpoint->GetRemoteHostDP8Address();
  2426. if (pGetAddressInfoData->pAddress == NULL)
  2427. {
  2428. DPFX(DPFPREP, 0, "Couldn't get remote host address!");
  2429. hr = DPNERR_OUTOFMEMORY;
  2430. }
  2431. break;
  2432. }
  2433. #ifndef DPNBUILD_NOMULTICAST
  2434. case SP_GET_ADDRESS_INFO_MULTICAST_GROUP:
  2435. {
  2436. pGetAddressInfoData->pAddress = pEndpoint->GetRemoteHostDP8Address();
  2437. //
  2438. // If we successfully got an address, add the multicast scope GUID.
  2439. //
  2440. if (pGetAddressInfoData->pAddress != NULL)
  2441. {
  2442. GUID guidScope;
  2443. pEndpoint->GetScopeGuid(&guidScope);
  2444. hr = IDirectPlay8Address_AddComponent(pGetAddressInfoData->pAddress,
  2445. DPNA_KEY_SCOPE,
  2446. &guidScope,
  2447. sizeof(guidScope),
  2448. DPNA_DATATYPE_GUID);
  2449. if (hr != DPN_OK)
  2450. {
  2451. DPFX(DPFPREP, 0, "Couldn't add scope GUID component to address (err = 0x%lx)! Ignoring.", hr);
  2452. hr = DPN_OK;
  2453. }
  2454. }
  2455. else
  2456. {
  2457. DPFX(DPFPREP, 0, "Couldn't get multicast group address!");
  2458. hr = DPNERR_OUTOFMEMORY;
  2459. }
  2460. break;
  2461. }
  2462. #endif // ! DPNBUILD_NOMULTICAST
  2463. default:
  2464. {
  2465. DNASSERT( FALSE );
  2466. break;
  2467. }
  2468. }
  2469. pEndpoint->DecCommandRef();
  2470. pEndpoint = NULL;
  2471. }
  2472. else
  2473. {
  2474. hr = DPNERR_INVALIDENDPOINT;
  2475. }
  2476. if ( hr != DPN_OK )
  2477. {
  2478. DPFX(DPFPREP, 0, "Problem getting DNAddress from endpoint!" );
  2479. DisplayDNError( 0, hr );
  2480. }
  2481. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  2482. return hr;
  2483. }
  2484. //**********************************************************************
  2485. //**********************************************************************
  2486. // ------------------------------
  2487. // DNSP_Update - update information/status of an endpoint
  2488. //
  2489. // Entry: Pointer to DNSP Interface
  2490. // Pointer to input data
  2491. //
  2492. // Exit: Error code
  2493. // ------------------------------
  2494. #undef DPF_MODNAME
  2495. #define DPF_MODNAME "DNSP_Update"
  2496. STDMETHODIMP DNSP_Update( IDP8ServiceProvider *pThis, SPUPDATEDATA *pUpdateData )
  2497. {
  2498. HRESULT hr;
  2499. CSPData *pSPData;
  2500. CEndpoint *pEndpoint;
  2501. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pUpdateData);
  2502. DNASSERT( pThis != NULL );
  2503. DNASSERT( pUpdateData != NULL );
  2504. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  2505. // Trust protocol to call us only in the initialized state
  2506. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  2507. //
  2508. // no need to tell thread pool to lock the thread count for this function.
  2509. //
  2510. switch ( pUpdateData->UpdateType )
  2511. {
  2512. case SP_UPDATE_HOST_MIGRATE:
  2513. {
  2514. #ifdef DBG
  2515. DNASSERT( ( pUpdateData->hEndpoint != INVALID_HANDLE_VALUE ) && ( pUpdateData->hEndpoint != NULL ) );
  2516. DBG_CASSERT( sizeof( pEndpoint ) == sizeof( pUpdateData->hEndpoint ) );
  2517. pEndpoint = pSPData->EndpointFromHandle( pUpdateData->hEndpoint );
  2518. if (pEndpoint == NULL)
  2519. {
  2520. DPFX(DPFPREP, 0, "Host migrate endpoint 0x%p is invalid!", pEndpoint);
  2521. DNASSERT( FALSE );
  2522. hr = DPNERR_INVALIDENDPOINT;
  2523. break;
  2524. }
  2525. DNASSERT( pEndpoint->GetType() == ENDPOINT_TYPE_LISTEN );
  2526. DPFX(DPFPREP, 3, "Host migrated to listen endpoint 0x%p.", pEndpoint);
  2527. pEndpoint->DecCommandRef();
  2528. pEndpoint = NULL;
  2529. #endif // DBG
  2530. hr = DPN_OK;
  2531. break;
  2532. }
  2533. case SP_UPDATE_ALLOW_ENUMS:
  2534. case SP_UPDATE_DISALLOW_ENUMS:
  2535. {
  2536. DNASSERT( ( pUpdateData->hEndpoint != INVALID_HANDLE_VALUE ) && ( pUpdateData->hEndpoint != NULL ) );
  2537. DBG_CASSERT( sizeof( pEndpoint ) == sizeof( pUpdateData->hEndpoint ) );
  2538. pEndpoint = pSPData->EndpointFromHandle( pUpdateData->hEndpoint );
  2539. if (pEndpoint == NULL)
  2540. {
  2541. DPFX(DPFPREP, 0, "Allow/disallow enums endpoint 0x%p is invalid!", pEndpoint);
  2542. DNASSERT( FALSE );
  2543. hr = DPNERR_INVALIDENDPOINT;
  2544. break;
  2545. }
  2546. DNASSERT( pEndpoint->GetType() == ENDPOINT_TYPE_LISTEN );
  2547. if ( pUpdateData->UpdateType == SP_UPDATE_ALLOW_ENUMS )
  2548. {
  2549. DPFX(DPFPREP, 3, "Allowing enums on listen endpoint 0x%p.", pEndpoint);
  2550. pEndpoint->SetEnumsAllowedOnListen( TRUE, TRUE );
  2551. }
  2552. else
  2553. {
  2554. DPFX(DPFPREP, 3, "Disallowing enums on listen endpoint 0x%p.", pEndpoint);
  2555. pEndpoint->SetEnumsAllowedOnListen( FALSE, TRUE );
  2556. }
  2557. pEndpoint->DecCommandRef();
  2558. pEndpoint = NULL;
  2559. hr = DPN_OK;
  2560. break;
  2561. }
  2562. default:
  2563. {
  2564. DPFX(DPFPREP, 0, "Unsupported update type %u!", pUpdateData->UpdateType);
  2565. hr = DPNERR_UNSUPPORTED;
  2566. break;
  2567. }
  2568. }
  2569. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  2570. return hr;
  2571. }
  2572. //**********************************************************************
  2573. #ifndef DPNBUILD_LIBINTERFACE
  2574. //**********************************************************************
  2575. // ------------------------------
  2576. // DNSP_IsApplicationSupported - determine if this application is supported by this
  2577. // SP.
  2578. //
  2579. // Entry: Pointer to DNSP Interface
  2580. // Pointer to input data
  2581. //
  2582. // Exit: Error code
  2583. // ------------------------------
  2584. #undef DPF_MODNAME
  2585. #define DPF_MODNAME "DNSP_IsApplicationSupported"
  2586. STDMETHODIMP DNSP_IsApplicationSupported( IDP8ServiceProvider *pThis, SPISAPPLICATIONSUPPORTEDDATA *pIsApplicationSupportedData )
  2587. {
  2588. CSPData *pSPData;
  2589. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pIsApplicationSupportedData);
  2590. DNASSERT( pThis != NULL );
  2591. DNASSERT( pIsApplicationSupportedData != NULL );
  2592. DNASSERT( pIsApplicationSupportedData->pApplicationGuid != NULL );
  2593. DNASSERT( pIsApplicationSupportedData->dwFlags == 0 );
  2594. //
  2595. // initialize, we support all applications with this SP
  2596. //
  2597. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  2598. //
  2599. // no need to tell thread pool to lock the thread count for this function.
  2600. //
  2601. // Trust protocol to call us only in the initialized state
  2602. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  2603. DPFX(DPFPREP, 2, "Returning: DPN_OK");
  2604. return DPN_OK;
  2605. }
  2606. //**********************************************************************
  2607. #endif // ! DPNBUILD_LIBINTERFACE
  2608. #ifndef DPNBUILD_ONLYONEADAPTER
  2609. //**********************************************************************
  2610. // ------------------------------
  2611. // DNSP_EnumAdapters - get a list of adapters for this SP
  2612. //
  2613. // Entry: Pointer DNSP Interface
  2614. // Pointer to input data
  2615. //
  2616. // Exit: Error code
  2617. // ------------------------------
  2618. #undef DPF_MODNAME
  2619. #define DPF_MODNAME "DNSP_EnumAdapters"
  2620. STDMETHODIMP DNSP_EnumAdapters( IDP8ServiceProvider *pThis, SPENUMADAPTERSDATA *pEnumAdaptersData )
  2621. {
  2622. HRESULT hr;
  2623. CSocketAddress *pSPAddress;
  2624. CSPData *pSPData;
  2625. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pEnumAdaptersData);
  2626. DNASSERT( pThis != NULL );
  2627. DNASSERT( pEnumAdaptersData != NULL );
  2628. DNASSERT( ( pEnumAdaptersData->pAdapterData != NULL ) ||
  2629. ( pEnumAdaptersData->dwAdapterDataSize == 0 ) );
  2630. DNASSERT( pEnumAdaptersData->dwFlags == 0 );
  2631. //
  2632. // initialize
  2633. //
  2634. hr = DPN_OK;
  2635. pEnumAdaptersData->dwAdapterCount = 0;
  2636. pSPAddress = NULL;
  2637. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  2638. //
  2639. // no need to tell thread pool to lock the thread count for this function.
  2640. //
  2641. // Trust protocol to call us only in the initialized state
  2642. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  2643. //
  2644. // get an SP address from the pool to perform conversions to GUIDs
  2645. //
  2646. #if ((defined(DPNBUILD_NOIPV6)) && (defined(DPNBUILD_NOIPX)))
  2647. pSPAddress = (CSocketAddress*) g_SocketAddressPool.Get((PVOID) ((DWORD_PTR) AF_INET));
  2648. #else // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  2649. pSPAddress = (CSocketAddress*) g_SocketAddressPool.Get((PVOID) ((DWORD_PTR) pSPData->GetType()));
  2650. #endif // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  2651. if ( pSPAddress == NULL )
  2652. {
  2653. hr = DPNERR_OUTOFMEMORY;
  2654. DPFX(DPFPREP, 0, "Failed to get address for GUID conversions in DNSP_EnumAdapters!" );
  2655. goto Failure;
  2656. }
  2657. //
  2658. // enumerate adapters
  2659. //
  2660. hr = pSPAddress->EnumAdapters( pEnumAdaptersData );
  2661. if ( hr != DPN_OK )
  2662. {
  2663. if (hr == DPNERR_BUFFERTOOSMALL)
  2664. {
  2665. DPFX(DPFPREP, 1, "Buffer too small for enumerating adapters.");
  2666. }
  2667. else
  2668. {
  2669. DPFX(DPFPREP, 0, "Problem enumerating adapters (err = 0x%lx)!", hr);
  2670. DisplayDNError( 0, hr );
  2671. }
  2672. goto Failure;
  2673. }
  2674. Exit:
  2675. if ( pSPAddress != NULL )
  2676. {
  2677. g_SocketAddressPool.Release( pSPAddress );
  2678. pSPAddress = NULL;
  2679. }
  2680. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  2681. return hr;
  2682. Failure:
  2683. goto Exit;
  2684. }
  2685. //**********************************************************************
  2686. #endif // ! DPNBUILD_ONLYONEADAPTER
  2687. #ifndef DPNBUILD_SINGLEPROCESS
  2688. //**********************************************************************
  2689. // ------------------------------
  2690. // DNSP_ProxyEnumQuery - proxy an enum query
  2691. //
  2692. // Entry: Pointer DNSP Interface
  2693. // Pointer to input data
  2694. //
  2695. // Exit: Error code
  2696. // ------------------------------
  2697. #undef DPF_MODNAME
  2698. #define DPF_MODNAME "DNSP_ProxyEnumQuery"
  2699. STDMETHODIMP DNSP_ProxyEnumQuery( IDP8ServiceProvider *pThis, SPPROXYENUMQUERYDATA *pProxyEnumQueryData )
  2700. {
  2701. HRESULT hr;
  2702. CSPData *pSPData;
  2703. CSocketAddress *pDestinationAddress;
  2704. CSocketAddress *pReturnAddress;
  2705. CEndpoint *pEndpoint;
  2706. const ENDPOINT_ENUM_QUERY_CONTEXT *pEndpointEnumContext;
  2707. BUFFERDESC BufferDesc[2];
  2708. PREPEND_BUFFER PrependBuffer;
  2709. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pProxyEnumQueryData);
  2710. DNASSERT( pThis != NULL );
  2711. DNASSERT( pProxyEnumQueryData != NULL );
  2712. DNASSERT( pProxyEnumQueryData->dwFlags == 0 );
  2713. //
  2714. // initialize
  2715. //
  2716. hr = DPN_OK;
  2717. DBG_CASSERT( OFFSETOF( ENDPOINT_ENUM_QUERY_CONTEXT, EnumQueryData ) == 0 );
  2718. pEndpointEnumContext = reinterpret_cast<ENDPOINT_ENUM_QUERY_CONTEXT*>( pProxyEnumQueryData->pIncomingQueryData );
  2719. DNASSERT(pEndpointEnumContext->pReturnAddress != NULL);
  2720. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  2721. pDestinationAddress = NULL;
  2722. pReturnAddress = NULL;
  2723. pEndpoint = NULL;
  2724. //
  2725. // No need to tell thread pool to lock the thread count for this function
  2726. // because there's already an outstanding enum that did.
  2727. //
  2728. // Trust protocol to call us only in the initialized state
  2729. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  2730. //
  2731. // preallocate addresses
  2732. //
  2733. #if ((defined(DPNBUILD_NOIPV6)) && (defined(DPNBUILD_NOIPX)))
  2734. pDestinationAddress = (CSocketAddress*) g_SocketAddressPool.Get((PVOID) ((DWORD_PTR) AF_INET));
  2735. #else // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  2736. pDestinationAddress = (CSocketAddress*) g_SocketAddressPool.Get((PVOID) ((DWORD_PTR) pEndpointEnumContext->pReturnAddress->GetFamily()));
  2737. #endif // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  2738. if ( pDestinationAddress == NULL )
  2739. {
  2740. hr = DPNERR_OUTOFMEMORY;
  2741. goto Failure;
  2742. }
  2743. #if ((defined(DPNBUILD_NOIPV6)) && (defined(DPNBUILD_NOIPX)))
  2744. pReturnAddress = (CSocketAddress*) g_SocketAddressPool.Get((PVOID) ((DWORD_PTR) AF_INET));
  2745. #else // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  2746. pReturnAddress = (CSocketAddress*) g_SocketAddressPool.Get((PVOID) ((DWORD_PTR) pEndpointEnumContext->pReturnAddress->GetFamily()));
  2747. #endif // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  2748. if ( pReturnAddress == NULL )
  2749. {
  2750. hr = DPNERR_OUTOFMEMORY;
  2751. goto Failure;
  2752. }
  2753. //
  2754. // set the endpoint and send it along
  2755. //
  2756. pEndpoint = pSPData->EndpointFromHandle( pEndpointEnumContext->hEndpoint );
  2757. if ( pEndpoint == NULL )
  2758. {
  2759. hr = DPNERR_INVALIDENDPOINT;
  2760. DPFX(DPFPREP, 8, "Invalid endpoint handle in DNSP_ProxyEnumQuery" );
  2761. goto Failure;
  2762. }
  2763. //
  2764. // set destination address from the supplied data
  2765. //
  2766. hr = pDestinationAddress->SocketAddressFromDP8Address( pProxyEnumQueryData->pDestinationAdapter,
  2767. #ifdef DPNBUILD_XNETSECURITY
  2768. NULL,
  2769. #endif // DPNBUILD_XNETSECURITY
  2770. #ifndef DPNBUILD_ONLYONETHREAD
  2771. FALSE,
  2772. #endif // DPNBUILD_ONLYONETHREAD
  2773. SP_ADDRESS_TYPE_DEVICE );
  2774. if ( hr != DPN_OK )
  2775. {
  2776. DPFX(DPFPREP, 0, "ProxyEnumQuery: Failed to convert target adapter address" );
  2777. goto Failure;
  2778. }
  2779. //
  2780. // set return address from incoming enum query
  2781. //
  2782. memcpy( pReturnAddress->GetWritableAddress(),
  2783. pEndpointEnumContext->pReturnAddress->GetAddress(),
  2784. pEndpointEnumContext->pReturnAddress->GetAddressSize() );
  2785. DNASSERT(pProxyEnumQueryData->pIncomingQueryData->pReceivedData->pNext == NULL);
  2786. DNASSERT( pEndpointEnumContext->dwEnumKey <= WORD_MAX );
  2787. BufferDesc[0].pBufferData = reinterpret_cast<BYTE*>(&PrependBuffer.ProxiedEnumDataHeader);
  2788. BufferDesc[0].dwBufferSize = sizeof( PrependBuffer.ProxiedEnumDataHeader );
  2789. memcpy(&BufferDesc[1],
  2790. &pProxyEnumQueryData->pIncomingQueryData->pReceivedData->BufferDesc,
  2791. sizeof(BufferDesc[1]));
  2792. PrependBuffer.ProxiedEnumDataHeader.bSPLeadByte = SP_HEADER_LEAD_BYTE;
  2793. PrependBuffer.ProxiedEnumDataHeader.bSPCommandByte = PROXIED_ENUM_DATA_KIND;
  2794. PrependBuffer.ProxiedEnumDataHeader.wEnumKey = static_cast<WORD>( pEndpointEnumContext->dwEnumKey );
  2795. //
  2796. // We could save 2 bytes on IPX by only passing 14 bytes for the
  2797. // SOCKADDR structure but it's not worth it, especially since it's
  2798. // looping back in the local network stack. SOCKADDR structures are also
  2799. // 16 bytes so reducing the data passed to 14 bytes would destroy alignment.
  2800. //
  2801. // Note that if we're using the large IPv6 addresses, the IPX wasted space is
  2802. // larger, and IPv4 addresses will now waste some, too.
  2803. //
  2804. DBG_CASSERT( (sizeof( PrependBuffer.ProxiedEnumDataHeader.ReturnAddress ) % 4) == 0 );
  2805. memcpy( &PrependBuffer.ProxiedEnumDataHeader.ReturnAddress,
  2806. pReturnAddress->GetAddress(),
  2807. sizeof( PrependBuffer.ProxiedEnumDataHeader.ReturnAddress ) );
  2808. #ifdef DPNBUILD_ASYNCSPSENDS
  2809. pEndpoint->GetSocketPort()->SendData( BufferDesc, 2, pDestinationAddress, NULL );
  2810. #else // ! DPNBUILD_ASYNCSPSENDS
  2811. pEndpoint->GetSocketPort()->SendData( BufferDesc, 2, pDestinationAddress );
  2812. #endif // ! DPNBUILD_ASYNCSPSENDS
  2813. pEndpoint->DecCommandRef();
  2814. pEndpoint = NULL;
  2815. Exit:
  2816. if ( pReturnAddress != NULL )
  2817. {
  2818. g_SocketAddressPool.Release( pReturnAddress );
  2819. pReturnAddress = NULL;
  2820. }
  2821. if (pDestinationAddress != NULL )
  2822. {
  2823. g_SocketAddressPool.Release( pDestinationAddress );
  2824. pDestinationAddress = NULL;
  2825. }
  2826. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  2827. return hr;
  2828. Failure:
  2829. if (pEndpoint != NULL )
  2830. {
  2831. pEndpoint->DecCommandRef();
  2832. pEndpoint = NULL;
  2833. }
  2834. goto Exit;
  2835. }
  2836. //**********************************************************************
  2837. #endif // ! DPNBUILD_SINGLEPROCESS
  2838. //**********************************************************************
  2839. /*
  2840. *
  2841. * DNSP_NotSupported is used for methods required to implement the
  2842. * interface but that are not supported by this SP.
  2843. *
  2844. */
  2845. //**********************************************************************
  2846. #undef DPF_MODNAME
  2847. #define DPF_MODNAME "DNSP_NotSupported"
  2848. STDMETHODIMP DNSP_NotSupported( IDP8ServiceProvider *pThis, PVOID pvParam )
  2849. {
  2850. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pvParam);
  2851. DPFX(DPFPREP, 2, "Returning: [DPNERR_UNSUPPORTED]");
  2852. return DPNERR_UNSUPPORTED;
  2853. }
  2854. //**********************************************************************
  2855. #ifndef DPNBUILD_NOMULTICAST
  2856. //**********************************************************************
  2857. // ------------------------------
  2858. // DNSP_EnumMulticastScopes - get a list of multicast scopes for this SP
  2859. //
  2860. // Entry: Pointer DNSP Interface
  2861. // Pointer to input data
  2862. //
  2863. // Exit: Error code
  2864. // ------------------------------
  2865. #undef DPF_MODNAME
  2866. #define DPF_MODNAME "DNSP_EnumMulticastScopes"
  2867. STDMETHODIMP DNSP_EnumMulticastScopes( IDP8ServiceProvider *pThis, SPENUMMULTICASTSCOPESDATA *pEnumMulticastScopesData )
  2868. {
  2869. HRESULT hr;
  2870. CSPData *pSPData;
  2871. CSocketAddress *pSPAddress;
  2872. BOOL fUseMADCAP;
  2873. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pEnumMulticastScopesData);
  2874. DNASSERT( pThis != NULL );
  2875. DNASSERT( pEnumMulticastScopesData != NULL );
  2876. DNASSERT( pEnumMulticastScopesData->pguidAdapter != NULL );
  2877. DNASSERT( ( pEnumMulticastScopesData->pScopeData != NULL ) ||
  2878. ( pEnumMulticastScopesData->dwScopeDataSize == 0 ) );
  2879. DNASSERT( pEnumMulticastScopesData->dwFlags == 0 );
  2880. //
  2881. // initialize
  2882. //
  2883. hr = DPN_OK;
  2884. pEnumMulticastScopesData->dwScopeCount = 0;
  2885. pSPAddress = NULL;
  2886. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  2887. //
  2888. // no need to tell thread pool to lock the thread count for this function.
  2889. //
  2890. // Trust protocol to call us only in the initialized state
  2891. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  2892. //
  2893. // get an SP address from the pool to perform conversions to GUIDs
  2894. //
  2895. #if ((defined(DPNBUILD_NOIPV6)) && (defined(DPNBUILD_NOIPX)))
  2896. pSPAddress = (CSocketAddress*) g_SocketAddressPool.Get((PVOID) ((DWORD_PTR) AF_INET));
  2897. #else // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  2898. pSPAddress = (CSocketAddress*) g_SocketAddressPool.Get((PVOID) ((DWORD_PTR) pSPData->GetType()));
  2899. #endif // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  2900. if ( pSPAddress == NULL )
  2901. {
  2902. hr = DPNERR_OUTOFMEMORY;
  2903. DPFX(DPFPREP, 0, "Failed to get address for GUID conversions in DNSP_EnumMulticastScopes!" );
  2904. goto Failure;
  2905. }
  2906. //
  2907. // enumerate adapters
  2908. //
  2909. #ifdef WINNT
  2910. fUseMADCAP = pSPData->GetThreadPool()->EnsureMadcapLoaded();
  2911. #else // ! WINNT
  2912. fUseMADCAP = FALSE;
  2913. #endif // ! WINNT
  2914. hr = pSPAddress->EnumMulticastScopes( pEnumMulticastScopesData, fUseMADCAP );
  2915. if ( hr != DPN_OK )
  2916. {
  2917. if (hr == DPNERR_BUFFERTOOSMALL)
  2918. {
  2919. DPFX(DPFPREP, 1, "Buffer too small for enumerating scopes.");
  2920. }
  2921. else
  2922. {
  2923. DPFX(DPFPREP, 0, "Problem enumerating scopes (err = 0x%lx)!", hr);
  2924. DisplayDNError( 0, hr );
  2925. }
  2926. goto Failure;
  2927. }
  2928. Exit:
  2929. if ( pSPAddress != NULL )
  2930. {
  2931. g_SocketAddressPool.Release( pSPAddress );
  2932. pSPAddress = NULL;
  2933. }
  2934. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  2935. return hr;
  2936. Failure:
  2937. goto Exit;
  2938. }
  2939. //**********************************************************************
  2940. //**********************************************************************
  2941. // ------------------------------
  2942. // DNSP_ShareEndpointInfo - get a list of multicast scopes for this SP
  2943. //
  2944. // Entry: Pointer DNSP Interface
  2945. // Pointer to input data
  2946. //
  2947. // Exit: Error code
  2948. // ------------------------------
  2949. #undef DPF_MODNAME
  2950. #define DPF_MODNAME "DNSP_ShareEndpointInfo"
  2951. STDMETHODIMP DNSP_ShareEndpointInfo( IDP8ServiceProvider *pThis, SPSHAREENDPOINTINFODATA *pShareEndpointInfoData )
  2952. {
  2953. HRESULT hr;
  2954. CSPData *pSPData;
  2955. CSPData *pSPDataShare;
  2956. BOOL fShareInterfaceReferenceAdded;
  2957. CSocketData *pSocketData;
  2958. #if ((! defined(DPNBUILD_NOIPV6)) || (! defined(DPNBUILD_NOIPX)))
  2959. short sShareSPType;
  2960. #endif // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  2961. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pShareEndpointInfoData);
  2962. DNASSERT( pThis != NULL );
  2963. DNASSERT( pShareEndpointInfoData != NULL );
  2964. DNASSERT( pShareEndpointInfoData->pDP8ServiceProvider != NULL );
  2965. DNASSERT( pShareEndpointInfoData->dwFlags == 0 );
  2966. //
  2967. // initialize
  2968. //
  2969. hr = DPN_OK;
  2970. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  2971. pSPDataShare = CSPData::SPDataFromCOMInterface( pShareEndpointInfoData->pDP8ServiceProvider );
  2972. fShareInterfaceReferenceAdded = FALSE;
  2973. pSocketData = NULL;
  2974. //
  2975. // no need to tell thread pool to lock the thread count for this function.
  2976. //
  2977. //
  2978. // First, validate the source (shared) SP's state. We must assume it's a
  2979. // valid dpnwsock SP (CSPData::SPDataFromCOMInterface should assert if not),
  2980. // but we can make sure it has been initialized.
  2981. //
  2982. pSPDataShare->Lock();
  2983. switch ( pSPDataShare->GetState() )
  2984. {
  2985. //
  2986. // provider is initialized, add a reference and proceed
  2987. //
  2988. case SPSTATE_INITIALIZED:
  2989. {
  2990. IDP8ServiceProvider_AddRef( pShareEndpointInfoData->pDP8ServiceProvider );
  2991. fShareInterfaceReferenceAdded = TRUE;
  2992. DNASSERT( hr == DPN_OK );
  2993. break;
  2994. }
  2995. //
  2996. // provider is uninitialized
  2997. //
  2998. case SPSTATE_UNINITIALIZED:
  2999. {
  3000. hr = DPNERR_UNINITIALIZED;
  3001. DPFX(DPFPREP, 0, "ShareEndpointInfo called with uninitialized shared SP 0x%p!",
  3002. pSPDataShare );
  3003. break;
  3004. }
  3005. //
  3006. // provider is closing
  3007. //
  3008. case SPSTATE_CLOSING:
  3009. {
  3010. hr = DPNERR_ABORTED;
  3011. DPFX(DPFPREP, 0, "ShareEndpointInfo called with shared SP 0x%p that is closing!",
  3012. pSPDataShare );
  3013. break;
  3014. }
  3015. //
  3016. // unknown
  3017. //
  3018. default:
  3019. {
  3020. DPFX(DPFPREP, 0, "ShareEndpointInfo called with shared SP 0x%p in unrecognized state %u!",
  3021. pSPDataShare, pSPDataShare->GetState() );
  3022. DNASSERT( FALSE );
  3023. hr = DPNERR_GENERIC;
  3024. break;
  3025. }
  3026. }
  3027. pSPDataShare->Unlock();
  3028. if ( hr != DPN_OK )
  3029. {
  3030. goto Failure;
  3031. }
  3032. #if ((! defined(DPNBUILD_NOIPV6)) || (! defined(DPNBUILD_NOIPX)))
  3033. //
  3034. // We can also double check that it's not the wrong type (IP vs. IPX).
  3035. //
  3036. sShareSPType = pSPDataShare->GetType();
  3037. #endif // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  3038. //
  3039. // Make sure the source SP has a valid socket data object, and get a
  3040. // reference to it. Don't create it if it didn't exist, though.
  3041. //
  3042. pSPDataShare->Lock();
  3043. pSocketData = pSPDataShare->GetSocketData();
  3044. if (pSocketData == NULL)
  3045. {
  3046. pSPDataShare->Unlock();
  3047. DPFX(DPFPREP, 0, "Cannot share endpoint info, shared SP has not created its own endpoint information yet!" );
  3048. hr = DPNERR_NOTREADY;
  3049. goto Failure;
  3050. }
  3051. pSocketData->AddRef();
  3052. pSPDataShare->Unlock();
  3053. IDP8ServiceProvider_Release( pShareEndpointInfoData->pDP8ServiceProvider );
  3054. fShareInterfaceReferenceAdded = FALSE;
  3055. //
  3056. // Validate the local SP's state
  3057. //
  3058. pSPData->Lock();
  3059. // Trust protocol to call us only in the initialized state
  3060. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  3061. #if ((! defined(DPNBUILD_NOIPV6)) || (! defined(DPNBUILD_NOIPX)))
  3062. if (pSPData->GetType() != sShareSPType)
  3063. {
  3064. pSPData->Unlock();
  3065. DPFX(DPFPREP, 0, "ShareEndpointInfo called on different SP types (0x%p == state %u, 0x%p == state %u)!",
  3066. pSPData, pSPData->GetState(), pSPDataShare, pSPDataShare->GetState() );
  3067. hr = DPNERR_INVALIDINTERFACE;
  3068. goto Failure;
  3069. }
  3070. #endif // ! DPNBUILD_NOIPV6 or ! DPNBUILD_NOIPX
  3071. //
  3072. // If we're here, the provider is initialized and of the right type.
  3073. // Make sure we do not already have "endpoint info" of our own.
  3074. //
  3075. if (pSPData->GetSocketData() != NULL)
  3076. {
  3077. pSPData->Unlock();
  3078. DPFX(DPFPREP, 0, "Cannot share endpoint info, SP has already created its own endpoint information!" );
  3079. hr = DPNERR_ALREADYINITIALIZED;
  3080. goto Failure;
  3081. }
  3082. //
  3083. // Transfer the local reference to the SP data object.
  3084. //
  3085. pSPData->SetSocketData(pSocketData);
  3086. pSocketData = NULL;
  3087. pSPData->Unlock();
  3088. DNASSERT( hr == DPN_OK );
  3089. Exit:
  3090. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  3091. return hr;
  3092. Failure:
  3093. if ( pSocketData != NULL )
  3094. {
  3095. pSocketData->Release();
  3096. pSocketData = NULL;
  3097. }
  3098. if ( fShareInterfaceReferenceAdded != FALSE )
  3099. {
  3100. IDP8ServiceProvider_Release( pThis );
  3101. fShareInterfaceReferenceAdded = FALSE;
  3102. }
  3103. goto Exit;
  3104. }
  3105. //**********************************************************************
  3106. //**********************************************************************
  3107. // ------------------------------
  3108. // DNSP_GetEndpointByAddress - retrieves an endpoint, given its addressing information
  3109. //
  3110. // Entry: Pointer DNSP Interface
  3111. // Pointer to input data
  3112. //
  3113. // Exit: Error code
  3114. // ------------------------------
  3115. #undef DPF_MODNAME
  3116. #define DPF_MODNAME "DNSP_GetEndpointByAddress"
  3117. STDMETHODIMP DNSP_GetEndpointByAddress( IDP8ServiceProvider* pThis, SPGETENDPOINTBYADDRESSDATA *pGetEndpointByAddressData )
  3118. {
  3119. HRESULT hr;
  3120. CSPData *pSPData;
  3121. DPFX(DPFPREP, 2, "Parameters: (0x%p, 0x%p)", pThis, pGetEndpointByAddressData);
  3122. DNASSERT( pThis != NULL );
  3123. DNASSERT( pGetEndpointByAddressData != NULL );
  3124. DNASSERT( pGetEndpointByAddressData->pAddressHost != NULL );
  3125. DNASSERT( pGetEndpointByAddressData->pAddressDeviceInfo != NULL );
  3126. DNASSERT( pGetEndpointByAddressData->dwFlags == 0 );
  3127. //
  3128. // initialize
  3129. //
  3130. hr = DPN_OK;
  3131. pSPData = CSPData::SPDataFromCOMInterface( pThis );
  3132. //
  3133. // no need to tell thread pool to lock the thread count for this function.
  3134. //
  3135. // Trust protocol to call us only in the initialized state
  3136. DNASSERT( pSPData->GetState() == SPSTATE_INITIALIZED );
  3137. //
  3138. // Look up the endpoint handle and context
  3139. //
  3140. hr = pSPData->GetEndpointFromAddress(pGetEndpointByAddressData->pAddressHost,
  3141. pGetEndpointByAddressData->pAddressDeviceInfo,
  3142. &pGetEndpointByAddressData->hEndpoint,
  3143. &pGetEndpointByAddressData->pvEndpointContext);
  3144. if (hr != DPN_OK)
  3145. {
  3146. DPFX(DPFPREP, 0, "Couldn't get endpoint from address (err = 0x%lx)!", hr);
  3147. goto Failure;
  3148. }
  3149. Exit:
  3150. DPFX(DPFPREP, 2, "Returning: [0x%lx]", hr);
  3151. return hr;
  3152. Failure:
  3153. goto Exit;
  3154. }
  3155. //**********************************************************************
  3156. #endif // ! DPNBUILD_NOMULTICAST