-#define UNAME_LEN (256)
-
-namespace
-{
-
-std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_t lastTime = 0)
-{
-std::string answer;
-
-if (loginInStart)
- answer += "<User result=\"ok\">";
-else
- answer += "<User result=\"ok\" login=\"" + user.GetLogin() + "\">";
-
-answer += "<Login value=\"" + user.GetLogin() + "\"/>";
-
-if (user.GetProperty().password.ModificationTime() > lastTime)
- {
- if (showPass)
- answer += "<Password value=\"" + user.GetProperty().password.Get() + "\" />";
- else
- answer += "<Password value=\"++++++\"/>";
- }
-
-if (user.GetProperty().cash.ModificationTime() > lastTime)
- answer += "<Cash value=\"" + x2str(user.GetProperty().cash.Get()) + "\"/>";
-if (user.GetProperty().freeMb.ModificationTime() > lastTime)
- answer += "<FreeMb value=\"" + x2str(user.GetProperty().freeMb.Get()) + "\"/>";
-if (user.GetProperty().credit.ModificationTime() > lastTime)
- answer += "<Credit value=\"" + x2str(user.GetProperty().credit.Get()) + "\"/>";
-
-if (user.GetProperty().nextTariff.Get() != "")
- {
- if (user.GetProperty().tariffName.ModificationTime() > lastTime ||
- user.GetProperty().nextTariff.ModificationTime() > lastTime)
- answer += "<Tariff value=\"" + user.GetProperty().tariffName.Get() + "/" + user.GetProperty().nextTariff.Get() + "\"/>";
- }
-else
- {
- if (user.GetProperty().tariffName.ModificationTime() > lastTime)
- answer += "<Tariff value=\"" + user.GetProperty().tariffName.Get() + "\"/>";
- }
-
-if (user.GetProperty().note.ModificationTime() > lastTime)
- answer += "<Note value=\"" + Encode12str(user.GetProperty().note) + "\"/>";
-if (user.GetProperty().phone.ModificationTime() > lastTime)
- answer += "<Phone value=\"" + Encode12str(user.GetProperty().phone) + "\"/>";
-if (user.GetProperty().address.ModificationTime() > lastTime)
- answer += "<Address value=\"" + Encode12str(user.GetProperty().address) + "\"/>";
-if (user.GetProperty().email.ModificationTime() > lastTime)
- answer += "<Email value=\"" + Encode12str(user.GetProperty().email) + "\"/>";
-
-std::vector<const USER_PROPERTY_LOGGED<std::string> *> userdata;
-userdata.push_back(user.GetProperty().userdata0.GetPointer());
-userdata.push_back(user.GetProperty().userdata1.GetPointer());
-userdata.push_back(user.GetProperty().userdata2.GetPointer());
-userdata.push_back(user.GetProperty().userdata3.GetPointer());
-userdata.push_back(user.GetProperty().userdata4.GetPointer());
-userdata.push_back(user.GetProperty().userdata5.GetPointer());
-userdata.push_back(user.GetProperty().userdata6.GetPointer());
-userdata.push_back(user.GetProperty().userdata7.GetPointer());
-userdata.push_back(user.GetProperty().userdata8.GetPointer());
-userdata.push_back(user.GetProperty().userdata9.GetPointer());
-
-for (size_t i = 0; i < userdata.size(); i++)
- if (userdata[i]->ModificationTime() > lastTime)
- answer += "<UserData" + x2str(i) + " value=\"" + Encode12str(userdata[i]->Get()) + "\" />";
-
-if (user.GetProperty().realName.ModificationTime() > lastTime)
- answer += "<Name value=\"" + Encode12str(user.GetProperty().realName) + "\"/>";
-if (user.GetProperty().group.ModificationTime() > lastTime)
- answer += "<Group value=\"" + Encode12str(user.GetProperty().group) + "\"/>";
-if (user.GetConnectedModificationTime() > lastTime)
- answer += std::string("<Status value=\"") + (user.GetConnected() ? "1" : "0") + "\"/>";
-if (user.GetProperty().alwaysOnline.ModificationTime() > lastTime)
- answer += std::string("<AOnline value=\"") + (user.GetProperty().alwaysOnline.Get() ? "1" : "0") + "\"/>";
-if (user.GetCurrIPModificationTime() > lastTime)
- answer += "<CurrIP value=\"" + inet_ntostring(user.GetCurrIP()) + "\"/>";
-if (user.GetPingTime() > lastTime)
- answer += "<PingTime value=\"" + x2str(user.GetPingTime()) + "\"/>";
-if (user.GetProperty().ips.ModificationTime() > lastTime)
- answer += "<IP value=\"" + user.GetProperty().ips.Get().GetIpStr() + "\"/>";
-
-answer += "<Traff";
-const DIR_TRAFF & upload(user.GetProperty().down.Get());
-const DIR_TRAFF & download(user.GetProperty().up.Get());
-if (user.GetProperty().up.ModificationTime() > lastTime)
- for (size_t j = 0; j < DIR_NUM; j++)
- answer += " MU" + x2str(j) + "=\"" + x2str(upload[j]) + "\"";
-if (user.GetProperty().down.ModificationTime() > lastTime)
- for (size_t j = 0; j < DIR_NUM; j++)
- answer += " MD" + x2str(j) + "=\"" + x2str(download[j]) + "\"";
-if (user.GetSessionUploadModificationTime() > lastTime)
- for (size_t j = 0; j < DIR_NUM; j++)
- answer += " SU" + x2str(j) + "=\"" + x2str(user.GetSessionUpload()[j]) + "\"";
-if (user.GetSessionDownloadModificationTime() > lastTime)
- for (size_t j = 0; j < DIR_NUM; j++)
- answer += " SD" + x2str(j) + "=\"" + x2str(user.GetSessionDownload()[j]) + "\"";
-answer += "/>";
-
-if (user.GetProperty().disabled.ModificationTime() > lastTime)
- answer += std::string("<Down value=\"") + (user.GetProperty().disabled.Get() ? "1" : "0") + "\"/>";
-if (user.GetProperty().disabledDetailStat.ModificationTime() > lastTime)
- answer += std::string("<DisableDetailStat value=\"") + (user.GetProperty().disabledDetailStat.Get() ? "1" : "0") + "\"/>";
-if (user.GetProperty().passive.ModificationTime() > lastTime)
- answer += std::string("<Passive value=\"") + (user.GetProperty().passive.Get() ? "1" : "0") + "\"/>";
-if (user.GetProperty().lastCashAdd.ModificationTime() > lastTime)
- answer += "<LastCash value=\"" + x2str(user.GetProperty().lastCashAdd.Get()) + "\"/>";
-if (user.GetProperty().lastCashAddTime.ModificationTime() > lastTime)
- answer += "<LastTimeCash value=\"" + x2str(user.GetProperty().lastCashAddTime.Get()) + "\"/>";
-if (user.GetProperty().lastActivityTime.ModificationTime() > lastTime)
- answer += "<LastActivityTime value=\"" + x2str(user.GetProperty().lastActivityTime.Get()) + "\"/>";
-if (user.GetProperty().creditExpire.ModificationTime() > lastTime)
- answer += "<CreditExpire value=\"" + x2str(user.GetProperty().creditExpire.Get()) + "\"/>";
-
-if (lastTime == 0)
- {
- answer += "<AuthorizedBy>";
- std::vector<std::string> list(user.GetAuthorizers());
- for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
- answer += "<Auth name=\"" + *it + "\"/>";
- answer += "</AuthorizedBy>";
- }
-
-answer += "</User>";
-
-return answer;
-}
-
-} // namespace anonymous
-
-//-----------------------------------------------------------------------------
-// GET SERVER INFO
-//-----------------------------------------------------------------------------
-int PARSER_GET_SERVER_INFO::ParseStart(void *, const char *el, const char **)
-{
-answer.clear();
-if (strcasecmp(el, "GetServerInfo") == 0)
- {
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_SERVER_INFO::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "GetServerInfo") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_SERVER_INFO::CreateAnswer()
-{
-char un[UNAME_LEN];
-struct utsname utsn;
-
-uname(&utsn);
-un[0] = 0;
-
-strcat(un, utsn.sysname);
-strcat(un, " ");
-strcat(un, utsn.release);
-strcat(un, " ");
-strcat(un, utsn.machine);
-strcat(un, " ");
-strcat(un, utsn.nodename);
-
-answer.clear();
-answer += "<ServerInfo>";
-answer += std::string("<version value=\"") + SERVER_VERSION + "\"/>";
-answer += "<tariff_num value=\"" + x2str(tariffs->Count()) + "\"/>";
-answer += "<tariff value=\"2\"/>";
-answer += "<user_num value=\"" + x2str(users->Count()) + "\"/>";
-answer += std::string("<uname value=\"") + un + "\"/>";
-answer += "<dir_num value=\"" + x2str(DIR_NUM) + "\"/>";
-answer += "<day_fee value=\"" + x2str(settings->GetDayFee()) + "\"/>";
-
-for (size_t i = 0; i< DIR_NUM; i++)
- answer += "<dir_name_" + x2str(i) + " value=\"" + Encode12str(settings->GetDirName(i)) + "\"/>";
-
-answer += "</ServerInfo>";
-}
-//-----------------------------------------------------------------------------
-// GET USER
-//-----------------------------------------------------------------------------
-int PARSER_GET_USER::ParseStart(void *, const char *el, const char **attr)
-{
-if (strcasecmp(el, "GetUser") == 0)
- {
- if (attr[0] && attr[1])
- login = attr[1];
- else
- {
- //login.clear();
- login.erase(login.begin(), login.end());
- return -1;
- }
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_USER::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "GetUser") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USER::CreateAnswer()
-{
-USER_PTR u;
-
-answer.clear();
-
-if (users->FindByName(login, &u))
- {
- answer = "<User result=\"error\" reason=\"User not found.\"/>";
- return;
- }
-
-answer = UserToXML(*u, false, currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd);
-}
-//-----------------------------------------------------------------------------
-// GET USERS
-//-----------------------------------------------------------------------------
-int PARSER_GET_USERS::ParseStart(void *, const char *el, const char ** attr)
-{
-/*if (attr && *attr && *(attr+1))
- {
- printfd(__FILE__, "attr=%s %s\n", *attr, *(attr+1));
- }
-else
- {
- printfd(__FILE__, "attr = NULL\n");
- }*/
-
-lastUpdateFound = false;
-if (strcasecmp(el, "GetUsers") == 0)
- {
- while (attr && *attr && *(attr+1))
- {
- if (strcasecmp(*attr, "LastUpdate") == 0)
- {
- if (str2x(*(attr+1), lastUserUpdateTime) == 0)
- {
- //printfd(__FILE__, "lastUserUpdateTime=%d\n", lastUserUpdateTime);
- lastUpdateFound = true;
- }
- else
- {
- //printfd(__FILE__, "NO lastUserUpdateTime\n");
- }
- }
- ++attr;
- }
-
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_USERS::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "GetUsers") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USERS::CreateAnswer()
-{
-answer.clear();
-
-int h = users->OpenSearch();
-if (!h)
- {
- printfd(__FILE__, "users->OpenSearch() error\n");
- users->CloseSearch(h);
- return;
- }
-
-if (lastUpdateFound)
- answer += "<Users LastUpdate=\"" + x2str(time(NULL)) + "\">";
-else
- answer += "<Users>";
-
-USER_PTR u;
-
-while (users->SearchNext(h, &u) == 0)
- answer += UserToXML(*u, true, currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd, lastUserUpdateTime);
-
-users->CloseSearch(h);
-
-answer += "</Users>";
-}
-//-----------------------------------------------------------------------------
-// ADD USER
-//-----------------------------------------------------------------------------
-int PARSER_ADD_USER::ParseStart(void *, const char *el, const char **attr)
-{
-depth++;
-
-if (depth == 1)
- {
- if (strcasecmp(el, "AddUser") == 0)
- {
- return 0;
- }
- }
-else
- {
- if (strcasecmp(el, "login") == 0)
- {
- login = attr[1];
- return 0;
- }
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_ADD_USER::ParseEnd(void *, const char *el)
-{
-if (depth == 1)
- {
- if (strcasecmp(el, "AddUser") == 0)
- {
- CreateAnswer();
- depth--;
- return 0;
- }
- }
-
-depth--;
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_ADD_USER::Reset()
-{
-BASE_PARSER::Reset();
-depth = 0;
-}
-//-----------------------------------------------------------------------------
-void PARSER_ADD_USER::CreateAnswer()
-{
-if (CheckUserData() == 0)
- answer = "<AddUser result=\"ok\"/>";
-else
- answer = "<AddUser result=\"error\" reason=\"Access denied\"/>";
-}
-//-----------------------------------------------------------------------------
-int PARSER_ADD_USER::CheckUserData()
-{
-USER_PTR u;
-if (users->FindByName(login, &u))
- {
- return users->Add(login, currAdmin);
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-// PARSER CHG USER
-//-----------------------------------------------------------------------------
-PARSER_CHG_USER::PARSER_CHG_USER()
- : BASE_PARSER(),
- usr(NULL),
- ucr(NULL),
- upr(NULL),
- downr(NULL),
- cashMsg(),
- login(),
- cashMustBeAdded(false),
- res(0)
-{
-Reset();
-}
-//-----------------------------------------------------------------------------
-PARSER_CHG_USER::~PARSER_CHG_USER()
-{
-delete usr;
-delete ucr;
-delete[] upr;
-delete[] downr;
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHG_USER::Reset()
-{
-depth = 0;
-delete usr;
-
-delete ucr;
-
-delete[] upr;
-
-delete[] downr;
-
-usr = new USER_STAT_RES;
-ucr = new USER_CONF_RES;