mirror of https://github.com/aria2/aria2
* Util.{h,cc}: added startsWith().
* CookieBox.cc: rewrited criteriaFind() using Util::startsWith() and Util::endsWith(). * SocketCore.cc: struct addrinfo is now zero-initialized. * common.h: added #include directive of limit.h. * DownloadEngine.cc: added #include directive of sys/time.h and algorithm. * Exception.h: added #include directive of stdio.h. * AbstractCommand.h: added #include directive of sys/time.h. * DownloadCommand.h: added #include directive of sys/time.h. * *.h: added #include directive of common.h to all base classes. subclasses' one was removed.pull/1/head
parent
87a229cab1
commit
20ba8c707a
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
2006-02-28 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
* Util.{h,cc}: added startsWith().
|
||||||
|
* CookieBox.cc: rewrited criteriaFind() using Util::startsWith() and
|
||||||
|
Util::endsWith().
|
||||||
|
* SocketCore.cc: struct addrinfo is now zero-initialized.
|
||||||
|
* common.h: added #include directive of limit.h.
|
||||||
|
* DownloadEngine.cc: added #include directive of sys/time.h and
|
||||||
|
algorithm.
|
||||||
|
* Exception.h: added #include directive of stdio.h.
|
||||||
|
* AbstractCommand.h: added #include directive of sys/time.h.
|
||||||
|
* DownloadCommand.h: added #include directive of sys/time.h.
|
||||||
|
* *.h: added #include directive of common.h to all base classes.
|
||||||
|
subclasses' one was removed.
|
||||||
|
|
||||||
2006-02-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2006-02-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
* Release 0.2.0
|
* Release 0.2.0
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
#include "SegmentMan.h"
|
#include "SegmentMan.h"
|
||||||
#include "common.h"
|
#include <sys/time.h>
|
||||||
|
|
||||||
class AbstractCommand : public Command {
|
class AbstractCommand : public Command {
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#ifndef _BASE64_H_
|
#ifndef _BASE64_H_
|
||||||
#define _BASE64_H_
|
#define _BASE64_H_
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "common.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class Base64
|
class Base64
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#define _D_CHUNKED_ENCODING_H_
|
#define _D_CHUNKED_ENCODING_H_
|
||||||
|
|
||||||
#include "TransferEncoding.h"
|
#include "TransferEncoding.h"
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
class ChunkedEncoding:public TransferEncoding {
|
class ChunkedEncoding:public TransferEncoding {
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#ifndef _D_COMMAND_H_
|
#ifndef _D_COMMAND_H_
|
||||||
#define _D_COMMAND_H_
|
#define _D_COMMAND_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
class Command {
|
class Command {
|
||||||
protected:
|
protected:
|
||||||
int cuid;
|
int cuid;
|
||||||
|
|
|
@ -68,10 +68,8 @@ vector<Cookie> CookieBox::criteriaFind(string host, string dir, bool secure) con
|
||||||
for(vector<Cookie>::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) {
|
for(vector<Cookie>::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) {
|
||||||
const Cookie& c = *itr;
|
const Cookie& c = *itr;
|
||||||
if((secure || !c.secure && !secure) &&
|
if((secure || !c.secure && !secure) &&
|
||||||
c.domain.size() <= host.size() &&
|
Util::endsWith(host, c.domain) &&
|
||||||
c.path.size() <= dir.size() &&
|
Util::startsWith(dir, c.path)) {
|
||||||
c.domain.compare(0, c.domain.size(), host, host.size()-c.domain.size(), c.domain.size()) == 0 &&
|
|
||||||
c.path.compare(0, c.path.size(), dir, 0, c.path.size()) == 0) {
|
|
||||||
// TODO we currently ignore expire date.
|
// TODO we currently ignore expire date.
|
||||||
result.push_back(c);
|
result.push_back(c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#ifndef _D_COOKIE_BOX_H_
|
#ifndef _D_COOKIE_BOX_H_
|
||||||
#define _D_COOKIE_BOX_H_
|
#define _D_COOKIE_BOX_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "AbstractCommand.h"
|
#include "AbstractCommand.h"
|
||||||
#include "TransferEncoding.h"
|
#include "TransferEncoding.h"
|
||||||
|
#include <sys/time.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -24,7 +24,9 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,9 @@
|
||||||
#ifndef _D_EXCEPTION_H_
|
#ifndef _D_EXCEPTION_H_
|
||||||
#define _D_EXCEPTION_H_
|
#define _D_EXCEPTION_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#ifndef _D_FILE_H_
|
#ifndef _D_FILE_H_
|
||||||
#define _D_FILE_H_
|
#define _D_FILE_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Segment.h"
|
#include "Segment.h"
|
||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
|
#include "common.h"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "HttpHeader.h"
|
#include "HttpHeader.h"
|
||||||
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#ifndef _D_HTTP_HEADER_H_
|
#ifndef _D_HTTP_HEADER_H_
|
||||||
#define _D_HTTP_HEADER_H_
|
#define _D_HTTP_HEADER_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
|
@ -21,8 +21,10 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#ifndef _D_LOGGER_H_
|
#ifndef _D_LOGGER_H_
|
||||||
#define _D_LOGGER_H_
|
#define _D_LOGGER_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#ifndef _D_OPTION_H_
|
#ifndef _D_OPTION_H_
|
||||||
#define _D_OPTION_H_
|
#define _D_OPTION_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#ifndef _D_SEGMENT_H_
|
#ifndef _D_SEGMENT_H_
|
||||||
#define _D_SEGMENT_H_
|
#define _D_SEGMENT_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "Segment.h"
|
#include "Segment.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
class SegmentSplitter {
|
class SegmentSplitter {
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -129,6 +129,7 @@ void SocketCore::establishConnection(string host, int port) {
|
||||||
// ok
|
// ok
|
||||||
} else {
|
} else {
|
||||||
struct addrinfo ai;
|
struct addrinfo ai;
|
||||||
|
memset((char*)&ai, 0, sizeof(ai));
|
||||||
ai.ai_flags = 0;
|
ai.ai_flags = 0;
|
||||||
ai.ai_family = PF_INET;
|
ai.ai_family = PF_INET;
|
||||||
ai.ai_socktype = SOCK_STREAM;
|
ai.ai_socktype = SOCK_STREAM;
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#ifndef _D_TRANSFER_ENCODING_H_
|
#ifndef _D_TRANSFER_ENCODING_H_
|
||||||
#define _D_TRANSFER_ENCODING_H_
|
#define _D_TRANSFER_ENCODING_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
class TransferEncoding {
|
class TransferEncoding {
|
||||||
public:
|
public:
|
||||||
virtual ~TransferEncoding() {}
|
virtual ~TransferEncoding() {}
|
||||||
|
|
27
src/Util.cc
27
src/Util.cc
|
@ -73,14 +73,6 @@ void Util::split(pair<string, string>& hp, string src, char delim) {
|
||||||
} else {
|
} else {
|
||||||
hp.first = trim(src.substr(0, p));
|
hp.first = trim(src.substr(0, p));
|
||||||
hp.second = trim(src.substr(p+1));
|
hp.second = trim(src.substr(p+1));
|
||||||
/*
|
|
||||||
unsigned int p2 = src.find_first_not_of(" ", p+1);
|
|
||||||
if(p2 == string::npos) {
|
|
||||||
hp.second = "";
|
|
||||||
} else {
|
|
||||||
hp.second = src.substr(p2);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,11 +101,28 @@ void Util::slice(vector<string>& result, string src, char delim) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Util::startsWith(string target, string part) {
|
||||||
|
if(target.size() < part.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(part == "") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(target.find(part) == 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Util::endsWith(string target, string part) {
|
bool Util::endsWith(string target, string part) {
|
||||||
if(target.size() < part.size()) {
|
if(target.size() < part.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(target.compare(target.size()-part.size(), part.size(), part, 0, part.size()) == 0) {
|
if(part == "") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(target.find(part) == target.size()-part.size()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#ifndef _D_UTIL_H_
|
#ifndef _D_UTIL_H_
|
||||||
#define _D_UTIL_H_
|
#define _D_UTIL_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -50,6 +51,8 @@ public:
|
||||||
|
|
||||||
static string trim(string src);
|
static string trim(string src);
|
||||||
|
|
||||||
|
static bool startsWith(string target, string part);
|
||||||
|
|
||||||
static bool endsWith(string target, string part);
|
static bool endsWith(string target, string part);
|
||||||
|
|
||||||
static string replace(string target, string oldstr, string newstr);
|
static string replace(string target, string oldstr, string newstr);
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#ifndef _D_MESSAGE_H_
|
#ifndef _D_MESSAGE_H_
|
||||||
#define _D_MESSAGE_H_
|
#define _D_MESSAGE_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#define MSG_DOWNLOAD_COMPLETED "CUID#%d - The download for one segment completed successfully."
|
#define MSG_DOWNLOAD_COMPLETED "CUID#%d - The download for one segment completed successfully."
|
||||||
#define MSG_NO_SEGMENT_AVAILABLE "CUID#%d - No segment available."
|
#define MSG_NO_SEGMENT_AVAILABLE "CUID#%d - No segment available."
|
||||||
#define MSG_CONNECTING_TO_SERVER "CUID#%d - Connecting to %s:%d"
|
#define MSG_CONNECTING_TO_SERVER "CUID#%d - Connecting to %s:%d"
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#ifndef _D_PREFS_H_
|
#ifndef _D_PREFS_H_
|
||||||
#define _D_PREFS_H_
|
#define _D_PREFS_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -12,6 +12,7 @@ class UtilTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testSlice);
|
CPPUNIT_TEST(testSlice);
|
||||||
CPPUNIT_TEST(testEndsWith);
|
CPPUNIT_TEST(testEndsWith);
|
||||||
CPPUNIT_TEST(testReplace);
|
CPPUNIT_TEST(testReplace);
|
||||||
|
CPPUNIT_TEST(testStartsWith);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ public:
|
||||||
void testSlice();
|
void testSlice();
|
||||||
void testEndsWith();
|
void testEndsWith();
|
||||||
void testReplace();
|
void testReplace();
|
||||||
|
void testStartsWith();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,3 +123,37 @@ void UtilTest::testReplace() {
|
||||||
CPPUNIT_ASSERT_EQUAL(string("abc"), Util::replace("abc", "", "a"));
|
CPPUNIT_ASSERT_EQUAL(string("abc"), Util::replace("abc", "", "a"));
|
||||||
CPPUNIT_ASSERT_EQUAL(string("xbc"), Util::replace("abc", "a", "x"));
|
CPPUNIT_ASSERT_EQUAL(string("xbc"), Util::replace("abc", "a", "x"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UtilTest::testStartsWith() {
|
||||||
|
string target;
|
||||||
|
string part;
|
||||||
|
|
||||||
|
target = "abcdefg";
|
||||||
|
part = "abc";
|
||||||
|
CPPUNIT_ASSERT(Util::startsWith(target, part));
|
||||||
|
|
||||||
|
target = "abcdefg";
|
||||||
|
part = "abx";
|
||||||
|
CPPUNIT_ASSERT(!Util::startsWith(target, part));
|
||||||
|
|
||||||
|
target = "abcdefg";
|
||||||
|
part = "bcd";
|
||||||
|
CPPUNIT_ASSERT(!Util::startsWith(target, part));
|
||||||
|
|
||||||
|
target = "";
|
||||||
|
part = "a";
|
||||||
|
CPPUNIT_ASSERT(!Util::startsWith(target, part));
|
||||||
|
|
||||||
|
target = "";
|
||||||
|
part = "";
|
||||||
|
CPPUNIT_ASSERT(Util::startsWith(target, part));
|
||||||
|
|
||||||
|
target = "a";
|
||||||
|
part = "";
|
||||||
|
CPPUNIT_ASSERT(Util::startsWith(target, part));
|
||||||
|
|
||||||
|
target = "a";
|
||||||
|
part = "a";
|
||||||
|
CPPUNIT_ASSERT(Util::startsWith(target, part));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue