]> git.stg.codes - stg.git/blobdiff - stglibs/srvconf.lib/parsers/chg_tariff.cpp
Merge branch 'stg-2.409-radius'
[stg.git] / stglibs / srvconf.lib / parsers / chg_tariff.cpp
index c23cd0cd3ad690d9144f33f85d8c9f7f0d28cae1..16c4b198dbf1d4e605de0a51d22c39f46abf8d4e 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "chg_tariff.h"
 
+#include "resetable_utils.h"
+
 #include "stg/tariff_conf.h"
 #include "stg/common.h"
 
@@ -32,13 +34,6 @@ using namespace STG;
 namespace
 {
 
-template <typename T>
-void appendResetable(std::ostream & stream, const std::string & name, const T & value)
-{
-if (!value.empty())
-    stream << "<" << name << " value=\"" << value.data() << "\"/>";
-}
-
 template <typename A, typename T>
 void appendSlashedResetable(std::ostream & stream, const std::string & name, const A & array, T A::value_type:: * field)
 {
@@ -56,23 +51,34 @@ stream << "<" << name << " value=\"" << res << "\"/>";
 
 } // namespace anonymous
 
-std::string CHG_TARIFF::Serialize(const TARIFF_DATA_RES & data)
+std::string CHG_TARIFF::Serialize(const TARIFF_DATA_RES & data, const std::string & /*encoding*/)
 {
 std::ostringstream stream;
 
-appendResetable(stream, "fee", data.tariffConf.fee);
-appendResetable(stream, "passiveCost", data.tariffConf.passiveCost);
-appendResetable(stream, "free", data.tariffConf.free);
+appendResetableTag(stream, "fee", data.tariffConf.fee);
+appendResetableTag(stream, "passiveCost", data.tariffConf.passiveCost);
+appendResetableTag(stream, "free", data.tariffConf.free);
 
 if (!data.tariffConf.traffType.empty())
-    switch (data.tariffConf.traffType.data())
+    stream << "<traffType value=\"" + TARIFF::TraffTypeToString(data.tariffConf.traffType.data()) + "\"/>";
+
+if (!data.tariffConf.period.empty())
+    switch (data.tariffConf.period.data())
+        {
+        case TARIFF::DAY: stream << "<period value=\"day\"/>"; break;
+        case TARIFF::MONTH: stream << "<period value=\"month\"/>"; break;
+        }
+
+if (!data.tariffConf.changePolicy.empty())
+    switch (data.tariffConf.changePolicy.data())
         {
-        case TRAFF_UP: stream << "<traffType value=\"up\"/>"; break;
-        case TRAFF_DOWN: stream << "<traffType value=\"down\"/>"; break;
-        case TRAFF_UP_DOWN: stream << "<traffType value=\"up+down\"/>"; break;
-        case TRAFF_MAX: stream << "<traffType value=\"max\"/>"; break;
+        case TARIFF::ALLOW: stream << "<changePolicy value=\"allow\"/>"; break;
+        case TARIFF::TO_CHEAP: stream << "<changePolicy value=\"to_cheap\"/>"; break;
+        case TARIFF::TO_EXPENSIVE: stream << "<changePolicy value=\"to_expensive\"/>"; break;
+        case TARIFF::DENY: stream << "<changePolicy value=\"deny\"/>"; break;
         }
 
+appendResetableTag(stream, "changePolicyTimeout", data.tariffConf.changePolicyTimeout);
 for (size_t i = 0; i < DIR_NUM; ++i)
     if (!data.dirPrice[i].hDay.empty() &&
         !data.dirPrice[i].mDay.empty() &&
@@ -89,6 +95,7 @@ appendSlashedResetable(stream, "priceNightA", data.dirPrice, &DIRPRICE_DATA_RES:
 appendSlashedResetable(stream, "priceNightB", data.dirPrice, &DIRPRICE_DATA_RES::priceNightB);
 appendSlashedResetable(stream, "singlePrice", data.dirPrice, &DIRPRICE_DATA_RES::singlePrice);
 appendSlashedResetable(stream, "noDiscount", data.dirPrice, &DIRPRICE_DATA_RES::noDiscount);
+appendSlashedResetable(stream, "threshold", data.dirPrice, &DIRPRICE_DATA_RES::threshold);
 
 return stream.str();
 }