*
*/
+#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/locker.h"
+#include "../../../stg_timer.h"
+
#include <string>
#include <vector>
#include <sstream>
#include <libpq-fe.h>
-#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<std::string> * usersList) const
{
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);
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
}
//-----------------------------------------------------------------------------
-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);
PQclear(result);
-if (SaveUserServices(uid, conf.service))
+if (SaveUserServices(uid, conf.services))
{
printfd(__FILE__, "POSTGRESQL_STORE::SaveUserConf(): 'Failed to save user's services'\n");
if (RollbackTransaction())
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::RestoreUserStat(USER_STAT * stat,
+int POSTGRESQL_STORE::RestoreUserStat(STG::UserStat * stat,
const std::string & login) const
{
STG_LOCKER lock(&mutex);
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::RestoreUserConf(USER_CONF * conf,
+int POSTGRESQL_STORE::RestoreUserConf(STG::UserConf * conf,
const std::string & login) const
{
STG_LOCKER lock(&mutex);
for (int i = 0; i < tuples; ++i)
{
- conf->service.push_back(PQgetvalue(result, i, 0));
+ conf->services.push_back(PQgetvalue(result, i, 0));
}
PQclear(result);
tuples = PQntuples(result);
-conf->ips.Erase();
+STG::UserIPs ips;
for (int i = 0; i < tuples; ++i)
{
- IP_MASK ipm;
-
- int ip, mask;
+ STG::IPMask im;
- ip = inet_strington(PQgetvalue(result, i, 0));
+ im.ip = inet_strington(PQgetvalue(result, i, 0));
- if (str2x(PQgetvalue(result, i, 1), mask))
+ if (str2x(PQgetvalue(result, i, 1), im.mask))
{
printfd(__FILE__, "POSTGRESQL_STORE::RestoreUserConf(): 'Failed to fetch mask'\n");
continue;
}
- ipm.ip = ip;
- ipm.mask = mask;
-
- conf->ips.Add(ipm);
+ ips.add(im);
}
+conf->ips = ips;
PQclear(result);
//-----------------------------------------------------------------------------
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
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::WriteDetailedStat(const std::map<IP_DIR_PAIR, STAT_NODE> & statTree,
+int POSTGRESQL_STORE::WriteDetailedStat(const STG::TraffStat & statTree,
time_t lastStat,
const std::string & login) const
{
return -1;
}
-std::map<IP_DIR_PAIR, STAT_NODE>::const_iterator it;
+STG::TraffStat::const_iterator it;
time_t currTime = time(NULL);
for (it = statTree.begin(); it != statTree.end(); ++it)
}
//-----------------------------------------------------------------------------
-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);
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::SaveUserIPs(uint32_t uid,
- const USER_IPS & ips) const
+ const STG::UserIPs & ips) const
{
PGresult * result;
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 "