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.

608 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1999
  6. //
  7. // File: view.cpp
  8. //
  9. // Contents: ICertView IDispatch helper functions
  10. //
  11. //--------------------------------------------------------------------------
  12. #include <pch.cpp>
  13. #pragma hdrstop
  14. #include <stdlib.h>
  15. #include "csdisp.h"
  16. #include "csprop.h"
  17. #define __dwFILE__ __dwFILE_CERTLIB_VIEW_CPP__
  18. //+------------------------------------------------------------------------
  19. // ICertView dispatch support
  20. //WCHAR wszRegKeyViewClsid[] = wszCLASS_CERTVIEW TEXT("\\Clsid");
  21. //+------------------------------------
  22. // OpenConnection method:
  23. static OLECHAR *_apszOpenConnection[] = {
  24. TEXT("OpenConnection"),
  25. TEXT("strConfig"),
  26. };
  27. //+------------------------------------
  28. // EnumCertViewColumn method:
  29. static OLECHAR *_apszEnumCertViewColumn[] = {
  30. TEXT("EnumCertViewColumn"),
  31. TEXT("fResultColumn"),
  32. };
  33. //+------------------------------------
  34. // GetColumnCount method:
  35. static OLECHAR *_apszGetColumnCount[] = {
  36. TEXT("GetColumnCount"),
  37. TEXT("fResultColumn"),
  38. };
  39. //+------------------------------------
  40. // GetColumnIndex method:
  41. static OLECHAR *_apszGetColumnIndex[] = {
  42. TEXT("GetColumnIndex"),
  43. TEXT("fResultColumn"),
  44. TEXT("strColumnName"),
  45. };
  46. //+------------------------------------
  47. // SetResultColumnCount method:
  48. static OLECHAR *_apszSetResultColumnCount[] = {
  49. TEXT("SetResultColumnCount"),
  50. TEXT("cResultColumn"),
  51. };
  52. //+------------------------------------
  53. // SetResultColumn method:
  54. static OLECHAR *_apszSetResultColumn[] = {
  55. TEXT("SetResultColumn"),
  56. TEXT("ColumnIndex"),
  57. };
  58. //+------------------------------------
  59. // SetRestriction method:
  60. static OLECHAR *_apszSetRestriction[] = {
  61. TEXT("SetRestriction"),
  62. TEXT("ColumnIndex"),
  63. TEXT("SeekOperator"),
  64. TEXT("SortOrder"),
  65. TEXT("pvarValue"),
  66. };
  67. //+------------------------------------
  68. // OpenView method:
  69. static OLECHAR *_apszOpenView[] = {
  70. TEXT("OpenView"),
  71. };
  72. //+------------------------------------
  73. // SetTable method:
  74. static OLECHAR *_apszSetTable[] = {
  75. TEXT("SetTable"),
  76. TEXT("Table"),
  77. };
  78. //+------------------------------------
  79. // Dispatch Table:
  80. DISPATCHTABLE s_adtView[] =
  81. {
  82. #define VIEW_OPENCONNECTION 0
  83. DECLARE_DISPATCH_ENTRY(_apszOpenConnection)
  84. #define VIEW_ENUMCERTVIEWCOLUMN 1
  85. DECLARE_DISPATCH_ENTRY(_apszEnumCertViewColumn)
  86. #define VIEW_GETCOLUMNCOUNT 2
  87. DECLARE_DISPATCH_ENTRY(_apszGetColumnCount)
  88. #define VIEW_GETCOLUMNINDEX 3
  89. DECLARE_DISPATCH_ENTRY(_apszGetColumnIndex)
  90. #define VIEW_SETRESULTCOLUMNCOUNT 4
  91. DECLARE_DISPATCH_ENTRY(_apszSetResultColumnCount)
  92. #define VIEW_SETRESULTCOLUMN 5
  93. DECLARE_DISPATCH_ENTRY(_apszSetResultColumn)
  94. #define VIEW_SETRESTRICTION 6
  95. DECLARE_DISPATCH_ENTRY(_apszSetRestriction)
  96. #define VIEW_OPENVIEW 7
  97. DECLARE_DISPATCH_ENTRY(_apszOpenView)
  98. #define VIEW2_SETTABLE 8
  99. DECLARE_DISPATCH_ENTRY(_apszSetTable)
  100. };
  101. #define CVIEWDISPATCH (ARRAYSIZE(s_adtView))
  102. #define CVIEWDISPATCH_V1 VIEW2_SETTABLE
  103. #define CVIEWDISPATCH_V2 CVIEWDISPATCH
  104. DWORD s_acViewDispatch[] = {
  105. CVIEWDISPATCH_V2,
  106. CVIEWDISPATCH_V1,
  107. };
  108. IID const *s_apViewiid[] = {
  109. &IID_ICertView2,
  110. &IID_ICertView,
  111. };
  112. HRESULT
  113. View_Init(
  114. IN DWORD Flags,
  115. OUT DISPATCHINTERFACE *pdiView)
  116. {
  117. HRESULT hr;
  118. hr = DispatchSetup2(
  119. Flags,
  120. CLSCTX_INPROC_SERVER,
  121. wszCLASS_CERTVIEW,
  122. &CLSID_CCertView,
  123. ARRAYSIZE(s_acViewDispatch), // cver
  124. s_apViewiid,
  125. s_acViewDispatch,
  126. s_adtView,
  127. pdiView);
  128. _JumpIfError(hr, error, "DispatchSetup2(ICertView)");
  129. error:
  130. return(hr);
  131. }
  132. VOID
  133. View_Release(
  134. IN OUT DISPATCHINTERFACE *pdiView)
  135. {
  136. DispatchRelease(pdiView);
  137. }
  138. HRESULT
  139. ViewVerifyVersion(
  140. IN DISPATCHINTERFACE *pdiView,
  141. IN DWORD RequiredVersion)
  142. {
  143. HRESULT hr;
  144. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  145. switch (pdiView->m_dwVersion)
  146. {
  147. case 1:
  148. CSASSERT(
  149. NULL == pdiView->pDispatch ||
  150. CVIEWDISPATCH_V1 == pdiView->m_cDispatchTable);
  151. break;
  152. case 2:
  153. CSASSERT(
  154. NULL == pdiView->pDispatch ||
  155. CVIEWDISPATCH_V2 == pdiView->m_cDispatchTable);
  156. break;
  157. default:
  158. hr = HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR);
  159. _JumpError(hr, error, "m_dwVersion");
  160. }
  161. if (pdiView->m_dwVersion < RequiredVersion)
  162. {
  163. hr = E_NOTIMPL;
  164. _JumpError(hr, error, "old interface");
  165. }
  166. hr = S_OK;
  167. error:
  168. return(hr);
  169. }
  170. HRESULT
  171. View_OpenConnection(
  172. IN DISPATCHINTERFACE *pdiView,
  173. IN WCHAR const *pwszConfig)
  174. {
  175. HRESULT hr;
  176. BSTR strConfig = NULL;
  177. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  178. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  179. {
  180. hr = E_OUTOFMEMORY;
  181. _JumpError(hr, error, "ConvertWszToBstr");
  182. }
  183. if (NULL != pdiView->pDispatch)
  184. {
  185. VARIANT avar[1];
  186. avar[0].vt = VT_BSTR;
  187. avar[0].bstrVal = strConfig;
  188. hr = DispatchInvoke(
  189. pdiView,
  190. VIEW_OPENCONNECTION,
  191. ARRAYSIZE(avar),
  192. avar,
  193. 0,
  194. NULL);
  195. _JumpIfError(hr, error, "Invoke(OpenConnection)");
  196. }
  197. else
  198. {
  199. hr = ((ICertView *) pdiView->pUnknown)->OpenConnection(strConfig);
  200. _JumpIfError(hr, error, "OpenConnection");
  201. }
  202. error:
  203. if (NULL != strConfig)
  204. {
  205. SysFreeString(strConfig);
  206. }
  207. return(hr);
  208. }
  209. HRESULT
  210. View_GetColumnCount(
  211. IN DISPATCHINTERFACE *pdiView,
  212. IN LONG fResultColumn,
  213. OUT LONG *pcColumn)
  214. {
  215. HRESULT hr;
  216. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  217. if (NULL != pdiView->pDispatch)
  218. {
  219. VARIANT avar[1];
  220. avar[0].vt = VT_I4;
  221. avar[0].lVal = fResultColumn;
  222. hr = DispatchInvoke(
  223. pdiView,
  224. VIEW_GETCOLUMNCOUNT,
  225. ARRAYSIZE(avar),
  226. avar,
  227. VT_I4,
  228. pcColumn);
  229. _JumpIfError(hr, error, "Invoke(GetColumnCount)");
  230. }
  231. else
  232. {
  233. hr = ((ICertView *) pdiView->pUnknown)->GetColumnCount(
  234. fResultColumn,
  235. pcColumn);
  236. _JumpIfError(hr, error, "GetColumnCount");
  237. }
  238. error:
  239. return(hr);
  240. }
  241. HRESULT
  242. View_GetColumnIndex(
  243. IN DISPATCHINTERFACE *pdiView,
  244. IN LONG fResultColumn,
  245. IN WCHAR const *pwszColumnName,
  246. OUT LONG *pColumnIndex)
  247. {
  248. HRESULT hr;
  249. BSTR strColumnName = NULL;
  250. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  251. if (!ConvertWszToBstr(&strColumnName, pwszColumnName, -1))
  252. {
  253. hr = E_OUTOFMEMORY;
  254. _JumpError(hr, error, "ConvertWszToBstr");
  255. }
  256. if (NULL != pdiView->pDispatch)
  257. {
  258. VARIANT avar[2];
  259. avar[0].vt = VT_I4;
  260. avar[0].lVal = fResultColumn;
  261. avar[1].vt = VT_BSTR;
  262. avar[1].bstrVal = strColumnName;
  263. hr = DispatchInvoke(
  264. pdiView,
  265. VIEW_GETCOLUMNINDEX,
  266. ARRAYSIZE(avar),
  267. avar,
  268. VT_I4,
  269. pColumnIndex);
  270. _JumpIfError(hr, error, "Invoke(GetColumnIndex)");
  271. }
  272. else
  273. {
  274. hr = ((ICertView *) pdiView->pUnknown)->GetColumnIndex(
  275. fResultColumn,
  276. strColumnName,
  277. pColumnIndex);
  278. _JumpIfError(hr, error, "GetColumnIndex");
  279. }
  280. error:
  281. if (NULL != strColumnName)
  282. {
  283. SysFreeString(strColumnName);
  284. }
  285. return(hr);
  286. }
  287. HRESULT
  288. View_SetResultColumnCount(
  289. IN DISPATCHINTERFACE *pdiView,
  290. IN LONG cResultColumn)
  291. {
  292. HRESULT hr;
  293. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  294. if (NULL != pdiView->pDispatch)
  295. {
  296. VARIANT avar[1];
  297. avar[0].vt = VT_I4;
  298. avar[0].lVal = cResultColumn;
  299. hr = DispatchInvoke(
  300. pdiView,
  301. VIEW_SETRESULTCOLUMNCOUNT,
  302. ARRAYSIZE(avar),
  303. avar,
  304. 0,
  305. NULL);
  306. _JumpIfError(hr, error, "Invoke(SetResultColumnCount)");
  307. }
  308. else
  309. {
  310. hr = ((ICertView *) pdiView->pUnknown)->SetResultColumnCount(cResultColumn);
  311. _JumpIfError(hr, error, "SetResultColumnCount");
  312. }
  313. error:
  314. return(hr);
  315. }
  316. HRESULT
  317. View_SetResultColumn(
  318. IN DISPATCHINTERFACE *pdiView,
  319. IN LONG ColumnIndex)
  320. {
  321. HRESULT hr;
  322. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  323. if (NULL != pdiView->pDispatch)
  324. {
  325. VARIANT avar[1];
  326. avar[0].vt = VT_I4;
  327. avar[0].lVal = ColumnIndex;
  328. hr = DispatchInvoke(
  329. pdiView,
  330. VIEW_SETRESULTCOLUMN,
  331. ARRAYSIZE(avar),
  332. avar,
  333. 0,
  334. NULL);
  335. _JumpIfError(hr, error, "Invoke(SetResultColumn)");
  336. }
  337. else
  338. {
  339. hr = ((ICertView *) pdiView->pUnknown)->SetResultColumn(ColumnIndex);
  340. _JumpIfError(hr, error, "SetResultColumn");
  341. }
  342. error:
  343. return(hr);
  344. }
  345. HRESULT
  346. View_SetRestriction(
  347. IN DISPATCHINTERFACE *pdiView,
  348. IN LONG ColumnIndex,
  349. IN LONG SeekOperator,
  350. IN LONG SortOrder,
  351. IN VARIANT const *pvarValue)
  352. {
  353. HRESULT hr;
  354. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  355. if (NULL != pdiView->pDispatch)
  356. {
  357. VARIANT avar[4];
  358. avar[0].vt = VT_I4;
  359. avar[0].lVal = ColumnIndex;
  360. avar[1].vt = VT_I4;
  361. avar[1].lVal = SeekOperator;
  362. avar[2].vt = VT_I4;
  363. avar[2].lVal = SortOrder;
  364. avar[3] = *pvarValue;
  365. hr = DispatchInvoke(
  366. pdiView,
  367. VIEW_SETRESTRICTION,
  368. ARRAYSIZE(avar),
  369. avar,
  370. 0,
  371. NULL);
  372. _JumpIfError(hr, error, "Invoke(SetRestriction)");
  373. }
  374. else
  375. {
  376. hr = ((ICertView *) pdiView->pUnknown)->SetRestriction(
  377. ColumnIndex,
  378. SeekOperator,
  379. SortOrder,
  380. pvarValue);
  381. _JumpIfError(hr, error, "SetRestriction");
  382. }
  383. error:
  384. return(hr);
  385. }
  386. HRESULT
  387. View_OpenView(
  388. IN DISPATCHINTERFACE *pdiView,
  389. OUT DISPATCHINTERFACE *pdiViewRow)
  390. {
  391. HRESULT hr;
  392. IEnumCERTVIEWROW *pEnumRow = NULL;
  393. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  394. if (NULL != pdiView->pDispatch)
  395. {
  396. hr = DispatchInvoke(
  397. pdiView,
  398. VIEW_OPENVIEW,
  399. 0,
  400. NULL,
  401. VT_DISPATCH,
  402. &pEnumRow);
  403. _JumpIfError(hr, error, "Invoke(OpenView)");
  404. }
  405. else
  406. {
  407. hr = ((ICertView *) pdiView->pUnknown)->OpenView(&pEnumRow);
  408. _JumpIfError(hr, error, "OpenView");
  409. }
  410. hr = ViewRow_Init2(NULL != pdiView->pDispatch, pEnumRow, pdiViewRow);
  411. _JumpIfError(hr, error, "ViewRow_Init2");
  412. error:
  413. if (NULL != pEnumRow)
  414. {
  415. pEnumRow->Release();
  416. }
  417. return(hr);
  418. }
  419. HRESULT
  420. View2_SetTable(
  421. IN DISPATCHINTERFACE *pdiView,
  422. IN LONG Table)
  423. {
  424. HRESULT hr;
  425. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  426. hr = ViewVerifyVersion(pdiView, 2);
  427. _JumpIfError(hr, error, "ViewVerifyVersion");
  428. if (NULL != pdiView->pDispatch)
  429. {
  430. VARIANT avar[1];
  431. avar[0].vt = VT_I4;
  432. avar[0].lVal = Table;
  433. hr = DispatchInvoke(
  434. pdiView,
  435. VIEW2_SETTABLE,
  436. ARRAYSIZE(avar),
  437. avar,
  438. 0,
  439. NULL);
  440. _JumpIfError(hr, error, "Invoke(SetTable)");
  441. }
  442. else
  443. {
  444. hr = ((ICertView2 *) pdiView->pUnknown)->SetTable(Table);
  445. _JumpIfError(hr, error, "SetTable");
  446. }
  447. error:
  448. return(hr);
  449. }
  450. HRESULT
  451. View_EnumCertViewColumn(
  452. IN DISPATCHINTERFACE *pdiView,
  453. IN LONG fResultColumn,
  454. OUT DISPATCHINTERFACE *pdiViewColumn)
  455. {
  456. HRESULT hr;
  457. IEnumCERTVIEWCOLUMN *pEnumColumn = NULL;
  458. CSASSERT(NULL != pdiView && NULL != pdiView->pDispatchTable);
  459. if (NULL != pdiView->pDispatch)
  460. {
  461. VARIANT avar[1];
  462. avar[0].vt = VT_I4;
  463. avar[0].lVal = fResultColumn;
  464. hr = DispatchInvoke(
  465. pdiView,
  466. VIEW_ENUMCERTVIEWCOLUMN,
  467. ARRAYSIZE(avar),
  468. avar,
  469. VT_DISPATCH,
  470. &pEnumColumn);
  471. _JumpIfError(hr, error, "Invoke(EnumCertViewColumn)");
  472. }
  473. else
  474. {
  475. hr = ((ICertView *) pdiView->pUnknown)->EnumCertViewColumn(
  476. fResultColumn,
  477. &pEnumColumn);
  478. _JumpIfError(hr, error, "EnumCertViewColumn");
  479. }
  480. hr = ViewColumn_Init2(
  481. NULL != pdiView->pDispatch,
  482. pEnumColumn,
  483. pdiViewColumn);
  484. _JumpIfError(hr, error, "ViewColumn_Init2");
  485. error:
  486. if (NULL != pEnumColumn)
  487. {
  488. pEnumColumn->Release();
  489. }
  490. return(hr);
  491. }