]> cygwin.com Git - cygwin-apps/setup.git/blame_incremental - netio.cc
Use solver to check for problems and produce a list of package transactions
[cygwin-apps/setup.git] / netio.cc
... / ...
CommitLineData
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#include "netio.h"
21
22#include "LogFile.h"
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27
28#include "resource.h"
29#include "state.h"
30#include "msg.h"
31#include "nio-file.h"
32#include "nio-ie5.h"
33#include "nio-http.h"
34#include "nio-ftp.h"
35#include "dialog.h"
36
37int NetIO::net_method;
38char *NetIO::net_proxy_host;
39int NetIO::net_proxy_port;
40
41char *NetIO::net_user;
42char *NetIO::net_passwd;
43char *NetIO::net_proxy_user;
44char *NetIO::net_proxy_passwd;
45char *NetIO::net_ftp_user;
46char *NetIO::net_ftp_passwd;
47
48NetIO::NetIO (char const *Purl)
49{
50 set_url (Purl);
51}
52
53NetIO::~NetIO ()
54{
55 if (url)
56 delete[] url;
57 if (proto)
58 delete[] proto;
59 if (host)
60 delete[] host;
61 if (path)
62 delete[] path;
63}
64
65void
66NetIO::set_url (char const *Purl)
67{
68 char *bp, *ep, c;
69
70 file_size = 0;
71 url = new char[strlen (Purl) + 1];
72 strcpy (url, Purl);
73 proto = 0;
74 host = 0;
75 port = 0;
76 path = 0;
77
78 bp = url;
79 ep = strstr (bp, "://");
80 if (!ep)
81 {
82 path = strdup (url);
83 return;
84 }
85
86 *ep = 0;
87 proto = new char [strlen (bp)+1];
88 strcpy (proto, bp);
89 *ep = ':';
90 bp = ep + 3;
91
92 ep = bp + strcspn (bp, ":/");
93 c = *ep;
94 *ep = 0;
95 host = new char [strlen (bp) + 1];
96 strcpy (host, bp);
97 *ep = c;
98
99 if (*ep == ':')
100 {
101 port = atoi (ep + 1);
102 ep = strchr (ep, '/');
103 }
104
105 if (*ep)
106 {
107 path = new char [strlen (ep)+1];
108 strcpy (path, ep);
109 }
110}
111
112int
113NetIO::ok ()
114{
115 return 0;
116}
117
118int
119NetIO::read (char *buf, int nbytes)
120{
121 return 0;
122}
123
124NetIO *
125NetIO::open (char const *url, bool cachable)
126{
127 NetIO *rv = 0;
128 enum
129 { http, https, ftp, ftps, file }
130 proto;
131 if (strncmp (url, "http://", 7) == 0)
132 proto = http;
133 else if (strncmp (url, "https://", 8) == 0)
134 proto = https;
135 else if (strncmp (url, "ftp://", 6) == 0)
136 proto = ftp;
137 else if (strncmp (url, "ftps://", 7) == 0)
138 proto = ftps;
139 else
140 proto = file;
141
142 if (proto == file)
143 rv = new NetIO_File (url);
144 else if (net_method == IDC_NET_IE5)
145 rv = new NetIO_IE5 (url, false, cachable);
146 else if (net_method == IDC_NET_PROXY)
147 rv = new NetIO_HTTP (url);
148 else if (net_method == IDC_NET_DIRECT)
149 rv = new NetIO_IE5 (url, true, cachable);
150 else if (net_method == IDC_NET_DIRECT_LEGACY)
151 {
152 switch (proto)
153 {
154 case http:
155 rv = new NetIO_HTTP (url);
156 break;
157 case ftp:
158 rv = new NetIO_FTP (url);
159 break;
160 case file:
161 rv = new NetIO_File (url);
162 break;
163 default:
164 mbox (NULL, "Protocol not handled by legacy URL handler", "Cygwin Setup", MB_OK);
165 }
166 }
167
168 if (rv && !rv->ok ())
169 {
170 delete rv;
171 return 0;
172 }
173
174 return rv;
175}
176
177
178static char **user, **passwd;
179static int loading = 0;
180
181static void
182check_if_enable_ok (HWND h)
183{
184 int e = 0;
185 if (*user)
186 e = 1;
187 EnableWindow (GetDlgItem (h, IDOK), e);
188}
189
190static void
191load_dialog (HWND h)
192{
193 loading = 1;
194 eset (h, IDC_NET_USER, *user);
195 eset (h, IDC_NET_PASSWD, *passwd);
196 check_if_enable_ok (h);
197 loading = 0;
198}
199
200static void
201save_dialog (HWND h)
202{
203 *user = eget (h, IDC_NET_USER, *user);
204 *passwd = eget (h, IDC_NET_PASSWD, *passwd);
205 if (! *passwd) {
206 *passwd = new char[1];
207 passwd[0] = '\0';
208 }
209}
210
211static BOOL
212auth_cmd (HWND h, int id, HWND hwndctl, UINT code)
213{
214 switch (id)
215 {
216
217 case IDC_NET_USER:
218 case IDC_NET_PASSWD:
219 if (code == EN_CHANGE && !loading)
220 {
221 save_dialog (h);
222 check_if_enable_ok (h);
223 }
224 break;
225
226 case IDOK:
227 save_dialog (h);
228 EndDialog (h, 0);
229 break;
230
231 case IDCANCEL:
232 EndDialog (h, 1);
233 Logger ().exit (1);
234 break;
235 }
236 return 0;
237}
238
239static INT_PTR CALLBACK
240auth_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
241{
242 switch (message)
243 {
244 case WM_INITDIALOG:
245 load_dialog (h);
246 return FALSE;
247 case WM_COMMAND:
248 auth_cmd (h, LOWORD(wParam), (HWND)lParam, HIWORD(wParam));
249 return 0;
250 }
251 return FALSE;
252}
253
254static int
255auth_common (HINSTANCE h, int id, HWND owner)
256{
257 return DialogBox (h, MAKEINTRESOURCE (id), owner, auth_proc);
258}
259
260int
261NetIO::get_auth (HWND owner)
262{
263 user = &net_user;
264 passwd = &net_passwd;
265 return auth_common (hinstance, IDD_NET_AUTH, owner);
266}
267
268int
269NetIO::get_proxy_auth (HWND owner)
270{
271 user = &net_proxy_user;
272 passwd = &net_proxy_passwd;
273 return auth_common (hinstance, IDD_PROXY_AUTH, owner);
274}
275
276int
277NetIO::get_ftp_auth (HWND owner)
278{
279 if (net_ftp_user)
280 {
281 delete[] net_ftp_user;
282 net_ftp_user = NULL;
283 }
284 if (net_ftp_passwd)
285 {
286 delete[] net_ftp_passwd;
287 net_ftp_passwd = NULL;
288 }
289 if (!ftp_auth)
290 return IDCANCEL;
291 user = &net_ftp_user;
292 passwd = &net_ftp_passwd;
293 return auth_common (hinstance, IDD_FTP_AUTH, owner);
294}
295
296const char *
297NetIO::net_method_name ()
298{
299 switch (net_method)
300 {
301 case IDC_NET_IE5:
302 return "IE5";
303 case IDC_NET_DIRECT:
304 return "Direct";
305 case IDC_NET_PROXY:
306 return "Proxy";
307 case IDC_NET_DIRECT_LEGACY:
308 return "Direct (legacy)";
309 default:
310 return "Unknown";
311 }
312}
This page took 0.070781 seconds and 5 git commands to generate.