Przeglądaj źródła

2008-05-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	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
Tatsuhiro Tsujikawa 17 lat temu
rodzic
commit
1942b8d7b3
7 zmienionych plików z 44 dodań i 8 usunięć
  1. 11 0
      ChangeLog
  2. 2 0
      src/A2STR.cc
  3. 1 0
      src/A2STR.h
  4. 5 2
      src/CookieBoxFactory.cc
  5. 3 0
      src/CookieBoxFactory.h
  6. 13 6
      src/CookieParser.cc
  7. 9 0
      src/CookieParser.h

+ 11 - 0
ChangeLog

@@ -1,3 +1,14 @@
+2008-05-13  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	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  <tujikawa at rednoah dot com>
 
 	Made string literal to static const std::string

+ 2 - 0
src/A2STR.cc

@@ -38,4 +38,6 @@ namespace aria2 {
 
 const std::string A2STR::NIL("");
 
+const std::string A2STR::SHARP_C("#");
+
 } // namespace aria2

+ 1 - 0
src/A2STR.h

@@ -45,6 +45,7 @@ private:
 public:
   static const std::string NIL;
 
+  static const std::string SHARP_C;
 };
 } // namespace aria2
 

+ 5 - 2
src/CookieBoxFactory.cc

@@ -37,10 +37,13 @@
 #include "CookieBox.h"
 #include "Util.h"
 #include "RecoverableException.h"
+#include "A2STR.h"
 #include <istream>
 
 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) {

+ 3 - 0
src/CookieBoxFactory.h

@@ -65,6 +65,9 @@ public:
   {
     return defaultCookies;
   }
+
+private:
+  static const std::string TRUE;
 };
 
 typedef SharedHandle<CookieBoxFactory> CookieBoxFactoryHandle;

+ 13 - 6
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);

+ 9 - 0
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<CookieParser> CookieParserHandle;