diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-10-09 14:22:49 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-10-09 14:22:49 +0000 |
| commit | 8b17d4b276222b203722eea9ded9cd3797a4b656 (patch) | |
| tree | fd20f43edf2e3891707cbff18bd1f7160cf627d2 /src/Cookie.h | |
| parent | 9b1280f7a3c0d0223ad8bbc20e108b776d9c53af (diff) | |
2010-10-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten Cookie class and Cookie parser based on
http://tools.ietf.org/html/draft-ietf-httpstate-cookie-14 with
some modifications. When parsing cookie date, match time first so
that it parses asctime() format. The request-path must be ends
with '/' so that request-path '/foo/' path-matches cookie-path
'/foo' and '/foo/' in the proposed algorithm.
* src/Cookie.cc
* src/Cookie.h
* src/CookieParser.cc: Removed
* src/CookieParser.h: Removed
* src/CookieStorage.cc
* src/CookieStorage.h
* src/HttpResponse.cc
* src/Makefile.am
* src/Makefile.in
* src/MultiUrlRequestInfo.cc
* src/NsCookieParser.cc
* src/NsCookieParser.h
* src/Sqlite3CookieParser.cc
* src/Sqlite3CookieParser.h
* src/a2functional.h
* src/cookie_helper.cc
* src/cookie_helper.h
* src/util.cc
* src/util.h
* test/CookieBoxFactoryTest.cc: Removed
* test/CookieHelperTest.cc
* test/CookieParserTest.cc: Removed
* test/CookieStorageTest.cc
* test/CookieTest.cc
* test/HttpRequestTest.cc
* test/Makefile.am
* test/Makefile.in
* test/NsCookieParserTest.cc
* test/Sqlite3CookieParserTest.cc
* test/TestUtil.cc
* test/TestUtil.h
* test/a2functionalTest.cc
* test/chromium_cookies.sqlite
* test/cookies.sqlite
* test/nscookietest.txt
Diffstat (limited to 'src/Cookie.h')
| -rw-r--r-- | src/Cookie.h | 157 |
1 files changed, 101 insertions, 56 deletions
diff --git a/src/Cookie.h b/src/Cookie.h index 02a34054..5c4bc4e3 100644 --- a/src/Cookie.h +++ b/src/Cookie.h @@ -2,7 +2,7 @@ /* * aria2 - The high speed download utility * - * Copyright (C) 2006 Tatsuhiro Tsujikawa + * Copyright (C) 2010 Tatsuhiro Tsujikawa * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,8 +32,8 @@ * files in the program, then also delete it here. */ /* copyright --> */ -#ifndef _D_COOKIE_H_ -#define _D_COOKIE_H_ +#ifndef D_COOKIE_H +#define D_COOKIE_H #include "common.h" @@ -47,70 +47,83 @@ class Cookie { private: std::string name_; std::string value_; - time_t expiry_; - std::string path_; + time_t expiryTime_; + // If persistent_ is false, this is a session scope cookie and it is + // never expired during session. So isExpired() always returns + // false. + bool persistent_; std::string domain_; + bool hostOnly_; + std::string path_; bool secure_; + bool httpOnly_; time_t creationTime_; - time_t lastAccess_; + time_t lastAccessTime_; public: - /* - * If expires = 0 is given, then the cookie becomes session cookie. - * domain is normalized using normalizeDomain() function and - * assigned to domain_. If domain is not specified in cookie, call - * markOriginServerOnly() after construction. - */ - Cookie(const std::string& name, - const std::string& value, - time_t expires, - const std::string& path, - const std::string& domain, - bool secure); - - /* - * Creates session cookie. This is equivalent to Cookie(name, value, - * 0, path, domain, secure); domain is normalized using - * normalizeDomain() function and assigned to domain_. If domain is - * not specified in cookie, call markOriginServerOnly() after - * construction. - */ - Cookie(const std::string& name, - const std::string& value, - const std::string& path, - const std::string& domain, - bool secure); - Cookie(); + Cookie + (const std::string& name, + const std::string& value, + time_t expiryTime, + bool persistent, + const std::string& domain, + bool hostOnly, + const std::string& path, + bool secure, + bool httpOnly, + time_t creationTime); + ~Cookie(); std::string toString() const; - bool good() const; - - bool match(const std::string& requestHost, const std::string& requestPath, - time_t date, bool secure) const; - - bool validate(const std::string& requestHost, - const std::string& requestPath) const; + bool match + (const std::string& requestHost, const std::string& requestPath, + time_t date, bool secure) const; bool operator==(const Cookie& cookie) const; - bool isExpired() const; + bool isExpired(time_t base) const; const std::string& getName() const { return name_; } + void setName(const std::string& name) + { + name_ = name; + } + const std::string& getValue() const { return value_; } - const std::string& getPath() const + void setValue(const std::string& value) { - return path_; + value_ = value; + } + + time_t getExpiryTime() const + { + return expiryTime_; + } + + void setExpiryTime(time_t expiryTime) + { + expiryTime_ = expiryTime; + } + + bool getPersistent() const + { + return persistent_; + } + + void setPersistent(bool persistent) + { + persistent_ = persistent; } const std::string& getDomain() const @@ -118,42 +131,74 @@ public: return domain_; } - time_t getExpiry() const + void setDomain(const std::string& domain) + { + domain_ = domain; + } + + bool getHostOnly() const + { + return hostOnly_; + } + + void setHostOnly(bool hostOnly) + { + hostOnly_ = hostOnly; + } + + const std::string& getPath() const + { + return path_; + } + + void setPath(const std::string& path) { - return expiry_; + path_ = path; } - bool isSecureCookie() const + bool getSecure() const { return secure_; } - bool isSessionCookie() const + void setSecure(bool secure) { - return expiry_ == 0; + secure_ = secure; } - std::string toNsCookieFormat() const; + bool getHttpOnly() const + { + return httpOnly_; + } - // Makes this Cookie only sent to the origin server. This function - // removes first "." from domain_ if domain_ starts with ".". - void markOriginServerOnly(); + void setHttpOnly(bool httpOnly) + { + httpOnly_ = httpOnly; + } time_t getCreationTime() const { return creationTime_; } - void updateLastAccess(); + void setCreationTime(time_t creationTime) + { + creationTime_ = creationTime; + } + + time_t getLastAccessTime() const + { + return lastAccessTime_; + } - time_t getLastAccess() const + void setLastAccessTime(time_t lastAccessTime) { - return lastAccess_; + lastAccessTime_ = lastAccessTime; } - static std::string normalizeDomain(const std::string& domain); + std::string toNsCookieFormat() const; }; } // namespace aria2 -#endif // _D_COOKIE_H_ +#endif // D_COOKIE_H |
