[PATCH setup 2/2] Improve file:// url handling

2018-02-28 Thread SZAVAI Gyula
As a repo url, we're accepting
* raw windows paths (with both \ and /)
  c:\cygwin repo
  \\machine\share\cygwin repo
* proper file: urls
  file:///c:/cygwin%20repo
  file://machine/share/cygwin%20repo

Most non-standard urls accepted by the old code should work, too.
Paths longer than 260 characters are not supported anymore.
---
 netio.cc | 21 ++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/netio.cc b/netio.cc
index c8982de..1e784b1 100644
--- a/netio.cc
+++ b/netio.cc
@@ -25,6 +25,8 @@
 #include 
 #include 
 
+#include 
+
 #include "resource.h"
 #include "state.h"
 #include "msg.h"
@@ -72,11 +74,24 @@ NetIO::open (char const *url, bool cachable)
   else if (strncmp (url, "ftps://", 7) == 0)
 proto = ftps;
   else if (strncmp (url, "file://", 7) == 0)
-proto = file;
-  else
 {
   proto = file;
-  file_url = (std::string("file://") + url);
+
+  // WinInet expects a legacy file:// url
+  // (a windows path with "file://" prepended)
+  // 
https://blogs.msdn.microsoft.com/freeassociations/2005/05/19/the-bizarre-and-unhappy-story-of-file-urls/
+  char path[MAX_PATH];
+  DWORD len = MAX_PATH;
+  if (S_OK == PathCreateFromUrl(url, path, , 0))
+{
+  file_url = std::string("file://") + path;
+  url = file_url.c_str();
+}
+}
+  else // treat everything else as a windows path
+{
+  proto = file;
+  file_url = std::string("file://") + url;
   url = file_url.c_str();
 }
 
-- 
2.16.1



[PATCH setup 1/2] NetIO: Remove unused url parsing code

2018-02-28 Thread SZAVAI Gyula
---
 netio.cc   | 64 --
 netio.h| 11 ++-
 nio-ie5.cc |  3 +--
 3 files changed, 3 insertions(+), 75 deletions(-)

diff --git a/netio.cc b/netio.cc
index d60f119..c8982de 100644
--- a/netio.cc
+++ b/netio.cc
@@ -42,70 +42,6 @@ char *NetIO::net_proxy_passwd;
 char *NetIO::net_ftp_user;
 char *NetIO::net_ftp_passwd;
 
