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