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

Annotation of /trunk/Src/wptProxySettingsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 180 - (hide annotations)
Mon Mar 6 14:41:58 2006 UTC (18 years, 11 months ago) by twoaday
File size: 5652 byte(s)
2006-02-27  Timo Schulz  <twoaday@freakmail.de>
 
        * wptSOCKS.cpp (socks_handshake): New.
        * wptMainProc.cpp (winpt_main_proc): A dbl-click forces
        the key manager in teh foreground if possible.
        * wptHotkey.cpp (hotkey_unregister): Unregister all hotkeys.
        * wptRegistry.cpp (get_reg_proxy_prefs,
        set_reg_proxy_prefs): Use directly the proxy context.
        Changed all callers.
        * wptProxySettingsDlg.cpp (init_proxy_protocols): New.
        (keyserver_proxy_dlg_proc): Use directly the proxy context.
        * wptKeyserver.cpp (kserver_connect): Better proxy support.
        (kserver_send_request, kserver_recvkey_request): Likewise.
        * wptKeyserverDlg.cpp (name_from_proto): New.
        (set_proxy): Adjusted for the new code.


1 werner 36 /* 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     #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    
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 werner 46 if (!isdigit ((unsigned int)buf[i]))
46 werner 36 return -1;
47     }
48     return 0;
49     }
50    
51    
52     static int
53 twoaday 180 read_proxy (HWND dlg, keyserver_proxy_t ctx)
54 werner 36 {
55     char t[512];
56     int ncount = 0, pos = 0;
57    
58 twoaday 180 ncount = GetDlgItemText (dlg, IDC_PROXY_PWD, t, DIM (t)-1);
59     if (ncount > 0)
60     ctx->pass = strdup (t);
61     ncount = GetDlgItemText (dlg, IDC_PROXY_USER, t, DIM (t)-1);
62     if (ncount > 0)
63     ctx->user = strdup (t);
64     ncount = GetDlgItemText (dlg, IDC_PROXY_HOST, t, DIM (t)-1);
65     if (ncount > 0) {
66 werner 36 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 twoaday 180 ctx->port = GetDlgItemInt (dlg, IDC_PROXY_PORT, NULL, FALSE);
81     if (ctx->port < 0 || ctx->port > 65535) {
82 werner 36 msg_box (dlg, _("Please select a value from 0-65535 for the port"),
83     _("Proxy Settings"), MB_INFO);
84     return -1;
85     }
86 twoaday 180 if (ctx->user && !ctx->pass || !ctx->user && ctx->pass) {
87 werner 36 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 twoaday 180 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 werner 36 /* Dialog box procedure for proxy authentication. */
120     BOOL CALLBACK
121     keyserver_proxy_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
122 twoaday 180 {
123     int auth = 0;
124    
125 werner 36 switch (msg) {
126     case WM_INITDIALOG:
127 twoaday 180 if (proxy.host != NULL) {
128     SetDlgItemText (dlg, IDC_PROXY_HOST, proxy.host);
129     SetDlgItemInt( dlg, IDC_PROXY_PORT, proxy.port, FALSE );
130     if (proxy.user != NULL) {
131     SetDlgItemText (dlg, IDC_PROXY_USER, proxy.user);
132 werner 36 CheckDlgButton (dlg, IDC_PROXY_AUTH, BST_CHECKED);
133     auth++;
134     }
135 twoaday 180 if (proxy.pass != NULL) {
136     SetDlgItemText (dlg, IDC_PROXY_PWD, proxy.pass);
137 werner 36 auth++;
138     }
139     }
140 twoaday 180 enable_proxy_auth (dlg, auth);
141 twoaday 78 SetDlgItemText (dlg, IDC_PROXY_HOSTINF, _("Proxy host name or IP address"));
142 werner 36 SetDlgItemText (dlg, IDC_PROXY_AUTH, _("Server requires &authentication"));
143 twoaday 78 SetDlgItemText (dlg, IDC_PROXY_USERINF, _("User name"));
144     SetDlgItemText (dlg, IDC_PROXY_PWDINF, _("Password"));
145 twoaday 180 SetDlgItemText (dlg, IDC_PROXY_PROTOINF, _("Proxy type"));
146     SetDlgItemText (dlg, IDC_PROXY_AUTHINF, _("Authentication"));
147 werner 36 SetWindowText (dlg, _("Proxy Settings"));
148 twoaday 180 init_proxy_protocols (dlg);
149 twoaday 78 center_window (dlg, NULL);
150 werner 36 SetForegroundWindow (dlg);
151     break;
152    
153     case WM_SYSCOMMAND:
154 twoaday 180 if (LOWORD (wparam) == SC_CLOSE)
155 werner 36 EndDialog (dlg, TRUE);
156     return FALSE;
157    
158     case WM_COMMAND:
159     switch (HIWORD (wparam)) {
160     case BN_CLICKED:
161 twoaday 180 switch ((int)LOWORD (wparam)) {
162 werner 36 case IDC_PROXY_AUTH:
163     if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH))
164     enable_proxy_auth (dlg, 1);
165     else
166     enable_proxy_auth (dlg, 0);
167     break;
168     }
169     break;
170     }
171    
172 twoaday 180 switch (LOWORD (wparam)) {
173 werner 36 case IDOK:
174     if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH) &&
175     item_get_text_length (dlg, IDC_PROXY_HOST) == 0 &&
176     item_get_text_length (dlg, IDC_PROXY_USER) == 0 &&
177     item_get_text_length (dlg, IDC_PROXY_PWD) == 0) {
178     msg_box (dlg, _("Please fill out all required fields for authentication."),
179     _("Proxy Settings"), MB_WARN);
180     return TRUE;
181     }
182 twoaday 180 kserver_proxy_release (&proxy);
183     if (read_proxy (dlg, &proxy))
184 werner 36 return FALSE;
185 twoaday 180 set_reg_proxy_prefs (&proxy);
186 werner 36 EndDialog (dlg, TRUE);
187     return TRUE;
188    
189     case IDCANCEL:
190     EndDialog (dlg, FALSE);
191     return FALSE;
192     }
193     break;
194     }
195    
196     return FALSE;
197     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26