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