/* */ #ifndef D_NETRC_H #define D_NETRC_H #include "common.h" #include #include #include "SharedHandle.h" namespace aria2 { class Authenticatable { public: virtual ~Authenticatable() {} virtual bool match(const std::string& hostname) const = 0; }; class Authenticator : public Authenticatable { private: std::string machine_; std::string login_; std::string password_; std::string account_; public: Authenticator(); Authenticator(const std::string& machine, const std::string& login, const std::string& password, const std::string& account); virtual ~Authenticator(); virtual bool match(const std::string& hostname) const; const std::string& getMachine() const { return machine_; } void setMachine(const std::string& machine); template void setMachine(InputIterator first, InputIterator last) { machine_.assign(first, last); } const std::string& getLogin() const { return login_; } void setLogin(const std::string& login); template void setLogin(InputIterator first, InputIterator last) { login_.assign(first, last); } const std::string& getPassword() const { return password_; } void setPassword(const std::string& password); template void setPassword(InputIterator first, InputIterator last) { password_.assign(first, last); } const std::string& getAccount() const { return account_; } void setAccount(const std::string& account); template void setAccount(InputIterator first, InputIterator last) { account_.assign(first, last); } }; class DefaultAuthenticator : public Authenticator { public: DefaultAuthenticator(); DefaultAuthenticator(const std::string& login, const std::string& password, const std::string& account); virtual ~DefaultAuthenticator(); virtual bool match(const std::string& hostname) const; }; class Netrc { private: std::vector > authenticators_; void storeAuthenticator(const SharedHandle& authenticator); public: Netrc(); ~Netrc(); void parse(const std::string& path); SharedHandle findAuthenticator (const std::string& hostname) const; const std::vector >& getAuthenticators() const { return authenticators_; } void addAuthenticator(const SharedHandle& authenticator); }; } // namespace aria2 #endif // D_NETRC_H