1 #include "user_helper.h"
10 #include "../../../user_property.h"
12 //------------------------------------------------------------------------------
14 void USER_HELPER::GetUserInfo(xmlrpc_c::value * info,
19 std::map<std::string, xmlrpc_c::value> structVal;
21 structVal["result"] = xmlrpc_c::value_boolean(true);
22 structVal["login"] = xmlrpc_c::value_string(ptr->GetLogin());
26 structVal["password"] = xmlrpc_c::value_string(ptr->GetProperty().password.Get());
30 structVal["password"] = xmlrpc_c::value_string("++++++++");
33 structVal["cash"] = xmlrpc_c::value_double(ptr->GetProperty().cash.Get());
34 structVal["freemb"] = xmlrpc_c::value_double(ptr->GetProperty().freeMb.Get());
35 structVal["credit"] = xmlrpc_c::value_double(ptr->GetProperty().credit.Get());
37 if (ptr->GetProperty().nextTariff.Get() != "")
39 structVal["tariff"] = xmlrpc_c::value_string(
40 ptr->GetProperty().tariffName.Get() +
42 ptr->GetProperty().nextTariff.Get()
47 structVal["tariff"] = xmlrpc_c::value_string(ptr->GetProperty().tariffName.Get());
50 structVal["note"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().note, "KOI8-RU", "UTF-8"));
52 structVal["phone"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().phone, "KOI8-RU", "UTF-8"));
54 structVal["address"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().address, "KOI8-RU", "UTF-8"));
56 structVal["email"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().email, "KOI8-RU", "UTF-8"));
58 std::vector<xmlrpc_c::value> userdata;
60 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata0.Get(), "KOI8-RU", "UTF-8")));
61 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata1.Get(), "KOI8-RU", "UTF-8")));
62 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata2.Get(), "KOI8-RU", "UTF-8")));
63 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata3.Get(), "KOI8-RU", "UTF-8")));
64 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata4.Get(), "KOI8-RU", "UTF-8")));
65 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata5.Get(), "KOI8-RU", "UTF-8")));
66 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata6.Get(), "KOI8-RU", "UTF-8")));
67 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata7.Get(), "KOI8-RU", "UTF-8")));
68 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata8.Get(), "KOI8-RU", "UTF-8")));
69 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata9.Get(), "KOI8-RU", "UTF-8")));
71 structVal["userdata"] = xmlrpc_c::value_array(userdata);
73 structVal["name"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().realName, "KOI8-RU", "UTF-8"));
75 structVal["group"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().group, "KOI8-RU", "UTF-8"));
77 structVal["status"] = xmlrpc_c::value_boolean(ptr->GetConnected());
78 structVal["aonline"] = xmlrpc_c::value_boolean(ptr->GetProperty().alwaysOnline.Get());
79 structVal["currip"] = xmlrpc_c::value_string(inet_ntostring(ptr->GetCurrIP()));
80 structVal["pingtime"] = xmlrpc_c::value_int(ptr->GetPingTime());
81 structVal["ips"] = xmlrpc_c::value_string(ptr->GetProperty().ips.Get().GetIpStr());
83 std::map<std::string, xmlrpc_c::value> traffInfo;
84 std::vector<xmlrpc_c::value> mu(DIR_NUM);
85 std::vector<xmlrpc_c::value> md(DIR_NUM);
86 std::vector<xmlrpc_c::value> su(DIR_NUM);
87 std::vector<xmlrpc_c::value> sd(DIR_NUM);
93 download = ptr->GetProperty().down.Get();
94 upload = ptr->GetProperty().up.Get();
95 sdownload = ptr->GetSessionUpload();
96 supload = ptr->GetSessionDownload();
98 for (int j = 0; j < DIR_NUM; j++)
101 x2str(upload[j], value);
102 mu[j] = xmlrpc_c::value_string(value);
103 x2str(download[j], value);
104 md[j] = xmlrpc_c::value_string(value);
105 x2str(supload[j], value);
106 su[j] = xmlrpc_c::value_string(value);
107 x2str(sdownload[j], value);
108 sd[j] = xmlrpc_c::value_string(value);
111 traffInfo["mu"] = xmlrpc_c::value_array(mu);
112 traffInfo["md"] = xmlrpc_c::value_array(md);
113 traffInfo["su"] = xmlrpc_c::value_array(su);
114 traffInfo["sd"] = xmlrpc_c::value_array(sd);
116 structVal["traff"] = xmlrpc_c::value_struct(traffInfo);
118 structVal["down"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabled.Get());
119 structVal["disableddetailstat"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabledDetailStat.Get());
120 structVal["passive"] = xmlrpc_c::value_boolean(ptr->GetProperty().passive.Get());
121 structVal["lastcash"] = xmlrpc_c::value_double(ptr->GetProperty().lastCashAdd.Get());
122 structVal["lasttimecash"] = xmlrpc_c::value_int(ptr->GetProperty().lastCashAddTime.Get());
123 structVal["lastactivitytime"] = xmlrpc_c::value_int(ptr->GetProperty().lastActivityTime.Get());
124 structVal["creditexpire"] = xmlrpc_c::value_int(ptr->GetProperty().creditExpire.Get());
126 *info = xmlrpc_c::value_struct(structVal);
129 //------------------------------------------------------------------------------
131 bool USER_HELPER::SetUserInfo(const xmlrpc_c::value & info,
133 const std::string & login,
137 std::map<std::string, xmlrpc_c::value> structVal(
138 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
141 std::map<std::string, xmlrpc_c::value>::iterator it;
143 if ((it = structVal.find("password")) != structVal.end())
145 std::string value(xmlrpc_c::value_string(it->second));
146 if (ptr->GetProperty().password.Get() != value)
147 if (!ptr->GetProperty().password.Set(value,
154 if ((it = structVal.find("ips")) != structVal.end())
157 ips = StrToIPS(xmlrpc_c::value_string(it->second));
158 if (!ptr->GetProperty().ips.Set(ips,
165 if ((it = structVal.find("address")) != structVal.end())
167 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
168 if (ptr->GetProperty().address.Get() != value)
169 if (!ptr->GetProperty().address.Set(value,
176 if ((it = structVal.find("phone")) != structVal.end())
178 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
179 if (ptr->GetProperty().phone.Get() != value)
180 if (!ptr->GetProperty().phone.Set(value,
187 if ((it = structVal.find("email")) != structVal.end())
189 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
190 if (ptr->GetProperty().email.Get() != value)
191 if (!ptr->GetProperty().email.Set(value,
198 if ((it = structVal.find("cash")) != structVal.end())
200 double value(xmlrpc_c::value_double(it->second));
201 if (ptr->GetProperty().cash.Get() != value)
202 if (!ptr->GetProperty().cash.Set(value,
209 if ((it = structVal.find("creditexpire")) != structVal.end())
211 time_t value(xmlrpc_c::value_int(it->second));
212 if (ptr->GetProperty().creditExpire.Get() != value)
213 if (!ptr->GetProperty().creditExpire.Set(value,
220 if ((it = structVal.find("credit")) != structVal.end())
222 double value(xmlrpc_c::value_double(it->second));
223 if (ptr->GetProperty().credit.Get() != value)
224 if (!ptr->GetProperty().credit.Set(value,
231 if ((it = structVal.find("freemb")) != structVal.end())
233 double value(xmlrpc_c::value_double(it->second));
234 if (ptr->GetProperty().freeMb.Get() != value)
235 if (!ptr->GetProperty().freeMb.Set(value,
242 if ((it = structVal.find("down")) != structVal.end())
244 bool value(xmlrpc_c::value_boolean(it->second));
245 if (ptr->GetProperty().disabled.Get() != value)
246 if (!ptr->GetProperty().disabled.Set(value,
253 if ((it = structVal.find("passive")) != structVal.end())
255 bool value(xmlrpc_c::value_boolean(it->second));
256 if (ptr->GetProperty().passive.Get() != value)
257 if (!ptr->GetProperty().passive.Set(value,
264 if ((it = structVal.find("aonline")) != structVal.end())
266 bool value(xmlrpc_c::value_boolean(it->second));
267 if (ptr->GetProperty().alwaysOnline.Get() != value)
268 if (!ptr->GetProperty().alwaysOnline.Set(value,
275 if ((it = structVal.find("disableddetailstat")) != structVal.end())
277 bool value(xmlrpc_c::value_boolean(it->second));
278 if (ptr->GetProperty().disabledDetailStat.Get() != value)
279 if (!ptr->GetProperty().disabledDetailStat.Set(value,
286 if ((it = structVal.find("name")) != structVal.end())
288 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
289 if (ptr->GetProperty().realName.Get() != value)
290 if (!ptr->GetProperty().realName.Set(value,
297 if ((it = structVal.find("group")) != structVal.end())
299 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
300 if (ptr->GetProperty().group.Get() != value)
301 if (!ptr->GetProperty().group.Set(value,
308 if ((it = structVal.find("note")) != structVal.end())
310 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
311 if (ptr->GetProperty().note.Get() != value)
312 if (!ptr->GetProperty().note.Set(value,
319 if ((it = structVal.find("userdata")) != structVal.end())
321 std::vector<USER_PROPERTY_LOGGED<string> *> userdata;
322 userdata.push_back(ptr->GetProperty().userdata0.GetPointer());
323 userdata.push_back(ptr->GetProperty().userdata1.GetPointer());
324 userdata.push_back(ptr->GetProperty().userdata2.GetPointer());
325 userdata.push_back(ptr->GetProperty().userdata3.GetPointer());
326 userdata.push_back(ptr->GetProperty().userdata4.GetPointer());
327 userdata.push_back(ptr->GetProperty().userdata5.GetPointer());
328 userdata.push_back(ptr->GetProperty().userdata6.GetPointer());
329 userdata.push_back(ptr->GetProperty().userdata7.GetPointer());
330 userdata.push_back(ptr->GetProperty().userdata8.GetPointer());
331 userdata.push_back(ptr->GetProperty().userdata9.GetPointer());
333 std::vector<xmlrpc_c::value> udata(
334 xmlrpc_c::value_array(it->second).vectorValueValue()
337 for (unsigned i = 0; i < userdata.size(); ++i)
339 std::string value(IconvString(xmlrpc_c::value_string(udata[i]), "UTF-8", "KOI8-RU"));
340 if (userdata[i]->Get() != value)
341 if (!userdata[i]->Set(value,
349 if ((it = structVal.find("traff")) != structVal.end())
351 std::map<std::string, xmlrpc_c::value> traff(
352 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(it->second))
356 dtData = ptr->GetProperty().up.Get();
357 if ((it = traff.find("mu")) != traff.end())
359 std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
361 for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
364 if (str2x(xmlrpc_c::value_string(data[i]), value))
365 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month upload value'\n");
369 if (!ptr->GetProperty().up.Set(dtData,
375 dtData = ptr->GetProperty().down.Get();
376 if ((it = traff.find("md")) != traff.end())
378 std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
380 for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
383 if (str2x(xmlrpc_c::value_string(data[i]), value))
384 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month download value'\n");
388 if (!ptr->GetProperty().down.Set(dtData,
396 if ((it = structVal.find("tariff")) != structVal.end())
398 std::string tariff(xmlrpc_c::value_string(it->second));
399 size_t pos = tariff.find('/');
400 std::string nextTariff;
401 if (pos != std::string::npos)
403 nextTariff = tariff.substr(pos + 1);
404 tariff = tariff.substr(0, pos);
407 if (tariffs->FindByName(tariff))
408 if (ptr->GetProperty().tariffName.Get() != tariff)
409 if (!ptr->GetProperty().tariffName.Set(tariff,
415 if (nextTariff != "" &&
416 tariffs->FindByName(nextTariff))
417 if (ptr->GetProperty().nextTariff.Get() != nextTariff)
418 if (!ptr->GetProperty().nextTariff.Set(tariff,