summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-10-29 00:16:46 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-10-29 00:16:46 +0900
commit0ba6f8c352da64db26907cbfa4ff9579700562e0 (patch)
treea243284f5bfc73faa984762f54cce587b49b4c56 /src
parent69966d7ac995436695b59ac8e9b736343308c277 (diff)
Use same domain-match algorithm for no-proxy and netrc.
Now "example.org" does not domain-match ".example.org" in both functions.
Diffstat (limited to 'src')
-rw-r--r--src/AbstractCommand.cc25
-rw-r--r--src/Netrc.cc10
-rw-r--r--src/util.cc12
-rw-r--r--src/util.h11
4 files changed, 25 insertions, 33 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc
index 491a9a24..e2636193 100644
--- a/src/AbstractCommand.cc
+++ b/src/AbstractCommand.cc
@@ -586,24 +586,6 @@ bool isProxyRequest
} // namespace
namespace {
-class DomainMatch {
-private:
- std::string hostname_;
-public:
- DomainMatch(const std::string& hostname):hostname_(hostname) {}
-
- bool operator()(const std::string& domain) const
- {
- if(util::startsWith(domain, A2STR::DOT_C)) {
- return util::endsWith(hostname_, domain);
- } else {
- return util::endsWith(hostname_, A2STR::DOT_C+domain);
- }
- }
-};
-} // namespace
-
-namespace {
bool inNoProxy(const SharedHandle<Request>& req,
const std::string& noProxy)
{
@@ -612,16 +594,11 @@ bool inNoProxy(const SharedHandle<Request>& req,
if(entries.empty()) {
return false;
}
- DomainMatch domainMatch(A2STR::DOT_C+req->getHost());
for(std::vector<std::string>::const_iterator i = entries.begin(),
eoi = entries.end(); i != eoi; ++i) {
std::string::size_type slashpos = (*i).find('/');
if(slashpos == std::string::npos) {
- if(util::isNumericHost(*i)) {
- if(req->getHost() == *i) {
- return true;
- }
- } else if(domainMatch(*i)) {
+ if(util::noProxyDomainMatch(req->getHost(), *i)) {
return true;
}
} else {
diff --git a/src/Netrc.cc b/src/Netrc.cc
index dc7618b9..29306a71 100644
--- a/src/Netrc.cc
+++ b/src/Netrc.cc
@@ -63,15 +63,7 @@ Authenticator::~Authenticator() {}
bool Authenticator::match(const std::string& hostname) const
{
- if(util::isNumericHost(hostname)) {
- return hostname == machine_;
- } else {
- if(util::startsWith(machine_, A2STR::DOT_C)) {
- return util::endsWith(A2STR::DOT_C+hostname, machine_);
- } else {
- return hostname == machine_;
- }
- }
+ return util::noProxyDomainMatch(hostname, machine_);
}
void Authenticator::setMachine(const std::string& machine)
diff --git a/src/util.cc b/src/util.cc
index bd76b39f..b8e8782c 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -1752,6 +1752,18 @@ std::string safeStrerror(int errNum)
return makeString(strerror(errNum));
}
+bool noProxyDomainMatch
+(const std::string& hostname,
+ const std::string& domain)
+{
+ if(!util::isNumericHost(hostname) &&
+ util::startsWith(domain, A2STR::DOT_C)) {
+ return util::endsWith(hostname, domain);
+ } else {
+ return hostname == domain;
+ }
+}
+
} // namespace util
} // namespace aria2
diff --git a/src/util.h b/src/util.h
index d51348fb..1fffd10a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -520,6 +520,17 @@ SharedHandle<T> copy(const SharedHandle<T>& a)
return SharedHandle<T>(new T(*a.get()));
}
+// This is a bit different from cookie_helper::domainMatch(). If
+// hostname is numeric host, then returns true if domain == hostname.
+// That is if domain starts with ".", then returns true if domain is a
+// suffix of hostname. If domain does not start with ".", then
+// returns true if domain == hostname. Otherwise returns true.
+// For example,
+//
+// * noProxyDomainMatch("aria2.sf.net", ".sf.net") returns true.
+// * noProxyDomainMatch("sf.net", ".sf.net") returns false.
+bool noProxyDomainMatch(const std::string& hostname, const std::string& domain);
+
} // namespace util
} // namespace aria2