]> cygwin.com Git - cygwin-apps/setup.git/blame - netio.cc
Show overall progress for checking packages in package cache
[cygwin-apps/setup.git] / netio.cc
CommitLineData
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
a77b6167
MB
20#include "netio.h"
21
5fa64c3c 22#include "LogFile.h"
a77b6167 23
23c9e63c
DD
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27
94085635
SG
28#include <shlwapi.h>
29
23c9e63c
DD
30#include "resource.h"
31#include "state.h"
32#include "msg.h"
23c9e63c 33#include "nio-ie5.h"
4e8ff53f 34#include "dialog.h"
23c9e63c 35
071f7af3
MB
36int NetIO::net_method;
37char *NetIO::net_proxy_host;
38int NetIO::net_proxy_port;
39
40char *NetIO::net_user;
41char *NetIO::net_passwd;
42char *NetIO::net_proxy_user;
43char *NetIO::net_proxy_passwd;
44char *NetIO::net_ftp_user;
45char *NetIO::net_ftp_passwd;
46
23c9e63c
DD
47int
48NetIO::ok ()
49{
50 return 0;
51}
52
53int
54NetIO::read (char *buf, int nbytes)
55{
56 return 0;
57}
58
59NetIO *
ca875ed3 60NetIO::open (char const *url, bool cachable)
23c9e63c
DD
61{
62 NetIO *rv = 0;
595eaf37
SG
63 std::string file_url;
64
b24c88b3 65 enum
ca875ed3 66 { http, https, ftp, ftps, file }
b24c88b3 67 proto;
23c9e63c
DD
68 if (strncmp (url, "http://", 7) == 0)
69 proto = http;
ca875ed3
JT
70 else if (strncmp (url, "https://", 8) == 0)
71 proto = https;
23c9e63c
DD
72 else if (strncmp (url, "ftp://", 6) == 0)
73 proto = ftp;
ca875ed3
JT
74 else if (strncmp (url, "ftps://", 7) == 0)
75 proto = ftps;
595eaf37 76 else if (strncmp (url, "file://", 7) == 0)
94085635
SG
77 {
78 proto = file;
79
80 // WinInet expects a 'legacy' file:// URL
81 // (i.e. a windows path with "file://" prepended)
82 // https://blogs.msdn.microsoft.com/freeassociations/2005/05/19/the-bizarre-and-unhappy-story-of-file-urls/
83 char path[MAX_PATH];
84 DWORD len = MAX_PATH;
85 if (S_OK == PathCreateFromUrl(url, path, &len, 0))
86 {
87 file_url = std::string("file://") + path;
88 url = file_url.c_str();
89 }
90 }
595eaf37 91 else
94085635 92 // treat everything else as a windows path
595eaf37
SG
93 {
94 proto = file;
94085635 95 file_url = std::string("file://") + url;
595eaf37
SG
96 url = file_url.c_str();
97 }
23c9e63c 98
f75381c6 99 rv = new NetIO_IE5 (url, proto == file ? false : cachable);
23c9e63c 100
ca875ed3 101 if (rv && !rv->ok ())
23c9e63c
DD
102 {
103 delete rv;
104 return 0;
105 }
106
107 return rv;
108}
4e8ff53f
DD
109
110
111static char **user, **passwd;
348860fa 112static int loading = 0;
4e8ff53f
DD
113
114static void
115check_if_enable_ok (HWND h)
116{
117 int e = 0;
ed6137e5 118 if (*user)
4e8ff53f
DD
119 e = 1;
120 EnableWindow (GetDlgItem (h, IDOK), e);
121}
122
123static void
124load_dialog (HWND h)
125{
348860fa 126 loading = 1;
4e8ff53f
DD
127 eset (h, IDC_NET_USER, *user);
128 eset (h, IDC_NET_PASSWD, *passwd);
129 check_if_enable_ok (h);
348860fa 130 loading = 0;
4e8ff53f
DD
131}
132
133static void
134save_dialog (HWND h)
135{
136 *user = eget (h, IDC_NET_USER, *user);
137 *passwd = eget (h, IDC_NET_PASSWD, *passwd);
ed6137e5
MB
138 if (! *passwd) {
139 *passwd = new char[1];
a2046f55 140 (*passwd)[0] = '\0';
ed6137e5 141 }
4e8ff53f
DD
142}
143
144static BOOL
145auth_cmd (HWND h, int id, HWND hwndctl, UINT code)
146{
147 switch (id)
148 {
149
150 case IDC_NET_USER:
151 case IDC_NET_PASSWD:
348860fa
DD
152 if (code == EN_CHANGE && !loading)
153 {
154 save_dialog (h);
155 check_if_enable_ok (h);
156 }
4e8ff53f
DD
157 break;
158
159 case IDOK:
160 save_dialog (h);
161 EndDialog (h, 0);
162 break;
163
164 case IDCANCEL:
165 EndDialog (h, 1);
5fa64c3c 166 Logger ().exit (1);
4e8ff53f
DD
167 break;
168 }
b24c88b3 169 return 0;
4e8ff53f
DD
170}
171
e08abe3f 172static INT_PTR CALLBACK
4e8ff53f
DD
173auth_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
174{
175 switch (message)
176 {
177 case WM_INITDIALOG:
178 load_dialog (h);
179 return FALSE;
180 case WM_COMMAND:
4875ac88
MB
181 auth_cmd (h, LOWORD(wParam), (HWND)lParam, HIWORD(wParam));
182 return 0;
4e8ff53f
DD
183 }
184 return FALSE;
185}
186
187static int
ab57ceaa 188auth_common (HINSTANCE h, int id, HWND owner)
4e8ff53f 189{
ab57ceaa 190 return DialogBox (h, MAKEINTRESOURCE (id), owner, auth_proc);
4e8ff53f
DD
191}
192
193int
ab57ceaa 194NetIO::get_auth (HWND owner)
4e8ff53f
DD
195{
196 user = &net_user;
197 passwd = &net_passwd;
ab57ceaa 198 return auth_common (hinstance, IDD_NET_AUTH, owner);
4e8ff53f
DD
199}
200
201int
ab57ceaa 202NetIO::get_proxy_auth (HWND owner)
4e8ff53f
DD
203{
204 user = &net_proxy_user;
205 passwd = &net_proxy_passwd;
ab57ceaa 206 return auth_common (hinstance, IDD_PROXY_AUTH, owner);
4e8ff53f 207}
85553593
CV
208
209int
ab57ceaa 210NetIO::get_ftp_auth (HWND owner)
85553593
CV
211{
212 if (net_ftp_user)
213 {
5e0464a1 214 delete[] net_ftp_user;
85553593
CV
215 net_ftp_user = NULL;
216 }
217 if (net_ftp_passwd)
218 {
5e0464a1 219 delete[] net_ftp_passwd;
85553593
CV
220 net_ftp_passwd = NULL;
221 }
85553593
CV
222 user = &net_ftp_user;
223 passwd = &net_ftp_passwd;
ab57ceaa 224 return auth_common (hinstance, IDD_FTP_AUTH, owner);
85553593 225}
ca875ed3
JT
226
227const char *
228NetIO::net_method_name ()
229{
230 switch (net_method)
231 {
4b615680
SG
232 case IDC_NET_PRECONFIG:
233 return "Preconfig";
ca875ed3
JT
234 case IDC_NET_DIRECT:
235 return "Direct";
236 case IDC_NET_PROXY:
237 return "Proxy";
ca875ed3
JT
238 default:
239 return "Unknown";
240 }
241}
This page took 0.13876 seconds and 5 git commands to generate.