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