-NetIO::NetIO (char const *Purl)
-{
-  set_url (Purl);
-}
-
-NetIO::~NetIO ()
-{
-  if (url)
-delete[] url;
-  if (proto)
-delete[] proto;
-  if (host)
-delete[] host;
-  if (path)
-delete[] path;
-}
-
-void
-NetIO::set_url (char const *Purl)
-{
-  char *bp, *ep, c;
-
-  file_size = 0;
-  url = new char[strlen (Purl) + 1];
-  strcpy (url, Purl);
-  proto = 0;
-  host = 0;
-  port = 0;
-  path = 0;
-
-  bp = url;
-  ep = strstr (bp, "://");
-  if (!ep)
-{
-  path = strdup (url);
-  return;
-}
-
-  *ep = 0;
-  proto = new char [strlen (bp)+1];
-  strcpy (proto, bp);
-  *ep = ':';
-  bp = ep + 3;
-
-  ep = bp + strcspn (bp, ":/");
-  c = *ep;
-  *ep = 0;
-  host = new char [strlen (bp) + 1];
-  strcpy (host, bp);
-  *ep = c;
-
-  if (*ep == ':')
-{
-  port = atoi (ep + 1);
-  ep = strchr (ep, '/');
-}
-
-  if (*ep)
-{
-  path = new char [strlen (ep)+1];
-  strcpy (path, ep);
-}
-}
-
 int
 NetIO::ok ()
 {
diff --git a/netio.h b/netio.h
index 7b7d13f..6d0f044 100644
--- a/netio.h
+++ b/netio.h
@@ -24,8 +24,6 @@
 class NetIO
 {
 protected:
-  NetIO (char const *url);
-  void set_url (char const *url);
   BOOL ftp_auth;
 
   static char *net_user;
@@ -39,13 +37,8 @@ protected:
 public:
   /* if nonzero, this is the estimated total file size */
   int file_size;
-  /* broken down url FYI */
-  char *url;
-  char *proto;
-  char *host;
-  int port;
-  char *path;
-virtual ~ NetIO ();
+
+  virtual ~ NetIO () {};
 
   /* The user calls this function to create a suitable accessor for
  the given URL.  It uses the network setup state in state.h.  If
diff --git a/nio-ie5.cc b/nio-ie5.cc
index 5c93894..6fada0f 100644
--- a/nio-ie5.cc
+++ b/nio-ie5.cc
@@ -114,8 +114,7 @@ DWORD Proxy::type (void) const
 static HINTERNET internet = 0;
 static Proxy last_proxy = Proxy(-1, "", -1);
 
-NetIO_IE5::NetIO_IE5 (char const *_url, bool cachable):
-NetIO (_url)
+NetIO_IE5::NetIO_IE5 (char const *url, bool cachable)
 {
   int resend = 0;
 
-- 
2.16.1



Remove legacy networking code, vol 2

2018-02-28 Thread SZAVAI Gyula
[PATCH setup 1/2] NetIO: Remove unused url parsing code
[PATCH setup 2/2] Improve file:// url handling

 netio.cc   | 85 
++---
 netio.h| 11 ++-
 nio-ie5.cc |  3 +--
 3 files changed, 21 insertions(+), 78 deletions(-)


[PATCH setup 4/5] Add Proxy class

2018-01-26 Thread SZAVAI Gyula
---
 nio-ie5.cc | 59 +++
 1 file changed, 59 insertions(+)

diff --git a/nio-ie5.cc b/nio-ie5.cc
index a649233..e1a8e5c 100644
--- a/nio-ie5.cc
+++ b/nio-ie5.cc
@@ -63,6 +63,65 @@ determine_default_useragent(void)
   return default_useragent;
 }
 
+
+class Proxy
+{
+  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 ) const;
+
+  DWORD type (void) const;
+  char const *string (void) const;
+  char const *bypass (void) const;
+};
+
+bool Proxy::operator!= (const Proxy ) const
+{
+if (method != o.method) return true;
+if (method != IDC_NET_PROXY) return false;
+if (host != o.host) return true;
+if (port != o.port) return true;
+return false;
+}
+
+char const *Proxy::string(void) const
+{
+  if (method == IDC_NET_PROXY)
+return hostport.c_str();
+  else
+return NULL;
+}
+
+char const *Proxy::bypass(void) const
+{
+  if (method == IDC_NET_PROXY)
+return "";   // use "<-loopback>" to do NOT bypass for localhost
+  else
+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: return INTERNET_OPEN_TYPE_DIRECT;
+}
+}
+
+
 NetIO_IE5::NetIO_IE5 (char const *_url, bool direct, bool cachable):
 NetIO (_url)
 {
-- 
2.14.3



[PATCH setup 5/5] Remove NetIO_HTTP

2018-01-26 Thread SZAVAI Gyula
---
 Makefile.am |   2 -
 netio.cc|  10 +--
 nio-http.cc | 208 
 nio-http.h  |  39 
 nio-ie5.cc  |  30 -
 nio-ie5.h   |   2 +-
 6 files changed, 16 insertions(+), 275 deletions(-)
 delete mode 100644 nio-http.cc
 delete mode 100644 nio-http.h

diff --git a/Makefile.am b/Makefile.am
index f8f5993..cd5648a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -192,8 +192,6 @@ inilint_SOURCES = \
netio.h \
nio-ie5.cc \
nio-ie5.h \
-   nio-http.cc \
-   nio-http.h \
package_db.cc \
package_db.h \
package_depends.h \
diff --git a/netio.cc b/netio.cc
index d77108b..90fb3df 100644
--- a/netio.cc
+++ b/netio.cc
@@ -29,7 +29,6 @@
 #include "state.h"
 #include "msg.h"
 #include "nio-ie5.h"
-#include "nio-http.h"
 #include "dialog.h"
 
 int NetIO::net_method;
@@ -144,14 +143,7 @@ NetIO::open (char const *url, bool cachable)
   url = url2.c_str();
 }
 
-  if (proto == file)
-rv = new NetIO_IE5 (url, true, false);
-  else if (net_method == IDC_NET_PRECONFIG)
-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);
+  rv = new NetIO_IE5 (url, proto == file ? false : cachable);
 
   if (rv && !rv->ok ())
 {
diff --git a/nio-http.cc b/nio-http.cc
deleted file mode 100644
index 413ee7f..000
--- 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 

[PATCH setup 3/5] Remove NetIO_File

2018-01-26 Thread SZAVAI Gyula
---
 Makefile.am |  2 --
 netio.cc| 12 +---
 nio-file.cc | 64 -
 nio-file.h  | 31 --
 4 files changed, 9 insertions(+), 100 deletions(-)
 delete mode 100644 nio-file.cc
 delete mode 100644 nio-file.h

diff --git a/Makefile.am b/Makefile.am
index aca3ccc..f8f5993 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -192,8 +192,6 @@ inilint_SOURCES = \
netio.h \
nio-ie5.cc \
nio-ie5.h \
-   nio-file.cc \
-   nio-file.h \
nio-http.cc \
nio-http.h \
package_db.cc \
diff --git a/netio.cc b/netio.cc
index 6c357fc..d77108b 100644
--- a/netio.cc
+++ b/netio.cc
@@ -28,7 +28,6 @@
 #include "resource.h"
 #include "state.h"
 #include "msg.h"
-#include "nio-file.h"
 #include "nio-ie5.h"
 #include "nio-http.h"
 #include "dialog.h"
@@ -124,6 +123,7 @@ NetIO *
 NetIO::open (char const *url, bool cachable)
 {
   NetIO *rv = 0;
+  std::string url2;
   enum
   { http, https, ftp, ftps, file }
   proto;
@@ -135,11 +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;
+  else
+{
+  proto = file;
+  url2 = (std::string("file://") + url);
+  url = url2.c_str();
+}
 
   if (proto == file)
-rv = new NetIO_File (url);
+rv = new NetIO_IE5 (url, true, false);
   else if (net_method == IDC_NET_PRECONFIG)
 rv = new NetIO_IE5 (url, false, cachable);
   else if (net_method == IDC_NET_PROXY)
diff --git a/nio-file.cc b/nio-file.cc
deleted file mode 100644
index fce1b2c..000
--- 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..000
--- 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 */
-- 
2.14.3



[PATCH setup 1/5] Remove direct(legacy) connection type

2018-01-26 Thread SZAVAI Gyula
---
 ConnectionSetting.cc |   5 --
 Makefile.am  |   2 -
 net.cc   |   9 +--
 netio.cc |  20 --
 nio-ftp.cc   | 179 ---
 nio-ftp.h|  41 
 res.rc   |   2 -
 resource.h   |   1 -
 8 files changed, 3 insertions(+), 256 deletions(-)
 delete mode 100644 nio-ftp.cc
 delete mode 100644 nio-ftp.h

diff --git a/ConnectionSetting.cc b/ConnectionSetting.cc
index 1154d94..5baf76c 100644
--- a/ConnectionSetting.cc
+++ b/ConnectionSetting.cc
@@ -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;
 }
@@ -66,8 +63,6 @@ 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/Makefile.am b/Makefile.am
index a238d88..aca3ccc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -194,8 +194,6 @@ inilint_SOURCES = \
nio-ie5.h \
nio-file.cc \
nio-file.h \
-   nio-ftp.cc \
-   nio-ftp.h \
nio-http.cc \
nio-http.h \
package_db.cc \
diff --git a/net.cc b/net.cc
index fa6f1e3..5ff3713 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_IE5, IDC_NET_DIRECT, IDC_NET_PROXY, 0 };
 static bool doing_loading = false;
 
 void
