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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
24 #include "stg/module_settings.h"
25 #include "stg/store.h"
26 #include "stg/notifer.h"
27 #include "stg/subscriptions.h"
28 #include "stg/user_ips.h"
30 #include "stg/logger.h"
45 using UserPtr = STG::User*;
46 using ConstUserPtr = const STG::User*;
49 class CHG_BEFORE_NOTIFIER : public STG::PropertyNotifierBase<T> {
51 CHG_BEFORE_NOTIFIER(AUTH_AO & a, UserPtr u)
53 CHG_BEFORE_NOTIFIER(const CHG_BEFORE_NOTIFIER<T> & rvalue)
54 : user(rvalue.user), auth(rvalue.auth) {}
55 void notify(const T & oldValue, const T & newValue) override;
56 UserPtr GetUser() const { return user; }
59 CHG_BEFORE_NOTIFIER<T> & operator=(const CHG_BEFORE_NOTIFIER<T> & rvalue);
64 //-----------------------------------------------------------------------------
66 class CHG_AFTER_NOTIFIER : public STG::PropertyNotifierBase<T> {
68 CHG_AFTER_NOTIFIER(AUTH_AO & a, UserPtr u)
70 CHG_AFTER_NOTIFIER(const CHG_AFTER_NOTIFIER<T> & rvalue)
71 : user(rvalue.user), auth(rvalue.auth) {}
72 void notify(const T & oldValue, const T & newValue) override;
73 UserPtr GetUser() const { return user; }
76 CHG_AFTER_NOTIFIER<T> & operator=(const CHG_AFTER_NOTIFIER<T> & rvalue);
81 //-----------------------------------------------------------------------------
82 class AUTH_AO : public STG::Auth {
86 void SetUsers(STG::Users * u) override { users = u; }
90 int Reload(const STG::ModuleSettings & /*ms*/) override { return 0; }
91 bool IsRunning() override { return isRunning; }
92 void SetSettings(const STG::ModuleSettings &) override {}
93 int ParseSettings() override { return 0; }
94 const std::string & GetStrError() const override { return errorStr; }
95 std::string GetVersion() const override;
96 uint16_t GetStartPosition() const override { return 30; }
97 uint16_t GetStopPosition() const override { return 30; }
99 int SendMessage(const STG::Message & msg, uint32_t ip) const override;
102 AUTH_AO(const AUTH_AO & rvalue);
103 AUTH_AO & operator=(const AUTH_AO & rvalue);
105 void AddUser(UserPtr u);
106 void DelUser(UserPtr u);
109 void SetUserNotifiers(UserPtr u);
110 void UnSetUserNotifiers(UserPtr u);
111 void UpdateUserAuthorization(ConstUserPtr u) const;
113 mutable std::string errorStr;
115 std::vector<UserPtr> userList;
117 STG::ModuleSettings settings;
119 std::list<CHG_BEFORE_NOTIFIER<int> > BeforeChgAONotifierList;
120 std::list<CHG_AFTER_NOTIFIER<int> > AfterChgAONotifierList;
122 std::list<CHG_BEFORE_NOTIFIER<STG::UserIPs> > BeforeChgIPNotifierList;
123 std::list<CHG_AFTER_NOTIFIER<STG::UserIPs> > AfterChgIPNotifierList;
125 STG::ScopedConnection m_onAddUserConn;
126 STG::ScopedConnection m_onDelUserConn;
128 STG::PluginLogger logger;
130 friend class CHG_BEFORE_NOTIFIER<int>;
131 friend class CHG_AFTER_NOTIFIER<int>;
132 friend class CHG_BEFORE_NOTIFIER<STG::UserIPs>;
133 friend class CHG_AFTER_NOTIFIER<STG::UserIPs>;