1 #include <ostream> // xmlrpc-c devs have missed something :)
3 #include "tariffs_methods.h"
5 #include "tariff_helper.h"
6 #include "stg/tariffs.h"
8 #include "stg/admins.h"
11 void METHOD_TARIFF_GET::execute(xmlrpc_c::paramList const & paramList,
12 xmlrpc_c::value * const retvalPtr)
14 std::string cookie = paramList.getString(0);
15 std::string name = paramList.getString(1);
16 paramList.verifyEnd(2);
18 std::map<std::string, xmlrpc_c::value> structVal;
21 if (config->GetAdminInfo(cookie, &adminInfo))
23 structVal["result"] = xmlrpc_c::value_boolean(false);
24 *retvalPtr = xmlrpc_c::value_struct(structVal);
28 const TARIFF * tariff = tariffs->FindByName(name);
32 structVal["result"] = xmlrpc_c::value_boolean(false);
33 *retvalPtr = xmlrpc_c::value_struct(structVal);
37 TARIFF_DATA td(tariff->GetTariffData());
39 TARIFF_HELPER helper(td);
41 helper.GetTariffInfo(retvalPtr);
44 void METHOD_TARIFF_CHG::execute(xmlrpc_c::paramList const & paramList,
45 xmlrpc_c::value * const retvalPtr)
47 std::string cookie = paramList.getString(0);
48 std::string name = paramList.getString(1);
49 xmlrpc_c::value_struct info(paramList.getStruct(2));
50 paramList.verifyEnd(3);
54 if (config->GetAdminInfo(cookie, &adminInfo))
56 *retvalPtr = xmlrpc_c::value_boolean(false);
62 if (admins->Find(adminInfo.admin, &admin))
64 *retvalPtr = xmlrpc_c::value_boolean(false);
68 const TARIFF * tariff = tariffs->FindByName(name);
72 *retvalPtr = xmlrpc_c::value_boolean(false);
76 TARIFF_DATA td(tariff->GetTariffData());
78 TARIFF_HELPER helper(td);
80 helper.SetTariffInfo(info);
82 if (tariffs->Chg(td, admin))
84 *retvalPtr = xmlrpc_c::value_boolean(false);
88 *retvalPtr = xmlrpc_c::value_boolean(true);
91 void METHOD_TARIFFS_GET::execute(xmlrpc_c::paramList const & paramList,
92 xmlrpc_c::value * const retvalPtr)
94 std::string cookie = paramList.getString(0);
95 paramList.verifyEnd(1);
97 std::map<std::string, xmlrpc_c::value> structVal;
100 if (config->GetAdminInfo(cookie, &adminInfo))
102 structVal["result"] = xmlrpc_c::value_boolean(false);
103 *retvalPtr = xmlrpc_c::value_struct(structVal);
107 std::vector<xmlrpc_c::value> tariffsInfo;
110 std::vector<TARIFF_DATA> dataList;
111 tariffs->GetTariffsData(&dataList);
112 auto it = dataList.begin();
113 for (; it != dataList.end(); ++it)
115 xmlrpc_c::value info;
116 TARIFF_DATA td(*it); // 'cause TARIFF_HELPER work in both ways and take not const referense
117 TARIFF_HELPER helper(td);
118 helper.GetTariffInfo(&info);
119 tariffsInfo.push_back(info);
122 *retvalPtr = xmlrpc_c::value_array(tariffsInfo);
125 void METHOD_TARIFF_ADD::execute(xmlrpc_c::paramList const & paramList,
126 xmlrpc_c::value * const retvalPtr)
128 std::string cookie = paramList.getString(0);
129 std::string tariff = paramList.getString(1);
130 paramList.verifyEnd(2);
132 ADMIN_INFO adminInfo;
134 if (config->GetAdminInfo(cookie, &adminInfo))
136 *retvalPtr = xmlrpc_c::value_boolean(false);
142 if (admins->Find(adminInfo.admin, &admin))
144 *retvalPtr = xmlrpc_c::value_boolean(false);
148 if (tariffs->Add(tariff, admin))
150 *retvalPtr = xmlrpc_c::value_boolean(false);
154 *retvalPtr = xmlrpc_c::value_boolean(true);
157 void METHOD_TARIFF_DEL::execute(xmlrpc_c::paramList const & paramList,
158 xmlrpc_c::value * const retvalPtr)
160 std::string cookie = paramList.getString(0);
161 std::string tariff = paramList.getString(1);
162 paramList.verifyEnd(2);
164 ADMIN_INFO adminInfo;
166 if (config->GetAdminInfo(cookie, &adminInfo))
168 *retvalPtr = xmlrpc_c::value_boolean(false);
174 if (admins->Find(adminInfo.admin, &admin))
176 *retvalPtr = xmlrpc_c::value_boolean(false);
180 if (users->TariffInUse(tariff))
182 *retvalPtr = xmlrpc_c::value_boolean(false);
186 if (tariffs->Del(tariff, admin))
188 *retvalPtr = xmlrpc_c::value_boolean(false);
192 *retvalPtr = xmlrpc_c::value_boolean(true);