From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19177 invoked by alias); 28 Apr 2017 12:13:34 -0000 Mailing-List: contact cygwin-apps-help@cygwin.com; run by ezmlm Precedence: bulk Sender: cygwin-apps-owner@cygwin.com List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Mail-Followup-To: cygwin-apps@cygwin.com Received: (qmail 19087 invoked by uid 89); 28 Apr 2017 12:13:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=radio, Progress, boxes, 3731 X-HELO: rgout01.bt.lon5.cpcloud.co.uk Received: from rgout01.bt.lon5.cpcloud.co.uk (HELO rgout01.bt.lon5.cpcloud.co.uk) (65.20.0.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Apr 2017 12:13:29 +0000 X-OWM-Source-IP: 31.51.207.210 (GB) X-OWM-Env-Sender: jonturney@btinternet.com X-Junkmail-Premium-Raw: score=8/50,refid=2.7.2:2017.4.26.2416:17:8.707,ip=,rules=NO_URI_FOUND, NO_CTA_URI_FOUND, NO_MESSAGE_ID, NO_URI_HTTPS, TO_MALFORMED Received: from localhost.localdomain (31.51.207.210) by rgout01.bt.lon5.cpcloud.co.uk (9.0.019.13-1) (authenticated as jonturney@btinternet.com) id 58F62BE3012F5837; Fri, 28 Apr 2017 13:13:31 +0100 From: Jon Turney To: cygwin-apps@cygwin.com Cc: Jon Turney Subject: [PATCH setup 11/11] Use wininet for fetching URLs in direct (non-proxy) case (DO NOT APPLY) Date: Fri, 28 Apr 2017 12:13:00 -0000 Message-Id: <20170428121205.12240-12-jon.turney@dronecode.org.uk> In-Reply-To: <20170428121205.12240-1-jon.turney@dronecode.org.uk> References: <20170428121205.12240-1-jon.turney@dronecode.org.uk> X-SW-Source: 2017-04/txt/msg00097.txt.bz2 >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)'. Problems with this patch: No progress feedback as we download. We just get handed the whole file by wininet. Files are cached by wininet. This is good for setup.ini, as we don't fetch it again when it hasn't changed, but bad for package archives as we end up with two copies (one in wininet's cache and one in setup's cache). 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 --- ConnectionSetting.cc | 5 +++++ net.cc | 34 +++++++++++++++++----------------- netio.cc | 32 +++++++++++++++++++++++++++++--- netio.h | 2 ++ nio-ie5.cc | 23 ++++++++++++++--------- nio-ie5.h | 2 +- res.rc | 2 ++ resource.h | 1 + 8 files changed, 71 insertions(+), 30 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/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..76d0c8a 100644 --- a/netio.cc +++ b/netio.cc @@ -126,22 +126,28 @@ NetIO::open (char const *url) { 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); 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); + 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..ca2d55d 100644 --- a/netio.h +++ b/netio.h @@ -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..5aab75b 100644 --- a/nio-ie5.cc +++ b/nio-ie5.cc @@ -27,28 +27,33 @@ #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): 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); + connection = InternetOpenUrl (*internet, url, NULL, 0, flags, 0); try_again: diff --git a/nio-ie5.h b/nio-ie5.h index 801cf8a..02a9b5b 100644 --- a/nio-ie5.h +++ b/nio-ie5.h @@ -22,7 +22,7 @@ class NetIO_IE5:public NetIO { HINTERNET connection; public: - NetIO_IE5 (char const *url); + NetIO_IE5 (char const *url, bool direct); ~NetIO_IE5 (); virtual int ok (); virtual int read (char *buf, int nbytes); diff --git a/res.rc b/res.rc index aad74ac..8f1ab10 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 | 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 -- 2.12.2