1 |
werner |
36 |
/* wptVerifyFileDlg.cpp - (File Manager) Verify file |
2 |
|
|
* Copyright (C) 2001, 2002, 2005 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 |
|
|
|
26 |
werner |
47 |
#include "resource.h" |
27 |
werner |
36 |
#include "wptGPG.h" |
28 |
|
|
#include "wptW32API.h" |
29 |
|
|
#include "wptTypes.h" |
30 |
|
|
#include "wptNLS.h" |
31 |
|
|
#include "wptVersion.h" |
32 |
|
|
#include "wptCommonCtl.h" |
33 |
|
|
#include "wptKeylist.h" |
34 |
|
|
#include "wptTypes.h" |
35 |
|
|
#include "wptKeyserver.h" |
36 |
|
|
|
37 |
|
|
static listview_ctrl_t dlg_lv = NULL; |
38 |
|
|
static HWND dlg_wnd = NULL; /* handle to the dialog box window */ |
39 |
|
|
static HANDLE dlg_event = NULL; /* event for the dialog. */ |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
/* Dialog box procedure to show the verify results of a file. */ |
43 |
|
|
static BOOL CALLBACK |
44 |
|
|
file_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
45 |
|
|
{ |
46 |
|
|
static listview_ctrl_t lv = NULL; |
47 |
|
|
int rc = 0; |
48 |
|
|
|
49 |
twoaday |
85 |
switch (msg) { |
50 |
werner |
36 |
case WM_INITDIALOG: |
51 |
|
|
SetWindowText (dlg, _("File Verify")); |
52 |
|
|
SetDlgItemText (dlg, IDC_VERIFY_SAVE, _("&Save")); |
53 |
|
|
rc = verlist_build (&lv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 1); |
54 |
|
|
if (rc) |
55 |
|
|
BUG (dlg); |
56 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_VERIFY_SAVE), FALSE); |
57 |
|
|
SetForegroundWindow (dlg); |
58 |
|
|
dlg_lv = lv; |
59 |
|
|
dlg_wnd = dlg; |
60 |
|
|
return TRUE; |
61 |
|
|
|
62 |
|
|
case WM_DESTROY: |
63 |
|
|
if (lv) { |
64 |
|
|
listview_release (lv); |
65 |
|
|
lv = NULL; |
66 |
|
|
} |
67 |
|
|
dlg_lv = NULL; |
68 |
|
|
dlg_wnd = NULL; |
69 |
|
|
return FALSE; |
70 |
|
|
|
71 |
|
|
case WM_NOTIFY: |
72 |
|
|
NMHDR *notify; |
73 |
|
|
|
74 |
|
|
notify = (NMHDR *)lparam; |
75 |
|
|
if (notify && notify->code == NM_DBLCLK && |
76 |
|
|
notify->idFrom == IDC_VERIFY_SIGLIST) { |
77 |
|
|
char buf[64]; |
78 |
|
|
listview_get_item_text (lv, listview_get_curr_pos (lv), 4, buf, 63); |
79 |
|
|
if (strlen (buf) == 10 && buf[0] == '0' && buf[1] == 'x') { |
80 |
|
|
rc = msg_box (dlg, _("Do you want to retrieve the key?"), |
81 |
|
|
_("Verify"), MB_QUEST_ASK); |
82 |
|
|
if (rc == IDYES) { |
83 |
|
|
if (!hkp_recv_key (dlg, default_keyserver, |
84 |
|
|
default_keyserver_port, buf, 0, 0)) |
85 |
twoaday |
161 |
keycache_update (0, buf); |
86 |
werner |
36 |
} |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
} |
90 |
|
|
break; |
91 |
|
|
|
92 |
|
|
case WM_SYSCOMMAND: |
93 |
|
|
if (LOWORD (wparam) == SC_CLOSE) |
94 |
|
|
EndDialog (dlg, TRUE); |
95 |
|
|
return FALSE; |
96 |
|
|
|
97 |
|
|
case WM_COMMAND: |
98 |
|
|
switch (LOWORD (wparam)) { |
99 |
|
|
case IDOK: |
100 |
|
|
if (dlg_event) |
101 |
|
|
SetEvent (dlg_event); |
102 |
|
|
EndDialog (dlg, TRUE); |
103 |
|
|
return TRUE; |
104 |
|
|
} |
105 |
|
|
break; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
return FALSE; |
109 |
twoaday |
32 |
} |
110 |
werner |
36 |
|
111 |
|
|
|
112 |
|
|
/* Thread which spawns the verify dialog. */ |
113 |
|
|
static DWORD CALLBACK |
114 |
|
|
file_verify_dlg_thread (void *opaque) |
115 |
|
|
{ |
116 |
twoaday |
68 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_VERIFY, |
117 |
|
|
GetActiveWindow(), file_verify_dlg_proc, 0); |
118 |
werner |
36 |
if (dlg_event) { |
119 |
|
|
CloseHandle (dlg_event); |
120 |
|
|
dlg_event = NULL; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
ExitThread (0); |
124 |
|
|
return 0; |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
|
128 |
|
|
/* Create the verify dialog asynchronly. */ |
129 |
|
|
int |
130 |
|
|
file_verify_create_dlg (void) |
131 |
|
|
{ |
132 |
|
|
DWORD tid; |
133 |
|
|
HANDLE thread_hd; |
134 |
|
|
SECURITY_ATTRIBUTES sec_attr; |
135 |
|
|
|
136 |
|
|
if (dlg_wnd) |
137 |
|
|
return 0; |
138 |
|
|
|
139 |
|
|
memset (&sec_attr, 0, sizeof (sec_attr)); |
140 |
|
|
sec_attr.bInheritHandle = FALSE; |
141 |
|
|
sec_attr.lpSecurityDescriptor = NULL; |
142 |
|
|
sec_attr.nLength = sizeof (sec_attr); |
143 |
|
|
thread_hd = CreateThread (&sec_attr, 0, file_verify_dlg_thread, NULL, 0, &tid); |
144 |
|
|
if (thread_hd == NULL) { |
145 |
|
|
msg_box (NULL, "Could not create verify thread.", _("Verify"), MB_ERR); |
146 |
|
|
return -1; |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
return 0; |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
|
153 |
|
|
/* Add the signature + information in @c to the verify dialog. */ |
154 |
|
|
void |
155 |
|
|
file_verify_add_state (file_sig_ctx_t c) |
156 |
|
|
{ |
157 |
|
|
if (dlg_lv) |
158 |
|
|
verlist_add_sig_log (dlg_lv, c); |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
|
162 |
|
|
/* Create an event for the verify dialog. */ |
163 |
|
|
void |
164 |
|
|
file_verify_use_event (void) |
165 |
|
|
{ |
166 |
|
|
SECURITY_ATTRIBUTES sec_attr; |
167 |
|
|
|
168 |
|
|
memset (&sec_attr, 0, sizeof (sec_attr)); |
169 |
|
|
sec_attr.bInheritHandle = FALSE; |
170 |
|
|
sec_attr.nLength = sizeof (sec_attr); |
171 |
|
|
dlg_event = CreateEvent (&sec_attr, TRUE, FALSE, NULL); |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
|
175 |
|
|
/* Wait until the verify event is signaled. */ |
176 |
|
|
void |
177 |
|
|
file_verify_wait (void) |
178 |
|
|
{ |
179 |
|
|
WaitForSingleObject (dlg_event, INFINITE); |
180 |
|
|
} |