mirror of https://github.com/aria2/aria2
2008-08-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
If a cookie whose expire date is later than 2038-01-19 03:14:07 GMT is sent from server, its expire date is assumed to 2038-01-19 03:14:07 GMT. If Util::httpGMT is failed, then Cookie::onetime is set to true. * src/Util.cc * src/Util.h * src/CookieParser.cc * test/UtilTest.cc * test/CookieParserTest.ccpull/1/head
parent
adfcf57e32
commit
0e6c0498a3
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
2008-08-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
If a cookie whose expire date is later than 2038-01-19 03:14:07 GMT is
|
||||||
|
sent from server, its expire date is assumed to 2038-01-19 03:14:07 GMT.
|
||||||
|
If Util::httpGMT is failed, then Cookie::onetime is set to true.
|
||||||
|
* src/Util.cc
|
||||||
|
* src/Util.h
|
||||||
|
* src/CookieParser.cc
|
||||||
|
* test/UtilTest.cc
|
||||||
|
* test/CookieParserTest.cc
|
||||||
|
|
||||||
2008-08-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2008-08-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Seprate the implementation to load old mozilla format of cookie to
|
Seprate the implementation to load old mozilla format of cookie to
|
||||||
|
|
|
@ -58,8 +58,15 @@ void CookieParser::setField(Cookie& cookie, const std::string& name, const std::
|
||||||
} else if(name == C_PATH) {
|
} else if(name == C_PATH) {
|
||||||
cookie.path = value;
|
cookie.path = value;
|
||||||
} else if(name == C_EXPIRES) {
|
} else if(name == C_EXPIRES) {
|
||||||
cookie.expires = Util::httpGMT(value);
|
time_t expires = Util::httpGMT(value);
|
||||||
|
if(expires == -1) {
|
||||||
|
// If parsing expire date is failed, it is assumed as a session scope
|
||||||
|
// cookie.
|
||||||
|
cookie.onetime = true;
|
||||||
|
} else {
|
||||||
|
cookie.expires = expires;
|
||||||
cookie.onetime = false;
|
cookie.onetime = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
cookie.name = name;
|
cookie.name = name;
|
||||||
cookie.value = value;
|
cookie.value = value;
|
||||||
|
|
10
src/Util.cc
10
src/Util.cc
|
@ -695,8 +695,16 @@ time_t Util::httpGMT(const std::string& httpStdTime)
|
||||||
{
|
{
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
memset(&tm, 0, sizeof(tm));
|
memset(&tm, 0, sizeof(tm));
|
||||||
strptime(httpStdTime.c_str(), "%a, %Y-%m-%d %H:%M:%S GMT", &tm);
|
char* r = strptime(httpStdTime.c_str(), "%a, %Y-%m-%d %H:%M:%S GMT", &tm);
|
||||||
|
if(r != httpStdTime.c_str()+httpStdTime.size()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
time_t thetime = timegm(&tm);
|
time_t thetime = timegm(&tm);
|
||||||
|
if(thetime == -1) {
|
||||||
|
if(tm.tm_year >= 2038-1900) {
|
||||||
|
thetime = INT32_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
return thetime;
|
return thetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,6 +209,14 @@ public:
|
||||||
|
|
||||||
static std::string abbrevSize(int64_t size);
|
static std::string abbrevSize(int64_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses given httpTimeFormat and returns seconds ellapsed since epoc.
|
||||||
|
* The available format is "%a, %Y-%m-%d %H:%M:%S GMT".
|
||||||
|
* If specified date is later than "Tue, 2038-01-19 3:14:7 GMT",
|
||||||
|
* this function returns INT32_MAX.
|
||||||
|
* This function also cannot handle prior 1900-1-1 0:0:0 GMT.
|
||||||
|
* If parse operation is failed, then return -1.
|
||||||
|
*/
|
||||||
static time_t httpGMT(const std::string& httpTimeFormat);
|
static time_t httpGMT(const std::string& httpTimeFormat);
|
||||||
|
|
||||||
static void toStream(std::ostream& os,
|
static void toStream(std::ostream& os,
|
||||||
|
|
|
@ -51,6 +51,11 @@ void CookieParserTest::testParse()
|
||||||
std::string str3 = "";
|
std::string str3 = "";
|
||||||
c = CookieParser().parse(str3);
|
c = CookieParser().parse(str3);
|
||||||
CPPUNIT_ASSERT(!c.good());
|
CPPUNIT_ASSERT(!c.good());
|
||||||
|
|
||||||
|
std::string str4 = "UID=300; expires=Wed, 1890-01-01 0:0:0 GMT;";
|
||||||
|
c = CookieParser().parse(str4, "localhost", "/");
|
||||||
|
CPPUNIT_ASSERT(c.good());
|
||||||
|
CPPUNIT_ASSERT(c.onetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CookieParserTest::testParse_file()
|
void CookieParserTest::testParse_file()
|
||||||
|
|
|
@ -45,6 +45,7 @@ class UtilTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testToString_binaryStream);
|
CPPUNIT_TEST(testToString_binaryStream);
|
||||||
CPPUNIT_TEST(testItos);
|
CPPUNIT_TEST(testItos);
|
||||||
CPPUNIT_TEST(testUitos);
|
CPPUNIT_TEST(testUitos);
|
||||||
|
CPPUNIT_TEST(testHttpGMT);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -83,6 +84,7 @@ public:
|
||||||
void testToString_binaryStream();
|
void testToString_binaryStream();
|
||||||
void testItos();
|
void testItos();
|
||||||
void testUitos();
|
void testUitos();
|
||||||
|
void testHttpGMT();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -668,4 +670,15 @@ void UtilTest::testUitos()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UtilTest::testHttpGMT()
|
||||||
|
{
|
||||||
|
CPPUNIT_ASSERT_EQUAL((time_t)0, Util::httpGMT("Thu, 1970-01-01 0:0:0 GMT"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL((time_t)2147483647,
|
||||||
|
Util::httpGMT("Tue, 2038-01-19 3:14:7 GMT"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL((time_t)2147483647,
|
||||||
|
Util::httpGMT("Tue, 2038-01-19 3:14:8 GMT"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL((time_t)-1,
|
||||||
|
Util::httpGMT("Tue, 2008/10/10 23:33:33 UTC"));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue