From: Elena Mamontova Date: Thu, 17 Mar 2016 07:39:43 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/stg-2.409' into ticket26 X-Git-Tag: 2.409~174^2~1^2~9 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/8c7e6453aff765245cc5c28f37543f13d92dbe74?hp=3a88b66f861decb863bbb00a450e2801ee668a09 Merge remote-tracking branch 'origin/stg-2.409' into ticket26 --- diff --git a/include/stg/resetable.h b/include/stg/resetable.h index 8a6ad27c..a451b357 100644 --- a/include/stg/resetable.h +++ b/include/stg/resetable.h @@ -50,6 +50,11 @@ public: is_set = true; } } + void maybeSet(value_type& dest) const + { + if (is_set) + dest = value; + } private: value_type value; diff --git a/include/stg/tariff_conf.h b/include/stg/tariff_conf.h index ae40c128..fe94b6e5 100644 --- a/include/stg/tariff_conf.h +++ b/include/stg/tariff_conf.h @@ -98,18 +98,17 @@ struct DIRPRICE_DATA_RES DIRPRICE_DATA GetData() const { DIRPRICE_DATA dd; - dd.hDay = hDay.data(); - dd.hNight = hNight.data(); - dd.mDay = mDay.data(); - dd.mNight = mNight.data(); - dd.noDiscount = noDiscount.data(); - dd.priceDayA = priceDayA.data(); - dd.priceDayB = priceDayB.data(); - - dd.priceNightA = priceNightA.data(); - dd.priceNightB = priceNightB.data(); - dd.singlePrice = singlePrice.data(); - dd.threshold = threshold.data(); + hDay.maybeSet(dd.hDay); + hNight.maybeSet(dd.hNight); + mDay.maybeSet(dd.mDay); + mNight.maybeSet(dd.mNight); + noDiscount.maybeSet(dd.noDiscount); + priceDayA.maybeSet(dd.priceDayA); + priceDayB.maybeSet(dd.priceDayB); + priceNightA.maybeSet(dd.priceNightA); + priceNightB.maybeSet(dd.priceNightB); + singlePrice.maybeSet(dd.singlePrice); + threshold.maybeSet(dd.threshold); return dd; } @@ -194,12 +193,12 @@ struct TARIFF_CONF_RES TARIFF_CONF GetData() const { TARIFF_CONF tc; - tc.fee = fee.data(); - tc.free = free.data(); - tc.name = name.data(); - tc.passiveCost = passiveCost.data(); - tc.traffType = traffType.data(); - tc.period = period.data(); + fee.maybeSet(tc.fee); + free.maybeSet(tc.free); + name.maybeSet(tc.name); + passiveCost.maybeSet(tc.passiveCost); + traffType.maybeSet(tc.traffType); + period.maybeSet(tc.period); return tc; } diff --git a/include/stg/user_ips.h b/include/stg/user_ips.h index e55f99fa..52e5df77 100644 --- a/include/stg/user_ips.h +++ b/include/stg/user_ips.h @@ -166,7 +166,7 @@ return false; inline bool USER_IPS::OnlyOneIP() const { -if (ips.size() == 1 && ips.front().mask == 32) +if (ips.size() == 1 && ips.front().mask == 32 && ips.front().ip != 0) return true; return false; diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index b878b39c..34fc4bd0 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -377,6 +377,8 @@ while (running) WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++"); +manager.stop(); + if (loop.Stop()) WriteServLog("Event loop not stopped."); diff --git a/projects/stargazer/plugin_mgr.cpp b/projects/stargazer/plugin_mgr.cpp index eec1d656..10911b97 100644 --- a/projects/stargazer/plugin_mgr.cpp +++ b/projects/stargazer/plugin_mgr.cpp @@ -98,23 +98,7 @@ PluginManager::PluginManager(const SETTINGS_IMPL& settings, PluginManager::~PluginManager() { - std::sort(m_modules.begin(), m_modules.end(), StopModCmp); - for (size_t i = 0; i < m_modules.size(); ++i) - { - PLUGIN & plugin = m_modules[i]->GetPlugin(); - if (m_modules[i]->Stop()) - { - m_log("Failed to stop module '%s': '%s'", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); - printfd(__FILE__, "Failed to stop module '%s': '%s'\n", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); - } - else - { - m_log("Module '%s' stopped successfully.", plugin.GetVersion().c_str()); - printfd(__FILE__, "Module '%s' stopped successfully.\n", plugin.GetVersion().c_str()); - } - } + stop(); for (size_t i = 0; i < m_modules.size(); ++i) delete m_modules[i]; } @@ -140,3 +124,26 @@ void PluginManager::reload(const SETTINGS_IMPL& settings) } } } + +void PluginManager::stop() +{ + std::sort(m_modules.begin(), m_modules.end(), StopModCmp); + for (size_t i = 0; i < m_modules.size(); ++i) + { + if (!m_modules[i]->IsRunning()) + continue; + PLUGIN & plugin = m_modules[i]->GetPlugin(); + if (m_modules[i]->Stop()) + { + m_log("Failed to stop module '%s': '%s'", plugin.GetVersion().c_str(), + plugin.GetStrError().c_str()); + printfd(__FILE__, "Failed to stop module '%s': '%s'\n", plugin.GetVersion().c_str(), + plugin.GetStrError().c_str()); + } + else + { + m_log("Module '%s' stopped successfully.", plugin.GetVersion().c_str()); + printfd(__FILE__, "Module '%s' stopped successfully.\n", plugin.GetVersion().c_str()); + } + } +} diff --git a/projects/stargazer/plugin_mgr.h b/projects/stargazer/plugin_mgr.h index 0330f4e8..a37052d5 100644 --- a/projects/stargazer/plugin_mgr.h +++ b/projects/stargazer/plugin_mgr.h @@ -49,6 +49,7 @@ class PluginManager ~PluginManager(); void reload(const SETTINGS_IMPL& settings); + void stop(); private: std::vector m_modules; diff --git a/projects/stargazer/plugins/authorization/ao/ao.cpp b/projects/stargazer/plugins/authorization/ao/ao.cpp index 100e0557..5acea091 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.cpp +++ b/projects/stargazer/plugins/authorization/ao/ao.cpp @@ -70,15 +70,8 @@ return "Always Online authorizator v.1.0"; } //----------------------------------------------------------------------------- AUTH_AO::AUTH_AO() - : errorStr(), - users(NULL), - usersList(), + : users(NULL), isRunning(false), - settings(), - BeforeChgAONotifierList(), - AfterChgAONotifierList(), - BeforeChgIPNotifierList(), - AfterChgIPNotifierList(), onAddUserNotifier(*this), onDelUserNotifier(*this), logger(GetPluginLogger(GetStgLogger(), "auth_ao")) diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 4456c372..6b34618f 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -86,7 +86,7 @@ std::vector::const_iterator pvi; /////////////////////////// pv.param = "Port"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' not found."; printfd(__FILE__, "Parameter 'Port' not found\n"); @@ -102,7 +102,7 @@ port = static_cast(p); /////////////////////////// pv.param = "UserDelay"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'UserDelay\' not found."; printfd(__FILE__, "Parameter 'UserDelay' not found\n"); @@ -118,7 +118,7 @@ if (ParseIntInRange(pvi->value[0], 5, 600, &userDelay)) /////////////////////////// pv.param = "UserTimeout"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'UserTimeout\' not found."; printfd(__FILE__, "Parameter 'UserTimeout' not found\n"); @@ -134,7 +134,7 @@ if (ParseIntInRange(pvi->value[0], 15, 1200, &userTimeout)) /////////////////////////// pv.param = "LogProtocolErrors"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) logProtocolErrors = false; else if (ParseYesNo(pvi->value[0], &logProtocolErrors)) { @@ -147,7 +147,7 @@ std::string freeMbType; int n = 0; pv.param = "FreeMb"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'FreeMb\' not found."; printfd(__FILE__, "Parameter 'FreeMb' not found\n"); @@ -188,15 +188,13 @@ return 0; #ifdef IA_PHASE_DEBUG IA_PHASE::IA_PHASE() : phase(1), - phaseTime(), flog(NULL) { gettimeofday(&phaseTime, NULL); } #else IA_PHASE::IA_PHASE() - : phase(1), - phaseTime() + : phase(1) { gettimeofday(&phaseTime, NULL); } diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp index 8c4fdc2d..ce42d911 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp @@ -59,9 +59,6 @@ return cnc.GetPlugin(); NF_CAP::NF_CAP() : traffCnt(NULL), - settings(), - tidTCP(), - tidUDP(), runningTCP(false), runningUDP(false), stoppedTCP(true), @@ -70,7 +67,6 @@ NF_CAP::NF_CAP() portU(0), sockTCP(-1), sockUDP(-1), - errorStr(), logger(GetPluginLogger(GetStgLogger(), "cap_nf")) { } @@ -84,7 +80,7 @@ int NF_CAP::ParseSettings() std::vector::iterator it; for (it = settings.moduleParams.begin(); it != settings.moduleParams.end(); ++it) { - if (it->param == "TCPPort") + if (it->param == "TCPPort" && !it->value.empty()) { if (str2x(it->value[0], portT)) { @@ -94,7 +90,7 @@ for (it = settings.moduleParams.begin(); it != settings.moduleParams.end(); ++it } continue; } - if (it->param == "UDPPort") + if (it->param == "UDPPort" && !it->value.empty()) { if (str2x(it->value[0], portU)) { diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp index 400709bd..aebca059 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp @@ -84,11 +84,8 @@ return "cap_divert v.1.0"; } //----------------------------------------------------------------------------- DIVERT_CAP::DIVERT_CAP() - : settings(), - port(0), + : port(0), disableForwarding(false), - errorStr(), - thread(), nonstop(false), isRunning(false), traffCnt(NULL), @@ -290,7 +287,7 @@ std::vector::const_iterator pvi; pv.param = "Port"; pvi = std::find(settings.moduleParams.begin(), settings.moduleParams.end(), pv); -if (pvi == settings.moduleParams.end()) +if (pvi == settings.moduleParams.end() || pvi->value.empty()) { p = 15701; } @@ -306,7 +303,7 @@ port = p; bool d = false; pv.param = "DisableForwarding"; pvi = std::find(settings.moduleParams.begin(), settings.moduleParams.end(), pv); -if (pvi == settings.moduleParams.end()) +if (pvi == settings.moduleParams.end() || pvi->value.empty()) { disableForwarding = false; } diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp index 254fd3f9..36159fed 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp @@ -121,15 +121,9 @@ return "cap_bpf v.1.0"; } //----------------------------------------------------------------------------- BPF_CAP::BPF_CAP() - : capSettings(), - errorStr(), - bpfData(), - polld(), - thread(), - nonstop(false), + : nonstop(false), isRunning(false), capSock(-1), - settings(), traffCnt(NULL), logger(GetPluginLogger(GetStgLogger(), "cap_bpf")) { diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp index fd83c485..cc64bc18 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp @@ -78,9 +78,7 @@ return "cap_ether v.1.2"; } //----------------------------------------------------------------------------- ETHER_CAP::ETHER_CAP() - : errorStr(), - thread(), - nonstop(false), + : nonstop(false), isRunning(false), capSock(-1), traffCnt(NULL), diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp index 45ca9b1f..18696ec2 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp @@ -63,13 +63,10 @@ return "cap_ipq v.1.2"; //----------------------------------------------------------------------------- IPQ_CAP::IPQ_CAP() : ipq_h(NULL), - errorStr(), - thread(), nonstop(false), isRunning(false), capSock(-1), traffCnt(NULL), - buf(), logger(GetPluginLogger(GetStgLogger(), "cap_ipq")) { memset(buf, 0, BUFSIZE); diff --git a/projects/stargazer/plugins/capture/nfqueue/nfqueue.cpp b/projects/stargazer/plugins/capture/nfqueue/nfqueue.cpp index 68f7270c..0c14c10f 100644 --- a/projects/stargazer/plugins/capture/nfqueue/nfqueue.cpp +++ b/projects/stargazer/plugins/capture/nfqueue/nfqueue.cpp @@ -93,9 +93,7 @@ return "cap_nfqueue v.1.0"; } //----------------------------------------------------------------------------- NFQ_CAP::NFQ_CAP() - : errorStr(), - thread(), - nonstop(false), + : nonstop(false), isRunning(false), queueNumber(0), nfqHandle(NULL), @@ -108,8 +106,8 @@ NFQ_CAP::NFQ_CAP() int NFQ_CAP::ParseSettings() { for (size_t i = 0; i < settings.moduleParams.size(); i++) - if (settings.moduleParams[i].param == "queueNumber") - if (str2x(settings.moduleParams[i].param, queueNumber) < 0) + if (settings.moduleParams[i].param == "queueNumber" && !settings.moduleParams[i].value.empty()) + if (str2x(settings.moduleParams[i].value[0], queueNumber) < 0) { errorStr = "Queue number should be a number. Got: '" + settings.moduleParams[i].param + "'"; logger(errorStr); diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp index dca87fbe..3b28ddd8 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp @@ -33,8 +33,7 @@ PLUGIN_CREATOR rpcc; extern "C" PLUGIN * GetPlugin(); RPC_CONFIG_SETTINGS::RPC_CONFIG_SETTINGS() - : errorStr(), - port(0), + : port(0), cookieTimeout(0) { } @@ -45,7 +44,7 @@ PARAM_VALUE pv; pv.param = "Port"; std::vector::const_iterator pvi; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' not found."; printfd(__FILE__, "Parameter 'Port' not found\n"); @@ -62,7 +61,7 @@ port = static_cast(p); pv.param = "CookieTimeout"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { cookieTimeout = 1800; // 30 * 60 } @@ -85,22 +84,15 @@ return rpcc.GetPlugin(); } RPC_CONFIG::RPC_CONFIG() - : errorStr(), - rpcConfigSettings(), - users(NULL), + : users(NULL), admins(NULL), tariffs(NULL), store(NULL), - settings(), fd(-1), - rpcRegistry(), rpcServer(NULL), running(false), stopped(true), - tid(), - cookies(), dayFee(0), - dirNames(), logger(GetPluginLogger(GetStgLogger(), "conf_rpc")) { } diff --git a/projects/stargazer/plugins/configuration/sgconfig/conn.cpp b/projects/stargazer/plugins/configuration/sgconfig/conn.cpp index 8bba49be..c792125e 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/conn.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/conn.cpp @@ -60,7 +60,12 @@ Conn::Conn(const BASE_PARSER::REGISTRY & registry, m_bufferSize(sizeof(m_header)), m_stream(NULL), m_logger(logger), +#ifdef DUMPCRYPTO + m_dataState(false, *this), + m_dumper(endpoint()) +#else m_dataState(false, *this) +#endif { if (m_xmlParser == NULL) throw Error("Failed to create XML parser."); @@ -84,16 +89,20 @@ bool Conn::Read() if (res < 0) { m_state = ERROR; - Log(__FILE__, "Failed to read data from " + inet_ntostring(IP()) + ":" + x2str(Port()) + ". Reason: '" + strerror(errno) + "'"); + Log(__FILE__, "Failed to read data from " + endpoint() + ". Reason: '" + strerror(errno) + "'"); return false; } if (res == 0 && m_state != DATA) // EOF is ok for data. { m_state = ERROR; - Log(__FILE__, "Failed to read data from " + inet_ntostring(IP()) + ":" + x2str(Port()) + ". Unexpected EOF."); + Log(__FILE__, "Failed to read data from " + endpoint() + ". Unexpected EOF."); return false; } +#ifdef DUMPCRYPTO + m_dumper.write(m_buffer, res); +#endif m_bufferSize -= res; + m_buffer = static_cast(m_buffer) + res; return HandleBuffer(res); } @@ -103,7 +112,7 @@ bool Conn::WriteAnswer(const void* buffer, size_t size) if (res < 0) { m_state = ERROR; - Log(__FILE__, "Failed to write data to " + inet_ntostring(IP()) + ":" + x2str(Port()) + ". Reason: '" + strerror(errno) + "'."); + Log(__FILE__, "Failed to write data to " + endpoint() + ". Reason: '" + strerror(errno) + "'."); return false; } return true; @@ -140,7 +149,7 @@ bool Conn::HandleHeader() { if (strncmp(m_header, STG_HEADER, sizeof(m_header)) != 0) { - Log(__FILE__, "Received invalid header from " + inet_ntostring(IP()) + ":" + x2str(Port()) + "."); + Log(__FILE__, "Received invalid header from " + endpoint() + "."); WriteAnswer(ERR_HEADER, sizeof(ERR_HEADER) - 1); // Without \0 m_state = ERROR; return false; @@ -156,7 +165,7 @@ bool Conn::HandleLogin() if (m_admins.Find(m_login, &m_admin)) // ADMINS::Find returns true on error. { std::string login(m_login, strnlen(m_login, sizeof(m_login))); - Log(__FILE__, "Received invalid login '" + ToPrintable(login) + "' from " + inet_ntostring(IP()) + ":" + x2str(Port()) + "."); + Log(__FILE__, "Received invalid login '" + ToPrintable(login) + "' from " + endpoint() + "."); WriteAnswer(ERR_LOGIN, sizeof(ERR_LOGIN) - 1); // Without \0 m_state = ERROR; return false; @@ -177,7 +186,7 @@ bool Conn::HandleCryptoLogin() if (strncmp(m_login, login, sizeof(login)) != 0) { - Log(__FILE__, "Attempt to connect with wrong password from " + m_admin->GetLogin() + "@" + inet_ntostring(IP()) + ":" + x2str(Port()) + "."); + Log(__FILE__, "Attempt to connect with wrong password from " + m_admin->GetLogin() + "@" + endpoint() + "."); WriteAnswer(ERR_LOGINS, sizeof(ERR_LOGINS) - 1); // Without \0 m_state = ERROR; return false; @@ -192,7 +201,8 @@ bool Conn::HandleCryptoLogin() bool Conn::HandleData(size_t size) { - m_stream->Put(m_buffer, size, size == 0 || memchr(m_buffer, 0, size) != NULL); + m_stream->Put(m_data, size, size == 0 || memchr(m_data, 0, size) != NULL); + m_buffer = m_data; return m_stream->IsOk(); } @@ -208,7 +218,7 @@ bool Conn::DataCallback(const void * block, size_t size, void * data) if (XML_Parse(state.conn.m_xmlParser, xml, length, state.final) == XML_STATUS_ERROR) { - state.conn.Log(__FILE__, "Received invalid XML from " + state.conn.m_admin->GetLogin() + "@" + inet_ntostring(state.conn.IP()) + ":" + x2str(state.conn.Port()) + "."); + state.conn.Log(__FILE__, "Received invalid XML from " + state.conn.m_admin->GetLogin() + "@" + state.conn.endpoint() + "."); printfd(__FILE__, "XML parse error at line %d, %d: %s. Is final: %d\n", static_cast(XML_GetCurrentLineNumber(state.conn.m_xmlParser)), static_cast(XML_GetCurrentColumnNumber(state.conn.m_xmlParser)), @@ -222,7 +232,7 @@ bool Conn::DataCallback(const void * block, size_t size, void * data) { if (!state.conn.WriteResponse()) { - state.conn.Log(__FILE__, "Failed to write response to " + state.conn.m_admin->GetLogin() + "@" + inet_ntostring(state.conn.IP()) + ":" + x2str(state.conn.Port()) + "."); + state.conn.Log(__FILE__, "Failed to write response to " + state.conn.m_admin->GetLogin() + "@" + state.conn.endpoint() + "."); state.conn.m_state = ERROR; return false; } @@ -242,7 +252,7 @@ void Conn::ParseXMLStart(void * data, const char * el, const char ** attr) if (conn.m_parser == NULL) { - conn.Log(__FILE__, "Received unknown command '" + std::string(el) + "' from " + conn.m_admin->GetLogin() + "@" + inet_ntostring(conn.IP()) + ":" + x2str(conn.Port()) + "."); + conn.Log(__FILE__, "Received unknown command '" + std::string(el) + "' from " + conn.m_admin->GetLogin() + "@" + conn.endpoint() + "."); conn.m_state = ERROR; return; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/conn.h b/projects/stargazer/plugins/configuration/sgconfig/conn.h index fae0c4b2..c67c972e 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/conn.h +++ b/projects/stargazer/plugins/configuration/sgconfig/conn.h @@ -23,6 +23,8 @@ #include "parser.h" +#include "dumphelpers.h" + #include "stg/os_int.h" #include "stg/const.h" @@ -63,6 +65,8 @@ class Conn uint32_t IP() const { return *(uint32_t *)(&m_addr.sin_addr); } uint16_t Port() const { return ntohs(m_addr.sin_port); } + std::string endpoint() const { return inet_ntostring(IP()) + ":" + x2str(Port()); } + bool Read(); bool IsOk() const { return m_state != ERROR; } @@ -127,6 +131,10 @@ class Conn Conn & conn; } m_dataState; +#ifdef DUMPCRYPTO + Dumper m_dumper; +#endif + static bool DataCallback(const void * block, size_t size, void * data); static void ParseXMLStart(void * data, const char * el, const char ** attr); static void ParseXMLEnd(void * data, const char * el); diff --git a/projects/stargazer/plugins/configuration/sgconfig/dumphelpers.h b/projects/stargazer/plugins/configuration/sgconfig/dumphelpers.h new file mode 100644 index 00000000..cc02d14d --- /dev/null +++ b/projects/stargazer/plugins/configuration/sgconfig/dumphelpers.h @@ -0,0 +1,85 @@ +#ifndef __STG_DUMP_HELPERS_H__ +#define __STG_DUMP_HELPERS_H__ + +#include "stg/common.h" + +#include +#include +#include +#include + +#include +#include + +namespace STG +{ + +class Dumper +{ + public: + explicit Dumper(const std::string& tag) + : m_stream(getName(tag).c_str()) + { + } + ~Dumper() {} + + void write(const void* data, size_t size) + { + writePrefix(); + m_stream << " "; + writeHEX(data, size); + } + + private: + std::ofstream m_stream; + + tm getTime() const + { + time_t now = time(NULL); + tm localTime; + localtime_r(&now, &localTime); + return localTime; + } + + std::string getName(const std::string& tag) const + { + tm localTime = getTime(); + + std::ostringstream res; + res << tag + << "-" << (localTime.tm_year + 1900) << twoDigit(localTime.tm_mon + 1) << twoDigit(localTime.tm_mday) + << "-" << twoDigit(localTime.tm_hour) << twoDigit(localTime.tm_min) << twoDigit(localTime.tm_sec) + << ".data"; + + return res.str(); + } + + void writePrefix() + { + tm localTime = getTime(); + m_stream << "[" << (localTime.tm_year + 1900) << "-" << twoDigit(localTime.tm_mon + 1) << "-" << twoDigit(localTime.tm_mday) + << " " << twoDigit(localTime.tm_hour) << ":" << twoDigit(localTime.tm_min) << ":" << twoDigit(localTime.tm_sec) + << "]"; + } + + void writeHEX(const void* data, size_t size) + { + m_stream << "(" << std::setw(4) << std::setfill(' ') << size << ") "; + const unsigned char* pos = static_cast(data); + for (size_t i = 0; i < size; ++i) + m_stream << std::hex << std::setw(2) << std::setfill('0') << static_cast(*pos++); + m_stream << std::dec << "\n"; + } + + std::string twoDigit(int value) const + { + std::string res = x2str(value); + if (res.length() < 2) + res = "0" + res; + return res; + } +}; + +} // namespace Caster + +#endif diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp index 1873b9bb..75be7537 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp @@ -46,7 +46,7 @@ void GET_SERVER_INFO::CreateAnswer() utsn.machine + " " + utsn.nodename; - m_answer = GetOpenTag() + "" + + m_answer = std::string("" + "" + "" + "" + @@ -57,5 +57,5 @@ void GET_SERVER_INFO::CreateAnswer() for (size_t i = 0; i< DIR_NUM; i++) m_answer += ""; - m_answer += GetCloseTag(); + m_answer += ""; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp index cc32b6fc..0607db6f 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp @@ -56,6 +56,16 @@ std::string AOS2String(const A & array, size_t size, const F C::* field, F multi return res; } +template +bool str2res(const std::string& source, RESETABLE& dest, T divisor) +{ + T value = 0; + if (str2x(source, value)) + return false; + dest = value / divisor; + return true; +} + template bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE C::* field, F divisor) { @@ -64,15 +74,13 @@ bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE std::string::size_type pos = 0; while (index < size && (pos = source.find('/', from)) != std::string::npos) { - if (str2x(source.substr(from, pos - from), (array[index].*field).data())) + if (!str2res(source.substr(from, pos - from), array[index].*field, divisor)) return false; - (array[index].*field).data() /= divisor; from = pos + 1; ++index; } - if (str2x(source.substr(from), (array[index].*field).data())) + if (str2res(source.substr(from), array[index].*field, divisor)) return false; - (array[index].*field).data() /= divisor; return true; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp index c54ae8eb..2e9d7087 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp @@ -52,9 +52,9 @@ std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_ std::string answer; if (loginInStart) - answer += ""; + answer += ""; else - answer += ""; + answer += ""; answer += ""; diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp index ca2dd440..73f58145 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp @@ -42,7 +42,7 @@ bool STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s) /////////////////////////// pv.param = "Port"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' is not found."; printfd(__FILE__, "%s\n", errorStr.c_str()); @@ -59,7 +59,7 @@ bool STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s) pv.param = "BindAddress"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi != s.moduleParams.end()) + if (pvi != s.moduleParams.end() && !pvi->value.empty()) m_bindAddress = pvi->value[0]; return true; diff --git a/projects/stargazer/plugins/other/ping/ping.cpp b/projects/stargazer/plugins/other/ping/ping.cpp index c65a5cba..bec692fa 100644 --- a/projects/stargazer/plugins/other/ping/ping.cpp +++ b/projects/stargazer/plugins/other/ping/ping.cpp @@ -50,7 +50,7 @@ std::vector::const_iterator pvi; pv.param = "PingDelay"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'PingDelay\' not found."; printfd(__FILE__, "Parameter 'PingDelay' not found\n"); @@ -67,18 +67,9 @@ return 0; } //----------------------------------------------------------------------------- PING::PING() - : errorStr(), - pingSettings(), - settings(), - users(NULL), - usersList(), - thread(), - mutex(), + : users(NULL), nonstop(false), isRunning(false), - pinger(), - ChgCurrIPNotifierList(), - ChgIPNotifierList(), onAddUserNotifier(*this), onDelUserNotifier(*this), logger(GetPluginLogger(GetStgLogger(), "ping")) diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index 27c419b8..74bf87a1 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -73,12 +73,7 @@ return rsc.GetPlugin(); //----------------------------------------------------------------------------- RS::SETTINGS::SETTINGS() : sendPeriod(0), - port(0), - errorStr(), - netRouters(), - userParams(), - password(), - subnetFile() + port(0) { } //----------------------------------------------------------------------------- @@ -91,7 +86,7 @@ netRouters.clear(); /////////////////////////// pv.param = "Port"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' not found."; printfd(__FILE__, "Parameter 'Port' not found\n"); @@ -107,7 +102,7 @@ port = static_cast(p); /////////////////////////// pv.param = "SendPeriod"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'SendPeriod\' not found."; printfd(__FILE__, "Parameter 'SendPeriod' not found\n"); @@ -123,7 +118,7 @@ if (ParseIntInRange(pvi->value[0], 5, 600, &sendPeriod)) /////////////////////////// pv.param = "UserParams"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'UserParams\' not found."; printfd(__FILE__, "Parameter 'UserParams' not found\n"); @@ -133,7 +128,7 @@ userParams = pvi->value; /////////////////////////// pv.param = "Password"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Password\' not found."; printfd(__FILE__, "Parameter 'Password' not found\n"); @@ -143,7 +138,7 @@ password = pvi->value[0]; /////////////////////////// pv.param = "SubnetFile"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'SubnetFile\' not found."; printfd(__FILE__, "Parameter 'SubnetFile' not found\n"); diff --git a/projects/stargazer/plugins/other/smux/smux.cpp b/projects/stargazer/plugins/other/smux/smux.cpp index d1af2dbc..5a20d495 100644 --- a/projects/stargazer/plugins/other/smux/smux.cpp +++ b/projects/stargazer/plugins/other/smux/smux.cpp @@ -24,9 +24,6 @@ namespace { PLUGIN_CREATOR smc; -bool SPrefixLess(const Sensors::value_type & a, - const Sensors::value_type & b); - bool SPrefixLess(const Sensors::value_type & a, const Sensors::value_type & b) { @@ -57,7 +54,7 @@ int p; pv.param = "Port"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' not found."; printfd(__FILE__, "Parameter 'Port' not found\n"); @@ -73,7 +70,7 @@ port = static_cast(p); pv.param = "Password"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Password\' not found."; printfd(__FILE__, "Parameter 'Password' not found\n"); @@ -86,7 +83,7 @@ else pv.param = "Server"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Server\' not found."; printfd(__FILE__, "Parameter 'Server' not found\n"); diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index a8b3990f..2a7eb6c1 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -80,11 +80,6 @@ return fsc.GetPlugin(); //----------------------------------------------------------------------------- FILES_STORE_SETTINGS::FILES_STORE_SETTINGS() : settings(NULL), - errorStr(), - workDir(), - usersDir(), - adminsDir(), - tariffsDir(), statMode(0), statUID(0), statGID(0), @@ -105,7 +100,7 @@ PARAM_VALUE pv; pv.param = owner; std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); -if (pvi == moduleParams.end()) +if (pvi == moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'" + owner + "\' not found."; printfd(__FILE__, "%s\n", errorStr.c_str()); @@ -126,7 +121,7 @@ PARAM_VALUE pv; pv.param = group; std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); -if (pvi == moduleParams.end()) +if (pvi == moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'" + group + "\' not found."; printfd(__FILE__, "%s\n", errorStr.c_str()); @@ -164,7 +159,7 @@ PARAM_VALUE pv; pv.param = modeStr; std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); -if (pvi == moduleParams.end()) +if (pvi == moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'" + modeStr + "\' not found."; printfd(__FILE__, "%s\n", errorStr.c_str()); @@ -206,7 +201,7 @@ std::vector::const_iterator pvi; PARAM_VALUE pv; pv.param = "RemoveBak"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { removeBak = true; } @@ -221,7 +216,7 @@ else pv.param = "ReadBak"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { readBak = false; } @@ -236,7 +231,7 @@ else pv.param = "WorkDir"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'WorkDir\' not found."; printfd(__FILE__, "Parameter 'WorkDir' not found\n"); diff --git a/projects/stargazer/plugins/store/firebird/firebird_store.cpp b/projects/stargazer/plugins/store/firebird/firebird_store.cpp index 81160114..f9a2f78e 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store.cpp @@ -50,14 +50,10 @@ return frsc.GetPlugin(); //----------------------------------------------------------------------------- FIREBIRD_STORE::FIREBIRD_STORE() : version("firebird_store v.1.4"), - strError(), db_server("localhost"), db_database("/var/stg/stargazer.fdb"), db_user("stg"), db_password("123456"), - settings(), - db(), - mutex(), til(IBPP::ilConcurrency), tlr(IBPP::lrWait), schemaVersion(0), @@ -78,39 +74,41 @@ std::string s; for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i) { + if (i->value.empty()) + continue; s = ToLower(i->param); if (s == "server") - db_server = *(i->value.begin()); + db_server = i->value.front(); if (s == "database") - db_database = *(i->value.begin()); + db_database = i->value.front(); if (s == "user") - db_user = *(i->value.begin()); + db_user = i->value.front(); if (s == "password") - db_password = *(i->value.begin()); + db_password = i->value.front(); // Advanced settings block if (s == "isolationLevel") { - if (*(i->value.begin()) == "Concurrency") + if (i->value.front() == "Concurrency") til = IBPP::ilConcurrency; - else if (*(i->value.begin()) == "DirtyRead") + else if (i->value.front() == "DirtyRead") til = IBPP::ilReadDirty; - else if (*(i->value.begin()) == "ReadCommitted") + else if (i->value.front() == "ReadCommitted") til = IBPP::ilReadCommitted; - else if (*(i->value.begin()) == "Consistency") + else if (i->value.front() == "Consistency") til = IBPP::ilConsistency; } if (s == "lockResolution") { - if (*(i->value.begin()) == "Wait") + if (i->value.front() == "Wait") tlr = IBPP::lrWait; - else if (*(i->value.begin()) == "NoWait") + else if (i->value.front() == "NoWait") tlr = IBPP::lrNoWait; } } diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp index f7aef966..a7b719ed 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp @@ -31,6 +31,13 @@ #include "firebird_store.h" #include "stg/ibpp.h" +namespace +{ + +const int pt_mega = 1024 * 1024; + +} + //----------------------------------------------------------------------------- int FIREBIRD_STORE::GetTariffsList(std::vector * tariffsList) const { @@ -305,8 +312,8 @@ try st->Get(7, td->dirPrice[dir].priceNightB); td->dirPrice[dir].priceNightB /= 1024*1024; st->Get(8, td->dirPrice[dir].threshold); - if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) < 1.0e-3 && - std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) < 1.0e-3) + if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) < 1.0e-3 / pt_mega && + std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) < 1.0e-3 / pt_mega) { td->dirPrice[dir].singlePrice = true; } diff --git a/projects/stargazer/plugins/store/mysql/mysql_store.cpp b/projects/stargazer/plugins/store/mysql/mysql_store.cpp index 1e4c235d..6b16a99d 100644 --- a/projects/stargazer/plugins/store/mysql/mysql_store.cpp +++ b/projects/stargazer/plugins/store/mysql/mysql_store.cpp @@ -111,28 +111,23 @@ return msc.GetPlugin(); } //----------------------------------------------------------------------------- MYSQL_STORE_SETTINGS::MYSQL_STORE_SETTINGS() - : settings(NULL), - errorStr(), - dbUser(), - dbPass(), - dbName(), - dbHost() + : settings(NULL) { } //----------------------------------------------------------------------------- -int MYSQL_STORE_SETTINGS::ParseParam(const std::vector & moduleParams, - const std::string & name, std::string & result) +int MYSQL_STORE_SETTINGS::ParseParam(const std::vector & moduleParams, + const std::string & name, std::string & result) { PARAM_VALUE pv; pv.param = name; std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); -if (pvi == moduleParams.end()) +if (pvi == moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'" + name + "\' not found."; return -1; } - + result = pvi->value[0]; return 0; @@ -159,10 +154,7 @@ return 0; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- MYSQL_STORE::MYSQL_STORE() - : errorStr(), - version("mysql_store v.0.67"), - storeSettings(), - settings(), + : version("mysql_store v.0.67"), schemaVersion(0), logger(GetPluginLogger(GetStgLogger(), "store_mysql")) { diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp index 80431c0d..35551c5d 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp @@ -64,14 +64,11 @@ return pgsc.GetPlugin(); //----------------------------------------------------------------------------- POSTGRESQL_STORE::POSTGRESQL_STORE() : versionString("postgresql_store v.1.3"), - strError(), server("localhost"), database("stargazer"), user("stg"), password("123456"), clientEncoding("KOI8"), - settings(), - mutex(), version(0), retries(3), connection(NULL), @@ -96,26 +93,28 @@ std::string s; for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i) { + if (i->value.empty()) + continue; s = ToLower(i->param); if (s == "server") { - server = *(i->value.begin()); + server = i->value.front(); } if (s == "database") { - database = *(i->value.begin()); + database = i->value.front(); } if (s == "user") { - user = *(i->value.begin()); + user = i->value.front(); } if (s == "password") { - password = *(i->value.begin()); + password = i->value.front(); } if (s == "retries") { - if (str2x(*(i->value.begin()), retries)) + if (str2x(i->value.front(), retries)) { strError = "Invalid 'retries' value"; printfd(__FILE__, "POSTGRESQL_STORE::ParseSettings(): '%s'\n", strError.c_str()); diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp index dabc06db..045411b1 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp @@ -36,6 +36,13 @@ #include "postgresql_store.h" #include "stg/locker.h" +namespace +{ + +const int pt_mega = 1024 * 1024; + +} + //----------------------------------------------------------------------------- int POSTGRESQL_STORE::GetTariffsList(std::vector * tariffsList) const { @@ -568,8 +575,8 @@ for (int i = 0; i < std::min(tuples, DIR_NUM); ++i) tuple >> td->dirPrice[dir].mNight; } - if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) > 1.0e-3 && - std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) > 1.0e-3) + if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) < 1.0e-3 / pt_mega && + std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) < 1.0e-3 / pt_mega) { td->dirPrice[dir].singlePrice = true; } diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 36930576..5d505307 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -557,6 +557,8 @@ if (authorizedBy.empty()) lastDisconnectReason = reason; lastIPForDisconnect = currIP; currIP = 0; // DelUser in traffcounter + if (connected) + Disconnect(false, "not authorized"); return; } } diff --git a/projects/stargazer/users_impl.cpp b/projects/stargazer/users_impl.cpp index 97873aeb..18d1abaf 100644 --- a/projects/stargazer/users_impl.cpp +++ b/projects/stargazer/users_impl.cpp @@ -319,6 +319,7 @@ STG_LOCKER lock(&mutex); if (FindByNameNonLock(login, &iter)) { WriteServLog("Attempt to unauthorize non-existant user '%s'", login.c_str()); + printfd(__FILE__, "Attempt to unauthorize non-existant user '%s'", login.c_str()); return false; } @@ -424,15 +425,7 @@ while (us->nonstop) stgUsleep(100000); } //while (us->nonstop) -user_iter ui = us->users.begin(); -while (ui != us->users.end()) - { - us->DelUserFromIndexes(ui); - ++ui; - } - -std::list::iterator iter; -iter = us->usersToDelete.begin(); +std::list::iterator iter(us->usersToDelete.begin()); while (iter != us->usersToDelete.end()) { iter->delTime -= 2 * userDeleteDelayTime; diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index 22ec354b..8b62e68b 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -752,6 +752,11 @@ if (errno == ERANGE) return 0; } +//--------------------------------------------------------------------------- +int str2x(const std::string & str, double & x) +{ +return strtodouble2(str.c_str(), x); +} #ifndef WIN32 //--------------------------------------------------------------------------- int str2x(const std::string & str, int64_t & x) diff --git a/stglibs/common.lib/include/stg/common.h b/stglibs/common.lib/include/stg/common.h index f46c922a..af0f89a1 100644 --- a/stglibs/common.lib/include/stg/common.h +++ b/stglibs/common.lib/include/stg/common.h @@ -152,6 +152,7 @@ std::string ToPrintable(const std::string & src); //----------------------------------------------------------------------------- int str2x(const std::string & str, int32_t & x); int str2x(const std::string & str, uint32_t & x); +int str2x(const std::string & str, double & x); #ifndef WIN32 int str2x(const std::string & str, int64_t & x); int str2x(const std::string & str, uint64_t & x); diff --git a/stglibs/dotconfpp.lib/dotconfpp.cpp b/stglibs/dotconfpp.lib/dotconfpp.cpp index caf5a590..8f766f01 100644 --- a/stglibs/dotconfpp.lib/dotconfpp.cpp +++ b/stglibs/dotconfpp.lib/dotconfpp.cpp @@ -336,7 +336,7 @@ int DOTCONFDocument::setContent(const char * _fileName) char realpathBuf[PATH_MAX]; if(realpath(_fileName, realpathBuf) == NULL){ - error(0, _fileName, "realpath('%s') failed: %s", _fileName, strerror(errno)); + error(0, _fileName, "%s", strerror(errno)); return -1; } @@ -514,9 +514,9 @@ void DOTCONFDocument::error(int lineNum, const char * fileName, const char * fmt char * buf = (char*)mempool->alloc(len); if(lineNum) - (void) snprintf(buf, len, "DOTCONF++: file '%s', line %d: %s\n", fileName, lineNum, msg); + (void) snprintf(buf, len, "File '%s', line %d: %s\n", fileName, lineNum, msg); else - (void) snprintf(buf, len, "DOTCONF++: file '%s': %s\n", fileName, msg); + (void) snprintf(buf, len, "File '%s': %s\n", fileName, msg); if (errorCallback) { errorCallback(errorCallbackData, buf); diff --git a/tests/test_crypto.cpp b/tests/test_crypto.cpp index f95ecdb0..8db8ab72 100644 --- a/tests/test_crypto.cpp +++ b/tests/test_crypto.cpp @@ -431,4 +431,40 @@ namespace tut ensure_equals("DecryptString(EncryptString(longTest)) == longTest", source, std::string(longTest)); } + template<> + template<> + void testobject::test<8>() + { + set_test_name("Check old string encryption"); + + BLOWFISH_CTX ctx; + InitContext("123456", 7, &ctx); + const unsigned char source[] = {0xe9, 0xfe, 0xcb, 0xc5, 0xad, 0x3e, 0x87, 0x39, + 0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb, + 0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb, + 0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb}; + char res[32]; + DecryptString(res, source, 32, &ctx); + + ensure_equals("DecryptString(...) == 'admin'", std::string(res), "admin"); + } + + template<> + template<> + void testobject::test<9>() + { + set_test_name("Check new string encryption"); + + BLOWFISH_CTX ctx; + InitContext("123456", 7, &ctx); + const unsigned char source[] = {0xe9, 0xfe, 0xcb, 0xc5, 0xad, 0x3e, 0x87, 0x39, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + char res[32]; + DecryptString(res, source, 32, &ctx); + + ensure_equals("DecryptString(...) == 'admin'", std::string(res), "admin"); + } + }