X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/750f1f62ce6576bf1ad86366a5fb8ce1c4524ccd..59fa9c93d72d1e065274dadc44a53595fd54648a:/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 e3cb3f0c..a98e593b 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/conn.h +++ b/projects/stargazer/plugins/configuration/sgconfig/conn.h @@ -18,32 +18,32 @@ * Author : Maxim Mamontov */ -#ifndef __STG_SGCONFIG_CONN_H__ -#define __STG_SGCONFIG_CONN_H__ +#pragma once #include "parser.h" -#include "stg/os_int.h" +#include "dumphelpers.h" + #include "stg/const.h" #include #include +#include #include #include -class SETTINGS; -class ADMINS; -class USERS; -class TARIFFS; -class ADMIN; -class BASE_PARSER; -class PLUGIN_LOGGER; - namespace STG { +struct Settings; +struct Admins; +struct Users; +struct Tariffs; +struct Admin; +class PluginLogger; + class DECRYPT_STREAM; class Conn @@ -51,24 +51,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 BASE_PARSER::REGISTRY & registry, - ADMINS & admins, int sock, const sockaddr_in& addr, - PLUGIN_LOGGER & logger); + Admins & admins, int sock, const sockaddr_in& addr, + PluginLogger & logger); ~Conn(); int Sock() const { return m_sock; } - uint32_t IP() const { return *(uint32_t *)(&m_addr.sin_addr); } + uint32_t IP() const { return *reinterpret_cast(&m_addr.sin_addr); } uint16_t Port() const { return ntohs(m_addr.sin_port); } + std::string endpoint() const { return inet_ntostring(IP()) + ":" + std::to_string(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]; @@ -81,9 +85,9 @@ class Conn const BASE_PARSER::REGISTRY & m_registry; - ADMINS & m_admins; + Admins & m_admins; - ADMIN * m_admin; + Admin * m_admin; int m_sock; sockaddr_in m_addr; @@ -102,7 +106,7 @@ class Conn char m_cryptoLogin[ADM_LOGIN_LEN]; // Without \0 char m_data[1024]; STG::DECRYPT_STREAM * m_stream; - PLUGIN_LOGGER & m_logger; + PluginLogger & m_logger; BASE_PARSER * GetParser(const std::string & tag) const; @@ -125,6 +129,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); @@ -132,5 +140,3 @@ class Conn }; } - -#endif