More patch for Windows. Please try this.
This is additional to the previous bugfix patch.

Changes :
 move config files directory
 enable -x
 add inet_pton.c from web
 enable IPv6 ( merge from polipovc  http://code.google.com/p/polipovc/ )

To build by MinGW, Add inet_pton.c, existing dirent_compat.c, -DHAVE_IPv6
and -liphlpapi to Makefile.
I think that you should use -O0 and suitable -fexec-charset= on MinGW.


diff -Nur ./polipo-master/dns.c ./polipo-1.1.2/dns.c
--- ./polipo-master/dns.c       Fri Nov 21 09:15:36 2014
+++ ./polipo-1.1.2/dns.c        Tue Apr 28 18:37:23 2015
@@ -49,6 +49,9 @@
 int dnsNegativeTtl = 120;
 
 #ifdef HAVE_IPv6
+#ifdef WIN32
+#include <ws2tcpip.h>
+#endif
 int dnsQueryIPv6 = 2;
 #else
 const int dnsQueryIPv6 = 0;
@@ -169,6 +172,53 @@
 }
 #endif
 
+#ifdef WIN32
+#include <iphlpapi.h>
+//#include <stdio.h>
+int getlocalDNS() {
+   
+   FIXED_INFO * FixedInfo;
+   ULONG    ulOutBufLen;
+   DWORD    dwRetVal;
+   IP_ADDR_STRING * pIPAddr;
+
+   FixedInfo = (FIXED_INFO *) GlobalAlloc( GPTR, sizeof( FIXED_INFO ) );
+   ulOutBufLen = sizeof( FIXED_INFO );
+   
+   if( ERROR_BUFFER_OVERFLOW == GetNetworkParams( FixedInfo, &ulOutBufLen ) ) {
+      GlobalFree( FixedInfo );
+      FixedInfo = (FIXED_INFO *) GlobalAlloc( GPTR, ulOutBufLen );
+      if (FixedInfo == NULL) {
+        do_log(L_ERROR, "Error allocating memory for FIXED_INFO\n");
+        return -1; 
+      }
+   }
+
+   if ( dwRetVal = GetNetworkParams( FixedInfo, &ulOutBufLen ) ) {
+        do_log(L_ERROR, "GetNetworkParams failed with error: %08x\n", dwRetVal 
);
+        return -1;
+   }
+   else {
+      //do_log(L_WARN,  "Host Name: %s\n", FixedInfo -> HostName );
+      //do_log(L_WARN,  "Domain Name: %s\n", FixedInfo -> DomainName ); 
+      //printf( "DNS Servers:\n" );
+      // printf( "\t%s\n", FixedInfo -> DnsServerList.IpAddress.String );
+
+      if(dnsNameServer == NULL || dnsNameServer->string[0] == '\0'){
+         dnsNameServer = internAtom( FixedInfo -> 
DnsServerList.IpAddress.String );
+      }
+      return 0;
+      
+      //pIPAddr = FixedInfo -> DnsServerList.Next;
+      //while ( pIPAddr ) {
+      //   printf( "\t%s\n", pIPAddr ->IpAddress.String );
+      //   pIPAddr = pIPAddr ->Next;
+      //}
+   }
+}
+
+#endif //WIN32
+
 void
 preinitDns()
 {
@@ -194,13 +244,18 @@
         } else {
             do_log_error(L_WARN, errno, "DNS: couldn't create socket");
         }
-    } else {
+    }
+#ifndef WIN32
+    else {
         close(fd);
     }
 #endif
+#endif
 
 #ifndef NO_FANCY_RESOLVER
-#ifndef WIN32
+#ifdef WIN32
+    getlocalDNS();
+#else
     parseResolvConf("/etc/resolv.conf");
 #endif
     if(dnsNameServer == NULL || dnsNameServer->string[0] == '\0')
@@ -537,7 +592,7 @@
 #ifdef EAI_NONAME
     case EAI_NONAME:
 #endif
-#ifdef EAI_NODATA
+#if defined( EAI_NODATA ) && !defined( _MSC_VER )
     case EAI_NODATA:
 #endif
         error = EDNS_NO_ADDRESS; break;
@@ -546,7 +601,9 @@
 #ifdef EAI_MEMORY
     case EAI_MEMORY: error = ENOMEM; break;
 #endif
+#ifdef EAI_SYSTEM
     case EAI_SYSTEM: error = errno; break;
+#endif
     default: error = EUNKNOWN;
     }
 
