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

Annotation of /trunk/Src/wptProxySettingsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 225 - (hide annotations)
Tue Jun 6 13:37:59 2006 UTC (18 years, 8 months ago) by twoaday
File size: 6268 byte(s)


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26