From: Maksym Mamontov Date: Sat, 27 Aug 2022 15:41:54 +0000 (+0300) Subject: Fight CLang warnings. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/b27841d687ec9e84983340b5581376dfb24010ea?hp=43ac308ea20014761481bc40525496a0bb1d9740 Fight CLang warnings. --- diff --git a/include/stg/corporations.h b/include/stg/corporations.h index 944844c6..d5898fa7 100644 --- a/include/stg/corporations.h +++ b/include/stg/corporations.h @@ -25,7 +25,7 @@ namespace STG { -struct Admin; +class Admin; struct CorpConf; struct Corporations { diff --git a/include/stg/plugin.h b/include/stg/plugin.h index c638a2f5..9e0b362c 100644 --- a/include/stg/plugin.h +++ b/include/stg/plugin.h @@ -30,8 +30,8 @@ struct TraffCounter; struct Settings; struct Store; struct Admins; -struct Users; -struct Tariffs; +class Users; +class Tariffs; struct Services; struct Corporations; struct ModuleSettings; diff --git a/include/stg/services.h b/include/stg/services.h index 5d3b2bee..41c0cf54 100644 --- a/include/stg/services.h +++ b/include/stg/services.h @@ -25,7 +25,7 @@ namespace STG { -struct Admin; +class Admin; struct ServiceConf; struct ServiceConfOpt; diff --git a/include/stg/tariffs.h b/include/stg/tariffs.h index c47b857f..959c6112 100644 --- a/include/stg/tariffs.h +++ b/include/stg/tariffs.h @@ -28,7 +28,7 @@ namespace STG { -struct Admin; +class Admin; struct Tariff; struct TariffData; diff --git a/include/stg/users.h b/include/stg/users.h index 1587f350..a0be8493 100644 --- a/include/stg/users.h +++ b/include/stg/users.h @@ -29,8 +29,8 @@ namespace STG { -struct Admin; -struct User; +class Admin; +class User; struct Auth; class Users diff --git a/libs/ia/ia.cpp b/libs/ia/ia.cpp index a05d3061..bdfa67f1 100644 --- a/libs/ia/ia.cpp +++ b/libs/ia/ia.cpp @@ -29,6 +29,14 @@ //--------------------------------------------------------------------------- +#include "stg/common.h" +#include "stg/ia.h" + +#include +#include +#include +#include + #ifdef WIN32 #include #include @@ -42,14 +50,6 @@ #include #endif -#include -#include -#include -#include - -#include "stg/common.h" -#include "stg/ia.h" - #define IA_NONE (0) #define IA_CONNECT (1) #define IA_DISCONNECT (2) @@ -75,7 +75,7 @@ sigset_t signalSet; sigfillset(&signalSet); pthread_sigmask(SIG_BLOCK, &signalSet, NULL); -IA_CLIENT_PROT * c = (IA_CLIENT_PROT *)data; +auto* c = static_cast(data); static int a = 0; if (a == 0) @@ -101,7 +101,7 @@ return tv.tv_sec*1000 + tv.tv_usec/1000; //--------------------------------------------------------------------------- unsigned long WINAPI RunW(void * data) { -IA_CLIENT_PROT * c = (IA_CLIENT_PROT *)data; +auto* c = static_cast(data); while (c->GetNonstop()) c->Run(); return 0; @@ -120,7 +120,7 @@ if (ip == INADDR_NONE) hostent * phe = gethostbyname(hostName.c_str()); if (phe) { - ip = *((uint32_t *)phe->h_addr_list[0]); + ip = *reinterpret_cast(phe->h_addr_list[0]); } else { @@ -138,81 +138,79 @@ return true; //--------------------------------------------------------------------------- IA_CLIENT_PROT::IA_CLIENT_PROT(const std::string & sn, unsigned short p, const std::string & ln, uint16_t lp) - : action(IA_NONE), - phase(1), - phaseTime(0), - codeError(0), - nonstop(false), - isNetPrepared(false), - proxyMode(false), - serverName(sn), - port(p), - ip(0), - localName(ln), - localPort(lp), - firstConnect(true), - reconnect(0), - sockr(0), - protNum(0), - userTimeout(60), - aliveTimeout(5), - rnd(0), - pStatusChangedCb(NULL), - pStatChangedCb(NULL), - pInfoCb(NULL), - pErrorCb(NULL), - pDirNameCb(NULL), - statusChangedCbData(NULL), - statChangedCbData(NULL), - infoCbData(NULL), - errorCbData(NULL), - dirNameCbData(NULL), - connSyn8(NULL), - connSynAck8(NULL), - connAck8(NULL), - aliveSyn8(NULL), - aliveAck8(NULL), - disconnSyn8(NULL), - disconnSynAck8(NULL), - disconnAck8(NULL), - info(NULL) -{ -memset(&stat, 0, sizeof(stat)); + : m_action(IA_NONE), + m_phase(1), + m_phaseTime(0), + m_codeError(0), + m_nonstop(false), + m_isNetPrepared(false), + m_proxyMode(false), + m_serverName(sn), + m_port(p), + m_ip(0), + m_localName(ln), + m_localPort(lp), + m_firstConnect(true), + m_reconnect(0), + m_sockr(0), + m_protNum(0), + m_userTimeout(60), + m_aliveTimeout(5), + m_rnd(0), + m_pStatusChangedCb(NULL), + m_pStatChangedCb(NULL), + m_pInfoCb(NULL), + m_pErrorCb(NULL), + m_pDirNameCb(NULL), + m_statusChangedCbData(NULL), + m_statChangedCbData(NULL), + m_infoCbData(NULL), + m_errorCbData(NULL), + m_dirNameCbData(NULL), + m_connSyn8(NULL), + m_connSynAck8(NULL), + m_connAck8(NULL), + m_aliveSyn8(NULL), + m_aliveAck8(NULL), + m_disconnSyn8(NULL), + m_disconnSynAck8(NULL), + m_disconnAck8(NULL), + m_info(NULL) +{ +memset(&m_stat, 0, sizeof(m_stat)); #ifdef WIN32 -WSAStartup(MAKEWORD(2, 0), &wsaData); +WSAStartup(MAKEWORD(2, 0), &m_wsaData); #endif -packetTypes["CONN_SYN"] = CONN_SYN_N; -packetTypes["CONN_SYN_ACK"] = CONN_SYN_ACK_N; -packetTypes["CONN_ACK"] = CONN_ACK_N; -packetTypes["ALIVE_SYN"] = ALIVE_SYN_N; -packetTypes["ALIVE_ACK"] = ALIVE_ACK_N; -packetTypes["DISCONN_SYN"] = DISCONN_SYN_N; -packetTypes["DISCONN_SYN_ACK"] = DISCONN_SYN_ACK_N; -packetTypes["DISCONN_ACK"] = DISCONN_ACK_N; -packetTypes["FIN"] = FIN_N; -packetTypes["ERR"] = ERROR_N; -packetTypes["INFO"] = INFO_N; -packetTypes["INFO_7"] = INFO_7_N; -packetTypes["INFO_8"] = INFO_8_N; - -unsigned char key[IA_PASSWD_LEN]; +m_packetTypes["CONN_SYN"] = CONN_SYN_N; +m_packetTypes["CONN_SYN_ACK"] = CONN_SYN_ACK_N; +m_packetTypes["CONN_ACK"] = CONN_ACK_N; +m_packetTypes["ALIVE_SYN"] = ALIVE_SYN_N; +m_packetTypes["ALIVE_ACK"] = ALIVE_ACK_N; +m_packetTypes["DISCONN_SYN"] = DISCONN_SYN_N; +m_packetTypes["DISCONN_SYN_ACK"] = DISCONN_SYN_ACK_N; +m_packetTypes["DISCONN_ACK"] = DISCONN_ACK_N; +m_packetTypes["FIN"] = FIN_N; +m_packetTypes["ERR"] = ERROR_N; +m_packetTypes["INFO"] = INFO_N; +m_packetTypes["INFO_7"] = INFO_7_N; +m_packetTypes["INFO_8"] = INFO_8_N; + +char key[IA_PASSWD_LEN]; memset(key, 0, IA_PASSWD_LEN); -strncpy((char *)key, "pr7Hhen", 8); -Blowfish_Init(&ctxHdr, key, IA_PASSWD_LEN); +strncpy(key, "pr7Hhen", 8); +Blowfish_Init(&m_ctxHdr, key, IA_PASSWD_LEN); memset(key, 0, IA_PASSWD_LEN); -Blowfish_Init(&ctxPass, key, IA_PASSWD_LEN); +Blowfish_Init(&m_ctxPass, key, IA_PASSWD_LEN); for (size_t i = 0; i < DIR_NUM; ++i) - { - selectedDirs[i] = false; - } + m_selectedDirs[i] = false; -servAddr.sin_family = AF_INET; -servAddr.sin_port = htons(port); -servAddr.sin_addr.s_addr = ip; +m_servAddr.sin_family = AF_INET; +m_servAddr.sin_port = htons(m_port); +m_servAddr.sin_addr.s_addr = m_ip; } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::PrepareNet() @@ -237,74 +235,74 @@ if (ip == INADDR_NONE) } }*/ -if (!HostNameToIP(serverName, ip)) +if (!HostNameToIP(m_serverName, m_ip)) { - ip = 0; - strError = std::string("Unknown host ") + "\'" + serverName + "\'"; - codeError = IA_GETHOSTBYNAME_ERROR; - if (pErrorCb != NULL) - pErrorCb(strError, IA_GETHOSTBYNAME_ERROR, errorCbData); + m_ip = 0; + m_strError = std::string("Unknown host ") + "\'" + m_serverName + "\'"; + m_codeError = IA_GETHOSTBYNAME_ERROR; + if (m_pErrorCb != NULL) + m_pErrorCb(m_strError, IA_GETHOSTBYNAME_ERROR, m_errorCbData); return; } #ifndef WIN32 -close(sockr); +close(m_sockr); #else -closesocket(sockr); +closesocket(m_sockr); #endif -sockr = socket(AF_INET, SOCK_DGRAM, 0); +m_sockr = socket(AF_INET, SOCK_DGRAM, 0); struct sockaddr_in localAddrR; localAddrR.sin_family = AF_INET; -if (localPort) - localAddrR.sin_port = htons(localPort); +if (m_localPort) + localAddrR.sin_port = htons(m_localPort); else - localAddrR.sin_port = htons(port); + localAddrR.sin_port = htons(m_port); -if (!localName.empty()) +if (!m_localName.empty()) { - if (!HostNameToIP(localName, localIP)) + if (!HostNameToIP(m_localName, m_localIP)) { - strError = std::string("Unknown host ") + "\'" + serverName + "\'"; - codeError = IA_GETHOSTBYNAME_ERROR; - if (pErrorCb != NULL) - pErrorCb(strError, IA_GETHOSTBYNAME_ERROR, errorCbData); - localIP = INADDR_ANY; + m_strError = std::string("Unknown host ") + "\'" + m_serverName + "\'"; + m_codeError = IA_GETHOSTBYNAME_ERROR; + if (m_pErrorCb != NULL) + m_pErrorCb(m_strError, IA_GETHOSTBYNAME_ERROR, m_errorCbData); + m_localIP = INADDR_ANY; } } else { - localIP = INADDR_ANY; + m_localIP = INADDR_ANY; } -localAddrR.sin_addr.s_addr = localIP; +localAddrR.sin_addr.s_addr = m_localIP; -servAddr.sin_family = AF_INET; -servAddr.sin_port = htons(port); -servAddr.sin_addr.s_addr = ip; +m_servAddr.sin_family = AF_INET; +m_servAddr.sin_port = htons(m_port); +m_servAddr.sin_addr.s_addr = m_ip; -int res = bind(sockr, (struct sockaddr*)&localAddrR, sizeof(localAddrR)); +int res = bind(m_sockr, reinterpret_cast(&localAddrR), sizeof(localAddrR)); if (res == -1) { - strError = "bind error"; - codeError = IA_BIND_ERROR; - if (pErrorCb != NULL) - pErrorCb(strError, IA_BIND_ERROR, errorCbData); + m_strError = "bind error"; + m_codeError = IA_BIND_ERROR; + if (m_pErrorCb != NULL) + m_pErrorCb(m_strError, IA_BIND_ERROR, m_errorCbData); return; } #ifdef WIN32 unsigned long arg = 1; -ioctlsocket(sockr, FIONBIO, &arg); +ioctlsocket(m_sockr, FIONBIO, &arg); #else -if (0 != fcntl(sockr, F_SETFL, O_NONBLOCK)) +if (0 != fcntl(m_sockr, F_SETFL, O_NONBLOCK)) { - strError = "fcntl error"; - codeError = IA_FCNTL_ERROR; - if (pErrorCb != NULL) - pErrorCb(strError, IA_FCNTL_ERROR, errorCbData); + m_strError = "fcntl error"; + m_codeError = IA_FCNTL_ERROR; + if (m_pErrorCb != NULL) + m_pErrorCb(m_strError, IA_FCNTL_ERROR, m_errorCbData); } #endif @@ -313,9 +311,9 @@ if (0 != fcntl(sockr, F_SETFL, O_NONBLOCK)) IA_CLIENT_PROT::~IA_CLIENT_PROT() { #ifndef WIN32 -close(sockr); +close(m_sockr); #else -closesocket(sockr); +closesocket(m_sockr); WSACleanup(); #endif } @@ -323,8 +321,8 @@ WSACleanup(); int IA_CLIENT_PROT::DeterminatePacketType(const char * buffer) { std::map::iterator pi; -pi = packetTypes.find(buffer); -if (pi == packetTypes.end()) +pi = m_packetTypes.find(buffer); +if (pi == m_packetTypes.end()) { return -1; } @@ -334,30 +332,30 @@ else } } //--------------------------------------------------------------------------- -void IA_CLIENT_PROT::FillHdr8(char * buffer, unsigned long) +void IA_CLIENT_PROT::FillHdr8(char* buffer, unsigned long) { strncpy(buffer, IA_ID, 6); buffer[IA_MAGIC_LEN] = 0; buffer[IA_MAGIC_LEN + 1] = IA_PROTO_VER; -strncpy(buffer + sizeof(HDR_8), login.c_str(), IA_LOGIN_LEN); +strncpy(buffer + sizeof(HDR_8), m_login.c_str(), IA_LOGIN_LEN); } //--------------------------------------------------------------------------- int IA_CLIENT_PROT::Send(char * buffer, int len) { -if (!isNetPrepared) +if (!m_isNetPrepared) { PrepareNet(); - isNetPrepared = true; + m_isNetPrepared = true; } int db = sizeof(HDR_8); -EncryptString(buffer + db, buffer + db, IA_LOGIN_LEN, &ctxHdr); +EncryptString(buffer + db, buffer + db, IA_LOGIN_LEN, &m_ctxHdr); db += IA_LOGIN_LEN; int encLen = (len - sizeof(HDR_8) - IA_LOGIN_LEN); -EncryptString(buffer + db, buffer + db, encLen, &ctxPass); +EncryptString(buffer + db, buffer + db, encLen, &m_ctxPass); -return sendto(sockr, buffer, len, 0, (struct sockaddr*)&servAddr, sizeof(servAddr)); +return sendto(m_sockr, buffer, len, 0, reinterpret_cast(&m_servAddr), sizeof(m_servAddr)); } //--------------------------------------------------------------------------- int IA_CLIENT_PROT::Recv(char * buffer, int len) @@ -370,13 +368,13 @@ socklen_t fromLen; struct sockaddr_in addr; fromLen = sizeof(addr); -int res = recvfrom(sockr, buffer, len, 0, (struct sockaddr*)&addr, &fromLen); +int res = recvfrom(m_sockr, buffer, len, 0, reinterpret_cast(&addr), &fromLen); if (res == -1) return res; if (strcmp(buffer + 4 + sizeof(HDR_8), "ERR")) - DecryptString(buffer, buffer, len, &ctxPass); + DecryptString(buffer, buffer, len, &m_ctxPass); return 0; } @@ -467,113 +465,113 @@ return ret; //--------------------------------------------------------------------------- void IA_CLIENT_PROT::Start() { -nonstop = true; +m_nonstop = true; #ifdef WIN32 unsigned long pt; CreateThread(NULL, 16384, RunW, this, 0, &pt); #else -pthread_create(&thread, NULL, RunL, this); +pthread_create(&m_thread, NULL, RunL, this); #endif } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::Stop() { -nonstop = false; +m_nonstop = false; } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::Run() { NetRecv(); -switch (phase) +switch (m_phase) { case 1: - if (action == IA_CONNECT) + if (m_action == IA_CONNECT) { - action = IA_NONE; + m_action = IA_NONE; NetSend(CONN_SYN_N); - phase = 2; - phaseTime = GetTickCount(); + m_phase = 2; + m_phaseTime = GetTickCount(); } - if (reconnect && !firstConnect) + if (m_reconnect && !m_firstConnect) { - action = IA_CONNECT; + m_action = IA_CONNECT; } break; case 2: - if ((int)(GetTickCount() - phaseTime)/1000 > aliveTimeout) + if (static_cast(GetTickCount() - m_phaseTime)/1000 > m_aliveTimeout) { - phase = 1; - phaseTime = GetTickCount(); - if (pStatusChangedCb != NULL) - pStatusChangedCb(0, statusChangedCbData); + m_phase = 1; + m_phaseTime = GetTickCount(); + if (m_pStatusChangedCb != NULL) + m_pStatusChangedCb(0, m_statusChangedCbData); } - if (action == IA_DISCONNECT) + if (m_action == IA_DISCONNECT) { - action = IA_NONE; + m_action = IA_NONE; NetSend(DISCONN_SYN_N); - phase = 4; - phaseTime = GetTickCount(); + m_phase = 4; + m_phaseTime = GetTickCount(); } break; case 3: - if ((int)(GetTickCount() - phaseTime)/1000 > userTimeout) + if (static_cast(GetTickCount() - m_phaseTime)/1000 > m_userTimeout) { - phase = 1; - phaseTime = GetTickCount(); - if (pStatusChangedCb != NULL) - pStatusChangedCb(0, statusChangedCbData); - firstConnect = false; + m_phase = 1; + m_phaseTime = GetTickCount(); + if (m_pStatusChangedCb != NULL) + m_pStatusChangedCb(0, m_statusChangedCbData); + m_firstConnect = false; } - if (action == IA_DISCONNECT) + if (m_action == IA_DISCONNECT) { - action = IA_NONE; + m_action = IA_NONE; NetSend(DISCONN_SYN_N); - phase = 4; - phaseTime = GetTickCount(); + m_phase = 4; + m_phaseTime = GetTickCount(); } break; case 4: - if ((int)(GetTickCount() - phaseTime)/1000 > aliveTimeout) + if (static_cast(GetTickCount() - m_phaseTime)/1000 > m_aliveTimeout) { - phase=1; - phaseTime = GetTickCount(); - if (pStatusChangedCb != NULL) - pStatusChangedCb(0, statusChangedCbData); + m_phase=1; + m_phaseTime = GetTickCount(); + if (m_pStatusChangedCb != NULL) + m_pStatusChangedCb(0, m_statusChangedCbData); } - if (action == IA_CONNECT) + if (m_action == IA_CONNECT) { - action = IA_NONE; + m_action = IA_NONE; NetSend(CONN_SYN_N); - phase = 2; - phaseTime = GetTickCount(); + m_phase = 2; + m_phaseTime = GetTickCount(); } break; case 5: - if ((int)(GetTickCount() - phaseTime)/1000 > aliveTimeout) + if (static_cast(GetTickCount() - m_phaseTime)/1000 > m_aliveTimeout) { - phase = 1; - phaseTime = GetTickCount(); - if (pStatusChangedCb != NULL) - pStatusChangedCb(0, statusChangedCbData); + m_phase = 1; + m_phaseTime = GetTickCount(); + if (m_pStatusChangedCb != NULL) + m_pStatusChangedCb(0, m_statusChangedCbData); } - if (action == IA_CONNECT) + if (m_action == IA_CONNECT) { - action = IA_NONE; + m_action = IA_NONE; NetSend(CONN_SYN_N); - phase = 2; - phaseTime = GetTickCount(); + m_phase = 2; + m_phaseTime = GetTickCount(); } break; @@ -584,164 +582,162 @@ return; //--------------------------------------------------------------------------- void IA_CLIENT_PROT::GetStat(LOADSTAT * ls) { -memcpy(ls, &stat, sizeof(stat)); +memcpy(ls, &m_stat, sizeof(m_stat)); } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::SetServer(const std::string & sn, unsigned short p) { -serverName = sn; -port = p; +m_serverName = sn; +m_port = p; PrepareNet(); } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::SetLogin(const std::string & l) { -login = l; +m_login = l; } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::SetPassword(const std::string & p) { -password = p; +m_password = p; -unsigned char keyL[IA_PASSWD_LEN]; +char keyL[IA_PASSWD_LEN]; memset(keyL, 0, IA_PASSWD_LEN); -strncpy((char *)keyL, password.c_str(), IA_PASSWD_LEN); -Blowfish_Init(&ctxPass, keyL, IA_PASSWD_LEN); +strncpy(keyL, m_password.c_str(), IA_PASSWD_LEN); +Blowfish_Init(&m_ctxPass, keyL, IA_PASSWD_LEN); } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::SetEnabledDirs(const bool * selectedDirs) { -memcpy(IA_CLIENT_PROT::selectedDirs, selectedDirs, sizeof(bool) * DIR_NUM); +memcpy(m_selectedDirs, selectedDirs, sizeof(bool) * DIR_NUM); } //--------------------------------------------------------------------------- int IA_CLIENT_PROT::Connect() { -action = IA_CONNECT; +m_action = IA_CONNECT; return 0; } //--------------------------------------------------------------------------- int IA_CLIENT_PROT::Disconnect() { -firstConnect = true; -action = IA_DISCONNECT; +m_firstConnect = true; +m_action = IA_DISCONNECT; return 0; } //--------------------------------------------------------------------------- int IA_CLIENT_PROT::GetStrError(std::string * error) const { -int ret = codeError; -*error = strError; -strError = ""; -codeError = 0; +int ret = m_codeError; +*error = m_strError; +m_strError = ""; +m_codeError = 0; return ret; } //--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Process_CONN_SYN_ACK_8(const char * buffer) +int IA_CLIENT_PROT::Process_CONN_SYN_ACK_8(const void* buffer) { std::vector dirNames; -connSynAck8 = (CONN_SYN_ACK_8*)buffer; +m_connSynAck8 = static_cast(buffer); #ifdef ARCH_BE -SwapBytes(connSynAck8->len); -SwapBytes(connSynAck8->rnd); -SwapBytes(connSynAck8->userTimeOut); -SwapBytes(connSynAck8->aliveDelay); +SwapBytes(m_connSynAck8->len); +SwapBytes(m_connSynAck8->rnd); +SwapBytes(m_connSynAck8->userTimeOut); +SwapBytes(m_connSynAck8->aliveDelay); #endif -rnd = connSynAck8->rnd; -userTimeout = connSynAck8->userTimeOut; -aliveTimeout = connSynAck8->aliveDelay; +m_rnd = m_connSynAck8->rnd; +m_userTimeout = m_connSynAck8->userTimeOut; +m_aliveTimeout = m_connSynAck8->aliveDelay; for (int i = 0; i < DIR_NUM; i++) - { - dirNames.push_back((const char*)connSynAck8->dirName[i]); - } + dirNames.push_back(reinterpret_cast(m_connSynAck8->dirName[i])); -if (pDirNameCb != NULL) - pDirNameCb(dirNames, dirNameCbData); +if (m_pDirNameCb != NULL) + m_pDirNameCb(dirNames, m_dirNameCbData); NetSend(CONN_ACK_N); -phase = 3; -phaseTime = GetTickCount(); +m_phase = 3; +m_phaseTime = GetTickCount(); return CONN_SYN_ACK_N; } //--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Process_ALIVE_SYN_8(const char * buffer) +int IA_CLIENT_PROT::Process_ALIVE_SYN_8(const void* buffer) { -aliveSyn8 = (ALIVE_SYN_8*)buffer; +m_aliveSyn8 = static_cast(buffer); #ifdef ARCH_BE -SwapBytes(aliveSyn8->len); -SwapBytes(aliveSyn8->rnd); -SwapBytes(aliveSyn8->cash); -SwapBytes(aliveSyn8->status); +SwapBytes(m_aliveSyn8->len); +SwapBytes(m_aliveSyn8->rnd); +SwapBytes(m_aliveSyn8->cash); +SwapBytes(m_aliveSyn8->status); for (int i = 0; i < DIR_NUM; ++i) { - SwapBytes(aliveSyn8->mu[i]); - SwapBytes(aliveSyn8->md[i]); - SwapBytes(aliveSyn8->su[i]); - SwapBytes(aliveSyn8->sd[i]); + SwapBytes(m_aliveSyn8->mu[i]); + SwapBytes(m_aliveSyn8->md[i]); + SwapBytes(m_aliveSyn8->su[i]); + SwapBytes(m_aliveSyn8->sd[i]); } #endif -rnd = aliveSyn8->rnd; -memcpy(&stat, (char*)aliveSyn8->mu, sizeof(stat)); +m_rnd = m_aliveSyn8->rnd; +memcpy(&m_stat, m_aliveSyn8->mu, sizeof(m_stat)); -if (pStatChangedCb != NULL) - pStatChangedCb(stat, statChangedCbData); +if (m_pStatChangedCb != NULL) + m_pStatChangedCb(m_stat, m_statChangedCbData); -if (pStatusChangedCb != NULL) - pStatusChangedCb(1, statusChangedCbData); +if (m_pStatusChangedCb != NULL) + m_pStatusChangedCb(1, m_statusChangedCbData); NetSend(ALIVE_ACK_N); -phaseTime = GetTickCount(); +m_phaseTime = GetTickCount(); return ALIVE_SYN_N; } //--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Process_DISCONN_SYN_ACK_8(const char * buffer) +int IA_CLIENT_PROT::Process_DISCONN_SYN_ACK_8(const void* buffer) { -disconnSynAck8 = (DISCONN_SYN_ACK_8*)buffer; +m_disconnSynAck8 = static_cast(buffer); #ifdef ARCH_BE -SwapBytes(disconnSynAck8->len); -SwapBytes(disconnSynAck8->rnd); +SwapBytes(m_disconnSynAck8->len); +SwapBytes(m_disconnSynAck8->rnd); #endif -rnd = disconnSynAck8->rnd; +m_rnd = m_disconnSynAck8->rnd; NetSend(DISCONN_ACK_N); -phase = 5; -phaseTime = GetTickCount(); +m_phase = 5; +m_phaseTime = GetTickCount(); return DISCONN_SYN_ACK_N; } //--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Process_FIN_8(const char *) +int IA_CLIENT_PROT::Process_FIN_8(const void*) { -phase = 1; -phaseTime = GetTickCount(); -if (pStatusChangedCb != NULL) - pStatusChangedCb(0, statusChangedCbData); +m_phase = 1; +m_phaseTime = GetTickCount(); +if (m_pStatusChangedCb != NULL) + m_pStatusChangedCb(0, m_statusChangedCbData); return FIN_N; } //--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Process_INFO_8(const char * buffer) +int IA_CLIENT_PROT::Process_INFO_8(const void* buffer) { -info = (INFO_8*)buffer; +m_info = static_cast(buffer); #ifdef ARCH_BE -SwapBytes(info->len); -SwapBytes(info->sendTime); +SwapBytes(m_info->len); +SwapBytes(m_info->sendTime); #endif -if (pInfoCb != NULL) - pInfoCb((char*)info->text, info->infoType, info->showTime, info->sendTime, infoCbData); +if (m_pInfoCb != NULL) + m_pInfoCb(reinterpret_cast(m_info->text), m_info->infoType, m_info->showTime, m_info->sendTime, m_infoCbData); return INFO_8_N; } //--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Process_ERROR(const char * buffer) +int IA_CLIENT_PROT::Process_ERROR(const void* buffer) { ERR_8 err; memcpy(&err, buffer, sizeof(err)); @@ -750,142 +746,139 @@ memcpy(&err, buffer, sizeof(err)); SwapBytes(err.len); #endif -KOIToWin((const char*)err.text, &messageText); -if (pErrorCb != NULL) - pErrorCb(messageText, IA_SERVER_ERROR, errorCbData); -phase = 1; -phaseTime = GetTickCount(); -codeError = IA_SERVER_ERROR; +KOIToWin(reinterpret_cast(err.text), &m_messageText); +if (m_pErrorCb != NULL) + m_pErrorCb(m_messageText, IA_SERVER_ERROR, m_errorCbData); +m_phase = 1; +m_phaseTime = GetTickCount(); +m_codeError = IA_SERVER_ERROR; return ERROR_N; } //--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Prepare_CONN_SYN_8(char * buffer) +int IA_CLIENT_PROT::Prepare_CONN_SYN_8(void* buffer) { -connSyn8 = (CONN_SYN_8*)buffer; +m_connSyn8 = static_cast(buffer); assert(sizeof(CONN_SYN_8) == Min8(sizeof(CONN_SYN_8)) && "CONN_SYN_8 is not aligned to 8 bytes"); -connSyn8->len = sizeof(CONN_SYN_8); +m_connSyn8->len = sizeof(CONN_SYN_8); #ifdef ARCH_BE -SwapBytes(connSyn8->len); +SwapBytes(m_connSyn8->len); #endif -strncpy((char*)connSyn8->type, "CONN_SYN", IA_MAX_TYPE_LEN); -strncpy((char*)connSyn8->login, login.c_str(), IA_LOGIN_LEN); -connSyn8->dirs = 0; +strncpy(reinterpret_cast(m_connSyn8->type), "CONN_SYN", IA_MAX_TYPE_LEN); +strncpy(reinterpret_cast(m_connSyn8->login), m_login.c_str(), IA_LOGIN_LEN); +m_connSyn8->dirs = 0; for (int i = 0; i < DIR_NUM; i++) - { - connSyn8->dirs |= (selectedDirs[i] << i); - } + m_connSyn8->dirs |= (m_selectedDirs[i] << i); return sizeof(CONN_SYN_8); } //--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Prepare_CONN_ACK_8(char * buffer) +int IA_CLIENT_PROT::Prepare_CONN_ACK_8(void* buffer) { -connAck8 = (CONN_ACK_8*)buffer; +m_connAck8 = static_cast(buffer); assert(sizeof(CONN_ACK_8) == Min8(sizeof(CONN_ACK_8)) && "CONN_ACK_8 is not aligned to 8 bytes"); -connAck8->len = sizeof(CONN_ACK_8); -strncpy((char*)connAck8->loginS, login.c_str(), IA_LOGIN_LEN); -strncpy((char*)connAck8->type, "CONN_ACK", IA_MAX_TYPE_LEN); -rnd++; -connAck8->rnd = rnd; +m_connAck8->len = sizeof(CONN_ACK_8); +strncpy(reinterpret_cast(m_connAck8->loginS), m_login.c_str(), IA_LOGIN_LEN); +strncpy(reinterpret_cast(m_connAck8->type), "CONN_ACK", IA_MAX_TYPE_LEN); +m_rnd++; +m_connAck8->rnd = m_rnd; #ifdef ARCH_BE -SwapBytes(connAck8->len); -SwapBytes(connAck8->rnd); +SwapBytes(m_connAck8->len); +SwapBytes(m_connAck8->rnd); #endif return sizeof(CONN_ACK_8); } //--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Prepare_ALIVE_ACK_8(char * buffer) +int IA_CLIENT_PROT::Prepare_ALIVE_ACK_8(void* buffer) { -aliveAck8 = (ALIVE_ACK_8*)buffer; +m_aliveAck8 = static_cast(buffer); assert(Min8(sizeof(ALIVE_ACK_8)) == sizeof(ALIVE_ACK_8) && "ALIVE_ACK_8 is not aligned to 8 bytes"); -aliveAck8 = (ALIVE_ACK_8*)buffer; -aliveAck8->len = sizeof(ALIVE_ACK_8); -strncpy((char*)aliveAck8->loginS, login.c_str(), IA_LOGIN_LEN); -strncpy((char*)aliveAck8->type, "ALIVE_ACK", IA_MAX_TYPE_LEN); -aliveAck8->rnd = ++rnd; +m_aliveAck8->len = sizeof(ALIVE_ACK_8); +strncpy(reinterpret_cast(m_aliveAck8->loginS), m_login.c_str(), IA_LOGIN_LEN); +strncpy(reinterpret_cast(m_aliveAck8->type), "ALIVE_ACK", IA_MAX_TYPE_LEN); +m_aliveAck8->rnd = ++m_rnd; #ifdef ARCH_BE -SwapBytes(aliveAck8->len); -SwapBytes(aliveAck8->rnd); +SwapBytes(m_aliveAck8->len); +SwapBytes(m_aliveAck8->rnd); #endif return sizeof(ALIVE_ACK_8); } //--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Prepare_DISCONN_SYN_8(char * buffer) +int IA_CLIENT_PROT::Prepare_DISCONN_SYN_8(void* buffer) { -disconnSyn8 = (DISCONN_SYN_8*)buffer; +m_disconnSyn8 = static_cast(buffer); assert(Min8(sizeof(DISCONN_SYN_8)) == sizeof(DISCONN_SYN_8) && "DISCONN_SYN_8 is not aligned to 8 bytes"); -disconnSyn8->len = sizeof(DISCONN_SYN_8); +m_disconnSyn8->len = sizeof(DISCONN_SYN_8); #ifdef ARCH_BE -SwapBytes(disconnSyn8->len); +SwapBytes(m_disconnSyn8->len); #endif -strncpy((char*)disconnSyn8->loginS, login.c_str(), IA_LOGIN_LEN); -strncpy((char*)disconnSyn8->type, "DISCONN_SYN", IA_MAX_TYPE_LEN); -strncpy((char*)disconnSyn8->login, login.c_str(), IA_LOGIN_LEN); +strncpy(reinterpret_cast(m_disconnSyn8->loginS), m_login.c_str(), IA_LOGIN_LEN); +strncpy(reinterpret_cast(m_disconnSyn8->type), "DISCONN_SYN", IA_MAX_TYPE_LEN); +strncpy(reinterpret_cast(m_disconnSyn8->login), m_login.c_str(), IA_LOGIN_LEN); return sizeof(DISCONN_SYN_8); } //--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Prepare_DISCONN_ACK_8(char * buffer) +int IA_CLIENT_PROT::Prepare_DISCONN_ACK_8(void* buffer) { -disconnAck8 = (DISCONN_ACK_8*)buffer; +m_disconnAck8 = static_cast(buffer); assert(Min8(sizeof(DISCONN_ACK_8)) == sizeof(DISCONN_ACK_8) && "DISCONN_ACK_8 is not aligned to 8 bytes"); -disconnAck8->len = Min8(sizeof(DISCONN_ACK_8)); -disconnAck8->rnd = rnd + 1; +m_disconnAck8->len = Min8(sizeof(DISCONN_ACK_8)); +m_disconnAck8->rnd = m_rnd + 1; #ifdef ARCH_BE -SwapBytes(disconnAck8->len); -SwapBytes(disconnAck8->rnd); +SwapBytes(m_disconnAck8->len); +SwapBytes(m_disconnAck8->rnd); #endif -strncpy((char*)disconnAck8->loginS, login.c_str(), IA_LOGIN_LEN); -strncpy((char*)disconnAck8->type, "DISCONN_ACK", IA_MAX_TYPE_LEN); +strncpy(reinterpret_cast(m_disconnAck8->loginS), m_login.c_str(), IA_LOGIN_LEN); +strncpy(reinterpret_cast(m_disconnAck8->type), "DISCONN_ACK", IA_MAX_TYPE_LEN); return Min8(sizeof(DISCONN_ACK_8)); } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::SetStatusChangedCb(tpStatusChangedCb p, void * data) { -pStatusChangedCb = p; -statusChangedCbData = data; +m_pStatusChangedCb = p; +m_statusChangedCbData = data; } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::SetStatChangedCb(tpStatChangedCb p, void * data) { -pStatChangedCb = p; -statChangedCbData = data; +m_pStatChangedCb = p; +m_statChangedCbData = data; } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::SetInfoCb(tpCallBackInfoFn p, void * data) { -pInfoCb = p; -infoCbData = data; +m_pInfoCb = p; +m_infoCbData = data; } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::SetDirNameCb(tpCallBackDirNameFn p, void * data) { -pDirNameCb = p; -dirNameCbData = data; +m_pDirNameCb = p; +m_dirNameCbData = data; } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::SetErrorCb(tpCallBackErrorFn p, void * data) { -pErrorCb = p; -errorCbData = data; +m_pErrorCb = p; +m_errorCbData = data; } //--------------------------------------------------------------------------- diff --git a/libs/ia/include/stg/ia.h b/libs/ia/include/stg/ia.h index c37f4394..11030a7e 100644 --- a/libs/ia/include/stg/ia.h +++ b/libs/ia/include/stg/ia.h @@ -24,8 +24,14 @@ * 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 #ifndef WIN32 #include @@ -36,13 +42,6 @@ #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) @@ -66,134 +65,134 @@ friend unsigned long WINAPI RunW(void * data); 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(); + int NetRecv(); + int NetSend(int n); + bool GetNonstop() const { return m_nonstop; }; + 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_nonstop; + 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 + pthread_t 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 @@ -201,6 +200,3 @@ unsigned long WINAPI RunW(void *); #else void * RunW(void *); #endif - -//--------------------------------------------------------------------------- -#endif //IA_AUTH_C_H diff --git a/libs/pinger/include/stg/pinger.h b/libs/pinger/include/stg/pinger.h index 26f5f4b3..b726a751 100644 --- a/libs/pinger/include/stg/pinger.h +++ b/libs/pinger/include/stg/pinger.h @@ -4,13 +4,13 @@ $Author: nobunaga $ */ -#ifndef PINGER_H -#define PINGER_H +#pragma once -#include #include #include #include +#include +#include #ifdef LINUX #include @@ -27,26 +27,24 @@ #include #endif -#include - //----------------------------------------------------------------------------- struct ICMP_HDR { -uint8_t type; -uint8_t code; -uint16_t checksum; -union + uint8_t type; + uint8_t code; + uint16_t checksum; + union { - struct + struct { - uint16_t id; - uint16_t sequence; + uint16_t id; + uint16_t sequence; } echo; - uint32_t gateway; - struct + uint32_t gateway; + struct { - uint16_t unused; - uint16_t mtu; + uint16_t unused; + uint16_t mtu; } frag; } un; }; @@ -68,8 +66,8 @@ struct IP_HDR //----------------------------------------------------------------------------- struct PING_IP_TIME { -uint32_t ip; -time_t pingTime; + uint32_t ip; + time_t pingTime; }; //----------------------------------------------------------------------------- @@ -83,53 +81,51 @@ struct PING_MESSAGE //----------------------------------------------------------------------------- class STG_PINGER { -public: - typedef std::multimap PingIPs; - typedef PingIPs::size_type SizeType; - - explicit STG_PINGER(time_t delay = 15); - ~STG_PINGER(); - - int Start(); - int Stop(); - void AddIP(uint32_t ip); - void DelIP(uint32_t ip); - SizeType GetPingIPNum() const { return pingIP.size(); } - void PrintAllIP(); - int GetIPTime(uint32_t ip, time_t * t) const; - void SetDelayTime(time_t d) { delay = d; } - time_t GetDelayTime() const { return delay; } - const std::string & GetStrError() const { return errorStr; } - -private: - uint16_t PingCheckSum(void * data, int len); - int SendPing(uint32_t ip); - uint32_t RecvPing(); - void RealAddIP(); - void RealDelIP(); - - static void * RunSendPing(void * d); - static void * RunRecvPing(void * d); - - time_t delay; - bool nonstop; - bool isRunningRecver; - bool isRunningSender; - int sendSocket; - int recvSocket; - pthread_t sendThread; - pthread_t recvThread; - - PING_MESSAGE pmSend; - uint32_t pid; - - std::string errorStr; - - std::multimap pingIP; - std::list ipToAdd; - std::list ipToDel; - - mutable pthread_mutex_t mutex; + public: + typedef std::multimap PingIPs; + typedef PingIPs::size_type SizeType; + + explicit STG_PINGER(time_t delay = 15); + ~STG_PINGER(); + + int Start(); + int Stop(); + void AddIP(uint32_t ip); + void DelIP(uint32_t ip); + SizeType GetPingIPNum() const { return m_pingIP.size(); } + void PrintAllIP(); + int GetIPTime(uint32_t ip, time_t * t) const; + void SetDelayTime(time_t d) { m_delay = d; } + time_t GetDelayTime() const { return m_delay; } + const std::string & GetStrError() const { return m_errorStr; } + + private: + uint16_t PingCheckSum(void * data, int len); + int SendPing(uint32_t ip); + uint32_t RecvPing(); + void RealAddIP(); + void RealDelIP(); + + static void * RunSendPing(void * d); + static void * RunRecvPing(void * d); + + time_t m_delay; + bool m_nonstop; + bool m_isRunningRecver; + bool m_isRunningSender; + int m_sendSocket; + int m_recvSocket; + pthread_t m_sendThread; + pthread_t m_recvThread; + + PING_MESSAGE m_pmSend; + uint32_t m_pid; + + std::string m_errorStr; + + std::multimap m_pingIP; + std::list m_ipToAdd; + std::list m_ipToDel; + + mutable pthread_mutex_t m_mutex; }; -//----------------------------------------------------------------------------- -#endif diff --git a/libs/pinger/pinger.cpp b/libs/pinger/pinger.cpp index 07415812..042edcba 100644 --- a/libs/pinger/pinger.cpp +++ b/libs/pinger/pinger.cpp @@ -26,54 +26,46 @@ extern volatile time_t stgTime; //----------------------------------------------------------------------------- STG_PINGER::STG_PINGER(time_t d) - : delay(d), - nonstop(false), - isRunningRecver(false), - isRunningSender(false), - sendSocket(-1), - recvSocket(-1), - sendThread(), - recvThread(), - pmSend(), - pid(0), - errorStr(), - pingIP(), - ipToAdd(), - ipToDel(), - mutex() + : m_delay(d), + m_nonstop(false), + m_isRunningRecver(false), + m_isRunningSender(false), + m_sendSocket(-1), + m_recvSocket(-1), + m_pid(0) { -pthread_mutex_init(&mutex, NULL); -memset(&pmSend, 0, sizeof(pmSend)); +pthread_mutex_init(&m_mutex, NULL); +memset(&m_pmSend, 0, sizeof(m_pmSend)); } //----------------------------------------------------------------------------- STG_PINGER::~STG_PINGER() { -pthread_mutex_destroy(&mutex); +pthread_mutex_destroy(&m_mutex); } //----------------------------------------------------------------------------- int STG_PINGER::Start() { struct protoent *proto = NULL; proto = getprotobyname("ICMP"); -sendSocket = socket(PF_INET, SOCK_RAW, proto->p_proto); -recvSocket = socket(PF_INET, SOCK_RAW, proto->p_proto); -nonstop = true; -pid = (int) getpid() % 65535; -if (sendSocket < 0 || recvSocket < 0) +m_sendSocket = socket(PF_INET, SOCK_RAW, proto->p_proto); +m_recvSocket = socket(PF_INET, SOCK_RAW, proto->p_proto); +m_nonstop = true; +m_pid = static_cast(getpid()) % 65535; +if (m_sendSocket < 0 || m_recvSocket < 0) { - errorStr = "Cannot create socket."; + m_errorStr = "Cannot create socket."; return -1; } -if (pthread_create(&sendThread, NULL, RunSendPing, this)) +if (pthread_create(&m_sendThread, NULL, RunSendPing, this)) { - errorStr = "Cannot create send thread."; + m_errorStr = "Cannot create send thread."; return -1; } -if (pthread_create(&recvThread, NULL, RunRecvPing, this)) +if (pthread_create(&m_recvThread, NULL, RunRecvPing, this)) { - errorStr = "Cannot create recv thread."; + m_errorStr = "Cannot create recv thread."; return -1; } @@ -82,9 +74,9 @@ return 0; //----------------------------------------------------------------------------- int STG_PINGER::Stop() { -close(recvSocket); -nonstop = false; -if (isRunningRecver) +close(m_recvSocket); +m_nonstop = false; +if (m_isRunningRecver) { //5 seconds to thread stops itself for (size_t i = 0; i < 25; i++) @@ -92,7 +84,7 @@ if (isRunningRecver) if (i % 5 == 0) SendPing(0x0100007f);//127.0.0.1 - if (!isRunningRecver) + if (!m_isRunningRecver) break; struct timespec ts = {0, 200000000}; @@ -100,12 +92,12 @@ if (isRunningRecver) } } -if (isRunningSender) +if (m_isRunningSender) { //5 seconds to thread stops itself for (size_t i = 0; i < 25; i++) { - if (!isRunningSender) + if (!m_isRunningSender) break; struct timespec ts = {0, 200000000}; @@ -113,9 +105,9 @@ if (isRunningSender) } } -close(sendSocket); +close(m_sendSocket); -if (isRunningSender || isRunningRecver) +if (m_isRunningSender || m_isRunningRecver) return -1; return 0; @@ -123,54 +115,50 @@ return 0; //----------------------------------------------------------------------------- void STG_PINGER::AddIP(uint32_t ip) { -STG_LOCKER lock(&mutex); -ipToAdd.push_back(ip); +STG_LOCKER lock(&m_mutex); +m_ipToAdd.push_back(ip); } //----------------------------------------------------------------------------- void STG_PINGER::DelIP(uint32_t ip) { -STG_LOCKER lock(&mutex); -ipToDel.push_back(ip); +STG_LOCKER lock(&m_mutex); +m_ipToDel.push_back(ip); } //----------------------------------------------------------------------------- void STG_PINGER::RealAddIP() { -STG_LOCKER lock(&mutex); +STG_LOCKER lock(&m_mutex); -std::list::iterator iter; -iter = ipToAdd.begin(); -while (iter != ipToAdd.end()) +auto iter = m_ipToAdd.begin(); +while (iter != m_ipToAdd.end()) { - pingIP.insert(std::make_pair(*iter, 0)); + m_pingIP.insert(std::make_pair(*iter, 0)); ++iter; } -ipToAdd.erase(ipToAdd.begin(), ipToAdd.end()); +m_ipToAdd.erase(m_ipToAdd.begin(), m_ipToAdd.end()); } //----------------------------------------------------------------------------- void STG_PINGER::RealDelIP() { -STG_LOCKER lock(&mutex); +STG_LOCKER lock(&m_mutex); -std::list::iterator iter; -std::multimap::iterator treeIter; -iter = ipToDel.begin(); -while (iter != ipToDel.end()) +auto iter = m_ipToDel.begin(); +while (iter != m_ipToDel.end()) { - treeIter = pingIP.find(*iter); - if (treeIter != pingIP.end()) - pingIP.erase(treeIter); + auto treeIter = m_pingIP.find(*iter); + if (treeIter != m_pingIP.end()) + m_pingIP.erase(treeIter); ++iter; } -ipToDel.erase(ipToDel.begin(), ipToDel.end()); +m_ipToDel.erase(m_ipToDel.begin(), m_ipToDel.end()); } //----------------------------------------------------------------------------- void STG_PINGER::PrintAllIP() { -STG_LOCKER lock(&mutex); -std::multimap::iterator iter; -iter = pingIP.begin(); -while (iter != pingIP.end()) +STG_LOCKER lock(&m_mutex); +auto iter = m_pingIP.begin(); +while (iter != m_pingIP.end()) { uint32_t ip = iter->first; time_t t = iter->second; @@ -183,11 +171,10 @@ while (iter != pingIP.end()) //----------------------------------------------------------------------------- int STG_PINGER::GetIPTime(uint32_t ip, time_t * t) const { -STG_LOCKER lock(&mutex); -std::multimap::const_iterator treeIter; +STG_LOCKER lock(&m_mutex); -treeIter = pingIP.find(ip); -if (treeIter == pingIP.end()) +auto treeIter = m_pingIP.find(ip); +if (treeIter == m_pingIP.end()) return -1; *t = treeIter->second; @@ -220,16 +207,16 @@ addr.sin_family = AF_INET; addr.sin_port = 0; addr.sin_addr.s_addr = ip; -memset(&pmSend, 0, sizeof(pmSend)); -pmSend.hdr.type = ICMP_ECHO; -pmSend.hdr.un.echo.id = static_cast(pid); -memcpy(pmSend.msg, &ip, sizeof(ip)); +memset(&m_pmSend, 0, sizeof(m_pmSend)); +m_pmSend.hdr.type = ICMP_ECHO; +m_pmSend.hdr.un.echo.id = static_cast(m_pid); +memcpy(m_pmSend.msg, &ip, sizeof(ip)); -pmSend.hdr.checksum = PingCheckSum(&pmSend, sizeof(pmSend)); +m_pmSend.hdr.checksum = PingCheckSum(&m_pmSend, sizeof(m_pmSend)); -if (sendto(sendSocket, &pmSend, sizeof(pmSend), 0, (sockaddr *)&addr, sizeof(addr)) <= 0 ) +if (sendto(m_sendSocket, &m_pmSend, sizeof(m_pmSend), 0, reinterpret_cast(&addr), sizeof(addr)) <= 0 ) { - errorStr = "Send ping error: " + std::string(strerror(errno)); + m_errorStr = "Send ping error: " + std::string(strerror(errno)); return -1; } @@ -246,12 +233,12 @@ char buf[128]; memset(buf, 0, sizeof(buf)); socklen_t len = sizeof(addr); -if (recvfrom(recvSocket, &buf, sizeof(buf), 0, reinterpret_cast(&addr), &len)) +if (recvfrom(m_recvSocket, &buf, sizeof(buf), 0, reinterpret_cast(&addr), &len)) { struct IP_HDR * ip = static_cast(static_cast(buf)); struct ICMP_HDR *icmp = static_cast(static_cast(buf + ip->ihl * 4)); - if (icmp->un.echo.id != pid) + if (icmp->un.echo.id != m_pid) return 0; ipAddr = *static_cast(static_cast(buf + sizeof(ICMP_HDR) + ip->ihl * 4)); @@ -266,18 +253,18 @@ sigset_t signalSet; sigfillset(&signalSet); pthread_sigmask(SIG_BLOCK, &signalSet, NULL); -STG_PINGER * pinger = static_cast(d); +auto* pinger = static_cast(d); -pinger->isRunningSender = true; +pinger->m_isRunningSender = true; time_t lastPing = 0; -while (pinger->nonstop) +while (pinger->m_nonstop) { pinger->RealAddIP(); pinger->RealDelIP(); std::multimap::iterator iter; - iter = pinger->pingIP.begin(); - while (iter != pinger->pingIP.end()) + iter = pinger->m_pingIP.begin(); + while (iter != pinger->m_pingIP.end()) { pinger->SendPing(iter->first); ++iter; @@ -292,7 +279,7 @@ while (pinger->nonstop) currTime = lastPing = time(NULL); #endif - while (currTime - lastPing < pinger->delay && pinger->nonstop) + while (currTime - lastPing < pinger->m_delay && pinger->m_nonstop) { #ifdef STG_TIME currTime = stgTime; @@ -304,7 +291,7 @@ while (pinger->nonstop) } } -pinger->isRunningSender = false; +pinger->m_isRunningSender = false; return NULL; } @@ -315,18 +302,18 @@ sigset_t signalSet; sigfillset(&signalSet); pthread_sigmask(SIG_BLOCK, &signalSet, NULL); -STG_PINGER * pinger = static_cast(d); +auto* pinger = static_cast(d); -pinger->isRunningRecver = true; +pinger->m_isRunningRecver = true; -while (pinger->nonstop) +while (pinger->m_nonstop) { uint32_t ip = pinger->RecvPing(); if (ip) { - std::multimap::iterator treeIterUpper = pinger->pingIP.upper_bound(ip); - std::multimap::iterator treeIterLower = pinger->pingIP.lower_bound(ip); + auto treeIterUpper = pinger->m_pingIP.upper_bound(ip); + auto treeIterLower = pinger->m_pingIP.lower_bound(ip); while (treeIterUpper != treeIterLower) { #ifdef STG_TIME @@ -339,7 +326,7 @@ while (pinger->nonstop) } } -pinger->isRunningRecver = false; +pinger->m_isRunningRecver = false; return NULL; } //----------------------------------------------------------------------------- diff --git a/libs/srvconf/include/stg/servconf.h b/libs/srvconf/include/stg/servconf.h index 2f246b67..fe3cb32c 100644 --- a/libs/srvconf/include/stg/servconf.h +++ b/libs/srvconf/include/stg/servconf.h @@ -101,7 +101,7 @@ class ServConf private: class Impl; - Impl* pImpl; + Impl* m_impl; }; } // namespace STG diff --git a/libs/srvconf/netunit.cpp b/libs/srvconf/netunit.cpp index ec2e3c5b..7d6332c6 100644 --- a/libs/srvconf/netunit.cpp +++ b/libs/srvconf/netunit.cpp @@ -80,25 +80,25 @@ const char RECV_HEADER_ANSWER_ERROR[] = "Error receiving header answer."; //--------------------------------------------------------------------------- NetTransact::NetTransact(const std::string& s, uint16_t p, const std::string& l, const std::string& pwd) - : server(s), - port(p), - localPort(0), - login(l), - password(pwd), - sock(-1) + : m_server(s), + m_port(p), + m_localPort(0), + m_login(l), + m_password(pwd), + m_sock(-1) { } //--------------------------------------------------------------------------- NetTransact::NetTransact(const std::string& s, uint16_t p, const std::string& la, uint16_t lp, const std::string& l, const std::string& pwd) - : server(s), - port(p), - localAddress(la), - localPort(lp), - login(l), - password(pwd), - sock(-1) + : m_server(s), + m_port(p), + m_localAddress(la), + m_localPort(lp), + m_login(l), + m_password(pwd), + m_sock(-1) { } //--------------------------------------------------------------------------- @@ -109,43 +109,43 @@ NetTransact::~NetTransact() //--------------------------------------------------------------------------- int NetTransact::Connect() { - sock = socket(PF_INET, SOCK_STREAM, 0); - if (sock < 0) + m_sock = socket(PF_INET, SOCK_STREAM, 0); + if (m_sock < 0) { - errorMsg = CREATE_SOCKET_ERROR; + m_errorMsg = CREATE_SOCKET_ERROR; return st_conn_fail; } - if (!localAddress.empty()) + if (!m_localAddress.empty()) { - if (localPort == 0) - localPort = port; + if (m_localPort == 0) + m_localPort = m_port; - unsigned long ip = inet_addr(localAddress.c_str()); + uint32_t ip = inet_addr(m_localAddress.c_str()); if (ip == INADDR_NONE) { - auto phe = gethostbyname(localAddress.c_str()); + auto phe = gethostbyname(m_localAddress.c_str()); if (phe == NULL) { - errorMsg = "Can not reslove '" + localAddress + "'"; + m_errorMsg = "Can not reslove '" + m_localAddress + "'"; return st_dns_err; } struct hostent he; memcpy(&he, phe, sizeof(he)); - ip = *((long *)he.h_addr_list[0]); + ip = *reinterpret_cast(he.h_addr_list[0]); } struct sockaddr_in localAddr; memset(&localAddr, 0, sizeof(localAddr)); localAddr.sin_family = AF_INET; - localAddr.sin_port = htons(localPort); + localAddr.sin_port = htons(m_localPort); localAddr.sin_addr.s_addr = ip; - if (bind(sock, (struct sockaddr *)&localAddr, sizeof(localAddr)) < 0) + if (bind(m_sock, reinterpret_cast(&localAddr), sizeof(localAddr)) < 0) { - errorMsg = BIND_FAILED; + m_errorMsg = BIND_FAILED; return st_conn_fail; } } @@ -153,29 +153,29 @@ int NetTransact::Connect() struct sockaddr_in outerAddr; memset(&outerAddr, 0, sizeof(outerAddr)); - unsigned long ip = inet_addr(server.c_str()); + uint32_t ip = inet_addr(m_server.c_str()); if (ip == INADDR_NONE) { - auto phe = gethostbyname(server.c_str()); + auto phe = gethostbyname(m_server.c_str()); if (phe == NULL) { - errorMsg = "Can not reslove '" + server + "'"; + m_errorMsg = "Can not reslove '" + m_server + "'"; return st_dns_err; } struct hostent he; memcpy(&he, phe, sizeof(he)); - ip = *((long *)he.h_addr_list[0]); + ip = *reinterpret_cast(he.h_addr_list[0]); } outerAddr.sin_family = AF_INET; - outerAddr.sin_port = htons(port); + outerAddr.sin_port = htons(m_port); outerAddr.sin_addr.s_addr = ip; - if (connect(sock, (struct sockaddr *)&outerAddr, sizeof(outerAddr)) < 0) + if (connect(m_sock, reinterpret_cast(&outerAddr), sizeof(outerAddr)) < 0) { - errorMsg = CONNECT_FAILED; + m_errorMsg = CONNECT_FAILED; return st_conn_fail; } @@ -184,11 +184,11 @@ int NetTransact::Connect() //--------------------------------------------------------------------------- void NetTransact::Disconnect() { - if (sock != -1) + if (m_sock != -1) { - shutdown(sock, SHUT_RDWR); - close(sock); - sock = -1; + shutdown(m_sock, SHUT_RDWR); + close(m_sock); + m_sock = -1; } } //--------------------------------------------------------------------------- @@ -224,9 +224,9 @@ int NetTransact::Transact(const std::string& request, Callback callback, void* d //--------------------------------------------------------------------------- int NetTransact::TxHeader() { - if (!WriteAll(sock, STG_HEADER, strlen(STG_HEADER))) + if (!WriteAll(m_sock, STG_HEADER, strlen(STG_HEADER))) { - errorMsg = SEND_HEADER_ERROR; + m_errorMsg = SEND_HEADER_ERROR; return st_send_fail; } @@ -237,9 +237,9 @@ int NetTransact::RxHeaderAnswer() { char buffer[sizeof(STG_HEADER) + 1]; - if (!ReadAll(sock, buffer, strlen(OK_HEADER))) + if (!ReadAll(m_sock, buffer, strlen(OK_HEADER))) { - errorMsg = RECV_HEADER_ANSWER_ERROR; + m_errorMsg = RECV_HEADER_ANSWER_ERROR; return st_recv_fail; } @@ -248,11 +248,11 @@ int NetTransact::RxHeaderAnswer() if (strncmp(ERR_HEADER, buffer, strlen(ERR_HEADER)) == 0) { - errorMsg = INCORRECT_HEADER; + m_errorMsg = INCORRECT_HEADER; return st_header_err; } - errorMsg = UNKNOWN_ERROR; + m_errorMsg = UNKNOWN_ERROR; return st_unknown_err; } //--------------------------------------------------------------------------- @@ -260,11 +260,11 @@ int NetTransact::TxLogin() { char loginZ[ADM_LOGIN_LEN + 1]; memset(loginZ, 0, ADM_LOGIN_LEN + 1); - strncpy(loginZ, login.c_str(), ADM_LOGIN_LEN); + strncpy(loginZ, m_login.c_str(), ADM_LOGIN_LEN); - if (!WriteAll(sock, loginZ, ADM_LOGIN_LEN)) + if (!WriteAll(m_sock, loginZ, ADM_LOGIN_LEN)) { - errorMsg = SEND_LOGIN_ERROR; + m_errorMsg = SEND_LOGIN_ERROR; return st_send_fail; } @@ -275,9 +275,9 @@ int NetTransact::RxLoginAnswer() { char buffer[sizeof(OK_LOGIN) + 1]; - if (!ReadAll(sock, buffer, strlen(OK_LOGIN))) + if (!ReadAll(m_sock, buffer, strlen(OK_LOGIN))) { - errorMsg = RECV_LOGIN_ANSWER_ERROR; + m_errorMsg = RECV_LOGIN_ANSWER_ERROR; return st_recv_fail; } @@ -286,11 +286,11 @@ int NetTransact::RxLoginAnswer() if (strncmp(ERR_LOGIN, buffer, strlen(ERR_LOGIN)) == 0) { - errorMsg = INCORRECT_LOGIN; + m_errorMsg = INCORRECT_LOGIN; return st_login_err; } - errorMsg = UNKNOWN_ERROR; + m_errorMsg = UNKNOWN_ERROR; return st_unknown_err; } //--------------------------------------------------------------------------- @@ -300,11 +300,11 @@ int NetTransact::TxLoginS() memset(loginZ, 0, ADM_LOGIN_LEN + 1); BLOWFISH_CTX ctx; - InitContext(password.c_str(), PASSWD_LEN, &ctx); - EncryptString(loginZ, login.c_str(), std::min(login.length() + 1, ADM_LOGIN_LEN), &ctx); - if (!WriteAll(sock, loginZ, ADM_LOGIN_LEN)) + InitContext(m_password.c_str(), PASSWD_LEN, &ctx); + EncryptString(loginZ, m_login.c_str(), std::min(m_login.length() + 1, ADM_LOGIN_LEN), &ctx); + if (!WriteAll(m_sock, loginZ, ADM_LOGIN_LEN)) { - errorMsg = SEND_LOGIN_ERROR; + m_errorMsg = SEND_LOGIN_ERROR; return st_send_fail; } @@ -315,9 +315,9 @@ int NetTransact::RxLoginSAnswer() { char buffer[sizeof(OK_LOGINS) + 1]; - if (!ReadAll(sock, buffer, strlen(OK_LOGINS))) + if (!ReadAll(m_sock, buffer, strlen(OK_LOGINS))) { - errorMsg = RECV_LOGIN_ANSWER_ERROR; + m_errorMsg = RECV_LOGIN_ANSWER_ERROR; return st_recv_fail; } @@ -326,21 +326,21 @@ int NetTransact::RxLoginSAnswer() if (strncmp(ERR_LOGINS, buffer, strlen(ERR_LOGINS)) == 0) { - errorMsg = INCORRECT_LOGIN; + m_errorMsg = INCORRECT_LOGIN; return st_logins_err; } - errorMsg = UNKNOWN_ERROR; + m_errorMsg = UNKNOWN_ERROR; return st_unknown_err; } //--------------------------------------------------------------------------- int NetTransact::TxData(const std::string& text) { - STG::ENCRYPT_STREAM stream(password, TxCrypto, this); + STG::ENCRYPT_STREAM stream(m_password, TxCrypto, this); stream.Put(text.c_str(), text.length() + 1, true); if (!stream.IsOk()) { - errorMsg = SEND_DATA_ERROR; + m_errorMsg = SEND_DATA_ERROR; return st_send_fail; } @@ -350,14 +350,14 @@ int NetTransact::TxData(const std::string& text) int NetTransact::RxDataAnswer(Callback callback, void* data) { ReadState state = {false, callback, data, this}; - STG::DECRYPT_STREAM stream(password, RxCrypto, &state); + STG::DECRYPT_STREAM stream(m_password, RxCrypto, &state); while (!state.last) { char buffer[1024]; - ssize_t res = read(sock, buffer, sizeof(buffer)); + ssize_t res = read(m_sock, buffer, sizeof(buffer)); if (res < 0) { - errorMsg = RECV_DATA_ANSWER_ERROR; + m_errorMsg = RECV_DATA_ANSWER_ERROR; return st_recv_fail; } stream.Put(buffer, res, res == 0); @@ -372,7 +372,7 @@ bool NetTransact::TxCrypto(const void* block, size_t size, void* data) { assert(data != NULL); auto& nt = *static_cast(data); - if (!WriteAll(nt.sock, block, size)) + if (!WriteAll(nt.m_sock, block, size)) return false; return true; } diff --git a/libs/srvconf/netunit.h b/libs/srvconf/netunit.h index 66d95c3d..b9980abe 100644 --- a/libs/srvconf/netunit.h +++ b/libs/srvconf/netunit.h @@ -39,7 +39,7 @@ class NetTransact ~NetTransact(); int Transact(const std::string& request, Callback f, void* data); - const std::string & GetError() const { return errorMsg; } + const std::string & GetError() const { return m_errorMsg; } int Connect(); void Disconnect(); @@ -57,14 +57,14 @@ class NetTransact int TxData(const std::string& text); int RxDataAnswer(Callback f, void* data); - std::string server; - uint16_t port; - std::string localAddress; - uint16_t localPort; - std::string login; - std::string password; - int sock; - std::string errorMsg; + std::string m_server; + uint16_t m_port; + std::string m_localAddress; + uint16_t m_localPort; + std::string m_login; + std::string m_password; + int m_sock; + std::string m_errorMsg; static bool TxCrypto(const void * block, size_t size, void * data); static bool RxCrypto(const void * block, size_t size, void * data); diff --git a/libs/srvconf/servconf.cpp b/libs/srvconf/servconf.cpp index c038fd29..408e93fc 100644 --- a/libs/srvconf/servconf.cpp +++ b/libs/srvconf/servconf.cpp @@ -65,7 +65,7 @@ class ServConf::Impl Impl(const std::string& server, uint16_t port, const std::string& localAddress, uint16_t localPort, const std::string& login, const std::string& password); - ~Impl() { XML_ParserFree(parser); } + ~Impl() { XML_ParserFree(m_parser); } const std::string& GetStrError() const; static void Start(void* data, const char* el, const char** attr); @@ -76,23 +76,23 @@ class ServConf::Impl template int Exec(const std::string& request, C callback, void* data) { - return ExecImpl(request, P(callback, data, encoding)); + return ExecImpl(request, P(callback, data, m_encoding)); } template int Exec(const std::string& tag, const std::string& request, C callback, void* data) { - return ExecImpl(request, P(tag, callback, data, encoding)); + return ExecImpl(request, P(tag, callback, data, m_encoding)); } - const std::string& Encoding() const { return encoding; } + const std::string& Encoding() const { return m_encoding; } private: - NetTransact nt; + NetTransact m_nt; - std::string encoding; - std::string errorMsg; - XML_Parser parser; + std::string m_encoding; + std::string m_errorMsg; + XML_Parser m_parser; static bool ParserRecv(const std::string& chunk, bool last, void* data); static bool SimpleRecv(const std::string& chunk, bool last, void* data); @@ -101,14 +101,14 @@ class ServConf::Impl bool ServConf::Impl::ParserRecv(const std::string& chunk, bool last, void* data) { - auto sc = static_cast(data); + auto* sc = static_cast(data); - if (XML_Parse(sc->parser, chunk.c_str(), chunk.length(), last) == XML_STATUS_ERROR) + if (XML_Parse(sc->m_parser, chunk.c_str(), chunk.length(), last) == XML_STATUS_ERROR) { - strprintf(&sc->errorMsg, "XML parse error at line %d, %d: %s. Is last: %d", - static_cast(XML_GetCurrentLineNumber(sc->parser)), - static_cast(XML_GetCurrentColumnNumber(sc->parser)), - XML_ErrorString(XML_GetErrorCode(sc->parser)), static_cast(last)); + strprintf(&sc->m_errorMsg, "XML parse error at line %d, %d: %s. Is last: %d", + static_cast(XML_GetCurrentLineNumber(sc->m_parser)), + static_cast(XML_GetCurrentColumnNumber(sc->m_parser)), + XML_ErrorString(XML_GetErrorCode(sc->m_parser)), static_cast(last)); return false; } @@ -123,106 +123,106 @@ bool ServConf::Impl::SimpleRecv(const std::string& chunk, bool /*last*/, void* d ServConf::ServConf(const std::string& server, uint16_t port, const std::string& login, const std::string& password) - : pImpl(new Impl(server, port, login, password)) + : m_impl(new Impl(server, port, login, password)) { } ServConf::ServConf(const std::string& server, uint16_t port, const std::string& localAddress, uint16_t localPort, const std::string& login, const std::string& password) - : pImpl(new Impl(server, port, localAddress, localPort, login, password)) + : m_impl(new Impl(server, port, localAddress, localPort, login, password)) { } ServConf::~ServConf() { - delete pImpl; + delete m_impl; } int ServConf::ServerInfo(ServerInfo::Callback f, void* data) { - return pImpl->Exec("", f, data); + return m_impl->Exec("", f, data); } int ServConf::RawXML(const std::string& request, RawXML::Callback f, void* data) { - return pImpl->RawXML(request, f, data); + return m_impl->RawXML(request, f, data); } // -- Admins -- int ServConf::GetAdmins(GetContainer::Callback::Type f, void* data) { - return pImpl->Exec >("admins", "", f, data); + return m_impl->Exec >("admins", "", f, data); } int ServConf::GetAdmin(const std::string& login, GetAdmin::Callback f, void* data) { - return pImpl->Exec("", f, data); + return m_impl->Exec("", f, data); } int ServConf::ChgAdmin(const AdminConfOpt& conf, Simple::Callback f, void* data) { - return pImpl->Exec("ChgAdmin", "Encoding()) + "/>", f, data); + return m_impl->Exec("ChgAdmin", "Encoding()) + "/>", f, data); } int ServConf::AddAdmin(const std::string& login, const AdminConfOpt& conf, Simple::Callback f, void* data) { - auto res = pImpl->Exec("AddAdmin", "", f, data); + auto res = m_impl->Exec("AddAdmin", "", f, data); if (res != st_ok) return res; - return pImpl->Exec("ChgAdmin", "Encoding()) + "/>", f, data); + return m_impl->Exec("ChgAdmin", "Encoding()) + "/>", f, data); } int ServConf::DelAdmin(const std::string& login, Simple::Callback f, void* data) { - return pImpl->Exec("DelAdmin", "", f, data); + return m_impl->Exec("DelAdmin", "", f, data); } // -- Tariffs -- int ServConf::GetTariffs(GetContainer::Callback::Type f, void* data) { - return pImpl->Exec >("tariffs", "", f, data); + return m_impl->Exec >("tariffs", "", f, data); } int ServConf::GetTariff(const std::string& name, GetTariff::Callback f, void* data) { - return pImpl->Exec("", f, data); + return m_impl->Exec("", f, data); } int ServConf::ChgTariff(const TariffDataOpt& tariffData, Simple::Callback f, void* data) { - return pImpl->Exec("SetTariff", "" + ChgTariff::serialize(tariffData, pImpl->Encoding()) + "", f, data); + return m_impl->Exec("SetTariff", "" + ChgTariff::serialize(tariffData, m_impl->Encoding()) + "", f, data); } int ServConf::AddTariff(const std::string& name, const TariffDataOpt& tariffData, Simple::Callback f, void* data) { - auto res = pImpl->Exec("AddTariff", "", f, data); + auto res = m_impl->Exec("AddTariff", "", f, data); if (res != st_ok) return res; - return pImpl->Exec("SetTariff", "" + ChgTariff::serialize(tariffData, pImpl->Encoding()) + "", f, data); + return m_impl->Exec("SetTariff", "" + ChgTariff::serialize(tariffData, m_impl->Encoding()) + "", f, data); } int ServConf::DelTariff(const std::string& name, Simple::Callback f, void* data) { - return pImpl->Exec("DelTariff", "", f, data); + return m_impl->Exec("DelTariff", "", f, data); } // -- Users -- int ServConf::GetUsers(GetContainer::Callback::Type f, void* data) { - return pImpl->Exec >("users", "", f, data); + return m_impl->Exec >("users", "", f, data); } int ServConf::GetUser(const std::string& login, GetUser::Callback f, void* data) { - return pImpl->Exec("", f, data); + return m_impl->Exec("", f, data); } int ServConf::ChgUser(const std::string& login, @@ -230,12 +230,12 @@ int ServConf::ChgUser(const std::string& login, const UserStatOpt& stat, Simple::Callback f, void* data) { - return pImpl->Exec("" + ChgUser::serialize(conf, stat, pImpl->Encoding()) + "", f, data); + return m_impl->Exec("" + ChgUser::serialize(conf, stat, m_impl->Encoding()) + "", f, data); } int ServConf::DelUser(const std::string& login, Simple::Callback f, void* data) { - return pImpl->Exec("DelUser", "", f, data); + return m_impl->Exec("DelUser", "", f, data); } int ServConf::AddUser(const std::string& login, @@ -243,116 +243,116 @@ int ServConf::AddUser(const std::string& login, const UserStatOpt& stat, Simple::Callback f, void* data) { - auto res = pImpl->Exec("AddUser", "", f, data); + auto res = m_impl->Exec("AddUser", "", f, data); if (res != st_ok) return res; - return pImpl->Exec("" + ChgUser::serialize(conf, stat, pImpl->Encoding()) + "", f, data); + return m_impl->Exec("" + ChgUser::serialize(conf, stat, m_impl->Encoding()) + "", f, data); } int ServConf::AuthBy(const std::string& login, AuthBy::Callback f, void* data) { - return pImpl->Exec("", f, data); + return m_impl->Exec("", f, data); } int ServConf::SendMessage(const std::string& login, const std::string& text, Simple::Callback f, void* data) { - return pImpl->Exec("SendMessageResult", "", f, data); + return m_impl->Exec("SendMessageResult", "", f, data); } int ServConf::CheckUser(const std::string& login, const std::string& password, Simple::Callback f, void* data) { - return pImpl->Exec("CheckUser", "", f, data); + return m_impl->Exec("CheckUser", "", f, data); } // -- Services -- int ServConf::GetServices(GetContainer::Callback::Type f, void* data) { - return pImpl->Exec >("services", "", f, data); + return m_impl->Exec >("services", "", f, data); } int ServConf::GetService(const std::string& name, GetService::Callback f, void* data) { - return pImpl->Exec("", f, data); + return m_impl->Exec("", f, data); } int ServConf::ChgService(const ServiceConfOpt& conf, Simple::Callback f, void* data) { - return pImpl->Exec("SetService", "Encoding()) + "/>", f, data); + return m_impl->Exec("SetService", "Encoding()) + "/>", f, data); } int ServConf::AddService(const std::string& name, const ServiceConfOpt& conf, Simple::Callback f, void* data) { - auto res = pImpl->Exec("AddService", "", f, data); + auto res = m_impl->Exec("AddService", "", f, data); if (res != st_ok) return res; - return pImpl->Exec("SetService", "Encoding()) + "/>", f, data); + return m_impl->Exec("SetService", "Encoding()) + "/>", f, data); } int ServConf::DelService(const std::string& name, Simple::Callback f, void* data) { - return pImpl->Exec("DelService", "", f, data); + return m_impl->Exec("DelService", "", f, data); } // -- Corporations -- int ServConf::GetCorporations(GetContainer::Callback::Type f, void* data) { - return pImpl->Exec >("corporations", "", f, data); + return m_impl->Exec >("corporations", "", f, data); } int ServConf::GetCorp(const std::string& name, GetCorp::Callback f, void* data) { - return pImpl->Exec("", f, data); + return m_impl->Exec("", f, data); } int ServConf::ChgCorp(const CorpConfOpt & conf, Simple::Callback f, void* data) { - return pImpl->Exec("SetCorp", "" + ChgCorp::serialize(conf, pImpl->Encoding()) + "", f, data); + return m_impl->Exec("SetCorp", "" + ChgCorp::serialize(conf, m_impl->Encoding()) + "", f, data); } int ServConf::AddCorp(const std::string& name, const CorpConfOpt& conf, Simple::Callback f, void* data) { - auto res = pImpl->Exec("AddCorp", "", f, data); + auto res = m_impl->Exec("AddCorp", "", f, data); if (res != st_ok) return res; - return pImpl->Exec("SetCorp", "" + ChgCorp::serialize(conf, pImpl->Encoding()) + "", f, data); + return m_impl->Exec("SetCorp", "" + ChgCorp::serialize(conf, m_impl->Encoding()) + "", f, data); } int ServConf::DelCorp(const std::string& name, Simple::Callback f, void* data) { - return pImpl->Exec("DelCorp", "", f, data); + return m_impl->Exec("DelCorp", "", f, data); } const std::string& ServConf::GetStrError() const { - return pImpl->GetStrError(); + return m_impl->GetStrError(); } //----------------------------------------------------------------------------- ServConf::Impl::Impl(const std::string& server, uint16_t port, const std::string& login, const std::string& password) - : nt(server, port, login, password) + : m_nt(server, port, login, password) { setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); - encoding = nl_langinfo(CODESET); - parser = XML_ParserCreate(NULL); + m_encoding = nl_langinfo(CODESET); + m_parser = XML_ParserCreate(NULL); } //----------------------------------------------------------------------------- ServConf::Impl::Impl(const std::string& server, uint16_t port, const std::string& localAddress, uint16_t localPort, const std::string& login, const std::string& password) - : nt(server, port, localAddress, localPort, login, password) + : m_nt(server, port, localAddress, localPort, login, password) { setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); - encoding = nl_langinfo(CODESET); - parser = XML_ParserCreate(NULL); + m_encoding = nl_langinfo(CODESET); + m_parser = XML_ParserCreate(NULL); } //----------------------------------------------------------------------------- void ServConf::Impl::Start(void* data, const char* el, const char** attr) @@ -367,51 +367,51 @@ void ServConf::Impl::End(void* data, const char* el) //----------------------------------------------------------------------------- const std::string & ServConf::Impl::GetStrError() const { - return errorMsg; + return m_errorMsg; } //----------------------------------------------------------------------------- int ServConf::Impl::ExecImpl(const std::string& request, Parser&& cp) { - XML_ParserReset(parser, NULL); - XML_SetElementHandler(parser, Start, End); - XML_SetUserData(parser, &cp); + XML_ParserReset(m_parser, NULL); + XML_SetElementHandler(m_parser, Start, End); + XML_SetUserData(m_parser, &cp); int ret = 0; - if ((ret = nt.Connect()) != st_ok) + if ((ret = m_nt.Connect()) != st_ok) { - errorMsg = nt.GetError(); - cp.Failure(errorMsg); + m_errorMsg = m_nt.GetError(); + cp.Failure(m_errorMsg); return ret; } - if ((ret = nt.Transact(request, ParserRecv, this)) != st_ok) + if ((ret = m_nt.Transact(request, ParserRecv, this)) != st_ok) { - errorMsg = nt.GetError(); - cp.Failure(errorMsg); + m_errorMsg = m_nt.GetError(); + cp.Failure(m_errorMsg); return ret; } - nt.Disconnect(); + m_nt.Disconnect(); return st_ok; } int ServConf::Impl::RawXML(const std::string& request, RawXML::Callback callback, void* data) { int ret = 0; - if ((ret = nt.Connect()) != st_ok) + if ((ret = m_nt.Connect()) != st_ok) { - errorMsg = nt.GetError(); - callback(false, errorMsg, "", data); + m_errorMsg = m_nt.GetError(); + callback(false, m_errorMsg, "", data); return ret; } std::string response; - if ((ret = nt.Transact(request, SimpleRecv, &response)) != st_ok) + if ((ret = m_nt.Transact(request, SimpleRecv, &response)) != st_ok) { - errorMsg = nt.GetError(); - callback(false, errorMsg, "", data); + m_errorMsg = m_nt.GetError(); + callback(false, m_errorMsg, "", data); return ret; } - nt.Disconnect(); + m_nt.Disconnect(); callback(true, "", response, data); return st_ok; } diff --git a/projects/sgauth/web.cpp b/projects/sgauth/web.cpp index a162acc4..5d259559 100644 --- a/projects/sgauth/web.cpp +++ b/projects/sgauth/web.cpp @@ -59,22 +59,22 @@ return NULL; } //--------------------------------------------------------------------------- WEB::WEB() - : res(0), - listenSocket(0), - outerSocket(0), - refreshPeriod(0), - listenWebAddr(0) + : m_res(0), + m_listenSocket(0), + m_outerSocket(0), + m_refreshPeriod(0), + m_listenWebAddr(0) { #ifdef WIN32 -res = WSAStartup(MAKEWORD(2,0), &wsaData); +m_res = WSAStartup(MAKEWORD(2,0), &m_wsaData); #endif for (int i = 0; i < DIR_NUM; i++) - dirName[i] = "-"; + m_dirName[i] = "-"; -refreshPeriod = 5; +m_refreshPeriod = 5; -memset(&ls, 0, sizeof(ls)); +memset(&m_ls, 0, sizeof(m_ls)); } //--------------------------------------------------------------------------- void WEB::Start() @@ -90,22 +90,22 @@ CreateThread( &pt // pointer to returned thread identifier ); #else -pthread_create(&thread, NULL, RunWeb, NULL); +pthread_create(&m_thread, NULL, RunWeb, NULL); #endif } //--------------------------------------------------------------------------- void WEB::PrepareNet() { -listenSocket = socket(PF_INET, SOCK_STREAM, 0); +m_listenSocket = socket(PF_INET, SOCK_STREAM, 0); struct sockaddr_in listenAddr; listenAddr.sin_family = AF_INET; listenAddr.sin_port = htons(LISTEN_PORT); -listenAddr.sin_addr.s_addr = listenWebAddr; +listenAddr.sin_addr.s_addr = m_listenWebAddr; #ifndef WIN32 int lng = 1; -if (0 != setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, &lng, 4)) +if (0 != setsockopt(m_listenSocket, SOL_SOCKET, SO_REUSEADDR, &lng, 4)) { printf("Setsockopt Fail\n"); printf(">>> Error %s\n", strerror(errno)); @@ -115,16 +115,16 @@ if (0 != setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, &lng, 4)) #endif -res = bind(listenSocket, (struct sockaddr*)&listenAddr, sizeof(listenAddr)); +m_res = bind(m_listenSocket, reinterpret_cast(&listenAddr), sizeof(listenAddr)); -if (res == -1) +if (m_res == -1) { printf("Bind failed.\n"); exit(0); } -res = listen(listenSocket, 0); -if (res == -1) +m_res = listen(m_listenSocket, 0); +if (m_res == -1) { printf("Listen failed.\n"); exit(0); @@ -133,14 +133,14 @@ if (res == -1) //--------------------------------------------------------------------------- void WEB::SetRefreshPagePeriod(int p) { -refreshPeriod = p; -if (refreshPeriod <= 0 || refreshPeriod > 24*3600) - refreshPeriod = 5; +m_refreshPeriod = p; +if (m_refreshPeriod <= 0 || m_refreshPeriod > 24*3600) + m_refreshPeriod = 5; } //--------------------------------------------------------------------------- void WEB::SetListenAddr(uint32_t ip) { -listenWebAddr = ip; +m_listenWebAddr = ip; } //--------------------------------------------------------------------------- void WEB::Run() @@ -157,13 +157,13 @@ while (1) int outerAddrLen = sizeof(outerAddr); #endif - outerSocket = accept(listenSocket, (struct sockaddr*)&outerAddr, &outerAddrLen); - if (outerSocket == -1) + m_outerSocket = accept(m_listenSocket, reinterpret_cast(&outerAddr), &outerAddrLen); + if (m_outerSocket == -1) { printf(">>> Error %s\n", strerror(errno)); continue; } - recv(outerSocket, recvBuffer, sizeof(recvBuffer), 0); + recv(m_outerSocket, recvBuffer, sizeof(recvBuffer), 0); if (strncmp(recvBuffer, "GET /sgauth.css", strlen("GET /sgauth.css")) == 0) { @@ -201,9 +201,9 @@ while (1) } #ifdef WIN32 - closesocket(outerSocket); + closesocket(m_outerSocket); #else - close(outerSocket); + close(m_outerSocket); #endif } } @@ -224,7 +224,7 @@ const char * redirect = char buff[2000]; sprintf(buff, redirect, url); -send(outerSocket, buff, strlen(buff), 0); +send(m_outerSocket, buff, strlen(buff), 0); return 0; } @@ -251,167 +251,167 @@ const char * replyHeader = const char * replyFooter = "\n\n"; char replyHeaderBuffer[2000]; -sprintf(replyHeaderBuffer, replyHeader, refreshPeriod); +sprintf(replyHeaderBuffer, replyHeader, m_refreshPeriod); -send(outerSocket, replyHeaderBuffer, strlen(replyHeaderBuffer), 0); +send(m_outerSocket, replyHeaderBuffer, strlen(replyHeaderBuffer), 0); char str[512]; int st = clnp->GetAuthorized(); sprintf(str, "%s

\n", gettext("Connect")); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str, "%s

\n", gettext("Disconnect")); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str, "%s

\n", gettext("Refresh")); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str, "%s

\n", gettext("Exit")); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str, "

%s

\n" , st ? "ConnectionStateOnline":"ConnectionStateOffline", st ? "Online":"Offline"); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); -sprintf(str, "

%s: %.3f

\n" , gettext("Cash"), ls.cash / 1000.0); -res = send(outerSocket, str, strlen(str), 0); +sprintf(str, "

%s: %.3f

\n" , gettext("Cash"), m_ls.cash / 1000.0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str, "

%s: %s

\n" , gettext("PrepaidTraffic"), - ls.freeMb[0] == 'C' ? ls.freeMb + 1 : ls.freeMb); -res = send(outerSocket, str, strlen(str), 0); + m_ls.freeMb[0] == 'C' ? m_ls.freeMb + 1 : m_ls.freeMb); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str, "\n"); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str, " \n"); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str, " \n"); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); rowNum = 0; for (j = 0; j < DIR_NUM; j++) { - if (dirName[j][0] == 0) + if (m_dirName[j][0] == 0) continue; std::string s; - KOIToWin(dirName[j], &s);// +++++++++ sigsegv ========== TODO too long dir name crashes sgauth + KOIToWin(m_dirName[j], &s);// +++++++++ sigsegv ========== TODO too long dir name crashes sgauth sprintf(str, " \n", rowNum++, s.c_str()); - send(outerSocket, str, strlen(str), 0); + send(m_outerSocket, str, strlen(str), 0); } sprintf(str," \n"); -send(outerSocket, str, strlen(str), 0); +send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n"); -send(outerSocket, str, strlen(str), 0); +send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n", gettext("Month Upload")); -send(outerSocket, str, strlen(str), 0); +send(m_outerSocket, str, strlen(str), 0); rowNum = 0; for (j = 0; j < DIR_NUM; j++) { - if (dirName[j][0] == 0) + if (m_dirName[j][0] == 0) continue; - sprintf(str," \n", rowNum++, IntToKMG(ls.mu[j], ST_F)); - res = send(outerSocket, str, strlen(str), 0); + sprintf(str," \n", rowNum++, IntToKMG(m_ls.mu[j], ST_F)); + m_res = send(m_outerSocket, str, strlen(str), 0); } sprintf(str," \n"); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n"); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n", gettext("Month Download")); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); rowNum = 0; for (j = 0; j < DIR_NUM; j++) { - if (dirName[j][0] == 0) + if (m_dirName[j][0] == 0) continue; - sprintf(str," \n", rowNum++, IntToKMG(ls.md[j], ST_F)); - res = send(outerSocket, str, strlen(str), 0); + sprintf(str," \n", rowNum++, IntToKMG(m_ls.md[j], ST_F)); + m_res = send(m_outerSocket, str, strlen(str), 0); } sprintf(str," \n"); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n"); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n", gettext("Session Upload")); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); rowNum = 0; for (j = 0; j < DIR_NUM; j++) { - if (dirName[j][0] == 0) + if (m_dirName[j][0] == 0) continue; - sprintf(str," \n", rowNum++, IntToKMG(ls.su[j], ST_F)); - res = send(outerSocket, str, strlen(str), 0); + sprintf(str," \n", rowNum++, IntToKMG(m_ls.su[j], ST_F)); + m_res = send(m_outerSocket, str, strlen(str), 0); } sprintf(str," \n"); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n"); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n", gettext("Session Download")); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); for (j = 0; j < DIR_NUM; j++) { - if (dirName[j][0] == 0) + if (m_dirName[j][0] == 0) continue; - sprintf(str," \n", j, IntToKMG(ls.sd[j], ST_F)); - res = send(outerSocket, str, strlen(str), 0); + sprintf(str," \n", j, IntToKMG(m_ls.sd[j], ST_F)); + m_res = send(m_outerSocket, str, strlen(str), 0); } sprintf(str," \n"); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str,"
 %s
%s%s%s
%s%s%s
%s%s%s
%s%s%s
\n"); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); rowNum = 0; -if (!messages.empty()) +if (!m_messages.empty()) { sprintf(str," \n"); - res = send(outerSocket, str, strlen(str), 0); + m_res = send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n"); - send(outerSocket, str, strlen(str), 0); + send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n"); - send(outerSocket, str, strlen(str), 0); + send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n"); - send(outerSocket, str, strlen(str), 0); + send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n"); - send(outerSocket, str, strlen(str), 0); + send(m_outerSocket, str, strlen(str), 0); std::list::reverse_iterator it; - it = messages.rbegin(); - while (it != messages.rend()) + it = m_messages.rbegin(); + while (it != m_messages.rend()) { sprintf(str," \n", rowNum); - send(outerSocket, str, strlen(str), 0); + send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n", it->recvTime.c_str()); - send(outerSocket, str, strlen(str), 0); + send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n", it->msg.c_str()); - send(outerSocket, str, strlen(str), 0); + send(m_outerSocket, str, strlen(str), 0); sprintf(str," \n"); - send(outerSocket, str, strlen(str), 0); + send(m_outerSocket, str, strlen(str), 0); ++it; ++rowNum; } sprintf(str,"
DateText
%s%s
\n"); - res = send(outerSocket, str, strlen(str), 0); + m_res = send(m_outerSocket, str, strlen(str), 0); } time_t t = time(NULL); sprintf(str,"Îáíîâëåíî: %s" , ctime(&t)); -res = send(outerSocket, str, strlen(str), 0); +m_res = send(m_outerSocket, str, strlen(str), 0); -send(outerSocket, replyFooter, strlen(replyFooter), 0); +send(m_outerSocket, replyFooter, strlen(replyFooter), 0); return 0; } @@ -425,16 +425,16 @@ const char * replyHeader = const char * replyFooter= "\n\n"; -send(outerSocket, replyHeader, strlen(replyHeader), 0); -send(outerSocket, SGAuth::css, strlen(SGAuth::css), 0); -send(outerSocket, replyFooter, strlen(replyFooter), 0); +send(m_outerSocket, replyHeader, strlen(replyHeader), 0); +send(m_outerSocket, SGAuth::css, strlen(SGAuth::css), 0); +send(m_outerSocket, replyFooter, strlen(replyFooter), 0); return 0; } //--------------------------------------------------------------------------- void WEB::SetDirName(const std::string & dn, int n) { -web->dirName[n] = dn; +web->m_dirName[n] = dn; } //--------------------------------------------------------------------------- void WEB::AddMessage(const std::string & message, int type) @@ -446,16 +446,16 @@ m.msg = message; m.type = type; m.recvTime = ctime(&t); -messages.push_back(m); +m_messages.push_back(m); -if (messages.size() > MAX_MESSAGES) - messages.pop_front(); +if (m_messages.size() > MAX_MESSAGES) + m_messages.pop_front(); } //--------------------------------------------------------------------------- void WEB::UpdateStat(const LOADSTAT & ls) { -memcpy((void*)&(WEB::ls), &ls, sizeof(LOADSTAT)); +memcpy(&m_ls, &ls, sizeof(LOADSTAT)); } //--------------------------------------------------------------------------- diff --git a/projects/sgauth/web.h b/projects/sgauth/web.h index a933230a..d086125c 100644 --- a/projects/sgauth/web.h +++ b/projects/sgauth/web.h @@ -23,6 +23,12 @@ $Date: 2007/12/17 08:39:08 $ */ +#include "stg/const.h" +#include "stg/ia_packets.h" + +#include +#include + #ifndef WIN32 #include #include @@ -36,53 +42,47 @@ #include #endif -#include -#include - -#include "stg/const.h" -#include "stg/ia_packets.h" - #define MAX_MESSAGES (10) //----------------------------------------------------------------------------- struct STG_MESSAGE { -std::string msg; -std::string recvTime; -int type; + std::string msg; + std::string recvTime; + int type; }; //----------------------------------------------------------------------------- class WEB { -public: - WEB(); - void Run(); - void SetDirName(const std::string & dn, int n); - void SetRefreshPagePeriod(int p); - void SetListenAddr(uint32_t ip); - void AddMessage(const std::string & message, int type); - void UpdateStat(const LOADSTAT & ls); - void Start(); -private: - void PrepareNet(); - int SendReply(); - int SendCSS(); - int Redirect(const char * url); + public: + WEB(); + void Run(); + void SetDirName(const std::string & dn, int n); + void SetRefreshPagePeriod(int p); + void SetListenAddr(uint32_t ip); + void AddMessage(const std::string & message, int type); + void UpdateStat(const LOADSTAT & ls); + void Start(); + private: + void PrepareNet(); + int SendReply(); + int SendCSS(); + int Redirect(const char * url); - #ifdef WIN32 - WSADATA wsaData; - #else - pthread_t thread; - #endif + #ifdef WIN32 + WSADATA m_wsaData; + #else + pthread_t m_thread; + #endif - std::string dirName[DIR_NUM]; - int res; - int listenSocket; - int outerSocket; - int refreshPeriod; + std::string m_dirName[DIR_NUM]; + int m_res; + int m_listenSocket; + int m_outerSocket; + int m_refreshPeriod; - uint32_t listenWebAddr; - LOADSTAT ls; + uint32_t m_listenWebAddr; + LOADSTAT m_ls; - std::list messages; + std::list m_messages; }; //----------------------------------------------------------------------------- diff --git a/projects/sgconf/options.cpp b/projects/sgconf/options.cpp index 06378d1c..1f02fd98 100644 --- a/projects/sgconf/options.cpp +++ b/projects/sgconf/options.cpp @@ -37,7 +37,7 @@ namespace { template -void ReadConfigFile(const std::string & filePath, void (C::* callback)(const std::string&, const std::string&), C * obj) +void ReadConfigFile(const std::string& filePath, void (C::* callback)(const std::string&, const std::string&), C* obj) { std::ifstream stream(filePath.c_str()); std::string line; @@ -70,10 +70,10 @@ using SGCONF::OPTION_BLOCKS; using SGCONF::ACTION; using SGCONF::PARSER_STATE; -OPTION::OPTION(const std::string & shortName, - const std::string & longName, +OPTION::OPTION(const std::string& shortName, + const std::string& longName, std::unique_ptr action, - const std::string & description) + const std::string& description) : m_shortName(shortName), m_longName(longName), m_action(std::move(action)), @@ -81,9 +81,9 @@ OPTION::OPTION(const std::string & shortName, { } -OPTION::OPTION(const std::string & longName, +OPTION::OPTION(const std::string& longName, std::unique_ptr action, - const std::string & description) + const std::string& description) : m_longName(longName), m_action(std::move(action)), m_description(description) @@ -103,7 +103,7 @@ void OPTION::Help(size_t level) const m_action->Suboptions().Help(level); } -bool OPTION::Check(const char * arg) const +bool OPTION::Check(const char* arg) const { if (arg == NULL) return false; @@ -117,7 +117,7 @@ bool OPTION::Check(const char * arg) const return m_shortName == arg; } -PARSER_STATE OPTION::Parse(int argc, char ** argv, void * data) +PARSER_STATE OPTION::Parse(int argc, char** argv, void* data) { if (!m_action) throw ERROR("Option is not defined."); @@ -125,7 +125,7 @@ PARSER_STATE OPTION::Parse(int argc, char ** argv, void * data) { return m_action->Parse(argc, argv, data); } - catch (const ACTION::ERROR & ex) + catch (const ACTION::ERROR& ex) { if (m_longName.empty()) throw ERROR("-" + m_shortName + ": " + ex.what()); @@ -135,7 +135,7 @@ PARSER_STATE OPTION::Parse(int argc, char ** argv, void * data) } } -void OPTION::ParseValue(const std::string & value) +void OPTION::ParseValue(const std::string& value) { if (!m_action) throw ERROR("Option is not defined."); @@ -143,24 +143,24 @@ void OPTION::ParseValue(const std::string & value) { return m_action->ParseValue(value); } - catch (const ACTION::ERROR & ex) + catch (const ACTION::ERROR& ex) { throw ERROR(m_longName + ": " + ex.what()); } } -OPTION_BLOCK & OPTION_BLOCK::Add(const std::string & shortName, - const std::string & longName, - std::unique_ptr action, - const std::string & description) +OPTION_BLOCK& OPTION_BLOCK::Add(const std::string& shortName, + const std::string& longName, + std::unique_ptr action, + const std::string& description) { m_options.emplace_back(shortName, longName, std::move(action), description); return *this; } -OPTION_BLOCK & OPTION_BLOCK::Add(const std::string & longName, - std::unique_ptr action, - const std::string & description) +OPTION_BLOCK& OPTION_BLOCK::Add(const std::string& longName, + std::unique_ptr action, + const std::string& description) { m_options.emplace_back(longName, std::move(action), description); return *this; @@ -176,7 +176,7 @@ void OPTION_BLOCK::Help(size_t level) const option.Help(level + 1); } -PARSER_STATE OPTION_BLOCK::Parse(int argc, char ** argv, void * data) +PARSER_STATE OPTION_BLOCK::Parse(int argc, char** argv, void* data) { PARSER_STATE state(false, argc, argv); if (state.argc == 0) @@ -192,14 +192,14 @@ PARSER_STATE OPTION_BLOCK::Parse(int argc, char ** argv, void * data) return state; } -void OPTION_BLOCK::ParseFile(const std::string & filePath) +void OPTION_BLOCK::ParseFile(const std::string& filePath) { if (access(filePath.c_str(), R_OK)) throw ERROR("File '" + filePath + "' does not exists."); ReadConfigFile(filePath, &OPTION_BLOCK::OptionCallback, this); } -void OPTION_BLOCK::OptionCallback(const std::string & key, const std::string & value) +void OPTION_BLOCK::OptionCallback(const std::string& key, const std::string& value) { for (auto& option : m_options) if (option.Name() == key) @@ -215,7 +215,7 @@ void OPTION_BLOCKS::Help(size_t level) const } } -PARSER_STATE OPTION_BLOCKS::Parse(int argc, char ** argv) +PARSER_STATE OPTION_BLOCKS::Parse(int argc, char** argv) { PARSER_STATE state(false, argc, argv); auto it = m_blocks.begin(); diff --git a/projects/sgconf/options.h b/projects/sgconf/options.h index 012b5167..f2f0a0eb 100644 --- a/projects/sgconf/options.h +++ b/projects/sgconf/options.h @@ -36,26 +36,26 @@ struct PARSER_STATE; class OPTION { public: - OPTION(const std::string & shortName, - const std::string & longName, + OPTION(const std::string& shortName, + const std::string& longName, std::unique_ptr action, - const std::string & description); - OPTION(const std::string & longName, + const std::string& description); + OPTION(const std::string& longName, std::unique_ptr action, - const std::string & description); + const std::string& description); OPTION(OPTION&& rhs) = default; - OPTION& operator=(OPTION& rhs) = default; + OPTION& operator=(OPTION&& rhs) = default; void Help(size_t level = 0) const; - PARSER_STATE Parse(int argc, char ** argv, void * data); + PARSER_STATE Parse(int argc, char** argv, void* data); void ParseValue(const std::string & value); - bool Check(const char * arg) const; - const std::string & Name() const { return m_longName; } + bool Check(const char* arg) const; + const std::string& Name() const { return m_longName; } struct ERROR : std::runtime_error { - explicit ERROR(const std::string & message) + explicit ERROR(const std::string & message) noexcept : std::runtime_error(message.c_str()) {} }; @@ -70,28 +70,28 @@ class OPTION_BLOCK { public: OPTION_BLOCK() {} - explicit OPTION_BLOCK(const std::string & description) + explicit OPTION_BLOCK(const std::string& description) : m_description(description) {} OPTION_BLOCK(OPTION_BLOCK&&) = default; OPTION_BLOCK& operator=(OPTION_BLOCK&&) = default; - OPTION_BLOCK & Add(const std::string & shortName, - const std::string & longName, - std::unique_ptr action, - const std::string & description); - OPTION_BLOCK & Add(const std::string & longName, - std::unique_ptr action, - const std::string & description); + OPTION_BLOCK& Add(const std::string& shortName, + const std::string& longName, + std::unique_ptr action, + const std::string& description); + OPTION_BLOCK& Add(const std::string& longName, + std::unique_ptr action, + const std::string& description); void Help(size_t level) const; - PARSER_STATE Parse(int argc, char ** argv, void * data = NULL); - void ParseFile(const std::string & filePath); + PARSER_STATE Parse(int argc, char** argv, void* data = NULL); + void ParseFile(const std::string& filePath); struct ERROR : std::runtime_error { - explicit ERROR(const std::string & message) + explicit ERROR(const std::string & message) noexcept : std::runtime_error(message.c_str()) {} }; @@ -99,17 +99,17 @@ class OPTION_BLOCK std::vector