]> cygwin.com Git - cygwin-apps/setup.git/blob - netio.cc
* geturl.cc (get_url_to_file): Add parameter `allow_ftp_auth'.
[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 static char *cvsid = "\n%%% $Id$\n";
21
22 #include "win32.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "resource.h"
28 #include "state.h"
29 #include "msg.h"
30 #include "netio.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 #include "log.h"
37
38 #include "port.h"
39
40 NetIO::NetIO (char *Purl, BOOL allow_ftp_auth)
41 {
42 set_url (Purl);
43 ftp_auth = allow_ftp_auth;
44 }
45
46 NetIO::~NetIO ()
47 {
48 if (url)
49 free (url);
50 if (proto)
51 free (proto);
52 if (host)
53 free (host);
54 if (path)
55 free (path);
56 }
57
58 void
59 NetIO::set_url (char *Purl)
60 {
61 char *bp, *ep, c;
62
63 file_size = 0;
64 url = _strdup (Purl);
65 proto = 0;
66 host = 0;
67 port = 0;
68 path = 0;
69
70 bp = url;
71 ep = strstr (bp, "://");
72 if (!ep)
73 {
74 path = url;
75 return;
76 }
77
78 *ep = 0;
79 proto = _strdup (bp);
80 *ep = ':';
81 bp = ep+3;
82
83 ep = bp + strcspn (bp, ":/");
84 c = *ep;
85 *ep = 0;
86 host = _strdup (bp);
87 *ep = c;
88
89 if (*ep == ':')
90 {
91 port = atoi (ep+1);
92 ep = strchr (ep, '/');
93 }
94
95 if (*ep)
96 path = _strdup (ep);
97 }
98
99 int
100 NetIO::ok ()
101 {
102 return 0;
103 }
104
105 int
106 NetIO::read (char *buf, int nbytes)
107 {
108 return 0;
109 }
110
111 NetIO *
112 NetIO::open (char *url, BOOL allow_ftp_auth)
113 {
114 NetIO *rv = 0;
115 enum {http, ftp, file} proto;
116 if (strncmp (url, "http://", 7) == 0)
117 proto = http;
118 else if (strncmp (url, "ftp://", 6) == 0)
119 proto = ftp;
120 else
121 proto = file;
122
123 if (proto == file)
124 rv = new NetIO_File (url);
125 else if (net_method == IDC_NET_IE5)
126 rv = new NetIO_IE5 (url);
127 else if (net_method == IDC_NET_PROXY)
128 rv = new NetIO_HTTP (url, allow_ftp_auth);
129 else if (net_method == IDC_NET_DIRECT)
130 {
131 switch (proto)
132 {
133 case http:
134 rv = new NetIO_HTTP (url);
135 break;
136 case ftp:
137 rv = new NetIO_FTP (url, allow_ftp_auth);
138 break;
139 }
140 }
141
142 if (!rv->ok ())
143 {
144 delete rv;
145 return 0;
146 }
147
148 return rv;
149 }
150
151
152 static char **user, **passwd;
153 static int loading = 0;
154
155 static void
156 check_if_enable_ok (HWND h)
157 {
158 int e = 0;
159 if (*user && *passwd)
160 e = 1;
161 EnableWindow (GetDlgItem (h, IDOK), e);
162 }
163
164 static void
165 load_dialog (HWND h)
166 {
167 loading = 1;
168 eset (h, IDC_NET_USER, *user);
169 eset (h, IDC_NET_PASSWD, *passwd);
170 check_if_enable_ok (h);
171 loading = 0;
172 }
173
174 static void
175 save_dialog (HWND h)
176 {
177 *user = eget (h, IDC_NET_USER, *user);
178 *passwd = eget (h, IDC_NET_PASSWD, *passwd);
179 }
180
181 static BOOL
182 auth_cmd (HWND h, int id, HWND hwndctl, UINT code)
183 {
184 switch (id)
185 {
186
187 case IDC_NET_USER:
188 case IDC_NET_PASSWD:
189 if (code == EN_CHANGE && !loading)
190 {
191 save_dialog (h);
192 check_if_enable_ok (h);
193 }
194 break;
195
196 case IDOK:
197 save_dialog (h);
198 EndDialog (h, 0);
199 break;
200
201 case IDCANCEL:
202 EndDialog (h, 1);
203 exit_setup (1);
204 break;
205 }
206 }
207
208 static BOOL CALLBACK
209 auth_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
210 {
211 switch (message)
212 {
213 case WM_INITDIALOG:
214 load_dialog (h);
215 return FALSE;
216 case WM_COMMAND:
217 return HANDLE_WM_COMMAND (h, wParam, lParam, auth_cmd);
218 }
219 return FALSE;
220 }
221
222 static int
223 auth_common (HINSTANCE h, int id)
224 {
225 return DialogBox (h, MAKEINTRESOURCE (id), 0, auth_proc);
226 }
227
228 int
229 NetIO::get_auth ()
230 {
231 user = &net_user;
232 passwd = &net_passwd;
233 return auth_common (hinstance, IDD_NET_AUTH);
234 }
235
236 int
237 NetIO::get_proxy_auth ()
238 {
239 user = &net_proxy_user;
240 passwd = &net_proxy_passwd;
241 return auth_common (hinstance, IDD_PROXY_AUTH);
242 }
243
244 int
245 NetIO::get_ftp_auth ()
246 {
247 if (net_ftp_user)
248 {
249 free (net_ftp_user);
250 net_ftp_user = NULL;
251 }
252 if (net_ftp_passwd)
253 {
254 free (net_ftp_passwd);
255 net_ftp_passwd = NULL;
256 }
257 if (!ftp_auth)
258 return IDCANCEL;
259 user = &net_ftp_user;
260 passwd = &net_ftp_passwd;
261 return auth_common (hinstance, IDD_FTP_AUTH);
262 }
This page took 0.050508 seconds and 6 git commands to generate.