From: Maxim Mamontov Date: Fri, 20 Sep 2013 21:35:08 +0000 (+0300) Subject: Moved CHECK_USER parser from global scope. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/5f1252496dfef1724c21421ea470a04d09af7ad0 Moved CHECK_USER parser from global scope. --- diff --git a/stglibs/srvconf.lib/include/stg/parser_check_user.h b/stglibs/srvconf.lib/include/stg/parser_check_user.h deleted file mode 100644 index 4e1f498c..00000000 --- a/stglibs/srvconf.lib/include/stg/parser_check_user.h +++ /dev/null @@ -1,51 +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_CHECK_USER_H__ -#define __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__ - -#include "parser.h" - -#include - -namespace STG -{ - -class PARSER_CHECK_USER: public PARSER -{ -public: - typedef int (* CALLBACK)(bool result, const std::string & reason, void * data); - - PARSER_CHECK_USER(); - int ParseStart(const char * el, const char ** attr); - void ParseEnd(const char * el); - void SetCallback(CALLBACK f, void * data); -private: - CALLBACK callback; - void * data; - int depth; - - void ParseAnswer(const char * el, const char ** attr); -}; - -} // namespace STG - -#endif diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index 1b4033e3..40311ec2 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_check_user.h" #include "stg/parser_get_user.h" #include "stg/parser_get_users.h" #include "stg/parser_chg_user.h" @@ -55,7 +54,7 @@ public: 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(SERVER_INFO::CALLBACK f, void * data); - int CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data); + int CheckUser(const std::string & login, const std::string & password, 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 17432044..21abf0ed 100644 --- a/stglibs/srvconf.lib/include/stg/servconf_types.h +++ b/stglibs/srvconf.lib/include/stg/servconf_types.h @@ -87,6 +87,13 @@ struct INFO typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); } // namespace SERVER_INFO + +namespace CHECK_USER +{ + +typedef int (* CALLBACK)(bool result, const std::string & reason, void * data); + +} } // namespace STG #endif diff --git a/stglibs/srvconf.lib/parser_auth_by.cpp b/stglibs/srvconf.lib/parser_auth_by.cpp index b3904a1b..34e490ca 100644 --- a/stglibs/srvconf.lib/parser_auth_by.cpp +++ b/stglibs/srvconf.lib/parser_auth_by.cpp @@ -80,7 +80,7 @@ if (depth == 0) } } //----------------------------------------------------------------------------- -void AUTH_BY::PARSER::SetCallback(AUTH_BY::CALLBACK f, void * d) +void AUTH_BY::PARSER::SetCallback(CALLBACK f, void * d) { callback = f; data = d; diff --git a/stglibs/srvconf.lib/parser_check_user.cpp b/stglibs/srvconf.lib/parser_check_user.cpp index 8c150357..0cb37522 100644 --- a/stglibs/srvconf.lib/parser_check_user.cpp +++ b/stglibs/srvconf.lib/parser_check_user.cpp @@ -19,7 +19,7 @@ * Author : Maxim Mamontov */ -#include "stg/parser_check_user.h" +#include "parser_check_user.h" #include @@ -27,14 +27,14 @@ using namespace STG; -PARSER_CHECK_USER::PARSER_CHECK_USER() +CHECK_USER::PARSER::PARSER() : callback(NULL), data(NULL), depth(0) { } //----------------------------------------------------------------------------- -int PARSER_CHECK_USER::ParseStart(const char * el, const char ** attr) +int CHECK_USER::PARSER::ParseStart(const char * el, const char ** attr) { depth++; if (depth == 1) @@ -43,12 +43,12 @@ if (depth == 1) return 0; } //----------------------------------------------------------------------------- -void PARSER_CHECK_USER::ParseEnd(const char *) +void CHECK_USER::PARSER::ParseEnd(const char *) { depth--; } //----------------------------------------------------------------------------- -void PARSER_CHECK_USER::ParseAnswer(const char *, const char **attr) +void CHECK_USER::PARSER::ParseAnswer(const char *, const char **attr) { if (!callback) return; @@ -58,7 +58,7 @@ else callback(false, "Invalid response.", data); } //----------------------------------------------------------------------------- -void PARSER_CHECK_USER::SetCallback(CALLBACK f, void * d) +void CHECK_USER::PARSER::SetCallback(CALLBACK f, void * d) { callback = f; data = d; diff --git a/stglibs/srvconf.lib/parser_check_user.h b/stglibs/srvconf.lib/parser_check_user.h new file mode 100644 index 00000000..11d6ab96 --- /dev/null +++ b/stglibs/srvconf.lib/parser_check_user.h @@ -0,0 +1,54 @@ +/* + * 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_CHECK_USER_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__ + +#include "stg/parser.h" +#include "stg/servconf_types.h" + +#include + +namespace STG +{ +namespace CHECK_USER +{ + +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: + CALLBACK callback; + void * data; + int depth; + + void ParseAnswer(const char * el, const char ** attr); +}; + +} // namespace CHECK_USER +} // namespace STG + +#endif diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 0c24b38a..49d3ab73 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -23,6 +23,7 @@ #include "netunit.h" #include "parser_auth_by.h" #include "parser_server_info.h" +#include "parser_check_user.h" #include "stg/common.h" @@ -45,7 +46,7 @@ public: 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(SERVER_INFO::CALLBACK f, void * data); - int CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data); + int CheckUser(const std::string & login, const std::string & password, CHECK_USER::CALLBACK f, void * data); const std::string & GetStrError() const; static void Start(void * data, const char * el, const char ** attr); @@ -57,7 +58,7 @@ private: AUTH_BY::PARSER parserAuthBy; SERVER_INFO::PARSER parserServerInfo; PARSER_CHG_USER parserChgUser; - PARSER_CHECK_USER parserCheckUser; + CHECK_USER::PARSER parserCheckUser; PARSER_SEND_MESSAGE parserSendMessage; NETTRANSACT nt; @@ -127,7 +128,7 @@ int SERVCONF::ServerInfo(SERVER_INFO::CALLBACK f, void * data) return pImpl->ServerInfo(f, data); } -int SERVCONF::CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data) +int SERVCONF::CheckUser(const std::string & login, const std::string & password, CHECK_USER::CALLBACK f, void * data) { return pImpl->CheckUser(login, password, f, data); } @@ -182,7 +183,7 @@ parserSendMessage.SetCallback(f, data); return Exec(request, parserSendMessage); } //----------------------------------------------------------------------------- -int SERVCONF::IMPL::CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data) +int SERVCONF::IMPL::CheckUser(const std::string & login, const std::string & password, CHECK_USER::CALLBACK f, void * data) { parserCheckUser.SetCallback(f, data); return Exec("", parserCheckUser);