]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/configuration/sgconfig/configproto.h
Reduced scopes plus graceful connection shutdown.
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / configproto.h
index 29369867b56a1605596f0f51f1fd61e3cfca4758..af924928a9b1490df86ae5c4072caffe02bd344c 100644 (file)
 #ifndef CONFIGPROTO_H
 #define CONFIGPROTO_H
 
-#include <expat.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
 #include <string>
+#include <list>
+#include <vector>
 
-#include "parser.h"
-#include "../../../users.h"
-#include "../../../admins.h"
-#include "../../../tariffs.h"
-#include "stg_logger.h"
+#include "stg/module_settings.h"
+#include "stg/os_int.h"
 
-using namespace std;
+#include <expat.h>
+#include <pthread.h>
 
 #define  STG_HEADER     "SG04"
 #define  OK_HEADER      "OKHD"
@@ -50,94 +46,72 @@ using namespace std;
 #define  OK_LOGINS      "OKLS"
 #define  ERR_LOGINS     "ERLS"
 
+class BASE_PARSER;
+class USERS;
+class ADMINS;
+class ADMIN;
+class TARIFFS;
+class PLUGIN_LOGGER;
+class STORE;
+class SETTINGS;
+
 //-----------------------------------------------------------------------------
-class CONFIGPROTO
-{
+class CONFIGPROTO {
 public:
-    CONFIGPROTO();
+    CONFIGPROTO(PLUGIN_LOGGER & l);
     ~CONFIGPROTO();
 
     void            SetPort(uint16_t port);
-    //void            SetHostAllow(HOSTALLOW * ha);
     void            SetAdmins(ADMINS * a);
-    void            SetUsers(USERS * u);
-    void            SetTariffs(TARIFFS * t);
-    void            SetStore(BASE_STORE * s);
-    void            SetStgSettings(const SETTINGS * s);
-    const string &  GetAdminLogin();
-    uint32_t        GetAdminIP();
+    uint32_t        GetAdminIP() const { return adminIP; }
     int             Prepare();
     int             Stop();
-    const string &  GetStrError();
-    static void *   Run(void * a);
+    const std::string & GetStrError() const { return errorStr; }
+    void            Run();
 
 private:
+    CONFIGPROTO(const CONFIGPROTO & rvalue);
+    CONFIGPROTO & operator=(const CONFIGPROTO & rvalue);
+
     int             RecvHdr(int sock);
     int             RecvLogin(int sock);
-    int             SendLoginAnswer(int sock, int err);
+    int             SendLoginAnswer(int sock);
     int             SendHdrAnswer(int sock, int err);
     int             RecvLoginS(int sock);
     int             SendLoginSAnswer(int sock, int err);
     int             RecvData(int sock);
-    int             SendDataAnswer(int sock);
-    void            SendError(const char * text);
+    int             SendDataAnswer(int sock, const std::string & answer);
+    int             SendError(int sock, const std::string & text);
     void            WriteLogAccessFailed(uint32_t ip);
+    const std::string & GetDataAnswer() const { return dataAnswer; }
 
     int             ParseCommand();
 
-    list<string>    answerList;
-    list<string>    requestList;
-    uint32_t        adminIP;
-    string          adminLogin;
-    uint16_t        port;
-    pthread_t       thrReciveSendConf;
-    bool            nonstop;
-    int             state;
-    //HOSTALLOW *     hostAllow;
-    ADMIN           currAdmin;
-    STG_LOGGER &    WriteServLog;
-
-    int                 outerSocket;
-    int                 listenSocket;
-    struct sockaddr_in  outerAddr;
-    socklen_t           outerAddrLen;
-
-    PARSER_GET_SERVER_INFO      parserGetServInfo;
-
-    PARSER_GET_USERS            parserGetUsers;
-    PARSER_GET_USER             parserGetUser;
-    PARSER_CHG_USER             parserChgUser;
-    PARSER_ADD_USER             parserAddUser;
-    PARSER_DEL_USER             parserDelUser;
-    PARSER_CHECK_USER           parserCheckUser;
-    PARSER_SEND_MESSAGE         parserSendMessage;
-
-    PARSER_GET_ADMINS           parserGetAdmins;
-    PARSER_ADD_ADMIN            parserAddAdmin;
-    PARSER_DEL_ADMIN            parserDelAdmin;
-    PARSER_CHG_ADMIN            parserChgAdmin;
-
-    PARSER_GET_TARIFFS          parserGetTariffs;
-    PARSER_ADD_TARIFF           parserAddTariff;
-    PARSER_DEL_TARIFF           parserDelTariff;
-    PARSER_CHG_TARIFF           parserChgTariff;
+    std::list<std::string>      requestList;
+    uint32_t                    adminIP;
+    std::string                 adminLogin;
+    std::string                 adminPassword;
+    uint16_t                    port;
+    pthread_t                   thrReciveSendConf;
+    bool                        nonstop;
+    int                         state;
+    ADMIN *                     currAdmin;
+    PLUGIN_LOGGER &             logger;
+    std::string                 dataAnswer;
+
+    int                         listenSocket;
 
     ADMINS *                    admins;
-    //USERS *                     users;
-    //TARIFFS *                   tariffs;
-    //BASE_STORE *                store;
-    //const SETTINGS *            settings;
 
     BASE_PARSER *               currParser;
-    vector<BASE_PARSER*>        dataParser;
+    std::vector<BASE_PARSER *>  dataParser;
 
     XML_Parser                  xmlParser;
 
-    string                      errorStr;
+    std::string                 errorStr;
 
     friend void ParseXMLStart(void *data, const char *el, const char **attr);
     friend void ParseXMLEnd(void *data, const char *el);
 };
 //-----------------------------------------------------------------------------
 #endif //CONFIGPROTO_H
-