Sfoglia il codice sorgente

2009-05-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Added --xml-rpc-max-request-size option to limit the size of
	XML-RPC request.
Tatsuhiro Tsujikawa 16 anni fa
parent
commit
544732b124
6 ha cambiato i file con 31 aggiunte e 0 eliminazioni
  1. 5 0
      ChangeLog
  2. 9 0
      src/HttpServerCommand.cc
  3. 9 0
      src/OptionHandlerFactory.cc
  4. 2 0
      src/prefs.cc
  5. 2 0
      src/prefs.h
  6. 4 0
      src/usage_text.h

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+2009-05-26  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Added --xml-rpc-max-request-size option to limit the size of
+	XML-RPC request.
+	
 2009-05-26  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Documented XML-RPC API in man page.

+ 9 - 0
src/HttpServerCommand.cc

@@ -45,6 +45,7 @@
 #include "RecoverableException.h"
 #include "prefs.h"
 #include "Option.h"
+#include "Util.h"
 
 namespace aria2 {
 
@@ -103,6 +104,14 @@ bool HttpServerCommand::execute()
       if(header.isNull()) {
 	_e->commands.push_back(this);
 	return false;
+      } else if(static_cast<uint64_t>
+		(_e->option->getAsInt(PREF_XML_RPC_MAX_REQUEST_SIZE)) <
+		_httpServer->getContentLength()) {
+	logger->info("Request too long. ContentLength=%s."
+		     " See --xml-rpc-max-request-size option to loose"
+		     " this limitation.",
+		     Util::uitos(_httpServer->getContentLength()).c_str());
+	return true;
       } else {
 	Command* command = new HttpServerBodyCommand(cuid, _httpServer, _e,
 						     _socket);

+ 9 - 0
src/OptionHandlerFactory.cc

@@ -400,6 +400,15 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
     op->addTag(TAG_ADVANCED);
     handlers.push_back(op);
   }
+  {
+    SharedHandle<OptionHandler> op(new UnitNumberOptionHandler
+				   (PREF_XML_RPC_MAX_REQUEST_SIZE,
+				    TEXT_XML_RPC_MAX_REQUEST_SIZE,
+				    "2M",
+				    0));
+    op->addTag(TAG_ADVANCED);
+    handlers.push_back(op);
+  }			    
   {
     SharedHandle<OptionHandler> op(new DefaultOptionHandler
 				   (PREF_XML_RPC_USER,

+ 2 - 0
src/prefs.cc

@@ -167,6 +167,8 @@ const std::string PREF_REUSE_URI("reuse-uri");
 const std::string PREF_XML_RPC_USER("xml-rpc-user");
 // value: string
 const std::string PREF_XML_RPC_PASSWD("xml-rpc-passwd");
+// value: 1*digit
+const std::string PREF_XML_RPC_MAX_REQUEST_SIZE("xml-rpc-max-request-size");
 // value: string
 const std::string PREF_ON_DOWNLOAD_START("on-download-start");
 const std::string PREF_ON_DOWNLOAD_STOP("on-download-stop");

+ 2 - 0
src/prefs.h

@@ -171,6 +171,8 @@ extern const std::string PREF_REUSE_URI;
 extern const std::string PREF_XML_RPC_USER;
 // value: string
 extern const std::string PREF_XML_RPC_PASSWD;
+// value: 1*digit
+extern const std::string PREF_XML_RPC_MAX_REQUEST_SIZE;
 // value: string
 extern const std::string PREF_ON_DOWNLOAD_START;
 extern const std::string PREF_ON_DOWNLOAD_STOP;

+ 4 - 0
src/usage_text.h

@@ -491,6 +491,10 @@ _(" --enable-xml-rpc[=true|false] Enable XML-RPC server.\n"\
   "                              It is strongly recommended to set username and\n"\
   "                              password using --xml-rpc-user and --xml-rpc-passwd\n"\
   "                              option. See also --xml-rpc-listen-port option.")
+#define TEXT_XML_RPC_MAX_REQUEST_SIZE \
+_(" --xml-rpc-max-request-size=SIZE Set max size of XML-RPC request. If aria2\n"\
+  "                              detected the request is more than SIZE bytes, it\n"\
+  "                              drops connection.")
 #define TEXT_XML_RPC_USER \
 _(" --xml-rpc-user=USER          Set XML-RPC user.")
 #define TEXT_XML_RPC_PASSWD \