diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-02-21 14:00:58 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-02-21 14:00:58 +0000 |
| commit | 32e8f2b011d1e1db9f724108894d9e2cd01d9f2a (patch) | |
| tree | 00cc6f5607cbc52707873d6482342409dfbd4878 /src | |
| parent | e0aa767f9428eb34a7ab7c1169c1ecc55262dade (diff) | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/AbstractCommand.cc | 11 | ||||
| -rw-r--r-- | src/DownloadEngine.cc | 3 | ||||
| -rw-r--r-- | src/FtpConnection.cc | 18 | ||||
| -rw-r--r-- | src/FtpInitiateConnectionCommand.cc | 16 | ||||
| -rw-r--r-- | src/FtpNegotiationCommand.cc | 30 | ||||
| -rw-r--r-- | src/HttpConnection.cc | 22 | ||||
| -rw-r--r-- | src/HttpInitiateConnectionCommand.cc | 12 | ||||
| -rw-r--r-- | src/HttpResponseCommand.cc | 5 | ||||
| -rw-r--r-- | src/Request.h | 4 | ||||
| -rw-r--r-- | src/main.cc | 120 | ||||
| -rw-r--r-- | src/message.h | 2 | ||||
| -rw-r--r-- | src/prefs.h | 79 |
12 files changed, 236 insertions, 86 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index 89683a70..a16bf6a6 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -27,8 +27,7 @@ #include "Util.h" #include "message.h" #include "SleepCommand.h" - -#define TIMEOUT_SEC 60 +#include "prefs.h" AbstractCommand::AbstractCommand(int cuid, Request* req, DownloadEngine* e, Socket* s): Command(cuid), req(req), e(e), checkSocketIsReadable(false), checkSocketIsWritable(false) { @@ -63,7 +62,7 @@ bool AbstractCommand::isTimeoutDetected() { return false; } else { long long int elapsed = Util::difftv(now, checkPoint); - if(elapsed >= TIMEOUT_SEC*1000000) { + if(elapsed >= e->option->getAsInt(PREF_TIMEOUT)*1000000) { return true; } else { return false; @@ -103,11 +102,11 @@ bool AbstractCommand::execute() { delete(err); //req->resetUrl(); req->addTryCount(); - if(req->noMoreTry()) { - e->logger->error(MSG_MAX_RETRY, cuid); + if(req->getTryCount() >= e->option->getAsInt(PREF_MAX_TRY)) { + e->logger->error(MSG_MAX_TRY, cuid, req->getTryCount()); return true; } else { - return prepareForRetry(e->option->getAsInt("retry_wait")); + return prepareForRetry(e->option->getAsInt(PREF_RETRY_WAIT)); } } } diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 337e221c..80b98141 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -20,12 +20,11 @@ */ /* copyright --> */ #include "DownloadEngine.h" +#include "Util.h" #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include "DlAbortEx.h" -#include "Util.h" using namespace std; diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc index 4c528ada..4614304e 100644 --- a/src/FtpConnection.cc +++ b/src/FtpConnection.cc @@ -22,26 +22,34 @@ #include "FtpConnection.h" #include "Util.h" #include "DlAbortEx.h" +#include "DlRetryEx.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() {} 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()); socket->writeData(request); } 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 ********"); socket->writeData(request); } 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()); socket->writeData(request); } @@ -143,7 +151,7 @@ bool FtpConnection::bulkReceiveResponse(pair<int, string>& response) { if(strbuf.size() >= 4) { status = getStatus(strbuf); if(status == 0) { - throw new DlAbortEx(EX_INVALID_RESPONSE); + throw new DlRetryEx(EX_INVALID_RESPONSE); } } else { return false; @@ -197,7 +205,7 @@ int FtpConnection::receivePasvResponse(pair<string, int>& dest) { // port number dest.second = 256*p1+p2; } else { - throw new DlAbortEx(EX_INVALID_RESPONSE); + throw new DlRetryEx(EX_INVALID_RESPONSE); } } return response.first; diff --git a/src/FtpInitiateConnectionCommand.cc b/src/FtpInitiateConnectionCommand.cc index 26bec02c..03af4232 100644 --- a/src/FtpInitiateConnectionCommand.cc +++ b/src/FtpInitiateConnectionCommand.cc @@ -25,6 +25,7 @@ #include "FtpTunnelRequestCommand.h" #include "DlAbortEx.h" #include "message.h" +#include "prefs.h" FtpInitiateConnectionCommand::FtpInitiateConnectionCommand(int cuid, Request* req, DownloadEngine* e):AbstractCommand(cuid, req, e) {} @@ -47,10 +48,10 @@ bool FtpInitiateConnectionCommand::executeInternal(Segment segment) { Command* command; if(useHttpProxy()) { e->logger->info(MSG_CONNECTING_TO_SERVER, cuid, - e->option->get("http_proxy_host").c_str(), - e->option->getAsInt("http_proxy_port")); - socket->establishConnection(e->option->get("http_proxy_host"), - e->option->getAsInt("http_proxy_port")); + e->option->get(PREF_HTTP_PROXY_HOST).c_str(), + e->option->getAsInt(PREF_HTTP_PROXY_PORT)); + socket->establishConnection(e->option->get(PREF_HTTP_PROXY_HOST), + e->option->getAsInt(PREF_HTTP_PROXY_PORT)); if(useHttpProxyGet()) { command = new HttpRequestCommand(cuid, req, e, socket); @@ -71,14 +72,13 @@ bool FtpInitiateConnectionCommand::executeInternal(Segment segment) { } bool FtpInitiateConnectionCommand::useHttpProxy() const { - return e->option->defined("http_proxy_enabled") && - e->option->get("http_proxy_enabled") == "true"; + return e->option->get(PREF_HTTP_PROXY_ENABLED) == V_TRUE; } 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 { - return useHttpProxy() && e->option->get("ftp_via_http_proxy") == "tunnel"; + return useHttpProxy() && e->option->get(PREF_FTP_VIA_HTTP_PROXY) == V_TUNNEL; } diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index ee6821ec..2f5bb342 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -22,7 +22,9 @@ #include "FtpNegotiationCommand.h" #include "FtpDownloadCommand.h" #include "DlAbortEx.h" +#include "DlRetryEx.h" #include "message.h" +#include "prefs.h" FtpNegotiationCommand::FtpNegotiationCommand(int cuid, Request* req, DownloadEngine* e, Socket* s): AbstractCommand(cuid, req, e, s), @@ -64,7 +66,7 @@ bool FtpNegotiationCommand::recvGreeting() { return false; } if(status != 220) { - throw new DlAbortEx(EX_CONNECTION_FAILED); + throw new DlRetryEx(EX_CONNECTION_FAILED); } sequence = SEQ_SEND_USER; @@ -92,7 +94,7 @@ bool FtpNegotiationCommand::recvUser() { sequence = SEQ_SEND_PASS; break; default: - throw new DlAbortEx(EX_BAD_STATUS, status); + throw new DlRetryEx(EX_BAD_STATUS, status); } return true; } @@ -109,7 +111,7 @@ bool FtpNegotiationCommand::recvPass() { return false; } if(status != 230) { - throw new DlAbortEx(EX_BAD_STATUS, status); + throw new DlRetryEx(EX_BAD_STATUS, status); } sequence = SEQ_SEND_TYPE; return true; @@ -127,7 +129,7 @@ bool FtpNegotiationCommand::recvType() { return false; } if(status != 200) { - throw new DlAbortEx(EX_BAD_STATUS, status); + throw new DlRetryEx(EX_BAD_STATUS, status); } sequence = SEQ_SEND_CWD; return true; @@ -145,7 +147,7 @@ bool FtpNegotiationCommand::recvCwd() { return false; } if(status != 250) { - throw new DlAbortEx(EX_BAD_STATUS, status); + throw new DlRetryEx(EX_BAD_STATUS, status); } sequence = SEQ_SEND_SIZE; return true; @@ -164,16 +166,18 @@ bool FtpNegotiationCommand::recvSize() { return false; } 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) { e->segmentMan->downloadStarted = true; e->segmentMan->totalSize = size; } else if(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; } else { sequence = SEQ_SEND_PORT; @@ -193,7 +197,7 @@ bool FtpNegotiationCommand::recvPort() { return false; } if(status != 200) { - throw new DlAbortEx(EX_BAD_STATUS, status); + throw new DlRetryEx(EX_BAD_STATUS, status); } sequence = SEQ_SEND_REST; return true; @@ -212,7 +216,7 @@ bool FtpNegotiationCommand::recvPasv() { return false; } if(status != 227) { - throw new DlAbortEx(EX_BAD_STATUS, status); + throw new DlRetryEx(EX_BAD_STATUS, status); } // make a data connection to the server. 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. if(status != 350) { - throw new DlAbortEx(EX_BAD_STATUS, status); + throw new DlRetryEx(EX_BAD_STATUS, status); } sequence = SEQ_SEND_RETR; return true; @@ -267,9 +271,9 @@ bool FtpNegotiationCommand::recvRetr() { return false; } 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); dataSocket = serverSocket->acceptConnection(); } diff --git a/src/HttpConnection.cc b/src/HttpConnection.cc index 9f373d33..535e745f 100644 --- a/src/HttpConnection.cc +++ b/src/HttpConnection.cc @@ -20,11 +20,11 @@ */ /* copyright --> */ #include "HttpConnection.h" -#include "DlAbortEx.h" #include "DlRetryEx.h" #include "Util.h" #include "Base64.h" #include "message.h" +#include "prefs.h" 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) {} @@ -36,12 +36,14 @@ void HttpConnection::sendRequest(const Segment& segment) 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")+ "Host: "+getHost(req->getHost(), req->getPort())+"\r\n"; if(useProxyAuth()) { 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"; 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"+ "Cache-Control: no-cache\r\n"; 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 "+ - 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()) { request += "Referer: "+req->getPreviousUrl()+"\r\n"; @@ -135,11 +139,9 @@ int HttpConnection::receiveResponse(HttpHeader& headers) { } bool HttpConnection::useProxy() const { - return option->defined("http_proxy_enabled") && - option->get("http_proxy_enabled") == "true"; + return option->get(PREF_HTTP_PROXY_ENABLED) == V_TRUE; } bool HttpConnection::useProxyAuth() const { - return option->defined("http_proxy_auth_enabled") && - option->get("http_proxy_auth_enabled") == "true"; + return option->get(PREF_HTTP_PROXY_AUTH_ENABLED) == V_TRUE; } diff --git a/src/HttpInitiateConnectionCommand.cc b/src/HttpInitiateConnectionCommand.cc index e94c39c9..8b53aab8 100644 --- a/src/HttpInitiateConnectionCommand.cc +++ b/src/HttpInitiateConnectionCommand.cc @@ -24,6 +24,7 @@ #include "HttpProxyRequestCommand.h" #include "Util.h" #include "message.h" +#include "prefs.h" HttpInitiateConnectionCommand::HttpInitiateConnectionCommand(int cuid, Request* req, DownloadEngine* e):AbstractCommand(cuid, req, e) {} @@ -35,10 +36,10 @@ bool HttpInitiateConnectionCommand::executeInternal(Segment segment) { Command* command; if(useProxy()) { e->logger->info(MSG_CONNECTING_TO_SERVER, cuid, - e->option->get("http_proxy_host").c_str(), - e->option->getAsInt("http_proxy_port")); - socket->establishConnection(e->option->get("http_proxy_host"), - e->option->getAsInt("http_proxy_port")); + e->option->get(PREF_HTTP_PROXY_HOST).c_str(), + e->option->getAsInt(PREF_HTTP_PROXY_PORT)); + socket->establishConnection(e->option->get(PREF_HTTP_PROXY_HOST), + e->option->getAsInt(PREF_HTTP_PROXY_PORT)); command = new HttpProxyRequestCommand(cuid, req, e, socket); } else { @@ -52,6 +53,5 @@ bool HttpInitiateConnectionCommand::executeInternal(Segment segment) { } bool HttpInitiateConnectionCommand::useProxy() { - return e->option->defined("http_proxy_enabled") && - e->option->get("http_proxy_enabled") == "true"; + return e->option->get(PREF_HTTP_PROXY_ENABLED) == V_TRUE; } diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index 1fd273bb..f5788be7 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -21,6 +21,7 @@ /* copyright --> */ #include "HttpResponseCommand.h" #include "DlAbortEx.h" +#include "DlRetryEx.h" #include "HttpDownloadCommand.h" #include "HttpInitiateConnectionCommand.h" #include "message.h" @@ -77,7 +78,7 @@ void HttpResponseCommand::checkResponse(int status, const Segment& segment) { if(!(status < 400 && status >= 300 || (segment.sp+segment.ds == 0 && status == 200) || (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) { 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); } e->segmentMan->isSplittable = !(size == 0); diff --git a/src/Request.h b/src/Request.h index 7a7b0fce..8d8676ef 100644 --- a/src/Request.h +++ b/src/Request.h @@ -29,8 +29,6 @@ using namespace std; -#define MAX_TRY_COUNT 5 - #define SAFE_CHARS "abcdefghijklmnopqrstuvwxyz"\ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\ "0123456789"\ @@ -77,7 +75,7 @@ public: void resetTryCount() { tryCount = 0; } void addTryCount() { 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 getCurrentUrl() const { return currentUrl; } diff --git a/src/main.cc b/src/main.cc index 773bdd17..63c46a95 100644 --- a/src/main.cc +++ b/src/main.cc @@ -27,6 +27,7 @@ #include "DefaultDiskWriter.h" #include "Util.h" #include "InitiateConnectionCommandFactory.h" +#include "prefs.h" #include <vector> #include <algorithm> #include <signal.h> @@ -96,7 +97,9 @@ void showVersion() { } void showUsage() { + cout << endl; cout << "Usage: " << PACKAGE_NAME << " [options] URL ..." << endl; + cout << endl; cout << "Options:" << endl; cout << " -d, --dir=DIR The directory to store 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 << " between 1 and 5. If this option is specified the" << 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 << " 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-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-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 << " this option in order to use HTTP authentication" << endl; cout << " as well as --http-proxy option." << endl; - cout << " --referer Set Referer. This affects to all URLs." << endl; - cout << " --retry-wait Set amount of time in second between requests" << endl; - cout << " for errors. Specify a value between 0 and 60." << endl; + cout << " --referer=REFERER Set Referer. This affects to all URLs." << endl; + cout << " --ftp-user=USER Set FTP user. This affects to all URLs." << 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 << " -h, --help Print this message and exit." << endl; + cout << endl; cout << "URL:" << 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 << " Download a file by 1 connection:" << endl; cout << " aria2c http://AAA.BBB.CCC/file.zip" << endl; cout << " Download a file by 2 connections:" << 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 << " 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; } @@ -145,16 +164,13 @@ int main(int argc, char* argv[]) { int c; Option* op = new Option(); - op->put("retry_wait", "5"); - - // TODO warning! Delete username/password line when commit - op->put("ftp_user", "anonymous"); - op->put("ftp_passwd", "IE60USER@"); - op->put("ftp_type", "I"); - - op->put("ftp_pasv_enabled", "true"); - op->put("ftp_via_http_proxy", "tunnel"); - op->put("http_abs_uri_request_enabled", "true"); + op->put(PREF_RETRY_WAIT, "5"); + op->put(PREF_TIMEOUT, "60"); + op->put(PREF_FTP_USER, "anonymous"); + op->put(PREF_FTP_PASSWD, "ARIA2USER@"); + op->put(PREF_FTP_TYPE, V_BINARY); + op->put(PREF_FTP_PASV_ENABLED, V_TRUE); + op->put(PREF_FTP_VIA_HTTP_PROXY, V_TUNNEL); while(1) { int optIndex = 0; @@ -165,6 +181,7 @@ int main(int argc, char* argv[]) { { "out", required_argument, NULL, 'o' }, { "log", required_argument, NULL, 'l' }, { "split", required_argument, NULL, 's' }, + { "timeout", required_argument, NULL, 't' }, { "http-proxy", required_argument, &lopt, 1 }, { "http-user", required_argument, &lopt, 2 }, { "http-passwd", required_argument, &lopt, 3 }, @@ -173,11 +190,16 @@ int main(int argc, char* argv[]) { { "http-auth-scheme", required_argument, &lopt, 6 }, { "referer", required_argument, &lopt, 7 }, { "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' }, { "help", no_argument, NULL, 'h' }, { 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) { break; } @@ -194,29 +216,29 @@ int main(int argc, char* argv[]) { showUsage(); exit(1); } - op->put("http_proxy_host", proxy.first); - op->put("http_proxy_port", Util::itos(port)); - op->put("http_proxy_enabled", "true"); + op->put(PREF_HTTP_PROXY_HOST, proxy.first); + op->put(PREF_HTTP_PROXY_PORT, Util::itos(port)); + op->put(PREF_HTTP_PROXY_ENABLED, V_TRUE); break; } case 2: - op->put("http_user", optarg); + op->put(PREF_HTTP_USER, optarg); break; case 3: - op->put("http_passwd", optarg); + op->put(PREF_HTTP_PASSWD, optarg); break; case 4: - op->put("http_proxy_user", optarg); - op->put("http_proxy_auth_enabled", "true"); + op->put(PREF_HTTP_PROXY_USER, optarg); + op->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE); break; case 5: - op->put("http_proxy_passwd", optarg); + op->put(PREF_HTTP_PROXY_PASSWD, optarg); break; case 6: - if(string("BASIC") == optarg) { - op->put("http_auth_scheme", "BASIC"); + if(string(V_BASIC) == optarg) { + op->put(PREF_HTTP_AUTH_SCHEME, V_BASIC); } else { - cerr << "Currently, supported authentication scheme is BASIC." << endl; + cerr << "Currently, supported authentication scheme is basic." << endl; } break; case 7: @@ -229,9 +251,33 @@ int main(int argc, char* argv[]) { showUsage(); exit(1); } - op->put("retry-wait", Util::itos(wait)); + op->put(PREF_RETRY_WAIT, Util::itos(wait)); 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; } @@ -253,12 +299,26 @@ int main(int argc, char* argv[]) { break; case 's': 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; showUsage(); exit(1); } 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': showVersion(); exit(0); diff --git a/src/message.h b/src/message.h index d326953c..7323c58e 100644 --- a/src/message.h +++ b/src/message.h @@ -32,7 +32,7 @@ #define MSG_RECEIVE_RESPONSE "CUID#%d - Response received:\n%s" #define MSG_DOWNLOAD_ABORTED "CUID#%d - Download aborted." #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_SEGMENT_FILE_EXISTS "The segment file %s exists." diff --git a/src/prefs.h b/src/prefs.h new file mode 100644 index 00000000..847990da --- /dev/null +++ b/src/prefs.h @@ -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_ |
