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.

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