X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/f6aeba07ab90a20378c84c89f46afb9e85738612..fe97f14f9caa463e2bc6b81124ce5e9553bc924d:/projects/stargazer/plugins/configuration/sgconfig/conn.h diff --git a/projects/stargazer/plugins/configuration/sgconfig/conn.h b/projects/stargazer/plugins/configuration/sgconfig/conn.h index 396e9753..7825d4f9 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/conn.h +++ b/projects/stargazer/plugins/configuration/sgconfig/conn.h @@ -21,12 +21,13 @@ #ifndef __STG_SGCONFIG_CONN_H__ #define __STG_SGCONFIG_CONN_H__ +#include "parser.h" + #include "stg/os_int.h" #include "stg/const.h" #include #include -#include #include @@ -52,20 +53,18 @@ class Conn Error(const std::string& message) : runtime_error(message.c_str()) {} }; - Conn(const SETTINGS & settings, - ADMINS & admins, - USERS & users, - TARIFFS & tariffs, - int sock, const sockaddr_in& addr); + Conn(const BASE_PARSER::REGISTRY & registry, + ADMINS & admins, int sock, const sockaddr_in& addr); ~Conn(); int Sock() const { return m_sock; } uint32_t IP() const { return *(uint32_t *)(&m_addr.sin_addr); } - uint16_t Port() const { return m_addr.sin_port; } + uint16_t Port() const { return ntohs(m_addr.sin_port); } bool Read(); bool IsOk() const { return m_state != ERROR; } + bool IsDone() const { return m_state == DONE; } bool IsKeepAlive() const { return m_keepAlive; } private: @@ -78,10 +77,9 @@ class Conn static const char OK_LOGINS[5]; static const char ERR_LOGINS[5]; - const SETTINGS & m_settings; + const BASE_PARSER::REGISTRY & m_registry; + ADMINS & m_admins; - USERS & m_users; - TARIFFS & m_tariffs; ADMIN * m_admin; @@ -93,7 +91,7 @@ class Conn XML_Parser m_xmlParser; - enum { HEADER, LOGIN, CRYPTO_LOGIN, DATA, ERROR } m_state; + enum { HEADER, LOGIN, CRYPTO_LOGIN, DATA, DONE, ERROR } m_state; void * m_buffer; size_t m_bufferSize; @@ -103,7 +101,7 @@ class Conn char m_data[1024]; STG::DECRYPT_STREAM * m_stream; - BASE_PARSER * GetParser(const std::string & tag); + BASE_PARSER * GetParser(const std::string & tag) const; bool HandleBuffer(size_t size); @@ -112,6 +110,9 @@ class Conn bool HandleCryptoLogin(); bool HandleData(size_t size); + bool WriteAnswer(const void* buffer, size_t size); + bool WriteResponse(); + struct DataState { DataState(bool f, Conn & c) : final(f), conn(c) {} @@ -122,6 +123,7 @@ class Conn static bool DataCallback(const void * block, size_t size, void * data); static void ParseXMLStart(void * data, const char * el, const char ** attr); static void ParseXMLEnd(void * data, const char * el); + static bool WriteCallback(const void * block, size_t size, void * data); }; }