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

Annotation of /trunk/Src/wptKeyRevokersDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 129 - (hide annotations)
Fri Dec 30 13:56:10 2005 UTC (19 years, 2 months ago) by twoaday
File size: 5304 byte(s)
2005-12-27  Timo Schulz  <ts@g10code.com>
                                                                                
        * wptListView.cpp (listview_set_view): New.
        (listview_del_column): New.
        * wptW32API.cpp (get_locale_date): New.
        (get_menu_state): New.
        (force_foreground_window): New.
        * wptVerifyList.cpp (strtimestamp): Support for
        locale date formats.
        * wptGPGUtil.cpp (gpg_revoke_cert): Handle bad
        passphrases.
        * wptKeyEditCB.cpp (editkey_command_handler): Immediately
        return when a bad passphrase was submitted.
        * wptKeyRevokersDlg.cpp (keyrevokers_dlg_proc): Change
        column order.
        * wptKeylist.cpp (keylist_upd_col): New.
        * wptKeyManagerDlg.cpp (update_ui_items): Deactivate
        'Revocation' for public keys.
        (translate_menu_strings): s/Revoke/Revoke Cert.
        (modify_listview_columns): New.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26