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.

623 lines
14 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CProxyCfgIPAddressInfo.cpp
  7. //
  8. // Description:
  9. // CProxyCfgIPAddressInfo implementation.
  10. //
  11. // Maintained By:
  12. // Galen Barbee (GalenB) 02-AUG-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. //////////////////////////////////////////////////////////////////////////////
  16. // Include Files
  17. //////////////////////////////////////////////////////////////////////////////
  18. #include "Pch.h"
  19. #include "CProxyCfgIPAddressInfo.h"
  20. //////////////////////////////////////////////////////////////////////////////
  21. // Constant Definitions
  22. //////////////////////////////////////////////////////////////////////////////
  23. DEFINE_THISCLASS("CProxyCfgIPAddressInfo")
  24. //////////////////////////////////////////////////////////////////////////////
  25. //++
  26. //
  27. // CProxyCfgIPAddressInfo::S_HrCreateInstance
  28. //
  29. // Description:
  30. // Create a CProxyCfgIPAddressInfo instance.
  31. //
  32. // Arguments:
  33. // ppunkOut
  34. //
  35. // Return Values:
  36. // S_OK
  37. // Success.
  38. //
  39. // E_POINTER
  40. // A passed in argument is NULL.
  41. //
  42. // E_OUTOFMEMORY
  43. // Out of memory.
  44. //
  45. // Other HRESULT error.
  46. //
  47. //--
  48. //////////////////////////////////////////////////////////////////////////////
  49. HRESULT
  50. CProxyCfgIPAddressInfo::S_HrCreateInstance(
  51. IUnknown ** ppunkOut,
  52. IUnknown * punkOuterIn,
  53. HCLUSTER * phClusterIn,
  54. CLSID * pclsidMajorIn,
  55. ULONG ulIPAddressIn,
  56. ULONG ulSubnetMaskIn
  57. )
  58. {
  59. TraceFunc( "" );
  60. HRESULT hr = S_OK;
  61. CProxyCfgIPAddressInfo * ppcipai = NULL;
  62. if ( ppunkOut == NULL )
  63. {
  64. hr = THR( E_POINTER );
  65. goto Cleanup;
  66. } // if:
  67. ppcipai = new CProxyCfgIPAddressInfo;
  68. if ( ppcipai == NULL )
  69. {
  70. hr = THR( E_OUTOFMEMORY );
  71. goto Cleanup;
  72. } // if:
  73. hr = THR( ppcipai->HrInit( punkOuterIn, phClusterIn, pclsidMajorIn, ulIPAddressIn, ulSubnetMaskIn ) );
  74. if ( FAILED( hr ) )
  75. {
  76. goto Cleanup;
  77. }
  78. hr = THR( ppcipai->TypeSafeQI( IUnknown, ppunkOut ) );
  79. if ( FAILED( hr ) )
  80. {
  81. goto Cleanup;
  82. }
  83. Cleanup:
  84. if ( ppcipai != NULL )
  85. {
  86. ppcipai->Release();
  87. } // if:
  88. HRETURN( hr );
  89. } //*** CProxyCfgIPAddressInfo::S_HrCreateInstance
  90. //////////////////////////////////////////////////////////////////////////////
  91. //++
  92. //
  93. // CProxyCfgIPAddressInfo::CProxyCfgIPAddressInfo
  94. //
  95. // Description:
  96. // Constructor of the CProxyCfgIPAddressInfo class. This initializes
  97. // the m_cRef variable to 1 instead of 0 to account of possible
  98. // QueryInterface failure in DllGetClassObject.
  99. //
  100. // Arguments:
  101. // None.
  102. //
  103. // Return Value:
  104. // None.
  105. //
  106. // Remarks:
  107. // None.
  108. //
  109. //--
  110. //////////////////////////////////////////////////////////////////////////////
  111. CProxyCfgIPAddressInfo::CProxyCfgIPAddressInfo( void )
  112. : m_cRef( 1 )
  113. {
  114. TraceFunc( "" );
  115. InterlockedIncrement( &g_cObjects );
  116. Assert( m_pcccb == NULL );
  117. TraceFuncExit();
  118. } //*** CProxyCfgIPAddressInfo::CProxyCfgIPAddressInfo
  119. //////////////////////////////////////////////////////////////////////////////
  120. //++
  121. //
  122. // CProxyCfgIPAddressInfo::~CProxyCfgIPAddressInfo
  123. //
  124. // Description:
  125. // Destructor of the CProxyCfgIPAddressInfo class.
  126. //
  127. // Arguments:
  128. // None.
  129. //
  130. // Return Value:
  131. // None.
  132. //
  133. // Remarks:
  134. // None.
  135. //
  136. //--
  137. //////////////////////////////////////////////////////////////////////////////
  138. CProxyCfgIPAddressInfo::~CProxyCfgIPAddressInfo( void )
  139. {
  140. TraceFunc( "" );
  141. // m_cRef - noop
  142. if ( m_punkOuter != NULL )
  143. {
  144. m_punkOuter->Release();
  145. }
  146. if ( m_pcccb != NULL )
  147. {
  148. m_pcccb->Release();
  149. } // if:
  150. // m_phCluster - DO NOT CLOSE!
  151. // m_pclsidMajor - noop
  152. InterlockedDecrement( &g_cObjects );
  153. TraceFuncExit();
  154. } //*** CProxyCfgIPAddressInfo::~CProxyCfgIPAddressInfo
  155. //
  156. //
  157. //
  158. HRESULT
  159. CProxyCfgIPAddressInfo::HrInit(
  160. IUnknown * punkOuterIn,
  161. HCLUSTER * phClusterIn,
  162. CLSID * pclsidMajorIn,
  163. ULONG ulIPAddressIn,
  164. ULONG ulSubnetMaskIn
  165. )
  166. {
  167. TraceFunc( "" );
  168. HRESULT hr;
  169. // IUnknown
  170. Assert( m_cRef == 1 );
  171. if ( punkOuterIn != NULL )
  172. {
  173. m_punkOuter = punkOuterIn;
  174. m_punkOuter->AddRef();
  175. }
  176. if ( phClusterIn == NULL )
  177. goto InvalidArg;
  178. m_phCluster = phClusterIn;
  179. if ( pclsidMajorIn != NULL )
  180. {
  181. m_pclsidMajor = pclsidMajorIn;
  182. }
  183. else
  184. {
  185. m_pclsidMajor = (CLSID *) &TASKID_Major_Client_And_Server_Log;
  186. }
  187. if ( punkOuterIn != NULL )
  188. {
  189. hr = THR( punkOuterIn->TypeSafeQI( IClusCfgCallback, &m_pcccb ) );
  190. if ( FAILED( hr ) )
  191. goto Cleanup;
  192. }
  193. m_ulIPAddress = ulIPAddressIn;
  194. m_ulSubnetMask = ulSubnetMaskIn;
  195. hr = S_OK;
  196. Cleanup:
  197. HRETURN( hr );
  198. InvalidArg:
  199. hr = THR( E_INVALIDARG );
  200. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_IPAddressInfo_HrInit_InvalidArg, hr );
  201. goto Cleanup;
  202. } // *** HrInit
  203. //*************************************************************************//
  204. /////////////////////////////////////////////////////////////////////////////
  205. // CProxyCfgIPAddressInfo -- IUknkown interface.
  206. /////////////////////////////////////////////////////////////////////////////
  207. //////////////////////////////////////////////////////////////////////////////
  208. //++
  209. //
  210. // CProxyCfgIPAddressInfo::QueryInterface
  211. //
  212. // Description:
  213. // Query this object for the passed in interface.
  214. //
  215. // Arguments:
  216. // riidIn
  217. // Id of interface requested.
  218. //
  219. // ppvOut
  220. // Pointer to the requested interface.
  221. //
  222. // Return Value:
  223. // S_OK
  224. // If the interface is available on this object.
  225. //
  226. // E_NOINTERFACE
  227. // If the interface is not available.
  228. //
  229. // E_POINTER
  230. // ppvOut was NULL.
  231. //
  232. // Remarks:
  233. // None.
  234. //
  235. //--
  236. //////////////////////////////////////////////////////////////////////////////
  237. STDMETHODIMP
  238. CProxyCfgIPAddressInfo::QueryInterface(
  239. REFIID riidIn
  240. , void ** ppvOut
  241. )
  242. {
  243. TraceQIFunc( riidIn, ppvOut );
  244. HRESULT hr = S_OK;
  245. //
  246. // Validate arguments.
  247. //
  248. Assert( ppvOut != NULL );
  249. if ( ppvOut == NULL )
  250. {
  251. hr = THR( E_POINTER );
  252. goto Cleanup;
  253. }
  254. //
  255. // Handle known interfaces.
  256. //
  257. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  258. {
  259. *ppvOut = static_cast< IClusCfgIPAddressInfo * >( this );
  260. } // if: IUnknown
  261. else if ( IsEqualIID( riidIn, IID_IClusCfgIPAddressInfo ) )
  262. {
  263. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgIPAddressInfo, this, 0 );
  264. } // else if: IClusCfgIPAddressInfo
  265. else
  266. {
  267. *ppvOut = NULL;
  268. hr = E_NOINTERFACE;
  269. } // else
  270. //
  271. // Add a reference to the interface if successful.
  272. //
  273. if ( SUCCEEDED( hr ) )
  274. {
  275. ((IUnknown *) *ppvOut)->AddRef();
  276. } // if: success
  277. Cleanup:
  278. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  279. } //*** CProxyCfgIPAddressInfo::QueryInterface
  280. //////////////////////////////////////////////////////////////////////////////
  281. //++
  282. //
  283. // CProxyCfgIPAddressInfo::AddRef
  284. //
  285. // Description:
  286. // Increment the reference count of this object by one.
  287. //
  288. // Arguments:
  289. // None.
  290. //
  291. // Return Value:
  292. // The new reference count.
  293. //
  294. // Remarks:
  295. // None.
  296. //
  297. //--
  298. //////////////////////////////////////////////////////////////////////////////
  299. STDMETHODIMP_( ULONG )
  300. CProxyCfgIPAddressInfo::AddRef( void )
  301. {
  302. TraceFunc( "[IUnknown]" );
  303. InterlockedIncrement( &m_cRef );
  304. CRETURN( m_cRef );
  305. } //*** CProxyCfgIPAddressInfo::AddRef
  306. // IClusSetHandleProvider
  307. //////////////////////////////////////////////////////////////////////////////
  308. //++
  309. //
  310. // CProxyCfgIPAddressInfo::Release
  311. //
  312. // Description:
  313. // Decrement the reference count of this object by one.
  314. //
  315. // Arguments:
  316. // None.
  317. //
  318. // Return Value:
  319. // The new reference count.
  320. //
  321. // Remarks:
  322. // None.
  323. //
  324. //--
  325. //////////////////////////////////////////////////////////////////////////////
  326. STDMETHODIMP_( ULONG )
  327. CProxyCfgIPAddressInfo::Release( void )
  328. {
  329. TraceFunc( "[IUnknown]" );
  330. LONG cRef;
  331. cRef = InterlockedDecrement( &m_cRef );
  332. if ( cRef == 0 )
  333. {
  334. TraceDo( delete this );
  335. }
  336. CRETURN( cRef );
  337. } //*** CProxyCfgIPAddressInfo::Release
  338. //*************************************************************************//
  339. /////////////////////////////////////////////////////////////////////////////
  340. // CProxyCfgIPAddressInfo -- IClusCfgIPAddressInfo interface.
  341. /////////////////////////////////////////////////////////////////////////////
  342. //
  343. //
  344. //
  345. STDMETHODIMP
  346. CProxyCfgIPAddressInfo::GetUID(
  347. BSTR * pbstrUIDOut
  348. )
  349. {
  350. TraceFunc( "[IClusCfgIPAddressInfo]" );
  351. HRESULT hr;
  352. DWORD sc;
  353. DWORD ulNetwork = m_ulIPAddress & m_ulSubnetMask;
  354. LPWSTR psz = NULL;
  355. if ( pbstrUIDOut == NULL )
  356. {
  357. hr = THR( E_POINTER );
  358. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2kProxy_IPAddressInfo_GetName_InvalidPointer, hr );
  359. goto Cleanup;
  360. }
  361. sc = TW32( ClRtlTcpipAddressToString( ulNetwork, &psz ) ); // KB: Allocates to psz using LocalAlloc().
  362. if ( sc != ERROR_SUCCESS )
  363. {
  364. hr = HRESULT_FROM_WIN32( sc );
  365. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_IPAddressInfo_GetUID_ClRtlTcpipAddressToString_Failed, hr );
  366. goto Cleanup;
  367. } // if:
  368. *pbstrUIDOut = SysAllocString( psz );
  369. if ( *pbstrUIDOut == NULL )
  370. {
  371. hr = THR( E_OUTOFMEMORY );
  372. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_IPAddressInfo_GetUID_OutOfMemory, hr );
  373. goto Cleanup;
  374. }
  375. hr = S_OK;
  376. Cleanup:
  377. if ( psz != NULL )
  378. {
  379. LocalFree( psz ); // KB: Don't use TraceFree() here!
  380. } // if:
  381. HRETURN( hr );
  382. } //***CProxyCfgIPAddressInfo::GetUID
  383. //
  384. //
  385. //
  386. STDMETHODIMP
  387. CProxyCfgIPAddressInfo::GetIPAddress(
  388. ULONG * pulDottedQuadOut
  389. )
  390. {
  391. TraceFunc( "[IClusCfgIPAddressInfo]" );
  392. HRESULT hr;
  393. if ( pulDottedQuadOut == NULL )
  394. goto InvalidPointer;
  395. *pulDottedQuadOut = m_ulIPAddress;
  396. hr = S_OK;
  397. Cleanup:
  398. HRETURN( hr );
  399. InvalidPointer:
  400. hr = THR( E_POINTER );
  401. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_GetIPAddress_InvalidPointer, hr );
  402. goto Cleanup;
  403. } //***CProxyCfgIPAddressInfo::GetIPAddress
  404. //
  405. //
  406. //
  407. STDMETHODIMP
  408. CProxyCfgIPAddressInfo::SetIPAddress(
  409. ULONG ulDottedQuadIn
  410. )
  411. {
  412. TraceFunc( "[IClusCfgIPAddressInfo]" );
  413. HRESULT hr = THR( E_NOTIMPL );
  414. HRETURN( hr );
  415. } //***CProxyCfgIPAddressInfo::SetIPAddress
  416. //
  417. //
  418. //
  419. STDMETHODIMP
  420. CProxyCfgIPAddressInfo::GetSubnetMask(
  421. ULONG * pulDottedQuadOut
  422. )
  423. {
  424. TraceFunc( "[IClusCfgIPAddressInfo]" );
  425. HRESULT hr;
  426. if ( pulDottedQuadOut == NULL )
  427. goto InvalidPointer;
  428. *pulDottedQuadOut = m_ulSubnetMask;
  429. hr = S_OK;
  430. Cleanup:
  431. HRETURN( hr );
  432. InvalidPointer:
  433. hr = THR( E_POINTER );
  434. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_GetSubnetMask_InvalidPointer, hr );
  435. goto Cleanup;
  436. } //***CProxyCfgIPAddressInfo::GetSubnetMask
  437. //
  438. //
  439. //
  440. STDMETHODIMP
  441. CProxyCfgIPAddressInfo::SetSubnetMask(
  442. ULONG ulDottedQuadIn
  443. )
  444. {
  445. TraceFunc( "[IClusCfgIPAddressInfo]" );
  446. HRESULT hr = THR( E_NOTIMPL );
  447. HRETURN( hr );
  448. } //***CProxyCfgIPAddressInfo::SetSubnetMask
  449. //****************************************************************************
  450. //
  451. // IClusCfgCallback
  452. //
  453. //****************************************************************************
  454. //////////////////////////////////////////////////////////////////////////////
  455. //++
  456. //
  457. // CProxyCfgIPAddressInfo::SendStatusReport
  458. //
  459. // Description:
  460. //
  461. // Arguments:
  462. //
  463. // Return Value:
  464. //
  465. // Remarks:
  466. // None.
  467. //
  468. //--
  469. //////////////////////////////////////////////////////////////////////////////
  470. STDMETHODIMP
  471. CProxyCfgIPAddressInfo::SendStatusReport(
  472. BSTR bstrNodeNameIn,
  473. CLSID clsidTaskMajorIn,
  474. CLSID clsidTaskMinorIn,
  475. ULONG ulMinIn,
  476. ULONG ulMaxIn,
  477. ULONG ulCurrentIn,
  478. HRESULT hrStatusIn,
  479. BSTR bstrDescriptionIn,
  480. FILETIME * pftTimeIn,
  481. BSTR bstrReferenceIn
  482. )
  483. {
  484. TraceFunc( "[IClusCfgCallback]" );
  485. HRESULT hr = S_OK;
  486. if ( m_pcccb != NULL )
  487. {
  488. hr = THR( m_pcccb->SendStatusReport( bstrNodeNameIn,
  489. clsidTaskMajorIn,
  490. clsidTaskMinorIn,
  491. ulMinIn,
  492. ulMaxIn,
  493. ulCurrentIn,
  494. hrStatusIn,
  495. bstrDescriptionIn,
  496. pftTimeIn,
  497. bstrReferenceIn
  498. ) );
  499. } // if:
  500. HRETURN( hr );
  501. } //*** CProxyCfgIPAddressInfo::SendStatusReport