Blame SOURCES/0036-curl-7.29.0-c8644d1f.patch

105fd7
From 3fef242a1e1a74140a1678d84164086d0f47d83a Mon Sep 17 00:00:00 2001
105fd7
From: Peter Wu <peter@lekensteyn.nl>
105fd7
Date: Thu, 27 Nov 2014 23:59:19 +0100
105fd7
Subject: [PATCH 01/11] sws: move away from IPv4/IPv4-only assumption
105fd7
105fd7
Instead of depending the socket domain type on use_ipv6, specify the
105fd7
domain type (AF_INET / AF_INET6) as variable. An enum is used here with
105fd7
switch to avoid compiler warnings in connect_to, complaining that rc
105fd7
is possibly undefined (which is not possible as socket_domain is
105fd7
always set).
105fd7
105fd7
Besides abstracting the socket type, make the debugging messages be
105fd7
independent on IP (introduce location_str which points to "port XXXXX").
105fd7
Rename "ipv_inuse" to "socket_type" and tighten the scope (main).
105fd7
105fd7
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
105fd7
105fd7
Upstream-commit: cf6c5c222d86088cbfc9dee4c23f8ada96ee91e7
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 tests/server/sws.c | 88 ++++++++++++++++++++++++------------------------------
105fd7
 1 file changed, 39 insertions(+), 49 deletions(-)
105fd7
105fd7
diff --git a/tests/server/sws.c b/tests/server/sws.c
105fd7
index aef55ea..fa10d54 100644
105fd7
--- a/tests/server/sws.c
105fd7
+++ b/tests/server/sws.c
105fd7
@@ -65,11 +65,13 @@
105fd7
 #define ERANGE  34 /* errno.h value */
105fd7
 #endif
105fd7
 
105fd7
+static enum {
105fd7
+  socket_domain_inet = AF_INET,
105fd7
 #ifdef ENABLE_IPV6
105fd7
-static bool use_ipv6 = FALSE;
105fd7
+  socket_domain_inet6 = AF_INET6
105fd7
 #endif
105fd7
+} socket_domain = AF_INET;
105fd7
 static bool use_gopher = FALSE;
105fd7
-static const char *ipv_inuse = "IPv4";
105fd7
 static int serverlogslocked = 0;
105fd7
 static bool is_proxy = FALSE;
105fd7
 
105fd7
@@ -1285,7 +1287,7 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
105fd7
 #endif
105fd7
 
105fd7
 #ifdef ENABLE_IPV6
105fd7
-  if(use_ipv6) {
105fd7
+  if(socket_domain == AF_INET6) {
105fd7
     op_br = "[";
105fd7
     cl_br = "]";
105fd7
   }
105fd7
@@ -1297,14 +1299,8 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
105fd7
   logmsg("about to connect to %s%s%s:%hu",
105fd7
          op_br, ipaddr, cl_br, port);
105fd7
 
105fd7
-#ifdef ENABLE_IPV6
105fd7
-  if(!use_ipv6)
105fd7
-#endif
105fd7
-    serverfd = socket(AF_INET, SOCK_STREAM, 0);
105fd7
-#ifdef ENABLE_IPV6
105fd7
-  else
105fd7
-    serverfd = socket(AF_INET6, SOCK_STREAM, 0);
105fd7
-#endif
105fd7
+
105fd7
+  serverfd = socket(socket_domain, SOCK_STREAM, 0);
105fd7
   if(CURL_SOCKET_BAD == serverfd) {
105fd7
     error = SOCKERRNO;
105fd7
     logmsg("Error creating socket for server conection: (%d) %s",
105fd7
@@ -1322,9 +1318,8 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
105fd7
     logmsg("TCP_NODELAY set for server conection");
105fd7
 #endif
105fd7
 
105fd7
-#ifdef ENABLE_IPV6
105fd7
-  if(!use_ipv6) {
105fd7
-#endif
105fd7
+  switch(socket_domain) {
105fd7
+  case AF_INET:
105fd7
     memset(&serveraddr.sa4, 0, sizeof(serveraddr.sa4));
105fd7
     serveraddr.sa4.sin_family = AF_INET;
105fd7
     serveraddr.sa4.sin_port = htons(port);
105fd7
@@ -1335,9 +1330,9 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
105fd7
     }
105fd7
 
105fd7
     rc = connect(serverfd, &serveraddr.sa, sizeof(serveraddr.sa4));
105fd7
+    break;
105fd7
 #ifdef ENABLE_IPV6
105fd7
-  }
105fd7
-  else {
105fd7
+  case AF_INET6:
105fd7
     memset(&serveraddr.sa6, 0, sizeof(serveraddr.sa6));
105fd7
     serveraddr.sa6.sin6_family = AF_INET6;
105fd7
     serveraddr.sa6.sin6_port = htons(port);
105fd7
@@ -1348,8 +1343,9 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
105fd7
     }
105fd7
 
105fd7
     rc = connect(serverfd, &serveraddr.sa, sizeof(serveraddr.sa6));
105fd7
-  }
105fd7
+    break;
105fd7
 #endif /* ENABLE_IPV6 */
105fd7
+  }
105fd7
 
105fd7
   if(got_exit_signal) {
105fd7
     sclose(serverfd);
105fd7
@@ -1924,21 +1920,20 @@ int main(int argc, char *argv[])
105fd7
   int arg=1;
105fd7
   long pid;
105fd7
   const char *hostport = "127.0.0.1";
105fd7
+  const char *socket_type = "IPv4";
105fd7
+  char port_str[11];
105fd7
+  const char *location_str = port_str;
105fd7
   size_t socket_idx;
105fd7
 
105fd7
   memset(&req, 0, sizeof(req));
105fd7
 
105fd7
   while(argc>arg) {
105fd7
     if(!strcmp("--version", argv[arg])) {
105fd7
-      printf("sws IPv4%s"
105fd7
-             "\n"
105fd7
-             ,
105fd7
+      puts("sws IPv4"
105fd7
 #ifdef ENABLE_IPV6
105fd7
              "/IPv6"
105fd7
-#else
105fd7
-             ""
105fd7
 #endif
105fd7
-             );
105fd7
+          );
105fd7
       return 0;
105fd7
     }
105fd7
     else if(!strcmp("--pidfile", argv[arg])) {
105fd7
@@ -1957,16 +1952,16 @@ int main(int argc, char *argv[])
105fd7
       end_of_headers = "\r\n"; /* gopher style is much simpler */
105fd7
     }
105fd7
     else if(!strcmp("--ipv4", argv[arg])) {
105fd7
-#ifdef ENABLE_IPV6
105fd7
-      ipv_inuse = "IPv4";
105fd7
-      use_ipv6 = FALSE;
105fd7
-#endif
105fd7
+      socket_type = "IPv4";
105fd7
+      socket_domain = AF_INET;
105fd7
+      location_str = port_str;
105fd7
       arg++;
105fd7
     }
105fd7
     else if(!strcmp("--ipv6", argv[arg])) {
105fd7
 #ifdef ENABLE_IPV6
105fd7
-      ipv_inuse = "IPv6";
105fd7
-      use_ipv6 = TRUE;
105fd7
+      socket_type = "IPv6";
105fd7
+      socket_domain = AF_INET6;
105fd7
+      location_str = port_str;
105fd7
 #endif
105fd7
       arg++;
105fd7
     }
105fd7
@@ -2018,6 +2013,8 @@ int main(int argc, char *argv[])
105fd7
     }
105fd7
   }
105fd7
 
105fd7
+  snprintf(port_str, sizeof(port_str), "port %hu", port);
105fd7
+
105fd7
 #ifdef WIN32
105fd7
   win32_init();
105fd7
   atexit(win32_cleanup);
105fd7
@@ -2027,14 +2024,7 @@ int main(int argc, char *argv[])
105fd7
 
105fd7
   pid = (long)getpid();
105fd7
 
105fd7
-#ifdef ENABLE_IPV6
105fd7
-  if(!use_ipv6)
105fd7
-#endif
105fd7
-    sock = socket(AF_INET, SOCK_STREAM, 0);
105fd7
-#ifdef ENABLE_IPV6
105fd7
-  else
105fd7
-    sock = socket(AF_INET6, SOCK_STREAM, 0);
105fd7
-#endif
105fd7
+  sock = socket(socket_domain, SOCK_STREAM, 0);
105fd7
 
105fd7
   all_sockets[0] = sock;
105fd7
   num_sockets = 1;
105fd7
@@ -2061,33 +2051,33 @@ int main(int argc, char *argv[])
105fd7
     goto sws_cleanup;
105fd7
   }
105fd7
 
105fd7
-#ifdef ENABLE_IPV6
105fd7
-  if(!use_ipv6) {
105fd7
-#endif
105fd7
+  switch(socket_domain) {
105fd7
+  case AF_INET:
105fd7
     memset(&me.sa4, 0, sizeof(me.sa4));
105fd7
     me.sa4.sin_family = AF_INET;
105fd7
     me.sa4.sin_addr.s_addr = INADDR_ANY;
105fd7
     me.sa4.sin_port = htons(port);
105fd7
     rc = bind(sock, &me.sa, sizeof(me.sa4));
105fd7
+    break;
105fd7
 #ifdef ENABLE_IPV6
105fd7
-  }
105fd7
-  else {
105fd7
+  case AF_INET6:
105fd7
     memset(&me.sa6, 0, sizeof(me.sa6));
105fd7
     me.sa6.sin6_family = AF_INET6;
105fd7
     me.sa6.sin6_addr = in6addr_any;
105fd7
     me.sa6.sin6_port = htons(port);
105fd7
     rc = bind(sock, &me.sa, sizeof(me.sa6));
105fd7
-  }
105fd7
+    break;
105fd7
 #endif /* ENABLE_IPV6 */
105fd7
+  }
105fd7
   if(0 != rc) {
105fd7
     error = SOCKERRNO;
105fd7
-    logmsg("Error binding socket on port %hu: (%d) %s",
105fd7
-           port, error, strerror(error));
105fd7
+    logmsg("Error binding socket on %s: (%d) %s",
105fd7
+           location_str, error, strerror(error));
105fd7
     goto sws_cleanup;
105fd7
   }
105fd7
 
105fd7
-  logmsg("Running %s %s version on port %d",
105fd7
-         use_gopher?"GOPHER":"HTTP", ipv_inuse, (int)port);
105fd7
+  logmsg("Running %s %s version on %s",
105fd7
+         use_gopher?"GOPHER":"HTTP", socket_type, location_str);
105fd7
 
105fd7
   /* start accepting connections */
105fd7
   rc = listen(sock, 5);
105fd7
@@ -2251,8 +2241,8 @@ sws_cleanup:
105fd7
   restore_signal_handlers();
105fd7
 
