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

Contents of /trunk/Src/wptKeyserverSearchDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 208 - (show annotations)
Mon May 1 12:22:18 2006 UTC (18 years, 10 months ago) by twoaday
File size: 5044 byte(s)
See ChangeLog.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26