pull/1/head
Tatsuhiro Tsujikawa 2006-02-21 14:00:58 +00:00
parent e0aa767f94
commit 32e8f2b011
13 changed files with 237 additions and 87 deletions

2
README
View File

@ -7,7 +7,7 @@ You must use this program at your own risk.
2. About aria2 2. About aria2
-------------- --------------
aria2 has segmented downloading engine in its core. By segmented downloding, 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:

View File

@ -27,8 +27,7 @@
#include "Util.h" #include "Util.h"
#include "message.h" #include "message.h"
#include "SleepCommand.h" #include "SleepCommand.h"
#include "prefs.h"
#define TIMEOUT_SEC 60
AbstractCommand::AbstractCommand(int cuid, Request* req, DownloadEngine* e, Socket* s): AbstractCommand::AbstractCommand(int cuid, Request* req, DownloadEngine* e, Socket* s):
Command(cuid), req(req), e(e), checkSocketIsReadable(false), checkSocketIsWritable(false) { Command(cuid), req(req), e(e), checkSocketIsReadable(false), checkSocketIsWritable(false) {
@ -63,7 +62,7 @@ bool AbstractCommand::isTimeoutDetected() {
return false; return false;
} else { } else {
long long int elapsed = Util::difftv(now, checkPoint); long long int elapsed = Util::difftv(now, checkPoint);
if(elapsed >= TIMEOUT_SEC*1000000) { if(elapsed >= e->option->getAsInt(PREF_TIMEOUT)*1000000) {
return true; return true;
} else { } else {
return false; return false;
@ -103,11 +102,11 @@ bool AbstractCommand::execute() {
delete(err); delete(err);
//req->resetUrl(); //req->resetUrl();
req->addTryCount(); req->addTryCount();
if(req->noMoreTry()) { if(req->getTryCount() >= e->option->getAsInt(PREF_MAX_TRY)) {
e->logger->error(MSG_MAX_RETRY, cuid); e->logger->error(MSG_MAX_TRY, cuid, req->getTryCount());
return true; return true;
} else { } else {
return prepareForRetry(e->option->getAsInt("retry_wait")); return prepareForRetry(e->option->getAsInt(PREF_RETRY_WAIT));
} }
} }
} }

View File

@ -20,12 +20,11 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "Util.h"
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "DlAbortEx.h"
#include "Util.h"
using namespace std; using namespace std;

View File

@ -22,26 +22,34 @@
#include "FtpConnection.h" #include "FtpConnection.h"
#include "Util.h" #include "Util.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "DlRetryEx.h"
#include "message.h" #include "message.h"
#include "prefs.h"
FtpConnection::FtpConnection(int cuid, const Socket* socket, const Request* req, const Option* op, const Logger* logger):cuid(cuid), socket(socket), req(req), option(op), logger(logger) {} FtpConnection::FtpConnection(int cuid, const Socket* socket, const Request* req, const Option* op, const Logger* logger):cuid(cuid), socket(socket), req(req), option(op), logger(logger) {}
FtpConnection::~FtpConnection() {} FtpConnection::~FtpConnection() {}
void FtpConnection::sendUser() const { void FtpConnection::sendUser() const {
string request = "USER "+option->get("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_FTP_REQUEST, cuid, request.c_str());
socket->writeData(request); socket->writeData(request);
} }
void FtpConnection::sendPass() const { void FtpConnection::sendPass() const {
string request = "PASS "+option->get("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_FTP_REQUEST, cuid, "PASS ********");
socket->writeData(request); socket->writeData(request);
} }
void FtpConnection::sendType() const { void FtpConnection::sendType() const {
string request = "TYPE "+option->get("ftp_type")+"\r\n"; string type;
if(option->get(PREF_FTP_TYPE) == V_ASCII) {
type = "A";
} else {
type = "I";
}
string request = "TYPE "+type+"\r\n";
logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str()); logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str());
socket->writeData(request); socket->writeData(request);
} }
@ -143,7 +151,7 @@ bool FtpConnection::bulkReceiveResponse(pair<int, string>& response) {
if(strbuf.size() >= 4) { if(strbuf.size() >= 4) {
status = getStatus(strbuf); status = getStatus(strbuf);
if(status == 0) { if(status == 0) {
throw new DlAbortEx(EX_INVALID_RESPONSE); throw new DlRetryEx(EX_INVALID_RESPONSE);
} }
} else { } else {
return false; return false;
@ -197,7 +205,7 @@ int FtpConnection::receivePasvResponse(pair<string, int>& dest) {
// port number // port number
dest.second = 256*p1+p2; dest.second = 256*p1+p2;
} else { } else {
throw new DlAbortEx(EX_INVALID_RESPONSE); throw new DlRetryEx(EX_INVALID_RESPONSE);
} }
} }
return response.first; return response.first;

View File

@ -25,6 +25,7 @@
#include "FtpTunnelRequestCommand.h" #include "FtpTunnelRequestCommand.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "message.h" #include "message.h"
#include "prefs.h"
FtpInitiateConnectionCommand::FtpInitiateConnectionCommand(int cuid, Request* req, DownloadEngine* e):AbstractCommand(cuid, req, e) {} FtpInitiateConnectionCommand::FtpInitiateConnectionCommand(int cuid, Request* req, DownloadEngine* e):AbstractCommand(cuid, req, e) {}
@ -47,10 +48,10 @@ bool FtpInitiateConnectionCommand::executeInternal(Segment segment) {
Command* command; Command* command;
if(useHttpProxy()) { if(useHttpProxy()) {
e->logger->info(MSG_CONNECTING_TO_SERVER, cuid, e->logger->info(MSG_CONNECTING_TO_SERVER, cuid,
e->option->get("http_proxy_host").c_str(), e->option->get(PREF_HTTP_PROXY_HOST).c_str(),
e->option->getAsInt("http_proxy_port")); e->option->getAsInt(PREF_HTTP_PROXY_PORT));
socket->establishConnection(e->option->get("http_proxy_host"), socket->establishConnection(e->option->get(PREF_HTTP_PROXY_HOST),
e->option->getAsInt("http_proxy_port")); e->option->getAsInt(PREF_HTTP_PROXY_PORT));
if(useHttpProxyGet()) { if(useHttpProxyGet()) {
command = new HttpRequestCommand(cuid, req, e, socket); command = new HttpRequestCommand(cuid, req, e, socket);
@ -71,14 +72,13 @@ bool FtpInitiateConnectionCommand::executeInternal(Segment segment) {
} }
bool FtpInitiateConnectionCommand::useHttpProxy() const { bool FtpInitiateConnectionCommand::useHttpProxy() const {
return e->option->defined("http_proxy_enabled") && return e->option->get(PREF_HTTP_PROXY_ENABLED) == V_TRUE;
e->option->get("http_proxy_enabled") == "true";
} }
bool FtpInitiateConnectionCommand::useHttpProxyGet() const { bool FtpInitiateConnectionCommand::useHttpProxyGet() const {
return useHttpProxy() && e->option->get("ftp_via_http_proxy") == "get"; return useHttpProxy() && e->option->get(PREF_FTP_VIA_HTTP_PROXY) == V_GET;
} }
bool FtpInitiateConnectionCommand::useHttpProxyConnect() const { bool FtpInitiateConnectionCommand::useHttpProxyConnect() const {
return useHttpProxy() && e->option->get("ftp_via_http_proxy") == "tunnel"; return useHttpProxy() && e->option->get(PREF_FTP_VIA_HTTP_PROXY) == V_TUNNEL;
} }

View File

@ -22,7 +22,9 @@
#include "FtpNegotiationCommand.h" #include "FtpNegotiationCommand.h"
#include "FtpDownloadCommand.h" #include "FtpDownloadCommand.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "DlRetryEx.h"
#include "message.h" #include "message.h"
#include "prefs.h"
FtpNegotiationCommand::FtpNegotiationCommand(int cuid, Request* req, DownloadEngine* e, Socket* s): FtpNegotiationCommand::FtpNegotiationCommand(int cuid, Request* req, DownloadEngine* e, Socket* s):
AbstractCommand(cuid, req, e, s), AbstractCommand(cuid, req, e, s),
@ -64,7 +66,7 @@ bool FtpNegotiationCommand::recvGreeting() {
return false; return false;
} }
if(status != 220) { if(status != 220) {
throw new DlAbortEx(EX_CONNECTION_FAILED); throw new DlRetryEx(EX_CONNECTION_FAILED);
} }
sequence = SEQ_SEND_USER; sequence = SEQ_SEND_USER;
@ -92,7 +94,7 @@ bool FtpNegotiationCommand::recvUser() {
sequence = SEQ_SEND_PASS; sequence = SEQ_SEND_PASS;
break; break;
default: default:
throw new DlAbortEx(EX_BAD_STATUS, status); throw new DlRetryEx(EX_BAD_STATUS, status);
} }
return true; return true;
} }
@ -109,7 +111,7 @@ bool FtpNegotiationCommand::recvPass() {
return false; return false;
} }
if(status != 230) { if(status != 230) {
throw new DlAbortEx(EX_BAD_STATUS, status); throw new DlRetryEx(EX_BAD_STATUS, status);
} }
sequence = SEQ_SEND_TYPE; sequence = SEQ_SEND_TYPE;
return true; return true;
@ -127,7 +129,7 @@ bool FtpNegotiationCommand::recvType() {
return false; return false;
} }
if(status != 200) { if(status != 200) {
throw new DlAbortEx(EX_BAD_STATUS, status); throw new DlRetryEx(EX_BAD_STATUS, status);
} }
sequence = SEQ_SEND_CWD; sequence = SEQ_SEND_CWD;
return true; return true;
@ -145,7 +147,7 @@ bool FtpNegotiationCommand::recvCwd() {
return false; return false;
} }
if(status != 250) { if(status != 250) {
throw new DlAbortEx(EX_BAD_STATUS, status); throw new DlRetryEx(EX_BAD_STATUS, status);
} }
sequence = SEQ_SEND_SIZE; sequence = SEQ_SEND_SIZE;
return true; return true;
@ -164,16 +166,18 @@ bool FtpNegotiationCommand::recvSize() {
return false; return false;
} }
if(status != 213) { if(status != 213) {
throw new DlAbortEx(EX_BAD_STATUS, status); throw new DlRetryEx(EX_BAD_STATUS, status);
}
if(size == LONG_LONG_MAX || size < 0) {
throw new DlAbortEx(EX_TOO_LARGE_FILE, size);
} }
// TODO check the value of size
if(!e->segmentMan->downloadStarted) { if(!e->segmentMan->downloadStarted) {
e->segmentMan->downloadStarted = true; e->segmentMan->downloadStarted = true;
e->segmentMan->totalSize = size; e->segmentMan->totalSize = size;
} else if(e->segmentMan->totalSize != size) { } else if(e->segmentMan->totalSize != size) {
throw new DlAbortEx(EX_SIZE_MISMATCH, e->segmentMan->totalSize, size); throw new DlAbortEx(EX_SIZE_MISMATCH, e->segmentMan->totalSize, size);
} }
if(e->option->get("ftp_pasv_enabled") == "true") { if(e->option->get(PREF_FTP_PASV_ENABLED) == V_TRUE) {
sequence = SEQ_SEND_PASV; sequence = SEQ_SEND_PASV;
} else { } else {
sequence = SEQ_SEND_PORT; sequence = SEQ_SEND_PORT;
@ -193,7 +197,7 @@ bool FtpNegotiationCommand::recvPort() {
return false; return false;
} }
if(status != 200) { if(status != 200) {
throw new DlAbortEx(EX_BAD_STATUS, status); throw new DlRetryEx(EX_BAD_STATUS, status);
} }
sequence = SEQ_SEND_REST; sequence = SEQ_SEND_REST;
return true; return true;
@ -212,7 +216,7 @@ bool FtpNegotiationCommand::recvPasv() {
return false; return false;
} }
if(status != 227) { if(status != 227) {
throw new DlAbortEx(EX_BAD_STATUS, status); throw new DlRetryEx(EX_BAD_STATUS, status);
} }
// make a data connection to the server. // make a data connection to the server.
dataSocket = new Socket(); dataSocket = new Socket();
@ -249,7 +253,7 @@ bool FtpNegotiationCommand::recvRest() {
} }
// TODO if we recieve negative response, then we set e->segmentMan->splittable = false, and continue. // TODO if we recieve negative response, then we set e->segmentMan->splittable = false, and continue.
if(status != 350) { if(status != 350) {
throw new DlAbortEx(EX_BAD_STATUS, status); throw new DlRetryEx(EX_BAD_STATUS, status);
} }
sequence = SEQ_SEND_RETR; sequence = SEQ_SEND_RETR;
return true; return true;
@ -267,9 +271,9 @@ bool FtpNegotiationCommand::recvRetr() {
return false; return false;
} }
if(status != 150) { if(status != 150) {
throw new DlAbortEx(EX_BAD_STATUS, status); throw new DlRetryEx(EX_BAD_STATUS, status);
} }
if(e->option->get("ftp_pasv_enabled") != "true") { if(e->option->get(PREF_FTP_PASV_ENABLED) != V_TRUE) {
assert(serverSocket); assert(serverSocket);
dataSocket = serverSocket->acceptConnection(); dataSocket = serverSocket->acceptConnection();
} }