105fd7
   if(got_exit_signal) {
105fd7
-    logmsg("========> %s sws (port: %d pid: %ld) exits with signal (%d)",
105fd7
-           ipv_inuse, (int)port, pid, exit_signal);
105fd7
+    logmsg("========> %s sws (%s pid: %ld) exits with signal (%d)",
105fd7
+           socket_type, location_str, pid, exit_signal);
105fd7
     /*
105fd7
      * To properly set the return status of the process we
105fd7
      * must raise the same signal SIGINT or SIGTERM that we
105fd7
-- 
105fd7
2.5.2
105fd7
105fd7
105fd7
From d8d875f7c528157feec0795c03bd065420903f5d Mon Sep 17 00:00:00 2001
105fd7
From: Steve Holme <steve_holme@hotmail.com>
105fd7
Date: Wed, 3 Dec 2014 00:00:40 +0000
105fd7
Subject: [PATCH 02/11] sws.c: Fixed compilation warning when IPv6 is disabled
105fd7
105fd7
sws.c:69: warning: comma at end of enumerator list
105fd7
105fd7
Upstream-commit: d784000a1468efc986c7d156d2e7c84d1920af87
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 tests/server/sws.c | 4 ++--
105fd7
 1 file changed, 2 insertions(+), 2 deletions(-)
105fd7
105fd7
diff --git a/tests/server/sws.c b/tests/server/sws.c
105fd7
index fa10d54..2b7e628 100644
105fd7
--- a/tests/server/sws.c
105fd7
+++ b/tests/server/sws.c
105fd7
@@ -66,9 +66,9 @@
105fd7
 #endif
105fd7
 
105fd7
 static enum {
105fd7
-  socket_domain_inet = AF_INET,
105fd7
+  socket_domain_inet = AF_INET
105fd7
 #ifdef ENABLE_IPV6
105fd7
-  socket_domain_inet6 = AF_INET6
105fd7
+  , socket_domain_inet6 = AF_INET6
105fd7
 #endif
105fd7
 } socket_domain = AF_INET;
105fd7
 static bool use_gopher = FALSE;
105fd7
-- 
105fd7
2.5.2
105fd7
105fd7
105fd7
From db2095dec37630309bacca6795cd4cfcf6557c9b Mon Sep 17 00:00:00 2001
105fd7
From: Peter Wu <peter@lekensteyn.nl>
105fd7
Date: Thu, 27 Nov 2014 23:59:20 +0100
105fd7
Subject: [PATCH 03/11] sws: restrict TCP_NODELAY to IP sockets
105fd7
105fd7
TCP_NODELAY does not make sense for Unix sockets, so enable it only if
105fd7
the socket is using IP.
105fd7
105fd7
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
105fd7
105fd7
Upstream-commit: fb7d7e0022f22035449bbc506068004f0568f8ae
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 tests/server/sws.c | 73 ++++++++++++++++++++++++++++++++----------------------
105fd7
 1 file changed, 44 insertions(+), 29 deletions(-)
105fd7
105fd7
diff --git a/tests/server/sws.c b/tests/server/sws.c
105fd7
index 2b7e628..0739a70 100644
105fd7
--- a/tests/server/sws.c
105fd7
+++ b/tests/server/sws.c
105fd7
@@ -331,6 +331,21 @@ static void restore_signal_handlers(void)
105fd7
 #endif
105fd7
 }
105fd7
 
105fd7
+/* returns true if the current socket is an IP one */
105fd7
+static bool socket_domain_is_ip(void)
105fd7
+{
105fd7
+  switch(socket_domain) {
105fd7
+  case AF_INET:
105fd7
+#ifdef ENABLE_IPV6
105fd7
+  case AF_INET6:
105fd7
+#endif
105fd7
+    return true;
105fd7
+  default:
105fd7
+  /* case AF_UNIX: */
105fd7
+    return false;
105fd7
+  }
105fd7
+}
105fd7
+
105fd7
 /* based on the testno, parse the correct server commands */
105fd7
 static int parse_servercmd(struct httprequest *req)
105fd7
 {
105fd7
@@ -1282,9 +1297,6 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
105fd7
   int rc;
105fd7
   const char *op_br = "";
105fd7
   const char *cl_br = "";
105fd7
-#ifdef TCP_NODELAY
105fd7
-  curl_socklen_t flag;
105fd7
-#endif
105fd7
 
105fd7
 #ifdef ENABLE_IPV6
105fd7
   if(socket_domain == AF_INET6) {
105fd7
@@ -1309,13 +1321,15 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
105fd7
   }
105fd7
 
105fd7
 #ifdef TCP_NODELAY
105fd7
-  /* Disable the Nagle algorithm */
105fd7
-  flag = 1;
105fd7
-  if(0 != setsockopt(serverfd, IPPROTO_TCP, TCP_NODELAY,
105fd7
-                     (void *)&flag, sizeof(flag)))
105fd7
-    logmsg("====> TCP_NODELAY for server conection failed");
105fd7
-  else
105fd7
-    logmsg("TCP_NODELAY set for server conection");
105fd7
+  if(socket_domain_is_ip()) {
105fd7
+    /* Disable the Nagle algorithm */
105fd7
+    curl_socklen_t flag = 1;
105fd7
+    if(0 != setsockopt(serverfd, IPPROTO_TCP, TCP_NODELAY,
105fd7
+                       (void *)&flag, sizeof(flag)))
105fd7
+      logmsg("====> TCP_NODELAY for server conection failed");
105fd7
+    else
105fd7
+      logmsg("TCP_NODELAY set for server conection");
105fd7
+  }
105fd7
 #endif
105fd7
 
105fd7
   switch(socket_domain) {
105fd7
@@ -1398,9 +1412,6 @@ static void http_connect(curl_socket_t *infdp,
105fd7
   bool poll_server_rd[2] = { TRUE, TRUE };
105fd7
   bool poll_client_wr[2] = { TRUE, TRUE };
105fd7
   bool poll_server_wr[2] = { TRUE, TRUE };
105fd7
-#ifdef TCP_NODELAY
105fd7
-  curl_socklen_t flag;
105fd7
-#endif
105fd7
   bool primary = FALSE;
105fd7
   bool secondary = FALSE;
105fd7
   int max_tunnel_idx; /* CTRL or DATA */
105fd7
@@ -1514,13 +1525,15 @@ static void http_connect(curl_socket_t *infdp,
105fd7
           memset(&req2, 0, sizeof(req2));
105fd7
           logmsg("====> Client connect DATA");
105fd7
 #ifdef TCP_NODELAY
105fd7
-          /* Disable the Nagle algorithm */
105fd7
-          flag = 1;
105fd7
-          if(0 != setsockopt(datafd, IPPROTO_TCP, TCP_NODELAY,
105fd7
-                             (void *)&flag, sizeof(flag)))
105fd7
-            logmsg("====> TCP_NODELAY for client DATA conection failed");
105fd7
-          else
105fd7
-            logmsg("TCP_NODELAY set for client DATA conection");
105fd7
+          if(socket_domain_is_ip()) {
105fd7
+            /* Disable the Nagle algorithm */
105fd7
+            curl_socklen_t flag = 1;
105fd7
+            if(0 != setsockopt(datafd, IPPROTO_TCP, TCP_NODELAY,
105fd7
+                               (void *)&flag, sizeof(flag)))
105fd7
+              logmsg("====> TCP_NODELAY for client DATA conection failed");
105fd7
+            else
105fd7
+              logmsg("TCP_NODELAY set for client DATA conection");
105fd7
+          }
105fd7
 #endif
105fd7
           req2.pipelining = FALSE;
105fd7
           init_httprequest(&req2);
105fd7
@@ -1826,15 +1839,17 @@ static curl_socket_t accept_connection(curl_socket_t sock)
105fd7
   num_sockets += 1;
105fd7
 
105fd7
 #ifdef TCP_NODELAY
105fd7
-  /*
105fd7
-   * Disable the Nagle algorithm to make it easier to send out a large
105fd7
-   * response in many small segments to torture the clients more.
105fd7
-   */
105fd7
-  if(0 != setsockopt(msgsock, IPPROTO_TCP, TCP_NODELAY,
105fd7
-                     (void *)&flag, sizeof(flag)))
105fd7
-    logmsg("====> TCP_NODELAY failed");
105fd7
-  else
105fd7
-    logmsg("TCP_NODELAY set");
105fd7
+  if(socket_domain_is_ip()) {
105fd7
+    /*
105fd7
+     * Disable the Nagle algorithm to make it easier to send out a large
105fd7
+     * response in many small segments to torture the clients more.
105fd7
+     */
105fd7
+    if(0 != setsockopt(msgsock, IPPROTO_TCP, TCP_NODELAY,
105fd7
+                       (void *)&flag, sizeof(flag)))
105fd7
+      logmsg("====> TCP_NODELAY failed");
105fd7
+    else
105fd7
+      logmsg("TCP_NODELAY set");
105fd7
+  }
105fd7
 #endif
105fd7
 
105fd7
   return msgsock;
105fd7
-- 
105fd7
2.5.2
105fd7
105fd7
105fd7
From 7ab987459a931e593dc9f533d6e6cb6e9a26d424 Mon Sep 17 00:00:00 2001
105fd7
From: Peter Wu <peter@lekensteyn.nl>
105fd7
Date: Wed, 3 Dec 2014 02:20:00 +0100
105fd7
Subject: [PATCH 04/11] sws: add UNIX domain socket support
105fd7
105fd7
This extends sws with a --unix-socket option which causes the port to
105fd7
be ignored (as the server now listens on the path specified by
105fd7
--unix-socket). This feature will be available in the following patch
105fd7
that enables checking for UNIX domain socket support.
105fd7
105fd7
Proxy support (CONNECT) is not considered nor tested. It does not make
105fd7
sense anyway, first connecting through a TCP proxy, then let that TCP
105fd7
proxy connect to a UNIX socket.
105fd7
105fd7
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
105fd7
105fd7
Upstream-commit: e9c7a86220ddf4e67b8bff56cddfc7388afcc9ef
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 tests/server/server_sockaddr.h |  9 ++++++-
105fd7
 tests/server/sws.c             | 53 ++++++++++++++++++++++++++++++++++++++++++
105fd7
 2 files changed, 61 insertions(+), 1 deletion(-)
105fd7
105fd7
diff --git a/tests/server/server_sockaddr.h b/tests/server/server_sockaddr.h
105fd7
index 6a17fe0..3f4cd67 100644
105fd7
--- a/tests/server/server_sockaddr.h
105fd7
+++ b/tests/server/server_sockaddr.h
105fd7
@@ -7,7 +7,7 @@
105fd7
  *                            | (__| |_| |  _ <| |___
105fd7
  *                             \___|\___/|_| \_\_____|
105fd7
  *
105fd7
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
105fd7
+ * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
105fd7
  *
105fd7
  * This software is licensed as described in the file COPYING, which
105fd7
  * you should have received as part of this distribution. The terms
105fd7
@@ -23,12 +23,19 @@
105fd7
  ***************************************************************************/
105fd7
 #include "server_setup.h"
105fd7
 
105fd7
+#ifdef HAVE_SYS_UN_H
105fd7
+#include <sys/un.h> /* for sockaddr_un */
105fd7
+#endif
105fd7
+
105fd7
 typedef union {
105fd7
   struct sockaddr      sa;
105fd7
   struct sockaddr_in   sa4;
105fd7
 #ifdef ENABLE_IPV6
105fd7
   struct sockaddr_in6  sa6;
105fd7
 #endif
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+  struct sockaddr_un   sau;
105fd7
+#endif
105fd7
 } srvr_sockaddr_union_t;
105fd7
 
105fd7
 #endif /* HEADER_CURL_SERVER_SOCKADDR_H */
105fd7
diff --git a/tests/server/sws.c b/tests/server/sws.c
105fd7
index 0739a70..24ecb8f 100644
105fd7
--- a/tests/server/sws.c
105fd7
+++ b/tests/server/sws.c
105fd7
@@ -70,6 +70,9 @@ static enum {
105fd7
 #ifdef ENABLE_IPV6
105fd7
   , socket_domain_inet6 = AF_INET6
105fd7
 #endif
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+  , socket_domain_unix = AF_UNIX
105fd7
+#endif
105fd7
 } socket_domain = AF_INET;
105fd7
 static bool use_gopher = FALSE;
105fd7
 static int serverlogslocked = 0;
105fd7
@@ -1359,6 +1362,11 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
105fd7
     rc = connect(serverfd, &serveraddr.sa, sizeof(serveraddr.sa6));
105fd7
     break;
105fd7
 #endif /* ENABLE_IPV6 */
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+  case AF_UNIX:
105fd7
+    logmsg("Proxying through UNIX socket is not (yet?) supported.");
105fd7
+    return CURL_SOCKET_BAD;
105fd7
+#endif /* USE_UNIX_SOCKETS */
105fd7
   }
105fd7
 
105fd7
   if(got_exit_signal) {
105fd7
@@ -1928,6 +1936,10 @@ int main(int argc, char *argv[])
105fd7
   int wrotepidfile = 0;
105fd7
   int flag;
105fd7
   unsigned short port = DEFAULT_PORT;
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+  const char *unix_socket = NULL;
105fd7
+  bool unlink_socket = false;
105fd7
+#endif
105fd7
   char *pidname= (char *)".http.pid";
105fd7
   struct httprequest req;
105fd7
   int rc;
105fd7
@@ -1948,6 +1960,9 @@ int main(int argc, char *argv[])
105fd7
 #ifdef ENABLE_IPV6
105fd7
              "/IPv6"
105fd7
 #endif
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+             "/unix"
105fd7
+#endif
105fd7
           );
105fd7
       return 0;
105fd7
     }
105fd7
@@ -1980,6 +1995,23 @@ int main(int argc, char *argv[])
105fd7
 #endif
105fd7
       arg++;
105fd7
     }
105fd7
+    else if(!strcmp("--unix-socket", argv[arg])) {
105fd7
+      arg++;
105fd7
+      if(argc>arg) {
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+        unix_socket = argv[arg];
105fd7
+        if(strlen(unix_socket) >= sizeof(me.sau.sun_path)) {
105fd7
+          fprintf(stderr, "sws: socket path must be shorter than %zu chars\n",
105fd7
+                  sizeof(me.sau.sun_path));
105fd7
+          return 0;
105fd7
+        }
105fd7
+        socket_type = "unix";
105fd7
+        socket_domain = AF_UNIX;
105fd7
+        location_str = unix_socket;
105fd7
+#endif
105fd7
+        arg++;
105fd7
+      }
105fd7
+    }
105fd7
     else if(!strcmp("--port", argv[arg])) {
105fd7
       arg++;
105fd7
       if(argc>arg) {
105fd7
@@ -2020,6 +2052,7 @@ int main(int argc, char *argv[])
105fd7
            " --pidfile [file]\n"
105fd7
            " --ipv4\n"
105fd7
            " --ipv6\n"
105fd7
+           " --unix-socket [file]\n"
105fd7
            " --port [port]\n"
105fd7
            " --srcdir [path]\n"
105fd7
            " --connect [ip4-addr]\n"
105fd7
@@ -2083,6 +2116,14 @@ int main(int argc, char *argv[])
105fd7
     rc = bind(sock, &me.sa, sizeof(me.sa6));
105fd7
     break;
105fd7
 #endif /* ENABLE_IPV6 */
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+  case AF_UNIX:
105fd7
+    memset(&me.sau, 0, sizeof(me.sau));
105fd7
+    me.sau.sun_family = AF_UNIX;
105fd7
+    strncpy(me.sau.sun_path, unix_socket, sizeof(me.sau.sun_path));
105fd7
+    rc = bind(sock, &me.sa, sizeof(me.sau));
105fd7
+    break;
105fd7
+#endif /* USE_UNIX_SOCKETS */
105fd7
   }
105fd7
   if(0 != rc) {
105fd7
     error = SOCKERRNO;
105fd7
@@ -2103,6 +2144,11 @@ int main(int argc, char *argv[])
105fd7
     goto sws_cleanup;
105fd7
   }
105fd7
 
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+  /* listen succeeds, so let's assume a valid listening UNIX socket */
105fd7
+  unlink_socket = true;
105fd7
+#endif
105fd7
+
105fd7
   /*
105fd7
   ** As soon as this server writes its pid file the test harness will
105fd7
   ** attempt to connect to this server and initiate its verification.
105fd7
@@ -2242,6 +2288,13 @@ sws_cleanup:
105fd7
   if(sock != CURL_SOCKET_BAD)
105fd7
     sclose(sock);
105fd7
 
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+  if(unlink_socket && socket_domain == AF_UNIX) {
105fd7
+    rc = unlink(unix_socket);
105fd7
+    logmsg("unlink(%s) = %d (%s)", unix_socket, rc, strerror(rc));
105fd7
+  }
105fd7
+#endif
105fd7
+
105fd7
   if(got_exit_signal)
105fd7
     logmsg("signalled to die");
105fd7
 
105fd7
-- 
105fd7
2.5.2
105fd7
105fd7
105fd7
From d04ea6f7f09e1556f80c4bbf4fc9497f83bc37a6 Mon Sep 17 00:00:00 2001
105fd7
From: Peter Wu <peter@lekensteyn.nl>
105fd7
Date: Thu, 27 Nov 2014 23:59:23 +0100
105fd7
Subject: [PATCH 05/11] tests: add HTTP UNIX socket server testing support
105fd7
105fd7
The variable `$ipvnum` can now contain "unix" besides the integers 4
105fd7
and 6 since the variable. Functions which receive this parameter
105fd7
have their `$port` parameter renamed to `$port_or_path` to support a
105fd7
path to the UNIX domain socket (as a "port" is only meaningful for TCP).
105fd7
105fd7
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
105fd7
105fd7
Upstream-commit: f1cc2a2c0cf8e191e606c6093c679fbee95e8809
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 tests/FILEFORMAT    |  2 ++
105fd7
 tests/README        |  3 ++
105fd7
 tests/httpserver.pl | 15 ++++++++-
105fd7
 tests/runtests.pl   | 96 +++++++++++++++++++++++++++++++++++++++++++++--------
105fd7
 tests/serverhelp.pm |  4 +--
105fd7
 5 files changed, 104 insertions(+), 16 deletions(-)
105fd7
105fd7
diff --git a/tests/FILEFORMAT b/tests/FILEFORMAT
105fd7
index 96cd5c8..702368f 100644
105fd7
--- a/tests/FILEFORMAT
105fd7
+++ b/tests/FILEFORMAT
105fd7
@@ -165,6 +165,7 @@ smtp
105fd7
 httptls+srp
105fd7
 httptls+srp-ipv6
105fd7
 http-proxy
105fd7
+http-unix
105fd7
 
105fd7
 Give only one per line.  This subsection is mandatory.
105fd7
 </server>
105fd7
@@ -284,6 +285,7 @@ Available substitute variables include:
105fd7
 %HTTPPORT  - Port number of the HTTP server
105fd7
 %HOST6IP   - IPv6 address of the host running this test
105fd7
 %HTTP6PORT - IPv6 port number of the HTTP server
105fd7
+%HTTPUNIXPATH - Path to the UNIX socket of the HTTP server
105fd7
 %HTTPSPORT - Port number of the HTTPS server
105fd7
 %PROXYPORT - Port number of the HTTP proxy
105fd7
 %FTPPORT   - Port number of the FTP server
105fd7
diff --git a/tests/README b/tests/README
105fd7
index fff618e..b442693 100644
105fd7
--- a/tests/README
105fd7
+++ b/tests/README
105fd7
@@ -80,6 +80,9 @@ The cURL Test Suite
105fd7
   machine, or just move the servers in case you have local services on any of
105fd7
   those ports.
105fd7
 
105fd7
+  The HTTP server supports listening on a UNIX domain socket, the default
105fd7
+  location is 'http.sock'.
105fd7
+
105fd7
  1.4 Run
105fd7
 
105fd7
   'make test'. This builds the test suite support code and invokes the
105fd7
diff --git a/tests/httpserver.pl b/tests/httpserver.pl
105fd7
index a38c3ce..1b8c3d2 100755
105fd7
--- a/tests/httpserver.pl
105fd7
+++ b/tests/httpserver.pl
105fd7
@@ -36,6 +36,7 @@ use serverhelp qw(
105fd7
 
105fd7
 my $verbose = 0;     # set to 1 for debugging
105fd7
 my $port = 8990;     # just a default
105fd7
+my $unix_socket;     # location to place a listening UNIX socket
105fd7
 my $ipvnum = 4;      # default IP version of http server
105fd7
 my $idnum = 1;       # dafault http server instance number
105fd7
 my $proto = 'http';  # protocol the http server speaks
105fd7
@@ -74,6 +75,13 @@ while(@ARGV) {
105fd7
     elsif($ARGV[0] eq '--ipv6') {
105fd7
         $ipvnum = 6;
105fd7
     }
105fd7
+    elsif($ARGV[0] eq '--unix-socket') {
105fd7
+        $ipvnum = 'unix';
105fd7
+        if($ARGV[1]) {
105fd7
+            $unix_socket = $ARGV[1];
105fd7
+            shift @ARGV;
105fd7
+        }
105fd7
+    }
105fd7
     elsif($ARGV[0] eq '--gopher') {
105fd7
         $gopher = 1;
105fd7
     }
105fd7
@@ -117,7 +125,12 @@ if(!$logfile) {
105fd7
 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
105fd7
 $flags .= "--gopher " if($gopher);
105fd7
 $flags .= "--connect $connect " if($connect);
105fd7
-$flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
105fd7
+if($ipvnum eq 'unix') {
105fd7
+    $flags .= "--unix-socket '$unix_socket' ";
105fd7
+} else {
105fd7
+    $flags .= "--ipv$ipvnum --port $port ";
105fd7
+}
105fd7
+$flags .= "--srcdir \"$srcdir\"";
105fd7
 
105fd7
 if($verbose) {
105fd7
     print STDERR "RUN: server/sws $flags\n";
105fd7
diff --git a/tests/runtests.pl b/tests/runtests.pl
105fd7
index b39da66..fa96345 100755
105fd7
--- a/tests/runtests.pl
105fd7
+++ b/tests/runtests.pl
105fd7
@@ -140,6 +140,7 @@ my $GOPHER6PORT;         # Gopher IPv6 server port
105fd7
 my $HTTPTLSPORT;         # HTTP TLS (non-stunnel) server port
105fd7
 my $HTTPTLS6PORT;        # HTTP TLS (non-stunnel) IPv6 server port
105fd7
 my $HTTPPROXYPORT;       # HTTP proxy port, when using CONNECT
105fd7
+my $HTTPUNIXPATH;        # HTTP server UNIX domain socket path
105fd7
 
105fd7
 my $srcdir = $ENV{'srcdir'} || '.';
105fd7
 my $CURL="../src/curl".exe_ext(); # what curl executable to run on the tests
105fd7
@@ -201,10 +202,12 @@ my $ssl_version; # set if libcurl is built with SSL support
105fd7
 my $large_file;  # set if libcurl is built with large file support
105fd7
 my $has_idn;     # set if libcurl is built with IDN support
105fd7
 my $http_ipv6;   # set if HTTP server has IPv6 support
105fd7
+my $http_unix;   # set if HTTP server has UNIX sockets support
105fd7
 my $ftp_ipv6;    # set if FTP server has IPv6 support
105fd7
 my $tftp_ipv6;   # set if TFTP server has IPv6 support
105fd7
 my $gopher_ipv6; # set if Gopher server has IPv6 support
105fd7
 my $has_ipv6;    # set if libcurl is built with IPv6 support
105fd7
+my $has_unix;    # set if libcurl is built with UNIX sockets support
105fd7
 my $has_libz;    # set if libcurl is built with libz support
105fd7
 my $has_getrlimit;  # set if system has getrlimit()
105fd7
 my $has_ntlm;    # set if libcurl is built with NTLM support
105fd7
@@ -358,6 +361,13 @@ sub init_serverpidfile_hash {
105fd7
       }
105fd7
     }
105fd7
   }
105fd7
+  for my $proto (('http', 'imap', 'pop3', 'smtp')) {
105fd7
+    for my $ssl (('', 's')) {
105fd7
+      my $serv = servername_id("$proto$ssl", "unix", 1);
105fd7
+      my $pidf = server_pidfilename("$proto$ssl", "unix", 1);
105fd7
+      $serverpidfile{$serv} = $pidf;
105fd7
+    }
105fd7
+  }
105fd7
 }
105fd7
 
105fd7
 #######################################################################
105fd7
@@ -641,11 +651,11 @@ sub stopserver {
105fd7
     # All servers relative to the given one must be stopped also
105fd7
     #
105fd7
     my @killservers;
105fd7
-    if($server =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|))$/) {
105fd7
+    if($server =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|-unix|))$/) {
105fd7
         # given a stunnel based ssl server, also kill non-ssl underlying one
105fd7
         push @killservers, "${1}${2}";
105fd7
     }
105fd7
-    elsif($server =~ /^(ftp|http|imap|pop3|smtp)((\d*)(-ipv6|))$/) {
105fd7
+    elsif($server =~ /^(ftp|http|imap|pop3|smtp)((\d*)(-ipv6|-unix|))$/) {
105fd7
         # given a non-ssl server, also kill stunnel based ssl piggybacking one
105fd7
         push @killservers, "${1}s${2}";
105fd7
     }
105fd7
@@ -691,10 +701,12 @@ sub stopserver {
105fd7
 # assign requested address")
105fd7
 #
105fd7
 sub verifyhttp {
105fd7
-    my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
105fd7
+    my ($proto, $ipvnum, $idnum, $ip, $port_or_path) = @_;
105fd7
     my $server = servername_id($proto, $ipvnum, $idnum);
105fd7
     my $pid = 0;
105fd7
     my $bonus="";
105fd7
+    # $port_or_path contains a path for UNIX sockets, sws ignores the port
105fd7
+    my $port = ($ipvnum eq "unix") ? 80 : $port_or_path;
105fd7
 
105fd7
     my $verifyout = "$LOGDIR/".
105fd7
         servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
105fd7
@@ -714,6 +726,7 @@ sub verifyhttp {
105fd7
     $flags .= "--silent ";
105fd7
     $flags .= "--verbose ";
105fd7
     $flags .= "--globoff ";
105fd7
+    $flags .= "--unix-socket '$port_or_path' " if $ipvnum eq "unix";
105fd7
     $flags .= "-1 "         if($has_axtls);
105fd7
     $flags .= "--insecure " if($proto eq 'https');
105fd7
     $flags .= "\"$proto://$ip:$port/${bonus}verifiedserver\"";
105fd7
@@ -1160,7 +1173,7 @@ sub responsiveserver {
105fd7
 # start the http server
105fd7
 #
105fd7
 sub runhttpserver {
105fd7
-    my ($proto, $verbose, $alt, $port) = @_;
105fd7
+    my ($proto, $verbose, $alt, $port_or_path) = @_;
105fd7
     my $ip = $HOSTIP;
105fd7
     my $ipvnum = 4;
105fd7
     my $idnum = 1;
105fd7
@@ -1188,6 +1201,10 @@ sub runhttpserver {
105fd7
     if ($doesntrun{$pidfile}) {
105fd7
         return (0,0);
105fd7
     }
105fd7
+    elsif($alt eq "unix") {
105fd7
+        # IP (protocol) is mutually exclusive with UNIX sockets
105fd7
+        $ipvnum = "unix";
105fd7
+    }
105fd7
 
105fd7
     my $pid = processexists($pidfile);
105fd7
     if($pid > 0) {
105fd7
@@ -1204,7 +1221,12 @@ sub runhttpserver {
105fd7
     $flags .= "--verbose " if($debugprotocol);
105fd7
     $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
105fd7
     $flags .= "--id $idnum " if($idnum > 1);
105fd7
-    $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
105fd7
+    if($ipvnum eq "unix") {
105fd7
+        $flags .= "--unix-socket '$port_or_path' ";
105fd7
+    } else {
105fd7
+        $flags .= "--ipv$ipvnum --port $port_or_path ";
105fd7
+    }
105fd7
+    $flags .= "--srcdir \"$srcdir\"";
105fd7
 
105fd7
     my $cmd = "$perl $srcdir/httpserver.pl $flags";
105fd7
     my ($httppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
105fd7
@@ -1219,7 +1241,7 @@ sub runhttpserver {
105fd7
     }
105fd7
 
105fd7
     # Server is up. Verify that we can speak to it.
105fd7
-    my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
105fd7
+    my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port_or_path);
105fd7
     if(!$pid3) {
105fd7
         logmsg "RUN: $srvrname server failed verification\n";
105fd7
         # failed to talk to it properly. Kill the server and return failure
105fd7
@@ -1984,7 +2006,7 @@ sub runsocksserver {
105fd7
 # be used to verify that a server present in %run hash is still functional
105fd7
 #
105fd7
 sub responsive_http_server {
105fd7
-    my ($proto, $verbose, $alt, $port) = @_;
105fd7
+    my ($proto, $verbose, $alt, $port_or_path) = @_;
105fd7
     my $ip = $HOSTIP;
105fd7
     my $ipvnum = 4;
105fd7
     my $idnum = 1;
105fd7
@@ -1997,8 +2019,12 @@ sub responsive_http_server {
105fd7
     elsif($alt eq "proxy") {
105fd7
         $idnum = 2;
105fd7
     }
105fd7
+    elsif($alt eq "unix") {
105fd7
+        # IP (protocol) is mutually exclusive with UNIX sockets
105fd7
+        $ipvnum = "unix";
105fd7
+    }
105fd7
 
105fd7
-    return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
105fd7
+    return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port_or_path);
105fd7
 }
105fd7
 
105fd7
 #######################################################################
105fd7
@@ -2264,9 +2290,10 @@ sub checksystem {
105fd7
             @protocols = split(' ', lc($1));
105fd7
 
105fd7
             # Generate a "proto-ipv6" version of each protocol to match the
105fd7
-            # IPv6 <server> name. This works even if IPv6 support isn't
105fd7
+            # IPv6 <server> name and a "proto-unix" to match the variant which
105fd7
+            # uses UNIX domain sockets. This works even if support isn't
105fd7
             # compiled in because the <features> test will fail.
105fd7
-            push @protocols, map($_ . '-ipv6', @protocols);
105fd7
+            push @protocols, map(("$_-ipv6", "$_-unix"), @protocols);
105fd7
 
105fd7
             # 'http-proxy' is used in test cases to do CONNECT through
105fd7
             push @protocols, 'http-proxy';
105fd7
@@ -2299,6 +2326,9 @@ sub checksystem {
105fd7
             if($feat =~ /IPv6/i) {
105fd7
                 $has_ipv6 = 1;
105fd7
             }
105fd7
+            if($feat =~ /unix-sockets/i) {
105fd7
+                $has_unix = 1;
105fd7
+            }
105fd7
             if($feat =~ /libz/i) {
105fd7
                 $has_libz = 1;
105fd7
             }
105fd7
@@ -2396,6 +2426,12 @@ sub checksystem {
105fd7
         }
105fd7
     }
105fd7
 
105fd7
+    if($has_unix) {
105fd7
+        # client has UNIX sockets support, check whether the HTTP server has it
105fd7
+        my @sws = `server/sws --version`;
105fd7
+        $http_unix = 1 if($sws[0] =~ /unix/);
105fd7
+    }
105fd7
+
105fd7
     if(!$curl_debug && $torture) {
105fd7
         die "can't run torture tests since curl was not built with curldebug";
105fd7
     }
105fd7
@@ -2423,6 +2459,7 @@ sub checksystem {
105fd7
     logmsg sprintf("  track memory: %s\n", $curl_debug?"ON ":"OFF");
105fd7
     logmsg sprintf("* valgrind:     %8s", $valgrind?"ON ":"OFF");
105fd7
     logmsg sprintf("  HTTP IPv6     %s\n", $http_ipv6?"ON ":"OFF");
105fd7
+    logmsg sprintf("* HTTP UNIX     %s\n", $http_unix?"ON ":"OFF");
105fd7
     logmsg sprintf("* FTP IPv6      %8s", $ftp_ipv6?"ON ":"OFF");
105fd7
     logmsg sprintf("  Libtool lib:  %s\n", $libtool?"ON ":"OFF");
105fd7
     logmsg sprintf("* Shared build:      %s\n", $has_shared);
105fd7
@@ -2473,6 +2510,13 @@ sub checksystem {
105fd7
         logmsg "\n";
105fd7
     }
105fd7
 
105fd7
+    if($has_unix) {
105fd7
+        logmsg "* UNIX socket paths:\n";
105fd7
+        if($http_unix) {
105fd7
+            logmsg sprintf("*   HTTP-UNIX:%s\n", $HTTPUNIXPATH);
105fd7
+        }
105fd7
+    }
105fd7
+
105fd7
     $has_textaware = ($^O eq 'MSWin32') || ($^O eq 'msys');
105fd7
 
105fd7
     logmsg "***************************************** \n";
105fd7
@@ -2520,6 +2564,10 @@ sub subVariables {
105fd7
   $$thing =~ s/%TFTP6PORT/$TFTP6PORT/g;
105fd7
   $$thing =~ s/%TFTPPORT/$TFTPPORT/g;
105fd7
 
105fd7
+  # server UNIX domain socket paths
105fd7
+
105fd7
+  $$thing =~ s/%HTTPUNIXPATH/$HTTPUNIXPATH/g;
105fd7
+
105fd7
   # client IP addresses
105fd7
 
105fd7
   $$thing =~ s/%CLIENT6IP/$CLIENT6IP/g;
105fd7
@@ -2707,6 +2755,11 @@ sub singletest {
105fd7
                 next;
105fd7
             }
105fd7
         }
105fd7
+        elsif($f eq "unix-sockets") {
105fd7
+            if($has_unix) {
105fd7
+                next;
105fd7
+            }
105fd7
+        }
105fd7
         elsif($f eq "libz") {
105fd7
             if($has_libz) {
105fd7
                 next;
105fd7
@@ -3219,11 +3272,11 @@ sub singletest {
105fd7
         my @killservers;
105fd7
         foreach my $server (@killtestservers) {
105fd7
             chomp $server;
105fd7
-            if($server =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|))$/) {
105fd7
+            if($server =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|-unix|))$/) {
105fd7
                 # given a stunnel ssl server, also kill non-ssl underlying one
105fd7
                 push @killservers, "${1}${2}";
105fd7
             }
105fd7
-            elsif($server =~ /^(ftp|http|imap|pop3|smtp)((\d*)(-ipv6|))$/) {
105fd7
+            elsif($server =~ /^(ftp|http|imap|pop3|smtp)((\d*)(-ipv6|-unix|))$/) {
105fd7
                 # given a non-ssl server, also kill stunnel piggybacking one
105fd7
                 push @killservers, "${1}s${2}";
105fd7
             }
105fd7
@@ -3728,7 +3781,7 @@ sub startservers {
105fd7
         $what =~ s/[^a-z0-9-]//g;
105fd7
 
105fd7
         my $certfile;
105fd7
-        if($what =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|))$/) {
105fd7
+        if($what =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|-unix|))$/) {
105fd7
             $certfile = ($whatlist[1]) ? $whatlist[1] : 'stunnel.pem';
105fd7
         }
105fd7
 
105fd7
@@ -4066,6 +4119,22 @@ sub startservers {
105fd7
                 }
105fd7
             }
105fd7
         }
105fd7
+        elsif($what eq "http-unix") {
105fd7
+            if($torture && $run{'http-unix'} &&
105fd7
+               !responsive_http_server("http", $verbose, "unix", $HTTPUNIXPATH)) {
105fd7
+                stopserver('http-unix');
105fd7
+            }
105fd7
+            if(!$run{'http-unix'}) {
105fd7
+                ($pid, $pid2) = runhttpserver("http", $verbose, "unix",
105fd7
+                                              $HTTPUNIXPATH);
105fd7
+                if($pid <= 0) {
105fd7
+                    return "failed starting HTTP-unix server";
105fd7
+                }
105fd7
+                logmsg sprintf("* pid http-unix => %d %d\n", $pid, $pid2)
105fd7
+                    if($verbose);
105fd7
+                $run{'http-unix'}="$pid $pid2";
105fd7
+            }
105fd7
+        }
105fd7
         elsif($what eq "none") {
105fd7
             logmsg "* starts no server\n" if ($verbose);
105fd7
         }
105fd7
@@ -4502,6 +4571,7 @@ $GOPHER6PORT     = $base++; # Gopher IPv6 server port
105fd7
 $HTTPTLSPORT     = $base++; # HTTP TLS (non-stunnel) server port
105fd7
 $HTTPTLS6PORT    = $base++; # HTTP TLS (non-stunnel) IPv6 server port
105fd7
 $HTTPPROXYPORT   = $base++; # HTTP proxy port, when using CONNECT
105fd7
+$HTTPUNIXPATH    = 'http.sock'; # HTTP server UNIX domain socket path
105fd7
 
105fd7
 #######################################################################
105fd7
 # clear and create logging directory:
105fd7
diff --git a/tests/serverhelp.pm b/tests/serverhelp.pm
105fd7
index a1d1dc3..1fc621b 100644
105fd7
--- a/tests/serverhelp.pm
105fd7
+++ b/tests/serverhelp.pm
105fd7
@@ -109,8 +109,8 @@ sub servername_str {
105fd7
 
105fd7
     $ipver = (not $ipver) ? 'ipv4' : lc($ipver);
105fd7
     die "unsupported IP version: '$ipver'" unless($ipver &&
105fd7
-        ($ipver =~ /^(4|6|ipv4|ipv6|-ipv4|-ipv6)$/));
105fd7
-    $ipver = ($ipver =~ /6$/) ? '-IPv6' : '';
105fd7
+        ($ipver =~ /^(4|6|ipv4|ipv6|-ipv4|-ipv6|unix)$/));
105fd7
+    $ipver = ($ipver =~ /6$/) ? '-IPv6' : (($ipver =~ /unix$/) ? '-unix' : '');
105fd7
 
105fd7
     $idnum = 1 if(not $idnum);
105fd7
     die "unsupported ID number: '$idnum'" unless($idnum &&
105fd7
-- 
105fd7
2.5.2
105fd7
105fd7
105fd7
From d2f7b1d51e356586356da87d1ae32c0c44274887 Mon Sep 17 00:00:00 2001
105fd7
From: Peter Wu <peter@lekensteyn.nl>
105fd7
Date: Thu, 27 Nov 2014 23:59:24 +0100
105fd7
Subject: [PATCH 06/11] tests: add two HTTP over UNIX socket tests
105fd7
105fd7
test1435: a simple test that checks whether a HTTP request can be
105fd7
performed over the UNIX socket. The hostname/port are interpreted
105fd7
by sws and should be ignored by cURL.
105fd7
105fd7
test1436: test for the ability to do two requests to the same host,
105fd7
interleaved with one to a different hostname.
105fd7
105fd7
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
105fd7
105fd7
Upstream-commit: 479abdd32eee15dab78d0cd6b1786d569680f0ac
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 tests/data/Makefile.am |  1 +
105fd7
 tests/data/Makefile.in |  1 +
105fd7
 tests/data/test1435    | 46 +++++++++++++++++++++++++++
105fd7
 tests/data/test1436    | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++
105fd7
 4 files changed, 133 insertions(+)
105fd7
 create mode 100644 tests/data/test1435
105fd7
 create mode 100644 tests/data/test1436
105fd7
105fd7
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
105fd7
index c4f76df..35bc6eb 100644
105fd7
--- a/tests/data/Makefile.am
105fd7
+++ b/tests/data/Makefile.am
105fd7
@@ -93,6 +93,7 @@ test1379 test1380 test1381 test1382 test1383 test1384 test1385 test1386 \
105fd7
 test1387 test1388 test1389 test1390 test1391 test1392 test1393 \
105fd7
 test1400 test1401 test1402 test1403 test1404 test1405 test1406 test1407 \
105fd7
 test1408 test1409 test1410 test1411 test1412 test1413 test1415 \
105fd7
+test1435 test1436 \
105fd7
 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \
105fd7
 test1508 test1529 \
105fd7
 test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 \
105fd7
diff --git a/tests/data/Makefile.in b/tests/data/Makefile.in
105fd7
index e73ca96..d5e5f01 100644
105fd7
--- a/tests/data/Makefile.in
105fd7
+++ b/tests/data/Makefile.in
105fd7
@@ -357,6 +357,7 @@ test1379 test1380 test1381 test1382 test1383 test1384 test1385 test1386 \
105fd7
 test1387 test1388 test1389 test1390 test1391 test1392 test1393 \
105fd7
 test1400 test1401 test1402 test1403 test1404 test1405 test1406 test1407 \
105fd7
 test1408 test1409 test1410 test1411 test1412 test1413 test1415 \
105fd7
+test1435 test1436 \
105fd7
 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \
105fd7
 test1508 test1529 \
105fd7
 test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 \
105fd7
diff --git a/tests/data/test1435 b/tests/data/test1435
105fd7
new file mode 100644
105fd7
index 0000000..56ff9d1
105fd7
--- /dev/null
105fd7
+++ b/tests/data/test1435
105fd7
@@ -0,0 +1,46 @@
105fd7
+<testcase>
105fd7
+<info>
105fd7
+<keywords>
105fd7
+HTTP
105fd7
+HTTP GET
105fd7
+unix sockets
105fd7
+</keywords>
105fd7
+</info>
105fd7
+
105fd7
+<reply>
105fd7
+<data>
105fd7
+HTTP/1.1 200 OK
105fd7
+Date: Sun, 16 Nov 2014 23:47:38 GMT
105fd7
+Content-Length: 17
105fd7
+
105fd7
+Based on test300
105fd7
+</data>
105fd7
+</reply>
105fd7
+
105fd7
+<client>
105fd7
+<features>
105fd7
+unix-sockets
105fd7
+</features>
105fd7
+<server>
105fd7
+http-unix
105fd7
+</server>
105fd7
+ <name>
105fd7
+simple HTTP GET over UNIX socket
105fd7
+ </name>
105fd7
+ <command>
105fd7
+--unix-socket %HTTPUNIXPATH http://server-interpreted.example.com/1435
105fd7
+</command>
105fd7
+</client>
105fd7
+
105fd7
+<verify>
105fd7
+<strip>
105fd7
+^User-Agent:.*
105fd7
+</strip>
105fd7
+<protocol>
105fd7
+GET /1435 HTTP/1.1
105fd7
+Host: server-interpreted.example.com
105fd7
+Accept: */*
105fd7
+
105fd7
+</protocol>
105fd7
+</verify>
105fd7
+</testcase>
105fd7
diff --git a/tests/data/test1436 b/tests/data/test1436
105fd7
new file mode 100644
105fd7
index 0000000..b16eadd
105fd7
--- /dev/null
105fd7
+++ b/tests/data/test1436
105fd7
@@ -0,0 +1,85 @@
105fd7
+<testcase>
105fd7
+<info>
105fd7
+<keywords>
105fd7
+HTTP
105fd7
+HTTP GET
105fd7
+unix sockets
105fd7
+</keywords>
105fd7
+</info>
105fd7
+
105fd7
+<reply>
105fd7
+<data1>
105fd7
+HTTP/1.1 200 OK
105fd7
+Date: Mon, 17 Nov 2014 13:42:47 GMT
105fd7
+Content-Length: 6
105fd7
+
105fd7
+First
105fd7
+</data1>
105fd7
+<data2>
105fd7
+HTTP/1.1 200 OK
105fd7
+Date: Mon, 17 Nov 2014 13:42:48 GMT
105fd7
+Content-Length: 7
105fd7
+
105fd7
+Second
105fd7
+</data2>
105fd7
+<data3>
105fd7
+HTTP/1.1 200 OK
105fd7
+Date: Mon, 17 Nov 2014 13:42:49 GMT
105fd7
+Content-Length: 6
105fd7
+
105fd7
+Third
105fd7
+</data3>
105fd7
+</reply>
105fd7
+
105fd7
+<client>
105fd7
+<features>
105fd7
+unix-sockets
105fd7
+</features>
105fd7
+<server>
105fd7
+http-unix
105fd7
+</server>
105fd7
+ <name>
105fd7
+HTTP requests with multiple connections over UNIX socket
105fd7
+ </name>
105fd7
+ <command>
105fd7
+--unix-socket %HTTPUNIXPATH http://one.example.com/14360001 http://two.example.com/14360002 http://one.example.com/14360003
105fd7
+</command>
105fd7
+</client>
105fd7
+
105fd7
+<verify>
105fd7
+<strip>
105fd7
+^User-Agent:.*
105fd7
+</strip>
105fd7
+<protocol>
105fd7
+GET /14360001 HTTP/1.1
105fd7
+Host: one.example.com
105fd7
+Accept: */*
105fd7
+
105fd7
+GET /14360002 HTTP/1.1
105fd7
+Host: two.example.com
105fd7
+Accept: */*
105fd7
+
105fd7
+GET /14360003 HTTP/1.1
105fd7
+Host: one.example.com
105fd7
+Accept: */*
105fd7
+
105fd7
+</protocol>
105fd7
+<stdout>
105fd7
+HTTP/1.1 200 OK
105fd7
+Date: Mon, 17 Nov 2014 13:42:47 GMT
105fd7
+Content-Length: 6
105fd7
+
105fd7
+First
105fd7
+HTTP/1.1 200 OK
105fd7
+Date: Mon, 17 Nov 2014 13:42:48 GMT
105fd7
+Content-Length: 7
105fd7
+
105fd7
+Second
105fd7
+HTTP/1.1 200 OK
105fd7
+Date: Mon, 17 Nov 2014 13:42:49 GMT
105fd7
+Content-Length: 6
105fd7
+
105fd7
+Third
105fd7
+</stdout>
105fd7
+</verify>
105fd7
+</testcase>
105fd7
-- 
105fd7
2.5.2
105fd7
105fd7
105fd7
From f784b2d3d6cf08193662a23aae9305f11c4a4559 Mon Sep 17 00:00:00 2001
105fd7
From: Peter Wu <peter@lekensteyn.nl>
105fd7
Date: Thu, 27 Nov 2014 23:59:25 +0100
105fd7
Subject: [PATCH 07/11] libcurl: add UNIX domain sockets support
105fd7
105fd7
The ability to do HTTP requests over a UNIX domain socket has been
105fd7
requested before, in Apr 2008 [0][1] and Sep 2010 [2]. While a
105fd7
discussion happened, no patch seems to get through. I decided to give it
105fd7
a go since I need to test a nginx HTTP server which listens on a UNIX
105fd7
domain socket.
105fd7
105fd7
One patch [3] seems to make it possible to use the
105fd7
CURLOPT_OPENSOCKETFUNCTION function to gain a UNIX domain socket.
105fd7
Another person wrote a Go program which can do HTTP over a UNIX socket
105fd7
for Docker[4] which uses a special URL scheme (though the name contains
105fd7
cURL, it has no relation to the cURL library).
105fd7
105fd7
This patch considers support for UNIX domain sockets at the same level
105fd7
as HTTP proxies / IPv6, it acts as an intermediate socket provider and
105fd7
not as a separate protocol. Since this feature affects network
105fd7
operations, a new feature flag was added ("unix-sockets") with a
105fd7
corresponding CURL_VERSION_UNIX_SOCKETS macro.
105fd7
105fd7
A new CURLOPT_UNIX_SOCKET_PATH option is added and documented. This
105fd7
option enables UNIX domain sockets support for all requests on the
105fd7
handle (replacing IP sockets and skipping proxies).
105fd7
105fd7
A new configure option (--enable-unix-sockets) and CMake option
105fd7
(ENABLE_UNIX_SOCKETS) can disable this optional feature. Note that I
105fd7
deliberately did not mark this feature as advanced, this is a
105fd7
feature/component that should easily be available.
105fd7
105fd7
 [0]: http://curl.haxx.se/mail/lib-2008-04/0279.html
105fd7
 [1]: http://daniel.haxx.se/blog/2008/04/14/http-over-unix-domain-sockets/
105fd7
 [2]: http://sourceforge.net/p/curl/feature-requests/53/
105fd7
 [3]: http://curl.haxx.se/mail/lib-2008-04/0361.html
105fd7
 [4]: https://github.com/Soulou/curl-unix-socket
105fd7
105fd7
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
105fd7
105fd7
Upstream-commit: 970c22f970f0172e6a4c98ccc3176c740ddaa1c6
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 configure                        | 112 +++++++++++++++++++++++++++++++++++++++
105fd7
 configure.ac                     |  38 +++++++++++++
105fd7
 docs/libcurl/curl_easy_setopt.3  |  12 +++++
105fd7
 docs/libcurl/curl_version_info.3 |   2 +
105fd7
 docs/libcurl/symbols-in-versions |   2 +
105fd7
 include/curl/curl.h              |   4 ++
105fd7
 lib/Makefile.in                  |   1 +
105fd7
 lib/curl_addrinfo.c              |  39 ++++++++++++++
105fd7
 lib/curl_addrinfo.h              |   4 ++
105fd7
 lib/curl_config.h.in             |   3 ++
105fd7
 lib/url.c                        |  44 +++++++++++++++
105fd7
 lib/urldata.h                    |   4 ++
105fd7
 lib/version.c                    |   3 ++
105fd7
 src/Makefile.in                  |   1 +
105fd7
 src/tool_getparam.c              |   3 +-
105fd7
 tests/server/Makefile.in         |   1 +
105fd7
 16 files changed, 272 insertions(+), 1 deletion(-)
105fd7
105fd7
diff --git a/configure b/configure
105fd7
index c5d1817..3e1f5d3 100755
105fd7
--- a/configure
105fd7
+++ b/configure
105fd7
@@ -889,6 +889,7 @@ SONAME_BUMP_TRUE
105fd7
 CFLAG_CURL_SYMBOL_HIDING
105fd7
 DOING_CURL_SYMBOL_HIDING_FALSE
105fd7
 DOING_CURL_SYMBOL_HIDING_TRUE
105fd7
+USE_UNIX_SOCKETS
105fd7
 BUILD_LIBHOSTNAME_FALSE
105fd7
 BUILD_LIBHOSTNAME_TRUE
105fd7
 USE_EMBEDDED_ARES_FALSE
105fd7
@@ -1159,6 +1160,7 @@ enable_sspi
105fd7
 enable_crypto_auth
105fd7
 enable_ntlm_wb
105fd7
 enable_tls_srp
105fd7
+enable_unix_sockets
105fd7
 enable_cookies
105fd7
 enable_soname_bump
105fd7
 '
105fd7
@@ -1873,6 +1875,8 @@ Optional Features:
105fd7
                           helper
105fd7
   --enable-tls-srp        Enable TLS-SRP authentication
105fd7
   --disable-tls-srp       Disable TLS-SRP authentication
105fd7
+  --enable-unix-sockets   Enable UNIX domain sockets
105fd7
+  --disable-unix-sockets  Disable UNIX domain sockets
105fd7
   --enable-cookies        Enable cookies support
105fd7
   --disable-cookies       Disable cookies support
105fd7
   --enable-soname-bump    Enable enforced SONAME bump
105fd7
@@ -2607,6 +2611,61 @@ $as_echo "$ac_res" >&6; }
105fd7
   eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
105fd7
 
105fd7
 } # ac_fn_c_check_type
105fd7
+
105fd7
+# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
105fd7
+# ----------------------------------------------------
105fd7
+# Tries to find if the field MEMBER exists in type AGGR, after including
105fd7
+# INCLUDES, setting cache variable VAR accordingly.
105fd7
+ac_fn_c_check_member ()
105fd7
+{
105fd7
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
105fd7
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
105fd7
+$as_echo_n "checking for $2.$3... " >&6; }
105fd7
+if eval \${$4+:} false; then :
105fd7
+  $as_echo_n "(cached) " >&6
105fd7
+else
105fd7
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
105fd7
+/* end confdefs.h.  */
105fd7
+$5
105fd7
+int main (void)
105fd7
+{
105fd7
+static $2 ac_aggr;
105fd7
+if (ac_aggr.$3)
105fd7
+return 0;
105fd7
+ ;
105fd7
+ return 0;
105fd7
+}
105fd7
+_ACEOF
105fd7
+if ac_fn_c_try_compile "$LINENO"; then :
105fd7
+  eval "$4=yes"
105fd7
+else
105fd7
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
105fd7
+/* end confdefs.h.  */
105fd7
+$5
105fd7
+int main (void)
105fd7
+{
105fd7
+static $2 ac_aggr;
105fd7
+if (sizeof ac_aggr.$3)
105fd7
+return 0;
105fd7
+ ;
105fd7
+ return 0;
105fd7
+}
105fd7
+_ACEOF
105fd7
+if ac_fn_c_try_compile "$LINENO"; then :
105fd7
+  eval "$4=yes"
105fd7
+else
105fd7
+  eval "$4=no"
105fd7
+fi
105fd7
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
105fd7
+fi
105fd7
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
105fd7
+fi
105fd7
+eval ac_res=\$$4
105fd7
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
105fd7
+$as_echo "$ac_res" >&6; }
105fd7
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
105fd7
+
105fd7
+} # ac_fn_c_check_member
105fd7
 cat >config.log <<_ACEOF
105fd7
 This file contains any messages produced by compilers while
105fd7
 running configure, to aid debugging if configure makes a mistake.
105fd7
@@ -5447,6 +5506,7 @@ PKGADD_VENDOR="curl.haxx.se"
105fd7
 curl_tls_srp_msg="no      (--enable-tls-srp)"
105fd7
     curl_res_msg="default (--enable-ares / --enable-threaded-resolver)"
105fd7
    curl_ipv6_msg="no      (--enable-ipv6)"
105fd7
+curl_unix_sockets_msg="no      (--enable-unix-sockets)"
105fd7
     curl_idn_msg="no      (--with-{libidn,winidn})"
105fd7
  curl_manual_msg="no      (--enable-manual)"
105fd7
 curl_libcurl_msg="enabled (--disable-libcurl-option)"
105fd7
@@ -39239,6 +39299,53 @@ $as_echo "#define USE_TLS_SRP 1" >>confdefs.h
105fd7
    curl_tls_srp_msg="enabled"
105fd7
 fi
105fd7
 
105fd7
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable UNIX domain sockets" >&5
105fd7
+$as_echo_n "checking whether to enable UNIX domain sockets... " >&6; }
105fd7
+# Check whether --enable-unix-sockets was given.
105fd7
+if test "${enable_unix_sockets+set}" = set; then :
105fd7
+  enableval=$enable_unix_sockets;  case "$enableval" in
105fd7
+  no)  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
105fd7
+$as_echo "no" >&6; }
105fd7
+       want_unix_sockets=no
105fd7
+       ;;
105fd7
+  *)   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
105fd7
+$as_echo "yes" >&6; }
105fd7
+       want_unix_sockets=yes
105fd7
+       ;;
105fd7
+  esac
105fd7
+else
105fd7
+
105fd7
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: auto" >&5
105fd7
+$as_echo "auto" >&6; }
105fd7
+       want_unix_sockets=auto
105fd7
+
105fd7
+
105fd7
+fi
105fd7
+
105fd7
+if test "x$want_unix_sockets" != "xno"; then
105fd7
+  ac_fn_c_check_member "$LINENO" "struct sockaddr_un" "sun_path" "ac_cv_member_struct_sockaddr_un_sun_path" "
105fd7
+    #include <sys/un.h>
105fd7
+
105fd7
+"
105fd7
+if test "x$ac_cv_member_struct_sockaddr_un_sun_path" = xyes; then :
105fd7
+
105fd7
+
105fd7
+$as_echo "#define USE_UNIX_SOCKETS 1" >>confdefs.h
105fd7
+
105fd7
+    USE_UNIX_SOCKETS=1
105fd7
+
105fd7
+    curl_unix_sockets_msg="enabled"
105fd7
+
105fd7
+else
105fd7
+
105fd7
+    if test "x$want_unix_sockets" = "xyes"; then
105fd7
+      as_fn_error $? "--enable-unix-sockets is not available on this platform!" "$LINENO" 5
105fd7
+    fi
105fd7
+
105fd7
+fi
105fd7
+
105fd7
+fi
105fd7
+
105fd7
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable support for cookies" >&5
105fd7
 $as_echo_n "checking whether to enable support for cookies... " >&6; }
