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>
|
||||
|
||||
* Release 0.2.0
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "Request.h"
|
||||
#include "DownloadEngine.h"
|
||||
#include "SegmentMan.h"
|
||||
#include "common.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
class AbstractCommand : public Command {
|
||||
private:
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#ifndef _BASE64_H_
|
||||
#define _BASE64_H_
|
||||
#include <string>
|
||||
#include "common.h"
|
||||
using namespace std;
|
||||
|
||||
class Base64
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#define _D_CHUNKED_ENCODING_H_
|
||||
|
||||
#include "TransferEncoding.h"
|
||||
#include "common.h"
|
||||
|
||||
class ChunkedEncoding:public TransferEncoding {
|
||||
private:
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef _D_COMMAND_H_
|
||||
#define _D_COMMAND_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
class Command {
|
||||
protected:
|
||||
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++) {
|
||||
const Cookie& c = *itr;
|
||||
if((secure || !c.secure && !secure) &&
|
||||
c.domain.size() <= host.size() &&
|
||||
c.path.size() <= dir.size() &&
|
||||
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) {
|
||||
Util::endsWith(host, c.domain) &&
|
||||
Util::startsWith(dir, c.path)) {
|
||||
// TODO we currently ignore expire date.
|
||||
result.push_back(c);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#ifndef _D_COOKIE_BOX_H_
|
||||
#define _D_COOKIE_BOX_H_
|
||||
|
||||
#include "common.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "AbstractCommand.h"
|
||||
#include "TransferEncoding.h"
|
||||
#include <sys/time.h>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -24,7 +24,9 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <fcntl.h>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
|
@ -22,7 +22,9 @@
|
|||
#ifndef _D_EXCEPTION_H_
|
||||
#define _D_EXCEPTION_H_
|
||||
|
||||
#include "common.h"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#ifndef _D_FILE_H_
|
||||
#define _D_FILE_H_
|
||||
|
||||
#include "common.h"
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "Logger.h"
|
||||
#include "Segment.h"
|
||||
#include "Request.h"
|
||||
#include "common.h"
|
||||
#include <utility>
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "Option.h"
|
||||
#include "Logger.h"
|
||||
#include "HttpHeader.h"
|
||||
#include "common.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#ifndef _D_HTTP_HEADER_H_
|
||||
#define _D_HTTP_HEADER_H_
|
||||
|
||||
#include "common.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
|
|
@ -21,8 +21,10 @@
|
|||
/* copyright --> */
|
||||
#ifndef _D_LOGGER_H_
|
||||
#define _D_LOGGER_H_
|
||||
|
||||
#include <string>
|
||||
#include "Exception.h"
|
||||
#include "common.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#ifndef _D_OPTION_H_
|
||||
#define _D_OPTION_H_
|
||||
|
||||
#include "common.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#ifndef _D_SEGMENT_H_
|
||||
#define _D_SEGMENT_H_
|
||||
|
||||
#include "common.h"
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "Segment.h"
|
||||
#include "Logger.h"
|
||||
#include "common.h"
|
||||
|
||||
class SegmentSplitter {
|
||||
protected:
|
||||
|
|
|
@ -129,6 +129,7 @@ void SocketCore::establishConnection(string host, int port) {
|
|||
// ok
|
||||
} else {
|
||||
struct addrinfo ai;
|
||||
memset((char*)&ai, 0, sizeof(ai));
|
||||
ai.ai_flags = 0;
|
||||
ai.ai_family = PF_INET;
|
||||
ai.ai_socktype = SOCK_STREAM;
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef _D_TRANSFER_ENCODING_H_
|
||||
#define _D_TRANSFER_ENCODING_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
class TransferEncoding {
|
||||
public:
|
||||
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 {
|
||||
hp.first = trim(src.substr(0, p));
|
||||
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) {
|
||||
if(target.size() < part.size()) {
|
||||
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;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#ifndef _D_UTIL_H_
|
||||
#define _D_UTIL_H_
|
||||
|
||||
#include "common.h"
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
@ -50,6 +51,8 @@ public:
|
|||
|
||||
static string trim(string src);
|
||||
|
||||
static bool startsWith(string target, string part);
|
||||
|
||||
static bool endsWith(string target, string part);
|
||||
|
||||
static string replace(string target, string oldstr, string newstr);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
/* copyright --> */
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef _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_NO_SEGMENT_AVAILABLE "CUID#%d - No segment available."
|
||||
#define MSG_CONNECTING_TO_SERVER "CUID#%d - Connecting to %s:%d"
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef _D_PREFS_H_
|
||||
#define _D_PREFS_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
|
|
|
@ -12,6 +12,7 @@ class UtilTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testSlice);
|
||||
CPPUNIT_TEST(testEndsWith);
|
||||
CPPUNIT_TEST(testReplace);
|
||||
CPPUNIT_TEST(testStartsWith);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
|
@ -24,6 +25,7 @@ public:
|
|||
void testSlice();
|
||||
void testEndsWith();
|
||||
void testReplace();
|
||||
void testStartsWith();
|
||||
};
|
||||
|
||||
|
||||
|
@ -121,3 +123,37 @@ void UtilTest::testReplace() {
|
|||
CPPUNIT_ASSERT_EQUAL(string("abc"), Util::replace("abc", "", "a"));
|
||||
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