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.

481 lines
16 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: crlrlist.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "global.hxx"
  11. #include <dbgdef.h>
  12. extern HINSTANCE HinstDll;
  13. extern HMODULE HmodRichEdit;
  14. static const HELPMAP helpmap[] = {
  15. {IDC_CRL_REVOCATIONLIST_REVOKED_CERTIFICATES, IDH_CRLVIEW_REVOCATIONLIST_REVOCATION_LIST},
  16. {IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST, IDH_CRLVIEW_REVOCATIONLIST_LIST_ENTRY},
  17. {IDC_CRL_REVOCATIONLIST_DETAIL_EDIT, IDH_CRLVIEW_REVOCATIONLIST_LIST_ENTRY_DETAIL}
  18. };
  19. //////////////////////////////////////////////////////////////////////////////////////
  20. //
  21. //////////////////////////////////////////////////////////////////////////////////////
  22. static void DisplayCRLEntryValues(HWND hWndListView, PCCRL_CONTEXT pcrl, int entryIndex)
  23. {
  24. LPWSTR pwszText;
  25. WCHAR szText[CRYPTUI_MAX_STRING_SIZE];
  26. LV_ITEMW lvI;
  27. DWORD index = 0;
  28. ShowWindow(hWndListView, SW_HIDE);
  29. //
  30. memset(&lvI, 0, sizeof(lvI));
  31. lvI.iItem = ListView_GetItemCount(hWndListView) - 1;
  32. lvI.mask = LVIF_PARAM;
  33. while (lvI.iItem >= 0)
  34. {
  35. if (ListView_GetItemU(hWndListView, &lvI))
  36. {
  37. FreeListDisplayHelper((PLIST_DISPLAY_HELPER) lvI.lParam);
  38. }
  39. lvI.iItem--;
  40. }
  41. ListView_DeleteAllItems(hWndListView);
  42. //
  43. // set up the fields in the list view item struct that don't change from item to item
  44. //
  45. memset(&lvI, 0, sizeof(lvI));
  46. lvI.mask = LVIF_TEXT | LVIF_STATE | LVIF_PARAM;
  47. lvI.state = 0;
  48. lvI.stateMask = 0;
  49. lvI.pszText = szText;
  50. lvI.iSubItem = 0;
  51. //
  52. // serial number
  53. //
  54. if (FormatSerialNoString(&pwszText, &(pcrl->pCrlInfo->rgCRLEntry[entryIndex].SerialNumber)))
  55. {
  56. LoadStringU(HinstDll, IDS_ADV_SER_NUM, szText, ARRAYSIZE(szText));
  57. lvI.iItem = index;
  58. lvI.cchTextMax = wcslen(szText);
  59. lvI.lParam = (LPARAM) MakeListDisplayHelper(TRUE, pwszText, NULL, 0);
  60. ListView_InsertItemU(hWndListView, &lvI);
  61. ListView_SetItemTextU(hWndListView, index, 1, pwszText);
  62. index++;
  63. }
  64. //
  65. // revocation date
  66. //
  67. if (FormatDateString(&pwszText, pcrl->pCrlInfo->rgCRLEntry[entryIndex].RevocationDate, TRUE, TRUE, hWndListView))
  68. {
  69. LoadStringU(HinstDll, IDS_REVOCATION_DATE, szText, ARRAYSIZE(szText));
  70. lvI.iItem = index;
  71. lvI.cchTextMax = wcslen(szText);
  72. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  73. ListView_InsertItemU(hWndListView, &lvI);
  74. ListView_SetItemTextU(hWndListView, index, 1, pwszText);
  75. index++;
  76. }
  77. //
  78. // add all the extensions
  79. //
  80. DisplayExtensions(
  81. hWndListView,
  82. pcrl->pCrlInfo->rgCRLEntry[entryIndex].cExtension,
  83. pcrl->pCrlInfo->rgCRLEntry[entryIndex].rgExtension,
  84. FALSE,
  85. &index);
  86. DisplayExtensions(
  87. hWndListView,
  88. pcrl->pCrlInfo->rgCRLEntry[entryIndex].cExtension,
  89. pcrl->pCrlInfo->rgCRLEntry[entryIndex].rgExtension,
  90. TRUE,
  91. &index);
  92. ShowWindow(hWndListView, SW_SHOW);
  93. }
  94. //////////////////////////////////////////////////////////////////////////////////////
  95. //
  96. //////////////////////////////////////////////////////////////////////////////////////
  97. static void AddCertificatesToList(HWND hWndListView, CRL_VIEW_HELPER *pviewhelp)
  98. {
  99. LPWSTR pwszText;
  100. LV_ITEMW lvI;
  101. DWORD i;
  102. PCCRL_CONTEXT pcrl;
  103. int index = 0;
  104. pcrl = pviewhelp->pcvcrl->pCRLContext;
  105. //
  106. // set up the fields in the list view item struct that don't change from item to item
  107. //
  108. lvI.mask = LVIF_TEXT | LVIF_STATE;
  109. lvI.state = 0;
  110. lvI.stateMask = 0;
  111. lvI.iSubItem = 0;
  112. //
  113. // loop for each cert
  114. //
  115. for (i=0; i<pcrl->pCrlInfo->cCRLEntry; i++)
  116. {
  117. if (FormatSerialNoString(&(lvI.pszText), &(pcrl->pCrlInfo->rgCRLEntry[i].SerialNumber)))
  118. {
  119. lvI.cchTextMax = wcslen(lvI.pszText);
  120. lvI.iItem = index++;
  121. ListView_InsertItemU(hWndListView, &lvI);
  122. free(lvI.pszText);
  123. lvI.pszText = NULL;
  124. FormatDateString(&pwszText, pcrl->pCrlInfo->rgCRLEntry[i].RevocationDate, TRUE, TRUE, hWndListView);
  125. ListView_SetItemTextU(hWndListView, index-1 , 1, pwszText);
  126. free(pwszText);
  127. }
  128. }
  129. }
  130. //////////////////////////////////////////////////////////////////////////////////////
  131. //
  132. //////////////////////////////////////////////////////////////////////////////////////
  133. INT_PTR APIENTRY ViewPageCRLRevocationList(HWND hwndDlg, UINT msg, WPARAM wParam,
  134. LPARAM lParam)
  135. {
  136. PROPSHEETPAGE *ps;
  137. PCCRL_CONTEXT pcrl;
  138. CRL_VIEW_HELPER *pviewhelp;
  139. HWND hWndListView;
  140. HWND hwnd;
  141. LV_COLUMNW lvC;
  142. WCHAR szText[CRYPTUI_MAX_STRING_SIZE];
  143. PCRL_INFO pCrlInfo;
  144. int listIndex;
  145. LVITEMW lvI;
  146. LPNMLISTVIEW pnmv;
  147. NMLISTVIEW nmv;
  148. switch ( msg ) {
  149. case WM_INITDIALOG:
  150. //
  151. // save the pviewhelp struct in DWLP_USER so it can always be accessed
  152. //
  153. ps = (PROPSHEETPAGE *) lParam;
  154. pviewhelp = (CRL_VIEW_HELPER *) (ps->lParam);
  155. pcrl = pviewhelp->pcvcrl->pCRLContext;
  156. SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR) pviewhelp);
  157. //
  158. // clear the text in the detail edit box
  159. //
  160. CryptUISetRicheditTextW(hwndDlg, IDC_CRL_REVOCATIONLIST_DETAIL_EDIT, L"");
  161. //
  162. // initialize the columns in the list view
  163. //
  164. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  165. lvC.fmt = LVCFMT_LEFT; // Left-align the column.
  166. lvC.pszText = szText; // The text for the column.
  167. // Add the columns. They are loaded from a string table.
  168. lvC.iSubItem = 0;
  169. lvC.cx = 200;
  170. LoadStringU(HinstDll, IDS_ADV_SER_NUM, szText, ARRAYSIZE(szText));
  171. if (ListView_InsertColumnU(GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOKED_CERTIFICATES), 0, &lvC) == -1)
  172. {
  173. // error
  174. }
  175. lvC.cx = 140;
  176. LoadStringU(HinstDll, IDS_REVOCATION_DATE, szText, ARRAYSIZE(szText));
  177. if (ListView_InsertColumnU(GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOKED_CERTIFICATES), 1, &lvC) == -1)
  178. {
  179. // error
  180. }
  181. // Add the columns. They are loaded from a string table.
  182. lvC.iSubItem = 0;
  183. lvC.cx = 121;
  184. LoadStringU(HinstDll, IDS_FIELD, szText, ARRAYSIZE(szText));
  185. if (ListView_InsertColumnU(GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST), 0, &lvC) == -1)
  186. {
  187. // error
  188. }
  189. lvC.cx = 200;
  190. LoadStringU(HinstDll, IDS_VALUE, szText, ARRAYSIZE(szText));
  191. if (ListView_InsertColumnU(GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST), 1, &lvC) == -1)
  192. {
  193. // error
  194. }
  195. //
  196. // add all the certificates to the certificate list box
  197. //
  198. AddCertificatesToList(GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOKED_CERTIFICATES), pviewhelp);
  199. //
  200. // set the styles in the list views so that they highlight an entire line and
  201. // so they alway show their selection
  202. //
  203. SendDlgItemMessageA(
  204. hwndDlg,
  205. IDC_CRL_REVOCATIONLIST_REVOKED_CERTIFICATES,
  206. LVM_SETEXTENDEDLISTVIEWSTYLE,
  207. 0,
  208. LVS_EX_FULLROWSELECT);
  209. SendDlgItemMessageA(
  210. hwndDlg,
  211. IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST,
  212. LVM_SETEXTENDEDLISTVIEWSTYLE,
  213. 0,
  214. LVS_EX_FULLROWSELECT);
  215. //
  216. // initialize the current selection
  217. //
  218. pviewhelp->currentSelection = -1;
  219. return TRUE;
  220. case WM_NOTIFY:
  221. pviewhelp = (CRL_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  222. pcrl = pviewhelp->pcvcrl->pCRLContext;
  223. pCrlInfo = pcrl->pCrlInfo;
  224. switch (((NMHDR FAR *) lParam)->code)
  225. {
  226. case PSN_SETACTIVE:
  227. break;
  228. case PSN_APPLY:
  229. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  230. break;
  231. case PSN_KILLACTIVE:
  232. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  233. return TRUE;
  234. case PSN_RESET:
  235. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  236. break;
  237. case PSN_QUERYCANCEL:
  238. pviewhelp->fCancelled = TRUE;
  239. return FALSE;
  240. case PSN_HELP:
  241. pviewhelp = (CRL_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  242. if (FIsWin95) {
  243. //WinHelpA(hwndDlg, (LPSTR) pviewhelp->pcvcrl->szHelpFileName,
  244. // HELP_CONTEXT, pviewhelp->pcvcrl->dwHelpId);
  245. }
  246. else {
  247. //WinHelpW(hwndDlg, pviewhelp->pcvcrl->szHelpFileName, HELP_CONTEXT,
  248. // pviewhelp->pcvcrl->dwHelpId);
  249. }
  250. return TRUE;
  251. case LVN_ITEMCHANGING:
  252. pnmv = (LPNMLISTVIEW) lParam;
  253. switch(((NMHDR FAR *) lParam)->idFrom)
  254. {
  255. case IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST:
  256. if (pnmv->uNewState & LVIS_SELECTED)
  257. {
  258. DisplayHelperTextInEdit(
  259. GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST),
  260. hwndDlg,
  261. IDC_CRL_REVOCATIONLIST_DETAIL_EDIT,
  262. pnmv->iItem);
  263. }
  264. break;
  265. case IDC_CRL_REVOCATIONLIST_REVOKED_CERTIFICATES:
  266. if (pnmv->uNewState & LVIS_SELECTED)
  267. {
  268. memcpy(&nmv, pnmv, sizeof(nmv));
  269. nmv.hdr.code = NM_CLICK;
  270. SendMessage(hwndDlg, WM_NOTIFY, 0, (LPARAM) &nmv);
  271. }
  272. break;
  273. }
  274. return TRUE;
  275. case NM_CLICK:
  276. pnmv = (LPNMLISTVIEW) lParam;
  277. switch (((NMHDR FAR *) lParam)->idFrom)
  278. {
  279. case IDC_CRL_REVOCATIONLIST_REVOKED_CERTIFICATES:
  280. hWndListView = GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOKED_CERTIFICATES);
  281. if ((pnmv->iItem == -1) || (pviewhelp->currentSelection == pnmv->iItem))
  282. {
  283. break;
  284. }
  285. //
  286. // clear the text in the detail edit box
  287. //
  288. CryptUISetRicheditTextW(hwndDlg, IDC_CRL_REVOCATIONLIST_DETAIL_EDIT, L"");
  289. DisplayCRLEntryValues(
  290. GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST),
  291. pcrl,
  292. pnmv->iItem);
  293. pviewhelp->currentSelection = pnmv->iItem;
  294. break;
  295. // do the fall through when the update code is written properly
  296. // FALL THROUGH!! - do this so everything gets updated
  297. // break;
  298. case IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST:
  299. DisplayHelperTextInEdit(
  300. GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST),
  301. hwndDlg,
  302. IDC_CRL_REVOCATIONLIST_DETAIL_EDIT,
  303. pnmv->iItem);
  304. break;
  305. }
  306. break;
  307. case NM_SETFOCUS:
  308. switch (((NMHDR FAR *) lParam)->idFrom)
  309. {
  310. case IDC_CRL_REVOCATIONLIST_REVOKED_CERTIFICATES:
  311. hWndListView = GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOKED_CERTIFICATES);
  312. if ((ListView_GetItemCount(hWndListView) != 0) &&
  313. (ListView_GetNextItem(hWndListView, -1, LVNI_SELECTED) == -1))
  314. {
  315. memset(&lvI, 0, sizeof(lvI));
  316. lvI.mask = LVIF_STATE;
  317. lvI.iItem = 0;
  318. lvI.state = LVIS_FOCUSED;
  319. lvI.stateMask = LVIS_FOCUSED;
  320. ListView_SetItem(hWndListView, &lvI);
  321. }
  322. break;
  323. case IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST:
  324. hWndListView = GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST);
  325. if ((ListView_GetItemCount(hWndListView) != 0) &&
  326. (ListView_GetNextItem(hWndListView, -1, LVNI_SELECTED) == -1))
  327. {
  328. memset(&lvI, 0, sizeof(lvI));
  329. lvI.mask = LVIF_STATE;
  330. lvI.iItem = 0;
  331. lvI.state = LVIS_SELECTED | LVIS_FOCUSED;
  332. lvI.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  333. ListView_SetItem(hWndListView, &lvI);
  334. }
  335. break;
  336. }
  337. break;
  338. }
  339. break;
  340. case WM_COMMAND:
  341. pviewhelp = (CRL_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  342. pcrl = pviewhelp->pcvcrl->pCRLContext;
  343. pCrlInfo = pcrl->pCrlInfo;
  344. switch (LOWORD(wParam))
  345. {
  346. case IDHELP:
  347. if (FIsWin95) {
  348. //WinHelpA(hwndDlg, (LPSTR) pviewhelp->pcvcrl->szHelpFileName,
  349. // HELP_CONTEXT, pviewhelp->pcvcrl->dwHelpId);
  350. }
  351. else {
  352. //WinHelpW(hwndDlg, pviewhelp->pcvcrl->szHelpFileName, HELP_CONTEXT,
  353. // pviewhelp->pcvcrl->dwHelpId);
  354. }
  355. return TRUE;
  356. }
  357. break;
  358. case WM_DESTROY:
  359. pviewhelp = (CRL_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  360. //
  361. // get all the items in the list view and free the lParam
  362. // associated with each of them (lParam is the helper sruct)
  363. //
  364. hWndListView = GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST);
  365. memset(&lvI, 0, sizeof(lvI));
  366. lvI.iItem = ListView_GetItemCount(hWndListView) - 1;
  367. lvI.mask = LVIF_PARAM;
  368. while (lvI.iItem >= 0)
  369. {
  370. if (ListView_GetItemU(hWndListView, &lvI))
  371. {
  372. FreeListDisplayHelper((PLIST_DISPLAY_HELPER) lvI.lParam);
  373. }
  374. lvI.iItem--;
  375. }
  376. break;
  377. case WM_HELP:
  378. case WM_CONTEXTMENU:
  379. if (msg == WM_HELP)
  380. {
  381. hwnd = GetDlgItem(hwndDlg, ((LPHELPINFO)lParam)->iCtrlId);
  382. }
  383. else
  384. {
  385. hwnd = (HWND) wParam;
  386. }
  387. if ((hwnd != GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOKED_CERTIFICATES)) &&
  388. (hwnd != GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_REVOCATIONENTRY_LIST)) &&
  389. (hwnd != GetDlgItem(hwndDlg, IDC_CRL_REVOCATIONLIST_DETAIL_EDIT)))
  390. {
  391. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  392. return TRUE;
  393. }
  394. else
  395. {
  396. return OnContextHelp(hwndDlg, msg, wParam, lParam, helpmap);
  397. }
  398. }
  399. return FALSE;
  400. }