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
pull/1/head
Tatsuhiro Tsujikawa 2008-11-04 14:57:05 +00:00
parent bd2ead4763
commit 7513095042
2 changed files with 33 additions and 0 deletions

View File

@ -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.

View File

@ -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) {