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

Annotation of /trunk/Src/wptProxySettingsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File size: 3755 byte(s)
WinPT initial checkin.


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     read_proxy (HWND dlg, keyserver_proxy_ctx * ctx)
34     {
35     char t[512];
36     int ncount = 0, pos = 0;
37    
38     ncount = GetDlgItemText( dlg, IDC_PROXY_PWD, t, sizeof t -1 );
39     if( ncount )
40     ctx->pass = strdup( t );
41     ncount = GetDlgItemText( dlg, IDC_PROXY_USER, t, sizeof t -1 );
42     if( ncount )
43     ctx->user = strdup( t );
44     ncount = GetDlgItemText( dlg, IDC_PROXY_HOST, t, sizeof t -1 );
45     if( ncount ) {
46     if (!strncmp (t, "http://", 7))
47     pos = 7;
48     ctx->host = strdup (t + pos);
49     }
50     ctx->port = GetDlgItemInt( dlg, IDC_PROXY_PORT, NULL, FALSE );
51     if( ctx->port < 0 || ctx->port > 65535 ) {
52     msg_box( dlg, _("Please select a value from 0-65535 for the port"), _("Proxy Settings"), MB_INFO );
53     return -1;
54     }
55     if( ctx->user && !ctx->pass || !ctx->user && ctx->pass ) {
56     msg_box( dlg, _("When you want to use authentication, "
57     "please fill out both fields."), _("Proxy Settings"), MB_ERR );
58     return -1;
59     }
60     if( ctx->host && !ctx->port || !ctx->host && ctx->port ) {
61     msg_box( dlg, _("Please enter a host name and a port."), _("Proxy Settings"), MB_INFO );
62     return -1;
63     }
64     return 0;
65     } /* read_proxy */
66    
67    
68     BOOL CALLBACK
69     keyserver_proxy_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
70     {
71     const char *proxy = NULL, * user, * pass;
72     int port = 0;
73     int rc = 0;
74    
75     switch ( msg ) {
76     case WM_INITDIALOG:
77     proxy = kserver_get_proxy( &port );
78     if( proxy ) {
79     SetDlgItemText( dlg, IDC_PROXY_HOST, proxy );
80     SetDlgItemInt( dlg, IDC_PROXY_PORT, port, FALSE );
81     user = kserver_get_proxy_info( PROXY_USER );
82     if( user )
83     SetDlgItemText( dlg, IDC_PROXY_USER, user );
84     pass = kserver_get_proxy_info( PROXY_PASS );
85     if( pass )
86     SetDlgItemText( dlg, IDC_PROXY_PWD, pass );
87     }
88     center_window( dlg );
89     SetForegroundWindow( dlg );
90     break;
91    
92     case WM_SYSCOMMAND:
93     if( LOWORD( wparam ) == SC_CLOSE )
94     EndDialog( dlg, TRUE );
95     return FALSE;
96    
97     case WM_COMMAND:
98     switch( LOWORD( wparam ) ) {
99     case IDOK:
100     keyserver_proxy_ctx ctx;
101     memset (&ctx, 0, sizeof (ctx));
102     if (read_proxy (dlg, &ctx))
103     return FALSE;
104     kserver_change_proxy (&ctx);
105     proxy_release (&ctx);
106     EndDialog (dlg, TRUE);
107     return TRUE;
108    
109     case IDCANCEL:
110     EndDialog (dlg, FALSE);
111     return FALSE;
112     }
113     break;
114     }
115    
116     return FALSE;
117     } /* keyserver_proxy_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26