2 #include "tariffs_methods.h"
3 #include "tariff_helper.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);
37 tariff->GetTariffData(&td);
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->FindAdmin(adminInfo.admin, &admin))
64 *retvalPtr = xmlrpc_c::value_boolean(false);
68 const TARIFF * tariff = tariffs->FindByName(name);
72 *retvalPtr = xmlrpc_c::value_boolean(false);
78 tariff->GetTariffData(&td);
80 TARIFF_HELPER helper(td);
82 helper.SetTariffInfo(info);
84 if (tariffs->Chg(td, admin))
86 *retvalPtr = xmlrpc_c::value_boolean(false);
90 *retvalPtr = xmlrpc_c::value_boolean(true);
93 void METHOD_TARIFFS_GET::execute(xmlrpc_c::paramList const & paramList,
94 xmlrpc_c::value * const retvalPtr)
96 std::string cookie = paramList.getString(0);
97 paramList.verifyEnd(1);
99 std::map<std::string, xmlrpc_c::value> structVal;
100 ADMIN_INFO adminInfo;
102 if (config->GetAdminInfo(cookie, &adminInfo))
104 structVal["result"] = xmlrpc_c::value_boolean(false);
105 *retvalPtr = xmlrpc_c::value_struct(structVal);
109 std::vector<xmlrpc_c::value> tariffsInfo;
112 std::list<TARIFF_DATA> dataList;
113 tariffs->GetTariffsData(&dataList);
114 std::list<TARIFF_DATA>::const_iterator it = dataList.begin();
115 for (; it != dataList.end(); ++it)
117 xmlrpc_c::value info;
118 TARIFF_DATA td(*it); // 'cause TARIFF_HELPER work in both ways and take not const referense
119 TARIFF_HELPER helper(td);
120 helper.GetTariffInfo(&info);
121 tariffsInfo.push_back(info);
124 *retvalPtr = xmlrpc_c::value_array(tariffsInfo);
127 void METHOD_TARIFF_ADD::execute(xmlrpc_c::paramList const & paramList,
128 xmlrpc_c::value * const retvalPtr)
130 std::string cookie = paramList.getString(0);
131 std::string tariff = paramList.getString(1);
133 paramList.verifyEnd(2);
135 ADMIN_INFO adminInfo;
137 if (config->GetAdminInfo(cookie, &adminInfo))
139 *retvalPtr = xmlrpc_c::value_boolean(false);
145 if (admins->FindAdmin(adminInfo.admin, &admin))
147 *retvalPtr = xmlrpc_c::value_boolean(false);
151 if (tariffs->Add(tariff, admin))
153 *retvalPtr = xmlrpc_c::value_boolean(false);
157 *retvalPtr = xmlrpc_c::value_boolean(true);
160 void METHOD_TARIFF_DEL::execute(xmlrpc_c::paramList const & paramList,
161 xmlrpc_c::value * const retvalPtr)
163 std::string cookie = paramList.getString(0);
164 std::string tariff = paramList.getString(1);
165 paramList.verifyEnd(2);
167 ADMIN_INFO adminInfo;
169 if (config->GetAdminInfo(cookie, &adminInfo))
171 *retvalPtr = xmlrpc_c::value_boolean(false);
177 if (admins->FindAdmin(adminInfo.admin, &admin))
179 *retvalPtr = xmlrpc_c::value_boolean(false);
183 if (users->TariffInUse(tariff))
185 *retvalPtr = xmlrpc_c::value_boolean(false);
189 if (tariffs->Del(tariff, admin))
191 *retvalPtr = xmlrpc_c::value_boolean(false);
195 *retvalPtr = xmlrpc_c::value_boolean(true);