X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/fca86b001448a88f8cb55ead2320e2280997eada..a42349b9f8b4cbdcc6ad763ccf509f84fbaaf39d:/projects/stargazer/plugins/store/files/file_store.h diff --git a/projects/stargazer/plugins/store/files/file_store.h b/projects/stargazer/plugins/store/files/file_store.h index cb3abdb3..8bc2ab37 100644 --- a/projects/stargazer/plugins/store/files/file_store.h +++ b/projects/stargazer/plugins/store/files/file_store.h @@ -18,74 +18,70 @@ * Author : Boris Mikhailenko */ -/* - $Revision: 1.22 $ - $Date: 2010/01/19 11:06:53 $ - $Author: faust $ - */ +#pragma once - -#ifndef FILE_STORE_H -#define FILE_STORE_H +#include "stg/module_settings.h" +#include "stg/store.h" +#include "stg/conffiles.h" +#include "stg/user_traff.h" +#include "stg/logger.h" #include -#include -#include "base_settings.h" -#include "base_store.h" -#include "conffiles.h" -#include "user_traff.h" +#include +#include -using namespace std; -//----------------------------------------------------------------------------- -extern "C" BASE_STORE * GetStore(); //----------------------------------------------------------------------------- -class FILES_STORE_SETTINGS//: public BASE_SETTINGS -{ +class FILES_STORE_SETTINGS { public: FILES_STORE_SETTINGS(); - virtual ~FILES_STORE_SETTINGS(); - virtual int ParseSettings(const MODULE_SETTINGS & s); - virtual const string & GetStrError() const; + int ParseSettings(const STG::ModuleSettings & s); + const std::string & GetStrError() const; - string GetWorkDir() const; - string GetUsersDir() const; - string GetAdminsDir() const; - string GetTariffsDir() const; + std::string GetWorkDir() const { return workDir; } + std::string GetUsersDir() const { return usersDir; } + std::string GetAdminsDir() const { return adminsDir; } + std::string GetTariffsDir() const { return tariffsDir; } + std::string GetServicesDir() const { return servicesDir; } - mode_t GetStatMode() const; + mode_t GetStatMode() const { return statMode; } mode_t GetStatModeDir() const; - uid_t GetStatUID() const; - gid_t GetStatGID() const; + uid_t GetStatUID() const { return statUID; } + gid_t GetStatGID() const { return statGID; } - mode_t GetConfMode() const; + mode_t GetConfMode() const { return confMode; } mode_t GetConfModeDir() const; - uid_t GetConfUID() const; - gid_t GetConfGID() const; + uid_t GetConfUID() const { return confUID; } + gid_t GetConfGID() const { return confGID; } - mode_t GetLogMode() const; - uid_t GetLogUID() const; - gid_t GetLogGID() const; + mode_t GetLogMode() const { return userLogMode; } + uid_t GetLogUID() const { return userLogUID; } + gid_t GetLogGID() const { return userLogGID; } - bool GetRemoveBak() const; - bool GetReadBak() const; + bool GetRemoveBak() const { return removeBak; } + bool GetReadBak() const { return readBak; } private: - const MODULE_SETTINGS * settings; + FILES_STORE_SETTINGS(const FILES_STORE_SETTINGS & rvalue); + FILES_STORE_SETTINGS & operator=(const FILES_STORE_SETTINGS & rvalue); + + const STG::ModuleSettings * settings; int User2UID(const char * user, uid_t * uid); int Group2GID(const char * gr, gid_t * gid); int Str2Mode(const char * str, mode_t * mode); - int ParseOwner(const vector & moduleParams, const string & owner, uid_t * uid); - int ParseGroup(const vector & moduleParams, const string & group, uid_t * uid); - int ParseMode(const vector & moduleParams, const string & modeStr, mode_t * mode); - int ParseYesNo(const string & value, bool * val); - string errorStr; + int ParseOwner(const std::vector & moduleParams, const std::string & owner, uid_t * uid); + int ParseGroup(const std::vector & moduleParams, const std::string & group, uid_t * uid); + int ParseMode(const std::vector & moduleParams, const std::string & modeStr, mode_t * mode); + int ParseYesNo(const std::string & value, bool * val); + + std::string errorStr; - string workDir; - string usersDir; - string adminsDir; - string tariffsDir; + std::string workDir; + std::string usersDir; + std::string adminsDir; + std::string tariffsDir; + std::string servicesDir; mode_t statMode; uid_t statUID; @@ -103,102 +99,103 @@ private: bool readBak; }; //----------------------------------------------------------------------------- -class FILES_STORE: public BASE_STORE -{ +class FILES_STORE: public STG::Store { public: FILES_STORE(); - virtual ~FILES_STORE(); - virtual const string & GetStrError() const; + const std::string & GetStrError() const override { return errorStr; } //User - virtual int GetUsersList(vector * usersList) const; - virtual int AddUser(const string & login) const; - virtual int DelUser(const string & login) const; - virtual int SaveUserStat(const USER_STAT & stat, const string & login) const; - virtual int SaveUserConf(const USER_CONF & conf, const string & login) const; - - virtual int RestoreUserStat(USER_STAT * stat, const string & login) const; - virtual int RestoreUserConf(USER_CONF * conf, const string & login) const; - - virtual int WriteUserChgLog(const string & login, - const string & admLogin, - uint32_t admIP, - const string & paramName, - const string & oldValue, - const string & newValue, - const string & message = "") const; - virtual int WriteUserConnect(const string & login, uint32_t ip) const; - virtual int WriteUserDisconnect(const string & login, - const DIR_TRAFF & up, - const DIR_TRAFF & down, - const DIR_TRAFF & sessionUp, - const DIR_TRAFF & sessionDown, - double cash, - double freeMb, - const std::string & reason) const; - - virtual int WriteDetailedStat(const map & statTree, - time_t lastStat, - const string & login) const; - - virtual int AddMessage(STG_MSG * msg, const string & login) const; - virtual int EditMessage(const STG_MSG & msg, const string & login) const; - virtual int GetMessage(uint64_t id, STG_MSG * msg, const string & login) const; - virtual int DelMessage(uint64_t id, const string & login) const; - virtual int GetMessageHdrs(vector * hdrsList, const string & login) const; - virtual int ReadMessage(const string & fileName, - STG_MSG_HDR * hdr, - string * text) const; - - virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const string & login) const; + int GetUsersList(std::vector * usersList) const override; + int AddUser(const std::string & login) const override; + int DelUser(const std::string & login) const override; + int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override; + int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override; + + int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override; + int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override; + + int WriteUserChgLog(const std::string & login, + const std::string & admLogin, + uint32_t admIP, + const std::string & paramName, + const std::string & oldValue, + const std::string & newValue, + const std::string & message = "") const override; + int WriteUserConnect(const std::string & login, uint32_t ip) const override; + int WriteUserDisconnect(const std::string & login, + const STG::DirTraff & up, + const STG::DirTraff & down, + const STG::DirTraff & sessionUp, + const STG::DirTraff & sessionDown, + double cash, + double freeMb, + const std::string & reason) const override; + + int WriteDetailedStat(const STG::TraffStat & statTree, + time_t lastStat, + const std::string & login) const override; + + int AddMessage(STG::Message * msg, const std::string & login) const override; + int EditMessage(const STG::Message & msg, const std::string & login) const override; + int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override; + int DelMessage(uint64_t id, const std::string & login) const override; + int GetMessageHdrs(std::vector * hdrsList, const std::string & login) const override; + + int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override; //Admin - virtual int GetAdminsList(vector * adminsList) const; - virtual int AddAdmin(const string & login) const; - virtual int DelAdmin(const string & login) const; - virtual int RestoreAdmin(ADMIN_CONF * ac, const string & login) const; - virtual int SaveAdmin(const ADMIN_CONF & ac) const; + int GetAdminsList(std::vector * adminsList) const override; + int AddAdmin(const std::string & login) const override; + int DelAdmin(const std::string & login) const override; + int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override; + int SaveAdmin(const STG::AdminConf & ac) const override; //Tariff - virtual int GetTariffsList(vector * tariffsList) const; - virtual int AddTariff(const string & name) const; - virtual int DelTariff(const string & name) const; - virtual int SaveTariff(const TARIFF_DATA & td, const string & tariffName) const; - virtual int RestoreTariff(TARIFF_DATA * td, const string & tariffName) const; + int GetTariffsList(std::vector * tariffsList) const override; + int AddTariff(const std::string & name) const override; + int DelTariff(const std::string & name) const override; + int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override; + int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override; //Corparation - virtual int GetCorpsList(vector *) const {return 0;}; - virtual int SaveCorp(const CORP_CONF &) const {return 0;}; - virtual int RestoreCorp(CORP_CONF *, const string &) const {return 0;}; - virtual int AddCorp(const string &) const {return 0;}; - virtual int DelCorp(const string &) const {return 0;}; + int GetCorpsList(std::vector *) const override { return 0; } + int SaveCorp(const STG::CorpConf &) const override { return 0; } + int RestoreCorp(STG::CorpConf *, const std::string &) const override { return 0; } + int AddCorp(const std::string &) const override { return 0; } + int DelCorp(const std::string &) const override { return 0; } // Services - virtual int GetServicesList(vector *) const {return 0;}; - virtual int SaveService(const SERVICE_CONF &) const {return 0;}; - virtual int RestoreService(SERVICE_CONF *, const string &) const {return 0;}; - virtual int AddService(const string &) const {return 0;}; - virtual int DelService(const string &) const {return 0;}; + int GetServicesList(std::vector *) const override; + int SaveService(const STG::ServiceConf &) const override; + int RestoreService(STG::ServiceConf *, const std::string &) const override; + int AddService(const std::string &) const override; + int DelService(const std::string &) const override; - //virtual BASE_SETTINGS * GetStoreSettings(); - virtual void SetSettings(const MODULE_SETTINGS & s); - virtual int ParseSettings(); - virtual const string & GetVersion() const; + void SetSettings(const STG::ModuleSettings & s) override { settings = s; } + int ParseSettings() override; + const std::string & GetVersion() const override { return version; } private: - virtual int RestoreUserStat(USER_STAT * stat, const string & login, const string & fileName) const; - virtual int RestoreUserConf(USER_CONF * conf, const string & login, const string & fileName) const; - - virtual int WriteLogString(const string & str, const string & login) const; - virtual int WriteLog2String(const string & str, const string & login) const; - int RemoveDir(const char * path) const; - int GetFilesList(vector * filesList, const string & directory, mode_t mode, const string & ext) const; - mutable string errorStr; - string version; - FILES_STORE_SETTINGS storeSettings; - MODULE_SETTINGS settings; + FILES_STORE(const FILES_STORE & rvalue); + FILES_STORE & operator=(const FILES_STORE & rvalue); + + int ReadMessage(const std::string & fileName, + STG::Message::Header * hdr, + std::string * text) const; + + virtual int RestoreUserStat(STG::UserStat * stat, const std::string & login, const std::string & fileName) const; + virtual int RestoreUserConf(STG::UserConf * conf, const std::string & login, const std::string & fileName) const; + + virtual int WriteLogString(const std::string & str, const std::string & login) const; + virtual int WriteLog2String(const std::string & str, const std::string & login) const; + int RemoveDir(const char * path) const; + int Touch(const std::string & path) const; + + mutable std::string errorStr; + std::string version; + FILES_STORE_SETTINGS storeSettings; + STG::ModuleSettings settings; mutable pthread_mutex_t mutex; -}; -//----------------------------------------------------------------------------- -#endif //FILE_STORE_H + STG::PluginLogger logger; +};