Selaa lähdekoodia

2009-08-30 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Added --xml-rpc-listen-all option. If true is given to this
	option, aria2 listens incoming XML-RPC requests on all network
	interfaces. If false is given, listens only on local loopback
	interface. The default value is false.
	* src/HttpListenCommand.cc
	* src/OptionHandlerFactory.cc
	* src/SocketCore.cc
	* src/SocketCore.h
	* src/prefs.cc
	* src/prefs.h
	* src/usage_text.h
Tatsuhiro Tsujikawa 16 vuotta sitten
vanhempi
commit
d182b380c2
8 muutettua tiedostoa jossa 42 lisäystä ja 4 poistoa
  1. 14 0
      ChangeLog
  2. 7 1
      src/HttpListenCommand.cc
  3. 9 0
      src/OptionHandlerFactory.cc
  4. 2 2
      src/SocketCore.cc
  5. 2 1
      src/SocketCore.h
  6. 2 0
      src/prefs.cc
  7. 2 0
      src/prefs.h
  8. 4 0
      src/usage_text.h

+ 14 - 0
ChangeLog

@@ -1,3 +1,17 @@
+2009-08-30  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Added --xml-rpc-listen-all option. If true is given to this
+	option, aria2 listens incoming XML-RPC requests on all network
+	interfaces. If false is given, listens only on local loopback
+	interface. The default value is false.
+	* src/HttpListenCommand.cc
+	* src/OptionHandlerFactory.cc
+	* src/SocketCore.cc
+	* src/SocketCore.h
+	* src/prefs.cc
+	* src/prefs.h
+	* src/usage_text.h
+
 2009-08-21  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	* Release 1.5.2

+ 7 - 1
src/HttpListenCommand.cc

@@ -42,6 +42,8 @@
 #include "CUIDCounter.h"
 #include "RequestGroupMan.h"
 #include "FileEntry.h"
+#include "prefs.h"
+#include "Option.h"
 
 namespace aria2 {
 
@@ -91,7 +93,11 @@ bool HttpListenCommand::bindPort(uint16_t port)
   _serverSocket.reset(new SocketCore());
   logger->info("CUID#%d - Setting up HttpListenCommand", cuid);
   try {
-    _serverSocket->bind(port);
+    int flags = 0;
+    if(_e->option->getAsBool(PREF_XML_RPC_LISTEN_ALL)) {
+      flags = AI_PASSIVE;
+    }
+    _serverSocket->bind(port, flags);
     _serverSocket->beginListen();
     _serverSocket->setNonBlockingMode();
     logger->info(MSG_LISTENING_PORT, cuid, port);

+ 9 - 0
src/OptionHandlerFactory.cc

@@ -392,6 +392,15 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
     handlers.push_back(op);
   }
 #ifdef ENABLE_XML_RPC
+  {
+    SharedHandle<OptionHandler> op(new BooleanOptionHandler
+				   (PREF_XML_RPC_LISTEN_ALL,
+				    TEXT_XML_RPC_LISTEN_ALL,
+				    V_FALSE,
+				    OptionHandler::OPT_ARG));
+    op->addTag(TAG_ADVANCED);
+    handlers.push_back(op);
+  }
   {
     SharedHandle<OptionHandler> op(new NumberOptionHandler
 				   (PREF_XML_RPC_LISTEN_PORT,

+ 2 - 2
src/SocketCore.cc

@@ -159,7 +159,7 @@ std::string uitos(T value)
   return str;
 }
 
-void SocketCore::bind(uint16_t port)
+void SocketCore::bind(uint16_t port, int flags)
 {
   closeConnection();
 
@@ -168,7 +168,7 @@ void SocketCore::bind(uint16_t port)
   memset(&hints, 0, sizeof(hints));
   hints.ai_family = _protocolFamily;
   hints.ai_socktype = _sockType;
-  hints.ai_flags = AI_PASSIVE;
+  hints.ai_flags = flags;
   hints.ai_protocol = 0;
   int s;
   s = getaddrinfo(0, uitos(port).c_str(), &hints, &res);

+ 2 - 1
src/SocketCore.h

@@ -145,10 +145,11 @@ public:
 
   /**
    * Creates a socket and bind it with locahost's address and port.
+   * flags is set to struct addrinfo's ai_flags.
    * @param port port to listen. If 0 is specified, os automaticaly
    * choose avaiable port.
    */
-  void bind(uint16_t port);
+  void bind(uint16_t port, int flags = AI_PASSIVE);
 
   /**
    * Listens form connection on it.

+ 2 - 0
src/prefs.cc

@@ -172,6 +172,8 @@ const std::string PREF_ON_DOWNLOAD_START("on-download-start");
 const std::string PREF_ON_DOWNLOAD_STOP("on-download-stop");
 const std::string PREF_ON_DOWNLOAD_COMPLETE("on-download-complete");
 const std::string PREF_ON_DOWNLOAD_ERROR("on-download-error");
+// value: true | false
+const std::string PREF_XML_RPC_LISTEN_ALL("xml-rpc-listen-all");
 
 /**
  * FTP related preferences

+ 2 - 0
src/prefs.h

@@ -176,6 +176,8 @@ extern const std::string PREF_ON_DOWNLOAD_START;
 extern const std::string PREF_ON_DOWNLOAD_STOP;
 extern const std::string PREF_ON_DOWNLOAD_COMPLETE;
 extern const std::string PREF_ON_DOWNLOAD_ERROR;
+// value: true | false
+extern const std::string PREF_XML_RPC_LISTEN_ALL;
 
 /**
  * FTP related preferences

+ 4 - 0
src/usage_text.h

@@ -562,3 +562,7 @@ _(" --on-download-stop=COMMAND   Set the command to be executed when download\n"
 _(" --bt-stop-timeout=SEC        Stop BitTorrent download if download speed is 0 in\n"\
   "                              consecutive SEC seconds. If 0 is given, this\n"\
   "                              feature is disabled.")
+#define TEXT_XML_RPC_LISTEN_ALL \
+_(" --xml-rpc-listen-all[=true|false] Listen incoming XML-RPC requests on all\n"\
+  "                              network interfaces. If false is given, listen only\n"\
+  "                              on local loopback interface.")