Browse Source

2008-09-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Made Cookie immutable.
	* src/Cookie.cc
	* src/Cookie.h
	* src/CookieParser.cc
	* src/CookieParser.h
	* src/CookieStorage.cc
	* test/CookieParserTest.cc
	* test/CookieStorageTest.cc
	* test/NsCookieParserTest.cc
	* test/Sqlite3MozCookieParserTest.cc
Tatsuhiro Tsujikawa 17 năm trước cách đây
mục cha
commit
6779c72b5d

+ 13 - 0
ChangeLog

@@ -1,3 +1,16 @@
+2008-09-01  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Made Cookie immutable.
+	* src/Cookie.cc
+	* src/Cookie.h
+	* src/CookieParser.cc
+	* src/CookieParser.h
+	* src/CookieStorage.cc
+	* test/CookieParserTest.cc
+	* test/CookieStorageTest.cc
+	* test/NsCookieParserTest.cc
+	* test/Sqlite3MozCookieParserTest.cc
+	
 2008-09-01  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Removed CookieBox, CookieBoxFactory.

+ 69 - 39
src/Cookie.cc

@@ -42,49 +42,43 @@ namespace aria2 {
 
 Cookie::Cookie(const std::string& name,
 	       const std::string& value,
-	       time_t  expires,
+	       time_t  expiry,
 	       const std::string& path,
 	       const std::string& domain,
 	       bool secure):
-  name(name),
-  value(value),
-  expires(expires),
-  path(path),
-  domain(Util::toLower(domain)),
-  secure(secure),
-  onetime(false) {}
+  _name(name),
+  _value(value),
+  _expiry(expiry),
+  _path(path),
+  _domain(Util::toLower(domain)),
+  _secure(secure),
+  _onetime(false) {}
 
 Cookie::Cookie(const std::string& name,
 	       const std::string& value,
 	       const std::string& path,
 	       const std::string& domain,
 	       bool secure):
-  name(name),
-  value(value),
-  path(path),
-  domain(Util::toLower(domain)),
-  secure(secure),
-  onetime(true) {}
+  _name(name),
+  _value(value),
+  _expiry(0),
+  _path(path),
+  _domain(Util::toLower(domain)),
+  _secure(secure),
+  _onetime(true) {}
 
-Cookie::Cookie():expires(0), secure(false), onetime(true) {}
+Cookie::Cookie():_expiry(0), _secure(false), _onetime(true) {}
 
 Cookie::~Cookie() {}
 
 std::string Cookie::toString() const
 {
-  return name+"="+value;
-}
-
-void Cookie::clear()
-{
-  name = value = path = domain = A2STR::NIL;
-  expires = 0;
-  secure = false;
+  return _name+"="+_value;
 }
 
 bool Cookie::good() const
 {
-  return !name.empty();
+  return !_name.empty();
 }
 
 static bool pathInclude(const std::string& requestPath, const std::string& path)
@@ -118,10 +112,10 @@ bool Cookie::match(const std::string& requestHost,
 		   time_t date, bool secure) const
 {
   std::string lowerRequestHost = Util::toLower(requestHost);
-  if((secure || (!this->secure && !secure)) &&
-     domainMatch(lowerRequestHost, this->domain) &&
-     pathInclude(requestPath, path) &&
-     (this->onetime || (date < this->expires))) {
+  if((secure || (!_secure && !secure)) &&
+     domainMatch(lowerRequestHost, _domain) &&
+     pathInclude(requestPath, _path) &&
+     (_onetime || (date < _expiry))) {
     return true;
   } else {
     return false;
@@ -132,20 +126,20 @@ bool Cookie::validate(const std::string& requestHost,
 		      const std::string& requestPath) const
 {
   std::string lowerRequestHost = Util::toLower(requestHost);
-  if(lowerRequestHost != domain) {
+  if(lowerRequestHost != _domain) {
     // domain must start with '.'
-    if(*domain.begin() != '.') {
+    if(*_domain.begin() != '.') {
       return false;
     }
     // domain must not end with '.'
-    if(*domain.rbegin() == '.') {
+    if(*_domain.rbegin() == '.') {
       return false;
     }
     // domain must include at least one embeded '.'
-    if(domain.size() < 4 || domain.find(".", 1) == std::string::npos) {
+    if(_domain.size() < 4 || _domain.find(".", 1) == std::string::npos) {
       return false;
     }
-    if(!Util::endsWith(lowerRequestHost, domain)) {
+    if(!Util::endsWith(lowerRequestHost, _domain)) {
       return false;
     }
     // From RFC2109
@@ -154,30 +148,66 @@ bool Cookie::validate(const std::string& requestHost,
     //   that contains one or more dots.
     if(std::count(lowerRequestHost.begin(),
 		  lowerRequestHost.begin()+
-		  (lowerRequestHost.size()-domain.size()), '.')
+		  (lowerRequestHost.size()-_domain.size()), '.')
        > 0) {
       return false;
     } 
   }
-  if(requestPath != path) {
+  if(requestPath != _path) {
     // From RFC2109
     // * The value for the Path attribute is not a prefix of the request-
     //   URI.
-    if(!pathInclude(requestPath, path)) {
+    if(!pathInclude(requestPath, _path)) {
       return false;
     }
   }
-  return !name.empty();
+  return good();
 }
 
 bool Cookie::operator==(const Cookie& cookie) const
 {
-  return domain == cookie.domain && path == cookie.path && name == cookie.name;
+  return _domain == cookie._domain && _path == cookie._path &&
+    _name == cookie._name;
 }
 
 bool Cookie::isExpired() const
 {
-  return !onetime && Time().getTime() >= expires;
+  return !_onetime && Time().getTime() >= _expiry;
+}
+
+const std::string& Cookie::getName() const
+{
+  return _name;
+}
+
+const std::string& Cookie::getValue() const
+{
+  return _value;
+}
+
+const std::string& Cookie::getPath() const
+{
+  return _path;
+}
+
+const std::string& Cookie::getDomain() const
+{
+  return _domain;
+}
+
+time_t Cookie::getExpiry() const
+{
+  return _expiry;
+}
+
+bool Cookie::isSecureCookie() const
+{
+  return _secure;
+}
+
+bool Cookie::isOnetimeCookie() const
+{
+  return _onetime;
 }
 
 } // namespace aria2

+ 24 - 10
src/Cookie.h

@@ -43,14 +43,16 @@
 namespace aria2 {
 
 class Cookie {
-public:
-  std::string name;
-  std::string value;
-  time_t expires;
-  std::string path;
-  std::string domain;
-  bool secure;
-  bool onetime; // if true, this cookie will expire when the user's session ends.
+private:
+  std::string _name;
+  std::string _value;
+  time_t _expiry;
+  std::string _path;
+  std::string _domain;
+  bool _secure;
+
+  // If true, this cookie will expire when aria2 exits.
+  bool _onetime;
 public:
   Cookie(const std::string& name,
 	 const std::string& value,
@@ -71,8 +73,6 @@ public:
 
   std::string toString() const;
 
-  void clear();
-
   bool good() const;
 
   bool match(const std::string& requestHost, const std::string& requestPath,
@@ -84,6 +84,20 @@ public:
   bool operator==(const Cookie& cookie) const;
 
   bool isExpired() const;
+
+  const std::string& getName() const;
+
+  const std::string& getValue() const;
+
+  const std::string& getPath() const;
+
+  const std::string& getDomain() const;
+
+  time_t getExpiry() const;
+
+  bool isSecureCookie() const;
+
+  bool isOnetimeCookie() const;
 };
 
 typedef std::deque<Cookie> Cookies;

+ 28 - 30
src/CookieParser.cc

@@ -38,6 +38,7 @@
 #include <strings.h>
 #include <utility>
 #include <istream>
+#include <map>
 
 namespace aria2 {
 
@@ -49,30 +50,6 @@ const std::string CookieParser::C_PATH("path");
 
 const std::string CookieParser::C_EXPIRES("expires");
 
-void CookieParser::setField(Cookie& cookie, const std::string& name, const std::string& value) const
-{
-  if(name == C_SECURE) {
-    cookie.secure = true;
-  } else if(name == C_DOMAIN) {
-    cookie.domain = value;
-  } else if(name == C_PATH) {
-    cookie.path = value;
-  } else if(name == C_EXPIRES) {
-    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;
-    }
-  } else {
-    cookie.name = name;
-    cookie.value = value;
-  }
-}
-
 Cookie CookieParser::parse(const std::string& cookieStr) const
 {
   return parse(cookieStr, A2STR::NIL, A2STR::NIL);
@@ -80,17 +57,38 @@ Cookie CookieParser::parse(const std::string& cookieStr) const
 
 Cookie CookieParser::parse(const std::string& cookieStr, const std::string& defaultDomain, const std::string& defaultPath) const
 {
-  Cookie cookie;
-  cookie.domain = defaultDomain;
-  cookie.path = defaultPath;
   std::deque<std::string> terms;
   Util::slice(terms, Util::trim(cookieStr), ';', true);
-  for(std::deque<std::string>::iterator itr = terms.begin(); itr != terms.end(); itr++) {
+  if(terms.empty()) {
+    return Cookie();
+  }
+  std::pair<std::string, std::string> nameValue;
+  Util::split(nameValue, terms.front(), '=');
+
+  std::map<std::string, std::string> values;
+  values[C_DOMAIN] = defaultDomain;
+  values[C_PATH] = defaultPath;
+  
+  for(std::deque<std::string>::iterator itr = terms.begin()+1;
+      itr != terms.end(); ++itr) {
     std::pair<std::string, std::string> nv;
     Util::split(nv, *itr, '=');
-    setField(cookie, nv.first, nv.second);
+    values[nv.first] = nv.second;
+  }
+  time_t expiry = -1;
+  if(values.find(C_EXPIRES) != values.end()) {
+    expiry = Util::httpGMT(values[C_EXPIRES]);
+  }
+  if(expiry == -1) {
+    return Cookie(nameValue.first, nameValue.second,
+		  values[C_PATH], values[C_DOMAIN],
+		  values.find(C_SECURE) != values.end());
+  } else {
+    return Cookie(nameValue.first, nameValue.second,
+		  expiry,
+		  values[C_PATH], values[C_DOMAIN],
+		  values.find(C_SECURE) != values.end());
   }
-  return cookie;
 }
 
 

+ 2 - 3
src/CookieParser.h

@@ -44,14 +44,13 @@
 namespace aria2 {
 
 class CookieParser {
-private:
-  void setField(Cookie& cookie, const std::string& name, const std::string& value) const;
 public:
   CookieParser() {}
 
   ~CookieParser() {}
 
-  Cookie parse(const std::string& cookieStr, const std::string& defaultDomain, const std::string& defaultPath) const;
+  Cookie parse(const std::string& cookieStr, const std::string& defaultDomain,
+	       const std::string& defaultPath) const;
 
   Cookie parse(const std::string& cookieStr) const;
 

+ 1 - 1
src/CookieStorage.cc

@@ -118,7 +118,7 @@ class OrderByPathDesc:public std::binary_function<Cookie, Cookie, bool> {
 public:
   bool operator()(const Cookie& lhs, const Cookie& rhs) const
   {
-    return lhs.path > rhs.path;
+    return lhs.getPath() > rhs.getPath();
   }
 };
 

+ 21 - 21
test/CookieParserTest.cc

@@ -29,24 +29,24 @@ void CookieParserTest::testParse()
   std::string str = "JSESSIONID=123456789; expires=Sun, 2007-06-10 11:00:00 GMT; path=/; domain=localhost; secure";
   Cookie c = CookieParser().parse(str);
   CPPUNIT_ASSERT(c.good());
-  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.expires);  
-  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
-  CPPUNIT_ASSERT_EQUAL(true, c.secure);
-  CPPUNIT_ASSERT_EQUAL(false, c.onetime);
+  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.getExpiry());  
+  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
+  CPPUNIT_ASSERT_EQUAL(true, c.isSecureCookie());
+  CPPUNIT_ASSERT_EQUAL(false, c.isOnetimeCookie());
 
   std::string str2 = "JSESSIONID=123456789";
   c = CookieParser().parse(str2, "default.domain", "/default/path");
   CPPUNIT_ASSERT(c.good());
-  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)0, c.expires);
-  CPPUNIT_ASSERT_EQUAL(std::string("default.domain"), c.domain);
-  CPPUNIT_ASSERT_EQUAL(std::string("/default/path"), c.path);
-  CPPUNIT_ASSERT_EQUAL(false, c.secure);
-  CPPUNIT_ASSERT_EQUAL(true, c.onetime);
+  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)0, c.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(std::string("default.domain"), c.getDomain());
+  CPPUNIT_ASSERT_EQUAL(std::string("/default/path"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(false, c.isSecureCookie());
+  CPPUNIT_ASSERT_EQUAL(true, c.isOnetimeCookie());
 
   std::string str3 = "";
   c = CookieParser().parse(str3);
@@ -55,7 +55,7 @@ void CookieParserTest::testParse()
   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);
+  CPPUNIT_ASSERT(c.isOnetimeCookie());
 }
 
 void CookieParserTest::testParse_file()
@@ -67,16 +67,16 @@ void CookieParserTest::testParse_file()
   CPPUNIT_ASSERT_EQUAL((int32_t)3, (int32_t)cookies.size());
 
   Cookie c = cookies[0];
-  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.value);
+  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
 
   c = cookies[1];
-  CPPUNIT_ASSERT_EQUAL(std::string("user"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("me"), c.value);
+  CPPUNIT_ASSERT_EQUAL(std::string("user"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("me"), c.getValue());
 
   c = cookies[2];
-  CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.value);
+  CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.getValue());
 }
 
 } // namespace aria2

+ 39 - 39
test/CookieStorageTest.cc

@@ -125,7 +125,7 @@ void CookieStorageTest::testCriteriaFind()
   std::deque<Cookie> aria2SlashFoo = st.criteriaFind("www.aria2.org", "/foo",
 						     0, false);
   CPPUNIT_ASSERT_EQUAL((size_t)3, aria2SlashFoo.size());
-  CPPUNIT_ASSERT_EQUAL(std::string("bravo"), aria2SlashFoo[0].name);
+  CPPUNIT_ASSERT_EQUAL(std::string("bravo"), aria2SlashFoo[0].getName());
   CPPUNIT_ASSERT(std::find(aria2SlashFoo.begin(), aria2SlashFoo.end(), alpha)
 		 != aria2SlashFoo.end());
   CPPUNIT_ASSERT(std::find(aria2SlashFoo.begin(), aria2SlashFoo.end(), echo)
@@ -142,12 +142,12 @@ void CookieStorageTest::testCriteriaFind()
 
   std::deque<Cookie> dlAria2 = st.criteriaFind("dl.aria2.org", "/", 0, false);
   CPPUNIT_ASSERT_EQUAL((size_t)1, dlAria2.size());
-  CPPUNIT_ASSERT_EQUAL(std::string("alpha"), dlAria2[0].name);
+  CPPUNIT_ASSERT_EQUAL(std::string("alpha"), dlAria2[0].getName());
 
   std::deque<Cookie> numericHostCookies = st.criteriaFind("192.168.1.1", "/", 0,
 							  false);
   CPPUNIT_ASSERT_EQUAL((size_t)1, numericHostCookies.size());
-  CPPUNIT_ASSERT_EQUAL(std::string("golf"), numericHostCookies[0].name);
+  CPPUNIT_ASSERT_EQUAL(std::string("golf"), numericHostCookies[0].getName());
 }
 
 void CookieStorageTest::testLoad()
@@ -159,36 +159,36 @@ void CookieStorageTest::testLoad()
   CPPUNIT_ASSERT_EQUAL((size_t)4, st.size());
 
   Cookie c = *st.begin();
-  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
-  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
-  CPPUNIT_ASSERT(c.secure);
+  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
+  CPPUNIT_ASSERT(c.isSecureCookie());
 
   c = *(st.begin()+1);
-  CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
-  CPPUNIT_ASSERT_EQUAL(std::string("/cgi-bin"), c.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
-  CPPUNIT_ASSERT(!c.secure);
+  CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(std::string("/cgi-bin"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
+  CPPUNIT_ASSERT(!c.isSecureCookie());
 
   c = *(st.begin()+2);
-  CPPUNIT_ASSERT_EQUAL(std::string("TAX"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("1000"), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
-  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("overflow"), c.domain);
-  CPPUNIT_ASSERT(!c.secure);
+  CPPUNIT_ASSERT_EQUAL(std::string("TAX"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("1000"), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("overflow"), c.getDomain());
+  CPPUNIT_ASSERT(!c.isSecureCookie());
 
   c = *(st.begin()+3);
-  CPPUNIT_ASSERT_EQUAL(std::string("novalue"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string(""), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
-  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
-  CPPUNIT_ASSERT(!c.secure);
+  CPPUNIT_ASSERT_EQUAL(std::string("novalue"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string(""), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
+  CPPUNIT_ASSERT(!c.isSecureCookie());
 }
 
 void CookieStorageTest::testLoad_sqlite3()
@@ -198,20 +198,20 @@ void CookieStorageTest::testLoad_sqlite3()
   st.load("cookies.sqlite");
   CPPUNIT_ASSERT_EQUAL((size_t)2, st.size());
   Cookie c = *st.begin();
-  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
-  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
-  CPPUNIT_ASSERT(c.secure);
+  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
+  CPPUNIT_ASSERT(c.isSecureCookie());
 
   c = *(st.begin()+1);
-  CPPUNIT_ASSERT_EQUAL(std::string("foo"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("bar"), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
-  CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), c.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("overflow_time_t"), c.domain);
-  CPPUNIT_ASSERT(!c.secure);
+  CPPUNIT_ASSERT_EQUAL(std::string("foo"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("bar"), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("overflow_time_t"), c.getDomain());
+  CPPUNIT_ASSERT(!c.isSecureCookie());
     
 #else // !HAVE_SQLITE3
   try {

+ 25 - 25
test/NsCookieParserTest.cc

@@ -31,39 +31,39 @@ void NsCookieParserTest::testParse()
   CPPUNIT_ASSERT_EQUAL((size_t)5, cookies.size());
 
   Cookie c = cookies[0];
-  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
-  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
+  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
 
   c = cookies[1];
-  CPPUNIT_ASSERT_EQUAL(std::string("user"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("me"), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.expires);
-  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("expired"), c.domain);
+  CPPUNIT_ASSERT_EQUAL(std::string("user"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("me"), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("expired"), c.getDomain());
 
   c = cookies[2];
-  CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
-  CPPUNIT_ASSERT_EQUAL(std::string("/cgi-bin"), c.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
+  CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(std::string("/cgi-bin"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
 
   c = cookies[3];
-  CPPUNIT_ASSERT_EQUAL(std::string("TAX"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("1000"), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
-  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("overflow"), c.domain);
+  CPPUNIT_ASSERT_EQUAL(std::string("TAX"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("1000"), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("overflow"), c.getDomain());
 
   c = cookies[4];
-  CPPUNIT_ASSERT_EQUAL(std::string("novalue"), c.name);
-  CPPUNIT_ASSERT_EQUAL(std::string(""), c.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
-  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
+  CPPUNIT_ASSERT_EQUAL(std::string("novalue"), c.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string(""), c.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
 }
 
 void NsCookieParserTest::testParse_fileNotFound()

+ 19 - 18
test/Sqlite3MozCookieParserTest.cc

@@ -33,30 +33,31 @@ void Sqlite3MozCookieParserTest::testParse()
   CPPUNIT_ASSERT_EQUAL((size_t)3, cookies.size());
 
   const Cookie& localhost = cookies[0];
-  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), localhost.domain);
-  CPPUNIT_ASSERT_EQUAL(std::string("/"), localhost.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), localhost.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), localhost.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, localhost.expires);
-  CPPUNIT_ASSERT_EQUAL(true, localhost.secure);
+  CPPUNIT_ASSERT_EQUAL(std::string("localhost"), localhost.getDomain());
+  CPPUNIT_ASSERT_EQUAL(std::string("/"), localhost.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), localhost.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), localhost.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, localhost.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(true, localhost.isSecureCookie());
 
   const Cookie& nullValue = cookies[1];
-  CPPUNIT_ASSERT_EQUAL(std::string("null_value"), nullValue.domain);
-  CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), nullValue.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("uid"), nullValue.name);
-  CPPUNIT_ASSERT_EQUAL(std::string(""), nullValue.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)0, nullValue.expires);
-  CPPUNIT_ASSERT_EQUAL(false, nullValue.secure);
+  CPPUNIT_ASSERT_EQUAL(std::string("null_value"), nullValue.getDomain());
+  CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), nullValue.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("uid"), nullValue.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string(""), nullValue.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)0, nullValue.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(false, nullValue.isSecureCookie());
 
   // See row id=3 has no name, so it is skipped.
 
   const Cookie& overflowTime = cookies[2];
-  CPPUNIT_ASSERT_EQUAL(std::string("overflow_time_t"), overflowTime.domain);
-  CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), overflowTime.path);
-  CPPUNIT_ASSERT_EQUAL(std::string("foo"), overflowTime.name);
-  CPPUNIT_ASSERT_EQUAL(std::string("bar"), overflowTime.value);
-  CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, overflowTime.expires);
-  CPPUNIT_ASSERT_EQUAL(false, overflowTime.secure);
+  CPPUNIT_ASSERT_EQUAL(std::string("overflow_time_t"),
+		       overflowTime.getDomain());
+  CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), overflowTime.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("foo"), overflowTime.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("bar"), overflowTime.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, overflowTime.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(false, overflowTime.isSecureCookie());
 }
 
 void Sqlite3MozCookieParserTest::testParse_fileNotFound()