/* */ #include "NetrcAuthResolver.h" #include "AuthConfig.h" #include "Netrc.h" namespace aria2 { NetrcAuthResolver::NetrcAuthResolver():ignoreDefault_(false) {} SharedHandle NetrcAuthResolver::resolveAuthConfig(const std::string& hostname) { if(!getUserDefinedAuthConfig()) { return findNetrcAuthenticator(hostname); } else { return getUserDefinedAuthConfig(); } } SharedHandle NetrcAuthResolver::findNetrcAuthenticator(const std::string& hostname) const { if(!netrc_) { return getDefaultAuthConfig(); } else { SharedHandle auth = netrc_->findAuthenticator(hostname); if(!auth) { return getDefaultAuthConfig(); } else { if(ignoreDefault_ && auth->getMachine().empty()) { return getDefaultAuthConfig(); } else { return SharedHandle (new AuthConfig(auth->getLogin(), auth->getPassword())); } } } } void NetrcAuthResolver::setNetrc(const SharedHandle& netrc) { netrc_ = netrc; } void NetrcAuthResolver::ignoreDefault() { ignoreDefault_ = true; } void NetrcAuthResolver::useDefault() { ignoreDefault_ = false; } } // namespace aria2