1 #include "tariffs_methods.h"
3 #include "tariff_helper.h"
4 #include "stg/tariffs.h"
6 #include "stg/admins.h"
9 void METHOD_TARIFF_GET::execute(xmlrpc_c::paramList const & paramList,
10 xmlrpc_c::value * const retvalPtr)
12 std::string cookie = paramList.getString(0);
13 std::string name = paramList.getString(1);
14 paramList.verifyEnd(2);
16 std::map<std::string, xmlrpc_c::value> structVal;
19 if (config->GetAdminInfo(cookie, &adminInfo))
21 structVal["result"] = xmlrpc_c::value_boolean(false);
22 *retvalPtr = xmlrpc_c::value_struct(structVal);
26 const TARIFF * tariff = tariffs->FindByName(name);
30 structVal["result"] = xmlrpc_c::value_boolean(false);
31 *retvalPtr = xmlrpc_c::value_struct(structVal);
35 TARIFF_DATA td(tariff->GetTariffData());
37 TARIFF_HELPER helper(td);
39 helper.GetTariffInfo(retvalPtr);
42 void METHOD_TARIFF_CHG::execute(xmlrpc_c::paramList const & paramList,
43 xmlrpc_c::value * const retvalPtr)
45 std::string cookie = paramList.getString(0);
46 std::string name = paramList.getString(1);
47 xmlrpc_c::value_struct info(paramList.getStruct(2));
48 paramList.verifyEnd(3);
52 if (config->GetAdminInfo(cookie, &adminInfo))
54 *retvalPtr = xmlrpc_c::value_boolean(false);
60 if (admins->Find(adminInfo.admin, &admin))
62 *retvalPtr = xmlrpc_c::value_boolean(false);
66 const TARIFF * tariff = tariffs->FindByName(name);
70 *retvalPtr = xmlrpc_c::value_boolean(false);
74 TARIFF_DATA td(tariff->GetTariffData());
76 TARIFF_HELPER helper(td);
78 helper.SetTariffInfo(info);
80 if (tariffs->Chg(td, admin))
82 *retvalPtr = xmlrpc_c::value_boolean(false);
86 *retvalPtr = xmlrpc_c::value_boolean(true);
89 void METHOD_TARIFFS_GET::execute(xmlrpc_c::paramList const & paramList,
90 xmlrpc_c::value * const retvalPtr)
92 std::string cookie = paramList.getString(0);
93 paramList.verifyEnd(1);
95 std::map<std::string, xmlrpc_c::value> structVal;
98 if (config->GetAdminInfo(cookie, &adminInfo))
100 structVal["result"] = xmlrpc_c::value_boolean(false);
101 *retvalPtr = xmlrpc_c::value_struct(structVal);
105 std::vector<xmlrpc_c::value> tariffsInfo;
108 std::list<TARIFF_DATA> dataList;
109 tariffs->GetTariffsData(&dataList);
110 std::list<TARIFF_DATA>::const_iterator it = dataList.begin();
111 for (; it != dataList.end(); ++it)
113 xmlrpc_c::value info;
114 TARIFF_DATA td(*it); // 'cause TARIFF_HELPER work in both ways and take not const referense
115 TARIFF_HELPER helper(td);
116 helper.GetTariffInfo(&info);
117 tariffsInfo.push_back(info);
120 *retvalPtr = xmlrpc_c::value_array(tariffsInfo);
123 void METHOD_TARIFF_ADD::execute(xmlrpc_c::paramList const & paramList,
124 xmlrpc_c::value * const retvalPtr)
126 std::string cookie = paramList.getString(0);
127 std::string tariff = paramList.getString(1);
128 paramList.verifyEnd(2);
130 ADMIN_INFO adminInfo;
132 if (config->GetAdminInfo(cookie, &adminInfo))
134 *retvalPtr = xmlrpc_c::value_boolean(false);
140 if (admins->Find(adminInfo.admin, &admin))
142 *retvalPtr = xmlrpc_c::value_boolean(false);
146 if (tariffs->Add(tariff, admin))
148 *retvalPtr = xmlrpc_c::value_boolean(false);
152 *retvalPtr = xmlrpc_c::value_boolean(true);
155 void METHOD_TARIFF_DEL::execute(xmlrpc_c::paramList const & paramList,
156 xmlrpc_c::value * const retvalPtr)
158 std::string cookie = paramList.getString(0);
159 std::string tariff = paramList.getString(1);
160 paramList.verifyEnd(2);
162 ADMIN_INFO adminInfo;
164 if (config->GetAdminInfo(cookie, &adminInfo))
166 *retvalPtr = xmlrpc_c::value_boolean(false);
172 if (admins->Find(adminInfo.admin, &admin))
174 *retvalPtr = xmlrpc_c::value_boolean(false);
178 if (users->TariffInUse(tariff))
180 *retvalPtr = xmlrpc_c::value_boolean(false);
184 if (tariffs->Del(tariff, admin))
186 *retvalPtr = xmlrpc_c::value_boolean(false);
190 *retvalPtr = xmlrpc_c::value_boolean(true);