diff --git a/ChangeLog b/ChangeLog index faf9ea9b..90db5e13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-11-04 Tatsuhiro Tsujikawa + + 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 Renamed --http-proxy-method as --proxy-method. diff --git a/src/option_processing.cc b/src/option_processing.cc index 9fc1cc01..ef323151 100644 --- a/src/option_processing.cc +++ b/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) {