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

Diff of /trunk/Src/wptProxySettingsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 22 by twoaday, Wed Aug 10 11:33:35 2005 UTC revision 78 by twoaday, Tue Nov 15 08:54:44 2005 UTC
# Line 1  Line 1 
1  /* wptProxySettingsDlg.cpp - Dialog for the proxy settings  /* wptProxySettingsDlg.cpp - Dialog for the proxy settings
2   *      Copyright (C) 2002-2005 Timo Schulz   *      Copyright (C) 2002-2005 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
6   * WinPT is free software; you can redistribute it and/or modify   * 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   * 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   * the Free Software Foundation; either version 2 of the License, or
9   * (at your option) any later version.   * (at your option) any later version.
10   *   *
11   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.   * GNU General Public License for more details.
15   *   *
16   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
20  #include <windows.h>  #ifdef HAVE_CONFIG_H
21    #include <config.h>
22  #include "../resource.h"  #endif
23  #include "wptTypes.h"  
24  #include "wptKeyserver.h"  #include <windows.h>
25  #include "wptW32API.h"  #include <ctype.h>
26  #include "wptErrors.h"  
27  #include "wptNLS.h"  #include "resource.h"
28  #include "wptKeyserver.h"  #include "wptTypes.h"
29    #include "wptKeyserver.h"
30    #include "wptW32API.h"
31  static int  #include "wptErrors.h"
32  check_number (HWND dlg, int id)  #include "wptNLS.h"
33  {  #include "wptKeyserver.h"
34      char buf[32];  
35      size_t i;  
36    static int
37      GetDlgItemText (dlg, id, buf, 31);  check_number (HWND dlg, int id)
38      for (i=0; i < strlen (buf); i++) {  {
39          if (!isdigit (buf[i]))      char buf[32];
40              return -1;      size_t i;
41      }  
42      return 0;      GetDlgItemText (dlg, id, buf, 31);
43  }      for (i=0; i < strlen (buf); i++) {
44            if (!isdigit ((unsigned int)buf[i]))
45                return -1;
46  static int      }
47  read_proxy (HWND dlg, keyserver_proxy_ctx * ctx)      return 0;
48  {  }
49      char t[512];  
50      int ncount = 0, pos = 0;  
51        static int
52      ncount = GetDlgItemText( dlg, IDC_PROXY_PWD, t, DIM (t)-1);  read_proxy (HWND dlg, keyserver_proxy_ctx * ctx)
53      if( ncount )  {
54          ctx->pass = strdup( t );      char t[512];
55      ncount = GetDlgItemText( dlg, IDC_PROXY_USER, t, DIM (t)-1);      int ncount = 0, pos = 0;
56      if( ncount )      
57          ctx->user = strdup( t );      ncount = GetDlgItemText( dlg, IDC_PROXY_PWD, t, DIM (t)-1);
58      ncount = GetDlgItemText( dlg, IDC_PROXY_HOST, t, DIM (t)-1);      if( ncount )
59      if (ncount) {          ctx->pass = strdup( t );
60          if (check_IP_or_hostname (t)) {      ncount = GetDlgItemText( dlg, IDC_PROXY_USER, t, DIM (t)-1);
61              msg_box (dlg, _("Invalid host/IP address."), _("Proxy Settings"), MB_ERR);      if( ncount )
62              return -1;          ctx->user = strdup( t );
63          }      ncount = GetDlgItemText( dlg, IDC_PROXY_HOST, t, DIM (t)-1);
64          /* XXX: check prefix */      if (ncount) {
65          if (!strncmp (t, "http://", 7))          if (check_IP_or_hostname (t)) {
66              pos = 7;              msg_box (dlg, _("Invalid host/IP address."), _("Proxy Settings"), MB_ERR);
67          ctx->host = strdup (t + pos);              return -1;
68      }          }
69      if (check_number (dlg, IDC_PROXY_PORT)) {          /* XXX: check prefix */
70          msg_box (dlg, _("Invalid port number."), _("Proxy Settings"), MB_ERR);          if (!strncmp (t, "http://", 7))
71          return -1;              pos = 7;
72      }          ctx->host = strdup (t + pos);
73        }
74      ctx->port = GetDlgItemInt( dlg, IDC_PROXY_PORT, NULL, FALSE );      if (check_number (dlg, IDC_PROXY_PORT)) {
75      if( ctx->port < 0 || ctx->port > 65535 ) {          msg_box (dlg, _("Invalid port number."), _("Proxy Settings"), MB_ERR);
76          msg_box( dlg, _("Please select a value from 0-65535 for the port"), _("Proxy Settings"), MB_INFO );          return -1;
77          return -1;      }
78      }  
79      if( ctx->user && !ctx->pass || !ctx->user && ctx->pass ) {      ctx->port = GetDlgItemInt( dlg, IDC_PROXY_PORT, NULL, FALSE );
80          msg_box( dlg, _("When you want to use authentication, "      if( ctx->port < 0 || ctx->port > 65535 ) {
81                                  "please fill out both fields."), _("Proxy Settings"), MB_ERR );          msg_box (dlg, _("Please select a value from 0-65535 for the port"),
82          return -1;                  _("Proxy Settings"), MB_INFO);
83      }          return -1;
84      if( ctx->host && !ctx->port || !ctx->host && ctx->port ) {      }
85          msg_box( dlg, _("Please enter a host name and a port."), _("Proxy Settings"), MB_INFO );      if( ctx->user && !ctx->pass || !ctx->user && ctx->pass ) {
86          return -1;          msg_box (dlg, _("When you want to use authentication, "
87      }                          "please fill out both fields."), _("Proxy Settings"), MB_ERR);
88      return 0;          return -1;
89  } /* read_proxy */      }
90        if (ctx->host && !ctx->port || !ctx->host && ctx->port) {
91            msg_box (dlg, _("Please enter a host name and a port."),
92  static void                   _("Proxy Settings"), MB_INFO);
93  enable_proxy_auth (HWND dlg, int val)          return -1;
94  {      }
95      int mode = val? TRUE : FALSE;      return 0;
96      EnableWindow (GetDlgItem (dlg, IDC_PROXY_PWD), mode);  }
97      EnableWindow (GetDlgItem (dlg, IDC_PROXY_USER), mode);  
98  }  
99    static void
100    enable_proxy_auth (HWND dlg, int val)
101  BOOL CALLBACK  {
102  keyserver_proxy_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)      int mode = val? TRUE : FALSE;
103  {      EnableWindow (GetDlgItem (dlg, IDC_PROXY_PWD), mode);
104      const char *proxy = NULL, *user=NULL, *pass = NULL;      EnableWindow (GetDlgItem (dlg, IDC_PROXY_USER), mode);
105      int port = 0, auth = 0;  }
106      int rc = 0;  
107        
108      switch (msg) {  /* Dialog box procedure for proxy authentication. */
109      case WM_INITDIALOG:  BOOL CALLBACK
110          proxy = kserver_get_proxy (&port);  keyserver_proxy_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
111          if (proxy) {  {
112              SetDlgItemText( dlg, IDC_PROXY_HOST, proxy );      const char *proxy = NULL, *user=NULL, *pass = NULL;
113              SetDlgItemInt( dlg, IDC_PROXY_PORT, port, FALSE );      int port = 0, auth = 0;  
114              user = kserver_get_proxy_info( PROXY_USER );      
115              if (user) {      switch (msg) {
116                  SetDlgItemText (dlg, IDC_PROXY_USER, user);      case WM_INITDIALOG:
117                  CheckDlgButton (dlg, IDC_PROXY_AUTH, BST_CHECKED);          proxy = kserver_get_proxy (&port);
118                  auth++;          if (proxy) {
119              }              SetDlgItemText( dlg, IDC_PROXY_HOST, proxy );
120              pass = kserver_get_proxy_info(PROXY_PASS);              SetDlgItemInt( dlg, IDC_PROXY_PORT, port, FALSE );
121              if (pass) {              user = kserver_get_proxy_info (PROXY_USER);
122                  SetDlgItemText( dlg, IDC_PROXY_PWD, pass );              if (user) {
123                  auth++;                  SetDlgItemText (dlg, IDC_PROXY_USER, user);
124              }                  CheckDlgButton (dlg, IDC_PROXY_AUTH, BST_CHECKED);
125          }                  auth++;
126          enable_proxy_auth (dlg, auth);              }
127          center_window (dlg);              pass = kserver_get_proxy_info(PROXY_PASS);
128          SetForegroundWindow (dlg);              if (pass) {
129          break;                  SetDlgItemText( dlg, IDC_PROXY_PWD, pass );
130                            auth++;
131      case WM_SYSCOMMAND:              }
132          if( LOWORD (wparam) == SC_CLOSE)          }
133              EndDialog (dlg, TRUE);          enable_proxy_auth (dlg, auth);  
134          return FALSE;          SetDlgItemText (dlg, IDC_PROXY_HOSTINF, _("Proxy host name or IP address"));
135                    SetDlgItemText (dlg, IDC_PROXY_AUTH, _("Server requires &authentication"));
136      case WM_COMMAND:          SetDlgItemText (dlg, IDC_PROXY_USERINF, _("User name"));
137          switch (HIWORD (wparam)) {          SetDlgItemText (dlg, IDC_PROXY_PWDINF, _("Password"));
138          case BN_CLICKED:          SetWindowText (dlg, _("Proxy Settings"));
139              switch( (int)LOWORD( wparam ) ) {          center_window (dlg, NULL);
140              case IDC_PROXY_AUTH:          SetForegroundWindow (dlg);
141                  if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH))          break;
142                      enable_proxy_auth (dlg, 1);          
143                  else      case WM_SYSCOMMAND:
144                      enable_proxy_auth (dlg, 0);          if( LOWORD (wparam) == SC_CLOSE)
145                  break;              EndDialog (dlg, TRUE);
146              }          return FALSE;
147              break;          
148          }      case WM_COMMAND:
149            switch (HIWORD (wparam)) {
150          switch( LOWORD( wparam ) ) {          case BN_CLICKED:
151          case IDOK:              switch( (int)LOWORD( wparam ) ) {
152              if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH) &&              case IDC_PROXY_AUTH:
153                  item_get_text_length (dlg, IDC_PROXY_HOST) == 0 &&                  if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH))
154                  item_get_text_length (dlg, IDC_PROXY_USER) == 0 &&                      enable_proxy_auth (dlg, 1);
155                  item_get_text_length (dlg, IDC_PROXY_PWD) == 0) {                  else
156                  msg_box (dlg, _("Please fill out all required fields for authentication."),                      enable_proxy_auth (dlg, 0);
157                           _("Proxy Settings"), MB_WARN);                  break;
158                  return FALSE;              }
159              }              break;
160              keyserver_proxy_ctx ctx;                      }
161              memset (&ctx, 0, sizeof (ctx));  
162              if (read_proxy (dlg, &ctx))          switch( LOWORD( wparam ) ) {
163                  return FALSE;          case IDOK:
164              kserver_change_proxy (&ctx);              if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH) &&
165              proxy_release (&ctx);                  item_get_text_length (dlg, IDC_PROXY_HOST) == 0 &&
166              EndDialog (dlg, TRUE);                  item_get_text_length (dlg, IDC_PROXY_USER) == 0 &&
167              return TRUE;                  item_get_text_length (dlg, IDC_PROXY_PWD) == 0) {
168                                msg_box (dlg, _("Please fill out all required fields for authentication."),
169          case IDCANCEL:                           _("Proxy Settings"), MB_WARN);
170              EndDialog (dlg, FALSE);                  return TRUE;
171              return FALSE;              }
172          }              keyserver_proxy_ctx ctx;            
173          break;              memset (&ctx, 0, sizeof (ctx));
174      }              if (read_proxy (dlg, &ctx))
175                        return FALSE;
176      return FALSE;              kserver_change_proxy (&ctx);
177  } /* keyserver_proxy_dlg_proc */              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    }

Legend:
Removed from v.22  
changed lines
  Added in v.78

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26