Re: I port polipo to VS2008 under Win32
honglei junan <[email protected]>
| Newsgroups | gmane.comp.web.polipo.user |
|---|---|
| Message-ID | <[email protected]> |
hi,This this the patch file,this is my first use pathc/diff tools,since i used to program under win32. hope it will give someone some help. On Tue, Jan 19, 2010 at 7:13 PM, honglei junan <[email protected]> wrote: > i port polipo-harden-test( 20100112) from web site > http://www.mangrin.org/~chrisd/ <http://www.mangrin.org/%7Echrisd/> to > VC2008,now,it can be compiled using Mingw or VC2008.both works well. you can > download the source code package from: > http://polipovc.googlecode.com/files/polipo_source.7z > > > > On Tue, Jan 19, 2010 at 8:45 AM, Juliusz Chroboczek < > [email protected]> wrote: > >> Dear Honglei, >> >> Would you please be so kind as to put your port (patches, not the >> binary) somewhere on the web, and post an announcement to the >> polipo-users mailing list? >> >> I don't run Windows myself, but I know there are people who are very >> much interested who lurk on polipo-users. >> >> Juliusz >> > > ------------------------------------------------------------------------------ Throughout its 18-year history, RSA Conference consistently attracts the world's best and brightest in the field, creating opportunities for Conference attendees to learn about information security's most important issues through interactions with peers, luminaries and emerging and established companies. http://p.sf.net/sfu/rsaconf-dev2dev _______________________________________________ Polipo-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/polipo-users
vc_polipo.patch
(application/octet-stream, 50.9 KB)
diff -Nur polipo-harden-test/Makefile polipo/Makefile
--- polipo-harden-test/Makefile 2009-12-12 07:39:48 +0800
+++ polipo/Makefile 2010-01-20 15:22:13 +0800
@@ -48,7 +48,7 @@
# On mingw, you need
# EXE=.exe
-# LDLIBS = -lwsock32
+LDLIBS = -lwsock32 Iphlpapi.lib
FILE_DEFINES = -DLOCAL_ROOT=\"$(LOCAL_ROOT)/\" \
-DDISK_CACHE_ROOT=\"$(DISK_CACHE_ROOT)/\"
diff -Nur polipo-harden-test/chunk.c polipo/chunk.c
--- polipo-harden-test/chunk.c 2009-12-12 07:39:48 +0800
+++ polipo/chunk.c 2010-01-13 18:41:42 +0800
@@ -184,7 +184,7 @@
}
#else
-#ifdef MINGW
+#ifdef WIN32 //MINGW
#define MAP_FAILED NULL
#define getpagesize() (64 * 1024)
static void *
diff -Nur polipo-harden-test/dirent.c polipo/dirent.c
--- polipo-harden-test/dirent.c 1970-01-01 08:00:00 +0800
+++ polipo/dirent.c 2010-01-12 17:42:40 +0800
@@ -0,0 +1,216 @@
+// dirent.c: emulates POSIX directory readin functions: opendir(), readdir(),
+// etc. under Win32
+//
+
+#include <windows.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <malloc.h>
+#include "dirent.h"
+
+struct DIR
+{
+ HANDLE hFind;
+ char szDirName[1];
+};
+
+//--------------------------------------------------------------------------
+// Name countslashes
+//
+// Description
+//--------------------------------------------------------------------------
+static int countslashes(const char *dirname)
+{
+ const char *p;
+ int n;
+
+ n = 0;
+ p = dirname;
+
+ while (*p)
+ if (*p++ == '\\')
+ ++n;
+
+ return n;
+}
+
+//--------------------------------------------------------------------------
+// Name opendir
+//
+// Description
+//--------------------------------------------------------------------------
+DIR * opendir ( const char * dirname )
+{
+ DIR * dir;
+ int nameLen;
+ struct stat st;
+ unsigned char flagNetPath;
+ unsigned char flagRootOnly;
+
+ if (dirname == NULL || *dirname == 0)
+ {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ nameLen = strlen( dirname );
+ flagNetPath = 0;
+ if (dirname[0] == '\\' && dirname[1] == '\\')
+ flagNetPath = 1;
+ /* we have to check for root-dir-only case */
+ flagRootOnly = 0;
+ if (flagNetPath)
+ {
+ if (countslashes(&dirname[2]) == 2) /* only the separation for server_name and the root*/
+ flagRootOnly = 1;
+ }
+
+ if ((dirname[nameLen-1] == '/' || dirname[nameLen-1] == '\\') &&
+ (nameLen != 3 || dirname[1] != ':') && nameLen != 1 && !flagRootOnly)
+ {
+ char * t = alloca( nameLen );
+ memcpy( t, dirname, nameLen );
+ t[nameLen-1] = 0;
+ dirname = t;
+ --nameLen;
+ }
+
+ if (stat( dirname, &st ))
+ return NULL;
+
+ if ((st.st_mode & S_IFDIR) == 0)
+ {
+ // this is not a DIR
+ errno = ENOTDIR;
+ return NULL;
+ }
+
+ if ((dir = malloc( sizeof( DIR ) + nameLen + 2 )) == NULL)
+ {
+ errno = ENOMEM;
+ return NULL;
+ }
+
+ dir->hFind = INVALID_HANDLE_VALUE;
+
+ memcpy( dir->szDirName, dirname, nameLen );
+ if (nameLen && dirname[nameLen-1] != ':' && dirname[nameLen-1] != '\\' &&
+ dirname[nameLen-1] != '/')
+ {
+ dir->szDirName[nameLen++] = '\\';
+ }
+ dir->szDirName[nameLen] = '*';
+ dir->szDirName[nameLen+1] = 0;
+
+ return dir;
+};
+
+//--------------------------------------------------------------------------
+// Name readdir
+//
+// Description
+//--------------------------------------------------------------------------
+struct dirent * readdir ( DIR * dir )
+{
+ static WIN32_FIND_DATA fData;
+
+ if (dir == NULL)
+ {
+ errno = EBADF;
+ return NULL;
+ }
+
+ do
+ {
+ int ok = 1;
+
+ if (dir->hFind == INVALID_HANDLE_VALUE)
+ {
+ dir->hFind = FindFirstFile( dir->szDirName, &fData );
+ if (dir->hFind == INVALID_HANDLE_VALUE)
+ ok = 0;
+ }
+ else
+ if (!FindNextFile( dir->hFind, &fData ))
+ ok = 0;
+
+ if (!ok)
+ {
+ switch (GetLastError())
+ {
+ case ERROR_NO_MORE_FILES:
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_PATH_NOT_FOUND:
+ errno = ENOENT;
+ break;
+
+ case ERROR_NOT_ENOUGH_MEMORY:
+ errno = ENOMEM;
+ break;
+
+ default:
+ errno = EINVAL;
+ break;
+ }
+ return NULL;
+ }
+ }
+ while (fData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
+
+ return (struct dirent *)&fData.cFileName;
+};
+
+//--------------------------------------------------------------------------
+// Name closedir
+//
+// Description
+//--------------------------------------------------------------------------
+int closedir ( DIR * dir )
+{
+ if (dir == NULL)
+ {
+ errno = EBADF;
+ return -1;
+ }
+ if (dir->hFind != INVALID_HANDLE_VALUE)
+ FindClose( dir->hFind );
+ free( dir );
+ return 0;
+};
+
+//--------------------------------------------------------------------------
+// Name rewinddir
+//
+// Description
+//--------------------------------------------------------------------------
+void rewinddir ( DIR * dir )
+{
+ if (dir)
+ {
+ if (dir->hFind != INVALID_HANDLE_VALUE)
+ FindClose( dir->hFind );
+ dir->hFind = INVALID_HANDLE_VALUE;
+ }
+};
+
+/*
+int main ( int argc, char ** argv )
+{
+ DIR * dir;
+ struct dirent * de;
+ char * arg;
+
+ arg = argc > 1 ? argv[1] : ".";
+
+ if (dir = opendir( arg ))
+ {
+ while (de = readdir( dir ))
+ {
+ puts( de->d_name );
+ }
+ closedir( dir );
+ }
+ return 0;
+};
+*/
diff -Nur polipo-harden-test/dirent.h polipo/dirent.h
--- polipo-harden-test/dirent.h 1970-01-01 08:00:00 +0800
+++ polipo/dirent.h 2010-01-12 17:47:09 +0800
@@ -0,0 +1,22 @@
+
+#ifndef DIRENT_H
+#define DIRENT_H
+
+#include <stdio.h>
+
+struct dirent
+{
+ long d_ino; /* Always zero. */
+ unsigned short d_reclen; /* Always zero. */
+ unsigned short d_namlen; /* Length of name in d_name. */
+ char d_name[FILENAME_MAX+1]; /* File name. */
+};
+
+typedef struct DIR DIR;
+
+DIR * opendir ( const char * dirname );
+struct dirent * readdir ( DIR * dir );
+int closedir ( DIR * dir );
+void rewinddir ( DIR * dir );
+
+#endif // DIRENT_H
diff -Nur polipo-harden-test/diskcache.c polipo/diskcache.c
--- polipo-harden-test/diskcache.c 2009-12-12 07:39:48 +0800
+++ polipo/diskcache.c 2010-01-12 22:31:47 +0800
@@ -53,11 +53,20 @@
};
#ifndef LOCAL_ROOT
-#define LOCAL_ROOT "/usr/share/polipo/www/"
+#ifndef WIN32
+ #define LOCAL_ROOT "/usr/share/polipo/www/"
+#else
+ #define LOCAL_ROOT "./www/"
+#endif
#endif
#ifndef DISK_CACHE_ROOT
-#define DISK_CACHE_ROOT "/var/cache/polipo/"
+#ifndef WIN32
+ #define DISK_CACHE_ROOT "/var/cache/polipo/"
+#else
+ #define DISK_CACHE_ROOT "./cache/"
+#endif
+
#endif
static int maxDiskEntriesSetter(ConfigVariablePtr, void*);
@@ -127,14 +136,18 @@
if(!root || root->length == 0)
return 0;
-
+ //under win32,allow relative path
+#ifndef WIN32
if(root->string[0] != '/') {
return -2;
}
-
- rc = stat(root->string, &ss);
- if(rc < 0)
- return -1;
+#endif
+ rc = stat(root->string, &ss);
+ if(rc < 0){
+ rc = mkdir(root->string,root->length);
+ if(rc<0)
+ return -1;
+ }
else if(!S_ISDIR(ss.st_mode)) {
errno = ENOTDIR;
return -1;
diff -Nur polipo-harden-test/dns.c polipo/dns.c
--- polipo-harden-test/dns.c 2009-12-12 07:39:48 +0800
+++ polipo/dns.c 2010-01-19 17:40:26 +0800
@@ -168,6 +168,54 @@
}
#endif
+//#include <winsock2.h>
+#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()
{
@@ -199,7 +247,11 @@
#endif
#ifndef NO_FANCY_RESOLVER
+#ifndef WIN32
parseResolvConf("/etc/resolv.conf");
+#else
+ getlocalDNS();
+#endif //WIN32
if(dnsNameServer == NULL || dnsNameServer->string[0] == '\0')
dnsNameServer = internAtom("127.0.0.1");
CONFIG_VARIABLE(dnsMaxTimeout, CONFIG_TIME,
@@ -1181,15 +1233,15 @@
} else
releaseAtom(value);
} else if(af == 0) {
- /* Ignore errors in this case. */
- if(query->inet4 && query->inet4->length == 0) {
- releaseAtom(query->inet4);
- query->inet4 = NULL;
- }
- if(query->inet6 && query->inet6->length == 0) {
- releaseAtom(query->inet6);
- query->inet6 = NULL;
- }
+ ///* Ignore errors in this case. */
+ //if(query->inet4 && query->inet4->length == 0) {
+ // releaseAtom(query->inet4);
+ // query->inet4 = NULL;
+ //}
+ //if(query->inet6 && query->inet6->length == 0) {
+ // releaseAtom(query->inet6);
+ // query->inet6 = NULL;
+ //}
if(query->inet4 || query->inet6) {
do_log(L_WARN, "Host %s has both %s and CNAME -- "
"ignoring CNAME.\n", scrub(query->name->string),
diff -Nur polipo-harden-test/event.h polipo/event.h
--- polipo-harden-test/event.h 2009-12-12 07:39:48 +0800
+++ polipo/event.h 2010-01-12 20:55:05 +0800
@@ -52,7 +52,10 @@
void initEvents(void);
void uninitEvents(void);
+
+#ifdef HAVE_FORK
void interestingSignals(sigset_t *ss);
+#endif
TimeEventHandlerPtr scheduleTimeEvent(int seconds,
int (*handler)(TimeEventHandlerPtr),
diff -Nur polipo-harden-test/fts_compat.c polipo/fts_compat.c
--- polipo-harden-test/fts_compat.c 2009-12-12 07:39:48 +0800
+++ polipo/fts_compat.c 2010-01-12 17:50:04 +0800
@@ -25,13 +25,23 @@
#include <stdlib.h>
#include <errno.h>
-#include <unistd.h>
+
+#ifdef _MSC_VER
+ #include "polipo.h"
+ #include <direct.h>
+#else
+ #include <unistd.h>
+ #include <dirent.h>
+#endif
+
#include <sys/types.h>
-#include <dirent.h>
+
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
+
+
#include "fts_compat.h"
static char *
@@ -127,7 +137,7 @@
/*
* Make the directory identified by the argument the current directory.
*/
-#ifdef MINGW
+#ifdef WIN32 //MINGW
int
change_to_dir(DIR *dir)
{
@@ -281,13 +291,13 @@
name = dirent->d_name;
again2:
- rc = stat(name, &fts->stat);
+ rc = stat(name, &fts->istat);
if(rc < 0) {
fts->ftsent.fts_info = FTS_NS;
goto error2;
}
- if(S_ISDIR(fts->stat.st_mode)) {
+ if(S_ISDIR(fts->istat.st_mode)) {
char *newcwd;
DIR *dir;
@@ -318,7 +328,7 @@
fts->depth++;
fts->dir[fts->depth] = dir;
goto done;
- } else if(S_ISREG(fts->stat.st_mode)) {
+ } else if(S_ISREG(fts->istat.st_mode)) {
fts->ftsent.fts_info = FTS_F;
goto done;
#ifdef S_ISLNK
@@ -350,7 +360,7 @@
fts->ftsent.fts_path = mkfilename(fts->cwd, name);
if(fts->ftsent.fts_path == NULL) goto error;
fts->ftsent.fts_accpath = name;
- fts->ftsent.fts_statp = &fts->stat;
+ fts->ftsent.fts_statp = &fts->istat;
return &fts->ftsent;
error:
diff -Nur polipo-harden-test/fts_compat.h polipo/fts_compat.h
--- polipo-harden-test/fts_compat.h 2009-12-12 07:39:48 +0800
+++ polipo/fts_compat.h 2010-01-12 17:46:20 +0800
@@ -50,12 +50,19 @@
typedef struct _FTSENT FTSENT;
+#ifdef _MSC_VER
+//#define DIR void
+#include "dirent.h"
+#else
+#include <dirent.h>
+#endif
+
struct _FTS {
int depth;
DIR *dir[FTS_MAX_DEPTH];
char *cwd0, *cwd;
struct _FTSENT ftsent;
- struct stat stat;
+ struct stat istat;
char *dname;
};
diff -Nur polipo-harden-test/http_parse.c polipo/http_parse.c
--- polipo-harden-test/http_parse.c 2009-12-12 07:39:48 +0800
+++ polipo/http_parse.c 2010-01-19 17:07:28 +0800
@@ -242,7 +242,7 @@
}
static int
-getNextETag(const char * restrict buf, int i,
+getNextETag(const char * restrict buf, int i, int j,
int *x_return, int *y_return, int *weak_return)
{
int weak = 0;
@@ -255,8 +255,16 @@
}
if(buf[i] == '"')
i++;
- else
- return -1;
+ /** jiang add:it seems many web site not use Etag="" ,for example:
+ ETag: app-1263351202-gzip http://www.kaixin001.com
+ ETag: D8AAB19DC186C8C3CDF8511FE1B509B7000026F7 http://cn.bing.com/
+ */
+ else{
+ *x_return = i;
+ *y_return = j;
+ *weak_return = weak;
+ return j;
+ }
x = i;
while(buf[i] != '"') {
@@ -1012,10 +1020,10 @@
int x, y;
int weak;
char *e;
- j = getNextETag(buf, value_start, &x, &y, &weak);
+ j = getNextETag(buf, value_start,value_end, &x, &y, &weak);
if(j < 0) {
if(buf[value_start] != '\r' && buf[value_start] != '\n')
- do_log(L_ERROR, "Couldn't parse ETag.\n");
+ do_log(L_ERROR, "Couldn't parse ETag.\n");
} else if(weak) {
do_log(L_WARN, "Server returned weak ETag -- ignored.\n");
} else {
diff -Nur polipo-harden-test/inttypes.h polipo/inttypes.h
--- polipo-harden-test/inttypes.h 1970-01-01 08:00:00 +0800
+++ polipo/inttypes.h 2010-01-12 20:14:12 +0800
@@ -0,0 +1,305 @@
+// ISO C9x compliant inttypes.h for Microsoft Visual Studio
+// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
+//
+// Copyright (c) 2006 Alexander Chemeris
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// 3. The name of the author may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _MSC_VER // [
+#error "Use this header only with Microsoft Visual C++ compilers!"
+#endif // _MSC_VER ]
+
+#ifndef _MSC_INTTYPES_H_ // [
+#define _MSC_INTTYPES_H_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif
+
+#include "stdint.h"
+
+// 7.8 Format conversion of integer types
+
+typedef struct {
+ intmax_t quot;
+ intmax_t rem;
+} imaxdiv_t;
+
+// 7.8.1 Macros for format specifiers
+
+#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
+
+// The fprintf macros for signed integers are:
+#define PRId8 "d"
+#define PRIi8 "i"
+#define PRIdLEAST8 "d"
+#define PRIiLEAST8 "i"
+#define PRIdFAST8 "d"
+#define PRIiFAST8 "i"
+
+#define PRId16 "hd"
+#define PRIi16 "hi"
+#define PRIdLEAST16 "hd"
+#define PRIiLEAST16 "hi"
+#define PRIdFAST16 "hd"
+#define PRIiFAST16 "hi"
+
+#define PRId32 "I32d"
+#define PRIi32 "I32i"
+#define PRIdLEAST32 "I32d"
+#define PRIiLEAST32 "I32i"
+#define PRIdFAST32 "I32d"
+#define PRIiFAST32 "I32i"
+
+#define PRId64 "I64d"
+#define PRIi64 "I64i"
+#define PRIdLEAST64 "I64d"
+#define PRIiLEAST64 "I64i"
+#define PRIdFAST64 "I64d"
+#define PRIiFAST64 "I64i"
+
+#define PRIdMAX "I64d"
+#define PRIiMAX "I64i"
+
+#define PRIdPTR "Id"
+#define PRIiPTR "Ii"
+
+// The fprintf macros for unsigned integers are:
+#define PRIo8 "o"
+#define PRIu8 "u"
+#define PRIx8 "x"
+#define PRIX8 "X"
+#define PRIoLEAST8 "o"
+#define PRIuLEAST8 "u"
+#define PRIxLEAST8 "x"
+#define PRIXLEAST8 "X"
+#define PRIoFAST8 "o"
+#define PRIuFAST8 "u"
+#define PRIxFAST8 "x"
+#define PRIXFAST8 "X"
+
+#define PRIo16 "ho"
+#define PRIu16 "hu"
+#define PRIx16 "hx"
+#define PRIX16 "hX"
+#define PRIoLEAST16 "ho"
+#define PRIuLEAST16 "hu"
+#define PRIxLEAST16 "hx"
+#define PRIXLEAST16 "hX"
+#define PRIoFAST16 "ho"
+#define PRIuFAST16 "hu"
+#define PRIxFAST16 "hx"
+#define PRIXFAST16 "hX"
+
+#define PRIo32 "I32o"
+#define PRIu32 "I32u"
+#define PRIx32 "I32x"
+#define PRIX32 "I32X"
+#define PRIoLEAST32 "I32o"
+#define PRIuLEAST32 "I32u"
+#define PRIxLEAST32 "I32x"
+#define PRIXLEAST32 "I32X"
+#define PRIoFAST32 "I32o"
+#define PRIuFAST32 "I32u"
+#define PRIxFAST32 "I32x"
+#define PRIXFAST32 "I32X"
+
+#define PRIo64 "I64o"
+#define PRIu64 "I64u"
+#define PRIx64 "I64x"
+#define PRIX64 "I64X"
+#define PRIoLEAST64 "I64o"
+#define PRIuLEAST64 "I64u"
+#define PRIxLEAST64 "I64x"
+#define PRIXLEAST64 "I64X"
+#define PRIoFAST64 "I64o"
+#define PRIuFAST64 "I64u"
+#define PRIxFAST64 "I64x"
+#define PRIXFAST64 "I64X"
+
+#define PRIoMAX "I64o"
+#define PRIuMAX "I64u"
+#define PRIxMAX "I64x"
+#define PRIXMAX "I64X"
+
+#define PRIoPTR "Io"
+#define PRIuPTR "Iu"
+#define PRIxPTR "Ix"
+#define PRIXPTR "IX"
+
+// The fscanf macros for signed integers are:
+#define SCNd8 "d"
+#define SCNi8 "i"
+#define SCNdLEAST8 "d"
+#define SCNiLEAST8 "i"
+#define SCNdFAST8 "d"
+#define SCNiFAST8 "i"
+
+#define SCNd16 "hd"
+#define SCNi16 "hi"
+#define SCNdLEAST16 "hd"
+#define SCNiLEAST16 "hi"
+#define SCNdFAST16 "hd"
+#define SCNiFAST16 "hi"
+
+#define SCNd32 "ld"
+#define SCNi32 "li"
+#define SCNdLEAST32 "ld"
+#define SCNiLEAST32 "li"
+#define SCNdFAST32 "ld"
+#define SCNiFAST32 "li"
+
+#define SCNd64 "I64d"
+#define SCNi64 "I64i"
+#define SCNdLEAST64 "I64d"
+#define SCNiLEAST64 "I64i"
+#define SCNdFAST64 "I64d"
+#define SCNiFAST64 "I64i"
+
+#define SCNdMAX "I64d"
+#define SCNiMAX "I64i"
+
+#ifdef _WIN64 // [
+# define SCNdPTR "I64d"
+# define SCNiPTR "I64i"
+#else // _WIN64 ][
+# define SCNdPTR "ld"
+# define SCNiPTR "li"
+#endif // _WIN64 ]
+
+// The fscanf macros for unsigned integers are:
+#define SCNo8 "o"
+#define SCNu8 "u"
+#define SCNx8 "x"
+#define SCNX8 "X"
+#define SCNoLEAST8 "o"
+#define SCNuLEAST8 "u"
+#define SCNxLEAST8 "x"
+#define SCNXLEAST8 "X"
+#define SCNoFAST8 "o"
+#define SCNuFAST8 "u"
+#define SCNxFAST8 "x"
+#define SCNXFAST8 "X"
+
+#define SCNo16 "ho"
+#define SCNu16 "hu"
+#define SCNx16 "hx"
+#define SCNX16 "hX"
+#define SCNoLEAST16 "ho"
+#define SCNuLEAST16 "hu"
+#define SCNxLEAST16 "hx"
+#define SCNXLEAST16 "hX"
+#define SCNoFAST16 "ho"
+#define SCNuFAST16 "hu"
+#define SCNxFAST16 "hx"
+#define SCNXFAST16 "hX"
+
+#define SCNo32 "lo"
+#define SCNu32 "lu"
+#define SCNx32 "lx"
+#define SCNX32 "lX"
+#define SCNoLEAST32 "lo"
+#define SCNuLEAST32 "lu"
+#define SCNxLEAST32 "lx"
+#define SCNXLEAST32 "lX"
+#define SCNoFAST32 "lo"
+#define SCNuFAST32 "lu"
+#define SCNxFAST32 "lx"
+#define SCNXFAST32 "lX"
+
+#define SCNo64 "I64o"
+#define SCNu64 "I64u"
+#define SCNx64 "I64x"
+#define SCNX64 "I64X"
+#define SCNoLEAST64 "I64o"
+#define SCNuLEAST64 "I64u"
+#define SCNxLEAST64 "I64x"
+#define SCNXLEAST64 "I64X"
+#define SCNoFAST64 "I64o"
+#define SCNuFAST64 "I64u"
+#define SCNxFAST64 "I64x"
+#define SCNXFAST64 "I64X"
+
+#define SCNoMAX "I64o"
+#define SCNuMAX "I64u"
+#define SCNxMAX "I64x"
+#define SCNXMAX "I64X"
+
+#ifdef _WIN64 // [
+# define SCNoPTR "I64o"
+# define SCNuPTR "I64u"
+# define SCNxPTR "I64x"
+# define SCNXPTR "I64X"
+#else // _WIN64 ][
+# define SCNoPTR "lo"
+# define SCNuPTR "lu"
+# define SCNxPTR "lx"
+# define SCNXPTR "lX"
+#endif // _WIN64 ]
+
+#endif // __STDC_FORMAT_MACROS ]
+
+// 7.8.2 Functions for greatest-width integer types
+
+// 7.8.2.1 The imaxabs function
+#define imaxabs _abs64
+
+// 7.8.2.2 The imaxdiv function
+
+// This is modified version of div() function from Microsoft's div.c found
+// in %MSVC.NET%\crt\src\div.c
+#ifdef STATIC_IMAXDIV // [
+static
+#else // STATIC_IMAXDIV ][
+_inline
+#endif // STATIC_IMAXDIV ]
+imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
+{
+ imaxdiv_t result;
+
+ result.quot = numer / denom;
+ result.rem = numer % denom;
+
+ if (numer < 0 && result.rem > 0) {
+ // did division wrong; must fix up
+ ++result.quot;
+ result.rem -= denom;
+ }
+
+ return result;
+}
+
+// 7.8.2.3 The strtoimax and strtoumax functions
+#define strtoimax _strtoi64
+#define strtoumax _strtoui64
+
+// 7.8.2.4 The wcstoimax and wcstoumax functions
+#define wcstoimax _wcstoi64
+#define wcstoumax _wcstoui64
+
+
+#endif // _MSC_INTTYPES_H_ ]
diff -Nur polipo-harden-test/io.c polipo/io.c
--- polipo-harden-test/io.c 2009-12-12 07:39:48 +0800
+++ polipo/io.c 2010-01-12 15:54:37 +0800
@@ -801,8 +801,8 @@
int
setNonblocking(int fd, int nonblocking)
{
-#ifdef MINGW
- return mingw_setnonblocking(fd, nonblocking);
+#ifdef WIN32 //MINGW
+ return win32_setnonblocking(fd, nonblocking);
#else
int rc;
rc = fcntl(fd, F_GETFL, 0);
diff -Nur polipo-harden-test/local.h polipo/local.h
--- polipo-harden-test/local.h 2009-12-12 07:39:48 +0800
+++ polipo/local.h 2010-01-12 16:13:56 +0800
@@ -20,6 +20,11 @@
THE SOFTWARE.
*/
+#ifdef _MSC_VER
+ typedef int pid_t;
+#endif
+
+
typedef struct _SpecialRequest {
ObjectPtr object;
int fd;
diff -Nur polipo-harden-test/log.c polipo/log.c
--- polipo-harden-test/log.c 2009-12-12 07:39:48 +0800
+++ polipo/log.c 2010-01-13 20:47:45 +0800
@@ -304,10 +304,6 @@
}
}
-#ifndef va_copy
-#define va_copy(a, b) do { a = b; } while(0)
-#endif
-
static void
accumulateSyslogV(int type, const char *f, va_list args)
{
diff -Nur polipo-harden-test/main.c polipo/main.c
--- polipo-harden-test/main.c 2009-12-12 07:39:48 +0800
+++ polipo/main.c 2010-01-13 16:10:20 +0800
@@ -38,6 +38,15 @@
fprintf(stderr, " -c: specify the configuration file to use.\n");
}
+#ifndef WIN32
+ #define DEFAULT_CONFIG_PATH "/etc/polipo/config"
+#else
+ #define DEFAULT_CONFIG_PATH "./config"
+#endif
+
+#include <direct.h>
+
+
int
main(int argc, char **argv)
{
@@ -46,6 +55,10 @@
int rc;
int expire = 0, printConfig = 0;
+ char buf[256];
+ if( getcwd(buf,sizeof(buf)) )
+ printf("CWD:%s\n",buf);
+
initAtoms();
CONFIG_VARIABLE(daemonise, CONFIG_BOOLEAN, "Run as a daemon");
CONFIG_VARIABLE(pidFile, CONFIG_ATOM, "File with pid of running daemon.");
@@ -107,8 +120,8 @@
}
if(configFile == NULL) {
- if(access("/etc/polipo/config", F_OK) >= 0)
- configFile = internAtom("/etc/polipo/config");
+ if(access( DEFAULT_CONFIG_PATH, F_OK) >= 0)
+ configFile = internAtom( DEFAULT_CONFIG_PATH );
if(configFile && access(configFile->string, F_OK) < 0) {
releaseAtom(configFile);
configFile = NULL;
diff -Nur polipo-harden-test/md5.h polipo/md5.h
--- polipo-harden-test/md5.h 2009-12-12 07:39:48 +0800
+++ polipo/md5.h 2010-01-12 20:12:22 +0800
@@ -35,7 +35,12 @@
#ifdef HAS_STDINT_H
#include <stdint.h>
#elif defined(HAS_INTTYPES_H)
-#include <inttypes.h>
+#ifdef _MSC_VER
+ #include "inttypes.h"
+#else
+ #include <inttypes.h>
+#endif
+
#endif
/* typedef a 32-bit type */
diff -Nur polipo-harden-test/mingw.c polipo/mingw.c
--- polipo-harden-test/mingw.c 2009-12-12 07:39:48 +0800
+++ polipo/mingw.c 2010-01-12 16:15:56 +0800
@@ -23,7 +23,7 @@
#include "polipo.h"
-#ifndef MINGW
+#ifndef WIN32 //MINGW
static int dummy ATTRIBUTE((unused));
@@ -53,7 +53,7 @@
* (with trivial modifications) from the OpenBSD project.
*/
int
-mingw_inet_aton(const char *cp, struct in_addr *addr)
+win32_inet_aton(const char *cp, struct in_addr *addr)
{
register unsigned int val;
register int base, n;
@@ -148,14 +148,14 @@
}
unsigned int
-mingw_sleep(unsigned int seconds)
+win32_sleep(unsigned int seconds)
{
Sleep(seconds * 1000);
return 0;
}
int
-mingw_gettimeofday(struct timeval *tv, char *tz)
+win32_gettimeofday(struct timeval *tv, char *tz)
{
const long long EPOCHFILETIME = (116444736000000000LL);
FILETIME ft;
@@ -183,7 +183,7 @@
return 0;
}
-int mingw_poll(struct pollfd *fds, unsigned int nfds, int timo)
+int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
{
struct timeval timeout, *toptr;
fd_set ifds, ofds, efds, *ip, *op;
@@ -248,7 +248,7 @@
return rc;
}
-int mingw_close_socket(SOCKET fd) {
+int win32_close_socket(SOCKET fd) {
int rc;
rc = closesocket(fd);
@@ -268,7 +268,7 @@
}
}
-int mingw_write_socket(SOCKET fd, void *buf, int n)
+int win32_write_socket(SOCKET fd, void *buf, int n)
{
int rc = send(fd, buf, n, 0);
if(rc == SOCKET_ERROR) {
@@ -277,7 +277,7 @@
return rc;
}
-int mingw_read_socket(SOCKET fd, void *buf, int n)
+int win32_read_socket(SOCKET fd, void *buf, int n)
{
int rc = recv(fd, buf, n, 0);
if(rc == SOCKET_ERROR) {
@@ -294,7 +294,7 @@
* is successful, other -1.
*/
int
-mingw_setnonblocking(SOCKET fd, int nonblocking)
+win32_setnonblocking(SOCKET fd, int nonblocking)
{
int rc;
@@ -312,7 +312,7 @@
* even if we are using winsock.
*/
SOCKET
-mingw_socket(int domain, int type, int protocol)
+win32_socket(int domain, int type, int protocol)
{
SOCKET fd = socket(domain, type, protocol);
if(fd == INVALID_SOCKET) {
@@ -342,7 +342,7 @@
* even if we are using winsock.
*/
int
-mingw_connect(SOCKET fd, struct sockaddr *addr, socklen_t addr_len)
+win32_connect(SOCKET fd, struct sockaddr *addr, socklen_t addr_len)
{
int rc = connect(fd, addr, addr_len);
assert(rc == 0 || rc == SOCKET_ERROR);
@@ -358,7 +358,7 @@
* even if we are using winsock.
*/
SOCKET
-mingw_accept(SOCKET fd, struct sockaddr *addr, socklen_t *addr_len)
+win32_accept(SOCKET fd, struct sockaddr *addr, socklen_t *addr_len)
{
SOCKET newfd = accept(fd, addr, addr_len);
if(newfd == INVALID_SOCKET) {
@@ -374,7 +374,7 @@
* even if we are using winsock.
*/
int
-mingw_shutdown(SOCKET fd, int mode)
+win32_shutdown(SOCKET fd, int mode)
{
int rc = shutdown(fd, mode);
assert(rc == 0 || rc == SOCKET_ERROR);
@@ -390,7 +390,7 @@
* even if we are using winsock.
*/
int
-mingw_getpeername(SOCKET fd, struct sockaddr *name, socklen_t *namelen)
+win32_getpeername(SOCKET fd, struct sockaddr *name, socklen_t *namelen)
{
int rc = getpeername(fd, name, namelen);
assert(rc == 0 || rc == SOCKET_ERROR);
@@ -403,7 +403,7 @@
/* Stat doesn't work on directories if the name ends in a slash. */
int
-mingw_stat(const char *filename, struct stat *ss)
+win32_stat(const char *filename, struct stat *ss)
{
int len, rc, saved_errno;
char *noslash;
@@ -425,7 +425,7 @@
errno = saved_errno;
return rc;
}
-#endif /* #ifdef MINGW */
+#endif /* #ifdef WIN32 MINGW */
#ifndef HAVE_READV_WRITEV
diff -Nur polipo-harden-test/mingw.h polipo/mingw.h
--- polipo-harden-test/mingw.h 2009-12-12 07:39:48 +0800
+++ polipo/mingw.h 2010-01-12 15:54:37 +0800
@@ -32,7 +32,7 @@
* symbol. For Unix or Unix-like systems, leave it undefined.
*/
-#ifdef MINGW
+#ifdef WIN32 //MINGW
/* Unfortunately, there's no hiding it. */
#define HAVE_WINSOCK 1
@@ -74,7 +74,7 @@
short events; /* requested events */
short revents; /* returned events */
};
-#define poll(x, y, z) mingw_poll(x, y, z)
+#define poll(x, y, z) win32_poll(x, y, z)
/* These wrappers do nothing special except set the global errno variable if
* an error occurs (winsock doesn't do this by default). They set errno
@@ -82,17 +82,17 @@
* outside of this file "shouldn't" have to worry about winsock specific error
* handling.
*/
-#define socket(x, y, z) mingw_socket(x, y, z)
-#define connect(x, y, z) mingw_connect(x, y, z)
-#define accept(x, y, z) mingw_accept(x, y, z)
-#define shutdown(x, y) mingw_shutdown(x, y)
-#define getpeername(x, y, z) mingw_getpeername(x, y, z)
+#define socket(x, y, z) win32_socket(x, y, z)
+#define connect(x, y, z) win32_connect(x, y, z)
+#define accept(x, y, z) win32_accept(x, y, z)
+#define shutdown(x, y) win32_shutdown(x, y)
+#define getpeername(x, y, z) win32_getpeername(x, y, z)
/* Wrapper macros to call misc. functions mingw is missing */
-#define sleep(x) mingw_sleep(x)
-#define inet_aton(x, y) mingw_inet_aton(x, y)
-#define gettimeofday(x, y) mingw_gettimeofday(x, y)
-#define stat(x, y) mingw_stat(x, y)
+#define sleep(x) win32_sleep(x)
+#define inet_aton(x, y) win32_inet_aton(x, y)
+#define gettimeofday(x, y) win32_gettimeofday(x, y)
+#define stat(x, y) win32_stat(x, y)
#define mkdir(x, y) mkdir(x)
@@ -100,27 +100,27 @@
typedef int socklen_t;
/* Function prototypes for functions in mingw.c */
-unsigned int mingw_sleep(unsigned int);
-int mingw_inet_aton(const char *, struct in_addr *);
-int mingw_gettimeofday(struct timeval *, char *);
-int mingw_poll(struct pollfd *, unsigned int, int);
-SOCKET mingw_socket(int, int, int);
-int mingw_connect(SOCKET, struct sockaddr*, socklen_t);
-SOCKET mingw_accept(SOCKET, struct sockaddr*, socklen_t *);
-int mingw_shutdown(SOCKET, int);
-int mingw_getpeername(SOCKET, struct sockaddr*, socklen_t *);
+unsigned int win32_sleep(unsigned int);
+int win32_inet_aton(const char *, struct in_addr *);
+int win32_gettimeofday(struct timeval *, char *);
+int win32_poll(struct pollfd *, unsigned int, int);
+SOCKET win32_socket(int, int, int);
+int win32_connect(SOCKET, struct sockaddr*, socklen_t);
+SOCKET win32_accept(SOCKET, struct sockaddr*, socklen_t *);
+int win32_shutdown(SOCKET, int);
+int win32_getpeername(SOCKET, struct sockaddr*, socklen_t *);
/* Three socket specific macros */
-#define READ(x, y, z) mingw_read_socket(x, y, z)
-#define WRITE(x, y, z) mingw_write_socket(x, y, z)
-#define CLOSE(x) mingw_close_socket(x)
-
-int mingw_read_socket(SOCKET, void *, int);
-int mingw_write_socket(SOCKET, void *, int);
-int mingw_close_socket(SOCKET);
+#define READ(x, y, z) win32_read_socket(x, y, z)
+#define WRITE(x, y, z) win32_write_socket(x, y, z)
+#define CLOSE(x) win32_close_socket(x)
+
+int win32_read_socket(SOCKET, void *, int);
+int win32_write_socket(SOCKET, void *, int);
+int win32_close_socket(SOCKET);
-int mingw_setnonblocking(SOCKET, int);
-int mingw_stat(const char*, struct stat*);
+int win32_setnonblocking(SOCKET, int);
+int win32_stat(const char*, struct stat*);
#endif
#ifndef HAVE_READV_WRITEV
diff -Nur polipo-harden-test/object.c polipo/object.c
--- polipo-harden-test/object.c 2009-12-12 07:39:48 +0800
+++ polipo/object.c 2010-01-13 20:11:05 +0800
@@ -809,7 +809,7 @@
discardObjects(int all, int force)
{
ObjectPtr object;
- int i;
+ int i=0;
static int in_discardObjects = 0;
TimeEventHandlerPtr event;
@@ -838,7 +838,7 @@
dispose_chunk(object->chunks[j].data);
object->chunks[j].data = NULL;
object->chunks[j].size = 0;
- i++;
+ // i++; //jiang :it seems no use here
}
}
object = object->previous;
diff -Nur polipo-harden-test/polipo.h polipo/polipo.h
--- polipo-harden-test/polipo.h 2009-12-12 07:39:48 +0800
+++ polipo/polipo.h 2010-01-20 15:20:09 +0800
@@ -24,7 +24,9 @@
#define _GNU_SOURCE
#endif
+#ifndef WIN32
#include <sys/param.h>
+#endif
#ifdef __MINGW32_VERSION
#define MINGW
@@ -37,13 +39,15 @@
#include <errno.h>
#include <string.h>
#include <assert.h>
-#include <unistd.h>
#include <fcntl.h>
#include <time.h>
-#include <sys/time.h>
#include <sys/stat.h>
+#ifndef _MSC_VER
+#include <unistd.h>
+#include <sys/time.h>
#include <dirent.h>
-#ifndef MINGW
+#endif
+#ifndef WIN32 //MINGW
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -58,6 +62,14 @@
#include <signal.h>
#endif
+#if defined(va_copy)
+#elif defined(__va_copy)
+# define va_copy(dst, src) __va_copy((dst), (src))
+#else
+//# define va_copy(dst, src) (memcpy(&(dst), &(src), sizeof (va_list)))
+# define va_copy(dst, src) do{((dst) = (src)) ;} while(0)
+#endif
+
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
@@ -165,7 +177,7 @@
#define UNALIGNED_ACCESS
#endif
-#ifndef MINGW
+#ifndef WIN32 //MINGW
#define HAVE_FORK
#ifndef NO_SYSLOG
#define HAVE_SYSLOG
@@ -181,6 +193,15 @@
#endif
#endif
+#ifdef _MSC_VER
+
+#define F_OK 00
+#define snprintf _snprintf
+#define S_ISDIR(x) (S_IFDIR&(x))
+#define S_ISREG(x) (S_IFREG&(x))
+
+#endif
+
#ifdef HAVE_READV_WRITEV
#define WRITEV(x, y, z) writev(x, y, z)
#define READV(x, y, z) readv(x, y, z)
diff -Nur polipo-harden-test/polipo.vcproj polipo/polipo.vcproj
--- polipo-harden-test/polipo.vcproj 1970-01-01 08:00:00 +0800
+++ polipo/polipo.vcproj 2010-01-13 16:35:35 +0800
@@ -0,0 +1,399 @@
+<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="polipo"
+ ProjectGUID="{B4E72DB8-4BA8-44D9-83F4-84162140CC91}"
+ RootNamespace="polipo"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;HAS_INTTYPES_H"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="ws2_32.lib Iphlpapi.lib"
+ GenerateDebugInformation="true"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="2"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions="WIN32;HAS_INTTYPES_H"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="ws2_32.lib Iphlpapi.lib"
+ GenerateDebugInformation="true"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Ô´Îļþ"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\atom.c"
+ >
+ </File>
+ <File
+ RelativePath=".\auth.c"
+ >
+ </File>
+ <File
+ RelativePath=".\chunk.c"
+ >
+ </File>
+ <File
+ RelativePath=".\client.c"
+ >
+ </File>
+ <File
+ RelativePath=".\config.c"
+ >
+ </File>
+ <File
+ RelativePath=".\diskcache.c"
+ >
+ </File>
+ <File
+ RelativePath=".\dns.c"
+ >
+ </File>
+ <File
+ RelativePath=".\event.c"
+ >
+ </File>
+ <File
+ RelativePath=".\forbidden.c"
+ >
+ </File>
+ <File
+ RelativePath=".\fts_compat.c"
+ >
+ </File>
+ <File
+ RelativePath=".\http.c"
+ >
+ </File>
+ <File
+ RelativePath=".\http_parse.c"
+ >
+ </File>
+ <File
+ RelativePath=".\io.c"
+ >
+ </File>
+ <File
+ RelativePath=".\local.c"
+ >
+ </File>
+ <File
+ RelativePath=".\log.c"
+ >
+ </File>
+ <File
+ RelativePath=".\main.c"
+ >
+ </File>
+ <File
+ RelativePath=".\md5.c"
+ >
+ </File>
+ <File
+ RelativePath=".\mingw.c"
+ >
+ </File>
+ <File
+ RelativePath=".\object.c"
+ >
+ </File>
+ <File
+ RelativePath=".\parse_time.c"
+ >
+ </File>
+ <File
+ RelativePath=".\server.c"
+ >
+ </File>
+ <File
+ RelativePath=".\socks.c"
+ >
+ </File>
+ <File
+ RelativePath=".\tunnel.c"
+ >
+ </File>
+ <File
+ RelativePath=".\util.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Í·Îļþ"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\atom.h"
+ >
+ </File>
+ <File
+ RelativePath=".\auth.h"
+ >
+ </File>
+ <File
+ RelativePath=".\chunk.h"
+ >
+ </File>
+ <File
+ RelativePath=".\client.h"
+ >
+ </File>
+ <File
+ RelativePath=".\config.h"
+ >
+ </File>
+ <File
+ RelativePath=".\diskcache.h"
+ >
+ </File>
+ <File
+ RelativePath=".\dns.h"
+ >
+ </File>
+ <File
+ RelativePath=".\event.h"
+ >
+ </File>
+ <File
+ RelativePath=".\forbidden.h"
+ >
+ </File>
+ <File
+ RelativePath=".\fts_compat.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ftsimport.h"
+ >
+ </File>
+ <File
+ RelativePath=".\http.h"
+ >
+ </File>
+ <File
+ RelativePath=".\http_parse.h"
+ >
+ </File>
+ <File
+ RelativePath=".\io.h"
+ >
+ </File>
+ <File
+ RelativePath=".\local.h"
+ >
+ </File>
+ <File
+ RelativePath=".\log.h"
+ >
+ </File>
+ <File
+ RelativePath=".\md5.h"
+ >
+ </File>
+ <File
+ RelativePath=".\md5import.h"
+ >
+ </File>
+ <File
+ RelativePath=".\mingw.h"
+ >
+ </File>
+ <File
+ RelativePath=".\object.h"
+ >
+ </File>
+ <File
+ RelativePath=".\parse_time.h"
+ >
+ </File>
+ <File
+ RelativePath=".\polipo.h"
+ >
+ </File>
+ <File
+ RelativePath=".\server.h"
+ >
+ </File>
+ <File
+ RelativePath=".\socks.h"
+ >
+ </File>
+ <File
+ RelativePath=".\tunnel.h"
+ >
+ </File>
+ <File
+ RelativePath=".\util.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="port"
+ >
+ <File
+ RelativePath=".\dirent.c"
+ >
+ </File>
+ <File
+ RelativePath=".\dirent.h"
+ >
+ </File>
+ <File
+ RelativePath=".\inttypes.h"
+ >
+ </File>
+ <File
+ RelativePath=".\stdint.h"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff -Nur polipo-harden-test/stdint.h polipo/stdint.h
--- polipo-harden-test/stdint.h 1970-01-01 08:00:00 +0800
+++ polipo/stdint.h 2009-12-05 14:45:53 +0800
@@ -0,0 +1,232 @@
+// ISO C9x compliant stdint.h for Microsoft Visual Studio
+// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
+//
+// Copyright (c) 2006-2008 Alexander Chemeris
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// 3. The name of the author may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _MSC_VER // [
+#error "Use this header only with Microsoft Visual C++ compilers!"
+#endif // _MSC_VER ]
+
+#ifndef _MSC_STDINT_H_ // [
+#define _MSC_STDINT_H_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif
+
+#include <limits.h>
+
+// For Visual Studio 6 in C++ mode wrap <wchar.h> include with 'extern "C++" {}'
+// or compiler give many errors like this:
+// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
+#if (_MSC_VER < 1300) && defined(__cplusplus)
+ extern "C++" {
+#endif
+# include <wchar.h>
+#if (_MSC_VER < 1300) && defined(__cplusplus)
+ }
+#endif
+
+// Define _W64 macros to mark types changing their size, like intptr_t.
+#ifndef _W64
+# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
+# define _W64 __w64
+# else
+# define _W64
+# endif
+#endif
+
+
+// 7.18.1 Integer types
+
+// 7.18.1.1 Exact-width integer types
+typedef __int8 int8_t;
+typedef __int16 int16_t;
+typedef __int32 int32_t;
+typedef __int64 int64_t;
+typedef unsigned __int8 uint8_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+
+// 7.18.1.2 Minimum-width integer types
+typedef int8_t int_least8_t;
+typedef int16_t int_least16_t;
+typedef int32_t int_least32_t;
+typedef int64_t int_least64_t;
+typedef uint8_t uint_least8_t;
+typedef uint16_t uint_least16_t;
+typedef uint32_t uint_least32_t;
+typedef uint64_t uint_least64_t;
+
+// 7.18.1.3 Fastest minimum-width integer types
+typedef int8_t int_fast8_t;
+typedef int16_t int_fast16_t;
+typedef int32_t int_fast32_t;
+typedef int64_t int_fast64_t;
+typedef uint8_t uint_fast8_t;
+typedef uint16_t uint_fast16_t;
+typedef uint32_t uint_fast32_t;
+typedef uint64_t uint_fast64_t;
+
+// 7.18.1.4 Integer types capable of holding object pointers
+#ifdef _WIN64 // [
+ typedef __int64 intptr_t;
+ typedef unsigned __int64 uintptr_t;
+#else // _WIN64 ][
+ typedef _W64 int intptr_t;
+ typedef _W64 unsigned int uintptr_t;
+#endif // _WIN64 ]
+
+// 7.18.1.5 Greatest-width integer types
+typedef int64_t intmax_t;
+typedef uint64_t uintmax_t;
+
+
+// 7.18.2 Limits of specified-width integer types
+
+#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
+
+// 7.18.2.1 Limits of exact-width integer types
+#define INT8_MIN ((int8_t)_I8_MIN)
+#define INT8_MAX _I8_MAX
+#define INT16_MIN ((int16_t)_I16_MIN)
+#define INT16_MAX _I16_MAX
+#define INT32_MIN ((int32_t)_I32_MIN)
+#define INT32_MAX _I32_MAX
+#define INT64_MIN ((int64_t)_I64_MIN)
+#define INT64_MAX _I64_MAX
+#define UINT8_MAX _UI8_MAX
+#define UINT16_MAX _UI16_MAX
+#define UINT32_MAX _UI32_MAX
+#define UINT64_MAX _UI64_MAX
+
+// 7.18.2.2 Limits of minimum-width integer types
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST8_MAX INT8_MAX
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST16_MAX INT16_MAX
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST32_MAX INT32_MAX
+#define INT_LEAST64_MIN INT64_MIN
+#define INT_LEAST64_MAX INT64_MAX
+#define UINT_LEAST8_MAX UINT8_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+// 7.18.2.3 Limits of fastest minimum-width integer types
+#define INT_FAST8_MIN INT8_MIN
+#define INT_FAST8_MAX INT8_MAX
+#define INT_FAST16_MIN INT16_MIN
+#define INT_FAST16_MAX INT16_MAX
+#define INT_FAST32_MIN INT32_MIN
+#define INT_FAST32_MAX INT32_MAX
+#define INT_FAST64_MIN INT64_MIN
+#define INT_FAST64_MAX INT64_MAX
+#define UINT_FAST8_MAX UINT8_MAX
+#define UINT_FAST16_MAX UINT16_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+// 7.18.2.4 Limits of integer types capable of holding object pointers
+#ifdef _WIN64 // [
+# define INTPTR_MIN INT64_MIN
+# define INTPTR_MAX INT64_MAX
+# define UINTPTR_MAX UINT64_MAX
+#else // _WIN64 ][
+# define INTPTR_MIN INT32_MIN
+# define INTPTR_MAX INT32_MAX
+# define UINTPTR_MAX UINT32_MAX
+#endif // _WIN64 ]
+
+// 7.18.2.5 Limits of greatest-width integer types
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+// 7.18.3 Limits of other integer types
+
+#ifdef _WIN64 // [
+# define PTRDIFF_MIN _I64_MIN
+# define PTRDIFF_MAX _I64_MAX
+#else // _WIN64 ][
+# define PTRDIFF_MIN _I32_MIN
+# define PTRDIFF_MAX _I32_MAX
+#endif // _WIN64 ]
+
+#define SIG_ATOMIC_MIN INT_MIN
+#define SIG_ATOMIC_MAX INT_MAX
+
+#ifndef SIZE_MAX // [
+# ifdef _WIN64 // [
+# define SIZE_MAX _UI64_MAX
+# else // _WIN64 ][
+# define SIZE_MAX _UI32_MAX
+# endif // _WIN64 ]
+#endif // SIZE_MAX ]
+
+// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
+#ifndef WCHAR_MIN // [
+# define WCHAR_MIN 0
+#endif // WCHAR_MIN ]
+#ifndef WCHAR_MAX // [
+# define WCHAR_MAX _UI16_MAX
+#endif // WCHAR_MAX ]
+
+#define WINT_MIN 0
+#define WINT_MAX _UI16_MAX
+
+#endif // __STDC_LIMIT_MACROS ]
+
+
+// 7.18.4 Limits of other integer types
+
+#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
+
+// 7.18.4.1 Macros for minimum-width integer constants
+
+#define INT8_C(val) val##i8
+#define INT16_C(val) val##i16
+#define INT32_C(val) val##i32
+#define INT64_C(val) val##i64
+
+#define UINT8_C(val) val##ui8
+#define UINT16_C(val) val##ui16
+#define UINT32_C(val) val##ui32
+#define UINT64_C(val) val##ui64
+
+// 7.18.4.2 Macros for greatest-width integer constants
+#define INTMAX_C INT64_C
+#define UINTMAX_C UINT64_C
+
+#endif // __STDC_CONSTANT_MACROS ]
+
+
+#endif // _MSC_STDINT_H_ ]
diff -Nur polipo-harden-test/util.c polipo/util.c
--- polipo-harden-test/util.c 2009-12-12 07:39:48 +0800
+++ polipo/util.c 2010-01-20 15:16:28 +0800
@@ -278,11 +278,11 @@
#else
-/* This is not going to work if va_list is interesting. But then, if you
- have a non-trivial implementation of va_list, you should have va_copy. */
-#ifndef va_copy
-#define va_copy(a, b) do { a = b; } while(0)
-#endif
+///* This is not going to work if va_list is interesting. But then, if you
+// have a non-trivial implementation of va_list, you should have va_copy. */
+//#ifndef va_copy
+//#define va_copy(a, b) do { a = b; } while(0)
+//#endif
char*
vsprintf_a(const char *f, va_list args)
@@ -392,7 +392,7 @@
default: s = NULL; break;
}
if(!s) s = strerror(e);
-#ifdef MINGW
+#ifdef WIN32 //MINGW
if(!s) {
if(e >= WSABASEERR && e <= WSABASEERR + 2000) {
/* This should be okay, as long as the caller discards the
@@ -456,7 +456,7 @@
mktime_gmt(struct tm *tm)
{
time_t t;
- char *tz;
+ char *tz=NULL;
static char *old_tz = NULL;
tz = getenv("TZ");
@@ -465,7 +465,7 @@
t = mktime(tm);
if(old_tz)
free(old_tz);
- if(tz)
+ if( tz && tz[0]>0 )
old_tz = sprintf_a("TZ=%s", tz);
else
old_tz = strdup("TZ"); /* XXX - non-portable? */