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.

316 lines
5.4 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: enum.cpp
  7. //
  8. // Contents: Cert Server Database interface implementation
  9. //
  10. //---------------------------------------------------------------------------
  11. #include <pch.cpp>
  12. #pragma hdrstop
  13. #include "csprop.h"
  14. #include "row.h"
  15. #include "enum.h"
  16. #include "db.h"
  17. #include "dbw.h"
  18. #define __dwFILE__ __dwFILE_CERTDB_ENUM_CPP__
  19. #if DBG
  20. LONG g_cCertDBName;
  21. LONG g_cCertDBNameTotal;
  22. #endif
  23. CEnumCERTDBNAME::CEnumCERTDBNAME()
  24. {
  25. DBGCODE(InterlockedIncrement(&g_cCertDBName));
  26. DBGCODE(InterlockedIncrement(&g_cCertDBNameTotal));
  27. m_prow = NULL;
  28. m_cRef = 1;
  29. }
  30. CEnumCERTDBNAME::~CEnumCERTDBNAME()
  31. {
  32. DBGCODE(InterlockedDecrement(&g_cCertDBName));
  33. _Cleanup();
  34. }
  35. // CEnumCERTDBNAME implementation
  36. VOID
  37. CEnumCERTDBNAME::_Cleanup()
  38. {
  39. if (NULL != m_prow)
  40. {
  41. ((CCertDBRow *) m_prow)->EnumerateClose(m_tableid);
  42. m_prow->Release();
  43. }
  44. }
  45. HRESULT
  46. CEnumCERTDBNAME::Open(
  47. IN ICertDBRow *prow,
  48. IN JET_TABLEID tableid,
  49. IN DWORD Flags)
  50. {
  51. HRESULT hr;
  52. if (NULL == prow)
  53. {
  54. hr = E_POINTER;
  55. _JumpError(hr, error, "NULL parm");
  56. }
  57. prow->AddRef();
  58. m_fNoMoreData = FALSE;
  59. m_prow = prow;
  60. m_tableid = tableid;
  61. m_Flags = Flags;
  62. m_ielt = 0;
  63. m_cskip = 0;
  64. hr = S_OK;
  65. error:
  66. return(hr);
  67. }
  68. // IEnumCERTDBNAME implementation
  69. STDMETHODIMP
  70. CEnumCERTDBNAME::Next(
  71. /* [in] */ ULONG celt,
  72. /* [out] */ CERTDBNAME *rgelt,
  73. /* [out] */ ULONG *pceltFetched)
  74. {
  75. HRESULT hr;
  76. if (NULL == rgelt || NULL == pceltFetched)
  77. {
  78. hr = E_POINTER;
  79. _JumpError(hr, error, "NULL parm");
  80. }
  81. *pceltFetched = 0;
  82. if (NULL == m_prow)
  83. {
  84. hr = E_UNEXPECTED;
  85. _JumpError(hr, error, "NULL m_prow");
  86. }
  87. if (m_fNoMoreData)
  88. {
  89. hr = S_FALSE;
  90. goto error;
  91. }
  92. CSASSERT(0 <= m_ielt);
  93. CSASSERT(0 <= m_ielt + m_cskip);
  94. DBGPRINT((
  95. DBG_SS_CERTDBI,
  96. "Enum::Next(celt=%d) ielt=%d, skip=%d\n",
  97. celt,
  98. m_ielt,
  99. m_cskip));
  100. hr = ((CCertDBRow *) m_prow)->EnumerateNext(
  101. &m_Flags,
  102. m_tableid,
  103. m_cskip,
  104. celt,
  105. rgelt,
  106. pceltFetched);
  107. if (S_FALSE == hr)
  108. {
  109. m_fNoMoreData = TRUE;
  110. }
  111. else
  112. {
  113. _JumpIfError(hr, error, "EnumerateNext");
  114. }
  115. m_ielt += m_cskip;
  116. m_ielt += *pceltFetched;
  117. m_cskip = 0;
  118. error:
  119. return(hr);
  120. }
  121. STDMETHODIMP
  122. CEnumCERTDBNAME::Skip(
  123. /* [in] */ LONG celt,
  124. /* [out] */ LONG *pielt)
  125. {
  126. HRESULT hr;
  127. LONG cskipnew;
  128. if (NULL == pielt)
  129. {
  130. hr = E_POINTER;
  131. _JumpError(hr, error, "NULL parm");
  132. }
  133. if (NULL == m_prow)
  134. {
  135. hr = E_UNEXPECTED;
  136. _JumpError(hr, error, "NULL m_prow");
  137. }
  138. cskipnew = m_cskip + celt;
  139. DBGPRINT((
  140. DBG_SS_CERTDBI,
  141. "Enum::Skip(%d) ielt=%d: %d --> %d, skip=%d --> %d\n",
  142. celt,
  143. m_ielt,
  144. m_ielt + m_cskip,
  145. m_ielt + cskipnew,
  146. m_cskip,
  147. cskipnew));
  148. CSASSERT(0 <= m_ielt);
  149. if (0 > cskipnew)
  150. {
  151. if (0 > m_ielt + cskipnew)
  152. {
  153. hr = E_INVALIDARG;
  154. _JumpError(hr, error, "Skip back to before start");
  155. }
  156. m_fNoMoreData = FALSE;
  157. }
  158. *pielt = m_ielt + cskipnew;
  159. m_cskip = cskipnew;
  160. hr = S_OK;
  161. error:
  162. return(hr);
  163. }
  164. STDMETHODIMP
  165. CEnumCERTDBNAME::Reset(VOID)
  166. {
  167. HRESULT hr;
  168. LONG iDummy;
  169. hr = Skip(-(m_ielt + m_cskip), &iDummy);
  170. _JumpIfError(hr, error, "Skip");
  171. CSASSERT(0 == iDummy);
  172. error:
  173. return(hr);
  174. }
  175. STDMETHODIMP
  176. CEnumCERTDBNAME::Clone(
  177. /* [out] */ IEnumCERTDBNAME **ppenum)
  178. {
  179. HRESULT hr;
  180. LONG iDummy;
  181. if (NULL == ppenum)
  182. {
  183. hr = E_POINTER;
  184. _JumpError(hr, error, "NULL parm");
  185. }
  186. *ppenum = NULL;
  187. if (NULL == m_prow)
  188. {
  189. hr = E_UNEXPECTED;
  190. _JumpError(hr, error, "NULL m_prow");
  191. }
  192. hr = ((CCertDBRow *) m_prow)->EnumCertDBName(
  193. CIE_TABLE_MASK & m_Flags,
  194. ppenum);
  195. _JumpIfError(hr, error, "EnumerateCertDBName");
  196. (*ppenum)->Skip(m_ielt + m_cskip, &iDummy);
  197. error:
  198. return(hr);
  199. }
  200. // IUnknown implementation
  201. STDMETHODIMP
  202. CEnumCERTDBNAME::QueryInterface(
  203. const IID& iid,
  204. void **ppv)
  205. {
  206. HRESULT hr;
  207. if (NULL == ppv)
  208. {
  209. hr = E_POINTER;
  210. _JumpError(hr, error, "NULL parm");
  211. }
  212. if (iid == IID_IUnknown)
  213. {
  214. *ppv = static_cast<IEnumCERTDBNAME *>(this);
  215. }
  216. else if (iid == IID_IEnumCERTDBNAME)
  217. {
  218. *ppv = static_cast<IEnumCERTDBNAME *>(this);
  219. }
  220. else
  221. {
  222. *ppv = NULL;
  223. hr = E_NOINTERFACE;
  224. _JumpError(hr, error, "IID");
  225. }
  226. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  227. hr = S_OK;
  228. error:
  229. return(hr);
  230. }
  231. ULONG STDMETHODCALLTYPE
  232. CEnumCERTDBNAME::AddRef()
  233. {
  234. return(InterlockedIncrement(&m_cRef));
  235. }
  236. ULONG STDMETHODCALLTYPE
  237. CEnumCERTDBNAME::Release()
  238. {
  239. ULONG cRef = InterlockedDecrement(&m_cRef);
  240. if (0 == cRef)
  241. {
  242. delete this;
  243. }
  244. return(cRef);
  245. }
  246. #if 0
  247. STDMETHODIMP
  248. CEnumCERTDBNAME::InterfaceSupportsErrorInfo(
  249. IN REFIID riid)
  250. {
  251. static const IID *arr[] =
  252. {
  253. &IID_IEnumCERTDBNAME,
  254. };
  255. for (int i = 0; i < sizeof(arr)/sizeof(arr[0]); i++)
  256. {
  257. if (InlineIsEqualGUID(*arr[i], riid))
  258. {
  259. return(S_OK);
  260. }
  261. }
  262. return(S_FALSE);
  263. }
  264. #endif