diff -uwrN aria2-0.10.2+1.orig/configure.ac aria2-0.10.2+1/configure.ac --- aria2-0.10.2+1.orig/configure.ac Thu Mar 29 04:57:13 2007 +++ aria2-0.10.2+1/configure.ac Mon Apr 16 11:35:16 2007 @@ -3,11 +3,22 @@ # AC_PREREQ(2.59) AC_INIT(aria2c, 0.10.2+1, t-tujikawa@users.sourceforge.net) + +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 -uwrN aria2-0.10.2+1.orig/lib/libgen.h aria2-0.10.2+1/lib/libgen.h --- aria2-0.10.2+1.orig/lib/libgen.h Wed Dec 31 16:00:00 1969 +++ aria2-0.10.2+1/lib/libgen.h Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/reconf aria2-0.10.2+1/reconf --- aria2-0.10.2+1.orig/reconf Wed Dec 31 16:00:00 1969 +++ aria2-0.10.2+1/reconf Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/AbstractDiskWriter.cc aria2-0.10.2+1/src/AbstractDiskWriter.cc --- aria2-0.10.2+1.orig/src/AbstractDiskWriter.cc Sat Mar 24 07:32:49 2007 +++ aria2-0.10.2+1/src/AbstractDiskWriter.cc Mon Apr 16 11:35:16 2007 @@ -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" @@ -79,7 +80,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)); } if(f.size() < totalLength) { @@ -99,7 +100,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 -uwrN aria2-0.10.2+1.orig/src/BitfieldMan.cc aria2-0.10.2+1/src/BitfieldMan.cc --- aria2-0.10.2+1.orig/src/BitfieldMan.cc Sat Mar 24 07:32:49 2007 +++ aria2-0.10.2+1/src/BitfieldMan.cc Mon Apr 16 11:35:16 2007 @@ -32,6 +32,7 @@ * files in the program, then also delete it here. */ /* copyright --> */ +#include "common.h" #include "BitfieldMan.h" #include "Util.h" #include diff -uwrN aria2-0.10.2+1.orig/src/BtPieceMessage.cc aria2-0.10.2+1/src/BtPieceMessage.cc --- aria2-0.10.2+1.orig/src/BtPieceMessage.cc Thu Jan 25 08:47:29 2007 +++ aria2-0.10.2+1/src/BtPieceMessage.cc Mon Apr 16 11:35:16 2007 @@ -73,7 +73,7 @@ PieceHandle piece = pieceStorage->getPiece(index); int64_t offset = ((int64_t)index)*btContext->getPieceLength()+begin; - logger->debug("CUID#%d - Piece received. index=%d, begin=%d, length=%d, offset=%llu, blockIndex=%d", + logger->debug("CUID#%d - Piece received. index=%d, begin=%d, length=%d, offset=" ULONGLONG_PRINTF ", blockIndex=%d", cuid, index, begin, blockLength, offset, slot.getBlockIndex()); pieceStorage->getDiskAdaptor()->writeData(block, blockLength, diff -uwrN aria2-0.10.2+1.orig/src/ByteArrayDiskWriter.cc aria2-0.10.2+1/src/ByteArrayDiskWriter.cc --- aria2-0.10.2+1.orig/src/ByteArrayDiskWriter.cc Sat Mar 24 07:32:49 2007 +++ aria2-0.10.2+1/src/ByteArrayDiskWriter.cc Mon Apr 16 11:35:16 2007 @@ -81,7 +81,7 @@ bufLength += dataLength; } -int ByteArrayDiskWriter::readData(char* data, int32_t len, int64_t position) { +int32_t ByteArrayDiskWriter::readData(char* data, int32_t len, int64_t position) { if(position >= bufLength) { return 0; } diff -uwrN aria2-0.10.2+1.orig/src/ByteArrayDiskWriter.h aria2-0.10.2+1/src/ByteArrayDiskWriter.h --- aria2-0.10.2+1.orig/src/ByteArrayDiskWriter.h Sat Mar 24 07:32:49 2007 +++ aria2-0.10.2+1/src/ByteArrayDiskWriter.h Mon Apr 16 11:35:16 2007 @@ -59,7 +59,7 @@ // position is ignored virtual void writeData(const char* data, int32_t len, int64_t position = 0); - virtual int readData(char* data, int32_t len, int64_t position); + virtual int32_t readData(char* data, int32_t len, int64_t position); // not implemented yet #ifdef ENABLE_MESSAGE_DIGEST diff -uwrN aria2-0.10.2+1.orig/src/CompactPeerListProcessor.cc aria2-0.10.2+1/src/CompactPeerListProcessor.cc --- aria2-0.10.2+1.orig/src/CompactPeerListProcessor.cc Sun Oct 1 04:29:14 2006 +++ aria2-0.10.2+1/src/CompactPeerListProcessor.cc Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/DefaultBtContext.cc aria2-0.10.2+1/src/DefaultBtContext.cc --- aria2-0.10.2+1.orig/src/DefaultBtContext.cc Mon Mar 26 05:16:57 2007 +++ aria2-0.10.2+1/src/DefaultBtContext.cc Sun Apr 15 20:01:10 2007 @@ -180,7 +180,7 @@ // retrieve infoHash ShaVisitor v; infoDic->accept(&v); - int32_t len; + int len; v.getHash(infoHash, len); infoHashString = Util::toHex(infoHash, INFO_HASH_LENGTH); // calculate the number of pieces diff -uwrN aria2-0.10.2+1.orig/src/DefaultBtProgressInfoFile.cc aria2-0.10.2+1/src/DefaultBtProgressInfoFile.cc --- aria2-0.10.2+1.orig/src/DefaultBtProgressInfoFile.cc Tue Nov 28 03:33:43 2006 +++ aria2-0.10.2+1/src/DefaultBtProgressInfoFile.cc Mon Apr 16 11:35:16 2007 @@ -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 { @@ -161,6 +166,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 -uwrN aria2-0.10.2+1.orig/src/DefaultPieceStorage.cc aria2-0.10.2+1/src/DefaultPieceStorage.cc --- aria2-0.10.2+1.orig/src/DefaultPieceStorage.cc Mon Mar 26 05:16:57 2007 +++ aria2-0.10.2+1/src/DefaultPieceStorage.cc Sun Apr 15 20:04:17 2007 @@ -372,11 +372,11 @@ } void DefaultPieceStorage::setBitfield(const unsigned char* bitfield, - int bitfieldLength) { + int32_t bitfieldLength) { bitfieldMan->setBitfield(bitfield, bitfieldLength); } -int DefaultPieceStorage::getBitfieldLength() { +int32_t DefaultPieceStorage::getBitfieldLength() { return bitfieldMan->getBitfieldLength(); } @@ -388,16 +388,16 @@ return diskAdaptor; } -int DefaultPieceStorage::getPieceLength(int index) { +int32_t DefaultPieceStorage::getPieceLength(int32_t index) { return bitfieldMan->getBlockLength(index); } -void DefaultPieceStorage::advertisePiece(int cuid, int index) { +void DefaultPieceStorage::advertisePiece(int32_t cuid, int32_t index) { HaveEntry entry(cuid, index); haves.push_front(entry); } -Integers DefaultPieceStorage::getAdvertisedPieceIndexes(int myCuid, +Integers DefaultPieceStorage::getAdvertisedPieceIndexes(int32_t myCuid, const Time& lastCheckTime) { Integers indexes; for(Haves::const_iterator itr = haves.begin(); itr != haves.end(); itr++) { @@ -429,7 +429,7 @@ } }; -void DefaultPieceStorage::removeAdvertisedPiece(int elapsed) { +void DefaultPieceStorage::removeAdvertisedPiece(int32_t elapsed) { Haves::iterator itr = find_if(haves.begin(), haves.end(), FindElapsedHave(elapsed)); if(itr != haves.end()) { diff -uwrN aria2-0.10.2+1.orig/src/DefaultPieceStorage.h aria2-0.10.2+1/src/DefaultPieceStorage.h --- aria2-0.10.2+1.orig/src/DefaultPieceStorage.h Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/src/DefaultPieceStorage.h Mon Apr 16 11:35:16 2007 @@ -123,9 +123,9 @@ virtual bool allDownloadFinished(); virtual void setBitfield(const unsigned char* bitfield, - int bitfieldLength); + int32_t bitfieldLength); - virtual int getBitfieldLength(); + virtual int32_t getBitfieldLength(); virtual const unsigned char* getBitfield(); @@ -145,14 +145,14 @@ virtual DiskAdaptorHandle getDiskAdaptor(); - virtual int getPieceLength(int index); + virtual int32_t getPieceLength(int32_t index); - virtual void advertisePiece(int cuid, int index); + virtual void advertisePiece(int32_t cuid, int32_t index); - virtual Integers getAdvertisedPieceIndexes(int myCuid, + virtual Integers getAdvertisedPieceIndexes(int32_t myCuid, const Time& lastCheckTime); - virtual void removeAdvertisedPiece(int elapsed); + virtual void removeAdvertisedPiece(int32_t elapsed); virtual void markAllPiecesDone(); diff -uwrN aria2-0.10.2+1.orig/src/Directory.cc aria2-0.10.2+1/src/Directory.cc --- aria2-0.10.2+1.orig/src/Directory.cc Sun Nov 5 07:04:17 2006 +++ aria2-0.10.2+1/src/Directory.cc Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/DiskWriter.h aria2-0.10.2+1/src/DiskWriter.h --- aria2-0.10.2+1.orig/src/DiskWriter.h Sat Mar 24 07:32:49 2007 +++ aria2-0.10.2+1/src/DiskWriter.h Mon Apr 16 11:35:16 2007 @@ -87,8 +87,8 @@ writeData((const char*)data, len, position); } - virtual int readData(char* data, int32_t len, int64_t position) = 0; - virtual int readData(unsigned char* data, int32_t len, int64_t position) { + virtual int32_t readData(char* data, int32_t len, int64_t position) = 0; + virtual int32_t readData(unsigned char* data, int32_t len, int64_t position) { return readData((char*)data, len, position); } #ifdef ENABLE_MESSAGE_DIGEST diff -uwrN aria2-0.10.2+1.orig/src/DownloadCommand.cc aria2-0.10.2+1/src/DownloadCommand.cc --- aria2-0.10.2+1.orig/src/DownloadCommand.cc Fri Mar 16 07:21:29 2007 +++ aria2-0.10.2+1/src/DownloadCommand.cc Mon Apr 16 11:35:16 2007 @@ -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, @@ -66,11 +68,15 @@ bool DownloadCommand::executeInternal() { if(maxDownloadSpeedLimit > 0 && maxDownloadSpeedLimit < e->segmentMan->calculateDownloadSpeed()) { +#ifdef HAVE_USLEEP usleep(1); +#else + _sleep(1); +#endif // HAVE_USLEEP e->commands.push_back(this); return false; } - int32_t bufSize = 16*1024; + int bufSize = 16*1024; char buf[bufSize]; socket->readData(buf, bufSize); @@ -80,7 +86,7 @@ segment->writtenLength += bufSize; peerStat->updateDownloadLength(bufSize); } else { - int32_t infbufSize = 16*1024; + int infbufSize = 16*1024; char infbuf[infbufSize]; transferDecoder->inflate(infbuf, infbufSize, buf, bufSize); e->segmentMan->diskWriter->writeData(infbuf, infbufSize, diff -uwrN aria2-0.10.2+1.orig/src/DownloadEngine.h aria2-0.10.2+1/src/DownloadEngine.h --- aria2-0.10.2+1.orig/src/DownloadEngine.h Wed Mar 28 08:08:22 2007 +++ aria2-0.10.2+1/src/DownloadEngine.h Mon Apr 16 11:35:16 2007 @@ -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" #include "NameResolver.h" diff -uwrN aria2-0.10.2+1.orig/src/File.cc aria2-0.10.2+1/src/File.cc --- aria2-0.10.2+1.orig/src/File.cc Mon Mar 26 05:16:57 2007 +++ aria2-0.10.2+1/src/File.cc Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/File.h aria2-0.10.2+1/src/File.h --- aria2-0.10.2+1.orig/src/File.h Mon Mar 26 05:16:57 2007 +++ aria2-0.10.2+1/src/File.h Mon Apr 16 11:35:16 2007 @@ -40,6 +40,43 @@ #include #include +#ifndef S_IRUSR +# define S_IRUSR 0000400 /* read permission, owner */ +#endif /* S_IRUSR */ +#ifndef S_IWUSR +# define S_IWUSR 0000200 /* write permission, owner */ +#endif /* S_IWUSR */ +#ifndef S_IXUSR +# define S_IXUSR 0000100/* execute/search permission, owner */ +#endif /* S_IXUSR */ +#ifndef S_IRWXU +# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) +#endif /* S_IRWXU */ +#ifndef S_IRGRP +# define S_IRGRP 0000040 /* read permission, group */ +#endif /* S_IRGRP */ +#ifndef S_IWGRP +# define S_IWGRP 0000020 /* write permission, grougroup */ +#endif /* S_IWGRP */ +#ifndef S_IXGRP +# define S_IXGRP 0000010/* execute/search permission, group */ +#endif /* S_IXGRP */ +#ifndef S_IRWXG +# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) +#endif /* S_IRWXG */ +#ifndef S_IROTH +# define S_IROTH 0000004 /* read permission, other */ +#endif /* S_IROTH */ +#ifndef S_IWOTH +# define S_IWOTH 0000002 /* write permission, other */ +#endif /* S_IWOTH */ +#ifndef S_IXOTH +# define S_IXOTH 0000001/* execute/search permission, other */ +#endif /* S_IXOTH */ +#ifndef S_IRWXO +# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) +#endif /* S_IRWXO */ + using namespace std; /** @@ -67,6 +104,11 @@ * Tests whether the file denoted by name is a directory. */ 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. diff -uwrN aria2-0.10.2+1.orig/src/FileEntry.cc aria2-0.10.2+1/src/FileEntry.cc --- aria2-0.10.2+1.orig/src/FileEntry.cc Sun Nov 5 07:04:17 2006 +++ aria2-0.10.2+1/src/FileEntry.cc Mon Apr 16 11:35:16 2007 @@ -32,10 +32,11 @@ * files in the program, then also delete it here. */ /* copyright --> */ + #include "FileEntry.h" #include "File.h" #include "DlAbortEx.h" -#include +#include "libgen.h" FileEntry::FileEntry(const string& path, long long int length, diff -uwrN aria2-0.10.2+1.orig/src/FtpConnection.cc aria2-0.10.2+1/src/FtpConnection.cc --- aria2-0.10.2+1.orig/src/FtpConnection.cc Wed Mar 21 03:19:23 2007 +++ aria2-0.10.2+1/src/FtpConnection.cc Mon Apr 16 11:35:16 2007 @@ -201,7 +201,7 @@ pair response; if(bulkReceiveResponse(response)) { if(response.first == 213) { - sscanf(response.second.c_str(), "%*d %Ld", &size); + sscanf(response.second.c_str(), "%*d " LONGLONG_SCANF, &size); } return response.first; } else { diff -uwrN aria2-0.10.2+1.orig/src/HttpConnection.h aria2-0.10.2+1/src/HttpConnection.h --- aria2-0.10.2+1.orig/src/HttpConnection.h Mon Mar 26 05:16:57 2007 +++ aria2-0.10.2+1/src/HttpConnection.h Mon Apr 16 11:35:16 2007 @@ -43,8 +43,11 @@ #include "common.h" #include "Logger.h" #include "HttpResponse.h" -#include #include + +#ifdef HAVE_NETINET_IN_H +#include +#endif // HAVE_NETINET_IN_H #define HEADERBUF_SIZE 4096 diff -uwrN aria2-0.10.2+1.orig/src/HttpRequest.h aria2-0.10.2+1/src/HttpRequest.h --- aria2-0.10.2+1.orig/src/HttpRequest.h Sun Mar 18 08:42:34 2007 +++ aria2-0.10.2+1/src/HttpRequest.h Mon Apr 16 11:35:16 2007 @@ -40,7 +40,9 @@ #include "Range.h" #include "Request.h" #include "Option.h" +#ifdef HAVE_NETINET_IN_H #include +#endif // HAVE_NETINET_IN_H class HttpRequest { private: diff -uwrN aria2-0.10.2+1.orig/src/HttpResponse.cc aria2-0.10.2+1/src/HttpResponse.cc --- aria2-0.10.2+1.orig/src/HttpResponse.cc Thu Mar 15 08:07:18 2007 +++ aria2-0.10.2+1/src/HttpResponse.cc Mon Apr 16 11:35:16 2007 @@ -57,7 +57,9 @@ // compare the received range against the requested range RangeHandle responseRange = httpHeader->getRange(); if(!httpRequest->isRangeSatisfied(responseRange)) { - throw new DlRetryEx("Invalid range header. Request: %lld-%lld/%lld, Response: %lld-%lld/%lld", + throw new DlRetryEx("Invalid range header. Request: " + LONGLONG_PRINTF "-" LONGLONG_PRINTF "/" LONGLONG_PRINTF ", Response: " + LONGLONG_PRINTF "-" LONGLONG_PRINTF "/" LONGLONG_PRINTF, httpRequest->getStartByte(), httpRequest->getEndByte(), httpRequest->getEntityLength(), diff -uwrN aria2-0.10.2+1.orig/src/HttpResponseCommand.cc aria2-0.10.2+1/src/HttpResponseCommand.cc --- aria2-0.10.2+1.orig/src/HttpResponseCommand.cc Thu Mar 15 08:07:18 2007 +++ aria2-0.10.2+1/src/HttpResponseCommand.cc Mon Apr 16 11:35:16 2007 @@ -185,7 +185,7 @@ httpResponse->getHttpRequest()->getRequest()->setKeepAlive(false); e->segmentMan->isSplittable = false; e->segmentMan->downloadStarted = true; - e->segmentMan->diskWriter->initAndOpenFile("/tmp/aria2"+Util::itos((int32_t)getpid())); + e->segmentMan->diskWriter->initAndOpenFile(Util::getTempDir()+"/aria2"+Util::itos((int32_t)getpid())); createHttpDownloadCommand(httpResponse); return true; } diff -uwrN aria2-0.10.2+1.orig/src/LogFactory.cc aria2-0.10.2+1/src/LogFactory.cc --- aria2-0.10.2+1.orig/src/LogFactory.cc Thu Sep 21 08:31:24 2006 +++ aria2-0.10.2+1/src/LogFactory.cc Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/Makefile.am aria2-0.10.2+1/src/Makefile.am --- aria2-0.10.2+1.orig/src/Makefile.am Wed Mar 28 08:08:22 2007 +++ aria2-0.10.2+1/src/Makefile.am Mon Apr 16 11:35:16 2007 @@ -81,7 +81,8 @@ GlowFileAllocator.cc GlowFileAllocator.h\ OptionParser.cc OptionParser.h\ OptionHandlerFactory.cc OptionHandlerFactory.h\ - NameResolver.cc NameResolver.h + NameResolver.cc NameResolver.h \ + Platform.cc Platform.h # debug_new.cpp if ENABLE_BITTORRENT @@ -199,11 +200,23 @@ MetalinkChunkChecksum.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 -uwrN aria2-0.10.2+1.orig/src/MetaFileUtil.cc aria2-0.10.2+1/src/MetaFileUtil.cc --- aria2-0.10.2+1.orig/src/MetaFileUtil.cc Thu Jan 11 08:32:31 2007 +++ aria2-0.10.2+1/src/MetaFileUtil.cc Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/MultiDiskAdaptor.cc aria2-0.10.2+1/src/MultiDiskAdaptor.cc --- aria2-0.10.2+1.orig/src/MultiDiskAdaptor.cc Thu Jan 25 08:47:29 2007 +++ aria2-0.10.2+1/src/MultiDiskAdaptor.cc Mon Apr 16 11:35:16 2007 @@ -145,7 +145,7 @@ return length; } -int MultiDiskAdaptor::readData(unsigned char* data, int32_t len, int64_t offset) +int32_t MultiDiskAdaptor::readData(unsigned char* data, int32_t len, int64_t offset) { int64_t fileOffset = offset; bool reading = false; diff -uwrN aria2-0.10.2+1.orig/src/MultiDiskAdaptor.h aria2-0.10.2+1/src/MultiDiskAdaptor.h --- aria2-0.10.2+1.orig/src/MultiDiskAdaptor.h Sat Mar 24 08:32:40 2007 +++ aria2-0.10.2+1/src/MultiDiskAdaptor.h Mon Apr 16 11:35:16 2007 @@ -115,10 +115,13 @@ int64_t fileOffset, int32_t rem) const; +#if defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) void hashUpdate(MessageDigestContext& ctx, const DiskWriterEntryHandle& entry, int64_t offset, int64_t length); +#endif /* defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) */ + string getTopDirPath() const; public: MultiDiskAdaptor():pieceLength(0), @@ -140,10 +143,13 @@ virtual void writeData(const unsigned char* data, int32_t len, int64_t offset); - virtual int readData(unsigned char* data, int32_t len, int64_t offset); + virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset); +#if defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) virtual string messageDigest(int64_t offset, int64_t length, const MessageDigestContext::DigestAlgo& algo); + +#endif /* defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) */ virtual bool fileExists(); diff -uwrN aria2-0.10.2+1.orig/src/NameResolver.cc aria2-0.10.2+1/src/NameResolver.cc --- aria2-0.10.2+1.orig/src/NameResolver.cc Wed Mar 28 08:08:22 2007 +++ aria2-0.10.2+1/src/NameResolver.cc Mon Apr 16 11:35:16 2007 @@ -34,6 +34,10 @@ /* copyright --> */ #include "NameResolver.h" +#ifndef HAVE_GETADDRINFO +# include "getaddrinfo.h" +#endif // HAVE_GETADDRINFO + #ifdef ENABLE_ASYNC_DNS void callback(void* arg, int status, struct hostent* host) { diff -uwrN aria2-0.10.2+1.orig/src/NameResolver.h aria2-0.10.2+1/src/NameResolver.h --- aria2-0.10.2+1.orig/src/NameResolver.h Wed Mar 28 08:08:22 2007 +++ aria2-0.10.2+1/src/NameResolver.h Mon Apr 16 11:35:16 2007 @@ -36,10 +36,23 @@ #define _D_NAME_RESOLVER_H_ #include "common.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 + +#ifndef HAVE_INET_ATON +# include "inet_aton.h" +#endif // HAVE_INET_ATON #ifdef ENABLE_ASYNC_DNS diff -uwrN aria2-0.10.2+1.orig/src/OptionHandlerImpl.h aria2-0.10.2+1/src/OptionHandlerImpl.h --- aria2-0.10.2+1.orig/src/OptionHandlerImpl.h Mon Mar 26 05:16:57 2007 +++ aria2-0.10.2+1/src/OptionHandlerImpl.h Mon Apr 16 11:35:16 2007 @@ -40,7 +40,9 @@ #include "Util.h" #include "FatalException.h" #include "prefs.h" +#ifdef HAVE_NETINET_IN_H #include +#endif // HAVE_NETINET_IN_H class NullOptionHandler : public OptionHandler { public: @@ -91,13 +93,13 @@ } else { string msg = _optName+" "; if(_min == -1 && _max != -1) { - msg += _("must be smaller than or equal to %lld."); + msg += _("must be smaller than or equal to " LONGLONG_PRINTF "."); throw new FatalException(msg.c_str(), _max); } else if(_min != -1 && _max != -1) { - msg += _("must be between %lld and %lld."); + msg += _("must be between " LONGLONG_PRINTF " and " LONGLONG_PRINTF "."); throw new FatalException(msg.c_str(), _min, _max); } else if(_min != -1 && _max == -1) { - msg += _("must be greater than or equal to %lld."); + msg += _("must be greater than or equal to " LONGLONG_PRINTF "."); throw new FatalException(msg.c_str(), _min); } else { msg += _("must be a number."); diff -uwrN aria2-0.10.2+1.orig/src/PeerConnection.cc aria2-0.10.2+1/src/PeerConnection.cc --- aria2-0.10.2+1.orig/src/PeerConnection.cc Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/src/PeerConnection.cc Mon Apr 16 11:35:16 2007 @@ -39,7 +39,9 @@ #include "Util.h" #include "LogFactory.h" #include "BtHandshakeMessage.h" +#ifdef HAVE_NETINET_IN_H #include +#endif // HAVE_NETINET_IN_H PeerConnection::PeerConnection(int32_t cuid, const SocketHandle& socket, diff -uwrN aria2-0.10.2+1.orig/src/PeerMessageUtil.cc aria2-0.10.2+1/src/PeerMessageUtil.cc --- aria2-0.10.2+1.orig/src/PeerMessageUtil.cc Thu Jan 25 08:47:29 2007 +++ aria2-0.10.2+1/src/PeerMessageUtil.cc Mon Apr 16 11:35:16 2007 @@ -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 int8_t PeerMessageUtil::getId(const unsigned char* msg) { return msg[0]; diff -uwrN aria2-0.10.2+1.orig/src/PieceStorage.h aria2-0.10.2+1/src/PieceStorage.h --- aria2-0.10.2+1.orig/src/PieceStorage.h Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/src/PieceStorage.h Mon Apr 16 11:35:16 2007 @@ -124,9 +124,9 @@ virtual const unsigned char* getBitfield() = 0; virtual void setBitfield(const unsigned char* bitfield, - int bitfieldLength) = 0; + int32_t bitfieldLength) = 0; - virtual int getBitfieldLength() = 0; + virtual int32_t getBitfieldLength() = 0; virtual bool isSelectiveDownloadingMode() = 0; @@ -136,26 +136,26 @@ virtual DiskAdaptorHandle getDiskAdaptor() = 0; - virtual int getPieceLength(int index) = 0; + virtual int32_t getPieceLength(int32_t index) = 0; /** * Adds piece index to advertise to other commands. They send have message * based on this information. */ - virtual void advertisePiece(int cuid, int index) = 0; + virtual void advertisePiece(int32_t cuid, int32_t index) = 0; /** * Returns piece index which is not advertised by the caller command and * newer than lastCheckTime. */ - virtual Integers getAdvertisedPieceIndexes(int myCuid, + virtual Integers getAdvertisedPieceIndexes(int32_t myCuid, const Time& lastCheckTime) = 0; /** * Removes have entry if specified seconds have elapsed since its * registration. */ - virtual void removeAdvertisedPiece(int elapsed) = 0; + virtual void removeAdvertisedPiece(int32_t elapsed) = 0; /** * Sets all bits in bitfield to 1. diff -uwrN aria2-0.10.2+1.orig/src/Platform.cc aria2-0.10.2+1/src/Platform.cc --- aria2-0.10.2+1.orig/src/Platform.cc Wed Dec 31 16:00:00 1969 +++ aria2-0.10.2+1/src/Platform.cc Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/Platform.h aria2-0.10.2+1/src/Platform.h --- aria2-0.10.2+1.orig/src/Platform.h Wed Dec 31 16:00:00 1969 +++ aria2-0.10.2+1/src/Platform.h Mon Apr 16 11:35:16 2007 @@ -0,0 +1,45 @@ +/* */ +#ifndef _D_PLATFORM_H_ +#define _D_PLATFORM_H_ + +class Platform { +public: + Platform(); + + ~Platform(); +}; + +#endif // _D_PLATFORM_H_ diff -uwrN aria2-0.10.2+1.orig/src/Request.cc aria2-0.10.2+1/src/Request.cc --- aria2-0.10.2+1.orig/src/Request.cc Wed Mar 21 03:19:23 2007 +++ aria2-0.10.2+1/src/Request.cc Mon Apr 16 11:35:16 2007 @@ -88,9 +88,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); @@ -132,6 +129,10 @@ 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 -uwrN aria2-0.10.2+1.orig/src/RequestInfo.h aria2-0.10.2+1/src/RequestInfo.h --- aria2-0.10.2+1.orig/src/RequestInfo.h Wed Nov 8 08:25:38 2006 +++ aria2-0.10.2+1/src/RequestInfo.h Mon Apr 16 11:35:16 2007 @@ -43,6 +43,10 @@ #include "Checksum.h" #include +#ifndef SA_RESETHAND +# define SA_RESETHAND 0x80000000 +#endif + class FileInfo { public: string filename; diff -uwrN aria2-0.10.2+1.orig/src/SegmentMan.cc aria2-0.10.2+1/src/SegmentMan.cc --- aria2-0.10.2+1.orig/src/SegmentMan.cc Mon Mar 26 05:16:57 2007 +++ aria2-0.10.2+1/src/SegmentMan.cc Mon Apr 16 11:35:16 2007 @@ -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" @@ -48,6 +49,10 @@ #include #include +#ifdef HAVE_IO_H +# include +#endif // HAVE_IO_H + SegmentMan::SegmentMan():logger(LogFactory::getInstance()), bitfield(0), totalSize(0), @@ -88,7 +93,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); @@ -106,7 +111,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"); @@ -155,6 +160,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 -uwrN aria2-0.10.2+1.orig/src/SimpleLogger.cc aria2-0.10.2+1/src/SimpleLogger.cc --- aria2-0.10.2+1.orig/src/SimpleLogger.cc Fri Dec 1 01:31:46 2006 +++ aria2-0.10.2+1/src/SimpleLogger.cc Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/SimpleRandomizer.h aria2-0.10.2+1/src/SimpleRandomizer.h --- aria2-0.10.2+1.orig/src/SimpleRandomizer.h Tue Feb 6 06:49:22 2007 +++ aria2-0.10.2+1/src/SimpleRandomizer.h Mon Apr 16 11:35:16 2007 @@ -54,13 +54,21 @@ } static void init() { - srandom(time(0)); +#ifdef HAVE_SRANDOM + srandom(time(NULL)); +#else + srand(time(NULL)); +#endif } virtual ~SimpleRandomizer() {} virtual int getRandomNumber() { +#ifdef HAVE_RANDOM return random(); +#else + return rand(); +#endif } virtual int getMaxRandomNumber() { diff -uwrN aria2-0.10.2+1.orig/src/SocketCore.cc aria2-0.10.2+1/src/SocketCore.cc --- aria2-0.10.2+1.orig/src/SocketCore.cc Thu Sep 21 08:31:24 2006 +++ aria2-0.10.2+1/src/SocketCore.cc Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/Util.cc aria2-0.10.2+1/src/Util.cc --- aria2-0.10.2+1.orig/src/Util.cc Mon Mar 26 05:16:57 2007 +++ aria2-0.10.2+1/src/Util.cc Mon Apr 16 11:35:16 2007 @@ -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,13 +42,26 @@ #include #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 -#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 template string uint2str(T value, bool comma) { @@ -83,8 +97,6 @@ return str; } - - string Util::uitos(uint16_t value, bool comma) { return uint2str(value, comma); } @@ -97,6 +109,12 @@ return uint2str(value, comma); } +#ifdef __CYGWIN__ +string Util::itos(int value, bool comma) { + return int2str(value, comma); +} +#endif /* __CYGWIN__ */ + string Util::itos(int32_t value, bool comma) { return int2str(value, comma); } @@ -310,6 +328,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; } @@ -324,10 +345,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) { @@ -496,7 +517,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) { @@ -596,16 +617,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; } @@ -645,12 +666,16 @@ } } -void Util::setGlobalSignalHandler(int signal, void (*handler)(int), int flags) { +void Util::setGlobalSignalHandler(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 Util::indexRange(int32_t& startIndex, int32_t& endIndex, @@ -690,4 +715,30 @@ size = sizeWithUnit.substr(0, p); } return strtoll(size.c_str(), 0, 10)*mult; +} + +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 -uwrN aria2-0.10.2+1.orig/src/Util.h aria2-0.10.2+1/src/Util.h --- aria2-0.10.2+1.orig/src/Util.h Mon Mar 26 05:16:57 2007 +++ aria2-0.10.2+1/src/Util.h Mon Apr 16 11:35:16 2007 @@ -56,6 +56,9 @@ static string llitos(int64_t value, bool comma = false); static string ullitos(uint64_t value, bool comma = false); static string itos(int32_t value, bool comma = false); +#ifdef __CYGWIN__ + static string itos(int value, bool comma = false); +#endif /* __CYGWIN__ */ static string uitos(uint32_t value, bool comma = false); static string itos(int16_t value, bool comma = false); static string uitos(uint16_t value, bool comma = false); @@ -148,6 +151,8 @@ static string getHomeDir(); static int64_t getRealSize(const string& sizeWithUnit); + + static string getTempDir(); }; #endif // _D_UTIL_H_ diff -uwrN aria2-0.10.2+1.orig/src/common.h aria2-0.10.2+1/src/common.h --- aria2-0.10.2+1.orig/src/common.h Mon Mar 26 05:16:57 2007 +++ aria2-0.10.2+1/src/common.h Mon Apr 16 11:35:16 2007 @@ -39,6 +39,7 @@ #ifdef HAVE_CONFIG_H # include #endif + #include #include #include @@ -54,6 +55,42 @@ #else # define _(String) (String) #endif + +#ifdef __MINGW32__ +# define LONGLONG_PRINTF "%I64d" +# define ULONGLONG_PRINTF "%I64u" +# define LONGLONG_SCANF "%I64d" +# define ULONGLONG_SCANF "%I64u" +# ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x501 +# endif // _WIN32_WINNT +# include +# undef ERROR +# include +# define SOCKOPT_T const char +# define HAVE_GETADDRINFO +typedef uint16_t in_port_t; +#else +# define LONGLONG_PRINTF "%lld" +# define ULONGLONG_PRINTF "%llu" +# define LONGLONG_SCANF "%Ld" +# define ULONGLONG_SCANF "%Lu" +# define SOCKOPT_T socklen_t +#endif // __MINGW32__ + +#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 #define USER_AGENT "aria2" diff -uwrN aria2-0.10.2+1.orig/src/getaddrinfo.c aria2-0.10.2+1/src/getaddrinfo.c --- aria2-0.10.2+1.orig/src/getaddrinfo.c Wed Dec 31 16:00:00 1969 +++ aria2-0.10.2+1/src/getaddrinfo.c Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/getaddrinfo.h aria2-0.10.2+1/src/getaddrinfo.h --- aria2-0.10.2+1.orig/src/getaddrinfo.h Wed Dec 31 16:00:00 1969 +++ aria2-0.10.2+1/src/getaddrinfo.h Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/inet_aton.c aria2-0.10.2+1/src/inet_aton.c --- aria2-0.10.2+1.orig/src/inet_aton.c Wed Dec 31 16:00:00 1969 +++ aria2-0.10.2+1/src/inet_aton.c Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/inet_aton.h aria2-0.10.2+1/src/inet_aton.h --- aria2-0.10.2+1.orig/src/inet_aton.h Wed Dec 31 16:00:00 1969 +++ aria2-0.10.2+1/src/inet_aton.h Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/libgen.c aria2-0.10.2+1/src/libgen.c --- aria2-0.10.2+1.orig/src/libgen.c Wed Dec 31 16:00:00 1969 +++ aria2-0.10.2+1/src/libgen.c Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/src/main.cc aria2-0.10.2+1/src/main.cc --- aria2-0.10.2+1.orig/src/main.cc Thu Mar 29 04:29:45 2007 +++ aria2-0.10.2+1/src/main.cc Mon Apr 16 11:35:16 2007 @@ -48,6 +48,7 @@ #include "OptionHandlerFactory.h" #include "FatalException.h" #include "File.h" +#include "Platform.h" #include #include #include @@ -75,6 +76,14 @@ # 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; void showVersion() { @@ -118,7 +127,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" @@ -295,6 +306,8 @@ } int main(int argc, char* argv[]) { + Platform platform; + #ifdef ENABLE_NLS setlocale (LC_CTYPE, ""); setlocale (LC_MESSAGES, ""); @@ -307,7 +320,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"); @@ -358,7 +373,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,12 +631,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 @@ -637,11 +656,11 @@ BitfieldManFactory::setDefaultRandomizer(SimpleRandomizer::getInstance()); FileAllocationMonitorFactory::setFactory(new ConsoleFileAllocationMonitorFactory()); 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 { @@ -665,7 +684,9 @@ } RequestFactorySingletonHolder::instance(requestFactory); +#ifdef SIGPIPE Util::setGlobalSignalHandler(SIGPIPE, SIG_IGN, 0); +#endif RequestInfo* firstReqInfo = 0; #ifdef ENABLE_BITTORRENT diff -uwrN aria2-0.10.2+1.orig/src/message.h aria2-0.10.2+1/src/message.h --- aria2-0.10.2+1.orig/src/message.h Sat Mar 24 20:44:47 2007 +++ aria2-0.10.2+1/src/message.h Mon Apr 16 11:35:16 2007 @@ -77,10 +77,10 @@ #define EX_CONNECTION_FAILED _("Connection failed.") #define EX_FILENAME_MISMATCH _("The requested filename and the previously registered one are not same. %s != %s") #define EX_BAD_STATUS _("The response status is not successful. status=%d") -#define EX_TOO_LARGE_FILE _("Too large file size. size=%lld") +#define EX_TOO_LARGE_FILE _("Too large file size. size=" LONGLONG_PRINTF) #define EX_TRANSFER_ENCODING_NOT_SUPPORTED _("Transfer encoding %s is not supported.") #define EX_SSL_INIT_FAILURE _("SSL initialization failed.") -#define EX_SIZE_MISMATCH _("Size mismatch %lld != %lld") +#define EX_SIZE_MISMATCH _("Size mismatch " LONGLONG_PRINTF " != " LONGLONG_PRINTF) #define EX_AUTH_FAILED _("Authorization failed.") #define EX_GOT_EOF _("Got EOF from the server.") #define EX_EOF_FROM_PEER _("Got EOF from peer.") @@ -91,7 +91,7 @@ #define EX_FILE_READ _("Failed to read from the file %s, cause: %s") #define EX_FILE_SHA1SUM _("Failed to calculate SHA1 digest of or a part of the file %s, cause: %s") #define EX_FILE_SEEK _("Failed to seek the file %s, cause: %s") -#define EX_FILE_OFFSET_OUT_OF_RANGE _("The offset is out of range, offset=%lld") +#define EX_FILE_OFFSET_OUT_OF_RANGE _("The offset is out of range, offset=" LONGLONG_PRINTF) #define EX_NOT_DIRECTORY _("%s is not a directory.") #define EX_MAKE_DIR _("Failed to make the directory %s, cause: %s") #define EX_SEGMENT_FILE_OPEN _("Failed to open the segment file %s, cause: %s") @@ -115,5 +115,5 @@ #define EX_FILE_ALREADY_EXISTS _("File %s exists, but %s does not exist. The download was canceled in order to prevent your file from being truncated to 0. If you are sure to download file all over again, then delete it or add --allow-overwrite=true option and restart aria2.") #define EX_INVALID_PAYLOAD_SIZE _("Invalid payload size for %s, size=%d. It should be %d.") #define EX_INVALID_BT_MESSAGE_ID _("Invalid ID=%d for %s. It should be %d.") -#define EX_INVALID_CHUNK_CHECKSUM _("Chunk checksum validation failed. checksumIndex=%d, offset=%lld, length=%d, expectedHash=%s, actualHash=%s") +#define EX_INVALID_CHUNK_CHECKSUM _("Chunk checksum validation failed. checksumIndex=%d, offset=" LONGLONG_PRINTF ", length=%d, expectedHash=%s, actualHash=%s") #endif // _D_MESSAGE_H_ diff -uwrN aria2-0.10.2+1.orig/src/prefs.h aria2-0.10.2+1/src/prefs.h --- aria2-0.10.2+1.orig/src/prefs.h Tue Mar 27 09:16:44 2007 +++ aria2-0.10.2+1/src/prefs.h Mon Apr 16 11:35:16 2007 @@ -40,8 +40,11 @@ /** * Constants */ +#undef V_TRUE #define V_TRUE "true" +#undef V_FALSE #define V_FALSE "false" +#undef V_NONE #define V_NONE "none" /** diff -uwrN aria2-0.10.2+1.orig/test/BitfieldManTest.cc aria2-0.10.2+1/test/BitfieldManTest.cc --- aria2-0.10.2+1.orig/test/BitfieldManTest.cc Sat Mar 24 07:32:49 2007 +++ aria2-0.10.2+1/test/BitfieldManTest.cc Mon Apr 16 11:35:16 2007 @@ -48,12 +48,12 @@ void BitfieldManTest::testGetBlockSize() { BitfieldMan bt1(1024, 1024*10); - CPPUNIT_ASSERT_EQUAL(1024, bt1.getBlockLength(9)); + CPPUNIT_ASSERT_EQUAL((int32_t)1024, bt1.getBlockLength(9)); BitfieldMan bt2(1024, 1024*10+1); - CPPUNIT_ASSERT_EQUAL(1024, bt2.getBlockLength(9)); - CPPUNIT_ASSERT_EQUAL(1, bt2.getBlockLength(10)); - CPPUNIT_ASSERT_EQUAL(0, bt2.getBlockLength(11)); + CPPUNIT_ASSERT_EQUAL((int32_t)1024, bt2.getBlockLength(9)); + CPPUNIT_ASSERT_EQUAL((int32_t)1, bt2.getBlockLength(10)); + CPPUNIT_ASSERT_EQUAL((int32_t)0, bt2.getBlockLength(11)); } void BitfieldManTest::testGetFirstMissingUnusedIndex() { @@ -61,22 +61,22 @@ unsigned char bitfield[2]; memset(bitfield, 0xff, sizeof(bitfield)); - CPPUNIT_ASSERT_EQUAL(0, bt1.getFirstMissingUnusedIndex(bitfield, sizeof(bitfield))); + CPPUNIT_ASSERT_EQUAL((int32_t)0, bt1.getFirstMissingUnusedIndex(bitfield, sizeof(bitfield))); CPPUNIT_ASSERT(bt1.setUseBit(0)); - CPPUNIT_ASSERT_EQUAL(1, bt1.getFirstMissingUnusedIndex(bitfield, sizeof(bitfield))); + CPPUNIT_ASSERT_EQUAL((int32_t)1, bt1.getFirstMissingUnusedIndex(bitfield, sizeof(bitfield))); CPPUNIT_ASSERT(bt1.unsetUseBit(0)); - CPPUNIT_ASSERT_EQUAL(0, bt1.getFirstMissingUnusedIndex(bitfield, sizeof(bitfield))); + CPPUNIT_ASSERT_EQUAL((int32_t)0, bt1.getFirstMissingUnusedIndex(bitfield, sizeof(bitfield))); CPPUNIT_ASSERT(bt1.setBit(0)); - CPPUNIT_ASSERT_EQUAL(1, bt1.getFirstMissingUnusedIndex(bitfield, sizeof(bitfield))); + CPPUNIT_ASSERT_EQUAL((int32_t)1, bt1.getFirstMissingUnusedIndex(bitfield, sizeof(bitfield))); for(int i = 0; i < 8; i++) { CPPUNIT_ASSERT(bt1.setBit(i)); } - CPPUNIT_ASSERT_EQUAL(8, bt1.getFirstMissingUnusedIndex(bitfield, sizeof(bitfield))); + CPPUNIT_ASSERT_EQUAL((int32_t)8, bt1.getFirstMissingUnusedIndex(bitfield, sizeof(bitfield))); - CPPUNIT_ASSERT_EQUAL(8, bt1.getFirstMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)8, bt1.getFirstMissingUnusedIndex()); CPPUNIT_ASSERT(bt1.setUseBit(8)); - CPPUNIT_ASSERT_EQUAL(9, bt1.getFirstMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)9, bt1.getFirstMissingUnusedIndex()); } void BitfieldManTest::testIsAllBitSet() { @@ -171,7 +171,7 @@ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; - CPPUNIT_ASSERT_EQUAL(0, bt1.getMissingIndex(bitArray, 32)); + CPPUNIT_ASSERT_EQUAL((int32_t)0, bt1.getMissingIndex(bitArray, 32)); unsigned char bitArray2[] = { 0x0f, 0xff, 0xff, 0xff, @@ -184,7 +184,7 @@ 0xff, 0xff, 0xff, 0xff, }; - CPPUNIT_ASSERT_EQUAL(4, bt1.getMissingIndex(bitArray2, 32)); + CPPUNIT_ASSERT_EQUAL((int32_t)4, bt1.getMissingIndex(bitArray2, 32)); unsigned char bitArray3[] = { 0x00, 0xff, 0xff, 0xff, @@ -197,7 +197,7 @@ 0xff, 0xff, 0xff, 0xff, }; - CPPUNIT_ASSERT_EQUAL(8, bt1.getMissingIndex(bitArray3, 32)); + CPPUNIT_ASSERT_EQUAL((int32_t)8, bt1.getMissingIndex(bitArray3, 32)); unsigned char bitArray4[] = { 0x00, 0x00, 0x00, 0x00, @@ -210,34 +210,34 @@ 0x00, 0x00, 0x00, 0x00, }; - CPPUNIT_ASSERT_EQUAL(-1, bt1.getMissingIndex(bitArray4, 32)); + CPPUNIT_ASSERT_EQUAL((int32_t)-1, bt1.getMissingIndex(bitArray4, 32)); } void BitfieldManTest::testGetSparceMissingUnusedIndex() { BitfieldMan bitfield(1024*1024, 10*1024*1024); - CPPUNIT_ASSERT_EQUAL(0, bitfield.getSparseMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)0, bitfield.getSparseMissingUnusedIndex()); bitfield.setBit(0); - CPPUNIT_ASSERT_EQUAL(5, bitfield.getSparseMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)5, bitfield.getSparseMissingUnusedIndex()); bitfield.setUseBit(5); - CPPUNIT_ASSERT_EQUAL(3, bitfield.getSparseMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)3, bitfield.getSparseMissingUnusedIndex()); bitfield.setBit(3); - CPPUNIT_ASSERT_EQUAL(8, bitfield.getSparseMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)8, bitfield.getSparseMissingUnusedIndex()); bitfield.setBit(8); - CPPUNIT_ASSERT_EQUAL(2, bitfield.getSparseMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)2, bitfield.getSparseMissingUnusedIndex()); bitfield.setBit(2); - CPPUNIT_ASSERT_EQUAL(7, bitfield.getSparseMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)7, bitfield.getSparseMissingUnusedIndex()); bitfield.setBit(7); - CPPUNIT_ASSERT_EQUAL(1, bitfield.getSparseMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)1, bitfield.getSparseMissingUnusedIndex()); bitfield.setBit(1); - CPPUNIT_ASSERT_EQUAL(4, bitfield.getSparseMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)4, bitfield.getSparseMissingUnusedIndex()); bitfield.setBit(4); - CPPUNIT_ASSERT_EQUAL(6, bitfield.getSparseMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)6, bitfield.getSparseMissingUnusedIndex()); bitfield.setBit(6); - CPPUNIT_ASSERT_EQUAL(9, bitfield.getSparseMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)9, bitfield.getSparseMissingUnusedIndex()); bitfield.setBit(9); - CPPUNIT_ASSERT_EQUAL(-1, bitfield.getSparseMissingUnusedIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)-1, bitfield.getSparseMissingUnusedIndex()); } void BitfieldManTest::testIsBitSetOffsetRange() diff -uwrN aria2-0.10.2+1.orig/test/BtAllowedFastMessageTest.cc aria2-0.10.2+1/test/BtAllowedFastMessageTest.cc --- aria2-0.10.2+1.orig/test/BtAllowedFastMessageTest.cc Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/test/BtAllowedFastMessageTest.cc Mon Apr 16 11:35:16 2007 @@ -36,7 +36,7 @@ PeerMessageUtil::setIntParam(&msg[5], 12345); BtAllowedFastMessageHandle pm = BtAllowedFastMessage::create(&msg[4], 5); CPPUNIT_ASSERT_EQUAL((int8_t)17, pm->getId()); - CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); // case: payload size is wrong try { diff -uwrN aria2-0.10.2+1.orig/test/BtBitfieldMessageTest.cc aria2-0.10.2+1/test/BtBitfieldMessageTest.cc --- aria2-0.10.2+1.orig/test/BtBitfieldMessageTest.cc Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/test/BtBitfieldMessageTest.cc Mon Apr 16 11:35:16 2007 @@ -37,7 +37,7 @@ BtBitfieldMessageHandle pm = BtBitfieldMessage::create(&msg[4], 3); CPPUNIT_ASSERT_EQUAL((int8_t)5, pm->getId()); CPPUNIT_ASSERT(memcmp(bitfield, pm->getBitfield(), sizeof(bitfield)) == 0); - CPPUNIT_ASSERT_EQUAL(2, pm->getBitfieldLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)2, pm->getBitfieldLength()); // case: payload size is wrong try { unsigned char msg[5]; diff -uwrN aria2-0.10.2+1.orig/test/BtCancelMessageTest.cc aria2-0.10.2+1/test/BtCancelMessageTest.cc --- aria2-0.10.2+1.orig/test/BtCancelMessageTest.cc Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/test/BtCancelMessageTest.cc Mon Apr 16 11:35:16 2007 @@ -66,9 +66,9 @@ PeerMessageUtil::setIntParam(&msg[13], 1024); BtCancelMessageHandle pm = BtCancelMessage::create(&msg[4], 13); CPPUNIT_ASSERT_EQUAL((int8_t)8, pm->getId()); - CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex()); - CPPUNIT_ASSERT_EQUAL(256, pm->getBegin()); - CPPUNIT_ASSERT_EQUAL(1024, pm->getLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)256, pm->getBegin()); + CPPUNIT_ASSERT_EQUAL((int32_t)1024, pm->getLength()); // case: payload size is wrong try { diff -uwrN aria2-0.10.2+1.orig/test/BtHaveMessageTest.cc aria2-0.10.2+1/test/BtHaveMessageTest.cc --- aria2-0.10.2+1.orig/test/BtHaveMessageTest.cc Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/test/BtHaveMessageTest.cc Mon Apr 16 11:35:16 2007 @@ -33,7 +33,7 @@ PeerMessageUtil::setIntParam(&msg[5], 12345); BtHaveMessageHandle pm = BtHaveMessage::create(&msg[4], 5); CPPUNIT_ASSERT_EQUAL((int8_t)4, pm->getId()); - CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); // case: payload size is wrong try { diff -uwrN aria2-0.10.2+1.orig/test/BtKeepAliveMessageTest.cc aria2-0.10.2+1/test/BtKeepAliveMessageTest.cc --- aria2-0.10.2+1.orig/test/BtKeepAliveMessageTest.cc Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/test/BtKeepAliveMessageTest.cc Mon Apr 16 11:35:16 2007 @@ -26,7 +26,7 @@ memset(msg, 0, sizeof(msg)); BtKeepAliveMessage message; CPPUNIT_ASSERT_EQUAL((int8_t)99, message.getId()); - CPPUNIT_ASSERT_EQUAL(4, message.getMessageLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)4, message.getMessageLength()); CPPUNIT_ASSERT(memcmp(msg, message.getMessage(), 4) == 0); } diff -uwrN aria2-0.10.2+1.orig/test/BtPieceMessageTest.cc aria2-0.10.2+1/test/BtPieceMessageTest.cc --- aria2-0.10.2+1.orig/test/BtPieceMessageTest.cc Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/test/BtPieceMessageTest.cc Mon Apr 16 11:35:16 2007 @@ -112,10 +112,10 @@ memcpy(&msg[13], data, sizeof(data)); BtPieceMessageHandle pm = BtPieceMessage::create(&msg[4], 11); CPPUNIT_ASSERT_EQUAL((int8_t)7, pm->getId()); - CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex()); - CPPUNIT_ASSERT_EQUAL(256, pm->getBegin()); + CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)256, pm->getBegin()); CPPUNIT_ASSERT(memcmp(data, pm->getBlock(), sizeof(data)) == 0); - CPPUNIT_ASSERT_EQUAL(2, pm->getBlockLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)2, pm->getBlockLength()); // case: payload size is wrong try { @@ -172,9 +172,9 @@ CPPUNIT_ASSERT(msg->isInvalidate()); CPPUNIT_ASSERT_EQUAL((size_t)1, btMessageDispatcher->messageQueue.size()); MockBtMessage2* rej = (MockBtMessage2*)btMessageDispatcher->messageQueue.front().get(); - CPPUNIT_ASSERT_EQUAL(1, rej->index); - CPPUNIT_ASSERT_EQUAL(1024, rej->begin); - CPPUNIT_ASSERT_EQUAL(16*1024, rej->length); + CPPUNIT_ASSERT_EQUAL((int32_t)1, rej->index); + CPPUNIT_ASSERT_EQUAL((int32_t)1024, rej->begin); + CPPUNIT_ASSERT_EQUAL((int32_t)16*1024, rej->length); } void BtPieceMessageTest::testChokingEvent_inAmAllowedIndexSet() { @@ -257,9 +257,9 @@ CPPUNIT_ASSERT(msg->isInvalidate()); CPPUNIT_ASSERT_EQUAL((size_t)1, btMessageDispatcher->messageQueue.size()); MockBtMessage2* rej = (MockBtMessage2*)btMessageDispatcher->messageQueue.front().get(); - CPPUNIT_ASSERT_EQUAL(1, rej->index); - CPPUNIT_ASSERT_EQUAL(1024, rej->begin); - CPPUNIT_ASSERT_EQUAL(16*1024, rej->length); + CPPUNIT_ASSERT_EQUAL((int32_t)1, rej->index); + CPPUNIT_ASSERT_EQUAL((int32_t)1024, rej->begin); + CPPUNIT_ASSERT_EQUAL((int32_t)16*1024, rej->length); } void BtPieceMessageTest::testCancelSendingPieceEvent_invalidate() { diff -uwrN aria2-0.10.2+1.orig/test/BtRejectMessageTest.cc aria2-0.10.2+1/test/BtRejectMessageTest.cc --- aria2-0.10.2+1.orig/test/BtRejectMessageTest.cc Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/test/BtRejectMessageTest.cc Mon Apr 16 11:35:16 2007 @@ -98,9 +98,9 @@ PeerMessageUtil::setIntParam(&msg[13], 1024); BtRejectMessageHandle pm = BtRejectMessage::create(&msg[4], 13); CPPUNIT_ASSERT_EQUAL((int8_t)16, pm->getId()); - CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex()); - CPPUNIT_ASSERT_EQUAL(256, pm->getBegin()); - CPPUNIT_ASSERT_EQUAL(1024, pm->getLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)256, pm->getBegin()); + CPPUNIT_ASSERT_EQUAL((int32_t)1024, pm->getLength()); // case: payload size is wrong try { diff -uwrN aria2-0.10.2+1.orig/test/BtRequestMessageTest.cc aria2-0.10.2+1/test/BtRequestMessageTest.cc --- aria2-0.10.2+1.orig/test/BtRequestMessageTest.cc Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/test/BtRequestMessageTest.cc Mon Apr 16 11:35:16 2007 @@ -132,9 +132,9 @@ PeerMessageUtil::setIntParam(&msg[13], 1024); BtRequestMessageHandle pm = BtRequestMessage::create(&msg[4], 13); CPPUNIT_ASSERT_EQUAL((int8_t)6, pm->getId()); - CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex()); - CPPUNIT_ASSERT_EQUAL(256, pm->getBegin()); - CPPUNIT_ASSERT_EQUAL(1024, pm->getLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)256, pm->getBegin()); + CPPUNIT_ASSERT_EQUAL((int32_t)1024, pm->getLength()); // case: payload size is wrong try { @@ -174,9 +174,9 @@ CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher->messageQueue.size()); MockBtMessage2* pieceMsg = (MockBtMessage2*)dispatcher->messageQueue.front().get(); CPPUNIT_ASSERT_EQUAL(string("piece"), pieceMsg->type); - CPPUNIT_ASSERT_EQUAL(1, pieceMsg->index); - CPPUNIT_ASSERT_EQUAL(16, pieceMsg->begin); - CPPUNIT_ASSERT_EQUAL(32, pieceMsg->length); + CPPUNIT_ASSERT_EQUAL((int32_t)1, pieceMsg->index); + CPPUNIT_ASSERT_EQUAL((int32_t)16, pieceMsg->begin); + CPPUNIT_ASSERT_EQUAL((int32_t)32, pieceMsg->length); } void BtRequestMessageTest::testDoReceivedAction_hasPieceAndAmChokingAndFastExtensionEnabled() { @@ -187,9 +187,9 @@ CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher->messageQueue.size()); MockBtMessage2* pieceMsg = (MockBtMessage2*)dispatcher->messageQueue.front().get(); CPPUNIT_ASSERT_EQUAL(string("reject"), pieceMsg->type); - CPPUNIT_ASSERT_EQUAL(1, pieceMsg->index); - CPPUNIT_ASSERT_EQUAL(16, pieceMsg->begin); - CPPUNIT_ASSERT_EQUAL(32, pieceMsg->length); + CPPUNIT_ASSERT_EQUAL((int32_t)1, pieceMsg->index); + CPPUNIT_ASSERT_EQUAL((int32_t)16, pieceMsg->begin); + CPPUNIT_ASSERT_EQUAL((int32_t)32, pieceMsg->length); } void BtRequestMessageTest::testDoReceivedAction_hasPieceAndAmChokingAndFastExtensionDisabled() { @@ -208,9 +208,9 @@ CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher->messageQueue.size()); MockBtMessage2* pieceMsg = (MockBtMessage2*)dispatcher->messageQueue.front().get(); CPPUNIT_ASSERT_EQUAL(string("reject"), pieceMsg->type); - CPPUNIT_ASSERT_EQUAL(2, pieceMsg->index); - CPPUNIT_ASSERT_EQUAL(16, pieceMsg->begin); - CPPUNIT_ASSERT_EQUAL(32, pieceMsg->length); + CPPUNIT_ASSERT_EQUAL((int32_t)2, pieceMsg->index); + CPPUNIT_ASSERT_EQUAL((int32_t)16, pieceMsg->begin); + CPPUNIT_ASSERT_EQUAL((int32_t)32, pieceMsg->length); } void BtRequestMessageTest::testDoReceivedAction_doesntHavePieceAndFastExtensionDisabled() { diff -uwrN aria2-0.10.2+1.orig/test/BtSuggestPieceMessageTest.cc aria2-0.10.2+1/test/BtSuggestPieceMessageTest.cc --- aria2-0.10.2+1.orig/test/BtSuggestPieceMessageTest.cc Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/test/BtSuggestPieceMessageTest.cc Mon Apr 16 11:35:16 2007 @@ -31,7 +31,7 @@ PeerMessageUtil::setIntParam(&msg[5], 12345); BtSuggestPieceMessageHandle pm = BtSuggestPieceMessage::create(&msg[4], 5); CPPUNIT_ASSERT_EQUAL((int8_t)13, pm->getId()); - CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); // case: payload size is wrong try { diff -uwrN aria2-0.10.2+1.orig/test/ChunkChecksumValidatorTest.cc aria2-0.10.2+1/test/ChunkChecksumValidatorTest.cc --- aria2-0.10.2+1.orig/test/ChunkChecksumValidatorTest.cc Wed Jan 24 07:55:34 2007 +++ aria2-0.10.2+1/test/ChunkChecksumValidatorTest.cc Mon Apr 16 11:35:16 2007 @@ -35,6 +35,7 @@ "0a4ea2f7dd7c52ddf2099a444ab2184b4d341bdb" }; void ChunkChecksumValidatorTest::testValidate() { +#ifdef ENABLE_MESSAGE_DIGEST BitfieldMan bitfieldMan(100, 250); bitfieldMan.setAllBit(); Strings checksums(&csArray[0], &csArray[3]); @@ -56,9 +57,11 @@ CPPUNIT_ASSERT(bitfieldMan.isBitSet(0)); CPPUNIT_ASSERT(!bitfieldMan.isBitSet(1)); CPPUNIT_ASSERT(bitfieldMan.isBitSet(2)); +#endif /* ENABLE_MESSAGE_DIGEST */ } void ChunkChecksumValidatorTest::testValidate2() { +#ifdef ENABLE_MESSAGE_DIGEST BitfieldMan bitfieldMan(50, 250); bitfieldMan.setAllBit(); Strings checksums(&csArray[0], &csArray[3]); @@ -81,9 +84,11 @@ CPPUNIT_ASSERT(!bitfieldMan.isBitSet(2)); CPPUNIT_ASSERT(!bitfieldMan.isBitSet(3)); CPPUNIT_ASSERT(bitfieldMan.isBitSet(4)); +#endif /* ENABLE_MESSAGE_DIGEST */ } void ChunkChecksumValidatorTest::testValidate3() { +#ifdef ENABLE_MESSAGE_DIGEST BitfieldMan bitfieldMan(50, 250); bitfieldMan.setAllBit(); Strings checksums; @@ -108,9 +113,11 @@ CPPUNIT_ASSERT(!bitfieldMan.isBitSet(2)); CPPUNIT_ASSERT(!bitfieldMan.isBitSet(3)); CPPUNIT_ASSERT(!bitfieldMan.isBitSet(4)); +#endif /* ENABLE_MESSAGE_DIGEST */ } void ChunkChecksumValidatorTest::testValidate4() { +#ifdef ENABLE_MESSAGE_DIGEST BitfieldMan bitfieldMan(70, 250); bitfieldMan.setAllBit(); Strings checksums(&csArray[0], &csArray[3]); @@ -132,4 +139,5 @@ CPPUNIT_ASSERT(!bitfieldMan.isBitSet(1)); CPPUNIT_ASSERT(!bitfieldMan.isBitSet(2)); CPPUNIT_ASSERT(bitfieldMan.isBitSet(3)); +#endif /* ENABLE_MESSAGE_DIGEST */ } diff -uwrN aria2-0.10.2+1.orig/test/DefaultBtContextTest.cc aria2-0.10.2+1/test/DefaultBtContextTest.cc --- aria2-0.10.2+1.orig/test/DefaultBtContextTest.cc Sat Dec 23 22:25:21 2006 +++ aria2-0.10.2+1/test/DefaultBtContextTest.cc Mon Apr 16 11:35:16 2007 @@ -54,7 +54,7 @@ string correctHash = "248d0a1cd08284299de78d5c1ed359bb46717d8c"; - CPPUNIT_ASSERT_EQUAL(20, btContext.getInfoHashLength()); + CPPUNIT_ASSERT_EQUAL((int32_t)20, btContext.getInfoHashLength()); CPPUNIT_ASSERT_EQUAL(correctHash, Util::toHex(btContext.getInfoHash(), btContext.getInfoHashLength())); } @@ -208,7 +208,7 @@ DefaultBtContext btContext; btContext.load("test.torrent"); - CPPUNIT_ASSERT_EQUAL(128, + CPPUNIT_ASSERT_EQUAL((int32_t)128, btContext.getPieceLength()); } diff -uwrN aria2-0.10.2+1.orig/test/DefaultBtMessageDispatcherTest.cc aria2-0.10.2+1/test/DefaultBtMessageDispatcherTest.cc --- aria2-0.10.2+1.orig/test/DefaultBtMessageDispatcherTest.cc Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/test/DefaultBtMessageDispatcherTest.cc Mon Apr 16 11:35:16 2007 @@ -370,7 +370,7 @@ void DefaultBtMessageDispatcherTest::testCountOutstandingRequest() { RequestSlot slot(0, 0, MY_PIECE_LENGTH, 0); btMessageDispatcher->addOutstandingRequest(slot); - CPPUNIT_ASSERT_EQUAL(1, btMessageDispatcher->countOutstandingRequest()); + CPPUNIT_ASSERT_EQUAL((int32_t)1, btMessageDispatcher->countOutstandingRequest()); } void DefaultBtMessageDispatcherTest::testIsOutstandingRequest() { diff -uwrN aria2-0.10.2+1.orig/test/DefaultDiskWriterTest.cc aria2-0.10.2+1/test/DefaultDiskWriterTest.cc --- aria2-0.10.2+1.orig/test/DefaultDiskWriterTest.cc Wed Jan 24 07:55:34 2007 +++ aria2-0.10.2+1/test/DefaultDiskWriterTest.cc Mon Apr 16 11:35:16 2007 @@ -25,11 +25,15 @@ DefaultDiskWriter dw; dw.openExistingFile("4096chunk.txt"); +#if defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) + CPPUNIT_ASSERT_EQUAL(string("608cabc0f2fa18c260cafd974516865c772363d5"), dw.messageDigest(0, 4096, DIGEST_ALGO_SHA1)); CPPUNIT_ASSERT_EQUAL(string("7a4a9ae537ebbbb826b1060e704490ad0f365ead"), dw.messageDigest(5, 100, DIGEST_ALGO_SHA1)); + +#endif /* defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) */ dw.closeFile(); } diff -uwrN aria2-0.10.2+1.orig/test/FileTest.cc aria2-0.10.2+1/test/FileTest.cc --- aria2-0.10.2+1.orig/test/FileTest.cc Sun Nov 5 07:04:17 2006 +++ aria2-0.10.2+1/test/FileTest.cc Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/test/MultiDiskAdaptorTest.cc aria2-0.10.2+1/test/MultiDiskAdaptorTest.cc --- aria2-0.10.2+1.orig/test/MultiDiskAdaptorTest.cc Wed Jan 24 07:55:34 2007 +++ aria2-0.10.2+1/test/MultiDiskAdaptorTest.cc Mon Apr 16 11:35:16 2007 @@ -9,7 +9,9 @@ CPPUNIT_TEST_SUITE(MultiDiskAdaptorTest); CPPUNIT_TEST(testWriteData); CPPUNIT_TEST(testReadData); +#if defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) CPPUNIT_TEST(testMessageDigest); +#endif /* defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) */ CPPUNIT_TEST_SUITE_END(); private: Option* option; @@ -30,7 +32,9 @@ void testWriteData(); void testReadData(); +#if defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) void testMessageDigest(); +#endif /* defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) */ }; @@ -134,6 +138,8 @@ CPPUNIT_ASSERT_EQUAL(string("1234567890ABCDEFGHIJKLMNO"), string((char*)buf)); } +#if defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) + void MultiDiskAdaptorTest::testMessageDigest() { FileEntryHandle entry1(new FileEntry("file1r.txt", 15, 0)); FileEntryHandle entry2(new FileEntry("file2r.txt", 7, 15)); @@ -154,3 +160,5 @@ CPPUNIT_ASSERT_EQUAL(string("6238bf61dd8df8f77156b2378e9e39cd3939680c"), sha1sum); adaptor->closeFile(); } + +#endif /* defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) */ diff -uwrN aria2-0.10.2+1.orig/test/MultiDiskWriterTest.cc aria2-0.10.2+1/test/MultiDiskWriterTest.cc --- aria2-0.10.2+1.orig/test/MultiDiskWriterTest.cc Wed Jan 24 07:55:34 2007 +++ aria2-0.10.2+1/test/MultiDiskWriterTest.cc Mon Apr 16 11:35:16 2007 @@ -1,6 +1,11 @@ +#include "common.h" #include "MultiDiskWriter.h" #include #include + +#ifdef HAVE_IO_H +# include +#endif // HAVE_IO_H using namespace std; diff -uwrN aria2-0.10.2+1.orig/test/PeerMessageUtilTest.cc aria2-0.10.2+1/test/PeerMessageUtilTest.cc --- aria2-0.10.2+1.orig/test/PeerMessageUtilTest.cc Sat Dec 23 23:10:43 2006 +++ aria2-0.10.2+1/test/PeerMessageUtilTest.cc Mon Apr 16 11:35:16 2007 @@ -1,5 +1,8 @@ +#include "common.h" #include "PeerMessageUtil.h" +#ifdef HAVE_NETINET_IN_H #include +#endif // HAVE_NETINET_IN_H #include using namespace std; diff -uwrN aria2-0.10.2+1.orig/test/SegmentManTest.cc aria2-0.10.2+1/test/SegmentManTest.cc --- aria2-0.10.2+1.orig/test/SegmentManTest.cc Sat Mar 24 07:32:49 2007 +++ aria2-0.10.2+1/test/SegmentManTest.cc Mon Apr 16 11:35:16 2007 @@ -146,7 +146,7 @@ SegmentHandle segment = segmentMan.getSegment(0, 5); CPPUNIT_ASSERT(!segment.isNull()); CPPUNIT_ASSERT_EQUAL(5, segment->index); - CPPUNIT_ASSERT_EQUAL(pieceLength, segment->length); - CPPUNIT_ASSERT_EQUAL(pieceLength, segment->segmentLength); + CPPUNIT_ASSERT_EQUAL(pieceLength, (int32_t) segment->length); + CPPUNIT_ASSERT_EQUAL(pieceLength, (int32_t) segment->segmentLength); CPPUNIT_ASSERT_EQUAL(100, segment->writtenLength); } diff -uwrN aria2-0.10.2+1.orig/test/ShaVisitorTest.cc aria2-0.10.2+1/test/ShaVisitorTest.cc --- aria2-0.10.2+1.orig/test/ShaVisitorTest.cc Sun Nov 5 07:04:17 2006 +++ aria2-0.10.2+1/test/ShaVisitorTest.cc Mon Apr 16 11:35:16 2007 @@ -1,4 +1,7 @@ +#if defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) #include "ShaVisitor.h" +#endif /* defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) */ + #include "MetaFileUtil.h" #include #include @@ -8,8 +11,11 @@ class ShaVisitorTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ShaVisitorTest); +#if defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) CPPUNIT_TEST(testVisit); CPPUNIT_TEST(testVisitCompound); +#endif /* defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) */ + CPPUNIT_TEST_SUITE_END(); private: @@ -35,6 +41,8 @@ return h; } +#if defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) + void ShaVisitorTest::testVisit() { ShaVisitor v; Data d("test", 4); @@ -58,3 +66,5 @@ CPPUNIT_ASSERT_EQUAL(string("36a58c6ab3eb02caa952f4345f57fabb06a39511"), hashHex); } + +#endif /* defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) */ diff -uwrN aria2-0.10.2+1.orig/test/SharedHandleTest.cc aria2-0.10.2+1/test/SharedHandleTest.cc --- aria2-0.10.2+1.orig/test/SharedHandleTest.cc Thu Mar 15 08:07:18 2007 +++ aria2-0.10.2+1/test/SharedHandleTest.cc Mon Apr 16 11:35:16 2007 @@ -34,21 +34,21 @@ cerr << "xh:" << endl; SharedHandle xh = new int(1); - CPPUNIT_ASSERT_EQUAL(1, xh.getRefCount()->totalRefCount); - CPPUNIT_ASSERT_EQUAL(1, xh.getRefCount()->strongRefCount); + CPPUNIT_ASSERT_EQUAL((int32_t)1, xh.getRefCount()->totalRefCount); + CPPUNIT_ASSERT_EQUAL((int32_t)1, xh.getRefCount()->strongRefCount); cerr << "nullHandle:" << endl; SharedHandle nullHandle = 0; - CPPUNIT_ASSERT_EQUAL(1, nullHandle.getRefCount()->totalRefCount); - CPPUNIT_ASSERT_EQUAL(1, nullHandle.getRefCount()->strongRefCount); + CPPUNIT_ASSERT_EQUAL((int32_t)1, nullHandle.getRefCount()->totalRefCount); + CPPUNIT_ASSERT_EQUAL((int32_t)1, nullHandle.getRefCount()->strongRefCount); cerr << "staticHandle:" << endl; - CPPUNIT_ASSERT_EQUAL(1, staticHandle.getRefCount()->totalRefCount); - CPPUNIT_ASSERT_EQUAL(1, staticHandle.getRefCount()->strongRefCount); + CPPUNIT_ASSERT_EQUAL((int32_t)1, staticHandle.getRefCount()->totalRefCount); + CPPUNIT_ASSERT_EQUAL((int32_t)1, staticHandle.getRefCount()->strongRefCount); SharedHandle localStaticHandle = getInstance(); - CPPUNIT_ASSERT_EQUAL(2, localStaticHandle.getRefCount()->totalRefCount); - CPPUNIT_ASSERT_EQUAL(2, localStaticHandle.getRefCount()->strongRefCount); + CPPUNIT_ASSERT_EQUAL((int32_t)2, localStaticHandle.getRefCount()->totalRefCount); + CPPUNIT_ASSERT_EQUAL((int32_t)2, localStaticHandle.getRefCount()->strongRefCount); } diff -uwrN aria2-0.10.2+1.orig/test/SingletonHolderTest.cc aria2-0.10.2+1/test/SingletonHolderTest.cc --- aria2-0.10.2+1.orig/test/SingletonHolderTest.cc Sun Mar 18 08:42:34 2007 +++ aria2-0.10.2+1/test/SingletonHolderTest.cc Mon Apr 16 11:35:16 2007 @@ -1,3 +1,4 @@ +#include #include "SingletonHolder.h" #include "SharedHandle.h" #include diff -uwrN aria2-0.10.2+1.orig/test/TimeSeedCriteriaTest.cc aria2-0.10.2+1/test/TimeSeedCriteriaTest.cc --- aria2-0.10.2+1.orig/test/TimeSeedCriteriaTest.cc Sun Aug 27 05:49:17 2006 +++ aria2-0.10.2+1/test/TimeSeedCriteriaTest.cc Mon Apr 16 11:35:16 2007 @@ -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 -uwrN aria2-0.10.2+1.orig/test/UtilTest.cc aria2-0.10.2+1/test/UtilTest.cc --- aria2-0.10.2+1.orig/test/UtilTest.cc Mon Mar 26 05:16:57 2007 +++ aria2-0.10.2+1/test/UtilTest.cc Mon Apr 16 11:35:16 2007 @@ -15,9 +15,13 @@ CPPUNIT_TEST(testStartsWith); // may be moved to other helper class in the future. CPPUNIT_TEST(testGetContentDispositionFilename); +#ifdef ENABLE_BITTORRENT CPPUNIT_TEST(testComputeFastSet); +#endif CPPUNIT_TEST(testRandomAlpha); +#ifdef ENABLE_MESSAGE_DIGEST CPPUNIT_TEST(testFileChecksum); +#endif CPPUNIT_TEST(testToUpper); CPPUNIT_TEST(testToLower); CPPUNIT_TEST(testUrldecode); @@ -36,11 +40,15 @@ void testEndsWith(); void testReplace(); void testStartsWith(); +#ifdef ENABLE_BITTORRENT void testComputeFastSet(); +#endif // may be moved to other helper class in the future. void testGetContentDispositionFilename(); void testRandomAlpha(); +#ifdef ENABLE_MESSAGE_DIGEST void testFileChecksum(); +#endif void testToUpper(); void testToLower(); void testUrldecode(); @@ -209,6 +217,8 @@ } }; +#ifdef ENABLE_BITTORRENT + void UtilTest::testComputeFastSet() { string ipaddr = "192.168.0.1"; unsigned char infoHash[20]; @@ -232,10 +242,14 @@ CPPUNIT_ASSERT(equal(fastSet.begin(), fastSet.end(), ansSet2.begin())); } +#endif + void UtilTest::testRandomAlpha() { CPPUNIT_ASSERT_EQUAL(string("rUopvKRn"), Util::randomAlpha(8)); } +#ifdef ENABLE_MESSAGE_DIGEST + void UtilTest::testFileChecksum() { unsigned char buf[20]; string filename = "4096chunk.txt"; @@ -250,6 +264,8 @@ md5); } +#endif + void UtilTest::testToUpper() { string src = "608cabc0f2fa18c260cafd974516865c772363d5"; string upp = "608CABC0F2FA18C260CAFD974516865C772363D5"; @@ -288,8 +304,8 @@ } void UtilTest::testCountBit() { - CPPUNIT_ASSERT_EQUAL(32, Util::countBit(UINT32_MAX)); - CPPUNIT_ASSERT_EQUAL(8, Util::countBit(255)); + CPPUNIT_ASSERT_EQUAL((int32_t)32, Util::countBit(UINT32_MAX)); + CPPUNIT_ASSERT_EQUAL((int32_t)8, Util::countBit(255)); } void UtilTest::testGetRealSize() diff -uwrN aria2-0.10.2+1.orig/test/Xml2MetalinkProcessorTest.cc aria2-0.10.2+1/test/Xml2MetalinkProcessorTest.cc --- aria2-0.10.2+1.orig/test/Xml2MetalinkProcessorTest.cc Sun Jan 28 06:18:35 2007 +++ aria2-0.10.2+1/test/Xml2MetalinkProcessorTest.cc Mon Apr 16 11:35:16 2007 @@ -37,9 +37,11 @@ CPPUNIT_ASSERT_EQUAL(string("0.5.2"), entry1->version); CPPUNIT_ASSERT_EQUAL(string("en-US"), entry1->language); CPPUNIT_ASSERT_EQUAL(string("Linux-x86"), entry1->os); +#if defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) CPPUNIT_ASSERT_EQUAL(string("a96cf3f0266b91d87d5124cf94326422800b627d"), entry1->checksum.getMessageDigest()); CPPUNIT_ASSERT(DIGEST_ALGO_SHA1 == entry1->checksum.getDigestAlgo()); +#endif /* defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) */ MetalinkResources::iterator resourceItr1 = entry1->resources.begin(); MetalinkResourceHandle resource1 = *resourceItr1; @@ -64,6 +66,7 @@ CPPUNIT_ASSERT_EQUAL(string("0.5.1"), entry2->version); CPPUNIT_ASSERT_EQUAL(string("ja-JP"), entry2->language); CPPUNIT_ASSERT_EQUAL(string("Linux-m68k"), entry2->os); +#if defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) CPPUNIT_ASSERT_EQUAL(string("4c255b0ed130f5ea880f0aa061c3da0487e251cc"), entry2->checksum.getMessageDigest()); CPPUNIT_ASSERT_EQUAL((size_t)2, entry2->chunkChecksum->pieceHashes.size()); @@ -74,6 +77,7 @@ entry2->chunkChecksum->pieceHashes.at(1)); CPPUNIT_ASSERT(DIGEST_ALGO_SHA1 == entry2->checksum.getDigestAlgo()); +#endif /* defined(HAVE_LIBSSL) || defined(HAVE_LIBGCRYPT) */ } catch(Exception* e) { CPPUNIT_FAIL(e->getMsg()); delete e;