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

Annotation of /trunk/Src/wptProxySettingsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 13 - (hide annotations)
Mon Apr 25 07:15:30 2005 UTC (19 years, 10 months ago) by twoaday
File size: 4136 byte(s)
Commit bug fixes. Release 0.9.92.

1 twoaday 2 /* wptProxySettingsDlg.cpp - Dialog for the proxy settings
2     * Copyright (C) 2002, 2003, 2004 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     #include <windows.h>
22    
23     #include "../resource.h"
24     #include "wptTypes.h"
25     #include "wptKeyserver.h"
26     #include "wptW32API.h"
27     #include "wptErrors.h"
28     #include "wptNLS.h"
29     #include "wptKeyserver.h"
30    
31    
32     static int
33 twoaday 13 check_number (HWND dlg, int id)
34     {
35     char buf[32];
36     size_t i;
37    
38     GetDlgItemText (dlg, id, buf, 31);
39     for (i=0; i < strlen (buf); i++) {
40     if (!isdigit (buf[i]))
41     return -1;
42     }
43     return 0;
44     }
45    
46    
47     static int
48 twoaday 2 read_proxy (HWND dlg, keyserver_proxy_ctx * ctx)
49     {
50     char t[512];
51     int ncount = 0, pos = 0;
52    
53     ncount = GetDlgItemText( dlg, IDC_PROXY_PWD, t, sizeof t -1 );
54     if( ncount )
55     ctx->pass = strdup( t );
56     ncount = GetDlgItemText( dlg, IDC_PROXY_USER, t, sizeof t -1 );
57     if( ncount )
58     ctx->user = strdup( t );
59     ncount = GetDlgItemText( dlg, IDC_PROXY_HOST, t, sizeof t -1 );
60     if( ncount ) {
61     if (!strncmp (t, "http://", 7))
62     pos = 7;
63     ctx->host = strdup (t + pos);
64 twoaday 13 }
65     if (check_number (dlg, IDC_PROXY_PORT)) {
66     msg_box (dlg, _("Invalid port number."), _("Proxy Settings"), MB_ERR);
67     return -1;
68 twoaday 2 }
69 twoaday 13
70 twoaday 2 ctx->port = GetDlgItemInt( dlg, IDC_PROXY_PORT, NULL, FALSE );
71     if( ctx->port < 0 || ctx->port > 65535 ) {
72     msg_box( dlg, _("Please select a value from 0-65535 for the port"), _("Proxy Settings"), MB_INFO );
73     return -1;
74     }
75     if( ctx->user && !ctx->pass || !ctx->user && ctx->pass ) {
76     msg_box( dlg, _("When you want to use authentication, "
77     "please fill out both fields."), _("Proxy Settings"), MB_ERR );
78     return -1;
79     }
80     if( ctx->host && !ctx->port || !ctx->host && ctx->port ) {
81     msg_box( dlg, _("Please enter a host name and a port."), _("Proxy Settings"), MB_INFO );
82     return -1;
83     }
84     return 0;
85     } /* read_proxy */
86    
87    
88     BOOL CALLBACK
89     keyserver_proxy_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
90     {
91     const char *proxy = NULL, * user, * pass;
92     int port = 0;
93     int rc = 0;
94    
95     switch ( msg ) {
96     case WM_INITDIALOG:
97     proxy = kserver_get_proxy( &port );
98     if( proxy ) {
99     SetDlgItemText( dlg, IDC_PROXY_HOST, proxy );
100     SetDlgItemInt( dlg, IDC_PROXY_PORT, port, FALSE );
101     user = kserver_get_proxy_info( PROXY_USER );
102     if( user )
103     SetDlgItemText( dlg, IDC_PROXY_USER, user );
104     pass = kserver_get_proxy_info( PROXY_PASS );
105     if( pass )
106     SetDlgItemText( dlg, IDC_PROXY_PWD, pass );
107     }
108     center_window( dlg );
109     SetForegroundWindow( dlg );
110     break;
111    
112     case WM_SYSCOMMAND:
113     if( LOWORD( wparam ) == SC_CLOSE )
114     EndDialog( dlg, TRUE );
115     return FALSE;
116    
117     case WM_COMMAND:
118     switch( LOWORD( wparam ) ) {
119     case IDOK:
120     keyserver_proxy_ctx ctx;
121     memset (&ctx, 0, sizeof (ctx));
122     if (read_proxy (dlg, &ctx))
123     return FALSE;
124     kserver_change_proxy (&ctx);
125     proxy_release (&ctx);
126     EndDialog (dlg, TRUE);
127     return TRUE;
128    
129     case IDCANCEL:
130     EndDialog (dlg, FALSE);
131     return FALSE;
132     }
133     break;
134     }
135    
136     return FALSE;
137     } /* keyserver_proxy_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26