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/user_ips.h"
29 #include "stg/logger.h"
44 using UserPtr = STG::User*;
45 using ConstUserPtr = const STG::User*;
48 class CHG_BEFORE_NOTIFIER : public STG::PropertyNotifierBase<T> {
50 CHG_BEFORE_NOTIFIER(AUTH_AO & a, UserPtr u)
52 CHG_BEFORE_NOTIFIER(const CHG_BEFORE_NOTIFIER<T> & rvalue)
53 : user(rvalue.user), auth(rvalue.auth) {}
54 void notify(const T & oldValue, const T & newValue) override;
55 UserPtr GetUser() const { return user; }
58 CHG_BEFORE_NOTIFIER<T> & operator=(const CHG_BEFORE_NOTIFIER<T> & rvalue);
63 //-----------------------------------------------------------------------------
65 class CHG_AFTER_NOTIFIER : public STG::PropertyNotifierBase<T> {
67 CHG_AFTER_NOTIFIER(AUTH_AO & a, UserPtr u)
69 CHG_AFTER_NOTIFIER(const CHG_AFTER_NOTIFIER<T> & rvalue)
70 : user(rvalue.user), auth(rvalue.auth) {}
71 void notify(const T & oldValue, const T & newValue) override;
72 UserPtr GetUser() const { return user; }
75 CHG_AFTER_NOTIFIER<T> & operator=(const CHG_AFTER_NOTIFIER<T> & rvalue);
80 //-----------------------------------------------------------------------------
81 class AUTH_AO : public STG::Auth {
85 void SetUsers(STG::Users * u) override { users = u; }
89 int Reload(const STG::ModuleSettings & /*ms*/) override { return 0; }
90 bool IsRunning() override { return isRunning; }
91 void SetSettings(const STG::ModuleSettings &) override {}
92 int ParseSettings() override { return 0; }
93 const std::string & GetStrError() const override { return errorStr; }
94 std::string GetVersion() const override;
95 uint16_t GetStartPosition() const override { return 30; }
96 uint16_t GetStopPosition() const override { return 30; }
98 int SendMessage(const STG::Message & msg, uint32_t ip) const override;
101 AUTH_AO(const AUTH_AO & rvalue);
102 AUTH_AO & operator=(const AUTH_AO & rvalue);
104 void AddUser(UserPtr u);
105 void DelUser(UserPtr u);
108 void SetUserNotifiers(UserPtr u);
109 void UnSetUserNotifiers(UserPtr u);
110 void UpdateUserAuthorization(ConstUserPtr u) const;
112 mutable std::string errorStr;
114 std::vector<UserPtr> userList;
116 STG::ModuleSettings settings;
118 std::list<CHG_BEFORE_NOTIFIER<int> > BeforeChgAONotifierList;
119 std::list<CHG_AFTER_NOTIFIER<int> > AfterChgAONotifierList;
121 std::list<CHG_BEFORE_NOTIFIER<STG::UserIPs> > BeforeChgIPNotifierList;
122 std::list<CHG_AFTER_NOTIFIER<STG::UserIPs> > AfterChgIPNotifierList;
124 class ADD_USER_NONIFIER: public STG::NotifierBase<UserPtr> {
126 explicit ADD_USER_NONIFIER(AUTH_AO & a) : auth(a) {}
127 virtual ~ADD_USER_NONIFIER() {}
128 void notify(const UserPtr & user) override { auth.AddUser(user); }
131 ADD_USER_NONIFIER(const ADD_USER_NONIFIER & rvalue);
132 ADD_USER_NONIFIER & operator=(const ADD_USER_NONIFIER & rvalue);
137 class DEL_USER_NONIFIER: public STG::NotifierBase<UserPtr> {
139 explicit DEL_USER_NONIFIER(AUTH_AO & a) : auth(a) {}
140 virtual ~DEL_USER_NONIFIER() {}
141 void notify(const UserPtr & user) override { auth.DelUser(user); }
144 DEL_USER_NONIFIER(const DEL_USER_NONIFIER & rvalue);
145 DEL_USER_NONIFIER & operator=(const DEL_USER_NONIFIER & rvalue);
150 STG::PluginLogger logger;
152 friend class CHG_BEFORE_NOTIFIER<int>;
153 friend class CHG_AFTER_NOTIFIER<int>;
154 friend class CHG_BEFORE_NOTIFIER<STG::UserIPs>;
155 friend class CHG_AFTER_NOTIFIER<STG::UserIPs>;