]> git.stg.codes - stg.git/commitdiff
Merge remote-tracking branch 'origin/ticket'
authorMaxim Mamontov <faust.madf@gmail.com>
Thu, 22 Dec 2016 19:56:56 +0000 (21:56 +0200)
committerMaxim Mamontov <faust.madf@gmail.com>
Thu, 22 Dec 2016 19:56:56 +0000 (21:56 +0200)
projects/stargazer/plugins/capture/nfqueue/nfqueue.h
projects/stargazer/plugins/store/files/file_store.cpp
projects/stargazer/plugins/store/firebird/firebird_store_utils.cpp
projects/stargazer/tariff_impl.cpp
stglibs/common.lib/include/stg/common.h
tests/Makefile
tests/Makefile.darwin
tests/test_tariff.cpp

index 27198073cfc255951df2b920f852e55481d8f6ac..fe40bc500ddaf9e88a058304759e1273a71cc64e 100644 (file)
@@ -35,7 +35,7 @@ class TARIFFS;
 class ADMINS;
 class TRAFFCOUNTER;
 class SETTINGS;
-class RAW_PACKET;
+struct RAW_PACKET;
 
 class TRAFFCOUNTER;
 
index f63d96869552c48b8cdcdaa85502c00445bf3b43..359b55e218bab974f07f2bb56a31d0c7695321fc 100644 (file)
@@ -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;
 }
 //-----------------------------------------------------------------------------
index 96eb817d64b8e24f78128b81013a8eeeb2ddf22f..bbbc879438a2aeeae5c1ff782b708e6247fc886c 100644 (file)
@@ -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);
 
index 2daaeeb3756c6bc8f8e7da3dc19bf22a78444efa..7dbae0da5def9330a4a6d01a957cf72b208d36e3 100644 (file)
@@ -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 "";
 }
 //-----------------------------------------------------------------------------
index 6201233d2b94941bad3fe04575925e3412800169..a9cc05b1f94e8df0e40e720810023741344fbbca 100644 (file)
@@ -31,6 +31,7 @@
 #include <time.h>
 #else
 #include <ctime>
+#include <climits> // NAME_MAX
 #endif
 #include <string>
 #include <sstream>
index f615b1d6df6ffb59c7de9304d8a328896182928b..2fca2809b1ee482cb28133ed9ff1c16db27f127b 100644 (file)
@@ -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 \
index 8066f8772f8247999dafb42760f5f9bbc402c22f..d53db9b2930ccbef9214aa7f76e1f5690dc893e0 100644 (file)
@@ -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 \
index 188aee8a1802cdad240568d766ab392ca783e7a5..9565be6848c7a3d16b288cb3a753647ee1215c73 100644 (file)
@@ -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);
     }
 }