/* */ #include "CookieParser.h" #include #include #include #include #include #include "util.h" #include "A2STR.h" #include "TimeA2.h" namespace aria2 { const std::string CookieParser::C_SECURE("secure"); const std::string CookieParser::C_DOMAIN("domain"); const std::string CookieParser::C_PATH("path"); const std::string CookieParser::C_EXPIRES("expires"); Cookie CookieParser::parse(const std::string& cookieStr, const std::string& defaultDomain, const std::string& defaultPath) const { std::vector terms; util::split(cookieStr, std::back_inserter(terms), ";", true); if(terms.empty()) { return Cookie(); } std::pair nameValue; util::split(nameValue, terms.front(), '='); std::map values; for(std::vector::iterator itr = terms.begin()+1, eoi = terms.end(); itr != eoi; ++itr) { std::pair nv; util::split(nv, *itr, '='); values[nv.first] = nv.second; } bool useDefaultDomain = false; std::map::iterator mitr; mitr = values.find(C_DOMAIN); if(mitr == values.end() || (*mitr).second.empty()) { useDefaultDomain = true; values[C_DOMAIN] = defaultDomain; } mitr = values.find(C_PATH); if(mitr == values.end() || (*mitr).second.empty()) { values[C_PATH] = defaultPath; } time_t expiry = 0; if(values.count(C_EXPIRES)) { Time expiryTime = Time::parseHTTPDate(values[C_EXPIRES]); if(expiryTime.good()) { expiry = expiryTime.getTime(); } } Cookie cookie(nameValue.first, nameValue.second, expiry, values[C_PATH], values[C_DOMAIN], values.find(C_SECURE) != values.end()); if(useDefaultDomain) { cookie.markOriginServerOnly(); } return cookie; } } // namespace aria2