105fd7
 # Check whether --enable-cookies was given.
105fd7
@@ -39357,6 +39464,9 @@ fi
105fd7
 if test "x$IPV6_ENABLED" = "x1"; then
105fd7
   SUPPORT_FEATURES="$SUPPORT_FEATURES IPv6"
105fd7
 fi
105fd7
+if test "x$USE_UNIX_SOCKETS" = "x1"; then
105fd7
+  SUPPORT_FEATURES="$SUPPORT_FEATURES unix-sockets"
105fd7
+fi
105fd7
 if test "x$HAVE_LIBZ" = "x1"; then
105fd7
   SUPPORT_FEATURES="$SUPPORT_FEATURES libz"
105fd7
 fi
105fd7
@@ -42289,6 +42399,7 @@ _EOF
105fd7
   TLS-SRP support:  ${curl_tls_srp_msg}
105fd7
   resolver:         ${curl_res_msg}
105fd7
   ipv6 support:     ${curl_ipv6_msg}
105fd7
+  UNIX sockets support: ${curl_unix_sockets_msg}
105fd7
   IDN support:      ${curl_idn_msg}
105fd7
   Build libcurl:    Shared=${enable_shared}, Static=${enable_static}
105fd7
   Built-in manual:  ${curl_manual_msg}
105fd7
@@ -42319,6 +42430,7 @@ $as_echo "$as_me: Configured to build curl/libcurl:
105fd7
   TLS-SRP support:  ${curl_tls_srp_msg}
