]> cygwin.com Git - cygwin-apps/setup.git/blame - netio.cc
2002-05-04 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / netio.cc
CommitLineData
23c9e63c 1/*
85553593 2 * Copyright (c) 2000, 2001, Red Hat, Inc.
23c9e63c
DD
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16/* The purpose of this file is to coordinate the various access
17 methods known to setup. To add a new method, create a pair of
18 nio-*.[ch] files and add the logic to NetIO::open here */
19
b24c88b3
RC
20#if 0
21static const char *cvsid =
22 "\n%%% $Id$\n";
23#endif
8507f105 24
23c9e63c
DD
25#include "win32.h"
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29
30#include "resource.h"
31#include "state.h"
32#include "msg.h"
33#include "netio.h"
34#include "nio-file.h"
35#include "nio-ie5.h"
4a83b7b0
DD
36#include "nio-http.h"
37#include "nio-ftp.h"
4e8ff53f 38#include "dialog.h"
4a83b7b0 39#include "log.h"
23c9e63c
DD
40
41#include "port.h"
42
341988b9 43NetIO::NetIO (char const *Purl, BOOL allow_ftp_auth)
4a83b7b0
DD
44{
45 set_url (Purl);
85553593 46 ftp_auth = allow_ftp_auth;
4a83b7b0
DD
47}
48
49NetIO::~NetIO ()
50{
51 if (url)
5e0464a1 52 delete[] url;
4a83b7b0 53 if (proto)
5e0464a1 54 delete[] proto;
4a83b7b0 55 if (host)
5e0464a1 56 delete[] host;
4a83b7b0 57 if (path)
5e0464a1 58 delete[] path;
4a83b7b0
DD
59}
60
61void
341988b9 62NetIO::set_url (char const *Purl)
23c9e63c
DD
63{
64 char *bp, *ep, c;
65
66 file_size = 0;
5e0464a1
RC
67 url = new char[strlen (Purl) + 1];
68 strcpy (url, Purl);
23c9e63c
DD
69 proto = 0;
70 host = 0;
71 port = 0;
72 path = 0;
73
74 bp = url;
75 ep = strstr (bp, "://");
76 if (!ep)
77 {
78 path = url;
79 return;
80 }
81
82 *ep = 0;
5e0464a1
RC
83 proto = new char [strlen (bp)+1];
84 strcpy (proto, bp);
23c9e63c 85 *ep = ':';
b24c88b3 86 bp = ep + 3;
23c9e63c 87
4a83b7b0 88 ep = bp + strcspn (bp, ":/");
23c9e63c
DD
89 c = *ep;
90 *ep = 0;
5e0464a1
RC
91 host = new char [strlen (bp) + 1];
92 strcpy (host, bp);
23c9e63c
DD
93 *ep = c;
94
95 if (*ep == ':')
96 {
b24c88b3 97 port = atoi (ep + 1);
23c9e63c
DD
98 ep = strchr (ep, '/');
99 }
100
101 if (*ep)
5e0464a1
RC
102 {
103 path = new char [strlen (ep)+1];
104 strcpy (path, ep);
105 }
23c9e63c
DD
106}
107
23c9e63c
DD
108int
109NetIO::ok ()
110{
111 return 0;
112}
113
114int
115NetIO::read (char *buf, int nbytes)
116{
117 return 0;
118}
119
120NetIO *
341988b9 121NetIO::open (char const *url, BOOL allow_ftp_auth)
23c9e63c
DD
122{
123 NetIO *rv = 0;
b24c88b3
RC
124 enum
125 { http, ftp, file }
126 proto;
23c9e63c
DD
127 if (strncmp (url, "http://", 7) == 0)
128 proto = http;
129 else if (strncmp (url, "ftp://", 6) == 0)
130 proto = ftp;
131 else
132 proto = file;
133
134 if (proto == file)
135 rv = new NetIO_File (url);
136 else if (net_method == IDC_NET_IE5)
137 rv = new NetIO_IE5 (url);
23c9e63c 138 else if (net_method == IDC_NET_PROXY)
85553593 139 rv = new NetIO_HTTP (url, allow_ftp_auth);
4a83b7b0
DD
140 else if (net_method == IDC_NET_DIRECT)
141 {
142 switch (proto)
143 {
144 case http:
145 rv = new NetIO_HTTP (url);
146 break;
147 case ftp:
85553593 148 rv = new NetIO_FTP (url, allow_ftp_auth);
4a83b7b0 149 break;
b24c88b3
RC
150 case file:
151 rv = new NetIO_File (url);
152 break;
4a83b7b0
DD
153 }
154 }
23c9e63c
DD
155
156 if (!rv->ok ())
157 {
158 delete rv;
159 return 0;
160 }
161
162 return rv;
163}
4e8ff53f
DD
164
165
166static char **user, **passwd;
348860fa 167static int loading = 0;
4e8ff53f
DD
168
169static void
170check_if_enable_ok (HWND h)
171{
172 int e = 0;
4e8ff53f
DD
173 if (*user && *passwd)
174 e = 1;
175 EnableWindow (GetDlgItem (h, IDOK), e);
176}
177
178static void
179load_dialog (HWND h)
180{
348860fa 181 loading = 1;
4e8ff53f
DD
182 eset (h, IDC_NET_USER, *user);
183 eset (h, IDC_NET_PASSWD, *passwd);
184 check_if_enable_ok (h);
348860fa 185 loading = 0;
4e8ff53f
DD
186}
187
188static void
189save_dialog (HWND h)
190{
191 *user = eget (h, IDC_NET_USER, *user);
192 *passwd = eget (h, IDC_NET_PASSWD, *passwd);
193}
194
195static BOOL
196auth_cmd (HWND h, int id, HWND hwndctl, UINT code)
197{
198 switch (id)
199 {
200
201 case IDC_NET_USER:
202 case IDC_NET_PASSWD:
348860fa
DD
203 if (code == EN_CHANGE && !loading)
204 {
205 save_dialog (h);
206 check_if_enable_ok (h);
207 }
4e8ff53f
DD
208 break;
209
210 case IDOK:
211 save_dialog (h);
212 EndDialog (h, 0);
213 break;
214
215 case IDCANCEL:
216 EndDialog (h, 1);
4a83b7b0 217 exit_setup (1);
4e8ff53f
DD
218 break;
219 }
b24c88b3 220 return 0;
4e8ff53f
DD
221}
222
223static BOOL CALLBACK
224auth_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
225{
226 switch (message)
227 {
228 case WM_INITDIALOG:
229 load_dialog (h);
230 return FALSE;
231 case WM_COMMAND:
232 return HANDLE_WM_COMMAND (h, wParam, lParam, auth_cmd);
233 }
234 return FALSE;
235}
236
237static int
ab57ceaa 238auth_common (HINSTANCE h, int id, HWND owner)
4e8ff53f 239{
ab57ceaa 240 return DialogBox (h, MAKEINTRESOURCE (id), owner, auth_proc);
4e8ff53f
DD
241}
242
243int
ab57ceaa 244NetIO::get_auth (HWND owner)
4e8ff53f
DD
245{
246 user = &net_user;
247 passwd = &net_passwd;
ab57ceaa 248 return auth_common (hinstance, IDD_NET_AUTH, owner);
4e8ff53f
DD
249}
250
251int
ab57ceaa 252NetIO::get_proxy_auth (HWND owner)
4e8ff53f
DD
253{
254 user = &net_proxy_user;
255 passwd = &net_proxy_passwd;
ab57ceaa 256 return auth_common (hinstance, IDD_PROXY_AUTH, owner);
4e8ff53f 257}
85553593
CV
258
259int
ab57ceaa 260NetIO::get_ftp_auth (HWND owner)
85553593
CV
261{
262 if (net_ftp_user)
263 {
5e0464a1 264 delete[] net_ftp_user;
85553593
CV
265 net_ftp_user = NULL;
266 }
267 if (net_ftp_passwd)
268 {
5e0464a1 269 delete[] net_ftp_passwd;
85553593
CV
270 net_ftp_passwd = NULL;
271 }
272 if (!ftp_auth)
273 return IDCANCEL;
274 user = &net_ftp_user;
275 passwd = &net_ftp_passwd;
ab57ceaa 276 return auth_common (hinstance, IDD_FTP_AUTH, owner);
85553593 277}
This page took 0.053819 seconds and 5 git commands to generate.