]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/authorization/stress/stress.h
Добавление исходников
[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 <string>
32 #include <pthread.h>
33 #include "base_auth.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_STRESS;
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_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 {
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_STRESS * a) { auth = a; }
66
67 private:
68     user_iter   user;
69     const AUTH_STRESS * auth;
70 };
71 //-----------------------------------------------------------------------------
72 class AUTH_STRESS_SETTINGS
73 {
74 public:
75                     AUTH_STRESS_SETTINGS();
76     const string&   GetStrError() const { return errorStr; }
77     int             ParseSettings(const MODULE_SETTINGS & s);
78     int             GetAverageOnlineTime() const;
79 private:
80     int             ParseIntInRange(const string & str, int min, int max, int * val);
81     int             averageOnlineTime;
82     string          errorStr;
83 };
84 //-----------------------------------------------------------------------------
85 class AUTH_STRESS :public BASE_AUTH
86 {
87 public:
88     AUTH_STRESS();
89     virtual ~AUTH_STRESS(){};
90
91     void                SetUsers(USERS * u);
92     void                SetTariffs(TARIFFS * t){};
93     void                SetAdmins(ADMINS * a){};
94     void                SetTraffcounter(TRAFFCOUNTER * tc){};
95     void                SetStore(BASE_STORE * ){};
96     void                SetStgSettings(const SETTINGS *){};
97
98     int                 Start();
99     int                 Stop();
100     bool                IsRunning();
101     void                SetSettings(const MODULE_SETTINGS & s);
102     int                 ParseSettings();
103     const string      & GetStrError() const;
104     const string        GetVersion() const;
105     uint16_t            GetStartPosition() const;
106     uint16_t            GetStopPosition() const;
107
108     void                AddUser(user_iter u);
109     void                DelUser(user_iter u);
110
111     void                Authorize(user_iter u) const;
112     void                Unauthorize(user_iter u) const;
113
114     int                 SendMessage(const STG_MSG & msg, uint32_t ip) const;
115
116 private:
117     void                GetUsers();
118     void                SetUserNotifiers(user_iter u);
119     void                UnSetUserNotifiers(user_iter u);
120
121     bool                nonstop;
122
123     static void *       Run(void *);
124
125     mutable string      errorStr;
126     AUTH_STRESS_SETTINGS    stressSettings;
127     USERS             * users;
128     list<user_iter>     usersList;
129     bool                isRunning;
130     MODULE_SETTINGS     settings;
131
132     pthread_t           thread;
133     pthread_mutex_t     mutex;
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(){};
142         virtual ~ADD_USER_NONIFIER(){};
143
144         void SetAuthorizator(AUTH_STRESS * a) { auth = a; }
145         void Notify(const user_iter & user)
146             {
147             auth->AddUser(user);
148             }
149
150     private:
151         AUTH_STRESS * auth;
152     } onAddUserNotifier;
153
154     class DEL_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
155     {
156     public:
157         DEL_USER_NONIFIER(){};
158         virtual ~DEL_USER_NONIFIER(){};
159
160         void SetAuthorizator(AUTH_STRESS * a) { auth = a; }
161         void Notify(const user_iter & user)
162             {
163             auth->DelUser(user);
164             }
165
166     private:
167         AUTH_STRESS * auth;
168     } onDelUserNotifier;
169
170 };
171 //-----------------------------------------------------------------------------
172
173 #endif
174
175