105fd7
   resolver:         ${curl_res_msg}
105fd7
   ipv6 support:     ${curl_ipv6_msg}
105fd7
+  UNIX sockets support: ${curl_unix_sockets_msg}
105fd7
   IDN support:      ${curl_idn_msg}
105fd7
   Build libcurl:    Shared=${enable_shared}, Static=${enable_static}
105fd7
   Built-in manual:  ${curl_manual_msg}
105fd7
diff --git a/configure.ac b/configure.ac
105fd7
index 60a6b58..9612c2f 100644
105fd7
--- a/configure.ac
105fd7
+++ b/configure.ac
105fd7
@@ -156,6 +156,7 @@ dnl initialize all the info variables
105fd7
 curl_tls_srp_msg="no      (--enable-tls-srp)"
105fd7
     curl_res_msg="default (--enable-ares / --enable-threaded-resolver)"
105fd7
    curl_ipv6_msg="no      (--enable-ipv6)"
105fd7
+curl_unix_sockets_msg="no      (--enable-unix-sockets)"
105fd7
     curl_idn_msg="no      (--with-{libidn,winidn})"
105fd7
  curl_manual_msg="no      (--enable-manual)"
105fd7
 curl_libcurl_msg="enabled (--disable-libcurl-option)"
105fd7
@@ -3302,6 +3303,39 @@ if test "$want_tls_srp" = "yes" && ( test "x$HAVE_GNUTLS_SRP" = "x1" || test "x$
105fd7
 fi
105fd7
 
105fd7
 dnl ************************************************************
105fd7
+dnl disable UNIX domain sockets support
105fd7
+dnl
105fd7
+AC_MSG_CHECKING([whether to enable UNIX domain sockets])
105fd7
+AC_ARG_ENABLE(unix-sockets,
105fd7
+AC_HELP_STRING([--enable-unix-sockets],[Enable UNIX domain sockets])
105fd7
+AC_HELP_STRING([--disable-unix-sockets],[Disable UNIX domain sockets]),
105fd7
+[ case "$enableval" in
105fd7
+  no)  AC_MSG_RESULT(no)
105fd7
+       want_unix_sockets=no
105fd7
+       ;;
105fd7
+  *)   AC_MSG_RESULT(yes)
105fd7
+       want_unix_sockets=yes
105fd7
+       ;;
105fd7
+  esac ], [
105fd7
+       AC_MSG_RESULT(auto)
105fd7
+       want_unix_sockets=auto
105fd7
+       ]
105fd7
+)
105fd7
+if test "x$want_unix_sockets" != "xno"; then
105fd7
+  AC_CHECK_MEMBER([struct sockaddr_un.sun_path], [
105fd7
+    AC_DEFINE(USE_UNIX_SOCKETS, 1, [Use UNIX domain sockets])
105fd7
+    AC_SUBST(USE_UNIX_SOCKETS, [1])
105fd7
+    curl_unix_sockets_msg="enabled"
105fd7
+  ], [
105fd7
+    if test "x$want_unix_sockets" = "xyes"; then
105fd7
+      AC_MSG_ERROR([--enable-unix-sockets is not available on this platform!])
105fd7
+    fi
105fd7
+  ], [
105fd7
+    #include <sys/un.h>
105fd7
+  ])
105fd7
+fi
105fd7
+
105fd7
+dnl ************************************************************
105fd7
 dnl disable cookies support
