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

Annotation of /trunk/Src/wptProxySettingsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 78 - (hide annotations)
Tue Nov 15 08:54:44 2005 UTC (19 years, 3 months ago) by twoaday
File size: 5471 byte(s)
2005-11-14  Timo Schulz  <ts@g10code.com>
 
        * wptGPG.cpp (check_gnupg_engine): Fix version check.
        * wptMainProc.cpp (winpt_main_proc): Check keyring
        file permissions always and do not use interative output
        when the windows session ends.
        * wptProxySettingsDlg.cpp (proxy_settings_dlg_proc):
        Localize all strings.
        * wptPassphraseDlg.cpp (passwd_dlg_proc): Likewise.
        * wptGPGPrefsDlg.cpp (gpg_prefs_dlg): Likewise.
        * wptKeyEditDlgs.cpp (do_init_keylist): Skip all
        non-valid keys.
         


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26