@@ -47,8 +47,7 @@ NetPage::CheckIfEnableNext ()
   DWORD ButtonFlags = PSWIZB_BACK;
 
   if (NetIO::net_method == IDC_NET_IE5 ||
-  NetIO::net_method == IDC_NET_DIRECT ||
-  NetIO::net_method == IDC_NET_DIRECT_LEGACY)
+  NetIO::net_method == IDC_NET_DIRECT)
 e = 1;
   else if (NetIO::net_method == IDC_NET_PROXY)
 {
@@ -132,8 +131,7 @@ 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_PROXY), BM_GETCHECK, 0, 0) != 
BST_CHECKED)
 SendMessage (GetDlgItem (IDC_NET_IE5), BM_CLICK, 0, 0);
 }
 
@@ -169,7 +167,6 @@ 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 cf634c1..86bb69a 100644
--- a/netio.cc
+++ b/netio.cc
@@ -31,7 +31,6 @@
 #include "nio-file.h"
 #include "nio-ie5.h"
 #include "nio-http.h"
-#include "nio-ftp.h"
 #include "dialog.h"
 
 int NetIO::net_method;
@@ -147,23 +146,6 @@ NetIO::open (char const *url, bool cachable)
 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)
-   {
-   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);
-   }
-}
 
   if (rv && !rv->ok ())
 {
@@ -304,8 +286,6 @@ NetIO::net_method_name ()
   return "Direct";
 case IDC_NET_PROXY:
   return "Proxy";
-case IDC_NET_DIRECT_LEGACY:
-  return "Direct (legacy)";
 default:
   return "Unknown";
 }
