]>
Commit | Line | Data |
---|---|---|
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 |
21 | static 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 | 43 | NetIO::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 | ||
49 | NetIO::~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 | ||
61 | void | |
341988b9 | 62 | NetIO::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 |
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 * | |
341988b9 | 121 | NetIO::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 | ||
166 | static char **user, **passwd; | |
348860fa | 167 | static int loading = 0; |
4e8ff53f DD |
168 | |
169 | static void | |
170 | check_if_enable_ok (HWND h) | |
171 | { | |
172 | int e = 0; | |
ed6137e5 | 173 | if (*user) |
4e8ff53f DD |
174 | e = 1; |
175 | EnableWindow (GetDlgItem (h, IDOK), e); | |
176 | } | |
177 | ||
178 | static void | |
179 | load_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 | ||
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); | |
ed6137e5 MB |
193 | if (! *passwd) { |
194 | *passwd = new char[1]; | |
195 | passwd[0] = '\0'; | |
196 | } | |
4e8ff53f DD |
197 | } |
198 | ||
199 | static BOOL | |
200 | auth_cmd (HWND h, int id, HWND hwndctl, UINT code) | |
201 | { | |
202 | switch (id) | |
203 | { | |
204 | ||
205 | case IDC_NET_USER: | |
206 | case IDC_NET_PASSWD: | |
348860fa DD |
207 | if (code == EN_CHANGE && !loading) |
208 | { | |
209 | save_dialog (h); | |
210 | check_if_enable_ok (h); | |
211 | } | |
4e8ff53f DD |
212 | break; |
213 | ||
214 | case IDOK: | |
215 | save_dialog (h); | |
216 | EndDialog (h, 0); | |
217 | break; | |
218 | ||
219 | case IDCANCEL: | |
220 | EndDialog (h, 1); | |
9f4a0c62 | 221 | LogSingleton::GetInstance().exit (1); |
4e8ff53f DD |
222 | break; |
223 | } | |
b24c88b3 | 224 | return 0; |
4e8ff53f DD |
225 | } |
226 | ||
227 | static BOOL CALLBACK | |
228 | auth_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) | |
229 | { | |
230 | switch (message) | |
231 | { | |
232 | case WM_INITDIALOG: | |
233 | load_dialog (h); | |
234 | return FALSE; | |
235 | case WM_COMMAND: | |
236 | return HANDLE_WM_COMMAND (h, wParam, lParam, auth_cmd); | |
237 | } | |
238 | return FALSE; | |
239 | } | |
240 | ||
241 | static int | |
ab57ceaa | 242 | auth_common (HINSTANCE h, int id, HWND owner) |
4e8ff53f | 243 | { |
ab57ceaa | 244 | return DialogBox (h, MAKEINTRESOURCE (id), owner, auth_proc); |
4e8ff53f DD |
245 | } |
246 | ||
247 | int | |
ab57ceaa | 248 | NetIO::get_auth (HWND owner) |
4e8ff53f DD |
249 | { |
250 | user = &net_user; | |
251 | passwd = &net_passwd; | |
ab57ceaa | 252 | return auth_common (hinstance, IDD_NET_AUTH, owner); |
4e8ff53f DD |
253 | } |
254 | ||
255 | int | |
ab57ceaa | 256 | NetIO::get_proxy_auth (HWND owner) |
4e8ff53f DD |
257 | { |
258 | user = &net_proxy_user; | |
259 | passwd = &net_proxy_passwd; | |
ab57ceaa | 260 | return auth_common (hinstance, IDD_PROXY_AUTH, owner); |
4e8ff53f | 261 | } |
85553593 CV |
262 | |
263 | int | |
ab57ceaa | 264 | NetIO::get_ftp_auth (HWND owner) |
85553593 CV |
265 | { |
266 | if (net_ftp_user) | |
267 | { | |
5e0464a1 | 268 | delete[] net_ftp_user; |
85553593 CV |
269 | net_ftp_user = NULL; |
270 | } | |
271 | if (net_ftp_passwd) | |
272 | { | |
5e0464a1 | 273 | delete[] net_ftp_passwd; |
85553593 CV |
274 | net_ftp_passwd = NULL; |
275 | } | |
276 | if (!ftp_auth) | |
277 | return IDCANCEL; | |
278 | user = &net_ftp_user; | |
279 | passwd = &net_ftp_passwd; | |
ab57ceaa | 280 | return auth_common (hinstance, IDD_FTP_AUTH, owner); |
85553593 | 281 | } |