/[winpt]/trunk/Src/wptKeyRevokersDlg.cpp
ViewVC logotype

Annotation of /trunk/Src/wptKeyRevokersDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 4942 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


1 twoaday 2 /* wptKeyRevokersDlg.cpp - Designated Revoker Keys
2     * Copyright (C) 2002, 2003, 2005 Timo Schulz
3     *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20    
21     #include <windows.h>
22     #include <commctrl.h>
23    
24     #include "../resource.h"
25     #include "wptCommonCtl.h"
26     #include "wptNLS.h"
27     #include "wptTypes.h"
28     #include "wptGPG.h"
29     #include "wptCommonCtl.h"
30     #include "wptContext.h"
31     #include "wptDlgs.h"
32     #include "wptErrors.h"
33     #include "wptKeyserver.h"
34 twoaday 20 #include "wptW32Api.h"
35     #include "wptVersion.h"
36 twoaday 23 #include "wptKeyEdit.h"
37     #include "wptKeyList.h"
38 twoaday 2
39    
40 twoaday 23 /* Initialize the listview given in @ctrl and return it in @r_lv. */
41 twoaday 2 static int
42 twoaday 20 revokelist_build (listview_ctrl_t *r_lv, HWND ctrl)
43 twoaday 2 {
44     listview_ctrl_t lv;
45     struct listview_column_s rlist[] = {
46     { 0, 55, (char *)_("Algorithm") },
47     { 1, 80, (char *)_("Key ID") },
48     { 2, 160, (char *)_("Name") },
49     {0}
50     };
51     int i, rc;
52    
53 twoaday 23 rc = listview_new (&lv);
54     if (rc)
55 twoaday 2 return rc;
56     lv->ctrl = ctrl;
57     lv->items = DIM( rlist )-1;
58 twoaday 23 for (i = 0; i < lv->items; i++)
59     listview_add_column (lv, &rlist[i]);
60     listview_set_ext_style (lv);
61 twoaday 2 *r_lv = lv;
62     return 0;
63 twoaday 23 }
64 twoaday 2
65    
66 twoaday 23 /* Initialize the listview @ctrl with all designated revokers of the
67     key @key. @ctx is used to retrieve the rev key from the cache to
68     show the user-id.
69     Return value: the initialized listview or NULL on error. */
70 twoaday 2 static listview_ctrl_t
71     revokelist_init (HWND ctrl, gpgme_key_t key, gpgme_keycache_t ctx)
72     {
73 twoaday 23 gpgme_error_t err;
74     gpgme_key_t revkey;
75     GpgKeyEdit *ke;
76     gpg_desig_rev_t rev=NULL, r;
77     listview_ctrl_t lv;
78     const char *id;
79 twoaday 2
80 twoaday 23 ke = new GpgKeyEdit (key);
81     if (!ke)
82     BUG (NULL);
83     err = ke->getDesignatedRevoker (&rev);
84     if (err) {
85     delete ke;
86     msg_box (NULL, gpgme_strerror (err), _("Designated Key Revokers"), MB_ERR);
87     return NULL;
88     }
89     delete rev;
90    
91 twoaday 2 if (revokelist_build (&lv, ctrl))
92     BUG (0);
93 twoaday 23 for (r = rev; r; r = r->next) {
94     if (get_pubkey (r->fpr+32, &revkey))
95     id = _("user ID not found");
96 twoaday 2 else
97 twoaday 23 id = revkey->uids->name;
98 twoaday 2 listview_add_item (lv, "");
99 twoaday 23 listview_add_sub_item (lv, 0, 0, get_key_pubalgo (r->pubkey_algo));
100     listview_add_sub_item (lv, 0, 1, r->fpr+32);
101 twoaday 2 listview_add_sub_item (lv, 0, 2, id);
102     }
103 twoaday 23
104     gpg_desig_rev_release (rev);
105 twoaday 2 return lv;
106 twoaday 23 }
107 twoaday 2
108    
109 twoaday 23 /* Dialog box procedure to show designated revokers. */
110 twoaday 2 BOOL CALLBACK
111 twoaday 20 key_revokers_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
112 twoaday 2 {
113     static listview_ctrl_t lv;
114     gpgme_key_t key;
115     char buf[128], keyid[32];
116     int rc;
117    
118     switch( msg ) {
119     case WM_INITDIALOG:
120     gpgme_keycache_t ctx;
121     key = (gpgme_key_t)lparam;
122     if( !key )
123     dlg_fatal_error( dlg, "Could not get dilaog param" );
124 twoaday 23 ctx = keycache_get_ctx (1);
125 twoaday 2 if( !ctx )
126     BUG( dlg );
127     lv = revokelist_init( GetDlgItem( dlg, IDC_KEYREVOKERS_LIST ), key, ctx );
128     return TRUE;
129    
130     case WM_NOTIFY:
131     NMHDR *notify;
132     notify = (NMHDR *)lparam;
133 twoaday 20 if (notify && notify->code == NM_DBLCLK && notify->idFrom == IDC_KEYREVOKERS_LIST) {
134     int idx = listview_get_curr_pos (lv);
135     listview_get_item_text (lv, idx, 1, keyid, DIM (keyid)-1);
136     listview_get_item_text (lv, idx, 2, buf, DIM (buf)-1);
137 twoaday 23 if (!strcmp( buf, _("user ID not found"))) {
138 twoaday 20 int id = log_box (_("Designated Key Revokers"), MB_YESNO|MB_INFO,
139     _("Do you want to retrieve 0x%s via the default keyserver?"), keyid);
140     if (id == IDNO)
141 twoaday 2 break;
142 twoaday 20 rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, buf, 0, 0);
143 twoaday 2 if( !rc ) {
144     const char * s;
145 twoaday 20 keycache_reload (dlg);
146     if (get_pubkey (keyid, &key))
147 twoaday 2 BUG( NULL );
148 twoaday 23 s = key->uids->name;
149     if (s)
150     listview_add_sub_item (lv, idx, 2, s);
151 twoaday 2 }
152     }
153 twoaday 20 else {
154     struct winpt_key_s k;
155     memset (&k, 0, sizeof k);
156     k.keyid = keyid;
157     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,
158     keyprops_dlg_proc, (LPARAM)&k);
159     }
160 twoaday 2 }
161     break;
162    
163     case WM_DESTROY:
164 twoaday 23 if (lv) {
165     listview_release (lv);
166 twoaday 2 lv = NULL;
167     }
168     return FALSE;
169    
170     case WM_COMMAND:
171 twoaday 23 switch (LOWORD (wparam)) {
172 twoaday 2 case IDOK:
173 twoaday 23 EndDialog (dlg, TRUE);
174 twoaday 2 break;
175     }
176     break;
177     }
178    
179     return FALSE;
180 twoaday 23 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26