diff --git a/nio-ftp.cc b/nio-ftp.cc
deleted file mode 100644
index 65625d5..000
--- 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"
-

Remove legacy networking code

2018-01-26 Thread SZAVAI Gyula
[PATCH setup 1/5] Remove direct(legacy) connection type
[PATCH setup 2/5] Rename IDC_NET_IE5 to IDC_NET_PRECONFIG
[PATCH setup 3/5] Remove NetIO_File
[PATCH setup 4/5] Add Proxy class
[PATCH setup 5/5] Remove NetIO_HTTP

 ConnectionSetting.cc |  11 ++---
 Makefile.am  |   6 ---
 net.cc   |  17 +++
 netio.cc |  42 -
 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   |  89 +---
 nio-ie5.h|   2 +-
 res.rc   |   4 +-
 resource.h   |   3 +-
 14 files changed, 96 insertions(+), 640 deletions(-)


[PATCH setup] Send User-Agent even when setup-specific proxy is used

2018-01-18 Thread SZAVAI Gyula
Setup is sending User-Agent header if direct connection or system proxy
is used, but not when direct(legacy) or setup-specific proxy. Fix this.
---
 Makefile.am  |   2 ++
 nio-http.cc  |   4 +++
 nio-ie5.cc   |  53 ++---
 useragent.cc | 109 +++
 useragent.h  |   8 +
 5 files changed, 125 insertions(+), 51 deletions(-)
 create mode 100644 useragent.cc
 create mode 100644 useragent.h

diff --git a/Makefile.am b/Makefile.am
index a238d88..3c88020 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -256,6 +256,8 @@ inilint_SOURCES = \
String++.h \
threebar.cc \
threebar.h \
+   useragent.cc \
+   useragent.h \
UserSettings.cc \
UserSettings.h \
win32.cc \
diff --git a/nio-http.cc b/nio-http.cc
index 413ee7f..3f7fd9b 100644
--- a/nio-http.cc
+++ b/nio-http.cc
@@ -29,6 +29,8 @@
 #include "netio.h"
 #include "nio-http.h"
 
