Applied aria2-1.0.0-mingw-r5.patch

pull/1/head
Ross Smith II 2008-11-22 20:28:50 +00:00
parent 5faa91e24c
commit 67d5d6d55e
11 changed files with 141 additions and 45 deletions

View File

@ -1,3 +1,30 @@
2008-11-22 Ross Smith II <aria2spam at smithii dot com>
Applied aria2-1.0.0-mingw-r5.patch to fix numerous compile/unit test
errors in MinGW:
Closed file after saving server stats (RequestGroupMan.cc)
Fixed time parsing if internal strptime() is missing (FtpConnection.cc)
Ignored case & handled 2-digit years (strptime.c)
Added missing suseconds_t definition (a2time.h)
Fixed socket CLOSE() define (SocketCore.cc)
Changed EINPROGRESS to A2_EINPROGRESS (SocketCore.cc)
Changed utime() test values from x000 to x00000 as MinGW failed on
values less than timezone offset from Unix epoch
Changed 'struct stat' to 'a2_struct_stat' (FileTest.cc)
Added waitRead() call prior to reading socket (FtpConnectionTest.cc)
Changed date from 01-Jan-1960 to 01-Jan-1970 00:00:01 as MinGW can't
handle negative dates (CookieParserTest.cc)
* src/a2time.h
* src/FtpConnection.cc
* src/RequestGroupMan.cc
* src/SocketCore.cc
* src/strptime.c
* test/CookieParserTest.cc
* test/CopyDiskAdaptorTest.cc
* test/FileTest.cc
* test/FtpConnectionTest.cc
* test/MultiDiskAdaptorTest.cc
2008-11-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed typo in "OPTIONS THAT TAKE AN OPTIONAL ARGUMENT" section.

View File

@ -367,7 +367,24 @@ unsigned int FtpConnection::receiveMdtmResponse(Time& time)
char buf[15]; // YYYYMMDDhhmmss+\0, milli second part is dropped.
sscanf(response.second.c_str(), "%*u %14s", buf);
if(strlen(buf) == 14) {
#ifdef HAVE_STRPTIME
time = Time::parse(buf, "%Y%m%d%H%M%S");
#else // !HAVE_STRPTIME
struct tm tm;
memset(&tm, 0, sizeof(tm));
tm.tm_sec = Util::parseInt(&buf[12]);
buf[12] = '\0';
tm.tm_min = Util::parseInt(&buf[10]);
buf[10] = '\0';
tm.tm_hour = Util::parseInt(&buf[8]);
buf[8] = '\0';
tm.tm_mday = Util::parseInt(&buf[6]);
buf[6] = '\0';
tm.tm_mon = Util::parseInt(&buf[4])-1;
buf[4] = '\0';
tm.tm_year = Util::parseInt(&buf[0])-1900;
time = Time(timegm(&tm));
#endif // !HAVE_STRPTIME
} else {
time = Time::null();
}

View File

@ -568,13 +568,15 @@ bool RequestGroupMan::saveServerStat(const std::string& filename) const
tempfile.c_str());
return false;
}
if(_serverStatMan->save(out) && File(tempfile).renameTo(filename)) {
_logger->notice(MSG_SERVER_STAT_SAVED, filename.c_str());
return true;
} else {
_logger->error(MSG_WRITING_SERVER_STAT_FILE_FAILED, filename.c_str());
return false;
if (_serverStatMan->save(out)) {
out.close();
if (File(tempfile).renameTo(filename)) {
_logger->notice(MSG_SERVER_STAT_SAVED, filename.c_str());
return true;
}
}
_logger->error(MSG_WRITING_SERVER_STAT_FILE_FAILED, filename.c_str());
return false;
}
void RequestGroupMan::removeStaleServerStat(time_t timeout)

View File

