1 #include "user_helper.h"
9 #include "user_property.h"
11 //------------------------------------------------------------------------------
13 void USER_HELPER::GetUserInfo(xmlrpc_c::value * info,
18 std::map<std::string, xmlrpc_c::value> structVal;
20 structVal["result"] = xmlrpc_c::value_boolean(true);
21 structVal["login"] = xmlrpc_c::value_string(ptr->GetLogin());
25 structVal["password"] = xmlrpc_c::value_string(ptr->GetProperty().password.Get());
29 structVal["password"] = xmlrpc_c::value_string("++++++++");
32 structVal["cash"] = xmlrpc_c::value_double(ptr->GetProperty().cash.Get());
33 structVal["freemb"] = xmlrpc_c::value_double(ptr->GetProperty().freeMb.Get());
34 structVal["credit"] = xmlrpc_c::value_double(ptr->GetProperty().credit.Get());
36 if (ptr->GetProperty().nextTariff.Get() != "")
38 structVal["tariff"] = xmlrpc_c::value_string(
39 ptr->GetProperty().tariffName.Get() +
41 ptr->GetProperty().nextTariff.Get()
46 structVal["tariff"] = xmlrpc_c::value_string(ptr->GetProperty().tariffName.Get());
49 structVal["note"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().note, "KOI8-RU", "UTF-8"));
51 structVal["phone"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().phone, "KOI8-RU", "UTF-8"));
53 structVal["address"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().address, "KOI8-RU", "UTF-8"));
55 structVal["email"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().email, "KOI8-RU", "UTF-8"));
57 std::vector<xmlrpc_c::value> userdata;
59 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata0.Get(), "KOI8-RU", "UTF-8")));
60 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata1.Get(), "KOI8-RU", "UTF-8")));
61 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata2.Get(), "KOI8-RU", "UTF-8")));
62 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata3.Get(), "KOI8-RU", "UTF-8")));
63 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata4.Get(), "KOI8-RU", "UTF-8")));
64 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata5.Get(), "KOI8-RU", "UTF-8")));
65 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata6.Get(), "KOI8-RU", "UTF-8")));
66 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata7.Get(), "KOI8-RU", "UTF-8")));
67 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata8.Get(), "KOI8-RU", "UTF-8")));
68 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata9.Get(), "KOI8-RU", "UTF-8")));
70 structVal["userdata"] = xmlrpc_c::value_array(userdata);
72 structVal["name"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().realName, "KOI8-RU", "UTF-8"));
74 structVal["group"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().group, "KOI8-RU", "UTF-8"));
76 structVal["status"] = xmlrpc_c::value_boolean(ptr->GetConnected());
77 structVal["aonline"] = xmlrpc_c::value_boolean(ptr->GetProperty().alwaysOnline.Get());
78 structVal["currip"] = xmlrpc_c::value_string(inet_ntostring(ptr->GetCurrIP()));
79 structVal["pingtime"] = xmlrpc_c::value_int(ptr->GetPingTime());
80 structVal["ips"] = xmlrpc_c::value_string(ptr->GetProperty().ips.Get().GetIpStr());
82 std::map<std::string, xmlrpc_c::value> traffInfo;
83 std::vector<xmlrpc_c::value> mu(DIR_NUM);
84 std::vector<xmlrpc_c::value> md(DIR_NUM);
85 std::vector<xmlrpc_c::value> su(DIR_NUM);
86 std::vector<xmlrpc_c::value> sd(DIR_NUM);
92 download = ptr->GetProperty().down.Get();
93 upload = ptr->GetProperty().up.Get();
94 sdownload = ptr->GetSessionUpload();
95 supload = ptr->GetSessionDownload();
97 for (int j = 0; j < DIR_NUM; j++)
100 x2str(upload[j], value);
101 mu[j] = xmlrpc_c::value_string(value);
102 x2str(download[j], value);
103 md[j] = xmlrpc_c::value_string(value);
104 x2str(supload[j], value);
105 su[j] = xmlrpc_c::value_string(value);
106 x2str(sdownload[j], value);
107 sd[j] = xmlrpc_c::value_string(value);
110 traffInfo["mu"] = xmlrpc_c::value_array(mu);
111 traffInfo["md"] = xmlrpc_c::value_array(md);
112 traffInfo["su"] = xmlrpc_c::value_array(su);
113 traffInfo["sd"] = xmlrpc_c::value_array(sd);
115 structVal["traff"] = xmlrpc_c::value_struct(traffInfo);
117 structVal["down"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabled.Get());
118 structVal["disableddetailstat"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabledDetailStat.Get());
119 structVal["passive"] = xmlrpc_c::value_boolean(ptr->GetProperty().passive.Get());
120 structVal["lastcash"] = xmlrpc_c::value_double(ptr->GetProperty().lastCashAdd.Get());
121 structVal["lasttimecash"] = xmlrpc_c::value_int(ptr->GetProperty().lastCashAddTime.Get());
122 structVal["lastactivitytime"] = xmlrpc_c::value_int(ptr->GetProperty().lastActivityTime.Get());
123 structVal["creditexpire"] = xmlrpc_c::value_int(ptr->GetProperty().creditExpire.Get());
125 *info = xmlrpc_c::value_struct(structVal);
128 //------------------------------------------------------------------------------
130 bool USER_HELPER::SetUserInfo(const xmlrpc_c::value & info,
132 const std::string & login,
136 std::map<std::string, xmlrpc_c::value> structVal(
137 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
140 std::map<std::string, xmlrpc_c::value>::iterator it;
142 if ((it = structVal.find("password")) != structVal.end())
144 std::string value(xmlrpc_c::value_string(it->second));
145 if (ptr->GetProperty().password.Get() != value)
146 if (!ptr->GetProperty().password.Set(value,
153 if ((it = structVal.find("ips")) != structVal.end())
156 ips = StrToIPS(xmlrpc_c::value_string(it->second));
157 if (!ptr->GetProperty().ips.Set(ips,
164 if ((it = structVal.find("address")) != structVal.end())
166 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
167 if (ptr->GetProperty().address.Get() != value)
168 if (!ptr->GetProperty().address.Set(value,
175 if ((it = structVal.find("phone")) != structVal.end())
177 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
178 if (ptr->GetProperty().phone.Get() != value)
179 if (!ptr->GetProperty().phone.Set(value,
186 if ((it = structVal.find("email")) != structVal.end())
188 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
189 if (ptr->GetProperty().email.Get() != value)
190 if (!ptr->GetProperty().email.Set(value,
197 if ((it = structVal.find("cash")) != structVal.end())
199 double value(xmlrpc_c::value_double(it->second));
200 if (ptr->GetProperty().cash.Get() != value)
201 if (!ptr->GetProperty().cash.Set(value,
208 if ((it = structVal.find("creditexpire")) != structVal.end())
210 time_t value(xmlrpc_c::value_int(it->second));
211 if (ptr->GetProperty().creditExpire.Get() != value)
212 if (!ptr->GetProperty().creditExpire.Set(value,
219 if ((it = structVal.find("credit")) != structVal.end())
221 double value(xmlrpc_c::value_double(it->second));
222 if (ptr->GetProperty().credit.Get() != value)
223 if (!ptr->GetProperty().credit.Set(value,
230 if ((it = structVal.find("freemb")) != structVal.end())
232 double value(xmlrpc_c::value_double(it->second));
233 if (ptr->GetProperty().freeMb.Get() != value)
234 if (!ptr->GetProperty().freeMb.Set(value,
241 if ((it = structVal.find("down")) != structVal.end())
243 bool value(xmlrpc_c::value_boolean(it->second));
244 if (ptr->GetProperty().disabled.Get() != value)
245 if (!ptr->GetProperty().disabled.Set(value,
252 if ((it = structVal.find("passive")) != structVal.end())
254 bool value(xmlrpc_c::value_boolean(it->second));
255 if (ptr->GetProperty().passive.Get() != value)
256 if (!ptr->GetProperty().passive.Set(value,
263 if ((it = structVal.find("aonline")) != structVal.end())
265 bool value(xmlrpc_c::value_boolean(it->second));
266 if (ptr->GetProperty().alwaysOnline.Get() != value)
267 if (!ptr->GetProperty().alwaysOnline.Set(value,
274 if ((it = structVal.find("disableddetailstat")) != structVal.end())
276 bool value(xmlrpc_c::value_boolean(it->second));
277 if (ptr->GetProperty().disabledDetailStat.Get() != value)
278 if (!ptr->GetProperty().disabledDetailStat.Set(value,
285 if ((it = structVal.find("name")) != structVal.end())
287 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
288 if (ptr->GetProperty().realName.Get() != value)
289 if (!ptr->GetProperty().realName.Set(value,
296 if ((it = structVal.find("group")) != structVal.end())
298 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
299 if (ptr->GetProperty().group.Get() != value)
300 if (!ptr->GetProperty().group.Set(value,
307 if ((it = structVal.find("note")) != structVal.end())
309 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
310 if (ptr->GetProperty().note.Get() != value)
311 if (!ptr->GetProperty().note.Set(value,
318 if ((it = structVal.find("userdata")) != structVal.end())
320 std::vector<USER_PROPERTY_LOGGED<string> *> userdata;
321 userdata.push_back(ptr->GetProperty().userdata0.GetPointer());
322 userdata.push_back(ptr->GetProperty().userdata1.GetPointer());
323 userdata.push_back(ptr->GetProperty().userdata2.GetPointer());
324 userdata.push_back(ptr->GetProperty().userdata3.GetPointer());
325 userdata.push_back(ptr->GetProperty().userdata4.GetPointer());
326 userdata.push_back(ptr->GetProperty().userdata5.GetPointer());
327 userdata.push_back(ptr->GetProperty().userdata6.GetPointer());
328 userdata.push_back(ptr->GetProperty().userdata7.GetPointer());
329 userdata.push_back(ptr->GetProperty().userdata8.GetPointer());
330 userdata.push_back(ptr->GetProperty().userdata9.GetPointer());
332 std::vector<xmlrpc_c::value> udata(
333 xmlrpc_c::value_array(it->second).vectorValueValue()
336 for (unsigned i = 0; i < userdata.size(); ++i)
338 std::string value(IconvString(xmlrpc_c::value_string(udata[i]), "UTF-8", "KOI8-RU"));
339 if (userdata[i]->Get() != value)
340 if (!userdata[i]->Set(value,
348 if ((it = structVal.find("traff")) != structVal.end())
350 std::map<std::string, xmlrpc_c::value> traff(
351 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(it->second))
355 dtData = ptr->GetProperty().up.Get();
356 if ((it = traff.find("mu")) != traff.end())
358 std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
360 for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
363 if (str2x(xmlrpc_c::value_string(data[i]), value))
364 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month upload value'\n");
368 if (!ptr->GetProperty().up.Set(dtData,
374 dtData = ptr->GetProperty().down.Get();
375 if ((it = traff.find("md")) != traff.end())
377 std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
379 for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
382 if (str2x(xmlrpc_c::value_string(data[i]), value))
383 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month download value'\n");
387 if (!ptr->GetProperty().down.Set(dtData,
395 if ((it = structVal.find("tariff")) != structVal.end())
397 std::string tariff(xmlrpc_c::value_string(it->second));
398 size_t pos = tariff.find('/');
399 std::string nextTariff;
400 if (pos != std::string::npos)
402 nextTariff = tariff.substr(pos + 1);
403 tariff = tariff.substr(0, pos);
406 if (tariffs->FindByName(tariff))
407 if (ptr->GetProperty().tariffName.Get() != tariff)
408 if (!ptr->GetProperty().tariffName.Set(tariff,
414 if (nextTariff != "" &&
415 tariffs->FindByName(nextTariff))
416 if (ptr->GetProperty().nextTariff.Get() != nextTariff)
417 if (!ptr->GetProperty().nextTariff.Set(tariff,