+#include "useragent.h"
+
 #ifndef _strnicmp
 #define _strnicmp strncasecmp
 #endif
@@ -125,6 +127,8 @@ retry_get:
 s->printf ("Proxy-Authorization: Basic %s\r\n",
   base64_encode (net_proxy_user, net_proxy_passwd));
 
+  s->printf ("%s", get_useragent_header());
+
   s->printf ("\r\n");
 
   char * l = s->gets ();
diff --git a/nio-ie5.cc b/nio-ie5.cc
index a649233..2e36ac6 100644
--- a/nio-ie5.cc
+++ b/nio-ie5.cc
@@ -27,42 +27,12 @@
 #include "netio.h"
 #include "nio-ie5.h"
 #include "LogSingleton.h"
-#include "setup_version.h"
-#include "getopt++/StringOption.h"
+#include "useragent.h"
 #include 
 
-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)
-{
-  static std::string default_useragent;
-
-  if (!default_useragent.empty())
-return default_useragent;
-
-  std::stringstream os;
-  os << "Windows NT " << OSMajorVersion() << "." << OSMinorVersion() << "." << 
OSBuildNumber();
-
-  std::string bitness = "Unknown";
-#ifdef __x86_64__
-  bitness = "Win64";
-#else
-  typedef BOOL (WINAPI *PFNISWOW64PROCESS)(HANDLE, PBOOL);
-  PFNISWOW64PROCESS pfnIsWow64Process = 
(PFNISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), 
"IsWow64Process");
-  if (pfnIsWow64Process) {
-BOOL bIsWow64 = FALSE;
-if (pfnIsWow64Process(GetCurrentProcess(), ))
-  bitness = bIsWow64 ? "WoW64" : "Win32";
-  }
-#endif
-  default_useragent = std::string("Cygwin-Setup/") + setup_version + " (" + 
os.str() + ";" + bitness + ")";
-  return default_useragent;
-}
-
 NetIO_IE5::NetIO_IE5 (char const *_url, bool direct, bool cachable):
 NetIO (_url)
 {
@@ -78,26 +48,7 @@ NetIO (_url)
 {
   InternetAttemptConnect (0);
 
-  const char *lpszAgent = determine_default_useragent().c_str();
-  if (UserAgent.isPresent())
-{
-  const std::string _agent = UserAgent;
-  if (user_agent.length())
-{
-  // override the default user agent string
-  lpszAgent = user_agent.c_str();
-  Log (LOG_PLAIN) << "User-Agent: header overridden to \"" << 
lpszAgent << "\"" << endLog;
-}
-  else
-{
-  // user-agent option is present, but no string is specified means
-  // don't add a user-agent header
-  lpszAgent = NULL;
-  Log (LOG_PLAIN) << "User-Agent: header suppressed " << lpszAgent 
<< endLog;
-}
-}
-
-  *internet = InternetOpen (lpszAgent,
+  *internet = InternetOpen (get_useragent(),
direct ? INTERNET_OPEN_TYPE_DIRECT : 
INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0);
 }
diff --git a/useragent.cc b/useragent.cc
new file mode 100644
index 000..a871a8b
--- /dev/null
+++ b/useragent.cc
@@ -0,0 +1,109 @@
+/*
+ * 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 
+ *
+ */
+
+#include "win32.h"
+
+#include "LogSingleton.h"
+#include "setup_version.h"
+#include "getopt++/StringOption.h"
+#include "useragent.h"
+#include 
+
+static StringOption UserAgentOption ("", '\0', "user-agent", "User agent 
string for HTTP requests");
+
+const std::string &
+determine_default_useragent(void)
+{
+  static std::string default_useragent;
+
+  if (!default_useragent.empty())
+return default_useragent;
+
+  std::stringstream os;
+  os << "Windows NT " << OSMajorVersion() << "." << OSMinorVersion() << "." << 
OSBuildNumber();
+
+  std::string bitness =