mirror of https://github.com/aria2/aria2
2006-08-28 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To make filename URL-decoded: * src/HttpResponseCommand.h: Updated doc. * src/HttpResponseCommand.cc (determinFilename): Made filename URL-decoded. * src/FtpInitiateConnectionCommand.cc (executeInternal): Made filename URL-decoded. * src/Util.h (urldecode): New function. * src/Util.cc (urldecode): New function.pull/1/head
parent
531d456950
commit
c096a3a553
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
2006-08-28 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
To make filename URL-decoded:
|
||||||
|
* src/HttpResponseCommand.h: Updated doc.
|
||||||
|
* src/HttpResponseCommand.cc
|
||||||
|
(determinFilename): Made filename URL-decoded.
|
||||||
|
* src/FtpInitiateConnectionCommand.cc
|
||||||
|
(executeInternal): Made filename URL-decoded.
|
||||||
|
* src/Util.h (urldecode): New function.
|
||||||
|
* src/Util.cc (urldecode): New function.
|
||||||
|
|
||||||
2006-08-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2006-08-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
To add --seed-time and --seed-ratio command-line option:
|
To add --seed-time and --seed-ratio command-line option:
|
||||||
|
|
4
TODO
4
TODO
|
@ -13,5 +13,5 @@
|
||||||
* List available os, version, etc for metalink
|
* List available os, version, etc for metalink
|
||||||
* ipv6(RFC2428 for ftp)
|
* ipv6(RFC2428 for ftp)
|
||||||
* Add silent mode.
|
* Add silent mode.
|
||||||
* Add NOTIFY log level. A message categorized in this level is printed in
|
* Add upload speed limit command-line option.
|
||||||
a console along with a log file.
|
* Save URLs and command-line arguments to .aria2 file.
|
||||||
|
|
|
@ -45,7 +45,7 @@ FtpInitiateConnectionCommand::~FtpInitiateConnectionCommand() {
|
||||||
|
|
||||||
bool FtpInitiateConnectionCommand::executeInternal(Segment segment) {
|
bool FtpInitiateConnectionCommand::executeInternal(Segment segment) {
|
||||||
if(!e->segmentMan->downloadStarted) {
|
if(!e->segmentMan->downloadStarted) {
|
||||||
e->segmentMan->filename = req->getFile();
|
e->segmentMan->filename = Util::urldecode(req->getFile());
|
||||||
bool segFileExists = e->segmentMan->segmentFileExists();
|
bool segFileExists = e->segmentMan->segmentFileExists();
|
||||||
if(segFileExists) {
|
if(segFileExists) {
|
||||||
e->segmentMan->load();
|
e->segmentMan->load();
|
||||||
|
|
|
@ -74,7 +74,7 @@ int HandshakeMessage::getMessageLength() {
|
||||||
|
|
||||||
string HandshakeMessage::toString() const {
|
string HandshakeMessage::toString() const {
|
||||||
return "handshake peerId="+
|
return "handshake peerId="+
|
||||||
Util::urlencode((unsigned char*)peerId, sizeof(peerId))+
|
Util::urlencode(peerId, sizeof(peerId))+
|
||||||
" reserved="+Util::toHex(reserved, sizeof(reserved));
|
" reserved="+Util::toHex(reserved, sizeof(reserved));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,11 +99,11 @@ string HttpResponseCommand::determinFilename(const HttpHeader& headers) {
|
||||||
string contentDisposition =
|
string contentDisposition =
|
||||||
Util::getContentDispositionFilename(headers.getFirst("Content-Disposition"));
|
Util::getContentDispositionFilename(headers.getFirst("Content-Disposition"));
|
||||||
if(contentDisposition.empty()) {
|
if(contentDisposition.empty()) {
|
||||||
return req->getFile();
|
return Util::urldecode(req->getFile());
|
||||||
} else {
|
} else {
|
||||||
logger->info("CUID#%d - Content-Disposition Detected. Use %s as filename",
|
logger->info("CUID#%d - Content-Disposition Detected. Use %s as filename",
|
||||||
cuid, contentDisposition.c_str());
|
cuid, contentDisposition.c_str());
|
||||||
return contentDisposition;
|
return Util::urldecode(contentDisposition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,9 @@ private:
|
||||||
bool handleOtherEncoding(const string& transferEncoding, const HttpHeader& headers);
|
bool handleOtherEncoding(const string& transferEncoding, const HttpHeader& headers);
|
||||||
void createHttpDownloadCommand(const string& transferEncoding = "");
|
void createHttpDownloadCommand(const string& transferEncoding = "");
|
||||||
void retrieveCookie(const HttpHeader& headers);
|
void retrieveCookie(const HttpHeader& headers);
|
||||||
|
/**
|
||||||
|
* Returned filename is URL-decoded.
|
||||||
|
*/
|
||||||
string determinFilename(const HttpHeader& headers);
|
string determinFilename(const HttpHeader& headers);
|
||||||
HttpConnection* http;
|
HttpConnection* http;
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
#include "SimpleLogger.h"
|
#include "SimpleLogger.h"
|
||||||
|
|
||||||
string LogFactory::filename;
|
string LogFactory::filename = "/dev/null";
|
||||||
Logger* LogFactory::logger = NULL;
|
Logger* LogFactory::logger = NULL;
|
||||||
|
|
||||||
Logger* LogFactory::getInstance() {
|
Logger* LogFactory::getInstance() {
|
||||||
|
|
|
@ -47,7 +47,9 @@ private:
|
||||||
public:
|
public:
|
||||||
SharedHandle():obj(new T()), ucount(new int(1)) {}
|
SharedHandle():obj(new T()), ucount(new int(1)) {}
|
||||||
SharedHandle(T* obj):obj(obj), ucount(new int(1)) {}
|
SharedHandle(T* obj):obj(obj), ucount(new int(1)) {}
|
||||||
|
SharedHandle(const SharedHandle<T>& t):obj(t.get()), ucount(t.getRefCount()) {
|
||||||
|
++*ucount;
|
||||||
|
}
|
||||||
template<class S>
|
template<class S>
|
||||||
SharedHandle(const SharedHandle<S>& t):obj(t.get()), ucount(t.getRefCount()) {
|
SharedHandle(const SharedHandle<S>& t):obj(t.get()), ucount(t.getRefCount()) {
|
||||||
++*ucount;
|
++*ucount;
|
||||||
|
@ -60,8 +62,18 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SharedHandle<T>& operator=(const SharedHandle<T>& t) {
|
||||||
|
++*t.getRefCount();
|
||||||
|
if(--*ucount == 0) {
|
||||||
|
delete obj;
|
||||||
|
delete ucount;
|
||||||
|
}
|
||||||
|
obj = t.get();
|
||||||
|
ucount = t.getRefCount();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
template<class S>
|
template<class S>
|
||||||
SharedHandle<T>& operator=(const SharedHandle<S>& t) {
|
SharedHandle<T>& operator=(const SharedHandle<S>& t) {
|
||||||
++*t.getRefCount();
|
++*t.getRefCount();
|
||||||
if(--*ucount == 0) {
|
if(--*ucount == 0) {
|
||||||
delete obj;
|
delete obj;
|
||||||
|
|
|
@ -653,10 +653,10 @@ void TorrentMan::onDownloadComplete() {
|
||||||
save();
|
save();
|
||||||
diskAdaptor->onDownloadComplete();
|
diskAdaptor->onDownloadComplete();
|
||||||
if(isSelectiveDownloadingMode()) {
|
if(isSelectiveDownloadingMode()) {
|
||||||
logger->notice("Download of selected files has completed.");
|
logger->notice("Download of selected files was complete.");
|
||||||
finishSelectiveDownloadingMode();
|
finishSelectiveDownloadingMode();
|
||||||
} else {
|
} else {
|
||||||
logger->info("The download has completed.");
|
logger->info("The download was complete.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ bool TrackerWatcherCommand::execute() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
string url = e->torrentMan->announce+"?"+
|
string url = e->torrentMan->announce+"?"+
|
||||||
"info_hash="+Util::torrentUrlencode(e->torrentMan->getInfoHash(), 20)+"&"+
|
"info_hash="+Util::torrentUrlencode((const char*)e->torrentMan->getInfoHash(), 20)+"&"+
|
||||||
"peer_id="+e->torrentMan->peerId+"&"+
|
"peer_id="+e->torrentMan->peerId+"&"+
|
||||||
"port="+Util::itos(e->torrentMan->getPort())+"&"+
|
"port="+Util::itos(e->torrentMan->getPort())+"&"+
|
||||||
"uploaded="+Util::llitos(e->torrentMan->getSessionUploadLength())+"&"+
|
"uploaded="+Util::llitos(e->torrentMan->getSessionUploadLength())+"&"+
|
||||||
|
|
29
src/Util.cc
29
src/Util.cc
|
@ -166,7 +166,7 @@ string Util::replace(const string& target, const string& oldstr, const string& n
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Util::urlencode(const unsigned char* target, int len) {
|
string Util::urlencode(const char* target, int len) {
|
||||||
string dest;
|
string dest;
|
||||||
for(int i = 0; i < len; i++) {
|
for(int i = 0; i < len; i++) {
|
||||||
if(!('0' <= target[i] && target[i] <= '9' ||
|
if(!('0' <= target[i] && target[i] <= '9' ||
|
||||||
|
@ -189,7 +189,7 @@ string Util::urlencode(const unsigned char* target, int len) {
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Util::torrentUrlencode(const unsigned char* target, int len) {
|
string Util::torrentUrlencode(const char* target, int len) {
|
||||||
string dest;
|
string dest;
|
||||||
for(int i = 0; i < len; i++) {
|
for(int i = 0; i < len; i++) {
|
||||||
if(isalpha(target[i]) || isdigit(target[i])) {
|
if(isalpha(target[i]) || isdigit(target[i])) {
|
||||||
|
@ -204,6 +204,31 @@ string Util::torrentUrlencode(const unsigned char* target, int len) {
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string Util::urldecode(const string& target) {
|
||||||
|
string result;
|
||||||
|
for(string::const_iterator itr = target.begin();
|
||||||
|
itr != target.end(); itr++) {
|
||||||
|
if(*itr == '+') {
|
||||||
|
result += ' ';
|
||||||
|
} else if(*itr == '%') {
|
||||||
|
if(itr+1 != target.end() && itr+2 != target.end() &&
|
||||||
|
isxdigit(*(itr+1)) && isxdigit(*(itr+2))) {
|
||||||
|
char temp[3];
|
||||||
|
temp[0] = *(itr+1);
|
||||||
|
temp[1] = *(itr+2);
|
||||||
|
temp[2] = '\0';
|
||||||
|
result += strtol(temp, 0, 16);
|
||||||
|
itr += 2;
|
||||||
|
} else {
|
||||||
|
result += *itr;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result += *itr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
string Util::toHex(const unsigned char* src, int len) {
|
string Util::toHex(const unsigned char* src, int len) {
|
||||||
char* temp = new char[len*2+1];
|
char* temp = new char[len*2+1];
|
||||||
for(int i = 0; i < len; i++) {
|
for(int i = 0; i < len; i++) {
|
||||||
|
|
|
@ -62,9 +62,11 @@ public:
|
||||||
|
|
||||||
static string replace(const string& target, const string& oldstr, const string& newstr);
|
static string replace(const string& target, const string& oldstr, const string& newstr);
|
||||||
|
|
||||||
static string urlencode(const unsigned char* target, int len);
|
static string urlencode(const char* target, int len);
|
||||||
|
|
||||||
static string torrentUrlencode(const unsigned char* target, int len);
|
static string urldecode(const string& target);
|
||||||
|
|
||||||
|
static string torrentUrlencode(const char* target, int len);
|
||||||
|
|
||||||
static string toHex(const unsigned char* src, int len);
|
static string toHex(const unsigned char* src, int len);
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ class OptionTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST_SUITE(OptionTest);
|
CPPUNIT_TEST_SUITE(OptionTest);
|
||||||
CPPUNIT_TEST(testPutAndGet);
|
CPPUNIT_TEST(testPutAndGet);
|
||||||
CPPUNIT_TEST(testPutAndGetAsInt);
|
CPPUNIT_TEST(testPutAndGetAsInt);
|
||||||
|
CPPUNIT_TEST(testPutAndGetAsDouble);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@ public:
|
||||||
|
|
||||||
void testPutAndGet();
|
void testPutAndGet();
|
||||||
void testPutAndGetAsInt();
|
void testPutAndGetAsInt();
|
||||||
|
void testPutAndGetAsDouble();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,3 +40,10 @@ void OptionTest::testPutAndGetAsInt() {
|
||||||
CPPUNIT_ASSERT(op.defined("key"));
|
CPPUNIT_ASSERT(op.defined("key"));
|
||||||
CPPUNIT_ASSERT_EQUAL(1000, op.getAsInt("key"));
|
CPPUNIT_ASSERT_EQUAL(1000, op.getAsInt("key"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OptionTest::testPutAndGetAsDouble() {
|
||||||
|
Option op;
|
||||||
|
op.put("key", "10.0");
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL(10.0, op.getAsDouble("key"));
|
||||||
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ void ShareRatioSeedCriteriaTest::testEvaluate() {
|
||||||
|
|
||||||
ShareRatioSeedCriteria cri(1.0, &torrentMan);
|
ShareRatioSeedCriteria cri(1.0, &torrentMan);
|
||||||
CPPUNIT_ASSERT(cri.evaluate());
|
CPPUNIT_ASSERT(cri.evaluate());
|
||||||
|
|
||||||
cri.setRatio(2.0);
|
cri.setRatio(2.0);
|
||||||
CPPUNIT_ASSERT(!cri.evaluate());
|
CPPUNIT_ASSERT(!cri.evaluate());
|
||||||
// check div by zero
|
// check div by zero
|
||||||
|
|
|
@ -20,6 +20,7 @@ class UtilTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testFileChecksum);
|
CPPUNIT_TEST(testFileChecksum);
|
||||||
CPPUNIT_TEST(testToUpper);
|
CPPUNIT_TEST(testToUpper);
|
||||||
CPPUNIT_TEST(testToLower);
|
CPPUNIT_TEST(testToLower);
|
||||||
|
CPPUNIT_TEST(testUrldecode);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ public:
|
||||||
void testFileChecksum();
|
void testFileChecksum();
|
||||||
void testToUpper();
|
void testToUpper();
|
||||||
void testToLower();
|
void testToLower();
|
||||||
|
void testUrldecode();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -248,3 +250,26 @@ void UtilTest::testToLower() {
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(upp, Util::toLower(src));
|
CPPUNIT_ASSERT_EQUAL(upp, Util::toLower(src));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "SharedHandle.h"
|
||||||
|
|
||||||
|
void UtilTest::testUrldecode() {
|
||||||
|
string src = "http://aria2.sourceforge.net/aria2%200.7.0%20docs.html";
|
||||||
|
CPPUNIT_ASSERT_EQUAL(string("http://aria2.sourceforge.net/aria2 0.7.0 docs.html"),
|
||||||
|
Util::urldecode(src));
|
||||||
|
|
||||||
|
string src2 = "aria2+aria2";
|
||||||
|
CPPUNIT_ASSERT_EQUAL(string("aria2 aria2"), Util::urldecode(src2));
|
||||||
|
|
||||||
|
string src3 = "%5t%20";
|
||||||
|
CPPUNIT_ASSERT_EQUAL(string("%5t "), Util::urldecode(src3));
|
||||||
|
|
||||||
|
string src4 = "%";
|
||||||
|
CPPUNIT_ASSERT_EQUAL(string("%"), Util::urldecode(src4));
|
||||||
|
|
||||||
|
string src5 = "%3";
|
||||||
|
CPPUNIT_ASSERT_EQUAL(string("%3"), Util::urldecode(src5));
|
||||||
|
|
||||||
|
string src6 = "%2f";
|
||||||
|
CPPUNIT_ASSERT_EQUAL(string("/"), Util::urldecode(src6));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue