Source code of Windows XP (NT5)
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.

588 lines
13 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 * pcc = NULL;
  62. if ( ppunkOut == NULL )
  63. {
  64. hr = THR( E_POINTER );
  65. goto Cleanup;
  66. } // if:
  67. pcc = new CProxyCfgIPAddressInfo;
  68. if ( pcc == NULL )
  69. {
  70. hr = THR( E_OUTOFMEMORY );
  71. goto Cleanup;
  72. } // if:
  73. hr = THR( pcc->HrInit( punkOuterIn, phClusterIn, pclsidMajorIn, ulIPAddressIn, ulSubnetMaskIn ) );
  74. if ( FAILED( hr ) )
  75. goto Cleanup;
  76. hr = THR( pcc->TypeSafeQI( IUnknown, ppunkOut ) );
  77. Cleanup:
  78. if ( pcc != NULL )
  79. {
  80. pcc->Release();
  81. } // if:
  82. HRETURN( hr );
  83. } //*** CProxyCfgIPAddressInfo::S_HrCreateInstance()
  84. //////////////////////////////////////////////////////////////////////////////
  85. //++
  86. //
  87. // CProxyCfgIPAddressInfo::CProxyCfgIPAddressInfo()
  88. //
  89. // Description:
  90. // Constructor of the CProxyCfgIPAddressInfo class. This initializes
  91. // the m_cRef variable to 1 instead of 0 to account of possible
  92. // QueryInterface failure in DllGetClassObject.
  93. //
  94. // Arguments:
  95. // None.
  96. //
  97. // Return Value:
  98. // None.
  99. //
  100. // Remarks:
  101. // None.
  102. //
  103. //--
  104. //////////////////////////////////////////////////////////////////////////////
  105. CProxyCfgIPAddressInfo::CProxyCfgIPAddressInfo( void )
  106. : m_cRef( 1 )
  107. {
  108. TraceFunc( "" );
  109. InterlockedIncrement( &g_cObjects );
  110. Assert( m_pcccb == NULL );
  111. TraceFuncExit();
  112. } //*** CProxyCfgIPAddressInfo::CProxyCfgIPAddressInfo()
  113. //////////////////////////////////////////////////////////////////////////////
  114. //++
  115. //
  116. // CProxyCfgIPAddressInfo::~CProxyCfgIPAddressInfo()
  117. //
  118. // Description:
  119. // Destructor of the CProxyCfgIPAddressInfo class.
  120. //
  121. // Arguments:
  122. // None.
  123. //
  124. // Return Value:
  125. // None.
  126. //
  127. // Remarks:
  128. // None.
  129. //
  130. //--
  131. //////////////////////////////////////////////////////////////////////////////
  132. CProxyCfgIPAddressInfo::~CProxyCfgIPAddressInfo( void )
  133. {
  134. TraceFunc( "" );
  135. // m_cRef - noop
  136. if ( m_punkOuter != NULL )
  137. {
  138. m_punkOuter->Release( );
  139. }
  140. if ( m_pcccb != NULL )
  141. {
  142. m_pcccb->Release();
  143. } // if:
  144. // m_phCluster - DO NOT CLOSE!
  145. // m_pclsidMajor - noop
  146. InterlockedDecrement( &g_cObjects );
  147. TraceFuncExit();
  148. } //*** CProxyCfgIPAddressInfo::~CProxyCfgIPAddressInfo()
  149. //
  150. //
  151. //
  152. HRESULT
  153. CProxyCfgIPAddressInfo::HrInit(
  154. IUnknown * punkOuterIn,
  155. HCLUSTER * phClusterIn,
  156. CLSID * pclsidMajorIn,
  157. ULONG ulIPAddressIn,
  158. ULONG ulSubnetMaskIn
  159. )
  160. {
  161. TraceFunc( "" );
  162. HRESULT hr;
  163. if ( punkOuterIn != NULL )
  164. {
  165. m_punkOuter = punkOuterIn;
  166. m_punkOuter->AddRef( );
  167. }
  168. if ( phClusterIn == NULL )
  169. goto InvalidArg;
  170. m_phCluster = phClusterIn;
  171. if ( pclsidMajorIn != NULL )
  172. {
  173. m_pclsidMajor = pclsidMajorIn;
  174. }
  175. else
  176. {
  177. m_pclsidMajor = (CLSID *) &TASKID_Major_Client_And_Server_Log;
  178. }
  179. if ( punkOuterIn != NULL )
  180. {
  181. hr = THR( punkOuterIn->TypeSafeQI( IClusCfgCallback, &m_pcccb ) );
  182. if ( FAILED( hr ) )
  183. goto Cleanup;
  184. }
  185. m_ulIPAddress = ulIPAddressIn;
  186. m_ulSubnetMask = ulSubnetMaskIn;
  187. hr = S_OK;
  188. Cleanup:
  189. HRETURN( hr );
  190. InvalidArg:
  191. hr = THR( E_INVALIDARG );
  192. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_IPAddressInfo_HrInit_InvalidArg, hr );
  193. goto Cleanup;
  194. } // *** HrInit
  195. //*************************************************************************//
  196. /////////////////////////////////////////////////////////////////////////////
  197. // CProxyCfgIPAddressInfo -- IUknkown interface.
  198. /////////////////////////////////////////////////////////////////////////////
  199. //////////////////////////////////////////////////////////////////////////////
  200. //++
  201. //
  202. // CProxyCfgIPAddressInfo:: [INKNOWN] QueryInterface()
  203. //
  204. // Description:
  205. // Query this object for the passed in interface.
  206. //
  207. // Arguments:
  208. // IN REFIID riid,
  209. // Id of interface requested.
  210. //
  211. // OUT void ** ppv
  212. // Pointer to the requested interface.
  213. //
  214. // Return Value:
  215. // S_OK
  216. // If the interface is available on this object.
  217. //
  218. // E_NOINTERFACE
  219. // If the interface is not available.
  220. //
  221. // Remarks:
  222. // None.
  223. //
  224. //--
  225. //////////////////////////////////////////////////////////////////////////////
  226. STDMETHODIMP
  227. CProxyCfgIPAddressInfo::QueryInterface(
  228. REFIID riid,
  229. LPVOID *ppv
  230. )
  231. {
  232. TraceQIFunc( riid, ppv );
  233. HRESULT hr = E_NOINTERFACE;
  234. if ( IsEqualIID( riid, IID_IUnknown ) )
  235. {
  236. *ppv = static_cast< IClusCfgIPAddressInfo * >( this );
  237. hr = S_OK;
  238. } // if: IUnknown
  239. else if ( IsEqualIID( riid, IID_IClusCfgIPAddressInfo ) )
  240. {
  241. *ppv = TraceInterface( __THISCLASS__, IClusCfgIPAddressInfo, this, 0 );
  242. hr = S_OK;
  243. } // else if:
  244. if ( SUCCEEDED( hr ) )
  245. {
  246. ((IUnknown*) *ppv)->AddRef();
  247. } // if: success
  248. QIRETURN_IGNORESTDMARSHALLING( hr, riid );
  249. } //*** CProxyCfgIPAddressInfo::QueryInterface()
  250. //////////////////////////////////////////////////////////////////////////////
  251. //++
  252. //
  253. // STDMETHODIMP_( ULONG )
  254. // CProxyCfgIPAddressInfo:: [IUNKNOWN] AddRef()
  255. //
  256. // Description:
  257. // Increment the reference count of this object by one.
  258. //
  259. // Arguments:
  260. // None.
  261. //
  262. // Return Value:
  263. // The new reference count.
  264. //
  265. // Remarks:
  266. // None.
  267. //
  268. //--
  269. //////////////////////////////////////////////////////////////////////////////
  270. STDMETHODIMP_(ULONG)
  271. CProxyCfgIPAddressInfo::AddRef( void )
  272. {
  273. TraceFunc( "[IUnknown]" );
  274. InterlockedIncrement( &m_cRef );
  275. RETURN( m_cRef );
  276. } //*** CProxyCfgIPAddressInfo::AddRef()
  277. // IClusSetHandleProvider
  278. //////////////////////////////////////////////////////////////////////////////
  279. //++
  280. //
  281. // STDMETHODIMP_( ULONG )
  282. // CProxyCfgIPAddressInfo:: [IUNKNOWN] Release()
  283. //
  284. // Description:
  285. // Decrement the reference count of this object by one.
  286. //
  287. // Arguments:
  288. // None.
  289. //
  290. // Return Value:
  291. // The new reference count.
  292. //
  293. // Remarks:
  294. // None.
  295. //
  296. //--
  297. //////////////////////////////////////////////////////////////////////////////
  298. STDMETHODIMP_(ULONG)
  299. CProxyCfgIPAddressInfo::Release( void )
  300. {
  301. TraceFunc( "[IUnknown]" );
  302. InterlockedDecrement( &m_cRef );
  303. if ( m_cRef )
  304. RETURN( m_cRef );
  305. TraceDo( delete this );
  306. RETURN( 0 );
  307. } //*** CProxyCfgIPAddressInfo::Release()
  308. //*************************************************************************//
  309. /////////////////////////////////////////////////////////////////////////////
  310. // CProxyCfgIPAddressInfo -- IClusCfgIPAddressInfo interface.
  311. /////////////////////////////////////////////////////////////////////////////
  312. //
  313. //
  314. //
  315. STDMETHODIMP
  316. CProxyCfgIPAddressInfo::GetUID(
  317. BSTR * pbstrUIDOut
  318. )
  319. {
  320. TraceFunc( "[IClusCfgIPAddressInfo]" );
  321. HRESULT hr;
  322. DWORD sc;
  323. DWORD ulNetwork = m_ulIPAddress & m_ulSubnetMask;
  324. LPWSTR psz = NULL;
  325. if ( pbstrUIDOut == NULL )
  326. goto InvalidPointer;
  327. sc = TW32( ClRtlTcpipAddressToString( ulNetwork, &psz ) ); // KB: Allocates to psz using LocalAlloc().
  328. if ( sc != ERROR_SUCCESS )
  329. {
  330. hr = HRESULT_FROM_WIN32( sc );
  331. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_IPAddressInfo_GetUID_ClRtlTcpipAddressToString_Failed, hr );
  332. goto Cleanup;
  333. } // if:
  334. *pbstrUIDOut = SysAllocString( psz );
  335. if ( *pbstrUIDOut == NULL )
  336. goto OutOfMemory;
  337. hr = S_OK;
  338. Cleanup:
  339. if ( psz != NULL )
  340. {
  341. LocalFree( psz ); // KB: Don't use TraceFree() here!
  342. } // if:
  343. HRETURN( hr );
  344. InvalidPointer:
  345. hr = THR( E_POINTER );
  346. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2kProxy_IPAddressInfo_GetName_InvalidPointer, hr );
  347. goto Cleanup;
  348. OutOfMemory:
  349. hr = E_OUTOFMEMORY;
  350. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_IPAddressInfo_GetUID_OutOfMemory, hr );
  351. goto Cleanup;
  352. } //***CProxyCfgIPAddressInfo::GetUID()
  353. //
  354. //
  355. //
  356. STDMETHODIMP
  357. CProxyCfgIPAddressInfo::GetIPAddress(
  358. ULONG * pulDottedQuadOut
  359. )
  360. {
  361. TraceFunc( "[IClusCfgIPAddressInfo]" );
  362. HRESULT hr;
  363. if ( pulDottedQuadOut == NULL )
  364. goto InvalidPointer;
  365. *pulDottedQuadOut = m_ulIPAddress;
  366. hr = S_OK;
  367. Cleanup:
  368. HRETURN( hr );
  369. InvalidPointer:
  370. hr = THR( E_POINTER );
  371. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_GetIPAddress_InvalidPointer, hr );
  372. goto Cleanup;
  373. } //***CProxyCfgIPAddressInfo::GetIPAddress()
  374. //
  375. //
  376. //
  377. STDMETHODIMP
  378. CProxyCfgIPAddressInfo::SetIPAddress(
  379. ULONG ulDottedQuadIn
  380. )
  381. {
  382. TraceFunc( "[IClusCfgIPAddressInfo]" );
  383. HRESULT hr = THR( E_NOTIMPL );
  384. HRETURN( hr );
  385. } //***CProxyCfgIPAddressInfo::SetIPAddress()
  386. //
  387. //
  388. //
  389. STDMETHODIMP
  390. CProxyCfgIPAddressInfo::GetSubnetMask(
  391. ULONG * pulDottedQuadOut
  392. )
  393. {
  394. TraceFunc( "[IClusCfgIPAddressInfo]" );
  395. HRESULT hr;
  396. if ( pulDottedQuadOut == NULL )
  397. goto InvalidPointer;
  398. *pulDottedQuadOut = m_ulSubnetMask;
  399. hr = S_OK;
  400. Cleanup:
  401. HRETURN( hr );
  402. InvalidPointer:
  403. hr = THR( E_POINTER );
  404. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_GetSubnetMask_InvalidPointer, hr );
  405. goto Cleanup;
  406. } //***CProxyCfgIPAddressInfo::GetSubnetMask()
  407. //
  408. //
  409. //
  410. STDMETHODIMP
  411. CProxyCfgIPAddressInfo::SetSubnetMask(
  412. ULONG ulDottedQuadIn
  413. )
  414. {
  415. TraceFunc( "[IClusCfgIPAddressInfo]" );
  416. HRESULT hr = THR( E_NOTIMPL );
  417. HRETURN( hr );
  418. } //***CProxyCfgIPAddressInfo::SetSubnetMask()
  419. //****************************************************************************
  420. //
  421. // IClusCfgCallback
  422. //
  423. //****************************************************************************
  424. //////////////////////////////////////////////////////////////////////////////
  425. //++
  426. //
  427. // CProxyCfgIPAddressInfo::SendStatusReport()
  428. //
  429. // Description:
  430. //
  431. // Arguments:
  432. //
  433. // Return Value:
  434. //
  435. // Remarks:
  436. // None.
  437. //
  438. //--
  439. //////////////////////////////////////////////////////////////////////////////
  440. STDMETHODIMP
  441. CProxyCfgIPAddressInfo::SendStatusReport(
  442. BSTR bstrNodeNameIn,
  443. CLSID clsidTaskMajorIn,
  444. CLSID clsidTaskMinorIn,
  445. ULONG ulMinIn,
  446. ULONG ulMaxIn,
  447. ULONG ulCurrentIn,
  448. HRESULT hrStatusIn,
  449. BSTR bstrDescriptionIn,
  450. FILETIME * pftTimeIn,
  451. BSTR bstrReferenceIn
  452. )
  453. {
  454. TraceFunc( "[IClusCfgCallback]" );
  455. HRESULT hr = S_OK;
  456. if ( m_pcccb != NULL )
  457. {
  458. hr = THR( m_pcccb->SendStatusReport( bstrNodeNameIn,
  459. clsidTaskMajorIn,
  460. clsidTaskMinorIn,
  461. ulMinIn,
  462. ulMaxIn,
  463. ulCurrentIn,
  464. hrStatusIn,
  465. bstrDescriptionIn,
  466. pftTimeIn,
  467. bstrReferenceIn
  468. ) );
  469. } // if:
  470. HRETURN( hr );
  471. } //*** CProxyCfgIPAddressInfo::SendStatusReport()