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.

551 lines
9.9 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: column.cpp
  7. //
  8. // Contents: Cert Server Data Base interface implementation
  9. //
  10. //---------------------------------------------------------------------------
  11. #include <pch.cpp>
  12. #pragma hdrstop
  13. #include "csdisp.h"
  14. #include "csprop.h"
  15. #include "column.h"
  16. #include "view.h"
  17. #if DBG_CERTSRV
  18. LONG g_cCertViewColumn;
  19. LONG g_cCertViewColumnTotal;
  20. #endif
  21. CEnumCERTVIEWCOLUMN::CEnumCERTVIEWCOLUMN()
  22. {
  23. DBGCODE(InterlockedIncrement(&g_cCertViewColumn));
  24. DBGCODE(InterlockedIncrement(&g_cCertViewColumnTotal));
  25. m_pvw = NULL;
  26. m_prow = NULL;
  27. m_cRef = 1;
  28. }
  29. CEnumCERTVIEWCOLUMN::~CEnumCERTVIEWCOLUMN()
  30. {
  31. DBGCODE(InterlockedDecrement(&g_cCertViewColumn));
  32. #if DBG_CERTSRV
  33. if (m_cRef > 1)
  34. {
  35. DBGPRINT((
  36. DBG_SS_CERTVIEWI,
  37. "%hs has %d instances left over\n",
  38. "CEnumCERTVIEWCOLUMN",
  39. m_cRef));
  40. }
  41. #endif
  42. if (NULL != m_pvw)
  43. {
  44. m_pvw->Release();
  45. }
  46. if (NULL != m_prow)
  47. {
  48. LocalFree(m_prow);
  49. }
  50. }
  51. HRESULT
  52. CEnumCERTVIEWCOLUMN::Open(
  53. IN LONG Flags,
  54. IN LONG iRow,
  55. IN ICertView *pvw,
  56. OPTIONAL IN CERTTRANSDBRESULTROW const *prow)
  57. {
  58. HRESULT hr;
  59. if (NULL == pvw)
  60. {
  61. hr = E_POINTER;
  62. _JumpError(hr, error, "NULL parm");
  63. }
  64. CSASSERT(0 == (CVRC_TABLE_MASK & CVRC_COLUMN_MASK));
  65. hr = E_INVALIDARG;
  66. if (~(CVRC_TABLE_MASK | CVRC_COLUMN_MASK) & Flags)
  67. {
  68. _JumpError(hr, error, "Flags");
  69. }
  70. switch (CVRC_COLUMN_MASK & Flags)
  71. {
  72. case CVRC_COLUMN_SCHEMA:
  73. case CVRC_COLUMN_RESULT:
  74. case CVRC_COLUMN_VALUE:
  75. break;
  76. default:
  77. _JumpError(hr, error, "Flags column");
  78. }
  79. switch (CVRC_TABLE_MASK & Flags)
  80. {
  81. case CVRC_TABLE_REQCERT:
  82. case CVRC_TABLE_EXTENSIONS:
  83. case CVRC_TABLE_ATTRIBUTES:
  84. case CVRC_TABLE_CRL:
  85. break;
  86. default:
  87. _JumpError(hr, error, "Flags table");
  88. }
  89. m_Flags = Flags;
  90. m_iRow = iRow;
  91. m_pvw = pvw;
  92. m_pvw->AddRef();
  93. DBGPRINT((
  94. DBG_SS_CERTVIEWI,
  95. "CEnumCERTVIEWCOLUMN::Open(cvrcTable=%x, cvrcColumn=%x)\n",
  96. CVRC_TABLE_MASK & Flags,
  97. CVRC_COLUMN_MASK & Flags));
  98. if (NULL != prow)
  99. {
  100. m_prow = (CERTTRANSDBRESULTROW *) LocalAlloc(LMEM_FIXED, prow->cbrow);
  101. if (NULL == m_prow)
  102. {
  103. hr = E_OUTOFMEMORY;
  104. _JumpError(hr, error, "LocalAlloc");
  105. }
  106. CopyMemory(m_prow, prow, prow->cbrow);
  107. }
  108. hr = m_pvw->GetColumnCount(m_Flags, &m_celt);
  109. _JumpIfError(hr, error, "GetColumnCount");
  110. Reset();
  111. error:
  112. return(hr);
  113. }
  114. STDMETHODIMP
  115. CEnumCERTVIEWCOLUMN::Next(
  116. /* [out, retval] */ LONG *pIndex)
  117. {
  118. HRESULT hr;
  119. if (NULL == pIndex)
  120. {
  121. hr = E_POINTER;
  122. _JumpError(hr, error, "NULL parm");
  123. }
  124. if (-1 > m_ielt || m_ielt >= m_celt - 1)
  125. {
  126. *pIndex = -1;
  127. hr = S_FALSE;
  128. goto error;
  129. }
  130. m_ielt++;
  131. hr = ((CCertView *) m_pvw)->FindColumn(
  132. m_Flags,
  133. m_ielt,
  134. &m_pcol,
  135. &m_pwszDisplayName);
  136. _JumpIfError(hr, error, "FindColumn");
  137. *pIndex = m_ielt;
  138. error:
  139. return(_SetErrorInfo(hr, L"CEnumCERTVIEWCOLUMN::Next"));
  140. }
  141. STDMETHODIMP
  142. CEnumCERTVIEWCOLUMN::GetName(
  143. /* [out, retval] */ BSTR *pstrOut)
  144. {
  145. HRESULT hr;
  146. if (NULL == pstrOut)
  147. {
  148. hr = E_POINTER;
  149. _JumpError(hr, error, "NULL parm");
  150. }
  151. if (NULL == m_pcol)
  152. {
  153. hr = E_UNEXPECTED;
  154. _JumpError(hr, error, "m_pcol NULL");
  155. }
  156. if (!ConvertWszToBstr(pstrOut, m_pcol->pwszName, -1))
  157. {
  158. hr = E_OUTOFMEMORY;
  159. _JumpError(hr, error, "ConvertWszToBstr");
  160. }
  161. hr = S_OK;
  162. error:
  163. return(_SetErrorInfo(hr, L"CEnumCERTVIEWCOLUMN::GetName"));
  164. }
  165. STDMETHODIMP
  166. CEnumCERTVIEWCOLUMN::GetDisplayName(
  167. /* [out, retval] */ BSTR *pstrOut)
  168. {
  169. HRESULT hr;
  170. if (NULL == pstrOut)
  171. {
  172. hr = E_POINTER;
  173. _JumpError(hr, error, "NULL parm");
  174. }
  175. if (NULL == m_pwszDisplayName)
  176. {
  177. hr = E_UNEXPECTED;
  178. _JumpError(hr, error, "m_pwszDisplayName NULL");
  179. }
  180. if (!ConvertWszToBstr(pstrOut, m_pwszDisplayName, -1))
  181. {
  182. hr = E_OUTOFMEMORY;
  183. _JumpError(hr, error, "ConvertWszToBstr");
  184. }
  185. hr = S_OK;
  186. error:
  187. return(_SetErrorInfo(hr, L"CEnumCERTVIEWCOLUMN::GetDisplayName"));
  188. }
  189. STDMETHODIMP
  190. CEnumCERTVIEWCOLUMN::GetType(
  191. /* [out, retval] */ LONG *pType)
  192. {
  193. HRESULT hr;
  194. if (NULL == pType)
  195. {
  196. hr = E_POINTER;
  197. _JumpError(hr, error, "NULL parm");
  198. }
  199. if (NULL == m_pcol)
  200. {
  201. hr = E_UNEXPECTED;
  202. _JumpError(hr, error, "m_pcol NULL");
  203. }
  204. *pType = PROPTYPE_MASK & m_pcol->Type;
  205. hr = S_OK;
  206. error:
  207. return(_SetErrorInfo(hr, L"CEnumCERTVIEWCOLUMN::GetType"));
  208. }
  209. STDMETHODIMP
  210. CEnumCERTVIEWCOLUMN::IsIndexed(
  211. /* [out, retval] */ LONG *pIndexed)
  212. {
  213. HRESULT hr;
  214. if (NULL == pIndexed)
  215. {
  216. hr = E_POINTER;
  217. _JumpError(hr, error, "NULL parm");
  218. }
  219. if (NULL == m_pcol)
  220. {
  221. hr = E_UNEXPECTED;
  222. _JumpError(hr, error, "m_pcol NULL");
  223. }
  224. *pIndexed = (PROPFLAGS_INDEXED & m_pcol->Type)? TRUE : FALSE;
  225. hr = S_OK;
  226. error:
  227. return(_SetErrorInfo(hr, L"CEnumCERTVIEWCOLUMN::IsIndexed"));
  228. }
  229. STDMETHODIMP
  230. CEnumCERTVIEWCOLUMN::GetMaxLength(
  231. /* [out, retval] */ LONG *pMaxLength)
  232. {
  233. HRESULT hr;
  234. if (NULL == pMaxLength)
  235. {
  236. hr = E_POINTER;
  237. _JumpError(hr, error, "NULL parm");
  238. }
  239. if (NULL == m_pcol)
  240. {
  241. hr = E_UNEXPECTED;
  242. _JumpError(hr, error, "m_pcol NULL");
  243. }
  244. *pMaxLength = m_pcol->cbMax;
  245. hr = S_OK;
  246. error:
  247. return(_SetErrorInfo(hr, L"CEnumCERTVIEWCOLUMN::GetMaxLength"));
  248. }
  249. DWORD
  250. AsnPropId(
  251. IN LONG Flags,
  252. IN WCHAR const *pwszName)
  253. {
  254. DWORD PropId = CR_PROP_NONE;
  255. switch (CVRC_TABLE_MASK & Flags)
  256. {
  257. case CVRC_TABLE_CRL:
  258. if (0 == lstrcmpi(pwszName, wszPROPCRLRAWCRL))
  259. {
  260. PropId = CR_PROP_BASECRL;
  261. }
  262. break;
  263. case CVRC_TABLE_REQCERT:
  264. if (0 == lstrcmpi(pwszName, wszPROPREQUESTRAWREQUEST))
  265. {
  266. PropId = MAXDWORD;
  267. }
  268. break;
  269. }
  270. return(PropId);
  271. }
  272. STDMETHODIMP
  273. CEnumCERTVIEWCOLUMN::GetValue(
  274. /* [in] */ LONG Flags,
  275. /* [out, retval] */ VARIANT *pvarValue)
  276. {
  277. HRESULT hr = E_UNEXPECTED;
  278. BYTE const *pbValue;
  279. CERTTRANSDBRESULTCOLUMN const *pColResult;
  280. if (NULL == pvarValue)
  281. {
  282. hr = E_POINTER;
  283. _JumpError(hr, error, "NULL parm");
  284. }
  285. VariantInit(pvarValue);
  286. if (CVRC_COLUMN_VALUE != (CVRC_COLUMN_MASK & m_Flags))
  287. {
  288. _JumpError(hr, error, "No Value");
  289. }
  290. if (NULL == m_pcol)
  291. {
  292. _JumpError(hr, error, "m_pcol NULL");
  293. }
  294. pColResult = &((CERTTRANSDBRESULTCOLUMN const *) (m_prow + 1))[m_ielt];
  295. CSASSERT(m_pcol->Type == pColResult->Type);
  296. if (0 == pColResult->obValue)
  297. {
  298. hr = S_OK; // leave VariantClear()'s VT_EMPTY tag
  299. goto error;
  300. }
  301. pbValue = (BYTE const *) Add2ConstPtr(m_prow, pColResult->obValue);
  302. hr = myUnmarshalFormattedVariant(
  303. Flags,
  304. AsnPropId(m_Flags, m_pcol->pwszName),
  305. m_pcol->Type,
  306. pColResult->cbValue,
  307. pbValue,
  308. pvarValue);
  309. _JumpIfError(hr, error, "myUnmarshalFormattedVariant");
  310. error:
  311. if (S_OK != hr)
  312. {
  313. VariantClear(pvarValue);
  314. }
  315. return(_SetErrorInfo(hr, L"CEnumCERTVIEWCOLUMN::GetValue"));
  316. }
  317. STDMETHODIMP
  318. CEnumCERTVIEWCOLUMN::Skip(
  319. /* [in] */ LONG celt)
  320. {
  321. HRESULT hr;
  322. LONG ieltnew = m_ielt + celt;
  323. if (-1 > ieltnew)
  324. {
  325. hr = E_INVALIDARG;
  326. _JumpError(hr, error, "Skip back to before start");
  327. }
  328. m_ielt = ieltnew;
  329. m_pcol = NULL;
  330. hr = S_OK;
  331. error:
  332. return(_SetErrorInfo(hr, L"CEnumCERTVIEWCOLUMN::Skip"));
  333. }
  334. STDMETHODIMP
  335. CEnumCERTVIEWCOLUMN::Reset(VOID)
  336. {
  337. m_ielt = -1;
  338. m_pcol = NULL;
  339. return(S_OK);
  340. }
  341. STDMETHODIMP
  342. CEnumCERTVIEWCOLUMN::Clone(
  343. /* [out] */ IEnumCERTVIEWCOLUMN **ppenum)
  344. {
  345. HRESULT hr;
  346. IEnumCERTVIEWCOLUMN *penum = NULL;
  347. if (NULL == ppenum)
  348. {
  349. hr = E_POINTER;
  350. _JumpError(hr, error, "NULL parm");
  351. }
  352. *ppenum = NULL;
  353. penum = new CEnumCERTVIEWCOLUMN;
  354. if (NULL == penum)
  355. {
  356. hr = E_OUTOFMEMORY;
  357. _JumpError(hr, error, "new CEnumCERTVIEWCOLUMN");
  358. }
  359. hr = ((CEnumCERTVIEWCOLUMN *) penum)->Open(
  360. m_Flags,
  361. -1,
  362. m_pvw,
  363. m_prow);
  364. _JumpIfError(hr, error, "Open");
  365. if (-1 != m_ielt)
  366. {
  367. hr = penum->Skip(m_ielt);
  368. _JumpIfError(hr, error, "Skip");
  369. if (NULL != m_pcol)
  370. {
  371. LONG Index;
  372. hr = penum->Next(&Index);
  373. _JumpIfError(hr, error, "Next");
  374. CSASSERT(Index == m_ielt);
  375. }
  376. }
  377. *ppenum = penum;
  378. penum = NULL;
  379. hr = S_OK;
  380. error:
  381. if (NULL != penum)
  382. {
  383. penum->Release();
  384. }
  385. return(_SetErrorInfo(hr, L"CEnumCERTVIEWCOLUMN::Clone"));
  386. }
  387. HRESULT
  388. CEnumCERTVIEWCOLUMN::_SetErrorInfo(
  389. IN HRESULT hrError,
  390. IN WCHAR const *pwszDescription)
  391. {
  392. CSASSERT(FAILED(hrError) || S_OK == hrError || S_FALSE == hrError);
  393. if (FAILED(hrError))
  394. {
  395. HRESULT hr;
  396. hr = DispatchSetErrorInfo(
  397. hrError,
  398. pwszDescription,
  399. wszCLASS_CERTVIEW L".CEnumCERTVIEWCOLUMN",
  400. &IID_IEnumCERTVIEWCOLUMN);
  401. CSASSERT(hr == hrError);
  402. }
  403. return(hrError);
  404. }
  405. #if 1
  406. // IUnknown implementation
  407. STDMETHODIMP
  408. CEnumCERTVIEWCOLUMN::QueryInterface(
  409. const IID& iid,
  410. void **ppv)
  411. {
  412. HRESULT hr;
  413. if (NULL == ppv)
  414. {
  415. hr = E_POINTER;
  416. _JumpError(hr, error, "NULL parm");
  417. }
  418. if (iid == IID_IUnknown)
  419. {
  420. *ppv = static_cast<IEnumCERTVIEWCOLUMN *>(this);
  421. }
  422. else if (iid == IID_IDispatch)
  423. {
  424. *ppv = static_cast<IEnumCERTVIEWCOLUMN *>(this);
  425. }
  426. else if (iid == IID_ISupportErrorInfo)
  427. {
  428. *ppv = static_cast<IEnumCERTVIEWCOLUMN *>(this);
  429. }
  430. else if (iid == IID_IEnumCERTVIEWCOLUMN)
  431. {
  432. *ppv = static_cast<IEnumCERTVIEWCOLUMN *>(this);
  433. }
  434. else
  435. {
  436. *ppv = NULL;
  437. hr = E_NOINTERFACE;
  438. _JumpError(hr, error, "IID");
  439. }
  440. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  441. hr = S_OK;
  442. error:
  443. return(hr);
  444. }
  445. ULONG STDMETHODCALLTYPE
  446. CEnumCERTVIEWCOLUMN::AddRef()
  447. {
  448. return(InterlockedIncrement(&m_cRef));
  449. }
  450. ULONG STDMETHODCALLTYPE
  451. CEnumCERTVIEWCOLUMN::Release()
  452. {
  453. ULONG cRef = InterlockedDecrement(&m_cRef);
  454. if (0 == cRef)
  455. {
  456. delete this;
  457. }
  458. return(cRef);
  459. }
  460. #endif