X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/8c6fa3fbaccc22127280bf77a48fab5a3ee0716e..2196a3a0cdc5384c082febb7f4aa5994cc7d80db:/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp index b4c449fb..3e564337 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp @@ -26,6 +26,16 @@ * */ +#include "postgresql_store.h" + +#include "stg/user_conf.h" +#include "stg/user_stat.h" +#include "stg/user_ips.h" +#include "stg/user_traff.h" +#include "stg/common.h" +#include "stg/const.h" +#include "../../../stg_timer.h" + #include #include #include @@ -33,16 +43,10 @@ #include -#include "stg/common.h" -#include "stg/const.h" -#include "stg/locker.h" -#include "../../../stg_timer.h" -#include "postgresql_store.h" - //----------------------------------------------------------------------------- int POSTGRESQL_STORE::GetUsersList(std::vector * usersList) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -98,7 +102,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::AddUser(const std::string & name) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -162,7 +166,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::DelUser(const std::string & login) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -223,15 +227,15 @@ if (CommitTransaction()) return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::SaveUserStat(const USER_STAT & stat, +int POSTGRESQL_STORE::SaveUserStat(const STG::UserStat & stat, const std::string & login) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); return SaveStat(stat, login); } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::SaveStat(const USER_STAT & stat, +int POSTGRESQL_STORE::SaveStat(const STG::UserStat & stat, const std::string & login, int year, int month) const @@ -334,10 +338,10 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::SaveUserConf(const USER_CONF & conf, +int POSTGRESQL_STORE::SaveUserConf(const STG::UserConf & conf, const std::string & login) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -605,10 +609,10 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::RestoreUserStat(USER_STAT * stat, +int POSTGRESQL_STORE::RestoreUserStat(STG::UserStat * stat, const std::string & login) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -745,10 +749,10 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::RestoreUserConf(USER_CONF * conf, +int POSTGRESQL_STORE::RestoreUserConf(STG::UserConf * conf, const std::string & login) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -954,10 +958,10 @@ if (PQresultStatus(result) != PGRES_TUPLES_OK) tuples = PQntuples(result); -USER_IPS ips; +STG::UserIPs ips; for (int i = 0; i < tuples; ++i) { - IP_MASK im; + STG::IPMask im; im.ip = inet_strington(PQgetvalue(result, i, 0)); @@ -967,7 +971,7 @@ for (int i = 0; i < tuples; ++i) continue; } - ips.Add(im); + ips.add(im); } conf->ips = ips; @@ -991,7 +995,7 @@ int POSTGRESQL_STORE::WriteUserChgLog(const std::string & login, const std::string & newValue, const std::string & message = "") const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -1108,7 +1112,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::WriteUserConnect(const std::string & login, uint32_t ip) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -1186,15 +1190,15 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::WriteUserDisconnect(const std::string & login, - const DIR_TRAFF & monthUp, - const DIR_TRAFF & monthDown, - const DIR_TRAFF & sessionUp, - const DIR_TRAFF & sessionDown, + const STG::DirTraff & monthUp, + const STG::DirTraff & monthDown, + const STG::DirTraff & sessionUp, + const STG::DirTraff & sessionDown, double cash, double freeMb, const std::string & reason) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -1349,11 +1353,11 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::WriteDetailedStat(const std::map & statTree, +int POSTGRESQL_STORE::WriteDetailedStat(const STG::TraffStat & statTree, time_t lastStat, const std::string & login) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -1384,7 +1388,7 @@ if (EscapeString(elogin)) return -1; } -std::map::const_iterator it; +STG::TraffStat::const_iterator it; time_t currTime = time(NULL); for (it = statTree.begin(); it != statTree.end(); ++it) @@ -1430,9 +1434,9 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const +int POSTGRESQL_STORE::SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const { -STG_LOCKER lock(&mutex); +std::lock_guard lock(m_mutex); return SaveStat(stat, login, year, month); } @@ -1499,7 +1503,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::SaveUserIPs(uint32_t uid, - const USER_IPS & ips) const + const STG::UserIPs & ips) const { PGresult * result; @@ -1520,7 +1524,7 @@ if (PQresultStatus(result) != PGRES_COMMAND_OK) PQclear(result); -for (size_t i = 0; i < ips.Count(); ++i) +for (size_t i = 0; i < ips.count(); ++i) { std::ostringstream query; query << "INSERT INTO tb_allowed_ip "