]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/authorization/stress/stress.h
Rename BASE_AUTH and BASE_STORE to AUTH and STORE
[stg.git] / projects / stargazer / plugins / authorization / stress / stress.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.3 $
23  $Date: 2009/06/19 12:50:32 $
24  $Author: faust $
25  */
26
27
28 #ifndef STRESS_H
29 #define STRESS_H
30
31 #include <pthread.h>
32
33 #include <string>
34 #include <list>
35
36 #include "auth.h"
37 #include "notifer.h"
38 #include "user_ips.h"
39 #include "users.h"
40
41 extern "C" PLUGIN * GetPlugin();
42
43 class AUTH_STRESS;
44 //-----------------------------------------------------------------------------
45 template <typename varParamType>
46 class CHG_BEFORE_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType> {
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_STRESS * a) { auth = a; }
52
53 private:
54     user_iter   user;
55     const       AUTH_STRESS * auth;
56 };
57 //-----------------------------------------------------------------------------
58 template <typename varParamType>
59 class CHG_AFTER_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType> {
60 public:
61     void        Notify(const varParamType & oldValue, const varParamType & newValue);
62     void        SetUser(user_iter u) { user = u; }
63     user_iter   GetUser() {return user; }
64     void        SetAuthorizator(const AUTH_STRESS * a) { auth = a; }
65
66 private:
67     user_iter   user;
68     const AUTH_STRESS * auth;
69 };
70 //-----------------------------------------------------------------------------
71 class AUTH_STRESS_SETTINGS {
72 public:
73                     AUTH_STRESS_SETTINGS();
74     const std::string &   GetStrError() const { return errorStr; }
75     int             ParseSettings(const MODULE_SETTINGS & s);
76     int             GetAverageOnlineTime() const;
77 private:
78     int             ParseIntInRange(const std::string & str, int min, int max, int * val);
79     int             averageOnlineTime;
80     std::string     errorStr;
81 };
82 //-----------------------------------------------------------------------------
83 class AUTH_STRESS :public AUTH {
84 public:
85     AUTH_STRESS();
86     virtual ~AUTH_STRESS() {}
87
88     void                SetUsers(USERS * u);
89     void                SetTariffs(TARIFFS * t) {}
90     void                SetAdmins(ADMINS * a) {}
91     void                SetTraffcounter(TRAFFCOUNTER * tc) {}
92     void                SetStore(STORE * ) {}
93     void                SetStgSettings(const SETTINGS *) {}
94
95     int                 Start();
96     int                 Stop();
97     bool                IsRunning();
98     void                SetSettings(const MODULE_SETTINGS & s);
99     int                 ParseSettings();
100     const std::string & GetStrError() const;
101     const std::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                Authorize(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     bool                nonstop;
119
120     static void *       Run(void *);
121
122     mutable std::string errorStr;
123     AUTH_STRESS_SETTINGS    stressSettings;
124     USERS             * users;
125     std::list<user_iter> usersList;
126     bool                isRunning;
127     MODULE_SETTINGS     settings;
128
129     pthread_t           thread;
130     pthread_mutex_t     mutex;
131
132     std::list<CHG_BEFORE_NOTIFIER<USER_IPS> > BeforeChgIPNotifierList;
133     std::list<CHG_AFTER_NOTIFIER<USER_IPS> > AfterChgIPNotifierList;
134
135     class ADD_USER_NONIFIER: public NOTIFIER_BASE<user_iter> {
136     public:
137         ADD_USER_NONIFIER() {}
138         virtual ~ADD_USER_NONIFIER() {}
139
140         void SetAuthorizator(AUTH_STRESS * a) { auth = a; }
141         void Notify(const user_iter & user)
142             {
143             auth->AddUser(user);
144             }
145
146     private:
147         AUTH_STRESS * auth;
148     } onAddUserNotifier;
149
150     class DEL_USER_NONIFIER: public NOTIFIER_BASE<user_iter> {
151     public:
152         DEL_USER_NONIFIER() {}
153         virtual ~DEL_USER_NONIFIER() {}
154
155         void SetAuthorizator(AUTH_STRESS * a) { auth = a; }
156         void Notify(const user_iter & user)
157             {
158             auth->DelUser(user);
159             }
160
161     private:
162         AUTH_STRESS * auth;
163     } onDelUserNotifier;
164
165 };
166 //-----------------------------------------------------------------------------
167
168 #endif