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