diff -Nur ./polipo-master/forbidden.c ./polipo-1.1.2/forbidden.c
--- ./polipo-master/forbidden.c Fri Nov 21 09:15:36 2014
+++ ./polipo-1.1.2/forbidden.c  Tue Apr 28 18:37:23 2015
@@ -24,6 +24,16 @@
 
 #ifndef NO_FORBIDDEN
 
+#ifdef WIN32
+#define FOBIDDEN_FILE         "C:/polipo/forbidden"
+#define FOBIDDEN_TUNNELS_FILE "C:/polipo/forbiddenTunnels"
+#define UNCACHABLE_FILE       "C:/polipo/uncachable"
+#else
+#define FOBIDDEN_FILE         "/etc/polipo/forbidden"
+#define FOBIDDEN_TUNNELS_FILE "/etc/polipo/forbiddenTunnels"
+#define UNCACHABLE_FILE       "/etc/polipo/uncachable"
+#endif
+
 #include <regex.h>
 #include <assert.h>
 
@@ -314,8 +324,8 @@
     }
 
     if(forbiddenFile == NULL) {
-        if(access("/etc/polipo/forbidden", F_OK) >= 0)
-            forbiddenFile = internAtom("/etc/polipo/forbidden");
+        if(access(FOBIDDEN_FILE, F_OK) >= 0)
+            forbiddenFile = internAtom(FOBIDDEN_FILE);
     }
 
     parseDomainFile(forbiddenFile, &forbiddenDomains, &forbiddenRegex);
@@ -335,8 +345,8 @@
     }
 
     if(uncachableFile == NULL) {
-        if(access("/etc/polipo/uncachable", F_OK) >= 0)
-            uncachableFile = internAtom("/etc/polipo/uncachable");
+        if(access(UNCACHABLE_FILE, F_OK) >= 0)
+            uncachableFile = internAtom(UNCACHABLE_FILE);
     }
 
     parseDomainFile(uncachableFile, &uncachableDomains, &uncachableRegex);
@@ -355,8 +365,8 @@
     }
     
     if(forbiddenTunnelsFile == NULL) {
-        if(access("/etc/polipo/forbiddenTunnels", F_OK) >= 0)
-            forbiddenTunnelsFile = internAtom("/etc/polipo/forbiddenTunnels");
+        if(access(FOBIDDEN_TUNNELS_FILE, F_OK) >= 0)
+            forbiddenTunnelsFile = internAtom(FOBIDDEN_TUNNELS_FILE);
     }
     
     parseDomainFile(forbiddenTunnelsFile, &forbiddenTunnelsDomains, 
&forbiddenTunnelsRegex);
diff -Nur ./polipo-master/fts_compat.c ./polipo-1.1.2/fts_compat.c
--- ./polipo-master/fts_compat.c        Fri Nov 21 09:15:36 2014
+++ ./polipo-1.1.2/fts_compat.c Tue Apr 28 18:37:23 2015
@@ -30,6 +30,7 @@
 #include <unistd.h>
 #include <dirent.h>
 #else
+#include <io.h> //struct _finddata_t
 #include "dirent_compat.h"
 #endif
 #include <sys/stat.h>
@@ -135,11 +136,26 @@
  * Make the directory identified by the argument the current directory.
  */
 #ifdef WIN32 /*MINGW*/
+struct DIR
+{
+    long                handle; /* -1 for failed rewind */
+    struct _finddata_t  info;
+    struct dirent       result; /* d_name null iff first time */
+    char                *name;  /* null-terminated char string */
+};
+#ifndef MAX_PATH
+#define MAX_PATH _MAX_PATH
+#endif
 int
 change_to_dir(DIR *dir)
 {
-    errno = ENOSYS;
-    return -1;
+    int len;
+    char buf[MAX_PATH];
+
+    len = lstrlen(dir->name);
+    memcpy(buf, dir->name, len);
+    buf[len - 2] = '\0';
+    return chdir((const char *) buf);
 }
 #else
 int
