]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig/configproto.h
Merge branch 'new-daily-fee'
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / configproto.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.14 $
23  $Date: 2010/10/04 20:24:14 $
24  $Author: faust $
25  */
26
27
28 #ifndef CONFIGPROTO_H
29 #define CONFIGPROTO_H
30
31 #include "parser_auth_by.h"
32 #include "parser_user_info.h"
33
34 #include "stg/users.h"
35 #include "stg/admins.h"
36 #include "stg/tariffs.h"
37 #include "stg/logger.h"
38 #include "parser.h"
39
40 #include <string>
41 #include <list>
42
43 #include <expat.h>
44 #include <sys/types.h>
45 #include <sys/socket.h>
46
47 #define  STG_HEADER     "SG04"
48 #define  OK_HEADER      "OKHD"
49 #define  ERR_HEADER     "ERHD"
50 #define  OK_LOGIN       "OKLG"
51 #define  ERR_LOGIN      "ERLG"
52 #define  OK_LOGINS      "OKLS"
53 #define  ERR_LOGINS     "ERLS"
54
55 //-----------------------------------------------------------------------------
56 class CONFIGPROTO {
57 public:
58     CONFIGPROTO(PLUGIN_LOGGER & l);
59     ~CONFIGPROTO();
60
61     void            SetPort(uint16_t p) { port = p; }
62     void            SetAdmins(ADMINS * a);
63     void            SetUsers(USERS * u);
64     void            SetTariffs(TARIFFS * t);
65     void            SetStore(STORE * s);
66     void            SetStgSettings(const SETTINGS * s);
67     uint32_t        GetAdminIP() const { return adminIP; }
68     int             Prepare();
69     int             Stop();
70     const std::string & GetStrError() const { return errorStr; }
71     void            Run();
72
73 private:
74     CONFIGPROTO(const CONFIGPROTO & rvalue);
75     CONFIGPROTO & operator=(const CONFIGPROTO & rvalue);
76
77     int             RecvHdr(int sock);
78     int             RecvLogin(int sock);
79     int             SendLoginAnswer(int sock);
80     int             SendHdrAnswer(int sock, int err);
81     int             RecvLoginS(int sock);
82     int             SendLoginSAnswer(int sock, int err);
83     int             RecvData(int sock);
84     int             SendDataAnswer(int sock);
85     void            SendError(const char * text);
86     void            WriteLogAccessFailed(uint32_t ip);
87
88     int             ParseCommand();
89
90     std::list<std::string>      answerList;
91     std::list<std::string>      requestList;
92     uint32_t                    adminIP;
93     std::string                 adminLogin;
94     std::string                 adminPassword;
95     uint16_t                    port;
96     pthread_t                   thrReciveSendConf;
97     bool                        nonstop;
98     int                         state;
99     ADMIN *                     currAdmin;
100     PLUGIN_LOGGER &             logger;
101
102     int                         listenSocket;
103
104     PARSER_GET_SERVER_INFO      parserGetServInfo;
105
106     PARSER_GET_USERS            parserGetUsers;
107     PARSER_GET_USER             parserGetUser;
108     PARSER_CHG_USER             parserChgUser;
109     PARSER_ADD_USER             parserAddUser;
110     PARSER_DEL_USER             parserDelUser;
111     PARSER_CHECK_USER           parserCheckUser;
112     PARSER_SEND_MESSAGE         parserSendMessage;
113     PARSER_AUTH_BY              parserAuthBy;
114     PARSER_USER_INFO            parserUserInfo;
115
116     PARSER_GET_ADMINS           parserGetAdmins;
117     PARSER_ADD_ADMIN            parserAddAdmin;
118     PARSER_DEL_ADMIN            parserDelAdmin;
119     PARSER_CHG_ADMIN            parserChgAdmin;
120
121     PARSER_GET_TARIFFS          parserGetTariffs;
122     PARSER_ADD_TARIFF           parserAddTariff;
123     PARSER_DEL_TARIFF           parserDelTariff;
124     PARSER_CHG_TARIFF           parserChgTariff;
125
126     ADMINS *                    admins;
127
128     BASE_PARSER *               currParser;
129     std::vector<BASE_PARSER *>  dataParser;
130
131     XML_Parser                  xmlParser;
132
133     std::string                 errorStr;
134
135     friend void ParseXMLStart(void *data, const char *el, const char **attr);
136     friend void ParseXMLEnd(void *data, const char *el);
137 };
138 //-----------------------------------------------------------------------------
139 #endif //CONFIGPROTO_H