View File

@ -20,11 +20,11 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "HttpConnection.h" #include "HttpConnection.h"
#include "DlAbortEx.h"
#include "DlRetryEx.h" #include "DlRetryEx.h"
#include "Util.h" #include "Util.h"
#include "Base64.h" #include "Base64.h"
#include "message.h" #include "message.h"
#include "prefs.h"
HttpConnection::HttpConnection(int cuid, const Socket* socket, const Request* req, const Option* op, const Logger* logger): HttpConnection::HttpConnection(int cuid, const Socket* socket, const Request* req, const Option* op, const Logger* logger):
cuid(cuid), socket(socket), req(req), option(op), logger(logger) {} cuid(cuid), socket(socket), req(req), option(op), logger(logger) {}
@ -36,12 +36,14 @@ void HttpConnection::sendRequest(const Segment& segment) const {
} }
void HttpConnection::sendProxyRequest() const { void HttpConnection::sendProxyRequest() const {
string request = string("CONNECT ")+req->getHost()+":"+Util::llitos(req->getPort())+ string request =
string("CONNECT ")+req->getHost()+":"+Util::llitos(req->getPort())+
string(" HTTP/1.1\r\n")+ string(" HTTP/1.1\r\n")+
"Host: "+getHost(req->getHost(), req->getPort())+"\r\n"; "Host: "+getHost(req->getHost(), req->getPort())+"\r\n";
if(useProxyAuth()) { if(useProxyAuth()) {
request += "Proxy-Authorization: Basic "+ request += "Proxy-Authorization: Basic "+
Base64::encode(option->get("http_proxy_user")+":"+option->get("http_proxy_passwd"))+"\r\n"; Base64::encode(option->get(PREF_HTTP_PROXY_USER)+":"+
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_HTTP_REQUEST, cuid, request.c_str());
@ -65,11 +67,13 @@ string HttpConnection::createRequest(const Segment& segment) const {
"Pragma: no-cache\r\n"+ "Pragma: no-cache\r\n"+
"Cache-Control: no-cache\r\n"; "Cache-Control: no-cache\r\n";
if(segment.sp+segment.ds > 0) { if(segment.sp+segment.ds > 0) {
request += "Range: bytes="+Util::llitos(segment.sp+segment.ds)+"-"+Util::llitos(segment.ep)+"\r\n"; request += "Range: bytes="+
Util::llitos(segment.sp+segment.ds)+"-"+Util::llitos(segment.ep)+"\r\n";
} }
if(option->get("http_auth_scheme") == "BASIC") { if(option->get(PREF_HTTP_AUTH_SCHEME) == V_BASIC) {
request += "Authorization: Basic "+ request += "Authorization: Basic "+
Base64::encode(option->get("http_user")+":"+option->get("http_passwd"))+"\r\n"; Base64::encode(option->get(PREF_HTTP_USER)+":"+
option->get(PREF_HTTP_PASSWD))+"\r\n";
} }
if(req->getPreviousUrl().size()) { if(req->getPreviousUrl().size()) {
request += "Referer: "+req->getPreviousUrl()+"\r\n"; request += "Referer: "+req->getPreviousUrl()+"\r\n";
@ -135,11 +139,9 @@ int HttpConnection::receiveResponse(HttpHeader& headers) {
} }
bool HttpConnection::useProxy() const { bool HttpConnection::useProxy() const {
return option->defined("http_proxy_enabled") && return option->get(PREF_HTTP_PROXY_ENABLED) == V_TRUE;
option->get("http_proxy_enabled") == "true";
} }
bool HttpConnection::useProxyAuth() const { bool HttpConnection::useProxyAuth() const {
return option->defined("http_proxy_auth_enabled") && return option->get(PREF_HTTP_PROXY_AUTH_ENABLED) == V_TRUE;
option->get("http_proxy_auth_enabled") == "true";
} }

View File

@ -24,6 +24,7 @@
#include "HttpProxyRequestCommand.h" #include "HttpProxyRequestCommand.h"
#include "Util.h" #include "Util.h"
#include "message.h" #include "message.h"
#include "prefs.h"
HttpInitiateConnectionCommand::HttpInitiateConnectionCommand(int cuid, Request* req, DownloadEngine* e):AbstractCommand(cuid, req, e) {} HttpInitiateConnectionCommand::HttpInitiateConnectionCommand(int cuid, Request* req, DownloadEngine* e):AbstractCommand(cuid, req, e) {}
@ -35,10 +36,10 @@ bool HttpInitiateConnectionCommand::executeInternal(Segment segment) {
Command* command; Command* command;
if(useProxy()) { if(useProxy()) {
e->logger->info(MSG_CONNECTING_TO_SERVER, cuid, e->logger->info(MSG_CONNECTING_TO_SERVER, cuid,
e->option->get("http_proxy_host").c_str(), e->option->get(PREF_HTTP_PROXY_HOST).c_str(),
e->option->getAsInt("http_proxy_port")); e->option->getAsInt(PREF_HTTP_PROXY_PORT));
socket->establishConnection(e->option->get("http_proxy_host"), socket->establishConnection(e->option->get(PREF_HTTP_PROXY_HOST),
e->option->getAsInt("http_proxy_port")); e->option->getAsInt(PREF_HTTP_PROXY_PORT));
command = new HttpProxyRequestCommand(cuid, req, e, socket); command = new HttpProxyRequestCommand(cuid, req, e, socket);
} else { } else {
@ -52,6 +53,5 @@ bool HttpInitiateConnectionCommand::executeInternal(Segment segment) {
} }
bool HttpInitiateConnectionCommand::useProxy() { bool HttpInitiateConnectionCommand::useProxy() {
return e->option->defined("http_proxy_enabled") && return e->option->get(PREF_HTTP_PROXY_ENABLED) == V_TRUE;
e->option->get("http_proxy_enabled") == "true";
} }

View File

@ -21,6 +21,7 @@
/* copyright --> */ /* copyright --> */
#include "HttpResponseCommand.h" #include "HttpResponseCommand.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "DlRetryEx.h"
#include "HttpDownloadCommand.h" #include "HttpDownloadCommand.h"
#include "HttpInitiateConnectionCommand.h" #include "HttpInitiateConnectionCommand.h"
#include "message.h" #include "message.h"
@ -77,7 +78,7 @@ void HttpResponseCommand::checkResponse(int status, const Segment& segment) {
if(!(status < 400 && status >= 300 || if(!(status < 400 && status >= 300 ||
(segment.sp+segment.ds == 0 && status == 200) (segment.sp+segment.ds == 0 && status == 200)
|| (segment.sp+segment.ds > 0 && status == 206))) { || (segment.sp+segment.ds > 0 && status == 206))) {
throw new DlAbortEx(EX_BAD_STATUS, status); throw new DlRetryEx(EX_BAD_STATUS, status);
} }
} }
@ -90,7 +91,7 @@ bool HttpResponseCommand::handleRedirect(string url, const HttpHeader& headers)
bool HttpResponseCommand::handleDefaultEncoding(const HttpHeader& headers) { bool HttpResponseCommand::handleDefaultEncoding(const HttpHeader& headers) {
long long int size = headers.getFirstAsLLInt("Content-Length"); long long int size = headers.getFirstAsLLInt("Content-Length");
if(size == LONG_LONG_MAX || size == LONG_LONG_MIN || size < 0) { if(size == LONG_LONG_MAX || size < 0) {
throw new DlAbortEx(EX_TOO_LARGE_FILE, size); throw new DlAbortEx(EX_TOO_LARGE_FILE, size);
} }
e->segmentMan->isSplittable = !(size == 0); e->segmentMan->isSplittable = !(size == 0);

View File

@ -29,8 +29,6 @@
using namespace std; using namespace std;
#define MAX_TRY_COUNT 5
#define SAFE_CHARS "abcdefghijklmnopqrstuvwxyz"\ #define SAFE_CHARS "abcdefghijklmnopqrstuvwxyz"\
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"\ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\
"0123456789"\ "0123456789"\
@ -77,7 +75,7 @@ public:
void resetTryCount() { tryCount = 0; } void resetTryCount() { tryCount = 0; }
void addTryCount() { tryCount++; } void addTryCount() { tryCount++; }
int getTryCount() const { return tryCount; } int getTryCount() const { return tryCount; }
bool noMoreTry() const { return tryCount >= MAX_TRY_COUNT; } //bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; }
string getUrl() const { return url; } string getUrl() const { return url; }
string getCurrentUrl() const { return currentUrl; } string getCurrentUrl() const { return currentUrl; }

View File

@ -27,6 +27,7 @@
#include "DefaultDiskWriter.h" #include "DefaultDiskWriter.h"
#include "Util.h" #include "Util.h"
#include "InitiateConnectionCommandFactory.h" #include "InitiateConnectionCommandFactory.h"
#include "prefs.h"
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <signal.h> #include <signal.h>
@ -96,7 +97,9 @@ void showVersion() {
} }
void showUsage() { void showUsage() {
cout << endl;
cout << "Usage: " << PACKAGE_NAME << " [options] URL ..." << endl; cout << "Usage: " << PACKAGE_NAME << " [options] URL ..." << endl;
cout << endl;
cout << "Options:" << endl; cout << "Options:" << endl;
cout << " -d, --dir=DIR The directory to store downloaded file." << endl; cout << " -d, --dir=DIR The directory to store downloaded file." << endl;
cout << " -o, --out=FILE The file name for downloaded file." << endl; cout << " -o, --out=FILE The file name for downloaded file." << endl;
@ -106,31 +109,47 @@ void showUsage() {
cout << " -s, --split=N Download a file using s connections. s must be" << endl; cout << " -s, --split=N Download a file using s connections. s must be" << endl;
cout << " between 1 and 5. If this option is specified the" << endl; cout << " between 1 and 5. If this option is specified the" << endl;
cout << " first URL is used, and the other URLs are ignored." << endl; cout << " first URL is used, and the other URLs are ignored." << endl;
cout << " --retry-wait=SEC Set amount of time in second between requests" << endl;
cout << " for errors. Specify a value between 0 and 60." << endl;
cout << " -t, --timeout=SEC Set timeout in second." << endl;
cout << " --http-proxy=HOST:PORT Use HTTP proxy server. This affects to all" << endl; cout << " --http-proxy=HOST:PORT Use HTTP proxy server. This affects to all" << endl;
cout << " URLs." << endl; cout << " URLs." << endl;
cout << " --http-user=USER Set HTTP user. This affects to all URLs." << endl; cout << " --http-user=USER Set HTTP user. This affects to all URLs." << endl;
cout << " --http-passwd=PASSWD Set HTTP password. This affects to all URLs." << endl; cout << " --http-passwd=PASSWD Set HTTP password. This affects to all URLs." << endl;
cout << " --http-proxy-user=USER Set HTTP proxy user. This affects to all URLs" << endl; cout << " --http-proxy-user=USER Set HTTP proxy user. This affects to all URLs" << endl;
cout << " --http-proxy-passwd=PASSWD Set HTTP proxy password. This affects to all URLs." << endl; cout << " --http-proxy-passwd=PASSWD Set HTTP proxy password. This affects to all URLs." << endl;
cout << " --http-auth-scheme=SCHEME Set HTTP authentication scheme. Currently, BASIC" << endl; cout << " --http-auth-scheme=SCHEME Set HTTP authentication scheme. Currently, basic" << endl;
cout << " is the only supported scheme. You MUST specify" << endl; cout << " is the only supported scheme. You MUST specify" << endl;
cout << " this option in order to use HTTP authentication" << endl; cout << " this option in order to use HTTP authentication" << endl;
cout << " as well as --http-proxy option." << endl; cout << " as well as --http-proxy option." << endl;
cout << " --referer Set Referer. This affects to all URLs." << endl; cout << " --referer=REFERER Set Referer. This affects to all URLs." << endl;
cout << " --retry-wait Set amount of time in second between requests" << endl; cout << " --ftp-user=USER Set FTP user. This affects to all URLs." << endl;
cout << " for errors. Specify a value between 0 and 60." << endl; cout << " Default: anonymous" << endl;
cout << " --ftp-passwd=PASSWD Set FTP password. This affects to all URLs." << endl;
cout << " Default: ARIA2USER@" << endl;
cout << " --ftp-type=TYPE Set FTP transfer type. TYPE is either 'binary'" << endl;
cout << " or 'ascii'." << endl;
cout << " Default: binary" << endl;
cout << " -p, --ftp-pasv Use passive mode in FTP." << endl;
cout << " --ftp-via-http-proxy=WAY Use HTTP proxy in FTP. WAY is either 'get' or" << endl;
cout << " 'tunnel'." << endl;
cout << " -v, --version Print the version number and exit." << endl; cout << " -v, --version Print the version number and exit." << endl;
cout << " -h, --help Print this message and exit." << endl; cout << " -h, --help Print this message and exit." << endl;
cout << endl;
cout << "URL:" << endl; cout << "URL:" << endl;
cout << " You can specify multiple URLs. All URLs must point to the same file" << endl; cout << " You can specify multiple URLs. All URLs must point to the same file" << endl;
cout << " or a download fails." << endl; cout << " or downloading fails." << endl;
cout << endl;
cout << "Examples:" << endl; cout << "Examples:" << endl;
cout << " Download a file by 1 connection:" << endl; cout << " Download a file by 1 connection:" << endl;
cout << " aria2c http://AAA.BBB.CCC/file.zip" << endl; cout << " aria2c http://AAA.BBB.CCC/file.zip" << endl;
cout << " Download a file by 2 connections:" << endl; cout << " Download a file by 2 connections:" << endl;
cout << " aria2c -s 2 http://AAA.BBB.CCC/file.zip" << endl; cout << " aria2c -s 2 http://AAA.BBB.CCC/file.zip" << endl;
cout << " Download a file by 2 connections, each connects to a different server." << endl; cout << " Download a file by 2 connections, each connects to a different server:" << endl;
cout << " aria2c http://AAA.BBB.CCC/file.zip http://DDD.EEE.FFF/GGG/file.zip" << endl; cout << " aria2c http://AAA.BBB.CCC/file.zip http://DDD.EEE.FFF/GGG/file.zip" << endl;
cout << " You can mix up different protocols:" << endl;
cout << " aria2c http://AAA.BBB.CCC/file.zip ftp://DDD.EEE.FFF/GGG/file.zip" << endl;
cout << endl;
cout << "Reports bugs to <tujikawa at rednoah dot com>" << endl; cout << "Reports bugs to <tujikawa at rednoah dot com>" << endl;
} }
@ -145,16 +164,13 @@ int main(int argc, char* argv[]) {
int c; int c;
Option* op = new Option(); Option* op = new Option();
op->put("retry_wait", "5"); op->put(PREF_RETRY_WAIT, "5");
op->put(PREF_TIMEOUT, "60");
// TODO warning! Delete username/password line when commit op->put(PREF_FTP_USER, "anonymous");
op->put("ftp_user", "anonymous"); op->put(PREF_FTP_PASSWD, "ARIA2USER@");
op->put("ftp_passwd", "IE60USER@"); op->put(PREF_FTP_TYPE, V_BINARY);
op->put("ftp_type", "I"); op->put(PREF_FTP_PASV_ENABLED, V_TRUE);
op->put(PREF_FTP_VIA_HTTP_PROXY, V_TUNNEL);
op->put("ftp_pasv_enabled", "true");
op->put("ftp_via_http_proxy", "tunnel");
op->put("http_abs_uri_request_enabled", "true");
while(1) { while(1) {
int optIndex = 0; int optIndex = 0;
@ -165,6 +181,7 @@ int main(int argc, char* argv[]) {
{ "out", required_argument, NULL, 'o' }, { "out", required_argument, NULL, 'o' },
{ "log", required_argument, NULL, 'l' }, { "log", required_argument, NULL, 'l' },
{ "split", required_argument, NULL, 's' }, { "split", required_argument, NULL, 's' },
{ "timeout", required_argument, NULL, 't' },
{ "http-proxy", required_argument, &lopt, 1 }, { "http-proxy", required_argument, &lopt, 1 },
{ "http-user", required_argument, &lopt, 2 }, { "http-user", required_argument, &lopt, 2 },
{ "http-passwd", required_argument, &lopt, 3 }, { "http-passwd", required_argument, &lopt, 3 },
@ -173,11 +190,16 @@ int main(int argc, char* argv[]) {
{ "http-auth-scheme", required_argument, &lopt, 6 }, { "http-auth-scheme", required_argument, &lopt, 6 },
{ "referer", required_argument, &lopt, 7 }, { "referer", required_argument, &lopt, 7 },
{ "retry-wait", required_argument, &lopt, 8 }, { "retry-wait", required_argument, &lopt, 8 },
{ "ftp-user", required_argument, &lopt, 9 },
{ "ftp-passwd", required_argument, &lopt, 10 },
{ "ftp-type", required_argument, &lopt, 11 },
{ "ftp-pasv", no_argument, NULL, 'p' },
{ "ftp-via-http-proxy", required_argument, &lopt, 12 },
{ "version", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
c = getopt_long(argc, argv, "Dd:o:l:s:vh", longOpts, &optIndex); c = getopt_long(argc, argv, "Dd:o:l:s:pt:vh", longOpts, &optIndex);
if(c == -1) { if(c == -1) {
break; break;
} }
@ -194,29 +216,29 @@ int main(int argc, char* argv[]) {
showUsage(); showUsage();
exit(1); exit(1);
} }
op->put("http_proxy_host", proxy.first); op->put(PREF_HTTP_PROXY_HOST, proxy.first);
op->put("http_proxy_port", Util::itos(port)); op->put(PREF_HTTP_PROXY_PORT, Util::itos(port));
op->put("http_proxy_enabled", "true"); op->put(PREF_HTTP_PROXY_ENABLED, V_TRUE);
break; break;
} }
case 2: case 2:
op->put("http_user", optarg); op->put(PREF_HTTP_USER, optarg);
break; break;
case 3: case 3:
op->put("http_passwd", optarg); op->put(PREF_HTTP_PASSWD, optarg);
break; break;
case 4: case 4:
op->put("http_proxy_user", optarg); op->put(PREF_HTTP_PROXY_USER, optarg);
op->put("http_proxy_auth_enabled", "true"); op->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE);
break; break;
case 5: case 5:
op->put("http_proxy_passwd", optarg); op->put(PREF_HTTP_PROXY_PASSWD, optarg);
break; break;
case 6: case 6:
if(string("BASIC") == optarg) { if(string(V_BASIC) == optarg) {
op->put("http_auth_scheme", "BASIC"); op->put(PREF_HTTP_AUTH_SCHEME, V_BASIC);
} else { } else {
cerr << "Currently, supported authentication scheme is BASIC." << endl; cerr << "Currently, supported authentication scheme is basic." << endl;
} }
break; break;
case 7: case 7:
@ -229,9 +251,33 @@ int main(int argc, char* argv[]) {
showUsage(); showUsage();
exit(1); exit(1);
} }
op->put("retry-wait", Util::itos(wait)); op->put(PREF_RETRY_WAIT, Util::itos(wait));
break; break;
} }
case 9:
op->put(PREF_FTP_USER, optarg);
break;
case 10:
op->put(PREF_FTP_PASSWD, optarg);
break;
case 11:
if(string(optarg) == V_BINARY || string(optarg) == V_ASCII) {
op->put(PREF_FTP_TYPE, optarg);
} else {
cerr << "ftp-type must be either 'binary' or 'ascii'." << endl;
showUsage();
exit(1);
}
break;
case 12:
if(string(optarg) == V_GET || string(optarg) == V_TUNNEL) {
op->put(PREF_FTP_VIA_HTTP_PROXY, optarg);
} else {
cerr << "ftp-via-http-proxy must be either 'get' or 'tunnel'." << endl;
showUsage();
exit(1);
}
break;
} }
break; break;
} }
@ -253,12 +299,26 @@ int main(int argc, char* argv[]) {
break; break;
case 's': case 's':
split = (int)strtol(optarg, NULL, 10); split = (int)strtol(optarg, NULL, 10);
if(!(1 < split && split < 5)) { if(!(1 <= split && split <= 5)) {
cerr << "split must be between 1 and 5." << endl; cerr << "split must be between 1 and 5." << endl;
showUsage(); showUsage();
exit(1); exit(1);
} }
break; break;
case 't': {
int timeout = (int)strtol(optarg, NULL, 10);
if(1 <= timeout && timeout <= 600) {
op->put(PREF_TIMEOUT, Util::itos(timeout));
} else {
cerr << "timeout must be between 1 and 600" << endl;
showUsage();
exit(1);
}
break;
}
case 'p':
op->put(PREF_FTP_PASV_ENABLED, V_TRUE);
break;
case 'v': case 'v':
showVersion(); showVersion();
exit(0); exit(0);

View File

@ -32,7 +32,7 @@
#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."
#define MSG_MAX_RETRY "CUID#%d - The retry count reached its max value. Download aborted." #define MSG_MAX_TRY "CUID#%d - %d times attempted, but no success. Download aborted."
#define MSG_UNREGISTER_CUID "CUID#%d - Unregistering cuid from segmentManager." #define MSG_UNREGISTER_CUID "CUID#%d - Unregistering cuid from segmentManager."
#define MSG_SEGMENT_FILE_EXISTS "The segment file %s exists." #define MSG_SEGMENT_FILE_EXISTS "The segment file %s exists."

79
src/prefs.h Normal file
View File

@ -0,0 +1,79 @@
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#ifndef _D_PREFS_H_
#define _D_PREFS_H_
/**
* Constants
*/
#define V_TRUE "true"
//#define V_FALSE "false"
/**
* General preferences
*/
// values: 1*digit
#define PREF_RETRY_WAIT "retry_wait"
// values: 1*digit
#define PREF_TIMEOUT "timeout"
// values: 1*digit
#define PREF_MAX_TRY "max_try"
/**
* FTP related preferences
*/
#define PREF_FTP_USER "ftp_user"
#define PREF_FTP_PASSWD "ftp_passwd"
// values: binary | ascii
#define PREF_FTP_TYPE "ftp_type"
# define V_BINARY "binary"
# define V_ASCII "ascii"
// values: get | tunnel
#define PREF_FTP_VIA_HTTP_PROXY "ftp_via_http_proxy"
# define V_GET "get"
# define V_TUNNEL "tunnel"
// values: true | false
#define PREF_FTP_PASV_ENABLED "ftp_pasv_enabled"
/**
* HTTP related preferences
*/
#define PREF_HTTP_USER "http_user"
#define PREF_HTTP_PASSWD "http_passwd"
// values: basic
#define PREF_HTTP_AUTH_SCHEME "http_auth_scheme"
# define V_BASIC "basic"
/**
* HTTP proxy related preferences
*/
#define PREF_HTTP_PROXY_USER "http_proxy_user"
#define PREF_HTTP_PROXY_PASSWD "http_proxy_passwd"
#define PREF_HTTP_PROXY_HOST "http_proxy_host"
#define PREF_HTTP_PROXY_PORT "http_proxy_port"
// values: true | false
#define PREF_HTTP_PROXY_ENABLED "http_proxy_enabled"
// values: true | false
#define PREF_HTTP_PROXY_AUTH_ENABLED "http_proxy_auth_enabled"
#endif // _D_PREFS_H_