1 #include <ostream> // xmlrpc-c devs have missed something :)
3 #include "tariffs_methods.h"
5 #include "tariff_helper.h"
7 #include "stg/tariffs.h"
8 #include "stg/tariff.h"
9 #include "stg/tariff_conf.h"
10 #include "stg/users.h"
11 #include "stg/admins.h"
12 #include "stg/admin.h"
14 void METHOD_TARIFF_GET::execute(xmlrpc_c::paramList const & paramList,
15 xmlrpc_c::value * const retvalPtr)
17 std::string cookie = paramList.getString(0);
18 std::string name = paramList.getString(1);
19 paramList.verifyEnd(2);
21 std::map<std::string, xmlrpc_c::value> structVal;
24 if (config->GetAdminInfo(cookie, &adminInfo))
26 structVal["result"] = xmlrpc_c::value_boolean(false);
27 *retvalPtr = xmlrpc_c::value_struct(structVal);
31 const auto tariff = tariffs->FindByName(name);
35 structVal["result"] = xmlrpc_c::value_boolean(false);
36 *retvalPtr = xmlrpc_c::value_struct(structVal);
40 auto td = tariff->GetTariffData();
42 TARIFF_HELPER helper(td);
44 helper.GetTariffInfo(retvalPtr);
47 void METHOD_TARIFF_CHG::execute(xmlrpc_c::paramList const & paramList,
48 xmlrpc_c::value * const retvalPtr)
50 std::string cookie = paramList.getString(0);
51 std::string name = paramList.getString(1);
52 xmlrpc_c::value_struct info(paramList.getStruct(2));
53 paramList.verifyEnd(3);
57 if (config->GetAdminInfo(cookie, &adminInfo))
59 *retvalPtr = xmlrpc_c::value_boolean(false);
65 if (admins->find(adminInfo.admin, &admin))
67 *retvalPtr = xmlrpc_c::value_boolean(false);
71 const auto tariff = tariffs->FindByName(name);
75 *retvalPtr = xmlrpc_c::value_boolean(false);
79 auto td = tariff->GetTariffData();
81 TARIFF_HELPER helper(td);
83 helper.SetTariffInfo(info);
85 if (tariffs->Chg(td, admin))
87 *retvalPtr = xmlrpc_c::value_boolean(false);
91 *retvalPtr = xmlrpc_c::value_boolean(true);
94 void METHOD_TARIFFS_GET::execute(xmlrpc_c::paramList const & paramList,
95 xmlrpc_c::value * const retvalPtr)
97 std::string cookie = paramList.getString(0);
98 paramList.verifyEnd(1);
100 std::map<std::string, xmlrpc_c::value> structVal;
101 ADMIN_INFO adminInfo;
103 if (config->GetAdminInfo(cookie, &adminInfo))
105 structVal["result"] = xmlrpc_c::value_boolean(false);
106 *retvalPtr = xmlrpc_c::value_struct(structVal);
110 std::vector<xmlrpc_c::value> tariffsInfo;
113 std::vector<STG::TariffData> dataList;
114 tariffs->GetTariffsData(&dataList);
115 auto it = dataList.begin();
116 for (; it != dataList.end(); ++it)
118 xmlrpc_c::value info;
119 auto td = *it; // 'cause TARIFF_HELPER work in both ways and take not const referense
120 TARIFF_HELPER helper(td);
121 helper.GetTariffInfo(&info);
122 tariffsInfo.push_back(info);
125 *retvalPtr = xmlrpc_c::value_array(tariffsInfo);
128 void METHOD_TARIFF_ADD::execute(xmlrpc_c::paramList const & paramList,
129 xmlrpc_c::value * const retvalPtr)
131 std::string cookie = paramList.getString(0);
132 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->find(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->find(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);