2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23 #include "stg/tariffs.h"
24 #include "stg/admin.h"
25 #include "stg/users.h"
26 #include "stg/user_property.h"
27 #include "stg/settings.h"
28 #include "stg/logger.h"
29 #include "stg/version.h"
30 #include "stg/store.h"
33 #include <cstdio> // sprintf
35 #include <sys/utsname.h>
37 #define UNAME_LEN (256)
42 std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_t lastTime = 0)
47 answer += "<User result=\"ok\">";
49 answer += "<User result=\"ok\" login=\"" + user.GetLogin() + "\">";
51 answer += "<Login value=\"" + user.GetLogin() + "\"/>";
53 if (user.GetProperty().password.ModificationTime() > lastTime)
56 answer += "<Password value=\"" + user.GetProperty().password.Get() + "\" />";
58 answer += "<Password value=\"++++++\"/>";
61 if (user.GetProperty().cash.ModificationTime() > lastTime)
62 answer += "<Cash value=\"" + x2str(user.GetProperty().cash.Get()) + "\"/>";
63 if (user.GetProperty().freeMb.ModificationTime() > lastTime)
64 answer += "<FreeMb value=\"" + x2str(user.GetProperty().freeMb.Get()) + "\"/>";
65 if (user.GetProperty().credit.ModificationTime() > lastTime)
66 answer += "<Credit value=\"" + x2str(user.GetProperty().credit.Get()) + "\"/>";
68 if (user.GetProperty().nextTariff.Get() != "")
70 if (user.GetProperty().tariffName.ModificationTime() > lastTime ||
71 user.GetProperty().nextTariff.ModificationTime() > lastTime)
72 answer += "<Tariff value=\"" + user.GetProperty().tariffName.Get() + "/" + user.GetProperty().nextTariff.Get() + "\"/>";
76 if (user.GetProperty().tariffName.ModificationTime() > lastTime)
77 answer += "<Tariff value=\"" + user.GetProperty().tariffName.Get() + "\"/>";
80 if (user.GetProperty().note.ModificationTime() > lastTime)
81 answer += "<Note value=\"" + Encode12str(user.GetProperty().note) + "\"/>";
82 if (user.GetProperty().phone.ModificationTime() > lastTime)
83 answer += "<Phone value=\"" + Encode12str(user.GetProperty().phone) + "\"/>";
84 if (user.GetProperty().address.ModificationTime() > lastTime)
85 answer += "<Address value=\"" + Encode12str(user.GetProperty().address) + "\"/>";
86 if (user.GetProperty().email.ModificationTime() > lastTime)
87 answer += "<Email value=\"" + Encode12str(user.GetProperty().email) + "\"/>";
89 std::vector<const USER_PROPERTY_LOGGED<std::string> *> userdata;
90 userdata.push_back(user.GetProperty().userdata0.GetPointer());
91 userdata.push_back(user.GetProperty().userdata1.GetPointer());
92 userdata.push_back(user.GetProperty().userdata2.GetPointer());
93 userdata.push_back(user.GetProperty().userdata3.GetPointer());
94 userdata.push_back(user.GetProperty().userdata4.GetPointer());
95 userdata.push_back(user.GetProperty().userdata5.GetPointer());
96 userdata.push_back(user.GetProperty().userdata6.GetPointer());
97 userdata.push_back(user.GetProperty().userdata7.GetPointer());
98 userdata.push_back(user.GetProperty().userdata8.GetPointer());
99 userdata.push_back(user.GetProperty().userdata9.GetPointer());
101 for (size_t i = 0; i < userdata.size(); i++)
102 if (userdata[i]->ModificationTime() > lastTime)
103 answer += "<UserData" + x2str(i) + " value=\"" + Encode12str(userdata[i]->Get()) + "\" />";
105 if (user.GetProperty().realName.ModificationTime() > lastTime)
106 answer += "<Name value=\"" + Encode12str(user.GetProperty().realName) + "\"/>";
107 if (user.GetProperty().group.ModificationTime() > lastTime)
108 answer += "<Group value=\"" + Encode12str(user.GetProperty().group) + "\"/>";
109 if (user.GetConnectedModificationTime() > lastTime)
110 answer += std::string("<Status value=\"") + (user.GetConnected() ? "1" : "0") + "\"/>";
111 if (user.GetProperty().alwaysOnline.ModificationTime() > lastTime)
112 answer += std::string("<AOnline value=\"") + (user.GetProperty().alwaysOnline.Get() ? "1" : "0") + "\"/>";
113 if (user.GetCurrIPModificationTime() > lastTime)
114 answer += "<CurrIP value=\"" + inet_ntostring(user.GetCurrIP()) + "\"/>";
115 if (user.GetPingTime() > lastTime)
116 answer += "<PingTime value=\"" + x2str(user.GetPingTime()) + "\"/>";
117 if (user.GetProperty().ips.ModificationTime() > lastTime)
118 answer += "<IP value=\"" + user.GetProperty().ips.Get().GetIpStr() + "\"/>";
121 const DIR_TRAFF & upload(user.GetProperty().down.Get());
122 const DIR_TRAFF & download(user.GetProperty().up.Get());
123 if (user.GetProperty().up.ModificationTime() > lastTime)
124 for (size_t j = 0; j < DIR_NUM; j++)
125 answer += " MU" + x2str(j) + "=\"" + x2str(upload[j]) + "\"";
126 if (user.GetProperty().down.ModificationTime() > lastTime)
127 for (size_t j = 0; j < DIR_NUM; j++)
128 answer += " MD" + x2str(j) + "=\"" + x2str(download[j]) + "\"";
129 if (user.GetSessionUploadModificationTime() > lastTime)
130 for (size_t j = 0; j < DIR_NUM; j++)
131 answer += " SU" + x2str(j) + "=\"" + x2str(user.GetSessionUpload()[j]) + "\"";
132 if (user.GetSessionDownloadModificationTime() > lastTime)
133 for (size_t j = 0; j < DIR_NUM; j++)
134 answer += " SD" + x2str(j) + "=\"" + x2str(user.GetSessionDownload()[j]) + "\"";
137 if (user.GetProperty().disabled.ModificationTime() > lastTime)
138 answer += std::string("<Down value=\"") + (user.GetProperty().disabled.Get() ? "1" : "0") + "\"/>";
139 if (user.GetProperty().disabledDetailStat.ModificationTime() > lastTime)
140 answer += std::string("<DisableDetailStat value=\"") + (user.GetProperty().disabledDetailStat.Get() ? "1" : "0") + "\"/>";
141 if (user.GetProperty().passive.ModificationTime() > lastTime)
142 answer += std::string("<Passive value=\"") + (user.GetProperty().passive.Get() ? "1" : "0") + "\"/>";
143 if (user.GetProperty().lastCashAdd.ModificationTime() > lastTime)
144 answer += "<LastCash value=\"" + x2str(user.GetProperty().lastCashAdd.Get()) + "\"/>";
145 if (user.GetProperty().lastCashAddTime.ModificationTime() > lastTime)
146 answer += "<LastTimeCash value=\"" + x2str(user.GetProperty().lastCashAddTime.Get()) + "\"/>";
147 if (user.GetProperty().lastActivityTime.ModificationTime() > lastTime)
148 answer += "<LastActivityTime value=\"" + x2str(user.GetProperty().lastActivityTime.Get()) + "\"/>";
149 if (user.GetProperty().creditExpire.ModificationTime() > lastTime)
150 answer += "<CreditExpire value=\"" + x2str(user.GetProperty().creditExpire.Get()) + "\"/>";
154 answer += "<AuthorizedBy>";
155 std::vector<std::string> list(user.GetAuthorizers());
156 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
157 answer += "<Auth name=\"" + *it + "\"/>";
158 answer += "</AuthorizedBy>";
166 } // namespace anonymous
168 //-----------------------------------------------------------------------------
170 //-----------------------------------------------------------------------------
171 int PARSER_GET_SERVER_INFO::ParseStart(void *, const char *el, const char **)
174 if (strcasecmp(el, "GetServerInfo") == 0)
180 //-----------------------------------------------------------------------------
181 int PARSER_GET_SERVER_INFO::ParseEnd(void *, const char *el)
183 if (strcasecmp(el, "GetServerInfo") == 0)
190 //-----------------------------------------------------------------------------
191 void PARSER_GET_SERVER_INFO::CreateAnswer()
199 strcat(un, utsn.sysname);
201 strcat(un, utsn.release);
203 strcat(un, utsn.machine);
205 strcat(un, utsn.nodename);
208 answer += "<ServerInfo>";
209 answer += std::string("<version value=\"") + SERVER_VERSION + "\"/>";
210 answer += "<tariff_num value=\"" + x2str(tariffs->Count()) + "\"/>";
211 answer += "<tariff value=\"2\"/>";
212 answer += "<user_num value=\"" + x2str(users->Count()) + "\"/>";
213 answer += std::string("<uname value=\"") + un + "\"/>";
214 answer += "<dir_num value=\"" + x2str(DIR_NUM) + "\"/>";
215 answer += "<day_fee value=\"" + x2str(settings->GetDayFee()) + "\"/>";
217 for (size_t i = 0; i< DIR_NUM; i++)
218 answer += "<dir_name_" + x2str(i) + " value=\"" + Encode12str(settings->GetDirName(i)) + "\"/>";
220 answer += "</ServerInfo>";
222 //-----------------------------------------------------------------------------
224 //-----------------------------------------------------------------------------
225 int PARSER_GET_USER::ParseStart(void *, const char *el, const char **attr)
227 if (strcasecmp(el, "GetUser") == 0)
229 if (attr[0] && attr[1])
234 login.erase(login.begin(), login.end());
241 //-----------------------------------------------------------------------------
242 int PARSER_GET_USER::ParseEnd(void *, const char *el)
244 if (strcasecmp(el, "GetUser") == 0)
251 //-----------------------------------------------------------------------------
252 void PARSER_GET_USER::CreateAnswer()
258 if (users->FindByName(login, &u))
260 answer = "<User result=\"error\" reason=\"User not found.\"/>";
264 answer = UserToXML(*u, false, currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd);
266 //-----------------------------------------------------------------------------
268 //-----------------------------------------------------------------------------
269 int PARSER_GET_USERS::ParseStart(void *, const char *el, const char ** attr)
271 /*if (attr && *attr && *(attr+1))
273 printfd(__FILE__, "attr=%s %s\n", *attr, *(attr+1));
277 printfd(__FILE__, "attr = NULL\n");
280 lastUpdateFound = false;
281 if (strcasecmp(el, "GetUsers") == 0)
283 while (attr && *attr && *(attr+1))
285 if (strcasecmp(*attr, "LastUpdate") == 0)
287 if (str2x(*(attr+1), lastUserUpdateTime) == 0)
289 //printfd(__FILE__, "lastUserUpdateTime=%d\n", lastUserUpdateTime);
290 lastUpdateFound = true;
294 //printfd(__FILE__, "NO lastUserUpdateTime\n");
304 //-----------------------------------------------------------------------------
305 int PARSER_GET_USERS::ParseEnd(void *, const char *el)
307 if (strcasecmp(el, "GetUsers") == 0)
314 //-----------------------------------------------------------------------------
315 void PARSER_GET_USERS::CreateAnswer()
319 int h = users->OpenSearch();
322 printfd(__FILE__, "users->OpenSearch() error\n");
323 users->CloseSearch(h);
328 answer += "<Users LastUpdate=\"" + x2str(time(NULL)) + "\">";
334 while (users->SearchNext(h, &u) == 0)
335 answer += UserToXML(*u, true, currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd, lastUserUpdateTime);
337 users->CloseSearch(h);
339 answer += "</Users>";
341 //-----------------------------------------------------------------------------
343 //-----------------------------------------------------------------------------
344 int PARSER_ADD_USER::ParseStart(void *, const char *el, const char **attr)
350 if (strcasecmp(el, "AddUser") == 0)
357 if (strcasecmp(el, "login") == 0)
365 //-----------------------------------------------------------------------------
366 int PARSER_ADD_USER::ParseEnd(void *, const char *el)
370 if (strcasecmp(el, "AddUser") == 0)
381 //-----------------------------------------------------------------------------
382 void PARSER_ADD_USER::Reset()
384 BASE_PARSER::Reset();
387 //-----------------------------------------------------------------------------
388 void PARSER_ADD_USER::CreateAnswer()
390 if (CheckUserData() == 0)
391 answer = "<AddUser result=\"ok\"/>";
393 answer = "<AddUser result=\"error\" reason=\"Access denied\"/>";
395 //-----------------------------------------------------------------------------
396 int PARSER_ADD_USER::CheckUserData()
399 if (users->FindByName(login, &u))
401 return users->Add(login, currAdmin);
405 //-----------------------------------------------------------------------------
407 //-----------------------------------------------------------------------------
408 PARSER_CHG_USER::PARSER_CHG_USER()
416 cashMustBeAdded(false),
421 //-----------------------------------------------------------------------------
422 PARSER_CHG_USER::~PARSER_CHG_USER()
429 //-----------------------------------------------------------------------------
430 void PARSER_CHG_USER::Reset()
441 usr = new USER_STAT_RES;
442 ucr = new USER_CONF_RES;
444 upr = new RESETABLE<uint64_t>[DIR_NUM];
445 downr = new RESETABLE<uint64_t>[DIR_NUM];
447 //-----------------------------------------------------------------------------
448 std::string PARSER_CHG_USER::EncChar2String(const char * strEnc)
451 Decode21str(str, strEnc);
454 //-----------------------------------------------------------------------------
455 int PARSER_CHG_USER::ParseStart(void *, const char *el, const char **attr)
461 if (strcasecmp(el, "SetUser") == 0)
468 //printfd(__FILE__, "el=%s\n", el);
469 if (strcasecmp(el, "login") == 0)
475 if (strcasecmp(el, "ip") == 0)
479 ucr->ips = StrToIPS(attr[1]);
483 printfd(__FILE__, "StrToIPS Error!\n");
487 if (strcasecmp(el, "password") == 0)
489 ucr->password = attr[1];
493 if (strcasecmp(el, "address") == 0)
495 ucr->address = EncChar2String(attr[1]);
499 if (strcasecmp(el, "aonline") == 0)
501 ucr->alwaysOnline = (*(attr[1]) != '0');
505 if (strcasecmp(el, "cash") == 0)
507 if (attr[2] && (strcasecmp(attr[2], "msg") == 0))
509 cashMsg = EncChar2String(attr[3]);
513 if (strtodouble2(attr[1], cash) == 0)
516 if (strcasecmp(attr[0], "set") == 0)
517 cashMustBeAdded = false;
519 if (strcasecmp(attr[0], "add") == 0)
520 cashMustBeAdded = true;
525 if (strcasecmp(el, "CreditExpire") == 0)
527 long int creditExpire = 0;
528 if (str2x(attr[1], creditExpire) == 0)
529 ucr->creditExpire = (time_t)creditExpire;
534 if (strcasecmp(el, "credit") == 0)
537 if (strtodouble2(attr[1], credit) == 0)
538 ucr->credit = credit;
542 if (strcasecmp(el, "freemb") == 0)
545 if (strtodouble2(attr[1], freeMb) == 0)
546 usr->freeMb = freeMb;
550 if (strcasecmp(el, "down") == 0)
553 if (str2x(attr[1], down) == 0)
554 ucr->disabled = down;
558 if (strcasecmp(el, "DisableDetailStat") == 0)
560 int disabledDetailStat = 0;
561 if (str2x(attr[1], disabledDetailStat) == 0)
562 ucr->disabledDetailStat = disabledDetailStat;
566 if (strcasecmp(el, "email") == 0)
568 ucr->email = EncChar2String(attr[1]);
572 for (int i = 0; i < USERDATA_NUM; i++)
575 sprintf(name, "userdata%d", i);
576 if (strcasecmp(el, name) == 0)
578 ucr->userdata[i] = EncChar2String(attr[1]);
583 if (strcasecmp(el, "group") == 0)
585 ucr->group = EncChar2String(attr[1]);
589 if (strcasecmp(el, "note") == 0)
591 ucr->note = EncChar2String(attr[1]);
595 if (strcasecmp(el, "passive") == 0)
598 if (str2x(attr[1], passive) == 0)
599 ucr->passive = passive;
603 if (strcasecmp(el, "phone") == 0)
605 ucr->phone = EncChar2String(attr[1]);
609 if (strcasecmp(el, "Name") == 0)
611 ucr->realName = EncChar2String(attr[1]);
615 if (strcasecmp(el, "traff") == 0)
623 int dir = attr[j][2] - '0';
625 if (strncasecmp(attr[j], "md", 2) == 0)
631 if (strncasecmp(attr[j], "mu", 2) == 0)
642 if (strcasecmp(el, "tariff") == 0)
644 if (strcasecmp(attr[0], "now") == 0)
645 ucr->tariffName = attr[1];
647 if (strcasecmp(attr[0], "delayed") == 0)
648 ucr->nextTariff = attr[1];
655 //-----------------------------------------------------------------------------
656 int PARSER_CHG_USER::ParseEnd(void *, const char *el)
660 if (strcasecmp(el, "SetUser") == 0)
672 //-----------------------------------------------------------------------------
673 void PARSER_CHG_USER::CreateAnswer()
678 answer = "<SetUser result=\"ok\"/>";
681 answer = "<SetUser result=\"error\"/>";
684 answer = "<SetUser result=\"error\"/>";
687 answer = "<SetUser result=\"error\"/>";
692 //-----------------------------------------------------------------------------
693 int PARSER_CHG_USER::AplayChanges()
695 printfd(__FILE__, "PARSER_CHG_USER::AplayChanges()\n");
699 if (users->FindByName(login, &u))
706 bool alwaysOnline = u->GetProperty().alwaysOnline;
707 if (!ucr->alwaysOnline.empty())
710 alwaysOnline = ucr->alwaysOnline.const_data();
712 bool onlyOneIP = u->GetProperty().ips.ConstData().OnlyOneIP();
713 if (!ucr->ips.empty())
716 onlyOneIP = ucr->ips.const_data().OnlyOneIP();
719 if (check && alwaysOnline && !onlyOneIP)
721 printfd(__FILE__, "Requested change leads to a forbidden state: AlwaysOnline with multiple IP's\n");
722 GetStgLogger()("%s Requested change leads to a forbidden state: AlwaysOnline with multiple IP's", currAdmin->GetLogStr().c_str());
727 for (size_t i = 0; i < ucr->ips.const_data().Count(); ++i)
730 uint32_t ip = ucr->ips.const_data().operator[](i).ip;
731 if (users->IsIPInUse(ip, login, &user))
733 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());
734 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());
740 if (!ucr->ips.empty())
741 if (!u->GetProperty().ips.Set(ucr->ips.const_data(), currAdmin, login, store))
744 if (!ucr->alwaysOnline.empty())
745 if (!u->GetProperty().alwaysOnline.Set(ucr->alwaysOnline.const_data(),
746 currAdmin, login, store))
749 if (!ucr->address.empty())
750 if (!u->GetProperty().address.Set(ucr->address.const_data(), currAdmin, login, store))
753 if (!ucr->creditExpire.empty())
754 if (!u->GetProperty().creditExpire.Set(ucr->creditExpire.const_data(),
755 currAdmin, login, store))
758 if (!ucr->credit.empty())
759 if (!u->GetProperty().credit.Set(ucr->credit.const_data(), currAdmin, login, store))
762 if (!usr->freeMb.empty())
763 if (!u->GetProperty().freeMb.Set(usr->freeMb.const_data(), currAdmin, login, store))
766 if (!ucr->disabled.empty())
767 if (!u->GetProperty().disabled.Set(ucr->disabled.const_data(), currAdmin, login, store))
770 if (!ucr->disabledDetailStat.empty())
771 if (!u->GetProperty().disabledDetailStat.Set(ucr->disabledDetailStat.const_data(), currAdmin, login, store))
774 if (!ucr->email.empty())
775 if (!u->GetProperty().email.Set(ucr->email.const_data(), currAdmin, login, store))
778 if (!ucr->group.empty())
779 if (!u->GetProperty().group.Set(ucr->group.const_data(), currAdmin, login, store))
782 if (!ucr->note.empty())
783 if (!u->GetProperty().note.Set(ucr->note.const_data(), currAdmin, login, store))
786 std::vector<USER_PROPERTY_LOGGED<std::string> *> userdata;
787 userdata.push_back(u->GetProperty().userdata0.GetPointer());
788 userdata.push_back(u->GetProperty().userdata1.GetPointer());
789 userdata.push_back(u->GetProperty().userdata2.GetPointer());
790 userdata.push_back(u->GetProperty().userdata3.GetPointer());
791 userdata.push_back(u->GetProperty().userdata4.GetPointer());
792 userdata.push_back(u->GetProperty().userdata5.GetPointer());
793 userdata.push_back(u->GetProperty().userdata6.GetPointer());
794 userdata.push_back(u->GetProperty().userdata7.GetPointer());
795 userdata.push_back(u->GetProperty().userdata8.GetPointer());
796 userdata.push_back(u->GetProperty().userdata9.GetPointer());
798 for (int i = 0; i < (int)userdata.size(); i++)
800 if (!ucr->userdata[i].empty())
802 if(!userdata[i]->Set(ucr->userdata[i].const_data(), currAdmin, login, store))
807 if (!ucr->passive.empty())
808 if (!u->GetProperty().passive.Set(ucr->passive.const_data(), currAdmin, login, store))
811 if (!ucr->password.empty())
812 if (!u->GetProperty().password.Set(ucr->password.const_data(), currAdmin, login, store))
815 if (!ucr->phone.empty())
816 if (!u->GetProperty().phone.Set(ucr->phone.const_data(), currAdmin, login, store))
819 if (!ucr->realName.empty())
820 if (!u->GetProperty().realName.Set(ucr->realName.const_data(), currAdmin, login, store))
824 if (!usr->cash.empty())
826 //if (*currAdmin->GetPriv()->userCash)
830 if (!u->GetProperty().cash.Set(usr->cash.const_data() + u->GetProperty().cash,
839 if (!u->GetProperty().cash.Set(usr->cash.const_data(), currAdmin, login, store, cashMsg))
846 if (!ucr->tariffName.empty())
848 if (tariffs->FindByName(ucr->tariffName.const_data()))
850 if (!u->GetProperty().tariffName.Set(ucr->tariffName.const_data(), currAdmin, login, store))
852 u->ResetNextTariff();
856 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
861 if (!ucr->nextTariff.empty())
863 if (tariffs->FindByName(ucr->nextTariff.const_data()))
865 if (!u->GetProperty().nextTariff.Set(ucr->nextTariff.const_data(), currAdmin, login, store))
870 //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
875 DIR_TRAFF up = u->GetProperty().up;
876 DIR_TRAFF down = u->GetProperty().down;
879 for (int i = 0; i < DIR_NUM; i++)
883 up[i] = upr[i].data();
886 if (!downr[i].empty())
888 down[i] = downr[i].data();
894 if (!u->GetProperty().up.Set(up, currAdmin, login, store))
898 if (!u->GetProperty().down.Set(down, currAdmin, login, store))
906 //-----------------------------------------------------------------------------
908 //-----------------------------------------------------------------------------
909 int PARSER_SEND_MESSAGE::ParseStart(void *, const char *el, const char **attr)
911 if (strcasecmp(el, "Message") == 0)
913 for (int i = 0; i < 14; i++)
917 result = res_params_error;
919 printfd(__FILE__, "To few parameters\n");
924 for (int i = 0; i < 14; i+=2)
926 if (strcasecmp(attr[i], "login") == 0)
928 ParseLogins(attr[i+1]);
929 /*if (users->FindByName(login, &u))
931 result = res_unknown;
936 if (strcasecmp(attr[i], "MsgVer") == 0)
938 str2x(attr[i+1], msg.header.ver);
939 if (msg.header.ver != 1)
940 result = res_params_error;
943 if (strcasecmp(attr[i], "MsgType") == 0)
945 str2x(attr[i+1], msg.header.type);
946 if (msg.header.type != 1)
947 result = res_params_error;
950 if (strcasecmp(attr[i], "Repeat") == 0)
952 str2x(attr[i+1], msg.header.repeat);
953 if (msg.header.repeat < 0)
954 result = res_params_error;
957 if (strcasecmp(attr[i], "RepeatPeriod") == 0)
959 str2x(attr[i+1], msg.header.repeatPeriod);
962 if (strcasecmp(attr[i], "ShowTime") == 0)
964 str2x(attr[i+1], msg.header.showTime);
967 if (strcasecmp(attr[i], "Text") == 0)
969 Decode21str(msg.text, attr[i+1]);
977 //-----------------------------------------------------------------------------
978 int PARSER_SEND_MESSAGE::ParseEnd(void *, const char *el)
981 if (strcasecmp(el, "Message") == 0)
983 result = res_unknown;
984 for (unsigned i = 0; i < logins.size(); i++)
986 if (users->FindByName(logins[i], &u))
988 printfd(__FILE__, "User not found. %s\n", logins[i].c_str());
991 msg.header.creationTime = static_cast<unsigned int>(stgTime);
995 /*if (result == res_ok)
997 if (strcmp(login, "*") == 0)
1001 printfd(__FILE__, "SendMsg text: %s\n", text);
1002 users->GetAllUsers(SendMessageAllUsers, &msg);
1006 u->AddMessage(pri, text);
1014 //-----------------------------------------------------------------------------
1015 int PARSER_SEND_MESSAGE::ParseLogins(const char * login)
1018 char * l = new char[strlen(login) + 1];
1024 logins.push_back(p);
1025 p = strtok(NULL, ":");
1031 //-----------------------------------------------------------------------------
1032 void PARSER_SEND_MESSAGE::CreateAnswer()
1037 answer = "<SendMessageResult value=\"ok\"/>";
1039 case res_params_error:
1040 printfd(__FILE__, "res_params_error\n");
1041 answer = "<SendMessageResult value=\"Parameters error.\"/>";
1044 printfd(__FILE__, "res_unknown\n");
1045 answer = "<SendMessageResult value=\"Unknown user.\"/>";
1048 printfd(__FILE__, "res_default\n");
1052 //-----------------------------------------------------------------------------
1054 //-----------------------------------------------------------------------------
1055 int PARSER_DEL_USER::ParseStart(void *, const char *el, const char **attr)
1058 if (strcasecmp(el, "DelUser") == 0)
1060 if (attr[0] == NULL || attr[1] == NULL)
1062 //CreateAnswer("Parameters error!");
1067 if (users->FindByName(attr[1], &u))
1078 //-----------------------------------------------------------------------------
1079 int PARSER_DEL_USER::ParseEnd(void *, const char *el)
1081 if (strcasecmp(el, "DelUser") == 0)
1084 users->Del(u->GetLogin(), currAdmin);
1090 //-----------------------------------------------------------------------------
1091 void PARSER_DEL_USER::CreateAnswer()
1094 answer = "<DelUser value=\"error\" reason=\"User not found\"/>";
1096 answer = "<DelUser value=\"ok\"/>";
1098 //-----------------------------------------------------------------------------
1099 /*void PARSERDELUSER::CreateAnswer(char * mes)
1101 //answerList->clear();
1102 answerList->erase(answerList->begin(), answerList->end());
1105 sprintf(str, "<DelUser value=\"%s\"/>", mes);
1106 answerList->push_back(str);
1108 //-----------------------------------------------------------------------------
1110 // <checkuser login="vasya" password=\"123456\"/>
1111 //-----------------------------------------------------------------------------
1112 int PARSER_CHECK_USER::ParseStart(void *, const char *el, const char **attr)
1116 if (strcasecmp(el, "CheckUser") == 0)
1118 if (attr[0] == NULL || attr[1] == NULL
1119 || attr[2] == NULL || attr[3] == NULL)
1123 printfd(__FILE__, "PARSER_CHECK_USER - attr err\n");
1128 if (users->FindByName(attr[1], &user))
1132 printfd(__FILE__, "PARSER_CHECK_USER - login err\n");
1136 if (strcmp(user->GetProperty().password.Get().c_str(), attr[3]))
1140 printfd(__FILE__, "PARSER_CHECK_USER - passwd err\n");
1150 //-----------------------------------------------------------------------------
1151 int PARSER_CHECK_USER::ParseEnd(void *, const char *el)
1153 if (strcasecmp(el, "CheckUser") == 0)
1159 //-----------------------------------------------------------------------------
1160 void PARSER_CHECK_USER::CreateAnswer()
1163 answer = std::string("<CheckUser value=\"Err\" reason=\"") + error + "\"/>";
1165 answer = "<CheckUser value=\"Ok\"/>";
1167 //-----------------------------------------------------------------------------
1168 //-----------------------------------------------------------------------------
1169 //-----------------------------------------------------------------------------