4 #include <sys/utsname.h>
6 #include <sys/socket.h>
7 #include <netinet/in.h>
14 #define UNAME_LEN (256)
15 //-----------------------------------------------------------------------------
17 //-----------------------------------------------------------------------------
18 int PARSER_GET_SERVER_INFO::ParseStart(void *, const char *el, const char **)
20 answerList->erase(answerList->begin(), answerList->end());
21 if (strcasecmp(el, "GetServerInfo") == 0)
27 //-----------------------------------------------------------------------------
28 int PARSER_GET_SERVER_INFO::ParseEnd(void *, const char *el)
30 if (strcasecmp(el, "GetServerInfo") == 0)
37 //-----------------------------------------------------------------------------
38 void PARSER_GET_SERVER_INFO::CreateAnswer()
40 char s[UNAME_LEN + 128];
47 strcat(un, utsn.sysname);
49 strcat(un, utsn.release);
51 strcat(un, utsn.machine);
53 strcat(un, utsn.nodename);
55 //answerList->clear();
56 answerList->erase(answerList->begin(), answerList->end());
57 answerList->push_back("<ServerInfo>");
59 sprintf(s, "<version value=\"%s\"/>", SERVER_VERSION);
60 answerList->push_back(s);
62 sprintf(s, "<tariff_num value=\"%d\"/>", tariffs->GetTariffsNum());
63 answerList->push_back(s);
65 sprintf(s, "<tariff value=\"%d\"/>", 2);
66 answerList->push_back(s);
68 sprintf(s, "<users_num value=\"%d\"/>", users->GetUserNum());
69 answerList->push_back(s);
71 sprintf(s, "<uname value=\"%s\"/>", un);
72 answerList->push_back(s);
74 sprintf(s, "<dir_num value=\"%d\"/>", DIR_NUM);
75 answerList->push_back(s);
77 sprintf(s, "<day_fee value=\"%d\"/>", settings->GetDayFee());
78 answerList->push_back(s);
80 for (int i = 0; i< DIR_NUM; i++)
83 Encode12str(dn2e, settings->GetDirName(i));
84 sprintf(s, "<dir_name_%d value=\"%s\"/>", i, dn2e.c_str());
85 answerList->push_back(s);
88 answerList->push_back("</ServerInfo>");
90 //-----------------------------------------------------------------------------
92 //-----------------------------------------------------------------------------
93 PARSER_GET_USER::PARSER_GET_USER()
97 //-----------------------------------------------------------------------------
98 int PARSER_GET_USER::ParseStart(void *, const char *el, const char **attr)
100 if (strcasecmp(el, "GetUser") == 0)
102 if (attr[0] && attr[1])
107 login.erase(login.begin(), login.end());
114 //-----------------------------------------------------------------------------
115 int PARSER_GET_USER::ParseEnd(void *, const char *el)
117 if (strcasecmp(el, "GetUser") == 0)
124 //-----------------------------------------------------------------------------
125 void PARSER_GET_USER::CreateAnswer()
132 answerList->erase(answerList->begin(), answerList->end());
134 if (users->FindByName(login, &u))
136 s = "<user result=\"error\"/>";
137 answerList->push_back(s);
141 s = "<user result=\"ok\">";
142 answerList->push_back(s);
144 s = "<login value=\"" + u->GetLogin() + "\"/>";
145 answerList->push_back(s);
147 if (currAdmin.GetPriv()->userConf || currAdmin.GetPriv()->userPasswd)
148 s = "<password value=\"" + u->property.password.Get() + "\" />";
150 s = "<password value=\"++++++\"/>";
151 answerList->push_back(s);
153 strprintf(&s, "<cash value=\"%f\" />", u->property.cash.Get());
154 answerList->push_back(s);
156 strprintf(&s, "<freemb value=\"%f\" />", u->property.freeMb.Get());
157 answerList->push_back(s);
159 strprintf(&s, "<credit value=\"%f\" />", u->property.credit.Get());
160 answerList->push_back(s);
162 if (u->property.nextTariff.Get() != "")
164 strprintf(&s, "<tariff value=\"%s/%s\" />",
165 u->property.tariffName.Get().c_str(),
166 u->property.nextTariff.Get().c_str());
170 strprintf(&s, "<tariff value=\"%s\" />",
171 u->property.tariffName.Get().c_str());
174 answerList->push_back(s);
176 Encode12str(enc, u->property.note);
177 s = "<note value=\"" + enc + "\" />";
178 answerList->push_back(s);
180 Encode12str(enc, u->property.phone);
181 s = "<phone value=\"" + enc + "\" />";
182 answerList->push_back(s);
184 Encode12str(enc, u->property.address);
185 s = "<address value=\"" + enc + "\" />";
186 answerList->push_back(s);
188 Encode12str(enc, u->property.email);
189 s = "<email value=\"" + enc + "\" />";
190 answerList->push_back(s);
193 vector<USER_PROPERTY_LOGGED<string> *> userdata;
194 userdata.push_back(u->property.userdata0.GetPointer());
195 userdata.push_back(u->property.userdata1.GetPointer());
196 userdata.push_back(u->property.userdata2.GetPointer());
197 userdata.push_back(u->property.userdata3.GetPointer());
198 userdata.push_back(u->property.userdata4.GetPointer());
199 userdata.push_back(u->property.userdata5.GetPointer());
200 userdata.push_back(u->property.userdata6.GetPointer());
201 userdata.push_back(u->property.userdata7.GetPointer());
202 userdata.push_back(u->property.userdata8.GetPointer());
203 userdata.push_back(u->property.userdata9.GetPointer());
206 for (unsigned i = 0; i < userdata.size(); i++)
208 Encode12str(enc, userdata[i]->Get());
209 s = "<UserData" + x2str(i, tmpI) + " value=\"" + enc + "\" />";
210 answerList->push_back(s);
213 Encode12str(enc, u->property.realName);
214 s = "<name value=\"" + enc + "\" />";
215 answerList->push_back(s);
217 Encode12str(enc, u->property.group);
218 s = "<GROUP value=\"" + enc + "\" />";
219 answerList->push_back(s);
221 strprintf(&s, "<status value=\"%d\" />", u->GetConnected());
222 answerList->push_back(s);
224 strprintf(&s, "<aonline value=\"%d\" />", u->property.alwaysOnline.Get());
225 answerList->push_back(s);
227 strprintf(&s, "<currip value=\"%s\" />", inet_ntostring(u->GetCurrIP()).c_str());
228 answerList->push_back(s);
230 strprintf(&s, "<PingTime value=\"%lu\" />", u->GetPingTime());
231 answerList->push_back(s);
234 sstr << u->property.ips.Get();
235 strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
236 answerList->push_back(s);
239 ss = new char[DIR_NUM*25*4 + 50];
241 sprintf(ss, "<traff");
244 download = u->property.down.Get();
245 upload = u->property.up.Get();
247 for (int j = 0; j < DIR_NUM; j++)
251 sprintf(st, " MU%d=\"%s\"", j, s.c_str());
254 x2str(download[j], s);
255 sprintf(st, " MD%d=\"%s\"", j, s.c_str());
258 sprintf(st, " SU%d=\"0\"", j);
261 sprintf(st, " SD%d=\"0\"", j);
265 answerList->push_back(ss);
268 strprintf(&s, "<down value=\"%d\" />", u->property.disabled.Get());
269 answerList->push_back(s);
271 strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->property.disabledDetailStat.Get());
272 answerList->push_back(s);
274 strprintf(&s, "<passive value=\"%d\" />", u->property.passive.Get());
275 answerList->push_back(s);
277 strprintf(&s, "<LastCash value=\"%f\" />", u->property.lastCashAdd.Get());
278 answerList->push_back(s);
280 strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->property.lastCashAddTime.Get());
281 answerList->push_back(s);
283 strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->property.lastActivityTime.Get());
284 answerList->push_back(s);
286 strprintf(&s, "<CreditExpire value=\"%ld\" />", u->property.creditExpire.Get());
287 answerList->push_back(s);
289 strprintf(&s, "</user>");
290 answerList->push_back(s);
292 //-----------------------------------------------------------------------------
294 //-----------------------------------------------------------------------------
295 PARSER_GET_USERS::PARSER_GET_USERS()
296 : lastUserUpdateTime(0),
297 lastUpdateFound(false)
300 //-----------------------------------------------------------------------------
301 int PARSER_GET_USERS::ParseStart(void *, const char *el, const char ** attr)
303 /*if (attr && *attr && *(attr+1))
305 printfd(__FILE__, "attr=%s %s\n", *attr, *(attr+1));
309 printfd(__FILE__, "attr = NULL\n");
312 lastUpdateFound = false;
313 if (strcasecmp(el, "GetUsers") == 0)
315 while (attr && *attr && *(attr+1))
317 if (strcasecmp(*attr, "LastUpdate") == 0)
319 if (str2x(*(attr+1), lastUserUpdateTime) == 0)
321 //printfd(__FILE__, "lastUserUpdateTime=%d\n", lastUserUpdateTime);
322 lastUpdateFound = true;
326 //printfd(__FILE__, "NO lastUserUpdateTime\n");
336 //-----------------------------------------------------------------------------
337 int PARSER_GET_USERS::ParseEnd(void *, const char *el)
339 if (strcasecmp(el, "GetUsers") == 0)
346 //-----------------------------------------------------------------------------
347 void PARSER_GET_USERS::CreateAnswer()
349 answerList->erase(answerList->begin(), answerList->end());
364 int h = users->OpenSearch();
367 printfd(__FILE__, "users->OpenSearch() error\n");
368 users->CloseSearch(h);
372 x2str(time(NULL), updateTime);
375 answerList->push_back("<Users LastUpdate=\"" + updateTime + "\">");
377 answerList->push_back("<Users>");
381 if (users->SearchNext(h, &u))
385 userStart = "<user login=\"" + u->GetLogin() + "\">";
388 if (u->property.password.ModificationTime() > lastUserUpdateTime)
390 if (currAdmin.GetPriv()->userConf || currAdmin.GetPriv()->userPasswd)
391 s = "<password value=\"" + u->property.password.Get() + "\" />";
393 s = "<password value=\"++++++\"/>";
398 if (u->property.cash.ModificationTime() > lastUserUpdateTime)
400 strprintf(&s, "<cash value=\"%f\" />", u->property.cash.Get());
402 //printfd(__FILE__, "cash value=\"%f\"\n", u->property.cash.Get());
406 if (u->property.freeMb.ModificationTime() > lastUserUpdateTime)
408 strprintf(&s, "<freemb value=\"%f\" />", u->property.freeMb.Get());
412 if (u->property.credit.ModificationTime() > lastUserUpdateTime)
414 strprintf(&s, "<credit value=\"%f\" />", u->property.credit.Get());
418 if (u->property.nextTariff.Get() != "")
420 if (u->property.tariffName.ModificationTime() > lastUserUpdateTime
421 || u->property.nextTariff.ModificationTime() > lastUserUpdateTime)
423 strprintf(&s, "<tariff value=\"%s/%s\" />",
424 u->property.tariffName.Get().c_str(),
425 u->property.nextTariff.Get().c_str());
431 if (u->property.tariffName.ModificationTime() > lastUserUpdateTime)
433 strprintf(&s, "<tariff value=\"%s\" />",
434 u->property.tariffName.Get().c_str());
439 if (u->property.note.ModificationTime() > lastUserUpdateTime)
441 Encode12str(enc, u->property.note);
442 strprintf(&s, "<note value=\"%s\" />", enc.c_str());
446 if (u->property.phone.ModificationTime() > lastUserUpdateTime)
448 Encode12str(enc, u->property.phone);
449 strprintf(&s, "<phone value=\"%s\" />", enc.c_str());
453 if (u->property.address.ModificationTime() > lastUserUpdateTime)
455 Encode12str(enc, u->property.address);
456 strprintf(&s, "<address value=\"%s\" />", enc.c_str());
460 if (u->property.email.ModificationTime() > lastUserUpdateTime)
462 Encode12str(enc, u->property.email);
463 strprintf(&s, "<email value=\"%s\" />", enc.c_str());
467 vector<USER_PROPERTY_LOGGED<string> *> userdata;
468 userdata.push_back(u->property.userdata0.GetPointer());
469 userdata.push_back(u->property.userdata1.GetPointer());
470 userdata.push_back(u->property.userdata2.GetPointer());
471 userdata.push_back(u->property.userdata3.GetPointer());
472 userdata.push_back(u->property.userdata4.GetPointer());
473 userdata.push_back(u->property.userdata5.GetPointer());
474 userdata.push_back(u->property.userdata6.GetPointer());
475 userdata.push_back(u->property.userdata7.GetPointer());
476 userdata.push_back(u->property.userdata8.GetPointer());
477 userdata.push_back(u->property.userdata9.GetPointer());
480 for (unsigned i = 0; i < userdata.size(); i++)
482 if (userdata[i]->ModificationTime() > lastUserUpdateTime)
484 Encode12str(enc, userdata[i]->Get());
485 s = "<UserData" + x2str(i, tmpI) + " value=\"" + enc + "\" />";
490 if (u->property.realName.ModificationTime() > lastUserUpdateTime)
492 Encode12str(enc, u->property.realName);
493 strprintf(&s, "<name value=\"%s\" />", enc.c_str());
497 if (u->property.group.ModificationTime() > lastUserUpdateTime)
499 Encode12str(enc, u->property.group);
500 strprintf(&s, "<GROUP value=\"%s\" />", enc.c_str());
504 if (u->property.alwaysOnline.ModificationTime() > lastUserUpdateTime)
506 strprintf(&s, "<aonline value=\"%d\" />", u->property.alwaysOnline.Get());
510 if (u->GetCurrIPModificationTime() > lastUserUpdateTime)
512 strprintf(&s, "<currip value=\"%s\" />", inet_ntostring(u->GetCurrIP()).c_str());
517 if (u->GetConnectedModificationTime() > lastUserUpdateTime)
519 strprintf(&s, "<status value=\"%d\" />", u->GetConnected());
523 if (u->GetPingTime() > lastUserUpdateTime)
525 strprintf(&s, "<PingTime value=\"%lu\" />", u->GetPingTime());
529 if (u->property.ips.ModificationTime() > lastUserUpdateTime)
532 sstr << u->property.ips.Get();
533 strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
538 traffStart = "<traff";
541 download = u->property.down.Get();
542 upload = u->property.up.Get();
545 if (u->property.up.ModificationTime() > lastUserUpdateTime)
547 for (int j = 0; j < DIR_NUM; j++)
551 sprintf(st, " MU%d=\"%s\" ", j, s.c_str());
556 if (u->property.down.ModificationTime() > lastUserUpdateTime)
558 for (int j = 0; j < DIR_NUM; j++)
560 x2str(download[j], s);
561 sprintf(st, " MD%d=\"%s\" ", j, s.c_str());
567 if (traffMiddle.length() > 0)
569 middle += traffStart;
570 middle += traffMiddle;
571 middle += traffFinish;
574 if (u->property.disabled.ModificationTime() > lastUserUpdateTime)
576 strprintf(&s, "<down value=\"%d\" />", u->property.disabled.Get());
580 if (u->property.disabledDetailStat.ModificationTime() > lastUserUpdateTime)
582 strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->property.disabledDetailStat.Get());
586 //printfd(__FILE__, ">>>>> %s\n", s.c_str());
588 if (u->property.passive.ModificationTime() > lastUserUpdateTime)
590 strprintf(&s, "<passive value=\"%d\" />", u->property.passive.Get());
594 if (u->property.lastCashAdd.ModificationTime() > lastUserUpdateTime)
596 strprintf(&s, "<LastCash value=\"%f\" />", u->property.lastCashAdd.Get());
600 if (u->property.lastCashAddTime.ModificationTime() > lastUserUpdateTime)
602 strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->property.lastCashAddTime.Get());
607 if (u->property.lastActivityTime.ModificationTime() > lastUserUpdateTime)
609 strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->property.lastActivityTime.Get());
613 if (u->property.creditExpire.ModificationTime() > lastUserUpdateTime)
615 strprintf(&s, "<CreditExpire value=\"%ld\" />", u->property.creditExpire.Get());
620 userFinish = "</user>";
622 if (middle.length() > 0)
624 /*printfd(__FILE__, "login: %s\n", u->GetLogin().c_str());
625 printfd(__FILE__, "middle: %s\n", middle.c_str());*/
627 answerList->push_back(userStart);
628 answerList->push_back(middle);
629 answerList->push_back(userFinish);
633 users->CloseSearch(h);
635 //answerList->push_back("</Users>");
637 answerList->push_back("</Users>");
639 //-----------------------------------------------------------------------------
641 //-----------------------------------------------------------------------------
642 PARSER_ADD_USER::PARSER_ADD_USER()
646 //-----------------------------------------------------------------------------
647 int PARSER_ADD_USER::ParseStart(void *, const char *el, const char **attr)
653 if (strcasecmp(el, "AddUser") == 0)
660 if (strcasecmp(el, "login") == 0)
668 //-----------------------------------------------------------------------------
669 int PARSER_ADD_USER::ParseEnd(void *, const char *el)
673 if (strcasecmp(el, "AddUser") == 0)
684 //-----------------------------------------------------------------------------
685 void PARSER_ADD_USER::Reset()
687 BASE_PARSER::Reset();
690 //-----------------------------------------------------------------------------
691 void PARSER_ADD_USER::CreateAnswer()
693 //answerList->clear();
694 answerList->erase(answerList->begin(), answerList->end());
696 if (CheckUserData() == 0)
698 answerList->push_back("<AddUser result=\"ok\"/>");
702 answerList->push_back("<AddUser result=\"error\" reason=\"Access denied\"/>");
705 //-----------------------------------------------------------------------------
706 int PARSER_ADD_USER::CheckUserData()
709 if (users->FindByName(login, &u))
711 return users->Add(login, currAdmin);
715 //-----------------------------------------------------------------------------
717 //-----------------------------------------------------------------------------
718 PARSER_CHG_USER::PARSER_CHG_USER()
723 cashMustBeAdded(false),
728 //-----------------------------------------------------------------------------
729 PARSER_CHG_USER::~PARSER_CHG_USER()
736 //-----------------------------------------------------------------------------
737 void PARSER_CHG_USER::Reset()
748 usr = new USER_STAT_RES;
749 ucr = new USER_CONF_RES;
751 upr = new RESETABLE<uint64_t>[DIR_NUM];
752 downr = new RESETABLE<uint64_t>[DIR_NUM];
754 //-----------------------------------------------------------------------------
755 string PARSER_CHG_USER::EncChar2String(const char * strEnc)
758 Decode21str(str, strEnc);
761 //-----------------------------------------------------------------------------
762 int PARSER_CHG_USER::ParseStart(void *, const char *el, const char **attr)
768 if (strcasecmp(el, "SetUser") == 0)
775 //printfd(__FILE__, "el=%s\n", el);
776 if (strcasecmp(el, "login") == 0)
782 if (strcasecmp(el, "ip") == 0)
786 ucr->ips = StrToIPS(attr[1]);
790 printfd(__FILE__, "StrToIPS Error!\n");
794 if (strcasecmp(el, "password") == 0)
796 ucr->password = attr[1];
800 if (strcasecmp(el, "address") == 0)
802 ucr->address = EncChar2String(attr[1]);
806 if (strcasecmp(el, "aonline") == 0)
808 ucr->alwaysOnline = (*(attr[1]) != '0');
812 if (strcasecmp(el, "cash") == 0)
814 if (attr[2] && (strcasecmp(attr[2], "msg") == 0))
816 cashMsg = EncChar2String(attr[3]);
820 if (strtodouble2(attr[1], cash) == 0)
823 if (strcasecmp(attr[0], "set") == 0)
824 cashMustBeAdded = false;
826 if (strcasecmp(attr[0], "add") == 0)
827 cashMustBeAdded = true;
832 if (strcasecmp(el, "CreditExpire") == 0)
834 long int creditExpire = 0;
835 if (str2x(attr[1], creditExpire) == 0)
836 ucr->creditExpire = (time_t)creditExpire;
841 if (strcasecmp(el, "credit") == 0)
844 if (strtodouble2(attr[1], credit) == 0)
845 ucr->credit = credit;
849 if (strcasecmp(el, "freemb") == 0)
852 if (strtodouble2(attr[1], freeMb) == 0)
853 usr->freeMb = freeMb;
857 if (strcasecmp(el, "down") == 0)
860 if (str2x(attr[1], down) == 0)
861 ucr->disabled = down;
865 if (strcasecmp(el, "DisableDetailStat") == 0)
867 int disabledDetailStat = 0;
868 if (str2x(attr[1], disabledDetailStat) == 0)
869 ucr->disabledDetailStat = disabledDetailStat;
873 if (strcasecmp(el, "email") == 0)
875 ucr->email = EncChar2String(attr[1]);
879 for (int i = 0; i < USERDATA_NUM; i++)
882 sprintf(name, "userdata%d", i);
883 if (strcasecmp(el, name) == 0)
885 ucr->userdata[i] = EncChar2String(attr[1]);
890 if (strcasecmp(el, "group") == 0)
892 ucr->group = EncChar2String(attr[1]);
896 if (strcasecmp(el, "note") == 0)
898 ucr->note = EncChar2String(attr[1]);
902 if (strcasecmp(el, "passive") == 0)
905 if (str2x(attr[1], passive) == 0)
906 ucr->passive = passive;
910 if (strcasecmp(el, "phone") == 0)
912 ucr->phone = EncChar2String(attr[1]);
916 if (strcasecmp(el, "Name") == 0)
918 ucr->realName = EncChar2String(attr[1]);
922 if (strcasecmp(el, "traff") == 0)
928 unsigned long long t = 0;
931 dir = attr[j][2] - '0';
933 if (strncasecmp(attr[j], "md", 2) == 0)
939 if (strncasecmp(attr[j], "mu", 2) == 0)
952 if (strcasecmp(el, "tariff") == 0)
954 if (strcasecmp(attr[0], "now") == 0)
955 ucr->tariffName = attr[1];
957 if (strcasecmp(attr[0], "delayed") == 0)
958 ucr->nextTariff = attr[1];
965 //-----------------------------------------------------------------------------
966 int PARSER_CHG_USER::ParseEnd(void *, const char *el)
970 if (strcasecmp(el, "SetUser") == 0)
982 //-----------------------------------------------------------------------------
983 void PARSER_CHG_USER::CreateAnswer()
985 //answerList->clear();
986 answerList->erase(answerList->begin(), answerList->end());
991 answerList->push_back("<SetUser result=\"ok\"/>");
994 answerList->push_back("<SetUser result=\"error\"/>");
997 answerList->push_back("<SetUser result=\"error\"/>");
1000 answerList->push_back("<SetUser result=\"error\"/>");
1005 //-----------------------------------------------------------------------------
1006 int PARSER_CHG_USER::CheckUserData()
1010 //-----------------------------------------------------------------------------
1011 int PARSER_CHG_USER::AplayChanges()
1016 if (users->FindByName(login, &u))
1022 if (!ucr->ips.res_empty())
1023 if (!u->property.ips.Set(ucr->ips.const_data(), currAdmin, login, store))
1026 if (!ucr->address.res_empty())
1027 if (!u->property.address.Set(ucr->address.const_data(), currAdmin, login, store))
1030 if (!ucr->alwaysOnline.res_empty())
1031 if (!u->property.alwaysOnline.Set(ucr->alwaysOnline.const_data(),
1032 currAdmin, login, store))
1035 if (!ucr->creditExpire.res_empty())
1036 if (!u->property.creditExpire.Set(ucr->creditExpire.const_data(),
1037 currAdmin, login, store))
1040 if (!ucr->credit.res_empty())
1041 if (!u->property.credit.Set(ucr->credit.const_data(), currAdmin, login, store))
1044 if (!usr->freeMb.res_empty())
1045 if (!u->property.freeMb.Set(usr->freeMb.const_data(), currAdmin, login, store))
1048 if (!ucr->disabled.res_empty())
1049 if (!u->property.disabled.Set(ucr->disabled.const_data(), currAdmin, login, store))
1052 if (!ucr->disabledDetailStat.res_empty())
1053 if (!u->property.disabledDetailStat.Set(ucr->disabledDetailStat.const_data(), currAdmin, login, store))
1056 if (!ucr->email.res_empty())
1057 if (!u->property.email.Set(ucr->email.const_data(), currAdmin, login, store))
1060 if (!ucr->group.res_empty())
1061 if (!u->property.group.Set(ucr->group.const_data(), currAdmin, login, store))
1064 if (!ucr->note.res_empty())
1065 if (!u->property.note.Set(ucr->note.const_data(), currAdmin, login, store))
1068 vector<USER_PROPERTY_LOGGED<string> *> userdata;
1069 userdata.push_back(u->property.userdata0.GetPointer());
1070 userdata.push_back(u->property.userdata1.GetPointer());
1071 userdata.push_back(u->property.userdata2.GetPointer());
1072 userdata.push_back(u->property.userdata3.GetPointer());
1073 userdata.push_back(u->property.userdata4.GetPointer());
1074 userdata.push_back(u->property.userdata5.GetPointer());
1075 userdata.push_back(u->property.userdata6.GetPointer());
1076 userdata.push_back(u->property.userdata7.GetPointer());
1077 userdata.push_back(u->property.userdata8.GetPointer());
1078 userdata.push_back(u->property.userdata9.GetPointer());
1080 for (int i = 0; i < (int)userdata.size(); i++)
1082 if (!ucr->userdata[i].res_empty())
1084 if(!userdata[i]->Set(ucr->userdata[i].const_data(), currAdmin, login, store))
1089 if (!ucr->passive.res_empty())
1090 if (!u->property.passive.Set(ucr->passive.const_data(), currAdmin, login, store))
1093 if (!ucr->password.res_empty())
1094 if (!u->property.password.Set(ucr->password.const_data(), currAdmin, login, store))
1097 if (!ucr->phone.res_empty())
1098 if (!u->property.phone.Set(ucr->phone.const_data(), currAdmin, login, store))
1101 if (!ucr->realName.res_empty())
1102 if (!u->property.realName.Set(ucr->realName.const_data(), currAdmin, login, store))
1106 if (!usr->cash.res_empty())
1108 //if (currAdmin->GetPriv()->userCash)
1110 if (cashMustBeAdded)
1112 if (!u->property.cash.Set(usr->cash.const_data() + u->property.cash,
1121 if (!u->property.cash.Set(usr->cash.const_data(), currAdmin, login, store, cashMsg))
1128 if (!ucr->tariffName.res_empty())
1130 if (tariffs->FindByName(ucr->tariffName.const_data()))
1132 if (!u->property.tariffName.Set(ucr->tariffName.const_data(), currAdmin, login, store))
1134 u->ResetNextTariff();
1138 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
1143 if (!ucr->nextTariff.res_empty())
1145 if (tariffs->FindByName(ucr->nextTariff.const_data()))
1147 if (!u->property.nextTariff.Set(ucr->nextTariff.const_data(), currAdmin, login, store))
1152 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
1157 DIR_TRAFF up = u->property.up;
1158 DIR_TRAFF down = u->property.down;
1161 for (int i = 0; i < DIR_NUM; i++)
1163 if (!upr[i].res_empty())
1168 if (!downr[i].res_empty())
1176 if (!u->property.up.Set(up, currAdmin, login, store))
1180 if (!u->property.down.Set(down, currAdmin, login, store))
1183 /*if (!usr->down.res_empty())
1185 u->property.down.Set(usr->down.const_data(), currAdmin, login, store);
1187 if (!usr->up.res_empty())
1189 u->property.up.Set(usr->up.const_data(), currAdmin, login, store);
1197 //-----------------------------------------------------------------------------
1199 //-----------------------------------------------------------------------------
1200 int PARSER_SEND_MESSAGE::ParseStart(void *, const char *el, const char **attr)
1202 if (strcasecmp(el, "Message") == 0)
1204 for (int i = 0; i < 14; i++)
1206 if (attr[i] == NULL)
1208 result = res_params_error;
1210 printfd(__FILE__, "To few parameters\n");
1215 for (int i = 0; i < 14; i+=2)
1217 if (strcasecmp(attr[i], "login") == 0)
1219 ParseLogins(attr[i+1]);
1220 /*if (users->FindByName(login, &u))
1222 result = res_unknown;
1227 if (strcasecmp(attr[i], "MsgVer") == 0)
1229 str2x(attr[i+1], msg.header.ver);
1230 if (msg.header.ver != 1)
1231 result = res_params_error;
1234 if (strcasecmp(attr[i], "MsgType") == 0)
1236 str2x(attr[i+1], msg.header.type);
1237 if (msg.header.type != 1)
1238 result = res_params_error;
1241 if (strcasecmp(attr[i], "Repeat") == 0)
1243 str2x(attr[i+1], msg.header.repeat);
1244 if (msg.header.repeat < 0)
1245 result = res_params_error;
1248 if (strcasecmp(attr[i], "RepeatPeriod") == 0)
1250 str2x(attr[i+1], msg.header.repeatPeriod);
1253 if (strcasecmp(attr[i], "ShowTime") == 0)
1255 str2x(attr[i+1], msg.header.showTime);
1258 if (strcasecmp(attr[i], "Text") == 0)
1260 Decode21str(msg.text, attr[i+1]);
1268 //-----------------------------------------------------------------------------
1269 int PARSER_SEND_MESSAGE::ParseEnd(void *, const char *el)
1272 if (strcasecmp(el, "Message") == 0)
1274 result = res_unknown;
1275 for (unsigned i = 0; i < logins.size(); i++)
1277 if (users->FindByName(logins[i], &u))
1279 printfd(__FILE__, "User not found. %s\n", logins[i].c_str());
1282 msg.header.creationTime = stgTime;
1283 u->AddMessage(&msg);
1286 /*if (result == res_ok)
1288 if (strcmp(login, "*") == 0)
1292 printfd(__FILE__, "SendMsg text: %s\n", text);
1293 users->GetAllUsers(SendMessageAllUsers, &msg);
1297 u->AddMessage(pri, text);
1305 //-----------------------------------------------------------------------------
1306 int PARSER_SEND_MESSAGE::ParseLogins(const char * login)
1309 char * l = new char[strlen(login) + 1];
1315 logins.push_back(p);
1316 p = strtok(NULL, ":");
1322 //-----------------------------------------------------------------------------
1323 void PARSER_SEND_MESSAGE::CreateAnswer()
1325 //answerList->clear();
1326 answerList->erase(answerList->begin(), answerList->end());
1327 //answerList->push_back("<SendMessageResult value=\"ok\"/>");
1332 answerList->push_back("<SendMessageResult value=\"ok\"/>");
1334 case res_params_error:
1335 printfd(__FILE__, "res_params_error\n");
1336 answerList->push_back("<SendMessageResult value=\"Parameters error\"/>");
1339 printfd(__FILE__, "res_unknown\n");
1340 answerList->push_back("<SendMessageResult value=\"Unknown user\"/>");
1343 printfd(__FILE__, "res_default\n");
1347 //-----------------------------------------------------------------------------
1349 //-----------------------------------------------------------------------------
1350 int PARSER_DEL_USER::ParseStart(void *, const char *el, const char **attr)
1353 if (strcasecmp(el, "DelUser") == 0)
1355 if (attr[0] == NULL || attr[1] == NULL)
1357 //CreateAnswer("Parameters error!");
1362 if (users->FindByName(attr[1], &u))
1373 //-----------------------------------------------------------------------------
1374 int PARSER_DEL_USER::ParseEnd(void *, const char *el)
1376 if (strcasecmp(el, "DelUser") == 0)
1379 users->Del(u->GetLogin(), currAdmin);
1385 //-----------------------------------------------------------------------------
1386 void PARSER_DEL_USER::CreateAnswer()
1389 answerList->push_back("<DelUser value=\"error\" reason=\"User not found\"/>");
1391 answerList->push_back("<DelUser value=\"ok\"/>");
1393 //-----------------------------------------------------------------------------
1394 /*void PARSERDELUSER::CreateAnswer(char * mes)
1396 //answerList->clear();
1397 answerList->erase(answerList->begin(), answerList->end());
1400 sprintf(str, "<DelUser value=\"%s\"/>", mes);
1401 answerList->push_back(str);
1403 //-----------------------------------------------------------------------------
1405 // <checkuser login="vasya" password=\"123456\"/>
1406 //-----------------------------------------------------------------------------
1407 int PARSER_CHECK_USER::ParseStart(void *, const char *el, const char **attr)
1411 if (strcasecmp(el, "CheckUser") == 0)
1413 if (attr[0] == NULL || attr[1] == NULL
1414 || attr[2] == NULL || attr[3] == NULL)
1418 printfd(__FILE__, "PARSER_CHECK_USER - attr err\n");
1423 if (users->FindByName(attr[1], &user))
1427 printfd(__FILE__, "PARSER_CHECK_USER - login err\n");
1431 if (strcmp(user->property.password.Get().c_str(), attr[3]))
1435 printfd(__FILE__, "PARSER_CHECK_USER - passwd err\n");
1445 //-----------------------------------------------------------------------------
1446 int PARSER_CHECK_USER::ParseEnd(void *, const char *el)
1448 if (strcasecmp(el, "CheckUser") == 0)
1454 //-----------------------------------------------------------------------------
1455 void PARSER_CHECK_USER::CreateAnswer()
1458 answerList->push_back("<CheckUser value=\"Ok\"/>");
1460 answerList->push_back("<CheckUser value=\"Err\"/>");
1462 //-----------------------------------------------------------------------------
1463 //-----------------------------------------------------------------------------
1464 //-----------------------------------------------------------------------------