1 #include "user_helper.h"
10 //------------------------------------------------------------------------------
12 void USER_HELPER::GetUserInfo(xmlrpc_c::value * info,
17 std::map<std::string, xmlrpc_c::value> structVal;
19 structVal["result"] = xmlrpc_c::value_boolean(true);
20 structVal["login"] = xmlrpc_c::value_string(iter->GetLogin());
24 structVal["password"] = xmlrpc_c::value_string(iter->property.password.Get());
28 structVal["password"] = xmlrpc_c::value_string("++++++++");
31 structVal["cash"] = xmlrpc_c::value_double(iter->property.cash.Get());
32 structVal["freemb"] = xmlrpc_c::value_double(iter->property.freeMb.Get());
33 structVal["credit"] = xmlrpc_c::value_double(iter->property.credit.Get());
35 if (iter->property.nextTariff.Get() != "")
37 structVal["tariff"] = xmlrpc_c::value_string(
38 iter->property.tariffName.Get() +
40 iter->property.nextTariff.Get()
45 structVal["tariff"] = xmlrpc_c::value_string(iter->property.tariffName.Get());
48 structVal["note"] = xmlrpc_c::value_string(IconvString(iter->property.note, "KOI8-RU", "UTF-8"));
50 structVal["phone"] = xmlrpc_c::value_string(IconvString(iter->property.phone, "KOI8-RU", "UTF-8"));
52 structVal["address"] = xmlrpc_c::value_string(IconvString(iter->property.address, "KOI8-RU", "UTF-8"));
54 structVal["email"] = xmlrpc_c::value_string(IconvString(iter->property.email, "KOI8-RU", "UTF-8"));
56 std::vector<xmlrpc_c::value> userdata;
58 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata0.Get(), "KOI8-RU", "UTF-8")));
59 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata1.Get(), "KOI8-RU", "UTF-8")));
60 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata2.Get(), "KOI8-RU", "UTF-8")));
61 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata3.Get(), "KOI8-RU", "UTF-8")));
62 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata4.Get(), "KOI8-RU", "UTF-8")));
63 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata5.Get(), "KOI8-RU", "UTF-8")));
64 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata6.Get(), "KOI8-RU", "UTF-8")));
65 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata7.Get(), "KOI8-RU", "UTF-8")));
66 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata8.Get(), "KOI8-RU", "UTF-8")));
67 userdata.push_back(xmlrpc_c::value_string(IconvString(iter->property.userdata9.Get(), "KOI8-RU", "UTF-8")));
69 structVal["userdata"] = xmlrpc_c::value_array(userdata);
71 structVal["name"] = xmlrpc_c::value_string(IconvString(iter->property.realName, "KOI8-RU", "UTF-8"));
73 structVal["group"] = xmlrpc_c::value_string(IconvString(iter->property.group, "KOI8-RU", "UTF-8"));
75 structVal["status"] = xmlrpc_c::value_boolean(iter->GetConnected());
76 structVal["aonline"] = xmlrpc_c::value_boolean(iter->property.alwaysOnline.Get());
77 structVal["currip"] = xmlrpc_c::value_string(inet_ntostring(iter->GetCurrIP()));
78 structVal["pingtime"] = xmlrpc_c::value_int(iter->GetPingTime());
79 structVal["ips"] = xmlrpc_c::value_string(iter->property.ips.Get().GetIpStr());
81 std::map<std::string, xmlrpc_c::value> traffInfo;
82 std::vector<xmlrpc_c::value> mu(DIR_NUM);
83 std::vector<xmlrpc_c::value> md(DIR_NUM);
84 std::vector<xmlrpc_c::value> su(DIR_NUM);
85 std::vector<xmlrpc_c::value> sd(DIR_NUM);
91 download = iter->property.down.Get();
92 upload = iter->property.up.Get();
93 sdownload = iter->GetSessionUpload();
94 supload = iter->GetSessionDownload();
96 for (int j = 0; j < DIR_NUM; j++)
99 x2str(upload[j], value);
100 mu[j] = xmlrpc_c::value_string(value);
101 x2str(download[j], value);
102 md[j] = xmlrpc_c::value_string(value);
103 x2str(supload[j], value);
104 su[j] = xmlrpc_c::value_string(value);
105 x2str(sdownload[j], value);
106 sd[j] = xmlrpc_c::value_string(value);
109 traffInfo["mu"] = xmlrpc_c::value_array(mu);
110 traffInfo["md"] = xmlrpc_c::value_array(md);
111 traffInfo["su"] = xmlrpc_c::value_array(su);
112 traffInfo["sd"] = xmlrpc_c::value_array(sd);
114 structVal["traff"] = xmlrpc_c::value_struct(traffInfo);
116 structVal["down"] = xmlrpc_c::value_boolean(iter->property.disabled.Get());
117 structVal["disableddetailstat"] = xmlrpc_c::value_boolean(iter->property.disabledDetailStat.Get());
118 structVal["passive"] = xmlrpc_c::value_boolean(iter->property.passive.Get());
119 structVal["lastcash"] = xmlrpc_c::value_double(iter->property.lastCashAdd.Get());
120 structVal["lasttimecash"] = xmlrpc_c::value_int(iter->property.lastCashAddTime.Get());
121 structVal["lastactivitytime"] = xmlrpc_c::value_int(iter->property.lastActivityTime.Get());
122 structVal["creditexpire"] = xmlrpc_c::value_int(iter->property.creditExpire.Get());
124 *info = xmlrpc_c::value_struct(structVal);
127 //------------------------------------------------------------------------------
129 bool USER_HELPER::SetUserInfo(const xmlrpc_c::value & info,
131 const std::string & login,
135 std::map<std::string, xmlrpc_c::value> structVal(
136 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
139 std::map<std::string, xmlrpc_c::value>::iterator it;
141 if ((it = structVal.find("password")) != structVal.end())
143 std::string value(xmlrpc_c::value_string(it->second));
144 if (iter->property.password.Get() != value)
145 if (!iter->property.password.Set(value,
152 if ((it = structVal.find("ips")) != structVal.end())
155 ips = StrToIPS(xmlrpc_c::value_string(it->second));
156 if (!iter->property.ips.Set(ips,
163 if ((it = structVal.find("address")) != structVal.end())
165 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
166 if (iter->property.address.Get() != value)
167 if (!iter->property.address.Set(value,
174 if ((it = structVal.find("phone")) != structVal.end())
176 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
177 if (iter->property.phone.Get() != value)
178 if (!iter->property.phone.Set(value,
185 if ((it = structVal.find("email")) != structVal.end())
187 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
188 if (iter->property.email.Get() != value)
189 if (!iter->property.email.Set(value,
196 if ((it = structVal.find("cash")) != structVal.end())
198 double value(xmlrpc_c::value_double(it->second));
199 if (iter->property.cash.Get() != value)
200 if (!iter->property.cash.Set(value,
207 if ((it = structVal.find("creditexpire")) != structVal.end())
209 time_t value(xmlrpc_c::value_int(it->second));
210 if (iter->property.creditExpire.Get() != value)
211 if (!iter->property.creditExpire.Set(value,
218 if ((it = structVal.find("credit")) != structVal.end())
220 double value(xmlrpc_c::value_double(it->second));
221 if (iter->property.credit.Get() != value)
222 if (!iter->property.credit.Set(value,
229 if ((it = structVal.find("freemb")) != structVal.end())
231 double value(xmlrpc_c::value_double(it->second));
232 if (iter->property.freeMb.Get() != value)
233 if (!iter->property.freeMb.Set(value,
240 if ((it = structVal.find("down")) != structVal.end())
242 bool value(xmlrpc_c::value_boolean(it->second));
243 if (iter->property.disabled.Get() != value)
244 if (!iter->property.disabled.Set(value,
251 if ((it = structVal.find("passive")) != structVal.end())
253 bool value(xmlrpc_c::value_boolean(it->second));
254 if (iter->property.passive.Get() != value)
255 if (!iter->property.passive.Set(value,
262 if ((it = structVal.find("aonline")) != structVal.end())
264 bool value(xmlrpc_c::value_boolean(it->second));
265 if (iter->property.alwaysOnline.Get() != value)
266 if (!iter->property.alwaysOnline.Set(value,
273 if ((it = structVal.find("disableddetailstat")) != structVal.end())
275 bool value(xmlrpc_c::value_boolean(it->second));
276 if (iter->property.disabledDetailStat.Get() != value)
277 if (!iter->property.disabledDetailStat.Set(value,
284 if ((it = structVal.find("name")) != structVal.end())
286 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
287 if (iter->property.realName.Get() != value)
288 if (!iter->property.realName.Set(value,
295 if ((it = structVal.find("group")) != structVal.end())
297 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
298 if (iter->property.group.Get() != value)
299 if (!iter->property.group.Set(value,
306 if ((it = structVal.find("note")) != structVal.end())
308 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
309 if (iter->property.note.Get() != value)
310 if (!iter->property.note.Set(value,
317 if ((it = structVal.find("userdata")) != structVal.end())
319 std::vector<USER_PROPERTY_LOGGED<string> *> userdata;
320 userdata.push_back(iter->property.userdata0.GetPointer());
321 userdata.push_back(iter->property.userdata1.GetPointer());
322 userdata.push_back(iter->property.userdata2.GetPointer());
323 userdata.push_back(iter->property.userdata3.GetPointer());
324 userdata.push_back(iter->property.userdata4.GetPointer());
325 userdata.push_back(iter->property.userdata5.GetPointer());
326 userdata.push_back(iter->property.userdata6.GetPointer());
327 userdata.push_back(iter->property.userdata7.GetPointer());
328 userdata.push_back(iter->property.userdata8.GetPointer());
329 userdata.push_back(iter->property.userdata9.GetPointer());
331 std::vector<xmlrpc_c::value> udata(
332 xmlrpc_c::value_array(it->second).vectorValueValue()
335 for (unsigned i = 0; i < userdata.size(); ++i)
337 std::string value(IconvString(xmlrpc_c::value_string(udata[i]), "UTF-8", "KOI8-RU"));
338 if (userdata[i]->Get() != value)
339 if (!userdata[i]->Set(value,
347 if ((it = structVal.find("traff")) != structVal.end())
349 std::map<std::string, xmlrpc_c::value> traff(
350 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(it->second))
354 dtData = iter->property.up.Get();
355 if ((it = traff.find("mu")) != traff.end())
357 std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
359 for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
362 if (str2x(xmlrpc_c::value_string(data[i]), value))
363 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month upload value'\n");
367 if (!iter->property.up.Set(dtData,
373 dtData = iter->property.down.Get();
374 if ((it = traff.find("md")) != traff.end())
376 std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
378 for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
381 if (str2x(xmlrpc_c::value_string(data[i]), value))
382 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month download value'\n");
386 if (!iter->property.down.Set(dtData,
394 if ((it = structVal.find("tariff")) != structVal.end())
396 std::string tariff(xmlrpc_c::value_string(it->second));
397 size_t pos = tariff.find('/');
398 std::string nextTariff;
399 if (pos != std::string::npos)
401 nextTariff = tariff.substr(pos + 1);
402 tariff = tariff.substr(0, pos);
405 if (tariffs->FindByName(tariff))
406 if (iter->property.tariffName.Get() != tariff)
407 if (!iter->property.tariffName.Set(tariff,
413 if (nextTariff != "" &&
414 tariffs->FindByName(nextTariff))
415 if (iter->property.nextTariff.Get() != nextTariff)
416 if (!iter->property.nextTariff.Set(tariff,