diff -Nur ./polipo-master/inet_pton.c ./polipo-1.1.2/inet_pton.c
--- ./polipo-master/inet_pton.c Thu Jan 01 09:00:00 1970
+++ ./polipo-1.1.2/inet_pton.c  Tue Apr 28 18:37:23 2015
@@ -0,0 +1,179 @@
+/*
+ * 
http://stackoverflow.com/questions/15370033/how-to-use-inet-pton-with-the-mingw-compiler
+ *
+ */
+
+#if defined( HAVE_IPv6 ) &&  !defined( inet_pton )
+
+#ifdef _MSC_VER
+/* #include <ws2tcpip.h> */
+#include "inttypes.h"
+#endif
+#include "polipo.h"
+
+int inet_pton4(const char *, char *);
+int inet_pton6(const char *, char *);
+
+int inet_pton(int af, const char *src, char *dst)
+{
+    switch (af)
+    {
+    case AF_INET:
+        return inet_pton4(src, dst);
+    case AF_INET6:
+        return inet_pton6(src, dst);
+    default:
+        return -1;
+    }
+}
+
+#define NS_INADDRSZ  4
+#define NS_IN6ADDRSZ 16
+#define NS_INT16SZ   2
+
+int inet_pton4(const char *src, char *dst)
+{
+    int ch;
+    uint8_t tmp[NS_INADDRSZ], *tp;
+
+    int saw_digit = 0;
+    int octets = 0;
+    *(tp = tmp) = 0;
+
+    while ((ch = *src++) != '\0')
+    {
+        if (ch >= '0' && ch <= '9')
+        {
+            uint32_t n = *tp * 10 + (ch - '0');
+
+            if (saw_digit && *tp == 0)
+                return 0;
+
+            if (n > 255)
+                return 0;
+
+            *tp = n;
+            if (!saw_digit)
+            {
+                if (++octets > 4)
+                    return 0;
+                saw_digit = 1;
+            }
+        }
+        else if (ch == '.' && saw_digit)
+        {
+            if (octets == 4)
+                return 0;
+            *++tp = 0;
+            saw_digit = 0;
+        }
+        else
+            return 0;
+    }
+    if (octets < 4)
+        return 0;
+
+    memcpy(dst, tmp, NS_INADDRSZ);
+
+    return 1;
+}
+
+int inet_pton6(const char *src, char *dst)
+{
+    static const char xdigits[] = "0123456789abcdef";
+    uint8_t tmp[NS_IN6ADDRSZ];
+
+    uint8_t *tp = (uint8_t*) memset(tmp, '\0', NS_IN6ADDRSZ);
+    uint8_t *endp = tp + NS_IN6ADDRSZ;
+    uint8_t *colonp = NULL;
+
+    const char *curtok = src;
+    int saw_xdigit = 0;
+    uint32_t val = 0;
+    int ch;
+
+       /* Leading :: requires some special handling. */
+    if (*src == ':')
+    {
+        if (*++src != ':')
+            return 0;
+    }
+
+    while ((ch = tolower(*src++)) != '\0')
+    {
+        const char *pch = strchr(xdigits, ch);
+        if (pch != NULL)
+        {
+            val <<= 4;
+            val |= (pch - xdigits);
+            if (val > 0xffff)
+                return 0;
+            saw_xdigit = 1;
+            continue;
+        }
+        if (ch == ':')
+        {
+            curtok = src;
+            if (!saw_xdigit)
+            {
+                if (colonp)
+                    return 0;
+                colonp = tp;
+                continue;
+            }
+            else if (*src == '\0')
+            {
+                return 0;
+            }
+            if (tp + NS_INT16SZ > endp)
+                return 0;
+            *tp++ = (uint8_t) (val >> 8) & 0xff;
+            *tp++ = (uint8_t) val & 0xff;
+            saw_xdigit = 0;
+            val = 0;
+            continue;
+        }
+        if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
+                inet_pton4(curtok, (char*) tp) > 0)
+        {
+            tp += NS_INADDRSZ;
+            saw_xdigit = 0;
+            break; /* '\0' was seen by inet_pton4(). */
+        }
+        return 0;
+    }
+    if (saw_xdigit)
+    {
+        if (tp + NS_INT16SZ > endp)
+            return 0;
+        *tp++ = (uint8_t) (val >> 8) & 0xff;
+        *tp++ = (uint8_t) val & 0xff;
+    }
+    if (colonp != NULL)
+    {
+        /*
+         * Since some memmove()'s erroneously fail to handle
+         * overlapping regions, we'll do the shift by hand.
+         */
+        const int n = tp - colonp;
+        int i;
+
+        if (tp == endp)
+            return 0;
+
+        for (i = 1; i <= n; i++)
+        {
+            endp[-i] = colonp[n - i];
+            colonp[n - i] = 0;
+        }
+        tp = endp;
+    }
+    if (tp != endp)
+        return 0;
+
+    memcpy(dst, tmp, NS_IN6ADDRSZ);
+
+    return 1;
+}
+
+#endif
diff -Nur ./polipo-master/io.c ./polipo-1.1.2/io.c
--- ./polipo-master/io.c        Tue Apr 28 18:38:01 2015
+++ ./polipo-1.1.2/io.c Tue Apr 28 18:37:23 2015
@@ -23,6 +23,9 @@
 #include "polipo.h"
 
 #ifdef HAVE_IPv6
