mirror of
https://github.com/aria2/aria2.git
synced 2025-01-24 02:31:29 +00:00
8b17d4b276
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
75 lines
1.6 KiB
C++
75 lines
1.6 KiB
C++
#include "TestUtil.h"
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <cerrno>
|
|
#include <cstring>
|
|
#include <sstream>
|
|
#include <fstream>
|
|
|
|
#include "a2io.h"
|
|
#include "File.h"
|
|
#include "StringFormat.h"
|
|
#include "FatalException.h"
|
|
#include "Cookie.h"
|
|
|
|
namespace aria2 {
|
|
|
|
void createFile(const std::string& path, size_t length)
|
|
{
|
|
File(File(path).getDirname()).mkdirs();
|
|
int fd = creat(path.c_str(), OPEN_MODE);
|
|
if(fd == -1) {
|
|
throw FATAL_EXCEPTION(StringFormat("Could not create file=%s. cause:%s",
|
|
path.c_str(), strerror(errno)).str());
|
|
}
|
|
if(-1 == ftruncate(fd, length)) {
|
|
throw FATAL_EXCEPTION(StringFormat("ftruncate failed. cause:%s",
|
|
strerror(errno)).str());
|
|
}
|
|
close(fd);
|
|
}
|
|
|
|
std::string readFile(const std::string& path)
|
|
{
|
|
std::stringstream ss;
|
|
std::ifstream in(path.c_str(), std::ios::binary);
|
|
char buf[4096];
|
|
while(1) {
|
|
in.read(buf, sizeof(buf));
|
|
ss.write(buf, in.gcount());
|
|
if(in.gcount() != sizeof(buf)) {
|
|
break;
|
|
}
|
|
}
|
|
return ss.str();
|
|
}
|
|
|
|
Cookie createCookie
|
|
(const std::string& name,
|
|
const std::string& value,
|
|
const std::string& domain,
|
|
bool hostOnly,
|
|
const std::string& path,
|
|
bool secure)
|
|
{
|
|
return Cookie
|
|
(name, value, 0, false, domain, hostOnly, path, secure, false, 0);
|
|
}
|
|
|
|
Cookie createCookie
|
|
(const std::string& name,
|
|
const std::string& value,
|
|
time_t expiryTime,
|
|
const std::string& domain,
|
|
bool hostOnly,
|
|
const std::string& path,
|
|
bool secure)
|
|
{
|
|
return Cookie
|
|
(name, value, expiryTime, true, domain, hostOnly, path, secure, false, 0);
|
|
}
|
|
|
|
} // namespace aria2
|