From 76dfa1976656bc8a0781050b675d9ea5875f8b1b Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 5 Aug 2013 20:28:05 +0300 Subject: [PATCH] Added GetUserInfo parser. --- .../plugins/configuration/sgconfig/Makefile | 3 +- .../sgconfig/parser_user_info.cpp | 70 +++++++++++++++++++ .../configuration/sgconfig/parser_user_info.h | 39 +++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp create mode 100644 projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h diff --git a/projects/stargazer/plugins/configuration/sgconfig/Makefile b/projects/stargazer/plugins/configuration/sgconfig/Makefile index 83e267d1..1b59f5cf 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/Makefile +++ b/projects/stargazer/plugins/configuration/sgconfig/Makefile @@ -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 index 00000000..72c3c6ec --- /dev/null +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp @@ -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 + */ + +#include "parser_user_info.h" + +#include "stg/user.h" +#include "stg/common.h" + +#include // 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(""); + return; + } + +std::string s = "GetAuthorizedModificationTime()) + "\"" + + " lastDisconnectTime=\"" + x2str(u->GetConnectedModificationTime()) + "\"" + + " connected=\"" + (u->GetConnected() ? "true" : "false") + "\"" + + " lastDisconnectReason=\"" + u->GetLastDisconnectReason() + "\">"; +std::vector list(u->GetAuthorizers()); +for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) + s += ""; +s += ""; +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 index 00000000..91b022f1 --- /dev/null +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h @@ -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 + */ + +#ifndef __STG_PARSER_USER_INFO_H__ +#define __STG_PARSER_USER_INFO_H__ + +#include + +#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 -- 2.43.2