Commit a806a741 authored by François Grisez's avatar François Grisez

Cosmetic rewriting of SociAuthDB

* usage of std::unique_ptr<>
* usage of override specifier
* remove one unused and unimplemented method
* other cosmetic changes
parent 0d40c05e
......@@ -101,8 +101,7 @@ void SociAuthDB::declareConfig(GenericStruct *mc) {
mc->addChildrenValues(items);
}
SociAuthDB::SociAuthDB() : conn_pool(NULL) {
SociAuthDB::SociAuthDB() {
GenericStruct *cr = GenericManager::get()->getRoot();
GenericStruct *ma = cr->get<GenericStruct>("module::Authentication");
GenericStruct *mp = cr->get<GenericStruct>("module::Presence");
......@@ -117,27 +116,22 @@ SociAuthDB::SociAuthDB() : conn_pool(NULL) {
hashed_passwd = ma->get<ConfigBoolean>("hashed-passwords")->read();
check_domain_in_presence_results = mp->get<ConfigBoolean>("check-domain-in-presence-results")->read();
conn_pool = new connection_pool(poolSize);
thread_pool = new ThreadPool(poolSize, max_queue_size);
conn_pool.reset(new connection_pool(poolSize));
thread_pool.reset(new ThreadPool(poolSize, max_queue_size));
LOGD("[SOCI] Authentication provider for backend %s created. Pooled for %d connections", backend.c_str(), (int)poolSize);
LOGD("[SOCI] Authentication provider for backend %s created. Pooled for %zu connections", backend.c_str(), poolSize);
try {
for (size_t i = 0; i < poolSize; i++) {
conn_pool->at(i).open(backend, connection_string);
}
} catch (soci::mysql_soci_error const & e) {
} catch (const soci::mysql_soci_error &e) {
SLOGE << "[SOCI] connection pool open MySQL error: " << e.err_num_ << " " << e.what() << endl;
} catch (exception const &e) {
SLOGE << "[SOCI] connection pool open error: " << e.what() << endl;
}
}
SociAuthDB::~SociAuthDB() {
delete thread_pool; // will automatically shut it down, clearing threads
delete conn_pool;
}
void SociAuthDB::getPasswordWithPool(const string &id, const string &domain,
const string &authid, AuthDbListener *listener, AuthDbListener *listener_ref) {
vector<passwd_algo_t> passwd;
......
......@@ -292,19 +292,17 @@ public:
namespace flexisip {
class SociAuthDB : public AuthDbBackend {
virtual ~SociAuthDB();
public:
SociAuthDB();
void setConnectionParameters(const std::string &domain, const std::string &request);
virtual void getUserWithPhoneFromBackend(const std::string & , const std::string &, AuthDbListener *listener);
virtual void getUsersWithPhonesFromBackend(std::list<std::tuple<std::string,std::string,AuthDbListener*>> &creds);
virtual void getPasswordFromBackend(const std::string &id, const std::string &domain,
const std::string &authid, AuthDbListener *listener, AuthDbListener *listener_ref);
void getUserWithPhoneFromBackend(const std::string & , const std::string &, AuthDbListener *listener) override;
void getUsersWithPhonesFromBackend(std::list<std::tuple<std::string,std::string,AuthDbListener*>> &creds) override;
void getPasswordFromBackend(const std::string &id, const std::string &domain,
const std::string &authid, AuthDbListener *listener, AuthDbListener *listener_ref) override;
static void declareConfig(GenericStruct *mc);
private:
SociAuthDB();
void getUserWithPhoneWithPool(const std::string &phone, const std::string &domain, AuthDbListener *listener);
void getUsersWithPhonesWithPool(std::list<std::tuple<std::string,std::string,AuthDbListener*>> &creds);
void getPasswordWithPool(const std::string &id, const std::string &domain,
......@@ -313,9 +311,9 @@ private:
void notifyAllListeners(std::list<std::tuple<std::string, std::string, AuthDbListener *>> &creds, const std::set<std::pair<std::string, std::string>> &presences);
size_t poolSize;
soci::connection_pool *conn_pool;
ThreadPool *thread_pool;
std::size_t poolSize;
std::unique_ptr<soci::connection_pool> conn_pool;
std::unique_ptr<ThreadPool> thread_pool;
std::string connection_string;
std::string backend;
std::string get_password_request;
......@@ -324,6 +322,8 @@ private:
std::string get_password_algo_request;
bool check_domain_in_presence_results = false;
bool hashed_passwd;
friend AuthDbBackend;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment