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"
26 #include "stg/logger.h"
27 #include "stg/module_settings.h"
33 class FIREBIRD_STORE : public STG::Store {
36 ~FIREBIRD_STORE() override;
38 int GetUsersList(std::vector<std::string> * usersList) const override;
39 int AddUser(const std::string & login) const override;
40 int DelUser(const std::string & login) const override;
41 int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
42 int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
43 int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
44 int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
45 int WriteUserChgLog(const std::string & login,
46 const std::string & admLogin,
48 const std::string & paramName,
49 const std::string & oldValue,
50 const std::string & newValue,
51 const std::string & message) const override;
52 int WriteUserConnect(const std::string & login, uint32_t ip) const override;
53 int WriteUserDisconnect(const std::string & login,
54 const STG::DirTraff & up,
55 const STG::DirTraff & down,
56 const STG::DirTraff & sessionUp,
57 const STG::DirTraff & sessionDown,
60 const std::string & reason) const override;
61 int WriteDetailedStat(const STG::TraffStat & statTree,
63 const std::string & login) const override;
65 int AddMessage(STG::Message * msg, const std::string & login) const override;
66 int EditMessage(const STG::Message & msg, const std::string & login) const override;
67 int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
68 int DelMessage(uint64_t id, const std::string & login) const override;
69 int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
71 int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
73 int GetAdminsList(std::vector<std::string> * adminsList) const override;
74 int SaveAdmin(const STG::AdminConf & ac) const override;
75 int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
76 int AddAdmin(const std::string & login) const override;
77 int DelAdmin(const std::string & login) const override;
79 int GetTariffsList(std::vector<std::string> * tariffsList) const override;
80 int AddTariff(const std::string & name) const override;
81 int DelTariff(const std::string & name) const override;
82 int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
83 int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
85 int GetCorpsList(std::vector<std::string> * corpsList) const override;
86 int SaveCorp(const STG::CorpConf & cc) const override;
87 int RestoreCorp(STG::CorpConf * cc, const std::string & name) const override;
88 int AddCorp(const std::string & name) const override;
89 int DelCorp(const std::string & name) const override;
91 inline void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
92 int ParseSettings() override;
94 inline const std::string & GetStrError() const override { return strError; }
96 inline const std::string & GetVersion() const override { return version; }
98 int GetServicesList(std::vector<std::string> * servicesList) const override;
99 int SaveService(const STG::ServiceConf & sc) const override;
100 int RestoreService(STG::ServiceConf * sc, const std::string & name) const override;
101 int AddService(const std::string & name) const override;
102 int DelService(const std::string & name) const override;
105 FIREBIRD_STORE(const FIREBIRD_STORE & rvalue);
106 FIREBIRD_STORE & operator=(const FIREBIRD_STORE & rvalue);
109 mutable std::string strError;
110 std::string db_server, db_database, db_user, db_password;
111 STG::ModuleSettings settings;
112 mutable IBPP::Database db;
113 mutable pthread_mutex_t mutex;
117 STG::PluginLogger logger;
119 int SaveStat(const STG::UserStat & stat, const std::string & login, int year = 0, int month = 0) const;
123 time_t ts2time_t(const IBPP::Timestamp & ts);
124 void time_t2ts(time_t t, IBPP::Timestamp * ts);
125 void ym2date(int year, int month, IBPP::Date * date);
127 template <typename T>
129 T Get(IBPP::Statement st, size_t pos)