/[winpt]/trunk/Src/wptProxySettingsDlg.cpp
ViewVC logotype

Contents of /trunk/Src/wptProxySettingsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (show annotations)
Mon Oct 31 14:04:59 2005 UTC (19 years, 4 months ago) by werner
File size: 5276 byte(s)
Minor changes; compiles now but gettext is still missing.

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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26