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

Diff of /trunk/Src/wptKeyserverSearchDlg.cpp

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

revision 147 by twoaday, Fri Jan 13 14:21:16 2006 UTC revision 185 by twoaday, Mon Mar 20 12:48:52 2006 UTC
# Line 35  Line 35 
35  #include "wptNLS.h"  #include "wptNLS.h"
36    
37    
38    enum { KSS_COL_BITS = 0, KSS_COL_KEYID, KSS_COL_DATE, KSS_COL_UID };
39    
40  int  int
41  hkp_recv_key2 (HWND dlg, const char *kserver, WORD port,  hkp_recv_key2 (HWND dlg, const char *kserver, WORD port,
42                 const char *pattern, int proto, char **r_fpr);                 const char *pattern, int proto, char **r_fpr);
43    
44    
45  /* Dialog box procedur for keyserver searching. */  /* Initialize dialog. */
46  BOOL CALLBACK  static listview_ctrl_t
47  hkpsearch_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  on_init_dialog (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
48  {  {
     static listview_ctrl_t lv = NULL;  
     static keyserver_ctx * ksc;  
     keyserver_key key;  
49      struct listview_column_s keysearch[] = {      struct listview_column_s keysearch[] = {
50          {0,  48, (char *)_("Size")},          {0,  48, (char *)_("Size")},
51          {1,  64, (char *)_("Key ID")},          {1,  64, (char *)_("Key ID")},
# Line 54  hkpsearch_dlg_proc (HWND dlg, UINT msg, Line 53  hkpsearch_dlg_proc (HWND dlg, UINT msg,
53          {3, 256, (char *)_("User ID")},          {3, 256, (char *)_("User ID")},
54          {0,   0, NULL}          {0,   0, NULL}
55      };      };
56      char t[32], info[384], *fpr = NULL;      char info[384];
57      int i, rc;      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      int conn_fd = 0;      int conn_fd = 0;
83        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    /* Dialog box procedure for keyserver searching. */
109    BOOL CALLBACK
110    hkpsearch_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
111    {
112        static listview_ctrl_t lv = NULL;
113        static keyserver_ctx *ksc;
114        char *fpr = NULL, t[32];
115        int pos;
116        int rc;
117            
118      switch (msg) {      switch (msg) {
119      case WM_INITDIALOG:      case WM_INITDIALOG:
120          ksc = (keyserver_ctx *)lparam;          ksc = (keyserver_ctx *)lparam;
121          if (!ksc)          if (!ksc)
122              dlg_fatal_error (dlg, "Could not get dialog param.");              dlg_fatal_error (dlg, "Could not get dialog param.");
123          SetWindowText (dlg, _("Keyserver Searching"));          lv = on_init_dialog (dlg, msg, wparam, lparam);
124          SetDlgItemText (dlg, IDC_HKPSEARCH_RECV, _("&Receive"));          rc = search_hkp_keys (dlg, ksc, lv);
         SetDlgItemText (dlg, IDOK, _("&Cancel"));  
         _snprintf (info, sizeof (info) - 1,  
                    _("Connect to '%s' to search for \"%s\""),  
                    ksc->name, ksc->pattern);  
         SetDlgItemText (dlg, IDC_HKPSEARCH_INFO, info);  
         listview_new (&lv);  
         lv->ctrl = GetDlgItem (dlg, IDC_HKPSEARCH_LIST);  
         for (i = 0; keysearch[i].width; i++)  
             listview_add_column (lv, &keysearch[i]);  
         listview_set_ext_style (lv);  
         rc = kserver_search_init (ksc->name, ksc->port, ksc->pattern, &conn_fd);  
         if (rc) {  
             msg_box (dlg, winpt_strerror (rc), _("Keyserver Search"), MB_ERR);  
             EndDialog (dlg, FALSE);  
             return FALSE;  
         }  
         rc = kserver_search_chkresp (conn_fd);  
125          if (rc) {          if (rc) {
             msg_box (dlg, winpt_strerror (rc), _("Keyserver Search"), MB_ERR);  
             closesocket (conn_fd);  
126              EndDialog (dlg, FALSE);              EndDialog (dlg, FALSE);
127              return FALSE;              return FALSE;
128          }          }
         for (;;) {  
             rc = kserver_search (conn_fd, &key);  
             if (rc)  
                 break;  
             if (!key.bits)  
                 continue;  
             _snprintf (t, sizeof (t) - 1, "%d", key.bits);  
             listview_add_item (lv, " ");  
             listview_add_sub_item (lv, 0, 0, t);  
             listview_add_sub_item (lv, 0, 1, key.keyid);  
             listview_add_sub_item (lv, 0, 2, key.date);  
             listview_add_sub_item (lv, 0, 3, key.uid);  
         }  
         closesocket (conn_fd);  
         SetForegroundWindow (dlg);  
129          return TRUE;          return TRUE;
130                    
131      case WM_DESTROY:      case WM_DESTROY:
# Line 128  hkpsearch_dlg_proc (HWND dlg, UINT msg, Line 151  hkpsearch_dlg_proc (HWND dlg, UINT msg,
151              return FALSE;              return FALSE;
152                            
153          case IDC_HKPSEARCH_RECV:          case IDC_HKPSEARCH_RECV:
154              if ((i = listview_get_curr_pos (lv)) == -1) {              if ((pos = listview_get_curr_pos (lv)) == -1) {
155                  msg_box (dlg, _("Please select a key."), _("Keyserver Search"), MB_ERR);                  msg_box (dlg, _("Please select a key."), _("Keyserver Search"), MB_ERR);
156                  return FALSE;                  return FALSE;
157              }              }
158              listview_get_item_text (lv, i, 1, t, sizeof (t) -1);              listview_get_item_text (lv, pos, 1, t, sizeof (t) -1);
159              rc = hkp_recv_key2 (dlg, ksc->name, ksc->port, t, 0, &fpr);              rc = hkp_recv_key2 (dlg, ksc->name, ksc->port, t, 0, &fpr);
160              if (!rc && fpr != NULL) {              if (!rc && fpr != NULL) {
161                  keycache_update (0, fpr);                  keycache_update (0, fpr);

Legend:
Removed from v.147  
changed lines
  Added in v.185

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26