+#ifdef WIN32
+#include <ws2tcpip.h>
+#endif
 #ifdef IPV6_PREFER_TEMPADDR
 #define HAVE_IPV6_PREFER_TEMPADDR 1
 #endif
@@ -754,11 +757,11 @@
         return NULL;
     }
 
-#ifndef WIN32
+//#ifndef WIN32
     /* on WIN32 SO_REUSEADDR allows two sockets bind to the same port */
     rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
     if(rc < 0) do_log_error(L_WARN, errno, "Couldn't set SO_REUSEADDR");
-#endif
+//#endif
 
     if(inet6) {
 #ifdef HAVE_IPv6
diff -Nur ./polipo-master/local.h ./polipo-1.1.2/local.h
--- ./polipo-master/local.h     Fri Nov 21 09:15:36 2014
+++ ./polipo-1.1.2/local.h      Tue Apr 28 18:37:23 2015
@@ -20,6 +20,7 @@
 THE SOFTWARE.
 */
 
+typedef int pid_t;
 typedef struct _SpecialRequest {
     ObjectPtr object;
     int fd;
diff -Nur ./polipo-master/log.c ./polipo-1.1.2/log.c
--- ./polipo-master/log.c       Fri Nov 21 09:15:36 2014
+++ ./polipo-1.1.2/log.c        Tue Apr 28 18:37:23 2015
@@ -22,6 +22,12 @@
 
 #include "polipo.h"
 
+#ifdef WIN32
+#define SYSLOG_FILE "C:/polipo/syslog.txt"
+#else
+#define SYSLOG_FILE "/var/log/polipo"
+#endif
+
 #ifdef HAVE_SYSLOG
 #include <syslog.h>
 #endif
@@ -112,7 +118,7 @@
 initLog(void)
 {
     if(daemonise && logFile == NULL && !logSyslog)
-        logFile = internAtom("/var/log/polipo");
+        logFile = internAtom(SYSLOG_FILE);
 
     if(logFile != NULL && logFile->length > 0) {
         FILE *f;
diff -Nur ./polipo-master/main.c ./polipo-1.1.2/main.c
--- ./polipo-master/main.c      Fri Nov 21 09:15:36 2014
+++ ./polipo-1.1.2/main.c       Tue Apr 28 18:37:23 2015
@@ -22,6 +22,12 @@
 
 #include "polipo.h"
 
+#ifdef WIN32
+#define CONFIG_FILE "C:/polipo/config"
+#else
+#define CONFIG_FILE "/etc/polipo/config"
+#endif
+
 AtomPtr configFile = NULL;
 AtomPtr pidFile = NULL;
 int daemonise = 0;
@@ -107,8 +113,8 @@
     }
 
     if(configFile == NULL) {
-        if(access("/etc/polipo/config", F_OK) >= 0)
-            configFile = internAtom("/etc/polipo/config");
+        if(access(CONFIG_FILE, F_OK) >= 0)
+            configFile = internAtom(CONFIG_FILE);
         if(configFile && access(configFile->string, F_OK) < 0) {
             releaseAtom(configFile);
             configFile = NULL;
diff -Nur ./polipo-master/mingw.h ./polipo-1.1.2/mingw.h
--- ./polipo-master/mingw.h     Fri Nov 21 09:15:36 2014
+++ ./polipo-1.1.2/mingw.h      Tue Apr 28 18:37:23 2015
@@ -56,7 +56,7 @@
 /* At time of writing, a fair bit of stuff doesn't work under Mingw.
  * Hopefully they will be fixed later (especially the disk-cache).
  */
-#define NO_IPv6 1
+//#define NO_IPv6 1
 
 #define S_IROTH S_IREAD
 
diff -Nur ./polipo-master/server.c ./polipo-1.1.2/server.c
--- ./polipo-master/server.c    Tue Apr 28 18:38:01 2015
+++ ./polipo-1.1.2/server.c     Tue Apr 28 18:37:23 2015
@@ -1207,7 +1207,8 @@
                request->time0.tv_sec != null_time.tv_sec)
                 rtt = timeval_minus_usec(&request->time1, &request->time0);
             if(size >= 8192 && d > 50000)
-                rate = (int)( ((double)size / (double)d) * 1000000.0 + 0.5 );
+/*                rate = (int)( ((double)size / (double)d) * 1000000.0 + 0.5 
); */
+                rate = (int)( ((long long)size * 1000000 * 10 / d + 5) / 10 );
         }
         request->time0 = null_time;
         request->time1 = null_time;

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Polipo-users mailing list
Polipo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/polipo-users

Reply via email to