]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp
Optimized sending answers in sgconfig.
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / parser_admin.cpp
index b1285a772441d3facc49cd96937c05f11ba9c24d..7783888e37d24e632c4771bb2645a98ca00328c1 100644 (file)
@@ -30,37 +30,29 @@ void PARSER_GET_ADMINS::CreateAnswer()
 const PRIV * priv = currAdmin->GetPriv();
 if (!priv->adminChg)
     {
 const PRIV * priv = currAdmin->GetPriv();
 if (!priv->adminChg)
     {
-    //answerList->clear();
-    answerList->erase(answerList->begin(), answerList->end());
-
-    answerList->push_back("<Error Result=\"Error. Access denied.\"/>");
+    answer = "<Error Result=\"Error. Access denied.\"/>";
     return;
     }
 
     return;
     }
 
-std::string s;
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
+answer.clear();
 
 
-answerList->push_back("<Admins>");
+answer += "<Admins>";
 ADMIN_CONF ac;
 int h = admins->OpenSearch();
 
 ADMIN_CONF ac;
 int h = admins->OpenSearch();
 
-unsigned int p;
 while (admins->SearchNext(h, &ac) == 0)
     {
 while (admins->SearchNext(h, &ac) == 0)
     {
-    //memcpy(&p, &ac.priv, sizeof(unsigned int));
-    p = (ac.priv.userStat << 0) +
-        (ac.priv.userConf << 2) +
-        (ac.priv.userCash << 4) +
-        (ac.priv.userPasswd << 6) +
-        (ac.priv.userAddDel << 8) +
-        (ac.priv.adminChg << 10) +
-        (ac.priv.tariffChg << 12);
-    strprintf(&s, "<admin login=\"%s\" priv=\"%d\"/>", ac.login.c_str(), p);
-    answerList->push_back(s);
+    unsigned int p = (ac.priv.userStat << 0) +
+                     (ac.priv.userConf << 2) +
+                     (ac.priv.userCash << 4) +
+                     (ac.priv.userPasswd << 6) +
+                     (ac.priv.userAddDel << 8) +
+                     (ac.priv.adminChg << 10) +
+                     (ac.priv.tariffChg << 12);
+    answer += "<admin login=\"" + ac.login + "\" priv=\"" + x2str(p) + "\"/>";
     }
 admins->CloseSearch(h);
     }
 admins->CloseSearch(h);
-answerList->push_back("</Admins>");
+answer += "</Admins>";
 }
 //-----------------------------------------------------------------------------
 
 }
 //-----------------------------------------------------------------------------
 
@@ -90,33 +82,10 @@ return -1;
 //-----------------------------------------------------------------------------
 void PARSER_DEL_ADMIN::CreateAnswer()
 {
 //-----------------------------------------------------------------------------
 void PARSER_DEL_ADMIN::CreateAnswer()
 {
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
 if (admins->Del(adminToDel, currAdmin) == 0)
 if (admins->Del(adminToDel, currAdmin) == 0)
-    {
-    answerList->push_back("<DelAdmin Result=\"Ok\"/>");
-    }
+    answer = "<DelAdmin Result=\"Ok\"/>";
 else
 else
-    {
-    std::string s;
-    strprintf(&s, "<DelAdmin Result=\"Error. %s\"/>", admins->GetStrError().c_str());
-    answerList->push_back(s);
-    }
-}
-//-----------------------------------------------------------------------------
-int PARSER_DEL_ADMIN::CheckAttr(const char **attr)
-{
-/*  <DelAdmin login=\"admin\">
- *  attr[0] = "login" (word login)
- *  attr[1] = login, value of login
- *  attr[2] = NULL                  */
-
-if (strcasecmp(attr[0], "login") == 0 && attr[1] && !attr[2])
-    {
-    return 0;
-    }
-return -1;
+    answer = "<DelAdmin Result=\"Error. " + admins->GetStrError() + "\"/>";
 }
 //-----------------------------------------------------------------------------
 //  ADD ADMIN
 }
 //-----------------------------------------------------------------------------
 //  ADD ADMIN
