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

Annotation of /trunk/Src/wptKeyserverSearchDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 273 - (hide annotations)
Fri Dec 8 10:22:17 2006 UTC (18 years, 2 months ago) by twoaday
File size: 5751 byte(s)


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26