/[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 35 by twoaday, Mon Mar 7 13:21:36 2005 UTC revision 36 by werner, Thu Oct 27 15:25:13 2005 UTC
# Line 1  Line 1 
1  /* wptKeyserverSearchDlg.cpp - Keyserver Searching  /* wptKeyserverSearchDlg.cpp - Keyserver Searching
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-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    
21  #include <windows.h>  #ifdef HAVE_CONFIG_H
22  #include <stdio.h>  #include <config.h>
23    #endif
24  #include "../resource.h"  
25  #include "wptCommonCtl.h"  #include <windows.h>
26  #include "wptKeyserver.h"  #include <windows.h>
27  #include "wptErrors.h"  #include <stdio.h>
28  #include "wptTypes.h"  
29  #include "wptGPG.h"  #include "../resource.h"
30  #include "wptContext.h" /* for passphrase_s */  #include "wptCommonCtl.h"
31  #include "wptDlgs.h"  #include "wptKeyserver.h"
32  #include "wptNLS.h"  #include "wptErrors.h"
33    #include "wptTypes.h"
34    #include "wptGPG.h"
35  BOOL CALLBACK  #include "wptContext.h" /* for passphrase_s */
36  hkpsearch_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  #include "wptDlgs.h"
37  {  #include "wptNLS.h"
38      static listview_ctrl_t lv = NULL;  
39      static keyserver_ctx * ksc;  
40      keyserver_key key;  BOOL CALLBACK
41      struct listview_column_s keysearch[] = {  hkpsearch_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
42          {0,  48, (char *)_("Size")},  {
43          {1,  64, (char *)_("Key ID")},      static listview_ctrl_t lv = NULL;
44          {2,  72, (char *)_("Creation")},      static keyserver_ctx * ksc;
45          {3, 256, (char *)_("User ID")},      keyserver_key key;
46          {0,   0, NULL}      struct listview_column_s keysearch[] = {
47      };          {0,  48, (char *)_("Size")},
48      char t[32], info[384];          {1,  64, (char *)_("Key ID")},
49      int i, rc;          {2,  72, (char *)_("Creation")},
50      int conn_fd = 0;          {3, 256, (char *)_("User ID")},
51                {0,   0, NULL}
52      switch (msg)      };
53      {      char t[32], info[384];
54      case WM_INITDIALOG:      int i, rc;
55          ksc = (keyserver_ctx *)lparam;      int conn_fd = 0;
56          if (!ksc)      
57              dlg_fatal_error (dlg, "Could not get dialog param.");      switch (msg)
58          #ifndef LANG_DE      {
59          SetWindowText (dlg, _("Keyserver Searching"));      case WM_INITDIALOG:
60          #endif          ksc = (keyserver_ctx *)lparam;
61          SetDlgItemText (dlg, IDC_HKPSEARCH_RECV, _("&Receive"));          if (!ksc)
62          _snprintf (info, sizeof (info) - 1,              dlg_fatal_error (dlg, "Could not get dialog param.");
63                     _("Connect to '%s' to search for \"%s\""),          #ifndef LANG_DE
64                     ksc->name, ksc->pattern);          SetWindowText (dlg, _("Keyserver Searching"));
65          SetDlgItemText (dlg, IDC_HKPSEARCH_INFO, info);          #endif
66          listview_new (&lv);          SetDlgItemText (dlg, IDC_HKPSEARCH_RECV, _("&Receive"));
67          lv->ctrl = GetDlgItem (dlg, IDC_HKPSEARCH_LIST);          _snprintf (info, sizeof (info) - 1,
68          for (i = 0; keysearch[i].width; i++)                     _("Connect to '%s' to search for \"%s\""),
69              listview_add_column (lv, &keysearch[i]);                     ksc->name, ksc->pattern);
70          listview_set_ext_style (lv);          SetDlgItemText (dlg, IDC_HKPSEARCH_INFO, info);
71          rc = kserver_search_init (ksc->name, ksc->port, ksc->pattern, &conn_fd);          listview_new (&lv);
72          if (rc) {          lv->ctrl = GetDlgItem (dlg, IDC_HKPSEARCH_LIST);
73              msg_box (dlg, winpt_strerror (rc), _("Keyserver - search init"), MB_ERR);          for (i = 0; keysearch[i].width; i++)
74              EndDialog (dlg, FALSE);              listview_add_column (lv, &keysearch[i]);
75              return FALSE;          listview_set_ext_style (lv);
76          }          rc = kserver_search_init (ksc->name, ksc->port, ksc->pattern, &conn_fd);
77          rc = kserver_search_chkresp (conn_fd);          if (rc) {
78          if (rc) {              msg_box (dlg, winpt_strerror (rc), _("Keyserver - search init"), MB_ERR);
79              msg_box (dlg, winpt_strerror (rc), _("Keyserver - check response"), MB_ERR);              EndDialog (dlg, FALSE);
80              closesocket (conn_fd);              return FALSE;
81              EndDialog (dlg, FALSE);          }
82              return FALSE;          rc = kserver_search_chkresp (conn_fd);
83          }          if (rc) {
84          for (;;) {              msg_box (dlg, winpt_strerror (rc), _("Keyserver - check response"), MB_ERR);
85              rc = kserver_search (conn_fd, &key);              closesocket (conn_fd);
86              if (rc)              EndDialog (dlg, FALSE);
87                  break;              return FALSE;
88              if (!key.bits)          }
89                  continue;          for (;;) {
90              _snprintf (t, sizeof (t) - 1, "%d", key.bits);              rc = kserver_search (conn_fd, &key);
91              listview_add_item (lv, " ");              if (rc)
92              listview_add_sub_item (lv, 0, 0, t);                  break;
93              listview_add_sub_item (lv, 0, 1, key.keyid);              if (!key.bits)
94              listview_add_sub_item (lv, 0, 2, key.date);                  continue;
95              listview_add_sub_item (lv, 0, 3, key.uid);              _snprintf (t, sizeof (t) - 1, "%d", key.bits);
96          }              listview_add_item (lv, " ");
97          closesocket (conn_fd);              listview_add_sub_item (lv, 0, 0, t);
98          SetForegroundWindow (dlg);              listview_add_sub_item (lv, 0, 1, key.keyid);
99          return TRUE;              listview_add_sub_item (lv, 0, 2, key.date);
100                        listview_add_sub_item (lv, 0, 3, key.uid);
101      case WM_DESTROY:          }
102          if (lv) {          closesocket (conn_fd);
103              listview_release (lv);          SetForegroundWindow (dlg);
104              lv = NULL;          return TRUE;
105          }          
106          return FALSE;      case WM_DESTROY:
107                    if (lv) {
108      case WM_SYSCOMMAND:              listview_release (lv);
109          if (LOWORD (wparam) == SC_CLOSE)              lv = NULL;
110              EndDialog (dlg, TRUE);          }
111          return FALSE;          return FALSE;
112                    
113      case WM_COMMAND:      case WM_SYSCOMMAND:
114          switch (LOWORD (wparam)) {          if (LOWORD (wparam) == SC_CLOSE)
115          case IDOK:              EndDialog (dlg, TRUE);
116              EndDialog (dlg, TRUE);          return FALSE;
117              return TRUE;          
118                    case WM_COMMAND:
119          case IDCANCEL:          switch (LOWORD (wparam)) {
120              EndDialog (dlg, FALSE);          case IDOK:
121              return FALSE;              EndDialog (dlg, TRUE);
122                            return TRUE;
123          case IDC_HKPSEARCH_RECV:              
124              if ((i = listview_get_curr_pos (lv)) == -1) {          case IDCANCEL:
125                  msg_box (dlg, _("Please select a key."), _("Keyserver"), MB_ERR);              EndDialog (dlg, FALSE);
126                  return FALSE;              return FALSE;
127              }              
128              listview_get_item_text (lv, i, 1, t, sizeof (t) -1);          case IDC_HKPSEARCH_RECV:
129              hkp_recv_key (dlg, ksc->name, ksc->port, t, 0, 0);              if ((i = listview_get_curr_pos (lv)) == -1) {
130              return TRUE;                  msg_box (dlg, _("Please select a key."), _("Keyserver"), MB_ERR);
131          }                  return FALSE;
132          break;              }
133      }              listview_get_item_text (lv, i, 1, t, sizeof (t) -1);
134                    hkp_recv_key (dlg, ksc->name, ksc->port, t, 0, 0);
135      return FALSE;              return TRUE;
136            }
137            break;
138        }
139        
140        return FALSE;
141  } /* hkpsearch_dlg_proc */  } /* hkpsearch_dlg_proc */

Legend:
Removed from v.35  
changed lines
  Added in v.36

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26