X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/d903c02d2bba584ff806ae9d00973fa4418f77b8..afcbfd1a09e22ff4839ba5db42047c96f355506c:/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 902cd394..ed2e64d1 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/conn.h +++ b/projects/stargazer/plugins/configuration/sgconfig/conn.h @@ -21,12 +21,15 @@ #ifndef __STG_SGCONFIG_CONN_H__ #define __STG_SGCONFIG_CONN_H__ +#include "parser.h" + +#include "dumphelpers.h" + #include "stg/os_int.h" #include "stg/const.h" #include #include -#include #include @@ -38,6 +41,7 @@ class USERS; class TARIFFS; class ADMIN; class BASE_PARSER; +class PLUGIN_LOGGER; namespace STG { @@ -49,26 +53,28 @@ class Conn public: struct Error : public std::runtime_error { - Error(const std::string& message) : runtime_error(message.c_str()) {} + explicit 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, + PLUGIN_LOGGER & logger); ~Conn(); int Sock() const { return m_sock; } uint32_t IP() const { return *(uint32_t *)(&m_addr.sin_addr); } uint16_t Port() const { return ntohs(m_addr.sin_port); } + std::string endpoint() const { return inet_ntostring(IP()) + ":" + x2str(Port()); } + bool Read(); bool IsOk() const { return m_state != ERROR; } bool IsDone() const { return m_state == DONE; } bool IsKeepAlive() const { return m_keepAlive; } + void SetKeepAlive() { m_keepAlive = true; } + private: static const char STG_HEADER[5]; @@ -79,10 +85,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; @@ -98,13 +103,14 @@ class Conn void * m_buffer; size_t m_bufferSize; - char m_header[sizeof(STG_HEADER)]; - char m_login[ADM_LOGIN_LEN + 1]; - char m_cryptoLogin[ADM_LOGIN_LEN + 1]; + char m_header[sizeof(STG_HEADER) - 1]; // Without \0 + char m_login[ADM_LOGIN_LEN]; // Without \0 + char m_cryptoLogin[ADM_LOGIN_LEN]; // Without \0 char m_data[1024]; STG::DECRYPT_STREAM * m_stream; + PLUGIN_LOGGER & m_logger; - BASE_PARSER * GetParser(const std::string & tag); + BASE_PARSER * GetParser(const std::string & tag) const; bool HandleBuffer(size_t size); @@ -116,6 +122,8 @@ class Conn bool WriteAnswer(const void* buffer, size_t size); bool WriteResponse(); + void Log(const char * file, const std::string & message); + struct DataState { DataState(bool f, Conn & c) : final(f), conn(c) {} @@ -123,6 +131,10 @@ class Conn Conn & conn; } m_dataState; +#ifdef DUMPCRYPTO + Dumper m_dumper; +#endif + 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);