2 #include "tariffs_methods.h"
3 #include "tariff_helper.h"
5 void METHOD_TARIFF_GET::execute(xmlrpc_c::paramList const & paramList,
6 xmlrpc_c::value * const retvalPtr)
8 std::string cookie = paramList.getString(0);
9 std::string name = paramList.getString(1);
10 paramList.verifyEnd(2);
12 std::map<std::string, xmlrpc_c::value> structVal;
15 if (config->GetAdminInfo(cookie, &adminInfo))
17 structVal["result"] = xmlrpc_c::value_boolean(false);
18 *retvalPtr = xmlrpc_c::value_struct(structVal);
22 const TARIFF * tariff = tariffs->FindByName(name);
26 structVal["result"] = xmlrpc_c::value_boolean(false);
27 *retvalPtr = xmlrpc_c::value_struct(structVal);
33 tariff->GetTariffData(&td);
35 TARIFF_HELPER helper(td);
37 helper.GetTariffInfo(retvalPtr);
40 void METHOD_TARIFF_CHG::execute(xmlrpc_c::paramList const & paramList,
41 xmlrpc_c::value * const retvalPtr)
43 std::string cookie = paramList.getString(0);
44 std::string name = paramList.getString(1);
45 xmlrpc_c::value_struct info(paramList.getStruct(2));
46 paramList.verifyEnd(3);
50 if (config->GetAdminInfo(cookie, &adminInfo))
52 *retvalPtr = xmlrpc_c::value_boolean(false);
58 if (admins->FindAdmin(adminInfo.admin, &admin))
60 *retvalPtr = xmlrpc_c::value_boolean(false);
64 const TARIFF * tariff = tariffs->FindByName(name);
68 *retvalPtr = xmlrpc_c::value_boolean(false);
74 tariff->GetTariffData(&td);
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);
129 paramList.verifyEnd(2);
131 ADMIN_INFO adminInfo;
133 if (config->GetAdminInfo(cookie, &adminInfo))
135 *retvalPtr = xmlrpc_c::value_boolean(false);
141 if (admins->FindAdmin(adminInfo.admin, &admin))
143 *retvalPtr = xmlrpc_c::value_boolean(false);
147 if (tariffs->Add(tariff, admin))
149 *retvalPtr = xmlrpc_c::value_boolean(false);
153 *retvalPtr = xmlrpc_c::value_boolean(true);
156 void METHOD_TARIFF_DEL::execute(xmlrpc_c::paramList const & paramList,
157 xmlrpc_c::value * const retvalPtr)
159 std::string cookie = paramList.getString(0);
160 std::string tariff = paramList.getString(1);
161 paramList.verifyEnd(2);
163 ADMIN_INFO adminInfo;
165 if (config->GetAdminInfo(cookie, &adminInfo))
167 *retvalPtr = xmlrpc_c::value_boolean(false);
173 if (admins->FindAdmin(adminInfo.admin, &admin))
175 *retvalPtr = xmlrpc_c::value_boolean(false);
179 if (users->TariffInUse(tariff))
181 *retvalPtr = xmlrpc_c::value_boolean(false);
185 if (tariffs->Del(tariff, admin))
187 *retvalPtr = xmlrpc_c::value_boolean(false);
191 *retvalPtr = xmlrpc_c::value_boolean(true);