mirror of https://github.com/aria2/aria2
Rewritten NsCookieParser using BufferedFile
parent
f38c2d2012
commit
c553d92f45
|
@ -44,6 +44,7 @@
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "Cookie.h"
|
#include "Cookie.h"
|
||||||
#include "cookie_helper.h"
|
#include "cookie_helper.h"
|
||||||
|
#include "BufferedFile.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -95,22 +96,17 @@ bool parseNsCookie
|
||||||
std::vector<Cookie> NsCookieParser::parse
|
std::vector<Cookie> NsCookieParser::parse
|
||||||
(const std::string& filename, time_t creationTime)
|
(const std::string& filename, time_t creationTime)
|
||||||
{
|
{
|
||||||
FILE* fp = a2fopen(utf8ToWChar(filename).c_str(), "rb");
|
BufferedFile fp(filename, BufferedFile::READ);
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
throw DL_ABORT_EX(fmt("Failed to open file %s",
|
throw DL_ABORT_EX(fmt("Failed to open file %s",
|
||||||
utf8ToNative(filename).c_str()));
|
utf8ToNative(filename).c_str()));
|
||||||
}
|
}
|
||||||
auto_delete_r<FILE*, int> deleter(fp, fclose);
|
|
||||||
std::vector<Cookie> cookies;
|
std::vector<Cookie> cookies;
|
||||||
char buf[8192];
|
char buf[8192];
|
||||||
while(1) {
|
while(1) {
|
||||||
if(!fgets(buf, sizeof(buf), fp)) {
|
if(!fp.getsn(buf, sizeof(buf))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
size_t len = strlen(buf);
|
|
||||||
if(buf[len-1] == '\n') {
|
|
||||||
buf[len-1] = '\0';
|
|
||||||
}
|
|
||||||
std::string line(buf);
|
std::string line(buf);
|
||||||
if(util::startsWith(line, A2STR::SHARP_C)) {
|
if(util::startsWith(line, A2STR::SHARP_C)) {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue