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

Annotation of /trunk/Src/wptKeyRevokersDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File size: 4419 byte(s)
WinPT initial checkin.


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    
35    
36     static int
37     revokelist_build( listview_ctrl_t *r_lv, HWND ctrl )
38     {
39     listview_ctrl_t lv;
40     struct listview_column_s rlist[] = {
41     { 0, 55, (char *)_("Algorithm") },
42     { 1, 80, (char *)_("Key ID") },
43     { 2, 160, (char *)_("Name") },
44     {0}
45     };
46     int i, rc;
47    
48     rc = listview_new( &lv );
49     if( rc )
50     return rc;
51     lv->ctrl = ctrl;
52     lv->items = DIM( rlist )-1;
53     for( i = 0; i < lv->items; i++ )
54     listview_add_column( lv, &rlist[i] );
55     listview_set_ext_style( lv );
56     *r_lv = lv;
57     return 0;
58     } /* revokelist_build */
59    
60    
61     static listview_ctrl_t
62     revokelist_init (HWND ctrl, gpgme_key_t key, gpgme_keycache_t ctx)
63     {
64     const char *keyid, *alg, *id;
65     int i, nkeys;
66     gpgme_key_t revkey;
67     listview_ctrl_t lv;
68    
69     if (revokelist_build (&lv, ctrl))
70     BUG (0);
71    
72     nkeys = gpgme_key_count_items (key, GPGME_ATTR_REVKEY_FPR);
73     for (i = 0; i < nkeys; i++) {
74     int algo = gpgme_key_get_ulong_attr (key, GPGME_ATTR_REVKEY_ALGO, NULL, i);
75     alg = gpgme_key_expand_attr (GPGME_ATTR_ALGO, algo);
76     keyid = gpgme_key_get_string_attr (key, GPGME_ATTR_REVKEY_FPR, NULL, i);
77     if (!keyid)
78     continue;
79     keyid += 32;
80     if (get_pubkey (keyid, &revkey))
81     id = _("User ID was not found");
82     else
83     id = gpgme_key_get_string_attr (revkey, GPGME_ATTR_NAME, NULL, 0);
84     listview_add_item (lv, "");
85     listview_add_sub_item (lv, 0, 0, alg);
86     listview_add_sub_item (lv, 0, 1, keyid);
87     listview_add_sub_item (lv, 0, 2, id);
88     }
89     return lv;
90     } /* revokelist_init */
91    
92    
93     BOOL CALLBACK
94     key_revokers_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
95     {
96     static listview_ctrl_t lv;
97     gpgme_key_t key;
98     char buf[128], keyid[32];
99     int rc;
100    
101     switch( msg ) {
102     case WM_INITDIALOG:
103     gpgme_keycache_t ctx;
104     key = (gpgme_key_t)lparam;
105     if( !key )
106     dlg_fatal_error( dlg, "Could not get dilaog param" );
107     ctx = keycache_get_ctx( 1 );
108     if( !ctx )
109     BUG( dlg );
110     lv = revokelist_init( GetDlgItem( dlg, IDC_KEYREVOKERS_LIST ), key, ctx );
111     return TRUE;
112    
113     case WM_NOTIFY:
114     NMHDR *notify;
115     notify = (NMHDR *)lparam;
116     if( notify && notify->code == NM_DBLCLK && notify->idFrom == IDC_KEYREVOKERS_LIST ) {
117     int idx = listview_get_curr_pos( lv );
118     listview_get_item_text( lv, idx, 1, keyid, sizeof keyid-1 );
119     listview_get_item_text( lv, idx, 2, buf, sizeof buf-1 );
120     if( !strcmp( buf, _("User ID was not found") ) ) {
121     int id = log_box( _("Designated Key Revokers"), MB_YESNO|MB_INFO,
122     _("Do you want to retrieve 0x%s via the default keyserver?"), keyid );
123     if( id == IDNO )
124     break;
125     rc = hkp_recv_key( dlg, default_keyserver, default_keyserver_port, buf, 0, 0 );
126     if( !rc ) {
127     const char * s;
128     keycache_reload( dlg );
129     if( get_pubkey( keyid, &key ) )
130     BUG( NULL );
131     s = gpgme_key_get_string_attr( key, GPGME_ATTR_NAME, NULL, 0 );
132     if( s )
133     listview_add_sub_item( lv, idx, 2, s );
134     }
135     }
136     }
137     break;
138    
139     case WM_DESTROY:
140     if( lv ) {
141     listview_release( lv );
142     lv = NULL;
143     }
144     return FALSE;
145    
146     case WM_COMMAND:
147     switch( LOWORD( wparam ) ) {
148     case IDOK:
149     EndDialog( dlg, TRUE );
150     break;
151     }
152     break;
153     }
154    
155     return FALSE;
156     } /* key_revokers_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26