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];
51 strcat(un, utsn.sysname);
53 strcat(un, utsn.release);
55 strcat(un, utsn.machine);
57 strcat(un, utsn.nodename);
59 //answerList->clear();
60 answerList->erase(answerList->begin(), answerList->end());
61 answerList->push_back("<ServerInfo>");
63 sprintf(s, "<version value=\"%s\"/>", SERVER_VERSION);
64 answerList->push_back(s);
66 sprintf(s, "<tariff_num value=\"%d\"/>", tariffs->GetTariffsNum());
67 answerList->push_back(s);
69 sprintf(s, "<tariff value=\"%d\"/>", 2);
70 answerList->push_back(s);
72 sprintf(s, "<users_num value=\"%d\"/>", users->GetUserNum());
73 answerList->push_back(s);
75 sprintf(s, "<uname value=\"%s\"/>", un);
76 answerList->push_back(s);
78 sprintf(s, "<dir_num value=\"%d\"/>", DIR_NUM);
79 answerList->push_back(s);
81 sprintf(s, "<day_fee value=\"%d\"/>", settings->GetDayFee());
82 answerList->push_back(s);
84 for (int i = 0; i< DIR_NUM; i++)
87 Encode12str(dn2e, settings->GetDirName(i));
88 sprintf(s, "<dir_name_%d value=\"%s\"/>", i, dn2e.c_str());
89 answerList->push_back(s);
92 answerList->push_back("</ServerInfo>");
94 //-----------------------------------------------------------------------------
96 //-----------------------------------------------------------------------------
97 PARSER_GET_USER::PARSER_GET_USER()
101 //-----------------------------------------------------------------------------
102 int PARSER_GET_USER::ParseStart(void *, const char *el, const char **attr)
104 if (strcasecmp(el, "GetUser") == 0)
106 if (attr[0] && attr[1])
111 login.erase(login.begin(), login.end());
118 //-----------------------------------------------------------------------------
119 int PARSER_GET_USER::ParseEnd(void *, const char *el)
121 if (strcasecmp(el, "GetUser") == 0)
128 //-----------------------------------------------------------------------------
129 void PARSER_GET_USER::CreateAnswer()
136 answerList->erase(answerList->begin(), answerList->end());
138 if (users->FindByName(login, &u))
140 s = "<user result=\"error\"/>";
141 answerList->push_back(s);
145 s = "<user result=\"ok\">";
146 answerList->push_back(s);
148 s = "<login value=\"" + u->GetLogin() + "\"/>";
149 answerList->push_back(s);
151 if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd)
152 s = "<password value=\"" + u->property.password.Get() + "\" />";
154 s = "<password value=\"++++++\"/>";
155 answerList->push_back(s);
157 strprintf(&s, "<cash value=\"%f\" />", u->property.cash.Get());
158 answerList->push_back(s);
160 strprintf(&s, "<freemb value=\"%f\" />", u->property.freeMb.Get());
161 answerList->push_back(s);
163 strprintf(&s, "<credit value=\"%f\" />", u->property.credit.Get());
164 answerList->push_back(s);
166 if (u->property.nextTariff.Get() != "")
168 strprintf(&s, "<tariff value=\"%s/%s\" />",
169 u->property.tariffName.Get().c_str(),
170 u->property.nextTariff.Get().c_str());
174 strprintf(&s, "<tariff value=\"%s\" />",
175 u->property.tariffName.Get().c_str());
178 answerList->push_back(s);
180 Encode12str(enc, u->property.note);
181 s = "<note value=\"" + enc + "\" />";
182 answerList->push_back(s);
184 Encode12str(enc, u->property.phone);
185 s = "<phone value=\"" + enc + "\" />";
186 answerList->push_back(s);
188 Encode12str(enc, u->property.address);
189 s = "<address value=\"" + enc + "\" />";
190 answerList->push_back(s);
192 Encode12str(enc, u->property.email);
193 s = "<email value=\"" + enc + "\" />";
194 answerList->push_back(s);
197 vector<USER_PROPERTY_LOGGED<string> *> userdata;
198 userdata.push_back(u->property.userdata0.GetPointer());
199 userdata.push_back(u->property.userdata1.GetPointer());
200 userdata.push_back(u->property.userdata2.GetPointer());
201 userdata.push_back(u->property.userdata3.GetPointer());
202 userdata.push_back(u->property.userdata4.GetPointer());
203 userdata.push_back(u->property.userdata5.GetPointer());
204 userdata.push_back(u->property.userdata6.GetPointer());
205 userdata.push_back(u->property.userdata7.GetPointer());
206 userdata.push_back(u->property.userdata8.GetPointer());
207 userdata.push_back(u->property.userdata9.GetPointer());
210 for (unsigned i = 0; i < userdata.size(); i++)
212 Encode12str(enc, userdata[i]->Get());
213 s = "<UserData" + x2str(i, tmpI) + " value=\"" + enc + "\" />";
214 answerList->push_back(s);
217 Encode12str(enc, u->property.realName);
218 s = "<name value=\"" + enc + "\" />";
219 answerList->push_back(s);
221 Encode12str(enc, u->property.group);
222 s = "<GROUP value=\"" + enc + "\" />";
223 answerList->push_back(s);
225 strprintf(&s, "<status value=\"%d\" />", u->GetConnected());
226 answerList->push_back(s);
228 strprintf(&s, "<aonline value=\"%d\" />", u->property.alwaysOnline.Get());
229 answerList->push_back(s);
231 strprintf(&s, "<currip value=\"%s\" />", inet_ntostring(u->GetCurrIP()).c_str());
232 answerList->push_back(s);
234 strprintf(&s, "<PingTime value=\"%lu\" />", u->GetPingTime());
235 answerList->push_back(s);
238 sstr << u->property.ips.Get();
239 strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
240 answerList->push_back(s);
243 ss = new char[DIR_NUM*25*4 + 50];
245 sprintf(ss, "<traff");
248 download = u->property.down.Get();
249 upload = u->property.up.Get();
251 for (int j = 0; j < DIR_NUM; j++)
255 sprintf(st, " MU%d=\"%s\"", j, s.c_str());
258 x2str(download[j], s);
259 sprintf(st, " MD%d=\"%s\"", j, s.c_str());
262 sprintf(st, " SU%d=\"0\"", j);
265 sprintf(st, " SD%d=\"0\"", j);
269 answerList->push_back(ss);
272 strprintf(&s, "<down value=\"%d\" />", u->property.disabled.Get());
273 answerList->push_back(s);
275 strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->property.disabledDetailStat.Get());
276 answerList->push_back(s);
278 strprintf(&s, "<passive value=\"%d\" />", u->property.passive.Get());
279 answerList->push_back(s);
281 strprintf(&s, "<LastCash value=\"%f\" />", u->property.lastCashAdd.Get());
282 answerList->push_back(s);
284 strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->property.lastCashAddTime.Get());
285 answerList->push_back(s);
287 strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->property.lastActivityTime.Get());
288 answerList->push_back(s);
290 strprintf(&s, "<CreditExpire value=\"%ld\" />", u->property.creditExpire.Get());
291 answerList->push_back(s);
293 strprintf(&s, "</user>");
294 answerList->push_back(s);
296 //-----------------------------------------------------------------------------
298 //-----------------------------------------------------------------------------
299 PARSER_GET_USERS::PARSER_GET_USERS()
301 lastUserUpdateTime = 0;
303 //-----------------------------------------------------------------------------
304 int PARSER_GET_USERS::ParseStart(void *, const char *el, const char ** attr)
306 /*if (attr && *attr && *(attr+1))
308 printfd(__FILE__, "attr=%s %s\n", *attr, *(attr+1));
312 printfd(__FILE__, "attr = NULL\n");
315 lastUpdateFound = false;
316 if (strcasecmp(el, "GetUsers") == 0)
318 while (attr && *attr && *(attr+1))
320 if (strcasecmp(*attr, "LastUpdate") == 0)
322 if (str2x(*(attr+1), lastUserUpdateTime) == 0)
324 //printfd(__FILE__, "lastUserUpdateTime=%d\n", lastUserUpdateTime);
325 lastUpdateFound = true;
329 //printfd(__FILE__, "NO lastUserUpdateTime\n");
339 //-----------------------------------------------------------------------------
340 int PARSER_GET_USERS::ParseEnd(void *, const char *el)
342 if (strcasecmp(el, "GetUsers") == 0)
349 //-----------------------------------------------------------------------------
350 void PARSER_GET_USERS::CreateAnswer()
352 answerList->erase(answerList->begin(), answerList->end());
367 int h = users->OpenSearch();
370 printfd(__FILE__, "users->OpenSearch() error\n");
371 users->CloseSearch(h);
375 x2str(time(NULL), updateTime);
378 answerList->push_back("<Users LastUpdate=\"" + updateTime + "\">");
380 answerList->push_back("<Users>");
384 if (users->SearchNext(h, &u))
388 userStart = "<user login=\"" + u->GetLogin() + "\">";
391 if (u->property.password.ModificationTime() > lastUserUpdateTime)
393 if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd)
394 s = "<password value=\"" + u->property.password.Get() + "\" />";
396 s = "<password value=\"++++++\"/>";
401 if (u->property.cash.ModificationTime() > lastUserUpdateTime)
403 strprintf(&s, "<cash value=\"%f\" />", u->property.cash.Get());
405 //printfd(__FILE__, "cash value=\"%f\"\n", u->property.cash.Get());
409 if (u->property.freeMb.ModificationTime() > lastUserUpdateTime)
411 strprintf(&s, "<freemb value=\"%f\" />", u->property.freeMb.Get());
415 if (u->property.credit.ModificationTime() > lastUserUpdateTime)
417 strprintf(&s, "<credit value=\"%f\" />", u->property.credit.Get());
421 if (u->property.nextTariff.Get() != "")
423 if (u->property.tariffName.ModificationTime() > lastUserUpdateTime
424 || u->property.nextTariff.ModificationTime() > lastUserUpdateTime)
426 strprintf(&s, "<tariff value=\"%s/%s\" />",
427 u->property.tariffName.Get().c_str(),
428 u->property.nextTariff.Get().c_str());
434 if (u->property.tariffName.ModificationTime() > lastUserUpdateTime)
436 strprintf(&s, "<tariff value=\"%s\" />",
437 u->property.tariffName.Get().c_str());
442 if (u->property.note.ModificationTime() > lastUserUpdateTime)
444 Encode12str(enc, u->property.note);
445 strprintf(&s, "<note value=\"%s\" />", enc.c_str());
449 if (u->property.phone.ModificationTime() > lastUserUpdateTime)
451 Encode12str(enc, u->property.phone);
452 strprintf(&s, "<phone value=\"%s\" />", enc.c_str());
456 if (u->property.address.ModificationTime() > lastUserUpdateTime)
458 Encode12str(enc, u->property.address);
459 strprintf(&s, "<address value=\"%s\" />", enc.c_str());
463 if (u->property.email.ModificationTime() > lastUserUpdateTime)
465 Encode12str(enc, u->property.email);
466 strprintf(&s, "<email value=\"%s\" />", enc.c_str());
470 vector<USER_PROPERTY_LOGGED<string> *> userdata;
471 userdata.push_back(u->property.userdata0.GetPointer());
472 userdata.push_back(u->property.userdata1.GetPointer());
473 userdata.push_back(u->property.userdata2.GetPointer());
474 userdata.push_back(u->property.userdata3.GetPointer());
475 userdata.push_back(u->property.userdata4.GetPointer());
476 userdata.push_back(u->property.userdata5.GetPointer());
477 userdata.push_back(u->property.userdata6.GetPointer());
478 userdata.push_back(u->property.userdata7.GetPointer());
479 userdata.push_back(u->property.userdata8.GetPointer());
480 userdata.push_back(u->property.userdata9.GetPointer());
483 for (unsigned i = 0; i < userdata.size(); i++)
485 if (userdata[i]->ModificationTime() > lastUserUpdateTime)
487 Encode12str(enc, userdata[i]->Get());
488 s = "<UserData" + x2str(i, tmpI) + " value=\"" + enc + "\" />";
493 if (u->property.realName.ModificationTime() > lastUserUpdateTime)
495 Encode12str(enc, u->property.realName);
496 strprintf(&s, "<name value=\"%s\" />", enc.c_str());
500 if (u->property.group.ModificationTime() > lastUserUpdateTime)
502 Encode12str(enc, u->property.group);
503 strprintf(&s, "<GROUP value=\"%s\" />", enc.c_str());
507 if (u->property.alwaysOnline.ModificationTime() > lastUserUpdateTime)
509 strprintf(&s, "<aonline value=\"%d\" />", u->property.alwaysOnline.Get());
513 if (u->GetCurrIPModificationTime() > lastUserUpdateTime)
515 strprintf(&s, "<currip value=\"%s\" />", inet_ntostring(u->GetCurrIP()).c_str());
520 if (u->GetConnectedModificationTime() > lastUserUpdateTime)
522 strprintf(&s, "<status value=\"%d\" />", u->GetConnected());
526 if (u->GetPingTime() > lastUserUpdateTime)
528 strprintf(&s, "<PingTime value=\"%lu\" />", u->GetPingTime());
532 if (u->property.ips.ModificationTime() > lastUserUpdateTime)
535 sstr << u->property.ips.Get();
536 strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
541 traffStart = "<traff";
544 download = u->property.down.Get();
545 upload = u->property.up.Get();
548 if (u->property.up.ModificationTime() > lastUserUpdateTime)
550 for (int j = 0; j < DIR_NUM; j++)
554 sprintf(st, " MU%d=\"%s\" ", j, s.c_str());
559 if (u->property.down.ModificationTime() > lastUserUpdateTime)
561 for (int j = 0; j < DIR_NUM; j++)
563 x2str(download[j], s);
564 sprintf(st, " MD%d=\"%s\" ", j, s.c_str());
570 if (traffMiddle.length() > 0)
572 middle += traffStart;
573 middle += traffMiddle;
574 middle += traffFinish;
577 if (u->property.disabled.ModificationTime() > lastUserUpdateTime)
579 strprintf(&s, "<down value=\"%d\" />", u->property.disabled.Get());
583 if (u->property.disabledDetailStat.ModificationTime() > lastUserUpdateTime)
585 strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->property.disabledDetailStat.Get());
589 //printfd(__FILE__, ">>>>> %s\n", s.c_str());
591 if (u->property.passive.ModificationTime() > lastUserUpdateTime)
593 strprintf(&s, "<passive value=\"%d\" />", u->property.passive.Get());
597 if (u->property.lastCashAdd.ModificationTime() > lastUserUpdateTime)
599 strprintf(&s, "<LastCash value=\"%f\" />", u->property.lastCashAdd.Get());
603 if (u->property.lastCashAddTime.ModificationTime() > lastUserUpdateTime)
605 strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->property.lastCashAddTime.Get());
610 if (u->property.lastActivityTime.ModificationTime() > lastUserUpdateTime)
612 strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->property.lastActivityTime.Get());
616 if (u->property.creditExpire.ModificationTime() > lastUserUpdateTime)
618 strprintf(&s, "<CreditExpire value=\"%ld\" />", u->property.creditExpire.Get());
623 userFinish = "</user>";
625 if (middle.length() > 0)
627 /*printfd(__FILE__, "login: %s\n", u->GetLogin().c_str());
628 printfd(__FILE__, "middle: %s\n", middle.c_str());*/
630 answerList->push_back(userStart);
631 answerList->push_back(middle);
632 answerList->push_back(userFinish);
636 users->CloseSearch(h);
638 //answerList->push_back("</Users>");
640 answerList->push_back("</Users>");
642 //-----------------------------------------------------------------------------
644 //-----------------------------------------------------------------------------
645 PARSER_ADD_USER::PARSER_ADD_USER()
649 //-----------------------------------------------------------------------------
650 int PARSER_ADD_USER::ParseStart(void *, const char *el, const char **attr)
656 if (strcasecmp(el, "AddUser") == 0)
663 if (strcasecmp(el, "login") == 0)
671 //-----------------------------------------------------------------------------
672 int PARSER_ADD_USER::ParseEnd(void *, const char *el)
676 if (strcasecmp(el, "AddUser") == 0)
687 //-----------------------------------------------------------------------------
688 void PARSER_ADD_USER::Reset()
690 BASE_PARSER::Reset();
693 //-----------------------------------------------------------------------------
694 void PARSER_ADD_USER::CreateAnswer()
696 //answerList->clear();
697 answerList->erase(answerList->begin(), answerList->end());
699 if (CheckUserData() == 0)
701 answerList->push_back("<AddUser result=\"ok\"/>");
705 answerList->push_back("<AddUser result=\"error\" reason=\"Access denied\"/>");
708 //-----------------------------------------------------------------------------
709 int PARSER_ADD_USER::CheckUserData()
712 if (users->FindByName(login, &u))
714 return users->Add(login, *currAdmin);
718 //-----------------------------------------------------------------------------
720 //-----------------------------------------------------------------------------
721 PARSER_CHG_USER::PARSER_CHG_USER()
730 //-----------------------------------------------------------------------------
731 PARSER_CHG_USER::~PARSER_CHG_USER()
738 //-----------------------------------------------------------------------------
739 void PARSER_CHG_USER::Reset()
750 usr = new USER_STAT_RES;
751 ucr = new USER_CONF_RES;
753 upr = new RESETABLE<uint64_t>[DIR_NUM];
754 downr = new RESETABLE<uint64_t>[DIR_NUM];
756 //-----------------------------------------------------------------------------
757 string PARSER_CHG_USER::EncChar2String(const char * strEnc)
760 Decode21str(str, strEnc);
763 //-----------------------------------------------------------------------------
764 int PARSER_CHG_USER::ParseStart(void *, const char *el, const char **attr)
770 if (strcasecmp(el, "SetUser") == 0)
777 //printfd(__FILE__, "el=%s\n", el);
778 if (strcasecmp(el, "login") == 0)
784 if (strcasecmp(el, "ip") == 0)
788 ucr->ips = StrToIPS(attr[1]);
792 printfd(__FILE__, "StrToIPS Error!\n");
796 if (strcasecmp(el, "password") == 0)
798 ucr->password = attr[1];
802 if (strcasecmp(el, "address") == 0)
804 ucr->address = EncChar2String(attr[1]);
808 if (strcasecmp(el, "aonline") == 0)
810 ucr->alwaysOnline = (*(attr[1]) != '0');
814 if (strcasecmp(el, "cash") == 0)
816 if (attr[2] && (strcasecmp(attr[2], "msg") == 0))
818 cashMsg = EncChar2String(attr[3]);
822 if (strtodouble2(attr[1], cash) == 0)
825 if (strcasecmp(attr[0], "set") == 0)
826 cashMustBeAdded = false;
828 if (strcasecmp(attr[0], "add") == 0)
829 cashMustBeAdded = true;
834 if (strcasecmp(el, "CreditExpire") == 0)
836 long int creditExpire = 0;
837 if (str2x(attr[1], creditExpire) == 0)
838 ucr->creditExpire = (time_t)creditExpire;
843 if (strcasecmp(el, "credit") == 0)
846 if (strtodouble2(attr[1], credit) == 0)
847 ucr->credit = credit;
851 if (strcasecmp(el, "freemb") == 0)
854 if (strtodouble2(attr[1], freeMb) == 0)
855 usr->freeMb = freeMb;
859 if (strcasecmp(el, "down") == 0)
862 if (str2x(attr[1], down) == 0)
863 ucr->disabled = down;
867 if (strcasecmp(el, "DisableDetailStat") == 0)
869 int disabledDetailStat = 0;
870 if (str2x(attr[1], disabledDetailStat) == 0)
871 ucr->disabledDetailStat = disabledDetailStat;
875 if (strcasecmp(el, "email") == 0)
877 ucr->email = EncChar2String(attr[1]);
881 for (int i = 0; i < USERDATA_NUM; i++)
884 sprintf(name, "userdata%d", i);
885 if (strcasecmp(el, name) == 0)
887 ucr->userdata[i] = EncChar2String(attr[1]);
892 if (strcasecmp(el, "group") == 0)
894 ucr->group = EncChar2String(attr[1]);
898 if (strcasecmp(el, "note") == 0)
900 ucr->note = EncChar2String(attr[1]);
904 if (strcasecmp(el, "passive") == 0)
907 if (str2x(attr[1], passive) == 0)
908 ucr->passive = passive;
912 if (strcasecmp(el, "phone") == 0)
914 ucr->phone = EncChar2String(attr[1]);
918 if (strcasecmp(el, "Name") == 0)
920 ucr->realName = EncChar2String(attr[1]);
924 if (strcasecmp(el, "traff") == 0)
930 unsigned long long t = 0;
933 dir = attr[j][2] - '0';
935 if (strncasecmp(attr[j], "md", 2) == 0)
941 if (strncasecmp(attr[j], "mu", 2) == 0)
954 if (strcasecmp(el, "tariff") == 0)
956 if (strcasecmp(attr[0], "now") == 0)
957 ucr->tariffName = attr[1];
959 if (strcasecmp(attr[0], "delayed") == 0)
960 ucr->nextTariff = attr[1];
967 //-----------------------------------------------------------------------------
968 int PARSER_CHG_USER::ParseEnd(void *, const char *el)
972 if (strcasecmp(el, "SetUser") == 0)
984 //-----------------------------------------------------------------------------
985 void PARSER_CHG_USER::CreateAnswer()
987 //answerList->clear();
988 answerList->erase(answerList->begin(), answerList->end());
993 answerList->push_back("<SetUser result=\"ok\"/>");
996 answerList->push_back("<SetUser result=\"error\"/>");
999 answerList->push_back("<SetUser result=\"error\"/>");
1002 answerList->push_back("<SetUser result=\"error\"/>");
1007 //-----------------------------------------------------------------------------
1008 int PARSER_CHG_USER::CheckUserData()
1012 //-----------------------------------------------------------------------------
1013 int PARSER_CHG_USER::AplayChanges()
1018 if (users->FindByName(login, &u))
1024 if (!ucr->ips.res_empty())
1025 if (!u->property.ips.Set(ucr->ips.const_data(), currAdmin, login, store))
1028 if (!ucr->address.res_empty())
1029 if (!u->property.address.Set(ucr->address.const_data(), currAdmin, login, store))
1032 if (!ucr->alwaysOnline.res_empty())
1033 if (!u->property.alwaysOnline.Set(ucr->alwaysOnline.const_data(),
1034 currAdmin, login, store))
1037 if (!ucr->creditExpire.res_empty())
1038 if (!u->property.creditExpire.Set(ucr->creditExpire.const_data(),
1039 currAdmin, login, store))
1042 if (!ucr->credit.res_empty())
1043 if (!u->property.credit.Set(ucr->credit.const_data(), currAdmin, login, store))
1046 if (!usr->freeMb.res_empty())
1047 if (!u->property.freeMb.Set(usr->freeMb.const_data(), currAdmin, login, store))
1050 if (!ucr->disabled.res_empty())
1051 if (!u->property.disabled.Set(ucr->disabled.const_data(), currAdmin, login, store))
1054 if (!ucr->disabledDetailStat.res_empty())
1055 if (!u->property.disabledDetailStat.Set(ucr->disabledDetailStat.const_data(), currAdmin, login, store))
1058 if (!ucr->email.res_empty())
1059 if (!u->property.email.Set(ucr->email.const_data(), currAdmin, login, store))
1062 if (!ucr->group.res_empty())
1063 if (!u->property.group.Set(ucr->group.const_data(), currAdmin, login, store))
1066 if (!ucr->note.res_empty())
1067 if (!u->property.note.Set(ucr->note.const_data(), currAdmin, login, store))
1070 vector<USER_PROPERTY_LOGGED<string> *> userdata;
1071 userdata.push_back(u->property.userdata0.GetPointer());
1072 userdata.push_back(u->property.userdata1.GetPointer());
1073 userdata.push_back(u->property.userdata2.GetPointer());
1074 userdata.push_back(u->property.userdata3.GetPointer());
1075 userdata.push_back(u->property.userdata4.GetPointer());
1076 userdata.push_back(u->property.userdata5.GetPointer());
1077 userdata.push_back(u->property.userdata6.GetPointer());
1078 userdata.push_back(u->property.userdata7.GetPointer());
1079 userdata.push_back(u->property.userdata8.GetPointer());
1080 userdata.push_back(u->property.userdata9.GetPointer());
1082 for (int i = 0; i < (int)userdata.size(); i++)
1084 if (!ucr->userdata[i].res_empty())
1086 if(!userdata[i]->Set(ucr->userdata[i].const_data(), currAdmin, login, store))
1091 if (!ucr->passive.res_empty())
1092 if (!u->property.passive.Set(ucr->passive.const_data(), currAdmin, login, store))
1095 if (!ucr->password.res_empty())
1096 if (!u->property.password.Set(ucr->password.const_data(), currAdmin, login, store))
1099 if (!ucr->phone.res_empty())
1100 if (!u->property.phone.Set(ucr->phone.const_data(), currAdmin, login, store))
1103 if (!ucr->realName.res_empty())
1104 if (!u->property.realName.Set(ucr->realName.const_data(), currAdmin, login, store))
1108 if (!usr->cash.res_empty())
1110 //if (currAdmin->GetPriv()->userCash)
1112 if (cashMustBeAdded)
1114 if (!u->property.cash.Set(usr->cash.const_data() + u->property.cash,
1123 if (!u->property.cash.Set(usr->cash.const_data(), currAdmin, login, store, cashMsg))
1130 if (!ucr->tariffName.res_empty())
1132 if (tariffs->FindByName(ucr->tariffName.const_data()))
1134 if (!u->property.tariffName.Set(ucr->tariffName.const_data(), currAdmin, login, store))
1136 u->ResetNextTariff();
1140 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
1145 if (!ucr->nextTariff.res_empty())
1147 if (tariffs->FindByName(ucr->nextTariff.const_data()))
1149 if (!u->property.nextTariff.Set(ucr->nextTariff.const_data(), currAdmin, login, store))
1154 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
1159 DIR_TRAFF up = u->property.up;
1160 DIR_TRAFF down = u->property.down;
1163 for (int i = 0; i < DIR_NUM; i++)
1165 if (!upr[i].res_empty())
1170 if (!downr[i].res_empty())
1178 if (!u->property.up.Set(up, currAdmin, login, store))
1182 if (!u->property.down.Set(down, currAdmin, login, store))
1185 /*if (!usr->down.res_empty())
1187 u->property.down.Set(usr->down.const_data(), currAdmin, login, store);
1189 if (!usr->up.res_empty())
1191 u->property.up.Set(usr->up.const_data(), currAdmin, login, store);
1199 //-----------------------------------------------------------------------------
1201 //-----------------------------------------------------------------------------
1202 int PARSER_SEND_MESSAGE::ParseStart(void *, const char *el, const char **attr)
1204 if (strcasecmp(el, "Message") == 0)
1206 for (int i = 0; i < 14; i++)
1208 if (attr[i] == NULL)
1210 result = res_params_error;
1212 printfd(__FILE__, "To few parameters\n");
1217 for (int i = 0; i < 14; i+=2)
1219 if (strcasecmp(attr[i], "login") == 0)
1221 ParseLogins(attr[i+1]);
1222 /*if (users->FindByName(login, &u))
1224 result = res_unknown;
1229 if (strcasecmp(attr[i], "MsgVer") == 0)
1231 str2x(attr[i+1], msg.header.ver);
1232 if (msg.header.ver != 1)
1233 result = res_params_error;
1236 if (strcasecmp(attr[i], "MsgType") == 0)
1238 str2x(attr[i+1], msg.header.type);
1239 if (msg.header.type != 1)
1240 result = res_params_error;
1243 if (strcasecmp(attr[i], "Repeat") == 0)
1245 str2x(attr[i+1], msg.header.repeat);
1246 if (msg.header.repeat < 0)
1247 result = res_params_error;
1250 if (strcasecmp(attr[i], "RepeatPeriod") == 0)
1252 str2x(attr[i+1], msg.header.repeatPeriod);
1255 if (strcasecmp(attr[i], "ShowTime") == 0)
1257 str2x(attr[i+1], msg.header.showTime);
1260 if (strcasecmp(attr[i], "Text") == 0)
1262 Decode21str(msg.text, attr[i+1]);
1270 //-----------------------------------------------------------------------------
1271 int PARSER_SEND_MESSAGE::ParseEnd(void *, const char *el)
1274 if (strcasecmp(el, "Message") == 0)
1276 result = res_unknown;
1277 for (unsigned i = 0; i < logins.size(); i++)
1279 if (users->FindByName(logins[i], &u))
1281 printfd(__FILE__, "User not found. %s\n", logins[i].c_str());
1284 msg.header.creationTime = stgTime;
1285 u->AddMessage(&msg);
1288 /*if (result == res_ok)
1290 if (strcmp(login, "*") == 0)
1294 printfd(__FILE__, "SendMsg text: %s\n", text);
1295 users->GetAllUsers(SendMessageAllUsers, &msg);
1299 u->AddMessage(pri, text);
1307 //-----------------------------------------------------------------------------
1308 int PARSER_SEND_MESSAGE::ParseLogins(const char * login)
1311 char * l = new char[strlen(login) + 1];
1317 logins.push_back(p);
1318 p = strtok(NULL, ":");
1324 //-----------------------------------------------------------------------------
1325 void PARSER_SEND_MESSAGE::CreateAnswer()
1327 //answerList->clear();
1328 answerList->erase(answerList->begin(), answerList->end());
1329 //answerList->push_back("<SendMessageResult value=\"ok\"/>");
1334 answerList->push_back("<SendMessageResult value=\"ok\"/>");
1336 case res_params_error:
1337 printfd(__FILE__, "res_params_error\n");
1338 answerList->push_back("<SendMessageResult value=\"Parameters error\"/>");
1341 printfd(__FILE__, "res_unknown\n");
1342 answerList->push_back("<SendMessageResult value=\"Unknown user\"/>");
1345 printfd(__FILE__, "res_default\n");
1349 //-----------------------------------------------------------------------------
1351 //-----------------------------------------------------------------------------
1352 int PARSER_DEL_USER::ParseStart(void *, const char *el, const char **attr)
1355 if (strcasecmp(el, "DelUser") == 0)
1357 if (attr[0] == NULL || attr[1] == NULL)
1359 //CreateAnswer("Parameters error!");
1364 if (users->FindByName(attr[1], &u))
1375 //-----------------------------------------------------------------------------
1376 int PARSER_DEL_USER::ParseEnd(void *, const char *el)
1378 if (strcasecmp(el, "DelUser") == 0)
1381 users->Del(u->GetLogin(), *currAdmin);
1387 //-----------------------------------------------------------------------------
1388 void PARSER_DEL_USER::CreateAnswer()
1391 answerList->push_back("<DelUser value=\"error\" reason=\"User not found\"/>");
1393 answerList->push_back("<DelUser value=\"ok\"/>");
1395 //-----------------------------------------------------------------------------
1396 /*void PARSERDELUSER::CreateAnswer(char * mes)
1398 //answerList->clear();
1399 answerList->erase(answerList->begin(), answerList->end());
1402 sprintf(str, "<DelUser value=\"%s\"/>", mes);
1403 answerList->push_back(str);
1405 //-----------------------------------------------------------------------------
1407 // <checkuser login="vasya" password=\"123456\"/>
1408 //-----------------------------------------------------------------------------
1409 int PARSER_CHECK_USER::ParseStart(void *, const char *el, const char **attr)
1413 if (strcasecmp(el, "CheckUser") == 0)
1415 if (attr[0] == NULL || attr[1] == NULL
1416 || attr[2] == NULL || attr[3] == NULL)
1420 printfd(__FILE__, "PARSER_CHECK_USER - attr err\n");
1425 if (users->FindByName(attr[1], &user))
1429 printfd(__FILE__, "PARSER_CHECK_USER - login err\n");
1433 if (strcmp(user->property.password.Get().c_str(), attr[3]))
1437 printfd(__FILE__, "PARSER_CHECK_USER - passwd err\n");
1447 //-----------------------------------------------------------------------------
1448 int PARSER_CHECK_USER::ParseEnd(void *, const char *el)
1450 if (strcasecmp(el, "CheckUser") == 0)
1456 //-----------------------------------------------------------------------------
1457 void PARSER_CHECK_USER::CreateAnswer()
1460 answerList->push_back("<CheckUser value=\"Ok\"/>");
1462 answerList->push_back("<CheckUser value=\"Err\"/>");
1464 //-----------------------------------------------------------------------------
1465 //-----------------------------------------------------------------------------
1466 //-----------------------------------------------------------------------------