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>
|
2008-05-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Made string literal to static const std::string
|
Made string literal to static const std::string
|
||||||
|
|
|
@ -38,4 +38,6 @@ namespace aria2 {
|
||||||
|
|
||||||
const std::string A2STR::NIL("");
|
const std::string A2STR::NIL("");
|
||||||
|
|
||||||
|
const std::string A2STR::SHARP_C("#");
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -45,6 +45,7 @@ private:
|
||||||
public:
|
public:
|
||||||
static const std::string NIL;
|
static const std::string NIL;
|
||||||
|
|
||||||
|
static const std::string SHARP_C;
|
||||||
};
|
};
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,13 @@
|
||||||
#include "CookieBox.h"
|
#include "CookieBox.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "RecoverableException.h"
|
#include "RecoverableException.h"
|
||||||
|
#include "A2STR.h"
|
||||||
#include <istream>
|
#include <istream>
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
const std::string CookieBoxFactory::TRUE("TRUE");
|
||||||
|
|
||||||
CookieBoxHandle CookieBoxFactory::createNewInstance()
|
CookieBoxHandle CookieBoxFactory::createNewInstance()
|
||||||
{
|
{
|
||||||
CookieBoxHandle box(new CookieBox());
|
CookieBoxHandle box(new CookieBox());
|
||||||
|
@ -52,7 +55,7 @@ void CookieBoxFactory::loadDefaultCookie(std::istream& s)
|
||||||
{
|
{
|
||||||
std::string line;
|
std::string line;
|
||||||
while(getline(s, line)) {
|
while(getline(s, line)) {
|
||||||
if(Util::startsWith(line, "#")) {
|
if(Util::startsWith(line, A2STR::SHARP_C)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -77,7 +80,7 @@ Cookie CookieBoxFactory::parseNsCookie(const std::string& nsCookieStr) const
|
||||||
}
|
}
|
||||||
c.domain = vs[0];
|
c.domain = vs[0];
|
||||||
c.path = vs[2];
|
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]);
|
int64_t expireDate = Util::parseLLInt(vs[4]);
|
||||||
// TODO assuming time_t is int32_t...
|
// TODO assuming time_t is int32_t...
|
||||||
if(expireDate > INT32_MAX) {
|
if(expireDate > INT32_MAX) {
|
||||||
|
|
|
@ -65,6 +65,9 @@ public:
|
||||||
{
|
{
|
||||||
return defaultCookies;
|
return defaultCookies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const std::string TRUE;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<CookieBoxFactory> CookieBoxFactoryHandle;
|
typedef SharedHandle<CookieBoxFactory> CookieBoxFactoryHandle;
|
||||||
|
|
|
@ -41,16 +41,23 @@
|
||||||
|
|
||||||
namespace aria2 {
|
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
|
void CookieParser::setField(Cookie& cookie, const std::string& name, const std::string& value) const
|
||||||
{
|
{
|
||||||
if(name.size() == std::string("secure").size() &&
|
if(name == SECURE) {
|
||||||
strcasecmp(name.c_str(), "secure") == 0) {
|
|
||||||
cookie.secure = true;
|
cookie.secure = true;
|
||||||
} else if(name.size() == std::string("domain").size() && strcasecmp(name.c_str(), "domain") == 0) {
|
} else if(name == DOMAIN) {
|
||||||
cookie.domain = value;
|
cookie.domain = value;
|
||||||
} else if(name.size() == std::string("path").size() && strcasecmp(name.c_str(), "path") == 0) {
|
} else if(name == PATH) {
|
||||||
cookie.path = value;
|
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.expires = Util::httpGMT(value);
|
||||||
cookie.onetime = false;
|
cookie.onetime = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -85,7 +92,7 @@ Cookies CookieParser::parse(std::istream& s) const
|
||||||
Cookies cookies;
|
Cookies cookies;
|
||||||
std::string line;
|
std::string line;
|
||||||
while(getline(s, 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;
|
continue;
|
||||||
}
|
}
|
||||||
Cookie cookie = parse(line);
|
Cookie cookie = parse(line);
|
||||||
|
|
|
@ -56,6 +56,15 @@ public:
|
||||||
Cookie parse(const std::string& cookieStr) const;
|
Cookie parse(const std::string& cookieStr) const;
|
||||||
|
|
||||||
Cookies parse(std::istream& s) 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;
|
typedef SharedHandle<CookieParser> CookieParserHandle;
|
||||||
|
|
Loading…
Reference in New Issue