pull/1/head
Tatsuhiro Tsujikawa 2006-02-21 15:01:05 +00:00
parent 32e8f2b011
commit 28fc3405dd
10 changed files with 87 additions and 33 deletions

View File

@ -1,23 +1,41 @@
2006-02-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* FtpInitiateConnectionCommand.{h,cc}:
* FtpNegotiationCommand.{h,cc}:
* FtpDownloadCommand.{h,cc}:
* FtpConnection.{h,cc}: Added FTP support
* SimpleLogger.cc: Log message now includes time information.
* main.cc: The value of --http-auth-scheme option is chagned from
'BASIC' to 'basic'
* main.cc: Added --timeout command-line option.
* prefs.h: option string constants are now defined in prefs.h
2006-02-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2006-02-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Fixed timeout bug in AbstractCommand * AbstractCommand.cc: Fixed timeout bug in AbstractCommand
* Added totalSize entry to .aria2 file. No compatibility for * SegmentMan.cc: Added totalSize entry to .aria2 file. No compatibility
version 0.1.0's. with version 0.1.0's one.
2006-02-18 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2006-02-18 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Added --enable-ssl option to configure script. * configure.in: Added --enable-ssl option to configure script.
* Make Request-URI an absolute path. Some servers cannot permit * HttpConnection.cc: Make Request-URI an absolute path. Some servers
absoluteURI as Request-URI. cannot permit absoluteURI as Request-URI.
* Added Referer support. * HttpConnection.cc: Added Referer support.
* Added referer command-line option. * main.cc: Added referer command-line option.
* Added rety-wait command-line option. * main.cc: Added rety-wait command-line option.
* Fixed formating bug in Exception::setMsg() * Exception.h: Fixed formating bug in Exception::setMsg()
* Added HTTPS support. * SocketCore.{h,cc}:
* Added SocketCore. Socket is now handle class for SocketCore. * Socket.{h, cc}:
* Fixed bug in ChunkedEncoding: expanding buffer size is wrong * Request.cc:
* Fixed bug in DownloadCommand: In Chunked Encoding, it wrongly * InitiateConnectionCommandFactory.cc:
adds to Segment.ds buff length from the socket. * HttpRequestCommand.cc: Added HTTPS support.
* SocketCore.{h,cc}: Added SocketCore. Socket becomes a handle class
for SocketCore.
* ChunkedEncoding.cc: Fixed bug in ChunkedEncoding: expanding buffer
size is wrong
* DownloadCommand.cc: Fixed bug in DownloadCommand: In Chunked
Encoding, it wrongly adds to Segment.ds buff length from the socket.
2006-02-17 Tatsuhiro Tsujikawa <tsujikawa at rednoah dot com> 2006-02-17 Tatsuhiro Tsujikawa <tsujikawa at rednoah dot com>

6
README
View File

@ -1,4 +1,4 @@
aria2 - a simple utility for downloading files faster. aria2 - a simple utility for downloading files.
1. Disclaimer 1. Disclaimer
------------- -------------
@ -11,10 +11,12 @@ aria2 has segmented downloading engine in its core. By segmented downloading,
it can download files very much faster than ordinary browsers. it can download files very much faster than ordinary browsers.
aria2 is in very early development stage. Currently it has following features: aria2 is in very early development stage. Currently it has following features:
* HTTP GET support * HTTP/HTTPS GET support
* HTTP Proxy support * HTTP Proxy support
* HTTP BASIC authentication support * HTTP BASIC authentication support
* HTTP Proxy authentication support * HTTP Proxy authentication support
* FTP support(active, passive mode)
* FTP through HTTP proxy(GET command or tunneling)
* Segmented download * Segmented download
* Cookie support(currently aria2 ignores "expires") * Cookie support(currently aria2 ignores "expires")
* It can run as a daemon process. * It can run as a daemon process.

1
TODO
View File

@ -1,6 +1,5 @@
* Add HTTP POST support * Add HTTP POST support
* Add expires handling for Cookie * Add expires handling for Cookie
* Add FTP support
* Add SSL server cert verification * Add SSL server cert verification
* Add SSL client cert support * Add SSL client cert support
* Better HTTP status handling * Better HTTP status handling

View File

