diff --git a/ChangeLog b/ChangeLog index c91a8f1a..39ca5a9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-05-13 Tatsuhiro Tsujikawa + + Made string literal to static const std::string. + Rewritten CookieParser::setField. + * src/A2STR.cc + * src/A2STR.h + * src/CookieBoxFactory.cc + * src/CookieBoxFactory.h + * src/CookieParser.cc + * src/CookieParser.h + 2008-05-13 Tatsuhiro Tsujikawa Made string literal to static const std::string diff --git a/src/A2STR.cc b/src/A2STR.cc index 675045ad..0766dbad 100644 --- a/src/A2STR.cc +++ b/src/A2STR.cc @@ -38,4 +38,6 @@ namespace aria2 { const std::string A2STR::NIL(""); +const std::string A2STR::SHARP_C("#"); + } // namespace aria2 diff --git a/src/A2STR.h b/src/A2STR.h index 48a83774..bd392ca7 100644 --- a/src/A2STR.h +++ b/src/A2STR.h @@ -45,6 +45,7 @@ private: public: static const std::string NIL; + static const std::string SHARP_C; }; } // namespace aria2 diff --git a/src/CookieBoxFactory.cc b/src/CookieBoxFactory.cc index f022f598..d6e104ec 100644 --- a/src/CookieBoxFactory.cc +++ b/src/CookieBoxFactory.cc @@ -37,10 +37,13 @@ #include "CookieBox.h" #include "Util.h" #include "RecoverableException.h" +#include "A2STR.h" #include namespace aria2 { +const std::string CookieBoxFactory::TRUE("TRUE"); + CookieBoxHandle CookieBoxFactory::createNewInstance() { CookieBoxHandle box(new CookieBox()); @@ -52,7 +55,7 @@ void CookieBoxFactory::loadDefaultCookie(std::istream& s) { std::string line; while(getline(s, line)) { - if(Util::startsWith(line, "#")) { + if(Util::startsWith(line, A2STR::SHARP_C)) { continue; } try { @@ -77,7 +80,7 @@ Cookie CookieBoxFactory::parseNsCookie(const std::string& nsCookieStr) const } c.domain = vs[0]; c.path = vs[2]; - c.secure = vs[3] == "TRUE" ? true : false; + c.secure = vs[3] == TRUE ? true : false; int64_t expireDate = Util::parseLLInt(vs[4]); // TODO assuming time_t is int32_t... if(expireDate > INT32_MAX) { diff --git a/src/CookieBoxFactory.h b/src/CookieBoxFactory.h index ea7aa149..e2cedd53 100644 --- a/src/CookieBoxFactory.h +++ b/src/CookieBoxFactory.h @@ -65,6 +65,9 @@ public: { return defaultCookies; } + +private: + static const std::string TRUE; }; typedef SharedHandle CookieBoxFactoryHandle; diff --git a/src/CookieParser.cc b/src/CookieParser.cc index eb1204af..d02eccd1 100644 --- a/src/CookieParser.cc +++ b/src/CookieParser.cc @@ -41,16 +41,23 @@ namespace aria2 { +const std::string CookieParser::SECURE("secure"); + +const std::string CookieParser::DOMAIN("domain"); + +const std::string CookieParser::PATH("path"); + +const std::string CookieParser::EXPIRES("expires"); + void CookieParser::setField(Cookie& cookie, const std::string& name, const std::string& value) const { - if(name.size() == std::string("secure").size() && - strcasecmp(name.c_str(), "secure") == 0) { + if(name == SECURE) { cookie.secure = true; - } else if(name.size() == std::string("domain").size() && strcasecmp(name.c_str(), "domain") == 0) { + } else if(name == DOMAIN) { cookie.domain = value; - } else if(name.size() == std::string("path").size() && strcasecmp(name.c_str(), "path") == 0) { + } else if(name == PATH) { cookie.path = value; - } else if(name.size() == std::string("expires").size() && strcasecmp(name.c_str(), "expires") == 0) { + } else if(name == EXPIRES) { cookie.expires = Util::httpGMT(value); cookie.onetime = false; } else { @@ -85,7 +92,7 @@ Cookies CookieParser::parse(std::istream& s) const Cookies cookies; std::string line; while(getline(s, line)) { - if(Util::trim(line).empty() || Util::startsWith(line, "#")) { + if(Util::trim(line).empty() || Util::startsWith(line, A2STR::SHARP_C)) { continue; } Cookie cookie = parse(line); diff --git a/src/CookieParser.h b/src/CookieParser.h index 42371d85..0c2d0390 100644 --- a/src/CookieParser.h +++ b/src/CookieParser.h @@ -56,6 +56,15 @@ public: Cookie parse(const std::string& cookieStr) const; Cookies parse(std::istream& s) const; + +private: + static const std::string SECURE; + + static const std::string DOMAIN; + + static const std::string PATH; + + static const std::string EXPIRES; }; typedef SharedHandle CookieParserHandle;