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

Annotation of /trunk/Src/wptKeyserverSearchDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 328 - (hide annotations)
Fri Sep 25 16:07:38 2009 UTC (15 years, 5 months ago) by twoaday
File size: 5567 byte(s)


1 werner 36 /* wptKeyserverSearchDlg.cpp - Keyserver Searching
2 twoaday 293 * Copyright (C) 2001-2007 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     #ifdef HAVE_CONFIG_H
17     #include <config.h>
18     #endif
19    
20     #include <windows.h>
21     #include <stdio.h>
22    
23 werner 47 #include "resource.h"
24 werner 36 #include "wptCommonCtl.h"
25 twoaday 271 #include "wptGPG.h"
26 werner 36 #include "wptKeyserver.h"
27     #include "wptErrors.h"
28     #include "wptTypes.h"
29     #include "wptDlgs.h"
30     #include "wptNLS.h"
31 twoaday 214 #include "wptKeylist.h"
32 werner 36
33    
34 twoaday 262 /* Default threshold for key items. */
35 twoaday 219 #define MAX_N_KEYS 64
36    
37     /* Symbolic column IDs. */
38 twoaday 214 enum { KSS_COL_BITS = 0, KSS_COL_ALGO,
39     KSS_COL_KEYID, KSS_COL_DATE, KSS_COL_UID };
40 twoaday 185
41 twoaday 214 int hkp_recv_key2 (HWND dlg, const char *kserver, WORD port,
42     const char *pattern, int proto, char **r_fpr);
43 twoaday 147
44 twoaday 185 /* Initialize dialog. */
45     static listview_ctrl_t
46     on_init_dialog (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
47 werner 36 {
48     struct listview_column_s keysearch[] = {
49     {0, 48, (char *)_("Size")},
50 twoaday 214 {1, 48, (char*)_("Algorithm")},
51 twoaday 219 {2, 80, (char *)_("Key ID")},
52 twoaday 214 {3, 72, (char *)_("Creation")},
53     {4, 256, (char *)_("User ID")},
54 werner 36 {0, 0, NULL}
55     };
56 twoaday 328 keyserver_ctx *parm = (keyserver_ctx*)lparam;
57 twoaday 262 listview_ctrl_t lv = NULL;
58     char info[300];
59 twoaday 185 int i;
60 twoaday 262
61 twoaday 185 SetDlgItemText (dlg, IDC_HKPSEARCH_RECV, _("&Receive"));
62     SetDlgItemText (dlg, IDOK, _("&Cancel"));
63 twoaday 262 _snprintf (info, DIM (info) - 1,
64     _("Connect to '%s' to search for \"%s\""),
65 twoaday 328 parm->name, parm->pattern);
66 twoaday 185 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 twoaday 256 /* Begin the key serach and add all results to the list view @lv.
78     Return value: 0 on success. */
79 twoaday 185 static int
80     search_hkp_keys (HWND dlg, keyserver_ctx *ksc, listview_ctrl_t lv)
81     {
82 twoaday 214 keyserver_key_s *key;
83     const char *uid;
84 twoaday 219 char bits[32], algo[32], keyid[32];
85 twoaday 273 size_t nkeys=0;
86 twoaday 214 int conn_fd = 0;
87 twoaday 273 int rc;
88 twoaday 185
89 twoaday 214 rc = kserver_search_begin (ksc->name, ksc->port, ksc->pattern,
90     &conn_fd, &nkeys);
91 twoaday 185 if (rc) {
92     msg_box (dlg, winpt_strerror (rc), _("Keyserver Search"), MB_ERR);
93     return rc;
94     }
95    
96 twoaday 219 if (nkeys > MAX_N_KEYS) {
97     rc = log_box (_("Keyserver Search"), MB_INFO_ASK,
98     _("The search result contains a lot of keys: %d\n\n"
99     "Do you really want to continue?"), nkeys);
100     if (rc == IDNO) {
101     kserver_search_end (conn_fd);
102     return -1;
103     }
104     }
105    
106 twoaday 214 while (nkeys-- > 0) {
107     if (kserver_search_next (conn_fd, &key))
108     break;
109     if (!key)
110 twoaday 185 continue;
111 twoaday 219
112 twoaday 262 _snprintf (bits, DIM (bits) - 1, "%d", key->bits);
113     _snprintf (algo, DIM (algo)-1, "%s",
114 twoaday 214 get_key_pubalgo ((gpgme_pubkey_algo_t)key->algo));
115 twoaday 262 _snprintf (keyid, DIM (keyid)-1, "0x%s", key->keyid);
116 twoaday 328 uid = key->main_uid? key->main_uid->uid : _("No User ID found");
117 twoaday 185 listview_add_item (lv, " ");
118 twoaday 214 listview_add_sub_item (lv, 0, KSS_COL_BITS, bits);
119     listview_add_sub_item (lv, 0, KSS_COL_ALGO, algo);
120 twoaday 219 listview_add_sub_item (lv, 0, KSS_COL_KEYID, keyid);
121 twoaday 214 listview_add_sub_item (lv, 0, KSS_COL_DATE, get_key_created (key->creation));
122     listview_add_sub_item (lv, 0, KSS_COL_UID, uid);
123     kserver_release_key (key); key=NULL;
124 twoaday 185 }
125    
126     kserver_search_end (conn_fd);
127     return 0;
128     }
129    
130    
131 twoaday 197 /* Fetch all selected keys from the keyserver in @ksc. */
132     static void
133     fetch_keys (HWND dlg, listview_ctrl_t lv, keyserver_ctx *ksc)
134     {
135     char keyid[32];
136     char *fpr;
137 twoaday 328 int n, rc;
138 twoaday 197
139     n = listview_count_items (lv, 1);
140     if (!n) {
141     msg_box (dlg, _("Please select a key."), _("Keyserver Search"), MB_ERR);
142     return;
143     }
144    
145 twoaday 328 rc = 0;
146 twoaday 197 for (n=0; n < listview_count_items (lv, 0); n++) {
147     if (!listview_get_item_state (lv, n))
148     continue;
149    
150 twoaday 262 listview_get_item_text (lv, n, KSS_COL_KEYID, keyid, DIM (keyid)-1);
151 twoaday 197 rc = hkp_recv_key2 (dlg, ksc->name, ksc->port, keyid, 0, &fpr);
152 twoaday 293 if (!rc && fpr != NULL)
153 twoaday 197 keycache_update (0, fpr);
154 twoaday 293 free_if_alloc (fpr);
155 twoaday 197 }
156     }
157    
158    
159 twoaday 185 /* Dialog box procedure for keyserver searching. */
160     BOOL CALLBACK
161     hkpsearch_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
162     {
163     static listview_ctrl_t lv = NULL;
164     static keyserver_ctx *ksc;
165 werner 36
166 twoaday 147 switch (msg) {
167 werner 36 case WM_INITDIALOG:
168     ksc = (keyserver_ctx *)lparam;
169 twoaday 256 if (!ksc)
170     BUG (0);
171 twoaday 185 lv = on_init_dialog (dlg, msg, wparam, lparam);
172 twoaday 219 if (search_hkp_keys (dlg, ksc, lv)) {
173 werner 36 EndDialog (dlg, FALSE);
174 twoaday 262 return TRUE;
175 werner 36 }
176     return TRUE;
177    
178     case WM_DESTROY:
179     if (lv) {
180     listview_release (lv);
181     lv = NULL;
182     }
183     return FALSE;
184    
185     case WM_COMMAND:
186     switch (LOWORD (wparam)) {
187     case IDOK:
188     EndDialog (dlg, TRUE);
189     return TRUE;
190    
191     case IDCANCEL:
192     EndDialog (dlg, FALSE);
193 twoaday 256 return TRUE;
194 werner 36
195     case IDC_HKPSEARCH_RECV:
196 twoaday 197 fetch_keys (dlg, lv, ksc);
197 werner 36 return TRUE;
198     }
199     break;
200     }
201    
202     return FALSE;
203 twoaday 147 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26