From: Maxim Mamontov Date: Sat, 17 Sep 2016 12:59:24 +0000 (+0300) Subject: Merge branch 'stg-2.409' into stg-2.409-radius X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/cf99afd4c25f733f4fe72ef780e4cd70ee25e459?hp=-c Merge branch 'stg-2.409' into stg-2.409-radius --- cf99afd4c25f733f4fe72ef780e4cd70ee25e459 diff --combined projects/stargazer/settings_impl.cpp index f7994149,0cf9501b..c925177f --- a/projects/stargazer/settings_impl.cpp +++ b/projects/stargazer/settings_impl.cpp @@@ -14,80 -14,27 +14,80 @@@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* - * Date: 27.10.2002 - */ - /* * Author : Boris Mikhailenko */ -/* -$Revision: 1.45 $ -$Date: 2010/08/19 13:42:30 $ -$Author: faust $ -*/ +#include "settings_impl.h" +#include "stg/logger.h" +#include "stg/dotconfpp.h" +#include "stg/common.h" + +#include #include #include -#include -#include "stg/logger.h" -#include "stg/dotconfpp.h" -#include "settings_impl.h" +namespace +{ + +struct Error : public std::runtime_error +{ + Error(const std::string& message) : runtime_error(message) {} +}; + +std::vector toValues(const DOTCONFDocumentNode& node) +{ + std::vector values; + + size_t i = 0; + const char* value = NULL; + while ((value = node.getValue(i++)) != NULL) + values.push_back(value); + + return values; +} + +std::vector toPVS(const DOTCONFDocumentNode& node) +{ + std::vector pvs; + + const DOTCONFDocumentNode* child = node.getChildNode(); + while (child != NULL) + { + if (child->getName() == NULL) + continue; + + if (child->getChildNode() == NULL) + pvs.push_back(PARAM_VALUE(child->getName(), toValues(*child))); + else + pvs.push_back(PARAM_VALUE(child->getName(), toValues(*child), toPVS(*child))); + + child = child->getNextNode(); + } + + return pvs; +} + +unsigned toPeriod(const char* value) +{ + if (value == NULL) + throw Error("No detail stat period value."); + + std::string period(value); + if (period == "1") + return dsPeriod_1; + else if (period == "1/2") + return dsPeriod_1_2; + else if (period == "1/4") + return dsPeriod_1_4; + else if (period == "1/6") + return dsPeriod_1_6; + + throw Error("Invalid detail stat period value: '" + period + "'. Should be one of '1', '1/2', '1/4' or '1/6'."); +} + +} //----------------------------------------------------------------------------- SETTINGS_IMPL::SETTINGS_IMPL(const std::string & cd) @@@ -115,8 -62,10 +115,10 @@@ messageTimeout(0), feeChargeType(0), reconnectOnTariffChange(false), + disableSessionLog(false), logger(GetStgLogger()) { + filterParamsLog.push_back("*"); } //----------------------------------------------------------------------------- SETTINGS_IMPL::SETTINGS_IMPL(const SETTINGS_IMPL & rval) @@@ -146,6 -95,8 +148,8 @@@ messageTimeout(rval.messageTimeout), feeChargeType(rval.feeChargeType), reconnectOnTariffChange(rval.reconnectOnTariffChange), + disableSessionLog(rval.disableSessionLog), + filterParamsLog(rval.filterParamsLog), modulesSettings(rval.modulesSettings), storeModuleSettings(rval.storeModuleSettings), logger(GetStgLogger()) @@@ -179,12 -130,53 +183,14 @@@ SETTINGS_IMPL & SETTINGS_IMPL::operator messageTimeout = rhs.messageTimeout; feeChargeType = rhs.feeChargeType; reconnectOnTariffChange = rhs.reconnectOnTariffChange; + disableSessionLog = rhs.disableSessionLog; + filterParamsLog = rhs.filterParamsLog; modulesSettings = rhs.modulesSettings; storeModuleSettings = rhs.storeModuleSettings; return *this; } //----------------------------------------------------------------------------- -int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector * params) -{ -const DOTCONFDocumentNode * childNode; -PARAM_VALUE pv; -const char * value; - -pv.param = node->getName(); - -if (node->getValue(1)) - { - strError = "Unexpected value \'" + std::string(node->getValue(1)) + "\'."; - return -1; - } - -value = node->getValue(0); - -if (!value) - { - strError = "Module name expected."; - return -1; - } - -childNode = node->getChildNode(); -while (childNode) - { - pv.param = childNode->getName(); - int i = 0; - while ((value = childNode->getValue(i++)) != NULL) - { - pv.value.push_back(value); - } - params->push_back(pv); - pv.value.clear(); - childNode = childNode->getNextNode(); - } - -return 0; -} -//----------------------------------------------------------------------------- void SETTINGS_IMPL::ErrorCallback(void * data, const char * buf) { printfd(__FILE__, "SETTINGS_IMPL::ErrorCallback() - %s\n", buf); @@@ -254,15 -246,11 +260,15 @@@ while (node if (strcasecmp(node->getName(), "DetailStatWritePeriod") == 0) { - if (ParseDetailStatWritePeriod(node->getValue(0)) != 0) - { - strError = "Incorrect DetailStatWritePeriod value: \'" + std::string(node->getValue(0)) + "\'"; + try + { + detailStatWritePeriod = toPeriod(node->getValue(0)); + } + catch (const Error& error) + { + strError = error.what(); return -1; - } + } } if (strcasecmp(node->getName(), "StatWritePeriod") == 0) @@@ -403,6 -391,22 +409,22 @@@ } } + if (strcasecmp(node->getName(), "DisableSessionLog") == 0) + { + if (ParseYesNo(node->getValue(0), &disableSessionLog) != 0) + { + strError = "Incorrect DisableSessionLog value: \'" + std::string(node->getValue(0)) + "\'"; + return -1; + } + } + + if (strcasecmp(node->getName(), "FilterParamsLog") == 0) + { + filterParamsLog.clear(); + for (int i = 0; node->getValue(i) != NULL; ++i) + filterParamsLog.push_back(node->getValue(i)); + } + if (strcasecmp(node->getName(), "DirNames") == 0) { const DOTCONFDocumentNode * child = node->getChildNode(); @@@ -438,13 -442,8 +460,13 @@@ } storeModulesCount++; + if (node->getValue(0) == NULL) + { + strError = "No module name in the StoreModule section."; + return -1; + } storeModuleSettings.moduleName = node->getValue(0); - ParseModuleSettings(node, &storeModuleSettings.moduleParams); + storeModuleSettings.moduleParams = toPVS(*node); } if (strcasecmp(node->getName(), "Modules") == 0) @@@ -462,14 -461,13 +484,14 @@@ child = child->getNextNode(); continue; } - MODULE_SETTINGS modSettings; - modSettings.moduleParams.clear(); - modSettings.moduleName = child->getValue(); - ParseModuleSettings(child, &modSettings.moduleParams); + if (child->getValue(0) == NULL) + { + strError = "No module name in the Module section."; + return -1; + } - modulesSettings.push_back(modSettings); + modulesSettings.push_back(MODULE_SETTINGS(child->getValue(0), toPVS(*child))); child = child->getNextNode(); } @@@ -478,9 -476,7 +500,7 @@@ if (strcasecmp(node->getName(), "ScriptParams") == 0) { for (int i = 0; node->getValue(i) != NULL; ++i) - { scriptParams.push_back(node->getValue(i)); - } } node = node->getNextNode(); } @@@ -488,3 -484,29 +508,3 @@@ return 0; } //----------------------------------------------------------------------------- -int SETTINGS_IMPL::ParseDetailStatWritePeriod(const std::string & detailStatPeriodStr) -{ -if (detailStatPeriodStr == "1") - { - detailStatWritePeriod = dsPeriod_1; - return 0; - } -else if (detailStatPeriodStr == "1/2") - { - detailStatWritePeriod = dsPeriod_1_2; - return 0; - } -else if (detailStatPeriodStr == "1/4") - { - detailStatWritePeriod = dsPeriod_1_4; - return 0; - } -else if (detailStatPeriodStr == "1/6") - { - detailStatWritePeriod = dsPeriod_1_6; - return 0; - } - -return -1; -} -//----------------------------------------------------------------------------- diff --combined projects/stargazer/settings_impl.h index 418777d5,cc35393b..2bac34e4 --- a/projects/stargazer/settings_impl.h +++ b/projects/stargazer/settings_impl.h @@@ -1,3 -1,9 +1,3 @@@ - /* - $Revision: 1.27 $ - $Date: 2010/08/19 13:42:30 $ - $Author: faust $ - */ - /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@@ -14,10 -20,20 +14,10 @@@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* - * Date: 27.10.2002 - */ - /* * Author : Boris Mikhailenko */ - /* - $Revision: 1.27 $ - $Date: 2010/08/19 13:42:30 $ - */ - - #ifndef SETTINGS_IMPL_H #define SETTINGS_IMPL_H @@@ -27,14 -43,13 +27,14 @@@ #include "stg/settings.h" #include "stg/common.h" #include "stg/module_settings.h" +#include "stg/ref.h" //----------------------------------------------------------------------------- enum DETAIL_STAT_PERIOD { -dsPeriod_1, -dsPeriod_1_2, -dsPeriod_1_4, -dsPeriod_1_6 + dsPeriod_1, + dsPeriod_1_2, + dsPeriod_1_4, + dsPeriod_1_6 }; //----------------------------------------------------------------------------- class STG_LOGGER; @@@ -43,7 -58,7 +43,7 @@@ class DOTCONFDocumentNode class SETTINGS_IMPL : public SETTINGS { public: SETTINGS_IMPL(const std::string &); - SETTINGS_IMPL(const SETTINGS_IMPL &); + SETTINGS_IMPL(const SETTINGS_IMPL & rhs); virtual ~SETTINGS_IMPL() {} SETTINGS_IMPL & operator=(const SETTINGS_IMPL &); @@@ -60,7 -75,7 +60,7 @@@ const std::string & GetRulesFileName() const { return rules; } const std::string & GetLogFileName() const { return logFile; } const std::string & GetPIDFileName() const { return pidFile; } - unsigned GetDetailStatWritePeriod() const + unsigned GetDetailStatWritePeriod() const { return detailStatWritePeriod; } unsigned GetStatWritePeriod() const { return statWritePeriod * 60; } unsigned GetDayFee() const { return dayFee; } @@@ -77,6 -92,8 +77,8 @@@ unsigned GetMessageTimeout() const { return messageTimeout * 3600 * 24; } unsigned GetFeeChargeType() const { return feeChargeType; } bool GetReconnectOnTariffChange() const { return reconnectOnTariffChange; } + bool GetDisableSessionLog() const { return disableSessionLog; } + const std::vector & GetFilterParamsLog() const { return filterParamsLog; } const std::string & GetModulesPath() const { return modulesPath; } const MODULE_SETTINGS & GetStoreModuleSettings() const @@@ -87,6 -104,9 +89,6 @@@ private: - int ParseDetailStatWritePeriod(const std::string & str); - int ParseModuleSettings(const DOTCONFDocumentNode * dirNameNode, std::vector * params); - static void ErrorCallback(void * data, const char * buf); std::string strError; @@@ -95,7 -115,7 +97,7 @@@ std::string modulesPath; std::vector dirName; std::string confDir; - std::string scriptsDir; + std::string scriptsDir; std::string rules; std::string logFile; std::string pidFile; @@@ -117,10 -137,12 +119,12 @@@ unsigned messageTimeout; unsigned feeChargeType; bool reconnectOnTariffChange; + bool disableSessionLog; + std::vector filterParamsLog; std::vector modulesSettings; MODULE_SETTINGS storeModuleSettings; - STG_LOGGER & logger; + STG::RefWrapper logger; }; //-----------------------------------------------------------------------------