On Fri, Jan 22, 2016 at 11:08:04PM -0700, Gabriel Klyber wrote:
> Is gziped base64 okay? Most of these changes are from yuuboshi. I
> highlighted the main changes I made in the previous post.
The MIME structure was missing, but it was possible to decode it.
Attached below as diffs.
DF
diff -u ../polipo-master/config.c ./config.c
--- ../polipo-master/config.c 2015-12-07 07:15:40.000000000 -0700
+++ ./config.c 2016-01-08 18:14:06.768718400 -0700
@@ -852,7 +852,7 @@
configFloatSetter(ConfigVariablePtr var, void* value)
{
assert(var->type == CONFIG_FLOAT);
- *var->value.i = *(float*)value;
+ *var->value.f = *(float*)value;
return 1;
}
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/dns.c ./dns.c
--- ../polipo-master/dns.c 2015-12-07 07:15:40.000000000 -0700
+++ ./dns.c 2016-01-22 22:02:35.762209300 -0700
@@ -169,6 +169,54 @@
}
#endif
+#ifdef WIN32
+#include <iphlpapi.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 +242,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 +590,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 +599,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 -u ../polipo-master/forbidden.c ./forbidden.c
--- ../polipo-master/forbidden.c 2015-12-07 07:15:40.000000000 -0700
+++ ./forbidden.c 2016-01-08 21:19:06.226261100 -0700
@@ -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(FORBIDDEN_FILE, F_OK) >= 0)
+ forbiddenFile = internAtom(FORBIDDEN_FILE);
}
parseDomainFile(forbiddenFile, &forbiddenDomains, &forbiddenRegex);
@@ -325,7 +335,7 @@
uncachableFile = expandTilde(uncachableFile);
if(uncachableFile == NULL) {
- uncachableFile = expandTilde(internAtom("~/.polipo-uncachable"));
+ uncachableFile = internAtom(UNCACHABLE_FILE);
if(uncachableFile) {
if(access(uncachableFile->string, F_OK) < 0) {
releaseAtom(uncachableFile);
@@ -335,8 +345,8 @@
}
if(uncachableFile == NULL) {
- if(access("/etc/polipo/uncachable", F_OK) >= 0)
- uncachableFile = internAtom("/etc/polipo/uncachable");
+ if(access(UNCACHEABLE_FILE, F_OK) >= 0)
+ uncachableFile = internAtom(UNCACHABLE_FILE);
}
parseDomainFile(uncachableFile, &uncachableDomains, &uncachableRegex);
@@ -345,7 +355,7 @@
forbiddenTunnelsFile = expandTilde(forbiddenTunnelsFile);
if(forbiddenTunnelsFile == NULL) {
- forbiddenTunnelsFile = expandTilde(internAtom("~/.polipo-forbiddenTunnels"));
+ forbiddenTunnelsFile = expandTilde(internAtom(FORBIDDEN_TUNNELS_FILE));
if(forbiddenTunnelsFile) {
if(access(forbiddenTunnelsFile->string, F_OK) < 0) {
releaseAtom(forbiddenTunnelsFile);
@@ -355,8 +365,8 @@
}
if(forbiddenTunnelsFile == NULL) {
- if(access("/etc/polipo/forbiddenTunnels", F_OK) >= 0)
- forbiddenTunnelsFile = internAtom("/etc/polipo/forbiddenTunnels");
+ if(access(FORBIDDEN_TUNNELS_FILE, F_OK) >= 0)
+ forbiddenTunnelsFile = internAtom(FOBIDDEN_TUNNELS_FILE);
}
parseDomainFile(forbiddenTunnelsFile, &forbiddenTunnelsDomains, &forbiddenTunnelsRegex);
diff -u ../polipo-master/fts_compat.c ./fts_compat.c
--- ../polipo-master/fts_compat.c 2015-12-07 07:15:40.000000000 -0700
+++ ./fts_compat.c 2016-01-08 21:25:07.846870100 -0700
@@ -30,6 +30,7 @@
#include <unistd.h>
#include <dirent.h>
#else
+#include <io.h>
#include "dirent_compat.h"
#endif
#include <sys/stat.h>
@@ -37,6 +38,9 @@
#include <string.h>
#include "fts_compat.h"
+#ifdef _MSC_VER
+#include "mingw.h"
+#endif
static char *
getcwd_a()
@@ -132,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 -u ../polipo-master/io.c ./io.c
--- ../polipo-master/io.c 2015-12-07 07:15:40.000000000 -0700
+++ ./io.c 2016-01-21 23:03:07.579706100 -0700
@@ -37,6 +37,12 @@
void
preinitIo()
{
+#ifdef HAVE_WINSOCK
+ WSADATA wsaData;
+ WORD wVersionRequested = MAKEWORD(2, 2);
+ int err;
+#endif
+
#ifdef HAVE_IPV6_PREFER_TEMPADDR
CONFIG_VARIABLE_SETTABLE(useTemporarySourceAddress, CONFIG_TRISTATE,
configIntSetter,
@@ -48,9 +54,7 @@
#ifdef HAVE_WINSOCK
/* Load the winsock dll */
- WSADATA wsaData;
- WORD wVersionRequested = MAKEWORD(2, 2);
- int err = WSAStartup( wVersionRequested, &wsaData );
+ err = WSAStartup( wVersionRequested, &wsaData );
if (err != 0) {
do_log_error(L_ERROR, err, "Couldn't load winsock dll");
exit(-1);
@@ -750,11 +754,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
@@ -851,7 +855,7 @@
{
int val = nodelay ? 1 : 0;
int rc;
- rc = setsockopt(fd, SOL_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
+ rc = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
if(rc < 0)
return -1;
return 0;
diff -u ../polipo-master/local.h ./local.h
--- ../polipo-master/local.h 2015-12-07 07:15:40.000000000 -0700
+++ ./local.h 2016-01-08 22:00:32.909636200 -0700
@@ -19,7 +19,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-
+//typedef int pid_t;
typedef struct _SpecialRequest {
ObjectPtr object;
int fd;
diff -u ../polipo-master/log.c ./log.c
--- ../polipo-master/log.c 2015-12-07 07:15:40.000000000 -0700
+++ ./log.c 2016-01-09 10:02:23.312970900 -0700
@@ -22,6 +22,12 @@
#include "polipo.h"
+#ifdef WIN32
+#define SYSLOG_FILE "E:/polipo/syslog.txt"
+#else
+#define SYSLOG_FILE "/var/log/polipo"
+#endif
+
#ifdef HAVE_SYSLOG
#include <syslog.h>
#endif
@@ -98,7 +104,13 @@
return NULL;
}
- setvbuf(f, NULL, _IOLBF, 0);
+ setvbuf(f, NULL, _IONBF,
+#ifdef _MSC_VER
+ 2048
+#else
+ 0
+#endif
+ );
return f;
}
@@ -106,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 -u ../polipo-master/main.c ./main.c
--- ../polipo-master/main.c 2015-12-07 07:15:40.000000000 -0700
+++ ./main.c 2016-01-08 21:39:55.924467500 -0700
@@ -21,6 +21,11 @@
*/
#include "polipo.h"
+#ifdef WIN32
+#define CONFIG_FILE "E:/polipo/config"
+#else
+#define CONFIG_FILE "/etc/polipo/config"
+#endif
AtomPtr configFile = NULL;
AtomPtr pidFile = NULL;
@@ -107,8 +112,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 -u ../polipo-master/md5.h ./md5.h
--- ../polipo-master/md5.h 2015-12-07 07:15:40.000000000 -0700
+++ ./md5.h 2016-01-08 18:35:50.890828700 -0700
@@ -35,9 +35,14 @@
#ifdef HAS_STDINT_H
#include <stdint.h>
#elif defined(HAS_INTTYPES_H)
+#ifdef _MSC_VER
+#include "inttypes.h"
+#else
#include <inttypes.h>
#endif
+#endif
+
/* typedef a 32-bit type */
typedef uint32_t UINT4;
diff -u ../polipo-master/mingw.c ./mingw.c
--- ../polipo-master/mingw.c 2015-12-07 07:15:40.000000000 -0700
+++ ./mingw.c 2016-01-21 22:28:05.726666500 -0700
@@ -186,8 +186,8 @@
if(tv) {
GetSystemTimeAsFileTime(&ft);
- li.LowPart = ft.dwLowDateTime;
- li.HighPart = ft.dwHighDateTime;
+ li.u.LowPart = ft.dwLowDateTime;
+ li.u.HighPart = ft.dwHighDateTime;
t = li.QuadPart; /* In 100-nanosecond intervals */
t -= EPOCHFILETIME; /* Offset to the Epoch time */
t /= 10; /* In microseconds */
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
diff -u ../polipo-master/object.c ./object.c
--- ../polipo-master/object.c 2015-12-07 07:15:40.000000000 -0700
+++ ./object.c 2016-01-08 18:16:02.848441300 -0700
@@ -985,8 +985,8 @@
if(object->last_modified >= 0)
/* Again, take care of clock skew */
stale = MIN(stale,
- object->age +
- (date - object->last_modified) * maxAgeFraction);
+ (int) (object->age +
+ (date - object->last_modified) * maxAgeFraction) );
else
stale = MIN(stale, object->age + maxNoModifiedAge);
}
Only in ./: patch
diff -u ../polipo-master/polipo.h ./polipo.h
--- ../polipo-master/polipo.h 2015-12-07 07:15:40.000000000 -0700
+++ ./polipo.h 2016-01-22 22:12:35.737420400 -0700
@@ -59,6 +59,7 @@
#include <sys/ioctl.h>
#include <signal.h>
#endif
+#include <ctype.h>
#ifdef __MINGW32__
#define MINGW
@@ -194,6 +195,10 @@
#endif
#endif
+#ifdef _MSC_VER
+#define F_OK 00
+#endif
+
#ifdef HAVE_READV_WRITEV
#define WRITEV(x, y, z) writev(x, y, z)
#define READV(x, y, z) readv(x, y, z)
diff -u ../polipo-master/server.c ./server.c
--- ../polipo-master/server.c 2015-12-07 07:15:40.000000000 -0700
+++ ./server.c 2016-01-08 21:45:48.417577700 -0700
@@ -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 = ((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;
diff -u ../polipo-master/socks.c ./socks.c
--- ../polipo-master/socks.c 2015-12-07 07:15:40.000000000 -0700
+++ ./socks.c 2016-01-08 18:30:27.116091400 -0700
@@ -83,6 +83,8 @@
void
preinitSocks()
{
+ int rc;
+
AtomPtr socksAuthCredentials = internAtom("");
aSocks4a = internAtom("socks4a");
@@ -103,7 +105,7 @@
// infer username and password from credentials
- int rc = atomSplit(socksAuthCredentials, ':', &socksUserName, &socksPassWord);
+ rc = atomSplit(socksAuthCredentials, ':', &socksUserName, &socksPassWord);
if (rc < 0) {
do_log(L_ERROR, "Error splitting credentials");
exit(1);
@@ -349,6 +351,8 @@
FdEventHandlerPtr event,
StreamRequestPtr srequest)
{
+ int (*readHandler)(int, FdEventHandlerPtr, StreamRequestPtr) = NULL;
+
SocksRequestPtr request = srequest->data;
if(status < 0)
@@ -362,7 +366,6 @@
return 0;
}
- int (*readHandler)(int, FdEventHandlerPtr, StreamRequestPtr) = NULL;
if (socksProxyType == aSocks4a){
readHandler = socksReadHandler;
} else if (socksPassWord == NULL) {
diff -u ../polipo-master/util.c ./util.c
--- ../polipo-master/util.c 2015-12-07 07:15:40.000000000 -0700
+++ ./util.c 2016-01-08 21:48:35.271512700 -0700
@@ -71,8 +71,10 @@
if(n < 0) return -2;
while(i < slen && n < len)
buf[n++] = s[i++];
- if(n < len)
+ if(n < len) {
+ buf[n] = 0;
return n;
+ }
else
return -1;
}
------------------------------------------------------------------------------
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