]> git.stg.codes - stg.git/blob - stglibs/srvconf.lib/include/stg/parser_get_user.h
7b6032e094a10529ed10ba23d52f2414d4641416
[stg.git] / stglibs / srvconf.lib / include / stg / parser_get_user.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  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
20  */
21
22 #ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__
23 #define __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__
24
25 #include "parser.h"
26
27 #include "stg/os_int.h"
28 #include "stg/const.h"
29
30 #include <string>
31 #include <map>
32
33 #include <ctime>
34
35 class BASE_PROPERTY_PARSER
36 {
37     public:
38         virtual ~BASE_PROPERTY_PARSER() {}
39         virtual void Parse(const char ** attr) = 0;
40 };
41
42 template <typename T>
43 class PROPERTY_PARSER : public BASE_PROPERTY_PARSER
44 {
45     public:
46         typedef T (* FUNC)(const char **);
47         PROPERTY_PARSER(T & v, FUNC f) : value(v), func(f) {}
48         virtual void Parse(const char ** attr) { value = func(attr); }
49     private:
50         T & value;
51         FUNC func;
52 };
53
54 typedef std::map<std::string, BASE_PROPERTY_PARSER *> PROPERTY_PARSERS;
55
56 class PARSER_GET_USER: public PARSER
57 {
58 public:
59     struct STAT
60     {
61         long long  su[DIR_NUM];
62         long long  sd[DIR_NUM];
63         long long  mu[DIR_NUM];
64         long long  md[DIR_NUM];
65         double     freeMb;
66     };
67
68     struct INFO
69     {
70         std::string login;
71         std::string password;
72         double      cash;
73         double      credit;
74         time_t      creditExpire;
75         double      lastCash;
76         double      prepaidTraff;
77         int         down;
78         int         passive;
79         int         disableDetailStat;
80         int         connected;
81         int         alwaysOnline;
82         uint32_t    ip;
83         std::string ips;
84         std::string tariff;
85         std::string group;
86         std::string note;
87         std::string email;
88         std::string name;
89         std::string address;
90         std::string phone;
91         STAT        stat;
92         std::string userData[USERDATA_NUM];
93     };
94
95     typedef void (* CALLBACK)(const INFO & info, void * data);
96
97     PARSER_GET_USER();
98     virtual ~PARSER_GET_USER();
99     int  ParseStart(const char *el, const char **attr);
100     void ParseEnd(const char *el);
101     void SetCallback(CALLBACK f, void * data);
102 private:
103     PROPERTY_PARSERS propertyParsers;
104     CALLBACK callback;
105     void * data;
106     INFO info;
107     int depth;
108
109     void ParseUser(const char *el, const char **attr);
110     void ParseUserParams(const char *el, const char **attr);
111 };
112
113 #endif