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