From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25945 invoked by alias); 24 Feb 2018 15:31:54 -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 25925 invoked by uid 9795); 24 Feb 2018 15:31:54 -0000 Date: Sat, 24 Feb 2018 15:31:00 -0000 Message-ID: <20180224153154.25884.qmail@sourceware.org> From: jturney@sourceware.org To: cygwin-apps-cvs@sourceware.org Subject: [setup - the official Cygwin setup program] branch master, updated. release_2.889-6-g16817b4 X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: a6c216b7b652a131e7fe5d8f46fbbc17b7b29d1f X-Git-Newrev: 16817b45b2c8d67dffcf045eefce5d7ce0989a27 X-SW-Source: 2018-q1/txt/msg00047.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=16817b45b2c8d67dffcf045eefce5d7ce0989a27 commit 16817b45b2c8d67dffcf045eefce5d7ce0989a27 Author: Jon Turney Date: Sun Jan 28 19:43:39 2018 +0000 Remove simpsock.{cc,h} and drop linkage with ws2_32 https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=f75381c6ea1cf99964f76056029f4e4268a90d99 commit f75381c6ea1cf99964f76056029f4e4268a90d99 Author: SZAVAI Gyula Date: Sun Jan 28 19:36:49 2018 +0000 Remove NetIO_HTTP https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=150fc845f2fcde9404700fd9300ec5195ac8e361 commit 150fc845f2fcde9404700fd9300ec5195ac8e361 Author: SZAVAI Gyula Date: Fri Jan 26 17:56:35 2018 +0100 Add Proxy class to encapsulate proxy configuration for NetIO_IE5 Drop Proxy::bypass method (jturney) https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=595eaf377a1f6c9c73eca1ddb7fa953339ddae31 commit 595eaf377a1f6c9c73eca1ddb7fa953339ddae31 Author: SZAVAI Gyula Date: Sun Jan 28 19:20:53 2018 +0000 Remove NetIO_File Convert raw paths into file:// form URLs so WinInet can handle them This maybe changes the set of malformed file:// URLs we handle (which is ok, although it would be nice to know the details), https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=4b615680f519c3c4f79cf640467263defa65707b commit 4b615680f519c3c4f79cf640467263defa65707b Author: SZAVAI Gyula Date: Fri Jan 26 17:56:33 2018 +0100 Rename IDC_NET_IE5 to IDC_NET_PRECONFIG https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=b271fd84fc02ef62acea4e4c22bb02fb3bddc360 commit b271fd84fc02ef62acea4e4c22bb02fb3bddc360 Author: SZAVAI Gyula Date: Sun Jan 28 19:06:49 2018 +0000 Remove direct(legacy) connection type If setup.rc contains net-method:Legacy, it will be silently converted to net-method:IE Diff: --- ConnectionSetting.cc | 11 +-- Makefile.am | 10 +-- net.cc | 17 ++-- netio.cc | 43 +++------- nio-file.cc | 64 -------------- nio-file.h | 31 ------- nio-ftp.cc | 179 --------------------------------------- nio-ftp.h | 41 --------- nio-http.cc | 208 --------------------------------------------- nio-http.h | 39 --------- nio-ie5.cc | 81 ++++++++++++++---- nio-ie5.h | 2 +- res.rc | 4 +- resource.h | 3 +- simpsock.cc | 229 -------------------------------------------------- simpsock.h | 43 ---------- 16 files changed, 90 insertions(+), 915 deletions(-) diff --git a/ConnectionSetting.cc b/ConnectionSetting.cc index 1154d94..2370a20 100644 --- a/ConnectionSetting.cc +++ b/ConnectionSetting.cc @@ -39,7 +39,7 @@ ConnectionSetting::~ConnectionSetting () case IDC_NET_DIRECT: UserSettings::instance().set("net-method", "Direct"); break; - case IDC_NET_IE5: + case IDC_NET_PRECONFIG: UserSettings::instance().set("net-method", "IE"); break; case IDC_NET_PROXY: @@ -49,9 +49,6 @@ 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,12 +60,10 @@ ConnectionSetting::typeFromString(const std::string& aType) if (!casecompare(aType, "Direct")) return IDC_NET_DIRECT; if (!casecompare(aType, "IE")) - return IDC_NET_IE5; + return IDC_NET_PRECONFIG; if (!casecompare(aType, "Proxy")) return IDC_NET_PROXY; - if (!casecompare(aType, "Legacy")) - return IDC_NET_DIRECT_LEGACY; /* A sanish default */ - return IDC_NET_IE5; + return IDC_NET_PRECONFIG; } diff --git a/Makefile.am b/Makefile.am index 37341b9..7a5b2cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -99,7 +99,7 @@ inilint_SOURCES = \ @SETUP@_LDADD = \ libgetopt++/libgetopt++.la -lgcrypt -lgpg-error -llzma -lbz2 -lz -lsolv -lregex \ - -lshlwapi -lcomctl32 -lole32 -lws2_32 -lpsapi -luuid -lntdll -lwininet -lmingw32 + -lshlwapi -lcomctl32 -lole32 -lpsapi -luuid -lntdll -lwininet -lmingw32 @SETUP@_LDFLAGS = -mwindows -Wc,-static -static-libtool-libs @SETUP@_SOURCES = \ AntiVirus.cc \ @@ -194,12 +194,6 @@ inilint_SOURCES = \ netio.h \ nio-ie5.cc \ nio-ie5.h \ - nio-file.cc \ - nio-file.h \ - nio-ftp.cc \ - nio-ftp.h \ - nio-http.cc \ - nio-http.h \ package_db.cc \ package_db.h \ package_depends.h \ @@ -241,8 +235,6 @@ inilint_SOURCES = \ setup_version.c \ sha2.h \ sha2.c \ - simpsock.cc \ - simpsock.h \ site.cc \ site.h \ source.cc \ diff --git a/net.cc b/net.cc index fa6f1e3..ad497ca 100644 --- a/net.cc +++ b/net.cc @@ -37,7 +37,7 @@ 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, IDC_NET_DIRECT_LEGACY, 0 }; +static int rb[] = { IDC_NET_PRECONFIG, IDC_NET_DIRECT, IDC_NET_PROXY, 0 }; static bool doing_loading = false; void @@ -46,9 +46,8 @@ NetPage::CheckIfEnableNext () int e = 0, p = 0; DWORD ButtonFlags = PSWIZB_BACK; - if (NetIO::net_method == IDC_NET_IE5 || - NetIO::net_method == IDC_NET_DIRECT || - NetIO::net_method == IDC_NET_DIRECT_LEGACY) + if (NetIO::net_method == IDC_NET_PRECONFIG || + NetIO::net_method == IDC_NET_DIRECT) e = 1; else if (NetIO::net_method == IDC_NET_PROXY) { @@ -112,7 +111,7 @@ NetPage::OnInit () std::string proxyString (ProxyOption); if (!NetIO::net_method) - NetIO::net_method = IDC_NET_IE5; + NetIO::net_method = IDC_NET_PRECONFIG; if (proxyString.size ()) { @@ -132,9 +131,8 @@ NetPage::OnInit () // Check to see if any radio buttons are selected. If not, select a default. if (SendMessage (GetDlgItem (IDC_NET_DIRECT), 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_IE5), BM_CLICK, 0, 0); + && SendMessage (GetDlgItem (IDC_NET_PROXY), BM_GETCHECK, 0, 0) != BST_CHECKED) + SendMessage (GetDlgItem (IDC_NET_PRECONFIG), BM_CLICK, 0, 0); } long @@ -166,10 +164,9 @@ NetPage::OnMessageCmd (int id, HWND hwndctl, UINT code) { switch (id) { - case IDC_NET_IE5: + case IDC_NET_PRECONFIG: 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 cf634c1..d60f119 100644 --- a/netio.cc +++ b/netio.cc @@ -28,10 +28,7 @@ #include "resource.h" #include "state.h" #include "msg.h" -#include "nio-file.h" #include "nio-ie5.h" -#include "nio-http.h" -#include "nio-ftp.h" #include "dialog.h" int NetIO::net_method; @@ -125,6 +122,8 @@ NetIO * NetIO::open (char const *url, bool cachable) { NetIO *rv = 0; + std::string file_url; + enum { http, https, ftp, ftps, file } proto; @@ -136,35 +135,17 @@ NetIO::open (char const *url, bool cachable) proto = ftp; else if (strncmp (url, "ftps://", 7) == 0) proto = ftps; - else + else if (strncmp (url, "file://", 7) == 0) proto = file; - - if (proto == file) - rv = new NetIO_File (url); - else if (net_method == IDC_NET_IE5) - 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) + else { - switch (proto) - { - case http: - rv = new NetIO_HTTP (url); - break; - case ftp: - rv = new NetIO_FTP (url); - break; - case file: - rv = new NetIO_File (url); - break; - default: - mbox (NULL, "Protocol not handled by legacy URL handler", "Cygwin Setup", MB_OK); - } + proto = file; + file_url = (std::string("file://") + url); + url = file_url.c_str(); } + rv = new NetIO_IE5 (url, proto == file ? false : cachable); + if (rv && !rv->ok ()) { delete rv; @@ -298,14 +279,12 @@ NetIO::net_method_name () { switch (net_method) { - case IDC_NET_IE5: - return "IE5"; + case IDC_NET_PRECONFIG: + return "Preconfig"; 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/nio-file.cc b/nio-file.cc deleted file mode 100644 index fce1b2c..0000000 --- a/nio-file.cc +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2000, Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * A copy of the GNU General Public License can be found at - * http://www.gnu.org/ - * - * Written by DJ Delorie - * - */ - -/* The purpose of this file is to manage access to files stored on the - local disk (i.e. "downloading" setup.ini). Called from netio.cc */ - -#include "win32.h" -#include -#include -#include -#include -#include "netio.h" -#include "nio-file.h" -#include "resource.h" -#include "msg.h" -#include "filemanip.h" -#include "LogSingleton.h" - -NetIO_File::NetIO_File (char const *Purl): -NetIO (Purl) -{ - fd = nt_fopen (path, "rb"); - if (fd) - { - file_size = get_file_size (std::string("file://") + path); - } - else - { - const char *err = strerror (errno); - if (!err) - err = "(unknown error)"; - Log (LOG_BABBLE) << "Can't open " << path << " for reading: " << err << endLog; - } -} - -NetIO_File::~NetIO_File () -{ - if (fd) - fclose ((FILE *) fd); -} - -int -NetIO_File::ok () -{ - return fd ? 1 : 0; -} - -int -NetIO_File::read (char *buf, int nbytes) -{ - return fread (buf, 1, nbytes, (FILE *) fd); -} diff --git a/nio-file.h b/nio-file.h deleted file mode 100644 index fe5e8e0..0000000 --- a/nio-file.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2000, Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * A copy of the GNU General Public License can be found at - * http://www.gnu.org/ - * - * Written by DJ Delorie - * - */ - -#ifndef SETUP_NIO_FILE_H -#define SETUP_NIO_FILE_H - -/* see nio-file.cc */ - -class NetIO_File:public NetIO -{ -public: - NetIO_File (char const *url); - void *fd; - ~NetIO_File (); - virtual int ok (); - virtual int read (char *buf, int nbytes); -}; - -#endif /* SETUP_NIO_FILE_H */ diff --git a/nio-ftp.cc b/nio-ftp.cc deleted file mode 100644 index 65625d5..0000000 --- a/nio-ftp.cc +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2000, 2001, Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * A copy of the GNU General Public License can be found at - * http://www.gnu.org/ - * - * Written by DJ Delorie - * - */ - -/* This file is responsible for implementing all direct FTP protocol - channels. It is intentionally simplistic. */ - -#include "nio-ftp.h" - -#include "LogSingleton.h" - -#include "win32.h" -#include -#include -#include -#include - -#include "resource.h" -#include "state.h" -#include "simpsock.h" - -static SimpleSocket *cmd = 0; -static char *cmd_host = 0; -static int cmd_port = 0; - -static char *last_line; - -static int -ftp_line (SimpleSocket * s) -{ - do - { - last_line = s->gets (); - Log (LOG_BABBLE) << "ftp > " << (last_line ? last_line : "error") - << endLog; - } - while (last_line && (!isdigit (last_line[0]) || last_line[3] != ' ')); - return atoi (last_line ? : "0"); -} - -NetIO_FTP::NetIO_FTP (char const *Purl):NetIO (Purl) -{ - s = 0; - int - code; - - if (port == 0) - port = 21; - -control_reconnect: - if ((cmd_host && strcmp (host, cmd_host) != 0) || port != cmd_port) - { - if (cmd) - cmd->printf ("QUIT\r\n"); - delete cmd; - delete [] cmd_host; - cmd = 0; - cmd_host = 0; - } - - if (cmd == 0) - { - SimpleSocket * - c = new SimpleSocket (host, port); - code = ftp_line (c); - - auth_retry: - if (net_ftp_user) - c->printf ("USER %s\r\n", net_ftp_user); - else - c->printf ("USER anonymous\r\n"); - code = ftp_line (c); - if (code == 331) - { - if (net_ftp_passwd) - c->printf ("PASS %s\r\n", net_ftp_passwd); - else - c->printf ("PASS cygwin-setup@\r\n"); - code = ftp_line (c); - } - if (code == 530) /* Authentication failed, retry */ - { - get_ftp_auth (NULL); - if (net_ftp_user && net_ftp_passwd) - goto auth_retry; - } - - if (code < 200 || code >= 300) - { - delete - c; - return; - } - - cmd = c; - cmd_host = new char [strlen (host) + 1]; - strcpy (cmd_host, host); - cmd_port = port; - - cmd->printf ("TYPE I\r\n"); - code = ftp_line (cmd); - } - - cmd->printf ("PASV\r\n"); - do - { - code = ftp_line (cmd); - } - while (code == 226); /* previous RETR */ - if (code == 421) /* Timeout, retry */ - { - Log (LOG_BABBLE) << "FTP timeout -- reconnecting" << endLog; - delete [] cmd_host; - cmd_host = new char[1]; cmd_host[0] = '\0'; - goto control_reconnect; - } - if (code != 227) - return; - - char * - digit = strpbrk (last_line + 3, "0123456789"); - if (!digit) - return; - - int - i1, i2, i3, i4, p1, p2; - sscanf (digit, "%d,%d,%d,%d,%d,%d", &i1, &i2, &i3, &i4, &p1, &p2); - char - tmp[20]; - sprintf (tmp, "%d.%d.%d.%d", i1, i2, i3, i4); - s = new SimpleSocket (tmp, p1 * 256 + p2); - - cmd->printf ("RETR %s\r\n", path); - code = ftp_line (cmd); - if (code != 150 && code != 125) - { - delete - s; - s = 0; - return; - } -} - -NetIO_FTP::~NetIO_FTP () -{ - if (s) - delete s; -} - -int -NetIO_FTP::ok () -{ - if (s && s->ok ()) - return 1; - return 0; -} - -int -NetIO_FTP::read (char *buf, int nbytes) -{ - int rv; - if (!ok ()) - return 0; - rv = s->read (buf, nbytes); - if (rv == 0) - ftp_line (cmd); - return rv; -} diff --git a/nio-ftp.h b/nio-ftp.h deleted file mode 100644 index 6944fc1..0000000 --- a/nio-ftp.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2000, 2001, Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * A copy of the GNU General Public License can be found at - * http://www.gnu.org/ - * - * Written by DJ Delorie - * - */ - -#ifndef SETUP_NIO_FTP_H -#define SETUP_NIO_FTP_H - -#include "netio.h" - -/* Direct FTP (without proxy) */ - -class SimpleSocket; - -class NetIO_FTP:public NetIO -{ - SimpleSocket *s; - -public: - NetIO_FTP (char const *url); - virtual ~ NetIO_FTP (); - - /* If !ok() that means the transfer isn't happening. */ - virtual int ok (); - - /* Read `nbytes' bytes from the file. Returns zero when the file - is complete. */ - virtual int read (char *buf, int nbytes); -}; - -#endif /* SETUP_NIO_FTP_H */ diff --git a/nio-http.cc b/nio-http.cc deleted file mode 100644 index 413ee7f..0000000 --- a/nio-http.cc +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2000, 2001, Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * A copy of the GNU General Public License can be found at - * http://www.gnu.org/ - * - * Written by DJ Delorie - * - */ - -/* This file is responsible for implementing all direct HTTP protocol - channels. It is intentionally simplistic. */ - -#include "win32.h" -#include -#include -#include - -#include "resource.h" -#include "state.h" -#include "simpsock.h" -#include "msg.h" - -#include "netio.h" -#include "nio-http.h" - -#ifndef _strnicmp -#define _strnicmp strncasecmp -#endif - -static char six2pr[64] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' -}; - -static char * -base64_encode (char *username, char *password) -{ - unsigned char *ep; - char *rp; - static char *rv = 0; - if (rv) - delete[] rv; - rv = new char[2 * (strlen (username) + strlen (password)) + 5]; - - char *up = new char[strlen (username) + strlen (password) + 6]; - strcpy (up, username); - strcat (up, ":"); - strcat (up, password); - ep = (unsigned char *) up + strlen (up); - *ep++ = 0; - *ep++ = 0; - *ep++ = 0; - - char block[4]; - - rp = rv; - - for (ep = (unsigned char *) up; *ep; ep += 3) - { - block[0] = six2pr[ep[0] >> 2]; - block[1] = six2pr[((ep[0] << 4) & 0x30) | ((ep[1] >> 4) & 0x0f)]; - block[2] = six2pr[((ep[1] << 2) & 0x3c) | ((ep[2] >> 6) & 0x03)]; - block[3] = six2pr[ep[2] & 0x3f]; - - if (ep[1] == 0) - block[2] = block[3] = '='; - if (ep[2] == 0) - block[3] = '='; - memcpy (rp, block, 4); - rp += 4; - } - *rp = 0; - - delete[] up; - - return rv; -} - -NetIO_HTTP::NetIO_HTTP (char const *Purl):NetIO (Purl) -{ - std::string url (Purl); -retry_get: - if (port == 0) - port = 80; - - if (net_method == IDC_NET_PROXY) - s = new SimpleSocket (net_proxy_host, net_proxy_port); - else - s = new SimpleSocket (host, port); - - if (!s->ok ()) - { - delete s; - s = NULL; - return; - } - - if (net_method == IDC_NET_PROXY) - s->printf ("GET %s HTTP/1.0\r\n", url.c_str ()); - else - s->printf ("GET %s HTTP/1.0\r\n", path); - - // Default HTTP port is 80. Host header can have no port if requested port - // is the same as the default. Some HTTP servers don't behave as expected - // when they receive a Host header with the unnecessary default port value. - if (port == 80) - s->printf ("Host: %s\r\n", host); - else - s->printf ("Host: %s:%d\r\n", host, port); - - if (net_user && net_passwd) - s->printf ("Authorization: Basic %s\r\n", - base64_encode (net_user, net_passwd)); - - if (net_proxy_user && net_proxy_passwd) - s->printf ("Proxy-Authorization: Basic %s\r\n", - base64_encode (net_proxy_user, net_proxy_passwd)); - - s->printf ("\r\n"); - - char * l = s->gets (); - int code; - if (!l) - return; - sscanf (l, "%*s %d", &code); - if (code >= 300 && code < 400) - { - while ((l = s->gets ()) != 0) - { - if (_strnicmp (l, "Location:", 9) == 0) - { - char * u = l + 9; - while (*u == ' ' || *u == '\t') - u++; - set_url (u); - delete s; - goto retry_get; - } - } - } - if (code == 401) /* authorization required */ - { - get_auth (NULL); - delete s; - goto retry_get; - } - if (code == 407) /* proxy authorization required */ - { - get_proxy_auth (NULL); - delete s; - goto retry_get; - } - if (code == 500 /* ftp authentication through proxy required */ - && net_method == IDC_NET_PROXY - && !url.compare (0, std::string::npos, "ftp://", 6)) - { - get_ftp_auth (NULL); - if (net_ftp_user && net_ftp_passwd) - { - delete s; - url = std::string("ftp://") + net_ftp_user + ":" - + net_ftp_passwd + "@" + url.substr (6); - goto retry_get; - } - } - if (code >= 300) - { - delete s; - s = NULL; - return; - } - - // Eat the header, picking out the Content-Length in the process - while (((l = s->gets ()) != NULL) && (*l != '\0')) - { - if (_strnicmp (l, "Content-Length:", 15) == 0) - sscanf (l, "%*s %d", &file_size); - } -} - -NetIO_HTTP::~NetIO_HTTP () -{ - if (s) - delete s; -} - -int -NetIO_HTTP::ok () -{ - if (s && s->ok ()) - return 1; - return 0; -} - -int -NetIO_HTTP::read (char *buf, int nbytes) -{ - return s->read (buf, nbytes); -} diff --git a/nio-http.h b/nio-http.h deleted file mode 100644 index d3d5102..0000000 --- a/nio-http.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2000, 2001, Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * A copy of the GNU General Public License can be found at - * http://www.gnu.org/ - * - * Written by DJ Delorie - * - */ - -#ifndef SETUP_NIO_HTTP_H -#define SETUP_NIO_HTTP_H - -/* Direct HTTP (with or without proxy) */ - -class SimpleSocket; - -class NetIO_HTTP:public NetIO -{ - SimpleSocket *s; - -public: - NetIO_HTTP (char const *url); - virtual ~ NetIO_HTTP (); - - /* If !ok() that means the transfer isn't happening. */ - virtual int ok (); - - /* Read `nbytes' bytes from the file. Returns zero when the file - is complete. */ - virtual int read (char *buf, int nbytes); -}; - -#endif /* SETUP_NIO_HTTP_H */ diff --git a/nio-ie5.cc b/nio-ie5.cc index a649233..5c93894 100644 --- a/nio-ie5.cc +++ b/nio-ie5.cc @@ -33,9 +33,6 @@ static StringOption UserAgent ("", '\0', "user-agent", "User agent string for HTTP requests"); -static HINTERNET internet_direct = 0; -static HINTERNET internet_preconfig = 0; - const std::string & determine_default_useragent(void) { @@ -63,20 +60,74 @@ determine_default_useragent(void) return default_useragent; } -NetIO_IE5::NetIO_IE5 (char const *_url, bool direct, bool cachable): -NetIO (_url) + +class Proxy { - int resend = 0; - HINTERNET *internet; + int method; + std::string host; + int port; + std::string hostport; // host:port + +public: + Proxy (int method, char const *host, int port) + : method(method), + host(host ? host : ""), + port(port), + hostport(std::string(host ? host : "") + ":" + std::to_string(port)) + {}; + + bool operator!= (const Proxy &o) const; + + DWORD type (void) const; + char const *string (void) const; +}; + +bool Proxy::operator!= (const Proxy &o) const +{ + if (method != o.method) return true; + if (method != IDC_NET_PROXY) return false; + // it's only meaningful to compare host:port for method == IDC_NET_PROXY + if (host != o.host) return true; + if (port != o.port) return true; + return false; +} - if (direct) - internet = &internet_direct; +char const *Proxy::string(void) const +{ + if (method == IDC_NET_PROXY) + return hostport.c_str(); else - internet = &internet_preconfig; + return NULL; +} + +DWORD Proxy::type (void) const +{ + switch (method) + { + case IDC_NET_PROXY: return INTERNET_OPEN_TYPE_PROXY; + case IDC_NET_PRECONFIG: return INTERNET_OPEN_TYPE_PRECONFIG; + default: + case IDC_NET_DIRECT: return INTERNET_OPEN_TYPE_DIRECT; + } +} + +static HINTERNET internet = 0; +static Proxy last_proxy = Proxy(-1, "", -1); + +NetIO_IE5::NetIO_IE5 (char const *_url, bool cachable): +NetIO (_url) +{ + int resend = 0; - if (*internet == 0) + Proxy proxy = Proxy(net_method, net_proxy_host, net_proxy_port); + if (proxy != last_proxy) { - InternetAttemptConnect (0); + last_proxy = proxy; + + if (internet != 0) + InternetCloseHandle(internet); + else + InternetAttemptConnect (0); const char *lpszAgent = determine_default_useragent().c_str(); if (UserAgent.isPresent()) @@ -97,9 +148,7 @@ NetIO (_url) } } - *internet = InternetOpen (lpszAgent, - direct ? INTERNET_OPEN_TYPE_DIRECT : INTERNET_OPEN_TYPE_PRECONFIG, - NULL, NULL, 0); + internet = InternetOpen (lpszAgent, proxy.type(), proxy.string(), NULL, 0); } DWORD flags = @@ -112,7 +161,7 @@ NetIO (_url) flags |= INTERNET_FLAG_RESYNCHRONIZE; } - 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 9a66e2a..a1ee90d 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, bool direct, bool cacheable); + NetIO_IE5 (char const *url, bool cacheable); ~NetIO_IE5 (); virtual int ok (); virtual int read (char *buf, int nbytes); diff --git a/res.rc b/res.rc index ea5411e..921ef03 100644 --- a/res.rc +++ b/res.rc @@ -157,14 +157,12 @@ STYLE DS_MODALFRAME | DS_CENTER | WS_CHILD | WS_CAPTION | WS_SYSMENU CAPTION "Cygwin Setup - Select Connection Type" FONT 8, "MS Shell Dlg" BEGIN - CONTROL "Use &System Proxy Settings",IDC_NET_IE5,"Button", + CONTROL "Use &System Proxy Settings",IDC_NET_PRECONFIG,"Button", BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,60,55,185,10 CONTROL "&Direct Connection",IDC_NET_DIRECT,"Button", BS_AUTORADIOBUTTON | WS_TABSTOP,60,70,73,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 31e080f..04a68fd 100644 --- a/resource.h +++ b/resource.h @@ -100,7 +100,7 @@ #define IDC_SITE_NEXT 508 #define IDC_BACK 509 #define IDC_OTHER_URL 510 -#define IDC_NET_IE5 511 +#define IDC_NET_PRECONFIG 511 #define IDC_NET_DIRECT 512 #define IDC_NET_PROXY 513 #define IDC_PROXY_HOST 514 @@ -178,7 +178,6 @@ #define IDC_FILE_INUSE_EDIT 590 #define IDC_FILE_INUSE_MSG 591 #define IDC_FILE_INUSE_HELP 592 -#define IDC_NET_DIRECT_LEGACY 593 #define IDC_DOWNLOAD_EDIT 594 #define IDC_CHOOSE_DO_SEARCH 595 #define IDC_CHOOSE_SYNC 596 diff --git a/simpsock.cc b/simpsock.cc deleted file mode 100644 index 9d37a05..0000000 --- a/simpsock.cc +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2000, Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * A copy of the GNU General Public License can be found at - * http://www.gnu.org/ - * - * Written by DJ Delorie - * - */ - -/* Simplified socket access functions */ - -#include "win32.h" -#include -#include -#include -#include - -#include "simpsock.h" -#include "LogSingleton.h" - -#define SSBUFSZ 1024 - -SimpleSocket::SimpleSocket (const char *hostname, int port) -{ - static int initted = 0; - if (!initted) - { - initted = 1; - WSADATA d; - WSAStartup (MAKEWORD (1, 1), &d); - } - - s = INVALID_SOCKET; - buf = 0; - putp = getp = 0; - - int i1, i2, i3, i4; - unsigned char ip[4]; - - if (sscanf (hostname, "%d.%d.%d.%d", &i1, &i2, &i3, &i4) == 4) - { - ip[0] = i1; - ip[1] = i2; - ip[2] = i3; - ip[3] = i4; - } - else - { - struct hostent *he; - he = gethostbyname (hostname); - if (!he) - { - LogPlainPrintf ("Can't resolve `%s'\n", hostname); - return; - } - memcpy (ip, he->h_addr_list[0], 4); - } - - s = socket (AF_INET, SOCK_STREAM, 0); - if (s == INVALID_SOCKET) - { - LogPlainPrintf ("Can't create socket, %d", WSAGetLastError ()); - return; - } - - struct sockaddr_in name; - - memset (&name, 0, sizeof (name)); - name.sin_family = AF_INET; - name.sin_port = htons (port); - memcpy (&name.sin_addr, ip, 4); - - if (connect (s, (sockaddr *) & name, sizeof (name))) - { - LogPlainPrintf ("Can't connect to %s:%d", hostname, port); - closesocket (s); - s = INVALID_SOCKET; - return; - } - - return; -} - -SimpleSocket::~SimpleSocket () -{ - invalidate (); -} - -int -SimpleSocket::ok () -{ - if (s == INVALID_SOCKET) - return 0; - return 1; -} - -int -SimpleSocket::printf (const char *fmt, ...) -{ - char buf[SSBUFSZ]; - va_list args; - va_start (args, fmt); - vsprintf (buf, fmt, args); - return write (buf, strlen (buf)); -} - -int -SimpleSocket::write (const char *buf, int len) -{ - int rv; - if (!ok ()) - return -1; - if ((rv = send (s, buf, len, 0)) == -1) - invalidate (); - return rv; -} - -int -SimpleSocket::fill () -{ - if (!ok ()) - return -1; - - if (buf == 0) - buf = new char [SSBUFSZ + 3]; - if (putp == getp) - putp = getp = 0; - - int n = SSBUFSZ - putp; - if (n == 0) - return 0; - int r = recv (s, buf + putp, n, 0); - if (r > 0) - { - putp += r; - } - else if (r < 0 && putp == getp) - { - invalidate (); - } - return r; -} - -char * -SimpleSocket::gets () -{ - if (getp > 0 && putp > getp) - { - memmove (buf, buf + getp, putp - getp); - putp -= getp; - getp = 0; - } - if (putp == getp) - if (fill () <= 0) - return 0; - - // getp is zero, always, here, and putp is the count - char *nl; - while ((nl = (char *) memchr (buf, '\n', putp)) == NULL && putp < SSBUFSZ) - if (fill () <= 0) - break; - - if (nl) - { - getp = nl - buf + 1; - while (nl >= buf && (*nl == '\n' || *nl == '\r')) - *nl-- = 0; - } - else if (putp > getp) - { - getp = putp; - nl = buf + putp; - nl[1] = 0; - } - else - return 0; - - return buf; -} - -#define MIN(a,b) ((a) < (b) ? (a) : (b)) - -int -SimpleSocket::read (char *ubuf, int ulen) -{ - if (!ok ()) - return -1; - - int n, rv = 0; - if (putp > getp) - { - n = MIN (ulen, putp - getp); - memmove (ubuf, buf + getp, n); - getp += n; - ubuf += n; - ulen -= n; - rv += n; - } - while (ulen > 0) - { - n = recv (s, ubuf, ulen, 0); - if (n < 0) - invalidate (); - if (n <= 0) - return rv > 0 ? rv : n; - ubuf += n; - ulen -= n; - rv += n; - } - return rv; -} - -void -SimpleSocket::invalidate (void) -{ - if (s != INVALID_SOCKET) - closesocket (s); - s = INVALID_SOCKET; - if (buf) - delete[] buf; - buf = 0; - getp = putp = 0; -} diff --git a/simpsock.h b/simpsock.h deleted file mode 100644 index 76bb02b..0000000 --- a/simpsock.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2000, Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * A copy of the GNU General Public License can be found at - * http://www.gnu.org/ - * - * Written by DJ Delorie - * - */ - -#ifndef SETUP_SIMPSOCK_H -#define SETUP_SIMPSOCK_H - -/* Simplified socket access functions */ - -class SimpleSocket -{ - - SOCKET s; - char *buf; - int putp, getp; - int fill (); - void invalidate (void); - -public: - SimpleSocket (const char *hostname, int port); - ~SimpleSocket (); - - int ok (); - - int printf (const char *fmt, ...); - int write (const char *buf, int len); - - char *gets (); - int read (char *buf, int len); -}; - -#endif /* SETUP_SIMPSOCK_H */