]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/authorization/ao/ao.h
Стилистические правки и инициализация неинициализованных членов в
[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 <string>
31 #include <pthread.h>
32 #include "base_auth.h"
33 #include "base_store.h"
34 #include "notifer.h"
35 #include "user_ips.h"
36 #include "../../../users.h"
37
38 using namespace std;
39
40 extern "C" BASE_PLUGIN * GetPlugin();
41
42 class AUTH_AO;
43 //-----------------------------------------------------------------------------
44 template <typename varParamType>
45 class CHG_BEFORE_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType>
46 {
47 public:
48                 CHG_BEFORE_NOTIFIER(AUTH_AO & a, user_iter u) : user(u), auth(a) {}
49     void        Notify(const varParamType & oldValue, const varParamType & newValue);
50     //void        SetUser(user_iter u) { user = u; }
51     user_iter   GetUser() {return user; }
52     //void        SetAuthorizator(const AUTH_AO * a) { auth = a; }
53
54 private:
55     user_iter   user;
56     const       AUTH_AO & auth;
57 };
58 //-----------------------------------------------------------------------------
59 template <typename varParamType>
60 class CHG_AFTER_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType>
61 {
62 public:
63                 CHG_AFTER_NOTIFIER(AUTH_AO & a, user_iter u) : user(u), auth(a) {}
64     void        Notify(const varParamType & oldValue, const varParamType & newValue);
65     //void        SetUser(user_iter u) { user = u; }
66     user_iter   GetUser() {return user; }
67     //void        SetAuthorizator(const AUTH_AO * a) { auth = a; }
68
69 private:
70     user_iter   user;
71     const AUTH_AO & auth;
72 };
73 //-----------------------------------------------------------------------------
74 class AUTH_AO_SETTINGS
75 {
76 public:
77     const string& GetStrError() const { static string s; return s; }
78     int ParseSettings(const MODULE_SETTINGS &) { return 0; }
79 };
80 //-----------------------------------------------------------------------------
81 class AUTH_AO :public BASE_AUTH
82 {
83 public:
84     AUTH_AO();
85     virtual ~AUTH_AO(){};
86
87     void                SetUsers(USERS * u);
88     void                SetTariffs(TARIFFS *){};
89     void                SetAdmins(ADMINS *){};
90     void                SetTraffcounter(TRAFFCOUNTER *){};
91     void                SetStore(BASE_STORE *){};
92     void                SetStgSettings(const SETTINGS *){};
93
94     int                 Start();
95     int                 Stop();
96     int                 Reload() { return 0; };
97     bool                IsRunning();
98     void                SetSettings(const MODULE_SETTINGS & s);
99     int                 ParseSettings();
100     const string      & GetStrError() const;
101     const string        GetVersion() const;
102     uint16_t            GetStartPosition() const;
103     uint16_t            GetStopPosition() const;
104
105     void                AddUser(user_iter u);
106     void                DelUser(user_iter u);
107
108     void                UpdateUserAuthorization(user_iter u) const;
109     void                Unauthorize(user_iter u) const;
110
111     int                 SendMessage(const STG_MSG & msg, uint32_t ip) const;
112
113 private:
114     void                GetUsers();
115     void                SetUserNotifiers(user_iter u);
116     void                UnSetUserNotifiers(user_iter u);
117
118     mutable string      errorStr;
119     AUTH_AO_SETTINGS    aoSettings;
120     USERS             * users;
121     list<user_iter>     usersList;
122     bool                isRunning;
123     MODULE_SETTINGS     settings;
124
125     /*
126     ÍÙ ÄÏÌÖÎÙ ÐÅÒÅÐÒÏ×ÅÒÉÔØ ×ÏÚÍÏÖÎÏÓÔØ Á×ÔÏÒÉÚÁÃÉÉ ÀÚÅÒÁ ÐÒÉ ÉÚÍÅÎÅÎÉÉ
127     ÓÌÅÄÕÀÝÉÈ ÅÇÏ ÐÁÒÁÍÅÔÒÏ×:
128     - alwaysOnline
129     - ips
130     */
131
132     list<CHG_BEFORE_NOTIFIER<int> >         BeforeChgAONotifierList;
133     list<CHG_AFTER_NOTIFIER<int> >          AfterChgAONotifierList;
134
135     list<CHG_BEFORE_NOTIFIER<USER_IPS> >    BeforeChgIPNotifierList;
136     list<CHG_AFTER_NOTIFIER<USER_IPS> >     AfterChgIPNotifierList;
137
138     class ADD_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
139     {
140     public:
141         ADD_USER_NONIFIER(AUTH_AO & a) : auth(a) {};
142         virtual ~ADD_USER_NONIFIER(){};
143
144         //void SetAuthorizator(AUTH_AO * a) { auth = a; }
145         void Notify(const user_iter & user)
146             {
147             auth.AddUser(user);
148             }
149
150     private:
151         AUTH_AO & auth;
152     } onAddUserNotifier;
153
154     class DEL_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
155     {
156     public:
157         DEL_USER_NONIFIER(AUTH_AO & a) : auth(a) {};
158         virtual ~DEL_USER_NONIFIER(){};
159
160         //void SetAuthorizator(AUTH_AO * a) { auth = a; }
161         void Notify(const user_iter & user)
162             {
163             auth.DelUser(user);
164             }
165
166     private:
167         AUTH_AO & auth;
168     } onDelUserNotifier;
169
170 };
171 //-----------------------------------------------------------------------------
172
173 #endif
174
175