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.

736 lines
16 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // EnumManageableNetworks.cpp
  7. //
  8. // Description:
  9. // CEnumManageableNetworks implementation.
  10. //
  11. // Maintained By:
  12. // Galen Barbee (GalenB) 02-FEB-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "ManagedNetwork.h"
  17. #include "EnumManageableNetworks.h"
  18. DEFINE_THISCLASS("CEnumManageableNetworks")
  19. // ************************************************************************
  20. //
  21. // Constructor / Destructor
  22. //
  23. // ************************************************************************
  24. //////////////////////////////////////////////////////////////////////////////
  25. //
  26. // HRESULT
  27. // CEnumManageableNetworks::S_HrCreateInstance(
  28. // IUnknown ** ppunkOut
  29. // )
  30. //
  31. //////////////////////////////////////////////////////////////////////////////
  32. HRESULT
  33. CEnumManageableNetworks::S_HrCreateInstance(
  34. IUnknown ** ppunkOut
  35. )
  36. {
  37. TraceFunc( "" );
  38. HRESULT hr = S_OK;
  39. CEnumManageableNetworks * pemn = NULL;
  40. Assert( ppunkOut != NULL );
  41. if ( ppunkOut == NULL )
  42. {
  43. hr = THR( E_POINTER );
  44. goto Cleanup;
  45. }
  46. pemn = new CEnumManageableNetworks;
  47. if ( pemn == NULL )
  48. {
  49. hr = THR( E_OUTOFMEMORY );
  50. goto Cleanup;
  51. }
  52. hr = THR( pemn->HrInit() );
  53. if ( FAILED( hr ) )
  54. {
  55. goto Cleanup;
  56. }
  57. hr = THR( pemn->TypeSafeQI( IUnknown, ppunkOut ) );
  58. if ( FAILED( hr ) )
  59. {
  60. goto Cleanup;
  61. }
  62. Cleanup:
  63. if ( pemn != NULL )
  64. {
  65. pemn->Release();
  66. }
  67. HRETURN( hr );
  68. } //*** CEnumManageableNetworks::S_HrCreateInstance
  69. //////////////////////////////////////////////////////////////////////////////
  70. //
  71. // CEnumManageableNetworks::CEnumManageableNetworks
  72. //
  73. //////////////////////////////////////////////////////////////////////////////
  74. CEnumManageableNetworks::CEnumManageableNetworks( void )
  75. : m_cRef( 1 )
  76. {
  77. TraceFunc( "" );
  78. InterlockedIncrement( &g_cObjects );
  79. TraceFuncExit();
  80. } //*** CEnumManageableNetworks::CEnumManageableNetworks
  81. //////////////////////////////////////////////////////////////////////////////
  82. //
  83. // STDMETHODIMP
  84. // CEnumManageableNetworks::HrInit
  85. //
  86. //////////////////////////////////////////////////////////////////////////////
  87. STDMETHODIMP
  88. CEnumManageableNetworks::HrInit( void )
  89. {
  90. TraceFunc( "" );
  91. HRESULT hr = S_OK;
  92. // IUnknown stuff
  93. Assert( m_cRef == 1 );
  94. // IEnumClusCfgNetworks
  95. Assert( m_cAlloced == 0 );
  96. Assert( m_cIter == 0 );
  97. Assert( m_pList == NULL );
  98. HRETURN( hr );
  99. } //*** CEnumManageableNetworks::HrInit
  100. //////////////////////////////////////////////////////////////////////////////
  101. //
  102. // CEnumManageableNetworks::~CEnumManageableNetworks
  103. //
  104. //////////////////////////////////////////////////////////////////////////////
  105. CEnumManageableNetworks::~CEnumManageableNetworks( void )
  106. {
  107. TraceFunc( "" );
  108. if ( m_pList != NULL )
  109. {
  110. while ( m_cAlloced != 0 )
  111. {
  112. m_cAlloced --;
  113. AssertMsg( m_pList[ m_cAlloced ], "This shouldn't happen." );
  114. if ( m_pList[ m_cAlloced ] != NULL )
  115. {
  116. (m_pList[ m_cAlloced ])->Release();
  117. }
  118. }
  119. TraceFree( m_pList );
  120. }
  121. InterlockedDecrement( &g_cObjects );
  122. TraceFuncExit();
  123. } //*** CEnumManageableNetworks::~CEnumManageableNetworks
  124. // ************************************************************************
  125. //
  126. // IUnknown
  127. //
  128. // ************************************************************************
  129. //////////////////////////////////////////////////////////////////////////////
  130. //++
  131. //
  132. // CEnumManageableNetworks::QueryInterface
  133. //
  134. // Description:
  135. // Query this object for the passed in interface.
  136. //
  137. // Arguments:
  138. // riidIn
  139. // Id of interface requested.
  140. //
  141. // ppvOut
  142. // Pointer to the requested interface.
  143. //
  144. // Return Value:
  145. // S_OK
  146. // If the interface is available on this object.
  147. //
  148. // E_NOINTERFACE
  149. // If the interface is not available.
  150. //
  151. // E_POINTER
  152. // ppvOut was NULL.
  153. //
  154. // Remarks:
  155. // None.
  156. //
  157. //--
  158. //////////////////////////////////////////////////////////////////////////////
  159. STDMETHODIMP
  160. CEnumManageableNetworks::QueryInterface(
  161. REFIID riidIn
  162. , LPVOID * ppvOut
  163. )
  164. {
  165. TraceQIFunc( riidIn, ppvOut );
  166. HRESULT hr = S_OK;
  167. //
  168. // Validate arguments.
  169. //
  170. Assert( ppvOut != NULL );
  171. if ( ppvOut == NULL )
  172. {
  173. hr = THR( E_POINTER );
  174. goto Cleanup;
  175. }
  176. //
  177. // Handle known interfaces.
  178. //
  179. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  180. {
  181. *ppvOut = static_cast< IEnumClusCfgNetworks * >( this );
  182. } // if: IUnknown
  183. else if ( IsEqualIID( riidIn, IID_IEnumClusCfgNetworks ) )
  184. {
  185. *ppvOut = TraceInterface( __THISCLASS__, IEnumClusCfgNetworks, this, 0 );
  186. } // else if: IEnumClusCfgNetworks
  187. else if ( IsEqualIID( riidIn, IID_IExtendObjectManager ) )
  188. {
  189. *ppvOut = TraceInterface( __THISCLASS__, IExtendObjectManager, this, 0 );
  190. } // else if: IExtendObjectManager
  191. else
  192. {
  193. *ppvOut = NULL;
  194. hr = E_NOINTERFACE;
  195. } // else
  196. //
  197. // Add a reference to the interface if successful.
  198. //
  199. if ( SUCCEEDED( hr ) )
  200. {
  201. ((IUnknown *) *ppvOut)->AddRef();
  202. } // if: success
  203. Cleanup:
  204. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  205. } //*** CEnumManageableNetworks::QueryInterface
  206. //////////////////////////////////////////////////////////////////////////////
  207. //
  208. // STDMETHODIMP_(ULONG)
  209. // CEnumManageableNetworks::AddRef
  210. //
  211. //////////////////////////////////////////////////////////////////////////////
  212. STDMETHODIMP_(ULONG)
  213. CEnumManageableNetworks::AddRef( void )
  214. {
  215. TraceFunc( "[IUnknown]" );
  216. InterlockedIncrement( &m_cRef );
  217. CRETURN( m_cRef );
  218. } //*** CEnumManageableNetworks::AddRef
  219. //////////////////////////////////////////////////////////////////////////////
  220. //
  221. // STDMETHODIMP_(ULONG)
  222. // CEnumManageableNetworks::Release
  223. //
  224. //////////////////////////////////////////////////////////////////////////////
  225. STDMETHODIMP_(ULONG)
  226. CEnumManageableNetworks::Release( void )
  227. {
  228. TraceFunc( "[IUnknown]" );
  229. LONG cRef;
  230. cRef = InterlockedDecrement( &m_cRef );
  231. if ( cRef == 0 )
  232. {
  233. TraceDo( delete this );
  234. }
  235. CRETURN( cRef );
  236. } //*** CEnumManageableNetworks::Release
  237. // ************************************************************************
  238. //
  239. // IExtendObjectManager
  240. //
  241. // ************************************************************************
  242. //////////////////////////////////////////////////////////////////////////////
  243. //
  244. // STDMETHODIMP
  245. // CEnumManageableNetworks::FindObject(
  246. // OBJECTCOOKIE cookieIn
  247. // , REFCLSID rclsidTypeIn
  248. // , LPCWSTR pcszNameIn
  249. // , LPUNKNOWN * punkOut
  250. // )
  251. //
  252. //////////////////////////////////////////////////////////////////////////////
  253. STDMETHODIMP
  254. CEnumManageableNetworks::FindObject(
  255. OBJECTCOOKIE cookieIn
  256. , REFCLSID rclsidTypeIn
  257. , LPCWSTR pcszNameIn
  258. , LPUNKNOWN * ppunkOut
  259. )
  260. {
  261. TraceFunc( "[IExtendObjectManager]" );
  262. OBJECTCOOKIE cookie;
  263. OBJECTCOOKIE cookieParent;
  264. IServiceProvider * psp;
  265. HRESULT hr = S_FALSE;
  266. IObjectManager * pom = NULL;
  267. IStandardInfo * psi = NULL;
  268. IEnumCookies * pec = NULL;
  269. DWORD cookieCount = 0;
  270. //
  271. // Check arguments
  272. //
  273. if ( cookieIn == 0 )
  274. {
  275. hr = THR( E_INVALIDARG );
  276. goto Cleanup;
  277. }
  278. if ( rclsidTypeIn != CLSID_NetworkType )
  279. {
  280. hr = THR( E_INVALIDARG );
  281. goto Cleanup;
  282. }
  283. if ( ppunkOut == NULL )
  284. {
  285. hr = THR( E_POINTER );
  286. goto Cleanup;
  287. }
  288. AssertMsg( pcszNameIn == NULL, "Enums shouldn't have names." );
  289. //
  290. // Grab the object manager.
  291. //
  292. hr = THR( CoCreateInstance( CLSID_ServiceManager,
  293. NULL,
  294. CLSCTX_INPROC_SERVER,
  295. TypeSafeParams( IServiceProvider, &psp )
  296. ) );
  297. if ( FAILED( hr ) )
  298. {
  299. goto Cleanup;
  300. }
  301. hr = THR( psp->TypeSafeQS( CLSID_ObjectManager,
  302. IObjectManager,
  303. &pom
  304. ) );
  305. psp->Release(); // release promptly
  306. if ( FAILED( hr ) )
  307. {
  308. goto Cleanup;
  309. }
  310. //
  311. // Ask the Object Manager for information about our cookie so we can
  312. // get to the "parent" cookie.
  313. //
  314. hr = THR( pom->GetObject( DFGUID_StandardInfo,
  315. cookieIn,
  316. reinterpret_cast< IUnknown ** >( &psi )
  317. ) );
  318. if ( FAILED( hr ) )
  319. {
  320. goto Cleanup;
  321. }
  322. hr = STHR( psi->GetParent( &cookieParent ) );
  323. if ( FAILED( hr ) )
  324. {
  325. goto Cleanup;
  326. }
  327. //
  328. // Now ask the Object Manager for a cookie enumerator.
  329. //
  330. hr = THR( pom->FindObject( CLSID_NetworkType,
  331. cookieParent,
  332. NULL,
  333. DFGUID_EnumCookies,
  334. NULL,
  335. reinterpret_cast< IUnknown ** >( &pec )
  336. ) );
  337. if ( FAILED( hr ) )
  338. {
  339. goto Cleanup;
  340. }
  341. pec = TraceInterface( L"CEnumManageableNetworks!IEnumCookies", IEnumCookies, pec, 1 );
  342. //
  343. // Ask the enumerator how many cookies it has.
  344. //
  345. hr = THR( pec->Count( &cookieCount ) );
  346. if ( FAILED( hr ) )
  347. {
  348. goto Cleanup;
  349. }
  350. m_cAlloced = cookieCount;
  351. if ( m_cAlloced == 0 )
  352. {
  353. // The error text is better than the coding value.
  354. hr = HRESULT_FROM_WIN32( TW32( ERROR_NOT_FOUND ) );
  355. goto Cleanup;
  356. }
  357. //
  358. // Allocate a buffer to store the punks.
  359. //
  360. m_pList = (IClusCfgNetworkInfo **) TraceAlloc( HEAP_ZERO_MEMORY, m_cAlloced * sizeof(IClusCfgNetworkInfo *) );
  361. if ( m_pList == NULL )
  362. {
  363. hr = THR( E_OUTOFMEMORY );
  364. goto Cleanup;
  365. }
  366. //
  367. // Reset the enumerator.
  368. //
  369. hr = THR( pec->Reset() );
  370. if ( FAILED( hr ) )
  371. {
  372. goto Cleanup;
  373. }
  374. //
  375. // Now loop thru to collect the interfaces.
  376. //
  377. m_cIter = 0;
  378. while ( hr == S_OK && m_cIter < m_cAlloced )
  379. {
  380. hr = STHR( pec->Next( 1, &cookie, NULL ) );
  381. if ( FAILED( hr ) )
  382. {
  383. goto Cleanup;
  384. }
  385. if ( hr == S_FALSE )
  386. {
  387. break; // exit condition
  388. }
  389. hr = THR( pom->GetObject( DFGUID_NetworkResource,
  390. cookie,
  391. reinterpret_cast< IUnknown ** >( &m_pList[ m_cIter ] )
  392. ) );
  393. if ( FAILED( hr ) )
  394. {
  395. goto Cleanup;
  396. }
  397. m_cIter++;
  398. } // while: S_OK
  399. //
  400. // Reset the iter.
  401. //
  402. m_cIter = 0;
  403. //
  404. // Grab the interface.
  405. //
  406. hr = THR( QueryInterface( DFGUID_EnumManageableNetworks,
  407. reinterpret_cast< void ** >( ppunkOut )
  408. ) );
  409. if ( FAILED( hr ) )
  410. {
  411. goto Cleanup;
  412. }
  413. Cleanup:
  414. if ( pom != NULL )
  415. {
  416. pom->Release();
  417. }
  418. if ( psi != NULL )
  419. {
  420. psi->Release();
  421. }
  422. if ( pec != NULL )
  423. {
  424. pec->Release();
  425. }
  426. HRETURN( hr );
  427. } //*** CEnumManageableNetworks::FindObject
  428. //****************************************************************************
  429. //
  430. // IEnumClusCfgNetworks
  431. //
  432. //****************************************************************************
  433. //////////////////////////////////////////////////////////////////////////////
  434. //
  435. // STDMETHODIMP
  436. // CEnumManageableNetworks::Next(
  437. // ULONG celt,
  438. // IClusCfgNetworkInfo ** rgOut,
  439. // ULONG * pceltFetchedOut
  440. // )
  441. //
  442. //////////////////////////////////////////////////////////////////////////////
  443. STDMETHODIMP
  444. CEnumManageableNetworks::Next(
  445. ULONG celt,
  446. IClusCfgNetworkInfo * rgOut[],
  447. ULONG * pceltFetchedOut
  448. )
  449. {
  450. TraceFunc( "[IEnumClusCfgNetworks]" );
  451. ULONG celtFetched;
  452. HRESULT hr = S_FALSE;
  453. //
  454. // Check parameters
  455. //
  456. if ( rgOut == NULL || celt == 0 )
  457. {
  458. hr = THR( E_POINTER );
  459. goto Cleanup;
  460. }
  461. //
  462. // Zero the return count.
  463. //
  464. if ( pceltFetchedOut != NULL )
  465. {
  466. *pceltFetchedOut = 0;
  467. }
  468. //
  469. // Clear the buffer
  470. //
  471. ZeroMemory( rgOut, celt * sizeof(rgOut[0]) );
  472. //
  473. // Loop thru copying the interfaces.
  474. //
  475. for( celtFetched = 0
  476. ; celtFetched + m_cIter < m_cAlloced && celtFetched < celt
  477. ; celtFetched ++
  478. )
  479. {
  480. hr = THR( m_pList[ m_cIter + celtFetched ]->TypeSafeQI( IClusCfgNetworkInfo, &rgOut[ celtFetched ] ) );
  481. if ( FAILED( hr ) )
  482. {
  483. goto CleanupList;
  484. }
  485. rgOut[ celtFetched ] = TraceInterface( L"CEnumManageableNetworks!IClusCfgNetworkInfo", IClusCfgNetworkInfo, rgOut[ celtFetched ], 1 );
  486. } // for: celtFetched
  487. if ( pceltFetchedOut != NULL )
  488. {
  489. *pceltFetchedOut = celtFetched;
  490. }
  491. m_cIter += celtFetched;
  492. if ( celtFetched != celt )
  493. {
  494. hr = S_FALSE;
  495. }
  496. else
  497. {
  498. hr = S_OK;
  499. }
  500. Cleanup:
  501. HRETURN( hr );
  502. CleanupList:
  503. for ( ; celtFetched != 0 ; )
  504. {
  505. celtFetched --;
  506. rgOut[ celtFetched ]->Release();
  507. rgOut[ celtFetched ] = NULL;
  508. }
  509. goto Cleanup;
  510. } //*** CEnumManageableNetworks::Next
  511. //////////////////////////////////////////////////////////////////////////////
  512. //
  513. // STDMETHODIMP
  514. // CEnumManageableNetworks::Skip(
  515. // ULONG celt
  516. // )
  517. //
  518. //////////////////////////////////////////////////////////////////////////////
  519. STDMETHODIMP
  520. CEnumManageableNetworks::Skip(
  521. ULONG celt
  522. )
  523. {
  524. TraceFunc( "[IEnumClusCfgNetworks]" );
  525. HRESULT hr = S_OK;
  526. m_cIter += celt;
  527. if ( m_cIter > m_cAlloced )
  528. {
  529. m_cIter = m_cAlloced;
  530. hr = S_FALSE;
  531. }
  532. HRETURN( hr );
  533. } //*** CEnumManageableNetworks::Skip
  534. //////////////////////////////////////////////////////////////////////////////
  535. //
  536. // STDMETHODIMP
  537. // CEnumManageableNetworks::Reset( void )
  538. //
  539. //////////////////////////////////////////////////////////////////////////////
  540. STDMETHODIMP
  541. CEnumManageableNetworks::Reset( void )
  542. {
  543. TraceFunc( "[IEnumClusCfgNetworks]" );
  544. HRESULT hr = S_OK;
  545. m_cIter = 0;
  546. HRETURN( hr );
  547. } //*** CEnumManageableNetworks::Reset
  548. //////////////////////////////////////////////////////////////////////////////
  549. //
  550. // STDMETHODIMP
  551. // CEnumManageableNetworks::Clone(
  552. // IEnumClusCfgNetworks ** ppenumOut
  553. // )
  554. //
  555. //////////////////////////////////////////////////////////////////////////////
  556. STDMETHODIMP
  557. CEnumManageableNetworks::Clone(
  558. IEnumClusCfgNetworks ** ppenumOut
  559. )
  560. {
  561. TraceFunc( "[IEnumClusCfgNetworks]" );
  562. //
  563. // KB: not going to implement this method.
  564. //
  565. HRESULT hr = THR( E_NOTIMPL );
  566. HRETURN( hr );
  567. } //*** CEnumManageableNetworks::Clone
  568. //////////////////////////////////////////////////////////////////////////////
  569. //
  570. // STDMETHODIMP
  571. // CEnumManageableNetworks::Count(
  572. // DWORD * pnCountOut
  573. // )
  574. //
  575. //////////////////////////////////////////////////////////////////////////////
  576. STDMETHODIMP
  577. CEnumManageableNetworks::Count(
  578. DWORD * pnCountOut
  579. )
  580. {
  581. TraceFunc( "[IEnumClusCfgManagedResources]" );
  582. HRESULT hr = S_OK;
  583. if ( pnCountOut == NULL )
  584. {
  585. hr = THR( E_POINTER );
  586. goto Cleanup;
  587. }
  588. *pnCountOut = m_cAlloced;
  589. Cleanup:
  590. HRETURN( hr );
  591. } //*** CEnumManageableNetworks::Count