]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp
stg-2.409 pre-merge.
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / parser_users.cpp
index 797b4c46c3835f86186e516fd6f9f619b83aeadb..2e9d70872a82e3a7ac1ff92236c36c306060d582 100644 (file)
@@ -26,7 +26,6 @@
 #include "stg/user_property.h"
 #include "stg/user_conf.h"
 #include "stg/user_stat.h"
-#include "stg/common.h"
 
 #include <cstdio>
 #include <cassert>
@@ -38,6 +37,13 @@ using STG::PARSER::DEL_USER;
 using STG::PARSER::CHG_USER;
 using STG::PARSER::CHECK_USER;
 
+const char * GET_USERS::tag  = "GetUsers";
+const char * GET_USER::tag   = "GetUser";
+const char * ADD_USER::tag   = "AddUser";
+const char * CHG_USER::tag   = "SetUser";
+const char * DEL_USER::tag   = "DelUser";
+const char * CHECK_USER::tag = "CheckUser";
+
 namespace
 {
 
@@ -46,9 +52,9 @@ std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_
     std::string answer;
 
     if (loginInStart)
-        answer += "<User result=\"ok\">";
+        answer += "<User login=\"" + user.GetLogin() + "\" result=\"ok\">";
     else
-        answer += "<User result=\"ok\" login=\"" + user.GetLogin() + "\">";
+        answer += "<User result=\"ok\">";
 
     answer += "<Login value=\"" + user.GetLogin() + "\"/>";
 
@@ -120,8 +126,8 @@ std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_
         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());
+    const DIR_TRAFF & upload(user.GetProperty().up.Get());
+    const DIR_TRAFF & download(user.GetProperty().down.Get());
     if (user.GetProperty().up.ModificationTime() > lastTime)
         for (size_t j = 0; j < DIR_NUM; j++)
             answer += " MU" + x2str(j) + "=\"" + x2str(upload[j]) + "\"";
@@ -170,7 +176,10 @@ std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_
 int GET_USERS::Start(void *, const char * el, const char ** attr)
 {
     if (strcasecmp(el, m_tag.c_str()) != 0)
+    {
+        printfd(__FILE__, "Got wrong tag: '%s' instead of '%s'\n", el, m_tag.c_str());
         return -1;
+    }
 
     while (attr && *attr && *(attr + 1))
     {
@@ -188,9 +197,9 @@ void GET_USERS::CreateAnswer()
     assert(h);
 
     if (m_lastUserUpdateTime > 0)
-        m_answer = "<" + m_tag + " LastUpdate=\"" + x2str(time(NULL)) + "\">";
+        m_answer = "<Users LastUpdate=\"" + x2str(time(NULL)) + "\">";
     else
-        m_answer = GetOpenTag();
+        m_answer = "<Users>";
 
     USER_PTR u;
 
@@ -199,7 +208,7 @@ void GET_USERS::CreateAnswer()
 
     m_users.CloseSearch(h);
 
-    m_answer += GetCloseTag();
+    m_answer += "</Users>";
 }
 
 int GET_USER::Start(void *, const char * el, const char ** attr)
@@ -219,7 +228,7 @@ void GET_USER::CreateAnswer()
     CONST_USER_PTR u;
 
     if (m_users.FindByName(m_login, &u))
-        m_answer = "<" + m_tag + " result=\"error\" reason=\"User not found.\"/>";
+        m_answer = "<User result=\"error\" reason=\"User not found.\"/>";
     else
         m_answer = UserToXML(*u, false, m_currAdmin.GetPriv()->userConf || m_currAdmin.GetPriv()->userPasswd);
 }
@@ -565,8 +574,8 @@ int CHG_USER::ApplyChanges()
         if (!u->GetProperty().realName.Set(m_ucr.realName.const_data(), &m_currAdmin, m_login, &m_store))
             return -1;
 
-
     if (!m_usr.cash.empty())
+    {
         if (m_cashMustBeAdded)
         {
             if (!u->GetProperty().cash.Set(m_usr.cash.const_data() + u->GetProperty().cash,
@@ -575,11 +584,13 @@ int CHG_USER::ApplyChanges()
                                            &m_store,
                                            m_cashMsg))
                 return -1;
-            else
-                if (!u->GetProperty().cash.Set(m_usr.cash.const_data(), &m_currAdmin, m_login, &m_store, m_cashMsg))
-                    return -1;
         }
-
+        else
+        {
+            if (!u->GetProperty().cash.Set(m_usr.cash.const_data(), &m_currAdmin, m_login, &m_store, m_cashMsg))
+                return -1;
+        }
+    }
 
     if (!m_ucr.tariffName.empty())
     {