Przeglądaj źródła

* Added Referer support.
* Added referer command-line option.
* Added rety-wait command-line option.
* Fixed formating bug in Exception::setMsg()

Tatsuhiro Tsujikawa 19 lat temu
rodzic
commit
5752a554bf

+ 4 - 0
ChangeLog

@@ -1,5 +1,9 @@
 2006-02-18  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
+	* 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

+ 4 - 0
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.

+ 2 - 2
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
+* Add SSL client cert support
+* Better HTTP status handling

+ 10 - 10
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 <tujikawa@rednoah.com>.
 #
@@ -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'`\\"
 

+ 1 - 1
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])

+ 14 - 7
src/AbstractCommand.cc

@@ -26,6 +26,7 @@
 #include <sys/time.h>
 #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;
 }
 

+ 1 - 1
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:

+ 4 - 8
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;
   }

+ 1 - 1
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:

+ 1 - 4
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() {}

+ 4 - 4
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);
   }
 }
+  

+ 1 - 0
src/Request.h

@@ -74,6 +74,7 @@ public:
   bool resetUrl();
   void resetRetryCount();
   void addRetryCount();
+  int getRetryCount();
   bool noMoreRetry();
 
   string getUrl() const { return url; }

+ 3 - 5
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;

+ 2 - 1
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();
 };

+ 16 - 2
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 <tujikawa at rednoah dot com>" << endl;
+  cout << "Contact Info: Tasuhiro Tsujikawa <tujikawa at users dot sourceforge dot net>" << 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;
     }