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

Diff of /trunk/Src/wptKeyserverDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 25 by twoaday, Wed Oct 12 10:04:26 2005 UTC revision 109 by twoaday, Fri Dec 2 07:32:13 2005 UTC
# Line 1  Line 1 
1  /* wptKeyserverDlg.cpp - Keyserver dialog  /* wptKeyserverDlg.cpp - Keyserver dialog
2   *      Copyright (C) 2000-2005 Timo Schulz   *      Copyright (C) 2000-2005 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
6   * WinPT is free software; you can redistribute it and/or modify   * 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   * 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   * the Free Software Foundation; either version 2 of the License, or
9   * (at your option) any later version.   * (at your option) any later version.
10   *   *
11   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.   * GNU General Public License for more details.
15   *   *
16   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
20    #ifdef HAVE_CONFIG_H
21  #include <windows.h>  #include <config.h>
22  #include <commctrl.h>  #endif
23  #include <malloc.h>  
24    #include <windows.h>
25  #include "../resource.h"  #include <commctrl.h>
26  #include "wptKeyserver.h"  #include <malloc.h>
27  #include "wptErrors.h"  
28  #include "wptTypes.h"  #include "resource.h"
29  #include "wptCommonCtl.h"  #include "wptKeyserver.h"
30  #include "wptNLS.h"  #include "wptErrors.h"
31  #include "wptW32API.h"  #include "wptTypes.h"
32  #include "wptVersion.h"  #include "wptCommonCtl.h"
33  #include "wptGPG.h"  #include "wptNLS.h"
34  #include "wptKeyManager.h"  #include "wptW32API.h"
35  #include "wptContext.h" /* for passphrase_s */  #include "wptVersion.h"
36  #include "wptDlgs.h"  #include "wptGPG.h"
37    #include "wptKeyManager.h"
38    #include "wptContext.h" /* for passphrase_s */
39  #define MAX_KEYSIZE 70000  #include "wptDlgs.h"
40    
41  char * get_reg_entry_keyserver (const char *);  
42  int set_reg_entry_keyserver (const char *, const char *);  #define MAX_KEYSIZE 70000
43    
44    char* get_reg_entry_keyserver (const char *);
45  static void  int set_reg_entry_keyserver (const char *, const char *);
46  hkp_err_box (HWND dlg, const char * host, u16 port, int rc)  
47  {  
48      const char *err = kserver_strerror();  /* Print out keyserver error and a possible Winsock error. */
49    static void
50      log_box( _("Keyserver"), MB_ERR, "%s:%d: %s", host, port, winpt_strerror (rc));  hkp_err_box (HWND dlg, const char *host, WORD port, int rc)
51      if (err)  {
52          msg_box (dlg, err, wsock_strerror (), MB_ERR);      const char *err = kserver_strerror ();
53  } /* hkp_err_box */  
54        log_box (_("Keyserver"), MB_ERR, "%s:%d: %s",
55                 host, port, winpt_strerror (rc));
56  int      if (err)
57  hkp_send_key (HWND dlg, const char *kserver, u16 port, const char *pattern)          msg_box (dlg, err, wsock_strerror (), MB_ERR);
58  {  }
59      gpgme_ctx_t c;  
60      gpgme_data_t keydata;  
61      gpgme_error_t ec;  /* Send the extracted key with keyid @pattern to the
62      char *rawkey = NULL, msg[1024];     keyserver @kserver (port @port).
63      size_t n;     Return value: 0 on success. */
64      int rc;  int
65        hkp_send_key (HWND dlg, const char *kserver, WORD port, const char *pattern)
66      ec = gpgme_new( &c );  {
67      if( ec )      gpgme_ctx_t ctx;
68          BUG( NULL );      gpgme_data_t keydata;
69      gpgme_set_armor (c, 1);      gpgme_error_t ec;
70      ec = gpgme_data_new( &keydata );      char *rawkey = NULL;
71      if( ec )      char msg[384];
72          BUG( NULL );      size_t n;
73      rc = (int) gpgme_op_export( c, pattern, 0, keydata );      
74      if( rc ) {      ec = gpgme_new (&ctx);
75          msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Export"), MB_ERR );      if (ec)
76          goto leave;          BUG (NULL);
77      }      gpgme_set_armor (ctx, 1);
78      rawkey = gpgme_data_release_and_get_mem (keydata, &n);      ec = gpgme_data_new (&keydata);
79      rc = kserver_sendkey (kserver, port, rawkey, n);      if (ec)
80      if (rc) {          BUG (NULL);
81          hkp_err_box (dlg, kserver, port, rc);      ec = gpgme_op_export (ctx, pattern, 0, keydata);
82          goto leave;      if (ec) {
83      }          msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR);
84                goto leave;
85      _snprintf (msg, sizeof (msg) -1, _("Key '%s' successfully sent"), pattern);      }
86      status_box (dlg, msg, _("GnuPG status"));      rawkey = gpgme_data_release_and_get_mem (keydata, &n);
87            ec = kserver_sendkey (kserver, port, rawkey, n);
88  leave:      if (ec) {
89      gpgme_release (c);          hkp_err_box (dlg, kserver, port, ec);
90      safe_free (rawkey);          goto leave;
91      return rc;      }
92  } /* hkp_send_key */      
93        _snprintf (msg, sizeof (msg) -1, _("Key '%s' successfully sent"), pattern);
94        status_box (dlg, msg, _("GnuPG status"));
95  int      
96  hkp_recv_key (HWND dlg, const char *kserver, u16 port,  leave:
97                const char *pattern, int proto, int flags)      gpgme_release (ctx);
98  {      if (rawkey)
99      gpgme_ctx_t ctx;          gpgme_free (rawkey);
100      gpgme_data_t keydata;      return ec? -1 : 0;
101      gpgme_error_t ec;  }
102      gpgme_import_result_t import_res;  
103      int rc;  
104      char *rawkey = NULL, msg[384];  /* Receive a key from the keyserver @kserver (port @port)
105           with the pattern @pattern.
106      rawkey = new char[MAX_KEYSIZE];     Return value: 0 on success. */
107      if (!rawkey)  int
108          BUG (0);  hkp_recv_key (HWND dlg, const char *kserver, WORD port,
109      memset (rawkey, 0, MAX_KEYSIZE);                const char *pattern, int proto, int flags)
110      if( proto == KSPROTO_LDAP ) {  {
111          rc = ldap_recvkey( kserver, pattern, rawkey, MAX_KEYSIZE-1 );      gpgme_ctx_t ctx;
112          if( rc ) {      gpgme_data_t keydata;
113              msg_box( dlg, _("LDAP key import failed.\n"      gpgme_error_t ec;
114                              "Please make sure you have an online connection"      gpgme_import_result_t import_res = NULL;
115                              " and gpgkeys_ldap.exe is installed"),      int rc;
116                              _("Keyserver"), MB_ERR );      char *rawkey = NULL;
117              free_if_alloc( rawkey );      char msg[384];
118              return rc;      
119          }      rawkey = new char[MAX_KEYSIZE];
120      }      if (!rawkey)
121      else if (proto == KSPROTO_FINGER) {          BUG (0);
122          rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1);      memset (rawkey, 0, MAX_KEYSIZE);
123          if (rc) {      if (proto == KSPROTO_LDAP) {
124              log_box (_("Keyserver"), MB_ERR, _("Finger key import failed: %s\n"),          rc = ldap_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1);
125                       winpt_strerror (rc));          if (rc) {
126              free_if_alloc (rawkey);              msg_box (dlg, _("LDAP key import failed.\n"
127              return rc;                              "Please make sure you have an online connection"
128          }                              " and gpgkeys_ldap.exe is installed"),
129      }                              _("Keyserver"), MB_ERR);
130      else if( ( rc = kserver_recvkey( kserver, port, kserver_check_keyid( pattern ),              free_if_alloc (rawkey);
131                                       rawkey, MAX_KEYSIZE-1 ) ) ) {              return rc;
132          hkp_err_box (dlg, kserver, port, rc);          }
133          free_if_alloc (rawkey);      }
134          return rc;      else if (proto == KSPROTO_FINGER) {
135      }          rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1);
136      else {          if (rc) {
137          if( !strstr( rawkey, "BEGIN PGP PUBLIC KEY BLOCK" ) ) {              log_box (_("Keyserver"), MB_ERR,
138              msg_box( dlg, _("This is not a valid OpenPGP key."), _("Keyserver"), MB_ERR );                       _("Finger key import failed: %s\n"), winpt_strerror (rc));
139              goto leave;              free_if_alloc (rawkey);
140          }              return rc;
141          ec = gpgme_new( &ctx );          }
142          if( ec )      }
143              BUG( NULL );      else if ((rc = kserver_recvkey (kserver, port,
144          gpgme_data_new_from_mem( &keydata, rawkey, strlen( rawkey ), 1 );                                      kserver_check_keyid (pattern),
145          rc = gpgme_op_import( ctx, keydata );                                      rawkey, MAX_KEYSIZE-1))) {
146          if( rc ) {          hkp_err_box (dlg, kserver, port, rc);
147              msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Import"), MB_ERR );          free_if_alloc (rawkey);
148              goto leave;          return rc;
149          }      }
150          import_res = gpgme_op_import_result (ctx);      else {
151      }          if (!strstr (rawkey, "BEGIN PGP PUBLIC KEY BLOCK")) {
152                    msg_box (dlg, _("This is not a valid OpenPGP key."),
153      /* if we use the refresh mode, a lot of keys will be fetched and thus only                       _("Keyserver"), MB_ERR);
154         a summarize at the end is presented and not for each key. */              goto leave;
155      if (!(flags & KM_KS_REFRESH)) {          }
156          if (import_res->new_user_ids == 0) {          ec = gpgme_new (&ctx);
157              _snprintf (msg, DIM (msg)-1,          if (ec)
158                         _("Key '%s' successfully received but nothing was changed."), pattern );              BUG (NULL);
159              status_box (dlg, msg, _("GnuPG Status"));          gpgme_data_new_from_mem (&keydata, rawkey, strlen (rawkey), 1);
160              rc = WPTERR_GENERAL;          rc = gpgme_op_import (ctx, keydata);
161              goto leave;          if (rc) {
162          }              msg_box (dlg, gpgme_strerror ((gpgme_error_t)rc), _("Import"), MB_ERR);
163          _snprintf (msg, DIM (msg)-1, _("Key '%s' sucessfully received and imported."), pattern);              goto leave;
164          status_box (dlg, msg, _("GnuPG Status"));          }
165      }          import_res = gpgme_op_import_result (ctx);
166            }
167  leave:      
168      free_if_alloc (rawkey);      /* if we use the refresh mode, a lot of keys will be fetched and thus only
169      gpgme_release (ctx);         a summarize at the end is presented and not for each key. */
170      gpgme_data_release (keydata);      if (!(flags & KM_KS_REFRESH)) {
171            if (import_res && import_res->unchanged == 1) {
172      return rc;              _snprintf (msg, DIM (msg)-1,
173  } /* hkp_recv_key */                         _("Key '%s' successfully received but nothing was changed."), pattern );
174                status_box (dlg, msg, _("GnuPG Status"));
175                rc = WPTERR_GENERAL;
176  #define my_iskeychar(a) ( ( (a) >='0' && (a) <= '9' ) || ( (a) >= 'A' && (a) <= 'F' ) )              goto leave;
177            }
178  static int          _snprintf (msg, DIM (msg)-1, _("Key '%s' sucessfully received and imported."), pattern);
179  check_pattern( const char *pattern )          status_box (dlg, msg, _("GnuPG Status"));
180  {      }
181      int rc = 1;      
182        leave:
183      /* Whitespace are not allowed! */      free_if_alloc (rawkey);
184      if( strchr( pattern, ' ') ) {      gpgme_release (ctx);
185          rc = WPTERR_GENERAL;      gpgme_data_release (keydata);
186          goto leave;  
187      }      return rc;
188        }
189      if( (( strstr( pattern, "0x" ) ) && ( strlen( pattern ) == 10 ) )  
190           || (strstr(pattern, "0x")) && ( strlen( pattern )  == 18 ) ) {  
191          rc = 0;  #define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F'))
192          goto leave;  
193      }  static int
194        check_pattern (const char *pattern)
195      if( (( my_iskeychar( pattern[0] )) && ( strlen( pattern )  == 8 ) )  {
196           || (my_iskeychar(pattern[0])) && ( strlen( pattern ) == 16) ) {      int rc = 1;
197          rc = 0;      
198          goto leave;      /* Whitespace are not allowed! */
199      }      if (strchr( pattern, ' ')) {
200                rc = WPTERR_GENERAL;
201      if( ( strchr( pattern, '@' ) ) && ( strlen( pattern ) >= 3 ) ) {          goto leave;
202          rc = 0;      }
203          goto leave;      
204      }      if (((strstr (pattern, "0x")) && (strlen (pattern) == 10)) ||
205                 (strstr(pattern, "0x")) && (strlen (pattern)  == 18)) {
206  leave:          rc = 0; /* Either long or short keyid */
207      return rc;          goto leave;
208  } /* check_pattern */      }
209        
210        if( (( my_iskeychar( pattern[0] )) && ( strlen( pattern )  == 8 ) )
211  static void           || (my_iskeychar(pattern[0])) && ( strlen( pattern ) == 16) ) {
212  set_proxy (HWND dlg)          rc = 0;
213  {          goto leave;
214      char proxy[384];      }
215      int port = 0;      
216            if( ( strchr( pattern, '@' ) ) && ( strlen( pattern ) >= 3 ) ) {
217      strcpy (proxy, "HTTP proxy: ");          rc = 0;
218      if (kserver_get_proxy (&port)) {          goto leave;
219          char t[256];      }
220          const char *http = kserver_get_proxy (&port);      
221          _snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port);  leave:
222          strcat (proxy, t);      return rc;
223      }  } /* check_pattern */
224      else  
225          strcat( proxy, "none" );  
226      SetDlgItemText( dlg, IDC_KEYSERVER_PROXY, proxy );  static void
227  } /* set_proxy */  set_proxy (HWND dlg)
228    {
229        char proxy[256];
230  static int inline      int port = 0;
231  kserver_get_pos (listview_ctrl_t lv)      
232  {      strcpy (proxy, "HTTP proxy: ");
233      if (listview_count_items (lv, 0) == 1)      if (kserver_get_proxy (&port)) {
234          return 0;          char t[128];
235      return listview_get_curr_pos (lv);          const char *http = kserver_get_proxy (&port);
236  }          _snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port);
237            strcat (proxy, t);
238        }
239  static u16 inline      else
240  kserver_get_port (listview_ctrl_t lv)          strcat (proxy, "none");
241  {      SetDlgItemText (dlg, IDC_KEYSERVER_PROXY, proxy);
242      char buf[16];  } /* set_proxy */
243    
244      listview_get_item_text (lv, kserver_get_pos (lv), 3, buf, 15);  
245      return (u16)strtoul (buf, NULL, 10);  static int inline
246  }  kserver_get_pos (listview_ctrl_t lv)
247    {
248  static void      if (listview_count_items (lv, 0) == 1)
249  load_default_ks (listview_ctrl_t lv)          return 0;
250  {      return listview_get_curr_pos (lv);
251      char * p, buf[192];  }
252      int i;  
253    
254      p = get_reg_entry_keyserver ("Default");  static u16 inline
255      if (!p)  kserver_get_port (listview_ctrl_t lv)
256          return;  {
257      for( i = 0; i < listview_count_items( lv, 0 ); i++ ) {      char buf[16];
258          listview_get_item_text( lv, i, 0, buf, sizeof (buf)-1 );  
259          if( !strncmp( p, buf, strlen( p ) ) ) {      listview_get_item_text (lv, kserver_get_pos (lv), 3, buf, 15);
260              listview_add_sub_item( lv, i, 2, "x" );      return (u16)strtoul (buf, NULL, 10);
261              break;  }
262          }  
263      }  static void
264      free_if_alloc (p);  load_default_ks (listview_ctrl_t lv)
265  } /* load_default_ks */  {
266        char * p, buf[192];
267        int i;
268  static int  
269  save_default_ks (listview_ctrl_t lv)      p = get_reg_entry_keyserver ("Default");
270  {      if (!p)
271      char buf[192], port[32];          return;
272      int idx, i;        for( i = 0; i < listview_count_items( lv, 0 ); i++ ) {
273            listview_get_item_text( lv, i, 0, buf, sizeof (buf)-1 );
274      idx = listview_get_curr_pos( lv );          if( !strncmp( p, buf, strlen( p ) ) ) {
275      if( idx == -1 ) {              listview_add_sub_item( lv, i, 2, "x" );
276          msg_box( NULL, _("Please select one of the servers."), _("Keyserver"), MB_ERR );              break;
277          return -1;          }
278      }      }
279      listview_get_item_text( lv, idx, 1, buf, sizeof (buf)-1 );      free_if_alloc (p);
280      if( *buf != 'H' ) {  } /* load_default_ks */
281          msg_box( NULL, _("Only HTTP keyserver can be used."), _("Keyserver"), MB_ERR );  
282          return -1;  
283      }  static int
284      for (i = 0; i < listview_count_items( lv, 0 ); i++)  save_default_ks (listview_ctrl_t lv)
285          listview_add_sub_item (lv, i, 2, "");  {
286      listview_add_sub_item (lv, idx, 2, "x");      char buf[192], port[32];
287      listview_get_item_text (lv, idx, 0, buf, sizeof (buf)-1);      int idx, i;  
288      set_reg_entry_keyserver ("Default", buf);  
289      i = kserver_get_port (lv);      idx = listview_get_curr_pos( lv );
290      sprintf (port, "%d", i);      if( idx == -1 ) {
291      set_reg_entry_keyserver ("Default_Port", port);          msg_box( NULL, _("Please select one of the servers."), _("Keyserver"), MB_ERR );
292      keyserver_set_default (buf, (u16)i);          return -1;
293      return 0;      }
294  } /* save_default_ks */      listview_get_item_text( lv, idx, 1, buf, sizeof (buf)-1 );
295        if( *buf != 'H' ) {
296            msg_box( NULL, _("Only HTTP keyserver can be used."), _("Keyserver"), MB_ERR );
297  int          return -1;
298  keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd)      }
299  {      for (i = 0; i < listview_count_items( lv, 0 ); i++)
300      struct listview_column_s keyserver[] = {          listview_add_sub_item (lv, i, 2, "");
301          {0, 160, (char *)_("DNS Name")},              listview_add_sub_item (lv, idx, 2, "x");
302          {1,  52, (char *)_("Protocol")},      listview_get_item_text (lv, idx, 0, buf, sizeof (buf)-1);
303          {2,  46, (char *)_("Default")},      set_reg_entry_keyserver ("Default", buf);
304          {3,  46, (char *)_("Port")},      i = kserver_get_port (lv);
305          {0,   0, NULL}      sprintf (port, "%d", i);
306      };      set_reg_entry_keyserver ("Default_Port", port);
307      listview_ctrl_t lv;      keyserver_set_default (buf, (u16)i);
308      char buf[32];      return 0;
309      int j;  } /* save_default_ks */
310    
311      listview_new (&lv);      
312      lv->ctrl = hwnd;        int
313      for (j=0; keyserver[j].fieldname; j++)  keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd)
314          listview_add_column (lv, &keyserver[j]);          {
315      for (j = 0; j<MAX_KEYSERVERS; j++) {      struct listview_column_s keyserver[] = {
316          if (!server[j].used)          {0, 160, (char *)_("DNS Name")},        
317              continue;          {1,  52, (char *)_("Protocol")},
318          listview_add_item (lv, " ");          {2,  46, (char *)_("Default")},
319          listview_add_sub_item (lv, 0, 0, server[j].name);          {3,  46, (char *)_("Port")},
320          switch (server[j].proto) {          {0,   0, NULL}
321          case KSPROTO_HTTP:      };
322              listview_add_sub_item( lv, 0, 1, "H" ); break;      listview_ctrl_t lv;
323          case KSPROTO_LDAP:      char buf[32];
324              listview_add_sub_item( lv, 0, 1, "L" ); break;      int j;
325          case KSPROTO_FINGER:  
326              listview_add_sub_item( lv, 0, 1, "F" ); break;      listview_new (&lv);    
327          }      lv->ctrl = hwnd;      
328          sprintf (buf, "%d", server[j].port);      for (j=0; keyserver[j].fieldname; j++)
329          listview_add_sub_item (lv, 0, 3, buf);          listview_add_column (lv, &keyserver[j]);        
330      }      for (j = 0; j<MAX_KEYSERVERS; j++) {
331      load_default_ks (lv);          if (!server[j].used)
332      if (listview_count_items (lv, 0) == 0) {              continue;
333          listview_add_item (lv, "");          listview_add_item (lv, " ");
334          listview_add_sub_item (lv, 0, 0, DEF_HKP_KEYSERVER);          listview_add_sub_item (lv, 0, 0, server[j].name);
335          listview_add_sub_item (lv, 0, 1, "H");          switch (server[j].proto) {
336      }          case KSPROTO_HTTP:
337      listview_set_ext_style (lv);              listview_add_sub_item( lv, 0, 1, "H" ); break;
338      *r_lv = lv;          case KSPROTO_LDAP:
339      return 0;              listview_add_sub_item( lv, 0, 1, "L" ); break;
340  }          case KSPROTO_FINGER:
341                listview_add_sub_item( lv, 0, 1, "F" ); break;
342            }
343  BOOL CALLBACK          sprintf (buf, "%d", server[j].port);
344  keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)          listview_add_sub_item (lv, 0, 3, buf);
345  {      }
346      static listview_ctrl_t lv = NULL;      load_default_ks (lv);
347      static int lv_idx = 0;      if (listview_count_items (lv, 0) == 0) {
348      int rc, proto_nr = 0;          listview_add_item (lv, "");
349      char kserver[128], pattern[128];          listview_add_sub_item (lv, 0, 0, DEF_HKP_KEYSERVER);
350      char proto[16];              listview_add_sub_item (lv, 0, 1, "H");
351      keyserver_ctx ksc;      }
352            listview_set_ext_style (lv);
353      switch ( msg ) {      *r_lv = lv;
354      case WM_INITDIALOG:      return 0;
355  #ifndef LANG_DE  }
356          SetWindowText( dlg, _("Keyserver Access") );  
357          SetDlgItemText( dlg, IDC_KEYSERVER_SEND,  
358                          _("Send key (default is receiving)") );  /* Dialog box procedure to access keyservers. */
359          SetDlgItemText( dlg, IDC_KEYSERVER_INFO,  BOOL CALLBACK
360                          _("Please enter the key ID or email address you search for"));  keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
361          SetDlgItemText( dlg, IDC_KEYSERVER_INDEX, _("&Search") );  {
362  #endif      static listview_ctrl_t lv = NULL;
363          set_proxy (dlg);      static int lv_idx = 0;
364          keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST));      int rc, proto_nr = 0;
365          center_window (dlg, NULL);      char kserver[128], pattern[128];
366          SetForegroundWindow (dlg);      char proto[16];    
367          return TRUE;      keyserver_ctx ksc;
368                
369      case WM_NOTIFY:      switch ( msg ) {
370          NMHDR *notify;      case WM_INITDIALOG:
371          notify = (NMHDR *)lparam;          SetWindowText (dlg, _("Keyserver Access"));
372          if( notify && notify->code == NM_CLICK          SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive"));
373              && notify->idFrom == IDC_KEYSERVER_LIST )          SetDlgItemText (dlg, IDC_KEYSERVER_SEND,
374              lv_idx = listview_get_curr_pos( lv );                          _("Send key (default is receiving)"));
375          return TRUE;          SetDlgItemText (dlg, IDC_KEYSERVER_INFO,
376                                    _("Please enter the key ID or email address you search for"));
377      case WM_DESTROY:          SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search"));
378          if( lv ) {          SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange"));
379              listview_release( lv );          SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default"));
380              lv = NULL;          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
381          }  
382          lv_idx = 0;          set_proxy (dlg);
383          return FALSE;          keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST));
384                    center_window (dlg, NULL);
385      case WM_SYSCOMMAND:          SetForegroundWindow (dlg);
386          if( LOWORD( wparam ) == SC_CLOSE )          return TRUE;
387              EndDialog( dlg, TRUE );          
388          return FALSE;      case WM_NOTIFY:
389                    NMHDR *notify;
390      case WM_COMMAND:          notify = (NMHDR *)lparam;
391          switch( LOWORD( wparam ) ) {          if( notify && notify->code == NM_CLICK
392          case IDC_KEYSERVER_PROXSETT:              && notify->idFrom == IDC_KEYSERVER_LIST )
393              dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, glob_hwnd,              lv_idx = listview_get_curr_pos( lv );
394                                keyserver_proxy_dlg_proc, NULL,          return TRUE;
395                                _("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY );          
396              set_proxy( dlg );      case WM_DESTROY:
397              return TRUE;          if( lv ) {
398                            listview_release( lv );
399          case IDC_KEYSERVER_INDEX:              lv = NULL;
400              if (!lv_idx) {          }
401                  lv_idx = kserver_get_pos (lv);          lv_idx = 0;
402                  if (lv_idx == -1) {          return FALSE;
403                      msg_box (dlg, _("Please select one of the keyservers."), _("Keyserver"), MB_INFO);          
404                      return FALSE;      case WM_SYSCOMMAND:
405                  }          if( LOWORD( wparam ) == SC_CLOSE )
406              }              EndDialog( dlg, TRUE );
407              listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1);          return FALSE;
408              if (*proto == 'L') {          
409                  msg_box( dlg, _("This is not implemented yet!"), _("Keyserver"), MB_ERR );      case WM_COMMAND:
410                  return FALSE;          switch( LOWORD( wparam ) ) {
411              }          case IDC_KEYSERVER_PROXSETT:
412              listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1);              dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, glob_hwnd,
413              if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) {                                keyserver_proxy_dlg_proc, NULL,
414                  msg_box (dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO);                                _("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY );
415                  return FALSE;              set_proxy( dlg );
416              }              return TRUE;
417              ksc.name = kserver;              
418              ksc.pattern = pattern;          case IDC_KEYSERVER_INDEX:
419              ksc.port = kserver_get_port (lv);              if (!lv_idx) {
420              DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg,                  lv_idx = kserver_get_pos (lv);
421                              hkpsearch_dlg_proc, (LPARAM) &ksc );                  if (lv_idx == -1) {
422              return TRUE;                      msg_box (dlg, _("Please select one of the keyservers."),
423                                             _("Keyserver"), MB_INFO);
424          case IDC_KEYSERVER_RECV:                      return FALSE;
425              memset (&kserver, 0, sizeof (kserver));                  }
426              if (!lv_idx) {              }
427                  lv_idx = kserver_get_pos (lv);              listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1);
428                  if (lv_idx == -1) {              if (*proto == 'L') {
429                      msg_box( dlg, _("Please select one of the keyservers."), _("Keyserver"), MB_INFO );                  msg_box( dlg, _("This is not implemented yet!"), _("Keyserver"), MB_ERR );
430                      return FALSE;                  return FALSE;
431                  }              }
432              }              listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1);
433              listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 );              if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) {
434              proto_nr = KSPROTO_HTTP;                  msg_box (dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO);
435              if( *proto == 'L' )                  return FALSE;
436                  proto_nr = KSPROTO_LDAP;              }
437              else if( *proto == 'F' )              ksc.name = kserver;
438                  proto_nr = KSPROTO_FINGER;              ksc.pattern = pattern;
439              listview_get_item_text( lv, lv_idx, 0, kserver, sizeof (kserver)-1 );              ksc.port = kserver_get_port (lv);
440              if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1 ) ) {              DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg,
441                  msg_box( dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO );                              hkpsearch_dlg_proc, (LPARAM) &ksc );
442                  return FALSE;              return TRUE;
443              }              
444              if( proto_nr == KSPROTO_LDAP && strchr( pattern, '@' ) ) {          case IDC_KEYSERVER_RECV:
445                  msg_box( dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO );              memset (&kserver, 0, sizeof (kserver));
446                  return FALSE;              if (!lv_idx) {
447              }                  lv_idx = kserver_get_pos (lv);
448              else if (proto_nr == KSPROTO_FINGER) {                  if (lv_idx == -1) {
449                  if (strchr (pattern, '@') || strchr (pattern, ' ')) {                      msg_box (dlg, _("Please select one of the keyservers."),
450                      msg_box (dlg, _("Only enter the name of the user."), _("FINGER Keyserver"), MB_INFO);                              _("Keyserver"), MB_INFO);
451                      return FALSE;                      return FALSE;
452                  }                  }
453              }              }
454              else if( check_pattern( pattern ) ) {              listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 );
455                  msg_box( dlg, _("Only email addresses or keyids are allowed."), _("HKP Keyserver"), MB_INFO );              proto_nr = KSPROTO_HTTP;
456                  return FALSE;              if( *proto == 'L' )
457              }                  proto_nr = KSPROTO_LDAP;
458              rc = hkp_recv_key (dlg, kserver, kserver_get_port (lv), pattern, proto_nr, 0);              else if( *proto == 'F' )
459              if (!rc)                  proto_nr = KSPROTO_FINGER;
460                  keycache_set_reload (1);              listview_get_item_text( lv, lv_idx, 0, kserver, sizeof (kserver)-1 );
461              return TRUE;              if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1 ) ) {
462                    msg_box( dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO );
463          case IDC_KEYSERVER_DEFAULT:                  return FALSE;
464              save_default_ks( lv );              }
465              break;              if( proto_nr == KSPROTO_LDAP && strchr( pattern, '@' ) ) {
466                                msg_box( dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO );
467          case IDCANCEL:                  return FALSE;
468              EndDialog( dlg, FALSE );              }
469              return FALSE;              else if (proto_nr == KSPROTO_FINGER) {
470          }                  if (strchr (pattern, '@') || strchr (pattern, ' ')) {
471          break;                      msg_box (dlg, _("Only enter the name of the user."), _("FINGER Keyserver"), MB_INFO);
472      }                      return FALSE;
473                        }
474      return FALSE;              }
475  } /* keyserver_dlg_proc */              else if( check_pattern( pattern ) ) {
476                    msg_box( dlg, _("Only email addresses or keyids are allowed."), _("HKP Keyserver"), MB_INFO );
477                    return FALSE;
478                }
479                rc = hkp_recv_key (dlg, kserver, kserver_get_port (lv), pattern, proto_nr, 0);
480                if (!rc)
481                    keycache_set_reload (1);
482                return TRUE;
483    
484            case IDC_KEYSERVER_DEFAULT:
485                save_default_ks (lv);
486                break;
487                
488            case IDCANCEL:
489                EndDialog (dlg, FALSE);
490                return FALSE;
491            }
492            break;
493        }
494        
495        return FALSE;
496    }
497    

Legend:
Removed from v.25  
changed lines
  Added in v.109

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26