diff -uwrN aria2-0.11.1+1.orig/ChangeLog aria2-0.11.1+1/ChangeLog --- aria2-0.11.1+1.orig/ChangeLog 2007-07-26 21:44:04.205000000 -0700 +++ aria2-0.11.1+1/ChangeLog 2007-07-26 21:44:19.455000000 -0700 @@ -1,3 +1,56 @@ +2007-07-26 Ross Smith II + + MinGW build enhancements. The following files are added: + * src/gai_strerror.{c,h} + * src/gettimeofday.{c,h} + + Changes to support the above new files: + * configure.ac + * src/Makefile.am + * src/a2netcompat.h + * src/TimeA2.cc + * src/DefaultPeerStorage.cc + * src/NameResolver.cc: removed mingw_strerror() function. + * src/SocketCore.cc: removed mingw_strerror() function. + + Miscellaneous MinGW build fixes. + * src/a2io.h: Use _lseeki64() instead of lseek() + * src/common.h + * src/DefaultFileAllocator.cc + * src/GlowFileAllocator.cc + * src/main.cc: Moved #include "prefs.h" to quiet compile error. + * src/NameResolver.cc + (callback): Changed int32_t to int. + (resolve): Changed int32_t to int. + * src/Platform.cc + * src/Platform.h + * test/MultiDiskWriterTest.cc + * test/PeerMessageUtilTest.cc + * src/localtime_r.c: Add DeleteCriticalSection() and atexit(). + + Other enhancements and fixes. + * src/HttpRequestCommand.cc + (executeInternal) Use non-blocking socket for HTTPS (MinGW only). + * src/SocketCore.cc: + (error): New function to abstract errno/WSAGetLastError(). + (errorMsg): New function to abstract errno/WSAGetLastError(). + (initiateSecureConnection): Added more detailed error reporting. + * src/SocketCore.h: Added private variable blocking, to allow + proper handling of OpenSSL psuedo-errors. + * src/message.h + (EX_SSL_INIT_FAILURE) + (EX_SSL_IO_ERROR) + (EX_SSL_PROTOCOL_ERROR) + (EX_SSL_UNKNOWN_ERROR) + (EX_SSL_CONNECT_ERROR) + (EX_SOCKET_BLOCKING) + (EX_SOCKET_NONBLOCKING) + (EX_SOCKET_UNKNOWN_ERROR) + * src/Util.cc + (setGlobalSignalHandler): Renamed signal to sig as signal is a + reserved name. + (httpGMT): Fixed typo. + 2007-07-23 Tatsuhiro Tsujikawa Merged Ross's win32 patch(manually) diff -uwrN aria2-0.11.1+1.orig/configure.ac aria2-0.11.1+1/configure.ac --- aria2-0.11.1+1.orig/configure.ac 2007-07-26 21:44:04.251875000 -0700 +++ aria2-0.11.1+1/configure.ac 2007-07-26 21:44:19.455000000 -0700 @@ -127,21 +127,34 @@ AM_GNU_GETTEXT_VERSION(0.12.1) AC_FUNC_ERROR_AT_LINE +case "$target" in + *mingw*) + ;; + *) AC_FUNC_MALLOC + AC_FUNC_REALLOC + ;; +esac + AC_FUNC_MEMCMP AC_FUNC_MMAP -AC_FUNC_REALLOC AC_FUNC_SELECT_ARGTYPES AC_FUNC_STAT AC_FUNC_VPRINTF -AC_CHECK_FUNCS([__argz_count __argz_next __argz_stringify 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 timegm usleep]) +AC_CHECK_FUNCS([__argz_count __argz_next __argz_stringify daemon ftruncate getcwd getpagesize 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 timegm usleep]) AC_CHECK_FUNCS([basename], [AM_CONDITIONAL([HAVE_BASENAME], true)], [AM_CONDITIONAL([HAVE_BASENAME], false)]) +AC_CHECK_FUNCS([gai_strerror], + [AM_CONDITIONAL([HAVE_GAI_STRERROR], true)], + [AM_CONDITIONAL([HAVE_GAI_STRERROR], false)]) AC_CHECK_FUNCS([getaddrinfo], [AM_CONDITIONAL([HAVE_GETADDRINFO], true)], [AM_CONDITIONAL([HAVE_GETADDRINFO], false)]) +AC_CHECK_FUNCS([gettimeofday], + [AM_CONDITIONAL([HAVE_GETTIMEOFDAY], true)], + [AM_CONDITIONAL([HAVE_GETTIMEOFDAY], false)]) AC_CHECK_FUNCS([inet_aton], [AM_CONDITIONAL([HAVE_INET_ATON], true)], [AM_CONDITIONAL([HAVE_INET_ATON], false)]) diff -uwrN aria2-0.11.1+1.orig/src/DefaultFileAllocator.cc aria2-0.11.1+1/src/DefaultFileAllocator.cc --- aria2-0.11.1+1.orig/src/DefaultFileAllocator.cc 2007-03-24 07:32:49.000000000 -0700 +++ aria2-0.11.1+1/src/DefaultFileAllocator.cc 2007-07-26 21:44:19.470625000 -0700 @@ -35,6 +35,7 @@ #include "DefaultFileAllocator.h" #include "DlAbortEx.h" #include "TimeA2.h" +#include "a2io.h" #include #include #include diff -uwrN aria2-0.11.1+1.orig/src/DefaultPeerStorage.cc aria2-0.11.1+1/src/DefaultPeerStorage.cc --- aria2-0.11.1+1.orig/src/DefaultPeerStorage.cc 2007-07-26 21:44:04.501875000 -0700 +++ aria2-0.11.1+1/src/DefaultPeerStorage.cc 2007-07-26 21:44:19.470625000 -0700 @@ -37,6 +37,10 @@ #include "BtRegistry.h" #include "message.h" +#ifndef HAVE_GETTIMEOFDAY +#include "gettimeofday.h" +#endif // HAVE_GETTIMEOFDAY + DefaultPeerStorage::DefaultPeerStorage(BtContextHandle btContext, const Option* option): btContext(btContext), diff -uwrN aria2-0.11.1+1.orig/src/GlowFileAllocator.cc aria2-0.11.1+1/src/GlowFileAllocator.cc --- aria2-0.11.1+1.orig/src/GlowFileAllocator.cc 2007-03-24 07:32:49.000000000 -0700 +++ aria2-0.11.1+1/src/GlowFileAllocator.cc 2007-07-26 21:44:19.517500000 -0700 @@ -35,6 +35,7 @@ #include "GlowFileAllocator.h" #include "DlAbortEx.h" #include "TimeA2.h" +#include "a2io.h" #include #include #include diff -uwrN aria2-0.11.1+1.orig/src/HttpRequestCommand.cc aria2-0.11.1+1/src/HttpRequestCommand.cc --- aria2-0.11.1+1.orig/src/HttpRequestCommand.cc 2007-05-20 06:51:52.000000000 -0700 +++ aria2-0.11.1+1/src/HttpRequestCommand.cc 2007-07-26 21:44:19.580000000 -0700 @@ -52,6 +52,10 @@ bool HttpRequestCommand::executeInternal() { socket->setBlockingMode(); if(req->getProtocol() == "https") { +#ifdef __MINGW32__ + // it only works in non-blocking mode + socket->setNonBlockingMode(); +#endif // __MINGW32__ socket->initiateSecureConnection(); } if(!e->option->getAsBool(PREF_HTTP_KEEP_ALIVE)) { diff -uwrN aria2-0.11.1+1.orig/src/Makefile.am aria2-0.11.1+1/src/Makefile.am --- aria2-0.11.1+1.orig/src/Makefile.am 2007-07-26 21:44:04.658125000 -0700 +++ aria2-0.11.1+1/src/Makefile.am 2007-07-26 21:44:19.533125000 -0700 @@ -235,6 +235,18 @@ SRCS += getaddrinfo.c getaddrinfo.h endif # !HAVE_GETADDRINFO +if !HAVE_GAI_STRERROR +SRCS += gai_strerror.c gai_strerror.h +endif # !HAVE_GAI_STRERROR + +if !HAVE_GETTIMEOFDAY +SRCS += gettimeofday.c gettimeofday.h +endif # !HAVE_GETTIMEOFDAY + +if !HAVE_GETTIMEOFDAY +SRCS += gettimeofday.c gettimeofday.h +endif # !HAVE_GETTIMEOFDAY + if !HAVE_INET_ATON SRCS += inet_aton.c inet_aton.h endif # !HAVE_INET_ATON diff -uwrN aria2-0.11.1+1.orig/src/NameResolver.cc aria2-0.11.1+1/src/NameResolver.cc --- aria2-0.11.1+1.orig/src/NameResolver.cc 2007-07-26 21:44:04.705000000 -0700 +++ aria2-0.11.1+1/src/NameResolver.cc 2007-07-26 21:44:19.533125000 -0700 @@ -33,10 +33,11 @@ */ /* copyright --> */ #include "NameResolver.h" +#include "a2netcompat.h" #ifdef ENABLE_ASYNC_DNS -void callback(void* arg, int32_t status, struct hostent* host) { +void callback(void* arg, int status, struct hostent* host) { NameResolver* resolverPtr = (NameResolver*)arg; #ifdef HAVE_LIBARES // This block is required since the assertion in ares_strerror fails @@ -65,6 +66,31 @@ #include "DlAbortEx.h" #include "message.h" +#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 NameResolver::resolve(const string& hostname) { memset(&_addr, 0, sizeof(in_addr)); @@ -75,7 +101,7 @@ ai.ai_socktype = SOCK_STREAM; ai.ai_protocol = 0; struct addrinfo* res; - int32_t ec; + int ec; if((ec = getaddrinfo(hostname.c_str(), 0, &ai, &res)) != 0) { throw new DlAbortEx(EX_RESOLVE_HOSTNAME, hostname.c_str(), gai_strerror(ec)); diff -uwrN aria2-0.11.1+1.orig/src/Platform.cc aria2-0.11.1+1/src/Platform.cc --- aria2-0.11.1+1.orig/src/Platform.cc 2007-07-26 21:44:04.783125000 -0700 +++ aria2-0.11.1+1/src/Platform.cc 2007-07-26 21:44:19.533125000 -0700 @@ -37,27 +37,22 @@ #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 "common.h" +#include "a2netcompat.h" #include "DlAbortEx.h" +#include "Platform.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 } + +#endif // HAVE_WINSOCK2_H diff -uwrN aria2-0.11.1+1.orig/src/Platform.h aria2-0.11.1+1/src/Platform.h --- aria2-0.11.1+1.orig/src/Platform.h 2007-07-26 21:44:04.814375000 -0700 +++ aria2-0.11.1+1/src/Platform.h 2007-07-26 21:44:19.533125000 -0700 @@ -35,6 +35,12 @@ #ifndef _D_PLATFORM_H_ #define _D_PLATFORM_H_ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif // HAVE_CONFIG_H + +#ifdef HAVE_WINSOCK2_H + class Platform { public: Platform(); @@ -42,4 +48,6 @@ ~Platform(); }; +#endif // HAVE_WINSOCK2_H + #endif // _D_PLATFORM_H_ diff -uwrN aria2-0.11.1+1.orig/src/SocketCore.cc aria2-0.11.1+1/src/SocketCore.cc --- aria2-0.11.1+1.orig/src/SocketCore.cc 2007-07-26 21:44:04.908125000 -0700 +++ aria2-0.11.1+1/src/SocketCore.cc 2007-07-26 21:44:19.564375000 -0700 @@ -42,30 +42,12 @@ #include #include #include +#include -#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 - +#ifndef __MINGW32__ +# define SOCKET_ERRNO (errno) +#else +# define SOCKET_ERRNO (WSAGetLastError()) #endif // __MINGW32__ SocketCore::SocketCore():sockfd(-1) { @@ -78,6 +60,7 @@ void SocketCore::init() { use = 1; + blocking = true; secure = false; #ifdef HAVE_LIBSSL // for SSL @@ -105,13 +88,17 @@ //sockfd = socket(AF_UNSPEC, SOCK_STREAM, PF_UNSPEC); sockfd = socket(AF_INET, SOCK_STREAM, 0); if(sockfd == -1) { - throw new DlAbortEx(EX_SOCKET_OPEN, strerror(errno)); + throw new DlAbortEx(EX_SOCKET_OPEN, errorMsg()); } SOCKOPT_T sockopt = 1; if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(socklen_t)) < 0) { +#ifdef __MINGW32__ + ::closesocket(sockfd); +#else close(sockfd); +#endif // __MINGW32__ sockfd = -1; - throw new DlAbortEx(EX_SOCKET_SET_OPT, strerror(errno)); + throw new DlAbortEx(EX_SOCKET_SET_OPT, errorMsg()); } struct sockaddr_in sockaddr; @@ -121,11 +108,11 @@ sockaddr.sin_port = htons(port); if(bind(sockfd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) == -1) { - throw new DlAbortEx(EX_SOCKET_BIND, strerror(errno)); + throw new DlAbortEx(EX_SOCKET_BIND, errorMsg()); } if(listen(sockfd, 1) == -1) { - throw new DlAbortEx(EX_SOCKET_LISTEN, strerror(errno)); + throw new DlAbortEx(EX_SOCKET_LISTEN, errorMsg()); } setNonBlockingMode(); @@ -137,7 +124,7 @@ memset((char*)&sockaddr, 0, sizeof(sockaddr)); int32_t fd; if((fd = accept(sockfd, (struct sockaddr*)&sockaddr, &len)) == -1) { - throw new DlAbortEx(EX_SOCKET_ACCEPT, strerror(errno)); + throw new DlAbortEx(EX_SOCKET_ACCEPT, errorMsg()); } SocketCore* s = new SocketCore(fd); @@ -149,7 +136,7 @@ memset((char*)&listenaddr, 0, sizeof(listenaddr)); socklen_t len = sizeof(listenaddr); if(getsockname(sockfd, (struct sockaddr*)&listenaddr, &len) == -1) { - throw new DlAbortEx(EX_SOCKET_GET_NAME, strerror(errno)); + throw new DlAbortEx(EX_SOCKET_GET_NAME, errorMsg()); } addrinfo.first = inet_ntoa(listenaddr.sin_addr); addrinfo.second = ntohs(listenaddr.sin_port); @@ -160,7 +147,7 @@ memset(&peerin, 0, sizeof(peerin)); int32_t len = sizeof(peerin); if(getpeername(sockfd, (struct sockaddr*)&peerin, (socklen_t*)&len) < 0) { - throw new DlAbortEx(EX_SOCKET_GET_PEER, strerror(errno)); + throw new DlAbortEx(EX_SOCKET_GET_PEER, errorMsg()); } peerinfo.first = inet_ntoa(peerin.sin_addr); peerinfo.second = ntohs(peerin.sin_port); @@ -170,13 +157,13 @@ closeConnection(); sockfd = socket(AF_INET, SOCK_STREAM, 0); if(sockfd == -1) { - throw new DlAbortEx(EX_SOCKET_OPEN, strerror(errno)); + throw new DlAbortEx(EX_SOCKET_OPEN, errorMsg()); } SOCKOPT_T sockopt = 1; if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(socklen_t)) < 0) { close(sockfd); sockfd = -1; - throw new DlAbortEx(EX_SOCKET_SET_OPT, strerror(errno)); + throw new DlAbortEx(EX_SOCKET_SET_OPT, errorMsg()); } struct sockaddr_in sockaddr; @@ -203,23 +190,27 @@ } // make socket non-blocking mode setNonBlockingMode(); - if(connect(sockfd, (struct sockaddr*)&sockaddr, (socklen_t)sizeof(sockaddr)) == -1 && errno != EINPROGRESS) { - throw new DlAbortEx(EX_SOCKET_CONNECT, host.c_str(), strerror(errno)); + if(connect(sockfd, (struct sockaddr*)&sockaddr, (socklen_t)sizeof(sockaddr)) == -1 && SOCKET_ERRNO != EINPROGRESS) { + throw new DlAbortEx(EX_SOCKET_CONNECT, host.c_str(), errorMsg()); } } -void SocketCore::setNonBlockingMode() const { +void SocketCore::setNonBlockingMode() { #ifdef __MINGW32__ u_long flag = 0; ::ioctlsocket(sockfd, FIONBIO, &flag); + if (WSAGetLastError()) { + throw new DlAbortEx(EX_SOCKET_NONBLOCKING, errorMsg()); + } #else int32_t flags = fcntl(sockfd, F_GETFL, 0); // TODO add error handling fcntl(sockfd, F_SETFL, flags|O_NONBLOCK); #endif // __MINGW32__ + blocking = false; } -void SocketCore::setBlockingMode() const { +void SocketCore::setBlockingMode() { #ifdef __MINGW32__ u_long flag = 1; ::ioctlsocket(sockfd, FIONBIO, &flag); @@ -228,6 +219,7 @@ // TODO add error handling fcntl(sockfd, F_SETFL, flags&(~O_NONBLOCK)); #endif // __MINGW32__ + blocking = true; } void SocketCore::closeConnection() { @@ -243,7 +235,11 @@ } #endif // HAVE_LIBGNUTLS if(sockfd != -1) { +#ifdef __MINGW32__ + ::closesocket(sockfd); +#else close(sockfd); +#endif // __MINGW32__ sockfd = -1; } #ifdef HAVE_LIBSSL @@ -277,10 +273,10 @@ // time out return false; } else { - if(errno == EINPROGRESS || errno == EINTR) { + if(SOCKET_ERRNO == EINPROGRESS || SOCKET_ERRNO == EINTR) { return false; } else { - throw new DlRetryEx(EX_SOCKET_CHECK_WRITABLE, strerror(errno)); + throw new DlRetryEx(EX_SOCKET_CHECK_WRITABLE, errorMsg()); } } } @@ -306,91 +302,84 @@ // time out return false; } else { - if(errno == EINPROGRESS || errno == EINTR) { + if(SOCKET_ERRNO == EINPROGRESS || SOCKET_ERRNO == EINTR) { return false; } else { - throw new DlRetryEx(EX_SOCKET_CHECK_READABLE, strerror(errno)); + throw new DlRetryEx(EX_SOCKET_CHECK_READABLE, errorMsg()); } } } void SocketCore::writeData(const char* data, int32_t len) { int32_t ret = 0; - if(!secure && (ret = send(sockfd, data, (size_t)len, 0)) != len + + if(!secure) { + if((ret = send(sockfd, data, (size_t)len, 0)) != len) { + throw new DlRetryEx(EX_SOCKET_SEND, errorMsg()); + } + } else { #ifdef HAVE_LIBSSL // for SSL // TODO handling len == 0 case required - || secure && (ret = SSL_write(ssl, data, len)) != len + if((ret = SSL_write(ssl, data, len)) != len) { + throw new DlRetryEx(EX_SOCKET_SEND, ERR_error_string(ERR_get_error(), NULL)); + } #endif // HAVE_LIBSSL #ifdef HAVE_LIBGNUTLS - || secure && (ret = gnutls_record_send(sslSession, data, len)) != len -#endif // HAVE_LIBGNUTLS - ) { - const char* errorMsg; -#ifdef HAVE_LIBGNUTLS - if(secure) { - errorMsg = gnutls_strerror(ret); - } else { - errorMsg = strerror(errno); + if((ret = gnutls_record_send(sslSession, data, len)) == len) { + throw new DlRetryEx(EX_SOCKET_SEND, gnutls_strerror(ret)); } -#else // HAVE_LIBGNUTLS - errorMsg = strerror(errno); -#endif - throw new DlRetryEx(EX_SOCKET_SEND, errorMsg); +#endif // HAVE_LIBGNUTLS } } void SocketCore::readData(char* data, int32_t& len) { int32_t ret = 0; - if(!secure && (ret = recv(sockfd, data, (size_t)len, 0)) < 0 + + if(!secure) { + if ((ret = recv(sockfd, data, (size_t)len, 0)) < 0) { + throw new DlRetryEx(EX_SOCKET_RECV, errorMsg()); + } + } else { #ifdef HAVE_LIBSSL // for SSL // TODO handling len == 0 case required - || secure && (ret = SSL_read(ssl, data, len)) < 0 + if ((ret = SSL_read(ssl, data, len)) < 0) { + throw new DlRetryEx(EX_SOCKET_RECV, ERR_error_string(ERR_get_error(), NULL)); + } #endif // HAVE_LIBSSL #ifdef HAVE_LIBGNUTLS - || secure && (ret = gnutlsRecv(data, len)) < 0 -#endif // HAVE_LIBGNUTLS - ) { - const char* errorMsg; -#ifdef HAVE_LIBGNUTLS - if(secure) { - errorMsg = gnutls_strerror(ret); - } else { - errorMsg = strerror(errno); + if ((ret = gnutlsRecv(data, len)) < 0) { + throw new DlRetryEx(EX_SOCKET_RECV, gnutls_strerror(ret)); } -#else // HAVE_LIBGNUTLS - errorMsg = strerror(errno); -#endif - throw new DlRetryEx(EX_SOCKET_RECV, errorMsg); +#endif // HAVE_LIBGNUTLS } + len = ret; } void SocketCore::peekData(char* data, int32_t& len) { int32_t ret = 0; - if(!secure && (ret = recv(sockfd, data, (size_t)len, MSG_PEEK)) < 0 + + if(!secure) { + if ((ret = recv(sockfd, data, (size_t)len, MSG_PEEK)) < 0) { + throw new DlRetryEx(EX_SOCKET_PEEK, errorMsg()); + } + } else { #ifdef HAVE_LIBSSL // for SSL // TODO handling len == 0 case required - || secure && (ret = SSL_peek(ssl, data, len)) < 0 + if ((ret = SSL_peek(ssl, data, len)) < 0) { + throw new DlRetryEx(EX_SOCKET_PEEK, ERR_error_string(ERR_get_error(), NULL)); + } #endif // HAVE_LIBSSL #ifdef HAVE_LIBGNUTLS - || secure && (ret = gnutlsPeek(data, len)) < 0 -#endif // HAVE_LIBGNUTLS - ) { - const char* errorMsg; -#ifdef HAVE_LIBGNUTLS - if(secure) { - errorMsg = gnutls_strerror(ret); - } else { - errorMsg = strerror(errno); + if ((ret = gnutlsPeek(data, len)) < 0) { + throw new DlRetryEx(EX_SOCKET_PEEK, gnutls_strerror(ret)); } -#else // HAVE_LIBGNUTLS - errorMsg = strerror(errno); -#endif - throw new DlRetryEx(EX_SOCKET_PEEK, errorMsg); +#endif // HAVE_LIBGNUTLS } + len = ret; } @@ -460,21 +449,44 @@ if(!secure) { sslCtx = SSL_CTX_new(SSLv23_client_method()); if(sslCtx == NULL) { - throw new DlAbortEx(EX_SSL_INIT_FAILURE); + throw new DlAbortEx(EX_SSL_INIT_FAILURE, ERR_error_string(ERR_get_error(), NULL)); } SSL_CTX_set_mode(sslCtx, SSL_MODE_AUTO_RETRY); ssl = SSL_new(sslCtx); if(ssl == NULL) { - throw new DlAbortEx(EX_SSL_INIT_FAILURE); + throw new DlAbortEx(EX_SSL_INIT_FAILURE, ERR_error_string(ERR_get_error(), NULL)); } if(SSL_set_fd(ssl, sockfd) == 0) { - throw new DlAbortEx(EX_SSL_INIT_FAILURE); + throw new DlAbortEx(EX_SSL_INIT_FAILURE, ERR_error_string(ERR_get_error(), NULL)); } // TODO handling return value == 0 case required - if(SSL_connect(ssl) <= 0) { - throw new DlAbortEx(EX_SSL_INIT_FAILURE); + int e = SSL_connect(ssl); + + if (e <= 0) { + int ssl_error = SSL_get_error(ssl, e); + switch(ssl_error) { + case SSL_ERROR_NONE: + break; + + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_WRITE: + case SSL_ERROR_WANT_X509_LOOKUP: + case SSL_ERROR_ZERO_RETURN: + if (blocking) { + throw new DlAbortEx(EX_SSL_CONNECT_ERROR, ssl_error); + } + break; + + case SSL_ERROR_SYSCALL: + throw new DlAbortEx(EX_SSL_IO_ERROR); + + case SSL_ERROR_SSL: + throw new DlAbortEx(EX_SSL_PROTOCOL_ERROR); + + default: + throw new DlAbortEx(EX_SSL_UNKNOWN_ERROR, ssl_error); + } } - secure = true; } #endif // HAVE_LIBSSL #ifdef HAVE_LIBGNUTLS @@ -493,9 +505,39 @@ gnutls_transport_set_ptr(sslSession, (gnutls_transport_ptr_t)sockfd); int32_t ret = gnutls_handshake(sslSession); if(ret < 0) { - throw new DlAbortEx(gnutls_strerror(ret)); + throw new DlAbortEx(EX_SSL_INIT_FAILURE, gnutls_strerror(ret)); } - secure = true; } #endif // HAVE_LIBGNUTLS + + secure = true; +} + +/* static */ int SocketCore::error() { + return SOCKET_ERRNO; +} + +/* static */ const char *SocketCore::errorMsg() { + return errorMsg(SOCKET_ERRNO); +} + +/* static */ const char *SocketCore::errorMsg(const int err) { +#ifndef __MINGW32__ + return strerror(err); +#else + static char buf[256]; + 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), EX_SOCKET_UNKNOWN_ERROR, err, err); + } + return buf; +#endif // __MINGW32__ } diff -uwrN aria2-0.11.1+1.orig/src/SocketCore.h aria2-0.11.1+1/src/SocketCore.h --- aria2-0.11.1+1.orig/src/SocketCore.h 2007-07-26 21:44:04.908125000 -0700 +++ aria2-0.11.1+1/src/SocketCore.h 2007-07-26 21:44:19.564375000 -0700 @@ -58,6 +58,7 @@ int32_t sockfd; // reference counter for this object. int32_t use; + bool blocking; bool secure; #ifdef HAVE_LIBSSL // for SSL @@ -79,6 +80,9 @@ void init(); SocketCore(int32_t sockfd); + static int error(); + static const char *errorMsg(); + static const char *errorMsg(const int err); public: SocketCore(); ~SocketCore(); @@ -123,12 +127,12 @@ */ void establishConnection(const string& host, int32_t port); - void setNonBlockingMode() const; + void setNonBlockingMode(); /** * Makes this socket blocking mode. */ - void setBlockingMode() const; + void setBlockingMode(); /** * Closes the connection of this socket. @@ -207,6 +211,5 @@ bool operator<(const SocketCore& s) { return sockfd < s.sockfd; } - }; #endif // _D_SOCKET_CORE_H_ diff -uwrN aria2-0.11.1+1.orig/src/TimeA2.cc aria2-0.11.1+1/src/TimeA2.cc --- aria2-0.11.1+1.orig/src/TimeA2.cc 2007-07-26 21:44:04.923750000 -0700 +++ aria2-0.11.1+1/src/TimeA2.cc 2007-07-26 21:44:19.548750000 -0700 @@ -32,9 +32,14 @@ * files in the program, then also delete it here. */ /* copyright --> */ + #include "TimeA2.h" #include "Util.h" +#ifndef HAVE_GETTIMEOFDAY +#include "gettimeofday.h" +#endif // HAVE_GETTIMEOFDAY + Time::Time() { reset(); } diff -uwrN aria2-0.11.1+1.orig/src/Util.cc aria2-0.11.1+1/src/Util.cc --- aria2-0.11.1+1.orig/src/Util.cc 2007-07-26 21:44:04.970625000 -0700 +++ aria2-0.11.1+1/src/Util.cc 2007-07-26 21:57:18.470625000 -0700 @@ -644,13 +644,13 @@ } } -void Util::setGlobalSignalHandler(int32_t signal, void (*handler)(int32_t), int32_t flags) { +void Util::setGlobalSignalHandler(int32_t sig, void (*handler)(int32_t), int32_t 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 @@ -728,7 +728,7 @@ time_t thetime = mktime(&tm); if (tz) { char s[256]; - sprintf("TZ=%s", tz); + snprintf(s, sizeof(s), "TZ=%s", tz); putenv(s); } tzset(); diff -uwrN aria2-0.11.1+1.orig/src/a2io.h aria2-0.11.1+1/src/a2io.h --- aria2-0.11.1+1.orig/src/a2io.h 2007-07-26 21:44:04.986250000 -0700 +++ aria2-0.11.1+1/src/a2io.h 2007-07-26 21:44:19.455000000 -0700 @@ -109,8 +109,8 @@ # define DEV_STDOUT "/dev/stdout" #endif // HAVE_WINSOCK2_H - #ifdef __MINGW32__ +# define lseek(a, b, c) _lseeki64((a), (b), (c)) # define a2mkdir(path, openMode) mkdir(path) #else # define a2mkdir(path, openMode) mkdir(path, openMode) diff -uwrN aria2-0.11.1+1.orig/src/a2netcompat.h aria2-0.11.1+1/src/a2netcompat.h --- aria2-0.11.1+1.orig/src/a2netcompat.h 2007-07-26 21:44:04.986250000 -0700 +++ aria2-0.11.1+1/src/a2netcompat.h 2007-07-26 21:44:19.455000000 -0700 @@ -58,16 +58,30 @@ # include "inet_aton.h" #endif // HAVE_INET_ATON -#ifdef __MINGW32__ +#ifdef HAVE_WINSOCK2_H +#ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x501 +#endif // _WIN32_WINNT # include # undef ERROR +#endif // HAVE_WINSOCK2_H + +#ifdef HAVE_WS2TCPIP_H # include +#endif // HAVE_WS2TCPIP_H + +#ifdef __MINGW32__ # define SOCKOPT_T const char # define HAVE_GETADDRINFO +# undef HAVE_GETADDRINFO #else # define SOCKOPT_T socklen_t #endif // __MINGW32__ +#ifndef HAVE_GAI_STRERROR +# include "gai_strerror.h" +#endif // HAVE_GAI_STRERROR + #ifndef HAVE_GETADDRINFO # include "getaddrinfo.h" #endif // HAVE_GETADDRINFO diff -uwrN aria2-0.11.1+1.orig/src/common.h aria2-0.11.1+1/src/common.h --- aria2-0.11.1+1.orig/src/common.h 2007-07-26 21:44:04.986250000 -0700 +++ aria2-0.11.1+1/src/common.h 2007-07-26 21:44:19.455000000 -0700 @@ -39,6 +39,16 @@ #ifdef HAVE_CONFIG_H # include #endif + +#ifdef __MINGW32__ +#ifdef malloc +# undef malloc +#endif +#ifdef realloc +# undef realloc +#endif +#endif // __MINGW32__ + #include #include #include @@ -83,12 +93,6 @@ #define DIR_OPEN_MODE S_IRWXU|S_IRWXG|S_IRWXO #ifdef __MINGW32__ -# ifndef _WIN32_WINNT -# define _WIN32_WINNT 0x501 -# endif // _WIN32_WINNT -#endif // __MINGW32__ - -#ifdef __MINGW32__ # define LONGLONG_PRINTF "%I64d" # define ULONGLONG_PRINTF "%I64u" # define LONGLONG_SCANF "%I64d" diff -uwrN aria2-0.11.1+1.orig/src/gai_strerror.c aria2-0.11.1+1/src/gai_strerror.c --- aria2-0.11.1+1.orig/src/gai_strerror.c 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.11.1+1/src/gai_strerror.c 2007-07-26 21:44:19.470625000 -0700 @@ -0,0 +1,103 @@ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef ENABLE_NLS +#include +#endif + +#include "gai_strerror.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") +}; + +/* + * gai_strerror(). + */ +const char * +gai_strerror(ecode) + int ecode; +{ + if (ecode < 0 || ecode > EAI_SYSTEM) + return _("Unknown error"); + + return gettext(eai_errlist[ecode]); +} diff -uwrN aria2-0.11.1+1.orig/src/gai_strerror.h aria2-0.11.1+1/src/gai_strerror.h --- aria2-0.11.1+1.orig/src/gai_strerror.h 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.11.1+1/src/gai_strerror.h 2007-07-26 21:44:19.486250000 -0700 @@ -0,0 +1,167 @@ +/* + * 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 + +/********************************************************************/ +/* + * 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) || defined(HAVE_GAI_STRERROR) +#define gai_strerror my_gai_strerror +#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 + +/* + * Functions. + */ +#ifdef __STDC__ +const char *gai_strerror(int); +#else +const char *gai_strerror(); +#endif + +#ifdef __cplusplus +}; +#endif /* __cplusplus */ + +#endif /* not _D_GETADDRINFO_H */ diff -uwrN aria2-0.11.1+1.orig/src/gettimeofday.c aria2-0.11.1+1/src/gettimeofday.c --- aria2-0.11.1+1.orig/src/gettimeofday.c 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.11.1+1/src/gettimeofday.c 2007-07-26 21:44:19.486250000 -0700 @@ -0,0 +1,55 @@ +/* source: cygwin-1.5.24-2-src/cygwin-1.5.24-2/winsup/mingw/mingwex/gettimeofday.c */ + +/* + * gettimeofday + * Implementation according to: + * The Open Group Base Specifications Issue 6 + * IEEE Std 1003.1, 2004 Edition + */ + +/* + * THIS SOFTWARE IS NOT COPYRIGHTED + * + * This source code is offered for use in the public domain. You may + * use, modify or distribute it freely. + * + * This code is distributed in the hope that it will be useful but + * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY + * DISCLAIMED. This includes but is not limited to warranties of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Contributed by: + * Danny Smith + */ + +#include + +#ifdef __MINGW32__ + +#define WIN32_LEAN_AND_MEAN +#include + +/* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */ +#define _W32_FT_OFFSET (116444736000000000ULL) + + +int __cdecl gettimeofday(struct timeval *__restrict__ tp, + void *__restrict__ tzp __attribute__((unused))) + { + union { + unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */ + FILETIME ft; + } _now; + + if(tp) + { + GetSystemTimeAsFileTime (&_now.ft); + tp->tv_usec=(long)((_now.ns100 / 10ULL) % 1000000ULL ); + tp->tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000ULL); + } + /* Always return 0 as per Open Group Base Specifications Issue 6. + Do not set errno on error. */ + return 0; +} + +#endif // __MINGW32__ diff -uwrN aria2-0.11.1+1.orig/src/gettimeofday.h aria2-0.11.1+1/src/gettimeofday.h --- aria2-0.11.1+1.orig/src/gettimeofday.h 1969-12-31 16:00:00.000000000 -0800 +++ aria2-0.11.1+1/src/gettimeofday.h 2007-07-26 21:44:19.517500000 -0700 @@ -0,0 +1,57 @@ +/* */ + +#ifndef _D_GETTIMEOFDAY_H +#define _D_GETTIMEOFDAY_H 1 + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifndef HAVE_GETTIMEOFDAY + +int __cdecl gettimeofday(struct timeval *__restrict__ tp, + void *__restrict__ tzp __attribute__((unused))); + +#endif // HAVE_GETTIMEOFDAY + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* not _D_GETTIMEOFDAY_H */ + diff -uwrN aria2-0.11.1+1.orig/src/localtime_r.c aria2-0.11.1+1/src/localtime_r.c --- aria2-0.11.1+1.orig/src/localtime_r.c 2007-07-26 21:44:05.033125000 -0700 +++ aria2-0.11.1+1/src/localtime_r.c 2007-07-26 21:44:19.517500000 -0700 @@ -34,28 +34,42 @@ /* copyright --> */ #include + #include #ifdef __MINGW32__ +#define WIN32_LEAN_AND_MEAN #include #endif // __MINGW32__ #include "localtime_r.h" +#ifdef __MINGW32__ + +static CRITICAL_SECTION localtime_r_cs; + +static void localtime_r_atexit() +{ + DeleteCriticalSection(&localtime_r_cs); +} + +#endif // __MINGW32__ + struct tm * localtime_r(const time_t *clock, struct tm *result) { static struct tm *local_tm; #ifdef __MINGW32__ - static CRITICAL_SECTION cs; static int initialized = 0; if (!initialized) { ++initialized; - InitializeCriticalSection(&cs); + InitializeCriticalSection(&localtime_r_cs); + atexit(localtime_r_atexit); } - EnterCriticalSection(&cs); + EnterCriticalSection(&localtime_r_cs); local_tm = localtime(clock); memcpy(result, local_tm, sizeof(struct tm)); - LeaveCriticalSection(&cs); + LeaveCriticalSection(&localtime_r_cs); #endif // __MINGW32__ return result; }; + diff -uwrN aria2-0.11.1+1.orig/src/main.cc aria2-0.11.1+1/src/main.cc --- aria2-0.11.1+1.orig/src/main.cc 2007-07-26 21:44:05.048750000 -0700 +++ aria2-0.11.1+1/src/main.cc 2007-07-26 21:44:19.517500000 -0700 @@ -35,7 +35,6 @@ #include "common.h" #include "LogFactory.h" #include "Util.h" -#include "prefs.h" #include "FeatureConfig.h" #include "MultiUrlRequestInfo.h" #include "TorrentRequestInfo.h" @@ -56,6 +55,7 @@ #include "message.h" #include "a2io.h" #include "Platform.h" +#include "prefs.h" #include #include #include diff -uwrN aria2-0.11.1+1.orig/src/message.h aria2-0.11.1+1/src/message.h --- aria2-0.11.1+1.orig/src/message.h 2007-07-26 21:44:05.064375000 -0700 +++ aria2-0.11.1+1/src/message.h 2007-07-26 21:44:19.564375000 -0700 @@ -138,7 +138,11 @@ #define EX_BAD_STATUS _("The response status is not successful. status=%d") #define EX_TOO_LARGE_FILE _("Too large file size. size=%s") #define EX_TRANSFER_ENCODING_NOT_SUPPORTED _("Transfer encoding %s is not supported.") -#define EX_SSL_INIT_FAILURE _("SSL initialization failed.") +#define EX_SSL_INIT_FAILURE _("SSL initialization failed: %s") +#define EX_SSL_IO_ERROR _("SSL I/O error") +#define EX_SSL_PROTOCOL_ERROR _("SSL protocol error") +#define EX_SSL_UNKNOWN_ERROR _("SSL unknown error %d") +#define EX_SSL_CONNECT_ERROR _("SSL initialization failed: OpenSSL connect error %d") #define EX_SIZE_MISMATCH _("Size mismatch Expected:%s Actual:%s") #define EX_AUTH_FAILED _("Authorization failed.") #define EX_GOT_EOF _("Got EOF from the server.") @@ -160,6 +164,8 @@ #define EX_SOCKET_OPEN _("Failed to open a socket, cause: %s") #define EX_SOCKET_SET_OPT _("Failed to set a socket option, cause: %s") +#define EX_SOCKET_BLOCKING _("Failed to set a socket as blocking, cause: %s") +#define EX_SOCKET_NONBLOCKING _("Failed to set a socket as non-blocking, cause: %s") #define EX_SOCKET_BIND _("Failed to bind a socket, cause: %s") #define EX_SOCKET_LISTEN _("Failed to listen to a socket, cause: %s") #define EX_SOCKET_ACCEPT _("Failed to accept a peer connection, cause: %s") @@ -172,6 +178,7 @@ #define EX_SOCKET_SEND _("Failed to send data, cause: %s") #define EX_SOCKET_RECV _("Failed to receive data, cause: %s") #define EX_SOCKET_PEEK _("Failed to peek data, cause: %s") +#define EX_SOCKET_UNKNOWN_ERROR _("Unknown socket error %d (0x%x)") #define EX_FILE_ALREADY_EXISTS _("File %s exists, but %s does not exist.") #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.") diff -uwrN aria2-0.11.1+1.orig/test/MultiDiskWriterTest.cc aria2-0.11.1+1/test/MultiDiskWriterTest.cc --- aria2-0.11.1+1.orig/test/MultiDiskWriterTest.cc 2007-07-26 21:44:05.189375000 -0700 +++ aria2-0.11.1+1/test/MultiDiskWriterTest.cc 2007-07-26 21:44:19.548750000 -0700 @@ -1,12 +1,9 @@ #include "common.h" #include "MultiDiskWriter.h" +#include "a2io.h" #include #include -#ifdef HAVE_IO_H -# include -#endif // HAVE_IO_H - using namespace std; class MultiDiskWriterTest:public CppUnit::TestFixture { diff -uwrN aria2-0.11.1+1.orig/test/PeerMessageUtilTest.cc aria2-0.11.1+1/test/PeerMessageUtilTest.cc --- aria2-0.11.1+1.orig/test/PeerMessageUtilTest.cc 2007-07-26 21:44:05.189375000 -0700 +++ aria2-0.11.1+1/test/PeerMessageUtilTest.cc 2007-07-26 21:44:19.548750000 -0700 @@ -1,8 +1,6 @@ #include "common.h" #include "PeerMessageUtil.h" -#ifdef HAVE_NETINET_IN_H -#include -#endif // HAVE_NETINET_IN_H +#include "a2netcompat.h" #include using namespace std;