@@ -133,9 +102,6 @@ return -1;
 //-----------------------------------------------------------------------------
 int PARSER_ADD_ADMIN::ParseEnd(void *, const char *el)
 {
 //-----------------------------------------------------------------------------
 int PARSER_ADD_ADMIN::ParseEnd(void *, const char *el)
 {
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
 if (strcasecmp(el, "AddAdmin") == 0)
     {
     CreateAnswer();
 if (strcasecmp(el, "AddAdmin") == 0)
     {
     CreateAnswer();
@@ -146,19 +112,10 @@ return -1;
 //-----------------------------------------------------------------------------
 void PARSER_ADD_ADMIN::CreateAnswer()
 {
 //-----------------------------------------------------------------------------
 void PARSER_ADD_ADMIN::CreateAnswer()
 {
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
 if (admins->Add(adminToAdd, currAdmin) == 0)
 if (admins->Add(adminToAdd, currAdmin) == 0)
-    {
-    answerList->push_back("<AddAdmin Result=\"Ok\"/>");
-    }
+    answer = "<AddAdmin Result=\"Ok\"/>";
 else
 else
-    {
-    std::string s;
-    strprintf(&s, "<AddAdmin Result=\"Error. %s\"/>", admins->GetStrError().c_str());
-    answerList->push_back(s);
-    }
+    answer = "<AddAdmin Result=\"Error. " + admins->GetStrError() + "\"/>";
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -210,16 +167,13 @@ return -1;
 //-----------------------------------------------------------------------------
 void PARSER_CHG_ADMIN::CreateAnswer()
 {
 //-----------------------------------------------------------------------------
 void PARSER_CHG_ADMIN::CreateAnswer()
 {
-answerList->erase(answerList->begin(), answerList->end());
-
-
 if (!login.empty())
     {
     ADMIN * origAdmin = NULL;
 
     if (admins->Find(login.data(), &origAdmin))
         {
 if (!login.empty())
     {
     ADMIN * origAdmin = NULL;
 
     if (admins->Find(login.data(), &origAdmin))
         {
-        answerList->push_back(std::string("<ChgAdmin Result = \"Admin '") + login.data() + "' is not found.\"/>");
+        answer = "<ChgAdmin Result = \"Admin '" + login.data() + "' is not found.\"/>";
         return;
         }
 
         return;
         }
 
@@ -233,7 +187,7 @@ if (!login.empty())
         int p = 0;
         if (str2x(privAsString.data().c_str(), p) < 0)
             {
         int p = 0;
         if (str2x(privAsString.data().c_str(), p) < 0)
             {
-            answerList->push_back("<ChgAdmin Result = \"Incorrect parameter Priv.\"/>");
+            answer = "<ChgAdmin Result = \"Incorrect parameter Priv.\"/>";
             return;
             }
 
             return;
             }
 
@@ -241,20 +195,10 @@ if (!login.empty())
         }
 
     if (admins->Change(conf, currAdmin) != 0)
         }
 
     if (admins->Change(conf, currAdmin) != 0)
-        {
-        std::string s;
-        strprintf(&s, "<ChgAdmin Result = \"%s\"/>", admins->GetStrError().c_str());
-        answerList->push_back(s);
-        }
+        answer = "<ChgAdmin Result = \"" + admins->GetStrError() + "\"/>";
     else
     else
-        {
-        answerList->push_back("<ChgAdmin Result = \"Ok\"/>");
-        }
+        answer = "<ChgAdmin Result = \"Ok\"/>";
     }
 else
     }
 else
-    {
-    answerList->push_back("<ChgAdmin Result = \"Incorrect parameter login.\"/>");
-    }
+    answer = "<ChgAdmin Result = \"Incorrect parameter login.\"/>";
 }
 }
-//-----------------------------------------------------------------------------*/
-