mirror of https://github.com/aria2/aria2
2010-01-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Replaced isNumberAndDotsNotation() with isNumericHost(). isNumericHost() can handle IPv6 address. * src/Cookie.cc * src/CookieStorage.cc * src/util.cc * src/util.h * test/CookieTest.cc * test/UtilTest.ccpull/1/head
parent
994d58a4a4
commit
eb4116ae57
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2010-01-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Replaced isNumberAndDotsNotation() with isNumericHost().
|
||||
isNumericHost() can handle IPv6 address.
|
||||
* src/Cookie.cc
|
||||
* src/CookieStorage.cc
|
||||
* src/util.cc
|
||||
* src/util.h
|
||||
* test/CookieTest.cc
|
||||
* test/UtilTest.cc
|
||||
|
||||
2010-01-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Included A2STR.h
|
||||
|
|
|
@ -56,7 +56,7 @@ static std::string prependDotIfNotExists(const std::string& domain)
|
|||
|
||||
std::string Cookie::normalizeDomain(const std::string& domain)
|
||||
{
|
||||
if(domain.empty() || util::isNumbersAndDotsNotation(domain)) {
|
||||
if(domain.empty() || util::isNumericHost(domain)) {
|
||||
return domain;
|
||||
}
|
||||
std::string md = prependDotIfNotExists(domain);
|
||||
|
|
|
@ -245,7 +245,7 @@ std::deque<Cookie> CookieStorage::criteriaFind(const std::string& requestHost,
|
|||
time_t date, bool secure)
|
||||
{
|
||||
std::deque<Cookie> res;
|
||||
bool numericHost = util::isNumbersAndDotsNotation(requestHost);
|
||||
bool numericHost = util::isNumericHost(requestHost);
|
||||
searchCookieByDomainSuffix
|
||||
((!numericHost && requestHost.find(A2STR::DOT_C) == std::string::npos)?
|
||||
requestHost+".local":requestHost,
|
||||
|
|
15
src/util.cc
15
src/util.cc
|
@ -664,13 +664,18 @@ std::string toLower(const std::string& src) {
|
|||
return temp;
|
||||
}
|
||||
|
||||
bool isNumbersAndDotsNotation(const std::string& name) {
|
||||
struct sockaddr_in sockaddr;
|
||||
if(inet_aton(name.c_str(), &sockaddr.sin_addr)) {
|
||||
return true;
|
||||
} else {
|
||||
bool isNumericHost(const std::string& name)
|
||||
{
|
||||
struct addrinfo hints;
|
||||
struct addrinfo* res;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
if(getaddrinfo(name.c_str(), 0, &hints, &res)) {
|
||||
return false;
|
||||
}
|
||||
freeaddrinfo(res);
|
||||
return true;
|
||||
}
|
||||
|
||||
void setGlobalSignalHandler(int sig, void (*handler)(int), int flags) {
|
||||
|
|
|
@ -222,7 +222,7 @@ std::string toUpper(const std::string& src);
|
|||
|
||||
std::string toLower(const std::string& src);
|
||||
|
||||
bool isNumbersAndDotsNotation(const std::string& name);
|
||||
bool isNumericHost(const std::string& name);
|
||||
|
||||
void setGlobalSignalHandler(int signal, void (*handler)(int), int flags);
|
||||
|
||||
|
|
|
@ -178,6 +178,8 @@ void CookieTest::testNormalizeDomain()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("..local"), dot.getDomain());
|
||||
Cookie ip("k", "v", "/", "192.168.1.1", false);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("192.168.1.1"), ip.getDomain());
|
||||
Cookie ipv6("k", "v", "/", "::1", false);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("::1"), ipv6.getDomain());
|
||||
}
|
||||
|
||||
void CookieTest::testToNsCookieFormat()
|
||||
|
|
|
@ -60,6 +60,7 @@ class UtilTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testParsePrioritizePieceRange);
|
||||
CPPUNIT_TEST(testApplyDir);
|
||||
CPPUNIT_TEST(testFixTaintedBasename);
|
||||
CPPUNIT_TEST(testIsNumericHost);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
|
@ -108,6 +109,7 @@ public:
|
|||
void testParsePrioritizePieceRange();
|
||||
void testApplyDir();
|
||||
void testFixTaintedBasename();
|
||||
void testIsNumericHost();
|
||||
};
|
||||
|
||||
|
||||
|
@ -919,4 +921,11 @@ void UtilTest::testFixTaintedBasename()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("a__b"), util::fixTaintedBasename("a\\/b"));
|
||||
}
|
||||
|
||||
void UtilTest::testIsNumericHost()
|
||||
{
|
||||
CPPUNIT_ASSERT(util::isNumericHost("192.168.0.1"));
|
||||
CPPUNIT_ASSERT(!util::isNumericHost("aria2.sf.net"));
|
||||
CPPUNIT_ASSERT(util::isNumericHost("::1"));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
Loading…
Reference in New Issue