X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/46b0747592074017ff0ea4b33d4a7194235886e5..73bee151e048054bde9a39c5ad2efec25af9c77b:/libs/ia/include/stg/ia.h?ds=sidebyside diff --git a/libs/ia/include/stg/ia.h b/libs/ia/include/stg/ia.h index c37f4394..48baed66 100644 --- a/libs/ia/include/stg/ia.h +++ b/libs/ia/include/stg/ia.h @@ -24,25 +24,27 @@ * Author : Boris Mikhailenko */ //--------------------------------------------------------------------------- -#ifndef IA_AUTH_C_H -#define IA_AUTH_C_H +#pragma once + +#include "stg/blowfish.h" +#include "stg/ia_packets.h" + +#include +#include +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#include +#pragma GCC diagnostic pop #ifndef WIN32 #include #include #include -#include #else #include #endif -#include -#include -#include - -#include "stg/blowfish.h" -#include "stg/ia_packets.h" - #define IA_BIND_ERROR (1) #define IA_SERVER_ERROR (2) #define IA_FCNTL_ERROR (3) @@ -60,147 +62,131 @@ typedef void (*tpCallBackDirNameFn)(const std::vector & dirName, vo //--------------------------------------------------------------------------- class IA_CLIENT_PROT { -#ifdef WIN32 -friend unsigned long WINAPI RunW(void * data); -#else -friend void * RunL(void * data); -#endif - -public: - IA_CLIENT_PROT(const std::string & sn, uint16_t p, const std::string & localName = "", uint16_t localPort = 0); - ~IA_CLIENT_PROT(); - - void Start(); - void Stop(); - void GetStat(LOADSTAT * ls); - - void SetServer(const std::string & sn, unsigned short port); - void SetLogin(const std::string & login); - void SetPassword(const std::string & password); - void SetEnabledDirs(const bool * selectedDirs); - - void SetStatusChangedCb(tpStatusChangedCb p, void * data); - void SetStatChangedCb(tpStatChangedCb p, void * data); - void SetInfoCb(tpCallBackInfoFn p, void * data); - void SetErrorCb(tpCallBackErrorFn p, void * data); - void SetDirNameCb(tpCallBackDirNameFn p, void * data); - - int Connect(); - int Disconnect(); - int GetAuthorized() const { return phase == 3 || phase == 4; }; - int GetPhase() const { return phase; }; - int GetStatus() const; - int GetReconnect() const { return reconnect; }; - void SetReconnect(int r) { reconnect = r; }; - char GetProtoVer() const { return proxyMode ? IA_PROTO_PROXY_VER : IA_PROTO_VER; }; - void GetMessageText(std::string * text) const { *text = messageText; }; - void GetInfoText(std::string * text) const { *text = infoText; }; - int GetStrError(std::string * error) const; - - void SetProxyMode(bool on) { proxyMode = on; }; - bool GetProxyMode() const { return proxyMode; }; - - void SetIP(uint32_t ip) { IA_CLIENT_PROT::ip = ip; }; - uint32_t GetIP() const { return ip; }; - -private: - void Run(); - int NetRecv(); - int NetSend(int n); - bool GetNonstop() const { return nonstop; }; - void PrepareNet(); - int DeterminatePacketType(const char * buffer); - - int Process_CONN_SYN_ACK_8(const char * buffer); - int Process_ALIVE_SYN_8(const char * buffer); - int Process_DISCONN_SYN_ACK_8(const char * buffer); - int Process_FIN_8(const char * buffer); - int Process_INFO_8(const char * buffer); - int Process_ERROR(const char * buffer); - - int Prepare_CONN_SYN_8(char * buffer); - int Prepare_CONN_ACK_8(char * buffer); - int Prepare_ALIVE_ACK_8(char * buffer); - int Prepare_DISCONN_SYN_8(char * buffer); - int Prepare_DISCONN_ACK_8(char * buffer); - - void FillHdr8(char * buffer, unsigned long ip); - int Send(char * buffer, int len); - int Recv(char * buffer, int len); - - LOADSTAT stat; - int action; - int phase; - int phaseTime; - std::string messageText; - std::string infoText; - mutable std::string strError; - mutable int codeError; - bool nonstop; - bool isNetPrepared; - bool proxyMode; - - BLOWFISH_CTX ctxPass; - BLOWFISH_CTX ctxHdr; - - bool selectedDirs[DIR_NUM]; - - std::string password; - std::string login; - - #ifdef WIN32 - WSADATA wsaData; - #else - pthread_t thread; - #endif - - std::string serverName; - uint16_t port; - uint32_t ip; - std::string localName; - uint32_t localIP; - uint32_t localPort; - - struct sockaddr_in servAddr; - - bool firstConnect; - int reconnect; - int sockr; - int protNum; - int userTimeout; - int aliveTimeout; - unsigned int rnd; - - tpStatusChangedCb pStatusChangedCb; - tpStatChangedCb pStatChangedCb; - tpCallBackInfoFn pInfoCb; - tpCallBackErrorFn pErrorCb; - tpCallBackDirNameFn pDirNameCb; - - void * statusChangedCbData; - void * statChangedCbData; - void * infoCbData; - void * errorCbData; - void * dirNameCbData; - - std::map packetTypes; - - CONN_SYN_8 * connSyn8; - CONN_SYN_ACK_8 * connSynAck8; - CONN_ACK_8 * connAck8; - ALIVE_SYN_8 * aliveSyn8; - ALIVE_ACK_8 * aliveAck8; - DISCONN_SYN_8 * disconnSyn8; - DISCONN_SYN_ACK_8 * disconnSynAck8; - DISCONN_ACK_8 * disconnAck8; - INFO_8 * info; + public: + IA_CLIENT_PROT(const std::string & sn, uint16_t p, const std::string & localName = "", uint16_t localPort = 0); + ~IA_CLIENT_PROT(); + + void Start(); + void Stop(); + void GetStat(LOADSTAT * ls); + + void SetServer(const std::string & sn, unsigned short port); + void SetLogin(const std::string & login); + void SetPassword(const std::string & password); + void SetEnabledDirs(const bool * selectedDirs); + + void SetStatusChangedCb(tpStatusChangedCb p, void * data); + void SetStatChangedCb(tpStatChangedCb p, void * data); + void SetInfoCb(tpCallBackInfoFn p, void * data); + void SetErrorCb(tpCallBackErrorFn p, void * data); + void SetDirNameCb(tpCallBackDirNameFn p, void * data); + + int Connect(); + int Disconnect(); + int GetAuthorized() const { return m_phase == 3 || m_phase == 4; }; + int GetPhase() const { return m_phase; }; + int GetStatus() const; + int GetReconnect() const { return m_reconnect; }; + void SetReconnect(int r) { m_reconnect = r; }; + char GetProtoVer() const { return m_proxyMode ? IA_PROTO_PROXY_VER : IA_PROTO_VER; }; + void GetMessageText(std::string * text) const { *text = m_messageText; }; + void GetInfoText(std::string * text) const { *text = m_infoText; }; + int GetStrError(std::string * error) const; + + void SetProxyMode(bool on) { m_proxyMode = on; }; + bool GetProxyMode() const { return m_proxyMode; }; + + void SetIP(uint32_t ip) { m_ip = ip; }; + uint32_t GetIP() const { return m_ip; }; + + private: + void Run(std::stop_token token); + int NetRecv(); + int NetSend(int n); + void PrepareNet(); + int DeterminatePacketType(const char * buffer); + + int Process_CONN_SYN_ACK_8(const void* buffer); + int Process_ALIVE_SYN_8(const void* buffer); + int Process_DISCONN_SYN_ACK_8(const void* buffer); + int Process_FIN_8(const void* buffer); + int Process_INFO_8(const void* buffer); + int Process_ERROR(const void* buffer); + + int Prepare_CONN_SYN_8(void* buffer); + int Prepare_CONN_ACK_8(void* buffer); + int Prepare_ALIVE_ACK_8(void* buffer); + int Prepare_DISCONN_SYN_8(void* buffer); + int Prepare_DISCONN_ACK_8(void* buffer); + + void FillHdr8(char* buffer, unsigned long ip); + int Send(char * buffer, int len); + int Recv(char * buffer, int len); + + LOADSTAT m_stat; + int m_action; + int m_phase; + int m_phaseTime; + std::string m_messageText; + std::string m_infoText; + mutable std::string m_strError; + mutable int m_codeError; + bool m_isNetPrepared; + bool m_proxyMode; + + BLOWFISH_CTX m_ctxPass; + BLOWFISH_CTX m_ctxHdr; + + bool m_selectedDirs[DIR_NUM]; + + std::string m_password; + std::string m_login; + + #ifdef WIN32 + WSADATA m_wsaData; + #else + std::jthread m_thread; + #endif + + std::string m_serverName; + uint16_t m_port; + uint32_t m_ip; + std::string m_localName; + uint32_t m_localIP; + uint32_t m_localPort; + + struct sockaddr_in m_servAddr; + + bool m_firstConnect; + int m_reconnect; + int m_sockr; + int m_protNum; + int m_userTimeout; + int m_aliveTimeout; + unsigned int m_rnd; + + tpStatusChangedCb m_pStatusChangedCb; + tpStatChangedCb m_pStatChangedCb; + tpCallBackInfoFn m_pInfoCb; + tpCallBackErrorFn m_pErrorCb; + tpCallBackDirNameFn m_pDirNameCb; + + void * m_statusChangedCbData; + void * m_statChangedCbData; + void * m_infoCbData; + void * m_errorCbData; + void * m_dirNameCbData; + + std::map m_packetTypes; + + CONN_SYN_8 * m_connSyn8; + const CONN_SYN_ACK_8 * m_connSynAck8; + CONN_ACK_8 * m_connAck8; + const ALIVE_SYN_8 * m_aliveSyn8; + ALIVE_ACK_8 * m_aliveAck8; + DISCONN_SYN_8 * m_disconnSyn8; + const DISCONN_SYN_ACK_8 * m_disconnSynAck8; + DISCONN_ACK_8 * m_disconnAck8; + const INFO_8 * m_info; }; //--------------------------------------------------------------------------- -#ifdef WIN32 -unsigned long WINAPI RunW(void *); -#else -void * RunW(void *); -#endif - -//--------------------------------------------------------------------------- -#endif //IA_AUTH_C_H