]> cygwin.com Git - cygwin-apps/setup.git/blob - netio.cc
2002-01-21 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / netio.cc
1 /*
2 * Copyright (c) 2000, 2001, Red Hat, Inc.
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
20 #if 0
21 static const char *cvsid =
22 "\n%%% $Id$\n";
23 #endif
24
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"
36 #include "nio-http.h"
37 #include "nio-ftp.h"
38 #include "dialog.h"
39 #include "log.h"
40
41 #include "port.h"
42
43 NetIO::NetIO (char const *Purl, BOOL allow_ftp_auth)
44 {
45 set_url (Purl);
46 ftp_auth = allow_ftp_auth;
47 }
48
49 NetIO::~NetIO ()
50 {
51 if (url)
52 delete[] url;
53 if (proto)
54 delete[] proto;
55 if (host)
56 delete[] host;
57 if (path)
58 delete[] path;
59 }
60
61 void
62 NetIO::set_url (char const *Purl)
63 {
64 char *bp, *ep, c;
65
66 file_size = 0;
67 url = new char[strlen (Purl) + 1];
68 strcpy (url, Purl);
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;
83 proto = new char [strlen (bp)+1];
84 strcpy (proto, bp);
85 *ep = ':';
86 bp = ep + 3;
87
88 ep = bp + strcspn (bp, ":/");
89 c = *ep;
90 *ep = 0;
91 host = new char [strlen (bp) + 1];
92 strcpy (host, bp);
93 *ep = c;
94
95 if (*ep == ':')
96 {
97 port = atoi (ep + 1);
98 ep = strchr (ep, '/');
99 }
100
101 if (*ep)
102 {
103 path = new char [strlen (ep)+1];
104 strcpy (path, ep);
105 }
106 }
107
108 int
109 NetIO::ok ()
110 {
111 return 0;
112 }
113
114 int
115 NetIO::read (char *buf, int nbytes)
116 {
117 return 0;
118 }
119
120 NetIO *
121 NetIO::open (char const *url, BOOL allow_ftp_auth)
122 {
123 NetIO *rv = 0;
124 enum
125 { http, ftp, file }
126 proto;
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);
138 else if (net_method == IDC_NET_PROXY)
139 rv = new NetIO_HTTP (url, allow_ftp_auth);
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:
148 rv = new NetIO_FTP (url, allow_ftp_auth);
149 break;
150 case file:
151 rv = new NetIO_File (url);
152 break;
153 }
154 }
155
156 if (!rv->ok ())
157 {
158 delete rv;
159 return 0;
160 }
161
162 return rv;
163 }
164
165
166 static char **user, **passwd;
167 static int loading = 0;
168
169 static void
170 check_if_enable_ok (HWND h)
171 {
172 int e = 0;
173 if (*user && *passwd)
174 e = 1;
175 EnableWindow (GetDlgItem (h, IDOK), e);
176 }
177
178 static void
179 load_dialog (HWND h)
180 {
181 loading = 1;
182 eset (h, IDC_NET_USER, *user);
183 eset (h, IDC_NET_PASSWD, *passwd);
184 check_if_enable_ok (h);
185 loading = 0;
186 }
187
188 static void
189 save_dialog (HWND h)
190 {
191 *user = eget (h, IDC_NET_USER, *user);
192 *passwd = eget (h, IDC_NET_PASSWD, *passwd);
193 }
194
195 static BOOL
196 auth_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:
203 if (code == EN_CHANGE && !loading)
204 {
205 save_dialog (h);
206 check_if_enable_ok (h);
207 }
208 break;
209
210 case IDOK:
211 save_dialog (h);
212 EndDialog (h, 0);
213 break;
214
215 case IDCANCEL:
216 EndDialog (h, 1);
217 exit_setup (1);
218 break;
219 }
220 return 0;
221 }
222
223 static BOOL CALLBACK
224 auth_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
237 static int
238 auth_common (HINSTANCE h, int id, HWND owner)
239 {
240 return DialogBox (h, MAKEINTRESOURCE (id), owner, auth_proc);
241 }
242
243 int
244 NetIO::get_auth (HWND owner)
245 {
246 user = &net_user;
247 passwd = &net_passwd;
248 return auth_common (hinstance, IDD_NET_AUTH, owner);
249 }
250
251 int
252 NetIO::get_proxy_auth (HWND owner)
253 {
254 user = &net_proxy_user;
255 passwd = &net_proxy_passwd;
256 return auth_common (hinstance, IDD_PROXY_AUTH, owner);
257 }
258
259 int
260 NetIO::get_ftp_auth (HWND owner)
261 {
262 if (net_ftp_user)
263 {
264 delete[] net_ftp_user;
265 net_ftp_user = NULL;
266 }
267 if (net_ftp_passwd)
268 {
269 delete[] net_ftp_passwd;
270 net_ftp_passwd = NULL;
271 }
272 if (!ftp_auth)
273 return IDCANCEL;
274 user = &net_ftp_user;
275 passwd = &net_ftp_passwd;
276 return auth_common (hinstance, IDD_FTP_AUTH, owner);
277 }
This page took 0.063665 seconds and 6 git commands to generate.