diff -uwNr aria2-0.9.0.orig/configure.ac aria2-0.9.0/configure.ac --- aria2-0.9.0.orig/configure.ac 2006-11-08 08:43:56.000000000 -0800 +++ aria2-0.9.0/configure.ac 2006-11-19 11:39:16.000000000 -0800 @@ -3,11 +3,22 @@ # AC_PREREQ(2.59) AC_INIT(aria2c, 0.9.0, tujikawa@rednoah.com) + +AC_CANONICAL_HOST +AC_CANONICAL_SYSTEM + AM_INIT_AUTOMAKE() AM_PATH_CPPUNIT(1.10.2) AC_CONFIG_SRCDIR([src/Socket.h]) AC_CONFIG_HEADERS([config.h]) +case "$target" in + *mingw*|*cygwin*) + WINSOCK_LIBS="-lws2_32" + AC_SUBST(WINSOCK_LIBS) + ;; +esac + # Set localedir localedir=${datadir}/locale AC_SUBST(localedir) @@ -99,7 +110,7 @@ # Checks for header files. AC_FUNC_ALLOCA #AC_HEADER_STDC -AC_CHECK_HEADERS([argz.h arpa/inet.h fcntl.h inttypes.h langinfo.h libintl.h limits.h locale.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdio_ext.h stdlib.h string.h strings.h sys/param.h sys/socket.h sys/time.h unistd.h]) +AC_CHECK_HEADERS([winsock2.h ws2tcpip.h argz.h arpa/inet.h fcntl.h inttypes.h io.h langinfo.h libgen.h libintl.h limits.h locale.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdio_ext.h stdlib.h string.h strings.h sys/param.h sys/socket.h sys/time.h unistd.h]) # Checks for typedefs, structures, and compiler characteristics. AC_HEADER_STDBOOL @@ -122,7 +133,19 @@ AC_FUNC_SELECT_ARGTYPES AC_FUNC_STAT AC_FUNC_VPRINTF -AC_CHECK_FUNCS([__argz_count __argz_next __argz_stringify ftruncate getcwd getpagesize gettimeofday inet_ntoa memchr mempcpy memset mkdir munmap nl_langinfo rmdir select setlocale socket stpcpy strcasecmp strchr strcspn strdup strerror strstr strtol strtoul]) +AC_CHECK_FUNCS([__argz_count __argz_next __argz_stringify ctime_r daemon ftruncate getcwd getpagesize gettimeofday inet_ntoa memchr mempcpy memset mkdir munmap nl_langinfo random rmdir select setlocale setmode sigaction sleep socket srandom stpcpy strcasecmp strchr strcspn strdup strerror strstr strtol strtoul usleep]) + +AC_CHECK_FUNCS([basename], [AM_CONDITIONAL([HAVE_BASENAME], true)], [AM_CONDITIONAL([HAVE_BASENAME], false)]) +AC_CHECK_FUNCS([getaddrinfo], [AM_CONDITIONAL([HAVE_GETADDRINFO], true)], [AM_CONDITIONAL([HAVE_GETADDRINFO], false)]) +AC_CHECK_FUNCS([inet_aton], [AM_CONDITIONAL([HAVE_INET_ATON], true)], [AM_CONDITIONAL([HAVE_INET_ATON], false)]) + +case "$target" in + *mingw*) + dnl true if _WIN32_WINNT >= 0x0501 + AM_CONDITIONAL([HAVE_GETADDRINFO], true) + ;; +esac + AC_CONFIG_FILES([Makefile src/Makefile test/Makefile diff -uwNr aria2-0.9.0.orig/lib/libgen.h aria2-0.9.0/lib/libgen.h --- aria2-0.9.0.orig/lib/libgen.h 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.9.0/lib/libgen.h 2006-11-19 11:39:16.000000000 -0800 @@ -0,0 +1,50 @@ +/* */ + +#ifndef _D_LIBGEN_H +#define _D_LIBGEN_H 1 + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +char *basename (char *path); +char *dirname (char *path); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* not _D_LIBGEN_H */ diff -uwNr aria2-0.9.0.orig/reconf aria2-0.9.0/reconf --- aria2-0.9.0.orig/reconf 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.9.0/reconf 2006-11-19 11:39:16.000000000 -0800 @@ -0,0 +1,15 @@ +#!/bin/sh +# +# $Id$ +# +# re autoconf/automake shell script +# + +die(){ + echo "$@" ; exit +} + +aclocal -I . -I m4 || die "The command 'aclocal -I .' failed" +autoheader || die "The command 'autoheader' failed" +automake || die "The command 'automake' failed" +autoconf || die "The command 'autoconf' failed" diff -uwNr aria2-0.9.0.orig/src/AbstractDiskWriter.cc aria2-0.9.0/src/AbstractDiskWriter.cc --- aria2-0.9.0.orig/src/AbstractDiskWriter.cc 2006-09-21 08:31:24.000000000 -0700 +++ aria2-0.9.0/src/AbstractDiskWriter.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,6 +32,7 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "AbstractDiskWriter.h" #include "DlAbortEx.h" #include "File.h" @@ -84,7 +85,7 @@ throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), "file not found"); } - if((fd = open(filename.c_str(), O_RDWR, S_IRUSR|S_IWUSR)) < 0) { + if((fd = open(filename.c_str(), O_RDWR|O_BINARY, S_IRUSR|S_IWUSR)) < 0) { throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno)); } } @@ -96,7 +97,7 @@ // if(filename.empty()) { // filename = "index.html"; // } - if((fd = open(filename.c_str(), O_CREAT|O_RDWR|O_TRUNC|addFlags, S_IRUSR|S_IWUSR)) < 0) { + if((fd = open(filename.c_str(), O_CREAT|O_RDWR|O_TRUNC|O_BINARY|addFlags, S_IRUSR|S_IWUSR)) < 0) { throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno)); } } diff -uwNr aria2-0.9.0.orig/src/BitfieldMan.cc aria2-0.9.0/src/BitfieldMan.cc --- aria2-0.9.0.orig/src/BitfieldMan.cc 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/src/BitfieldMan.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,6 +32,7 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "BitfieldMan.h" #include "Util.h" #include @@ -106,7 +107,11 @@ BitfieldMan::getMissingIndexRandomly(const unsigned char* bitfield, int bitfieldLength) const { +#ifdef HAVE_RANDOM int byte = (int)(((double)bitfieldLength)*random()/(RAND_MAX+1.0)); +#else + int byte = (int)(((double)bitfieldLength)*rand()/(RAND_MAX+1.0)); +#endif // HAVE_RANDOM unsigned char lastMask = 0; int lastByteLength = totalLength%(blockLength*8); diff -uwNr aria2-0.9.0.orig/src/CompactPeerListProcessor.cc aria2-0.9.0/src/CompactPeerListProcessor.cc --- aria2-0.9.0.orig/src/CompactPeerListProcessor.cc 2006-10-01 04:29:14.000000000 -0700 +++ aria2-0.9.0/src/CompactPeerListProcessor.cc 2006-11-19 11:39:16.000000000 -0800 @@ -31,9 +31,13 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "CompactPeerListProcessor.h" #include "Data.h" + +#ifdef HAVE_NETINET_IN_H #include +#endif // HAVE_NETINET_IN_H bool CompactPeerListProcessor::canHandle(const MetaEntry* peersEntry) const { return dynamic_cast(peersEntry) != 0; diff -uwNr aria2-0.9.0.orig/src/DefaultBtProgressInfoFile.cc aria2-0.9.0/src/DefaultBtProgressInfoFile.cc --- aria2-0.9.0.orig/src/DefaultBtProgressInfoFile.cc 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/src/DefaultBtProgressInfoFile.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,6 +32,7 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "DefaultBtProgressInfoFile.h" #include "BtRegistry.h" #include "LogFactory.h" @@ -42,6 +43,10 @@ #include "Util.h" #include +#ifdef HAVE_IO_H +# include +#endif // HAVE_IO_H + DefaultBtProgressInfoFile::DefaultBtProgressInfoFile(const BtContextHandle& btContext, const Option* option): btContext(btContext), @@ -59,7 +64,7 @@ void DefaultBtProgressInfoFile::save() { logger->info(MSG_SAVING_SEGMENT_FILE, filename.c_str()); - FILE* file = openFile(filename, "w"); + FILE* file = openFile(filename, "wb"); try { if(fwrite(btContext->getInfoHash(), btContext->getInfoHashLength(), 1, file) < 1) { @@ -93,7 +98,7 @@ void DefaultBtProgressInfoFile::load() { logger->info(MSG_LOADING_SEGMENT_FILE, filename.c_str()); - FILE* file = openFile(filename, "r+"); + FILE* file = openFile(filename, "r+b"); unsigned char* savedInfoHash = 0; unsigned char* savedBitfield = 0; try { @@ -157,6 +162,9 @@ throw new DlAbortEx(EX_SEGMENT_FILE_OPEN, filename.c_str(), strerror(errno)); } +#ifdef HAVE_SETMODE + setmode(fileno(file), O_BINARY); +#endif return file; } diff -uwNr aria2-0.9.0.orig/src/Directory.cc aria2-0.9.0/src/Directory.cc --- aria2-0.9.0.orig/src/Directory.cc 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/src/Directory.cc 2006-11-19 11:39:16.000000000 -0800 @@ -39,6 +39,7 @@ #include #include #include +#include Directory::Directory(const string& name):name(name) {} @@ -61,7 +62,11 @@ throw new DlAbortEx(EX_NOT_DIRECTORY, path.c_str()); } } else { +#ifdef __MINGW32__ + if(mkdir(path.c_str()) == -1) { +#else if(mkdir(path.c_str(), S_IRUSR|S_IWUSR|S_IXUSR) == -1) { +#endif // __MINGW32__ throw new DlAbortEx(EX_MAKE_DIR, path.c_str(), strerror(errno)); } } diff -uwNr aria2-0.9.0.orig/src/DownloadCommand.cc aria2-0.9.0/src/DownloadCommand.cc --- aria2-0.9.0.orig/src/DownloadCommand.cc 2006-11-08 08:25:38.000000000 -0800 +++ aria2-0.9.0/src/DownloadCommand.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,6 +32,7 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "DownloadCommand.h" #include "Util.h" #include "DlRetryEx.h" @@ -41,6 +42,7 @@ #include "message.h" #include "prefs.h" #include +#include DownloadCommand::DownloadCommand(int cuid, const RequestHandle req, @@ -65,7 +67,11 @@ int maxSpeedLimit = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT); if(maxSpeedLimit > 0 && maxSpeedLimit < e->segmentMan->calculateDownloadSpeed()) { +#ifdef HAVE_USLEEP usleep(1); +#else + _sleep(1); +#endif // HAVE_USLEEP e->commands.push_back(this); return false; } diff -uwNr aria2-0.9.0.orig/src/DownloadEngine.h aria2-0.9.0/src/DownloadEngine.h --- aria2-0.9.0.orig/src/DownloadEngine.h 2006-09-21 08:31:24.000000000 -0700 +++ aria2-0.9.0/src/DownloadEngine.h 2006-11-19 11:39:16.000000000 -0800 @@ -35,10 +35,11 @@ #ifndef _D_DOWNLOAD_ENGINE_H_ #define _D_DOWNLOAD_ENGINE_H_ +#include "common.h" +#include "common.h" #include "Command.h" #include "Socket.h" #include "SegmentMan.h" -#include "common.h" #include "Logger.h" #include "Option.h" #ifdef ENABLE_ASYNC_DNS diff -uwNr aria2-0.9.0.orig/src/File.cc aria2-0.9.0/src/File.cc --- aria2-0.9.0.orig/src/File.cc 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/src/File.cc 2006-11-19 11:39:16.000000000 -0800 @@ -67,6 +67,14 @@ return S_ISDIR(fstat.st_mode) == 1; } +bool File::isDir(const string& name) { + struct stat fstat; + if(stat(name.c_str(), &fstat) < 0) { + return false; + } + return S_ISDIR(fstat.st_mode) == 1; +} + bool File::remove() { if(isFile()) { return unlink(name.c_str()) == 0; @@ -98,14 +106,18 @@ if(Util::startsWith(name, "/")) { accDir = "/"; } - mode_t mode = S_IRUSR|S_IWUSR|S_IXUSR; for(Strings::const_iterator itr = dirs.begin(); itr != dirs.end(); itr++, accDir += "/") { accDir += *itr; if(File(accDir).isDir()) { continue; } +#ifdef __MINGW32__ + if(mkdir(accDir.c_str()) == -1) { +#else + mode_t mode = S_IRUSR|S_IWUSR|S_IXUSR; if(mkdir(accDir.c_str(), mode) == -1) { +#endif // __MINGW32__ return false; } } diff -uwNr aria2-0.9.0.orig/src/File.h aria2-0.9.0/src/File.h --- aria2-0.9.0.orig/src/File.h 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/src/File.h 2006-11-19 11:39:16.000000000 -0800 @@ -67,6 +67,11 @@ bool isDir(); /** + * Tests whether the file denoted by name is a directory. + */ + static bool isDir(const string& name); + + /** * Deletes the file or directory denoted by name. * If name denotes a directory, it must be empty in order to delete. */ diff -uwNr aria2-0.9.0.orig/src/FileEntry.cc aria2-0.9.0/src/FileEntry.cc --- aria2-0.9.0.orig/src/FileEntry.cc 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/src/FileEntry.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,6 +32,7 @@ * files in the program, then also delete it here. */ /* copyright --> */ + #include "FileEntry.h" #include "File.h" #include "DlAbortEx.h" diff -uwNr aria2-0.9.0.orig/src/HttpResponseCommand.cc aria2-0.9.0/src/HttpResponseCommand.cc --- aria2-0.9.0.orig/src/HttpResponseCommand.cc 2006-10-18 07:57:00.000000000 -0700 +++ aria2-0.9.0/src/HttpResponseCommand.cc 2006-11-19 11:39:16.000000000 -0800 @@ -140,7 +140,7 @@ req->setKeepAlive(false); e->segmentMan->isSplittable = false; e->segmentMan->downloadStarted = true; - e->segmentMan->diskWriter->initAndOpenFile("/tmp/aria2"+Util::itos(getpid())); + e->segmentMan->diskWriter->initAndOpenFile(Util::getTempDir()+"/aria2"+Util::itos(getpid())); createHttpDownloadCommand(); return true; } diff -uwNr aria2-0.9.0.orig/src/LogFactory.cc aria2-0.9.0/src/LogFactory.cc --- aria2-0.9.0.orig/src/LogFactory.cc 2006-09-21 08:31:24.000000000 -0700 +++ aria2-0.9.0/src/LogFactory.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,10 +32,17 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "LogFactory.h" #include "SimpleLogger.h" -string LogFactory::filename = "/dev/null"; +#ifdef HAVE_WINSOCK2_H +# define DEV_NULL "nul" +#else +# define DEV_NULL "/dev/null" +#endif // HAVE_WINSOCK2_H + +string LogFactory::filename = DEV_NULL; Logger* LogFactory::logger = NULL; Logger* LogFactory::getInstance() { diff -uwNr aria2-0.9.0.orig/src/Makefile.am aria2-0.9.0/src/Makefile.am --- aria2-0.9.0.orig/src/Makefile.am 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/src/Makefile.am 2006-11-19 11:39:16.000000000 -0800 @@ -55,7 +55,8 @@ UrlRequestInfo.cc UrlRequestInfo.h\ SpeedCalc.cc SpeedCalc.h\ PeerStat.h\ - BitfieldMan.cc BitfieldMan.h + BitfieldMan.cc BitfieldMan.h \ + Platform.cc Platform.h if ENABLE_ASYNC_DNS SRCS += NameResolver.cc NameResolver.h @@ -150,11 +151,23 @@ MetalinkRequestInfo.cc MetalinkRequestInfo.h endif # ENABLE_METALINK +if !HAVE_BASENAME +SRCS += libgen.c libgen.h +endif # !HAVE_BASENAME + +if !HAVE_GETADDRINFO +SRCS += getaddrinfo.c getaddrinfo.h +endif # !HAVE_GETADDRINFO + +if !HAVE_INET_ATON +SRCS += inet_aton.c inet_aton.h +endif # !HAVE_INET_ATON + noinst_LIBRARIES = libaria2c.a libaria2c_a_SOURCES = $(SRCS) aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\ @LIBGCRYPT_LIBS@ @OPENSSL_LIBS@ @XML_LIBS@ @LIBARES_LIBS@\ - @LIBCARES_LIBS@ + @LIBCARES_LIBS@ @WINSOCK_LIBS@ #aria2c_LDFLAGS = -pg AM_CPPFLAGS = -Wall\ -I../lib -I../intl -I$(top_srcdir)/intl\ diff -uwNr aria2-0.9.0.orig/src/MetaFileUtil.cc aria2-0.9.0/src/MetaFileUtil.cc --- aria2-0.9.0.orig/src/MetaFileUtil.cc 2006-09-21 08:31:24.000000000 -0700 +++ aria2-0.9.0/src/MetaFileUtil.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,6 +32,7 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "MetaFileUtil.h" #include "File.h" #include "DlAbortEx.h" @@ -39,15 +40,22 @@ #include #include +#ifdef HAVE_IO_H +# include +#endif // HAVE_IO_H + MetaEntry* MetaFileUtil::parseMetaFile(const string& file) { File f(file); int len = f.size(); char* buf = new char[len]; - FILE* fp = fopen(file.c_str(), "r+"); + FILE* fp = fopen(file.c_str(), "r+b"); try { if(fp == NULL) { throw new DlAbortEx("cannot open metainfo file"); } +#ifdef HAVE_SETMODE + setmode(fileno(fp), O_BINARY); +#endif if(fread(buf, len, 1, fp) != 1) { fclose(fp); throw new DlAbortEx("cannot read metainfo"); diff -uwNr aria2-0.9.0.orig/src/NameResolver.h aria2-0.9.0/src/NameResolver.h --- aria2-0.9.0.orig/src/NameResolver.h 2006-09-21 08:31:24.000000000 -0700 +++ aria2-0.9.0/src/NameResolver.h 2006-11-19 11:39:16.000000000 -0800 @@ -37,10 +37,19 @@ #include "common.h" #include "SharedHandle.h" + +#ifdef HAVE_NETDB_H #include +#endif // HAVE_NETDB_H +#ifdef HAVE_SYS_SOCKET_H #include +#endif // HAVE_SYS_SOCKET_H +#ifdef HAVE_NETINET_IN_H #include +#endif // HAVE_NETINET_IN_H +#ifdef HAVE_ARPA_INET_H #include +#endif // HAVE_ARPA_INET_H #ifdef __cplusplus extern "C" { diff -uwNr aria2-0.9.0.orig/src/PeerConnection.cc aria2-0.9.0/src/PeerConnection.cc --- aria2-0.9.0.orig/src/PeerConnection.cc 2006-09-21 08:31:24.000000000 -0700 +++ aria2-0.9.0/src/PeerConnection.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,13 +32,17 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "PeerConnection.h" #include "message.h" #include "DlAbortEx.h" #include "PeerMessageUtil.h" #include "Util.h" #include "LogFactory.h" + +#ifdef HAVE_NETINET_IN_H #include +#endif // HAVE_NETINET_IN_H PeerConnection::PeerConnection(int cuid, const SocketHandle& socket, diff -uwNr aria2-0.9.0.orig/src/PeerMessageUtil.cc aria2-0.9.0/src/PeerMessageUtil.cc --- aria2-0.9.0.orig/src/PeerMessageUtil.cc 2006-09-21 08:31:24.000000000 -0700 +++ aria2-0.9.0/src/PeerMessageUtil.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,10 +32,14 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "PeerMessageUtil.h" #include "DlAbortEx.h" #include "Util.h" + +#ifdef HAVE_NETINET_IN_H #include +#endif // HAVE_NETINET_IN_H int PeerMessageUtil::getId(const char* msg) { return (int)msg[0]; diff -uwNr aria2-0.9.0.orig/src/Platform.cc aria2-0.9.0/src/Platform.cc --- aria2-0.9.0.orig/src/Platform.cc 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.9.0/src/Platform.cc 2006-11-19 06:59:38.000000000 -0800 @@ -0,0 +1,63 @@ +/* */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif // HAVE_CONFIG_H + +#ifdef HAVE_WINSOCK2_H +# ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x501 +# endif // _WIN32_WINNT +# include +#endif // HAVE_WINSOCK2_H + +#include "Platform.h" +#include "DlAbortEx.h" + +Platform::Platform() { +#ifdef HAVE_WINSOCK2_H + WSADATA wsaData; + memset((char*)&wsaData, 0, sizeof(wsaData)); + if (WSAStartup(MAKEWORD(1, 1), &wsaData)) { + throw new DlAbortEx(_("Windows socket library initialization failed")); + } +#endif // HAVE_WINSOCK2_H +} + +Platform::~Platform() { +#ifdef HAVE_WINSOCK2_H + WSACleanup(); +#endif // HAVE_WINSOCK2_H +} diff -uwNr aria2-0.9.0.orig/src/Platform.h aria2-0.9.0/src/Platform.h --- aria2-0.9.0.orig/src/Platform.h 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.9.0/src/Platform.h 2006-11-19 06:59:38.000000000 -0800 @@ -0,0 +1,45 @@ +/* */ +#ifndef _D_PLATFORM_H_ +#define _D_PLATFORM_H_ + +class Platform { +public: + Platform(); + + ~Platform(); +}; + +#endif // _D_PLATFORM_H_ diff -uwNr aria2-0.9.0.orig/src/Request.cc aria2-0.9.0/src/Request.cc --- aria2-0.9.0.orig/src/Request.cc 2006-09-21 08:31:24.000000000 -0700 +++ aria2-0.9.0/src/Request.cc 2006-11-19 11:39:16.000000000 -0800 @@ -80,9 +80,6 @@ port = 0; dir = ""; file = ""; - if(tempUrl.find_first_not_of(SAFE_CHARS) != string::npos) { - return false; - } string::size_type startQueryIndex = tempUrl.find("?"); if(startQueryIndex != string::npos) { query = tempUrl.substr(startQueryIndex); @@ -124,5 +121,9 @@ file = tempUrl.substr(direp+1); } file += query; + if(tempUrl.find_first_not_of(SAFE_CHARS) != string::npos) { + // some torrents have invalid characters + return false; + } return true; } diff -uwNr aria2-0.9.0.orig/src/SegmentMan.cc aria2-0.9.0/src/SegmentMan.cc --- aria2-0.9.0.orig/src/SegmentMan.cc 2006-11-08 08:25:38.000000000 -0800 +++ aria2-0.9.0/src/SegmentMan.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,6 +32,7 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "SegmentMan.h" #include "DlAbortEx.h" #include "Util.h" @@ -44,6 +45,10 @@ #include #include +#ifdef HAVE_IO_H +# include +#endif // HAVE_IO_H + SegmentMan::SegmentMan():bitfield(0), totalSize(0), isSplittable(true), @@ -80,7 +85,7 @@ } string segFilename = getSegmentFilePath(); logger->info(MSG_LOADING_SEGMENT_FILE, segFilename.c_str()); - FILE* segFile = openSegFile(segFilename, "r+"); + FILE* segFile = openSegFile(segFilename, "r+b"); try { read(segFile); fclose(segFile); @@ -98,7 +103,7 @@ } string segFilename = getSegmentFilePath(); logger->info(MSG_SAVING_SEGMENT_FILE, segFilename.c_str()); - FILE* segFile = openSegFile(segFilename, "w"); + FILE* segFile = openSegFile(segFilename, "wb"); try { if(fwrite(&totalSize, sizeof(totalSize), 1, segFile) < 1) { throw string("writeError"); @@ -147,6 +152,9 @@ throw new DlAbortEx(EX_SEGMENT_FILE_OPEN, segFilename.c_str(), strerror(errno)); } +#ifdef HAVE_SETMODE + setmode(fileno(segFile), O_BINARY); +#endif return segFile; } diff -uwNr aria2-0.9.0.orig/src/SimpleLogger.cc aria2-0.9.0/src/SimpleLogger.cc --- aria2-0.9.0.orig/src/SimpleLogger.cc 2006-09-21 08:31:24.000000000 -0700 +++ aria2-0.9.0/src/SimpleLogger.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,6 +32,7 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "SimpleLogger.h" #include "Util.h" #include "DlAbortEx.h" @@ -41,6 +42,10 @@ #include #include +#ifdef HAVE_IO_H +# include +#endif // HAVE_IO_H + #define WRITE_LOG(LEVEL, MSG) \ va_list ap;\ va_start(ap, MSG);\ @@ -60,10 +65,13 @@ } void SimpleLogger::openFile(const string& filename) { - file = fopen(filename.c_str(), "a"); + file = fopen(filename.c_str(), "ab"); if(file == NULL) { throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno)); } +#ifdef HAVE_SETMODE + setmode(fileno(file), O_BINARY); +#endif } void SimpleLogger::closeFile() { @@ -106,7 +114,12 @@ } time_t now = time(NULL); char datestr[26]; +#ifdef HAVE_CTIME_R ctime_r(&now, datestr); +#else + char *p = ctime(&now); + strcpy(datestr, p); +#endif // HAVE_CTIME_R datestr[strlen(datestr)-1] = '\0'; writeHeader(file, datestr, levelStr); vfprintf(file, string(Util::replace(msg, "\r", "")+"\n").c_str(), ap); diff -uwNr aria2-0.9.0.orig/src/SocketCore.cc aria2-0.9.0/src/SocketCore.cc --- aria2-0.9.0.orig/src/SocketCore.cc 2006-09-21 08:31:24.000000000 -0700 +++ aria2-0.9.0/src/SocketCore.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,20 +32,37 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "SocketCore.h" #include "DlRetryEx.h" #include "DlAbortEx.h" #include "message.h" #include #include -#include #include +#include +#include + +#ifdef HAVE_NETDB_H +# include +#endif // HAVE_NETDB_H +#ifdef HAVE_SYS_SOCKET_H #include +#endif // HAVE_SYS_SOCKET_H +#ifdef HAVE_NETINET_IN_H #include +#endif // HAVE_NETINET_IN_H +#ifdef HAVE_ARPA_INET_H #include -#include -#include -#include +#endif // HAVE_ARPA_INET_H + +#ifndef HAVE_GETADDRINFO +# include "getaddrinfo.h" +#endif // HAVE_GETADDRINFO + +#ifndef HAVE_INET_ATON +# include "inet_aton.h" +#endif // HAVE_INET_ATON SocketCore::SocketCore():sockfd(-1) { init(); @@ -79,6 +96,31 @@ #endif // HAVE_LIBGNUTLS } +#ifdef __MINGW32__ + +static char *mingw_strerror(int err) { + err = WSAGetLastError(); + static char buf[2048]; + if (FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + err, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &buf, + sizeof(buf), + NULL + ) == 0) { + snprintf(buf, sizeof(buf), _("Unknown socket error %d"), err); + } + return buf; +} + +#define strerror mingw_strerror +#define gai_strerror mingw_strerror + +#endif // __MINGW32__ + void SocketCore::beginListen(int port) { closeConnection(); //sockfd = socket(AF_UNSPEC, SOCK_STREAM, PF_UNSPEC); @@ -86,7 +128,7 @@ if(sockfd == -1) { throw new DlAbortEx(EX_SOCKET_OPEN, strerror(errno)); } - socklen_t sockopt = 1; + SOCKOPT_T sockopt = 1; if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(socklen_t)) < 0) { close(sockfd); sockfd = -1; @@ -151,7 +193,7 @@ if(sockfd == -1) { throw new DlAbortEx(EX_SOCKET_OPEN, strerror(errno)); } - socklen_t sockopt = 1; + SOCKOPT_T sockopt = 1; if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(socklen_t)) < 0) { close(sockfd); sockfd = -1; @@ -188,15 +230,25 @@ } void SocketCore::setNonBlockingMode() const { +#ifdef __MINGW32__ + u_long flag = 0; + ::ioctlsocket(sockfd, FIONBIO, &flag); +#else int flags = fcntl(sockfd, F_GETFL, 0); // TODO add error handling fcntl(sockfd, F_SETFL, flags|O_NONBLOCK); +#endif } void SocketCore::setBlockingMode() const { +#ifdef __MINGW32__ + u_long flag = 1; + ::ioctlsocket(sockfd, FIONBIO, &flag); +#else int flags = fcntl(sockfd, F_GETFL, 0); // TODO add error handling fcntl(sockfd, F_SETFL, flags&(~O_NONBLOCK)); +#endif } void SocketCore::closeConnection() { diff -uwNr aria2-0.9.0.orig/src/TorrentRequestInfo.cc aria2-0.9.0/src/TorrentRequestInfo.cc --- aria2-0.9.0.orig/src/TorrentRequestInfo.cc 2006-11-08 08:25:38.000000000 -0800 +++ aria2-0.9.0/src/TorrentRequestInfo.cc 2006-11-19 11:39:16.000000000 -0800 @@ -66,8 +66,10 @@ op, targetFiles)); +#ifdef SA_RESETHAND setSignalHander(SIGINT, torrentHandler, SA_RESETHAND); setSignalHander(SIGTERM, torrentHandler, SA_RESETHAND); +#endif // SA_RESETHAND try { e->run(); diff -uwNr aria2-0.9.0.orig/src/Util.cc aria2-0.9.0/src/Util.cc --- aria2-0.9.0.orig/src/Util.cc 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/src/Util.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,6 +32,7 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "Util.h" #include "DlAbortEx.h" #include "File.h" @@ -41,11 +42,25 @@ #include #include #include -#include +#include + +#ifdef HAVE_SYS_SOCKET_H #include +#endif // HAVE_SYS_SOCKET_H +#ifdef HAVE_NETINET_IN_H #include +#endif // HAVE_NETINET_IN_H +#ifdef HAVE_ARPA_INET_H #include -#include +#endif // HAVE_ARPA_INET_H + +#ifdef HAVE_IO_H +# include +#endif // HAVE_IO_H + +#ifndef HAVE_INET_ATON +# include "inet_aton.h" +#endif // HAVE_INET_ATON string Util::itos(int value, bool comma) { string str = llitos(value, comma); @@ -261,6 +276,9 @@ FILE* Util::openFile(const string& filename, const string& mode) { FILE* file = fopen(filename.c_str(), mode.c_str()); +#ifdef HAVE_SETMODE + setmode(fileno(file), O_BINARY); +#endif return file; } @@ -275,10 +293,10 @@ int destFd = -1; int srcFd = -1; try { - if((destFd = open(dest.c_str(), O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR)) == -1) { + if((destFd = open(dest.c_str(), O_CREAT|O_WRONLY|O_TRUNC|O_BINARY, S_IRUSR|S_IWUSR)) == -1) { throw new DlAbortEx(EX_FILE_OPEN, dest.c_str(), strerror(errno)); } - if((srcFd = open(src.c_str(), O_RDONLY, S_IRUSR|S_IWUSR)) == -1) { + if((srcFd = open(src.c_str(), O_RDONLY|O_BINARY, S_IRUSR|S_IWUSR)) == -1) { throw new DlAbortEx(EX_FILE_OPEN, src.c_str(), strerror(errno)); } if(lseek(srcFd, srcOffset, SEEK_SET) != srcOffset) { @@ -441,7 +459,7 @@ char buf[BUFLEN]; int fd; - if((fd = open(filename.c_str(), O_RDWR, S_IRUSR|S_IWUSR)) < 0) { + if((fd = open(filename.c_str(), O_RDWR|O_BINARY, S_IRUSR|S_IWUSR)) < 0) { throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno)); } while(1) { @@ -551,16 +569,16 @@ } string Util::randomAlpha(int length) { + static char *random_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz{"; + string str; for(int i = 0; i < length; i++) { +#ifdef HAVE_RANDOM int index = (int)(((double)52)*random()/(RAND_MAX+1.0)); - char ch; - if(index < 26) { - ch = (char)('A'+index); - } else { - ch = (char)('a'+index-26); - } - str += ch; +#else + int index = (int)(((double)52)*rand()/(RAND_MAX+1.0)); +#endif + str += random_chars[index]; } return str; } @@ -599,3 +617,29 @@ return false; } } + +string Util::getTempDir() { + static string tempdir; + + if (tempdir.empty()) { + tempdir = getenv("TMP"); + if (File::isDir(tempdir)) { + return tempdir; + } + tempdir = getenv("TMPDIR"); + if (File::isDir(tempdir)) { + return tempdir; + } + tempdir = getenv("TEMP"); + if (File::isDir(tempdir)) { + return tempdir; + } + tempdir = "/tmp"; + if (File::isDir(tempdir)) { + return tempdir; + } + tempdir = "."; + } + + return tempdir; +} diff -uwNr aria2-0.9.0.orig/src/Util.h aria2-0.9.0/src/Util.h --- aria2-0.9.0.orig/src/Util.h 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/src/Util.h 2006-11-19 11:39:16.000000000 -0800 @@ -126,6 +126,8 @@ static string toLower(const string& src); static bool isNumbersAndDotsNotation(const string& name); + + static string getTempDir(); }; #endif // _D_UTIL_H_ diff -uwNr aria2-0.9.0.orig/src/common.h aria2-0.9.0/src/common.h --- aria2-0.9.0.orig/src/common.h 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/src/common.h 2006-11-19 11:39:16.000000000 -0800 @@ -36,7 +36,21 @@ #define _D_COMMON_H_ #ifdef HAVE_CONFIG_H # include -#endif +#endif // HAVE_CONFIG_H + +#ifdef __MINGW32__ +# ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x501 +# endif // _WIN32_WINNT +# include +# undef ERROR +# include +# define SOCKOPT_T const char +# define HAVE_GETADDRINFO +#else +# define SOCKOPT_T socklen_t +#endif // __MINGW32__ + #include #include #include @@ -50,6 +64,20 @@ # define _(String) (String) #endif +#ifndef EINPROGRESS +# define EINPROGRESS (WSAEINPROGRESS) +#endif // EINPROGRESS + +#include + +#ifndef O_NONBLOCK +# define O_NONBLOCK (O_NDELAY) +#endif // O_NONBLOCK + +#ifndef O_BINARY +# define O_BINARY (0) +#endif // O_BINARY + #ifndef LONG_LONG_MAX # define LONG_LONG_MAX 9223372036854775807LL # define LONG_LONG_MIN (-LONG_LONG_MAX - 1LL) diff -uwNr aria2-0.9.0.orig/src/getaddrinfo.c aria2-0.9.0/src/getaddrinfo.c --- aria2-0.9.0.orig/src/getaddrinfo.c 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.9.0/src/getaddrinfo.c 2006-11-19 11:39:16.000000000 -0800 @@ -0,0 +1,608 @@ +/* + * Copyright (c) 2001, 02 Motoyuki Kasahara + * + * 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. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``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 PROJECT OR CONTRIBUTORS 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. + */ + +/* + * This program provides getaddrinfo() and getnameinfo() described in + * RFC2133, 2553 and 3493. These functions are mainly used for IPv6 + * application to resolve hostname or address. + * + * This program is designed to be working on traditional IPv4 systems + * which don't have those functions. Therefore, this implementation + * supports IPv4 only. + * + * This program is useful for application which should support both IPv6 + * and traditional IPv4 systems. Use genuine getaddrinfo() and getnameinfo() + * provided by system if the system supports IPv6. Otherwise, use this + * implementation. + * + * This program is intended to be used in combination with GNU Autoconf. + * + * This program also provides freeaddrinfo() and gai_strerror(). + * + * To use this program in your application, insert the following lines to + * C source files after including `sys/types.h', `sys/socket.h' and + * `netdb.h'. `getaddrinfo.h' defines `struct addrinfo' and AI_, NI_, + * EAI_ macros. + * + * #ifndef HAVE_GETADDRINFO + * #include "getaddrinfo.h" + * #endif + * + * Restriction: + * getaddrinfo() and getnameinfo() of this program are NOT thread + * safe, unless the cpp macro ENABLE_PTHREAD is defined. + */ + +/* + * Add the following code to your configure.ac (or configure.in). + * AC_C_CONST + * AC_HEADER_STDC + * AC_CHECK_HEADERS(string.h memory.h stdlib.h) + * AC_CHECK_FUNCS(memcpy) + * AC_REPLACE_FUNCS(memset) + * AC_TYPE_SOCKLEN_T + * AC_TYPE_IN_PORT_T + * AC_DECL_H_ERRNO + * + * AC_CHECK_FUNCS(getaddrinfo getnameinfo) + * if test "$ac_cv_func_getaddrinfo$ac_cv_func_getnameinfo" != yesyes ; then + * LIBOBJS="$LIBOBJS getaddrinfo.$ac_objext" + * fi + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef __MINGW32__ +# include +# undef ERROR +# include +#endif + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif + +#include +#include + +#if defined(STDC_HEADERS) || defined(HAVE_STRING_H) +#include +#if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H) +#include +#endif /* not STDC_HEADERS and HAVE_MEMORY_H */ +#else /* not STDC_HEADERS and not HAVE_STRING_H */ +#include +#endif /* not STDC_HEADERS and not HAVE_STRING_H */ + +#ifdef HAVE_STDLIB_H +#include +#endif + +#ifdef ENABLE_PTHREAD +#include +#endif + +#ifdef ENABLE_NLS +#include +#endif + +#ifndef HAVE_MEMCPY +#define memcpy(d, s, n) bcopy((s), (d), (n)) +#ifdef __STDC__ +void *memchr(const void *, int, size_t); +int memcmp(const void *, const void *, size_t); +void *memmove(void *, const void *, size_t); +void *memset(void *, int, size_t); +#else /* not __STDC__ */ +char *memchr(); +int memcmp(); +char *memmove(); +char *memset(); +#endif /* not __STDC__ */ +#endif /* not HAVE_MEMCPY */ + +#ifndef H_ERRNO_DECLARED +extern int h_errno; +#endif + +#include "getaddrinfo.h" + +#ifdef ENABLE_NLS +#define _(string) gettext(string) +#ifdef gettext_noop +#define N_(string) gettext_noop(string) +#else +#define N_(string) (string) +#endif +#else +#define gettext(string) (string) +#define _(string) (string) +#define N_(string) (string) +#endif + +/* + * Error messages for gai_strerror(). + */ +static char *eai_errlist[] = { + N_("Success"), + + /* EAI_ADDRFAMILY */ + N_("Address family for hostname not supported"), + + /* EAI_AGAIN */ + N_("Temporary failure in name resolution"), + + /* EAI_BADFLAGS */ + N_("Invalid value for ai_flags"), + + /* EAI_FAIL */ + N_("Non-recoverable failure in name resolution"), + + /* EAI_FAMILY */ + N_("ai_family not supported"), + + /* EAI_MEMORY */ + N_("Memory allocation failure"), + + /* EAI_NONAME */ + N_("hostname nor servname provided, or not known"), + + /* EAI_OVERFLOW */ + N_("An argument buffer overflowed"), + + /* EAI_SERVICE */ + N_("servname not supported for ai_socktype"), + + /* EAI_SOCKTYPE */ + N_("ai_socktype not supported"), + + /* EAI_SYSTEM */ + N_("System error returned in errno") +}; + +/* + * Default hints for getaddrinfo(). + */ +static struct addrinfo default_hints = { + 0, PF_UNSPEC, 0, 0, 0, NULL, NULL, NULL +}; + +/* + * Mutex. + */ +#ifdef ENABLE_PTHREAD +static pthread_mutex_t gai_mutex = PTHREAD_MUTEX_INITIALIZER; +#endif + +/* + * Declaration of static functions. + */ +#ifdef __STDC__ +static int is_integer(const char *); +static int is_address(const char *); +static int itoa_length(int); +#else +static int is_integer(); +static int is_address(); +static int itoa_length(); +#endif + +/* + * gai_strerror(). + */ +const char * +gai_strerror(ecode) + int ecode; +{ + if (ecode < 0 || ecode > EAI_SYSTEM) + return _("Unknown error"); + + return gettext(eai_errlist[ecode]); +} + +/* + * freeaddrinfo(). + */ +void +freeaddrinfo(ai) + struct addrinfo *ai; +{ + struct addrinfo *next_ai; + + while (ai != NULL) { + if (ai->ai_canonname != NULL) + free(ai->ai_canonname); + if (ai->ai_addr != NULL) + free(ai->ai_addr); + next_ai = ai->ai_next; + free(ai); + ai = next_ai; + } +} + +/* + * Return 1 if the string `s' represents an integer. + */ +static int +is_integer(s) + const char *s; +{ + if (*s == '-' || *s == '+') + s++; + if (*s < '0' || '9' < *s) + return 0; + + s++; + while ('0' <= *s && *s <= '9') + s++; + + return (*s == '\0'); +} + +/* + * Return 1 if the string `s' represents an IPv4 address. + * Unlike inet_addr(), it doesn't permit malformed nortation such + * as "192.168". + */ +static int +is_address(s) + const char *s; +{ + const static char delimiters[] = {'.', '.', '.', '\0'}; + int i, j; + int octet; + + for (i = 0; i < 4; i++) { + if (*s == '0' && *(s + 1) != delimiters[i]) + return 0; + for (j = 0, octet = 0; '0' <= *s && *s <= '9' && j < 3; s++, j++) + octet = octet * 10 + (*s - '0'); + if (j == 0 || octet > 255 || *s != delimiters[i]) + return 0; + s++; + } + + return 1; +} + +/* + * Calcurate length of the string `s', where `s' is set by + * sprintf(s, "%d", n). + */ +static int +itoa_length(n) + int n; +{ + int result = 1; + + if (n < 0) { + n = -n; + result++; + } + + while (n >= 10) { + result++; + n /= 10; + } + + return result; +} + +/* + * getaddrinfo(). + */ +int +getaddrinfo(nodename, servname, hints, res) + const char *nodename; + const char *servname; + const struct addrinfo *hints; + struct addrinfo **res; +{ + struct addrinfo *head_res = NULL; + struct addrinfo *tail_res = NULL; + struct addrinfo *new_res; + struct sockaddr_in *sa_in; + struct in_addr **addr_list; + struct in_addr *addr_list_buf[2]; + struct in_addr addr_buf; + struct in_addr **ap; + struct servent *servent; + struct hostent *hostent; + const char *canonname = NULL; + in_port_t port; + int saved_h_errno; + int result = 0; + +#ifdef ENABLE_PTHREAD + pthread_mutex_lock(&gai_mutex); +#endif + + saved_h_errno = h_errno; + + if (nodename == NULL && servname == NULL) { + result = EAI_NONAME; + goto end; + } + + if (hints != NULL) { + if (hints->ai_family != PF_INET && hints->ai_family != PF_UNSPEC) { + result = EAI_FAMILY; + goto end; + } + if (hints->ai_socktype != SOCK_DGRAM + && hints->ai_socktype != SOCK_STREAM + && hints->ai_socktype != 0) { + result = EAI_SOCKTYPE; + goto end; + } + } else { + hints = &default_hints; + } + + if (servname != NULL) { + if (is_integer(servname)) + port = htons(atoi(servname)); + else { + if (hints->ai_flags & AI_NUMERICSERV) { + result = EAI_NONAME; + goto end; + } + + if (hints->ai_socktype == SOCK_DGRAM) + servent = getservbyname(servname, "udp"); + else if (hints->ai_socktype == SOCK_STREAM) + servent = getservbyname(servname, "tcp"); + else if (hints->ai_socktype == 0) + servent = getservbyname(servname, "tcp"); + else { + result = EAI_SOCKTYPE; + goto end; + } + + if (servent == NULL) { + result = EAI_SERVICE; + goto end; + } + port = servent->s_port; + } + } else { + port = htons(0); + } + + if (nodename != NULL) { + if (is_address(nodename)) { + addr_buf.s_addr = inet_addr(nodename); + addr_list_buf[0] = &addr_buf; + addr_list_buf[1] = NULL; + addr_list = addr_list_buf; + + if (hints->ai_flags & AI_CANONNAME + && !(hints->ai_flags & AI_NUMERICHOST)) { + hostent = gethostbyaddr((char *)&addr_buf, + sizeof(struct in_addr), AF_INET); + if (hostent != NULL) + canonname = hostent->h_name; + else + canonname = nodename; + } + } else { + if (hints->ai_flags & AI_NUMERICHOST) { + result = EAI_NONAME; + goto end; + } + + hostent = gethostbyname(nodename); + if (hostent == NULL) { + switch (h_errno) { + case HOST_NOT_FOUND: + case NO_DATA: + result = EAI_NONAME; + goto end; + case TRY_AGAIN: + result = EAI_AGAIN; + goto end; + default: + result = EAI_FAIL; + goto end; + } + } + addr_list = (struct in_addr **)hostent->h_addr_list; + + if (hints->ai_flags & AI_CANONNAME) + canonname = hostent->h_name; + } + } else { + if (hints->ai_flags & AI_PASSIVE) + addr_buf.s_addr = htonl(INADDR_ANY); + else + addr_buf.s_addr = htonl(0x7F000001); + addr_list_buf[0] = &addr_buf; + addr_list_buf[1] = NULL; + addr_list = addr_list_buf; + } + + for (ap = addr_list; *ap != NULL; ap++) { + new_res = (struct addrinfo *)malloc(sizeof(struct addrinfo)); + if (new_res == NULL) { + if (head_res != NULL) + freeaddrinfo(head_res); + result = EAI_MEMORY; + goto end; + } + + new_res->ai_family = PF_INET; + new_res->ai_socktype = hints->ai_socktype; + new_res->ai_protocol = hints->ai_protocol; + new_res->ai_addr = NULL; + new_res->ai_addrlen = sizeof(struct sockaddr_in); + new_res->ai_canonname = NULL; + new_res->ai_next = NULL; + + new_res->ai_addr = (struct sockaddr *) + malloc(sizeof(struct sockaddr_in)); + if (new_res->ai_addr == NULL) { + free(new_res); + if (head_res != NULL) + freeaddrinfo(head_res); + result = EAI_MEMORY; + goto end; + } + + sa_in = (struct sockaddr_in *)new_res->ai_addr; + memset(sa_in, 0, sizeof(struct sockaddr_in)); + sa_in->sin_family = PF_INET; + sa_in->sin_port = port; + memcpy(&sa_in->sin_addr, *ap, sizeof(struct in_addr)); + + if (head_res == NULL) + head_res = new_res; + else + tail_res->ai_next = new_res; + tail_res = new_res; + } + + if (canonname != NULL && head_res != NULL) { + head_res->ai_canonname = (char *)malloc(strlen(canonname) + 1); + if (head_res->ai_canonname != NULL) + strcpy(head_res->ai_canonname, canonname); + } + + *res = head_res; + + end: + h_errno = saved_h_errno; +#ifdef ENABLE_PTHREAD + pthread_mutex_unlock(&gai_mutex); +#endif + return result; +} + +/* + * getnameinfo(). + */ +int +getnameinfo(sa, salen, node, nodelen, serv, servlen, flags) + const struct sockaddr *sa; + socklen_t salen; + char *node; + socklen_t nodelen; + char *serv; + socklen_t servlen; + int flags; +{ + const struct sockaddr_in *sa_in = (const struct sockaddr_in *)sa; + struct hostent *hostent; + struct servent *servent; + char *ntoa_address; + int saved_h_errno; + int result = 0; + +#ifdef ENABLE_PTHREAD + pthread_mutex_lock(&gai_mutex); +#endif + + saved_h_errno = h_errno; + + if (sa_in->sin_family != PF_INET) { + result = EAI_FAMILY; + goto end; + } else if (node == NULL && serv == NULL) { + result = EAI_NONAME; + goto end; + } + + if (serv != NULL && servlen > 0) { + if (flags & NI_NUMERICSERV) + servent = NULL; + else if (flags & NI_DGRAM) + servent = getservbyport(sa_in->sin_port, "udp"); + else + servent = getservbyport(sa_in->sin_port, "tcp"); + + if (servent != NULL) { + if (servlen <= strlen(servent->s_name)) { + result = EAI_OVERFLOW; + goto end; + } + strcpy(serv, servent->s_name); + } else { + if (servlen <= itoa_length(ntohs(sa_in->sin_port))) { + result = EAI_OVERFLOW; + goto end; + } + sprintf(serv, "%d", ntohs(sa_in->sin_port)); + } + } + + if (node != NULL && nodelen > 0) { + if (flags & NI_NUMERICHOST) + hostent = NULL; + else { + hostent = gethostbyaddr((char *)&sa_in->sin_addr, + sizeof(struct in_addr), AF_INET); + } + if (hostent != NULL) { + if (nodelen <= strlen(hostent->h_name)) { + result = EAI_OVERFLOW; + goto end; + } + strcpy(node, hostent->h_name); + } else { + if (flags & NI_NAMEREQD) { + result = EAI_NONAME; + goto end; + } + ntoa_address = inet_ntoa(sa_in->sin_addr); + if (nodelen <= strlen(ntoa_address)) { + result = EAI_OVERFLOW; + goto end; + } + strcpy(node, ntoa_address); + } + + } + + end: + h_errno = saved_h_errno; +#ifdef ENABLE_PTHREAD + pthread_mutex_unlock(&gai_mutex); +#endif + return result; +} + diff -uwNr aria2-0.9.0.orig/src/getaddrinfo.h aria2-0.9.0/src/getaddrinfo.h --- aria2-0.9.0.orig/src/getaddrinfo.h 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.9.0/src/getaddrinfo.h 2006-11-19 11:39:16.000000000 -0800 @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2001, 02 Motoyuki Kasahara + * + * 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. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``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 PROJECT OR CONTRIBUTORS 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 _D_GETADDRINFO_H +#define _D_GETADDRINFO_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif // HAVE_CONFIG_H + +#ifdef __MINGW32__ +# ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x501 +# endif // _WIN32_WINNT +# include +# undef ERROR +# include +#endif // __MINGW32__ + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif // HAVE_SYS_SOCKET_H +#ifdef HAVE_NETDB_H +# include +#endif // HAVE_NETDB_H + +#include + +/********************************************************************/ +/* + * Undefine all the macros. + * might defines some of them. + */ +#ifdef EAI_ADDRFAMILY +#undef EAI_ADDRFAMILY +#endif +#ifdef EAI_AGAIN +#undef EAI_AGAIN +#endif +#ifdef EAI_BADFLAGS +#undef EAI_BADFLAGS +#endif +#ifdef EAI_FAIL +#undef EAI_FAIL +#endif +#ifdef EAI_FAMILY +#undef EAI_FAMILY +#endif +#ifdef EAI_MEMORY +#undef EAI_MEMORY +#endif +#ifdef EAI_NONAME +#undef EAI_NONAME +#endif +#ifdef EAI_OVERFLOW +#undef EAI_OVERFLOW +#endif +#ifdef EAI_SERVICE +#undef EAI_SERVICE +#endif +#ifdef EAI_SOCKTYPE +#undef EAI_SOCKTYPE +#endif +#ifdef EAI_SYSTEM +#undef EAI_SYSTEM +#endif + +#ifdef AI_PASSIVE +#undef AI_PASSIVE +#endif +#ifdef AI_CANONNAME +#undef AI_CANONNAME +#endif +#ifdef AI_NUMERICHOST +#undef AI_NUMERICHOST +#endif +#ifdef AI_NUMERICSERV +#undef AI_NUMERICSERV +#endif +#ifdef AI_V4MAPPED +#undef AI_V4MAPPED +#endif +#ifdef AI_ALL +#undef AI_ALL +#endif +#ifdef AI_ADDRCONFIG +#undef AI_ADDRCONFIG +#endif +#ifdef AI_DEFAULT +#undef AI_DEFAULT +#endif + +#ifdef NI_NOFQDN +#undef NI_NOFQDN +#endif +#ifdef NI_NUMERICHOST +#undef NI_NUMERICHOST +#endif +#ifdef NI_NAMEREQD +#undef NI_NAMEREQD +#endif +#ifdef NI_NUMERICSERV +#undef NI_NUMERICSERV +#endif +#ifdef NI_NUMERICSCOPE +#undef NI_NUMERICSCOPE +#endif + +#ifdef NI_DGRAM +#undef NI_DGRAM +#endif +#ifdef NI_MAXHOST +#undef NI_MAXHOST +#endif +#ifdef NI_MAXSERV +#undef NI_MAXSERV +#endif + +/* + * Fake struct and function names. + * might declares all or some of them. + */ +#if defined(HAVE_GETADDRINFO) || defined(HAVE_GETNAMEINFO) +#define addrinfo my_addrinfo +#define gai_strerror my_gai_strerror +#define freeaddrinfo my_freeaddrinfo +#define getaddrinfo my_getaddrinfo +#define getnameinfo my_getnameinfo +#endif + +/********************************************************************/ +/* + * Error codes. + */ +#define EAI_ADDRFAMILY 1 +#define EAI_AGAIN 2 +#define EAI_BADFLAGS 3 +#define EAI_FAIL 4 +#define EAI_FAMILY 5 +#define EAI_MEMORY 6 +#define EAI_NONAME 7 +#define EAI_OVERFLOW 8 +#define EAI_SERVICE 9 +#define EAI_SOCKTYPE 10 +#define EAI_SYSTEM 11 + +/* + * Flags for getaddrinfo(). + */ +#define AI_ADDRCONFIG 0x0001 +#define AI_ALL 0x0002 +#define AI_CANONNAME 0x0004 +#define AI_NUMERICHOST 0x0008 +#define AI_NUMERICSERV 0x0010 +#define AI_PASSIVE 0x0020 +#define AI_V4MAPPED 0x0040 +#define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG) + +/* + * Flags for getnameinfo(). + */ +#define NI_DGRAM 0x0001 +#define NI_NAMEREQD 0x0002 +#define NI_NOFQDN 0x0004 +#define NI_NUMERICHOST 0x0008 +#define NI_NUMERICSCOPE 0x0010 +#define NI_NUMERICSERV 0x0020 + +/* + * Maximum length of FQDN and servie name for getnameinfo(). + */ +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 + +/* + * Address families and Protocol families. + */ +#ifndef AF_UNSPEC +#define AF_UNSPEC AF_INET +#endif +#ifndef PF_UNSPEC +#define PF_UNSPEC PF_INET +#endif + +/* + * struct addrinfo. + */ +struct addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + socklen_t ai_addrlen; + char *ai_canonname; + struct sockaddr *ai_addr; + struct addrinfo *ai_next; +}; + +/* + * Functions. + */ +#ifdef __STDC__ +const char *gai_strerror(int); +void freeaddrinfo(struct addrinfo *); +int getaddrinfo(const char *, const char *, const struct addrinfo *, + struct addrinfo **); +int getnameinfo(const struct sockaddr *, socklen_t, char *, + socklen_t, char *, socklen_t, int); +#else +const char *gai_strerror(); +void freeaddrinfo(); +int getaddrinfo(); +int getnameinfo(); +#endif + +#ifdef __cplusplus +}; +#endif /* __cplusplus */ + +#endif /* not _D_GETADDRINFO_H */ diff -uwNr aria2-0.9.0.orig/src/inet_aton.c aria2-0.9.0/src/inet_aton.c --- aria2-0.9.0.orig/src/inet_aton.c 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.9.0/src/inet_aton.c 2006-11-19 11:39:16.000000000 -0800 @@ -0,0 +1,69 @@ +/* */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif // HAVE_CONFIG_H + +#ifdef __MINGW32__ +# define _WIN32_WINNT 0x501 +# include +# undef ERROR +# include +#endif // __MINGW32__ + +#ifdef HAVE_NETDB_H +# include +#endif // HAVE_NETDB_H +#ifdef HAVE_SYS_SOCKET_H +# include +#endif // HAVE_SYS_SOCKET_H +#ifdef HAVE_NETINET_IN_H +# include +#endif // HAVE_NETINET_IN_H +#ifdef HAVE_ARPA_INET_H +# include +#endif // HAVE_ARPA_INET_H + +#include + +int inet_aton(const char *cp, struct in_addr *inp) { + unsigned long res = inet_addr(cp); + if (res == INADDR_NONE && strcmp(cp, "255.255.255.255")) + return 0; + if (inp) + inp->s_addr = res; + return 1; +} diff -uwNr aria2-0.9.0.orig/src/inet_aton.h aria2-0.9.0/src/inet_aton.h --- aria2-0.9.0.orig/src/inet_aton.h 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.9.0/src/inet_aton.h 2006-11-19 11:39:16.000000000 -0800 @@ -0,0 +1,75 @@ +/* */ + +#ifndef _D_INET_ATON_H +#define _D_INET_ATON_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif // HAVE_CONFIG_H + +#ifdef __MINGW32__ +# ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x501 +# endif // _WIN32_WINNT +# include +# undef ERROR +# include +#endif // __MINGW32__ + +#ifdef HAVE_NETDB_H +# include +#endif // HAVE_NETDB_H +#ifdef HAVE_SYS_SOCKET_H +# include +#endif // HAVE_SYS_SOCKET_H +#ifdef HAVE_NETINET_IN_H +# include +#endif // HAVE_NETINET_IN_H +#ifdef HAVE_ARPA_INET_H +# include +#endif // HAVE_ARPA_INET_H + +int inet_aton(const char *cp, struct in_addr *inp); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* not _D_INET_ATON_H */ diff -uwNr aria2-0.9.0.orig/src/libgen.c aria2-0.9.0/src/libgen.c --- aria2-0.9.0.orig/src/libgen.c 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.9.0/src/libgen.c 2006-11-19 11:39:16.000000000 -0800 @@ -0,0 +1,89 @@ +/* */ + +#include +#include +#include + +#if defined(__CYGWIN__) || defined(__DJGPP__) || defined(__MINGW32__) +# define IS_PATH_SEPARATOR(c) (((c) == '/') || ((c) == '\\')) +#else +# define IS_PATH_SEPARATOR(c) ((c) == '/') +#endif + +/* per http://www.scit.wlv.ac.uk/cgi-bin/mansec?3C+basename */ +char* basename(char* s) { + char* rv; + + if (!s || !*s) + return "."; + + rv = s + strlen(s) - 1; + + do { + if (IS_PATH_SEPARATOR(*rv)) + return rv + 1; + --rv; + } while (rv >= s); + + return s; +} + +/* per http://www.scit.wlv.ac.uk/cgi-bin/mansec?3C+dirname */ +char* dirname(char* path) { + char *p; + + if (path == NULL || *path == '\0') + return "."; + p = path + strlen(path) - 1; + while (IS_PATH_SEPARATOR(*p)) { + if (p == path) + return path; + *p-- = '\0'; + } + + while (p >= path && !IS_PATH_SEPARATOR(*p)) + p--; + + if (p < path) + return "."; + + if (p == path) + return "/"; + + *p = '\0'; + + return path; +} diff -uwNr aria2-0.9.0.orig/src/main.cc aria2-0.9.0/src/main.cc --- aria2-0.9.0.orig/src/main.cc 2006-11-08 08:25:38.000000000 -0800 +++ aria2-0.9.0/src/main.cc 2006-11-19 07:01:18.000000000 -0800 @@ -32,11 +32,11 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "HttpInitiateConnectionCommand.h" #include "ConsoleDownloadEngine.h" #include "SegmentMan.h" #include "LogFactory.h" -#include "common.h" #include "DefaultDiskWriter.h" #include "Util.h" #include "InitiateConnectionCommandFactory.h" @@ -45,13 +45,15 @@ #include "DownloadEngineFactory.h" #include "UrlRequestInfo.h" #include "TorrentRequestInfo.h" +#include "Platform.h" #include #include #include #include +#include #include #include -#include + extern char* optarg; extern int optind, opterr, optopt; #include @@ -70,16 +72,28 @@ # include #endif // HAVE_LIBGNUTLS +#ifdef HAVE_WINSOCK2_H +# define DEV_STDOUT "con" +# define DEV_NULL "nul" +#else +# define DEV_STDOUT "/dev/stdout" +# define DEV_NULL "/dev/null" +#endif // HAVE_WINSOCK2_H + using namespace std; bool timeoutSpecified; -void setSignalHander(int signal, void (*handler)(int), int flags) { +void setSignalHander(int sig, void (*handler)(int), int flags) { +#ifdef HAVE_SIGACTION struct sigaction sigact; sigact.sa_handler = handler; sigact.sa_flags = flags; sigemptyset(&sigact.sa_mask); - sigaction(signal, &sigact, NULL); + sigaction(sig, &sigact, NULL); +#else + signal(sig, handler); +#endif // HAVE_SIGACTION } void showVersion() { @@ -123,7 +137,9 @@ cout << _(" -o, --out=FILE The file name for downloaded file.") << endl; cout << _(" -l, --log=LOG The file path to store log. If '-' is specified,\n" " log is written to stdout.") << endl; +#ifdef HAVE_DAEMON cout << _(" -D, --daemon Run as daemon.") << endl; +#endif // HAVE_DAEMON cout << _(" -s, --split=N Download a file using N connections. N must be\n" " between 1 and 5. This option affects all URLs.\n" " Thus, aria2 connects to each URL with\n" @@ -282,6 +298,8 @@ } int main(int argc, char* argv[]) { + Platform platform; + #ifdef ENABLE_NLS setlocale (LC_CTYPE, ""); setlocale (LC_MESSAGES, ""); @@ -295,7 +313,9 @@ op->put(PREF_STDOUT_LOG, V_FALSE); op->put(PREF_DIR, "."); op->put(PREF_SPLIT, "1"); +#ifdef HAVE_DAEMON op->put(PREF_DAEMON, V_FALSE); +#endif // HAVE_DAEMON op->put(PREF_SEGMENT_SIZE, Util::itos(1024*1024)); op->put(PREF_HTTP_KEEP_ALIVE, V_FALSE); op->put(PREF_LISTEN_PORT, "-1"); @@ -337,7 +357,9 @@ int optIndex = 0; int lopt; static struct option longOpts[] = { +#ifdef HAVE_DAEMON { "daemon", no_argument, NULL, 'D' }, +#endif // HAVE_DAEMON { "dir", required_argument, NULL, 'd' }, { "out", required_argument, NULL, 'o' }, { "log", required_argument, NULL, 'l' }, @@ -614,9 +636,11 @@ } break; } +#ifdef HAVE_DAEMON case 'D': op->put(PREF_DAEMON, V_TRUE); break; +#endif // HAVE_DAEMON case 'd': op->put(PREF_DIR, optarg); break; @@ -702,12 +726,14 @@ exit(EXIT_FAILURE); } } +#ifdef HAVE_DAEMON if(op->getAsBool(PREF_DAEMON)) { if(daemon(1, 1) < 0) { perror(_("daemon failed")); exit(EXIT_FAILURE); } } +#endif // HAVE_DAEMON Strings args(argv+optind, argv+argc); #ifdef HAVE_LIBSSL @@ -721,21 +747,28 @@ #ifdef ENABLE_METALINK xmlInitParser(); #endif // ENABLE_METALINK +#ifdef HAVE_SRANDOM srandom(time(NULL)); +#else + srand(time(NULL)); +#endif // HAVE_SRANDOM if(op->getAsBool(PREF_STDOUT_LOG)) { - LogFactory::setLogFile("/dev/stdout"); + LogFactory::setLogFile(DEV_STDOUT); } else if(op->get(PREF_LOG).size()) { LogFactory::setLogFile(op->get(PREF_LOG)); } else { - LogFactory::setLogFile("/dev/null"); + LogFactory::setLogFile(DEV_NULL); } int exitStatus = EXIT_SUCCESS; + try { Logger* logger = LogFactory::getInstance(); logger->info("%s %s", PACKAGE, PACKAGE_VERSION); logger->info("Logging started."); +#ifdef SIGPIPE setSignalHander(SIGPIPE, SIG_IGN, 0); +#endif // SIGPIPE RequestInfo* firstReqInfo = 0; #ifdef ENABLE_BITTORRENT diff -uwNr aria2-0.9.0.orig/test/BitfieldManTest.cc aria2-0.9.0/test/BitfieldManTest.cc --- aria2-0.9.0.orig/test/BitfieldManTest.cc 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/test/BitfieldManTest.cc 2006-11-19 11:39:16.000000000 -0800 @@ -83,7 +83,11 @@ void BitfieldManTest::testFilter() { // set random seed here in order to get same random numbers. +#ifdef HAVE_SRANDOM srandom(100); +#else + srand(100); +#endif // HAVE_SRANDOM BitfieldMan btman(2, 32); // test offset=4, length=12 @@ -143,7 +147,11 @@ } void BitfieldManTest::testGetMissingIndex() { +#ifdef HAVE_SRANDOM srandom(100); +#else + srand(100); +#endif // HAVE_SRANDOM BitfieldMan bt1(1024, 1024*256); diff -uwNr aria2-0.9.0.orig/test/FileTest.cc aria2-0.9.0/test/FileTest.cc --- aria2-0.9.0.orig/test/FileTest.cc 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/test/FileTest.cc 2006-11-19 11:39:16.000000000 -0800 @@ -83,7 +83,11 @@ CPPUNIT_ASSERT(!f.remove()); string dir = "/tmp/aria2testdir"; +#ifdef __MINGW32__ + mkdir(dir.c_str()); +#else mkdir(dir.c_str(), 0777); +#endif // __MINGW32__ File d(dir); CPPUNIT_ASSERT(d.exists()); CPPUNIT_ASSERT(d.remove()); diff -uwNr aria2-0.9.0.orig/test/Makefile.am aria2-0.9.0/test/Makefile.am --- aria2-0.9.0.orig/test/Makefile.am 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/test/Makefile.am 2006-11-19 11:39:16.000000000 -0800 @@ -53,7 +53,7 @@ aria2c_LDADD = ../src/libaria2c.a\ ${CPPUNIT_LIBS} @LIBGNUTLS_LIBS@\ @LIBGCRYPT_LIBS@ @OPENSSL_LIBS@ @XML_LIBS@\ - @LIBARES_LIBS@ @LIBCARES_LIBS@ + @LIBARES_LIBS@ @LIBCARES_LIBS@ @LIBINTL@ AM_CPPFLAGS = -Wall\ ${CPPUNIT_CFLAGS}\ -I ../src\ diff -uwNr aria2-0.9.0.orig/test/MultiDiskWriterTest.cc aria2-0.9.0/test/MultiDiskWriterTest.cc --- aria2-0.9.0.orig/test/MultiDiskWriterTest.cc 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/test/MultiDiskWriterTest.cc 2006-11-19 11:39:16.000000000 -0800 @@ -1,7 +1,12 @@ +#include "common.h" #include "MultiDiskWriter.h" #include #include +#ifdef HAVE_IO_H +# include +#endif // HAVE_IO_H + using namespace std; class MultiDiskWriterTest:public CppUnit::TestFixture { diff -uwNr aria2-0.9.0.orig/test/PeerMessageUtilTest.cc aria2-0.9.0/test/PeerMessageUtilTest.cc --- aria2-0.9.0.orig/test/PeerMessageUtilTest.cc 2006-07-30 05:58:28.000000000 -0700 +++ aria2-0.9.0/test/PeerMessageUtilTest.cc 2006-11-19 11:39:16.000000000 -0800 @@ -1,3 +1,4 @@ +#include "common.h" #include "PeerMessageUtil.h" #include "UnchokeMessage.h" #include "InterestedMessage.h" @@ -7,10 +8,13 @@ #include "RequestMessage.h" #include "PieceMessage.h" #include "CancelMessage.h" -#include #include #include +#ifdef HAVE_NETINET_IN_H +# include +#endif // HAVE_NETINET_IN_H + using namespace std; class PeerMessageUtilTest:public CppUnit::TestFixture { diff -uwNr aria2-0.9.0.orig/test/TimeSeedCriteriaTest.cc aria2-0.9.0/test/TimeSeedCriteriaTest.cc --- aria2-0.9.0.orig/test/TimeSeedCriteriaTest.cc 2006-08-27 05:49:18.000000000 -0700 +++ aria2-0.9.0/test/TimeSeedCriteriaTest.cc 2006-11-19 11:39:16.000000000 -0800 @@ -1,6 +1,7 @@ #include "TimeSeedCriteria.h" #include +#include class TimeSeedCriteriaTest:public CppUnit::TestFixture { @@ -17,7 +18,11 @@ void TimeSeedCriteriaTest::testEvaluate() { TimeSeedCriteria cri(1); +#ifdef HAVE_SLEEP sleep(1); +#else + _sleep(1); +#endif CPPUNIT_ASSERT(cri.evaluate()); cri.reset(); cri.setDuration(10); diff -uwNr aria2-0.9.0.orig/src/CompactTrackerResponseProcessor.cc aria2-0.9.0/src/CompactTrackerResponseProcessor.cc --- aria2-0.9.0.orig/src/CompactTrackerResponseProcessor.cc 2006-09-21 08:31:24.000000000 -0700 +++ aria2-0.9.0/src/CompactTrackerResponseProcessor.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,6 +32,7 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "CompactTrackerResponseProcessor.h" #include "LogFactory.h" #include "TorrentDownloadEngine.h" @@ -39,7 +40,10 @@ #include "DlAbortEx.h" #include "message.h" #include "PeerInitiateConnectionCommand.h" + +#ifdef HAVE_NETINET_IN_H #include +#endif // HAVE_NETINET_IN_H CompactTrackerResponseProcessor::CompactTrackerResponseProcessor(ByteArrayDiskWriter* diskWriter, TorrentDownloadEngine* e, Request* req): diskWriter(diskWriter), diff -uwNr aria2-0.9.0.orig/src/PeerInteraction.cc aria2-0.9.0/src/PeerInteraction.cc --- aria2-0.9.0.orig/src/PeerInteraction.cc 2006-11-05 07:04:18.000000000 -0800 +++ aria2-0.9.0/src/PeerInteraction.cc 2006-11-19 11:39:16.000000000 -0800 @@ -32,6 +32,7 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "PeerInteraction.h" #include "LogFactory.h" #include "DlAbortEx.h" @@ -40,7 +41,10 @@ #include "Util.h" #include "prefs.h" #include "BtRegistry.h" + +#ifdef HAVE_NETINET_IN_H #include +#endif // HAVE_NETINET_IN_H PeerInteraction::PeerInteraction(int cuid, const PeerHandle& peer,