2 #include <sys/utsname.h>
4 #include <sys/socket.h>
5 #include <netinet/in.h>
12 #include "stg/version.h"
13 #include "stg/tariffs.h"
14 #include "stg/user_property.h"
15 #include "stg/settings.h"
16 #include "stg/logger.h"
19 #define UNAME_LEN (256)
24 std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_t lastTime = 0)
29 answer += "<User result=\"ok\">";
31 answer += "<User result=\"ok\" login=\"" + user.GetLogin() + "\">";
33 answer += "<Login value=\"" + user.GetLogin() + "\"/>";
35 if (user.GetProperty().password.ModificationTime() > lastTime)
38 answer += "<Password value=\"" + user.GetProperty().password.Get() + "\" />";
40 answer += "<Password value=\"++++++\"/>";
43 if (user.GetProperty().cash.ModificationTime() > lastTime)
44 answer += "<Cash value=\"" + x2str(user.GetProperty().cash.Get()) + "\"/>";
45 if (user.GetProperty().freeMb.ModificationTime() > lastTime)
46 answer += "<FreeMb value=\"" + x2str(user.GetProperty().freeMb.Get()) + "\"/>";
47 if (user.GetProperty().credit.ModificationTime() > lastTime)
48 answer += "<Credit value=\"" + x2str(user.GetProperty().credit.Get()) + "\"/>";
50 if (user.GetProperty().nextTariff.Get() != "")
52 if (user.GetProperty().tariffName.ModificationTime() > lastTime ||
53 user.GetProperty().nextTariff.ModificationTime() > lastTime)
54 answer += "<Tariff value=\"" + user.GetProperty().tariffName.Get() + "/" + user.GetProperty().nextTariff.Get() + "\"/>";
58 if (user.GetProperty().tariffName.ModificationTime() > lastTime)
59 answer += "<Tariff value=\"" + user.GetProperty().tariffName.Get() + "\"/>";
62 if (user.GetProperty().note.ModificationTime() > lastTime)
63 answer += "<Note value=\"" + Encode12str(user.GetProperty().note) + "\"/>";
64 if (user.GetProperty().phone.ModificationTime() > lastTime)
65 answer += "<Phone value=\"" + Encode12str(user.GetProperty().phone) + "\"/>";
66 if (user.GetProperty().address.ModificationTime() > lastTime)
67 answer += "<Address value=\"" + Encode12str(user.GetProperty().address) + "\"/>";
68 if (user.GetProperty().email.ModificationTime() > lastTime)
69 answer += "<Email value=\"" + Encode12str(user.GetProperty().email) + "\"/>";
71 std::vector<const USER_PROPERTY_LOGGED<std::string> *> userdata;
72 userdata.push_back(user.GetProperty().userdata0.GetPointer());
73 userdata.push_back(user.GetProperty().userdata1.GetPointer());
74 userdata.push_back(user.GetProperty().userdata2.GetPointer());
75 userdata.push_back(user.GetProperty().userdata3.GetPointer());
76 userdata.push_back(user.GetProperty().userdata4.GetPointer());
77 userdata.push_back(user.GetProperty().userdata5.GetPointer());
78 userdata.push_back(user.GetProperty().userdata6.GetPointer());
79 userdata.push_back(user.GetProperty().userdata7.GetPointer());
80 userdata.push_back(user.GetProperty().userdata8.GetPointer());
81 userdata.push_back(user.GetProperty().userdata9.GetPointer());
83 for (size_t i = 0; i < userdata.size(); i++)
84 if (userdata[i]->ModificationTime() > lastTime)
85 answer += "<UserData" + x2str(i) + " value=\"" + Encode12str(userdata[i]->Get()) + "\" />";
87 if (user.GetProperty().realName.ModificationTime() > lastTime)
88 answer += "<Name value=\"" + Encode12str(user.GetProperty().realName) + "\"/>";
89 if (user.GetProperty().group.ModificationTime() > lastTime)
90 answer += "<Group value=\"" + Encode12str(user.GetProperty().group) + "\"/>";
91 if (user.GetConnectedModificationTime() > lastTime)
92 answer += std::string("<Status value=\"") + (user.GetConnected() ? "1" : "0") + "\"/>";
93 if (user.GetProperty().alwaysOnline.ModificationTime() > lastTime)
94 answer += std::string("<AOnline value=\"") + (user.GetProperty().alwaysOnline.Get() ? "1" : "0") + "\"/>";
95 if (user.GetCurrIPModificationTime() > lastTime)
96 answer += "<CurrIP value=\"" + inet_ntostring(user.GetCurrIP()) + "\"/>";
97 if (user.GetPingTime() > lastTime)
98 answer += "<PingTime value=\"" + x2str(user.GetPingTime()) + "\"/>";
99 if (user.GetProperty().ips.ModificationTime() > lastTime)
100 answer += "<IP value=\"" + user.GetProperty().ips.Get().GetIpStr() + "\"/>";
103 const DIR_TRAFF & upload(user.GetProperty().down.Get());
104 const DIR_TRAFF & download(user.GetProperty().up.Get());
105 if (user.GetProperty().up.ModificationTime() > lastTime)
106 for (size_t j = 0; j < DIR_NUM; j++)
107 answer += " MU" + x2str(j) + "=\"" + x2str(upload[j]) + "\"";
108 if (user.GetProperty().down.ModificationTime() > lastTime)
109 for (size_t j = 0; j < DIR_NUM; j++)
110 answer += " MD" + x2str(j) + "=\"" + x2str(download[j]) + "\"";
111 if (user.GetSessionUploadModificationTime() > lastTime)
112 for (size_t j = 0; j < DIR_NUM; j++)
113 answer += " SU" + x2str(j) + "=\"" + x2str(user.GetSessionUpload()[j]) + "\"";
114 if (user.GetSessionDownloadModificationTime() > lastTime)
115 for (size_t j = 0; j < DIR_NUM; j++)
116 answer += " SD" + x2str(j) + "=\"" + x2str(user.GetSessionDownload()[j]) + "\"";
119 if (user.GetProperty().disabled.ModificationTime() > lastTime)
120 answer += std::string("<Down value=\"") + (user.GetProperty().disabled.Get() ? "1" : "0") + "\"/>";
121 if (user.GetProperty().disabledDetailStat.ModificationTime() > lastTime)
122 answer += std::string("<DisableDetailStat value=\"") + (user.GetProperty().disabledDetailStat.Get() ? "1" : "0") + "\"/>";
123 if (user.GetProperty().passive.ModificationTime() > lastTime)
124 answer += std::string("<Passive value=\"") + (user.GetProperty().passive.Get() ? "1" : "0") + "\"/>";
125 if (user.GetProperty().lastCashAdd.ModificationTime() > lastTime)
126 answer += "<LastCash value=\"" + x2str(user.GetProperty().lastCashAdd.Get()) + "\"/>";
127 if (user.GetProperty().lastCashAddTime.ModificationTime() > lastTime)
128 answer += "<LastTimeCash value=\"" + x2str(user.GetProperty().lastCashAddTime.Get()) + "\"/>";
129 if (user.GetProperty().lastActivityTime.ModificationTime() > lastTime)
130 answer += "<LastActivityTime value=\"" + x2str(user.GetProperty().lastActivityTime.Get()) + "\"/>";
131 if (user.GetProperty().creditExpire.ModificationTime() > lastTime)
132 answer += "<CreditExpire value=\"" + x2str(user.GetProperty().creditExpire.Get()) + "\"/>";
136 answer += "<AuthorizedBy>";
137 std::vector<std::string> list(user.GetAuthorizers());
138 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
139 answer += "<Auth name=\"" + *it + "\"/>";
140 answer += "</AuthorizedBy>";
148 } // namespace anonymous
150 //-----------------------------------------------------------------------------
152 //-----------------------------------------------------------------------------
153 int PARSER_GET_SERVER_INFO::ParseStart(void *, const char *el, const char **)
156 if (strcasecmp(el, "GetServerInfo") == 0)
162 //-----------------------------------------------------------------------------
163 int PARSER_GET_SERVER_INFO::ParseEnd(void *, const char *el)
165 if (strcasecmp(el, "GetServerInfo") == 0)
172 //-----------------------------------------------------------------------------
173 void PARSER_GET_SERVER_INFO::CreateAnswer()
181 strcat(un, utsn.sysname);
183 strcat(un, utsn.release);
185 strcat(un, utsn.machine);
187 strcat(un, utsn.nodename);
190 answer += "<ServerInfo>";
191 answer += std::string("<version value=\"") + SERVER_VERSION + "\"/>";
192 answer += "<tariff_num value=\"" + x2str(tariffs->Count()) + "\"/>";
193 answer += "<tariff value=\"2\"/>";
194 answer += "<user_num value=\"" + x2str(users->Count()) + "\"/>";
195 answer += std::string("<uname value=\"") + un + "\"/>";
196 answer += "<dir_num value=\"" + x2str(DIR_NUM) + "\"/>";
197 answer += "<day_fee value=\"" + x2str(settings->GetDayFee()) + "\"/>";
199 for (size_t i = 0; i< DIR_NUM; i++)
200 answer += "<dir_name_" + x2str(i) + " value=\"" + Encode12str(settings->GetDirName(i)) + "\"/>";
202 answer += "</ServerInfo>";
204 //-----------------------------------------------------------------------------
206 //-----------------------------------------------------------------------------
207 int PARSER_GET_USER::ParseStart(void *, const char *el, const char **attr)
209 if (strcasecmp(el, "GetUser") == 0)
211 if (attr[0] && attr[1])
216 login.erase(login.begin(), login.end());
223 //-----------------------------------------------------------------------------
224 int PARSER_GET_USER::ParseEnd(void *, const char *el)
226 if (strcasecmp(el, "GetUser") == 0)
233 //-----------------------------------------------------------------------------
234 void PARSER_GET_USER::CreateAnswer()
240 if (users->FindByName(login, &u))
242 answer = "<User result=\"error\" reason=\"User not found.\"/>";
246 answer = UserToXML(*u, false, currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd);
248 //-----------------------------------------------------------------------------
250 //-----------------------------------------------------------------------------
251 int PARSER_GET_USERS::ParseStart(void *, const char *el, const char ** attr)
253 /*if (attr && *attr && *(attr+1))
255 printfd(__FILE__, "attr=%s %s\n", *attr, *(attr+1));
259 printfd(__FILE__, "attr = NULL\n");
262 lastUpdateFound = false;
263 if (strcasecmp(el, "GetUsers") == 0)
265 while (attr && *attr && *(attr+1))
267 if (strcasecmp(*attr, "LastUpdate") == 0)
269 if (str2x(*(attr+1), lastUserUpdateTime) == 0)
271 //printfd(__FILE__, "lastUserUpdateTime=%d\n", lastUserUpdateTime);
272 lastUpdateFound = true;
276 //printfd(__FILE__, "NO lastUserUpdateTime\n");
286 //-----------------------------------------------------------------------------
287 int PARSER_GET_USERS::ParseEnd(void *, const char *el)
289 if (strcasecmp(el, "GetUsers") == 0)
296 //-----------------------------------------------------------------------------
297 void PARSER_GET_USERS::CreateAnswer()
301 int h = users->OpenSearch();
304 printfd(__FILE__, "users->OpenSearch() error\n");
305 users->CloseSearch(h);
310 answer += "<Users LastUpdate=\"" + x2str(time(NULL)) + "\">";
316 while (users->SearchNext(h, &u) == 0)
317 answer += UserToXML(*u, true, currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd, lastUserUpdateTime);
319 users->CloseSearch(h);
321 answer += "</Users>";
323 //-----------------------------------------------------------------------------
325 //-----------------------------------------------------------------------------
326 int PARSER_ADD_USER::ParseStart(void *, const char *el, const char **attr)
332 if (strcasecmp(el, "AddUser") == 0)
339 if (strcasecmp(el, "login") == 0)
347 //-----------------------------------------------------------------------------
348 int PARSER_ADD_USER::ParseEnd(void *, const char *el)
352 if (strcasecmp(el, "AddUser") == 0)
363 //-----------------------------------------------------------------------------
364 void PARSER_ADD_USER::Reset()
366 BASE_PARSER::Reset();
369 //-----------------------------------------------------------------------------
370 void PARSER_ADD_USER::CreateAnswer()
372 if (CheckUserData() == 0)
373 answer = "<AddUser result=\"ok\"/>";
375 answer = "<AddUser result=\"error\" reason=\"Access denied\"/>";
377 //-----------------------------------------------------------------------------
378 int PARSER_ADD_USER::CheckUserData()
381 if (users->FindByName(login, &u))
383 return users->Add(login, currAdmin);
387 //-----------------------------------------------------------------------------
389 //-----------------------------------------------------------------------------
390 PARSER_CHG_USER::PARSER_CHG_USER()
398 cashMustBeAdded(false),
403 //-----------------------------------------------------------------------------
404 PARSER_CHG_USER::~PARSER_CHG_USER()
411 //-----------------------------------------------------------------------------
412 void PARSER_CHG_USER::Reset()
423 usr = new USER_STAT_RES;
424 ucr = new USER_CONF_RES;
426 upr = new RESETABLE<uint64_t>[DIR_NUM];
427 downr = new RESETABLE<uint64_t>[DIR_NUM];
429 //-----------------------------------------------------------------------------
430 std::string PARSER_CHG_USER::EncChar2String(const char * strEnc)
433 Decode21str(str, strEnc);
436 //-----------------------------------------------------------------------------
437 int PARSER_CHG_USER::ParseStart(void *, const char *el, const char **attr)
443 if (strcasecmp(el, "SetUser") == 0)
450 //printfd(__FILE__, "el=%s\n", el);
451 if (strcasecmp(el, "login") == 0)
457 if (strcasecmp(el, "ip") == 0)
461 ucr->ips = StrToIPS(attr[1]);
465 printfd(__FILE__, "StrToIPS Error!\n");
469 if (strcasecmp(el, "password") == 0)
471 ucr->password = attr[1];
475 if (strcasecmp(el, "address") == 0)
477 ucr->address = EncChar2String(attr[1]);
481 if (strcasecmp(el, "aonline") == 0)
483 ucr->alwaysOnline = (*(attr[1]) != '0');
487 if (strcasecmp(el, "cash") == 0)
489 if (attr[2] && (strcasecmp(attr[2], "msg") == 0))
491 cashMsg = EncChar2String(attr[3]);
495 if (strtodouble2(attr[1], cash) == 0)
498 if (strcasecmp(attr[0], "set") == 0)
499 cashMustBeAdded = false;
501 if (strcasecmp(attr[0], "add") == 0)
502 cashMustBeAdded = true;
507 if (strcasecmp(el, "CreditExpire") == 0)
509 long int creditExpire = 0;
510 if (str2x(attr[1], creditExpire) == 0)
511 ucr->creditExpire = (time_t)creditExpire;
516 if (strcasecmp(el, "credit") == 0)
519 if (strtodouble2(attr[1], credit) == 0)
520 ucr->credit = credit;
524 if (strcasecmp(el, "freemb") == 0)
527 if (strtodouble2(attr[1], freeMb) == 0)
528 usr->freeMb = freeMb;
532 if (strcasecmp(el, "down") == 0)
535 if (str2x(attr[1], down) == 0)
536 ucr->disabled = down;
540 if (strcasecmp(el, "DisableDetailStat") == 0)
542 int disabledDetailStat = 0;
543 if (str2x(attr[1], disabledDetailStat) == 0)
544 ucr->disabledDetailStat = disabledDetailStat;
548 if (strcasecmp(el, "email") == 0)
550 ucr->email = EncChar2String(attr[1]);
554 for (int i = 0; i < USERDATA_NUM; i++)
557 sprintf(name, "userdata%d", i);
558 if (strcasecmp(el, name) == 0)
560 ucr->userdata[i] = EncChar2String(attr[1]);
565 if (strcasecmp(el, "group") == 0)
567 ucr->group = EncChar2String(attr[1]);
571 if (strcasecmp(el, "note") == 0)
573 ucr->note = EncChar2String(attr[1]);
577 if (strcasecmp(el, "passive") == 0)
580 if (str2x(attr[1], passive) == 0)
581 ucr->passive = passive;
585 if (strcasecmp(el, "phone") == 0)
587 ucr->phone = EncChar2String(attr[1]);
591 if (strcasecmp(el, "Name") == 0)
593 ucr->realName = EncChar2String(attr[1]);
597 if (strcasecmp(el, "traff") == 0)
605 int dir = attr[j][2] - '0';
607 if (strncasecmp(attr[j], "md", 2) == 0)
613 if (strncasecmp(attr[j], "mu", 2) == 0)
624 if (strcasecmp(el, "tariff") == 0)
626 if (strcasecmp(attr[0], "now") == 0)
627 ucr->tariffName = attr[1];
629 if (strcasecmp(attr[0], "delayed") == 0)
630 ucr->nextTariff = attr[1];
637 //-----------------------------------------------------------------------------
638 int PARSER_CHG_USER::ParseEnd(void *, const char *el)
642 if (strcasecmp(el, "SetUser") == 0)
654 //-----------------------------------------------------------------------------
655 void PARSER_CHG_USER::CreateAnswer()
660 answer = "<SetUser result=\"ok\"/>";
663 answer = "<SetUser result=\"error\"/>";
666 answer = "<SetUser result=\"error\"/>";
669 answer = "<SetUser result=\"error\"/>";
674 //-----------------------------------------------------------------------------
675 int PARSER_CHG_USER::AplayChanges()
677 printfd(__FILE__, "PARSER_CHG_USER::AplayChanges()\n");
681 if (users->FindByName(login, &u))
688 bool alwaysOnline = u->GetProperty().alwaysOnline;
689 if (!ucr->alwaysOnline.empty())
692 alwaysOnline = ucr->alwaysOnline.const_data();
694 bool onlyOneIP = u->GetProperty().ips.ConstData().OnlyOneIP();
695 if (!ucr->ips.empty())
698 onlyOneIP = ucr->ips.const_data().OnlyOneIP();
701 if (check && alwaysOnline && !onlyOneIP)
703 printfd(__FILE__, "Requested change leads to a forbidden state: AlwaysOnline with multiple IP's\n");
704 GetStgLogger()("%s Requested change leads to a forbidden state: AlwaysOnline with multiple IP's", currAdmin->GetLogStr().c_str());
709 for (size_t i = 0; i < ucr->ips.const_data().Count(); ++i)
712 uint32_t ip = ucr->ips.const_data().operator[](i).ip;
713 if (users->IsIPInUse(ip, login, &user))
715 printfd(__FILE__, "Trying to assign an IP %s to '%s' that is already in use by '%s'\n", inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str());
716 GetStgLogger()("%s trying to assign an IP %s to '%s' that is currently in use by '%s'", currAdmin->GetLogStr().c_str(), inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str());
722 if (!ucr->ips.empty())
723 if (!u->GetProperty().ips.Set(ucr->ips.const_data(), currAdmin, login, store))
726 if (!ucr->alwaysOnline.empty())
727 if (!u->GetProperty().alwaysOnline.Set(ucr->alwaysOnline.const_data(),
728 currAdmin, login, store))
731 if (!ucr->address.empty())
732 if (!u->GetProperty().address.Set(ucr->address.const_data(), currAdmin, login, store))
735 if (!ucr->creditExpire.empty())
736 if (!u->GetProperty().creditExpire.Set(ucr->creditExpire.const_data(),
737 currAdmin, login, store))
740 if (!ucr->credit.empty())
741 if (!u->GetProperty().credit.Set(ucr->credit.const_data(), currAdmin, login, store))
744 if (!usr->freeMb.empty())
745 if (!u->GetProperty().freeMb.Set(usr->freeMb.const_data(), currAdmin, login, store))
748 if (!ucr->disabled.empty())
749 if (!u->GetProperty().disabled.Set(ucr->disabled.const_data(), currAdmin, login, store))
752 if (!ucr->disabledDetailStat.empty())
753 if (!u->GetProperty().disabledDetailStat.Set(ucr->disabledDetailStat.const_data(), currAdmin, login, store))
756 if (!ucr->email.empty())
757 if (!u->GetProperty().email.Set(ucr->email.const_data(), currAdmin, login, store))
760 if (!ucr->group.empty())
761 if (!u->GetProperty().group.Set(ucr->group.const_data(), currAdmin, login, store))
764 if (!ucr->note.empty())
765 if (!u->GetProperty().note.Set(ucr->note.const_data(), currAdmin, login, store))
768 std::vector<USER_PROPERTY_LOGGED<std::string> *> userdata;
769 userdata.push_back(u->GetProperty().userdata0.GetPointer());
770 userdata.push_back(u->GetProperty().userdata1.GetPointer());
771 userdata.push_back(u->GetProperty().userdata2.GetPointer());
772 userdata.push_back(u->GetProperty().userdata3.GetPointer());
773 userdata.push_back(u->GetProperty().userdata4.GetPointer());
774 userdata.push_back(u->GetProperty().userdata5.GetPointer());
775 userdata.push_back(u->GetProperty().userdata6.GetPointer());
776 userdata.push_back(u->GetProperty().userdata7.GetPointer());
777 userdata.push_back(u->GetProperty().userdata8.GetPointer());
778 userdata.push_back(u->GetProperty().userdata9.GetPointer());
780 for (int i = 0; i < (int)userdata.size(); i++)
782 if (!ucr->userdata[i].empty())
784 if(!userdata[i]->Set(ucr->userdata[i].const_data(), currAdmin, login, store))
789 if (!ucr->passive.empty())
790 if (!u->GetProperty().passive.Set(ucr->passive.const_data(), currAdmin, login, store))
793 if (!ucr->password.empty())
794 if (!u->GetProperty().password.Set(ucr->password.const_data(), currAdmin, login, store))
797 if (!ucr->phone.empty())
798 if (!u->GetProperty().phone.Set(ucr->phone.const_data(), currAdmin, login, store))
801 if (!ucr->realName.empty())
802 if (!u->GetProperty().realName.Set(ucr->realName.const_data(), currAdmin, login, store))
806 if (!usr->cash.empty())
808 //if (*currAdmin->GetPriv()->userCash)
812 if (!u->GetProperty().cash.Set(usr->cash.const_data() + u->GetProperty().cash,
821 if (!u->GetProperty().cash.Set(usr->cash.const_data(), currAdmin, login, store, cashMsg))
828 if (!ucr->tariffName.empty())
830 if (tariffs->FindByName(ucr->tariffName.const_data()))
832 if (!u->GetProperty().tariffName.Set(ucr->tariffName.const_data(), currAdmin, login, store))
834 u->ResetNextTariff();
838 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
843 if (!ucr->nextTariff.empty())
845 if (tariffs->FindByName(ucr->nextTariff.const_data()))
847 if (!u->GetProperty().nextTariff.Set(ucr->nextTariff.const_data(), currAdmin, login, store))
852 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
857 DIR_TRAFF up = u->GetProperty().up;
858 DIR_TRAFF down = u->GetProperty().down;
861 for (int i = 0; i < DIR_NUM; i++)
865 up[i] = upr[i].data();
868 if (!downr[i].empty())
870 down[i] = downr[i].data();
876 if (!u->GetProperty().up.Set(up, currAdmin, login, store))
880 if (!u->GetProperty().down.Set(down, currAdmin, login, store))
888 //-----------------------------------------------------------------------------
890 //-----------------------------------------------------------------------------
891 int PARSER_SEND_MESSAGE::ParseStart(void *, const char *el, const char **attr)
893 if (strcasecmp(el, "Message") == 0)
895 for (int i = 0; i < 14; i++)
899 result = res_params_error;
901 printfd(__FILE__, "To few parameters\n");
906 for (int i = 0; i < 14; i+=2)
908 if (strcasecmp(attr[i], "login") == 0)
910 ParseLogins(attr[i+1]);
911 /*if (users->FindByName(login, &u))
913 result = res_unknown;
918 if (strcasecmp(attr[i], "MsgVer") == 0)
920 str2x(attr[i+1], msg.header.ver);
921 if (msg.header.ver != 1)
922 result = res_params_error;
925 if (strcasecmp(attr[i], "MsgType") == 0)
927 str2x(attr[i+1], msg.header.type);
928 if (msg.header.type != 1)
929 result = res_params_error;
932 if (strcasecmp(attr[i], "Repeat") == 0)
934 str2x(attr[i+1], msg.header.repeat);
935 if (msg.header.repeat < 0)
936 result = res_params_error;
939 if (strcasecmp(attr[i], "RepeatPeriod") == 0)
941 str2x(attr[i+1], msg.header.repeatPeriod);
944 if (strcasecmp(attr[i], "ShowTime") == 0)
946 str2x(attr[i+1], msg.header.showTime);
949 if (strcasecmp(attr[i], "Text") == 0)
951 Decode21str(msg.text, attr[i+1]);
959 //-----------------------------------------------------------------------------
960 int PARSER_SEND_MESSAGE::ParseEnd(void *, const char *el)
963 if (strcasecmp(el, "Message") == 0)
965 result = res_unknown;
966 for (unsigned i = 0; i < logins.size(); i++)
968 if (users->FindByName(logins[i], &u))
970 printfd(__FILE__, "User not found. %s\n", logins[i].c_str());
973 msg.header.creationTime = static_cast<unsigned int>(stgTime);
977 /*if (result == res_ok)
979 if (strcmp(login, "*") == 0)
983 printfd(__FILE__, "SendMsg text: %s\n", text);
984 users->GetAllUsers(SendMessageAllUsers, &msg);
988 u->AddMessage(pri, text);
996 //-----------------------------------------------------------------------------
997 int PARSER_SEND_MESSAGE::ParseLogins(const char * login)
1000 char * l = new char[strlen(login) + 1];
1006 logins.push_back(p);
1007 p = strtok(NULL, ":");
1013 //-----------------------------------------------------------------------------
1014 void PARSER_SEND_MESSAGE::CreateAnswer()
1019 answer = "<SendMessageResult value=\"ok\"/>";
1021 case res_params_error:
1022 printfd(__FILE__, "res_params_error\n");
1023 answer = "<SendMessageResult value=\"Parameters error.\"/>";
1026 printfd(__FILE__, "res_unknown\n");
1027 answer = "<SendMessageResult value=\"Unknown user.\"/>";
1030 printfd(__FILE__, "res_default\n");
1034 //-----------------------------------------------------------------------------
1036 //-----------------------------------------------------------------------------
1037 int PARSER_DEL_USER::ParseStart(void *, const char *el, const char **attr)
1040 if (strcasecmp(el, "DelUser") == 0)
1042 if (attr[0] == NULL || attr[1] == NULL)
1044 //CreateAnswer("Parameters error!");
1049 if (users->FindByName(attr[1], &u))
1060 //-----------------------------------------------------------------------------
1061 int PARSER_DEL_USER::ParseEnd(void *, const char *el)
1063 if (strcasecmp(el, "DelUser") == 0)
1066 users->Del(u->GetLogin(), currAdmin);
1072 //-----------------------------------------------------------------------------
1073 void PARSER_DEL_USER::CreateAnswer()
1076 answer = "<DelUser value=\"error\" reason=\"User not found\"/>";
1078 answer = "<DelUser value=\"ok\"/>";
1080 //-----------------------------------------------------------------------------
1081 /*void PARSERDELUSER::CreateAnswer(char * mes)
1083 //answerList->clear();
1084 answerList->erase(answerList->begin(), answerList->end());
1087 sprintf(str, "<DelUser value=\"%s\"/>", mes);
1088 answerList->push_back(str);
1090 //-----------------------------------------------------------------------------
1092 // <checkuser login="vasya" password=\"123456\"/>
1093 //-----------------------------------------------------------------------------
1094 int PARSER_CHECK_USER::ParseStart(void *, const char *el, const char **attr)
1098 if (strcasecmp(el, "CheckUser") == 0)
1100 if (attr[0] == NULL || attr[1] == NULL
1101 || attr[2] == NULL || attr[3] == NULL)
1105 printfd(__FILE__, "PARSER_CHECK_USER - attr err\n");
1110 if (users->FindByName(attr[1], &user))
1114 printfd(__FILE__, "PARSER_CHECK_USER - login err\n");
1118 if (strcmp(user->GetProperty().password.Get().c_str(), attr[3]))
1122 printfd(__FILE__, "PARSER_CHECK_USER - passwd err\n");
1132 //-----------------------------------------------------------------------------
1133 int PARSER_CHECK_USER::ParseEnd(void *, const char *el)
1135 if (strcasecmp(el, "CheckUser") == 0)
1141 //-----------------------------------------------------------------------------
1142 void PARSER_CHECK_USER::CreateAnswer()
1145 answer = std::string("<CheckUser value=\"Err\" reason=\"") + error + "\"/>";
1147 answer = "<CheckUser value=\"Ok\"/>";
1149 //-----------------------------------------------------------------------------
1150 //-----------------------------------------------------------------------------
1151 //-----------------------------------------------------------------------------