2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
23 #include "stg/store.h"
24 #include "stg/locker.h"
25 #pragma GCC diagnostic push
26 #pragma GCC diagnostic ignored "-Wold-style-cast"
28 #pragma GCC diagnostic push
29 #include "stg/logger.h"
30 #include "stg/module_settings.h"
36 class FIREBIRD_STORE : public STG::Store
40 ~FIREBIRD_STORE() override;
42 int GetUsersList(std::vector<std::string> * usersList) const override;
43 int AddUser(const std::string & login) const override;
44 int DelUser(const std::string & login) const override;
45 int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
46 int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
47 int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
48 int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
49 int WriteUserChgLog(const std::string & login,
50 const std::string & admLogin,
52 const std::string & paramName,
53 const std::string & oldValue,
54 const std::string & newValue,
55 const std::string & message) const override;
56 int WriteUserConnect(const std::string & login, uint32_t ip) const override;
57 int WriteUserDisconnect(const std::string & login,
58 const STG::DirTraff & up,
59 const STG::DirTraff & down,
60 const STG::DirTraff & sessionUp,
61 const STG::DirTraff & sessionDown,
64 const std::string & reason) const override;
65 int WriteDetailedStat(const STG::TraffStat & statTree,
67 const std::string & login) const override;
69 int AddMessage(STG::Message * msg, const std::string & login) const override;
70 int EditMessage(const STG::Message & msg, const std::string & login) const override;
71 int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
72 int DelMessage(uint64_t id, const std::string & login) const override;
73 int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
75 int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
77 int GetAdminsList(std::vector<std::string> * adminsList) const override;
78 int SaveAdmin(const STG::AdminConf & ac) const override;
79 int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
80 int AddAdmin(const std::string & login) const override;
81 int DelAdmin(const std::string & login) const override;
83 int GetTariffsList(std::vector<std::string> * tariffsList) const override;
84 int AddTariff(const std::string & name) const override;
85 int DelTariff(const std::string & name) const override;
86 int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
87 int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
89 int GetCorpsList(std::vector<std::string> * corpsList) const override;
90 int SaveCorp(const STG::CorpConf & cc) const override;
91 int RestoreCorp(STG::CorpConf * cc, const std::string & name) const override;
92 int AddCorp(const std::string & name) const override;
93 int DelCorp(const std::string & name) const override;
95 inline void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
96 int ParseSettings() override;
98 inline const std::string & GetStrError() const override { return strError; }
100 inline const std::string & GetVersion() const override { return version; }
102 int GetServicesList(std::vector<std::string> * servicesList) const override;
103 int SaveService(const STG::ServiceConf & sc) const override;
104 int RestoreService(STG::ServiceConf * sc, const std::string & name) const override;
105 int AddService(const std::string & name) const override;
106 int DelService(const std::string & name) const override;
109 FIREBIRD_STORE(const FIREBIRD_STORE & rvalue);
110 FIREBIRD_STORE & operator=(const FIREBIRD_STORE & rvalue);
113 mutable std::string strError;
114 std::string db_server, db_database, db_user, db_password;
115 STG::ModuleSettings settings;
116 mutable IBPP::Database db;
117 mutable pthread_mutex_t mutex;
121 STG::PluginLogger logger;
123 int SaveStat(const STG::UserStat & stat, const std::string & login, int year = 0, int month = 0) const;
127 time_t ts2time_t(const IBPP::Timestamp & ts);
128 void time_t2ts(time_t t, IBPP::Timestamp * ts);
129 void ym2date(int year, int month, IBPP::Date * date);
131 template <typename T>
133 T Get(IBPP::Statement st, size_t pos)