mirror of https://github.com/aria2/aria2
authenticatable -> authenticator
parent
113c8fac7f
commit
58d4dde223
26
src/Netrc.cc
26
src/Netrc.cc
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
void Netrc::parse(const string& path)
|
void Netrc::parse(const string& path)
|
||||||
{
|
{
|
||||||
authenticatables.clear();
|
authenticators.clear();
|
||||||
ifstream f(path.c_str());
|
ifstream f(path.c_str());
|
||||||
|
|
||||||
if(!f) {
|
if(!f) {
|
||||||
|
@ -56,11 +56,11 @@ void Netrc::parse(const string& path)
|
||||||
}
|
}
|
||||||
pair<string, string> nameValuePair = Util::split(line, "\r\n\t ");
|
pair<string, string> nameValuePair = Util::split(line, "\r\n\t ");
|
||||||
if(nameValuePair.first == "machine") {
|
if(nameValuePair.first == "machine") {
|
||||||
storeAuthenticatable(authenticator);
|
storeAuthenticator(authenticator);
|
||||||
authenticator = new Authenticator();
|
authenticator = new Authenticator();
|
||||||
authenticator->setMachine(nameValuePair.second);
|
authenticator->setMachine(nameValuePair.second);
|
||||||
} else if(nameValuePair.first == "default") {
|
} else if(nameValuePair.first == "default") {
|
||||||
storeAuthenticatable(authenticator);
|
storeAuthenticator(authenticator);
|
||||||
authenticator = new DefaultAuthenticator();
|
authenticator = new DefaultAuthenticator();
|
||||||
} else {
|
} else {
|
||||||
if(authenticator.isNull()) {
|
if(authenticator.isNull()) {
|
||||||
|
@ -75,13 +75,13 @@ void Netrc::parse(const string& path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
storeAuthenticatable(authenticator);
|
storeAuthenticator(authenticator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Netrc::storeAuthenticatable(const AuthenticatableHandle& authenticatable)
|
void Netrc::storeAuthenticator(const AuthenticatorHandle& authenticator)
|
||||||
{
|
{
|
||||||
if(!authenticatable.isNull()) {
|
if(!authenticator.isNull()) {
|
||||||
authenticatables.push_back(authenticatable);
|
authenticators.push_back(authenticator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,18 +91,18 @@ private:
|
||||||
public:
|
public:
|
||||||
AuthHostMatch(const string& hostname):hostname(hostname) {}
|
AuthHostMatch(const string& hostname):hostname(hostname) {}
|
||||||
|
|
||||||
bool operator()(const AuthenticatableHandle& authenticatable)
|
bool operator()(const AuthenticatorHandle& authenticator)
|
||||||
{
|
{
|
||||||
return authenticatable->match(hostname);
|
return authenticator->match(hostname);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
AuthenticatableHandle Netrc::findAuthenticatable(const string& hostname) const
|
AuthenticatorHandle Netrc::findAuthenticator(const string& hostname) const
|
||||||
{
|
{
|
||||||
Authenticatables::const_iterator itr =
|
Authenticators::const_iterator itr =
|
||||||
find_if(authenticatables.begin(), authenticatables.end(),
|
find_if(authenticators.begin(), authenticators.end(),
|
||||||
AuthHostMatch(hostname));
|
AuthHostMatch(hostname));
|
||||||
if(itr == authenticatables.end()) {
|
if(itr == authenticators.end()) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return *itr;
|
return *itr;
|
||||||
|
|
17
src/Netrc.h
17
src/Netrc.h
|
@ -45,7 +45,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<Authenticatable> AuthenticatableHandle;
|
typedef SharedHandle<Authenticatable> AuthenticatableHandle;
|
||||||
typedef deque<AuthenticatableHandle> Authenticatables;
|
|
||||||
|
|
||||||
class Authenticator : public Authenticatable {
|
class Authenticator : public Authenticatable {
|
||||||
private:
|
private:
|
||||||
|
@ -102,6 +101,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<Authenticator> AuthenticatorHandle;
|
typedef SharedHandle<Authenticator> AuthenticatorHandle;
|
||||||
|
typedef deque<AuthenticatorHandle> Authenticators;
|
||||||
|
|
||||||
class DefaultAuthenticator : public Authenticator {
|
class DefaultAuthenticator : public Authenticator {
|
||||||
public:
|
public:
|
||||||
|
@ -124,27 +124,28 @@ typedef SharedHandle<DefaultAuthenticator> DefaultAuthenticatorHandle;
|
||||||
|
|
||||||
class Netrc {
|
class Netrc {
|
||||||
private:
|
private:
|
||||||
Authenticatables authenticatables;
|
Authenticators authenticators;
|
||||||
|
|
||||||
void storeAuthenticatable(const AuthenticatableHandle& authenticatable);
|
void storeAuthenticator(const AuthenticatorHandle& authenticator);
|
||||||
public:
|
public:
|
||||||
Netrc() {}
|
Netrc() {}
|
||||||
|
|
||||||
void parse(const string& path);
|
void parse(const string& path);
|
||||||
|
|
||||||
AuthenticatableHandle findAuthenticatable(const string& hostname) const;
|
AuthenticatorHandle findAuthenticator(const string& hostname) const;
|
||||||
|
|
||||||
const Authenticatables& getAuthenticatables() const
|
const Authenticators& getAuthenticators() const
|
||||||
{
|
{
|
||||||
return authenticatables;
|
return authenticators;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addAuthenticatable(const AuthenticatableHandle& authenticatable)
|
void addAuthenticator(const AuthenticatorHandle& authenticator)
|
||||||
{
|
{
|
||||||
authenticatables.push_back(authenticatable);
|
authenticators.push_back(authenticator);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<Netrc> NetrcHandle;
|
typedef SharedHandle<Netrc> NetrcHandle;
|
||||||
|
typedef SingletonHolder<NetrcHandle> NetrcSingletonHolder;
|
||||||
|
|
||||||
#endif // _D_NETRC_H_
|
#endif // _D_NETRC_H_
|
||||||
|
|
Loading…
Reference in New Issue