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.

873 lines
25 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dplparam.cpp
  6. * Content: DirectPlayLobby8 Parameter Validation helper routines
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 04/18/00 rmt Created
  12. * 04/25/00 rmt Bug #s 33138, 33145, 33150
  13. * 04/26/00 mjn Removed dwTimeOut from Send() API call
  14. * 06/15/00 rmt Bug #33617 - Must provide method for providing automatic launch of DirectPlay instances
  15. * 07/08/2000 rmt Bug #38725 - Need to provide method to detect if app was lobby launched
  16. * rmt Bug #38757 - Callback messages for connections may return AFTER WaitForConnection returns
  17. * rmt Bug #38755 - No way to specify player name in Connection Settings
  18. * rmt Bug #38758 - DPLOBBY8.H has incorrect comments
  19. * rmt Bug #38783 - pvUserApplicationContext is only partially implemented
  20. * rmt Added DPLHANDLE_ALLCONNECTIONS and dwFlags (reserved field to couple of funcs).
  21. * 10/16/01 mjn Added additional parameter validation (ManBugs 52414, 52168)
  22. *
  23. ***************************************************************************/
  24. #include "dnlobbyi.h"
  25. #ifndef DPNBUILD_NOPARAMVAL
  26. extern IUnknownVtbl DN_LobbyUnknownVtbl;
  27. #undef DPF_MODNAME
  28. #define DPF_MODNAME "DPL_ValidateGetConnectionSettings"
  29. HRESULT DPL_ValidateGetConnectionSettings(LPVOID lpv,const DPNHANDLE hLobbyClient, DPL_CONNECTION_SETTINGS * const pdplSessionInfo, DWORD *pdwInfoSize, const DWORD dwFlags )
  30. {
  31. if( !IsValidDirectPlayLobby8Object( lpv ) )
  32. {
  33. DPFERR( "Invalid object" );
  34. return DPNERR_INVALIDOBJECT;
  35. }
  36. if( hLobbyClient == DPLHANDLE_ALLCONNECTIONS )
  37. {
  38. DPFERR( "Cannot specify ALLCONNECTIONS for GetConnectionSettings" );
  39. return DPNERR_INVALIDHANDLE;
  40. }
  41. if( hLobbyClient == 0 )
  42. {
  43. DPFERR( "Invalid connection ID" );
  44. return DPNERR_INVALIDHANDLE;
  45. }
  46. if( pdwInfoSize == NULL || !DNVALID_WRITEPTR( pdwInfoSize, sizeof( DWORD ) ) )
  47. {
  48. DPFERR( "Invalid pointer specified for infosize" );
  49. return DPNERR_INVALIDPOINTER;
  50. }
  51. if( *pdwInfoSize > 0 &&
  52. (pdplSessionInfo == NULL || !DNVALID_WRITEPTR( pdplSessionInfo, *pdwInfoSize ) ) )
  53. {
  54. DPFERR( "Invalid pointer specified for session info pointer" );
  55. return DPNERR_INVALIDPOINTER;
  56. }
  57. if( dwFlags != 0 )
  58. {
  59. DPFERR( "Invalid flags specified" );
  60. return DPNERR_INVALIDFLAGS;
  61. }
  62. return DPN_OK;
  63. }
  64. #undef DPF_MODNAME
  65. #define DPF_MODNAME "DPL_ValidateSetConnectionSettings"
  66. HRESULT DPL_ValidateSetConnectionSettings(LPVOID lpv,const DPNHANDLE hLobbyClient, const DPL_CONNECTION_SETTINGS * const pdplSessionInfo, const DWORD dwFlags )
  67. {
  68. HRESULT hr;
  69. if( !IsValidDirectPlayLobby8Object( lpv ) )
  70. {
  71. DPFERR( "Invalid object" );
  72. return DPNERR_INVALIDOBJECT;
  73. }
  74. if( hLobbyClient == 0 )
  75. {
  76. DPFERR( "Invalid handle" );
  77. return DPNERR_INVALIDHANDLE;
  78. }
  79. if( pdplSessionInfo != NULL )
  80. {
  81. hr = DPL_ValidConnectionSettings( pdplSessionInfo );
  82. if( FAILED( hr ) )
  83. {
  84. DPFERR( "Error validating connectsettings struct" );
  85. return hr;
  86. }
  87. }
  88. if( dwFlags != 0 )
  89. {
  90. DPFERR( "Invalid flags specified" );
  91. return DPNERR_INVALIDFLAGS;
  92. }
  93. return DPN_OK;
  94. }
  95. #undef DPF_MODNAME
  96. #define DPF_MODNAME "DPL_ValidateConnectionSettings"
  97. HRESULT DPL_ValidConnectionSettings( const DPL_CONNECTION_SETTINGS * const pdplConnectSettings )
  98. {
  99. if( pdplConnectSettings == NULL || !DNVALID_READPTR( pdplConnectSettings, sizeof( DPL_CONNECTION_SETTINGS ) ) )
  100. {
  101. DPFERR( "Invalid pointer specified for connection settings field" );
  102. return DPNERR_INVALIDPOINTER;
  103. }
  104. if( pdplConnectSettings->dwSize != sizeof( DPL_CONNECTION_SETTINGS ) )
  105. {
  106. DPFERR( "Invalid size specified for dplconnectsettings struct" );
  107. return DPNERR_INVALIDPARAM;
  108. }
  109. if( pdplConnectSettings->dwFlags & ~( DPLCONNECTSETTINGS_HOST ) )
  110. {
  111. DPFERR( "Invalid flags specified in connectsettings struct" );
  112. return DPNERR_INVALIDFLAGS;
  113. }
  114. //
  115. // Application description
  116. //
  117. if( pdplConnectSettings->dpnAppDesc.dwSize != sizeof( DPN_APPLICATION_DESC ) )
  118. {
  119. DPFERR( "Invalid size specified on app desc" );
  120. return DPNERR_INVALIDPOINTER;
  121. }
  122. if ( (pdplConnectSettings->dpnAppDesc.dwFlags &
  123. ~(DPNSESSION_CLIENT_SERVER|DPNSESSION_MIGRATE_HOST|DPNSESSION_NODPNSVR|DPNSESSION_REQUIREPASSWORD)) ||
  124. ((pdplConnectSettings->dpnAppDesc.dwFlags & DPNSESSION_CLIENT_SERVER) &&
  125. (pdplConnectSettings->dpnAppDesc.dwFlags & DPNSESSION_MIGRATE_HOST)))
  126. {
  127. DPFERR( "Invalid flag(s) specified on app desc" );
  128. return( DPNERR_INVALIDFLAGS );
  129. }
  130. if( pdplConnectSettings->dpnAppDesc.pwszSessionName != NULL &&
  131. !DNVALID_STRING_W( pdplConnectSettings->dpnAppDesc.pwszSessionName ) )
  132. {
  133. DPFERR( "Invalid session name specified on app desc" );
  134. return DPNERR_INVALIDSTRING;
  135. }
  136. if (pdplConnectSettings->dpnAppDesc.dwFlags & DPNSESSION_REQUIREPASSWORD)
  137. {
  138. if (pdplConnectSettings->dpnAppDesc.pwszPassword == NULL)
  139. {
  140. DPFERR( "Password must be specified" );
  141. return( DPNERR_INVALIDPARAM );
  142. }
  143. else
  144. {
  145. if( !DNVALID_STRING_W( pdplConnectSettings->dpnAppDesc.pwszPassword ) )
  146. {
  147. DPFERR( "Invalid password specified on app desc" );
  148. return DPNERR_INVALIDSTRING;
  149. }
  150. }
  151. }
  152. else
  153. {
  154. if (pdplConnectSettings->dpnAppDesc.pwszPassword != NULL)
  155. {
  156. DPFERR( "Password not required" );
  157. return( DPNERR_INVALIDPARAM );
  158. }
  159. }
  160. if( pdplConnectSettings->dpnAppDesc.dwReservedDataSize != 0 &&
  161. !DNVALID_READPTR( pdplConnectSettings->dpnAppDesc.pvReservedData, pdplConnectSettings->dpnAppDesc.dwReservedDataSize ) )
  162. {
  163. DPFERR( "Invalid reserved data specified on app desc" );
  164. return DPNERR_INVALIDPOINTER;
  165. }
  166. if( pdplConnectSettings->dpnAppDesc.dwApplicationReservedDataSize != 0 &&
  167. !DNVALID_READPTR( pdplConnectSettings->dpnAppDesc.pvApplicationReservedData,
  168. pdplConnectSettings->dpnAppDesc.dwApplicationReservedDataSize ) )
  169. {
  170. DPFERR( "Invalid application reserved data specified on app desc" );
  171. return DPNERR_INVALIDPOINTER;
  172. }
  173. //
  174. // Back to connect settings
  175. //
  176. if( pdplConnectSettings->dwFlags & DPLCONNECTSETTINGS_HOST )
  177. {
  178. if( pdplConnectSettings->pdp8HostAddress != NULL )
  179. {
  180. DPFERR( "Host address must be NULL if description is for host" );
  181. return DPNERR_INVALIDPARAM;
  182. }
  183. }
  184. else
  185. {
  186. if( pdplConnectSettings->pdp8HostAddress == NULL ||
  187. !DNVALID_READPTR( pdplConnectSettings->pdp8HostAddress, sizeof( IDirectPlay8Address * ) ) )
  188. {
  189. DPFERR( "Invalid host address specified" );
  190. return DPNERR_INVALIDHOSTADDRESS;
  191. }
  192. }
  193. if( pdplConnectSettings->ppdp8DeviceAddresses == NULL ||
  194. !DNVALID_READPTR( pdplConnectSettings->ppdp8DeviceAddresses, pdplConnectSettings->cNumDeviceAddresses * sizeof( IDirectPlay8Address * ) ) )
  195. {
  196. DPFERR( "Invalid device addresses specified" );
  197. return DPNERR_INVALIDDEVICEADDRESS;
  198. }
  199. if( pdplConnectSettings->cNumDeviceAddresses == 0 )
  200. {
  201. DPFERR( "You must specify at least one device address" );
  202. return DPNERR_INVALIDPARAM;
  203. }
  204. if ((pdplConnectSettings->pwszPlayerName != NULL) && !DNVALID_STRING_W(pdplConnectSettings->pwszPlayerName))
  205. {
  206. DPFERR( "Invalid player name specified" );
  207. return( DPNERR_INVALIDSTRING );
  208. }
  209. return DPN_OK;
  210. }
  211. #undef DPF_MODNAME
  212. #define DPF_MODNAME "DPL_ValidateQueryInterface"
  213. HRESULT DPL_ValidateQueryInterface( LPVOID lpv,REFIID riid,LPVOID *ppv )
  214. {
  215. if( !IsValidDirectPlayLobby8Object( lpv ) )
  216. {
  217. DPFERR( "Invalid object" );
  218. return DPNERR_INVALIDOBJECT;
  219. }
  220. if( ppv == NULL || !DNVALID_WRITEPTR( ppv, sizeof( void * ) ) )
  221. {
  222. DPFERR( "Invalid pointer specified for target of queryinterface" );
  223. return DPNERR_INVALIDPOINTER;
  224. }
  225. return DPN_OK;
  226. }
  227. #undef DPF_MODNAME
  228. #define DPF_MODNAME "DPL_ValidateRelease"
  229. HRESULT DPL_ValidateRelease( PVOID pv )
  230. {
  231. if( !IsValidDirectPlayLobby8Object( pv ) )
  232. {
  233. DPFERR( "Invalid object" );
  234. return DPNERR_INVALIDOBJECT;
  235. }
  236. return DPN_OK;
  237. }
  238. #undef DPF_MODNAME
  239. #define DPF_MODNAME "DPL_ValidateAddRef"
  240. HRESULT DPL_ValidateAddRef( PVOID pv )
  241. {
  242. if( !IsValidDirectPlayLobby8Object( pv ) )
  243. {
  244. DPFERR( "Invalid object" );
  245. return DPNERR_INVALIDOBJECT;
  246. }
  247. return DPN_OK;
  248. }
  249. #undef DPF_MODNAME
  250. #define DPF_MODNAME "DPL_ValidateRegisterMessageHandler"
  251. HRESULT DPL_ValidateRegisterMessageHandler(PVOID pv,
  252. const PVOID pvUserContext,
  253. const PFNDPNMESSAGEHANDLER pfn,
  254. DPNHANDLE * const pdpnhConnection,
  255. const DWORD dwFlags)
  256. {
  257. if( !IsValidDirectPlayLobby8Object( pv ) )
  258. {
  259. DPFERR( "Invalid object" );
  260. return DPNERR_INVALIDOBJECT;
  261. }
  262. if( pfn == NULL )
  263. {
  264. DPFERR( "Invalid pointer for message handler " );
  265. return DPNERR_INVALIDPOINTER;
  266. }
  267. if( pdpnhConnection )
  268. {
  269. if( !DNVALID_WRITEPTR( pdpnhConnection, sizeof( DPNHANDLE ) ) )
  270. {
  271. DPFERR( "Invalid pointer specified for connection handle" );
  272. return DPNERR_INVALIDPOINTER;
  273. }
  274. }
  275. if( dwFlags & ~(DPLINITIALIZE_DISABLEPARAMVAL) )
  276. {
  277. DPFERR( "Invalid flags specified" );
  278. return DPNERR_INVALIDFLAGS;
  279. }
  280. return DPN_OK;
  281. }
  282. #undef DPF_MODNAME
  283. #define DPF_MODNAME "DPL_ValidateClose"
  284. HRESULT DPL_ValidateClose(PVOID pv, const DWORD dwFlags )
  285. {
  286. if( !IsValidDirectPlayLobby8Object( pv ) )
  287. {
  288. DPFERR( "Invalid object" );
  289. return DPNERR_INVALIDOBJECT;
  290. }
  291. if( dwFlags != 0 )
  292. {
  293. DPFERR( "Invalid flags specified" );
  294. return DPNERR_INVALIDFLAGS;
  295. }
  296. return DPN_OK;
  297. }
  298. #undef DPF_MODNAME
  299. #define DPF_MODNAME "DPL_ValidateSend"
  300. HRESULT DPL_ValidateSend(PVOID pv,
  301. const DPNHANDLE hTarget,
  302. const BYTE *const pBuffer,
  303. const DWORD dwBufferSize,
  304. const DWORD dwFlags)
  305. {
  306. if( !IsValidDirectPlayLobby8Object( pv ) )
  307. {
  308. DPFERR( "Invalid object" );
  309. return DPNERR_INVALIDOBJECT;
  310. }
  311. if( hTarget == 0 )
  312. {
  313. DPFERR( "Invalid handle" );
  314. return DPNERR_INVALIDHANDLE;
  315. }
  316. if( pBuffer == NULL ||
  317. !DNVALID_READPTR( pBuffer, dwBufferSize ) )
  318. {
  319. DPFERR( "Invalid pointer specified for buffer" );
  320. return DPNERR_INVALIDPOINTER;
  321. }
  322. if( dwBufferSize == 0 )
  323. {
  324. DPFERR( "Invalid buffer size specified" );
  325. return DPNERR_INVALIDPARAM;
  326. }
  327. if( dwBufferSize > 0x10000 )
  328. {
  329. DPFERR( "Queue does not support sends > 0x10000 in size" );
  330. return DPNERR_SENDTOOLARGE;
  331. }
  332. if( dwFlags != 0 )
  333. {
  334. DPFERR( "Invalid flags specified" );
  335. return DPNERR_INVALIDFLAGS;
  336. }
  337. return DPN_OK;
  338. }
  339. #undef DPF_MODNAME
  340. #define DPF_MODNAME "DPL_ValidateEnumLocalPrograms"
  341. HRESULT DPL_ValidateEnumLocalPrograms(IDirectPlay8LobbyClient *pInterface,
  342. const GUID *const pGuidApplication,
  343. BYTE *const pEnumData,
  344. DWORD *const pdwEnumDataSize,
  345. DWORD *const pdwEnumDataItems,
  346. const DWORD dwFlags )
  347. {
  348. if( !IsValidDirectPlayLobby8Object( pInterface ) )
  349. {
  350. DPFERR( "Invalid object" );
  351. return DPNERR_INVALIDOBJECT;
  352. }
  353. if( pGuidApplication != NULL && !DNVALID_READPTR( pGuidApplication, sizeof( GUID ) ) )
  354. {
  355. DPFERR( "Invalid pointer specified for application guid" );
  356. return DPNERR_INVALIDPOINTER;
  357. }
  358. if( pdwEnumDataSize == NULL || !DNVALID_WRITEPTR( pdwEnumDataSize, sizeof( DWORD ) ) )
  359. {
  360. DPFERR( "Invalid pointer specified for enum data size" );
  361. return DPNERR_INVALIDPOINTER;
  362. }
  363. if( pdwEnumDataItems == NULL || !DNVALID_WRITEPTR( pdwEnumDataItems, sizeof( DWORD ) ) )
  364. {
  365. DPFERR( "Invalid pointer specified for enum data count" );
  366. return DPNERR_INVALIDPOINTER;
  367. }
  368. if( *pdwEnumDataSize > 0 &&
  369. (pEnumData == NULL || !DNVALID_WRITEPTR( pEnumData, *pdwEnumDataSize ) ) )
  370. {
  371. DPFERR( "Invalid enum data pointer specified" );
  372. return DPNERR_INVALIDPOINTER;
  373. }
  374. if( dwFlags != 0 )
  375. {
  376. DPFERR( "Invalid flags specified" );
  377. return DPNERR_INVALIDFLAGS;
  378. }
  379. return DPN_OK;
  380. }
  381. #undef DPF_MODNAME
  382. #define DPF_MODNAME "DPL_ValidateConnectApplication"
  383. HRESULT DPL_ValidateConnectApplication(IDirectPlay8LobbyClient *pInterface,
  384. const DPL_CONNECT_INFO *const pdplConnectionInfo,
  385. const PVOID pvUserApplicationContext,
  386. DPNHANDLE *const hApplication,
  387. const DWORD dwTimeOut,
  388. const DWORD dwFlags)
  389. {
  390. HRESULT hResultCode;
  391. if( !IsValidDirectPlayLobby8Object( pInterface ) )
  392. {
  393. DPFERR( "Invalid object" );
  394. return DPNERR_INVALIDOBJECT;
  395. }
  396. DPFX(DPFPREP,4,"Validating connect info");
  397. if( FAILED( hResultCode = DPL_ValidConnectInfo( pdplConnectionInfo ) ) )
  398. {
  399. DPFX(DPFPREP, 0, "Error validating connect info hr=0x%x", hResultCode );
  400. return hResultCode;
  401. }
  402. if( hApplication == NULL ||
  403. !DNVALID_WRITEPTR( hApplication, sizeof( DPNHANDLE ) ) )
  404. {
  405. DPFERR( "Invalid pointer specified for application handle" );
  406. return DPNERR_INVALIDPOINTER;
  407. }
  408. if( dwFlags != 0 )
  409. {
  410. DPFERR( "Invalid flags" );
  411. return DPNERR_INVALIDFLAGS;
  412. }
  413. return DPN_OK;
  414. }
  415. #undef DPF_MODNAME
  416. #define DPF_MODNAME "DPL_ValidateReleaseApplication"
  417. HRESULT DPL_ValidateReleaseApplication(IDirectPlay8LobbyClient *pInterface,
  418. const DPNHANDLE hApplication, const DWORD dwFlags )
  419. {
  420. if( !IsValidDirectPlayLobby8Object( pInterface ) )
  421. {
  422. DPFERR( "Invalid object" );
  423. return DPNERR_INVALIDOBJECT;
  424. }
  425. if( hApplication == 0 )
  426. {
  427. DPFERR( "Invalid handle" );
  428. return DPNERR_INVALIDHANDLE;
  429. }
  430. if( dwFlags != 0 )
  431. {
  432. DPFERR( "Invalid flags" );
  433. return DPNERR_INVALIDFLAGS;
  434. }
  435. return DPN_OK;
  436. }
  437. #undef DPF_MODNAME
  438. #define DPF_MODNAME "DPL_ValidateUnRegisterProgram"
  439. HRESULT DPL_ValidateUnRegisterProgram(IDirectPlay8LobbiedApplication *pInterface,
  440. const GUID *pguidApplication,
  441. const DWORD dwFlags)
  442. {
  443. if( !IsValidDirectPlayLobby8Object( pInterface ) )
  444. {
  445. DPFERR( "Invalid object" );
  446. return DPNERR_INVALIDOBJECT;
  447. }
  448. if( pguidApplication == NULL ||
  449. !DNVALID_READPTR( pguidApplication, sizeof( GUID ) ) )
  450. {
  451. DPFERR( "Invalid pointer to application GUID specified" );
  452. return DPNERR_INVALIDPOINTER;
  453. }
  454. if( dwFlags != 0 )
  455. {
  456. DPFERR( "Invalid flags specified" );
  457. return DPNERR_INVALIDFLAGS;
  458. }
  459. return DPN_OK;
  460. }
  461. #undef DPF_MODNAME
  462. #define DPF_MODNAME "DPL_ValidateSetAppAvailable"
  463. HRESULT DPL_ValidateSetAppAvailable(IDirectPlay8LobbiedApplication *pInterface, const BOOL fAvailable, const DWORD dwFlags )
  464. {
  465. if( !IsValidDirectPlayLobby8Object( pInterface ) )
  466. {
  467. DPFERR( "Invalid object" );
  468. return DPNERR_INVALIDOBJECT;
  469. }
  470. if( dwFlags & ~(DPLAVAILABLE_ALLOWMULTIPLECONNECT) )
  471. {
  472. DPFERR( "Invalid flags specified" );
  473. return DPNERR_INVALIDFLAGS;
  474. }
  475. return DPN_OK;
  476. }
  477. #undef DPF_MODNAME
  478. #define DPF_MODNAME "DPL_ValidateWaitForConnection"
  479. HRESULT DPL_ValidateWaitForConnection(IDirectPlay8LobbiedApplication *pInterface,
  480. const DWORD dwMilliseconds, const DWORD dwFlags )
  481. {
  482. if( !IsValidDirectPlayLobby8Object( pInterface ) )
  483. {
  484. DPFERR( "Invalid object" );
  485. return DPNERR_INVALIDOBJECT;
  486. }
  487. if( dwFlags != 0 )
  488. {
  489. DPFERR( "Invalid flags specified" );
  490. return DPNERR_INVALIDFLAGS;
  491. }
  492. return DPN_OK;
  493. }
  494. #undef DPF_MODNAME
  495. #define DPF_MODNAME "DPL_ValidateUpdateStatus"
  496. HRESULT DPL_ValidateUpdateStatus(IDirectPlay8LobbiedApplication *pInterface,
  497. const DPNHANDLE hLobby,
  498. const DWORD dwStatus,
  499. const DWORD dwFlags )
  500. {
  501. if( !IsValidDirectPlayLobby8Object( pInterface ) )
  502. {
  503. DPFERR( "Invalid object" );
  504. return DPNERR_INVALIDOBJECT;
  505. }
  506. if( hLobby == 0 )
  507. {
  508. DPFERR( "Invalid handle" );
  509. return DPNERR_INVALIDHANDLE;
  510. }
  511. if( dwStatus != DPLSESSION_CONNECTED &&
  512. dwStatus != DPLSESSION_COULDNOTCONNECT &&
  513. dwStatus != DPLSESSION_DISCONNECTED &&
  514. dwStatus != DPLSESSION_TERMINATED &&
  515. dwStatus != DPLSESSION_HOSTMIGRATED &&
  516. dwStatus != DPLSESSION_HOSTMIGRATEDHERE )
  517. {
  518. DPFERR( "Invalid status specified" );
  519. return DPNERR_INVALIDPARAM;
  520. }
  521. if( dwFlags != 0 )
  522. {
  523. DPFERR( "Invalid flags specified" );
  524. return DPNERR_INVALIDFLAGS;
  525. }
  526. return DPN_OK;
  527. }
  528. #undef DPF_MODNAME
  529. #define DPF_MODNAME "DPL_ValidateRegisterProgram"
  530. HRESULT DPL_ValidateRegisterProgram(IDirectPlay8LobbiedApplication *pInterface,
  531. const DPL_PROGRAM_DESC *const pdplProgramDesc,
  532. const DWORD dwFlags)
  533. {
  534. HRESULT hResultCode;
  535. if( !IsValidDirectPlayLobby8Object( pInterface ) )
  536. {
  537. DPFERR( "Invalid object" );
  538. return DPNERR_INVALIDOBJECT;
  539. }
  540. if( FAILED( hResultCode = DPL_ValidProgramDesc(pdplProgramDesc) ) )
  541. {
  542. DPFX(DPFPREP, 0, "Error validating program desc structure hr=0x%x", hResultCode );
  543. return hResultCode;
  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 "DPL_ValidConnectInfo"
  554. HRESULT DPL_ValidConnectInfo( const DPL_CONNECT_INFO * const pdplConnectInfo )
  555. {
  556. if( pdplConnectInfo == NULL )
  557. {
  558. DPFERR( "Invalid pointer specified for connect info" );
  559. return DPNERR_INVALIDPOINTER;
  560. }
  561. if( pdplConnectInfo->dwSize != sizeof( DPL_CONNECT_INFO ) )
  562. {
  563. DPFERR( "Wrong size specified for connect info struct" );
  564. return DPNERR_INVALIDPARAM;
  565. }
  566. if( !DNVALID_READPTR( pdplConnectInfo, pdplConnectInfo->dwSize ) )
  567. {
  568. DPFERR( "Invalid pointer specified for connect info" );
  569. return DPNERR_INVALIDPOINTER;
  570. }
  571. if( pdplConnectInfo->dwFlags & ~(DPLCONNECT_LAUNCHNEW | DPLCONNECT_LAUNCHNOTFOUND) )
  572. {
  573. DPFERR("Invalid flags specified" );
  574. return DPNERR_INVALIDFLAGS;
  575. }
  576. if( pdplConnectInfo->dwFlags & DPLCONNECT_LAUNCHNEW &&
  577. pdplConnectInfo->dwFlags & DPLCONNECT_LAUNCHNOTFOUND )
  578. {
  579. DPFERR( "You cannot specify both launchnew and launchnotfound" );
  580. return DPNERR_INVALIDPARAM;
  581. }
  582. GUID guidTmp;
  583. memset( &guidTmp, 0x00, sizeof( GUID ) );
  584. if( pdplConnectInfo->guidApplication == guidTmp )
  585. {
  586. DPFERR( "Cannot specify GUID_NULL for the application GUID" );
  587. return DPNERR_INVALIDPARAM;
  588. }
  589. if( pdplConnectInfo->pdplConnectionSettings != NULL )
  590. {
  591. HRESULT hr = DPL_ValidConnectionSettings( pdplConnectInfo->pdplConnectionSettings );
  592. if( FAILED( hr ) )
  593. {
  594. DPFX(DPFPREP, 0, "Error validating connection settings field of connect info hr=0x%x", hr );
  595. return hr;
  596. }
  597. /* REMOVE - never implemented
  598. if (pdplConnectInfo->guidApplication != pdplConnectInfo->pdplConnectionSettings->dpnAppDesc.guidApplication)
  599. {
  600. DPFERR( "Different application guids specified in connect info and app desc" );
  601. return( DPNERR_INVALIDPARAM );
  602. }
  603. */
  604. }
  605. if( pdplConnectInfo->dwLobbyConnectDataSize > 0 &&
  606. (pdplConnectInfo->pvLobbyConnectData == NULL || !DNVALID_READPTR( pdplConnectInfo->pvLobbyConnectData, pdplConnectInfo->dwLobbyConnectDataSize ) ) )
  607. {
  608. DPFERR( "Invalid pointer specified for lobby connect data" );
  609. return DPNERR_INVALIDPOINTER;
  610. }
  611. return DPN_OK;
  612. }
  613. #undef DPF_MODNAME
  614. #define DPF_MODNAME "DPL_ValidProgramDesc"
  615. HRESULT DPL_ValidProgramDesc( const DPL_PROGRAM_DESC * const pdplProgramInfo )
  616. {
  617. if( pdplProgramInfo == NULL )
  618. {
  619. DPFERR( "Invalid pointer specified for program info" );
  620. return DPNERR_INVALIDPOINTER;
  621. }
  622. if( pdplProgramInfo->dwSize != sizeof( DPL_PROGRAM_DESC ) )
  623. {
  624. DPFERR( "Wrong size specified for program info struct" );
  625. return DPNERR_INVALIDPARAM;
  626. }
  627. if( !DNVALID_READPTR( pdplProgramInfo, pdplProgramInfo->dwSize ) )
  628. {
  629. DPFERR( "Invalid pointer specified for app info" );
  630. return DPNERR_INVALIDPOINTER;
  631. }
  632. if( pdplProgramInfo->dwFlags != 0 )
  633. {
  634. DPFERR("Invalid flags specified" );
  635. return DPNERR_INVALIDFLAGS;
  636. }
  637. GUID guidTmp;
  638. memset( &guidTmp, 0x00, sizeof( GUID ) );
  639. if( pdplProgramInfo->guidApplication == guidTmp )
  640. {
  641. DPFERR( "Cannot specify GUID_NULL for the application GUID" );
  642. return DPNERR_INVALIDPARAM;
  643. }
  644. if( pdplProgramInfo->pwszApplicationName == NULL )
  645. {
  646. DPFERR( "You must specify an application name" );
  647. return DPNERR_INVALIDPARAM;
  648. }
  649. if( !DNVALID_STRING_W( pdplProgramInfo->pwszApplicationName ) )
  650. {
  651. DPFERR( "Invalid string specified for application name" );
  652. return DPNERR_INVALIDSTRING;
  653. }
  654. if( pdplProgramInfo->pwszCommandLine != NULL &&
  655. !DNVALID_STRING_W( pdplProgramInfo->pwszCommandLine ) )
  656. {
  657. DPFERR( "Invalid command-line string specified" );
  658. return DPNERR_INVALIDSTRING;
  659. }
  660. if( pdplProgramInfo->pwszCurrentDirectory != NULL &&
  661. !DNVALID_STRING_W( pdplProgramInfo->pwszCurrentDirectory ) )
  662. {
  663. DPFERR( "Invalid current directory string specified" );
  664. return DPNERR_INVALIDSTRING;
  665. }
  666. if( pdplProgramInfo->pwszDescription != NULL &&
  667. !DNVALID_STRING_W( pdplProgramInfo->pwszDescription ) )
  668. {
  669. DPFERR( "Invalid description string specified" );
  670. return DPNERR_INVALIDSTRING;
  671. }
  672. if( pdplProgramInfo->pwszExecutableFilename == NULL )
  673. {
  674. DPFERR( "You must specify an executable name" );
  675. return DPNERR_INVALIDPARAM;
  676. }
  677. if( !DNVALID_STRING_W( pdplProgramInfo->pwszExecutableFilename ) )
  678. {
  679. DPFERR( "Invalid string specified for executable name" );
  680. return DPNERR_INVALIDSTRING;
  681. }
  682. if( pdplProgramInfo->pwszExecutablePath != NULL &&
  683. !DNVALID_STRING_W( pdplProgramInfo->pwszExecutablePath ) )
  684. {
  685. DPFERR( "Invalid executable path string specified" );
  686. return DPNERR_INVALIDSTRING;
  687. }
  688. if( pdplProgramInfo->pwszLauncherFilename != NULL &&
  689. !DNVALID_STRING_W( pdplProgramInfo->pwszLauncherFilename ) )
  690. {
  691. DPFERR( "Invalid launcher filename string specified" );
  692. return DPNERR_INVALIDSTRING;
  693. }
  694. if( pdplProgramInfo->pwszLauncherPath != NULL &&
  695. !DNVALID_STRING_W( pdplProgramInfo->pwszLauncherPath ) )
  696. {
  697. DPFERR( "Invalid launcher path string specified" );
  698. return DPNERR_INVALIDSTRING;
  699. }
  700. return DPN_OK;
  701. }
  702. #undef DPF_MODNAME
  703. #define DPF_MODNAME "IsValidDirectPlayLobby8Object"
  704. BOOL IsValidDirectPlayLobby8Object( LPVOID lpvObject )
  705. {
  706. INTERFACE_LIST *pIntList = (INTERFACE_LIST *) lpvObject;
  707. if( !DNVALID_READPTR( lpvObject, sizeof( INTERFACE_LIST ) ) )
  708. {
  709. DPFX(DPFPREP, 0, "Invalid object pointer" );
  710. return FALSE;
  711. }
  712. if( pIntList->lpVtbl != &DPL_Lobby8ClientVtbl &&
  713. pIntList->lpVtbl != &DPL_8LobbiedApplicationVtbl &&
  714. pIntList->lpVtbl != &DN_LobbyUnknownVtbl
  715. )
  716. {
  717. DPFX(DPFPREP, 0, "Invalid object - bad vtable" );
  718. return FALSE;
  719. }
  720. if( pIntList->iid != IID_IDirectPlay8LobbyClient &&
  721. pIntList->iid != IID_IDirectPlay8LobbiedApplication &&
  722. pIntList->iid != IID_IUnknown )
  723. {
  724. DPFX(DPFPREP, 0, "Invalid object - bad iid" );
  725. return FALSE;
  726. }
  727. if( pIntList->pObject == NULL ||
  728. !DNVALID_READPTR( pIntList->pObject, sizeof( OBJECT_DATA ) ) )
  729. {
  730. DPFX(DPFPREP, 0, "Invalid object" );
  731. return FALSE;
  732. }
  733. const DIRECTPLAYLOBBYOBJECT *pdpl = (DIRECTPLAYLOBBYOBJECT *) GET_OBJECT_FROM_INTERFACE( lpvObject );
  734. if( pdpl == NULL ||
  735. !DNVALID_READPTR( pdpl, sizeof( DIRECTPLAYLOBBYOBJECT ) ) )
  736. {
  737. DPFX(DPFPREP, 0, "Invalid object" );
  738. return FALSE;
  739. }
  740. return TRUE;
  741. }
  742. #endif // !DPNBUILD_NOPARAMVAL