From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 100517 invoked by alias); 2 May 2017 11:17:37 -0000 Mailing-List: contact cygwin-apps-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-apps-cvs-owner@sourceware.org Received: (qmail 100454 invoked by uid 9795); 2 May 2017 11:17:36 -0000 Date: Tue, 02 May 2017 11:17:00 -0000 Message-ID: <20170502111736.100425.qmail@sourceware.org> From: jturney@sourceware.org To: cygwin-apps-cvs@sourceware.org Subject: [setup - the official Cygwin setup program used to install Cygwin and keep it up to date] branch master, updated. release_2.878 X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 451e2119adb4caf61badf4d43e550ed3a3de3d1b X-Git-Newrev: 60800b0ec9e4ba2c37edd51d4877a717cf9e722e X-SW-Source: 2017-q2/txt/msg00018.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=60800b0ec9e4ba2c37edd51d4877a717cf9e722e commit 60800b0ec9e4ba2c37edd51d4877a717cf9e722e Author: Jon Turney Date: Mon May 1 23:38:20 2017 +0100 Update displayed copyright to 2017 https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=ca875ed36958ba7cca816bddda6028b0c5068a67 commit ca875ed36958ba7cca816bddda6028b0c5068a67 Author: Jon Turney Date: Thu Mar 30 11:48:44 2017 +0100 Use wininet for fetching URLs in direct (non-proxy) case From the discussion in [1], I was somewhat surprised to learn that setup doesn't support https or ftps. Switch to using wininet for fetching URLs in the direct (non-proxy) case, as well. (It's already used in proxy case). This allows https and ftps protocols to be used. For the moment, we keep around the existing, hand-built URL fetching as 'Direct (legacy)'. Arrange for mirrors.lst and setup.ini to be cached by wininet, but not package archives (as setup maintains it's own cache of those) Read from wininet in 64K chunks rather than the whole file, so we can report progress feedback as we download. Close rather than leak InternetOpenUrl() handles with errors. Also fix up some bad indentation. I think the reason we have a handbuilt HTTP client is that back in 2000 or so, we were concerned about the case where IE5 wasn't installed and so wininet wasn't available. But who knows... [1] https://cygwin.com/ml/cygwin/2017-03/msg00384.html Diff: --- ConnectionSetting.cc | 5 +++++ geturl.cc | 4 ++-- net.cc | 34 +++++++++++++++++----------------- netio.cc | 34 ++++++++++++++++++++++++++++++---- netio.h | 4 +++- nio-ie5.cc | 35 ++++++++++++++++++++++++++--------- nio-ie5.h | 4 ++-- res.rc | 4 +++- resource.h | 1 + 9 files changed, 89 insertions(+), 36 deletions(-) diff --git a/ConnectionSetting.cc b/ConnectionSetting.cc index 5baf76c..1154d94 100644 --- a/ConnectionSetting.cc +++ b/ConnectionSetting.cc @@ -49,6 +49,9 @@ ConnectionSetting::~ConnectionSetting () sprintf(port_str, "%d", NetIO::net_proxy_port); UserSettings::instance().set("net-proxy-port", port_str); break; + case IDC_NET_DIRECT_LEGACY: + UserSettings::instance().set("net-method", "Legacy"); + break; default: break; } @@ -63,6 +66,8 @@ ConnectionSetting::typeFromString(const std::string& aType) return IDC_NET_IE5; if (!casecompare(aType, "Proxy")) return IDC_NET_PROXY; + if (!casecompare(aType, "Legacy")) + return IDC_NET_DIRECT_LEGACY; /* A sanish default */ return IDC_NET_IE5; diff --git a/geturl.cc b/geturl.cc index 17ad8e9..53c0a3b 100644 --- a/geturl.cc +++ b/geturl.cc @@ -111,7 +111,7 @@ getUrlToStream (const string &_url, io_stream *output) Log (LOG_BABBLE) << "getUrlToStream " << _url << endLog; is_local_install = (source == IDC_SOURCE_LOCALDIR); init_dialog (_url, 0); - NetIO *n = NetIO::open (_url.c_str()); + NetIO *n = NetIO::open (_url.c_str(), true); if (!n || !n->ok ()) { delete n; @@ -213,7 +213,7 @@ get_url_to_file (const string &_url, remove (_filename.c_str()); /* but ignore errors */ - NetIO *n = NetIO::open (_url.c_str()); + NetIO *n = NetIO::open (_url.c_str(), false); if (!n || !n->ok ()) { delete n; diff --git a/net.cc b/net.cc index 659cf9b..903f096 100644 --- a/net.cc +++ b/net.cc @@ -37,30 +37,31 @@ extern ThreeBarProgressPage Progress; static StringOption ProxyOption ("", 'p', "proxy", "HTTP/FTP proxy (host:port)", false); -static int rb[] = { IDC_NET_IE5, IDC_NET_DIRECT, IDC_NET_PROXY, 0 }; +static int rb[] = { IDC_NET_IE5, IDC_NET_DIRECT, IDC_NET_PROXY, IDC_NET_DIRECT_LEGACY, 0 }; static bool doing_loading = false; void NetPage::CheckIfEnableNext () { - int e = 0, p = 0, pu = 0; + int e = 0, p = 0; DWORD ButtonFlags = PSWIZB_BACK; - if (NetIO::net_method == IDC_NET_IE5) - pu = 1; - if (NetIO::net_method == IDC_NET_IE5 || NetIO::net_method == IDC_NET_DIRECT) + if (NetIO::net_method == IDC_NET_IE5 || + NetIO::net_method == IDC_NET_DIRECT || + NetIO::net_method == IDC_NET_DIRECT_LEGACY) e = 1; else if (NetIO::net_method == IDC_NET_PROXY) { - p = pu = 1; + p = 1; if (NetIO::net_proxy_host && NetIO::net_proxy_port) - e = 1; + e = 1; + } + + if (e) + { + // There's something in the proxy and port boxes, enable "Next". + ButtonFlags |= PSWIZB_NEXT; } - if (e) - { - // There's something in the proxy and port boxes, enable "Next". - ButtonFlags |= PSWIZB_NEXT; - } GetOwner ()->SetButtons (ButtonFlags); @@ -131,8 +132,8 @@ NetPage::OnInit () // Check to see if any radio buttons are selected. If not, select a default. if (SendMessage (GetDlgItem (IDC_NET_IE5), BM_GETCHECK, 0, 0) != BST_CHECKED - && SendMessage (GetDlgItem (IDC_NET_PROXY), BM_GETCHECK, 0, 0) - != BST_CHECKED) + && SendMessage (GetDlgItem (IDC_NET_PROXY), BM_GETCHECK, 0, 0) != BST_CHECKED + && SendMessage (GetDlgItem (IDC_NET_DIRECT_LEGACY), BM_GETCHECK, 0, 0) != BST_CHECKED) SendMessage (GetDlgItem (IDC_NET_DIRECT), BM_CLICK, 0, 0); } @@ -141,9 +142,7 @@ NetPage::OnNext () { save_dialog (GetHWND ()); - Log (LOG_PLAIN) << "net: " - << ((NetIO::net_method == IDC_NET_IE5) ? "IE5" : - (NetIO::net_method == IDC_NET_DIRECT) ? "Direct" : "Proxy") << endLog; + Log (LOG_PLAIN) << "net: " << NetIO::net_method_name() << endLog; Progress.SetActivateTask (WM_APP_START_SITE_INFO_DOWNLOAD); return IDD_INSTATUS; @@ -170,6 +169,7 @@ NetPage::OnMessageCmd (int id, HWND hwndctl, UINT code) case IDC_NET_IE5: case IDC_NET_DIRECT: case IDC_NET_PROXY: + case IDC_NET_DIRECT_LEGACY: case IDC_PROXY_HOST: case IDC_PROXY_PORT: save_dialog (GetHWND()); diff --git a/netio.cc b/netio.cc index 5ec0b9a..cf634c1 100644 --- a/netio.cc +++ b/netio.cc @@ -122,26 +122,32 @@ NetIO::read (char *buf, int nbytes) } NetIO * -NetIO::open (char const *url) +NetIO::open (char const *url, bool cachable) { NetIO *rv = 0; enum - { http, ftp, file } + { http, https, ftp, ftps, file } proto; if (strncmp (url, "http://", 7) == 0) proto = http; + else if (strncmp (url, "https://", 8) == 0) + proto = https; else if (strncmp (url, "ftp://", 6) == 0) proto = ftp; + else if (strncmp (url, "ftps://", 7) == 0) + proto = ftps; else proto = file; if (proto == file) rv = new NetIO_File (url); else if (net_method == IDC_NET_IE5) - rv = new NetIO_IE5 (url); + rv = new NetIO_IE5 (url, false, cachable); else if (net_method == IDC_NET_PROXY) rv = new NetIO_HTTP (url); else if (net_method == IDC_NET_DIRECT) + rv = new NetIO_IE5 (url, true, cachable); + else if (net_method == IDC_NET_DIRECT_LEGACY) { switch (proto) { @@ -154,10 +160,12 @@ NetIO::open (char const *url) case file: rv = new NetIO_File (url); break; + default: + mbox (NULL, "Protocol not handled by legacy URL handler", "Cygwin Setup", MB_OK); } } - if (!rv->ok ()) + if (rv && !rv->ok ()) { delete rv; return 0; @@ -284,3 +292,21 @@ NetIO::get_ftp_auth (HWND owner) passwd = &net_ftp_passwd; return auth_common (hinstance, IDD_FTP_AUTH, owner); } + +const char * +NetIO::net_method_name () +{ + switch (net_method) + { + case IDC_NET_IE5: + return "IE5"; + case IDC_NET_DIRECT: + return "Direct"; + case IDC_NET_PROXY: + return "Proxy"; + case IDC_NET_DIRECT_LEGACY: + return "Direct (legacy)"; + default: + return "Unknown"; + } +} diff --git a/netio.h b/netio.h index aa06edb..7b7d13f 100644 --- a/netio.h +++ b/netio.h @@ -51,7 +51,7 @@ public: the given URL. It uses the network setup state in state.h. If anything fails, either the return values is NULL or the returned object is !ok() */ - static NetIO *open (char const *url); + static NetIO *open (char const *url, bool cachable); /* If !ok() that means the transfer isn't happening. */ virtual int ok (); @@ -64,6 +64,8 @@ public: static char *net_proxy_host; static int net_proxy_port; + static const char *net_method_name(); + /* Helper functions for http/ftp protocols. Both return nonzero for "cancel", zero for "ok". They set net_proxy_user, etc, in state.h */ diff --git a/nio-ie5.cc b/nio-ie5.cc index 236c459..daf29ad 100644 --- a/nio-ie5.cc +++ b/nio-ie5.cc @@ -27,28 +27,37 @@ #include "netio.h" #include "nio-ie5.h" -static HINTERNET internet = 0; +static HINTERNET internet_direct = 0; +static HINTERNET internet_preconfig = 0; -NetIO_IE5::NetIO_IE5 (char const *_url): +NetIO_IE5::NetIO_IE5 (char const *_url, bool direct, bool cachable): NetIO (_url) { int resend = 0; + HINTERNET *internet; - if (internet == 0) + if (direct) + internet = &internet_direct; + else + internet = &internet_preconfig; + + if (*internet == 0) { InternetAttemptConnect (0); - internet = InternetOpen ("Cygwin Setup", INTERNET_OPEN_TYPE_PRECONFIG, - NULL, NULL, 0); + *internet = InternetOpen ("Cygwin Setup", + direct ? INTERNET_OPEN_TYPE_DIRECT : INTERNET_OPEN_TYPE_PRECONFIG, + NULL, NULL, 0); } DWORD flags = - // INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_KEEP_CONNECTION | - // INTERNET_FLAG_PRAGMA_NOCACHE | - // INTERNET_FLAG_RELOAD | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_PASSIVE; - connection = InternetOpenUrl (internet, url, NULL, 0, flags, 0); + if (!cachable) { + flags |= INTERNET_FLAG_NO_CACHE_WRITE; + } + + connection = InternetOpenUrl (*internet, url, NULL, 0, flags, 0); try_again: @@ -113,6 +122,7 @@ try_again: } else if (type >= 300) { + InternetCloseHandle (connection); connection = 0; return; } @@ -147,8 +157,15 @@ NetIO_IE5::ok () int NetIO_IE5::read (char *buf, int nbytes) { +#define READ_CHUNK (64 * 1024) + /* Read in chunks rather than the whole file at once, so we can do progress + reporting */ + if (nbytes > READ_CHUNK) + nbytes = READ_CHUNK; + DWORD actual; if (InternetReadFile (connection, buf, nbytes, &actual)) return actual; + return -1; } diff --git a/nio-ie5.h b/nio-ie5.h index 801cf8a..9a66e2a 100644 --- a/nio-ie5.h +++ b/nio-ie5.h @@ -22,8 +22,8 @@ class NetIO_IE5:public NetIO { HINTERNET connection; public: - NetIO_IE5 (char const *url); - ~NetIO_IE5 (); + NetIO_IE5 (char const *url, bool direct, bool cacheable); + ~NetIO_IE5 (); virtual int ok (); virtual int read (char *buf, int nbytes); void flush_io (); diff --git a/res.rc b/res.rc index aad74ac..45b4207 100644 --- a/res.rc +++ b/res.rc @@ -163,6 +163,8 @@ BEGIN BS_AUTORADIOBUTTON | WS_TABSTOP,60,70,185,10 CONTROL "Use HTTP/FTP &Proxy:",IDC_NET_PROXY,"Button", BS_AUTORADIOBUTTON | WS_TABSTOP,60,85,88,10 + CONTROL "&Direct Connection (legacy)",IDC_NET_DIRECT_LEGACY,"Button", + BS_AUTORADIOBUTTON | WS_TABSTOP,60,150,94,10 EDITTEXT IDC_PROXY_HOST,120,105,120,12,ES_AUTOHSCROLL | WS_DISABLED | WS_GROUP EDITTEXT IDC_PROXY_PORT,120,125,30,12,ES_AUTOHSCROLL | @@ -263,7 +265,7 @@ BEGIN "necessary.",IDC_SPLASH_TEXT,115,25,195,90 ICON IDI_CYGWIN,IDC_SPLASH_ICON,4,6,0,0,SS_ICON | SS_REALSIZEIMAGE LTEXT "Version (unknown)",IDC_VERSION,115,127,195,10 - LTEXT "Copyright 2000-2016",IDC_SPLASH_COPYR,115,140,195,8 + LTEXT "Copyright 2000-2017",IDC_SPLASH_COPYR,115,140,195,8 LTEXT "http://www.cygwin.com/",IDC_SPLASH_URL,115,152,90,8 END diff --git a/resource.h b/resource.h index 68e8023..5bbb668 100644 --- a/resource.h +++ b/resource.h @@ -175,3 +175,4 @@ #define IDC_FILE_INUSE_EDIT 590 #define IDC_FILE_INUSE_MSG 591 #define IDC_FILE_INUSE_HELP 592 +#define IDC_NET_DIRECT_LEGACY 593