From 4ea28cb8377bc7b4654e6ae0216db6a7425d12c9 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 27 Jul 2011 23:28:31 +0900 Subject: Don't send basic auth header to service operated on differenct port. When --http-auth-challenge=true, aria2 only sends basic auth header when requested. Old implementation sends basic auth header to service operated in different port in successive request. This change avoid this bug. --- src/AuthConfigFactory.cc | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'src/AuthConfigFactory.cc') diff --git a/src/AuthConfigFactory.cc b/src/AuthConfigFactory.cc index 4d52fbb4..1a053a23 100644 --- a/src/AuthConfigFactory.cc +++ b/src/AuthConfigFactory.cc @@ -66,11 +66,14 @@ AuthConfigFactory::createAuthConfig if(!request->getUsername().empty()) { updateBasicCred(BasicCred(request->getUsername(), request->getPassword(), - request->getHost(), request->getDir(), true)); + request->getHost(), + request->getPort(), + request->getDir(), true)); return createAuthConfig(request->getUsername(), request->getPassword()); } std::deque::const_iterator i = - findBasicCred(request->getHost(), request->getDir()); + findBasicCred(request->getHost(), request->getPort(), + request->getDir()); if(i == basicCreds_.end()) { return SharedHandle(); } else { @@ -180,10 +183,13 @@ void AuthConfigFactory::updateBasicCred(const BasicCred& basicCred) } bool AuthConfigFactory::activateBasicCred -(const std::string& host, const std::string& path, const Option* op) +(const std::string& host, + uint16_t port, + const std::string& path, + const Option* op) { - std::deque::iterator i = findBasicCred(host, path); + std::deque::iterator i = findBasicCred(host, port, path); if(i == basicCreds_.end()) { SharedHandle authConfig = createHttpAuthResolver(op)->resolveAuthConfig(host); @@ -191,7 +197,7 @@ bool AuthConfigFactory::activateBasicCred return false; } else { BasicCred bc(authConfig->getUser(), authConfig->getPassword(), - host, path, true); + host, port, path, true); i = std::lower_bound(basicCreds_.begin(), basicCreds_.end(), bc); basicCreds_.insert(i, bc); return true; @@ -204,10 +210,10 @@ bool AuthConfigFactory::activateBasicCred AuthConfigFactory::BasicCred::BasicCred (const std::string& user, const std::string& password, - const std::string& host, const std::string& path, + const std::string& host, uint16_t port, const std::string& path, bool activated): user_(user), password_(password), - host_(host), path_(path), activated_(activated) + host_(host), port_(port), path_(path), activated_(activated) { if(!util::endsWith(path_, "/")) { path_ += "/"; @@ -226,27 +232,27 @@ bool AuthConfigFactory::BasicCred::isActivated() const bool AuthConfigFactory::BasicCred::operator==(const BasicCred& cred) const { - return host_ == cred.host_ && path_ == cred.path_; + return host_ == cred.host_ && port_ == cred.port_ && path_ == cred.path_; } bool AuthConfigFactory::BasicCred::operator<(const BasicCred& cred) const { - int c = host_.compare(cred.host_); - if(c == 0) { - return path_ > cred.path_; - } else { - return c < 0; - } + return host_ < cred.host_ || + (!(cred.host_ < host_) && (port_ < cred.port_ || + (!(cred.port_ < port_) && path_ > cred.path_))); } std::deque::iterator -AuthConfigFactory::findBasicCred(const std::string& host, - const std::string& path) +AuthConfigFactory::findBasicCred +(const std::string& host, + uint16_t port, + const std::string& path) { - BasicCred bc("", "", host, path); + BasicCred bc("", "", host, port, path); std::deque::iterator i = std::lower_bound(basicCreds_.begin(), basicCreds_.end(), bc); - for(; i != basicCreds_.end() && (*i).host_ == host; ++i) { + for(; i != basicCreds_.end() && (*i).host_ == host && (*i).port_ == port; + ++i) { if(util::startsWith(bc.path_, (*i).path_)) { return i; } -- cgit