Bump to libxml2 2.9.7
[platform/upstream/libxml2.git] / nanohttp.c
index e109ad7..9cd2292 100644 (file)
@@ -11,7 +11,6 @@
  * daniel@veillard.com
  */
 
-#define NEED_SOCKETS
 #define IN_LIBXML
 #include "libxml.h"
 
 #define XML_SOCKLEN_T unsigned int
 #endif
 
-#if defined(__MINGW32__) || defined(_WIN32_WCE)
-#ifndef _WINSOCKAPI_
-#define _WINSOCKAPI_
-#endif
+#if defined(_WIN32) && !defined(__CYGWIN__)
 #include <wsockcompat.h>
-#include <winsock2.h>
-#undef XML_SOCKLEN_T
-#define XML_SOCKLEN_T unsigned int
 #endif
 
 #include <libxml/globals.h>
@@ -182,7 +175,21 @@ xmlHTTPErrMemory(const char *extra)
  */
 static int socket_errno(void) {
 #ifdef _WINSOCKAPI_
-    return(WSAGetLastError());
+    int err = WSAGetLastError();
+    switch(err) {
+        case WSAECONNRESET:
+            return(ECONNRESET);
+        case WSAEINPROGRESS:
+            return(EINPROGRESS);
+        case WSAEINTR:
+            return(EINTR);
+        case WSAESHUTDOWN:
+            return(ESHUTDOWN);
+        case WSAEWOULDBLOCK:
+            return(EWOULDBLOCK);
+        default:
+            return(err);
+    }
 #else
     return(errno);
 #endif
@@ -629,7 +636,7 @@ xmlNanoHTTPRecv(xmlNanoHTTPCtxtPtr ctxt)
 
         if ((select(ctxt->fd + 1, &rfd, NULL, NULL, &tv) < 1)
 #if defined(EINTR)
-            && (errno != EINTR)
+            && (socket_errno() != EINTR)
 #endif
             )
             return (0);
@@ -1038,16 +1045,13 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr)
 static SOCKET
 xmlNanoHTTPConnectHost(const char *host, int port)
 {
-    struct hostent *h;
     struct sockaddr *addr = NULL;
-    struct in_addr ia;
     struct sockaddr_in sockin;
 
 #ifdef SUPPORT_IP6
     struct in6_addr ia6;
     struct sockaddr_in6 sockin6;
 #endif
-    int i;
     SOCKET s;
 
     memset (&sockin, 0, sizeof(sockin));
@@ -1084,7 +1088,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
 
        for (res = result; res; res = res->ai_next) {
            if (res->ai_family == AF_INET) {
-               if (res->ai_addrlen > sizeof(sockin)) {
+               if ((size_t)res->ai_addrlen > sizeof(sockin)) {
                    __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n");
                    freeaddrinfo (result);
                    return INVALID_SOCKET;
@@ -1094,7 +1098,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
                addr = (struct sockaddr *)&sockin;
 #ifdef SUPPORT_IP6
            } else if (have_ipv6 () && (res->ai_family == AF_INET6)) {
-               if (res->ai_addrlen > sizeof(sockin6)) {
+               if ((size_t)res->ai_addrlen > sizeof(sockin6)) {
                    __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n");
                    freeaddrinfo (result);
                    return INVALID_SOCKET;
@@ -1122,6 +1126,10 @@ xmlNanoHTTPConnectHost(const char *host, int port)
 #endif
 #if !defined(HAVE_GETADDRINFO) || !defined(_WIN32)
     {
+        struct hostent *h;
+        struct in_addr ia;
+        int i;
+
        h = gethostbyname (GETHOSTBYNAME_ARG_CAST host);
        if (h == NULL) {
 
@@ -1130,7 +1138,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
  * extraction code. it work on Linux, if it work on your platform
  * and one want to enable it, send me the defined(foobar) needed
  */
-#if defined(HAVE_NETDB_H) && defined(HOST_NOT_FOUND) && defined(linux)
+#if defined(HAVE_NETDB_H) && defined(HOST_NOT_FOUND) && defined(__linux__)
            const char *h_err_txt = "";
 
            switch (h_errno) {
@@ -1423,9 +1431,9 @@ retry:
     if (ctxt->port != 80) {
        /* reserve space for ':xxxxx', incl. potential proxy */
        if (proxy)
-           blen += 12;
+           blen += 17;
        else
-           blen += 6;
+           blen += 11;
     }
     bp = (char*)xmlMallocAtomic(blen);
     if ( bp == NULL ) {
@@ -1534,7 +1542,8 @@ retry:
        xmlGenericError(xmlGenericErrorContext,
                "\nRedirect to: %s\n", ctxt->location);
 #endif
-       while ( xmlNanoHTTPRecv(ctxt) > 0 ) ;
+       while ( xmlNanoHTTPRecv(ctxt) > 0 )
+            ;
         if (nbRedirects < XML_NANO_HTTP_MAX_REDIR) {
            nbRedirects++;
            if (redirURL != NULL)