You were right about Windows XP compatibility. Here are the key
changes I made. Full diff is in a follow-up post:
diff -u ../polipo-master/diskcache.c ./diskcache.c
--- ../polipo-master/diskcache.c    2015-12-07 07:15:40.000000000 -0700
+++ ./diskcache.c    2016-01-22 22:39:50.029992000 -0700
@@ -719,6 +719,7 @@
     { "ps", "application/postscript" },
     { "tar", "application/x-tar" },
     { "pac", "application/x-ns-proxy-autoconfig" },
+    { "dat", "application/x-ns-proxy-autoconfig" },
     { "css", "text/css" },
     { "js",  "application/x-javascript" },
     { "xml", "text/xml" },
@@ -854,14 +855,14 @@
     int dummy;
     int code;
     AtomPtr headers;
-    time_t date, last_modified, expires, polipo_age, polipo_access;
+    time_t date = -1, last_modified = -1, expires = -1, polipo_age =
-1, polipo_access = current_time.tv_sec;
     int length;
     off_t offset = -1;
     int body_offset;
-    char *etag;
+    char *etag = NULL;
     AtomPtr via;
     CacheControlRec cache_control;
-    char *location;
+    char *location = NULL;
     AtomPtr message;
     int dirty = 0;

@@ -1008,8 +1009,10 @@
         }
     }

-    if(location)
+    if(location) {
         free(location);
+        location = NULL;
+    }

     if(headers) {
         if(!object->headers)
@@ -1051,8 +1054,10 @@
     if(!object->etag)
         object->etag = etag;
     else {
-        if(etag)
+        if(etag) {
             free(etag);
+            etag = NULL;
+        }
     }
     releaseAtom(message);

@@ -1234,12 +1239,12 @@
                 rc = writeHeaders(fd, &body_offset, object, data, dsize);
                 if(rc < 0) {
                     do_log_error(L_ERROR, errno, "Couldn't write headers");
+                    close(fd);
                     rc = unlink(buf);
                     if(rc < 0 && errno != ENOENT)
                         do_log_error(L_ERROR, errno,
                                      "Couldn't unlink truncated entry %s",
                                      scrub(buf));
-                    close(fd);
                     return NULL;
                 }
                 assert(rc >= body_offset);
@@ -1422,16 +1427,8 @@
         /* See writeoutToDisk */
         d = 1;
     }
-
-    if(d) {
-        entry->object->flags &= ~OBJECT_DISK_ENTRY_COMPLETE;
-        if(entry->filename) {
-            urc = unlink(entry->filename);
-            if(urc < 0)
-                do_log_error(L_WARN, errno,
-                             "Couldn't unlink %s", scrub(entry->filename));
-        }
-    } else {
+
+    if(!d) {
         if(entry && entry->metadataDirty)
             writeoutMetadata(object);
         makeDiskEntry(object, 0);
@@ -1446,13 +1443,24 @@
                 return 0;
         }
     }
- again:
+
+again:
     rc = close(entry->fd);
     if(rc < 0 && errno == EINTR)
         goto again;

     entry->fd = -1;

+    if(d) {
+        entry->object->flags &= ~OBJECT_DISK_ENTRY_COMPLETE;
+        if(entry->filename) {
+            urc = unlink(entry->filename);
+            if(urc < 0)
+                do_log_error(L_WARN, errno,
+                             "Couldn't unlink %s", scrub(entry->filename));
+        }
+    }
+
     if(entry->filename)
         free(entry->filename);
     entry->filename = NULL;
@@ -1753,7 +1761,15 @@

     rc = writeHeaders(entry->fd, &entry->body_offset, object, NULL, 0);
     if(rc == -2) {
+#ifndef WIN32
         rc = rewriteEntry(object);
+#else
+        /* This is a hack that deletes the file instead of rewriting it.
+           It would be better to rename the file to a temporary name and
+           copy the contents to a new file with the original name. */
+        rc = destroyDiskEntry(object, 1);
+        rc = makeDiskEntry(object, 1);
+#endif
         if(rc < 0) return 0;
         return 1;
     }
@@ -2433,7 +2449,9 @@
     long left = 0, total = 0;

     if(diskCacheRoot == NULL ||
-       diskCacheRoot->length <= 0 || diskCacheRoot->string[0] != '/')
+       diskCacheRoot->length <= 0 ||
+        !(isalpha(diskCacheRoot->string[0]) &&
(diskCacheRoot->string[1] == ':') &&
+          ((diskCacheRoot->string[2] == '/') ||
(diskCacheRoot->string[2] == '\\'))))
         return;

     fts_argv[0] = diskCacheRoot->string;
diff -u ../polipo-master/mingw.h ./mingw.h
--- ../polipo-master/mingw.h    2015-12-07 07:15:40.000000000 -0700
+++ ./mingw.h    2016-01-22 22:10:44.091300600 -0700
@@ -56,12 +56,13 @@
 /* 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 S_IROTH S_IREAD

 /* Pull in winsock2.h for (almost) berkeley sockets. */
+#define FD_SETSIZE 1024
 #include <winsock2.h>
+#ifdef HAVE_IPv6
+#include <ws2tcpip.h>
+#endif

 // here we smash the errno defines so we can smash the socket
functions later to smash errno. yay!
 #ifdef ENOTCONN


On Fri, Jan 22, 2016 at 5:14 PM, Gabriel Klyber <g...@klyber.net> wrote:
> I prefer not to use the winsock pollfd strict since polipo does not use the
> corresponding and broken WSApoll. I pulled in Windows Vista to get some IPv6
> functionality. Maybe it was for getaddrinfo. I will look at it tonight,
> clean up some of the unlink code in diskcache and post a full diff.
>
> Gabe
>
> On Jan 22, 2016 9:23 AM, "Gisle Vanem" <gva...@yahoo.no> wrote:
>>
>> Gabriel Klyber wrote:
>>
>> > These modifications require Windows Vista or newer. I am not sure how
>> > early you need to define WINVER, but in my environment, mingw.h was
>> > too late.
>>
>> I'm not sure if your patch would pull in some Vista+ exports
>> from ws2_32.dll? Making it impossible to run Polipo on Win-XP.
>>
>> But to just use 'struct pollfd', one can do:
>>
>>   struct win32_pollfd {
>>      SOCKET fd;        /* file descriptor */
>>      short events;     /* requested events */
>>      short revents;    /* returned events */
>>  };
>>  #define pollfd               win32_pollfd
>>  #define poll(x, y, z)        win32_poll(x, y, z)
>>
>>
>> I'm not sure it's a god idea to *require* a specific WINVER
>> to build Polipo (default here in my SDK 8.1 is 0x0501).
>> There is AFAICS nothing in Polipo that needs anything more advanced
>> than is already in Win-XP (0x0501).
>>
>>
>> --gv
>>
>> --
>> --gv
>>
>>
>> ------------------------------------------------------------------------------
>> Site24x7 APM Insight: Get Deep Visibility into Application Performance
>> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
>> Monitor end-to-end web transactions and take corrective actions now
>> Troubleshoot faster and improve end-user experience. Signup Now!
>> http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
>> _______________________________________________
>> Polipo-users mailing list
>> Polipo-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/polipo-users

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Polipo-users mailing list
Polipo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/polipo-users

Reply via email to