31 |
#include "wptErrors.h" |
#include "wptErrors.h" |
32 |
#include "wptNLS.h" |
#include "wptNLS.h" |
33 |
#include "wptKeyserver.h" |
#include "wptKeyserver.h" |
34 |
|
#include "wptRegistry.h" |
35 |
|
|
36 |
|
|
37 |
static int |
static int |
50 |
|
|
51 |
|
|
52 |
static int |
static int |
53 |
read_proxy (HWND dlg, keyserver_proxy_ctx * ctx) |
read_proxy (HWND dlg, keyserver_proxy_t ctx) |
54 |
{ |
{ |
55 |
char t[512]; |
char t[512]; |
56 |
int ncount = 0, pos = 0; |
int ncount = 0, pos = 0; |
57 |
|
|
58 |
ncount = GetDlgItemText( dlg, IDC_PROXY_PWD, t, DIM (t)-1); |
ncount = GetDlgItemText (dlg, IDC_PROXY_PWD, t, DIM (t)-1); |
59 |
if( ncount ) |
if (ncount > 0) |
60 |
ctx->pass = strdup( t ); |
ctx->pass = strdup (t); |
61 |
ncount = GetDlgItemText( dlg, IDC_PROXY_USER, t, DIM (t)-1); |
ncount = GetDlgItemText (dlg, IDC_PROXY_USER, t, DIM (t)-1); |
62 |
if( ncount ) |
if (ncount > 0) |
63 |
ctx->user = strdup( t ); |
ctx->user = strdup (t); |
64 |
ncount = GetDlgItemText( dlg, IDC_PROXY_HOST, t, DIM (t)-1); |
ncount = GetDlgItemText (dlg, IDC_PROXY_HOST, t, DIM (t)-1); |
65 |
if (ncount) { |
if (ncount > 0) { |
66 |
if (check_IP_or_hostname (t)) { |
if (check_IP_or_hostname (t)) { |
67 |
msg_box (dlg, _("Invalid host/IP address."), _("Proxy Settings"), MB_ERR); |
msg_box (dlg, _("Invalid host/IP address."), _("Proxy Settings"), MB_ERR); |
68 |
return -1; |
return -1; |
77 |
return -1; |
return -1; |
78 |
} |
} |
79 |
|
|
80 |
ctx->port = GetDlgItemInt( dlg, IDC_PROXY_PORT, NULL, FALSE ); |
ctx->port = GetDlgItemInt (dlg, IDC_PROXY_PORT, NULL, FALSE); |
81 |
if( ctx->port < 0 || ctx->port > 65535 ) { |
if (ctx->port < 0 || ctx->port > 65535) { |
82 |
msg_box (dlg, _("Please select a value from 0-65535 for the port"), |
msg_box (dlg, _("Please select a value from 0-65535 for the port"), |
83 |
_("Proxy Settings"), MB_INFO); |
_("Proxy Settings"), MB_INFO); |
84 |
return -1; |
return -1; |
85 |
} |
} |
86 |
if( ctx->user && !ctx->pass || !ctx->user && ctx->pass ) { |
if (ctx->user && !ctx->pass || !ctx->user && ctx->pass) { |
87 |
msg_box (dlg, _("When you want to use authentication, " |
msg_box (dlg, _("When you want to use authentication, " |
88 |
"please fill out both fields."), _("Proxy Settings"), MB_ERR); |
"please fill out both fields."), _("Proxy Settings"), MB_ERR); |
89 |
return -1; |
return -1; |
106 |
} |
} |
107 |
|
|
108 |
|
|
109 |
|
static void |
110 |
|
init_proxy_protocols (HWND dlg) |
111 |
|
{ |
112 |
|
HWND cb = GetDlgItem (dlg, IDC_PROXY_PROTO); |
113 |
|
combox_add_string (cb, (char *)"HTTP"); |
114 |
|
/*combox_add_string (cb, (char *)"SOCKS5");*/ |
115 |
|
SendMessage (cb, CB_SETCURSEL, (WPARAM)0, 0); |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
/* Dialog box procedure for proxy authentication. */ |
/* Dialog box procedure for proxy authentication. */ |
120 |
BOOL CALLBACK |
BOOL CALLBACK |
121 |
keyserver_proxy_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyserver_proxy_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
122 |
{ |
{ |
123 |
const char *proxy = NULL, *user=NULL, *pass = NULL; |
int auth = 0; |
124 |
int port = 0, auth = 0; |
|
|
|
|
125 |
switch (msg) { |
switch (msg) { |
126 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
127 |
proxy = kserver_get_proxy (&port); |
if (proxy.host != NULL) { |
128 |
if (proxy) { |
SetDlgItemText (dlg, IDC_PROXY_HOST, proxy.host); |
129 |
SetDlgItemText( dlg, IDC_PROXY_HOST, proxy ); |
SetDlgItemInt( dlg, IDC_PROXY_PORT, proxy.port, FALSE ); |
130 |
SetDlgItemInt( dlg, IDC_PROXY_PORT, port, FALSE ); |
if (proxy.user != NULL) { |
131 |
user = kserver_get_proxy_info (PROXY_USER); |
SetDlgItemText (dlg, IDC_PROXY_USER, proxy.user); |
|
if (user) { |
|
|
SetDlgItemText (dlg, IDC_PROXY_USER, user); |
|
132 |
CheckDlgButton (dlg, IDC_PROXY_AUTH, BST_CHECKED); |
CheckDlgButton (dlg, IDC_PROXY_AUTH, BST_CHECKED); |
133 |
auth++; |
auth++; |
134 |
} |
} |
135 |
pass = kserver_get_proxy_info(PROXY_PASS); |
if (proxy.pass != NULL) { |
136 |
if (pass) { |
SetDlgItemText (dlg, IDC_PROXY_PWD, proxy.pass); |
|
SetDlgItemText( dlg, IDC_PROXY_PWD, pass ); |
|
137 |
auth++; |
auth++; |
138 |
} |
} |
139 |
} |
} |
140 |
enable_proxy_auth (dlg, auth); |
enable_proxy_auth (dlg, auth); |
141 |
SetDlgItemText (dlg, IDC_PROXY_HOSTINF, _("Proxy host name or IP address")); |
SetDlgItemText (dlg, IDC_PROXY_HOSTINF, _("Proxy host name or IP address")); |
142 |
SetDlgItemText (dlg, IDC_PROXY_AUTH, _("Server requires &authentication")); |
SetDlgItemText (dlg, IDC_PROXY_AUTH, _("Server requires &authentication")); |
143 |
SetDlgItemText (dlg, IDC_PROXY_USERINF, _("User name")); |
SetDlgItemText (dlg, IDC_PROXY_USERINF, _("User name")); |
144 |
SetDlgItemText (dlg, IDC_PROXY_PWDINF, _("Password")); |
SetDlgItemText (dlg, IDC_PROXY_PWDINF, _("Password")); |
145 |
|
SetDlgItemText (dlg, IDC_PROXY_PROTOINF, _("Proxy type")); |
146 |
|
SetDlgItemText (dlg, IDC_PROXY_AUTHINF, _("Authentication")); |
147 |
SetWindowText (dlg, _("Proxy Settings")); |
SetWindowText (dlg, _("Proxy Settings")); |
148 |
|
init_proxy_protocols (dlg); |
149 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
150 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
151 |
break; |
break; |
152 |
|
|
153 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
154 |
if( LOWORD (wparam) == SC_CLOSE) |
if (LOWORD (wparam) == SC_CLOSE) |
155 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
156 |
return FALSE; |
return FALSE; |
157 |
|
|
158 |
case WM_COMMAND: |
case WM_COMMAND: |
159 |
switch (HIWORD (wparam)) { |
switch (HIWORD (wparam)) { |
160 |
case BN_CLICKED: |
case BN_CLICKED: |
161 |
switch( (int)LOWORD( wparam ) ) { |
switch ((int)LOWORD (wparam)) { |
162 |
case IDC_PROXY_AUTH: |
case IDC_PROXY_AUTH: |
163 |
if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH)) |
if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH)) |
164 |
enable_proxy_auth (dlg, 1); |
enable_proxy_auth (dlg, 1); |
169 |
break; |
break; |
170 |
} |
} |
171 |
|
|
172 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
173 |
case IDOK: |
case IDOK: |
174 |
if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH) && |
if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH) && |
175 |
item_get_text_length (dlg, IDC_PROXY_HOST) == 0 && |
item_get_text_length (dlg, IDC_PROXY_HOST) == 0 && |
179 |
_("Proxy Settings"), MB_WARN); |
_("Proxy Settings"), MB_WARN); |
180 |
return TRUE; |
return TRUE; |
181 |
} |
} |
182 |
keyserver_proxy_ctx ctx; |
kserver_proxy_release (&proxy); |
183 |
memset (&ctx, 0, sizeof (ctx)); |
if (read_proxy (dlg, &proxy)) |
|
if (read_proxy (dlg, &ctx)) |
|
184 |
return FALSE; |
return FALSE; |
185 |
kserver_change_proxy (&ctx); |
set_reg_proxy_prefs (&proxy); |
|
proxy_release (&ctx); |
|
186 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
187 |
return TRUE; |
return TRUE; |
188 |
|
|