2010-01-15 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Code cleanup for proxy URI handling.
	* src/AbstractCommand.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-01-15 08:47:00 +00:00
parent a77d96e2cf
commit c16b346bb9
2 changed files with 26 additions and 29 deletions

View File

@ -1,3 +1,8 @@
2010-01-15 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Code cleanup for proxy URI handling.
* src/AbstractCommand.cc
2010-01-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-01-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added --bt-metadata-only option. If true is given to this option, Added --bt-metadata-only option. If true is given to this option,

View File

@ -365,8 +365,9 @@ void AbstractCommand::setWriteCheckSocketIf
} }
} }
static const std::string& getProxyStringFor(const std::string& proxyPref, // Returns proxy option value for the given protocol.
const SharedHandle<Option>& option) static const std::string& getProxyOptionFor
(const std::string& proxyPref, const SharedHandle<Option>& option)
{ {
if(option->defined(proxyPref)) { if(option->defined(proxyPref)) {
return option->get(proxyPref); return option->get(proxyPref);
@ -375,24 +376,29 @@ static const std::string& getProxyStringFor(const std::string& proxyPref,
} }
} }
static bool isProxyUsed(const std::string& proxyPref, // Returns proxy URI for given protocol. If no proxy URI is defined,
const SharedHandle<Option>& option) // then returns an empty string.
static const std::string& getProxyUri
(const std::string& protocol, const SharedHandle<Option>& option)
{ {
std::string proxy = getProxyStringFor(proxyPref, option); if(protocol == Request::PROTO_HTTP) {
if(proxy.empty()) { return getProxyOptionFor(PREF_HTTP_PROXY, option);
return false; } else if(protocol == Request::PROTO_HTTPS) {
return getProxyOptionFor(PREF_HTTPS_PROXY, option);
} else if(protocol == Request::PROTO_FTP) {
return getProxyOptionFor(PREF_FTP_PROXY, option);
} else { } else {
return Request().setUrl(proxy); return A2STR::NIL;
} }
} }
static bool isProxyRequest(const std::string& protocol, // Returns true if proxy is defined for the given protocol. Otherwise
const SharedHandle<Option>& option) // returns false.
static bool isProxyRequest
(const std::string& protocol, const SharedHandle<Option>& option)
{ {
return const std::string& proxyUri = getProxyUri(protocol, option);
(protocol == Request::PROTO_HTTP && isProxyUsed(PREF_HTTP_PROXY, option)) || return !proxyUri.empty() && Request().setUrl(proxyUri);
(protocol == Request::PROTO_HTTPS && isProxyUsed(PREF_HTTPS_PROXY,option))||
(protocol == Request::PROTO_FTP && isProxyUsed(PREF_FTP_PROXY, option));
} }
class DomainMatch { class DomainMatch {
@ -430,27 +436,13 @@ bool AbstractCommand::isProxyDefined() const
!inNoProxy(req, getOption()->get(PREF_NO_PROXY)); !inNoProxy(req, getOption()->get(PREF_NO_PROXY));
} }
static const std::string& getProxyString(const SharedHandle<Request>& req,
const SharedHandle<Option>& option)
{
if(req->getProtocol() == Request::PROTO_HTTP) {
return getProxyStringFor(PREF_HTTP_PROXY, option);
} else if(req->getProtocol() == Request::PROTO_HTTPS) {
return getProxyStringFor(PREF_HTTPS_PROXY, option);
} else if(req->getProtocol() == Request::PROTO_FTP) {
return getProxyStringFor(PREF_FTP_PROXY, option);
} else {
return A2STR::NIL;
}
}
SharedHandle<Request> AbstractCommand::createProxyRequest() const SharedHandle<Request> AbstractCommand::createProxyRequest() const
{ {
SharedHandle<Request> proxyRequest; SharedHandle<Request> proxyRequest;
if(inNoProxy(req, getOption()->get(PREF_NO_PROXY))) { if(inNoProxy(req, getOption()->get(PREF_NO_PROXY))) {
return proxyRequest; return proxyRequest;
} }
std::string proxy = getProxyString(req, getOption()); std::string proxy = getProxyUri(req->getProtocol(), getOption());
if(!proxy.empty()) { if(!proxy.empty()) {
proxyRequest.reset(new Request()); proxyRequest.reset(new Request());
if(proxyRequest->setUrl(proxy)) { if(proxyRequest->setUrl(proxy)) {