Browse Source

2008-11-04 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Added support for following envrionment variables: http_proxy,
	https_proxy, ftp_proxy and all_proxy.
	Each variable is equivalent to the aria2 option whose name is
	the variable name with '_' replaced with '-'.
	They overrides options specified in aria2.conf file.
	The envrionment variables can be overrode using command-line
	option.
	* src/option_processing.cc
Tatsuhiro Tsujikawa 17 năm trước cách đây
mục cha
commit
7513095042
2 tập tin đã thay đổi với 33 bổ sung0 xóa
  1. 10 0
      ChangeLog
  2. 23 0
      src/option_processing.cc

+ 10 - 0
ChangeLog

@@ -1,3 +1,13 @@
+2008-11-04  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Added support for following envrionment variables: http_proxy,
+	https_proxy, ftp_proxy and all_proxy.
+	Each variable is equivalent to the aria2 option whose name is the
+	variable name with '_' replaced with '-'.
+	They overrides options specified in aria2.conf file.
+	The envrionment variables can be overrode using command-line option.
+	* src/option_processing.cc
+	
 2008-11-04  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Renamed --http-proxy-method as --proxy-method.

+ 23 - 0
src/option_processing.cc

@@ -72,6 +72,23 @@ static std::string toBoolArg(const char* optarg)
   return arg;
 }
 
+static void overrideWithEnv(Option* op, const OptionParser& optionParser,
+			    const std::string& pref,
+			    const std::string& envName)
+{
+  char* value = getenv(envName.c_str());
+  if(value) {
+    try {
+      optionParser.findByName(pref)->parse(op, value);
+    } catch(Exception& e) {
+      std::cerr << "Caught Error while parsing environment variable"
+		<< " '" << envName << "'"
+		<< "\n"
+		<< e.stackTrace();
+    }
+  }
+}
+
 Option* option_processing(int argc, char* const argv[])
 {
   std::stringstream cmdstream;
@@ -555,6 +572,12 @@ Option* option_processing(int argc, char* const argv[])
 	exit(EXIT_FAILURE);
       }
     }
+    // Override configuration with environment variables.
+    overrideWithEnv(op, oparser, PREF_HTTP_PROXY, "http_proxy");
+    overrideWithEnv(op, oparser, PREF_HTTPS_PROXY, "https_proxy");
+    overrideWithEnv(op, oparser, PREF_FTP_PROXY, "ftp_proxy");
+    overrideWithEnv(op, oparser, PREF_ALL_PROXY, "all_proxy");
+
     try {
       oparser.parse(op, cmdstream);
     } catch(OptionHandlerException& e) {