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