1 #include "user_helper.h"
6 //------------------------------------------------------------------------------
8 void USER_HELPER::GetUserInfo(xmlrpc_c::value * info,
13 std::map<std::string, xmlrpc_c::value> structVal;
15 structVal["result"] = xmlrpc_c::value_boolean(true);
16 structVal["login"] = xmlrpc_c::value_string(iter->GetLogin());
20 structVal["password"] = xmlrpc_c::value_string(iter->property.password.Get());
24 structVal["password"] = xmlrpc_c::value_string("++++++++");
27 structVal["cash"] = xmlrpc_c::value_double(iter->property.cash.Get());
28 structVal["freemb"] = xmlrpc_c::value_double(iter->property.freeMb.Get());
29 structVal["credit"] = xmlrpc_c::value_double(iter->property.credit.Get());
31 if (iter->property.nextTariff.Get() != "")
33 structVal["tariff"] = xmlrpc_c::value_string(
34 iter->property.tariffName.Get() +
36 iter->property.nextTariff.Get()
41 structVal["tariff"] = xmlrpc_c::value_string(iter->property.tariffName.Get());
44 structVal["note"] = xmlrpc_c::value_string(IconvString(iter->property.note, "KOI8-R", "UTF-8"));
46 structVal["phone"] = xmlrpc_c::value_string(IconvString(iter->property.phone, "KOI8-R", "UTF-8"));
48 structVal["address"] = xmlrpc_c::value_string(IconvString(iter->property.address, "KOI8-R", "UTF-8"));
50 structVal["email"] = xmlrpc_c::value_string(IconvString(iter->property.email, "KOI8-R", "UTF-8"));
52 std::vector<xmlrpc_c::value> userdata;
54 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata0.Get(), "KOI8-R", "UTF-8")));
55 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata1.Get(), "KOI8-R", "UTF-8")));
56 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata2.Get(), "KOI8-R", "UTF-8")));
57 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata3.Get(), "KOI8-R", "UTF-8")));
58 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata4.Get(), "KOI8-R", "UTF-8")));
59 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata5.Get(), "KOI8-R", "UTF-8")));
60 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata6.Get(), "KOI8-R", "UTF-8")));
61 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata7.Get(), "KOI8-R", "UTF-8")));
62 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata8.Get(), "KOI8-R", "UTF-8")));
63 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata9.Get(), "KOI8-R", "UTF-8")));
65 structVal["userdata"] = xmlrpc_c::value_array(userdata);
67 structVal["name"] = xmlrpc_c::value_string(IconvString(iter->property.realName, "KOI8-R", "UTF-8"));
69 structVal["group"] = xmlrpc_c::value_string(IconvString(iter->property.group, "KOI8-R", "UTF-8"));
71 structVal["status"] = xmlrpc_c::value_boolean(iter->GetConnected());
72 structVal["aonline"] = xmlrpc_c::value_boolean(iter->property.alwaysOnline.Get());
73 structVal["currip"] = xmlrpc_c::value_string(inet_ntostring(iter->GetCurrIP()));
74 structVal["pingtime"] = xmlrpc_c::value_int(iter->GetPingTime());
75 structVal["ips"] = xmlrpc_c::value_string(iter->property.ips.Get().GetIpStr());
77 std::map<std::string, xmlrpc_c::value> traffInfo;
78 std::vector<xmlrpc_c::value> mu(DIR_NUM);
79 std::vector<xmlrpc_c::value> md(DIR_NUM);
80 std::vector<xmlrpc_c::value> su(DIR_NUM);
81 std::vector<xmlrpc_c::value> sd(DIR_NUM);
87 download = iter->property.down.Get();
88 upload = iter->property.up.Get();
89 sdownload = iter->GetSessionUpload();
90 supload = iter->GetSessionDownload();
92 for (int j = 0; j < DIR_NUM; j++)
95 x2str(upload[j], value);
96 mu[j] = xmlrpc_c::value_string(value);
97 x2str(download[j], value);
98 md[j] = xmlrpc_c::value_string(value);
99 x2str(supload[j], value);
100 su[j] = xmlrpc_c::value_string(value);
101 x2str(sdownload[j], value);
102 sd[j] = xmlrpc_c::value_string(value);
105 traffInfo["mu"] = xmlrpc_c::value_array(mu);
106 traffInfo["md"] = xmlrpc_c::value_array(md);
107 traffInfo["su"] = xmlrpc_c::value_array(su);
108 traffInfo["sd"] = xmlrpc_c::value_array(sd);
110 structVal["traff"] = xmlrpc_c::value_struct(traffInfo);
112 structVal["down"] = xmlrpc_c::value_boolean(iter->property.disabled.Get());
113 structVal["disableddetailstat"] = xmlrpc_c::value_boolean(iter->property.disabledDetailStat.Get());
114 structVal["passive"] = xmlrpc_c::value_boolean(iter->property.passive.Get());
115 structVal["lastcash"] = xmlrpc_c::value_double(iter->property.lastCashAdd.Get());
116 structVal["lasttimecash"] = xmlrpc_c::value_int(iter->property.lastCashAddTime.Get());
117 structVal["lastactivitytime"] = xmlrpc_c::value_int(iter->property.lastActivityTime.Get());
118 structVal["creditexpire"] = xmlrpc_c::value_int(iter->property.creditExpire.Get());
120 *info = xmlrpc_c::value_struct(structVal);
123 //------------------------------------------------------------------------------
125 bool USER_HELPER::SetUserInfo(const xmlrpc_c::value & info,
127 const std::string & login,
128 const BASE_STORE & store)
130 std::map<std::string, xmlrpc_c::value> structVal(
131 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
134 std::map<std::string, xmlrpc_c::value>::iterator it;
136 if ((it = structVal.find("password")) != structVal.end())
138 bool res = iter->property.password.Set(xmlrpc_c::value_string(it->second),
148 if ((it = structVal.find("ips")) != structVal.end())
151 ips = StrToIPS(xmlrpc_c::value_string(it->second));
152 bool res = iter->property.ips.Set(ips,
162 if ((it = structVal.find("address")) != structVal.end())
164 bool res = iter->property.address.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
174 if ((it = structVal.find("phone")) != structVal.end())
176 bool res = iter->property.phone.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
186 if ((it = structVal.find("email")) != structVal.end())
188 bool res = iter->property.email.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
198 if ((it = structVal.find("cash")) != structVal.end())
200 bool res = iter->property.cash.Set(xmlrpc_c::value_double(it->second),
210 if ((it = structVal.find("creditexpire")) != structVal.end())
212 bool res = iter->property.creditExpire.Set(xmlrpc_c::value_int(it->second),
222 if ((it = structVal.find("credit")) != structVal.end())
224 bool res = iter->property.credit.Set(xmlrpc_c::value_double(it->second),
234 if ((it = structVal.find("freemb")) != structVal.end())
236 bool res = iter->property.freeMb.Set(xmlrpc_c::value_double(it->second),
246 if ((it = structVal.find("down")) != structVal.end())
248 bool res = iter->property.disabled.Set(xmlrpc_c::value_boolean(it->second),
258 if ((it = structVal.find("passive")) != structVal.end())
260 bool res = iter->property.passive.Set(xmlrpc_c::value_boolean(it->second),
270 if ((it = structVal.find("aonline")) != structVal.end())
272 bool res = iter->property.alwaysOnline.Set(xmlrpc_c::value_boolean(it->second),
282 if ((it = structVal.find("disableddetailstat")) != structVal.end())
284 bool res = iter->property.disabledDetailStat.Set(xmlrpc_c::value_boolean(it->second),
294 if ((it = structVal.find("name")) != structVal.end())
296 bool res = iter->property.realName.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
306 if ((it = structVal.find("group")) != structVal.end())
308 bool res = iter->property.group.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
318 if ((it = structVal.find("note")) != structVal.end())
320 bool res = iter->property.note.Set(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-R"),
330 if ((it = structVal.find("userdata")) != structVal.end())
332 std::vector<USER_PROPERTY_LOGGED<string> *> userdata;
333 userdata.push_back(iter->property.userdata0.GetPointer());
334 userdata.push_back(iter->property.userdata1.GetPointer());
335 userdata.push_back(iter->property.userdata2.GetPointer());
336 userdata.push_back(iter->property.userdata3.GetPointer());
337 userdata.push_back(iter->property.userdata4.GetPointer());
338 userdata.push_back(iter->property.userdata5.GetPointer());
339 userdata.push_back(iter->property.userdata6.GetPointer());
340 userdata.push_back(iter->property.userdata7.GetPointer());
341 userdata.push_back(iter->property.userdata8.GetPointer());
342 userdata.push_back(iter->property.userdata9.GetPointer());
344 std::vector<xmlrpc_c::value> udata(
345 xmlrpc_c::value_array(it->second).vectorValueValue()
348 for (unsigned i = 0; i < userdata.size(); ++i)
350 bool res = userdata[i]->Set(IconvString(xmlrpc_c::value_string(udata[i]), "UTF-8", "KOI8-R"),
361 if ((it = structVal.find("traff")) != structVal.end())
363 std::map<std::string, xmlrpc_c::value> traff(
364 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(it->second))
368 dtData = iter->property.up.Get();
369 if ((it = traff.find("mu")) != traff.end())
371 std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
373 for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
376 if (str2x(xmlrpc_c::value_string(data[i]), value))
378 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month upload value'\n");
385 bool res = iter->property.up.Set(dtData,
394 dtData = iter->property.down.Get();
395 if ((it = traff.find("md")) != traff.end())
397 std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
399 for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
402 if (str2x(xmlrpc_c::value_string(data[i]), value))
404 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month download value'\n");
411 bool res = iter->property.down.Set(dtData,