#define _GNU_SOURCE
#endif
-#include <pwd.h>
-#include <grp.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include <fcntl.h>
-#include <dirent.h>
-
-#include <cstdio>
-#include <ctime>
-#include <cerrno>
-#include <cstring>
-#include <sstream>
-#include <algorithm>
+#include "file_store.h"
#include "stg/common.h"
#include "stg/user_ips.h"
#include "stg/blowfish.h"
#include "stg/logger.h"
#include "stg/locker.h"
-#include "stg/plugin_creator.h"
-#include "file_store.h"
+#include "stg/admin_conf.h"
+#include "stg/tariff.h"
+#include "stg/tariff_conf.h"
+#include "stg/service_conf.h"
+
+#include <sstream>
+#include <algorithm>
+#include <cstdio>
+#include <ctime>
+#include <cerrno>
+#include <cstring>
+
+#include <pwd.h>
+#include <grp.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <fcntl.h>
+#include <dirent.h>
#define DELETED_USERS_DIR "deleted_users"
//-----------------------------------------------------------------------------
namespace
{
-PLUGIN_CREATOR<FILES_STORE> fsc;
bool CheckAndCreate(const std::string & dir, mode_t mode)
{
}
-extern "C" STORE * GetStore();
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-STORE * GetStore()
+extern "C" STG::Store* GetStore()
{
-return fsc.GetPlugin();
+ static FILES_STORE plugin;
+ return &plugin;
}
//-----------------------------------------------------------------------------
FILES_STORE_SETTINGS::FILES_STORE_SETTINGS()
{
}
//-----------------------------------------------------------------------------
-int FILES_STORE_SETTINGS::ParseOwner(const std::vector<PARAM_VALUE> & moduleParams, const std::string & owner, uid_t * uid)
+int FILES_STORE_SETTINGS::ParseOwner(const std::vector<STG::ParamValue> & moduleParams, const std::string & owner, uid_t * uid)
{
-PARAM_VALUE pv;
+STG::ParamValue pv;
pv.param = owner;
-std::vector<PARAM_VALUE>::const_iterator pvi;
+std::vector<STG::ParamValue>::const_iterator pvi;
pvi = find(moduleParams.begin(), moduleParams.end(), pv);
if (pvi == moduleParams.end() || pvi->value.empty())
{
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE_SETTINGS::ParseGroup(const std::vector<PARAM_VALUE> & moduleParams, const std::string & group, gid_t * gid)
+int FILES_STORE_SETTINGS::ParseGroup(const std::vector<STG::ParamValue> & moduleParams, const std::string & group, gid_t * gid)
{
-PARAM_VALUE pv;
+STG::ParamValue pv;
pv.param = group;
-std::vector<PARAM_VALUE>::const_iterator pvi;
+std::vector<STG::ParamValue>::const_iterator pvi;
pvi = find(moduleParams.begin(), moduleParams.end(), pv);
if (pvi == moduleParams.end() || pvi->value.empty())
{
return -1;
}
//-----------------------------------------------------------------------------
-int FILES_STORE_SETTINGS::ParseMode(const std::vector<PARAM_VALUE> & moduleParams, const std::string & modeStr, mode_t * mode)
+int FILES_STORE_SETTINGS::ParseMode(const std::vector<STG::ParamValue> & moduleParams, const std::string & modeStr, mode_t * mode)
{
-PARAM_VALUE pv;
+STG::ParamValue pv;
pv.param = modeStr;
-std::vector<PARAM_VALUE>::const_iterator pvi;
+std::vector<STG::ParamValue>::const_iterator pvi;
pvi = find(moduleParams.begin(), moduleParams.end(), pv);
if (pvi == moduleParams.end() || pvi->value.empty())
{
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
+int FILES_STORE_SETTINGS::ParseSettings(const STG::ModuleSettings & s)
{
if (ParseOwner(s.moduleParams, "StatOwner", &statUID) < 0)
return -1;
if (ParseMode(s.moduleParams, "UserLogMode", &userLogMode) < 0)
return -1;
-std::vector<PARAM_VALUE>::const_iterator pvi;
-PARAM_VALUE pv;
+std::vector<STG::ParamValue>::const_iterator pvi;
+STG::ParamValue pv;
pv.param = "RemoveBak";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end() || pvi->value.empty())
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
FILES_STORE::FILES_STORE()
- : errorStr(),
- version("file_store v.1.04"),
- storeSettings(),
- settings(),
- mutex(),
- logger(GetPluginLogger(GetStgLogger(), "store_files"))
+ : version("file_store v.1.04"),
+ logger(STG::PluginLogger::get("store_files"))
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::RestoreUserConf(USER_CONF * conf, const std::string & login) const
+int FILES_STORE::RestoreUserConf(STG::UserConf * conf, const std::string & login) const
{
std::string fileName;
fileName = storeSettings.GetUsersDir() + "/" + login + "/conf";
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::RestoreUserConf(USER_CONF * conf, const std::string & login, const std::string & fileName) const
+int FILES_STORE::RestoreUserConf(STG::UserConf * conf, const std::string & login, const std::string & fileName) const
{
CONFIGFILE cf(fileName);
int e = cf.Error();
std::string ipStr;
cf.ReadString("IP", &ipStr, "?");
-USER_IPS ips;
try
{
- ips = StrToIPS(ipStr);
+ conf->ips = STG::UserIPs::parse(ipStr);
}
catch (const std::string & s)
{
printfd(__FILE__, "FILES_STORE::RestoreUserConf - ip read failed for user '%s'\n", login.c_str());
return -1;
}
-conf->ips = ips;
if (cf.ReadInt("alwaysOnline", &conf->alwaysOnline, 0) != 0)
{
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::RestoreUserStat(USER_STAT * stat, const std::string & login) const
+int FILES_STORE::RestoreUserStat(STG::UserStat * stat, const std::string & login) const
{
std::string fileName;
fileName = storeSettings.GetUsersDir() + "/" + login + "/stat";
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::RestoreUserStat(USER_STAT * stat, const std::string & login, const std::string & fileName) const
+int FILES_STORE::RestoreUserStat(STG::UserStat * stat, const std::string & login, const std::string & fileName) const
{
CONFIGFILE cf(fileName);
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::SaveUserConf(const USER_CONF & conf, const std::string & login) const
+int FILES_STORE::SaveUserConf(const STG::UserConf & conf, const std::string & login) const
{
std::string fileName;
fileName = storeSettings.GetUsersDir() + "/" + login + "/conf";
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::SaveUserStat(const USER_STAT & stat, const std::string & login) const
+int FILES_STORE::SaveUserStat(const STG::UserStat & stat, const std::string & login) const
{
std::string fileName;
fileName = storeSettings.GetUsersDir() + "/" + login + "/stat";
}
//-----------------------------------------------------------------------------
int FILES_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
return WriteLog2String(logStr.str(), login);
}
//-----------------------------------------------------------------------------
-int FILES_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const
+int FILES_STORE::SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const
{
// Classic stats
std::string stat1;
return 0;
}
//-----------------------------------------------------------------------------*/
-int FILES_STORE::SaveAdmin(const ADMIN_CONF & ac) const
+int FILES_STORE::SaveAdmin(const STG::AdminConf & ac) const
{
std::string fileName;
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const
+int FILES_STORE::RestoreAdmin(STG::AdminConf * ac, const std::string & login) const
{
std::string fileName;
strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), login.c_str());
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const
+int FILES_STORE::RestoreTariff(STG::TariffData * td, const std::string & tariffName) const
{
std::string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf";
CONFIGFILE conf(fileName);
return -1;
}
-td->tariffConf.traffType = TARIFF::StringToTraffType(str);
+td->tariffConf.traffType = STG::Tariff::parseTraffType(str);
if (conf.ReadString("Period", &str, "month") < 0)
- td->tariffConf.period = TARIFF::MONTH;
+ td->tariffConf.period = STG::Tariff::MONTH;
else
- td->tariffConf.period = TARIFF::StringToPeriod(str);
+ td->tariffConf.period = STG::Tariff::parsePeriod(str);
if (conf.ReadString("ChangePolicy", &str, "allow") < 0)
- td->tariffConf.changePolicy = TARIFF::ALLOW;
+ td->tariffConf.changePolicy = STG::Tariff::ALLOW;
else
- td->tariffConf.changePolicy = TARIFF::StringToChangePolicy(str);
+ td->tariffConf.changePolicy = STG::Tariff::parseChangePolicy(str);
conf.ReadTime("ChangePolicyTimeout", &td->tariffConf.changePolicyTimeout, 0);
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const
+int FILES_STORE::SaveTariff(const STG::TariffData & td, const std::string & tariffName) const
{
std::string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf";
cf.WriteDouble("PassiveCost", td.tariffConf.passiveCost);
cf.WriteDouble("Fee", td.tariffConf.fee);
cf.WriteDouble("Free", td.tariffConf.free);
- cf.WriteString("TraffType", TARIFF::TraffTypeToString(td.tariffConf.traffType));
- cf.WriteString("Period", TARIFF::PeriodToString(td.tariffConf.period));
- cf.WriteString("ChangePolicy", TARIFF::ChangePolicyToString(td.tariffConf.changePolicy));
+ cf.WriteString("TraffType", STG::Tariff::toString(td.tariffConf.traffType));
+ cf.WriteString("Period", STG::Tariff::toString(td.tariffConf.period));
+ cf.WriteString("ChangePolicy", STG::Tariff::toString(td.tariffConf.changePolicy));
cf.WriteTime("ChangePolicyTimeout", td.tariffConf.changePolicyTimeout);
}
return 0;
}
//-----------------------------------------------------------------------------*/
-int FILES_STORE::SaveService(const SERVICE_CONF & conf) const
+int FILES_STORE::SaveService(const STG::ServiceConf & conf) const
{
std::string fileName;
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::RestoreService(SERVICE_CONF * conf, const std::string & name) const
+int FILES_STORE::RestoreService(STG::ServiceConf * conf, const std::string & name) const
{
std::string fileName;
strprintf(&fileName, "%s/%s.serv", storeSettings.GetServicesDir().c_str(), name.c_str());
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::WriteDetailedStat(const std::map<IP_DIR_PAIR, STAT_NODE> & statTree,
+int FILES_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 stIter;
-stIter = statTree.begin();
+auto stIter = statTree.begin();
while (stIter != statTree.end())
{
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::AddMessage(STG_MSG * msg, const std::string & login) const
+int FILES_STORE::AddMessage(STG::Message * msg, const std::string & login) const
{
std::string fn;
std::string dn;
return EditMessage(*msg, login);
}
//-----------------------------------------------------------------------------
-int FILES_STORE::EditMessage(const STG_MSG & msg, const std::string & login) const
+int FILES_STORE::EditMessage(const STG::Message & msg, const std::string & login) const
{
std::string fileName;
return 0;
}
//-----------------------------------------------------------------------------
-int FILES_STORE::GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const
+int FILES_STORE::GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const
{
std::string fn;
strprintf(&fn, "%s/%s/messages/%lld", storeSettings.GetUsersDir().c_str(), login.c_str(), id);
return unlink(fn.c_str());
}
//-----------------------------------------------------------------------------
-int FILES_STORE::GetMessageHdrs(std::vector<STG_MSG_HDR> * hdrsList, const std::string & login) const
+int FILES_STORE::GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const
{
std::string dn(storeSettings.GetUsersDir() + "/" + login + "/messages/");
continue;
}
- STG_MSG_HDR hdr;
+ STG::Message::Header hdr;
if (ReadMessage(dn + messages[i], &hdr, NULL))
{
return -1;
}
//-----------------------------------------------------------------------------
int FILES_STORE::ReadMessage(const std::string & fileName,
- STG_MSG_HDR * hdr,
+ STG::Message::Header * hdr,
std::string * text) const
{
FILE * msgFile;