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