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,
 
  17 std::map<std::string, xmlrpc_c::value> structVal;
 
  19 structVal["result"] = xmlrpc_c::value_boolean(true);
 
  20 structVal["login"] = xmlrpc_c::value_string(ptr->GetLogin());
 
  24     structVal["password"] = xmlrpc_c::value_string(ptr->GetProperty().password.Get());
 
  28     structVal["password"] = xmlrpc_c::value_string("++++++++");
 
  31 structVal["cash"] = xmlrpc_c::value_double(ptr->GetProperty().cash.Get());
 
  32 structVal["freemb"] = xmlrpc_c::value_double(ptr->GetProperty().freeMb.Get());
 
  33 structVal["credit"] = xmlrpc_c::value_double(ptr->GetProperty().credit.Get());
 
  35 if (ptr->GetProperty().nextTariff.Get() != "")
 
  37     structVal["tariff"] = xmlrpc_c::value_string(
 
  38             ptr->GetProperty().tariffName.Get() +
 
  40             ptr->GetProperty().nextTariff.Get()
 
  45     structVal["tariff"] = xmlrpc_c::value_string(ptr->GetProperty().tariffName.Get());
 
  48 structVal["note"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().note, "KOI8-RU", "UTF-8"));
 
  50 structVal["phone"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().phone, "KOI8-RU", "UTF-8"));
 
  52 structVal["address"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().address, "KOI8-RU", "UTF-8"));
 
  54 structVal["email"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().email, "KOI8-RU", "UTF-8"));
 
  56 std::vector<xmlrpc_c::value> userdata;
 
  58 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata0.Get(), "KOI8-RU", "UTF-8")));
 
  59 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata1.Get(), "KOI8-RU", "UTF-8")));
 
  60 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata2.Get(), "KOI8-RU", "UTF-8")));
 
  61 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata3.Get(), "KOI8-RU", "UTF-8")));
 
  62 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata4.Get(), "KOI8-RU", "UTF-8")));
 
  63 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata5.Get(), "KOI8-RU", "UTF-8")));
 
  64 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata6.Get(), "KOI8-RU", "UTF-8")));
 
  65 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata7.Get(), "KOI8-RU", "UTF-8")));
 
  66 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata8.Get(), "KOI8-RU", "UTF-8")));
 
  67 userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata9.Get(), "KOI8-RU", "UTF-8")));
 
  69 structVal["userdata"] = xmlrpc_c::value_array(userdata);
 
  71 structVal["name"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().realName, "KOI8-RU", "UTF-8"));
 
  73 structVal["group"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().group, "KOI8-RU", "UTF-8"));
 
  75 structVal["status"] = xmlrpc_c::value_boolean(ptr->GetConnected());
 
  76 structVal["aonline"] = xmlrpc_c::value_boolean(ptr->GetProperty().alwaysOnline.Get());
 
  77 structVal["currip"] = xmlrpc_c::value_string(inet_ntostring(ptr->GetCurrIP()));
 
  78 structVal["pingtime"] = xmlrpc_c::value_int(ptr->GetPingTime());
 
  79 structVal["ips"] = xmlrpc_c::value_string(ptr->GetProperty().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 = ptr->GetProperty().down.Get();
 
  92 upload = ptr->GetProperty().up.Get();
 
  93 sdownload = ptr->GetSessionUpload();
 
  94 supload = ptr->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(ptr->GetProperty().disabled.Get());
 
 117 structVal["disableddetailstat"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabledDetailStat.Get());
 
 118 structVal["passive"] = xmlrpc_c::value_boolean(ptr->GetProperty().passive.Get());
 
 119 structVal["lastcash"] = xmlrpc_c::value_double(ptr->GetProperty().lastCashAdd.Get());
 
 120 structVal["lasttimecash"] = xmlrpc_c::value_int(ptr->GetProperty().lastCashAddTime.Get());
 
 121 structVal["lastactivitytime"] = xmlrpc_c::value_int(ptr->GetProperty().lastActivityTime.Get());
 
 122 structVal["creditexpire"] = xmlrpc_c::value_int(ptr->GetProperty().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 (ptr->GetProperty().password.Get() != value)
 
 145         if (!ptr->GetProperty().password.Set(value,
 
 152 if ((it = structVal.find("ips")) != structVal.end())
 
 155     ips = StrToIPS(xmlrpc_c::value_string(it->second));
 
 156     if (!ptr->GetProperty().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 (ptr->GetProperty().address.Get() != value)
 
 167         if (!ptr->GetProperty().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 (ptr->GetProperty().phone.Get() != value)
 
 178         if (!ptr->GetProperty().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 (ptr->GetProperty().email.Get() != value)
 
 189         if (!ptr->GetProperty().email.Set(value,
 
 196 if ((it = structVal.find("cash")) != structVal.end())
 
 198     double value(xmlrpc_c::value_double(it->second));
 
 199     if (ptr->GetProperty().cash.Get() != value)
 
 200         if (!ptr->GetProperty().cash.Set(value,
 
 207 if ((it = structVal.find("creditexpire")) != structVal.end())
 
 209     time_t value(xmlrpc_c::value_int(it->second));
 
 210     if (ptr->GetProperty().creditExpire.Get() != value)
 
 211         if (!ptr->GetProperty().creditExpire.Set(value,
 
 218 if ((it = structVal.find("credit")) != structVal.end())
 
 220     double value(xmlrpc_c::value_double(it->second));
 
 221     if (ptr->GetProperty().credit.Get() != value)
 
 222         if (!ptr->GetProperty().credit.Set(value,
 
 229 if ((it = structVal.find("freemb")) != structVal.end())
 
 231     double value(xmlrpc_c::value_double(it->second));
 
 232     if (ptr->GetProperty().freeMb.Get() != value)
 
 233         if (!ptr->GetProperty().freeMb.Set(value,
 
 240 if ((it = structVal.find("down")) != structVal.end())
 
 242     bool value(xmlrpc_c::value_boolean(it->second));
 
 243     if (ptr->GetProperty().disabled.Get() != value)
 
 244         if (!ptr->GetProperty().disabled.Set(value,
 
 251 if ((it = structVal.find("passive")) != structVal.end())
 
 253     bool value(xmlrpc_c::value_boolean(it->second));
 
 254     if (ptr->GetProperty().passive.Get() != value)
 
 255         if (!ptr->GetProperty().passive.Set(value,
 
 262 if ((it = structVal.find("aonline")) != structVal.end())
 
 264     bool value(xmlrpc_c::value_boolean(it->second));
 
 265     if (ptr->GetProperty().alwaysOnline.Get() != value)
 
 266         if (!ptr->GetProperty().alwaysOnline.Set(value,
 
 273 if ((it = structVal.find("disableddetailstat")) != structVal.end())
 
 275     bool value(xmlrpc_c::value_boolean(it->second));
 
 276     if (ptr->GetProperty().disabledDetailStat.Get() != value)
 
 277         if (!ptr->GetProperty().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 (ptr->GetProperty().realName.Get() != value)
 
 288         if (!ptr->GetProperty().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 (ptr->GetProperty().group.Get() != value)
 
 299         if (!ptr->GetProperty().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 (ptr->GetProperty().note.Get() != value)
 
 310         if (!ptr->GetProperty().note.Set(value,
 
 317 if ((it = structVal.find("userdata")) != structVal.end())
 
 319     std::vector<USER_PROPERTY_LOGGED<string> *> userdata;
 
 320     userdata.push_back(ptr->GetProperty().userdata0.GetPointer());
 
 321     userdata.push_back(ptr->GetProperty().userdata1.GetPointer());
 
 322     userdata.push_back(ptr->GetProperty().userdata2.GetPointer());
 
 323     userdata.push_back(ptr->GetProperty().userdata3.GetPointer());
 
 324     userdata.push_back(ptr->GetProperty().userdata4.GetPointer());
 
 325     userdata.push_back(ptr->GetProperty().userdata5.GetPointer());
 
 326     userdata.push_back(ptr->GetProperty().userdata6.GetPointer());
 
 327     userdata.push_back(ptr->GetProperty().userdata7.GetPointer());
 
 328     userdata.push_back(ptr->GetProperty().userdata8.GetPointer());
 
 329     userdata.push_back(ptr->GetProperty().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 = ptr->GetProperty().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 (!ptr->GetProperty().up.Set(dtData,
 
 373     dtData = ptr->GetProperty().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 (!ptr->GetProperty().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 (ptr->GetProperty().tariffName.Get() != tariff)
 
 407             if (!ptr->GetProperty().tariffName.Set(tariff,
 
 413     if (nextTariff != "" &&
 
 414         tariffs->FindByName(nextTariff))
 
 415         if (ptr->GetProperty().nextTariff.Get() != nextTariff)
 
 416             if (!ptr->GetProperty().nextTariff.Set(tariff,