]> git.stg.codes - stg.git/blob - stargazer/plugins/authorization/ao/ao.h
Remove some more std::list.
[stg.git] / stargazer / plugins / authorization / ao / ao.h
1 /*
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.
6  *
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.
11  *
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
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  */
20
21 /*
22  $Revision: 1.21 $
23  $Date: 2010/09/10 06:38:26 $
24  $Author: faust $
25 */
26
27 #ifndef AO_H
28 #define AO_H
29
30 #include <pthread.h>
31
32 #include <string>
33 #include <vector>
34 #include <list>
35
36 #include "stg/auth.h"
37 #include "stg/store.h"
38 #include "stg/notifer.h"
39 #include "stg/user_ips.h"
40 #include "stg/user.h"
41 #include "stg/logger.h"
42
43 extern "C" PLUGIN * GetPlugin();
44
45 class AUTH_AO;
46 class USERS;
47 //-----------------------------------------------------------------------------
48 template <typename T>
49 class CHG_BEFORE_NOTIFIER : public PROPERTY_NOTIFIER_BASE<T> {
50 public:
51                 CHG_BEFORE_NOTIFIER(AUTH_AO & a, USER_PTR u)
52                     : PROPERTY_NOTIFIER_BASE<T>(), user(u), auth(a) {}
53                 CHG_BEFORE_NOTIFIER(const CHG_BEFORE_NOTIFIER<T> & rvalue)
54                     : PROPERTY_NOTIFIER_BASE<T>(),
55                       user(rvalue.user), auth(rvalue.auth) {}
56     void        Notify(const T & oldValue, const T & newValue);
57     USER_PTR    GetUser() const { return user; }
58
59 private:
60     CHG_BEFORE_NOTIFIER<T> & operator=(const CHG_BEFORE_NOTIFIER<T> & rvalue);
61
62     USER_PTR        user;
63     const AUTH_AO & auth;
64 };
65 //-----------------------------------------------------------------------------
66 template <typename T>
67 class CHG_AFTER_NOTIFIER : public PROPERTY_NOTIFIER_BASE<T> {
68 public:
69                 CHG_AFTER_NOTIFIER(AUTH_AO & a, USER_PTR u)
70                     : PROPERTY_NOTIFIER_BASE<T>(), user(u), auth(a) {}
71                 CHG_AFTER_NOTIFIER(const CHG_AFTER_NOTIFIER<T> & rvalue)
72                     : PROPERTY_NOTIFIER_BASE<T>(),
73                       user(rvalue.user), auth(rvalue.auth) {}
74     void        Notify(const T & oldValue, const T & newValue);
75     USER_PTR    GetUser() const { return user; }
76
77 private:
78     CHG_AFTER_NOTIFIER<T> & operator=(const CHG_AFTER_NOTIFIER<T> & rvalue);
79
80     USER_PTR        user;
81     const AUTH_AO & auth;
82 };
83 //-----------------------------------------------------------------------------
84 class AUTH_AO : public AUTH {
85 public:
86     AUTH_AO();
87     virtual ~AUTH_AO(){}
88
89     void                SetUsers(USERS * u) { users = u; }
90
91     int                 Start();
92     int                 Stop();
93     int                 Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
94     bool                IsRunning() { return isRunning; }
95     void                SetSettings(const MODULE_SETTINGS &) {}
96     int                 ParseSettings() { return 0; }
97     const std::string & GetStrError() const { return errorStr; }
98     std::string         GetVersion() const;
99     uint16_t            GetStartPosition() const { return 30; }
100     uint16_t            GetStopPosition() const { return 30; }
101
102     void                AddUser(USER_PTR u);
103     void                DelUser(USER_PTR u);
104
105     int                 SendMessage(const STG_MSG & msg, uint32_t ip) const;
106
107 private:
108     AUTH_AO(const AUTH_AO & rvalue);
109     AUTH_AO & operator=(const AUTH_AO & rvalue);
110
111     void                GetUsers();
112     void                SetUserNotifiers(USER_PTR u);
113     void                UnSetUserNotifiers(USER_PTR u);
114     void                UpdateUserAuthorization(CONST_USER_PTR u) const;
115
116     mutable std::string errorStr;
117     USERS *             users;
118     std::vector<USER_PTR> userList;
119     bool                isRunning;
120     MODULE_SETTINGS     settings;
121
122     std::list<CHG_BEFORE_NOTIFIER<int> >      BeforeChgAONotifierList;
123     std::list<CHG_AFTER_NOTIFIER<int> >       AfterChgAONotifierList;
124
125     std::list<CHG_BEFORE_NOTIFIER<USER_IPS> > BeforeChgIPNotifierList;
126     std::list<CHG_AFTER_NOTIFIER<USER_IPS> >  AfterChgIPNotifierList;
127
128     class ADD_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
129     public:
130         explicit ADD_USER_NONIFIER(AUTH_AO & a) : auth(a) {}
131         virtual ~ADD_USER_NONIFIER() {}
132         void Notify(const USER_PTR & user) { auth.AddUser(user); }
133
134     private:
135         ADD_USER_NONIFIER(const ADD_USER_NONIFIER & rvalue);
136         ADD_USER_NONIFIER & operator=(const ADD_USER_NONIFIER & rvalue);
137
138         AUTH_AO & auth;
139     } onAddUserNotifier;
140
141     class DEL_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
142     public:
143         explicit DEL_USER_NONIFIER(AUTH_AO & a) : auth(a) {}
144         virtual ~DEL_USER_NONIFIER() {}
145         void Notify(const USER_PTR & user) { auth.DelUser(user); }
146
147     private:
148         DEL_USER_NONIFIER(const DEL_USER_NONIFIER & rvalue);
149         DEL_USER_NONIFIER & operator=(const DEL_USER_NONIFIER & rvalue);
150
151         AUTH_AO & auth;
152     } onDelUserNotifier;
153     PLUGIN_LOGGER logger;
154
155     friend class CHG_BEFORE_NOTIFIER<int>;
156     friend class CHG_AFTER_NOTIFIER<int>;
157     friend class CHG_BEFORE_NOTIFIER<USER_IPS>;
158     friend class CHG_AFTER_NOTIFIER<USER_IPS>;
159
160 };
161 //-----------------------------------------------------------------------------
162
163 #endif