]> git.stg.codes - stg.git/commitdiff
Added GetUserInfo parser.
authorMaxim Mamontov <faust.madf@gmail.com>
Mon, 5 Aug 2013 17:28:05 +0000 (20:28 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Mon, 5 Aug 2013 17:28:05 +0000 (20:28 +0300)
projects/stargazer/plugins/configuration/sgconfig/Makefile
projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp [new file with mode: 0644]
projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h [new file with mode: 0644]

index 83e267d15992fdc5ef690d7f3750b42e7d39e65e..1b59f5cfa844da7c643e85e7318c58771fb01338 100644 (file)
@@ -12,7 +12,8 @@ SRCS = ./stgconfig.cpp \
        ./parser.cpp \
        ./parser_tariff.cpp \
        ./parser_admin.cpp \
-       ./parser_auth_by.cpp
+       ./parser_auth_by.cpp \
+       ./parser_user_info.cpp
 
 LIBS += -lexpat \
        $(LIB_THREAD)
diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp
new file mode 100644 (file)
index 0000000..72c3c6e
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "parser_user_info.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;
+
+login = attr[1];
+return 0;
+}
+
+int PARSER_USER_INFO::ParseEnd(void * /*data*/, const char *el)
+{
+if (strcasecmp(el, "GetUserInfo") != 0)
+    return -1;
+
+CreateAnswer();
+return 0;
+}
+
+void PARSER_USER_INFO::CreateAnswer()
+{
+answerList->clear();
+
+CONST_USER_PTR u;
+if (users->FindByName(login, &u))
+    {
+    answerList->push_back("<UserInfo result=\"error\"/>");
+    return;
+    }
+
+std::string s = "<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)
+    s += "<Auth name=\"" + *it + "\"/>";
+s += "</UserInfo>";
+answerList->push_back(s);
+}
diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h
new file mode 100644 (file)
index 0000000..91b022f
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_PARSER_USER_INFO_H__
+#define __STG_PARSER_USER_INFO_H__
+
+#include <string>
+
+#include "parser.h"
+
+class PARSER_USER_INFO : public BASE_PARSER {
+public:
+    int ParseStart(void *data, const char *el, const char **attr);
+    int ParseEnd(void *data, const char *el);
+
+private:
+    std::string login;
+
+    void CreateAnswer();
+};
+
+#endif