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

Annotation of /trunk/Src/wptKeyserverSearchDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 214 - (hide annotations)
Sun May 14 18:40:36 2006 UTC (18 years, 9 months ago) by twoaday
File size: 5488 byte(s)
2006-05-14  Timo Schulz  <ts@g10code.de>
                                                                                
        * wptKeyCache.cpp (gpg_keycache_update_attr): Parse
        preferred keyserver URL.
        * wptHTTP.cpp (extractHostInfo): Fix segv.
        * wptGPGUtil.cpp (gpg_find_key_subpacket): Ignore default
        gpg.conf.
        * wptKeyserverSearchDlg.cpp (search_hkp_keys): Do not
        assume an existing user id.
        * wptPassphraseCB.cpp (passphrase_cb): Automatic cancel
        if no passphrase is available.

(for complete list of changes, see Src/ChangeLog)

About to release 0.12.1


1 werner 36 /* wptKeyserverSearchDlg.cpp - Keyserver Searching
2 twoaday 147 * Copyright (C) 2001-2006 Timo Schulz
3 werner 36 *
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     #ifdef HAVE_CONFIG_H
21     #include <config.h>
22     #endif
23    
24     #include <windows.h>
25     #include <stdio.h>
26    
27 werner 47 #include "resource.h"
28 werner 36 #include "wptCommonCtl.h"
29     #include "wptKeyserver.h"
30     #include "wptErrors.h"
31     #include "wptTypes.h"
32     #include "wptGPG.h"
33     #include "wptContext.h" /* for passphrase_s */
34     #include "wptDlgs.h"
35     #include "wptNLS.h"
36 twoaday 214 #include "wptKeylist.h"
37 werner 36
38    
39 twoaday 214 enum { KSS_COL_BITS = 0, KSS_COL_ALGO,
40     KSS_COL_KEYID, KSS_COL_DATE, KSS_COL_UID };
41 twoaday 185
42 twoaday 214 int hkp_recv_key2 (HWND dlg, const char *kserver, WORD port,
43     const char *pattern, int proto, char **r_fpr);
44 twoaday 147
45 twoaday 185 /* Initialize dialog. */
46     static listview_ctrl_t
47     on_init_dialog (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
48 werner 36 {
49     struct listview_column_s keysearch[] = {
50     {0, 48, (char *)_("Size")},
51 twoaday 214 {1, 48, (char*)_("Algorithm")},
52     {2, 64, (char *)_("Key ID")},
53     {3, 72, (char *)_("Creation")},
54     {4, 256, (char *)_("User ID")},
55 werner 36 {0, 0, NULL}
56     };
57 twoaday 185 char info[384];
58     int i;
59     listview_ctrl_t lv = NULL;
60    
61     SetDlgItemText (dlg, IDC_HKPSEARCH_RECV, _("&Receive"));
62     SetDlgItemText (dlg, IDOK, _("&Cancel"));
63     _snprintf (info, sizeof (info) - 1,
64     _("Connect to '%s' to search for \"%s\""),
65     ((keyserver_ctx *)lparam)->name, ((keyserver_ctx *)lparam)->pattern);
66     SetDlgItemText (dlg, IDC_HKPSEARCH_INFO, info);
67     SetWindowText (dlg, _("Keyserver Searching"));
68     SetForegroundWindow (dlg);
69 twoaday 208 listview_new (&lv, GetDlgItem (dlg, IDC_HKPSEARCH_LIST));
70 twoaday 185 for (i = 0; keysearch[i].width; i++)
71     listview_add_column (lv, &keysearch[i]);
72     listview_set_ext_style (lv);
73     return lv;
74     }
75    
76    
77    
78     static int
79     search_hkp_keys (HWND dlg, keyserver_ctx *ksc, listview_ctrl_t lv)
80     {
81 twoaday 214 keyserver_key_s *key;
82     const char *uid;
83     char bits[32], algo[32];
84     int conn_fd = 0;
85     int rc, nkeys = 0;
86 twoaday 185
87 twoaday 214 rc = kserver_search_begin (ksc->name, ksc->port, ksc->pattern,
88     &conn_fd, &nkeys);
89 twoaday 185 if (rc) {
90     msg_box (dlg, winpt_strerror (rc), _("Keyserver Search"), MB_ERR);
91     return rc;
92     }
93    
94 twoaday 214 while (nkeys-- > 0) {
95     if (kserver_search_next (conn_fd, &key))
96     break;
97     if (!key)
98 twoaday 185 continue;
99 twoaday 214 _snprintf (bits, sizeof (bits) - 1, "%d", key->bits);
100     _snprintf (algo, sizeof (algo)-1, "%s",
101     get_key_pubalgo ((gpgme_pubkey_algo_t)key->algo));
102     uid = key->main_uid? key->main_uid->uid : "";
103 twoaday 185 listview_add_item (lv, " ");
104 twoaday 214 listview_add_sub_item (lv, 0, KSS_COL_BITS, bits);
105     listview_add_sub_item (lv, 0, KSS_COL_ALGO, algo);
106     listview_add_sub_item (lv, 0, KSS_COL_KEYID, key->keyid);
107     listview_add_sub_item (lv, 0, KSS_COL_DATE, get_key_created (key->creation));
108     listview_add_sub_item (lv, 0, KSS_COL_UID, uid);
109     kserver_release_key (key); key=NULL;
110 twoaday 185 }
111    
112     kserver_search_end (conn_fd);
113     return 0;
114     }
115    
116    
117 twoaday 197 /* Fetch all selected keys from the keyserver in @ksc. */
118     static void
119     fetch_keys (HWND dlg, listview_ctrl_t lv, keyserver_ctx *ksc)
120     {
121     char keyid[32];
122     char *fpr;
123     int n, rc = 0;
124    
125     n = listview_count_items (lv, 1);
126     if (!n) {
127     msg_box (dlg, _("Please select a key."), _("Keyserver Search"), MB_ERR);
128     return;
129     }
130    
131     for (n=0; n < listview_count_items (lv, 0); n++) {
132     if (!listview_get_item_state (lv, n))
133     continue;
134    
135     listview_get_item_text (lv, n, KSS_COL_KEYID, keyid, sizeof (keyid)-1);
136     rc = hkp_recv_key2 (dlg, ksc->name, ksc->port, keyid, 0, &fpr);
137     if (!rc && fpr != NULL) {
138     keycache_update (0, fpr);
139     free_if_alloc (fpr);
140     }
141     }
142     }
143    
144    
145 twoaday 185 /* Dialog box procedure for keyserver searching. */
146     BOOL CALLBACK
147     hkpsearch_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
148     {
149     static listview_ctrl_t lv = NULL;
150     static keyserver_ctx *ksc;
151 twoaday 197 int rc = 0;
152 werner 36
153 twoaday 147 switch (msg) {
154 werner 36 case WM_INITDIALOG:
155     ksc = (keyserver_ctx *)lparam;
156     if (!ksc)
157     dlg_fatal_error (dlg, "Could not get dialog param.");
158 twoaday 185 lv = on_init_dialog (dlg, msg, wparam, lparam);
159     rc = search_hkp_keys (dlg, ksc, lv);
160 werner 36 if (rc) {
161     EndDialog (dlg, FALSE);
162     return FALSE;
163     }
164     return TRUE;
165    
166     case WM_DESTROY:
167     if (lv) {
168     listview_release (lv);
169     lv = NULL;
170     }
171     return FALSE;
172    
173     case WM_SYSCOMMAND:
174     if (LOWORD (wparam) == SC_CLOSE)
175     EndDialog (dlg, TRUE);
176     return FALSE;
177    
178     case WM_COMMAND:
179     switch (LOWORD (wparam)) {
180     case IDOK:
181     EndDialog (dlg, TRUE);
182     return TRUE;
183    
184     case IDCANCEL:
185     EndDialog (dlg, FALSE);
186     return FALSE;
187    
188     case IDC_HKPSEARCH_RECV:
189 twoaday 197 fetch_keys (dlg, lv, ksc);
190 werner 36 return TRUE;
191     }
192     break;
193     }
194    
195     return FALSE;
196 twoaday 147 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26