From: Elena Mamontova Date: Thu, 19 Jan 2017 14:00:03 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/master' into ticket X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/6c4d31bf18078de98e71575d4b032df303f23a3a?hp=f7ede97c7409f731705ae9771c712ebe900dc4ad Merge remote-tracking branch 'origin/master' into ticket --- diff --git a/doc/xmlrpc/Makefile b/doc/xmlrpc/Makefile index fcbc7630..48f58711 100644 --- a/doc/xmlrpc/Makefile +++ b/doc/xmlrpc/Makefile @@ -1,5 +1,5 @@ all: - xsltproc -o book/ --xinclude ../xslt/html/chunk.xsl API.xml + xsltproc --stringparam chunker.output.encoding "utf-8" -o book/ --xinclude /usr/share/sgml/docbook/xsl-stylesheets/html/chunk.xsl API.xml clean: rm book/*html diff --git a/projects/stargazer/plugins/capture/nfqueue/nfqueue.h b/projects/stargazer/plugins/capture/nfqueue/nfqueue.h index 27198073..fe40bc50 100644 --- a/projects/stargazer/plugins/capture/nfqueue/nfqueue.h +++ b/projects/stargazer/plugins/capture/nfqueue/nfqueue.h @@ -35,7 +35,7 @@ class TARIFFS; class ADMINS; class TRAFFCOUNTER; class SETTINGS; -class RAW_PACKET; +struct RAW_PACKET; class TRAFFCOUNTER; diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index f63d9686..359b55e2 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -1524,13 +1524,10 @@ if (conf.ReadString("ChangePolicy", &str, "allow") < 0) else td->tariffConf.changePolicy = TARIFF::StringToChangePolicy(str); -if (conf.ReadTime("ChangePolicyTimeout", &td->tariffConf.changePolicyTimeout, 0) < 0) - { - STG_LOCKER lock(&mutex); - errorStr = "Cannot read tariff " + tariffName + ". Parameter ChangePolicyTimeout"; - printfd(__FILE__, "FILES_STORE::RestoreTariff - changepolicytimeout read failed for tariff '%s'\n", tariffName.c_str()); - return -1; - } +if (conf.ReadString("ChangePolicyTimeout", &str, "1970-01-01 00:00:00") < 0) + td->tariffConf.changePolicyTimeout = 0; +else + td->tariffConf.changePolicyTimeout = readTime(str); return 0; } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_utils.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_utils.cpp index 96eb817d..bbbc8794 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_utils.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_utils.cpp @@ -41,6 +41,8 @@ time_t ts2time_t(const IBPP::Timestamp & ts) memset(&time_tm, 0, sizeof(time_tm)); ts.GetDate(year, month, day); ts.GetTime(hour, min, sec); + if (year < 1990) + return 0; sprintf(buf, "%d-%d-%d %d:%d:%d", year, month, day, hour, min, sec); stg_strptime(buf, "%Y-%m-%d %H:%M:%S", &time_tm); diff --git a/projects/stargazer/tariff_impl.cpp b/projects/stargazer/tariff_impl.cpp index 2daaeeb3..7dbae0da 100644 --- a/projects/stargazer/tariff_impl.cpp +++ b/projects/stargazer/tariff_impl.cpp @@ -148,7 +148,7 @@ else std::string TARIFF_IMPL::TariffChangeIsAllowed(const TARIFF & to, time_t currentTime) const { time_t timeout = GetChangePolicyTimeout(); -if ((currentTime > timeout) && (timeout != 0)) +if (currentTime > timeout && timeout != 0) return ""; switch (GetChangePolicy()) { @@ -167,5 +167,6 @@ switch (GetChangePolicy()) case TARIFF::DENY: return "Current tariff '" + GetName() + "', new tariff '" + to.GetName() + "'. The policy is '" + TARIFF::ChangePolicyToString(GetChangePolicy()) + "'."; } +return ""; } //----------------------------------------------------------------------------- diff --git a/stglibs/common.lib/include/stg/common.h b/stglibs/common.lib/include/stg/common.h index 6201233d..a9cc05b1 100644 --- a/stglibs/common.lib/include/stg/common.h +++ b/stglibs/common.lib/include/stg/common.h @@ -31,6 +31,7 @@ #include #else #include +#include // NAME_MAX #endif #include #include diff --git a/tests/Makefile b/tests/Makefile index f615b1d6..2fca2809 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -29,6 +29,7 @@ SOURCES = main.cpp \ ../projects/stargazer/user_property.cpp \ ../stglibs/conffiles.lib/conffiles.cpp \ ../stglibs/common.lib/common.cpp \ + ../stglibs/common.lib/strptime.cpp \ ../stglibs/logger.lib/logger.cpp \ ../stglibs/scriptexecuter.lib/scriptexecuter.cpp \ ../stglibs/crypto.lib/bfstream.cpp \ diff --git a/tests/Makefile.darwin b/tests/Makefile.darwin index 8066f877..d53db9b2 100644 --- a/tests/Makefile.darwin +++ b/tests/Makefile.darwin @@ -29,6 +29,7 @@ SOURCES = main.cpp \ ../projects/stargazer/user_property.cpp \ ../stglibs/conffiles.lib/conffiles.cpp \ ../stglibs/common.lib/common.cpp \ + ../stglibs/common.lib/strptime.cpp \ ../stglibs/logger.lib/logger.cpp \ ../stglibs/scriptexecuter.lib/scriptexecuter.cpp \ ../stglibs/crypto.lib/bfstream.cpp \ diff --git a/tests/test_tariff.cpp b/tests/test_tariff.cpp index 188aee8a..9565be68 100644 --- a/tests/test_tariff.cpp +++ b/tests/test_tariff.cpp @@ -359,17 +359,17 @@ namespace tut td.tariffConf.fee = 50; TARIFF_IMPL cheaper(td); - ensure_equals("Allow cheaper", tariff.TariffChangeIsAllowed(cheaper).empty(), true); + ensure_equals("Allow cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), true); td.tariffConf.fee = 100; TARIFF_IMPL equal(td); - ensure_equals("Allow equal", tariff.TariffChangeIsAllowed(equal).empty(), true); + ensure_equals("Allow equal", tariff.TariffChangeIsAllowed(equal, 1461606400).empty(), true); td.tariffConf.fee = 150; TARIFF_IMPL expensive(td); - ensure_equals("Allow expensive", tariff.TariffChangeIsAllowed(expensive).empty(), true); + ensure_equals("Allow expensive", tariff.TariffChangeIsAllowed(expensive, 1461606400).empty(), true); } template<> @@ -386,17 +386,17 @@ namespace tut td.tariffConf.fee = 50; TARIFF_IMPL cheaper(td); - ensure_equals("Allow cheaper", tariff.TariffChangeIsAllowed(cheaper).empty(), true); + ensure_equals("Allow cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), true); td.tariffConf.fee = 100; TARIFF_IMPL equal(td); - ensure_equals("Prohibit equal", tariff.TariffChangeIsAllowed(equal).empty(), false); + ensure_equals("Prohibit equal", tariff.TariffChangeIsAllowed(equal, 1461606400).empty(), false); td.tariffConf.fee = 150; TARIFF_IMPL expensive(td); - ensure_equals("Prohibit expensive", tariff.TariffChangeIsAllowed(expensive).empty(), false); + ensure_equals("Prohibit expensive", tariff.TariffChangeIsAllowed(expensive, 1461606400).empty(), false); } template<> @@ -413,17 +413,17 @@ namespace tut td.tariffConf.fee = 50; TARIFF_IMPL cheaper(td); - ensure_equals("Prohibit cheaper", tariff.TariffChangeIsAllowed(cheaper).empty(), false); + ensure_equals("Prohibit cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), false); td.tariffConf.fee = 100; TARIFF_IMPL equal(td); - ensure_equals("Allow equal", tariff.TariffChangeIsAllowed(equal).empty(), true); + ensure_equals("Allow equal", tariff.TariffChangeIsAllowed(equal, 1461606400).empty(), true); td.tariffConf.fee = 150; TARIFF_IMPL expensive(td); - ensure_equals("Allow expensive", tariff.TariffChangeIsAllowed(expensive).empty(), true); + ensure_equals("Allow expensive", tariff.TariffChangeIsAllowed(expensive, 1461606400).empty(), true); } template<> @@ -440,16 +440,70 @@ namespace tut td.tariffConf.fee = 50; TARIFF_IMPL cheaper(td); - ensure_equals("Prohibit cheaper", tariff.TariffChangeIsAllowed(cheaper).empty(), false); + ensure_equals("Prohibit cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), false); td.tariffConf.fee = 100; TARIFF_IMPL equal(td); - ensure_equals("Prohibit equal", tariff.TariffChangeIsAllowed(equal).empty(), false); + ensure_equals("Prohibit equal", tariff.TariffChangeIsAllowed(equal, 1461606400).empty(), false); td.tariffConf.fee = 150; TARIFF_IMPL expensive(td); - ensure_equals("Prohibit expensive", tariff.TariffChangeIsAllowed(expensive).empty(), false); + ensure_equals("Prohibit expensive", tariff.TariffChangeIsAllowed(expensive, 1461606400).empty(), false); + } + + template<> + template<> + void testobject::test<11>() + { + set_test_name("Check changePolicyTimeout < current time"); + + TARIFF_DATA td("test"); + td.tariffConf.changePolicyTimeout = 1451606400; + td.tariffConf.changePolicy = TARIFF::TO_EXPENSIVE; + td.tariffConf.fee = 100; + TARIFF_IMPL tariff(td); + + td.tariffConf.fee = 50; + TARIFF_IMPL cheaper(td); + + ensure_equals("Allow cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), true); + } + + template<> + template<> + void testobject::test<12>() + { + set_test_name("Check changePolicyTimeout > current time"); + + TARIFF_DATA td("test"); + td.tariffConf.changePolicyTimeout = 1483228800; + td.tariffConf.changePolicy = TARIFF::TO_EXPENSIVE; + td.tariffConf.fee = 100; + TARIFF_IMPL tariff(td); + + td.tariffConf.fee = 50; + TARIFF_IMPL cheaper(td); + + ensure_equals("Prohibit cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), false); + } + + template<> + template<> + void testobject::test<13>() + { + set_test_name("Check changePolicyTimeout = 0"); + + TARIFF_DATA td("test"); + td.tariffConf.changePolicyTimeout = 0; + td.tariffConf.changePolicy = TARIFF::TO_EXPENSIVE; + td.tariffConf.fee = 100; + TARIFF_IMPL tariff(td); + + td.tariffConf.fee = 50; + TARIFF_IMPL cheaper(td); + + ensure_equals("Prohibit cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), false); } }