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.

3536 lines
97 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: paramval.cpp
  6. * Content: DirectPlat8 Parameter Validation helper routines
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 02/28/00 rmt Created
  12. * 04/13/2000 rmt More parameter validation
  13. * 04/17/00 rmt More param validation
  14. * rmt Added DPF_MODNAMES
  15. * 04/18/00 rmt Fix: Bug #32669
  16. * 04/21/00 rmt Fix: Bug #33056 Param validation preventing read-only buffers
  17. * 04/25/00 rmt Fix: Bug #33190 and fixed param validation to allow nodpnsvr flag
  18. * 04/28/00 mjn Allow NULL Device Address in DN_ValidateConnect()
  19. * 05/03/00 mjn Added DPNENUMSERVICEPROVIDERS_ALL flag
  20. * 05/31/00 mjn Added operation specific SYNC flags
  21. * mjn Fix EnumHosts param validation for timeout and enum period
  22. * 06/12/00 mjn Removed validation of DPNSEND_ENCRYPTED,DPNSEND_SIGNED,DPNGROUP_MULTICAST,DPNENUM_GROUP_MULTICAST flags
  23. * 06/27/00 mjn Allow priorities to be specified to GetSendQueueInfo() API calls
  24. * mjn Added DPNSEND_NONSEQUENTIAL flag to Send/SendTo
  25. * mjn Allow mix-n-match of priorities in GetSendQueueInfo() API call
  26. * 07/09/00 mjn Ensure non-null addresses specified to Host
  27. * 07/12/00 rmt Bug #39018 - Need param validation on RegisterLobby() API call
  28. * 07/19/00 aarono Bug #39751 - fix parameter validation for CancelAsyncOperation
  29. * 07/20/00 mjn Fix validation of pvApplicationReservedData in DN_ValidHostAppDesc()
  30. * 07/26/00 mjn Fix param validation for Connect(),SendTo(),DestroyGroup(),AddPlayerToGroup()
  31. * RemovePlayerFromGroup(),SetGroupInfo()
  32. * 07/31/00 mjn Require dwFlags for DN_ValidateEnumClientsAndGroups()
  33. * 08/03/00 rmt Bug #41244 - Wrong return codes -- part 2
  34. * 08/04/00 mjn Added dwFlags to DN_ValidateGetConnectionInfoHelper()
  35. * 08/05/00 mjn Allow NULL Host address to EnumHosts()
  36. * 08/08/00 rmt Minor parameter validation error
  37. * 08/20/00 mjn Prevent 0 length send buffer
  38. * 09/04/00 mjn Ensure pvReservedData in application descriptions is NULL
  39. * 09/16/00 rmt Bug #45175 - DPLAY8: [A/V] Param validation prevents non-null async handle w/ no complete
  40. * 11/27/00 mjn Fixed spew for async op handle pointers and changed verification order
  41. * 07/22/01 mjn Added DPNBUILD_NOHOSTMIGRATE compile flag
  42. * 07/24/01 mjn Added DPNBUILD_NOPARAMVAL compile flag
  43. * 07/24/01 mjn Added DPNBUILD_NOSERVER compile flag
  44. * 10/08/01 vanceo Added multicast interface method validation
  45. *@@END_MSINTERNAL
  46. *
  47. ***************************************************************************/
  48. #include "dncorei.h"
  49. #ifndef DPNBUILD_NOPARAMVAL
  50. #ifndef DPNBUILD_NOVOICE
  51. extern IDirectPlayVoiceTransportVtbl DN_VoiceTbl;
  52. #endif // DPNBUILD_NOVOICE
  53. #undef DPF_MODNAME
  54. #define DPF_MODNAME "DN_ValidateDestroyPlayer"
  55. HRESULT DN_ValidateDestroyPlayer(PVOID pInterface,
  56. const DPNID dnid,
  57. const void *const pvDestroyData,
  58. const DWORD dwDestroyDataSize,
  59. const DWORD dwFlags)
  60. {
  61. if( !IsValidDirectPlay8Object( pInterface ) )
  62. {
  63. DPFX(DPFPREP, 0, "Invalid object" );
  64. return DPNERR_INVALIDOBJECT;
  65. }
  66. if( dnid == DPNID_ALL_PLAYERS_GROUP )
  67. {
  68. DPFERR( "Cannot get player context for all players group" );
  69. return DPNERR_INVALIDPLAYER;
  70. }
  71. if( dwDestroyDataSize > 0 &&
  72. (pvDestroyData == NULL || !DNVALID_READPTR( pvDestroyData, dwDestroyDataSize ) ) )
  73. {
  74. DPFERR( "Invalid pointer specified for destroy data" );
  75. return DPNERR_INVALIDPOINTER;
  76. }
  77. if( dwFlags != 0 )
  78. {
  79. DPFERR( "Invalid flags specified for destroy player" );
  80. return DPNERR_INVALIDFLAGS;
  81. }
  82. return DPN_OK;
  83. }
  84. #undef DPF_MODNAME
  85. #define DPF_MODNAME "DN_ValidateReturnBuffer"
  86. HRESULT DN_ValidateReturnBuffer(PVOID pInterface,
  87. const DPNHANDLE hBufferHandle,
  88. const DWORD dwFlags)
  89. {
  90. if( !IsValidDirectPlay8Object( pInterface ) )
  91. {
  92. DPFX(DPFPREP, 0, "Invalid object" );
  93. return DPNERR_INVALIDOBJECT;
  94. }
  95. if( hBufferHandle == NULL )
  96. {
  97. DPFERR( "Invalid handle specified" );
  98. return DPNERR_INVALIDHANDLE;
  99. }
  100. if( dwFlags != 0 )
  101. {
  102. DPFERR( "Invalid flags specified" );
  103. return DPNERR_INVALIDFLAGS;
  104. }
  105. return DPN_OK;
  106. }
  107. #undef DPF_MODNAME
  108. #define DPF_MODNAME "DN_ValidateGetPlayerContext"
  109. HRESULT DN_ValidateGetPlayerContext(PVOID pInterface,
  110. const DPNID dpnid,
  111. PVOID *const ppvPlayerContext,
  112. const DWORD dwFlags)
  113. {
  114. if( !IsValidDirectPlay8Object( pInterface ) )
  115. {
  116. DPFX(DPFPREP, 0, "Invalid object" );
  117. return DPNERR_INVALIDOBJECT;
  118. }
  119. if( dpnid == DPNID_ALL_PLAYERS_GROUP )
  120. {
  121. DPFERR( "Cannot get player context for all players group" );
  122. return DPNERR_INVALIDPLAYER;
  123. }
  124. if( ppvPlayerContext == NULL ||
  125. !DNVALID_WRITEPTR( ppvPlayerContext, sizeof( PVOID ) ) )
  126. {
  127. DPFERR( "Invalid pointer specified for player context" );
  128. return DPNERR_INVALIDPOINTER;
  129. }
  130. if (dwFlags != 0)
  131. {
  132. DPFERR("Invalid flags specified");
  133. return(DPNERR_INVALIDFLAGS);
  134. }
  135. return DPN_OK;
  136. }
  137. #undef DPF_MODNAME
  138. #define DPF_MODNAME "DN_ValidateGetGroupContext"
  139. HRESULT DN_ValidateGetGroupContext(PVOID pInterface,
  140. const DPNID dpnid,
  141. PVOID *const ppvGroupContext,
  142. const DWORD dwFlags)
  143. {
  144. if( !IsValidDirectPlay8Object( pInterface ) )
  145. {
  146. DPFX(DPFPREP, 0, "Invalid object" );
  147. return DPNERR_INVALIDOBJECT;
  148. }
  149. if( dpnid == DPNID_ALL_PLAYERS_GROUP )
  150. {
  151. DPFERR( "Cannot get group context for all players group" );
  152. return DPNERR_INVALIDGROUP;
  153. }
  154. if( ppvGroupContext == NULL ||
  155. !DNVALID_WRITEPTR( ppvGroupContext, sizeof( PVOID ) ) )
  156. {
  157. DPFERR( "Invalid pointer specified for group context" );
  158. return DPNERR_INVALIDPOINTER;
  159. }
  160. if (dwFlags != 0)
  161. {
  162. DPFERR("Invalid flags specified");
  163. return(DPNERR_INVALIDFLAGS);
  164. }
  165. return DPN_OK;
  166. }
  167. #ifndef DPNBUILD_NOLOBBY
  168. #undef DPF_MODNAME
  169. #define DPF_MODNAME "DN_ValidateRegisterLobby"
  170. HRESULT DN_ValidateRegisterLobby(PVOID pInterface,
  171. const DPNHANDLE dpnhLobbyConnection,
  172. const IDirectPlay8LobbiedApplication *const pIDP8LobbiedApplication,
  173. const DWORD dwFlags)
  174. {
  175. if( !IsValidDirectPlay8Object( pInterface ) )
  176. {
  177. DPFX(DPFPREP, 0, "Invalid object" );
  178. return DPNERR_INVALIDOBJECT;
  179. }
  180. if( pIDP8LobbiedApplication != NULL &&
  181. !DNVALID_READPTR( pIDP8LobbiedApplication, sizeof( IDirectPlay8LobbiedApplication * ) ) )
  182. {
  183. DPFERR( "Invalid interface pointer specified for register lobby" );
  184. return DPNERR_INVALIDPOINTER;
  185. }
  186. if( dwFlags == 0 )
  187. {
  188. DPFERR( "You must specify either DPNLOBBY_REGISTER or DPNLOBBY_UNREGISTER" );
  189. return DPNERR_INVALIDFLAGS;
  190. }
  191. if( (dwFlags & DPNLOBBY_REGISTER) &&
  192. (dwFlags & DPNLOBBY_UNREGISTER) )
  193. {
  194. DPFERR( "You cannot specify both register and UNREGISTER" );
  195. return DPNERR_INVALIDPARAM;
  196. }
  197. if( dwFlags & ~(DPNLOBBY_REGISTER | DPNLOBBY_UNREGISTER) )
  198. {
  199. DPFERR( "Invalid flags specified" );
  200. return DPNERR_INVALIDFLAGS;
  201. }
  202. if( dwFlags & DPNLOBBY_REGISTER )
  203. {
  204. if( dpnhLobbyConnection == 0 )
  205. {
  206. DPFX(DPFPREP, 0, "Invalid handle" );
  207. return DPNERR_INVALIDHANDLE;
  208. }
  209. if( !pIDP8LobbiedApplication )
  210. {
  211. DPFERR( "You must specify a lobby application interface to use" );
  212. return DPNERR_INVALIDPOINTER;
  213. }
  214. }
  215. else
  216. {
  217. if( dpnhLobbyConnection != 0 || pIDP8LobbiedApplication != NULL )
  218. {
  219. DPFX(DPFPREP, 0, "When unregistering you must specify 0 for handle and NULL for lobbiedapp" );
  220. return DPNERR_INVALIDPARAM;
  221. }
  222. }
  223. return DPN_OK;
  224. }
  225. #endif // ! DPNBUILD_NOLOBBY
  226. #undef DPF_MODNAME
  227. #define DPF_MODNAME "DN_ValidateTerminateSession"
  228. HRESULT DN_ValidateTerminateSession(PVOID pInterface,
  229. const void *const pvTerminateData,
  230. const DWORD dwTerminateDataSize,
  231. const DWORD dwFlags)
  232. {
  233. if( !IsValidDirectPlay8Object( pInterface ) )
  234. {
  235. DPFX(DPFPREP, 0, "Invalid object" );
  236. return DPNERR_INVALIDOBJECT;
  237. }
  238. if( dwTerminateDataSize > 0 &&
  239. (pvTerminateData == NULL || !DNVALID_READPTR( pvTerminateData, dwTerminateDataSize ) ) )
  240. {
  241. DPFERR( "Invalid pointer specified for terminate data" );
  242. return DPNERR_INVALIDPOINTER;
  243. }
  244. if( dwFlags != 0 )
  245. {
  246. DPFERR( "Invalid flags specified" );
  247. return DPNERR_INVALIDFLAGS;
  248. }
  249. return DPN_OK;
  250. }
  251. #undef DPF_MODNAME
  252. #define DPF_MODNAME "DN_ValidateGetHostAddress"
  253. HRESULT DN_ValidateGetHostAddress(PVOID pInterface,
  254. IDirectPlay8Address **const prgpAddress,
  255. DWORD *const pcAddress,
  256. const DWORD dwFlags)
  257. {
  258. if( !IsValidDirectPlay8Object( pInterface ) )
  259. {
  260. DPFX(DPFPREP, 0, "Invalid object" );
  261. return DPNERR_INVALIDOBJECT;
  262. }
  263. if( pcAddress == NULL || !DNVALID_WRITEPTR( pcAddress, sizeof( DWORD ) ) )
  264. {
  265. DPFX(DPFPREP, 0, "Invalid pointer specified for address count" );
  266. return DPNERR_INVALIDPOINTER;
  267. }
  268. if( *pcAddress > 0 &&
  269. (prgpAddress == NULL || !DNVALID_WRITEPTR( prgpAddress, sizeof( IDirectPlay8Address * ) * (*pcAddress) ) ) )
  270. {
  271. DPFERR( "Invalid pointer specified for address" );
  272. return DPNERR_INVALIDPOINTER;
  273. }
  274. if (dwFlags != 0)
  275. {
  276. DPFERR("Invalid flags specified");
  277. return(DPNERR_INVALIDFLAGS);
  278. }
  279. return DPN_OK;
  280. }
  281. #ifndef DPNBUILD_NOSERVER
  282. #undef DPF_MODNAME
  283. #define DPF_MODNAME "DN_ValidateGetClientAddress"
  284. HRESULT DN_ValidateGetClientAddress(IDirectPlay8Server *pInterface,
  285. const DPNID dpnid,
  286. IDirectPlay8Address **const ppAddress,
  287. const DWORD dwFlags)
  288. {
  289. if( !IsValidDirectPlay8Object( pInterface ) )
  290. {
  291. DPFX(DPFPREP, 0, "Invalid object" );
  292. return DPNERR_INVALIDOBJECT;
  293. }
  294. if( dpnid == DPNID_ALL_PLAYERS_GROUP )
  295. {
  296. DPFERR( "Cannot get client address for ALL" );
  297. return DPNERR_INVALIDPLAYER;
  298. }
  299. if( ppAddress == NULL || !DNVALID_WRITEPTR( ppAddress, sizeof( IDirectPlay8Address * ) ) )
  300. {
  301. DPFERR( "Invalid pointer specified for address" );
  302. return DPNERR_INVALIDPOINTER;
  303. }
  304. if (dwFlags != 0)
  305. {
  306. DPFERR("Invalid flags specified");
  307. return DPNERR_INVALIDFLAGS;
  308. }
  309. return DPN_OK;
  310. }
  311. #endif // DPNBUILD_NOSERVER
  312. #ifndef DPNBUILD_NOSERVER
  313. #undef DPF_MODNAME
  314. #define DPF_MODNAME "DN_ValidateGetClientInfo"
  315. HRESULT DN_ValidateGetClientInfo(IDirectPlay8Server *pInterface,
  316. const DPNID dpnid,
  317. DPN_PLAYER_INFO *const pdpnPlayerInfo,
  318. DWORD *const pdwSize,
  319. const DWORD dwFlags)
  320. {
  321. HRESULT hResultCode;
  322. if( !IsValidDirectPlay8Object( pInterface ) )
  323. {
  324. DPFX(DPFPREP, 0, "Invalid object" );
  325. return DPNERR_INVALIDOBJECT;
  326. }
  327. if( dpnid == DPNID_ALL_PLAYERS_GROUP )
  328. {
  329. DPFERR( "Cannot get client info for ALL" );
  330. return DPNERR_INVALIDPLAYER;
  331. }
  332. if( pdwSize == NULL || !DNVALID_WRITEPTR( pdwSize, sizeof( DWORD ) ) )
  333. {
  334. DPFERR( "Error validating size param, invalid pointer" );
  335. return DPNERR_INVALIDPOINTER;
  336. }
  337. if( *pdwSize &&
  338. (pdpnPlayerInfo == NULL || !DNVALID_WRITEPTR( pdpnPlayerInfo, *pdwSize ) ) )
  339. {
  340. DPFERR( "Error validating player info buffer, invalid pointer" );
  341. return DPNERR_INVALIDPOINTER;
  342. }
  343. if( pdpnPlayerInfo != NULL )
  344. {
  345. if( FAILED( hResultCode = DN_ValidPlayerInfo( pdpnPlayerInfo, FALSE ) ) )
  346. {
  347. DPFERR( "Error validating player info" );
  348. return hResultCode;
  349. }
  350. }
  351. if( dwFlags != 0 )
  352. {
  353. DPFERR( "Invalid flags specified" );
  354. return DPNERR_INVALIDFLAGS;
  355. }
  356. return DPN_OK;
  357. }
  358. #endif // DPNBUILD_NOSERVER
  359. #ifndef DPNBUILD_NOSERVER
  360. #undef DPF_MODNAME
  361. #define DPF_MODNAME "DN_ValidateSetServerInfo"
  362. HRESULT DN_ValidateSetServerInfo(IDirectPlay8Server *pInterface,
  363. const DPN_PLAYER_INFO *const pdpnPlayerInfo,
  364. PVOID const pvAsyncContext,
  365. DPNHANDLE *const phAsyncHandle,
  366. const DWORD dwFlags)
  367. {
  368. HRESULT hResultCode;
  369. if( !IsValidDirectPlay8Object( pInterface ) )
  370. {
  371. DPFX(DPFPREP, 0, "Invalid object" );
  372. return DPNERR_INVALIDOBJECT;
  373. }
  374. if( FAILED( hResultCode = DN_ValidPlayerInfo( pdpnPlayerInfo, TRUE ) ) )
  375. {
  376. DPFERR( "Error validating player info" );
  377. return hResultCode;
  378. }
  379. if( dwFlags & ~(DPNSETSERVERINFO_SYNC) )
  380. {
  381. DPFERR("Invalid flags specified" );
  382. return( DPNERR_INVALIDFLAGS );
  383. }
  384. if( dwFlags & DPNSETSERVERINFO_SYNC )
  385. {
  386. if( phAsyncHandle != NULL )
  387. {
  388. DPFERR( "You cannot specify an async handle if op is synchronous" );
  389. return( DPNERR_INVALIDPARAM );
  390. }
  391. }
  392. else
  393. {
  394. if( phAsyncHandle == NULL )
  395. {
  396. DPFERR( "You MUST specify a valid async handle w/async ops" );
  397. return( DPNERR_INVALIDPARAM );
  398. }
  399. if( !DNVALID_WRITEPTR( phAsyncHandle, sizeof( DPNHANDLE ) ) )
  400. {
  401. DPFERR("Invalid async handle pointer specified" );
  402. return( DPNERR_INVALIDPOINTER );
  403. }
  404. }
  405. return DPN_OK;
  406. }
  407. #endif // DPNBUILD_NOSERVER
  408. #undef DPF_MODNAME
  409. #define DPF_MODNAME "DN_ValidateSetPeerInfo"
  410. HRESULT DN_ValidateSetPeerInfo(IDirectPlay8Peer *pInterface,
  411. const DPN_PLAYER_INFO *const pdpnPlayerInfo,
  412. PVOID const pvAsyncContext,
  413. DPNHANDLE *const phAsyncHandle,
  414. const DWORD dwFlags)
  415. {
  416. HRESULT hResultCode;
  417. if( !IsValidDirectPlay8Object( pInterface ) )
  418. {
  419. DPFX(DPFPREP, 0, "Invalid object" );
  420. return DPNERR_INVALIDOBJECT;
  421. }
  422. if( FAILED( hResultCode = DN_ValidPlayerInfo( pdpnPlayerInfo, TRUE ) ) )
  423. {
  424. DPFERR( "Error validating player info" );
  425. return hResultCode;
  426. }
  427. if( dwFlags & ~(DPNSETPEERINFO_SYNC) )
  428. {
  429. DPFERR("Invalid flags specified" );
  430. return( DPNERR_INVALIDFLAGS );
  431. }
  432. if( dwFlags & DPNSETPEERINFO_SYNC )
  433. {
  434. if( phAsyncHandle != NULL )
  435. {
  436. DPFERR( "You cannot specify an async handle if op is synchronous" );
  437. return( DPNERR_INVALIDPARAM );
  438. }
  439. }
  440. else
  441. {
  442. if( phAsyncHandle == NULL )
  443. {
  444. DPFERR( "You MUST specify a valid async handle w/async ops" );
  445. return( DPNERR_INVALIDPARAM );
  446. }
  447. if( !DNVALID_WRITEPTR( phAsyncHandle, sizeof( DPNHANDLE ) ) )
  448. {
  449. DPFERR("Invalid async handle pointer specified" );
  450. return( DPNERR_INVALIDPOINTER );
  451. }
  452. }
  453. return DPN_OK;
  454. }
  455. #undef DPF_MODNAME
  456. #define DPF_MODNAME "DN_ValidateGetPeerInfo"
  457. HRESULT DN_ValidateGetPeerInfo(IDirectPlay8Peer *pInterface,
  458. const DPNID dpnid,
  459. DPN_PLAYER_INFO *const pdpnPlayerInfo,
  460. DWORD *const pdwSize,
  461. const DWORD dwFlags)
  462. {
  463. HRESULT hResultCode;
  464. if( !IsValidDirectPlay8Object( pInterface ) )
  465. {
  466. DPFX(DPFPREP, 0, "Invalid object" );
  467. return DPNERR_INVALIDOBJECT;
  468. }
  469. if( dpnid == DPNID_ALL_PLAYERS_GROUP )
  470. {
  471. DPFERR( "Cannot get peer info for ALL" );
  472. return DPNERR_INVALIDPLAYER;
  473. }
  474. if( pdwSize == NULL || !DNVALID_WRITEPTR( pdwSize, sizeof( DWORD ) ) )
  475. {
  476. DPFERR( "Error validating size param, invalid pointer" );
  477. return DPNERR_INVALIDPOINTER;
  478. }
  479. if( *pdwSize &&
  480. (pdpnPlayerInfo == NULL || !DNVALID_WRITEPTR( pdpnPlayerInfo, *pdwSize ) ) )
  481. {
  482. DPFERR( "Error validating player info buffer, invalid pointer" );
  483. return DPNERR_INVALIDPOINTER;
  484. }
  485. if( pdpnPlayerInfo != NULL )
  486. {
  487. if( FAILED( hResultCode = DN_ValidPlayerInfo( pdpnPlayerInfo, FALSE ) ) )
  488. {
  489. DPFERR( "Error validating player info" );
  490. return hResultCode;
  491. }
  492. }
  493. if( dwFlags != 0 )
  494. {
  495. DPFERR( "Invalid flags specified" );
  496. return DPNERR_INVALIDFLAGS;
  497. }
  498. return DPN_OK;
  499. }
  500. #undef DPF_MODNAME
  501. #define DPF_MODNAME "DN_ValidateGetPeerAddress"
  502. HRESULT DN_ValidateGetPeerAddress(IDirectPlay8Peer *pInterface,
  503. const DPNID dpnid,
  504. IDirectPlay8Address **const ppAddress,
  505. const DWORD dwFlags)
  506. {
  507. if( !IsValidDirectPlay8Object( pInterface ) )
  508. {
  509. DPFX(DPFPREP, 0, "Invalid object" );
  510. return DPNERR_INVALIDOBJECT;
  511. }
  512. if( dpnid == DPNID_ALL_PLAYERS_GROUP )
  513. {
  514. DPFERR( "Cannot get peer address for ALL" );
  515. return DPNERR_INVALIDPLAYER;
  516. }
  517. if( ppAddress == NULL || !DNVALID_WRITEPTR( ppAddress, sizeof( IDirectPlay8Address * ) ) )
  518. {
  519. DPFERR( "Invalid pointer specified for address" );
  520. return DPNERR_INVALIDPOINTER;
  521. }
  522. if (dwFlags != 0)
  523. {
  524. DPFERR("Invalid flags specified");
  525. return DPNERR_INVALIDFLAGS;
  526. }
  527. return DPN_OK;
  528. }
  529. #undef DPF_MODNAME
  530. #define DPF_MODNAME "DN_ValidateGetServerAddress"
  531. HRESULT DN_ValidateGetServerAddress(IDirectPlay8Client *pInterface,
  532. IDirectPlay8Address **const ppAddress,
  533. const DWORD dwFlags)
  534. {
  535. if( !IsValidDirectPlay8Object( pInterface ) )
  536. {
  537. DPFX(DPFPREP, 0, "Invalid object" );
  538. return DPNERR_INVALIDOBJECT;
  539. }
  540. if( ppAddress == NULL || !DNVALID_WRITEPTR( ppAddress, sizeof( IDirectPlay8Address * ) ) )
  541. {
  542. DPFERR( "Invalid pointer specified for address" );
  543. return DPNERR_INVALIDPOINTER;
  544. }
  545. if( dwFlags != 0 )
  546. {
  547. DPFERR( "Invalid flags specified" );
  548. return( DPNERR_INVALIDFLAGS );
  549. }
  550. return DPN_OK;
  551. }
  552. #undef DPF_MODNAME
  553. #define DPF_MODNAME "DN_ValidateGetHostSendQueueInfo"
  554. HRESULT DN_ValidateGetHostSendQueueInfo(IDirectPlay8Client *pInterface,
  555. DWORD *const pdwNumMsgs,
  556. DWORD *const pdwNumBytes,
  557. const DWORD dwFlags )
  558. {
  559. if( !IsValidDirectPlay8Object( pInterface ) )
  560. {
  561. DPFX(DPFPREP, 0, "Invalid object" );
  562. return DPNERR_INVALIDOBJECT;
  563. }
  564. if( pdwNumMsgs != NULL &&
  565. !DNVALID_WRITEPTR( pdwNumMsgs, sizeof( DWORD ) ) )
  566. {
  567. DPFERR("Invalid num messages specified" );
  568. return( DPNERR_INVALIDPOINTER );
  569. }
  570. if( pdwNumBytes != NULL &&
  571. !DNVALID_WRITEPTR( pdwNumBytes, sizeof( DWORD ) ) )
  572. {
  573. DPFERR("Invalid num bytes specified" );
  574. return( DPNERR_INVALIDPOINTER );
  575. }
  576. if( pdwNumBytes == NULL && pdwNumMsgs == NULL )
  577. {
  578. DPFERR("Must request at least one of num bytes and num messages" );
  579. return( DPNERR_INVALIDPARAM );
  580. }
  581. if( dwFlags & ~(DPNGETSENDQUEUEINFO_PRIORITY_HIGH | DPNGETSENDQUEUEINFO_PRIORITY_LOW | DPNGETSENDQUEUEINFO_PRIORITY_NORMAL) )
  582. {
  583. DPFERR( "Invalid flags specified" );
  584. return( DPNERR_INVALIDFLAGS );
  585. }
  586. #ifndef DPNBUILD_NOMULTICAST
  587. DIRECTNETOBJECT *pdnObject;
  588. // The multicast interface doesn't support low or high priority.
  589. pdnObject = (DIRECTNETOBJECT*) GET_OBJECT_FROM_INTERFACE(pInterface);
  590. if (pdnObject->dwFlags & DN_OBJECT_FLAG_MULTICAST)
  591. {
  592. if( dwFlags & (DPNGETSENDQUEUEINFO_PRIORITY_HIGH | DPNGETSENDQUEUEINFO_PRIORITY_LOW) )
  593. {
  594. DPFERR( "Invalid flags specified, multicast interface does not support high or low priority sends" );
  595. return( DPNERR_INVALIDFLAGS );
  596. }
  597. }
  598. #endif // ! DPNBUILD_NOMULTICAST
  599. return DPN_OK;
  600. }
  601. #undef DPF_MODNAME
  602. #define DPF_MODNAME "DN_ValidateGetServerInfo"
  603. HRESULT DN_ValidateGetServerInfo(IDirectPlay8Client *pInterface,
  604. DPN_PLAYER_INFO *const pdpnPlayerInfo,
  605. DWORD *const pdwSize,
  606. const DWORD dwFlags)
  607. {
  608. HRESULT hResultCode;
  609. if( !IsValidDirectPlay8Object( pInterface ) )
  610. {
  611. DPFX(DPFPREP, 0, "Invalid object" );
  612. return DPNERR_INVALIDOBJECT;
  613. }
  614. if( pdwSize == NULL || !DNVALID_WRITEPTR( pdwSize, sizeof( DWORD ) ) )
  615. {
  616. DPFERR( "Error validating size param, invalid pointer" );
  617. return DPNERR_INVALIDPOINTER;
  618. }
  619. if( *pdwSize &&
  620. (pdpnPlayerInfo == NULL || !DNVALID_WRITEPTR( pdpnPlayerInfo, *pdwSize ) ) )
  621. {
  622. DPFERR( "Error validating player info buffer, invalid pointer" );
  623. return DPNERR_INVALIDPOINTER;
  624. }
  625. if( pdpnPlayerInfo != NULL )
  626. {
  627. if( FAILED( hResultCode = DN_ValidPlayerInfo( pdpnPlayerInfo, FALSE ) ) )
  628. {
  629. DPFERR( "Error validating player info" );
  630. return hResultCode;
  631. }
  632. }
  633. if( dwFlags != 0 )
  634. {
  635. DPFERR( "Invalid flags specified" );
  636. return DPNERR_INVALIDFLAGS;
  637. }
  638. return DPN_OK;
  639. }
  640. #undef DPF_MODNAME
  641. #define DPF_MODNAME "DN_ValidateSetClientInfo"
  642. HRESULT DN_ValidateSetClientInfo(IDirectPlay8Client *pInterface,
  643. const DPN_PLAYER_INFO *const pdpnPlayerInfo,
  644. const PVOID pvAsyncContext,
  645. DPNHANDLE *const phAsyncHandle,
  646. const DWORD dwFlags)
  647. {
  648. HRESULT hResultCode;
  649. if( !IsValidDirectPlay8Object( pInterface ) )
  650. {
  651. DPFX(DPFPREP, 0, "Invalid object" );
  652. return DPNERR_INVALIDOBJECT;
  653. }
  654. if( FAILED( hResultCode = DN_ValidPlayerInfo( pdpnPlayerInfo, TRUE ) ) )
  655. {
  656. DPFERR("Error validating player info" );
  657. return hResultCode;
  658. }
  659. if( dwFlags & ~(DPNSETCLIENTINFO_SYNC) )
  660. {
  661. DPFERR("Invalid flags specified" );
  662. return( DPNERR_INVALIDFLAGS );
  663. }
  664. if( dwFlags & DPNSETCLIENTINFO_SYNC )
  665. {
  666. if( phAsyncHandle != NULL )
  667. {
  668. DPFERR( "You cannot specify an async handle pointer if op is synchronous" );
  669. return( DPNERR_INVALIDPARAM );
  670. }
  671. }
  672. else
  673. {
  674. if( phAsyncHandle == NULL )
  675. {
  676. DPFERR( "You MUST specify a valid async handle pointer w/async ops" );
  677. return( DPNERR_INVALIDPARAM );
  678. }
  679. if( !DNVALID_WRITEPTR( phAsyncHandle, sizeof( DPNHANDLE ) ) )
  680. {
  681. DPFERR("Invalid async handle pointer specified" );
  682. return( DPNERR_INVALIDPOINTER );
  683. }
  684. }
  685. return DPN_OK;
  686. }
  687. #undef DPF_MODNAME
  688. #define DPF_MODNAME "DN_ValidateGetConnectionInfoHelper"
  689. HRESULT DN_ValidateGetConnectionInfoHelper(PVOID pv,
  690. const DPNID dpnid,
  691. DPN_CONNECTION_INFO *const pdpConnectionInfo,
  692. BOOL fServerPlayer,
  693. const DWORD dwFlags)
  694. {
  695. if( !IsValidDirectPlay8Object( pv ) )
  696. {
  697. DPFX(DPFPREP, 0, "Invalid object" );
  698. return DPNERR_INVALIDOBJECT;
  699. }
  700. if( pdpConnectionInfo == NULL ||
  701. !DNVALID_WRITEPTR( pdpConnectionInfo, sizeof( DPN_CONNECTION_INFO ) ) )
  702. {
  703. DPFX(DPFPREP, 0, "Invalid pointer for connection info" );
  704. return(DPNERR_INVALIDPOINTER);
  705. }
  706. if( pdpConnectionInfo->dwSize != sizeof( DPN_CONNECTION_INFO )
  707. && pdpConnectionInfo->dwSize != sizeof( DPN_CONNECTION_INFO_INTERNAL )
  708. )
  709. {
  710. DPFX(DPFPREP, 0, "Invalid size on connection info structure" );
  711. return(DPNERR_INVALIDPARAM);
  712. }
  713. if (dwFlags != 0)
  714. {
  715. DPFERR("Invalid flags specified");
  716. return(DPNERR_INVALIDFLAGS);
  717. }
  718. return DPN_OK;
  719. }
  720. #undef DPF_MODNAME
  721. #define DPF_MODNAME "DN_ValidateGetSPCaps"
  722. HRESULT DN_ValidateGetSPCaps(PVOID pv,
  723. const GUID * const pguidSP,
  724. DPN_SP_CAPS *const pdnSPCaps,
  725. const DWORD dwFlags)
  726. {
  727. if( !IsValidDirectPlay8Object( pv ) )
  728. {
  729. DPFX(DPFPREP, 0, "Invalid object" );
  730. return(DPNERR_INVALIDOBJECT);
  731. }
  732. #ifndef DPNBUILD_ONLYONESP
  733. if( pguidSP == NULL ||
  734. !DNVALID_READPTR( pguidSP, sizeof( GUID ) ) )
  735. {
  736. DPFERR( "Invalid pointer specified for SP GUID" );
  737. return(DPNERR_INVALIDPOINTER);
  738. }
  739. #endif // ! DPNBUILD_ONLYONESP
  740. if( pdnSPCaps == NULL ||
  741. !DNVALID_WRITEPTR( pdnSPCaps, sizeof( DPN_SP_CAPS ) ) )
  742. {
  743. DPFX(DPFPREP, 0, "Invalid pointer for caps" );
  744. return(DPNERR_INVALIDPOINTER);
  745. }
  746. if( pdnSPCaps->dwSize != sizeof( DPN_SP_CAPS ) )
  747. {
  748. DPFX(DPFPREP, 0, "Invalid size on SP caps structure" );
  749. return(DPNERR_INVALIDPARAM);
  750. }
  751. if (dwFlags != 0)
  752. {
  753. DPFERR("Invalid flags specified");
  754. return(DPNERR_INVALIDFLAGS);
  755. }
  756. return DPN_OK;
  757. }
  758. #undef DPF_MODNAME
  759. #define DPF_MODNAME "DN_ValidateSetSPCaps"
  760. HRESULT DN_ValidateSetSPCaps(PVOID pv,
  761. const GUID * const pguidSP,
  762. const DPN_SP_CAPS *const pdnSPCaps,
  763. const DWORD dwFlags)
  764. {
  765. HRESULT hr;
  766. if( !IsValidDirectPlay8Object( pv ) )
  767. {
  768. DPFX(DPFPREP, 0, "Invalid object" );
  769. return(DPNERR_INVALIDOBJECT);
  770. }
  771. #ifndef DPNBUILD_ONLYONESP
  772. if( pguidSP == NULL ||
  773. !DNVALID_READPTR( pguidSP, sizeof( GUID ) ) )
  774. {
  775. DPFX(DPFPREP, 0, "Invalid pointer to GUID specified" );
  776. return(DPNERR_INVALIDPOINTER);
  777. }
  778. #endif // ! DPNBUILD_ONLYONESP
  779. if(dwFlags){
  780. DPFX(DPFPREP, 0, "Invalid Flags specified, must be zero" );
  781. return DPNERR_INVALIDFLAGS;
  782. }
  783. hr = DN_ValidSPCaps( pdnSPCaps );
  784. if( FAILED( hr ) )
  785. {
  786. DPFX(DPFPREP, 0, "Error validating caps structure hr=[0x%lx]", hr );
  787. return( hr );
  788. }
  789. return DPN_OK;
  790. }
  791. #undef DPF_MODNAME
  792. #define DPF_MODNAME "DN_ValidateGetCaps"
  793. HRESULT DN_ValidateGetCaps(PVOID pv,
  794. DPN_CAPS *const pdnCaps,
  795. const DWORD dwFlags)
  796. {
  797. if( !IsValidDirectPlay8Object( pv ) )
  798. {
  799. DPFX(DPFPREP, 0, "Invalid object" );
  800. return(DPNERR_INVALIDOBJECT);
  801. }
  802. if( pdnCaps == NULL ||
  803. !DNVALID_WRITEPTR( pdnCaps, sizeof( DPN_CAPS ) ) )
  804. {
  805. DPFX(DPFPREP, 0, "Invalid pointer for caps" );
  806. return(DPNERR_INVALIDPOINTER);
  807. }
  808. if( pdnCaps->dwSize != sizeof( DPN_CAPS ) && pdnCaps->dwSize != sizeof( DPN_CAPS_EX ))
  809. {
  810. DPFX(DPFPREP, 0, "Invalid size on caps structure" );
  811. return(DPNERR_INVALIDPARAM);
  812. }
  813. if (dwFlags != 0)
  814. {
  815. DPFERR("Invalid flags specified");
  816. return(DPNERR_INVALIDFLAGS);
  817. }
  818. return DPN_OK;
  819. }
  820. #undef DPF_MODNAME
  821. #define DPF_MODNAME "DN_ValidateSetCaps"
  822. HRESULT DN_ValidateSetCaps(PVOID pv,
  823. const DPN_CAPS *const pdnCaps,
  824. const DWORD dwFlags)
  825. {
  826. HRESULT hResultCode;
  827. if( !IsValidDirectPlay8Object( pv ) )
  828. {
  829. DPFX(DPFPREP, 0, "Invalid object" );
  830. return DPNERR_INVALIDOBJECT;
  831. }
  832. hResultCode = DN_ValidCaps( pdnCaps );
  833. if( FAILED( hResultCode ) )
  834. {
  835. DPFX(DPFPREP, 0, "Error validating caps structure hr=0x%x", hResultCode );
  836. return(hResultCode);
  837. }
  838. if( dwFlags != 0 )
  839. {
  840. DPFX(DPFPREP, 0, "Invalid flags specified" );
  841. return(DPNERR_INVALIDFLAGS);
  842. }
  843. return DPN_OK;
  844. }
  845. #undef DPF_MODNAME
  846. #define DPF_MODNAME "DN_ValidateEnumHosts"
  847. HRESULT DN_ValidateEnumHosts(PVOID pv,
  848. const DPN_APPLICATION_DESC *const pApplicationDesc,
  849. IDirectPlay8Address *const pAddrHost,
  850. IDirectPlay8Address *const pDeviceInfo,
  851. const VOID* const pUserEnumData,
  852. const DWORD dwUserEnumDataSize,
  853. const DWORD dwRetryCount,
  854. const DWORD dwRetryInterval,
  855. const DWORD dwTimeOut,
  856. PVOID const pvAsyncContext,
  857. DPNHANDLE *const pAsyncHandle,
  858. const DWORD dwFlags )
  859. {
  860. #ifndef DPNBUILD_ONLYONESP
  861. HRESULT hResultCode;
  862. GUID guidspHost, guidspDevice;
  863. #endif // ! DPNBUILD_ONLYONESP
  864. if( !IsValidDirectPlay8Object( pv ) )
  865. {
  866. DPFERR("Invalid object specified " );
  867. return( DPNERR_INVALIDOBJECT );
  868. }
  869. if( pApplicationDesc == NULL ||
  870. !DNVALID_READPTR( pApplicationDesc, sizeof( DPN_APPLICATION_DESC ) ) )
  871. {
  872. DPFERR( "Invalid pointer for app desc specified" );
  873. return( DPNERR_INVALIDPOINTER );
  874. }
  875. if( pApplicationDesc->dwSize != sizeof( DPN_APPLICATION_DESC ) )
  876. {
  877. DPFERR( "Invalid size for application desc" );
  878. return( DPNERR_INVALIDPARAM );
  879. }
  880. if ((pApplicationDesc->dwFlags != 0) ||
  881. (pApplicationDesc->dwMaxPlayers != 0) ||
  882. (pApplicationDesc->dwCurrentPlayers != 0) ||
  883. (pApplicationDesc->pvApplicationReservedData != NULL) || (pApplicationDesc->dwApplicationReservedDataSize != 0))
  884. {
  885. DPFERR( "Cannot specify flags, max players, current players, or application reserved data in application desc" );
  886. return DPNERR_INVALIDPARAM;
  887. }
  888. if (pApplicationDesc->dwReservedDataSize > 0)
  889. {
  890. if ((pApplicationDesc->pvReservedData == NULL) ||
  891. (! DNVALID_READPTR(pApplicationDesc->pvReservedData, pApplicationDesc->dwReservedDataSize)))
  892. {
  893. DPFERR("Invalid pointer specified for application desc reserved data");
  894. return DPNERR_INVALIDPARAM;
  895. }
  896. //
  897. // Make sure it's a type we know about and that it's valid.
  898. //
  899. if ((pApplicationDesc->dwReservedDataSize == DPN_MAX_APPDESC_RESERVEDDATA_SIZE) &&
  900. (*((DWORD*) pApplicationDesc->pvReservedData) == SPSESSIONDATAINFO_XNET))
  901. {
  902. SPSESSIONDATA_XNET * pSessionDataXNet;
  903. BYTE bCompare;
  904. BYTE * pbCurrent;
  905. DWORD dwBytesRemaining;
  906. pSessionDataXNet = (SPSESSIONDATA_XNET*) pApplicationDesc->pvReservedData;
  907. bCompare = ((BYTE*) (&pSessionDataXNet->ullKeyID))[1] ^ ((BYTE*) (&pSessionDataXNet->guidKey))[2];
  908. pbCurrent = (BYTE*) (pSessionDataXNet + 1);
  909. dwBytesRemaining = DPN_MAX_APPDESC_RESERVEDDATA_SIZE - sizeof(SPSESSIONDATA_XNET);
  910. while (dwBytesRemaining > 0)
  911. {
  912. if (*pbCurrent != bCompare)
  913. {
  914. DPFERR("Unsupported application desc reserved data");
  915. return DPNERR_INVALIDPARAM;
  916. }
  917. dwBytesRemaining--;
  918. pbCurrent++;
  919. }
  920. }
  921. else
  922. {
  923. DPFERR("Unsupported application desc reserved data");
  924. return DPNERR_INVALIDPARAM;
  925. }
  926. }
  927. else
  928. {
  929. if (pApplicationDesc->pvReservedData != NULL)
  930. {
  931. DPFERR("Application desc reserved data pointer should be NULL if reserved data size is 0");
  932. return DPNERR_INVALIDPARAM;
  933. }
  934. }
  935. if (pAddrHost != NULL)
  936. {
  937. if( !DNVALID_READPTR( pAddrHost, sizeof( IDirectPlay8Address * ) ) )
  938. {
  939. DPFERR( "Invalid pointer specified for host address" );
  940. return( DPNERR_INVALIDPOINTER );
  941. }
  942. #ifndef DPNBUILD_ONLYONESP
  943. if( FAILED( hResultCode = IDirectPlay8Address_GetSP( pAddrHost, &guidspHost ) ) )
  944. {
  945. DPFX(DPFPREP, 0, "Unable to get SP for specified address hr=0x%x", hResultCode );
  946. return( DPNERR_INVALIDHOSTADDRESS );
  947. }
  948. #endif // ! DPNBUILD_ONLYONESP
  949. }
  950. #if ((defined(DPNBUILD_ONLYONESP)) && (defined(DPNBUILD_ONLYONEADAPTER)))
  951. if (pDeviceInfo != NULL)
  952. #endif // DPNBUILD_ONLYONESP and DPNBUILD_ONLYONEADAPTER
  953. {
  954. if( pDeviceInfo == NULL || !DNVALID_READPTR( pDeviceInfo, sizeof ( IDirectPlay8Address * ) ) )
  955. {
  956. DPFERR("Invalid pointer for device address" );
  957. return( DPNERR_INVALIDPOINTER );
  958. }
  959. #ifndef DPNBUILD_ONLYONESP
  960. if( FAILED( hResultCode = IDirectPlay8Address_GetSP( pDeviceInfo, &guidspDevice ) ) )
  961. {
  962. DPFX(DPFPREP, 0, "Unable to get SP for specified address hr=0x%x", hResultCode );
  963. return( DPNERR_INVALIDDEVICEADDRESS );
  964. }
  965. if (pAddrHost != NULL)
  966. {
  967. if( guidspHost != guidspDevice )
  968. {
  969. DPFERR( "Device and remote addresses must use the same SP" );
  970. return( DPNERR_INVALIDPARAM );
  971. }
  972. }
  973. #endif // ! DPNBUILD_ONLYONESP
  974. }
  975. if( dwUserEnumDataSize > 0 &&
  976. (pUserEnumData == NULL || !DNVALID_READPTR( pUserEnumData, dwUserEnumDataSize ) ) )
  977. {
  978. DPFERR( "Invalid pointer specified for user enum data" );
  979. return( DPNERR_INVALIDPOINTER );
  980. }
  981. if( dwFlags & ~(DPNENUMHOSTS_OKTOQUERYFORADDRESSING | DPNENUMHOSTS_SYNC | DPNENUMHOSTS_NOBROADCASTFALLBACK) )
  982. {
  983. DPFX(DPFPREP, 0, "Invalid flags specified" );
  984. return( DPNERR_INVALIDFLAGS );
  985. }
  986. if( dwFlags & DPNENUMHOSTS_SYNC )
  987. {
  988. if( pAsyncHandle != NULL )
  989. {
  990. DPFERR( "You cannot specify an async handle pointer if op is synchronous" );
  991. return( DPNERR_INVALIDPARAM );
  992. }
  993. }
  994. else
  995. {
  996. if( pAsyncHandle == NULL )
  997. {
  998. DPFERR( "You MUST specify a valid async handle pointer w/async ops" );
  999. return( DPNERR_INVALIDPARAM );
  1000. }
  1001. if( !DNVALID_WRITEPTR( pAsyncHandle, sizeof( DPNHANDLE ) ) )
  1002. {
  1003. DPFERR("Invalid async handle pointer specified" );
  1004. return( DPNERR_INVALIDPOINTER );
  1005. }
  1006. }
  1007. return DPN_OK;
  1008. }
  1009. #undef DPF_MODNAME
  1010. #define DPF_MODNAME "DN_ValidateEnumGroupMembers"
  1011. HRESULT DN_ValidateEnumGroupMembers(PVOID pInterface,
  1012. const DPNID dpnid,
  1013. DPNID *const prgdpnid,
  1014. DWORD *const pcdpnid,
  1015. const DWORD dwFlags)
  1016. {
  1017. if( !IsValidDirectPlay8Object( pInterface ) )
  1018. {
  1019. DPFERR("Invalid object specified " );
  1020. return( DPNERR_INVALIDOBJECT );
  1021. }
  1022. if( dpnid == DPNID_ALL_PLAYERS_GROUP )
  1023. {
  1024. DPFERR("Cannot enumerate all players group" );
  1025. return DPNERR_INVALIDGROUP;
  1026. }
  1027. if( pcdpnid == NULL ||
  1028. !DNVALID_WRITEPTR( pcdpnid, sizeof( DWORD ) ) )
  1029. {
  1030. DPFERR("Invalid count param specified" );
  1031. return( DPNERR_INVALIDPOINTER );
  1032. }
  1033. if( *pcdpnid > 0 &&
  1034. (prgdpnid == NULL || !DNVALID_WRITEPTR( prgdpnid, *pcdpnid ) ) )
  1035. {
  1036. DPFERR("Invalid pointer specified for buffer" );
  1037. return( DPNERR_INVALIDPOINTER );
  1038. }
  1039. if( dwFlags != 0 )
  1040. {
  1041. DPFERR( "Invalid flags specified" );
  1042. return( DPNERR_INVALIDFLAGS );
  1043. }
  1044. return DPN_OK;
  1045. }
  1046. #undef DPF_MODNAME
  1047. #define DPF_MODNAME "DN_ValidateEnumClientsAndGroups"
  1048. HRESULT DN_ValidateEnumClientsAndGroups(PVOID pInterface,
  1049. DPNID *const prgdpnid,
  1050. DWORD *const pcdpnid,
  1051. const DWORD dwFlags)
  1052. {
  1053. if( !IsValidDirectPlay8Object( pInterface ) )
  1054. {
  1055. DPFERR("Invalid object specified " );
  1056. return( DPNERR_INVALIDOBJECT );
  1057. }
  1058. if( pcdpnid == NULL ||
  1059. !DNVALID_WRITEPTR( pcdpnid, sizeof( DWORD ) ) )
  1060. {
  1061. DPFERR("Invalid count param specified" );
  1062. return( DPNERR_INVALIDPOINTER );
  1063. }
  1064. if( *pcdpnid > 0 &&
  1065. (prgdpnid == NULL || !DNVALID_WRITEPTR( prgdpnid, *pcdpnid ) ) )
  1066. {
  1067. DPFERR("Invalid pointer specified for buffer" );
  1068. return( DPNERR_INVALIDPOINTER );
  1069. }
  1070. if (dwFlags == 0)
  1071. {
  1072. DPFERR("Flags must be specified");
  1073. return( DPNERR_INVALIDPARAM );
  1074. }
  1075. if (dwFlags & ~(DPNENUM_GROUPS | DPNENUM_PLAYERS))
  1076. {
  1077. DPFERR( "Invalid flags specified" );
  1078. return( DPNERR_INVALIDFLAGS );
  1079. }
  1080. return DPN_OK;
  1081. }
  1082. #undef DPF_MODNAME
  1083. #define DPF_MODNAME "DN_ValidateGetGroupInfo"
  1084. HRESULT DN_ValidateGetGroupInfo(PVOID pv,
  1085. const DPNID dpnid,
  1086. DPN_GROUP_INFO *const pdpnGroupInfo,
  1087. DWORD *const pdwSize,
  1088. const DWORD dwFlags)
  1089. {
  1090. HRESULT hResultCode;
  1091. if( !IsValidDirectPlay8Object( pv ) )
  1092. {
  1093. DPFERR("Invalid object specified " );
  1094. return( DPNERR_INVALIDOBJECT );
  1095. }
  1096. if( dpnid == DPNID_ALL_PLAYERS_GROUP )
  1097. {
  1098. DPFERR("Cannot get group info for all players group" );
  1099. return( DPNERR_INVALIDGROUP );
  1100. }
  1101. if( pdwSize == NULL ||
  1102. !DNVALID_WRITEPTR( pdwSize, sizeof( DWORD ) ) )
  1103. {
  1104. DPFERR("Invalid pdwSize parameter specified" );
  1105. return( DPNERR_INVALIDPOINTER );
  1106. }
  1107. // Only validate group info pointer if size is > 0
  1108. if( *pdwSize > 0 )
  1109. {
  1110. if( pdpnGroupInfo == NULL ||
  1111. !DNVALID_WRITEPTR( pdpnGroupInfo, *pdwSize ) )
  1112. {
  1113. DPFERR("Invalid pointer specified for group info" );
  1114. return( DPNERR_INVALIDPOINTER );
  1115. }
  1116. if( FAILED( hResultCode = DN_ValidGroupInfo( pdpnGroupInfo, FALSE ) ) )
  1117. {
  1118. DPFERR("Error validating group info parameter" );
  1119. return( hResultCode );
  1120. }
  1121. }
  1122. if( dwFlags != 0 )
  1123. {
  1124. DPFERR( "Invalid flags specified" );
  1125. return( DPNERR_INVALIDFLAGS );
  1126. }
  1127. return DPN_OK;
  1128. }
  1129. #undef DPF_MODNAME
  1130. #define DPF_MODNAME "DN_ValidateSetGroupInfo"
  1131. HRESULT DN_ValidateSetGroupInfo(PVOID pv,
  1132. const DPNID dpnid,
  1133. const DPN_GROUP_INFO *const pdpnGroupInfo,
  1134. PVOID const pvAsyncContext,
  1135. DPNHANDLE *const phAsyncHandle,
  1136. const DWORD dwFlags)
  1137. {
  1138. HRESULT hResultCode;
  1139. if( !IsValidDirectPlay8Object( pv ) )
  1140. {
  1141. DPFERR("Invalid object specified " );
  1142. return( DPNERR_INVALIDOBJECT );
  1143. }
  1144. if( dpnid == DPNID_ALL_PLAYERS_GROUP )
  1145. {
  1146. DPFERR( "Cannot remove from all players group" );
  1147. return( DPNERR_INVALIDGROUP );
  1148. }
  1149. if( FAILED( hResultCode = DN_ValidGroupInfo( pdpnGroupInfo, TRUE ) ) )
  1150. {
  1151. DPFERR( "Error validating group info structure" );
  1152. return(hResultCode);
  1153. }
  1154. if( dwFlags & ~(DPNSETGROUPINFO_SYNC) )
  1155. {
  1156. DPFERR("Invalid flags specified" );
  1157. return( DPNERR_INVALIDFLAGS );
  1158. }
  1159. if( dwFlags & DPNSETGROUPINFO_SYNC )
  1160. {
  1161. if( phAsyncHandle != NULL )
  1162. {
  1163. DPFERR( "You cannot specify an async handle pointer if op is synchronous" );
  1164. return( DPNERR_INVALIDPARAM );
  1165. }
  1166. }
  1167. else
  1168. {
  1169. if( phAsyncHandle == NULL )
  1170. {
  1171. DPFERR( "You MUST specify a valid async handle pointer w/async ops" );
  1172. return( DPNERR_INVALIDPARAM );
  1173. }
  1174. if( !DNVALID_WRITEPTR( phAsyncHandle, sizeof( DPNHANDLE ) ) )
  1175. {
  1176. DPFERR("Invalid async handle pointer specified" );
  1177. return( DPNERR_INVALIDPOINTER );
  1178. }
  1179. }
  1180. return DPN_OK;
  1181. }
  1182. #undef DPF_MODNAME
  1183. #define DPF_MODNAME "DN_ValidateRemoveClientFromGroup"
  1184. HRESULT DN_ValidateRemoveClientFromGroup(PVOID pInterface,
  1185. const DPNID dpnidGroup,
  1186. const DPNID dpnidClient,
  1187. PVOID const pvAsyncContext,
  1188. DPNHANDLE *const phAsyncHandle,
  1189. const DWORD dwFlags)
  1190. {
  1191. if( !IsValidDirectPlay8Object( pInterface ) )
  1192. {
  1193. DPFERR("Invalid object specified " );
  1194. return( DPNERR_INVALIDOBJECT );
  1195. }
  1196. if( dpnidGroup == DPNID_ALL_PLAYERS_GROUP )
  1197. {
  1198. DPFERR( "Cannot remove from all players group" );
  1199. return( DPNERR_INVALIDGROUP );
  1200. }
  1201. if( dpnidClient == DPNID_ALL_PLAYERS_GROUP )
  1202. {
  1203. DPFERR( "Cannot specify all players group as client to remove" );
  1204. return( DPNERR_INVALIDPARAM );
  1205. }
  1206. if( dwFlags & ~(DPNREMOVEPLAYERFROMGROUP_SYNC) )
  1207. {
  1208. DPFERR("Invalid flags specified" );
  1209. return( DPNERR_INVALIDFLAGS );
  1210. }
  1211. if( dwFlags & DPNREMOVEPLAYERFROMGROUP_SYNC )
  1212. {
  1213. if( phAsyncHandle != NULL )
  1214. {
  1215. DPFERR( "You cannot specify an async handle pointer if op is synchronous" );
  1216. return( DPNERR_INVALIDPARAM );
  1217. }
  1218. }
  1219. else
  1220. {
  1221. if( phAsyncHandle == NULL )
  1222. {
  1223. DPFERR( "You MUST specify a valid async handle pointer w/async ops" );
  1224. return( DPNERR_INVALIDPARAM );
  1225. }
  1226. if( !DNVALID_WRITEPTR( phAsyncHandle, sizeof( DPNHANDLE ) ) )
  1227. {
  1228. DPFERR("Invalid async handle pointer specified" );
  1229. return( DPNERR_INVALIDPOINTER );
  1230. }
  1231. }
  1232. return DPN_OK;
  1233. }
  1234. #undef DPF_MODNAME
  1235. #define DPF_MODNAME "DN_ValidateAddClientToGroup"
  1236. HRESULT DN_ValidateAddClientToGroup(PVOID pInterface,
  1237. const DPNID dpnidGroup,
  1238. const DPNID dpnidClient,
  1239. PVOID const pvAsyncContext,
  1240. DPNHANDLE *const phAsyncHandle,
  1241. const DWORD dwFlags)
  1242. {
  1243. if( !IsValidDirectPlay8Object( pInterface ) )
  1244. {
  1245. DPFERR("Invalid object specified " );
  1246. return( DPNERR_INVALIDOBJECT );
  1247. }
  1248. if( dpnidGroup == DPNID_ALL_PLAYERS_GROUP )
  1249. {
  1250. DPFERR( "Cannot add from all players group" );
  1251. return( DPNERR_INVALIDGROUP );
  1252. }
  1253. if( dpnidClient == DPNID_ALL_PLAYERS_GROUP )
  1254. {
  1255. DPFERR( "Cannot specify all players group as client to add" );
  1256. return( DPNERR_INVALIDPLAYER );
  1257. }
  1258. if( dwFlags & ~(DPNADDPLAYERTOGROUP_SYNC) )
  1259. {
  1260. DPFERR("Invalid flags specified" );
  1261. return( DPNERR_INVALIDFLAGS );
  1262. }
  1263. if( dwFlags & DPNADDPLAYERTOGROUP_SYNC )
  1264. {
  1265. if( phAsyncHandle != NULL )
  1266. {
  1267. DPFERR( "You cannot specify an async handle pointer if op is synchronous" );
  1268. return( DPNERR_INVALIDPARAM );
  1269. }
  1270. }
  1271. else
  1272. {
  1273. if( phAsyncHandle == NULL )
  1274. {
  1275. DPFERR( "You MUST specify a valid async handle pointer w/async ops" );
  1276. return( DPNERR_INVALIDPARAM );
  1277. }
  1278. if( !DNVALID_WRITEPTR( phAsyncHandle, sizeof( DPNHANDLE ) ) )
  1279. {
  1280. DPFERR("Invalid async handle pointer specified" );
  1281. return( DPNERR_INVALIDPOINTER );
  1282. }
  1283. }
  1284. return DPN_OK;
  1285. }
  1286. #undef DPF_MODNAME
  1287. #define DPF_MODNAME "DN_ValidateDestroyGroup"
  1288. HRESULT DN_ValidateDestroyGroup(PVOID pInterface,
  1289. const DPNID dpnidGroup,
  1290. PVOID const pvAsyncContext,
  1291. DPNHANDLE *const phAsyncHandle,
  1292. const DWORD dwFlags)
  1293. {
  1294. if( !IsValidDirectPlay8Object( pInterface ) )
  1295. {
  1296. DPFERR("Invalid object specified " );
  1297. return( DPNERR_INVALIDOBJECT );
  1298. }
  1299. if( dpnidGroup == DPNID_ALL_PLAYERS_GROUP )
  1300. {
  1301. DPFERR( "Cannot destroy all players group" );
  1302. return( DPNERR_INVALIDGROUP );
  1303. }
  1304. if( dwFlags & ~(DPNDESTROYGROUP_SYNC) )
  1305. {
  1306. DPFERR("Invalid flags specified" );
  1307. return( DPNERR_INVALIDFLAGS );
  1308. }
  1309. if( dwFlags & DPNDESTROYGROUP_SYNC )
  1310. {
  1311. if( phAsyncHandle != NULL )
  1312. {
  1313. DPFERR( "You cannot specify an async handle pointer if op is synchronous" );
  1314. return( DPNERR_INVALIDPARAM );
  1315. }
  1316. }
  1317. else
  1318. {
  1319. if( phAsyncHandle == NULL )
  1320. {
  1321. DPFERR( "You MUST specify a valid async handle pointer w/async ops" );
  1322. return( DPNERR_INVALIDPARAM );
  1323. }
  1324. if( !DNVALID_WRITEPTR( phAsyncHandle, sizeof( DPNHANDLE ) ) )
  1325. {
  1326. DPFERR("Invalid async handle pointer specified" );
  1327. return( DPNERR_INVALIDPOINTER );
  1328. }
  1329. }
  1330. return DPN_OK;
  1331. }
  1332. #undef DPF_MODNAME
  1333. #define DPF_MODNAME "DN_ValidateCreateGroup"
  1334. HRESULT DN_ValidateCreateGroup(PVOID pInterface,
  1335. const DPN_GROUP_INFO *const pdpnGroupInfo,
  1336. void *const pvGroupContext,
  1337. void *const pvAsyncContext,
  1338. DPNHANDLE *const phAsyncHandle,
  1339. const DWORD dwFlags)
  1340. {
  1341. HRESULT hResultCode;
  1342. if( !IsValidDirectPlay8Object( pInterface ) )
  1343. {
  1344. DPFERR("Invalid object specified " );
  1345. return( DPNERR_INVALIDOBJECT );
  1346. }
  1347. if( FAILED( hResultCode = DN_ValidGroupInfo( pdpnGroupInfo, TRUE ) ) )
  1348. {
  1349. DPFERR("Invalid group info structure" );
  1350. return( DPNERR_INVALIDPARAM );
  1351. }
  1352. if( dwFlags & ~(DPNCREATEGROUP_SYNC) )
  1353. {
  1354. DPFERR( "Invalid flags specified" );
  1355. return( DPNERR_INVALIDFLAGS );
  1356. }
  1357. if( dwFlags & DPNCREATEGROUP_SYNC )
  1358. {
  1359. if( phAsyncHandle != NULL )
  1360. {
  1361. DPFERR( "You cannot specify an async handle pointer if op is synchronous" );
  1362. return( DPNERR_INVALIDPARAM );
  1363. }
  1364. }
  1365. else
  1366. {
  1367. if( phAsyncHandle == NULL )
  1368. {
  1369. DPFERR( "You MUST specify a valid async handle pointer w/async ops" );
  1370. return( DPNERR_INVALIDPARAM );
  1371. }
  1372. if( !DNVALID_WRITEPTR( phAsyncHandle, sizeof( DPNHANDLE ) ) )
  1373. {
  1374. DPFERR("Invalid async handle pointer specified" );
  1375. return( DPNERR_INVALIDPOINTER );
  1376. }
  1377. }
  1378. return DPN_OK;
  1379. }
  1380. #undef DPF_MODNAME
  1381. #define DPF_MODNAME "DN_ValidateHost"
  1382. HRESULT DN_ValidateHost(PVOID pInterface,
  1383. const DPN_APPLICATION_DESC *const pdnAppDesc,
  1384. IDirectPlay8Address **const prgpDeviceInfo,
  1385. const DWORD cDeviceInfo,
  1386. const DPN_SECURITY_DESC *const pdnSecurity,
  1387. const DPN_SECURITY_CREDENTIALS *const pdnCredentials,
  1388. void *const pvPlayerContext,
  1389. const DWORD dwFlags)
  1390. {
  1391. HRESULT hResultCode;
  1392. #ifndef DPNBUILD_ONLYONESP
  1393. GUID guidSP;
  1394. #endif // ! DPNBUILD_ONLYONESP
  1395. DWORD dwTmpPort;
  1396. DWORD dwPortType;
  1397. DWORD dwPortSize;
  1398. if( !IsValidDirectPlay8Object( pInterface ) )
  1399. {
  1400. DPFERR("Invalid object specified " );
  1401. return( DPNERR_INVALIDOBJECT );
  1402. }
  1403. if( FAILED( hResultCode = DN_ValidHostAppDesc( pdnAppDesc ) ) )
  1404. {
  1405. DPFERR("Invalid host app desc specified");
  1406. return( hResultCode );
  1407. }
  1408. #if ((defined(DPNBUILD_ONLYONESP)) && (defined(DPNBUILD_ONLYONEADAPTER)))
  1409. if ( ( prgpDeviceInfo == NULL && cDeviceInfo != 0 ) ||
  1410. ( prgpDeviceInfo != NULL && cDeviceInfo == 0 ) )
  1411. {
  1412. DPFERR("You MUST specify a device address array and count, or NULL and 0");
  1413. return( DPNERR_INVALIDDEVICEADDRESS );
  1414. }
  1415. #else // ! DPNBUILD_ONLYONESP or ! DPNBUILD_ONLYONEADAPTER
  1416. if( prgpDeviceInfo == NULL || cDeviceInfo == 0 )
  1417. {
  1418. DPFERR("You MUST specify a device address");
  1419. return( DPNERR_INVALIDDEVICEADDRESS );
  1420. }
  1421. #endif // ! DPNBUILD_ONLYONESP or ! DPNBUILD_ONLYONEADAPTER
  1422. if( cDeviceInfo > MAX_HOST_ADDRESSES )
  1423. {
  1424. DPFX(DPFPREP, 0, "Cannot specify more than %u device addresses!", cDeviceInfo);
  1425. return( DPNERR_INVALIDPARAM );
  1426. }
  1427. #if ((defined(DPNBUILD_ONLYONESP)) && (defined(DPNBUILD_ONLYONEADAPTER)))
  1428. if (cDeviceInfo > 0)
  1429. #endif // DPNBUILD_ONLYONESP and DPNBUILD_ONLYONEADAPTER
  1430. {
  1431. if( !DNVALID_READPTR( prgpDeviceInfo, sizeof( IDirectPlay8Address * ) * cDeviceInfo ) )
  1432. {
  1433. DPFERR("Invalid pointer specified for device info" );
  1434. return( DPNERR_INVALIDPOINTER );
  1435. }
  1436. // ensure SPs are specified in addresses
  1437. for (DWORD dw = 0 ; dw < cDeviceInfo ; dw++)
  1438. {
  1439. if ( prgpDeviceInfo[dw] == NULL )
  1440. {
  1441. DPFERR( "Null device address interface pointer specified" );
  1442. return( DPNERR_INVALIDDEVICEADDRESS );
  1443. }
  1444. #ifndef DPNBUILD_ONLYONESP
  1445. if (IDirectPlay8Address_GetSP(prgpDeviceInfo[dw],&guidSP) != DPN_OK)
  1446. {
  1447. DPFERR("SP not specified for one of the addresses" );
  1448. return(DPNERR_INVALIDDEVICEADDRESS);
  1449. }
  1450. #endif // ! DPNBUILD_ONLYONESP
  1451. dwPortType = DPNA_DATATYPE_DWORD;
  1452. dwPortSize = sizeof( DWORD );
  1453. // Check to ensure it's not using the default DPNSVR port
  1454. if( SUCCEEDED( hResultCode = IDirectPlay8Address_GetComponentByName( prgpDeviceInfo[dw], DPNA_KEY_PORT, &dwTmpPort, &dwPortSize, &dwPortType ) ) )
  1455. {
  1456. if( dwTmpPort == DPNA_DPNSVR_PORT )
  1457. {
  1458. DPFERR( "Cannot use the DPNSVR port in device addresses" );
  1459. DPFERR( "This port is reserved for DPNSVR" );
  1460. return( DPNERR_INVALIDDEVICEADDRESS );
  1461. }
  1462. }
  1463. }
  1464. }
  1465. if( FAILED( hResultCode = DN_ValidSecurityDesc( pdnSecurity ) ) )
  1466. {
  1467. DPFERR("Error validating reserved param" );
  1468. return( hResultCode );
  1469. }
  1470. if( FAILED( hResultCode = DN_ValidSecurityCredentials(pdnCredentials) ) )
  1471. {
  1472. DPFERR("Error validating reserved param" );
  1473. return( hResultCode );
  1474. }
  1475. if( ( dwFlags & ~(DPNHOST_OKTOQUERYFORADDRESSING) ) != 0 )
  1476. {
  1477. DPFERR("Invalid flags specified" );
  1478. return( DPNERR_INVALIDFLAGS );
  1479. }
  1480. return DPN_OK;
  1481. }
  1482. #undef DPF_MODNAME
  1483. #define DPF_MODNAME "DN_ValidateEnumServiceProviders"
  1484. HRESULT DN_ValidateEnumServiceProviders(PVOID pInterface,
  1485. const GUID *const pguidServiceProvider,
  1486. const GUID *const pguidApplication,
  1487. DPN_SERVICE_PROVIDER_INFO *const pSPInfoBuffer,
  1488. DWORD *const pcbEnumData,
  1489. const DWORD *const pcReturned,
  1490. const DWORD dwFlags )
  1491. {
  1492. if( !IsValidDirectPlay8Object( pInterface ) )
  1493. {
  1494. DPFERR("Invalid object specified " );
  1495. return( DPNERR_INVALIDOBJECT );
  1496. }
  1497. if( pguidServiceProvider != NULL &&
  1498. !DNVALID_READPTR( pguidServiceProvider, sizeof( GUID ) ) )
  1499. {
  1500. DPFERR("Invalid service provider specified" );
  1501. return( DPNERR_INVALIDPOINTER );
  1502. }
  1503. if( pguidApplication != NULL &&
  1504. !DNVALID_READPTR( pguidApplication, sizeof( GUID ) ) )
  1505. {
  1506. DPFERR("Invalid application GUID specified" );
  1507. return( DPNERR_INVALIDPOINTER );
  1508. }
  1509. if( pcbEnumData == NULL ||
  1510. !DNVALID_READPTR( pcbEnumData, sizeof( DWORD ) ) )
  1511. {
  1512. DPFERR("Invalid enum data pointer" );
  1513. return( DPNERR_INVALIDPOINTER );
  1514. }
  1515. if( pcReturned == NULL ||
  1516. !DNVALID_READPTR( pcReturned, sizeof( DWORD ) ) )
  1517. {
  1518. DPFERR("Invalid retuned count" );
  1519. return( DPNERR_INVALIDPOINTER );
  1520. }
  1521. if( *pcbEnumData > 0 &&
  1522. (pSPInfoBuffer == NULL || !DNVALID_WRITEPTR(pSPInfoBuffer,*pcbEnumData) ) )
  1523. {
  1524. DPFERR("Invalid enum buffer specified" );
  1525. return( DPNERR_INVALIDPOINTER );
  1526. }
  1527. if( dwFlags & (~(DPNENUMSERVICEPROVIDERS_ALL)) )
  1528. {
  1529. DPFERR("Invalid flags specified" );
  1530. return( DPNERR_INVALIDFLAGS );
  1531. }
  1532. return DPN_OK;
  1533. }
  1534. #undef DPF_MODNAME
  1535. #define DPF_MODNAME "DN_ValidateCancelAsyncOperation"
  1536. HRESULT DN_ValidateCancelAsyncOperation(PVOID pvInterface,
  1537. const DPNHANDLE hAsyncOp,
  1538. const DWORD dwFlags )
  1539. {
  1540. DIRECTNETOBJECT *pdnObject;
  1541. if( !IsValidDirectPlay8Object( pvInterface ) )
  1542. {
  1543. DPFERR("Invalid object specified " );
  1544. return( DPNERR_INVALIDOBJECT );
  1545. }
  1546. pdnObject = static_cast<DIRECTNETOBJECT*>(GET_OBJECT_FROM_INTERFACE(pvInterface));
  1547. if( dwFlags )
  1548. {
  1549. #ifdef DIRECTPLAYDIRECTX9
  1550. if ( dwFlags & DPNCANCEL_PLAYER_SENDS )
  1551. {
  1552. if (pdnObject->dwFlags & DN_OBJECT_FLAG_CLIENT)
  1553. {
  1554. if( (DPNID) hAsyncOp != 0 )
  1555. {
  1556. DPFERR("Invalid player ID specified, must be 0" );
  1557. return( DPNERR_INVALIDPARAM );
  1558. }
  1559. }
  1560. else
  1561. {
  1562. if( (DPNID) hAsyncOp == 0 )
  1563. {
  1564. DPFERR("Invalid player ID specified, cannot be 0" );
  1565. return( DPNERR_INVALIDPLAYER );
  1566. }
  1567. }
  1568. // make sure only correct bits are set
  1569. if( dwFlags != ( dwFlags & ( DPNCANCEL_PLAYER_SENDS | DPNCANCEL_PLAYER_SENDS_PRIORITY_NORMAL | DPNCANCEL_PLAYER_SENDS_PRIORITY_HIGH | DPNCANCEL_PLAYER_SENDS_PRIORITY_LOW ) ) )
  1570. {
  1571. DPFERR("Invalid flags specified" );
  1572. return( DPNERR_INVALIDFLAGS );
  1573. }
  1574. }
  1575. else
  1576. #endif
  1577. {
  1578. if( hAsyncOp )
  1579. {
  1580. DPFERR("Invalid parameter, hAsyncOp specified with flags");
  1581. return ( DPNERR_INVALIDPARAM );
  1582. }
  1583. // make sure only correct bits are set, AND only 1 bit is set.
  1584. #ifdef DPNBUILD_NOMULTICAST
  1585. if( ( dwFlags != ( dwFlags & ( DPNCANCEL_ALL_OPERATIONS | DPNCANCEL_CONNECT | DPNCANCEL_ENUM | DPNCANCEL_SEND ) ) ) ||
  1586. #else // ! DPNBUILD_NOMULTICAST
  1587. if( ( dwFlags != ( dwFlags & ( DPNCANCEL_ALL_OPERATIONS | DPNCANCEL_CONNECT | DPNCANCEL_ENUM | DPNCANCEL_SEND | DPNCANCEL_JOIN ) ) ) ||
  1588. #endif // ! DPNBUILD_NOMULTICAST
  1589. ( ( ( dwFlags - 1 ) & dwFlags ) != 0 ) )
  1590. {
  1591. DPFERR("Invalid flags specified" );
  1592. return( DPNERR_INVALIDFLAGS );
  1593. }
  1594. }
  1595. // Server objects don't have the concept of connects, enums, or joins.
  1596. if (pdnObject->dwFlags & DN_OBJECT_FLAG_SERVER)
  1597. {
  1598. #ifdef DPNBUILD_NOMULTICAST
  1599. if (dwFlags & (DPNCANCEL_CONNECT | DPNCANCEL_ENUM))
  1600. #else // ! DPNBUILD_NOMULTICAST
  1601. if (dwFlags & (DPNCANCEL_CONNECT | DPNCANCEL_ENUM | DPNCANCEL_JOIN))
  1602. #endif // ! DPNBUILD_NOMULTICAST
  1603. {
  1604. DPFERR("Server interface cannot cancel connect, enum, or join operations");
  1605. return(DPNERR_INVALIDFLAGS);
  1606. }
  1607. }
  1608. // Client objects don't have the concept of joins.
  1609. else if (pdnObject->dwFlags & DN_OBJECT_FLAG_CLIENT)
  1610. {
  1611. #ifndef DPNBUILD_NOMULTICAST
  1612. if (dwFlags & DPNCANCEL_JOIN)
  1613. {
  1614. DPFERR("Client interface cannot cancel join operations");
  1615. return(DPNERR_INVALIDFLAGS);
  1616. }
  1617. #endif // ! DPNBUILD_NOMULTICAST
  1618. }
  1619. #ifndef DPNBUILD_NOMULTICAST
  1620. // Multicast objects don't have the concept of connects, enums, or player sends.
  1621. else if (pdnObject->dwFlags & DN_OBJECT_FLAG_MULTICAST)
  1622. {
  1623. if (dwFlags & (DPNCANCEL_CONNECT | DPNCANCEL_ENUM | DPNCANCEL_PLAYER_SENDS))
  1624. {
  1625. DPFERR("Multicast interface cannot cancel connect, enum or player send operations");
  1626. return(DPNERR_INVALIDFLAGS);
  1627. }
  1628. }
  1629. #endif // ! DPNBUILD_NOMULTICAST
  1630. // Peer objects don't have the concept of joins.
  1631. else
  1632. {
  1633. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_PEER);
  1634. #ifndef DPNBUILD_NOMULTICAST
  1635. if (dwFlags & DPNCANCEL_JOIN)
  1636. {
  1637. DPFERR("Peer interface cannot cancel join operations");
  1638. return(DPNERR_INVALIDFLAGS);
  1639. }
  1640. #endif // ! DPNBUILD_NOMULTICAST
  1641. }
  1642. }
  1643. else
  1644. {
  1645. if( hAsyncOp == NULL)
  1646. {
  1647. DPFERR("Invalid handle specified" );
  1648. return( DPNERR_INVALIDHANDLE );
  1649. }
  1650. }
  1651. return DPN_OK;
  1652. }
  1653. #undef DPF_MODNAME
  1654. #define DPF_MODNAME "DN_ValidateConnect"
  1655. HRESULT DN_ValidateConnect(PVOID pInterface,
  1656. const DPN_APPLICATION_DESC *const pdnAppDesc,
  1657. IDirectPlay8Address *const pHostAddr,
  1658. IDirectPlay8Address *const pDeviceInfo,
  1659. const DPN_SECURITY_DESC *const pdnSecurity,
  1660. const DPN_SECURITY_CREDENTIALS *const pdnCredentials,
  1661. const void *const pvUserConnectData,
  1662. const DWORD dwUserConnectDataSize,
  1663. void *const pvPlayerContext,
  1664. void *const pvAsyncContext,
  1665. DPNHANDLE *const phAsyncHandle,
  1666. const DWORD dwFlags)
  1667. {
  1668. HRESULT hResultCode;
  1669. #ifndef DPNBUILD_ONLYONESP
  1670. GUID guidHostSP;
  1671. GUID guidDeviceSP;
  1672. #endif // ! DPNBUILD_ONLYONESP
  1673. if( !IsValidDirectPlay8Object( pInterface ) )
  1674. {
  1675. DPFERR("Invalid object specified " );
  1676. return( DPNERR_INVALIDOBJECT );
  1677. }
  1678. hResultCode = DN_ValidConnectAppDesc( pdnAppDesc );
  1679. if( FAILED( hResultCode ) )
  1680. {
  1681. DPFX(DPFPREP, 0, "Invalid connect app desc hr=[0x%lx]", hResultCode );
  1682. return( hResultCode );
  1683. }
  1684. if( pHostAddr == NULL ||
  1685. !DNVALID_READPTR( pHostAddr, sizeof( IDirectPlay8Address * ) ) )
  1686. {
  1687. DPFERR("Invalid host address specified" );
  1688. return( DPNERR_INVALIDHOSTADDRESS );
  1689. }
  1690. #ifndef DPNBUILD_ONLYONESP
  1691. if( FAILED( hResultCode = IDirectPlay8Address_GetSP( pHostAddr, &guidHostSP ) ) )
  1692. {
  1693. DPFERR("No SP specified in host address" );
  1694. return( DPNERR_INVALIDHOSTADDRESS );
  1695. }
  1696. #endif // ! DPNBUILD_ONLYONESP
  1697. //
  1698. // Allow a NULL Device Address (we will copy the SP from the Host address)
  1699. //
  1700. if( pDeviceInfo != NULL)
  1701. {
  1702. if ( !DNVALID_READPTR( pDeviceInfo, sizeof( IDirectPlay8Address * ) ) )
  1703. {
  1704. DPFERR("Invalid device address specified" );
  1705. return( hResultCode );
  1706. }
  1707. #ifndef DPNBUILD_ONLYONESP
  1708. if( FAILED( hResultCode = IDirectPlay8Address_GetSP( pDeviceInfo, &guidDeviceSP ) ) )
  1709. {
  1710. DPFERR("No SP specified in device address" );
  1711. return( DPNERR_INVALIDDEVICEADDRESS );
  1712. }
  1713. if (guidHostSP != guidDeviceSP)
  1714. {
  1715. DPFERR( "Specified different SPs for device and connect" );
  1716. return(DPNERR_INVALIDDEVICEADDRESS);
  1717. }
  1718. #endif // ! DPNBUILD_ONLYONESP
  1719. DWORD dwTmpPort;
  1720. DWORD dwDataType;
  1721. DWORD dwDataSize;
  1722. dwDataType = DPNA_DATATYPE_DWORD;
  1723. dwDataSize = sizeof( DWORD );
  1724. // Check to ensure it's not using the default DPNSVR port
  1725. if( SUCCEEDED( hResultCode = IDirectPlay8Address_GetComponentByName( pDeviceInfo, DPNA_KEY_PORT, &dwTmpPort, &dwDataSize, &dwDataType ) ) )
  1726. {
  1727. if( dwTmpPort == DPNA_DPNSVR_PORT )
  1728. {
  1729. DPFERR( "Cannot use the DPNSVR port in device addresses" );
  1730. DPFERR( "This port is reserved for DPNSVR" );
  1731. return( DPNERR_INVALIDDEVICEADDRESS );
  1732. }
  1733. }
  1734. }
  1735. if( FAILED( hResultCode = DN_ValidSecurityDesc(pdnSecurity) ) )
  1736. {
  1737. DPFERR(" Invalid reserved specified" );
  1738. return( hResultCode );
  1739. }
  1740. if( FAILED( hResultCode = DN_ValidSecurityCredentials(pdnCredentials) ) )
  1741. {
  1742. DPFERR( "Invalid reserved2 specified" );
  1743. return( hResultCode );
  1744. }
  1745. if( dwUserConnectDataSize > 0 &&
  1746. (pvUserConnectData == NULL || !DNVALID_READPTR( pvUserConnectData, dwUserConnectDataSize ) ) )
  1747. {
  1748. DPFERR( "Invalid pointer specified for connect data" );
  1749. return( DPNERR_INVALIDPOINTER );
  1750. }
  1751. if( pvUserConnectData != NULL && dwUserConnectDataSize == 0 )
  1752. {
  1753. DPFERR( "Non NULL connect data with datasize = 0 is invalid" );
  1754. return( DPNERR_INVALIDPARAM );
  1755. }
  1756. if( dwFlags & ~(DPNCONNECT_SYNC | DPNCONNECT_OKTOQUERYFORADDRESSING) )
  1757. {
  1758. DPFERR( "Invalid flags specified" );
  1759. return( DPNERR_INVALIDFLAGS );
  1760. }
  1761. if( dwFlags & DPNCONNECT_SYNC )
  1762. {
  1763. if( phAsyncHandle != NULL )
  1764. {
  1765. DPFERR( "You cannot specify an async handle if op is synchronous" );
  1766. return( DPNERR_INVALIDPARAM );
  1767. }
  1768. }
  1769. else
  1770. {
  1771. if( phAsyncHandle == NULL )
  1772. {
  1773. DPFERR( "You MUST specify a valid async handle w/async ops" );
  1774. return( DPNERR_INVALIDPARAM );
  1775. }
  1776. if( !DNVALID_WRITEPTR( phAsyncHandle, sizeof( DPNHANDLE ) ) )
  1777. {
  1778. DPFERR("Invalid async handle pointer specified" );
  1779. return( DPNERR_INVALIDPOINTER );
  1780. }
  1781. }
  1782. return DPN_OK;
  1783. }
  1784. #undef DPF_MODNAME
  1785. #define DPF_MODNAME "DN_ValidateGetSendQueueInfo"
  1786. HRESULT DN_ValidateGetSendQueueInfo(PVOID pInterface,
  1787. DWORD *const pdwNumMsgs,
  1788. DWORD *const pdwNumBytes,
  1789. const DWORD dwFlags)
  1790. {
  1791. if( !IsValidDirectPlay8Object( pInterface ) )
  1792. {
  1793. DPFERR("Invalid object specified " );
  1794. return( DPNERR_INVALIDOBJECT );
  1795. }
  1796. if( pdwNumMsgs != NULL &&
  1797. !DNVALID_WRITEPTR( pdwNumMsgs, sizeof( DWORD ) ) )
  1798. {
  1799. DPFERR("Invalid num messages specified" );
  1800. return( DPNERR_INVALIDPOINTER );
  1801. }
  1802. if( pdwNumBytes != NULL &&
  1803. !DNVALID_WRITEPTR( pdwNumBytes, sizeof( DWORD ) ) )
  1804. {
  1805. DPFERR("Invalid num bytes specified" );
  1806. return( DPNERR_INVALIDPOINTER );
  1807. }
  1808. if( pdwNumBytes == NULL && pdwNumMsgs == NULL )
  1809. {
  1810. DPFERR("Must request at least one of num bytes and num messages" );
  1811. return( DPNERR_INVALIDPARAM );
  1812. }
  1813. if( dwFlags & ~(DPNGETSENDQUEUEINFO_PRIORITY_HIGH | DPNGETSENDQUEUEINFO_PRIORITY_LOW | DPNGETSENDQUEUEINFO_PRIORITY_NORMAL) )
  1814. {
  1815. DPFERR( "Invalid flags specified" );
  1816. return( DPNERR_INVALIDFLAGS );
  1817. }
  1818. return DPN_OK;
  1819. }
  1820. #undef DPF_MODNAME
  1821. #define DPF_MODNAME "DN_ValidateGetApplicationDesc"
  1822. HRESULT DN_ValidateGetApplicationDesc(PVOID pInterface,
  1823. DPN_APPLICATION_DESC *const pAppDescBuffer,
  1824. DWORD *const pcbDataSize,
  1825. const DWORD dwFlags )
  1826. {
  1827. if( !IsValidDirectPlay8Object( pInterface ) )
  1828. {
  1829. DPFERR("Invalid object specified " );
  1830. return( DPNERR_INVALIDOBJECT );
  1831. }
  1832. if( pcbDataSize == NULL ||
  1833. !DNVALID_WRITEPTR( pcbDataSize, sizeof( DWORD ) ) )
  1834. {
  1835. DPFERR("Invalid pointer specified for data size" );
  1836. return( DPNERR_INVALIDPOINTER );
  1837. }
  1838. if( *pcbDataSize > 0 &&
  1839. (pAppDescBuffer == NULL || !DNVALID_WRITEPTR( pAppDescBuffer, *pcbDataSize ) ) )
  1840. {
  1841. DPFERR( "Invalid pointer specified for app description buffer" );
  1842. return( DPNERR_INVALIDPOINTER );
  1843. }
  1844. if( *pcbDataSize > 0 &&
  1845. pAppDescBuffer->dwSize != sizeof( DPN_APPLICATION_DESC ) )
  1846. {
  1847. DPFERR("Invalid size specified" );
  1848. return(DPNERR_INVALIDPARAM);
  1849. }
  1850. if( dwFlags != 0 )
  1851. {
  1852. DPFERR( "Invalid flags specified" );
  1853. return( DPNERR_INVALIDFLAGS );
  1854. }
  1855. return DPN_OK;
  1856. }
  1857. #undef DPF_MODNAME
  1858. #define DPF_MODNAME "DN_ValidateSetApplicationDesc"
  1859. HRESULT DN_ValidateSetApplicationDesc(PVOID pInterface,
  1860. const DPN_APPLICATION_DESC *const pdnApplicationDesc,
  1861. const DWORD dwFlags)
  1862. {
  1863. HRESULT hResultCode;
  1864. if( !IsValidDirectPlay8Object( pInterface ) )
  1865. {
  1866. DPFERR("Invalid object specified " );
  1867. return( DPNERR_INVALIDOBJECT );
  1868. }
  1869. if( FAILED( hResultCode = DN_ValidHostAppDesc(pdnApplicationDesc) ) )
  1870. {
  1871. DPFX(DPFPREP, 0,"Invalid app desc specified hr=[0x%lx]", hResultCode );
  1872. return( hResultCode );
  1873. }
  1874. if( dwFlags != 0 )
  1875. {
  1876. DPFERR( "Invalid flags specified" );
  1877. return( DPNERR_INVALIDFLAGS );
  1878. }
  1879. return DPN_OK;
  1880. }
  1881. #undef DPF_MODNAME
  1882. #define DPF_MODNAME "DN_ValidateSendParams"
  1883. HRESULT DN_ValidateSendParams(PVOID pv,
  1884. const DPN_BUFFER_DESC *const pBufferDesc,
  1885. const DWORD cBufferDesc,
  1886. const DWORD dwTimeOut,
  1887. void *const pvAsyncContext,
  1888. DPNHANDLE *const phAsyncHandle,
  1889. const DWORD dwFlags )
  1890. {
  1891. HRESULT hResultCode;
  1892. if( !IsValidDirectPlay8Object( pv ) )
  1893. {
  1894. DPFERR("Invalid object specified " );
  1895. return(DPNERR_INVALIDOBJECT);
  1896. }
  1897. if( FAILED( hResultCode = DN_ValidBufferDescs( pBufferDesc, cBufferDesc ) ) )
  1898. {
  1899. DPFERR( "Invalid buffer descs specified" );
  1900. return( hResultCode );
  1901. }
  1902. if (pBufferDesc->dwBufferSize == 0)
  1903. {
  1904. DPFERR( "Cannot specify 0 data size" );
  1905. return(DPNERR_INVALIDPARAM);
  1906. }
  1907. if ( dwFlags & ~(DPNSEND_SYNC
  1908. | DPNSEND_NOCOPY
  1909. | DPNSEND_NOCOMPLETE
  1910. | DPNSEND_COMPLETEONPROCESS
  1911. | DPNSEND_GUARANTEED
  1912. | DPNSEND_NONSEQUENTIAL
  1913. | DPNSEND_NOLOOPBACK
  1914. | DPNSEND_PRIORITY_LOW
  1915. | DPNSEND_PRIORITY_HIGH
  1916. #ifdef DIRECTPLAYDIRECTX9
  1917. | DPNSEND_COALESCE
  1918. #endif // DIRECTPLAYDIRECTX9
  1919. ))
  1920. {
  1921. DPFERR( "Invalid flags specified" );
  1922. return(DPNERR_INVALIDFLAGS);
  1923. }
  1924. if ((dwFlags & DPNSEND_NOCOPY) && (dwFlags & DPNSEND_NOCOMPLETE))
  1925. {
  1926. DPFERR( "Cannot specify NOCOPY and NOCOMPLETE" );
  1927. return(DPNERR_INVALIDFLAGS);
  1928. }
  1929. if ((dwFlags & DPNSEND_COMPLETEONPROCESS) && (dwFlags & DPNSEND_NOCOMPLETE))
  1930. {
  1931. DPFERR("Cannot specify complete on process AND NOCOMPLETE" );
  1932. return(DPNERR_INVALIDFLAGS);
  1933. }
  1934. if ((dwFlags & DPNSEND_COMPLETEONPROCESS) && !(dwFlags & DPNSEND_GUARANTEED))
  1935. {
  1936. DPFERR("Cannot specify COMPLETEONPROCESS without guaranteed" );
  1937. return(DPNERR_INVALIDFLAGS);
  1938. }
  1939. // Guaranteed asyncs MUST get a complete
  1940. if ((dwFlags & DPNSEND_GUARANTEED) && !(dwFlags & DPNSEND_SYNC) &&
  1941. (dwFlags & DPNSEND_NOCOMPLETE) )
  1942. {
  1943. DPFERR("Async, guaranteed sends must get a completion" );
  1944. return(DPNERR_INVALIDFLAGS);
  1945. }
  1946. // Cannot specify high AND low priority
  1947. if ((dwFlags & DPNSEND_PRIORITY_HIGH) && (dwFlags & DPNSEND_PRIORITY_LOW))
  1948. {
  1949. DPFERR("Cannot specify high AND low priority");
  1950. return(DPNERR_INVALIDFLAGS);
  1951. }
  1952. if (dwFlags & DPNSEND_SYNC)
  1953. {
  1954. if( phAsyncHandle != NULL )
  1955. {
  1956. DPFERR( "You cannot specify an async handle if op is synchronous" );
  1957. return(DPNERR_INVALIDPARAM);
  1958. }
  1959. }
  1960. else
  1961. {
  1962. if( phAsyncHandle == NULL )
  1963. {
  1964. DPFERR( "You MUST specify a valid async handle if op async and/or has a completion" );
  1965. return(DPNERR_INVALIDPARAM);
  1966. }
  1967. if( !DNVALID_WRITEPTR( phAsyncHandle, sizeof( DPNHANDLE ) ) )
  1968. {
  1969. DPFERR("Invalid async handle pointer specified" );
  1970. return( DPNERR_INVALIDPOINTER );
  1971. }
  1972. }
  1973. #ifndef DPNBUILD_NOMULTICAST
  1974. DIRECTNETOBJECT *pdnObject;
  1975. // Multicast sends essentially must be normal priority, non-guaranteed, non-sequential sends.
  1976. pdnObject = static_cast<DIRECTNETOBJECT*>(GET_OBJECT_FROM_INTERFACE(pv));
  1977. if (pdnObject->dwFlags & DN_OBJECT_FLAG_MULTICAST)
  1978. {
  1979. if ((dwFlags & (DPNSEND_COMPLETEONPROCESS
  1980. | DPNSEND_GUARANTEED
  1981. | DPNSEND_NOLOOPBACK
  1982. | DPNSEND_PRIORITY_LOW
  1983. | DPNSEND_PRIORITY_HIGH
  1984. #ifdef DIRECTPLAYDIRECTX9
  1985. | DPNSEND_COALESCE
  1986. #endif // DIRECTPLAYDIRECTX9
  1987. )) ||
  1988. !(dwFlags & DPNSEND_NONSEQUENTIAL))
  1989. {
  1990. DPFERR("Multicast sends cannot be guaranteed, COMPLETEONPROCESS, and must be non-sequential, have normal priority, and be able to loop back");
  1991. return(DPNERR_INVALIDFLAGS);
  1992. }
  1993. if (dwTimeOut != 0)
  1994. {
  1995. DPFERR("Multicast sends cannot have timeouts");
  1996. return(DPNERR_INVALIDPARAM);
  1997. }
  1998. }
  1999. #endif // ! DPNBUILD_NOMULTICAST
  2000. return DPN_OK;
  2001. }
  2002. #ifndef DPNBUILD_NOMULTICAST
  2003. #undef DPF_MODNAME
  2004. #define DPF_MODNAME "DN_ValidateJoin"
  2005. HRESULT DN_ValidateJoin(IDirectPlay8Multicast *pInterface,
  2006. IDirectPlay8Address *const pGroupAddr,
  2007. IUnknown *const pDeviceInfo,
  2008. const DPN_SECURITY_DESC *const pdnSecurity,
  2009. const DPN_SECURITY_CREDENTIALS *const pdnCredentials,
  2010. void *const pvAsyncContext,
  2011. DPNHANDLE *const phAsyncHandle,
  2012. const DWORD dwFlags)
  2013. {
  2014. HRESULT hResultCode;
  2015. PVOID pvNewInterface;
  2016. #ifndef DPNBUILD_ONLYONESP
  2017. GUID guidSPFromGroup, guidSPFromDevice;
  2018. #endif // ! DPNBUILD_ONLYONESP
  2019. DWORD dwTmpPort;
  2020. DWORD dwDataType;
  2021. DWORD dwDataSize;
  2022. if( !IsValidDirectPlay8Object( pInterface ) )
  2023. {
  2024. DPFERR("Invalid object specified " );
  2025. return( DPNERR_INVALIDOBJECT );
  2026. }
  2027. // Check for an option group address.
  2028. #ifndef DPNBUILD_ONLYONESP
  2029. //
  2030. // Initialize the group object SP to GUID_NULL.
  2031. //
  2032. memset(&guidSPFromGroup, 0, sizeof(guidSPFromGroup));
  2033. #endif // ! DPNBUILD_ONLYONESP
  2034. if( pGroupAddr != NULL)
  2035. {
  2036. if( !DNVALID_READPTR( pGroupAddr, sizeof( IDirectPlay8Address * ) ) )
  2037. {
  2038. DPFERR("Invalid group address specified" );
  2039. return( DPNERR_INVALIDHOSTADDRESS );
  2040. }
  2041. #ifndef DPNBUILD_ONLYONESP
  2042. if( FAILED( hResultCode = IDirectPlay8Address_GetSP( pGroupAddr, &guidSPFromGroup ) ) )
  2043. {
  2044. DPFERR("No SP specified in host address" );
  2045. return( DPNERR_INVALIDHOSTADDRESS );
  2046. }
  2047. #endif // ! DPNBUILD_ONLYONESP
  2048. dwDataType = DPNA_DATATYPE_DWORD;
  2049. dwDataSize = sizeof( DWORD );
  2050. // Check to ensure it's not using the default DPNSVR port
  2051. if( SUCCEEDED( hResultCode = IDirectPlay8Address_GetComponentByName( pGroupAddr, DPNA_KEY_PORT, &dwTmpPort, &dwDataSize, &dwDataType ) ) )
  2052. {
  2053. if( dwTmpPort == DPNA_DPNSVR_PORT )
  2054. {
  2055. DPFERR( "Cannot use the DPNSVR port in device addresses" );
  2056. DPFERR( "This port is reserved for DPNSVR" );
  2057. return( DPNERR_INVALIDDEVICEADDRESS );
  2058. }
  2059. }
  2060. }
  2061. // A device address/object is required.
  2062. if( ( pDeviceInfo == NULL) ||
  2063. ( !DNVALID_READPTR( pDeviceInfo, sizeof( IUnknown * ) ) ) )
  2064. {
  2065. DPFERR("Invalid device address specified" );
  2066. return( DPNERR_INVALIDDEVICEADDRESS );
  2067. }
  2068. #ifndef DPNBUILD_ONLYONESP
  2069. //
  2070. // Initialize the group object SP to GUID_NULL.
  2071. //
  2072. memset(&guidSPFromDevice, 0, sizeof(guidSPFromGroup));
  2073. #endif // ! DPNBUILD_ONLYONESP
  2074. // Find out what type of interface this is.
  2075. if( ( (IDirectPlay8Peer_QueryInterface( (IDirectPlay8Peer*) pDeviceInfo, IID_IDirectPlay8Peer, &pvNewInterface )) == S_OK ) ||
  2076. #ifndef DPNBUILD_NOSERVER
  2077. ( (IDirectPlay8Server_QueryInterface( (IDirectPlay8Server*) pDeviceInfo, IID_IDirectPlay8Server, &pvNewInterface )) == S_OK ) ||
  2078. #endif // ! DPNBUILD_NOSERVER
  2079. ( (IDirectPlay8Client_QueryInterface( (IDirectPlay8Client*) pDeviceInfo, IID_IDirectPlay8Client, &pvNewInterface )) == S_OK ) ||
  2080. ( (IDirectPlay8Multicast_QueryInterface( (IDirectPlay8Multicast*) pDeviceInfo, IID_IDirectPlay8Multicast, &pvNewInterface )) == S_OK ) )
  2081. {
  2082. DIRECTNETOBJECT *pdnDeviceObject;
  2083. // It's a DIRECTNETOBJECT.
  2084. if( !IsValidDirectPlay8Object( pvNewInterface ) )
  2085. {
  2086. DPFERR("Invalid DirectPlay device object specified " );
  2087. IDirectPlay8Peer_Release((IDirectPlay8Peer*) pvNewInterface); // since it queried successfully like a core object, release it like a core object
  2088. pvNewInterface = NULL;
  2089. return( DPNERR_INVALIDDEVICEADDRESS );
  2090. }
  2091. // Make sure the DIRECTNETOBJECT is in the right state.
  2092. pdnDeviceObject = (DIRECTNETOBJECT*) GET_OBJECT_FROM_INTERFACE(pvNewInterface);
  2093. // Check to ensure message handler registered
  2094. if (!(pdnDeviceObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED))
  2095. {
  2096. DPFERR( "DirectPlay device object is not initialized" );
  2097. IDirectPlay8Peer_Release((IDirectPlay8Peer*) pvNewInterface); // all core objects release the same way
  2098. pvNewInterface = NULL;
  2099. DPF_RETURN(DPNERR_INVALIDDEVICEADDRESS);
  2100. }
  2101. if( pdnDeviceObject->dwFlags & DN_OBJECT_FLAG_CONNECTING )
  2102. {
  2103. DPFERR( "DirectPlay device object has not yet completed connecting / hosting" );
  2104. IDirectPlay8Peer_Release((IDirectPlay8Peer*) pvNewInterface); // all core objects release the same way
  2105. pvNewInterface = NULL;
  2106. DPF_RETURN(DPNERR_INVALIDDEVICEADDRESS);
  2107. }
  2108. if (!(pdnDeviceObject->dwFlags & DN_OBJECT_FLAG_CONNECTED) )
  2109. {
  2110. DPFERR("DirectPlay device object is not connected or hosting" );
  2111. IDirectPlay8Peer_Release((IDirectPlay8Peer*) pvNewInterface); // all core objects release the same way
  2112. pvNewInterface = NULL;
  2113. DPF_RETURN(DPNERR_INVALIDDEVICEADDRESS);
  2114. }
  2115. IDirectPlay8Peer_Release((IDirectPlay8Peer*) pvNewInterface); // all core objects release the same way
  2116. pvNewInterface = NULL;
  2117. }
  2118. else if( (IDirectPlay8Address_QueryInterface( (IDirectPlay8Address*) pDeviceInfo, IID_IDirectPlay8Address, &pvNewInterface )) == S_OK )
  2119. {
  2120. // It's an address.
  2121. #ifndef DPNBUILD_ONLYONESP
  2122. if( FAILED( hResultCode = IDirectPlay8Address_GetSP( reinterpret_cast<IDirectPlay8Address*>(pvNewInterface), &guidSPFromDevice ) ) )
  2123. {
  2124. DPFERR("No SP specified in device address" );
  2125. IDirectPlay8Address_Release(reinterpret_cast<IDirectPlay8Address*>(pvNewInterface));
  2126. pvNewInterface = NULL;
  2127. return( DPNERR_INVALIDDEVICEADDRESS );
  2128. }
  2129. #endif // ! DPNBUILD_ONLYONESP
  2130. dwDataType = DPNA_DATATYPE_DWORD;
  2131. dwDataSize = sizeof( DWORD );
  2132. // Check to ensure it's not using the default DPNSVR port
  2133. if( SUCCEEDED( hResultCode = IDirectPlay8Address_GetComponentByName( reinterpret_cast<IDirectPlay8Address*>(pvNewInterface), DPNA_KEY_PORT, &dwTmpPort, &dwDataSize, &dwDataType ) ) )
  2134. {
  2135. if( dwTmpPort == DPNA_DPNSVR_PORT )
  2136. {
  2137. DPFERR( "Cannot use the DPNSVR port in device addresses" );
  2138. DPFERR( "This port is reserved for DPNSVR" );
  2139. IDirectPlay8Address_Release(reinterpret_cast<IDirectPlay8Address*>(pvNewInterface));
  2140. pvNewInterface = NULL;
  2141. return( DPNERR_INVALIDDEVICEADDRESS );
  2142. }
  2143. }
  2144. IDirectPlay8Address_Release(reinterpret_cast<IDirectPlay8Address*>(pvNewInterface));
  2145. pvNewInterface = NULL;
  2146. #ifndef DPNBUILD_ONLYONESP
  2147. //
  2148. // Make sure that if both the group address or device address specified an SP,
  2149. // they both specified the same SP.
  2150. //
  2151. if (guidSPFromGroup != guidSPFromDevice)
  2152. {
  2153. //
  2154. // Reuse guidSPFromDevice to store GUID_NULL. It's okay that we lose the
  2155. // information it previously contained, we don't need it anymore.
  2156. //
  2157. memset(&guidSPFromDevice, 0, sizeof(guidSPFromDevice));
  2158. if (guidSPFromGroup != guidSPFromDevice)
  2159. {
  2160. DPFERR( "Specified different SPs for device and group" );
  2161. return(DPNERR_INVALIDDEVICEADDRESS);
  2162. }
  2163. }
  2164. #endif // ! DPNBUILD_ONLYONESP
  2165. }
  2166. else
  2167. {
  2168. DPFERR( "Invalid device address, it must be an IDirectPlay8Peer, IDirectPlay8Server, IDirectPlay8Client, IDirectPlay8Multicast, or IDirectPlay8Address object" );
  2169. return( DPNERR_INVALIDDEVICEADDRESS );
  2170. }
  2171. if( FAILED( hResultCode = DN_ValidSecurityDesc(pdnSecurity) ) )
  2172. {
  2173. DPFERR(" Invalid reserved specified" );
  2174. return( hResultCode );
  2175. }
  2176. if( FAILED( hResultCode = DN_ValidSecurityCredentials(pdnCredentials) ) )
  2177. {
  2178. DPFERR( "Invalid reserved2 specified" );
  2179. return( hResultCode );
  2180. }
  2181. if( dwFlags & ~( DPNJOIN_SYNC | DPNJOIN_ALLOWUNKNOWNSENDERS ) )
  2182. {
  2183. DPFERR( "Invalid flags specified" );
  2184. return( DPNERR_INVALIDFLAGS );
  2185. }
  2186. if( dwFlags & DPNJOIN_SYNC )
  2187. {
  2188. if( phAsyncHandle != NULL )
  2189. {
  2190. DPFERR( "You cannot specify an async handle if op is synchronous" );
  2191. return( DPNERR_INVALIDPARAM );
  2192. }
  2193. }
  2194. else
  2195. {
  2196. if( phAsyncHandle == NULL )
  2197. {
  2198. DPFERR( "You MUST specify a valid async handle w/async ops" );
  2199. return( DPNERR_INVALIDPARAM );
  2200. }
  2201. if( !DNVALID_WRITEPTR( phAsyncHandle, sizeof( DPNHANDLE ) ) )
  2202. {
  2203. DPFERR("Invalid async handle pointer specified" );
  2204. return( DPNERR_INVALIDPOINTER );
  2205. }
  2206. }
  2207. return DPN_OK;
  2208. }
  2209. #undef DPF_MODNAME
  2210. #define DPF_MODNAME "DN_ValidateGetGroupAddress"
  2211. HRESULT DN_ValidateGetGroupAddress(IDirectPlay8Multicast *pInterface,
  2212. IDirectPlay8Address **const ppAddress,
  2213. const DWORD dwFlags)
  2214. {
  2215. if( !IsValidDirectPlay8Object( pInterface ) )
  2216. {
  2217. DPFX(DPFPREP, 0, "Invalid object" );
  2218. return DPNERR_INVALIDOBJECT;
  2219. }
  2220. if( ppAddress == NULL || !DNVALID_WRITEPTR( ppAddress, sizeof( IDirectPlay8Address * ) ) )
  2221. {
  2222. DPFERR( "Invalid pointer specified for address" );
  2223. return DPNERR_INVALIDPOINTER;
  2224. }
  2225. if (dwFlags != 0)
  2226. {
  2227. DPFERR("Invalid flags specified");
  2228. return DPNERR_INVALIDFLAGS;
  2229. }
  2230. return DPN_OK;
  2231. }
  2232. #undef DPF_MODNAME
  2233. #define DPF_MODNAME "DN_ValidateCreateSenderContext"
  2234. HRESULT DN_ValidateCreateSenderContext(IDirectPlay8Multicast *pInterface,
  2235. IDirectPlay8Address *const pSenderAddress,
  2236. void *const pvSenderContext,
  2237. const DWORD dwFlags)
  2238. {
  2239. #ifndef DPNBUILD_ONLYONESP
  2240. HRESULT hResultCode;
  2241. GUID guidSender;
  2242. #endif // ! DPNBUILD_ONLYONESP
  2243. if( !IsValidDirectPlay8Object( pInterface ) )
  2244. {
  2245. DPFERR("Invalid object specified " );
  2246. return( DPNERR_INVALIDOBJECT );
  2247. }
  2248. if( pSenderAddress == NULL ||
  2249. !DNVALID_READPTR( pSenderAddress, sizeof( IDirectPlay8Address * ) ) )
  2250. {
  2251. DPFERR("Invalid host address specified" );
  2252. return( DPNERR_INVALIDHOSTADDRESS );
  2253. }
  2254. #ifndef DPNBUILD_ONLYONESP
  2255. if( FAILED( hResultCode = IDirectPlay8Address_GetSP( pSenderAddress, &guidSender ) ) )
  2256. {
  2257. DPFERR("No SP specified in address" );
  2258. return( DPNERR_INVALIDHOSTADDRESS );
  2259. }
  2260. #endif // ! DPNBUILD_ONLYONESP
  2261. if( dwFlags != 0 )
  2262. {
  2263. DPFERR("Invalid flags specified" );
  2264. return( DPNERR_INVALIDFLAGS );
  2265. }
  2266. return DPN_OK;
  2267. }
  2268. #undef DPF_MODNAME
  2269. #define DPF_MODNAME "DN_ValidateDestroySenderContext"
  2270. HRESULT DN_ValidateDestroySenderContext(IDirectPlay8Multicast *pInterface,
  2271. IDirectPlay8Address *const pSenderAddress,
  2272. const DWORD dwFlags)
  2273. {
  2274. #ifndef DPNBUILD_ONLYONESP
  2275. HRESULT hResultCode;
  2276. GUID guidSender;
  2277. #endif // ! DPNBUILD_ONLYONESP
  2278. if( !IsValidDirectPlay8Object( pInterface ) )
  2279. {
  2280. DPFERR("Invalid object specified " );
  2281. return( DPNERR_INVALIDOBJECT );
  2282. }
  2283. if( pSenderAddress == NULL ||
  2284. !DNVALID_READPTR( pSenderAddress, sizeof( IDirectPlay8Address * ) ) )
  2285. {
  2286. DPFERR("Invalid host address specified" );
  2287. return( DPNERR_INVALIDHOSTADDRESS );
  2288. }
  2289. #ifndef DPNBUILD_ONLYONESP
  2290. if( FAILED( hResultCode = IDirectPlay8Address_GetSP( pSenderAddress, &guidSender ) ) )
  2291. {
  2292. DPFERR("No SP specified in address" );
  2293. return( DPNERR_INVALIDHOSTADDRESS );
  2294. }
  2295. #endif // ! DPNBUILD_ONLYONESP
  2296. if( dwFlags != 0 )
  2297. {
  2298. DPFERR("Invalid flags specified" );
  2299. return( DPNERR_INVALIDFLAGS );
  2300. }
  2301. return DPN_OK;
  2302. }
  2303. #undef DPF_MODNAME
  2304. #define DPF_MODNAME "DN_ValidateEnumMulticastScopes"
  2305. HRESULT DN_ValidateEnumMulticastScopes(IDirectPlay8Multicast *pInterface,
  2306. const GUID *const pguidServiceProvider,
  2307. const GUID *const pguidDevice,
  2308. const GUID *const pguidApplication,
  2309. DPN_MULTICAST_SCOPE_INFO *const pScopeInfoBuffer,
  2310. DWORD *const pcbEnumData,
  2311. const DWORD *const pcReturned,
  2312. const DWORD dwFlags)
  2313. {
  2314. if( !IsValidDirectPlay8Object( pInterface ) )
  2315. {
  2316. DPFERR("Invalid object specified " );
  2317. return( DPNERR_INVALIDOBJECT );
  2318. }
  2319. if( pguidServiceProvider == NULL ||
  2320. !DNVALID_READPTR( pguidServiceProvider, sizeof( GUID ) ) )
  2321. {
  2322. DPFERR("Invalid service provider specified" );
  2323. return( DPNERR_INVALIDPOINTER );
  2324. }
  2325. if( pguidDevice == NULL ||
  2326. !DNVALID_READPTR( pguidDevice, sizeof( GUID ) ) )
  2327. {
  2328. DPFERR("Invalid device specified" );
  2329. return( DPNERR_INVALIDPOINTER );
  2330. }
  2331. if( pguidApplication != NULL &&
  2332. !DNVALID_READPTR( pguidApplication, sizeof( GUID ) ) )
  2333. {
  2334. DPFERR("Invalid application specified" );
  2335. return( DPNERR_INVALIDPOINTER );
  2336. }
  2337. if( pcbEnumData == NULL ||
  2338. !DNVALID_READPTR( pcbEnumData, sizeof( DWORD ) ) )
  2339. {
  2340. DPFERR("Invalid enum data pointer" );
  2341. return( DPNERR_INVALIDPOINTER );
  2342. }
  2343. if( pcReturned == NULL ||
  2344. !DNVALID_READPTR( pcReturned, sizeof( DWORD ) ) )
  2345. {
  2346. DPFERR("Invalid retuned count" );
  2347. return( DPNERR_INVALIDPOINTER );
  2348. }
  2349. if( *pcbEnumData > 0 &&
  2350. (pScopeInfoBuffer == NULL || !DNVALID_WRITEPTR(pScopeInfoBuffer,*pcbEnumData) ) )
  2351. {
  2352. DPFERR("Invalid enum buffer specified" );
  2353. return( DPNERR_INVALIDPOINTER );
  2354. }
  2355. if( dwFlags != 0 )
  2356. {
  2357. DPFERR("Invalid flags specified" );
  2358. return( DPNERR_INVALIDFLAGS );
  2359. }
  2360. return DPN_OK;
  2361. }
  2362. #endif // ! DPNBUILD_NOMULTICAST
  2363. #undef DPF_MODNAME
  2364. #define DPF_MODNAME "DN_ValidBufferDescs"
  2365. HRESULT DN_ValidBufferDescs(const DPN_BUFFER_DESC * const pbBufferDesc,
  2366. const DWORD cBufferDesc )
  2367. {
  2368. DWORD dw;
  2369. if( cBufferDesc == 0 )
  2370. {
  2371. DPFERR( "You must specify at least one buffer desc" );
  2372. return DPNERR_INVALIDPARAM;
  2373. }
  2374. if( cBufferDesc > DN_ASYNC_MAX_SEND_BUFFERDESC )
  2375. {
  2376. DPFX(DPFPREP, 0, "Too many buffer descs specified. Max allowed = %d", DN_ASYNC_MAX_SEND_BUFFERDESC );
  2377. return DPNERR_INVALIDPARAM;
  2378. }
  2379. if( pbBufferDesc == NULL ||
  2380. !DNVALID_READPTR( pbBufferDesc, cBufferDesc*sizeof( DPN_BUFFER_DESC ) ) )
  2381. {
  2382. DPFX(DPFPREP, 0, "Invalid buffer for buffer description" );
  2383. return DPNERR_INVALIDPOINTER;
  2384. }
  2385. for ( dw = 0 ; dw < cBufferDesc ; dw++ )
  2386. {
  2387. if( pbBufferDesc[dw].dwBufferSize > 0 &&
  2388. (pbBufferDesc[dw].pBufferData == NULL || !DNVALID_READPTR( pbBufferDesc[dw].pBufferData, pbBufferDesc[dw].dwBufferSize ) ) )
  2389. {
  2390. DPFX(DPFPREP, 0, "Invalid pBuffer Data" );
  2391. return DPNERR_INVALIDPOINTER;
  2392. }
  2393. }
  2394. return DPN_OK;
  2395. }
  2396. #undef DPF_MODNAME
  2397. #define DPF_MODNAME "DN_ValidConnectAppDesc"
  2398. HRESULT DN_ValidConnectAppDesc( const DPN_APPLICATION_DESC * const pdnAppDesc )
  2399. {
  2400. if( pdnAppDesc == NULL ||
  2401. !DNVALID_READPTR( pdnAppDesc, sizeof( DPN_APPLICATION_DESC ) ) )
  2402. {
  2403. DPFX(DPFPREP, 0, "Invalid pointer for app description" );
  2404. return DPNERR_INVALIDPOINTER;
  2405. }
  2406. if( pdnAppDesc->dwSize != sizeof( DPN_APPLICATION_DESC ) )
  2407. {
  2408. DPFX(DPFPREP, 0, "Invalid size for app description" );
  2409. return DPNERR_INVALIDPARAM;
  2410. }
  2411. if( pdnAppDesc->pwszSessionName != NULL &&
  2412. !DNVALID_STRING_W( pdnAppDesc->pwszSessionName ) )
  2413. {
  2414. DPFX(DPFPREP, 0, "Invalid session name specified" );
  2415. return DPNERR_INVALIDSTRING;
  2416. }
  2417. if( pdnAppDesc->pwszPassword != NULL &&
  2418. !DNVALID_STRING_W( pdnAppDesc->pwszPassword ) )
  2419. {
  2420. DPFX(DPFPREP, 0, "Invalid session desc" );
  2421. return DPNERR_INVALIDSTRING;
  2422. }
  2423. if (pdnAppDesc->dwReservedDataSize > 0)
  2424. {
  2425. if ((pdnAppDesc->pvReservedData == NULL) ||
  2426. (! DNVALID_READPTR(pdnAppDesc->pvReservedData, pdnAppDesc->dwReservedDataSize)))
  2427. {
  2428. DPFERR("Invalid pointer specified for application desc reserved data");
  2429. return DPNERR_INVALIDPARAM;
  2430. }
  2431. //
  2432. // Make sure it's a type we know about and that it's valid.
  2433. //
  2434. if ((pdnAppDesc->dwReservedDataSize == DPN_MAX_APPDESC_RESERVEDDATA_SIZE) &&
  2435. (*((DWORD*) pdnAppDesc->pvReservedData) == SPSESSIONDATAINFO_XNET))
  2436. {
  2437. SPSESSIONDATA_XNET * pSessionDataXNet;
  2438. BYTE bCompare;
  2439. BYTE * pbCurrent;
  2440. DWORD dwBytesRemaining;
  2441. pSessionDataXNet = (SPSESSIONDATA_XNET*) pdnAppDesc->pvReservedData;
  2442. bCompare = ((BYTE*) (&pSessionDataXNet->ullKeyID))[1] ^ ((BYTE*) (&pSessionDataXNet->guidKey))[2];
  2443. pbCurrent = (BYTE*) (pSessionDataXNet + 1);
  2444. dwBytesRemaining = DPN_MAX_APPDESC_RESERVEDDATA_SIZE - sizeof(SPSESSIONDATA_XNET);
  2445. while (dwBytesRemaining > 0)
  2446. {
  2447. if (*pbCurrent != bCompare)
  2448. {
  2449. DPFERR("Unsupported application desc reserved data");
  2450. return DPNERR_INVALIDPARAM;
  2451. }
  2452. dwBytesRemaining--;
  2453. pbCurrent++;
  2454. }
  2455. }
  2456. else
  2457. {
  2458. DPFERR("Unsupported application desc reserved data");
  2459. return DPNERR_INVALIDPARAM;
  2460. }
  2461. }
  2462. else
  2463. {
  2464. if (pdnAppDesc->pvReservedData != NULL)
  2465. {
  2466. DPFERR("Application desc reserved data pointer should be NULL if reserved data size is 0");
  2467. return DPNERR_INVALIDPARAM;
  2468. }
  2469. }
  2470. return DPN_OK;
  2471. }
  2472. #undef DPF_MODNAME
  2473. #define DPF_MODNAME "DN_ValidHostAppDesc"
  2474. HRESULT DN_ValidHostAppDesc( const DPN_APPLICATION_DESC * const pdnAppDesc )
  2475. {
  2476. GUID guidnull;
  2477. if( pdnAppDesc == NULL ||
  2478. !DNVALID_READPTR( pdnAppDesc, sizeof( DPN_APPLICATION_DESC ) ) )
  2479. {
  2480. DPFX(DPFPREP, 0, "Invalid pointer for app description" );
  2481. return DPNERR_INVALIDPOINTER;
  2482. }
  2483. if( pdnAppDesc->dwSize != sizeof( DPN_APPLICATION_DESC ) )
  2484. {
  2485. DPFX(DPFPREP, 0, "Invalid size for app description" );
  2486. return DPNERR_INVALIDPARAM;
  2487. }
  2488. if( pdnAppDesc->dwFlags & ~(DPNSESSION_CLIENT_SERVER |
  2489. #ifndef DPNBUILD_NOHOSTMIGRATE
  2490. DPNSESSION_MIGRATE_HOST |
  2491. #endif // ! DPNBUILD_NOHOSTMIGRATE
  2492. DPNSESSION_REQUIREPASSWORD |
  2493. DPNSESSION_NODPNSVR
  2494. #ifdef DIRECTPLAYDIRECTX9
  2495. |
  2496. DPNSESSION_NOENUMS |
  2497. DPNSESSION_FAST_SIGNED |
  2498. DPNSESSION_FULL_SIGNED
  2499. #endif // DIRECTPLAYDIRECTX9
  2500. ) )
  2501. {
  2502. DPFX(DPFPREP, 0, "Invalid flag specified" );
  2503. return DPNERR_INVALIDFLAGS;
  2504. }
  2505. #ifdef DIRECTPLAYDIRECTX9
  2506. if ((pdnAppDesc->dwFlags & DPNSESSION_FAST_SIGNED) && (pdnAppDesc->dwFlags & DPNSESSION_FULL_SIGNED))
  2507. {
  2508. DPFX(DPFPREP, 0, "Cannot have both fast and full signed session" );
  2509. return DPNERR_INVALIDPARAM;
  2510. }
  2511. #endif // DIRECTPLAYDIRECTX9
  2512. #ifndef DPNBUILD_NOHOSTMIGRATE
  2513. if( (pdnAppDesc->dwFlags & DPNSESSION_CLIENT_SERVER) &&
  2514. (pdnAppDesc->dwFlags & DPNSESSION_MIGRATE_HOST) )
  2515. {
  2516. DPFX(DPFPREP, 0, "Cannot have host migration with client/server" );
  2517. return DPNERR_INVALIDPARAM;
  2518. }
  2519. #endif // !DPNBUILD_NOHOSTMIGRATE
  2520. memset(&guidnull, 0, sizeof(guidnull));
  2521. if( pdnAppDesc->guidApplication == guidnull )
  2522. {
  2523. DPFERR( "You must specify a valid GUID for your application GUID" );
  2524. return DPNERR_INVALIDPARAM;
  2525. }
  2526. if( pdnAppDesc->pwszSessionName != NULL &&
  2527. !DNVALID_STRING_W( pdnAppDesc->pwszSessionName ) )
  2528. {
  2529. DPFX(DPFPREP, 0, "Invalid session name" );
  2530. return DPNERR_INVALIDSTRING;
  2531. }
  2532. if( pdnAppDesc->dwFlags & DPNSESSION_REQUIREPASSWORD )
  2533. {
  2534. if( pdnAppDesc->pwszPassword == NULL )
  2535. {
  2536. DPFERR( "Must specify a password w/the requirepassword flag." );
  2537. return DPNERR_INVALIDPARAM;
  2538. }
  2539. if( !DNVALID_STRING_W( pdnAppDesc->pwszPassword ) )
  2540. {
  2541. DPFX(DPFPREP, 0, "Invalid password specified." );
  2542. return DPNERR_INVALIDSTRING;
  2543. }
  2544. }
  2545. else
  2546. {
  2547. if( pdnAppDesc->pwszPassword != NULL )
  2548. {
  2549. DPFERR( "Cannot specify a password without the requirepassword flag" );
  2550. return DPNERR_INVALIDPARAM;
  2551. }
  2552. }
  2553. if (pdnAppDesc->dwReservedDataSize > 0)
  2554. {
  2555. if ((pdnAppDesc->pvReservedData == NULL) ||
  2556. (! DNVALID_READPTR(pdnAppDesc->pvReservedData, pdnAppDesc->dwReservedDataSize)))
  2557. {
  2558. DPFERR("Invalid pointer specified for application desc reserved data");
  2559. return DPNERR_INVALIDPARAM;
  2560. }
  2561. //
  2562. // Make sure it's a type we know about and that it's valid.
  2563. //
  2564. if ((pdnAppDesc->dwReservedDataSize == DPN_MAX_APPDESC_RESERVEDDATA_SIZE) &&
  2565. (*((DWORD*) pdnAppDesc->pvReservedData) == SPSESSIONDATAINFO_XNET))
  2566. {
  2567. SPSESSIONDATA_XNET * pSessionDataXNet;
  2568. BYTE bCompare;
  2569. BYTE * pbCurrent;
  2570. DWORD dwBytesRemaining;
  2571. pSessionDataXNet = (SPSESSIONDATA_XNET*) pdnAppDesc->pvReservedData;
  2572. bCompare = ((BYTE*) (&pSessionDataXNet->ullKeyID))[1] ^ ((BYTE*) (&pSessionDataXNet->guidKey))[2];
  2573. pbCurrent = (BYTE*) (pSessionDataXNet + 1);
  2574. dwBytesRemaining = DPN_MAX_APPDESC_RESERVEDDATA_SIZE - sizeof(SPSESSIONDATA_XNET);
  2575. while (dwBytesRemaining > 0)
  2576. {
  2577. if (*pbCurrent != bCompare)
  2578. {
  2579. DPFERR("Unsupported application desc reserved data");
  2580. return DPNERR_INVALIDPARAM;
  2581. }
  2582. dwBytesRemaining--;
  2583. pbCurrent++;
  2584. }
  2585. }
  2586. else
  2587. {
  2588. DPFERR("Unsupported application desc reserved data");
  2589. return DPNERR_INVALIDPARAM;
  2590. }
  2591. }
  2592. else
  2593. {
  2594. if (pdnAppDesc->pvReservedData != NULL)
  2595. {
  2596. DPFERR("Application desc reserved data pointer should be NULL if reserved data size is 0");
  2597. return DPNERR_INVALIDPARAM;
  2598. }
  2599. }
  2600. if ( pdnAppDesc->dwApplicationReservedDataSize != 0 &&
  2601. !DNVALID_READPTR( pdnAppDesc->pvApplicationReservedData, pdnAppDesc->dwApplicationReservedDataSize ) )
  2602. {
  2603. DPFX(DPFPREP, 0, "Invalid pointer for application reserved data" );
  2604. return DPNERR_INVALIDPARAM;
  2605. }
  2606. return DPN_OK;
  2607. }
  2608. #undef DPF_MODNAME
  2609. #define DPF_MODNAME "DN_ValidPlayerInfo"
  2610. HRESULT DN_ValidPlayerInfo(const DPN_PLAYER_INFO * const pdnPlayerInfo,
  2611. BOOL fSet )
  2612. {
  2613. if( pdnPlayerInfo == NULL ||
  2614. !DNVALID_READPTR( pdnPlayerInfo, sizeof( DPN_PLAYER_INFO ) ) )
  2615. {
  2616. DPFX(DPFPREP, 0, "Invalid pointer for player info" );
  2617. return DPNERR_INVALIDPOINTER;
  2618. }
  2619. if( pdnPlayerInfo->dwSize != sizeof( DPN_PLAYER_INFO ) )
  2620. {
  2621. DPFX(DPFPREP, 0, "Invalid size for player info" );
  2622. return DPNERR_INVALIDPARAM;
  2623. }
  2624. if( fSet )
  2625. {
  2626. if( pdnPlayerInfo->dwInfoFlags & ~(DPNINFO_NAME | DPNINFO_DATA) )
  2627. {
  2628. DPFERR("Invalid info flags specified" );
  2629. return DPNERR_INVALIDFLAGS;
  2630. }
  2631. if( pdnPlayerInfo->dwInfoFlags & DPNINFO_NAME )
  2632. {
  2633. if( pdnPlayerInfo->pwszName != NULL && !DNVALID_STRING_W( pdnPlayerInfo->pwszName ) )
  2634. {
  2635. DPFERR("Invalid string specified for name" );
  2636. return DPNERR_INVALIDSTRING;
  2637. }
  2638. }
  2639. else
  2640. {
  2641. if( pdnPlayerInfo->pwszName != NULL )
  2642. {
  2643. DPFERR( "You must specify DPNINFO_NAME to set name" );
  2644. return DPNERR_INVALIDSTRING;
  2645. }
  2646. }
  2647. if( pdnPlayerInfo->dwInfoFlags & DPNINFO_DATA )
  2648. {
  2649. if( pdnPlayerInfo->dwDataSize > 0 &&
  2650. (pdnPlayerInfo->pvData == NULL || !DNVALID_READPTR( pdnPlayerInfo->pvData, pdnPlayerInfo->dwDataSize ) ) )
  2651. {
  2652. DPFERR("Invalid pointer specified for data" );
  2653. return DPNERR_INVALIDPOINTER;
  2654. }
  2655. }
  2656. else
  2657. {
  2658. if( pdnPlayerInfo->pvData != NULL )
  2659. {
  2660. DPFERR("You must specify DPNINFO_DATA if you want to set data" );
  2661. return DPNERR_INVALIDPARAM;
  2662. }
  2663. }
  2664. if( pdnPlayerInfo->dwPlayerFlags != 0 )
  2665. {
  2666. DPFERR( "Invalid player flags specified" );
  2667. return DPNERR_INVALIDFLAGS;
  2668. }
  2669. }
  2670. return DPN_OK;
  2671. }
  2672. #undef DPF_MODNAME
  2673. #define DPF_MODNAME "DN_ValidGroupInfo"
  2674. HRESULT DN_ValidGroupInfo(const DPN_GROUP_INFO * const pdnGroupInfo,
  2675. BOOL fSet )
  2676. {
  2677. if( pdnGroupInfo == NULL ||
  2678. !DNVALID_READPTR( pdnGroupInfo, sizeof( DPN_GROUP_INFO ) ) )
  2679. {
  2680. DPFX(DPFPREP, 0, "Invalid pointer for group info" );
  2681. return DPNERR_INVALIDPOINTER;
  2682. }
  2683. if( pdnGroupInfo->dwSize != sizeof( DPN_GROUP_INFO ) )
  2684. {
  2685. DPFX(DPFPREP, 0, "Invalid size for group info" );
  2686. return DPNERR_INVALIDPARAM;
  2687. }
  2688. if( fSet )
  2689. {
  2690. if( pdnGroupInfo->dwInfoFlags & ~(DPNINFO_NAME | DPNINFO_DATA) )
  2691. {
  2692. DPFERR("Invalid info flags specified" );
  2693. return DPNERR_INVALIDFLAGS;
  2694. }
  2695. if( pdnGroupInfo->dwInfoFlags & DPNINFO_NAME )
  2696. {
  2697. if( pdnGroupInfo->pwszName != NULL && !DNVALID_STRING_W( pdnGroupInfo->pwszName ) )
  2698. {
  2699. DPFERR("Invalid string specified for name" );
  2700. return DPNERR_INVALIDSTRING;
  2701. }
  2702. }
  2703. else
  2704. {
  2705. if( pdnGroupInfo->pwszName != NULL )
  2706. {
  2707. DPFERR( "You must specify DPNINFO_NAME to set name" );
  2708. return DPNERR_INVALIDSTRING;
  2709. }
  2710. }
  2711. if( pdnGroupInfo->dwInfoFlags & DPNINFO_DATA )
  2712. {
  2713. if( pdnGroupInfo->dwDataSize > 0 &&
  2714. (pdnGroupInfo->pvData == NULL || !DNVALID_READPTR( pdnGroupInfo->pvData, pdnGroupInfo->dwDataSize ) ) )
  2715. {
  2716. DPFERR("Invalid pointer specified for data" );
  2717. return DPNERR_INVALIDPOINTER;
  2718. }
  2719. }
  2720. else
  2721. {
  2722. if( pdnGroupInfo->pvData != NULL )
  2723. {
  2724. DPFERR("You must specify DPNINFO_DATA if you want to set data" );
  2725. return DPNERR_INVALIDPARAM;
  2726. }
  2727. }
  2728. if( pdnGroupInfo->dwGroupFlags & ~(DPNGROUP_AUTODESTRUCT /* | DPNGROUP_MULTICAST */ ) )
  2729. {
  2730. DPFERR( "Invalid group flags specified" );
  2731. return DPNERR_INVALIDFLAGS;
  2732. }
  2733. }
  2734. return DPN_OK;
  2735. }
  2736. #undef DPF_MODNAME
  2737. #define DPF_MODNAME "DN_ValidSecurityCredentials"
  2738. HRESULT DN_ValidSecurityCredentials( const DPN_SECURITY_CREDENTIALS * const pdnCredentials )
  2739. {
  2740. if( pdnCredentials != NULL )
  2741. {
  2742. DPFERR( "Invalid value for reserved field" );
  2743. return DPNERR_INVALIDPOINTER;
  2744. }
  2745. return DPN_OK;
  2746. }
  2747. #undef DPF_MODNAME
  2748. #define DPF_MODNAME "DN_ValidSecurityDesc"
  2749. HRESULT DN_ValidSecurityDesc( const DPN_SECURITY_DESC * const pdnValidSecurityDesc )
  2750. {
  2751. if( pdnValidSecurityDesc != NULL )
  2752. {
  2753. DPFERR( "Invalid value for reserved field" );
  2754. return DPNERR_INVALIDPOINTER;
  2755. }
  2756. return DPN_OK;
  2757. }
  2758. #undef DPF_MODNAME
  2759. #define DPF_MODNAME "IsValidDirectPlay8Object"
  2760. BOOL IsValidDirectPlay8Object( LPVOID lpvObject )
  2761. #ifdef DPNBUILD_LIBINTERFACE
  2762. {
  2763. DIRECTNETOBJECT *pdn = (PDIRECTNETOBJECT) GET_OBJECT_FROM_INTERFACE( lpvObject );
  2764. if( pdn == NULL ||
  2765. !DNVALID_WRITEPTR( pdn, sizeof( DIRECTNETOBJECT ) ) )
  2766. {
  2767. DPFX(DPFPREP, 0, "Invalid object" );
  2768. return FALSE;
  2769. }
  2770. if( pdn->lpVtbl != &DN_ClientVtbl &&
  2771. pdn->lpVtbl != &DN_PeerVtbl &&
  2772. #ifndef DPNBUILD_NOSERVER
  2773. pdn->lpVtbl != &DN_ServerVtbl &&
  2774. #endif // ! DPNBUILD_NOSERVER
  2775. #ifndef DPNBUILD_NOVOICE
  2776. pdn->lpVtbl != &DN_VoiceTbl &&
  2777. #endif // ! DPNBUILD_NOVOICE
  2778. #ifndef DPNBUILD_NOPROTOCOLTESTITF
  2779. pdn->lpVtbl != &DN_ProtocolVtbl &&
  2780. #endif // ! DPNBUILD_NOPROTOCOLTESTITF
  2781. #ifndef DPNBUILD_NOMULTICAST
  2782. pdn->lpVtbl != &DNMcast_Vtbl &&
  2783. #endif // ! DPNBUILD_NOMULTICAST
  2784. pdn->lpVtbl != &SPMessagesVtbl
  2785. )
  2786. {
  2787. DPFX(DPFPREP, 0, "Invalid object - bad vtable" );
  2788. return FALSE;
  2789. }
  2790. return TRUE;
  2791. }
  2792. #else // ! DPNBUILD_LIBINTERFACE
  2793. {
  2794. INTERFACE_LIST *pIntList = (INTERFACE_LIST *) lpvObject;
  2795. if( !DNVALID_READPTR( lpvObject, sizeof( INTERFACE_LIST ) ) )
  2796. {
  2797. DPFX(DPFPREP, 0, "Invalid object pointer" );
  2798. return FALSE;
  2799. }
  2800. if( pIntList->lpVtbl != &DN_ClientVtbl &&
  2801. pIntList->lpVtbl != &DN_PeerVtbl &&
  2802. #ifndef DPNBUILD_NOSERVER
  2803. pIntList->lpVtbl != &DN_ServerVtbl &&
  2804. #endif // ! DPNBUILD_NOSERVER
  2805. #ifndef DPNBUILD_NOVOICE
  2806. pIntList->lpVtbl != &DN_VoiceTbl &&
  2807. #endif // ! DPNBUILD_NOVOICE
  2808. #ifndef DPNBUILD_NOPROTOCOLTESTITF
  2809. pIntList->lpVtbl != &DN_ProtocolVtbl &&
  2810. #endif // ! DPNBUILD_NOPROTOCOLTESTITF
  2811. #ifndef DPNBUILD_NOMULTICAST
  2812. pIntList->lpVtbl != &DNMcast_Vtbl &&
  2813. #endif // ! DPNBUILD_NOMULTICAST
  2814. pIntList->lpVtbl != &SPMessagesVtbl
  2815. )
  2816. {
  2817. DPFX(DPFPREP, 0, "Invalid object - bad vtable" );
  2818. return FALSE;
  2819. }
  2820. if( pIntList->iid != IID_IDirectPlay8Client &&
  2821. pIntList->iid != IID_IDirectPlay8Peer &&
  2822. #ifndef DPNBUILD_NOSERVER
  2823. pIntList->iid != IID_IDirectPlay8Server &&
  2824. #endif // ! DPNBUILD_NOSERVER
  2825. #ifndef DPNBUILD_NOVOICE
  2826. pIntList->iid != IID_IDirectPlayVoiceTransport &&
  2827. #endif // ! DPNBUILD_NOVOICE
  2828. #ifndef DPNBUILD_NOPROTOCOLTESTITF
  2829. pIntList->iid != IID_IDirectPlay8Protocol &&
  2830. #endif // ! DPNBUILD_NOPROTOCOLTESTITF
  2831. #ifndef DPNBUILD_NOMULTICAST
  2832. pIntList->iid != IID_IDirectPlay8Multicast &&
  2833. #endif // ! DPNBUILD_NOMULTICAST
  2834. pIntList->iid != IID_IDP8SPCallback )
  2835. {
  2836. DPFX(DPFPREP, 0, "Invalid object - bad iid" );
  2837. return FALSE;
  2838. }
  2839. if( pIntList->pObject == NULL ||
  2840. !DNVALID_READPTR( pIntList->pObject, sizeof( OBJECT_DATA ) ) )
  2841. {
  2842. DPFX(DPFPREP, 0, "Invalid object" );
  2843. return FALSE;
  2844. }
  2845. DIRECTNETOBJECT *pdn = (PDIRECTNETOBJECT) GET_OBJECT_FROM_INTERFACE( lpvObject );
  2846. if( pdn == NULL ||
  2847. !DNVALID_WRITEPTR( pdn, sizeof( DIRECTNETOBJECT ) ) )
  2848. {
  2849. DPFX(DPFPREP, 0, "Invalid object" );
  2850. return FALSE;
  2851. }
  2852. return TRUE;
  2853. }
  2854. #endif // ! DPNBUILD_LIBINTERFACE
  2855. #undef DPF_MODNAME
  2856. #define DPF_MODNAME "DN_ValidSPCaps"
  2857. HRESULT DN_ValidSPCaps( const DPN_SP_CAPS * const pdnSPCaps )
  2858. {
  2859. if( pdnSPCaps == NULL ||
  2860. !DNVALID_READPTR( pdnSPCaps, sizeof( DPN_SP_CAPS ) ) )
  2861. {
  2862. DPFX(DPFPREP, 0, "Invalid pointer for SP caps" );
  2863. return DPNERR_INVALIDPOINTER;
  2864. }
  2865. if( pdnSPCaps->dwSize != sizeof( DPN_SP_CAPS ) )
  2866. {
  2867. DPFX(DPFPREP, 0, "Invalid structure size" );
  2868. return DPNERR_INVALIDPARAM;
  2869. }
  2870. #ifdef DPNBUILD_ONLYONETHREAD
  2871. if ( pdnSPCaps->dwNumThreads != 0 )
  2872. {
  2873. DPFX(DPFPREP, 0, "Invalid thread count, must be 0!" );
  2874. return DPNERR_INVALIDPARAM;
  2875. }
  2876. #endif // DPNBUILD_ONLYONETHREAD
  2877. if ( pdnSPCaps->dwBuffersPerThread == 0 )
  2878. {
  2879. DPFX(DPFPREP, 0, "Invalid buffers per thread setting!" );
  2880. return DPNERR_INVALIDPARAM;
  2881. }
  2882. return DPN_OK;
  2883. }
  2884. #undef DPF_MODNAME
  2885. #define DPF_MODNAME "DN_ValidConnectionInfo"
  2886. HRESULT DN_ValidConnectionInfo( const DPN_CONNECTION_INFO * const pdnConnectionInfo )
  2887. {
  2888. if( pdnConnectionInfo == NULL ||
  2889. !DNVALID_READPTR( pdnConnectionInfo, sizeof( DPN_CONNECTION_INFO ) ) )
  2890. {
  2891. DPFX(DPFPREP, 0, "Invalid pointer for connection info" );
  2892. return DPNERR_INVALIDPOINTER;
  2893. }
  2894. if( pdnConnectionInfo->dwSize != sizeof( DPN_CONNECTION_INFO )
  2895. #ifndef DPNBUILD_NOPROTOCOLTESTITF
  2896. && pdnConnectionInfo->dwSize != sizeof( DPN_CONNECTION_INFO_INTERNAL )
  2897. #endif // !DPNBUILD_NOPROTOCOLTESTITF
  2898. )
  2899. {
  2900. DPFX(DPFPREP, 0, "Invalid structure size" );
  2901. return DPNERR_INVALIDPARAM;
  2902. }
  2903. return DPN_OK;
  2904. }
  2905. #undef DPF_MODNAME
  2906. #define DPF_MODNAME "DN_ValidCaps"
  2907. HRESULT DN_ValidCaps( const DPN_CAPS * const pdnCaps )
  2908. {
  2909. if( pdnCaps == NULL )
  2910. {
  2911. DPFX(DPFPREP, 0, "Invalid pointer for caps" );
  2912. return DPNERR_INVALIDPOINTER;
  2913. }
  2914. if( pdnCaps->dwSize != sizeof( DPN_CAPS ) && pdnCaps->dwSize != sizeof( DPN_CAPS_EX))
  2915. {
  2916. DPFX(DPFPREP, 0, "Invalid structure size" );
  2917. return DPNERR_INVALIDPARAM;
  2918. }
  2919. if (DNVALID_READPTR( pdnCaps, pdnCaps->dwSize)==FALSE)
  2920. {
  2921. DPFX(DPFPREP, 0, "Invalid pointer for caps" );
  2922. return DPNERR_INVALIDPOINTER;
  2923. }
  2924. if (pdnCaps->dwSize == sizeof( DPN_CAPS_EX))
  2925. {
  2926. DPN_CAPS_EX * pCapsEx=(DPN_CAPS_EX * ) pdnCaps;
  2927. if (pCapsEx->dwNumSendRetries>MAX_SEND_RETRIES_TO_DROP_LINK)
  2928. {
  2929. DPFX(DPFPREP, 0, "DPN_CAPS_EX::dwMaxNumSendRetries value %u is greater than %u ",
  2930. pCapsEx->dwNumSendRetries, MAX_SEND_RETRIES_TO_DROP_LINK);
  2931. return DPNERR_INVALIDPARAM;
  2932. }
  2933. if (pCapsEx->dwMaxSendRetryInterval>MAX_SEND_RETRY_INTERVAL_LIMIT)
  2934. {
  2935. DPFX(DPFPREP, 0, "DPN_CAPS_EX::dwMaxSendRetryInterval value %u is greater than %u ",
  2936. pCapsEx->dwMaxSendRetryInterval, MAX_SEND_RETRY_INTERVAL_LIMIT);
  2937. return DPNERR_INVALIDPARAM;
  2938. }
  2939. else if (pCapsEx->dwMaxSendRetryInterval<MIN_SEND_RETRY_INTERVAL_LIMIT)
  2940. {
  2941. DPFX(DPFPREP, 0, "DPN_CAPS_EX::dwMaxSendRetryInterval value %u is less than %u ",
  2942. pCapsEx->dwMaxSendRetryInterval, MIN_SEND_RETRY_INTERVAL_LIMIT);
  2943. return DPNERR_INVALIDPARAM;
  2944. }
  2945. if (pCapsEx->dwDropThresholdRate > 100)
  2946. {
  2947. DPFX(DPFPREP, 0, "DPN_CAPS_EX::dwDropThresholdRate value %u is greater than 100",
  2948. pCapsEx->dwDropThresholdRate);
  2949. return DPNERR_INVALIDPARAM;
  2950. }
  2951. if (pCapsEx->dwThrottleRate > 100)
  2952. {
  2953. DPFX(DPFPREP, 0, "DPN_CAPS_EX::dwThrottleRate value %u is greater than 100",
  2954. pCapsEx->dwThrottleRate);
  2955. return DPNERR_INVALIDPARAM;
  2956. }
  2957. if (pCapsEx->dwNumHardDisconnectSends>MAX_HARD_DISCONNECT_SENDS)
  2958. {
  2959. DPFX(DPFPREP, 0, "DPN_CAPS_EX::dwNumHardDisconnectSends value %u is greater than %u",
  2960. pCapsEx->dwNumHardDisconnectSends, MAX_HARD_DISCONNECT_SENDS);
  2961. return DPNERR_INVALIDPARAM;
  2962. }
  2963. else if (pCapsEx->dwNumHardDisconnectSends<MIN_HARD_DISCONNECT_SENDS)
  2964. {
  2965. DPFX(DPFPREP, 0, "DPN_CAPS_EX::dwNumHardDisconnectSends value %u is less than %u",
  2966. pCapsEx->dwNumHardDisconnectSends, MIN_HARD_DISCONNECT_SENDS);
  2967. return DPNERR_INVALIDPARAM;
  2968. }
  2969. if (pCapsEx->dwMaxHardDisconnectPeriod>MAX_HARD_DISCONNECT_PERIOD)
  2970. {
  2971. DPFX(DPFPREP, 0, "DPN_CAPS_EX::dwMaxHardDisconnectPeriod value %u is greater than %u",
  2972. pCapsEx->dwMaxHardDisconnectPeriod, MAX_HARD_DISCONNECT_PERIOD);
  2973. return DPNERR_INVALIDPARAM;
  2974. }
  2975. else if (pCapsEx->dwMaxHardDisconnectPeriod<MIN_HARD_DISCONNECT_PERIOD)
  2976. {
  2977. DPFX(DPFPREP, 0, "DPN_CAPS_EX::dwMaxHardDisconnectPeriod value %u is less than %u",
  2978. pCapsEx->dwMaxHardDisconnectPeriod, MIN_HARD_DISCONNECT_PERIOD);
  2979. return DPNERR_INVALIDPARAM;
  2980. }
  2981. }
  2982. return DPN_OK;
  2983. }
  2984. #endif // !DPNBUILD_NOPARAMVAL