1 |
werner |
36 |
/* wptProxySettingsDlg.cpp - Dialog for the proxy settings |
2 |
|
|
* Copyright (C) 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 |
werner |
47 |
#include <ctype.h> |
26 |
werner |
36 |
|
27 |
werner |
47 |
#include "resource.h" |
28 |
werner |
36 |
#include "wptTypes.h" |
29 |
|
|
#include "wptKeyserver.h" |
30 |
|
|
#include "wptW32API.h" |
31 |
|
|
#include "wptErrors.h" |
32 |
|
|
#include "wptNLS.h" |
33 |
|
|
#include "wptKeyserver.h" |
34 |
twoaday |
180 |
#include "wptRegistry.h" |
35 |
werner |
36 |
|
36 |
twoaday |
185 |
#define combo_get_sel(dlg, id) \ |
37 |
|
|
SendDlgItemMessage ((dlg), (id), CB_GETCURSEL, 0, 0) |
38 |
werner |
36 |
|
39 |
|
|
static int |
40 |
|
|
check_number (HWND dlg, int id) |
41 |
|
|
{ |
42 |
|
|
char buf[32]; |
43 |
|
|
size_t i; |
44 |
|
|
|
45 |
|
|
GetDlgItemText (dlg, id, buf, 31); |
46 |
|
|
for (i=0; i < strlen (buf); i++) { |
47 |
werner |
46 |
if (!isdigit ((unsigned int)buf[i])) |
48 |
werner |
36 |
return -1; |
49 |
|
|
} |
50 |
|
|
return 0; |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
|
54 |
|
|
static int |
55 |
twoaday |
180 |
read_proxy (HWND dlg, keyserver_proxy_t ctx) |
56 |
werner |
36 |
{ |
57 |
|
|
char t[512]; |
58 |
|
|
int ncount = 0, pos = 0; |
59 |
|
|
|
60 |
twoaday |
180 |
ncount = GetDlgItemText (dlg, IDC_PROXY_PWD, t, DIM (t)-1); |
61 |
|
|
if (ncount > 0) |
62 |
|
|
ctx->pass = strdup (t); |
63 |
|
|
ncount = GetDlgItemText (dlg, IDC_PROXY_USER, t, DIM (t)-1); |
64 |
|
|
if (ncount > 0) |
65 |
|
|
ctx->user = strdup (t); |
66 |
|
|
ncount = GetDlgItemText (dlg, IDC_PROXY_HOST, t, DIM (t)-1); |
67 |
|
|
if (ncount > 0) { |
68 |
werner |
36 |
if (check_IP_or_hostname (t)) { |
69 |
|
|
msg_box (dlg, _("Invalid host/IP address."), _("Proxy Settings"), MB_ERR); |
70 |
|
|
return -1; |
71 |
|
|
} |
72 |
|
|
/* XXX: check prefix */ |
73 |
|
|
if (!strncmp (t, "http://", 7)) |
74 |
|
|
pos = 7; |
75 |
|
|
ctx->host = strdup (t + pos); |
76 |
|
|
} |
77 |
twoaday |
185 |
else { |
78 |
|
|
msg_box (dlg, _("Please enter the proxy hostname."), |
79 |
|
|
_("Proxy Settings"), MB_ERR); |
80 |
|
|
return -1; |
81 |
|
|
} |
82 |
|
|
|
83 |
werner |
36 |
if (check_number (dlg, IDC_PROXY_PORT)) { |
84 |
|
|
msg_box (dlg, _("Invalid port number."), _("Proxy Settings"), MB_ERR); |
85 |
|
|
return -1; |
86 |
|
|
} |
87 |
|
|
|
88 |
twoaday |
180 |
ctx->port = GetDlgItemInt (dlg, IDC_PROXY_PORT, NULL, FALSE); |
89 |
|
|
if (ctx->port < 0 || ctx->port > 65535) { |
90 |
werner |
36 |
msg_box (dlg, _("Please select a value from 0-65535 for the port"), |
91 |
|
|
_("Proxy Settings"), MB_INFO); |
92 |
|
|
return -1; |
93 |
|
|
} |
94 |
twoaday |
180 |
if (ctx->user && !ctx->pass || !ctx->user && ctx->pass) { |
95 |
werner |
36 |
msg_box (dlg, _("When you want to use authentication, " |
96 |
|
|
"please fill out both fields."), _("Proxy Settings"), MB_ERR); |
97 |
|
|
return -1; |
98 |
|
|
} |
99 |
|
|
if (ctx->host && !ctx->port || !ctx->host && ctx->port) { |
100 |
|
|
msg_box (dlg, _("Please enter a host name and a port."), |
101 |
|
|
_("Proxy Settings"), MB_INFO); |
102 |
|
|
return -1; |
103 |
|
|
} |
104 |
twoaday |
185 |
ctx->proto = combo_get_sel (dlg, IDC_PROXY_PROTO); |
105 |
werner |
36 |
return 0; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
|
109 |
|
|
static void |
110 |
|
|
enable_proxy_auth (HWND dlg, int val) |
111 |
|
|
{ |
112 |
|
|
int mode = val? TRUE : FALSE; |
113 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_PROXY_PWD), mode); |
114 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_PROXY_USER), mode); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
|
118 |
twoaday |
180 |
static void |
119 |
|
|
init_proxy_protocols (HWND dlg) |
120 |
|
|
{ |
121 |
|
|
HWND cb = GetDlgItem (dlg, IDC_PROXY_PROTO); |
122 |
twoaday |
185 |
combox_add_string (cb, (char *)"NONE"); |
123 |
twoaday |
180 |
combox_add_string (cb, (char *)"HTTP"); |
124 |
|
|
/*combox_add_string (cb, (char *)"SOCKS5");*/ |
125 |
|
|
SendMessage (cb, CB_SETCURSEL, (WPARAM)0, 0); |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
|
129 |
werner |
36 |
/* Dialog box procedure for proxy authentication. */ |
130 |
|
|
BOOL CALLBACK |
131 |
|
|
keyserver_proxy_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
132 |
twoaday |
180 |
{ |
133 |
|
|
int auth = 0; |
134 |
|
|
|
135 |
werner |
36 |
switch (msg) { |
136 |
|
|
case WM_INITDIALOG: |
137 |
twoaday |
180 |
if (proxy.host != NULL) { |
138 |
|
|
SetDlgItemText (dlg, IDC_PROXY_HOST, proxy.host); |
139 |
|
|
SetDlgItemInt( dlg, IDC_PROXY_PORT, proxy.port, FALSE ); |
140 |
|
|
if (proxy.user != NULL) { |
141 |
|
|
SetDlgItemText (dlg, IDC_PROXY_USER, proxy.user); |
142 |
werner |
36 |
CheckDlgButton (dlg, IDC_PROXY_AUTH, BST_CHECKED); |
143 |
|
|
auth++; |
144 |
|
|
} |
145 |
twoaday |
180 |
if (proxy.pass != NULL) { |
146 |
|
|
SetDlgItemText (dlg, IDC_PROXY_PWD, proxy.pass); |
147 |
werner |
36 |
auth++; |
148 |
|
|
} |
149 |
|
|
} |
150 |
twoaday |
180 |
enable_proxy_auth (dlg, auth); |
151 |
twoaday |
78 |
SetDlgItemText (dlg, IDC_PROXY_HOSTINF, _("Proxy host name or IP address")); |
152 |
werner |
36 |
SetDlgItemText (dlg, IDC_PROXY_AUTH, _("Server requires &authentication")); |
153 |
twoaday |
78 |
SetDlgItemText (dlg, IDC_PROXY_USERINF, _("User name")); |
154 |
|
|
SetDlgItemText (dlg, IDC_PROXY_PWDINF, _("Password")); |
155 |
twoaday |
180 |
SetDlgItemText (dlg, IDC_PROXY_PROTOINF, _("Proxy type")); |
156 |
|
|
SetDlgItemText (dlg, IDC_PROXY_AUTHINF, _("Authentication")); |
157 |
werner |
36 |
SetWindowText (dlg, _("Proxy Settings")); |
158 |
twoaday |
180 |
init_proxy_protocols (dlg); |
159 |
twoaday |
185 |
SendDlgItemMessage (dlg, IDC_PROXY_PROTO, CB_SETCURSEL, |
160 |
|
|
(WPARAM)proxy.proto, 0); |
161 |
twoaday |
78 |
center_window (dlg, NULL); |
162 |
werner |
36 |
SetForegroundWindow (dlg); |
163 |
|
|
break; |
164 |
|
|
|
165 |
|
|
case WM_SYSCOMMAND: |
166 |
twoaday |
180 |
if (LOWORD (wparam) == SC_CLOSE) |
167 |
werner |
36 |
EndDialog (dlg, TRUE); |
168 |
|
|
return FALSE; |
169 |
|
|
|
170 |
|
|
case WM_COMMAND: |
171 |
|
|
switch (HIWORD (wparam)) { |
172 |
twoaday |
185 |
case CBN_SELCHANGE: |
173 |
|
|
if (combo_get_sel (dlg, (int)LOWORD (wparam))) { |
174 |
|
|
} |
175 |
|
|
else { |
176 |
|
|
} |
177 |
|
|
break; |
178 |
|
|
|
179 |
werner |
36 |
case BN_CLICKED: |
180 |
twoaday |
180 |
switch ((int)LOWORD (wparam)) { |
181 |
werner |
36 |
case IDC_PROXY_AUTH: |
182 |
|
|
if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH)) |
183 |
|
|
enable_proxy_auth (dlg, 1); |
184 |
|
|
else |
185 |
|
|
enable_proxy_auth (dlg, 0); |
186 |
|
|
break; |
187 |
|
|
} |
188 |
|
|
break; |
189 |
|
|
} |
190 |
|
|
|
191 |
twoaday |
180 |
switch (LOWORD (wparam)) { |
192 |
werner |
36 |
case IDOK: |
193 |
|
|
if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH) && |
194 |
|
|
item_get_text_length (dlg, IDC_PROXY_USER) == 0 && |
195 |
|
|
item_get_text_length (dlg, IDC_PROXY_PWD) == 0) { |
196 |
|
|
msg_box (dlg, _("Please fill out all required fields for authentication."), |
197 |
|
|
_("Proxy Settings"), MB_WARN); |
198 |
|
|
return TRUE; |
199 |
|
|
} |
200 |
twoaday |
180 |
kserver_proxy_release (&proxy); |
201 |
twoaday |
185 |
if (combo_get_sel (dlg, IDC_PROXY_PROTO) != PROXY_PROTO_NONE) { |
202 |
|
|
if (read_proxy (dlg, &proxy)) |
203 |
|
|
return FALSE; |
204 |
|
|
} |
205 |
twoaday |
180 |
set_reg_proxy_prefs (&proxy); |
206 |
twoaday |
185 |
log_box ("debug", 0, "%d", proxy.proto); |
207 |
werner |
36 |
EndDialog (dlg, TRUE); |
208 |
|
|
return TRUE; |
209 |
|
|
|
210 |
|
|
case IDCANCEL: |
211 |
|
|
EndDialog (dlg, FALSE); |
212 |
|
|
return FALSE; |
213 |
|
|
} |
214 |
|
|
break; |
215 |
|
|
} |
216 |
|
|
|
217 |
|
|
return FALSE; |
218 |
|
|
} |