]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig/configproto.h
Rearranged some headers in sgconfig.
[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 <string>
32 #include <list>
33 #include <vector>
34
35 #include "stg/os_int.h"
36
37 #include <expat.h>
38 #include <pthread.h>
39
40 #define  STG_HEADER     "SG04"
41 #define  OK_HEADER      "OKHD"
42 #define  ERR_HEADER     "ERHD"
43 #define  OK_LOGIN       "OKLG"
44 #define  ERR_LOGIN      "ERLG"
45 #define  OK_LOGINS      "OKLS"
46 #define  ERR_LOGINS     "ERLS"
47
48 class BASE_PARSER;
49 class USERS;
50 class ADMINS;
51 class ADMIN;
52 class TARIFFS;
53 class PLUGIN_LOGGER;
54 class STORE;
55 class SETTINGS;
56
57 //-----------------------------------------------------------------------------
58 class CONFIGPROTO {
59 public:
60     CONFIGPROTO(PLUGIN_LOGGER & l);
61     ~CONFIGPROTO();
62
63     void            SetPort(uint16_t p) { port = p; }
64     void            SetAdmins(ADMINS * a);
65     void            SetUsers(USERS * u);
66     void            SetTariffs(TARIFFS * t);
67     void            SetStore(STORE * s);
68     void            SetStgSettings(const SETTINGS * s);
69     uint32_t        GetAdminIP() const { return adminIP; }
70     int             Prepare();
71     int             Stop();
72     const std::string & GetStrError() const { return errorStr; }
73     void            Run();
74
75 private:
76     CONFIGPROTO(const CONFIGPROTO & rvalue);
77     CONFIGPROTO & operator=(const CONFIGPROTO & rvalue);
78
79     int             RecvHdr(int sock);
80     int             RecvLogin(int sock);
81     int             SendLoginAnswer(int sock);
82     int             SendHdrAnswer(int sock, int err);
83     int             RecvLoginS(int sock);
84     int             SendLoginSAnswer(int sock, int err);
85     int             RecvData(int sock);
86     int             SendDataAnswer(int sock);
87     void            SendError(const char * text);
88     void            WriteLogAccessFailed(uint32_t ip);
89
90     int             ParseCommand();
91
92     std::list<std::string>      answerList;
93     std::list<std::string>      requestList;
94     uint32_t                    adminIP;
95     std::string                 adminLogin;
96     std::string                 adminPassword;
97     uint16_t                    port;
98     pthread_t                   thrReciveSendConf;
99     bool                        nonstop;
100     int                         state;
101     ADMIN *                     currAdmin;
102     PLUGIN_LOGGER &             logger;
103
104     int                         listenSocket;
105
106     ADMINS *                    admins;
107
108     BASE_PARSER *               currParser;
109     std::vector<BASE_PARSER *>  dataParser;
110
111     XML_Parser                  xmlParser;
112
113     std::string                 errorStr;
114
115     friend void ParseXMLStart(void *data, const char *el, const char **attr);
116     friend void ParseXMLEnd(void *data, const char *el);
117 };
118 //-----------------------------------------------------------------------------
119 #endif //CONFIGPROTO_H