/* */ #include "Cookie.h" #include #include "A2STR.h" #include "a2functional.h" #include "cookie_helper.h" namespace aria2 { 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): name_(name), value_(value), expiryTime_(expiryTime), persistent_(persistent), domain_(domain), hostOnly_(hostOnly), path_(path), secure_(secure), httpOnly_(httpOnly), creationTime_(creationTime), lastAccessTime_(creationTime) {} Cookie::Cookie(): expiryTime_(0), persistent_(false), hostOnly_(false), secure_(false), httpOnly_(false), creationTime_(0), lastAccessTime_(0) {} Cookie::~Cookie() {} std::string Cookie::toString() const { return strconcat(name_, '=', value_); } bool Cookie::match (const std::string& requestHost, const std::string& requestPath, time_t date, bool secure) const { if((secure_ && !secure) || isExpired(date) || !cookie::pathMatch(requestPath, path_)) { return false; } if(hostOnly_) { return requestHost == domain_ ; } else { return cookie::domainMatch(requestHost, domain_); } } bool Cookie::operator==(const Cookie& cookie) const { return domain_ == cookie.domain_ && path_ == cookie.path_ && name_ == cookie.name_; } bool Cookie::isExpired(time_t base) const { return persistent_ && base > expiryTime_; } std::string Cookie::toNsCookieFormat() const { std::stringstream ss; if(!hostOnly_) { ss << A2STR::DOT_C; } ss << domain_ << "\t"; if(hostOnly_) { ss << "FALSE"; } else { ss << "TRUE"; } ss << "\t"; ss << path_ << "\t"; if(secure_) { ss << "TRUE"; } else { ss << "FALSE"; } ss << "\t"; if(persistent_) { ss << expiryTime_; } else { ss << 0; } ss << "\t"; ss << name_ << "\t"; ss << value_; return ss.str(); } } // namespace aria2