namespace STG
{
-struct Admin;
+class Admin;
struct CorpConf;
struct Corporations {
struct Settings;
struct Store;
struct Admins;
-struct Users;
-struct Tariffs;
+class Users;
+class Tariffs;
struct Services;
struct Corporations;
struct ModuleSettings;
namespace STG
{
-struct Admin;
+class Admin;
struct ServiceConf;
struct ServiceConfOpt;
namespace STG
{
-struct Admin;
+class Admin;
struct Tariff;
struct TariffData;
namespace STG
{
-struct Admin;
-struct User;
+class Admin;
+class User;
struct Auth;
class Users
//---------------------------------------------------------------------------
+#include "stg/common.h"
+#include "stg/ia.h"
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <cassert>
+
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#include <csignal>
#endif
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <cassert>
-
-#include "stg/common.h"
-#include "stg/ia.h"
-
#define IA_NONE (0)
#define IA_CONNECT (1)
#define IA_DISCONNECT (2)
sigfillset(&signalSet);
pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
-IA_CLIENT_PROT * c = (IA_CLIENT_PROT *)data;
+auto* c = static_cast<IA_CLIENT_PROT*>(data);
static int a = 0;
if (a == 0)
//---------------------------------------------------------------------------
unsigned long WINAPI RunW(void * data)
{
-IA_CLIENT_PROT * c = (IA_CLIENT_PROT *)data;
+auto* c = static_cast<IA_CLIENT_PROT*>(data);
while (c->GetNonstop())
c->Run();
return 0;
hostent * phe = gethostbyname(hostName.c_str());
if (phe)
{
- ip = *((uint32_t *)phe->h_addr_list[0]);
+ ip = *reinterpret_cast<uint32_t*>(phe->h_addr_list[0]);
}
else
{
//---------------------------------------------------------------------------
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()
}
}*/
-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<sockaddr*>(&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
IA_CLIENT_PROT::~IA_CLIENT_PROT()
{
#ifndef WIN32
-close(sockr);
+close(m_sockr);
#else
-closesocket(sockr);
+closesocket(m_sockr);
WSACleanup();
#endif
}
int IA_CLIENT_PROT::DeterminatePacketType(const char * buffer)
{
std::map<std::string, int>::iterator pi;
-pi = packetTypes.find(buffer);
-if (pi == packetTypes.end())
+pi = m_packetTypes.find(buffer);
+if (pi == m_packetTypes.end())
{
return -1;
}
}
}
//---------------------------------------------------------------------------
-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<sockaddr*>(&m_servAddr), sizeof(m_servAddr));
}
//---------------------------------------------------------------------------
int IA_CLIENT_PROT::Recv(char * buffer, int len)
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<sockaddr*>(&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;
}
//---------------------------------------------------------------------------
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<int>(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<int>(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<int>(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<int>(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;
//---------------------------------------------------------------------------
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<std::string> dirNames;
-connSynAck8 = (CONN_SYN_ACK_8*)buffer;
+m_connSynAck8 = static_cast<const CONN_SYN_ACK_8*>(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<const char*>(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<const ALIVE_SYN_8*>(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<const DISCONN_SYN_ACK_8*>(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<const INFO_8*>(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<const char*>(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));
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<const char*>(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<CONN_SYN_8*>(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<char*>(m_connSyn8->type), "CONN_SYN", IA_MAX_TYPE_LEN);
+strncpy(reinterpret_cast<char*>(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<CONN_ACK_8*>(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<char*>(m_connAck8->loginS), m_login.c_str(), IA_LOGIN_LEN);
+strncpy(reinterpret_cast<char*>(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<ALIVE_ACK_8*>(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<char*>(m_aliveAck8->loginS), m_login.c_str(), IA_LOGIN_LEN);
+strncpy(reinterpret_cast<char*>(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<DISCONN_SYN_8*>(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<char*>(m_disconnSyn8->loginS), m_login.c_str(), IA_LOGIN_LEN);
+strncpy(reinterpret_cast<char*>(m_disconnSyn8->type), "DISCONN_SYN", IA_MAX_TYPE_LEN);
+strncpy(reinterpret_cast<char*>(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<DISCONN_ACK_8*>(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<char*>(m_disconnAck8->loginS), m_login.c_str(), IA_LOGIN_LEN);
+strncpy(reinterpret_cast<char*>(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;
}
//---------------------------------------------------------------------------
* Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
*/
//---------------------------------------------------------------------------
-#ifndef IA_AUTH_C_H
-#define IA_AUTH_C_H
+#pragma once
+
+#include "stg/blowfish.h"
+#include "stg/ia_packets.h"
+
+#include <string>
+#include <vector>
+#include <map>
#ifndef WIN32
#include <sys/types.h>
#include <winsock2.h>
#endif
-#include <string>
-#include <vector>
-#include <map>
-
-#include "stg/blowfish.h"
-#include "stg/ia_packets.h"
-
#define IA_BIND_ERROR (1)
#define IA_SERVER_ERROR (2)
#define IA_FCNTL_ERROR (3)
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<std::string, int> 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<std::string, int> 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
#else
void * RunW(void *);
#endif
-
-//---------------------------------------------------------------------------
-#endif //IA_AUTH_C_H
$Author: nobunaga $
*/
-#ifndef PINGER_H
-#define PINGER_H
+#pragma once
-#include <ctime>
#include <string>
#include <list>
#include <map>
+#include <ctime>
+#include <cstdint>
#ifdef LINUX
#include <sys/types.h>
#include <arpa/inet.h>
#endif
-#include <cstdint>
-
//-----------------------------------------------------------------------------
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;
};
//-----------------------------------------------------------------------------
struct PING_IP_TIME
{
-uint32_t ip;
-time_t pingTime;
+ uint32_t ip;
+ time_t pingTime;
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
class STG_PINGER
{
-public:
- typedef std::multimap<uint32_t, time_t> 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<uint32_t, time_t> pingIP;
- std::list<uint32_t> ipToAdd;
- std::list<uint32_t> ipToDel;
-
- mutable pthread_mutex_t mutex;
+ public:
+ typedef std::multimap<uint32_t, time_t> 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<uint32_t, time_t> m_pingIP;
+ std::list<uint32_t> m_ipToAdd;
+ std::list<uint32_t> m_ipToDel;
+
+ mutable pthread_mutex_t m_mutex;
};
-//-----------------------------------------------------------------------------
-#endif
//-----------------------------------------------------------------------------
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<uint32_t>(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;
}
//-----------------------------------------------------------------------------
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++)
if (i % 5 == 0)
SendPing(0x0100007f);//127.0.0.1
- if (!isRunningRecver)
+ if (!m_isRunningRecver)
break;
struct timespec ts = {0, 200000000};
}
}
-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};
}
}
-close(sendSocket);
+close(m_sendSocket);
-if (isRunningSender || isRunningRecver)
+if (m_isRunningSender || m_isRunningRecver)
return -1;
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<uint32_t>::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<uint32_t>::iterator iter;
-std::multimap<uint32_t, time_t>::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<uint32_t, time_t>::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;
//-----------------------------------------------------------------------------
int STG_PINGER::GetIPTime(uint32_t ip, time_t * t) const
{
-STG_LOCKER lock(&mutex);
-std::multimap<uint32_t, time_t>::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;
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<uint16_t>(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<uint16_t>(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<sockaddr*>(&addr), sizeof(addr)) <= 0 )
{
- errorStr = "Send ping error: " + std::string(strerror(errno));
+ m_errorStr = "Send ping error: " + std::string(strerror(errno));
return -1;
}
memset(buf, 0, sizeof(buf));
socklen_t len = sizeof(addr);
-if (recvfrom(recvSocket, &buf, sizeof(buf), 0, reinterpret_cast<struct sockaddr*>(&addr), &len))
+if (recvfrom(m_recvSocket, &buf, sizeof(buf), 0, reinterpret_cast<struct sockaddr*>(&addr), &len))
{
struct IP_HDR * ip = static_cast<struct IP_HDR *>(static_cast<void *>(buf));
struct ICMP_HDR *icmp = static_cast<struct ICMP_HDR *>(static_cast<void *>(buf + ip->ihl * 4));
- if (icmp->un.echo.id != pid)
+ if (icmp->un.echo.id != m_pid)
return 0;
ipAddr = *static_cast<uint32_t*>(static_cast<void *>(buf + sizeof(ICMP_HDR) + ip->ihl * 4));
sigfillset(&signalSet);
pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
-STG_PINGER * pinger = static_cast<STG_PINGER *>(d);
+auto* pinger = static_cast<STG_PINGER *>(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<uint32_t, time_t>::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;
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;
}
}
-pinger->isRunningSender = false;
+pinger->m_isRunningSender = false;
return NULL;
}
sigfillset(&signalSet);
pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
-STG_PINGER * pinger = static_cast<STG_PINGER *>(d);
+auto* pinger = static_cast<STG_PINGER *>(d);
-pinger->isRunningRecver = true;
+pinger->m_isRunningRecver = true;
-while (pinger->nonstop)
+while (pinger->m_nonstop)
{
uint32_t ip = pinger->RecvPing();
if (ip)
{
- std::multimap<uint32_t, time_t>::iterator treeIterUpper = pinger->pingIP.upper_bound(ip);
- std::multimap<uint32_t, time_t>::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
}
}
-pinger->isRunningRecver = false;
+pinger->m_isRunningRecver = false;
return NULL;
}
//-----------------------------------------------------------------------------
private:
class Impl;
- Impl* pImpl;
+ Impl* m_impl;
};
} // namespace STG
//---------------------------------------------------------------------------
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)
{
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
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<uint32_t*>(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<sockaddr*>(&localAddr), sizeof(localAddr)) < 0)
{
- errorMsg = BIND_FAILED;
+ m_errorMsg = BIND_FAILED;
return st_conn_fail;
}
}
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<uint32_t*>(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<sockaddr *>(&outerAddr), sizeof(outerAddr)) < 0)
{
- errorMsg = CONNECT_FAILED;
+ m_errorMsg = CONNECT_FAILED;
return st_conn_fail;
}
//---------------------------------------------------------------------------
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;
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
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;
}
{
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;
}
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;
}
//---------------------------------------------------------------------------
{
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;
}
{
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;
}
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;
}
//---------------------------------------------------------------------------
memset(loginZ, 0, ADM_LOGIN_LEN + 1);
BLOWFISH_CTX ctx;
- InitContext(password.c_str(), PASSWD_LEN, &ctx);
- EncryptString(loginZ, login.c_str(), std::min<size_t>(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<size_t>(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;
}
{
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;
}
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;
}
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);
{
assert(data != NULL);
auto& nt = *static_cast<NetTransact*>(data);
- if (!WriteAll(nt.sock, block, size))
+ if (!WriteAll(nt.m_sock, block, size))
return false;
return true;
}
~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();
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);
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);
template <class P, typename C>
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 <class P, typename C>
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);
bool ServConf::Impl::ParserRecv(const std::string& chunk, bool last, void* data)
{
- auto sc = static_cast<ServConf::Impl*>(data);
+ auto* sc = static_cast<ServConf::Impl*>(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<int>(XML_GetCurrentLineNumber(sc->parser)),
- static_cast<int>(XML_GetCurrentColumnNumber(sc->parser)),
- XML_ErrorString(XML_GetErrorCode(sc->parser)), static_cast<int>(last));
+ strprintf(&sc->m_errorMsg, "XML parse error at line %d, %d: %s. Is last: %d",
+ static_cast<int>(XML_GetCurrentLineNumber(sc->m_parser)),
+ static_cast<int>(XML_GetCurrentColumnNumber(sc->m_parser)),
+ XML_ErrorString(XML_GetErrorCode(sc->m_parser)), static_cast<int>(last));
return false;
}
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<ServerInfo::Parser>("<GetServerInfo/>", f, data);
+ return m_impl->Exec<ServerInfo::Parser>("<GetServerInfo/>", 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<GetAdmin::Info>::Type f, void* data)
{
- return pImpl->Exec<GetContainer::Parser<GetAdmin::Parser> >("admins", "<GetAdmins/>", f, data);
+ return m_impl->Exec<GetContainer::Parser<GetAdmin::Parser> >("admins", "<GetAdmins/>", f, data);
}
int ServConf::GetAdmin(const std::string& login, GetAdmin::Callback f, void* data)
{
- return pImpl->Exec<GetAdmin::Parser>("<GetAdmin login=\"" + login + "\"/>", f, data);
+ return m_impl->Exec<GetAdmin::Parser>("<GetAdmin login=\"" + login + "\"/>", f, data);
}
int ServConf::ChgAdmin(const AdminConfOpt& conf, Simple::Callback f, void* data)
{
- return pImpl->Exec<Simple::Parser>("ChgAdmin", "<ChgAdmin" + ChgAdmin::serialize(conf, pImpl->Encoding()) + "/>", f, data);
+ return m_impl->Exec<Simple::Parser>("ChgAdmin", "<ChgAdmin" + ChgAdmin::serialize(conf, m_impl->Encoding()) + "/>", f, data);
}
int ServConf::AddAdmin(const std::string& login,
const AdminConfOpt& conf,
Simple::Callback f, void* data)
{
- auto res = pImpl->Exec<Simple::Parser>("AddAdmin", "<AddAdmin login=\"" + login + "\"/>", f, data);
+ auto res = m_impl->Exec<Simple::Parser>("AddAdmin", "<AddAdmin login=\"" + login + "\"/>", f, data);
if (res != st_ok)
return res;
- return pImpl->Exec<Simple::Parser>("ChgAdmin", "<ChgAdmin" + ChgAdmin::serialize(conf, pImpl->Encoding()) + "/>", f, data);
+ return m_impl->Exec<Simple::Parser>("ChgAdmin", "<ChgAdmin" + ChgAdmin::serialize(conf, m_impl->Encoding()) + "/>", f, data);
}
int ServConf::DelAdmin(const std::string& login, Simple::Callback f, void* data)
{
- return pImpl->Exec<Simple::Parser>("DelAdmin", "<DelAdmin login=\"" + login + "\"/>", f, data);
+ return m_impl->Exec<Simple::Parser>("DelAdmin", "<DelAdmin login=\"" + login + "\"/>", f, data);
}
// -- Tariffs --
int ServConf::GetTariffs(GetContainer::Callback<GetTariff::Info>::Type f, void* data)
{
- return pImpl->Exec<GetContainer::Parser<GetTariff::Parser> >("tariffs", "<GetTariffs/>", f, data);
+ return m_impl->Exec<GetContainer::Parser<GetTariff::Parser> >("tariffs", "<GetTariffs/>", f, data);
}
int ServConf::GetTariff(const std::string& name, GetTariff::Callback f, void* data)
{
- return pImpl->Exec<GetTariff::Parser>("<GetTariff name=\"" + name + "\"/>", f, data);
+ return m_impl->Exec<GetTariff::Parser>("<GetTariff name=\"" + name + "\"/>", f, data);
}
int ServConf::ChgTariff(const TariffDataOpt& tariffData, Simple::Callback f, void* data)
{
- return pImpl->Exec<Simple::Parser>("SetTariff", "<SetTariff name=\"" + tariffData.tariffConf.name.value() + "\">" + ChgTariff::serialize(tariffData, pImpl->Encoding()) + "</SetTariff>", f, data);
+ return m_impl->Exec<Simple::Parser>("SetTariff", "<SetTariff name=\"" + tariffData.tariffConf.name.value() + "\">" + ChgTariff::serialize(tariffData, m_impl->Encoding()) + "</SetTariff>", f, data);
}
int ServConf::AddTariff(const std::string& name,
const TariffDataOpt& tariffData,
Simple::Callback f, void* data)
{
- auto res = pImpl->Exec<Simple::Parser>("AddTariff", "<AddTariff name=\"" + name + "\"/>", f, data);
+ auto res = m_impl->Exec<Simple::Parser>("AddTariff", "<AddTariff name=\"" + name + "\"/>", f, data);
if (res != st_ok)
return res;
- return pImpl->Exec<Simple::Parser>("SetTariff", "<SetTariff name=\"" + name + "\">" + ChgTariff::serialize(tariffData, pImpl->Encoding()) + "</SetTariff>", f, data);
+ return m_impl->Exec<Simple::Parser>("SetTariff", "<SetTariff name=\"" + name + "\">" + ChgTariff::serialize(tariffData, m_impl->Encoding()) + "</SetTariff>", f, data);
}
int ServConf::DelTariff(const std::string& name, Simple::Callback f, void* data)
{
- return pImpl->Exec<Simple::Parser>("DelTariff", "<DelTariff name=\"" + name + "\"/>", f, data);
+ return m_impl->Exec<Simple::Parser>("DelTariff", "<DelTariff name=\"" + name + "\"/>", f, data);
}
// -- Users --
int ServConf::GetUsers(GetContainer::Callback<GetUser::Info>::Type f, void* data)
{
- return pImpl->Exec<GetContainer::Parser<GetUser::Parser> >("users", "<GetUsers/>", f, data);
+ return m_impl->Exec<GetContainer::Parser<GetUser::Parser> >("users", "<GetUsers/>", f, data);
}
int ServConf::GetUser(const std::string& login, GetUser::Callback f, void* data)
{
- return pImpl->Exec<GetUser::Parser>("<GetUser login=\"" + login + "\"/>", f, data);
+ return m_impl->Exec<GetUser::Parser>("<GetUser login=\"" + login + "\"/>", f, data);
}
int ServConf::ChgUser(const std::string& login,
const UserStatOpt& stat,
Simple::Callback f, void* data)
{
- return pImpl->Exec<ChgUser::Parser>("<SetUser><Login value=\"" + login + "\"/>" + ChgUser::serialize(conf, stat, pImpl->Encoding()) + "</SetUser>", f, data);
+ return m_impl->Exec<ChgUser::Parser>("<SetUser><Login value=\"" + login + "\"/>" + ChgUser::serialize(conf, stat, m_impl->Encoding()) + "</SetUser>", f, data);
}
int ServConf::DelUser(const std::string& login, Simple::Callback f, void* data)
{
- return pImpl->Exec<Simple::Parser>("DelUser", "<DelUser login=\"" + login + "\"/>", f, data);
+ return m_impl->Exec<Simple::Parser>("DelUser", "<DelUser login=\"" + login + "\"/>", f, data);
}
int ServConf::AddUser(const std::string& login,
const UserStatOpt& stat,
Simple::Callback f, void* data)
{
- auto res = pImpl->Exec<Simple::Parser>("AddUser", "<AddUser><Login value=\"" + login + "\"/></AddUser>", f, data);
+ auto res = m_impl->Exec<Simple::Parser>("AddUser", "<AddUser><Login value=\"" + login + "\"/></AddUser>", f, data);
if (res != st_ok)
return res;
- return pImpl->Exec<ChgUser::Parser>("<SetUser><Login value=\"" + login + "\"/>" + ChgUser::serialize(conf, stat, pImpl->Encoding()) + "</SetUser>", f, data);
+ return m_impl->Exec<ChgUser::Parser>("<SetUser><Login value=\"" + login + "\"/>" + ChgUser::serialize(conf, stat, m_impl->Encoding()) + "</SetUser>", f, data);
}
int ServConf::AuthBy(const std::string& login, AuthBy::Callback f, void* data)
{
- return pImpl->Exec<AuthBy::Parser>("<GetUserAuthBy login=\"" + login + "\"/>", f, data);
+ return m_impl->Exec<AuthBy::Parser>("<GetUserAuthBy login=\"" + login + "\"/>", f, data);
}
int ServConf::SendMessage(const std::string& login, const std::string& text, Simple::Callback f, void* data)
{
- return pImpl->Exec<Simple::Parser>("SendMessageResult", "<Message login=\"" + login + "\" msgver=\"1\" msgtype=\"1\" repeat=\"0\" repeatperiod=\"0\" showtime=\"0\" text=\"" + Encode12str(text) + "\"/>", f, data);
+ return m_impl->Exec<Simple::Parser>("SendMessageResult", "<Message login=\"" + login + "\" msgver=\"1\" msgtype=\"1\" repeat=\"0\" repeatperiod=\"0\" showtime=\"0\" text=\"" + Encode12str(text) + "\"/>", f, data);
}
int ServConf::CheckUser(const std::string& login, const std::string& password, Simple::Callback f, void* data)
{
- return pImpl->Exec<Simple::Parser>("CheckUser", "<CheckUser login=\"" + login + "\" password=\"" + password + "\"/>", f, data);
+ return m_impl->Exec<Simple::Parser>("CheckUser", "<CheckUser login=\"" + login + "\" password=\"" + password + "\"/>", f, data);
}
// -- Services --
int ServConf::GetServices(GetContainer::Callback<GetService::Info>::Type f, void* data)
{
- return pImpl->Exec<GetContainer::Parser<GetService::Parser> >("services", "<GetServices/>", f, data);
+ return m_impl->Exec<GetContainer::Parser<GetService::Parser> >("services", "<GetServices/>", f, data);
}
int ServConf::GetService(const std::string& name, GetService::Callback f, void* data)
{
- return pImpl->Exec<GetService::Parser>("<GetService name=\"" + name + "\"/>", f, data);
+ return m_impl->Exec<GetService::Parser>("<GetService name=\"" + name + "\"/>", f, data);
}
int ServConf::ChgService(const ServiceConfOpt& conf, Simple::Callback f, void* data)
{
- return pImpl->Exec<Simple::Parser>("SetService", "<SetService " + ChgService::serialize(conf, pImpl->Encoding()) + "/>", f, data);
+ return m_impl->Exec<Simple::Parser>("SetService", "<SetService " + ChgService::serialize(conf, m_impl->Encoding()) + "/>", f, data);
}
int ServConf::AddService(const std::string& name,
const ServiceConfOpt& conf,
Simple::Callback f, void* data)
{
- auto res = pImpl->Exec<Simple::Parser>("AddService", "<AddService name=\"" + name + "\"/>", f, data);
+ auto res = m_impl->Exec<Simple::Parser>("AddService", "<AddService name=\"" + name + "\"/>", f, data);
if (res != st_ok)
return res;
- return pImpl->Exec<Simple::Parser>("SetService", "<SetService " + ChgService::serialize(conf, pImpl->Encoding()) + "/>", f, data);
+ return m_impl->Exec<Simple::Parser>("SetService", "<SetService " + ChgService::serialize(conf, m_impl->Encoding()) + "/>", f, data);
}
int ServConf::DelService(const std::string& name, Simple::Callback f, void* data)
{
- return pImpl->Exec<Simple::Parser>("DelService", "<DelService name=\"" + name + "\"/>", f, data);
+ return m_impl->Exec<Simple::Parser>("DelService", "<DelService name=\"" + name + "\"/>", f, data);
}
// -- Corporations --
int ServConf::GetCorporations(GetContainer::Callback<GetCorp::Info>::Type f, void* data)
{
- return pImpl->Exec<GetContainer::Parser<GetCorp::Parser> >("corporations", "<GetCorporations/>", f, data);
+ return m_impl->Exec<GetContainer::Parser<GetCorp::Parser> >("corporations", "<GetCorporations/>", f, data);
}
int ServConf::GetCorp(const std::string& name, GetCorp::Callback f, void* data)
{
- return pImpl->Exec<GetCorp::Parser>("<GetCorp name=\"" + name + "\"/>", f, data);
+ return m_impl->Exec<GetCorp::Parser>("<GetCorp name=\"" + name + "\"/>", f, data);
}
int ServConf::ChgCorp(const CorpConfOpt & conf, Simple::Callback f, void* data)
{
- return pImpl->Exec<Simple::Parser>("SetCorp", "<SetCorp name=\"" + conf.name.value() + "\">" + ChgCorp::serialize(conf, pImpl->Encoding()) + "</SetCorp>", f, data);
+ return m_impl->Exec<Simple::Parser>("SetCorp", "<SetCorp name=\"" + conf.name.value() + "\">" + ChgCorp::serialize(conf, m_impl->Encoding()) + "</SetCorp>", f, data);
}
int ServConf::AddCorp(const std::string& name,
const CorpConfOpt& conf,
Simple::Callback f, void* data)
{
- auto res = pImpl->Exec<Simple::Parser>("AddCorp", "<AddCorp name=\"" + name + "\"/>", f, data);
+ auto res = m_impl->Exec<Simple::Parser>("AddCorp", "<AddCorp name=\"" + name + "\"/>", f, data);
if (res != st_ok)
return res;
- return pImpl->Exec<Simple::Parser>("SetCorp", "<SetCorp name=\"" + name + "\">" + ChgCorp::serialize(conf, pImpl->Encoding()) + "</SetCorp>", f, data);
+ return m_impl->Exec<Simple::Parser>("SetCorp", "<SetCorp name=\"" + name + "\">" + ChgCorp::serialize(conf, m_impl->Encoding()) + "</SetCorp>", f, data);
}
int ServConf::DelCorp(const std::string& name, Simple::Callback f, void* data)
{
- return pImpl->Exec<Simple::Parser>("DelCorp", "<DelCorp name=\"" + name + "\"/>", f, data);
+ return m_impl->Exec<Simple::Parser>("DelCorp", "<DelCorp name=\"" + name + "\"/>", 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)
//-----------------------------------------------------------------------------
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;
}
}
//---------------------------------------------------------------------------
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()
&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));
#endif
-res = bind(listenSocket, (struct sockaddr*)&listenAddr, sizeof(listenAddr));
+m_res = bind(m_listenSocket, reinterpret_cast<sockaddr*>(&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);
//---------------------------------------------------------------------------
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()
int outerAddrLen = sizeof(outerAddr);
#endif
- outerSocket = accept(listenSocket, (struct sockaddr*)&outerAddr, &outerAddrLen);
- if (outerSocket == -1)
+ m_outerSocket = accept(m_listenSocket, reinterpret_cast<sockaddr*>(&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)
{
}
#ifdef WIN32
- closesocket(outerSocket);
+ closesocket(m_outerSocket);
#else
- close(outerSocket);
+ close(m_outerSocket);
#endif
}
}
char buff[2000];
sprintf(buff, redirect, url);
-send(outerSocket, buff, strlen(buff), 0);
+send(m_outerSocket, buff, strlen(buff), 0);
return 0;
}
const char * replyFooter = "</body></html>\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, "<a href=\"connect\">%s</a><p>\n", gettext("Connect"));
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str, "<a href=\"disconnect\">%s</a><p>\n", gettext("Disconnect"));
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str, "<a href=\"/\">%s</a><p>\n", gettext("Refresh"));
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str, "<a href=\"exit\">%s</a><p>\n", gettext("Exit"));
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str, "<div id=\"%s\">%s</div><p>\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, "<div id=\"Cash\">%s: %.3f</div><p>\n" , gettext("Cash"), ls.cash / 1000.0);
-res = send(outerSocket, str, strlen(str), 0);
+sprintf(str, "<div id=\"Cash\">%s: %.3f</div><p>\n" , gettext("Cash"), m_ls.cash / 1000.0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str, "<div id=\"Prepaid Traffic\">%s: %s</div><p>\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, "<TABLE id=\"TraffTable\">\n");
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str, " <TR id=\"TraffTableCaptionRow\">\n");
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str, " <TD id=\"TraffTableCaptionCellC\"> </TD>\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, " <TD id=\"TraffTableCaptionCell%d\">%s</TD>\n", rowNum++, s.c_str());
- send(outerSocket, str, strlen(str), 0);
+ send(m_outerSocket, str, strlen(str), 0);
}
sprintf(str," </TR>\n");
-send(outerSocket, str, strlen(str), 0);
+send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TR id=\"TraffTableUMRow\">\n");
-send(outerSocket, str, strlen(str), 0);
+send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TD id=\"TraffTableUMCellC\">%s</TD>\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," <TD id=\"TraffTableUMCell%d\">%s</TD>\n", rowNum++, IntToKMG(ls.mu[j], ST_F));
- res = send(outerSocket, str, strlen(str), 0);
+ sprintf(str," <TD id=\"TraffTableUMCell%d\">%s</TD>\n", rowNum++, IntToKMG(m_ls.mu[j], ST_F));
+ m_res = send(m_outerSocket, str, strlen(str), 0);
}
sprintf(str," </TR>\n");
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TR id=\"TraffTableDMRow\">\n");
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TD id=\"TraffTableDMCellC\">%s</TD>\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," <TD id=\"TraffTableDMCell%d\">%s</TD>\n", rowNum++, IntToKMG(ls.md[j], ST_F));
- res = send(outerSocket, str, strlen(str), 0);
+ sprintf(str," <TD id=\"TraffTableDMCell%d\">%s</TD>\n", rowNum++, IntToKMG(m_ls.md[j], ST_F));
+ m_res = send(m_outerSocket, str, strlen(str), 0);
}
sprintf(str," </TR>\n");
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TR id=\"TraffTableUSRow\">\n");
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TD id=\"TraffTableUSCellC\">%s</TD>\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," <TD id=\"TraffTableUSCell%d\">%s</TD>\n", rowNum++, IntToKMG(ls.su[j], ST_F));
- res = send(outerSocket, str, strlen(str), 0);
+ sprintf(str," <TD id=\"TraffTableUSCell%d\">%s</TD>\n", rowNum++, IntToKMG(m_ls.su[j], ST_F));
+ m_res = send(m_outerSocket, str, strlen(str), 0);
}
sprintf(str," </TR>\n");
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TR id=\"TraffTableDSRow\">\n");
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TD id=\"TraffTableDSCellC\">%s</TD>\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," <TD id=\"TraffTableDSCell%d\">%s</TD>\n", j, IntToKMG(ls.sd[j], ST_F));
- res = send(outerSocket, str, strlen(str), 0);
+ sprintf(str," <TD id=\"TraffTableDSCell%d\">%s</TD>\n", j, IntToKMG(m_ls.sd[j], ST_F));
+ m_res = send(m_outerSocket, str, strlen(str), 0);
}
sprintf(str," </TR>\n");
-res = send(outerSocket, str, strlen(str), 0);
+m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str,"</TABLE>\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," <TABLE id=\"MessagesTable\">\n");
- res = send(outerSocket, str, strlen(str), 0);
+ m_res = send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TR id=\"MessagesTableRowC\">\n");
- send(outerSocket, str, strlen(str), 0);
+ send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TD>Date</TD>\n");
- send(outerSocket, str, strlen(str), 0);
+ send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TD>Text</TD>\n");
- send(outerSocket, str, strlen(str), 0);
+ send(m_outerSocket, str, strlen(str), 0);
sprintf(str," </TR>\n");
- send(outerSocket, str, strlen(str), 0);
+ send(m_outerSocket, str, strlen(str), 0);
std::list<STG_MESSAGE>::reverse_iterator it;
- it = messages.rbegin();
- while (it != messages.rend())
+ it = m_messages.rbegin();
+ while (it != m_messages.rend())
{
sprintf(str," <TR id=\"MessagesTableRow%d\">\n", rowNum);
- send(outerSocket, str, strlen(str), 0);
+ send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TD>%s</TD>\n", it->recvTime.c_str());
- send(outerSocket, str, strlen(str), 0);
+ send(m_outerSocket, str, strlen(str), 0);
sprintf(str," <TD>%s</TD>\n", it->msg.c_str());
- send(outerSocket, str, strlen(str), 0);
+ send(m_outerSocket, str, strlen(str), 0);
sprintf(str," </TR>\n");
- send(outerSocket, str, strlen(str), 0);
+ send(m_outerSocket, str, strlen(str), 0);
++it;
++rowNum;
}
sprintf(str," </TABLE>\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</b>" , 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;
}
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)
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));
}
//---------------------------------------------------------------------------
$Date: 2007/12/17 08:39:08 $
*/
+#include "stg/const.h"
+#include "stg/ia_packets.h"
+
+#include <string>
+#include <list>
+
#ifndef WIN32
#include <pthread.h>
#include <sys/types.h>
#include <winsock2.h>
#endif
-#include <string>
-#include <list>
-
-#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<STG_MESSAGE> messages;
+ std::list<STG_MESSAGE> m_messages;
};
//-----------------------------------------------------------------------------
{
template <class C>
-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;
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> action,
- const std::string & description)
+ const std::string& description)
: m_shortName(shortName),
m_longName(longName),
m_action(std::move(action)),
{
}
-OPTION::OPTION(const std::string & longName,
+OPTION::OPTION(const std::string& longName,
std::unique_ptr<ACTION> action,
- const std::string & description)
+ const std::string& description)
: m_longName(longName),
m_action(std::move(action)),
m_description(description)
m_action->Suboptions().Help(level);
}
-bool OPTION::Check(const char * arg) const
+bool OPTION::Check(const char* arg) const
{
if (arg == NULL)
return false;
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.");
{
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());
}
}
-void OPTION::ParseValue(const std::string & value)
+void OPTION::ParseValue(const std::string& value)
{
if (!m_action)
throw ERROR("Option is not defined.");
{
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> action,
- const std::string & description)
+OPTION_BLOCK& OPTION_BLOCK::Add(const std::string& shortName,
+ const std::string& longName,
+ std::unique_ptr<ACTION> 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> action,
- const std::string & description)
+OPTION_BLOCK& OPTION_BLOCK::Add(const std::string& longName,
+ std::unique_ptr<ACTION> action,
+ const std::string& description)
{
m_options.emplace_back(longName, std::move(action), description);
return *this;
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)
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)
}
}
-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();
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> action,
- const std::string & description);
- OPTION(const std::string & longName,
+ const std::string& description);
+ OPTION(const std::string& longName,
std::unique_ptr<ACTION> 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()) {}
};
{
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> action,
- const std::string & description);
- OPTION_BLOCK & Add(const std::string & longName,
- std::unique_ptr<ACTION> action,
- const std::string & description);
+ OPTION_BLOCK& Add(const std::string& shortName,
+ const std::string& longName,
+ std::unique_ptr<ACTION> action,
+ const std::string& description);
+ OPTION_BLOCK& Add(const std::string& longName,
+ std::unique_ptr<ACTION> 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()) {}
};
std::vector<OPTION> m_options;
std::string m_description;
- void OptionCallback(const std::string & key, const std::string & value);
+ void OptionCallback(const std::string& key, const std::string& value);
};
class OPTION_BLOCKS
{
public:
- OPTION_BLOCK & Add(const std::string & description)
+ OPTION_BLOCK& Add(const std::string& description)
{ m_blocks.push_back(OPTION_BLOCK(description)); return m_blocks.back(); }
void Add(OPTION_BLOCK&& block) { m_blocks.push_back(std::move(block)); }
void Help(size_t level) const;
- PARSER_STATE Parse(int argc, char ** argv);
+ PARSER_STATE Parse(int argc, char** argv);
private:
std::vector<OPTION_BLOCK> m_blocks;
size_t count() const override { return m_data.size(); }
- void fmap(std::function<void (const Admin&)> callback) const
+ void fmap(std::function<void (const Admin&)> callback) const override
{
for (const auto& admin : m_data)
callback(admin);
namespace STG
{
-struct Admin;
+class Admin;
struct Store;
class CorporationsImpl : public Corporations {
struct ModuleSettings;
struct Settings;
struct Admins;
-struct Tariffs;
-struct Users;
+class Tariffs;
+class Users;
struct Services;
struct Corporations;
struct TraffCounter;
namespace STG
{
-struct Users;
-
-class AUTH_AO;
+class Users;
using UserPtr = User*;
using ConstUserPtr = const User*;
sin.sin_family = AF_INET;
sin.sin_port = htons(portU);
sin.sin_addr.s_addr = inet_addr("0.0.0.0");
-if (bind(sockUDP, (struct sockaddr *)&sin, sizeof(sin)))
+if (bind(sockUDP, reinterpret_cast<const sockaddr*>(&sin), sizeof(sin)))
{
errorStr = "Error binding UDP socket";
logger("Cannot bind UDP socket: %s", strerror(errno));
sin.sin_family = AF_INET;
sin.sin_port = htons(portT);
sin.sin_addr.s_addr = inet_addr("0.0.0.0");
-if (bind(sockTCP, (struct sockaddr *)&sin, sizeof(sin)))
+if (bind(sockTCP, reinterpret_cast<const sockaddr*>(&sin), sizeof(sin)))
{
errorStr = "Error binding TCP socket";
logger("Cannot bind TCP socket: %s", strerror(errno));
namespace STG
{
-struct Users;
-struct Tariffs;
+class Users;
+class Tariffs;
struct Admins;
struct TraffCounter;
struct Store;
namespace STG
{
-struct Users;
-struct Tariffs;
+class Users;
+class Tariffs;
struct Admins;
struct TraffCounter;
struct Settings;
namespace STG
{
-struct Users;
-struct Tariffs;
+class Users;
+class Tariffs;
struct Admins;
struct TraffCounter;
struct Settings;
namespace STG
{
-struct Users;
-struct Tariffs;
+class Users;
+class Tariffs;
struct Admins;
struct TraffCounter;
struct Settings;
namespace STG
{
-struct Users;
-struct Tariffs;
+class Users;
+class Tariffs;
struct Admins;
struct TraffCounter;
struct Settings;
{
struct Settings;
-struct Users;
-struct Tariffs;
+class Users;
+class Tariffs;
}
namespace STG
{
-struct Users;
+class Users;
}
{
struct Admins;
-struct Tariffs;
-struct Users;
+class Tariffs;
+class Users;
struct Store;
}
namespace STG
{
-struct Tariffs;
-struct Users;
+class Tariffs;
+class Users;
struct Admins;
}
namespace STG
{
-struct Admin;
+class Admin;
struct Store;
-struct Tariffs;
-struct User;
-struct Users;
+class Tariffs;
+class User;
+class Users;
}
{
struct Admins;
-struct Tariffs;
-struct Users;
+class Tariffs;
+class Users;
struct Store;
struct IPMask;
struct Settings;
struct Admins;
-struct Tariffs;
-struct Users;
+class Tariffs;
+class Users;
struct Services;
struct Corporations;
struct Store;
struct Settings;
struct Admins;
-struct Users;
-struct Tariffs;
-struct Admin;
+class Users;
+class Tariffs;
+class Admin;
class PluginLogger;
class DECRYPT_STREAM;
namespace STG
{
-struct Admin;
+class Admin;
}
class BASE_PARSER
{
struct Admins;
-struct Admin;
+class Admin;
namespace PARSER
{
namespace STG
{
-struct Admin;
-struct Users;
+class Admin;
+class Users;
namespace PARSER
{
namespace STG
{
-struct Users;
-struct User;
+class Users;
+class User;
namespace PARSER
{
namespace STG
{
-struct Admin;
+class Admin;
struct Settings;
-struct Users;
-struct Tariffs;
+class Users;
+class Tariffs;
namespace PARSER
{
namespace STG
{
-struct Tariffs;
-struct Users;
-struct Admin;
+class Tariffs;
+class Users;
+class Admin;
namespace PARSER
{
namespace STG
{
-struct Users;
+class Users;
namespace PARSER
{
namespace STG
{
-struct Users;
-struct User;
-struct Tariffs;
-struct Admin;
+class Users;
+class User;
+class Tariffs;
+class Admin;
struct Store;
namespace PARSER
-#include <cassert>
+#include "smux.h"
+#include "utils.h"
+
+#include "stg/common.h"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
#include "stg/GetRequest-PDU.h"
#include "stg/GetResponse-PDU.h"
#include "stg/VarBindList.h"
#include "stg/VarBind.h"
+#pragma GCC diagnostic pop
-#include "stg/common.h"
-
-#include "utils.h"
-#include "smux.h"
+#include <cassert>
using STG::SMUX;
-#include <cassert>
-
-#include "stg/INTEGER.h"
+#include "sensors.h"
#include "stg/user.h"
-#include "sensors.h"
+#include <cassert>
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#include "stg/INTEGER.h"
+#pragma GCC diagnostic pop
-bool UsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
+void UsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
{
int handle = users.OpenSearch();
assert(handle && "USERS::OpenSearch is always correct");
users.CloseSearch(handle);
ValueToOS(count, objectSyntax);
-return true;
}
#ifdef DEBUG
-#ifndef __SENSORS_H__
-#define __SENSORS_H__
+#pragma once
-#include <map>
+#include "value2os.h"
+#include "types.h"
#include "stg/users.h"
#include "stg/user.h"
#include "stg/traffcounter.h"
#include "stg/user_property.h"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
#include "stg/ObjectSyntax.h"
+#pragma GCC diagnostic pop
-#include "value2os.h"
-#include "types.h"
+#include <map>
class Sensor {
public:
virtual ~Sensor() = default;
- virtual bool GetValue(ObjectSyntax_t * objectSyntax) const = 0;
+ virtual void GetValue(ObjectSyntax_t * objectSyntax) const = 0;
#ifdef DEBUG
virtual std::string ToString() const = 0;
#endif
public:
explicit TotalUsersSensor(const STG::Users & u) : users(u) {}
- bool GetValue(ObjectSyntax_t * objectSyntax) const override
+ void GetValue(ObjectSyntax_t * objectSyntax) const override
{
ValueToOS(users.Count(), objectSyntax);
- return true;
}
#ifdef DEBUG
public:
explicit UsersSensor(STG::Users & u) : users(u) {}
- bool GetValue(ObjectSyntax_t * objectSyntax) const override;
+ void GetValue(ObjectSyntax_t * objectSyntax) const override;
#ifdef DEBUG
std::string ToString() const override;
#endif
public:
explicit TotalTariffsSensor(const STG::Tariffs & t) : tariffs(t) {}
- bool GetValue(ObjectSyntax_t * objectSyntax) const override
+ void GetValue(ObjectSyntax_t * objectSyntax) const override
{
ValueToOS(tariffs.Count(), objectSyntax);
- return true;
}
#ifdef DEBUG
public:
explicit TotalAdminsSensor(const STG::Admins & a) : admins(a) {}
- bool GetValue(ObjectSyntax_t * objectSyntax) const override
+ void GetValue(ObjectSyntax_t * objectSyntax) const override
{
ValueToOS(admins.count(), objectSyntax);
- return true;
}
#ifdef DEBUG
public:
explicit TotalServicesSensor(const STG::Services & s) : services(s) {}
- bool GetValue(ObjectSyntax_t * objectSyntax) const override
+ void GetValue(ObjectSyntax_t * objectSyntax) const override
{
ValueToOS(services.Count(), objectSyntax);
- return true;
}
#ifdef DEBUG
public:
explicit TotalCorporationsSensor(const STG::Corporations & c) : corporations(c) {}
- bool GetValue(ObjectSyntax_t * objectSyntax) const override
+ void GetValue(ObjectSyntax_t * objectSyntax) const override
{
ValueToOS(corporations.Count(), objectSyntax);
- return true;
}
#ifdef DEBUG
public:
explicit TotalRulesSensor(const STG::TraffCounter & t) : traffcounter(t) {}
- bool GetValue(ObjectSyntax_t * objectSyntax) const override
+ void GetValue(ObjectSyntax_t * objectSyntax) const override
{
ValueToOS(traffcounter.rulesCount(), objectSyntax);
- return true;
}
#ifdef DEBUG
public:
explicit ConstSensor(const T & v) : value(v) {}
- bool GetValue(ObjectSyntax * objectSyntax) const override
- { return ValueToOS(value, objectSyntax); }
+ void GetValue(ObjectSyntax * objectSyntax) const override
+ {
+ ValueToOS(value, objectSyntax);
+ }
#ifdef DEBUG
std::string ToString() const override
return value;
}
#endif
-
-#endif
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
+#include "smux.h"
+#include "utils.h"
-#include <cstring>
-#include <cerrno>
-#include <ctime>
-#include <csignal>
-#include <cassert>
+#include "stg/common.h"
#include <vector>
#include <algorithm>
#include <stdexcept>
#include <utility>
-#include "stg/common.h"
+#include <cstring>
+#include <cerrno>
+#include <ctime>
+#include <csignal>
+#include <cassert>
-#include "smux.h"
-#include "utils.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
using STG::SMUX;
using STG::SMUX_SETTINGS;
#include "tables.h"
#include "types.h"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
#include "stg/SMUX-PDUs.h"
#include "stg/ObjectSyntax.h"
+#pragma GCC diagnostic pop
#include "stg/plugin.h"
#include "stg/module_settings.h"
namespace STG
{
-struct User;
+class User;
struct Settings;
-struct Users;
-struct Tariffs;
+class Users;
+class Tariffs;
struct Services;
struct Corporations;
struct TraffCounter;
-#include <cassert>
-#include <utility>
-#include <iterator>
-#include <algorithm>
+#include "tables.h"
#include "stg/user_property.h"
#include "stg/tariffs.h"
#include "stg/tariff_conf.h"
#include "stg/users.h"
-#include "tables.h"
+#include <utility>
+#include <iterator>
+#include <algorithm>
+#include <cassert>
+
+using STG::TariffUsersTable;
-std::pair<std::string, size_t> TD2Info(const STG::TariffData & td);
+namespace
+{
+
+std::pair<std::string, size_t> TD2Info(const STG::TariffData & td)
+{
+ return std::make_pair(td.tariffConf.name, 0);
+}
+
+}
void TariffUsersTable::UpdateSensors(Sensors & sensors) const
{
++it;
}
}
-
-std::pair<std::string, size_t> TD2Info(const STG::TariffData & td)
-{
-return std::make_pair(td.tariffConf.name, 0);
-}
-#ifndef __TABLES_H__
-#define __TABLES_H__
+#pragma once
+
+#include "sensors.h"
#include <string>
#include <map>
-#include "sensors.h"
-
namespace STG
{
-struct Tariffs;
-struct Users;
-}
+class Tariffs;
+class Users;
class TableSensor {
public:
};
typedef std::map<std::string, TableSensor *> Tables;
-
-#endif
+}
+#include "types.h"
+
#include <stdexcept>
#include <algorithm>
#include <iterator>
#include <sstream>
-#include "types.h"
-
namespace
{
-#ifndef __TYPES_H__
-#define __TYPES_H__
+#pragma once
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#include "stg/OBJECT_IDENTIFIER.h"
+#pragma GCC diagnostic pop
#include <string>
#include <vector>
#include <iostream>
-#include "stg/OBJECT_IDENTIFIER.h"
-
-class OID {
+class OID
+{
public:
explicit OID(const std::string & str);
OID(const char * str, size_t length);
{
return a.PrefixLess(b);
}
-
-#endif
-#include <unistd.h> // write
-
-#include <cstring> // memset
-#include <cerrno>
+#include "utils.h"
+#include "pen.h"
#include "stg/common.h"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
#include "stg/OpenPDU.h"
#include "stg/ClosePDU.h"
#include "stg/RReqPDU.h"
#include "stg/ber_decoder.h"
#include "stg/der_encoder.h"
+#pragma GCC diagnostic pop
-#include "pen.h"
-#include "utils.h"
+#include <cstring> // memset
+#include <cerrno>
+
+#include <unistd.h> // write
bool String2OI(const std::string & str, OBJECT_IDENTIFIER_t * oi)
{
if (length < 1)
return NULL;
asn_dec_rval_t error;
-error = ber_decode(0, &asn_DEF_SMUX_PDUs, (void **)&pdus, buffer, length);
+void* p = pdus;
+error = ber_decode(0, &asn_DEF_SMUX_PDUs, &p, buffer, length);
if(error.code != RC_OK)
{
printfd(__FILE__, "Failed to decode PDUs at byte %ld\n",
- (long)error.consumed);
+ static_cast<long>(error.consumed));
return NULL;
}
return pdus;
-#ifndef __UTILS_H__
-#define __UTILS_H__
-
-#include <string>
+#pragma once
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
#include "stg/OBJECT_IDENTIFIER.h"
#include "stg/SMUX-PDUs.h"
#include "stg/GetResponse-PDU.h"
+#pragma GCC diagnostic pop
+
+#include <string>
bool String2OI(const std::string & str, OBJECT_IDENTIFIER_t * oi);
bool SendOpenPDU(int fd);
const PDU_t * getRequest,
int errorStatus,
int errorIndex);
-
-#endif
-#ifndef __VALUE_2_OS_H__
-#define __VALUE_2_OS_H__
+#pragma once
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
#include "stg/ObjectSyntax.h"
+#pragma GCC diagnostic pop
+
+#include <string>
template <typename T>
-bool ValueToOS(const T & value, ObjectSyntax * objectSyntax);
+void ValueToOS(const T & value, ObjectSyntax * objectSyntax);
template <>
inline
-bool ValueToOS<int>(const int & value, ObjectSyntax * objectSyntax)
+void ValueToOS<int>(const int & value, ObjectSyntax * objectSyntax)
{
objectSyntax->present = ObjectSyntax_PR_simple;
SimpleSyntax_t * simpleSyntax = &objectSyntax->choice.simple;
simpleSyntax->present = SimpleSyntax_PR_number;
asn_long2INTEGER(&simpleSyntax->choice.number, value);
-return true;
}
template <>
inline
-bool ValueToOS<unsigned int>(const unsigned int & value, ObjectSyntax * objectSyntax)
+void ValueToOS<unsigned int>(const unsigned int & value, ObjectSyntax * objectSyntax)
{
objectSyntax->present = ObjectSyntax_PR_simple;
SimpleSyntax_t * simpleSyntax = &objectSyntax->choice.simple;
simpleSyntax->present = SimpleSyntax_PR_number;
asn_long2INTEGER(&simpleSyntax->choice.number, value);
-return true;
}
template <>
inline
-bool ValueToOS<long>(const long & value, ObjectSyntax * objectSyntax)
+void ValueToOS<long>(const long & value, ObjectSyntax * objectSyntax)
{
objectSyntax->present = ObjectSyntax_PR_simple;
SimpleSyntax_t * simpleSyntax = &objectSyntax->choice.simple;
simpleSyntax->present = SimpleSyntax_PR_number;
asn_long2INTEGER(&simpleSyntax->choice.number, value);
-return true;
}
template <>
inline
-bool ValueToOS<unsigned long>(const unsigned long & value, ObjectSyntax * objectSyntax)
+void ValueToOS<unsigned long>(const unsigned long & value, ObjectSyntax * objectSyntax)
{
objectSyntax->present = ObjectSyntax_PR_simple;
SimpleSyntax_t * simpleSyntax = &objectSyntax->choice.simple;
simpleSyntax->present = SimpleSyntax_PR_number;
asn_long2INTEGER(&simpleSyntax->choice.number, value);
-return true;
}
template <>
inline
-bool ValueToOS<std::string>(const std::string & value, ObjectSyntax * objectSyntax)
+void ValueToOS<std::string>(const std::string & value, ObjectSyntax * objectSyntax)
{
objectSyntax->present = ObjectSyntax_PR_simple;
SimpleSyntax_t * simpleSyntax = &objectSyntax->choice.simple;
simpleSyntax->present = SimpleSyntax_PR_string;
OCTET_STRING_fromBuf(&simpleSyntax->choice.string, value.c_str(), static_cast<int>(value.length()));
-return true;
}
-
-#endif
}
//-----------------------------------------------------------------------------
FILES_STORE_SETTINGS::FILES_STORE_SETTINGS()
- : settings(NULL),
- statMode(0),
- statUID(0),
- statGID(0),
- confMode(0),
- confUID(0),
- confGID(0),
- userLogMode(0),
- userLogUID(0),
- userLogGID(0),
- removeBak(true),
- readBak(true)
+ : m_statMode(0),
+ m_statUID(0),
+ m_statGID(0),
+ m_confMode(0),
+ m_confUID(0),
+ m_confGID(0),
+ m_userLogMode(0),
+ m_userLogUID(0),
+ m_userLogGID(0),
+ m_removeBak(true),
+ m_readBak(true)
{
}
//-----------------------------------------------------------------------------
pvi = find(moduleParams.begin(), moduleParams.end(), pv);
if (pvi == moduleParams.end() || pvi->value.empty())
{
- errorStr = "Parameter \'" + owner + "\' not found.";
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = "Parameter \'" + owner + "\' not found.";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
if (User2UID(pvi->value[0].c_str(), uid) < 0)
{
- errorStr = "Parameter \'" + owner + "\': Unknown user \'" + pvi->value[0] + "\'";
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = "Parameter \'" + owner + "\': Unknown user \'" + pvi->value[0] + "\'";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
return 0;
pvi = find(moduleParams.begin(), moduleParams.end(), pv);
if (pvi == moduleParams.end() || pvi->value.empty())
{
- errorStr = "Parameter \'" + group + "\' not found.";
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = "Parameter \'" + group + "\' not found.";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
if (Group2GID(pvi->value[0].c_str(), gid) < 0)
{
- errorStr = "Parameter \'" + group + "\': Unknown group \'" + pvi->value[0] + "\'";
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = "Parameter \'" + group + "\': Unknown group \'" + pvi->value[0] + "\'";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
return 0;
return 0;
}
-errorStr = "Incorrect value \'" + value + "\'.";
+m_errorStr = "Incorrect value \'" + value + "\'.";
return -1;
}
//-----------------------------------------------------------------------------
pvi = find(moduleParams.begin(), moduleParams.end(), pv);
if (pvi == moduleParams.end() || pvi->value.empty())
{
- errorStr = "Parameter \'" + modeStr + "\' not found.";
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = "Parameter \'" + modeStr + "\' not found.";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
if (Str2Mode(pvi->value[0].c_str(), mode) < 0)
{
- errorStr = "Parameter \'" + modeStr + "\': Incorrect mode \'" + pvi->value[0] + "\'";
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = "Parameter \'" + modeStr + "\': Incorrect mode \'" + pvi->value[0] + "\'";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
return 0;
//-----------------------------------------------------------------------------
int FILES_STORE_SETTINGS::ParseSettings(const STG::ModuleSettings & s)
{
-if (ParseOwner(s.moduleParams, "StatOwner", &statUID) < 0)
+if (ParseOwner(s.moduleParams, "StatOwner", &m_statUID) < 0)
return -1;
-if (ParseGroup(s.moduleParams, "StatGroup", &statGID) < 0)
+if (ParseGroup(s.moduleParams, "StatGroup", &m_statGID) < 0)
return -1;
-if (ParseMode(s.moduleParams, "StatMode", &statMode) < 0)
+if (ParseMode(s.moduleParams, "StatMode", &m_statMode) < 0)
return -1;
-if (ParseOwner(s.moduleParams, "ConfOwner", &confUID) < 0)
+if (ParseOwner(s.moduleParams, "ConfOwner", &m_confUID) < 0)
return -1;
-if (ParseGroup(s.moduleParams, "ConfGroup", &confGID) < 0)
+if (ParseGroup(s.moduleParams, "ConfGroup", &m_confGID) < 0)
return -1;
-if (ParseMode(s.moduleParams, "ConfMode", &confMode) < 0)
+if (ParseMode(s.moduleParams, "ConfMode", &m_confMode) < 0)
return -1;
-if (ParseOwner(s.moduleParams, "UserLogOwner", &userLogUID) < 0)
+if (ParseOwner(s.moduleParams, "UserLogOwner", &m_userLogUID) < 0)
return -1;
-if (ParseGroup(s.moduleParams, "UserLogGroup", &userLogGID) < 0)
+if (ParseGroup(s.moduleParams, "UserLogGroup", &m_userLogGID) < 0)
return -1;
-if (ParseMode(s.moduleParams, "UserLogMode", &userLogMode) < 0)
+if (ParseMode(s.moduleParams, "UserLogMode", &m_userLogMode) < 0)
return -1;
std::vector<STG::ParamValue>::const_iterator pvi;
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end() || pvi->value.empty())
{
- removeBak = true;
+ m_removeBak = true;
}
else
{
- if (ParseYesNo(pvi->value[0], &removeBak))
+ if (ParseYesNo(pvi->value[0], &m_removeBak))
{
printfd(__FILE__, "Cannot parse parameter 'RemoveBak'\n");
return -1;
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end() || pvi->value.empty())
{
- readBak = false;
+ m_readBak = false;
}
else
{
- if (ParseYesNo(pvi->value[0], &readBak))
+ if (ParseYesNo(pvi->value[0], &m_readBak))
{
printfd(__FILE__, "Cannot parse parameter 'ReadBak'\n");
return -1;
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end() || pvi->value.empty())
{
- errorStr = "Parameter \'WorkDir\' not found.";
+ m_errorStr = "Parameter \'WorkDir\' not found.";
printfd(__FILE__, "Parameter 'WorkDir' not found\n");
return -1;
}
-workDir = pvi->value[0];
-if (workDir.size() && workDir[workDir.size() - 1] == '/')
+m_workDir = pvi->value[0];
+if (m_workDir.size() && m_workDir[m_workDir.size() - 1] == '/')
{
- workDir.resize(workDir.size() - 1);
+ m_workDir.resize(m_workDir.size() - 1);
}
-usersDir = workDir + "/users/";
-if (!CheckAndCreate(usersDir, GetConfModeDir()))
+m_usersDir = m_workDir + "/users/";
+if (!CheckAndCreate(m_usersDir, GetConfModeDir()))
{
- errorStr = usersDir + " doesn't exist. Failed to create.";
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = m_usersDir + " doesn't exist. Failed to create.";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
-tariffsDir = workDir + "/tariffs/";
-if (!CheckAndCreate(tariffsDir, GetConfModeDir()))
+m_tariffsDir = m_workDir + "/tariffs/";
+if (!CheckAndCreate(m_tariffsDir, GetConfModeDir()))
{
- errorStr = tariffsDir + " doesn't exist. Failed to create.";
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = m_tariffsDir + " doesn't exist. Failed to create.";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
-adminsDir = workDir + "/admins/";
-if (!CheckAndCreate(adminsDir, GetConfModeDir()))
+m_adminsDir = m_workDir + "/admins/";
+if (!CheckAndCreate(m_adminsDir, GetConfModeDir()))
{
- errorStr = adminsDir + " doesn't exist. Failed to create.";
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = m_adminsDir + " doesn't exist. Failed to create.";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
-servicesDir = workDir + "/services/";
-if (!CheckAndCreate(servicesDir, GetConfModeDir()))
+m_servicesDir = m_workDir + "/services/";
+if (!CheckAndCreate(m_servicesDir, GetConfModeDir()))
{
- errorStr = servicesDir + " doesn't exist. Failed to create.";
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = m_servicesDir + " doesn't exist. Failed to create.";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
//-----------------------------------------------------------------------------
const std::string & FILES_STORE_SETTINGS::GetStrError() const
{
-return errorStr;
+return m_errorStr;
}
//-----------------------------------------------------------------------------
int FILES_STORE_SETTINGS::User2UID(const char * user, uid_t * uid)
pw = getpwnam(user);
if (!pw)
{
- errorStr = std::string("User \'") + std::string(user) + std::string("\' not found in system.");
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = std::string("User \'") + std::string(user) + std::string("\' not found in system.");
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
grp = getgrnam(gr);
if (!grp)
{
- errorStr = std::string("Group \'") + std::string(gr) + std::string("\' not found in system.");
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = std::string("Group \'") + std::string(gr) + std::string("\' not found in system.");
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
//-----------------------------------------------------------------------------
int FILES_STORE_SETTINGS::Str2Mode(const char * str, mode_t * mode)
{
-char a;
-char b;
-char c;
if (strlen(str) > 3)
{
- errorStr = std::string("Error parsing mode \'") + str + std::string("\'");
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = std::string("Error parsing mode \'") + str + std::string("\'");
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
for (int i = 0; i < 3; i++)
if (str[i] > '7' || str[i] < '0')
{
- errorStr = std::string("Error parsing mode \'") + str + std::string("\'");
- printfd(__FILE__, "%s\n", errorStr.c_str());
+ m_errorStr = std::string("Error parsing mode \'") + str + std::string("\'");
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
return -1;
}
-a = str[0] - '0';
-b = str[1] - '0';
-c = str[2] - '0';
+mode_t a = str[0] - '0';
+mode_t b = str[1] - '0';
+mode_t c = str[2] - '0';
-*mode = ((mode_t)c) + ((mode_t)b << 3) + ((mode_t)a << 6);
+*mode = c + (b << 3) + (a << 6);
return 0;
}
//-----------------------------------------------------------------------------
mode_t FILES_STORE_SETTINGS::GetStatModeDir() const
{
-mode_t mode = statMode;
-if (statMode & S_IRUSR) mode |= S_IXUSR;
-if (statMode & S_IRGRP) mode |= S_IXGRP;
-if (statMode & S_IROTH) mode |= S_IXOTH;
+mode_t mode = m_statMode;
+if (m_statMode & S_IRUSR) mode |= S_IXUSR;
+if (m_statMode & S_IRGRP) mode |= S_IXGRP;
+if (m_statMode & S_IROTH) mode |= S_IXOTH;
return mode;
}
//-----------------------------------------------------------------------------
mode_t FILES_STORE_SETTINGS::GetConfModeDir() const
{
-mode_t mode = confMode;
-if (confMode & S_IRUSR) mode |= S_IXUSR;
-if (confMode & S_IRGRP) mode |= S_IXGRP;
-if (confMode & S_IROTH) mode |= S_IXOTH;
+mode_t mode = m_confMode;
+if (m_confMode & S_IRUSR) mode |= S_IXUSR;
+if (m_confMode & S_IRGRP) mode |= S_IXGRP;
+if (m_confMode & S_IROTH) mode |= S_IXOTH;
return mode;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
FILES_STORE::FILES_STORE()
- : version("file_store v.1.04"),
- logger(STG::PluginLogger::get("store_files"))
+ : m_version("file_store v.1.04"),
+ m_logger(STG::PluginLogger::get("store_files"))
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-pthread_mutex_init(&mutex, &attr);
+pthread_mutex_init(&m_mutex, &attr);
}
//-----------------------------------------------------------------------------
int FILES_STORE::ParseSettings()
{
-int ret = storeSettings.ParseSettings(settings);
+int ret = m_storeSettings.ParseSettings(m_settings);
if (ret)
{
- STG_LOCKER lock(&mutex);
- errorStr = storeSettings.GetStrError();
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = m_storeSettings.GetStrError();
}
return ret;
}
{
std::vector<std::string> files;
-if (GetFileList(&files, storeSettings.GetUsersDir(), S_IFDIR, ""))
+if (GetFileList(&files, m_storeSettings.GetUsersDir(), S_IFDIR, ""))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Failed to open '" + storeSettings.GetUsersDir() + "': " + std::string(strerror(errno));
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Failed to open '" + m_storeSettings.GetUsersDir() + "': " + std::string(strerror(errno));
return -1;
}
-STG_LOCKER lock(&mutex);
+STG_LOCKER lock(&m_mutex);
userList->swap(files);
{
std::vector<std::string> files;
-if (GetFileList(&files, storeSettings.GetAdminsDir(), S_IFREG, ".adm"))
+if (GetFileList(&files, m_storeSettings.GetAdminsDir(), S_IFREG, ".adm"))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Failed to open '" + storeSettings.GetAdminsDir() + "': " + std::string(strerror(errno));
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Failed to open '" + m_storeSettings.GetAdminsDir() + "': " + std::string(strerror(errno));
return -1;
}
-STG_LOCKER lock(&mutex);
+STG_LOCKER lock(&m_mutex);
adminList->swap(files);
{
std::vector<std::string> files;
-if (GetFileList(&files, storeSettings.GetTariffsDir(), S_IFREG, ".tf"))
+if (GetFileList(&files, m_storeSettings.GetTariffsDir(), S_IFREG, ".tf"))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Failed to open '" + storeSettings.GetTariffsDir() + "': " + std::string(strerror(errno));
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Failed to open '" + m_storeSettings.GetTariffsDir() + "': " + std::string(strerror(errno));
return -1;
}
-STG_LOCKER lock(&mutex);
+STG_LOCKER lock(&m_mutex);
tariffList->swap(files);
{
std::vector<std::string> files;
-if (GetFileList(&files, storeSettings.GetServicesDir(), S_IFREG, ".serv"))
+if (GetFileList(&files, m_storeSettings.GetServicesDir(), S_IFREG, ".serv"))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Failed to open '" + storeSettings.GetServicesDir() + "': " + std::string(strerror(errno));
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Failed to open '" + m_storeSettings.GetServicesDir() + "': " + std::string(strerror(errno));
return -1;
}
-STG_LOCKER lock(&mutex);
+STG_LOCKER lock(&m_mutex);
list->swap(files);
if (!d)
{
- errorStr = "failed to open dir. Message: '";
- errorStr += strerror(errno);
- errorStr += "'";
+ m_errorStr = "failed to open dir. Message: '";
+ m_errorStr += strerror(errno);
+ m_errorStr += "'";
printfd(__FILE__, "FILE_STORE::RemoveDir() - Failed to open dir '%s': '%s'\n", path, strerror(errno));
return -1;
}
{
if (unlink(str.c_str()))
{
- STG_LOCKER lock(&mutex);
- errorStr = "unlink failed. Message: '";
- errorStr += strerror(errno);
- errorStr += "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "unlink failed. Message: '";
+ m_errorStr += strerror(errno);
+ m_errorStr += "'";
printfd(__FILE__, "FILES_STORE::RemoveDir() - unlink failed. Message: '%s'\n", strerror(errno));
closedir(d);
return -1;
if (rmdir(path))
{
- STG_LOCKER lock(&mutex);
- errorStr = "rmdir failed. Message: '";
- errorStr += strerror(errno);
- errorStr += "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "rmdir failed. Message: '";
+ m_errorStr += strerror(errno);
+ m_errorStr += "'";
printfd(__FILE__, "FILES_STORE::RemoveDir() - rmdir failed. Message: '%s'\n", strerror(errno));
return -1;
}
{
std::string fileName;
-strprintf(&fileName, "%s%s", storeSettings.GetUsersDir().c_str(), login.c_str());
+strprintf(&fileName, "%s%s", m_storeSettings.GetUsersDir().c_str(), login.c_str());
if (mkdir(fileName.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1)
{
- STG_LOCKER lock(&mutex);
- errorStr = std::string("mkdir failed. Message: '") + strerror(errno) + "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = std::string("mkdir failed. Message: '") + strerror(errno) + "'";
printfd(__FILE__, "FILES_STORE::AddUser - mkdir failed. Message: '%s'\n", strerror(errno));
return -1;
}
-strprintf(&fileName, "%s%s/conf", storeSettings.GetUsersDir().c_str(), login.c_str());
+strprintf(&fileName, "%s%s/conf", m_storeSettings.GetUsersDir().c_str(), login.c_str());
if (Touch(fileName))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot create file \"" + fileName + "\'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot create file \"" + fileName + "\'";
printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno));
return -1;
}
-strprintf(&fileName, "%s%s/stat", storeSettings.GetUsersDir().c_str(), login.c_str());
+strprintf(&fileName, "%s%s/stat", m_storeSettings.GetUsersDir().c_str(), login.c_str());
if (Touch(fileName))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot create file \"" + fileName + "\'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot create file \"" + fileName + "\'";
printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno));
return -1;
}
std::string dirName;
std::string dirName1;
-strprintf(&dirName, "%s/%s", storeSettings.GetWorkDir().c_str(), DELETED_USERS_DIR);
+strprintf(&dirName, "%s/%s", m_storeSettings.GetWorkDir().c_str(), DELETED_USERS_DIR);
if (access(dirName.c_str(), F_OK) != 0)
{
if (mkdir(dirName.c_str(), 0700) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Directory '" + dirName + "' cannot be created.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Directory '" + dirName + "' cannot be created.";
printfd(__FILE__, "FILES_STORE::DelUser - mkdir failed. Message: '%s'\n", strerror(errno));
return -1;
}
if (access(dirName.c_str(), F_OK) == 0)
{
- strprintf(&dirName, "%s/%s/%s.%lu", storeSettings.GetWorkDir().c_str(), DELETED_USERS_DIR, login.c_str(), time(NULL));
- strprintf(&dirName1, "%s/%s", storeSettings.GetUsersDir().c_str(), login.c_str());
+ strprintf(&dirName, "%s/%s/%s.%lu", m_storeSettings.GetWorkDir().c_str(), DELETED_USERS_DIR, login.c_str(), time(NULL));
+ strprintf(&dirName1, "%s/%s", m_storeSettings.GetUsersDir().c_str(), login.c_str());
if (rename(dirName1.c_str(), dirName.c_str()))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error moving dir from " + dirName1 + " to " + dirName;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error moving dir from " + dirName1 + " to " + dirName;
printfd(__FILE__, "FILES_STORE::DelUser - rename failed. Message: '%s'\n", strerror(errno));
return -1;
}
}
else
{
- strprintf(&dirName, "%s/%s", storeSettings.GetUsersDir().c_str(), login.c_str());
+ strprintf(&dirName, "%s/%s", m_storeSettings.GetUsersDir().c_str(), login.c_str());
if (RemoveDir(dirName.c_str()))
{
return -1;
int FILES_STORE::RestoreUserConf(STG::UserConf * conf, const std::string & login) const
{
std::string fileName;
-fileName = storeSettings.GetUsersDir() + "/" + login + "/conf";
+fileName = m_storeSettings.GetUsersDir() + "/" + login + "/conf";
if (RestoreUserConf(conf, login, fileName))
{
- if (!storeSettings.GetReadBak())
+ if (!m_storeSettings.GetReadBak())
{
return -1;
}
if (e)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' data not read.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' data not read.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - conf read failed for user '%s'\n", login.c_str());
return -1;
}
if (cf.ReadString("Password", &conf->password, "") < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' data not read. Parameter Password.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' data not read. Parameter Password.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - password read failed for user '%s'\n", login.c_str());
return -1;
}
if (conf->password.empty())
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' password is blank.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' password is blank.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - password is blank for user '%s'\n", login.c_str());
return -1;
}
if (cf.ReadString("tariff", &conf->tariffName, "") < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' data not read. Parameter Tariff.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' data not read. Parameter Tariff.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - tariff read failed for user '%s'\n", login.c_str());
return -1;
}
if (conf->tariffName.empty())
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' tariff is blank.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' tariff is blank.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - tariff is blank for user '%s'\n", login.c_str());
return -1;
}
}
catch (const std::string & s)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' data not read. Parameter IP address. " + s;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' data not read. Parameter IP address. " + s;
printfd(__FILE__, "FILES_STORE::RestoreUserConf - ip read failed for user '%s'\n", login.c_str());
return -1;
}
if (cf.ReadInt("alwaysOnline", &conf->alwaysOnline, 0) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' data not read. Parameter AlwaysOnline.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' data not read. Parameter AlwaysOnline.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - alwaysonline read failed for user '%s'\n", login.c_str());
return -1;
}
if (cf.ReadInt("down", &conf->disabled, 0) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' data not read. Parameter Down.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' data not read. Parameter Down.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - down read failed for user '%s'\n", login.c_str());
return -1;
}
if (cf.ReadInt("passive", &conf->passive, 0) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' data not read. Parameter Passive.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' data not read. Parameter Passive.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - passive read failed for user '%s'\n", login.c_str());
return -1;
}
if (cf.ReadDouble("Credit", &conf->credit, 0) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' data not read. Parameter Credit.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' data not read. Parameter Credit.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - credit read failed for user '%s'\n", login.c_str());
return -1;
}
int FILES_STORE::RestoreUserStat(STG::UserStat * stat, const std::string & login) const
{
std::string fileName;
-fileName = storeSettings.GetUsersDir() + "/" + login + "/stat";
+fileName = m_storeSettings.GetUsersDir() + "/" + login + "/stat";
if (RestoreUserStat(stat, login, fileName))
{
- if (!storeSettings.GetReadBak())
+ if (!m_storeSettings.GetReadBak())
{
return -1;
}
if (e)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' stat not read. Cannot open file " + fileName + ".";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' stat not read. Cannot open file " + fileName + ".";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - stat read failed for user '%s'\n", login.c_str());
return -1;
}
snprintf(s, 22, "D%d", i);
if (cf.ReadULongLongInt(s, &traff, 0) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' stat not read. Parameter " + std::string(s);
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' stat not read. Parameter " + std::string(s);
printfd(__FILE__, "FILES_STORE::RestoreUserStat - download stat read failed for user '%s'\n", login.c_str());
return -1;
}
snprintf(s, 22, "U%d", i);
if (cf.ReadULongLongInt(s, &traff, 0) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' stat not read. Parameter " + std::string(s);
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' stat not read. Parameter " + std::string(s);
printfd(__FILE__, "FILES_STORE::RestoreUserStat - upload stat read failed for user '%s'\n", login.c_str());
return -1;
}
if (cf.ReadDouble("Cash", &stat->cash, 0) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' stat not read. Parameter Cash";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' stat not read. Parameter Cash";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - cash read failed for user '%s'\n", login.c_str());
return -1;
}
if (cf.ReadDouble("FreeMb", &stat->freeMb, 0) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' stat not read. Parameter FreeMb";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' stat not read. Parameter FreeMb";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - freemb read failed for user '%s'\n", login.c_str());
return -1;
}
if (cf.ReadTime("LastCashAddTime", &stat->lastCashAddTime, 0) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' stat not read. Parameter LastCashAddTime";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' stat not read. Parameter LastCashAddTime";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - lastcashaddtime read failed for user '%s'\n", login.c_str());
return -1;
}
if (cf.ReadTime("PassiveTime", &stat->passiveTime, 0) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' stat not read. Parameter PassiveTime";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' stat not read. Parameter PassiveTime";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - passivetime read failed for user '%s'\n", login.c_str());
return -1;
}
if (cf.ReadDouble("LastCashAdd", &stat->lastCashAdd, 0) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' stat not read. Parameter LastCashAdd";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' stat not read. Parameter LastCashAdd";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - lastcashadd read failed for user '%s'\n", login.c_str());
return -1;
}
if (cf.ReadTime("LastActivityTime", &stat->lastActivityTime, 0) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "User \'" + login + "\' stat not read. Parameter LastActivityTime";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "User \'" + login + "\' stat not read. Parameter LastActivityTime";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - lastactivitytime read failed for user '%s'\n", login.c_str());
return -1;
}
int FILES_STORE::SaveUserConf(const STG::UserConf & conf, const std::string & login) const
{
std::string fileName;
-fileName = storeSettings.GetUsersDir() + "/" + login + "/conf";
+fileName = m_storeSettings.GetUsersDir() + "/" + login + "/conf";
CONFIGFILE cfstat(fileName, true);
if (e)
{
- STG_LOCKER lock(&mutex);
- errorStr = std::string("User \'") + login + "\' conf not written\n";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = std::string("User \'") + login + "\' conf not written\n";
printfd(__FILE__, "FILES_STORE::SaveUserConf - conf write failed for user '%s'\n", login.c_str());
return -1;
}
-e = chmod(fileName.c_str(), storeSettings.GetConfMode());
-e += chown(fileName.c_str(), storeSettings.GetConfUID(), storeSettings.GetConfGID());
+e = chmod(fileName.c_str(), m_storeSettings.GetConfMode());
+e += chown(fileName.c_str(), m_storeSettings.GetConfUID(), m_storeSettings.GetConfGID());
if (e)
{
- STG_LOCKER lock(&mutex);
+ STG_LOCKER lock(&m_mutex);
printfd(__FILE__, "FILES_STORE::SaveUserConf - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
int FILES_STORE::SaveUserStat(const STG::UserStat & stat, const std::string & login) const
{
std::string fileName;
-fileName = storeSettings.GetUsersDir() + "/" + login + "/stat";
+fileName = m_storeSettings.GetUsersDir() + "/" + login + "/stat";
{
CONFIGFILE cfstat(fileName, true);
if (e)
{
- STG_LOCKER lock(&mutex);
- errorStr = std::string("User \'") + login + "\' stat not written\n";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = std::string("User \'") + login + "\' stat not written\n";
printfd(__FILE__, "FILES_STORE::SaveUserStat - stat write failed for user '%s'\n", login.c_str());
return -1;
}
cfstat.WriteInt("LastActivityTime", stat.lastActivityTime);
}
-int e = chmod(fileName.c_str(), storeSettings.GetStatMode());
-e += chown(fileName.c_str(), storeSettings.GetStatUID(), storeSettings.GetStatGID());
+int e = chmod(fileName.c_str(), m_storeSettings.GetStatMode());
+e += chown(fileName.c_str(), m_storeSettings.GetStatUID(), m_storeSettings.GetStatGID());
if (e)
{
- STG_LOCKER lock(&mutex);
+ STG_LOCKER lock(&m_mutex);
printfd(__FILE__, "FILES_STORE::SaveUserStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
FILE * f;
time_t tm = time(NULL);
std::string fileName;
-fileName = storeSettings.GetUsersDir() + "/" + login + "/log";
+fileName = m_storeSettings.GetUsersDir() + "/" + login + "/log";
f = fopen(fileName.c_str(), "at");
if (f)
}
else
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot open \'" + fileName + "\'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot open \'" + fileName + "\'";
printfd(__FILE__, "FILES_STORE::WriteLogString - log write failed for user '%s'\n", login.c_str());
return -1;
}
-int e = chmod(fileName.c_str(), storeSettings.GetLogMode());
-e += chown(fileName.c_str(), storeSettings.GetLogUID(), storeSettings.GetLogGID());
+int e = chmod(fileName.c_str(), m_storeSettings.GetLogMode());
+e += chown(fileName.c_str(), m_storeSettings.GetLogUID(), m_storeSettings.GetLogGID());
if (e)
{
- STG_LOCKER lock(&mutex);
+ STG_LOCKER lock(&m_mutex);
printfd(__FILE__, "FILES_STORE::WriteLogString - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
FILE * f;
time_t tm = time(NULL);
std::string fileName;
-fileName = storeSettings.GetUsersDir() + "/" + login + "/log2";
+fileName = m_storeSettings.GetUsersDir() + "/" + login + "/log2";
f = fopen(fileName.c_str(), "at");
if (f)
}
else
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot open \'" + fileName + "\'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot open \'" + fileName + "\'";
printfd(__FILE__, "FILES_STORE::WriteLogString - log write failed for user '%s'\n", login.c_str());
return -1;
}
-int e = chmod(fileName.c_str(), storeSettings.GetLogMode());
-e += chown(fileName.c_str(), storeSettings.GetLogUID(), storeSettings.GetLogGID());
+int e = chmod(fileName.c_str(), m_storeSettings.GetLogMode());
+e += chown(fileName.c_str(), m_storeSettings.GetLogUID(), m_storeSettings.GetLogGID());
if (e)
{
- STG_LOCKER lock(&mutex);
+ STG_LOCKER lock(&m_mutex);
printfd(__FILE__, "FILES_STORE::WriteLogString - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
// Classic stats
std::string stat1;
strprintf(&stat1,"%s/%s/stat.%d.%02d",
- storeSettings.GetUsersDir().c_str(), login.c_str(), year + 1900, month + 1);
+ m_storeSettings.GetUsersDir().c_str(), login.c_str(), year + 1900, month + 1);
CONFIGFILE s(stat1, true);
if (s.Error())
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot create file '" + stat1 + "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot create file '" + stat1 + "'";
printfd(__FILE__, "FILES_STORE::SaveMonthStat - month stat write failed for user '%s'\n", login.c_str());
return -1;
}
// New stats
std::string stat2;
strprintf(&stat2,"%s/%s/stat2.%d.%02d",
- storeSettings.GetUsersDir().c_str(), login.c_str(), year + 1900, month + 1);
+ m_storeSettings.GetUsersDir().c_str(), login.c_str(), year + 1900, month + 1);
CONFIGFILE s2(stat2, true);
if (s2.Error())
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot create file '" + stat2 + "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot create file '" + stat2 + "'";
printfd(__FILE__, "FILES_STORE::SaveMonthStat - month stat write failed for user '%s'\n", login.c_str());
return -1;
}
for (size_t i = 0; i < DIR_NUM; i++)
{
char dirName[3];
- snprintf(dirName, 3, "U%llu", (unsigned long long)i);
+ snprintf(dirName, 3, "U%llu", i);
s.WriteInt(dirName, stat.monthUp[i]); // Classic
s2.WriteInt(dirName, stat.monthUp[i]); // New
- snprintf(dirName, 3, "D%llu", (unsigned long long)i);
+ snprintf(dirName, 3, "D%llu", i);
s.WriteInt(dirName, stat.monthDown[i]); // Classic
s2.WriteInt(dirName, stat.monthDown[i]); // New
}
int FILES_STORE::AddAdmin(const std::string & login) const
{
std::string fileName;
-strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), login.c_str());
+strprintf(&fileName, "%s/%s.adm", m_storeSettings.GetAdminsDir().c_str(), login.c_str());
if (Touch(fileName))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot create file " + fileName;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot create file " + fileName;
printfd(__FILE__, "FILES_STORE::AddAdmin - failed to add admin '%s'\n", login.c_str());
return -1;
}
int FILES_STORE::DelAdmin(const std::string & login) const
{
std::string fileName;
-strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), login.c_str());
+strprintf(&fileName, "%s/%s.adm", m_storeSettings.GetAdminsDir().c_str(), login.c_str());
if (unlink(fileName.c_str()))
{
- STG_LOCKER lock(&mutex);
- errorStr = "unlink failed. Message: '";
- errorStr += strerror(errno);
- errorStr += "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "unlink failed. Message: '";
+ m_errorStr += strerror(errno);
+ m_errorStr += "'";
printfd(__FILE__, "FILES_STORE::DelAdmin - unlink failed. Message: '%s'\n", strerror(errno));
}
return 0;
{
std::string fileName;
-strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login.c_str());
+strprintf(&fileName, "%s/%s.adm", m_storeSettings.GetAdminsDir().c_str(), ac.login.c_str());
{
CONFIGFILE cf(fileName, true);
if (e)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot write admin " + ac.login + ". " + fileName;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot write admin " + ac.login + ". " + fileName;
printfd(__FILE__, "FILES_STORE::SaveAdmin - failed to save admin '%s'\n", ac.login.c_str());
return -1;
}
int FILES_STORE::RestoreAdmin(STG::AdminConf * ac, const std::string & login) const
{
std::string fileName;
-strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), login.c_str());
+strprintf(&fileName, "%s/%s.adm", m_storeSettings.GetAdminsDir().c_str(), login.c_str());
CONFIGFILE cf(fileName);
char pass[ADM_PASSWD_LEN + 1];
char password[ADM_PASSWD_LEN + 1];
if (cf.Error())
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot open " + fileName;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot open " + fileName;
printfd(__FILE__, "FILES_STORE::RestoreAdmin - failed to restore admin '%s'\n", ac->login.c_str());
return -1;
}
if (cf.ReadString("password", &p, "*"))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error in parameter password";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error in parameter password";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - password read failed for admin '%s'\n", ac->login.c_str());
return -1;
}
ac->priv.userConf = a;
else
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error in parameter ChgConf";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error in parameter ChgConf";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgconf read failed for admin '%s'\n", ac->login.c_str());
return -1;
}
ac->priv.userPasswd = a;
else
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error in parameter ChgPassword";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error in parameter ChgPassword";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgpassword read failed for admin '%s'\n", ac->login.c_str());
return -1;
}
ac->priv.userStat = a;
else
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error in parameter ChgStat";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error in parameter ChgStat";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgstat read failed for admin '%s'\n", ac->login.c_str());
return -1;
}
ac->priv.userCash = a;
else
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error in parameter ChgCash";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error in parameter ChgCash";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgcash read failed for admin '%s'\n", ac->login.c_str());
return -1;
}
ac->priv.userAddDel = a;
else
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error in parameter UsrAddDel";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error in parameter UsrAddDel";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - usradddel read failed for admin '%s'\n", ac->login.c_str());
return -1;
}
ac->priv.adminChg = a;
else
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error in parameter ChgAdmin";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error in parameter ChgAdmin";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgadmin read failed for admin '%s'\n", ac->login.c_str());
return -1;
}
ac->priv.tariffChg = a;
else
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error in parameter ChgTariff";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error in parameter ChgTariff";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgtariff read failed for admin '%s'\n", ac->login.c_str());
return -1;
}
int FILES_STORE::AddTariff(const std::string & name) const
{
std::string fileName;
-strprintf(&fileName, "%s/%s.tf", storeSettings.GetTariffsDir().c_str(), name.c_str());
+strprintf(&fileName, "%s/%s.tf", m_storeSettings.GetTariffsDir().c_str(), name.c_str());
if (Touch(fileName))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot create file " + fileName;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot create file " + fileName;
printfd(__FILE__, "FILES_STORE::AddTariff - failed to add tariff '%s'\n", name.c_str());
return -1;
}
int FILES_STORE::DelTariff(const std::string & name) const
{
std::string fileName;
-strprintf(&fileName, "%s/%s.tf", storeSettings.GetTariffsDir().c_str(), name.c_str());
+strprintf(&fileName, "%s/%s.tf", m_storeSettings.GetTariffsDir().c_str(), name.c_str());
if (unlink(fileName.c_str()))
{
- STG_LOCKER lock(&mutex);
- errorStr = "unlink failed. Message: '";
- errorStr += strerror(errno);
- errorStr += "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "unlink failed. Message: '";
+ m_errorStr += strerror(errno);
+ m_errorStr += "'";
printfd(__FILE__, "FILES_STORE::DelTariff - unlink failed. Message: '%s'\n", strerror(errno));
}
return 0;
//-----------------------------------------------------------------------------
int FILES_STORE::RestoreTariff(STG::TariffData * td, const std::string & tariffName) const
{
-std::string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf";
+std::string fileName = m_storeSettings.GetTariffsDir() + "/" + tariffName + ".tf";
CONFIGFILE conf(fileName);
std::string str;
td->tariffConf.name = tariffName;
if (conf.Error() != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read file " + fileName;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read file " + fileName;
printfd(__FILE__, "FILES_STORE::RestoreTariff - failed to read tariff '%s'\n", tariffName.c_str());
return -1;
}
strprintf(¶m, "Time%d", i);
if (conf.ReadString(param, &str, "00:00-00:00") < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - time%d read failed for tariff '%s'\n", i, tariffName.c_str());
return -1;
}
strprintf(¶m, "PriceDayA%d", i);
if (conf.ReadDouble(param, &td->dirPrice[i].priceDayA, 0.0) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - pricedaya read failed for tariff '%s'\n", tariffName.c_str());
return -1;
}
strprintf(¶m, "PriceDayB%d", i);
if (conf.ReadDouble(param, &td->dirPrice[i].priceDayB, 0.0) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - pricedayb read failed for tariff '%s'\n", tariffName.c_str());
return -1;
}
strprintf(¶m, "PriceNightA%d", i);
if (conf.ReadDouble(param, &td->dirPrice[i].priceNightA, 0.0) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - pricenighta read failed for tariff '%s'\n", tariffName.c_str());
return -1;
}
strprintf(¶m, "PriceNightB%d", i);
if (conf.ReadDouble(param, &td->dirPrice[i].priceNightB, 0.0) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - pricenightb read failed for tariff '%s'\n", tariffName.c_str());
return -1;
}
strprintf(¶m, "Threshold%d", i);
if (conf.ReadInt(param, &td->dirPrice[i].threshold, 0) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - threshold read failed for tariff '%s'\n", tariffName.c_str());
return -1;
}
strprintf(¶m, "SinglePrice%d", i);
if (conf.ReadInt(param, &td->dirPrice[i].singlePrice, 0) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - singleprice read failed for tariff '%s'\n", tariffName.c_str());
return -1;
}
strprintf(¶m, "NoDiscount%d", i);
if (conf.ReadInt(param, &td->dirPrice[i].noDiscount, 0) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - nodiscount read failed for tariff '%s'\n", tariffName.c_str());
return -1;
}
if (conf.ReadDouble("Fee", &td->tariffConf.fee, 0) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read tariff " + tariffName + ". Parameter Fee";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read tariff " + tariffName + ". Parameter Fee";
printfd(__FILE__, "FILES_STORE::RestoreTariff - fee read failed for tariff '%s'\n", tariffName.c_str());
return -1;
}
if (conf.ReadDouble("Free", &td->tariffConf.free, 0) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read tariff " + tariffName + ". Parameter Free";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read tariff " + tariffName + ". Parameter Free";
printfd(__FILE__, "FILES_STORE::RestoreTariff - free read failed for tariff '%s'\n", tariffName.c_str());
return -1;
}
if (conf.ReadDouble("PassiveCost", &td->tariffConf.passiveCost, 0) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read tariff " + tariffName + ". Parameter PassiveCost";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read tariff " + tariffName + ". Parameter PassiveCost";
printfd(__FILE__, "FILES_STORE::RestoreTariff - passivecost read failed for tariff '%s'\n", tariffName.c_str());
return -1;
}
if (conf.ReadString("TraffType", &str, "") < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read tariff " + tariffName + ". Parameter TraffType";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read tariff " + tariffName + ". Parameter TraffType";
printfd(__FILE__, "FILES_STORE::RestoreTariff - trafftype read failed for tariff '%s'\n", tariffName.c_str());
return -1;
}
//-----------------------------------------------------------------------------
int FILES_STORE::SaveTariff(const STG::TariffData & td, const std::string & tariffName) const
{
-std::string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf";
+std::string fileName = m_storeSettings.GetTariffsDir() + "/" + tariffName + ".tf";
{
CONFIGFILE cf(fileName, true);
if (e)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error writing tariff " + tariffName;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error writing tariff " + tariffName;
printfd(__FILE__, "FILES_STORE::RestoreTariff - failed to save tariff '%s'\n", tariffName.c_str());
return e;
}
int FILES_STORE::AddService(const std::string & name) const
{
std::string fileName;
-strprintf(&fileName, "%s/%s.serv", storeSettings.GetServicesDir().c_str(), name.c_str());
+strprintf(&fileName, "%s/%s.serv", m_storeSettings.GetServicesDir().c_str(), name.c_str());
if (Touch(fileName))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot create file " + fileName;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot create file " + fileName;
printfd(__FILE__, "FILES_STORE::AddService - failed to add service '%s'\n", name.c_str());
return -1;
}
int FILES_STORE::DelService(const std::string & name) const
{
std::string fileName;
-strprintf(&fileName, "%s/%s.serv", storeSettings.GetServicesDir().c_str(), name.c_str());
+strprintf(&fileName, "%s/%s.serv", m_storeSettings.GetServicesDir().c_str(), name.c_str());
if (unlink(fileName.c_str()))
{
- STG_LOCKER lock(&mutex);
- errorStr = "unlink failed. Message: '";
- errorStr += strerror(errno);
- errorStr += "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "unlink failed. Message: '";
+ m_errorStr += strerror(errno);
+ m_errorStr += "'";
printfd(__FILE__, "FILES_STORE::DelAdmin - unlink failed. Message: '%s'\n", strerror(errno));
}
return 0;
{
std::string fileName;
-strprintf(&fileName, "%s/%s.serv", storeSettings.GetServicesDir().c_str(), conf.name.c_str());
+strprintf(&fileName, "%s/%s.serv", m_storeSettings.GetServicesDir().c_str(), conf.name.c_str());
{
CONFIGFILE cf(fileName, true);
if (e)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot write service " + conf.name + ". " + fileName;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot write service " + conf.name + ". " + fileName;
printfd(__FILE__, "FILES_STORE::SaveService - failed to save service '%s'\n", conf.name.c_str());
return -1;
}
int FILES_STORE::RestoreService(STG::ServiceConf * conf, const std::string & name) const
{
std::string fileName;
-strprintf(&fileName, "%s/%s.serv", storeSettings.GetServicesDir().c_str(), name.c_str());
+strprintf(&fileName, "%s/%s.serv", m_storeSettings.GetServicesDir().c_str(), name.c_str());
CONFIGFILE cf(fileName);
if (cf.Error())
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot open " + fileName;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot open " + fileName;
printfd(__FILE__, "FILES_STORE::RestoreService - failed to restore service '%s'\n", name.c_str());
return -1;
}
if (cf.ReadString("name", &conf->name, name))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error in parameter 'name'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error in parameter 'name'";
printfd(__FILE__, "FILES_STORE::RestoreService - name read failed for service '%s'\n", name.c_str());
return -1;
}
if (cf.ReadString("comment", &conf->comment, ""))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error in parameter 'comment'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error in parameter 'comment'";
printfd(__FILE__, "FILES_STORE::RestoreService - comment read failed for service '%s'\n", name.c_str());
return -1;
}
if (cf.ReadDouble("cost", &conf->cost, 0.0))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error in parameter 'cost'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error in parameter 'cost'";
printfd(__FILE__, "FILES_STORE::RestoreService - cost read failed for service '%s'\n", name.c_str());
return -1;
}
unsigned short value = 0;
if (cf.ReadUShortInt("pay_day", &value, 0))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error in parameter 'pay_day'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error in parameter 'pay_day'";
printfd(__FILE__, "FILES_STORE::RestoreService - pay day read failed for service '%s'\n", name.c_str());
return -1;
}
t = time(NULL);
-snprintf(dn, FN_STR_LEN, "%s/%s/detail_stat", storeSettings.GetUsersDir().c_str(), login.c_str());
+snprintf(dn, FN_STR_LEN, "%s/%s/detail_stat", m_storeSettings.GetUsersDir().c_str(), login.c_str());
if (access(dn, F_OK) != 0)
{
if (mkdir(dn, 0700) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno));
return -1;
}
}
-int e = chown(dn, storeSettings.GetStatUID(), storeSettings.GetStatGID());
-e += chmod(dn, storeSettings.GetStatModeDir());
+int e = chown(dn, m_storeSettings.GetStatUID(), m_storeSettings.GetStatGID());
+e += chmod(dn, m_storeSettings.GetStatModeDir());
if (e)
{
- STG_LOCKER lock(&mutex);
+ STG_LOCKER lock(&m_mutex);
printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
}
snprintf(dn, FN_STR_LEN, "%s/%s/detail_stat/%d",
- storeSettings.GetUsersDir().c_str(),
+ m_storeSettings.GetUsersDir().c_str(),
login.c_str(),
lt->tm_year+1900);
{
if (mkdir(dn, 0700) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno));
return -1;
}
}
-e = chown(dn, storeSettings.GetStatUID(), storeSettings.GetStatGID());
-e += chmod(dn, storeSettings.GetStatModeDir());
+e = chown(dn, m_storeSettings.GetStatUID(), m_storeSettings.GetStatGID());
+e += chmod(dn, m_storeSettings.GetStatModeDir());
if (e)
{
- STG_LOCKER lock(&mutex);
+ STG_LOCKER lock(&m_mutex);
printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
snprintf(dn, FN_STR_LEN, "%s/%s/detail_stat/%d/%s%d",
- storeSettings.GetUsersDir().c_str(),
+ m_storeSettings.GetUsersDir().c_str(),
login.c_str(),
lt->tm_year+1900,
lt->tm_mon+1 < 10 ? "0" : "",
{
if (mkdir(dn, 0700) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno));
return -1;
}
}
-e = chown(dn, storeSettings.GetStatUID(), storeSettings.GetStatGID());
-e += chmod(dn, storeSettings.GetStatModeDir());
+e = chown(dn, m_storeSettings.GetStatUID(), m_storeSettings.GetStatGID());
+e += chmod(dn, m_storeSettings.GetStatModeDir());
if (e)
{
- STG_LOCKER lock(&mutex);
+ STG_LOCKER lock(&m_mutex);
printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
if (!statFile)
{
- STG_LOCKER lock(&mutex);
- errorStr = "File \'" + std::string(fn) + "\' cannot be written.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "File \'" + std::string(fn) + "\' cannot be written.";
printfd(__FILE__, "FILES_STORE::WriteDetailStat - fopen failed. Message: '%s'\n", strerror(errno));
return -1;
}
if (fprintf(statFile, "-> %02d.%02d.%02d - %02d.%02d.%02d\n",
h1, m1, s1, h2, m2, s2) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = std::string("fprint failed. Message: '") + strerror(errno) + "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = std::string("fprint failed. Message: '") + strerror(errno) + "'";
printfd(__FILE__, "FILES_STORE::WriteDetailStat - fprintf failed. Message: '%s'\n", strerror(errno));
fclose(statFile);
return -1;
u.c_str(),
stIter->second.cash) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "fprint failed. Message: '";
- errorStr += strerror(errno);
- errorStr += "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "fprint failed. Message: '";
+ m_errorStr += strerror(errno);
+ m_errorStr += "'";
printfd(__FILE__, "FILES_STORE::WriteDetailStat - fprintf failed. Message: '%s'\n", strerror(errno));
fclose(statFile);
return -1;
u.c_str(),
stIter->second.cash) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = std::string("fprint failed. Message: '");
- errorStr += strerror(errno);
- errorStr += "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = std::string("fprint failed. Message: '");
+ m_errorStr += strerror(errno);
+ m_errorStr += "'";
printfd(__FILE__, "FILES_STORE::WriteDetailStat - fprintf failed. Message: '%s'\n", strerror(errno));
fclose(statFile);
return -1;
fclose(statFile);
-e = chown(fn, storeSettings.GetStatUID(), storeSettings.GetStatGID());
-e += chmod(fn, storeSettings.GetStatMode());
+e = chown(fn, m_storeSettings.GetStatUID(), m_storeSettings.GetStatGID());
+e += chmod(fn, m_storeSettings.GetStatMode());
if (e)
{
- STG_LOCKER lock(&mutex);
+ STG_LOCKER lock(&m_mutex);
printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
std::string dn;
struct timeval tv;
-strprintf(&dn, "%s/%s/messages", storeSettings.GetUsersDir().c_str(), login.c_str());
+strprintf(&dn, "%s/%s/messages", m_storeSettings.GetUsersDir().c_str(), login.c_str());
if (access(dn.c_str(), F_OK) != 0)
{
if (mkdir(dn.c_str(), 0700) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Directory \'";
- errorStr += dn;
- errorStr += "\' cannot be created.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Directory \'";
+ m_errorStr += dn;
+ m_errorStr += "\' cannot be created.";
printfd(__FILE__, "FILES_STORE::AddMessage - mkdir failed. Message: '%s'\n", strerror(errno));
return -1;
}
}
-chmod(dn.c_str(), storeSettings.GetConfModeDir());
+chmod(dn.c_str(), m_storeSettings.GetConfModeDir());
gettimeofday(&tv, NULL);
-msg->header.id = ((long long)tv.tv_sec) * 1000000 + ((long long)tv.tv_usec);
+msg->header.id = tv.tv_sec * 1000000 + tv.tv_usec;
strprintf(&fn, "%s/%lld", dn.c_str(), msg->header.id);
if (Touch(fn))
{
- STG_LOCKER lock(&mutex);
- errorStr = "File \'";
- errorStr += fn;
- errorStr += "\' cannot be writen.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "File \'";
+ m_errorStr += fn;
+ m_errorStr += "\' cannot be writen.";
printfd(__FILE__, "FILES_STORE::AddMessage - fopen failed. Message: '%s'\n", strerror(errno));
return -1;
}
std::string fileName;
FILE * msgFile;
-strprintf(&fileName, "%s/%s/messages/%lld", storeSettings.GetUsersDir().c_str(), login.c_str(), msg.header.id);
+strprintf(&fileName, "%s/%s/messages/%lld", m_storeSettings.GetUsersDir().c_str(), login.c_str(), msg.header.id);
if (access(fileName.c_str(), F_OK) != 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Message for user \'";
- errorStr += login + "\' with ID \'";
- errorStr += std::to_string(msg.header.id) + "\' does not exist.";
- printfd(__FILE__, "FILES_STORE::EditMessage - %s\n", errorStr.c_str());
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Message for user \'";
+ m_errorStr += login + "\' with ID \'";
+ m_errorStr += std::to_string(msg.header.id) + "\' does not exist.";
+ printfd(__FILE__, "FILES_STORE::EditMessage - %s\n", m_errorStr.c_str());
return -1;
}
msgFile = fopen((fileName + ".new").c_str(), "wt");
if (!msgFile)
{
- STG_LOCKER lock(&mutex);
- errorStr = "File \'" + fileName + "\' cannot be writen.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "File \'" + fileName + "\' cannot be writen.";
printfd(__FILE__, "FILES_STORE::EditMessage - fopen failed. Message: '%s'\n", strerror(errno));
return -1;
}
if (!res)
{
- STG_LOCKER lock(&mutex);
- errorStr = std::string("fprintf failed. Message: '") + strerror(errno) + "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = std::string("fprintf failed. Message: '") + strerror(errno) + "'";
printfd(__FILE__, "FILES_STORE::EditMessage - fprintf failed. Message: '%s'\n", strerror(errno));
fclose(msgFile);
return -1;
fclose(msgFile);
-chmod((fileName + ".new").c_str(), storeSettings.GetConfMode());
+chmod((fileName + ".new").c_str(), m_storeSettings.GetConfMode());
if (rename((fileName + ".new").c_str(), fileName.c_str()) < 0)
{
- STG_LOCKER lock(&mutex);
- errorStr = "Error moving dir from " + fileName + ".new to " + fileName;
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Error moving dir from " + fileName + ".new to " + fileName;
printfd(__FILE__, "FILES_STORE::EditMessage - rename failed. Message: '%s'\n", strerror(errno));
return -1;
}
int FILES_STORE::GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const
{
std::string fn;
-strprintf(&fn, "%s/%s/messages/%lld", storeSettings.GetUsersDir().c_str(), login.c_str(), id);
+strprintf(&fn, "%s/%s/messages/%lld", m_storeSettings.GetUsersDir().c_str(), login.c_str(), id);
msg->header.id = id;
return ReadMessage(fn, &msg->header, &msg->text);
}
int FILES_STORE::DelMessage(uint64_t id, const std::string & login) const
{
std::string fn;
-strprintf(&fn, "%s/%s/messages/%lld", storeSettings.GetUsersDir().c_str(), login.c_str(), id);
+strprintf(&fn, "%s/%s/messages/%lld", m_storeSettings.GetUsersDir().c_str(), login.c_str(), id);
return unlink(fn.c_str());
}
//-----------------------------------------------------------------------------
int FILES_STORE::GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const
{
-std::string dn(storeSettings.GetUsersDir() + "/" + login + "/messages/");
+std::string dn(m_storeSettings.GetUsersDir() + "/" + login + "/messages/");
if (access(dn.c_str(), F_OK) != 0)
{
{
if (unlink((dn + messages[i]).c_str()))
{
- STG_LOCKER lock(&mutex);
- errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'";
printfd(__FILE__, "FILES_STORE::GetMessageHdrs - unlink failed. Message: '%s'\n", strerror(errno));
return -1;
}
{
if (unlink((dn + messages[i]).c_str()))
{
- STG_LOCKER lock(&mutex);
- errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'";
printfd(__FILE__, "FILES_STORE::GetMessageHdrs - unlink failed. Message: '%s'\n", strerror(errno));
return -1;
}
msgFile = fopen(fileName.c_str(), "rt");
if (!msgFile)
{
- STG_LOCKER lock(&mutex);
- errorStr = "File \'";
- errorStr += fileName;
- errorStr += "\' cannot be openned.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "File \'";
+ m_errorStr += fileName;
+ m_errorStr += "\' cannot be openned.";
printfd(__FILE__, "FILES_STORE::ReadMessage - fopen failed. Message: '%s'\n", strerror(errno));
return -1;
}
d[1] = &hdr->lastSendTime;
d[2] = &hdr->creationTime;
d[3] = &hdr->showTime;
-d[4] = (unsigned*)(&hdr->repeat);
+d[4] = reinterpret_cast<unsigned*>(&hdr->repeat);
d[5] = &hdr->repeatPeriod;
memset(p, 0, sizeof(p));
for (int pos = 0; pos < 6; pos++)
{
if (fgets(p, sizeof(p) - 1, msgFile) == NULL) {
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read file \'";
- errorStr += fileName;
- errorStr += "\'. Missing data.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read file \'";
+ m_errorStr += fileName;
+ m_errorStr += "\'. Missing data.";
printfd(__FILE__, "FILES_STORE::ReadMessage - cannot read file (missing data)\n");
printfd(__FILE__, "FILES_STORE::ReadMessage - position: %d\n", pos);
fclose(msgFile);
if (feof(msgFile))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read file \'";
- errorStr += fileName;
- errorStr += "\'. Missing data.";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read file \'";
+ m_errorStr += fileName;
+ m_errorStr += "\'. Missing data.";
printfd(__FILE__, "FILES_STORE::ReadMessage - cannot read file (feof)\n");
printfd(__FILE__, "FILES_STORE::ReadMessage - position: %d\n", pos);
fclose(msgFile);
if (str2x(p, *(d[pos])))
{
- STG_LOCKER lock(&mutex);
- errorStr = "Cannot read file \'";
- errorStr += fileName;
- errorStr += "\'. Incorrect value. \'";
- errorStr += p;
- errorStr += "\'";
+ STG_LOCKER lock(&m_mutex);
+ m_errorStr = "Cannot read file \'";
+ m_errorStr += fileName;
+ m_errorStr += "\'. Incorrect value. \'";
+ m_errorStr += p;
+ m_errorStr += "\'";
printfd(__FILE__, "FILES_STORE::ReadMessage - incorrect value\n");
fclose(msgFile);
return -1;
#include <pthread.h>
//-----------------------------------------------------------------------------
-class FILES_STORE_SETTINGS {
-public:
- FILES_STORE_SETTINGS();
- int ParseSettings(const STG::ModuleSettings & s);
- const std::string & GetStrError() const;
-
- std::string GetWorkDir() const { return workDir; }
- std::string GetUsersDir() const { return usersDir; }
- std::string GetAdminsDir() const { return adminsDir; }
- std::string GetTariffsDir() const { return tariffsDir; }
- std::string GetServicesDir() const { return servicesDir; }
-
- mode_t GetStatMode() const { return statMode; }
- mode_t GetStatModeDir() const;
- uid_t GetStatUID() const { return statUID; }
- gid_t GetStatGID() const { return statGID; }
-
- mode_t GetConfMode() const { return confMode; }
- mode_t GetConfModeDir() const;
- uid_t GetConfUID() const { return confUID; }
- gid_t GetConfGID() const { return confGID; }
-
- mode_t GetLogMode() const { return userLogMode; }
- uid_t GetLogUID() const { return userLogUID; }
- gid_t GetLogGID() const { return userLogGID; }
-
- bool GetRemoveBak() const { return removeBak; }
- bool GetReadBak() const { return readBak; }
-
-private:
- FILES_STORE_SETTINGS(const FILES_STORE_SETTINGS & rvalue);
- FILES_STORE_SETTINGS & operator=(const FILES_STORE_SETTINGS & rvalue);
-
- const STG::ModuleSettings * settings;
-
- int User2UID(const char * user, uid_t * uid);
- int Group2GID(const char * gr, gid_t * gid);
- int Str2Mode(const char * str, mode_t * mode);
- int ParseOwner(const std::vector<STG::ParamValue> & moduleParams, const std::string & owner, uid_t * uid);
- int ParseGroup(const std::vector<STG::ParamValue> & moduleParams, const std::string & group, uid_t * uid);
- int ParseMode(const std::vector<STG::ParamValue> & moduleParams, const std::string & modeStr, mode_t * mode);
- int ParseYesNo(const std::string & value, bool * val);
-
- std::string errorStr;
-
- std::string workDir;
- std::string usersDir;
- std::string adminsDir;
- std::string tariffsDir;
- std::string servicesDir;
-
- mode_t statMode;
- uid_t statUID;
- gid_t statGID;
-
- mode_t confMode;
- uid_t confUID;
- gid_t confGID;
-
- mode_t userLogMode;
- uid_t userLogUID;
- gid_t userLogGID;
-
- bool removeBak;
- bool readBak;
+class FILES_STORE_SETTINGS
+{
+ public:
+ FILES_STORE_SETTINGS();
+
+ FILES_STORE_SETTINGS(const FILES_STORE_SETTINGS&) = default;
+ FILES_STORE_SETTINGS& operator=(const FILES_STORE_SETTINGS&) = default;
+ FILES_STORE_SETTINGS(FILES_STORE_SETTINGS&&) = default;
+ FILES_STORE_SETTINGS& operator=(FILES_STORE_SETTINGS&&) = default;
+
+ int ParseSettings(const STG::ModuleSettings & s);
+ const std::string & GetStrError() const;
+
+ std::string GetWorkDir() const { return m_workDir; }
+ std::string GetUsersDir() const { return m_usersDir; }
+ std::string GetAdminsDir() const { return m_adminsDir; }
+ std::string GetTariffsDir() const { return m_tariffsDir; }
+ std::string GetServicesDir() const { return m_servicesDir; }
+
+ mode_t GetStatMode() const { return m_statMode; }
+ mode_t GetStatModeDir() const;
+ uid_t GetStatUID() const { return m_statUID; }
+ gid_t GetStatGID() const { return m_statGID; }
+
+ mode_t GetConfMode() const { return m_confMode; }
+ mode_t GetConfModeDir() const;
+ uid_t GetConfUID() const { return m_confUID; }
+ gid_t GetConfGID() const { return m_confGID; }
+
+ mode_t GetLogMode() const { return m_userLogMode; }
+ uid_t GetLogUID() const { return m_userLogUID; }
+ gid_t GetLogGID() const { return m_userLogGID; }
+
+ bool GetRemoveBak() const { return m_removeBak; }
+ bool GetReadBak() const { return m_readBak; }
+
+ private:
+
+ int User2UID(const char * user, uid_t * uid);
+ int Group2GID(const char * gr, gid_t * gid);
+ int Str2Mode(const char * str, mode_t * mode);
+ int ParseOwner(const std::vector<STG::ParamValue> & moduleParams, const std::string & owner, uid_t * uid);
+ int ParseGroup(const std::vector<STG::ParamValue> & moduleParams, const std::string & group, uid_t * uid);
+ int ParseMode(const std::vector<STG::ParamValue> & moduleParams, const std::string & modeStr, mode_t * mode);
+ int ParseYesNo(const std::string & value, bool * val);
+
+ std::string m_errorStr;
+
+ std::string m_workDir;
+ std::string m_usersDir;
+ std::string m_adminsDir;
+ std::string m_tariffsDir;
+ std::string m_servicesDir;
+
+ mode_t m_statMode;
+ uid_t m_statUID;
+ gid_t m_statGID;
+
+ mode_t m_confMode;
+ uid_t m_confUID;
+ gid_t m_confGID;
+
+ mode_t m_userLogMode;
+ uid_t m_userLogUID;
+ gid_t m_userLogGID;
+
+ bool m_removeBak;
+ bool m_readBak;
};
//-----------------------------------------------------------------------------
-class FILES_STORE: public STG::Store {
-public:
- FILES_STORE();
- const std::string & GetStrError() const override { return errorStr; }
-
- //User
- int GetUsersList(std::vector<std::string> * usersList) const override;
- int AddUser(const std::string & login) const override;
- int DelUser(const std::string & login) const override;
- int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
- int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
-
- int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
- int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
-
- int WriteUserChgLog(const std::string & login,
- const std::string & admLogin,
- uint32_t admIP,
- const std::string & paramName,
- const std::string & oldValue,
- const std::string & newValue,
- const std::string & message = "") const override;
- int WriteUserConnect(const std::string & login, uint32_t ip) const override;
- int WriteUserDisconnect(const std::string & login,
- const STG::DirTraff & up,
- const STG::DirTraff & down,
- const STG::DirTraff & sessionUp,
- const STG::DirTraff & sessionDown,
- double cash,
- double freeMb,
- const std::string & reason) const override;
-
- int WriteDetailedStat(const STG::TraffStat & statTree,
- time_t lastStat,
- const std::string & login) const override;
-
- int AddMessage(STG::Message * msg, const std::string & login) const override;
- int EditMessage(const STG::Message & msg, const std::string & login) const override;
- int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
- int DelMessage(uint64_t id, const std::string & login) const override;
- int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
-
- int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
-
- //Admin
- int GetAdminsList(std::vector<std::string> * adminsList) const override;
- int AddAdmin(const std::string & login) const override;
- int DelAdmin(const std::string & login) const override;
- int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
- int SaveAdmin(const STG::AdminConf & ac) const override;
-
- //Tariff
- int GetTariffsList(std::vector<std::string> * tariffsList) const override;
- int AddTariff(const std::string & name) const override;
- int DelTariff(const std::string & name) const override;
- int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
- int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
-
- //Corparation
- int GetCorpsList(std::vector<std::string> *) const override { return 0; }
- int SaveCorp(const STG::CorpConf &) const override { return 0; }
- int RestoreCorp(STG::CorpConf *, const std::string &) const override { return 0; }
- int AddCorp(const std::string &) const override { return 0; }
- int DelCorp(const std::string &) const override { return 0; }
-
- // Services
- int GetServicesList(std::vector<std::string> *) const override;
- int SaveService(const STG::ServiceConf &) const override;
- int RestoreService(STG::ServiceConf *, const std::string &) const override;
- int AddService(const std::string &) const override;
- int DelService(const std::string &) const override;
-
- void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
- int ParseSettings() override;
- const std::string & GetVersion() const override { return version; }
-
-private:
- FILES_STORE(const FILES_STORE & rvalue);
- FILES_STORE & operator=(const FILES_STORE & rvalue);
-
- int ReadMessage(const std::string & fileName,
- STG::Message::Header * hdr,
- std::string * text) const;
-
- virtual int RestoreUserStat(STG::UserStat * stat, const std::string & login, const std::string & fileName) const;
- virtual int RestoreUserConf(STG::UserConf * conf, const std::string & login, const std::string & fileName) const;
-
- virtual int WriteLogString(const std::string & str, const std::string & login) const;
- virtual int WriteLog2String(const std::string & str, const std::string & login) const;
- int RemoveDir(const char * path) const;
- int Touch(const std::string & path) const;
-
- mutable std::string errorStr;
- std::string version;
- FILES_STORE_SETTINGS storeSettings;
- STG::ModuleSettings settings;
- mutable pthread_mutex_t mutex;
-
- STG::PluginLogger logger;
+class FILES_STORE: public STG::Store
+{
+ public:
+ FILES_STORE();
+
+ FILES_STORE(const FILES_STORE&) = delete;
+ FILES_STORE & operator=(const FILES_STORE&) = delete;
+
+ const std::string & GetStrError() const override { return m_errorStr; }
+
+ //User
+ int GetUsersList(std::vector<std::string> * usersList) const override;
+ int AddUser(const std::string & login) const override;
+ int DelUser(const std::string & login) const override;
+ int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
+ int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
+
+ int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
+ int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
+
+ int WriteUserChgLog(const std::string & login,
+ const std::string & admLogin,
+ uint32_t admIP,
+ const std::string & paramName,
+ const std::string & oldValue,
+ const std::string & newValue,
+ const std::string & message = "") const override;
+ int WriteUserConnect(const std::string & login, uint32_t ip) const override;
+ int WriteUserDisconnect(const std::string & login,
+ const STG::DirTraff & up,
+ const STG::DirTraff & down,
+ const STG::DirTraff & sessionUp,
+ const STG::DirTraff & sessionDown,
+ double cash,
+ double freeMb,
+ const std::string & reason) const override;
+
+ int WriteDetailedStat(const STG::TraffStat & statTree,
+ time_t lastStat,
+ const std::string & login) const override;
+
+ int AddMessage(STG::Message * msg, const std::string & login) const override;
+ int EditMessage(const STG::Message & msg, const std::string & login) const override;
+ int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
+ int DelMessage(uint64_t id, const std::string & login) const override;
+ int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
+
+ int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
+
+ //Admin
+ int GetAdminsList(std::vector<std::string> * adminsList) const override;
+ int AddAdmin(const std::string & login) const override;
+ int DelAdmin(const std::string & login) const override;
+ int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
+ int SaveAdmin(const STG::AdminConf & ac) const override;
+
+ //Tariff
+ int GetTariffsList(std::vector<std::string> * tariffsList) const override;
+ int AddTariff(const std::string & name) const override;
+ int DelTariff(const std::string & name) const override;
+ int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
+ int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
+
+ //Corparation
+ int GetCorpsList(std::vector<std::string> *) const override { return 0; }
+ int SaveCorp(const STG::CorpConf &) const override { return 0; }
+ int RestoreCorp(STG::CorpConf *, const std::string &) const override { return 0; }
+ int AddCorp(const std::string &) const override { return 0; }
+ int DelCorp(const std::string &) const override { return 0; }
+
+ // Services
+ int GetServicesList(std::vector<std::string> *) const override;
+ int SaveService(const STG::ServiceConf &) const override;
+ int RestoreService(STG::ServiceConf *, const std::string &) const override;
+ int AddService(const std::string &) const override;
+ int DelService(const std::string &) const override;
+
+ void SetSettings(const STG::ModuleSettings & s) override { m_settings = s; }
+ int ParseSettings() override;
+ const std::string & GetVersion() const override { return m_version; }
+
+ private:
+ int ReadMessage(const std::string & fileName,
+ STG::Message::Header * hdr,
+ std::string * text) const;
+
+ int RemoveDir(const char * path) const;
+ int Touch(const std::string & path) const;
+
+ int RestoreUserStat(STG::UserStat * stat, const std::string & login, const std::string & fileName) const;
+ int RestoreUserConf(STG::UserConf * conf, const std::string & login, const std::string & fileName) const;
+
+ int WriteLogString(const std::string & str, const std::string & login) const;
+ int WriteLog2String(const std::string & str, const std::string & login) const;
+
+ mutable std::string m_errorStr;
+ std::string m_version;
+ FILES_STORE_SETTINGS m_storeSettings;
+ STG::ModuleSettings m_settings;
+ mutable pthread_mutex_t m_mutex;
+
+ STG::PluginLogger m_logger;
};
#include "stg/store.h"
#include "stg/locker.h"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
#include "stg/ibpp.h"
+#pragma GCC diagnostic push
#include "stg/logger.h"
#include "stg/module_settings.h"
#include <string>
#include <vector>
-class FIREBIRD_STORE : public STG::Store {
-public:
- FIREBIRD_STORE();
- ~FIREBIRD_STORE() override;
-
- int GetUsersList(std::vector<std::string> * usersList) const override;
- int AddUser(const std::string & login) const override;
- int DelUser(const std::string & login) const override;
- int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
- int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
- int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
- int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
- int WriteUserChgLog(const std::string & login,
- const std::string & admLogin,
- uint32_t admIP,
- const std::string & paramName,
- const std::string & oldValue,
- const std::string & newValue,
- const std::string & message) const override;
- int WriteUserConnect(const std::string & login, uint32_t ip) const override;
- int WriteUserDisconnect(const std::string & login,
- const STG::DirTraff & up,
- const STG::DirTraff & down,
- const STG::DirTraff & sessionUp,
- const STG::DirTraff & sessionDown,
- double cash,
- double freeMb,
- const std::string & reason) const override;
- int WriteDetailedStat(const STG::TraffStat & statTree,
- time_t lastStat,
- const std::string & login) const override;
-
- int AddMessage(STG::Message * msg, const std::string & login) const override;
- int EditMessage(const STG::Message & msg, const std::string & login) const override;
- int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
- int DelMessage(uint64_t id, const std::string & login) const override;
- int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
-
- int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
-
- int GetAdminsList(std::vector<std::string> * adminsList) const override;
- int SaveAdmin(const STG::AdminConf & ac) const override;
- int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
- int AddAdmin(const std::string & login) const override;
- int DelAdmin(const std::string & login) const override;
-
- int GetTariffsList(std::vector<std::string> * tariffsList) const override;
- int AddTariff(const std::string & name) const override;
- int DelTariff(const std::string & name) const override;
- int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
- int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
-
- int GetCorpsList(std::vector<std::string> * corpsList) const override;
- int SaveCorp(const STG::CorpConf & cc) const override;
- int RestoreCorp(STG::CorpConf * cc, const std::string & name) const override;
- int AddCorp(const std::string & name) const override;
- int DelCorp(const std::string & name) const override;
-
- inline void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
- int ParseSettings() override;
-
- inline const std::string & GetStrError() const override { return strError; }
-
- inline const std::string & GetVersion() const override { return version; }
-
- int GetServicesList(std::vector<std::string> * servicesList) const override;
- int SaveService(const STG::ServiceConf & sc) const override;
- int RestoreService(STG::ServiceConf * sc, const std::string & name) const override;
- int AddService(const std::string & name) const override;
- int DelService(const std::string & name) const override;
-
-private:
- FIREBIRD_STORE(const FIREBIRD_STORE & rvalue);
- FIREBIRD_STORE & operator=(const FIREBIRD_STORE & rvalue);
-
- std::string version;
- mutable std::string strError;
- std::string db_server, db_database, db_user, db_password;
- STG::ModuleSettings settings;
- mutable IBPP::Database db;
- mutable pthread_mutex_t mutex;
- IBPP::TIL til;
- IBPP::TLR tlr;
- int schemaVersion;
- STG::PluginLogger logger;
-
- int SaveStat(const STG::UserStat & stat, const std::string & login, int year = 0, int month = 0) const;
- int CheckVersion();
+class FIREBIRD_STORE : public STG::Store
+{
+ public:
+ FIREBIRD_STORE();
+ ~FIREBIRD_STORE() override;
+
+ int GetUsersList(std::vector<std::string> * usersList) const override;
+ int AddUser(const std::string & login) const override;
+ int DelUser(const std::string & login) const override;
+ int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
+ int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
+ int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
+ int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
+ int WriteUserChgLog(const std::string & login,
+ const std::string & admLogin,
+ uint32_t admIP,
+ const std::string & paramName,
+ const std::string & oldValue,
+ const std::string & newValue,
+ const std::string & message) const override;
+ int WriteUserConnect(const std::string & login, uint32_t ip) const override;
+ int WriteUserDisconnect(const std::string & login,
+ const STG::DirTraff & up,
+ const STG::DirTraff & down,
+ const STG::DirTraff & sessionUp,
+ const STG::DirTraff & sessionDown,
+ double cash,
+ double freeMb,
+ const std::string & reason) const override;
+ int WriteDetailedStat(const STG::TraffStat & statTree,
+ time_t lastStat,
+ const std::string & login) const override;
+
+ int AddMessage(STG::Message * msg, const std::string & login) const override;
+ int EditMessage(const STG::Message & msg, const std::string & login) const override;
+ int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
+ int DelMessage(uint64_t id, const std::string & login) const override;
+ int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
+
+ int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
+
+ int GetAdminsList(std::vector<std::string> * adminsList) const override;
+ int SaveAdmin(const STG::AdminConf & ac) const override;
+ int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
+ int AddAdmin(const std::string & login) const override;
+ int DelAdmin(const std::string & login) const override;
+
+ int GetTariffsList(std::vector<std::string> * tariffsList) const override;
+ int AddTariff(const std::string & name) const override;
+ int DelTariff(const std::string & name) const override;
+ int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
+ int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
+
+ int GetCorpsList(std::vector<std::string> * corpsList) const override;
+ int SaveCorp(const STG::CorpConf & cc) const override;
+ int RestoreCorp(STG::CorpConf * cc, const std::string & name) const override;
+ int AddCorp(const std::string & name) const override;
+ int DelCorp(const std::string & name) const override;
+
+ inline void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
+ int ParseSettings() override;
+
+ inline const std::string & GetStrError() const override { return strError; }
+
+ inline const std::string & GetVersion() const override { return version; }
+
+ int GetServicesList(std::vector<std::string> * servicesList) const override;
+ int SaveService(const STG::ServiceConf & sc) const override;
+ int RestoreService(STG::ServiceConf * sc, const std::string & name) const override;
+ int AddService(const std::string & name) const override;
+ int DelService(const std::string & name) const override;
+
+ private:
+ FIREBIRD_STORE(const FIREBIRD_STORE & rvalue);
+ FIREBIRD_STORE & operator=(const FIREBIRD_STORE & rvalue);
+
+ std::string version;
+ mutable std::string strError;
+ std::string db_server, db_database, db_user, db_password;
+ STG::ModuleSettings settings;
+ mutable IBPP::Database db;
+ mutable pthread_mutex_t mutex;
+ IBPP::TIL til;
+ IBPP::TLR tlr;
+ int schemaVersion;
+ STG::PluginLogger logger;
+
+ int SaveStat(const STG::UserStat & stat, const std::string & login, int year = 0, int month = 0) const;
+ int CheckVersion();
};
time_t ts2time_t(const IBPP::Timestamp & ts);
#include "firebird_store.h"
-#include "stg/ibpp.h"
#include "stg/admin_conf.h"
#include "stg/blowfish.h"
#include "stg/common.h"
{
st->Get(2, ac->login);
st->Get(3, ac->password);
- st->Get(4, (int16_t &)ac->priv.userConf);
- st->Get(5, (int16_t &)ac->priv.userPasswd);
- st->Get(6, (int16_t &)ac->priv.userStat);
- st->Get(7, (int16_t &)ac->priv.userCash);
- st->Get(8, (int16_t &)ac->priv.userAddDel);
- st->Get(9, (int16_t &)ac->priv.tariffChg);
- st->Get(10, (int16_t &)ac->priv.adminChg);
+ st->Get(4, reinterpret_cast<int16_t &>(ac->priv.userConf));
+ st->Get(5, reinterpret_cast<int16_t &>(ac->priv.userPasswd));
+ st->Get(6, reinterpret_cast<int16_t &>(ac->priv.userStat));
+ st->Get(7, reinterpret_cast<int16_t &>(ac->priv.userCash));
+ st->Get(8, reinterpret_cast<int16_t &>(ac->priv.userAddDel));
+ st->Get(9, reinterpret_cast<int16_t &>(ac->priv.tariffChg));
+ st->Get(10, reinterpret_cast<int16_t &>(ac->priv.adminChg));
}
else
{
st->Execute();
st->Prepare("insert into tb_allowed_ip (fk_user, ip, mask) values (?, ?, ?)");
- for(size_t j = 0; i < conf.ips.count(); j++)
+ for(size_t j = 0; j < conf.ips.count(); j++)
{
st->Set(1, uid);
st->Set(2, (int32_t)conf.ips[j].ip);
}
-class POSTGRESQL_STORE : public STG::Store {
-public:
- POSTGRESQL_STORE();
- ~POSTGRESQL_STORE() override;
-
- // Users
- int GetUsersList(std::vector<std::string> * usersList) const override;
- int AddUser(const std::string & login) const override;
- int DelUser(const std::string & login) const override;
- int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
- int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
- int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
- int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
- int WriteUserChgLog(const std::string & login,
- const std::string & admLogin,
- uint32_t admIP,
- const std::string & paramName,
- const std::string & oldValue,
- const std::string & newValue,
- const std::string & message) const override;
- int WriteUserConnect(const std::string & login, uint32_t ip) const override;
- int WriteUserDisconnect(const std::string & login,
- const STG::DirTraff & up,
- const STG::DirTraff & down,
- const STG::DirTraff & sessionUp,
- const STG::DirTraff & sessionDown,
- double cash,
- double freeMb,
- const std::string & reason) const override;
- int WriteDetailedStat(const STG::TraffStat & statTree,
- time_t lastStat,
- const std::string & login) const override;
-
- // Messages
- int AddMessage(STG::Message * msg, const std::string & login) const override;
- int EditMessage(const STG::Message & msg, const std::string & login) const override;
- int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
- int DelMessage(uint64_t id, const std::string & login) const override;
- int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
-
- // Stats
- int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
-
- // Admins
- int GetAdminsList(std::vector<std::string> * adminsList) const override;
- int SaveAdmin(const STG::AdminConf & ac) const override;
- int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
- int AddAdmin(const std::string & login) const override;
- int DelAdmin(const std::string & login) const override;
-
- // Tariffs
- int GetTariffsList(std::vector<std::string> * tariffsList) const override;
- int AddTariff(const std::string & name) const override;
- int DelTariff(const std::string & name) const override;
- int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
- int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
-
- // Corporations
- int GetCorpsList(std::vector<std::string> * corpsList) const override;
- int SaveCorp(const STG::CorpConf & cc) const override;
- int RestoreCorp(STG::CorpConf * cc, const std::string & name) const override;
- int AddCorp(const std::string & name) const override;
- int DelCorp(const std::string & name) const override;
-
- // Services
- int GetServicesList(std::vector<std::string> * servicesList) const override;
- int SaveService(const STG::ServiceConf & sc) const override;
- int RestoreService(STG::ServiceConf * sc, const std::string & name) const override;
- int AddService(const std::string & name) const override;
- int DelService(const std::string & name) const override;
-
- // Settings
- void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
- int ParseSettings() override;
-
- const std::string & GetStrError() const override { return strError; }
- const std::string & GetVersion() const override { return versionString; }
-private:
- POSTGRESQL_STORE(const POSTGRESQL_STORE & rvalue);
- POSTGRESQL_STORE & operator=(const POSTGRESQL_STORE & rvalue);
-
- int StartTransaction() const;
- int CommitTransaction() const;
- int RollbackTransaction() const;
-
- int EscapeString(std::string & value) const;
-
- int SaveStat(const STG::UserStat & stat, const std::string & login, int year = 0, int month = 0) const;
-
- int SaveUserServices(uint32_t uid, const std::vector<std::string> & services) const;
- int SaveUserData(uint32_t uid, const std::vector<std::string> & data) const;
- int SaveUserIPs(uint32_t uid, const STG::UserIPs & ips) const;
-
- void MakeDate(std::string & date, int year = 0, int month = 0) const;
-
- int Connect();
- int Reset() const;
- int CheckVersion() const;
-
- std::string versionString;
- mutable std::string strError;
- std::string server;
- std::string database;
- std::string user;
- std::string password;
- std::string clientEncoding;
- STG::ModuleSettings settings;
- mutable pthread_mutex_t mutex;
- mutable int version;
- int retries;
-
- PGconn * connection;
-
- STG::PluginLogger logger;
+class POSTGRESQL_STORE : public STG::Store
+{
+ public:
+ POSTGRESQL_STORE();
+ ~POSTGRESQL_STORE() override;
+
+ // Users
+ int GetUsersList(std::vector<std::string> * usersList) const override;
+ int AddUser(const std::string & login) const override;
+ int DelUser(const std::string & login) const override;
+ int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
+ int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
+ int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
+ int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
+ int WriteUserChgLog(const std::string & login,
+ const std::string & admLogin,
+ uint32_t admIP,
+ const std::string & paramName,
+ const std::string & oldValue,
+ const std::string & newValue,
+ const std::string & message) const override;
+ int WriteUserConnect(const std::string & login, uint32_t ip) const override;
+ int WriteUserDisconnect(const std::string & login,
+ const STG::DirTraff & up,
+ const STG::DirTraff & down,
+ const STG::DirTraff & sessionUp,
+ const STG::DirTraff & sessionDown,
+ double cash,
+ double freeMb,
+ const std::string & reason) const override;
+ int WriteDetailedStat(const STG::TraffStat & statTree,
+ time_t lastStat,
+ const std::string & login) const override;
+
+ // Messages
+ int AddMessage(STG::Message * msg, const std::string & login) const override;
+ int EditMessage(const STG::Message & msg, const std::string & login) const override;
+ int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
+ int DelMessage(uint64_t id, const std::string & login) const override;
+ int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
+
+ // Stats
+ int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
+
+ // Admins
+ int GetAdminsList(std::vector<std::string> * adminsList) const override;
+ int SaveAdmin(const STG::AdminConf & ac) const override;
+ int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
+ int AddAdmin(const std::string & login) const override;
+ int DelAdmin(const std::string & login) const override;
+
+ // Tariffs
+ int GetTariffsList(std::vector<std::string> * tariffsList) const override;
+ int AddTariff(const std::string & name) const override;
+ int DelTariff(const std::string & name) const override;
+ int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
+ int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
+
+ // Corporations
+ int GetCorpsList(std::vector<std::string> * corpsList) const override;
+ int SaveCorp(const STG::CorpConf & cc) const override;
+ int RestoreCorp(STG::CorpConf * cc, const std::string & name) const override;
+ int AddCorp(const std::string & name) const override;
+ int DelCorp(const std::string & name) const override;
+
+ // Services
+ int GetServicesList(std::vector<std::string> * servicesList) const override;
+ int SaveService(const STG::ServiceConf & sc) const override;
+ int RestoreService(STG::ServiceConf * sc, const std::string & name) const override;
+ int AddService(const std::string & name) const override;
+ int DelService(const std::string & name) const override;
+
+ // Settings
+ void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
+ int ParseSettings() override;
+
+ const std::string & GetStrError() const override { return strError; }
+ const std::string & GetVersion() const override { return versionString; }
+ private:
+ POSTGRESQL_STORE(const POSTGRESQL_STORE & rvalue);
+ POSTGRESQL_STORE & operator=(const POSTGRESQL_STORE & rvalue);
+
+ int StartTransaction() const;
+ int CommitTransaction() const;
+ int RollbackTransaction() const;
+
+ int EscapeString(std::string & value) const;
+
+ int SaveStat(const STG::UserStat & stat, const std::string & login, int year = 0, int month = 0) const;
+
+ int SaveUserServices(uint32_t uid, const std::vector<std::string> & services) const;
+ int SaveUserData(uint32_t uid, const std::vector<std::string> & data) const;
+ int SaveUserIPs(uint32_t uid, const STG::UserIPs & ips) const;
+
+ void MakeDate(std::string & date, int year = 0, int month = 0) const;
+
+ int Connect();
+ int Reset() const;
+ int CheckVersion() const;
+
+ std::string versionString;
+ mutable std::string strError;
+ std::string server;
+ std::string database;
+ std::string user;
+ std::string password;
+ std::string clientEncoding;
+ STG::ModuleSettings settings;
+ mutable pthread_mutex_t mutex;
+ mutable int version;
+ int retries;
+
+ PGconn * connection;
+
+ STG::PluginLogger logger;
};
{
td->dirPrice[dir].singlePrice = false;
}
- if (td->dirPrice[dir].threshold == (int)0xffFFffFF)
+ if (td->dirPrice[dir].threshold == static_cast<int>(0xffFFffFF))
{
td->dirPrice[dir].noDiscount = true;
}
namespace STG
{
-struct Admin;
+class Admin;
struct Store;
class ServicesImpl : public Services {
$Author: faust $
*/
-#include <cassert>
-#include <algorithm>
-#include <vector>
+#include "tariffs_impl.h"
#include "stg/locker.h"
#include "stg/logger.h"
#include "stg/store.h"
#include "stg/admin.h"
#include "stg/admin_conf.h"
-#include "tariffs_impl.h"
+
+#include <cassert>
+#include <algorithm>
using STG::TariffsImpl;
struct Store;
class Logger;
-struct Admin;
+class Admin;
class TariffsImpl : public Tariffs {
public:
//-----------------------------------------------------------------------------
struct Tariff;
-struct Tariffs;
-struct Admin;
+class Tariffs;
+class Admin;
class UserImpl;
#ifdef USE_ABSTRACT_SETTINGS
struct Settings;
auto dayResetTraff = settings->GetDayResetTraff();
if (dayResetTraff == 0)
dayResetTraff = DaysInCurrentMonth();
-if (t1.tm_mday == dayResetTraff)
+if (static_cast<unsigned>(t1.tm_mday) == dayResetTraff)
{
printfd(__FILE__, "ResetTraff\n");
for_each(users.begin(), users.end(), [](auto& user){ user.ProcessNewMonth(); });
typedef std::list<UserImpl>::iterator user_iter;
typedef std::list<UserImpl>::const_iterator const_user_iter;
-class UsersImpl;
//-----------------------------------------------------------------------------
struct USER_TO_DEL {
USER_TO_DEL()
//-----------------------------------------------------------------------------
class UsersImpl : public Users
{
- friend class PROPERTY_NOTIFER_IP_BEFORE;
- friend class PROPERTY_NOTIFER_IP_AFTER;
-
public:
using UserImplPtr = UserImpl*;