]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp
Merge branch 'stg-2.409-radius'
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / parser_tariffs.cpp
index 4763e97fd47a945411acd6d0ad382cf0ed27bbfa..9c75267480e9591544e920ddb2b28788ff3f08ac 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "stg/tariffs.h"
 #include "stg/users.h"
-#include "stg/common.h"
 #include "stg/resetable.h"
 
 #include <cstdio> // snprintf
@@ -57,6 +56,16 @@ std::string AOS2String(const A & array, size_t size, const F C::* field, F multi
     return res;
 }
 
+template <typename T>
+bool str2res(const std::string& source, RESETABLE<T>& dest, T divisor)
+{
+    T value = 0;
+    if (str2x(source, value))
+        return false;
+    dest = value / divisor;
+    return true;
+}
+
 template <typename A, typename C, typename F>
 bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE<F> C::* field, F divisor)
 {
@@ -65,15 +74,13 @@ bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE<F>
     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;
 }
 
@@ -107,6 +114,8 @@ void GET_TARIFFS::CreateAnswer()
                   "<Free value=\"" + x2str(it->tariffConf.free) + "\"/>" +
                   "<TraffType value=\"" + TARIFF::TraffTypeToString(it->tariffConf.traffType) + "\"/>" +
                   "<Period value=\"" + TARIFF::PeriodToString(it->tariffConf.period) + "\"/>" +
+                  "<ChangePolicy value=\"" + TARIFF::ChangePolicyToString(it->tariffConf.changePolicy) + "\"/>" +
+                  "<ChangePolicyTimeout value=\"" + x2str(it->tariffConf.changePolicyTimeout) + "\"/>" +
                   "</tariff>";
         }
 
@@ -163,7 +172,11 @@ int CHG_TARIFF::Start(void *, const char * el, const char ** attr)
     {
         if (strcasecmp(el, m_tag.c_str()) == 0)
         {
-            td.tariffConf.name = attr[1];
+            const TARIFF * tariff = m_tariffs.FindByName(attr[1]);
+            if (tariff != NULL)
+                td = tariff->GetTariffData();
+            else
+                return -1;
             return 0;
         }
     }
@@ -281,6 +294,20 @@ int CHG_TARIFF::Start(void *, const char * el, const char ** attr)
             td.tariffConf.period = TARIFF::StringToPeriod(attr[1]);
             return 0;
         }
+
+        if (strcasecmp(el, "ChangePolicy") == 0)
+        {
+            td.tariffConf.changePolicy = TARIFF::StringToChangePolicy(attr[1]);
+            return 0;
+        }
+
+        if (strcasecmp(el, "ChangePolicyTimeout") == 0)
+        {
+            int64_t policyTime = 0;
+            if (str2x(attr[1], policyTime) == 0)
+                td.tariffConf.changePolicyTimeout = (time_t)policyTime;
+            return 0;
+        }
     }
     return -1;
 }