@ -32,13 +32,13 @@ FtpConnection::~FtpConnection() {}
void FtpConnection::sendUser() const { void FtpConnection::sendUser() const {
string request = "USER "+option->get(PREF_FTP_USER)+"\r\n"; string request = "USER "+option->get(PREF_FTP_USER)+"\r\n";
logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str()); logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request); socket->writeData(request);
} }
void FtpConnection::sendPass() const { void FtpConnection::sendPass() const {
string request = "PASS "+option->get(PREF_FTP_PASSWD)+"\r\n"; string request = "PASS "+option->get(PREF_FTP_PASSWD)+"\r\n";
logger->info(MSG_SENDING_FTP_REQUEST, cuid, "PASS ********"); logger->info(MSG_SENDING_REQUEST, cuid, "PASS ********");
socket->writeData(request); socket->writeData(request);
} }
@ -50,25 +50,25 @@ void FtpConnection::sendType() const {
type = "I"; type = "I";
} }
string request = "TYPE "+type+"\r\n"; string request = "TYPE "+type+"\r\n";
logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str()); logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request); socket->writeData(request);
} }
void FtpConnection::sendCwd() const { void FtpConnection::sendCwd() const {
string request = "CWD "+req->getDir()+"\r\n"; string request = "CWD "+req->getDir()+"\r\n";
logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str()); logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request); socket->writeData(request);
} }
void FtpConnection::sendSize() const { void FtpConnection::sendSize() const {
string request = "SIZE "+req->getFile()+"\r\n"; string request = "SIZE "+req->getFile()+"\r\n";
logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str()); logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request); socket->writeData(request);
} }
void FtpConnection::sendPasv() const { void FtpConnection::sendPasv() const {
string request = "PASV\r\n"; string request = "PASV\r\n";
logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str()); logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request); socket->writeData(request);
} }
@ -87,7 +87,7 @@ Socket* FtpConnection::sendPort() const {
Util::itos(ipaddr[0])+","+Util::itos(ipaddr[1])+","+ Util::itos(ipaddr[0])+","+Util::itos(ipaddr[1])+","+
Util::itos(ipaddr[2])+","+Util::itos(ipaddr[3])+","+ Util::itos(ipaddr[2])+","+Util::itos(ipaddr[3])+","+
Util::itos(addrinfo.second/256)+","+Util::itos(addrinfo.second%256)+"\r\n"; Util::itos(addrinfo.second/256)+","+Util::itos(addrinfo.second%256)+"\r\n";
logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str()); logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request); socket->writeData(request);
} catch (Exception* ex) { } catch (Exception* ex) {
delete serverSocket; delete serverSocket;
@ -98,13 +98,13 @@ Socket* FtpConnection::sendPort() const {
void FtpConnection::sendRest(const Segment& segment) const { void FtpConnection::sendRest(const Segment& segment) const {
string request = "REST "+Util::llitos(segment.sp+segment.ds)+"\r\n"; string request = "REST "+Util::llitos(segment.sp+segment.ds)+"\r\n";
logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str()); logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request); socket->writeData(request);
} }
void FtpConnection::sendRetr() const { void FtpConnection::sendRetr() const {
string request = "RETR "+req->getFile()+"\r\n"; string request = "RETR "+req->getFile()+"\r\n";
logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str()); logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request); socket->writeData(request);
} }

View File

@ -31,7 +31,7 @@ HttpConnection::HttpConnection(int cuid, const Socket* socket, const Request* re
void HttpConnection::sendRequest(const Segment& segment) const { void HttpConnection::sendRequest(const Segment& segment) const {
string request = createRequest(segment); string request = createRequest(segment);
logger->info(MSG_SENDING_HTTP_REQUEST, cuid, request.c_str()); logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request.c_str(), request.size()); socket->writeData(request.c_str(), request.size());
} }
@ -46,7 +46,7 @@ void HttpConnection::sendProxyRequest() const {
option->get(PREF_HTTP_PROXY_PORT))+"\r\n"; option->get(PREF_HTTP_PROXY_PORT))+"\r\n";
} }
request += "\r\n"; request += "\r\n";
logger->info(MSG_SENDING_HTTP_REQUEST, cuid, request.c_str()); logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request.c_str(), request.size()); socket->writeData(request.c_str(), request.size());
} }

View File

