1 #include "stg/tariffs.h"
4 #include "stg/user_ips.h"
5 #include "stg/common.h"
6 #include "stg/user_property.h"
7 #include "user_helper.h"
10 //------------------------------------------------------------------------------
12 void USER_HELPER::GetUserInfo(xmlrpc_c::value * info,
15 std::map<std::string, xmlrpc_c::value> structVal;
17 structVal["result"] = xmlrpc_c::value_boolean(true);
18 structVal["login"] = xmlrpc_c::value_string(ptr->GetLogin());
22 structVal["password"] = xmlrpc_c::value_string(ptr->GetProperty().password.Get());
26 structVal["password"] = xmlrpc_c::value_string("++++++++");
29 structVal["cash"] = xmlrpc_c::value_double(ptr->GetProperty().cash.Get());
30 structVal["freemb"] = xmlrpc_c::value_double(ptr->GetProperty().freeMb.Get());
31 structVal["credit"] = xmlrpc_c::value_double(ptr->GetProperty().credit.Get());
33 if (ptr->GetProperty().nextTariff.Get() != "")
35 structVal["tariff"] = xmlrpc_c::value_string(
36 ptr->GetProperty().tariffName.Get() +
38 ptr->GetProperty().nextTariff.Get()
43 structVal["tariff"] = xmlrpc_c::value_string(ptr->GetProperty().tariffName.Get());
46 structVal["note"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().note, "KOI8-RU", "UTF-8"));
48 structVal["phone"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().phone, "KOI8-RU", "UTF-8"));
50 structVal["address"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().address, "KOI8-RU", "UTF-8"));
52 structVal["email"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().email, "KOI8-RU", "UTF-8"));
54 std::vector<xmlrpc_c::value> userdata;
56 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata0.Get(), "KOI8-RU", "UTF-8")));
57 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata1.Get(), "KOI8-RU", "UTF-8")));
58 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata2.Get(), "KOI8-RU", "UTF-8")));
59 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata3.Get(), "KOI8-RU", "UTF-8")));
60 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata4.Get(), "KOI8-RU", "UTF-8")));
61 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata5.Get(), "KOI8-RU", "UTF-8")));
62 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata6.Get(), "KOI8-RU", "UTF-8")));
63 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata7.Get(), "KOI8-RU", "UTF-8")));
64 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata8.Get(), "KOI8-RU", "UTF-8")));
65 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata9.Get(), "KOI8-RU", "UTF-8")));
67 structVal["userdata"] = xmlrpc_c::value_array(userdata);
69 structVal["name"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().realName, "KOI8-RU", "UTF-8"));
71 structVal["group"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().group, "KOI8-RU", "UTF-8"));
73 structVal["status"] = xmlrpc_c::value_boolean(ptr->GetConnected());
74 structVal["aonline"] = xmlrpc_c::value_boolean(ptr->GetProperty().alwaysOnline.Get());
75 structVal["currip"] = xmlrpc_c::value_string(inet_ntostring(ptr->GetCurrIP()));
76 structVal["pingtime"] = xmlrpc_c::value_int(ptr->GetPingTime());
77 structVal["ips"] = xmlrpc_c::value_string(ptr->GetProperty().ips.Get().GetIpStr());
79 std::map<std::string, xmlrpc_c::value> traffInfo;
80 std::vector<xmlrpc_c::value> mu(DIR_NUM);
81 std::vector<xmlrpc_c::value> md(DIR_NUM);
82 std::vector<xmlrpc_c::value> su(DIR_NUM);
83 std::vector<xmlrpc_c::value> sd(DIR_NUM);
89 download = ptr->GetProperty().down.Get();
90 upload = ptr->GetProperty().up.Get();
91 sdownload = ptr->GetSessionUpload();
92 supload = ptr->GetSessionDownload();
94 for (int j = 0; j < DIR_NUM; j++)
97 x2str(upload[j], value);
98 mu[j] = xmlrpc_c::value_string(value);
99 x2str(download[j], value);
100 md[j] = xmlrpc_c::value_string(value);
101 x2str(supload[j], value);
102 su[j] = xmlrpc_c::value_string(value);
103 x2str(sdownload[j], value);
104 sd[j] = xmlrpc_c::value_string(value);
107 traffInfo["mu"] = xmlrpc_c::value_array(mu);
108 traffInfo["md"] = xmlrpc_c::value_array(md);
109 traffInfo["su"] = xmlrpc_c::value_array(su);
110 traffInfo["sd"] = xmlrpc_c::value_array(sd);
112 structVal["traff"] = xmlrpc_c::value_struct(traffInfo);
114 structVal["down"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabled.Get());
115 structVal["disableddetailstat"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabledDetailStat.Get());
116 structVal["passive"] = xmlrpc_c::value_boolean(ptr->GetProperty().passive.Get());
117 structVal["lastcash"] = xmlrpc_c::value_double(ptr->GetProperty().lastCashAdd.Get());
118 structVal["lasttimecash"] = xmlrpc_c::value_int(ptr->GetProperty().lastCashAddTime.Get());
119 structVal["lastactivitytime"] = xmlrpc_c::value_int(ptr->GetProperty().lastActivityTime.Get());
120 structVal["creditexpire"] = xmlrpc_c::value_int(ptr->GetProperty().creditExpire.Get());
122 *info = xmlrpc_c::value_struct(structVal);
125 //------------------------------------------------------------------------------
127 bool USER_HELPER::SetUserInfo(const xmlrpc_c::value & info,
129 const std::string & login,
133 std::map<std::string, xmlrpc_c::value> structVal(
134 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
137 std::map<std::string, xmlrpc_c::value>::iterator it;
139 if ((it = structVal.find("password")) != structVal.end())
141 std::string value(xmlrpc_c::value_string(it->second));
142 if (ptr->GetProperty().password.Get() != value)
143 if (!ptr->GetProperty().password.Set(value,
150 if ((it = structVal.find("ips")) != structVal.end())
153 ips = StrToIPS(xmlrpc_c::value_string(it->second));
154 if (!ptr->GetProperty().ips.Set(ips,
161 if ((it = structVal.find("address")) != structVal.end())
163 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
164 if (ptr->GetProperty().address.Get() != value)
165 if (!ptr->GetProperty().address.Set(value,
172 if ((it = structVal.find("phone")) != structVal.end())
174 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
175 if (ptr->GetProperty().phone.Get() != value)
176 if (!ptr->GetProperty().phone.Set(value,
183 if ((it = structVal.find("email")) != structVal.end())
185 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
186 if (ptr->GetProperty().email.Get() != value)
187 if (!ptr->GetProperty().email.Set(value,
194 if ((it = structVal.find("cash")) != structVal.end())
196 double value(xmlrpc_c::value_double(it->second));
197 if (ptr->GetProperty().cash.Get() != value)
198 if (!ptr->GetProperty().cash.Set(value,
205 if ((it = structVal.find("creditexpire")) != structVal.end())
207 time_t value(xmlrpc_c::value_int(it->second));
208 if (ptr->GetProperty().creditExpire.Get() != value)
209 if (!ptr->GetProperty().creditExpire.Set(value,
216 if ((it = structVal.find("credit")) != structVal.end())
218 double value(xmlrpc_c::value_double(it->second));
219 if (ptr->GetProperty().credit.Get() != value)
220 if (!ptr->GetProperty().credit.Set(value,
227 if ((it = structVal.find("freemb")) != structVal.end())
229 double value(xmlrpc_c::value_double(it->second));
230 if (ptr->GetProperty().freeMb.Get() != value)
231 if (!ptr->GetProperty().freeMb.Set(value,
238 if ((it = structVal.find("down")) != structVal.end())
240 bool value(xmlrpc_c::value_boolean(it->second));
241 if (ptr->GetProperty().disabled.Get() != value)
242 if (!ptr->GetProperty().disabled.Set(value,
249 if ((it = structVal.find("passive")) != structVal.end())
251 bool value(xmlrpc_c::value_boolean(it->second));
252 if (ptr->GetProperty().passive.Get() != value)
253 if (!ptr->GetProperty().passive.Set(value,
260 if ((it = structVal.find("aonline")) != structVal.end())
262 bool value(xmlrpc_c::value_boolean(it->second));
263 if (ptr->GetProperty().alwaysOnline.Get() != value)
264 if (!ptr->GetProperty().alwaysOnline.Set(value,
271 if ((it = structVal.find("disableddetailstat")) != structVal.end())
273 bool value(xmlrpc_c::value_boolean(it->second));
274 if (ptr->GetProperty().disabledDetailStat.Get() != value)
275 if (!ptr->GetProperty().disabledDetailStat.Set(value,
282 if ((it = structVal.find("name")) != structVal.end())
284 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
285 if (ptr->GetProperty().realName.Get() != value)
286 if (!ptr->GetProperty().realName.Set(value,
293 if ((it = structVal.find("group")) != structVal.end())
295 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
296 if (ptr->GetProperty().group.Get() != value)
297 if (!ptr->GetProperty().group.Set(value,
304 if ((it = structVal.find("note")) != structVal.end())
306 std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
307 if (ptr->GetProperty().note.Get() != value)
308 if (!ptr->GetProperty().note.Set(value,
315 if ((it = structVal.find("userdata")) != structVal.end())
317 std::vector<USER_PROPERTY_LOGGED<string> *> userdata;
318 userdata.push_back(ptr->GetProperty().userdata0.GetPointer());
319 userdata.push_back(ptr->GetProperty().userdata1.GetPointer());
320 userdata.push_back(ptr->GetProperty().userdata2.GetPointer());
321 userdata.push_back(ptr->GetProperty().userdata3.GetPointer());
322 userdata.push_back(ptr->GetProperty().userdata4.GetPointer());
323 userdata.push_back(ptr->GetProperty().userdata5.GetPointer());
324 userdata.push_back(ptr->GetProperty().userdata6.GetPointer());
325 userdata.push_back(ptr->GetProperty().userdata7.GetPointer());
326 userdata.push_back(ptr->GetProperty().userdata8.GetPointer());
327 userdata.push_back(ptr->GetProperty().userdata9.GetPointer());
329 std::vector<xmlrpc_c::value> udata(
330 xmlrpc_c::value_array(it->second).vectorValueValue()
333 for (unsigned i = 0; i < userdata.size(); ++i)
335 std::string value(IconvString(xmlrpc_c::value_string(udata[i]), "UTF-8", "KOI8-RU"));
336 if (userdata[i]->Get() != value)
337 if (!userdata[i]->Set(value,
345 if ((it = structVal.find("traff")) != structVal.end())
347 std::map<std::string, xmlrpc_c::value> traff(
348 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(it->second))
352 dtData = ptr->GetProperty().up.Get();
353 if ((it = traff.find("mu")) != traff.end())
355 std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
357 for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
360 if (str2x(xmlrpc_c::value_string(data[i]), value))
361 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month upload value'\n");
365 if (!ptr->GetProperty().up.Set(dtData,
371 dtData = ptr->GetProperty().down.Get();
372 if ((it = traff.find("md")) != traff.end())
374 std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
376 for (int i = 0; i < std::min(DIR_NUM, static_cast<int>(data.size())); ++i)
379 if (str2x(xmlrpc_c::value_string(data[i]), value))
380 printfd(__FILE__, "USER_HELPER::SetUserInfo(): 'Invalid month download value'\n");
384 if (!ptr->GetProperty().down.Set(dtData,
392 if ((it = structVal.find("tariff")) != structVal.end())
394 std::string tariff(xmlrpc_c::value_string(it->second));
395 size_t pos = tariff.find('/');
396 std::string nextTariff;
397 if (pos != std::string::npos)
399 nextTariff = tariff.substr(pos + 1);
400 tariff = tariff.substr(0, pos);
403 if (tariffs->FindByName(tariff))
404 if (ptr->GetProperty().tariffName.Get() != tariff)
405 if (!ptr->GetProperty().tariffName.Set(tariff,
411 if (nextTariff != "" &&
412 tariffs->FindByName(nextTariff))
413 if (ptr->GetProperty().nextTariff.Get() != nextTariff)
414 if (!ptr->GetProperty().nextTariff.Set(tariff,