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.

448 lines
9.3 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // EnumCookies.cpp
  7. //
  8. // Description:
  9. // CEnumCookies implementation.
  10. //
  11. // Maintained By:
  12. // David Potter (DavidP) 14-JUN-2001
  13. // Geoffrey Pease (GPease) 08-MAY-2000
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16. #include "Pch.h"
  17. #include "EnumCookies.h"
  18. #include "ObjectManager.h"
  19. DEFINE_THISCLASS("CEnumCookies")
  20. // ************************************************************************
  21. //
  22. // Constructor / Destructor
  23. //
  24. // ************************************************************************
  25. //////////////////////////////////////////////////////////////////////////////
  26. //
  27. // HRESULT
  28. // CEnumCookies::S_HrCreateInstance(
  29. // IUnknown ** ppunkOut
  30. // )
  31. //
  32. //////////////////////////////////////////////////////////////////////////////
  33. HRESULT
  34. CEnumCookies::S_HrCreateInstance(
  35. IUnknown ** ppunkOut
  36. )
  37. {
  38. TraceFunc( "" );
  39. HRESULT hr = S_OK;
  40. CEnumCookies * pec = NULL;
  41. Assert( ppunkOut != NULL );
  42. if ( ppunkOut == NULL )
  43. {
  44. hr = THR( E_POINTER );
  45. goto Cleanup;
  46. }
  47. pec = new CEnumCookies;
  48. if ( pec == NULL )
  49. {
  50. hr = THR( E_OUTOFMEMORY );
  51. goto Cleanup;
  52. }
  53. hr = THR( pec->HrInit() );
  54. if ( FAILED( hr ) )
  55. {
  56. goto Cleanup;
  57. }
  58. hr = THR( pec->TypeSafeQI( IUnknown, ppunkOut ) );
  59. if ( FAILED( hr ) )
  60. {
  61. goto Cleanup;
  62. }
  63. Cleanup:
  64. if ( pec != NULL )
  65. {
  66. pec->Release();
  67. }
  68. HRETURN( hr );
  69. } //*** CEnumCookies::S_HrCreateInstance
  70. //////////////////////////////////////////////////////////////////////////////
  71. //
  72. // CEnumCookies::CEnumCookies
  73. //
  74. //////////////////////////////////////////////////////////////////////////////
  75. CEnumCookies::CEnumCookies( void )
  76. : m_cRef( 1 )
  77. {
  78. TraceFunc( "" );
  79. InterlockedIncrement( &g_cObjects );
  80. TraceFuncExit();
  81. } //*** CEnumCookies::CEnumCookies
  82. //////////////////////////////////////////////////////////////////////////////
  83. //
  84. // STDMETHODIMP
  85. // CEnumCookies::HrInit
  86. //
  87. //////////////////////////////////////////////////////////////////////////////
  88. STDMETHODIMP
  89. CEnumCookies::HrInit( void )
  90. {
  91. TraceFunc( "" );
  92. HRESULT hr = S_OK;
  93. // IUnknown stuff
  94. Assert( m_cRef == 1 );
  95. // IEnumCookies
  96. Assert( m_cIter == 0 );
  97. Assert( m_pList == NULL );
  98. Assert( m_cCookies == 0 );
  99. HRETURN( hr );
  100. } //*** CEnumCookies::HrInit
  101. //////////////////////////////////////////////////////////////////////////////
  102. //
  103. // CEnumCookies::~CEnumCookies
  104. //
  105. //////////////////////////////////////////////////////////////////////////////
  106. CEnumCookies::~CEnumCookies( void )
  107. {
  108. TraceFunc( "" );
  109. if ( m_pList != NULL )
  110. {
  111. TraceFree( m_pList );
  112. } // if: m_pList
  113. InterlockedDecrement( &g_cObjects );
  114. TraceFuncExit();
  115. } //*** CEnumCookies::~CEnumCookies
  116. // ************************************************************************
  117. //
  118. // IUnknown
  119. //
  120. // ************************************************************************
  121. //////////////////////////////////////////////////////////////////////////////
  122. //++
  123. //
  124. // CEnumCookies::QueryInterface
  125. //
  126. // Description:
  127. // Query this object for the passed in interface.
  128. //
  129. // Arguments:
  130. // riidIn
  131. // Id of interface requested.
  132. //
  133. // ppvOut
  134. // Pointer to the requested interface.
  135. //
  136. // Return Value:
  137. // S_OK
  138. // If the interface is available on this object.
  139. //
  140. // E_NOINTERFACE
  141. // If the interface is not available.
  142. //
  143. // E_POINTER
  144. // ppvOut was NULL.
  145. //
  146. // Remarks:
  147. // None.
  148. //
  149. //--
  150. //////////////////////////////////////////////////////////////////////////////
  151. STDMETHODIMP
  152. CEnumCookies::QueryInterface(
  153. REFIID riidIn
  154. , LPVOID * ppvOut
  155. )
  156. {
  157. TraceQIFunc( riidIn, ppvOut );
  158. HRESULT hr = S_OK;
  159. //
  160. // Validate arguments.
  161. //
  162. Assert( ppvOut != NULL );
  163. if ( ppvOut == NULL )
  164. {
  165. hr = THR( E_POINTER );
  166. goto Cleanup;
  167. }
  168. //
  169. // Handle known interfaces.
  170. //
  171. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  172. {
  173. *ppvOut = static_cast< IEnumCookies * >( this );
  174. } // if: IUnknown
  175. else if ( IsEqualIID( riidIn, IID_IEnumCookies ) )
  176. {
  177. *ppvOut = TraceInterface( __THISCLASS__, IEnumCookies, this, 0 );
  178. } // else if: IEnumCookies
  179. else
  180. {
  181. *ppvOut = NULL;
  182. hr = E_NOINTERFACE;
  183. } // else
  184. //
  185. // Add a reference to the interface if successful.
  186. //
  187. if ( SUCCEEDED( hr ) )
  188. {
  189. ((IUnknown *) *ppvOut)->AddRef();
  190. } // if: success
  191. Cleanup:
  192. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  193. } //*** CEnumCookies::QueryInterface
  194. //////////////////////////////////////////////////////////////////////////////
  195. //
  196. // STDMETHODIMP_(ULONG)
  197. // CEnumCookies::AddRef
  198. //
  199. //////////////////////////////////////////////////////////////////////////////
  200. STDMETHODIMP_( ULONG )
  201. CEnumCookies::AddRef( void )
  202. {
  203. TraceFunc( "[IUnknown]" );
  204. InterlockedIncrement( &m_cRef );
  205. CRETURN( m_cRef );
  206. } //*** CEnumCookies::AddRef
  207. //////////////////////////////////////////////////////////////////////////////
  208. //
  209. // STDMETHODIMP_(ULONG)
  210. // CEnumCookies::Release
  211. //
  212. //////////////////////////////////////////////////////////////////////////////
  213. STDMETHODIMP_( ULONG )
  214. CEnumCookies::Release( void )
  215. {
  216. TraceFunc( "[IUnknown]" );
  217. LONG cRef;
  218. cRef = InterlockedDecrement( &m_cRef );
  219. if ( cRef == 0 )
  220. {
  221. TraceDo( delete this );
  222. }
  223. CRETURN( cRef );
  224. } //*** CEnumCookies::Release
  225. //****************************************************************************
  226. //
  227. // IEnumCookies
  228. //
  229. //****************************************************************************
  230. //////////////////////////////////////////////////////////////////////////////
  231. //
  232. // STDMETHODIMP
  233. // CEnumCookies::Next(
  234. // ULONG celt,
  235. // IClusCfgNetworkInfo * rgNetworksOut[],
  236. // ULONG * pceltFetchedOut
  237. // )
  238. //
  239. //////////////////////////////////////////////////////////////////////////////
  240. STDMETHODIMP
  241. CEnumCookies::Next(
  242. ULONG celt,
  243. OBJECTCOOKIE rgcookieOut[],
  244. ULONG * pceltFetchedOut
  245. )
  246. {
  247. TraceFunc( "[IEnumCookies]" );
  248. HRESULT hr = S_OK;
  249. ULONG cIter = 0;
  250. //
  251. // Check parameters
  252. //
  253. if ( rgcookieOut == NULL )
  254. goto InvalidPointer;
  255. //
  256. // Loop and copy the cookies.
  257. //
  258. while ( m_cIter < m_cCookies && cIter < celt )
  259. {
  260. rgcookieOut[ cIter++ ] = m_pList[ m_cIter++ ];
  261. } // for each remaining cookie, up to requested count (at most).
  262. Assert( hr == S_OK );
  263. if ( cIter != celt )
  264. {
  265. hr = S_FALSE;
  266. }
  267. if ( pceltFetchedOut != NULL )
  268. {
  269. *pceltFetchedOut = cIter;
  270. }
  271. Cleanup:
  272. HRETURN( hr );
  273. InvalidPointer:
  274. hr = THR( E_POINTER );
  275. goto Cleanup;
  276. } //*** CEnumCookies::Next
  277. //////////////////////////////////////////////////////////////////////////////
  278. //
  279. // STDMETHODIMP
  280. // CEnumCookies::Skip(
  281. // ULONG celt
  282. // )
  283. //
  284. //////////////////////////////////////////////////////////////////////////////
  285. STDMETHODIMP
  286. CEnumCookies::Skip(
  287. ULONG celt
  288. )
  289. {
  290. TraceFunc( "[IEnumCookies]" );
  291. HRESULT hr = S_OK;
  292. m_cIter += celt;
  293. if ( m_cIter >= m_cAlloced )
  294. {
  295. m_cIter = m_cAlloced;
  296. hr = S_FALSE;
  297. }
  298. HRETURN( hr );
  299. } //*** CEnumCookies::Skip
  300. //////////////////////////////////////////////////////////////////////////////
  301. //
  302. // STDMETHODIMP
  303. // CEnumCookies::Reset( void )
  304. //
  305. //////////////////////////////////////////////////////////////////////////////
  306. STDMETHODIMP
  307. CEnumCookies::Reset( void )
  308. {
  309. TraceFunc( "[IEnumCookies]" );
  310. HRESULT hr = S_OK;
  311. m_cIter = 0;
  312. HRETURN( hr );
  313. } //*** CEnumCookies::Reset
  314. //////////////////////////////////////////////////////////////////////////////
  315. //
  316. // STDMETHODIMP
  317. // CEnumCookies::Clone(
  318. // IEnumCookies ** ppenumOut
  319. // )
  320. //
  321. //////////////////////////////////////////////////////////////////////////////
  322. STDMETHODIMP
  323. CEnumCookies::Clone(
  324. IEnumCookies ** ppenumOut
  325. )
  326. {
  327. TraceFunc( "[IEnumCookies]" );
  328. //
  329. // KB: not going to implement this method.
  330. //
  331. HRESULT hr = THR( E_NOTIMPL );
  332. HRETURN( hr );
  333. } //*** CEnumCookies::Clone
  334. //////////////////////////////////////////////////////////////////////////////
  335. //
  336. // STDMETHODIMP
  337. // CEnumCookies::Count(
  338. // DWORD * pnCountOut
  339. // )
  340. //
  341. //////////////////////////////////////////////////////////////////////////////
  342. STDMETHODIMP
  343. CEnumCookies::Count(
  344. DWORD * pnCountOut
  345. )
  346. {
  347. TraceFunc( "[IEnumCookies]" );
  348. HRESULT hr = S_OK;
  349. if ( pnCountOut == NULL )
  350. {
  351. hr = THR( E_POINTER );
  352. goto Cleanup;
  353. }
  354. *pnCountOut = m_cCookies;
  355. Cleanup:
  356. HRETURN( hr );
  357. } //*** CEnumCookies::Count