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