]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp
More stgTime cleanup.
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / parser_user_info.cpp
index 0e06a4a7ac12d9d41159933344f65c4202c5813c..ccc86d8ce9f694267d49d7955571eb902022ed0d 100644 (file)
 
 #include "parser_user_info.h"
 
+#include "stg/users.h"
 #include "stg/user.h"
-#include "stg/common.h"
 
 #include <strings.h> // strcasecmp
 
-int PARSER_USER_INFO::ParseStart(void * /*data*/, const char *el, const char **attr)
-{
-login.clear();
-if (strcasecmp(el, "GetUserInfo") != 0)
-    return -1;
-
-if (!attr[0] || !attr[1] || strcasecmp(attr[0], "login") != 0)
-    return -1;
+using STG::PARSER::USER_INFO;
 
-login = attr[1];
-return 0;
-}
+const char * USER_INFO::tag = "GetUserInfo";
 
-int PARSER_USER_INFO::ParseEnd(void * /*data*/, const char *el)
+int USER_INFO::Start(void * /*data*/, const char *el, const char **attr)
 {
-if (strcasecmp(el, "GetUserInfo") != 0)
-    return -1;
+    if (strcasecmp(el, m_tag.c_str()) != 0)
+        return -1;
+
+    if (!attr[1])
+        return -1;
 
-CreateAnswer();
-return 0;
+    m_login = attr[1];
+    return 0;
 }
 
-void PARSER_USER_INFO::CreateAnswer()
+void USER_INFO::CreateAnswer()
 {
-CONST_USER_PTR u;
-if (users->FindByName(login, &u))
+    using ConstUserPtr = const User*;
+    ConstUserPtr u;
+    if (m_users.FindByName(m_login, &u))
     {
-    answer = "<UserInfo result=\"error\"/>";
-    return;
+        m_answer = "<UserInfo result=\"error\"/>";
+        return;
     }
 
-answer = "<UserInfo lastAuthTime=\"" + x2str(u->GetAuthorizedModificationTime()) + "\"" +
-         " lastDisconnectTime=\"" + x2str(u->GetConnectedModificationTime()) + "\"" +
-         " connected=\"" + (u->GetConnected() ? "true" : "false") + "\"" +
-         " lastDisconnectReason=\"" + u->GetLastDisconnectReason() + "\">";
-std::vector<std::string> list(u->GetAuthorizers());
-for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
-    answer += "<Auth name=\"" + *it + "\"/>";
-answer += "</UserInfo>";
+    m_answer = "<UserInfo lastAuthTime=\"" + std::to_string(u->GetAuthorizedModificationTime()) + "\"" +
+             " lastDisconnectTime=\"" + std::to_string(u->GetConnectedModificationTime()) + "\"" +
+             " connected=\"" + (u->GetConnected() ? "true" : "false") + "\"" +
+             " lastDisconnectReason=\"" + u->GetLastDisconnectReason() + "\">";
+    std::vector<std::string> list(u->GetAuthorizers());
+    for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
+        m_answer += "<Auth name=\"" + *it + "\"/>";
+    m_answer += "</UserInfo>";
 }