/* */ #ifndef _D_NETRC_H_ #define _D_NETRC_H_ #include "common.h" class Authenticatable { public: virtual ~Authenticatable() {} virtual bool match(const string& hostname) const = 0; }; typedef SharedHandle AuthenticatableHandle; class Authenticator : public Authenticatable { private: string machine; string login; string password; string account; public: Authenticator() {} Authenticator(const string& machine, const string& login, const string& password, const string& account) :machine(machine), login(login), password(password), account(account) {} virtual ~Authenticator() {} virtual bool match(const string& hostname) const { return hostname == machine; } const string& getMachine() const { return machine; } void setMachine(const string& machine) { this->machine = machine; } const string& getLogin() const { return login; } void setLogin(const string& login) { this->login = login; } const string& getPassword() const { return password; } void setPassword(const string& password) { this->password = password; } const string& getAccount() const { return account; } void setAccount(const string& account) { this->account = account; } }; typedef SharedHandle AuthenticatorHandle; typedef deque Authenticators; class DefaultAuthenticator : public Authenticator { public: DefaultAuthenticator() {} DefaultAuthenticator(const string& login, const string& password, const string& account) :Authenticator("", login, password, account) {} virtual ~DefaultAuthenticator() {} virtual bool match(const string& hostname) const { return true; } }; typedef SharedHandle DefaultAuthenticatorHandle; class Netrc { private: Authenticators authenticators; void storeAuthenticator(const AuthenticatorHandle& authenticator); string getRequiredNextToken(ifstream& f) const; void skipMacdef(ifstream& f) const; public: Netrc() {} void parse(const string& path); AuthenticatorHandle findAuthenticator(const string& hostname) const; const Authenticators& getAuthenticators() const { return authenticators; } void addAuthenticator(const AuthenticatorHandle& authenticator) { authenticators.push_back(authenticator); } }; typedef SharedHandle NetrcHandle; //typedef SingletonHolder NetrcSingletonHolder; #endif // _D_NETRC_H_