105fd7
 dnl
105fd7
 AC_MSG_CHECKING([whether to enable support for cookies])
105fd7
@@ -3382,6 +3416,9 @@ fi
105fd7
 if test "x$IPV6_ENABLED" = "x1"; then
105fd7
   SUPPORT_FEATURES="$SUPPORT_FEATURES IPv6"
105fd7
 fi
105fd7
+if test "x$USE_UNIX_SOCKETS" = "x1"; then
105fd7
+  SUPPORT_FEATURES="$SUPPORT_FEATURES unix-sockets"
105fd7
+fi
105fd7
 if test "x$HAVE_LIBZ" = "x1"; then
105fd7
   SUPPORT_FEATURES="$SUPPORT_FEATURES libz"
105fd7
 fi
105fd7
@@ -3557,6 +3594,7 @@ AC_MSG_NOTICE([Configured to build curl/libcurl:
105fd7
   TLS-SRP support:  ${curl_tls_srp_msg}
105fd7
   resolver:         ${curl_res_msg}
105fd7
   ipv6 support:     ${curl_ipv6_msg}
105fd7
+  UNIX sockets support: ${curl_unix_sockets_msg}
105fd7
   IDN support:      ${curl_idn_msg}
105fd7
   Build libcurl:    Shared=${enable_shared}, Static=${enable_static}
105fd7
   Built-in manual:  ${curl_manual_msg}
105fd7
diff --git a/docs/libcurl/curl_easy_setopt.3 b/docs/libcurl/curl_easy_setopt.3
105fd7
index d73b664..ad739e1 100644
105fd7
--- a/docs/libcurl/curl_easy_setopt.3
105fd7
+++ b/docs/libcurl/curl_easy_setopt.3
105fd7
@@ -961,6 +961,18 @@ systems support this option. (Added in 7.25.0)
105fd7
 Pass a long. Sets the interval, in seconds, that the operating system will wait
105fd7
 between sending keepalive probes. Not all operating systems support this
105fd7
 option. (Added in 7.25.0)
105fd7
+.IP CURLOPT_UNIX_SOCKET_PATH
105fd7
+Pass a \fIpath\fP to a UNIX domain socket. This enables the use of UNIX domain
105fd7
+sockets as connection end point and sets the path to \fIpath\fP. If \fIpath\fP
105fd7
+is NULL, then UNIX domain sockets are disabled. An empty string will result in
105fd7
+an error at some point.
105fd7
+
105fd7
+When enabled, cURL will connect to the UNIX domain socket instead of
105fd7
+establishing a TCP connection to a host. Since no TCP connection is
105fd7
+established, cURL does not need to resolve the DNS hostname in the URL.
105fd7
+
105fd7
+The maximum path length on Cygwin, Linux and Solaris is 107. On other platforms
105fd7
+might be even less.
105fd7
 .SH NAMES and PASSWORDS OPTIONS (Authentication)
105fd7
 .IP CURLOPT_NETRC
105fd7
 This parameter controls the preference of libcurl between using user names and
105fd7
diff --git a/docs/libcurl/curl_version_info.3 b/docs/libcurl/curl_version_info.3
105fd7
index ccb2028..c148cbc 100644
105fd7
--- a/docs/libcurl/curl_version_info.3
105fd7
+++ b/docs/libcurl/curl_version_info.3
105fd7
@@ -133,6 +133,8 @@ libcurl was built with support for TLS-SRP. (Added in 7.21.4)
105fd7
 .IP CURL_VERSION_NTLM_WB
105fd7
 libcurl was built with support for NTLM delegation to a winbind helper.
105fd7
 (Added in 7.22.0)
105fd7
+.IP CURL_VERSION_UNIX_SOCKETS
105fd7
+libcurl was built with support for UNIX domain sockets.
105fd7
 .RE
105fd7
 \fIssl_version\fP is an ASCII string for the OpenSSL version used. If libcurl
105fd7
 has no SSL support, this is NULL.
105fd7
diff --git a/docs/libcurl/symbols-in-versions b/docs/libcurl/symbols-in-versions
105fd7
index b275900..0f7469d 100644
105fd7
--- a/docs/libcurl/symbols-in-versions
105fd7
+++ b/docs/libcurl/symbols-in-versions
105fd7
@@ -503,6 +503,7 @@ CURLOPT_TLSAUTH_TYPE            7.21.4
105fd7
 CURLOPT_TLSAUTH_USERNAME        7.21.4
105fd7
 CURLOPT_TRANSFERTEXT            7.1.1
105fd7
 CURLOPT_TRANSFER_ENCODING       7.21.6
105fd7
+CURLOPT_UNIX_SOCKET_PATH        7.40.0
105fd7
 CURLOPT_UNRESTRICTED_AUTH       7.10.4
105fd7
 CURLOPT_UPLOAD                  7.1
105fd7
 CURLOPT_URL                     7.1
105fd7
@@ -703,6 +704,7 @@ CURL_VERSION_SPNEGO             7.10.8
105fd7
 CURL_VERSION_SSL                7.10
105fd7
 CURL_VERSION_SSPI               7.13.2
105fd7
 CURL_VERSION_TLSAUTH_SRP        7.21.4
105fd7
+CURL_VERSION_UNIX_SOCKETS       7.40.0
105fd7
 CURL_WAIT_POLLIN                7.28.0
105fd7
 CURL_WAIT_POLLOUT               7.28.0
105fd7
 CURL_WAIT_POLLPRI               7.28.0
105fd7
diff --git a/include/curl/curl.h b/include/curl/curl.h
105fd7
index 8e548e3..14f6fd7 100644
105fd7
--- a/include/curl/curl.h
105fd7
+++ b/include/curl/curl.h
105fd7
@@ -1536,6 +1536,9 @@ typedef enum {
105fd7
   /* set the SMTP auth originator */
105fd7
   CINIT(MAIL_AUTH, OBJECTPOINT, 217),
105fd7
 
105fd7
+  /* Path to UNIX domain socket */
105fd7
+  CINIT(UNIX_SOCKET_PATH, OBJECTPOINT, 231),
105fd7
+
105fd7
   CURLOPT_LASTENTRY /* the last unused */
105fd7
 } CURLoption;
105fd7
 
105fd7
@@ -2154,6 +2157,7 @@ typedef struct {
105fd7
 #define CURL_VERSION_CURLDEBUG (1<<13) /* debug memory tracking supported */
105fd7
 #define CURL_VERSION_TLSAUTH_SRP (1<<14) /* TLS-SRP auth is supported */
105fd7
 #define CURL_VERSION_NTLM_WB   (1<<15) /* NTLM delegating to winbind helper */
105fd7
+#define CURL_VERSION_UNIX_SOCKETS (1<<19) /* UNIX domain sockets support */
105fd7
 
105fd7
  /*
105fd7
  * NAME curl_version_info()
105fd7
diff --git a/lib/Makefile.in b/lib/Makefile.in
105fd7
index ca02e27..5ad2600 100644
105fd7
--- a/lib/Makefile.in
105fd7
+++ b/lib/Makefile.in
105fd7
@@ -386,6 +386,7 @@ USE_OPENLDAP = @USE_OPENLDAP@
105fd7
 USE_POLARSSL = @USE_POLARSSL@
105fd7
 USE_SCHANNEL = @USE_SCHANNEL@
105fd7
 USE_SSLEAY = @USE_SSLEAY@
105fd7
+USE_UNIX_SOCKETS = @USE_UNIX_SOCKETS@
105fd7
 USE_WINDOWS_SSPI = @USE_WINDOWS_SSPI@
105fd7
 VERSION = @VERSION@
105fd7
 VERSIONED_FLAVOUR = @VERSIONED_FLAVOUR@
105fd7
diff --git a/lib/curl_addrinfo.c b/lib/curl_addrinfo.c
105fd7
index 10652c6..52e45ce 100644
105fd7
--- a/lib/curl_addrinfo.c
105fd7
+++ b/lib/curl_addrinfo.c
105fd7
@@ -33,6 +33,9 @@
105fd7
 #ifdef HAVE_ARPA_INET_H
105fd7
 #  include <arpa/inet.h>
105fd7
 #endif
105fd7
+#ifdef HAVE_SYS_UN_H
105fd7
+#  include <sys/un.h>
105fd7
+#endif
105fd7
 
105fd7
 #ifdef __VMS
105fd7
 #  include <in.h>
105fd7
@@ -477,6 +480,42 @@ Curl_addrinfo *Curl_str2addr(char *address, int port)
105fd7
   return NULL; /* bad input format */
105fd7
 }
105fd7
 
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+/**
105fd7
+ * Given a path to a UNIX domain socket, return a newly allocated Curl_addrinfo
105fd7
+ * struct initialized with this path.
105fd7
+ */
105fd7
+Curl_addrinfo *Curl_unix2addr(const char *path)
105fd7
+{
105fd7
+  Curl_addrinfo *ai;
105fd7
+  struct sockaddr_un *sun;
105fd7
+  size_t path_len;
105fd7
+
105fd7
+  ai = calloc(1, sizeof(Curl_addrinfo));
105fd7
+  if(!ai)
105fd7
+    return NULL;
105fd7
+  if((ai->ai_addr = calloc(1, sizeof(struct sockaddr_un))) == NULL) {
105fd7
+    free(ai);
105fd7
+    return NULL;
105fd7
+  }
105fd7
+  /* sun_path must be able to store the NUL-terminated path */
105fd7
+  path_len = strlen(path);
105fd7
+  if(path_len >= sizeof(sun->sun_path)) {
105fd7
+    free(ai->ai_addr);
105fd7
+    free(ai);
105fd7
+    return NULL;
105fd7
+  }
105fd7
+
105fd7
+  ai->ai_family = AF_UNIX;
105fd7
+  ai->ai_socktype = SOCK_STREAM; /* assume reliable transport for HTTP */
105fd7
+  ai->ai_addrlen = (curl_socklen_t) sizeof(struct sockaddr_un);
105fd7
+  sun = (void *) ai->ai_addr;
105fd7
+  sun->sun_family = AF_UNIX;
105fd7
+  memcpy(sun->sun_path, path, path_len + 1); /* copy NUL byte */
105fd7
+  return ai;
105fd7
+}
105fd7
+#endif
105fd7
+
105fd7
 #if defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO)
105fd7
 /*
105fd7
  * curl_dofreeaddrinfo()
105fd7
diff --git a/lib/curl_addrinfo.h b/lib/curl_addrinfo.h
105fd7
index 6d2b753..4ef8827 100644
105fd7
--- a/lib/curl_addrinfo.h
105fd7
+++ b/lib/curl_addrinfo.h
105fd7
@@ -79,6 +79,10 @@ Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port);
105fd7
 
105fd7
 Curl_addrinfo *Curl_str2addr(char *dotted, int port);
105fd7
 
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+Curl_addrinfo *Curl_unix2addr(const char *path);
105fd7
+#endif
105fd7
+
105fd7
 #if defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO)
105fd7
 void
105fd7
 curl_dofreeaddrinfo(struct addrinfo *freethis,
105fd7
diff --git a/lib/curl_config.h.in b/lib/curl_config.h.in
105fd7
index 1716c96..19b66fa 100644
105fd7
--- a/lib/curl_config.h.in
105fd7
+++ b/lib/curl_config.h.in
105fd7
@@ -1017,6 +1017,9 @@
105fd7
 /* Use TLS-SRP authentication */
105fd7
 #undef USE_TLS_SRP
105fd7
 
105fd7
+/* Use UNIX domain sockets */
105fd7
+#undef USE_UNIX_SOCKETS
105fd7
+
105fd7
 /* Define to 1 if you have the `normaliz' (WinIDN) library (-lnormaliz). */
105fd7
 #undef USE_WIN32_IDN
105fd7
 
105fd7
diff --git a/lib/url.c b/lib/url.c
105fd7
index 57944e4..7257b5e 100644
105fd7
--- a/lib/url.c
105fd7
+++ b/lib/url.c
105fd7
@@ -47,6 +47,10 @@
105fd7
 #include <inet.h>
105fd7
 #endif
105fd7
 
105fd7
+#ifdef HAVE_SYS_UN_H
105fd7
+#include <sys/un.h>
105fd7
+#endif
105fd7
+
105fd7
 #ifndef HAVE_SOCKET
105fd7
 #error "We can't compile without socket() support!"
105fd7
 #endif
105fd7
@@ -2429,6 +2433,13 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
105fd7
     data->set.tcp_keepintvl = va_arg(param, long);
105fd7
     break;
105fd7
 
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+  case CURLOPT_UNIX_SOCKET_PATH:
105fd7
+    result = setstropt(&data->set.str[STRING_UNIX_SOCKET_PATH],
105fd7
+                       va_arg(param, char *));
105fd7
+    break;
105fd7
+#endif
105fd7
+
105fd7
   default:
105fd7
     /* unknown tag and its companion, just ignore: */
105fd7
     result = CURLE_UNKNOWN_OPTION;
105fd7
@@ -4764,6 +4775,32 @@ static CURLcode resolve_server(struct SessionHandle *data,
105fd7
     /* set a pointer to the hostname we display */
105fd7
     fix_hostname(data, conn, &conn->host);
105fd7
 
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+    if(data->set.str[STRING_UNIX_SOCKET_PATH]) {
105fd7
+      /* UNIX domain sockets are local. The host gets ignored, just use the
105fd7
+       * specified domain socket address. Do not cache "DNS entries". There is
105fd7
+       * no DNS involved and we already have the filesystem path available */
105fd7
+      const char *path = data->set.str[STRING_UNIX_SOCKET_PATH];
105fd7
+
105fd7
+      hostaddr = calloc(1, sizeof(struct Curl_dns_entry));
105fd7
+      if(!hostaddr)
105fd7
+        result = CURLE_OUT_OF_MEMORY;
105fd7
+      else if((hostaddr->addr = Curl_unix2addr(path)) != NULL)
105fd7
+        hostaddr->inuse++;
105fd7
+      else {
105fd7
+        /* Long paths are not supported for now */
105fd7
+        if(strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {
105fd7
+          failf(data, "UNIX socket path too long: '%s'", path);
105fd7
+          result = CURLE_COULDNT_RESOLVE_HOST;
105fd7
+        }
105fd7
+        else
105fd7
+          result = CURLE_OUT_OF_MEMORY;
105fd7
+        free(hostaddr);
105fd7
+        hostaddr = NULL;
105fd7
+      }
105fd7
+    }
105fd7
+    else
105fd7
+#endif
105fd7
     if(!conn->proxy.name || !*conn->proxy.name) {
105fd7
       /* If not connecting via a proxy, extract the port from the URL, if it is
105fd7
        * there, thus overriding any defaults that might have been set above. */
105fd7
@@ -5071,6 +5108,13 @@ static CURLcode create_conn(struct SessionHandle *data,
105fd7
   else if(!proxy)
105fd7
     proxy = detect_proxy(conn);
105fd7
 
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+  if(proxy && data->set.str[STRING_UNIX_SOCKET_PATH]) {
105fd7
+    free(proxy);  /* UNIX domain sockets cannot be proxied, so disable it */
105fd7
+    proxy = NULL;
105fd7
+  }
105fd7
+#endif
105fd7
+
105fd7
   if(proxy && (!*proxy || (conn->handler->flags & PROTOPT_NONETWORK))) {
105fd7
     free(proxy);  /* Don't bother with an empty proxy string or if the
105fd7
                      protocol doesn't work with network */
105fd7
diff --git a/lib/urldata.h b/lib/urldata.h
105fd7
index b3ee7e3..723e40d 100644
105fd7
--- a/lib/urldata.h
105fd7
+++ b/lib/urldata.h
105fd7
@@ -1375,6 +1375,10 @@ enum dupstring {
105fd7
   STRING_TLSAUTH_PASSWORD,     /* TLS auth <password> */
105fd7
 #endif
105fd7
 
105fd7
+#ifdef USE_UNIX_SOCKETS
105fd7
+  STRING_UNIX_SOCKET_PATH,  /* path to UNIX socket, if used */
105fd7
+#endif
105fd7
+
105fd7
   /* -- end of zero-terminated strings -- */
105fd7
 
105fd7
   STRING_LASTZEROTERMINATED,
105fd7
diff --git a/lib/version.c b/lib/version.c
105fd7
index d39fe0c..e798738 100644
105fd7
--- a/lib/version.c
105fd7
+++ b/lib/version.c
105fd7
@@ -278,6 +278,9 @@ static curl_version_info_data version_info = {
105fd7
 #if defined(USE_TLS_SRP)
105fd7
   | CURL_VERSION_TLSAUTH_SRP
105fd7
 #endif
105fd7
+#if defined(USE_UNIX_SOCKETS)
105fd7
+  | CURL_VERSION_UNIX_SOCKETS
105fd7
+#endif
105fd7
   ,
105fd7
   NULL, /* ssl_version */
105fd7
   0,    /* ssl_version_num, this is kept at zero */
105fd7
diff --git a/src/Makefile.in b/src/Makefile.in
105fd7
index 5f739a9..948092f 100644
105fd7
--- a/src/Makefile.in
105fd7
+++ b/src/Makefile.in
105fd7
@@ -272,6 +272,7 @@ USE_OPENLDAP = @USE_OPENLDAP@
105fd7
 USE_POLARSSL = @USE_POLARSSL@
105fd7
 USE_SCHANNEL = @USE_SCHANNEL@
105fd7
 USE_SSLEAY = @USE_SSLEAY@
105fd7
+USE_UNIX_SOCKETS = @USE_UNIX_SOCKETS@
105fd7
 USE_WINDOWS_SSPI = @USE_WINDOWS_SSPI@
105fd7
 VERSION = @VERSION@
105fd7
 VERSIONED_FLAVOUR = @VERSIONED_FLAVOUR@
105fd7
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
105fd7
index 98d53a7..0cd84d5 100644
105fd7
--- a/src/tool_getparam.c
105fd7
+++ b/src/tool_getparam.c
105fd7
@@ -285,7 +285,8 @@ static const struct feat feats[] = {
105fd7
   {"krb4",           CURL_VERSION_KERBEROS4},
105fd7
   {"libz",           CURL_VERSION_LIBZ},
105fd7
   {"CharConv",       CURL_VERSION_CONV},
105fd7
-  {"TLS-SRP",        CURL_VERSION_TLSAUTH_SRP}
105fd7
+  {"TLS-SRP",        CURL_VERSION_TLSAUTH_SRP},
105fd7
+  {"unix-sockets",   CURL_VERSION_UNIX_SOCKETS}
105fd7
 };
105fd7
 
105fd7
 ParameterError getparameter(char *flag,    /* f or -long-flag */
105fd7
diff --git a/tests/server/Makefile.in b/tests/server/Makefile.in
105fd7
index 0ca4380..055fe9b 100644
105fd7
--- a/tests/server/Makefile.in
105fd7
+++ b/tests/server/Makefile.in
105fd7
@@ -329,6 +329,7 @@ USE_OPENLDAP = @USE_OPENLDAP@
105fd7
 USE_POLARSSL = @USE_POLARSSL@
105fd7
 USE_SCHANNEL = @USE_SCHANNEL@
105fd7
 USE_SSLEAY = @USE_SSLEAY@
105fd7
+USE_UNIX_SOCKETS = @USE_UNIX_SOCKETS@
105fd7
 USE_WINDOWS_SSPI = @USE_WINDOWS_SSPI@
105fd7
 VERSION = @VERSION@
105fd7
 VERSIONED_FLAVOUR = @VERSIONED_FLAVOUR@
105fd7
-- 
105fd7
2.5.2
105fd7
105fd7
105fd7
From 877e40cd741b5b65f503236a6947e38c28a2d6ce Mon Sep 17 00:00:00 2001
105fd7
From: Peter Wu <peter@lekensteyn.nl>
105fd7
Date: Thu, 27 Nov 2014 23:59:26 +0100
105fd7
Subject: [PATCH 08/11] tool: add --unix-socket option
105fd7
105fd7
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
105fd7
105fd7
Upstream-commit: c8644d1f638fdd8f4bf34fe64e910ba704fb26c0
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 src/tool_cfgable.c  | 1 +
105fd7
 src/tool_cfgable.h  | 2 ++
105fd7
 src/tool_getparam.c | 6 +++++-
105fd7
 src/tool_help.c     | 1 +
105fd7
 src/tool_operate.c  | 4 ++++
105fd7
 5 files changed, 13 insertions(+), 1 deletion(-)
105fd7
105fd7
diff --git a/src/tool_cfgable.c b/src/tool_cfgable.c
105fd7
index da11f4a..2479b73 100644
105fd7
--- a/src/tool_cfgable.c
105fd7
+++ b/src/tool_cfgable.c
105fd7
@@ -98,6 +98,7 @@ void free_config_fields(struct Configurable *config)
105fd7
 
105fd7
   config->trace_stream = NULL; /* closed elsewhere when appropriate */
105fd7
 
105fd7
+  Curl_safefree(config->unix_socket_path);
105fd7
   Curl_safefree(config->writeout);
105fd7
 
105fd7
   config->errors = NULL; /* closed elsewhere when appropriate */
105fd7
diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h
105fd7
index 1f6f948..a9b033b 100644
105fd7
--- a/src/tool_cfgable.h
105fd7
+++ b/src/tool_cfgable.h
105fd7
@@ -204,6 +204,8 @@ struct Configurable {
105fd7
   bool use_metalink;        /* process given URLs as metalink XML file */
105fd7
   metalinkfile *metalinkfile_list; /* point to the first node */
105fd7
   metalinkfile *metalinkfile_last; /* point to the last/current node */
105fd7
+
105fd7
+  char *unix_socket_path;   /* path to UNIX domain socket */
105fd7
 }; /* struct Configurable */
105fd7
 
105fd7
 void free_config_fields(struct Configurable *config);
105fd7
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
105fd7
index 0cd84d5..57cf97d 100644
105fd7
--- a/src/tool_getparam.c
105fd7
+++ b/src/tool_getparam.c
105fd7
@@ -144,7 +144,7 @@ static const struct LongShort aliases[]= {
105fd7
   {"$v", "ssl-reqd",                 FALSE},
105fd7
          /* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */
105fd7
   {"$w", "sessionid",                FALSE},
105fd7
-         /* ¡sessionid' listed as --no-sessionid in the help */
105fd7
+         /* ?sessionid' listed as --no-sessionid in the help */
105fd7
   {"$x", "ftp-ssl-control",          FALSE},
105fd7
   {"$y", "ftp-ssl-ccc",              FALSE},
105fd7
   {"$j", "ftp-ssl-ccc-mode",         TRUE},
105fd7
@@ -173,6 +173,7 @@ static const struct LongShort aliases[]= {
105fd7
   {"$H", "mail-auth",                TRUE},
105fd7
   {"$I", "post303",                  FALSE},
105fd7
   {"$J", "metalink",                 FALSE},
105fd7
+  {"$M", "unix-socket",              TRUE},
105fd7
   {"0",  "http1.0",                  FALSE},
105fd7
   {"1",  "tlsv1",                    FALSE},
105fd7
   {"10",  "tlsv1.0",                 FALSE},
105fd7
@@ -862,6 +863,9 @@ ParameterError getparameter(char *flag,    /* f or -long-flag */
105fd7
 #endif
105fd7
           break;
105fd7
         }
105fd7
+      case 'M': /* --unix-socket */
105fd7
+        GetStr(&config->unix_socket_path, nextarg);
105fd7
+        break;
105fd7
       }
105fd7
       break;
105fd7
     case '#': /* --progress-bar */
105fd7
diff --git a/src/tool_help.c b/src/tool_help.c
105fd7
index f7cd618..3a64e35 100644
105fd7
--- a/src/tool_help.c
105fd7
+++ b/src/tool_help.c
105fd7
@@ -214,6 +214,7 @@ static const char *const helptext[] = {
105fd7
   "     --tlsuser USER  TLS username",
105fd7
   "     --tlspassword STRING TLS password",
105fd7
   "     --tlsauthtype STRING  TLS authentication type (default SRP)",
105fd7
+  "     --unix-socket FILE    Connect through this UNIX domain socket",
105fd7
   " -A, --user-agent STRING  User-Agent to send to server (H)",
105fd7
   " -v, --verbose       Make the operation more talkative",
105fd7
   " -V, --version       Show version number and quit",
105fd7
diff --git a/src/tool_operate.c b/src/tool_operate.c
105fd7
index 4166fc2..7a13fcf 100644
105fd7
--- a/src/tool_operate.c
105fd7
+++ b/src/tool_operate.c
105fd7
@@ -1320,6 +1320,10 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
105fd7
         if(config->mail_auth)
105fd7
           my_setopt_str(curl, CURLOPT_MAIL_AUTH, config->mail_auth);
105fd7
 
105fd7
+        /* new in 7.40.0 */
105fd7
+        if(config->unix_socket_path)
105fd7
+          my_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, config->unix_socket_path);
105fd7
+
105fd7
         /* initialize retry vars for loop below */
105fd7
         retry_sleep_default = (config->retry_delay) ?
105fd7
           config->retry_delay*1000L : RETRY_SLEEP_DEFAULT; /* ms */
105fd7
-- 
105fd7
2.5.2
105fd7
105fd7
105fd7
From 60bdcf03a1696b3d09ad1c04824816766c513dcd Mon Sep 17 00:00:00 2001
105fd7
From: Daniel Stenberg <daniel@haxx.se>
105fd7
Date: Wed, 3 Dec 2014 02:35:12 +0100
105fd7
Subject: [PATCH 09/11] curl.1: added --unix-socket
105fd7
105fd7
Upstream-commit: 7853c1cfe6fc7828afbb812791a383781aca3be3
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 docs/curl.1 | 3 +++
105fd7
 1 file changed, 3 insertions(+)
105fd7
105fd7
diff --git a/docs/curl.1 b/docs/curl.1
105fd7
index 7f3571b..38fa084 100644
105fd7
--- a/docs/curl.1
105fd7
+++ b/docs/curl.1
105fd7
@@ -1471,6 +1471,9 @@ If this option is used several times, the last one will be used.
105fd7
 .IP "--trace-time"
105fd7
 Prepends a time stamp to each trace or verbose line that curl displays.
105fd7
 (Added in 7.14.0)
105fd7
+.IP "--unix-socket <path>"
105fd7
+(HTTP) Connect through this UNIX domain socket, instead of using the
105fd7
+network. (Added in 7.40.0)
105fd7
 .IP "-u, --user <user:password>"
105fd7
 Specify the user name and password to use for server authentication. Overrides
105fd7
 \fI-n, --netrc\fP and \fI--netrc-optional\fP.
105fd7
-- 
105fd7
2.5.2
105fd7
105fd7
105fd7
From af6fa1e00657c637d52cc24eab6d769b8eb793a9 Mon Sep 17 00:00:00 2001
105fd7
From: Daniel Stenberg <daniel@haxx.se>
105fd7
Date: Thu, 4 Dec 2014 02:46:15 +0100
105fd7
Subject: [PATCH 10/11] updateconninfo: clear destination struct before
105fd7
 getsockname()
105fd7
105fd7
Otherwise we may read uninitialized bytes later in the unix-domain
105fd7
sockets case.
105fd7
105fd7
Upstream-commit: 9730c9fb7075792a112b65a023379fad3ec8dda4
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 lib/connect.c | 1 +
105fd7
 1 file changed, 1 insertion(+)
105fd7
105fd7
diff --git a/lib/connect.c b/lib/connect.c
105fd7
index ba9ab92..5aa53fe 100644
105fd7
--- a/lib/connect.c
105fd7
+++ b/lib/connect.c
105fd7
@@ -630,6 +630,7 @@ void Curl_updateconninfo(struct connectdata *conn, curl_socket_t sockfd)
105fd7
     }
105fd7
 
105fd7
     len = sizeof(struct Curl_sockaddr_storage);
105fd7
+    memset(&ssloc, 0, sizeof(ssloc));
105fd7
     if(getsockname(sockfd, (struct sockaddr*) &ssloc, &len)) {
105fd7
       error = SOCKERRNO;
105fd7
       failf(data, "getsockname() failed with errno %d: %s",
105fd7
-- 
105fd7
2.5.2
105fd7
105fd7
105fd7
From 8d951bb327fb6a1e107e044dbc179096883c4489 Mon Sep 17 00:00:00 2001
105fd7
From: Peter Wu <peter@lekensteyn.nl>
105fd7
Date: Thu, 4 Dec 2014 11:01:41 -0800
105fd7
Subject: [PATCH 11/11] tool: fix CURLOPT_UNIX_SOCKET_PATH in --libcurl output
105fd7
105fd7
Mark CURLOPT_UNIX_SOCKET_PATH as string to ensure that it ends up as
105fd7
option in the file generated by --libcurl.
105fd7
105fd7
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
105fd7
105fd7
Upstream-commit: 2e557de09431854e4ad137cd741a582caa917517
105fd7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
105fd7
---
105fd7
 src/tool_operate.c | 3 ++-
105fd7
 1 file changed, 2 insertions(+), 1 deletion(-)
105fd7
105fd7
diff --git a/src/tool_operate.c b/src/tool_operate.c
105fd7
index 7a13fcf..41b0e6b 100644
105fd7
--- a/src/tool_operate.c
105fd7
+++ b/src/tool_operate.c
105fd7
@@ -1322,7 +1322,8 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
105fd7
 
105fd7
         /* new in 7.40.0 */
105fd7
         if(config->unix_socket_path)
105fd7
-          my_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, config->unix_socket_path);
105fd7
+          my_setopt_str(curl, CURLOPT_UNIX_SOCKET_PATH,
105fd7
+                        config->unix_socket_path);
105fd7
 
105fd7
         /* initialize retry vars for loop below */
105fd7
         retry_sleep_default = (config->retry_delay) ?
105fd7
-- 
105fd7
2.5.2
105fd7