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

Annotation of /trunk/Src/wptKeyserverSearchDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 197 - (hide annotations)
Mon Apr 10 07:38:06 2006 UTC (18 years, 10 months ago) by twoaday
File size: 5059 byte(s)
2006-04-09  Timo Schulz  <ts@g10code.de>
 
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): Only return true
        if the homedir value was changed.
        * wptGPG.cpp (default_key_from_cache): Only return secret key
        if public part is available.
        (set_gnupg_default_key): Fix NULL problem.
        * wptKeyEditDlgs.cpp (do_editkey_clean): Set update flag.
        * wptFileCBS.cpp (write_cb, read_cb): Better error handling.
        * wptFileManagerDlg.cpp (file_manager_dlg_proc): Handle
        'always-on-top' correctly.
        * wptKeylist.cpp (keylist_get_recipients): Allocate enough
        mem to hold all possible keys.
        (keylist_enum_keys): Likewise.


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    
37    
38 twoaday 185 enum { KSS_COL_BITS = 0, KSS_COL_KEYID, KSS_COL_DATE, KSS_COL_UID };
39    
40 twoaday 147 int
41     hkp_recv_key2 (HWND dlg, const char *kserver, WORD port,
42     const char *pattern, int proto, char **r_fpr);
43    
44    
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     {1, 64, (char *)_("Key ID")},
52     {2, 72, (char *)_("Creation")},
53     {3, 256, (char *)_("User ID")},
54     {0, 0, NULL}
55     };
56 twoaday 185 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);
69     lv->ctrl = GetDlgItem (dlg, IDC_HKPSEARCH_LIST);
70     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     int rc;
82 werner 36 int conn_fd = 0;
83 twoaday 185 char t[32];
84     keyserver_key key;
85    
86     rc = kserver_search_begin (ksc->name, ksc->port, ksc->pattern, &conn_fd);
87     if (rc) {
88     msg_box (dlg, winpt_strerror (rc), _("Keyserver Search"), MB_ERR);
89     return rc;
90     }
91    
92     while (!kserver_search_next (conn_fd, &key)) {
93     if (!key.bits)
94     continue;
95     _snprintf (t, sizeof (t) - 1, "%d", key.bits);
96     listview_add_item (lv, " ");
97     listview_add_sub_item (lv, 0, KSS_COL_BITS, t);
98     listview_add_sub_item (lv, 0, KSS_COL_KEYID, key.keyid);
99     listview_add_sub_item (lv, 0, KSS_COL_DATE, key.date);
100     listview_add_sub_item (lv, 0, KSS_COL_UID, key.uid);
101     }
102    
103     kserver_search_end (conn_fd);
104     return 0;
105     }
106    
107    
108 twoaday 197 /* Fetch all selected keys from the keyserver in @ksc. */
109     static void
110     fetch_keys (HWND dlg, listview_ctrl_t lv, keyserver_ctx *ksc)
111     {
112     char keyid[32];
113     char *fpr;
114     int n, rc = 0;
115    
116     n = listview_count_items (lv, 1);
117     if (!n) {
118     msg_box (dlg, _("Please select a key."), _("Keyserver Search"), MB_ERR);
119     return;
120     }
121    
122     for (n=0; n < listview_count_items (lv, 0); n++) {
123     if (!listview_get_item_state (lv, n))
124     continue;
125    
126     listview_get_item_text (lv, n, KSS_COL_KEYID, keyid, sizeof (keyid)-1);
127     rc = hkp_recv_key2 (dlg, ksc->name, ksc->port, keyid, 0, &fpr);
128     if (!rc && fpr != NULL) {
129     keycache_update (0, fpr);
130     free_if_alloc (fpr);
131     }
132     }
133     }
134    
135    
136 twoaday 185 /* Dialog box procedure for keyserver searching. */
137     BOOL CALLBACK
138     hkpsearch_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
139     {
140     static listview_ctrl_t lv = NULL;
141     static keyserver_ctx *ksc;
142 twoaday 197 int rc = 0;
143 werner 36
144 twoaday 147 switch (msg) {
145 werner 36 case WM_INITDIALOG:
146     ksc = (keyserver_ctx *)lparam;
147     if (!ksc)
148     dlg_fatal_error (dlg, "Could not get dialog param.");
149 twoaday 185 lv = on_init_dialog (dlg, msg, wparam, lparam);
150     rc = search_hkp_keys (dlg, ksc, lv);
151 werner 36 if (rc) {
152     EndDialog (dlg, FALSE);
153     return FALSE;
154     }
155     return TRUE;
156    
157     case WM_DESTROY:
158     if (lv) {
159     listview_release (lv);
160     lv = NULL;
161     }
162     return FALSE;
163    
164     case WM_SYSCOMMAND:
165     if (LOWORD (wparam) == SC_CLOSE)
166     EndDialog (dlg, TRUE);
167     return FALSE;
168    
169     case WM_COMMAND:
170     switch (LOWORD (wparam)) {
171     case IDOK:
172     EndDialog (dlg, TRUE);
173     return TRUE;
174    
175     case IDCANCEL:
176     EndDialog (dlg, FALSE);
177     return FALSE;
178    
179     case IDC_HKPSEARCH_RECV:
180 twoaday 197 fetch_keys (dlg, lv, ksc);
181 werner 36 return TRUE;
182     }
183     break;
184     }
185    
186     return FALSE;
187 twoaday 147 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26