@ -20,6 +20,8 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "SimpleLogger.h" #include "SimpleLogger.h"
#include "Util.h"
#include <time.h>
#include <stdarg.h> #include <stdarg.h>
SimpleLogger::SimpleLogger(string filename) { SimpleLogger::SimpleLogger(string filename) {
@ -50,9 +52,13 @@ void SimpleLogger::writeLog(int level, string msg, va_list ap, Exception* e) con
default: default:
levelStr = "INFO"; levelStr = "INFO";
} }
vfprintf(file, string(levelStr+" - "+msg+"\n").c_str(), ap); time_t now = time(NULL);
char datestr[26];
ctime_r(&now, datestr);
datestr[strlen(datestr)-1] = '\0';
vfprintf(file, string(string(datestr)+" - "+levelStr+" - "+Util::replace(msg, "\r", "")+"\n").c_str(), ap);
if(e != NULL) { if(e != NULL) {
fprintf(file, string(levelStr+" - exception: "+e->getMsg()+"\n").c_str()); fprintf(file, string(string(datestr)+" - "+levelStr+" - exception: "+Util::replace(e->getMsg(), "\r", "")+"\n").c_str());
} }
fflush(stdout); fflush(stdout);
} }

View File

@ -119,3 +119,21 @@ bool Util::endsWith(string target, string part) {
return false; return false;
} }
} }
string Util::replace(string target, string oldstr, string newstr) {
if(target == "" || oldstr == "" ) {
return target;
}
string result;
string::size_type p = 0;
string::size_type np = target.find(oldstr);
while(np != string::npos) {
result += target.substr(p, np-p)+newstr;
p = np+oldstr.size();
np = target.find(oldstr, p);
}
result += target.substr(p);
return result;
}

View File

@ -51,6 +51,8 @@ public:
static string trim(string src); static string trim(string src);
static bool endsWith(string target, string part); static bool endsWith(string target, string part);
static string replace(string target, string oldstr, string newstr);
}; };
#endif // _D_UTIL_H_ #endif // _D_UTIL_H_

View File

@ -27,8 +27,7 @@
#define MSG_CONNECTING_TO_SERVER "CUID#%d - Connecting to %s:%d" #define MSG_CONNECTING_TO_SERVER "CUID#%d - Connecting to %s:%d"
#define MSG_SEGMENT_CHANGED "CUID#%d - The segment changed. We send the request again with new Range header." #define MSG_SEGMENT_CHANGED "CUID#%d - The segment changed. We send the request again with new Range header."
#define MSG_REDIRECT "CUID#%d - Redirecting to %s" #define MSG_REDIRECT "CUID#%d - Redirecting to %s"
#define MSG_SENDING_HTTP_REQUEST "CUID#%d - Sending the request:\n%s" #define MSG_SENDING_REQUEST "CUID#%d - Requesting:\n%s"
#define MSG_SENDING_FTP_REQUEST "CUID#%d - Sending the request: %s"
#define MSG_RECEIVE_RESPONSE "CUID#%d - Response received:\n%s" #define MSG_RECEIVE_RESPONSE "CUID#%d - Response received:\n%s"
#define MSG_DOWNLOAD_ABORTED "CUID#%d - Download aborted." #define MSG_DOWNLOAD_ABORTED "CUID#%d - Download aborted."
#define MSG_RESTARTING_DOWNLOAD "CUID#%d - Restarting the download." #define MSG_RESTARTING_DOWNLOAD "CUID#%d - Restarting the download."

View File

@ -11,6 +11,7 @@ class UtilTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testSplit); CPPUNIT_TEST(testSplit);
CPPUNIT_TEST(testSlice); CPPUNIT_TEST(testSlice);
CPPUNIT_TEST(testEndsWith); CPPUNIT_TEST(testEndsWith);
CPPUNIT_TEST(testReplace);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
@ -22,6 +23,7 @@ public:
void testSplit(); void testSplit();
void testSlice(); void testSlice();
void testEndsWith(); void testEndsWith();
void testReplace();
}; };
@ -111,3 +113,11 @@ void UtilTest::testEndsWith() {
part = "g"; part = "g";
CPPUNIT_ASSERT(!Util::endsWith(target, part)); CPPUNIT_ASSERT(!Util::endsWith(target, part));
} }
void UtilTest::testReplace() {
CPPUNIT_ASSERT_EQUAL(string("abc\n"), Util::replace("abc\r\n", "\r", ""));
CPPUNIT_ASSERT_EQUAL(string("abc"), Util::replace("abc\r\n", "\r\n", ""));
CPPUNIT_ASSERT_EQUAL(string(""), Util::replace("", "\r\n", ""));
CPPUNIT_ASSERT_EQUAL(string("abc"), Util::replace("abc", "", "a"));
CPPUNIT_ASSERT_EQUAL(string("xbc"), Util::replace("abc", "a", "x"));
}