]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/userstat/userstat.h
Добавление исходников
[stg.git] / projects / stargazer / plugins / other / userstat / userstat.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 : Maxim Mamontov <faust@stargazer.dp.ua>
19  */
20
21 /*
22  $Revision: 1.1 $
23  $Date: 2008/07/05 12:35:53 $
24  $Author: faust $
25 */
26
27 #ifndef __USERSTAT_H__
28 #define __USERSTAT_H__
29
30 #include <expat.h>
31 #include <pthread.h>
32 #include <netinet/in.h>
33
34 #include "base_plugin.h"
35
36 extern "C" BASE_PLUGIN * GetPlugin();
37
38 struct THREAD_INFO
39 {
40     pthread_t thread;
41     USERS * users;
42     BASE_STORE * store;
43     int outerSocket;
44     bool done;
45 };
46
47 uint32_t n2l(unsigned char * c)
48 {
49     uint32_t t = *c++ << 24;
50     t += *c++ << 16;
51     t += *c++ << 8;
52     t += *c;
53     return t;
54 }
55
56 void l2n(uint32_t t, unsigned char * c)
57 {
58     *c++ = t >> 24 & 0x000000FF;
59     *c++ = t >> 16 & 0x000000FF;
60     *c++ = t >> 8 & 0x000000FF;
61     *c++ = t & 0x000000FF;
62 }
63
64 class USERSTAT : public BASE_PLUGIN
65 {
66 public:
67     USERSTAT();
68     ~USERSTAT();
69
70     virtual void SetUsers(USERS * u) { users = u; };
71     virtual void SetTariffs(TARIFFS * t) {};
72     virtual void SetAdmins(ADMINS * a) {};
73     virtual void SetTraffcounter(TRAFFCOUNTER * tc) {};
74     virtual void SetStore(BASE_STORE * st) { store = st; };
75     virtual void SetStgSettings(const SETTINGS * s) {};
76     virtual void SetSettings(const MODULE_SETTINGS & s) { settings = s; };
77     virtual int  ParseSettings();
78
79     virtual int  Start();
80     virtual int  Stop();
81     virtual bool IsRunning() { return isRunning; };
82     virtual const string  & GetStrError() const { return errorStr; };
83     virtual const string    GetVersion() const { return version; };
84     virtual uint16_t        GetStartPosition() const { return 0; };
85     virtual uint16_t        GetStopPosition() const { return 0; };
86
87 private:
88     struct IsDone : public unary_function<THREAD_INFO, bool>
89     {
90         bool operator()(const THREAD_INFO & info) { return info.done; };
91     };
92     struct ToLower : public unary_function<char, char>
93     {
94         char operator() (char c) const  { return std::tolower(c); }
95     };
96     bool isRunning;
97     bool nonstop;
98     std::string errorStr;
99     std::string version;
100     std::vector<THREAD_INFO> pool;
101     int listenSocket;
102     int threads;
103     unsigned maxThreads;
104     uint16_t port;
105     struct sockaddr_in listenAddr;
106     pthread_t thread;
107     pthread_mutex_t mutex;
108     USERS * users;
109     BASE_STORE * store;
110
111     MODULE_SETTINGS settings;
112
113     XML_Parser xmlParser;
114
115     int Prepare();
116     int Finalize();
117     static void * Run(void *);
118     static void * Operate(void *);
119
120     friend void ParseXMLStart(void * data, char * name, char ** attr);
121     friend void ParseXMLEnd(void * data, char * name);
122 };
123
124 #endif