@ -69,7 +69,7 @@
#endif // __MINGW32__
#ifdef __MINGW32__
# define CLOSE(X) ::closesocket(sockfd)
# define CLOSE(X) ::closesocket(X)
#else
# define CLOSE(X) while(close(X) == -1 && errno == EINTR)
#endif // __MINGW32__
@ -399,7 +399,7 @@ bool SocketCore::isWritable(time_t timeout)
// time out
return false;
} else {
if(SOCKET_ERRNO == EINPROGRESS || SOCKET_ERRNO == EINTR) {
if(SOCKET_ERRNO == A2_EINPROGRESS || SOCKET_ERRNO == EINTR) {
return false;
} else {
throw DlRetryEx(StringFormat(EX_SOCKET_CHECK_WRITABLE, errorMsg()).str());
@ -452,7 +452,7 @@ bool SocketCore::isReadable(time_t timeout)
// time out
return false;
} else {
if(SOCKET_ERRNO == EINPROGRESS || SOCKET_ERRNO == EINTR) {
if(SOCKET_ERRNO == A2_EINPROGRESS || SOCKET_ERRNO == EINTR) {
return false;
} else {
throw DlRetryEx(StringFormat(EX_SOCKET_CHECK_READABLE, errorMsg()).str());

View File

@ -57,4 +57,8 @@
# include "asctime_r.h"
#endif // HAVE_ASCTIME_R
#ifdef __MINGW32__
# define suseconds_t uint64_t
#endif
#endif // _D_A2TIME_H_

View File

@ -236,25 +236,19 @@ _strptime (const char *buf, const char *format, struct tm *timeptr, int *gmt)
c = *++format;
switch (c) {
case 'A' :
case 'a' :
ret = match_string (&buf, full_weekdays);
if (ret < 0)
return NULL;
timeptr->tm_wday = ret;
break;
case 'a' :
ret = match_string (&buf, abb_weekdays);
if (ret < 0)
return NULL;
timeptr->tm_wday = ret;
break;
case 'B' :
ret = match_string (&buf, full_month);
if (ret < 0)
return NULL;
timeptr->tm_mon = ret;
break;
case 'b' :
case 'h' :
ret = match_string (&buf, full_month);
if (ret < 0)
ret = match_string (&buf, abb_month);
if (ret < 0)
return NULL;
@ -420,7 +414,18 @@ _strptime (const char *buf, const char *format, struct tm *timeptr, int *gmt)
ret = strtol (buf, &s, 10);
if (s == buf)
return NULL;
if (ret < 70)
/*
* y represents stricty 2 digits, raise error if more than 3
* digits are parsed.
*/
if (ret > 99) {
return NULL;
}
/*
* The value in the range 69-99 refer to years in 20th century.
* The value in the range 00-68 refer to years in 21st century.
*/
if (ret < 69)
timeptr->tm_year = 100 + ret;
else
timeptr->tm_year = ret;
@ -492,10 +497,5 @@ strptime (const char *buf, const char *format, struct tm *timeptr)
gmt = 0;
ret = _strptime(buf, format, timeptr, &gmt);
if (ret && gmt) {
time_t t = timegm(timeptr);
localtime_r(&t, timeptr);
}
return (ret);
}

View File

@ -52,11 +52,17 @@ void CookieParserTest::testParse()
c = CookieParser().parse(str3);
CPPUNIT_ASSERT(!c.good());
#ifndef __MINGW32__
std::string str4 = "UID=300; expires=Wed, 01-Jan-1960 00:00:00 GMT";
time_t expire_time = (time_t) -315619200;
#else
std::string str4 = "UID=300; expires=Wed, 01-Jan-1970 00:00:01 GMT";
time_t expire_time = (time_t) 1;
#endif
c = CookieParser().parse(str4, "localhost", "/");
CPPUNIT_ASSERT(c.good());
CPPUNIT_ASSERT(!c.isSessionCookie());
CPPUNIT_ASSERT_EQUAL((time_t)-315619200, c.getExpiry());
CPPUNIT_ASSERT_EQUAL(expire_time, c.getExpiry());
std::string str5 = "k=v; expires=Sun, 10-Jun-07 11:00:00 GMT";
c = CookieParser().parse(str5);

View File

@ -59,21 +59,24 @@ void CopyDiskAdaptorTest::testUtime()
createFile(prefix+"/"+entries[3]->getPath(), entries[3]->getLength());
createFile(prefix+"/"+entries[4]->getPath(), entries[4]->getLength());
CPPUNIT_ASSERT_EQUAL((size_t)2, adaptor.utime(Time(1000), Time(2000)));
time_t atime = (time_t) 100000;
time_t mtime = (time_t) 200000;
CPPUNIT_ASSERT_EQUAL((time_t)2000,
CPPUNIT_ASSERT_EQUAL((size_t)2, adaptor.utime(Time(atime), Time(mtime)));
CPPUNIT_ASSERT_EQUAL((time_t)mtime,
File(prefix+"/"+entries[0]->getPath())
.getModifiedTime().getTime());
CPPUNIT_ASSERT_EQUAL((time_t)2000,
CPPUNIT_ASSERT_EQUAL((time_t)mtime,
File(prefix+"/"+entries[4]->getPath())
.getModifiedTime().getTime());
CPPUNIT_ASSERT((time_t)2000 != File(prefix+"/"+entries[1]->getPath())
CPPUNIT_ASSERT((time_t)mtime != File(prefix+"/"+entries[1]->getPath())
.getModifiedTime().getTime());
CPPUNIT_ASSERT((time_t)2000 != File(prefix+"/"+entries[2]->getPath())
CPPUNIT_ASSERT((time_t)mtime != File(prefix+"/"+entries[2]->getPath())
.getModifiedTime().getTime());
CPPUNIT_ASSERT((time_t)2000 != File(prefix+"/"+entries[3]->getPath())
CPPUNIT_ASSERT((time_t)mtime != File(prefix+"/"+entries[3]->getPath())
.getModifiedTime().getTime());
}

View File

@ -215,16 +215,20 @@ void FileTest::testUtime()
{
File f("/tmp/FileTest_testUTime");
createFile(f.getPath(), 0);
CPPUNIT_ASSERT(f.utime(Time(1000), Time(2000)));
struct stat buf;
time_t atime = (time_t) 100000;
time_t mtime = (time_t) 200000;
CPPUNIT_ASSERT(f.utime(Time(atime), Time(mtime)));
a2_struct_stat buf;
CPPUNIT_ASSERT(0 == stat(f.getPath().c_str(), &buf));
CPPUNIT_ASSERT_EQUAL((time_t)1000, buf.st_atime);
CPPUNIT_ASSERT_EQUAL((time_t)2000, f.getModifiedTime().getTime());
CPPUNIT_ASSERT_EQUAL((time_t)atime, buf.st_atime);
CPPUNIT_ASSERT_EQUAL((time_t)mtime, f.getModifiedTime().getTime());
File notFound("/tmp/FileTest_testUTime_notFound");
notFound.remove();
CPPUNIT_ASSERT(!notFound.utime(Time(1000), Time(2000)));
CPPUNIT_ASSERT(!notFound.utime(Time(atime), Time(mtime)));
}
} // namespace aria2

View File

@ -34,6 +34,7 @@ class FtpConnectionTest:public CppUnit::TestFixture {
private:
SharedHandle<SocketCore> _serverSocket;
uint16_t _listenPort;
SharedHandle<SocketCore> _clientSocket;
SharedHandle<FtpConnection> _ftp;
SharedHandle<Option> _option;
SharedHandle<AuthConfigFactory> _authConfigFactory;
@ -54,14 +55,14 @@ public:
SharedHandle<Request> req(new Request());
req->setUrl("ftp://localhost/dir/file.img");
SharedHandle<SocketCore> clientSocket(new SocketCore());
clientSocket->establishConnection("127.0.0.1", _listenPort);
_clientSocket.reset(new SocketCore());
_clientSocket->establishConnection("127.0.0.1", _listenPort);
while(!clientSocket->isWritable(0));
clientSocket->setBlockingMode();
while(!_clientSocket->isWritable(0));
_clientSocket->setBlockingMode();
_serverSocket.reset(listenSocket->acceptConnection());
_ftp.reset(new FtpConnection(1, clientSocket, req,
_ftp.reset(new FtpConnection(1, _clientSocket, req,
_authConfigFactory->createAuthConfig(req),
_option.get()));
}
@ -83,35 +84,50 @@ public:
CPPUNIT_TEST_SUITE_REGISTRATION(FtpConnectionTest);
static void waitRead(const SharedHandle<SocketCore>& socket)
{
while(!socket->isReadable(0));
}
void FtpConnectionTest::testReceiveResponse()
{
_serverSocket->writeData("100");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)0, _ftp->receiveResponse());
_serverSocket->writeData(" single line response");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)0, _ftp->receiveResponse());
_serverSocket->writeData("\r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)100, _ftp->receiveResponse());
// 2 responses in the buffer
_serverSocket->writeData("101 single1\r\n"
"102 single2\r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)101, _ftp->receiveResponse());
CPPUNIT_ASSERT_EQUAL((unsigned int)102, _ftp->receiveResponse());
_serverSocket->writeData("103-multi line response\r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)0, _ftp->receiveResponse());
_serverSocket->writeData("103-line2\r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)0, _ftp->receiveResponse());
_serverSocket->writeData("103");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)0, _ftp->receiveResponse());
_serverSocket->writeData(" ");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)0, _ftp->receiveResponse());
_serverSocket->writeData("last\r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)103, _ftp->receiveResponse());
_serverSocket->writeData("104-multi\r\n"
"104 \r\n"
"105-multi\r\n"
"105 \r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)104, _ftp->receiveResponse());
CPPUNIT_ASSERT_EQUAL((unsigned int)105, _ftp->receiveResponse());
}
@ -132,8 +148,10 @@ void FtpConnectionTest::testReceiveMdtmResponse()
{
Time t;
_serverSocket->writeData("213 20080908124312");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)0, _ftp->receiveMdtmResponse(t));
_serverSocket->writeData("\r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)213, _ftp->receiveMdtmResponse(t));
CPPUNIT_ASSERT_EQUAL((time_t)1220877792, t.getTime());
}
@ -141,6 +159,7 @@ void FtpConnectionTest::testReceiveMdtmResponse()
// see milli second part is ignored
Time t;
_serverSocket->writeData("213 20080908124312.014\r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)213, _ftp->receiveMdtmResponse(t));
CPPUNIT_ASSERT_EQUAL((time_t)1220877792, t.getTime());
}
@ -148,19 +167,24 @@ void FtpConnectionTest::testReceiveMdtmResponse()
// hhmmss part is missing
Time t;
_serverSocket->writeData("213 20080908\r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)213, _ftp->receiveMdtmResponse(t));
CPPUNIT_ASSERT(t.bad());
}
{
#ifdef HAVE_STRPTIME
// invalid month: 19
Time t;
_serverSocket->writeData("213 20081908124312\r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)213, _ftp->receiveMdtmResponse(t));
CPPUNIT_ASSERT(t.bad());
#endif
}
{
Time t;
_serverSocket->writeData("550 File Not Found\r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)550, _ftp->receiveMdtmResponse(t));
}
}
@ -172,9 +196,11 @@ void FtpConnectionTest::testReceiveResponse_overflow()
memcpy(data, "213 ", 4);
for(int i = 0; i < 4; ++i) {
_serverSocket->writeData(data, sizeof(data));
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)0, _ftp->receiveResponse());
}
_serverSocket->writeData(data, sizeof(data));
waitRead(_clientSocket);
try {
_ftp->receiveResponse();
CPPUNIT_FAIL("exception must be thrown.");
@ -198,9 +224,11 @@ void FtpConnectionTest::testReceivePwdResponse()
{
std::string pwd;
_serverSocket->writeData("257 ");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)0, _ftp->receivePwdResponse(pwd));
CPPUNIT_ASSERT(pwd.empty());
_serverSocket->writeData("\"/dir/to\" is your directory.\r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)257, _ftp->receivePwdResponse(pwd));
CPPUNIT_ASSERT_EQUAL(std::string("/dir/to"), pwd);
}
@ -209,6 +237,7 @@ void FtpConnectionTest::testReceivePwdResponse_unquotedResponse()
{
std::string pwd;
_serverSocket->writeData("257 /dir/to\r\n");
waitRead(_clientSocket);
try {
_ftp->receivePwdResponse(pwd);
CPPUNIT_FAIL("exception must be thrown.");
@ -221,6 +250,7 @@ void FtpConnectionTest::testReceivePwdResponse_badStatus()
{
std::string pwd;
_serverSocket->writeData("500 failed\r\n");
waitRead(_clientSocket);
CPPUNIT_ASSERT_EQUAL((unsigned int)500, _ftp->receivePwdResponse(pwd));
CPPUNIT_ASSERT(pwd.empty());
}

View File

@ -364,17 +364,20 @@ void MultiDiskAdaptorTest::testUtime()
adaptor.setTopDir(topDir);
adaptor.setFileEntries(fileEntries);
CPPUNIT_ASSERT_EQUAL((size_t)2, adaptor.utime(Time(1000), Time(2000)));
time_t atime = (time_t) 100000;
time_t mtime = (time_t) 200000;
CPPUNIT_ASSERT_EQUAL((time_t)2000,
CPPUNIT_ASSERT_EQUAL((size_t)2, adaptor.utime(Time(atime), Time(mtime)));
CPPUNIT_ASSERT_EQUAL((time_t)mtime,
File(prefix+"/"+entries[0]->getPath())
.getModifiedTime().getTime());
CPPUNIT_ASSERT_EQUAL((time_t)2000,
CPPUNIT_ASSERT_EQUAL((time_t)mtime,
File(prefix+"/"+entries[3]->getPath())
.getModifiedTime().getTime());
CPPUNIT_ASSERT((time_t)2000 != File(prefix+"/"+entries[2]->getPath())
CPPUNIT_ASSERT((time_t)mtime != File(prefix+"/"+entries[2]->getPath())
.getModifiedTime().getTime());
}