From 5752a554bff85455ab0c54ed6e982c6bb5807a8b Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 18 Feb 2006 05:13:21 +0000 Subject: [PATCH] * Added Referer support. * Added referer command-line option. * Added rety-wait command-line option. * Fixed formating bug in Exception::setMsg() --- ChangeLog | 4 ++++ README | 4 ++++ TODO | 4 ++-- configure | 20 ++++++++++---------- configure.in | 2 +- src/AbstractCommand.cc | 21 ++++++++++++++------- src/AbstractCommand.h | 2 +- src/DownloadCommand.cc | 12 ++++-------- src/DownloadCommand.h | 2 +- src/Exception.h | 5 +---- src/HttpResponseCommand.cc | 8 ++++---- src/Request.h | 1 + src/SleepCommand.cc | 8 +++----- src/SleepCommand.h | 3 ++- src/main.cc | 18 ++++++++++++++++-- 15 files changed, 68 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35434dd2..5134134b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2006-02-18 Tatsuhiro Tsujikawa + * Added Referer support. + * Added referer command-line option. + * Added rety-wait command-line option. + * Fixed formating bug in Exception::setMsg() * Added HTTPS support. * Added SocketCore. Socket is now handle class for SocketCore. * Fixed bug in ChunkedEncoding: expanding buffer size is wrong diff --git a/README b/README index 83faad38..785c7da0 100644 --- a/README +++ b/README @@ -25,3 +25,7 @@ $ ./configure $ make The executable is aria2c in src directory. + +4. SSL +------ +You need OpenSSL library(0.9.7b or higher) to enable HTTPS support. diff --git a/TODO b/TODO index d92e87f0..ae172335 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,6 @@ * Add HTTP POST support * Add expires handling for Cookie -* Fix no wait retry in HttpInitiateConnectionCommand, HttpRequestCommand, HttpResponseCommand, except for redirection. * Add FTP support * Add SSL server cert verification -* Add SSL client cert support \ No newline at end of file +* Add SSL client cert support +* Better HTTP status handling \ No newline at end of file diff --git a/configure b/configure index 8966e04a..c4dfebb0 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.59 for aria2c 0.1.0. +# Generated by GNU Autoconf 2.59 for aria2c 0.2.0-dev. # # Report bugs to . # @@ -269,8 +269,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='aria2c' PACKAGE_TARNAME='aria2c' -PACKAGE_VERSION='0.1.0' -PACKAGE_STRING='aria2c 0.1.0' +PACKAGE_VERSION='0.2.0-dev' +PACKAGE_STRING='aria2c 0.2.0-dev' PACKAGE_BUGREPORT='tujikawa@rednoah.com' ac_unique_file="src/Socket.h" @@ -788,7 +788,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures aria2c 0.1.0 to adapt to many kinds of systems. +\`configure' configures aria2c 0.2.0-dev to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -850,7 +850,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of aria2c 0.1.0:";; + short | recursive ) echo "Configuration of aria2c 0.2.0-dev:";; esac cat <<\_ACEOF @@ -976,7 +976,7 @@ fi test -n "$ac_init_help" && exit 0 if $ac_init_version; then cat <<\_ACEOF -aria2c configure 0.1.0 +aria2c configure 0.2.0-dev generated by GNU Autoconf 2.59 Copyright (C) 2003 Free Software Foundation, Inc. @@ -990,7 +990,7 @@ cat >&5 <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by aria2c $as_me 0.1.0, which was +It was created by aria2c $as_me 0.2.0-dev, which was generated by GNU Autoconf 2.59. Invocation command line was $ $0 $@ @@ -1633,7 +1633,7 @@ fi # Define the identity of the package. PACKAGE='aria2c' - VERSION='0.1.0' + VERSION='0.2.0-dev' cat >>confdefs.h <<_ACEOF @@ -5795,7 +5795,7 @@ _ASBOX } >&5 cat >&5 <<_CSEOF -This file was extended by aria2c $as_me 0.1.0, which was +This file was extended by aria2c $as_me 0.2.0-dev, which was generated by GNU Autoconf 2.59. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5858,7 +5858,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -aria2c config.status 0.1.0 +aria2c config.status 0.2.0-dev configured by $0, generated by GNU Autoconf 2.59, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" diff --git a/configure.in b/configure.in index 2b2326e5..9c0d833f 100644 --- a/configure.in +++ b/configure.in @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. # AC_PREREQ(2.59) -AC_INIT(aria2c, 0.1.0, tujikawa@rednoah.com) +AC_INIT(aria2c, 0.2.0-dev, tujikawa@rednoah.com) AM_INIT_AUTOMAKE() AM_PATH_CPPUNIT(1.10.2) AC_CONFIG_SRCDIR([src/Socket.h]) diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index 6358e3d0..0a2f78d3 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -26,6 +26,7 @@ #include #include "Util.h" #include "message.h" +#include "SleepCommand.h" #define TIMEOUT_SEC 5 @@ -91,28 +92,34 @@ bool AbstractCommand::execute() { } return executeInternal(seg); } catch(DlAbortEx* err) { - e->logger->error(MSG_DOWNLOAD_ABORTED, err); + e->logger->error(MSG_DOWNLOAD_ABORTED, err, cuid); onError(err); delete(err); req->resetUrl(); return true; } catch(DlRetryEx* err) { - e->logger->error(MSG_RESTARTING_DOWNLOAD, err); + e->logger->error(MSG_RESTARTING_DOWNLOAD, err, cuid); onError(err); delete(err); - req->resetUrl(); + //req->resetUrl(); req->addRetryCount(); if(req->noMoreRetry()) { - e->logger->error(MSG_MAX_RETRY); + e->logger->error(MSG_MAX_RETRY, cuid); return true; } else { - return prepareForRetry(); + return prepareForRetry(e->option->getAsInt("retry_wait")); } } } -bool AbstractCommand::prepareForRetry() { - e->commands.push(InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, req, e)); +bool AbstractCommand::prepareForRetry(int wait) { + Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, req, e); + if(wait == 0) { + e->commands.push(command); + } else { + SleepCommand* scom = new SleepCommand(cuid, e, command, wait); + e->commands.push(scom); + } return true; } diff --git a/src/AbstractCommand.h b/src/AbstractCommand.h index 23c538c5..3d94511b 100644 --- a/src/AbstractCommand.h +++ b/src/AbstractCommand.h @@ -39,7 +39,7 @@ protected: Socket* socket; bool checkSocketIsReadable; bool checkSocketIsWritable; - virtual bool prepareForRetry(); + virtual bool prepareForRetry(int wait); virtual void onError(Exception* e); virtual bool executeInternal(Segment segment) = 0; public: diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 4be67c1b..39391963 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -24,7 +24,6 @@ #include "Util.h" #include "DlRetryEx.h" #include "HttpInitiateConnectionCommand.h" -#include "SleepCommand.h" #include "InitiateConnectionCommandFactory.h" #include "message.h" @@ -72,18 +71,15 @@ bool DownloadCommand::executeInternal(Segment seg) { } -bool DownloadCommand::prepareForRetry() { - req->resetUrl(); - Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, req, e); - SleepCommand* scom = new SleepCommand(cuid, e, command); - e->commands.push(scom); - return true; +bool DownloadCommand::prepareForRetry(int wait) { + //req->resetUrl(); + return AbstractCommand::prepareForRetry(wait); } bool DownloadCommand::prepareForNextSegment() { req->resetUrl(); if(!e->segmentMan->finished()) { - return AbstractCommand::prepareForRetry(); + return AbstractCommand::prepareForRetry(0); } else { return true; } diff --git a/src/DownloadCommand.h b/src/DownloadCommand.h index 8d8f6b63..0ea9d680 100644 --- a/src/DownloadCommand.h +++ b/src/DownloadCommand.h @@ -32,7 +32,7 @@ class DownloadCommand : public AbstractCommand { protected: bool executeInternal(Segment segment); - bool prepareForRetry(); + bool prepareForRetry(int wait); bool prepareForNextSegment(); public: diff --git a/src/Exception.h b/src/Exception.h index 6b013fcb..83b62bce 100644 --- a/src/Exception.h +++ b/src/Exception.h @@ -31,13 +31,10 @@ class Exception { private: string msg; protected: - void setMsg(string msgsrc, ...) { - va_list ap; - va_start(ap, msgsrc); + void setMsg(string msgsrc, va_list ap) { char buf[256]; vsnprintf(buf, sizeof(buf), msgsrc.c_str(), ap); msg = buf; - va_end(ap); } public: Exception() {} diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index c8347fe0..22c7fa71 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -36,12 +36,11 @@ HttpResponseCommand::~HttpResponseCommand() {} bool HttpResponseCommand::executeInternal(Segment seg) { if(SEGMENT_EQUAL(req->seg, seg) == false) { e->logger->info(MSG_SEGMENT_CHANGED, cuid); - return prepareForRetry(); + return prepareForRetry(0); } HttpHeader headers; HttpConnection httpConnection(cuid, socket, e->option, e->logger); int status = httpConnection.receiveResponse(headers); - // check HTTP status number checkResponse(status, seg); retrieveCookie(headers); @@ -80,7 +79,7 @@ bool HttpResponseCommand::handleRedirect(string url, const HttpHeader& headers) req->redirectUrl(url); e->logger->info(MSG_REDIRECT, cuid, url.c_str()); e->noWait = true; - return prepareForRetry(); + return prepareForRetry(0); } bool HttpResponseCommand::handleDefaultEncoding(const HttpHeader& headers) { @@ -102,7 +101,7 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpHeader& headers) { e->segmentMan->load(); e->diskWriter->openExistingFile(e->segmentMan->getFilePath()); // send request again to the server with Range header - return prepareForRetry(); + return prepareForRetry(0); } else { Segment seg; e->segmentMan->getSegment(seg, cuid); @@ -147,3 +146,4 @@ void HttpResponseCommand::retrieveCookie(const HttpHeader& headers) { req->cookieBox->add(c); } } + diff --git a/src/Request.h b/src/Request.h index 503aa541..0d9554e6 100644 --- a/src/Request.h +++ b/src/Request.h @@ -74,6 +74,7 @@ public: bool resetUrl(); void resetRetryCount(); void addRetryCount(); + int getRetryCount(); bool noMoreRetry(); string getUrl() const { return url; } diff --git a/src/SleepCommand.cc b/src/SleepCommand.cc index 7e56419d..82fc6dc5 100644 --- a/src/SleepCommand.cc +++ b/src/SleepCommand.cc @@ -22,10 +22,8 @@ #include "SleepCommand.h" #include "Util.h" -#define WAIT_SEC 5 - -SleepCommand::SleepCommand(int cuid, DownloadEngine* e, Command* nextCommand): - Command(cuid), engine(e), nextCommand(nextCommand) { +SleepCommand::SleepCommand(int cuid, DownloadEngine* e, Command* nextCommand, int wait): + Command(cuid), engine(e), nextCommand(nextCommand), wait(wait) { gettimeofday(&checkPoint, NULL); } @@ -38,7 +36,7 @@ SleepCommand::~SleepCommand() { bool SleepCommand::execute() { struct timeval now; gettimeofday(&now, NULL); - if(Util::difftv(now, checkPoint) >= WAIT_SEC*1000000) { + if(Util::difftv(now, checkPoint) >= wait*1000000) { engine->commands.push(nextCommand); nextCommand = NULL; return true; diff --git a/src/SleepCommand.h b/src/SleepCommand.h index c737076c..6d75cd86 100644 --- a/src/SleepCommand.h +++ b/src/SleepCommand.h @@ -30,9 +30,10 @@ class SleepCommand:public Command { private: DownloadEngine* engine; Command* nextCommand; + int wait; struct timeval checkPoint; public: - SleepCommand(int cuid, DownloadEngine* e, Command* nextCommand); + SleepCommand(int cuid, DownloadEngine* e, Command* nextCommand, int wait); ~SleepCommand(); bool execute(); }; diff --git a/src/main.cc b/src/main.cc index 89aaba16..718ddd76 100644 --- a/src/main.cc +++ b/src/main.cc @@ -90,7 +90,7 @@ void showVersion() { cout << "along with this program; if not, write to the Free Software" << endl; cout << "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA" << endl; cout << endl; - cout << "Contact Info: Tasuhiro Tsujikawa " << endl; + cout << "Contact Info: Tasuhiro Tsujikawa " << endl; cout << endl; } @@ -117,6 +117,8 @@ void showUsage() { 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 << " -v, --version Print the version number and exit." << endl; cout << " -h, --help Print this message and exit." << endl; cout << "URL:" << endl; @@ -143,6 +145,7 @@ int main(int argc, char* argv[]) { int c; Option* op = new Option(); + op->put("retry_wait", "5"); while(1) { int optIndex = 0; @@ -160,6 +163,7 @@ int main(int argc, char* argv[]) { { "http-proxy-passwd", required_argument, &lopt, 5 }, { "http-auth-scheme", required_argument, &lopt, 6 }, { "referer", required_argument, &lopt, 7 }, + { "retry-wait", required_argument, &lopt, 8 }, { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { 0, 0, 0, 0 } @@ -182,7 +186,7 @@ int main(int argc, char* argv[]) { exit(1); } op->put("http_proxy_host", proxy.first); - op->put("http_proxy_port", proxy.second); + op->put("http_proxy_port", Util::itos(port)); op->put("http_proxy_enabled", "true"); break; } @@ -209,6 +213,16 @@ int main(int argc, char* argv[]) { case 7: referer = optarg; break; + case 8: { + int wait = (int)strtol(optarg, NULL, 10); + if(!(0 <= wait && wait <= 60)) { + cerr << "retry-wait must be between 0 and 60." << endl; + showUsage(); + exit(1); + } + op->put("retry-wait", Util::itos(wait)); + break; + } } break; }