1 |
/* wptProxySettingsDlg.cpp - Dialog for the proxy settings |
/* wptProxySettingsDlg.cpp - Dialog for the proxy settings |
2 |
* Copyright (C) 2002, 2003, 2004 Timo Schulz |
* Copyright (C) 2002-2005 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
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> |
#include <windows.h> |
21 |
|
|
22 |
#include "../resource.h" |
#include "../resource.h" |
49 |
char t[512]; |
char t[512]; |
50 |
int ncount = 0, pos = 0; |
int ncount = 0, pos = 0; |
51 |
|
|
52 |
ncount = GetDlgItemText( dlg, IDC_PROXY_PWD, t, sizeof t -1 ); |
ncount = GetDlgItemText( dlg, IDC_PROXY_PWD, t, DIM (t)-1); |
53 |
if( ncount ) |
if( ncount ) |
54 |
ctx->pass = strdup( t ); |
ctx->pass = strdup( t ); |
55 |
ncount = GetDlgItemText( dlg, IDC_PROXY_USER, t, sizeof t -1 ); |
ncount = GetDlgItemText( dlg, IDC_PROXY_USER, t, DIM (t)-1); |
56 |
if( ncount ) |
if( ncount ) |
57 |
ctx->user = strdup( t ); |
ctx->user = strdup( t ); |
58 |
ncount = GetDlgItemText( dlg, IDC_PROXY_HOST, t, sizeof t -1 ); |
ncount = GetDlgItemText( dlg, IDC_PROXY_HOST, t, DIM (t)-1); |
59 |
if( ncount ) { |
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 |
if (!strncmp (t, "http://", 7)) |
if (!strncmp (t, "http://", 7)) |
66 |
pos = 7; |
pos = 7; |
67 |
ctx->host = strdup (t + pos); |
ctx->host = strdup (t + pos); |
68 |
} |
} |
69 |
if (check_number (dlg, IDC_PROXY_PORT)) { |
if (check_number (dlg, IDC_PROXY_PORT)) { |
70 |
msg_box (dlg, _("Invalid port number."), _("Proxy Settings"), MB_ERR); |
msg_box (dlg, _("Invalid port number."), _("Proxy Settings"), MB_ERR); |
71 |
return -1; |
return -1; |
89 |
} /* read_proxy */ |
} /* read_proxy */ |
90 |
|
|
91 |
|
|
92 |
|
static void |
93 |
|
enable_proxy_auth (HWND dlg, int val) |
94 |
|
{ |
95 |
|
int mode = val? TRUE : FALSE; |
96 |
|
EnableWindow (GetDlgItem (dlg, IDC_PROXY_PWD), mode); |
97 |
|
EnableWindow (GetDlgItem (dlg, IDC_PROXY_USER), mode); |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
BOOL CALLBACK |
BOOL CALLBACK |
102 |
keyserver_proxy_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
keyserver_proxy_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
103 |
{ |
{ |
104 |
const char *proxy = NULL, * user, * pass; |
const char *proxy = NULL, *user=NULL, *pass = NULL; |
105 |
int port = 0; |
int port = 0, auth = 0; |
106 |
int rc = 0; |
int rc = 0; |
107 |
|
|
108 |
switch ( msg ) { |
switch (msg) { |
109 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
110 |
proxy = kserver_get_proxy( &port ); |
proxy = kserver_get_proxy (&port); |
111 |
if( proxy ) { |
if (proxy) { |
112 |
SetDlgItemText( dlg, IDC_PROXY_HOST, proxy ); |
SetDlgItemText( dlg, IDC_PROXY_HOST, proxy ); |
113 |
SetDlgItemInt( dlg, IDC_PROXY_PORT, port, FALSE ); |
SetDlgItemInt( dlg, IDC_PROXY_PORT, port, FALSE ); |
114 |
user = kserver_get_proxy_info( PROXY_USER ); |
user = kserver_get_proxy_info( PROXY_USER ); |
115 |
if( user ) |
if (user) { |
116 |
SetDlgItemText( dlg, IDC_PROXY_USER, user ); |
SetDlgItemText (dlg, IDC_PROXY_USER, user); |
117 |
pass = kserver_get_proxy_info( PROXY_PASS ); |
CheckDlgButton (dlg, IDC_PROXY_AUTH, BST_CHECKED); |
118 |
if( pass ) |
auth++; |
119 |
|
} |
120 |
|
pass = kserver_get_proxy_info(PROXY_PASS); |
121 |
|
if (pass) { |
122 |
SetDlgItemText( dlg, IDC_PROXY_PWD, pass ); |
SetDlgItemText( dlg, IDC_PROXY_PWD, pass ); |
123 |
|
auth++; |
124 |
|
} |
125 |
} |
} |
126 |
center_window( dlg ); |
enable_proxy_auth (dlg, auth); |
127 |
SetForegroundWindow( dlg ); |
center_window (dlg); |
128 |
|
SetForegroundWindow (dlg); |
129 |
break; |
break; |
130 |
|
|
131 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
132 |
if( LOWORD( wparam ) == SC_CLOSE ) |
if( LOWORD (wparam) == SC_CLOSE) |
133 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
134 |
return FALSE; |
return FALSE; |
135 |
|
|
136 |
case WM_COMMAND: |
case WM_COMMAND: |
137 |
|
switch (HIWORD (wparam)) { |
138 |
|
case BN_CLICKED: |
139 |
|
switch( (int)LOWORD( wparam ) ) { |
140 |
|
case IDC_PROXY_AUTH: |
141 |
|
if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH)) |
142 |
|
enable_proxy_auth (dlg, 1); |
143 |
|
else |
144 |
|
enable_proxy_auth (dlg, 0); |
145 |
|
break; |
146 |
|
} |
147 |
|
break; |
148 |
|
} |
149 |
|
|
150 |
switch( LOWORD( wparam ) ) { |
switch( LOWORD( wparam ) ) { |
151 |
case IDOK: |
case IDOK: |
152 |
|
if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH) && |
153 |
|
item_get_text_length (dlg, IDC_PROXY_HOST) == 0 && |
154 |
|
item_get_text_length (dlg, IDC_PROXY_USER) == 0 && |
155 |
|
item_get_text_length (dlg, IDC_PROXY_PWD) == 0) { |
156 |
|
msg_box (dlg, _("Please fill out all required fields for authentication."), |
157 |
|
_("Proxy Settings"), MB_WARN); |
158 |
|
return FALSE; |
159 |
|
} |
160 |
keyserver_proxy_ctx ctx; |
keyserver_proxy_ctx ctx; |
161 |
memset (&ctx, 0, sizeof (ctx)); |
memset (&ctx, 0, sizeof (ctx)); |
162 |
if (read_proxy (dlg, &ctx)) |
if (read_proxy (dlg, &ctx)) |