mirror of https://github.com/aria2/aria2
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.hpull/1/head
parent
898b807ba2
commit
1942b8d7b3
11
ChangeLog
11
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
|
||||
|
|
|
@ -38,4 +38,6 @@ namespace aria2 {
|
|||
|
||||
const std::string A2STR::NIL("");
|
||||
|
||||
const std::string A2STR::SHARP_C("#");
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -45,6 +45,7 @@ private:
|
|||
public:
|
||||
static const std::string NIL;
|
||||
|
||||
static const std::string SHARP_C;
|
||||
};
|
||||
} // namespace aria2
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -65,6 +65,9 @@ public:
|
|||
{
|
||||
return defaultCookies;
|
||||
}
|
||||
|
||||
private:
|
||||
static const std::string TRUE;
|
||||
};
|
||||
|
||||
typedef SharedHandle<CookieBoxFactory> CookieBoxFactoryHandle;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue