From: Maxim Mamontov Date: Fri, 20 Sep 2013 21:27:44 +0000 (+0300) Subject: Moved SERVER_INFO parser from global scope. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/9250e16a677fc52e7338b5c0b7b405e510831259?ds=inline Moved SERVER_INFO parser from global scope. --- diff --git a/stglibs/srvconf.lib/include/stg/parser_server_info.h b/stglibs/srvconf.lib/include/stg/parser_server_info.h deleted file mode 100644 index cb57bffd..00000000 --- a/stglibs/srvconf.lib/include/stg/parser_server_info.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 : Boris Mikhailenko - * Author : Maxim Mamontov - */ - -#ifndef __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ -#define __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ - -#include "parser.h" - -#include "property_parsers.h" -#include "stg/const.h" - -#include - -namespace STG -{ - -class PARSER_SERVER_INFO: public PARSER -{ -public: - struct INFO - { - std::string version; - int tariffNum; - int tariffType; - int usersNum; - std::string uname; - int dirNum; - std::string dirName[DIR_NUM]; - }; - typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); - - PARSER_SERVER_INFO(); - int ParseStart(const char * el, const char ** attr); - void ParseEnd(const char * el); - void SetCallback(CALLBACK f, void * data); -private: - PROPERTY_PARSERS propertyParsers; - CALLBACK callback; - void * data; - int depth; - bool parsingAnswer; - INFO info; - std::string error; -}; - -} - -#endif diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index e55cff2c..1b4033e3 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -27,7 +27,6 @@ #ifndef __STG_STGLIBS_SERVCONF_H__ #define __STG_STGLIBS_SERVCONF_H__ -#include "stg/parser_server_info.h" #include "stg/parser_check_user.h" #include "stg/parser_get_user.h" #include "stg/parser_get_users.h" @@ -55,7 +54,7 @@ public: int ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data); int AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data); int SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALLBACK f, void * data); - int ServerInfo(PARSER_SERVER_INFO::CALLBACK f, void * data); + int ServerInfo(SERVER_INFO::CALLBACK f, void * data); int CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data); const std::string & GetStrError() const; diff --git a/stglibs/srvconf.lib/include/stg/servconf_types.h b/stglibs/srvconf.lib/include/stg/servconf_types.h index 7ffc5811..17432044 100644 --- a/stglibs/srvconf.lib/include/stg/servconf_types.h +++ b/stglibs/srvconf.lib/include/stg/servconf_types.h @@ -21,6 +21,8 @@ #ifndef __STG_STGLIBS_SRVCONF_TYPES_H__ #define __STG_STGLIBS_SRVCONF_TYPES_H__ +#include "stg/const.h" // DIR_NUM + #include #include @@ -68,6 +70,23 @@ typedef std::vector INFO; typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); } // namespace AUTH_BY + +namespace SERVER_INFO +{ + +struct INFO +{ + std::string version; + int tariffNum; + int tariffType; + int usersNum; + std::string uname; + int dirNum; + std::string dirName[DIR_NUM]; +}; +typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); + +} // namespace SERVER_INFO } // namespace STG #endif diff --git a/stglibs/srvconf.lib/parser_server_info.cpp b/stglibs/srvconf.lib/parser_server_info.cpp index 38a373b8..d4c610e0 100644 --- a/stglibs/srvconf.lib/parser_server_info.cpp +++ b/stglibs/srvconf.lib/parser_server_info.cpp @@ -19,7 +19,7 @@ * Author : Maxim Mamontov */ -#include "stg/parser_server_info.h" +#include "parser_server_info.h" #include "stg/common.h" @@ -39,7 +39,7 @@ const size_t DIRNAME_LEN = 16; } -PARSER_SERVER_INFO::PARSER_SERVER_INFO() +SERVER_INFO::PARSER::PARSER() : callback(NULL), data(NULL), depth(0), @@ -56,7 +56,7 @@ PARSER_SERVER_INFO::PARSER_SERVER_INFO() AddParser(propertyParsers, "dir_name_" + x2str(i), info.dirName[i], GetEncodedValue); } //----------------------------------------------------------------------------- -int PARSER_SERVER_INFO::ParseStart(const char *el, const char **attr) +int SERVER_INFO::PARSER::ParseStart(const char *el, const char **attr) { depth++; if (depth == 1) @@ -69,7 +69,7 @@ else return 0; } //----------------------------------------------------------------------------- -void PARSER_SERVER_INFO::ParseEnd(const char * /*el*/) +void SERVER_INFO::PARSER::ParseEnd(const char * /*el*/) { depth--; if (depth == 0 && parsingAnswer) @@ -81,7 +81,7 @@ if (depth == 0 && parsingAnswer) } } //----------------------------------------------------------------------------- -void PARSER_SERVER_INFO::SetCallback(CALLBACK f, void * d) +void SERVER_INFO::PARSER::SetCallback(CALLBACK f, void * d) { callback = f; data = d; diff --git a/stglibs/srvconf.lib/parser_server_info.h b/stglibs/srvconf.lib/parser_server_info.h new file mode 100644 index 00000000..2e91106c --- /dev/null +++ b/stglibs/srvconf.lib/parser_server_info.h @@ -0,0 +1,58 @@ +/* + * 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 : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ + +#include "stg/parser.h" + +#include "stg/property_parsers.h" +#include "stg/servconf_types.h" + +#include + +namespace STG +{ +namespace SERVER_INFO +{ + +class PARSER: public STG::PARSER +{ +public: + + PARSER(); + int ParseStart(const char * el, const char ** attr); + void ParseEnd(const char * el); + void SetCallback(CALLBACK f, void * data); +private: + PROPERTY_PARSERS propertyParsers; + CALLBACK callback; + void * data; + int depth; + bool parsingAnswer; + INFO info; + std::string error; +}; + +} // namespace SERVER_INFO +} // namespace STG + +#endif diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index a7663f0e..0c24b38a 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -22,6 +22,7 @@ #include "netunit.h" #include "parser_auth_by.h" +#include "parser_server_info.h" #include "stg/common.h" @@ -43,7 +44,7 @@ public: int ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data); int AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data); int SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALLBACK f, void * data); - int ServerInfo(PARSER_SERVER_INFO::CALLBACK f, void * data); + int ServerInfo(SERVER_INFO::CALLBACK f, void * data); int CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data); const std::string & GetStrError() const; @@ -54,7 +55,7 @@ private: PARSER_GET_USERS parserGetUsers; PARSER_GET_USER parserGetUser; AUTH_BY::PARSER parserAuthBy; - PARSER_SERVER_INFO parserServerInfo; + SERVER_INFO::PARSER parserServerInfo; PARSER_CHG_USER parserChgUser; PARSER_CHECK_USER parserCheckUser; PARSER_SEND_MESSAGE parserSendMessage; @@ -121,7 +122,7 @@ int SERVCONF::SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALL return pImpl->SendMessage(request, f, data); } -int SERVCONF::ServerInfo(PARSER_SERVER_INFO::CALLBACK f, void * data) +int SERVCONF::ServerInfo(SERVER_INFO::CALLBACK f, void * data) { return pImpl->ServerInfo(f, data); } @@ -163,7 +164,7 @@ parserGetUsers.SetCallback(f, data); return Exec("", parserGetUsers); } //----------------------------------------------------------------------------- -int SERVCONF::IMPL::ServerInfo(PARSER_SERVER_INFO::CALLBACK f, void * data) +int SERVCONF::IMPL::ServerInfo(SERVER_INFO::CALLBACK f, void * data) { parserServerInfo.SetCallback(f, data); return Exec("", parserServerInfo);