Rewrite AuthConfig objects using std::unique_ptr

This commit is contained in:
Tatsuhiro Tsujikawa
2013-06-26 21:45:29 +09:00
parent a4cf50914d
commit d485c8e767
18 changed files with 342 additions and 345 deletions

View File

@@ -52,42 +52,39 @@ class AuthConfig;
class Request;
class AuthResolver;
class AuthConfigFactory {
private:
std::shared_ptr<Netrc> netrc_;
std::shared_ptr<AuthConfig> createAuthConfig(const std::string& user,
const std::string& password) const;
std::shared_ptr<AuthResolver> createHttpAuthResolver(const Option* op) const;
std::shared_ptr<AuthResolver> createFtpAuthResolver(const Option* op) const;
class BasicCred {
public:
class BasicCred {
public:
std::string user_;
std::string password_;
std::string host_;
uint16_t port_;
std::string path_;
bool activated_;
std::string user_;
std::string password_;
std::string host_;
uint16_t port_;
std::string path_;
bool activated_;
BasicCred(const std::string& user, const std::string& password,
const std::string& host, uint16_t port, const std::string& path,
bool activated = false);
BasicCred(std::string user, std::string password,
std::string host, uint16_t port, std::string path,
bool activated = false);
void activate();
void activate();
bool isActivated() const;
bool isActivated() const;
bool operator==(const BasicCred& cred) const;
bool operator==(const BasicCred& cred) const;
bool operator<(const BasicCred& cred) const;
};
bool operator<(const BasicCred& cred) const;
};
typedef std::set<std::shared_ptr<BasicCred>,
DerefLess<std::shared_ptr<BasicCred> > > BasicCredSet;
class AuthConfigFactory {
public:
typedef std::set<std::unique_ptr<BasicCred>,
DerefLess<std::unique_ptr<BasicCred>>> BasicCredSet;
private:
std::unique_ptr<Netrc> netrc_;
std::unique_ptr<AuthResolver> createHttpAuthResolver(const Option* op) const;
std::unique_ptr<AuthResolver> createFtpAuthResolver(const Option* op) const;
BasicCredSet basicCreds_;
public:
AuthConfigFactory();
@@ -98,10 +95,10 @@ public:
// are used in this method: PREF_HTTP_USER, PREF_HTTP_PASSWD,
// PREF_FTP_USER, PREF_FTP_PASSWD, PREF_NO_NETRC and
// PREF_HTTP_AUTH_CHALLENGE.
std::shared_ptr<AuthConfig> createAuthConfig
std::unique_ptr<AuthConfig> createAuthConfig
(const std::shared_ptr<Request>& request, const Option* op);
void setNetrc(const std::shared_ptr<Netrc>& netrc);
void setNetrc(std::unique_ptr<Netrc> netrc);
// Find a BasicCred using findBasicCred() and activate it then
// return true. If matching BasicCred is not found, AuthConfig
@@ -127,7 +124,9 @@ public:
// If the same BasicCred is already added, then it is replaced with
// given basicCred. Otherwise, insert given basicCred to
// basicCreds_.
void updateBasicCred(const std::shared_ptr<BasicCred>& basicCred);
//
// Made public for unit test.
void updateBasicCred(std::unique_ptr<BasicCred> basicCred);
};
} // namespace aria2