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);
129 paramList.verifyEnd(2);
131 ADMIN_INFO adminInfo;
133 if (config->GetAdminInfo(cookie, &adminInfo))
135 *retvalPtr = xmlrpc_c::value_boolean(false);
141 if (admins->Find(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->Find(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);