From: Maxim Mamontov Date: Fri, 20 Sep 2013 22:04:12 +0000 (+0300) Subject: Moved CHG_USER and SEND_MESSAGE parsers from global scope. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/97f1f905311bcb76c3b500e3e49c1b9f49dff491 Moved CHG_USER and SEND_MESSAGE parsers from global scope. --- diff --git a/stglibs/srvconf.lib/include/stg/parser_chg_user.h b/stglibs/srvconf.lib/include/stg/parser_chg_user.h deleted file mode 100644 index 75431ae1..00000000 --- a/stglibs/srvconf.lib/include/stg/parser_chg_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_CHG_USER_H__ -#define __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__ - -#include "parser.h" - -#include - -namespace STG -{ - -class PARSER_CHG_USER: public PARSER -{ -public: - typedef void (* CALLBACK)(bool result, const std::string& reason, void * data); - - PARSER_CHG_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/parser_send_message.h b/stglibs/srvconf.lib/include/stg/parser_send_message.h deleted file mode 100644 index 912d507e..00000000 --- a/stglibs/srvconf.lib/include/stg/parser_send_message.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_SEND_MESSAGE_H__ -#define __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__ - -#include "parser.h" - -#include - -namespace STG -{ - -class PARSER_SEND_MESSAGE: public PARSER -{ -public: - typedef void (* CALLBACK)(bool result, const std::string& reason, void * data); - - PARSER_SEND_MESSAGE(); - 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 8ecb59cd..f709528f 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -27,9 +27,6 @@ #ifndef __STG_STGLIBS_SERVCONF_H__ #define __STG_STGLIBS_SERVCONF_H__ -#include "stg/parser_chg_user.h" -#include "stg/parser_send_message.h" - #include "stg/servconf_types.h" #include "stg/os_int.h" @@ -48,9 +45,9 @@ public: int GetUsers(GET_USERS::CALLBACK f, void * data); int GetUser(const std::string & login, GET_USER::CALLBACK f, void * data); - int ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data); + int ChgUser(const std::string & request, 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 SendMessage(const std::string & request, SEND_MESSAGE::CALLBACK f, void * data); int ServerInfo(SERVER_INFO::CALLBACK f, void * data); int CheckUser(const std::string & login, const std::string & password, CHECK_USER::CALLBACK f, void * data); diff --git a/stglibs/srvconf.lib/include/stg/servconf_types.h b/stglibs/srvconf.lib/include/stg/servconf_types.h index 81677c42..6aef40cf 100644 --- a/stglibs/srvconf.lib/include/stg/servconf_types.h +++ b/stglibs/srvconf.lib/include/stg/servconf_types.h @@ -147,6 +147,20 @@ typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & } // namespace GET_USERS +namespace CHG_USER +{ + +typedef void (* CALLBACK)(bool result, const std::string & reason, void * data); + +} + +namespace SEND_MESSAGE +{ + +typedef void (* CALLBACK)(bool result, const std::string & reason, void * data); + +} + } // namespace STG #endif diff --git a/stglibs/srvconf.lib/parser_chg_user.cpp b/stglibs/srvconf.lib/parser_chg_user.cpp index 084b0cc8..b5f4eb73 100644 --- a/stglibs/srvconf.lib/parser_chg_user.cpp +++ b/stglibs/srvconf.lib/parser_chg_user.cpp @@ -19,7 +19,7 @@ * Author : Maxim Mamontov */ -#include "stg/parser_chg_user.h" +#include "parser_chg_user.h" #include @@ -27,14 +27,14 @@ using namespace STG; -PARSER_CHG_USER::PARSER_CHG_USER() +CHG_USER::PARSER::PARSER() : callback(NULL), data(NULL), depth(0) { } //----------------------------------------------------------------------------- -int PARSER_CHG_USER::ParseStart(const char *el, const char **attr) +int CHG_USER::PARSER::ParseStart(const char *el, const char **attr) { depth++; if (depth == 1) @@ -49,12 +49,12 @@ if (depth == 1) return 0; } //----------------------------------------------------------------------------- -void PARSER_CHG_USER::ParseEnd(const char *) +void CHG_USER::PARSER::ParseEnd(const char *) { depth--; } //----------------------------------------------------------------------------- -void PARSER_CHG_USER::ParseAnswer(const char * /*el*/, const char ** attr) +void CHG_USER::PARSER::ParseAnswer(const char * /*el*/, const char ** attr) { if (!callback) return; @@ -64,7 +64,7 @@ else callback(false, "Invalid response.", data); } //----------------------------------------------------------------------------- -void PARSER_CHG_USER::SetCallback(CALLBACK f, void * d) +void CHG_USER::PARSER::SetCallback(CALLBACK f, void * d) { callback = f; data = d; diff --git a/stglibs/srvconf.lib/parser_chg_user.h b/stglibs/srvconf.lib/parser_chg_user.h new file mode 100644 index 00000000..d74dea76 --- /dev/null +++ b/stglibs/srvconf.lib/parser_chg_user.h @@ -0,0 +1,52 @@ +/* + * 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_CHG_USER_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__ + +#include "stg/parser.h" +#include "stg/servconf_types.h" + +namespace STG +{ +namespace CHG_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 CHG_USER +} // namespace STG + +#endif diff --git a/stglibs/srvconf.lib/parser_send_message.cpp b/stglibs/srvconf.lib/parser_send_message.cpp index 08b60462..318cc8eb 100644 --- a/stglibs/srvconf.lib/parser_send_message.cpp +++ b/stglibs/srvconf.lib/parser_send_message.cpp @@ -19,7 +19,7 @@ * Author : Maxim Mamontov */ -#include "stg/parser_send_message.h" +#include "parser_send_message.h" #include @@ -27,14 +27,14 @@ using namespace STG; -PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE() +SEND_MESSAGE::PARSER::PARSER() : callback(NULL), data(NULL), depth(0) { } //----------------------------------------------------------------------------- -int PARSER_SEND_MESSAGE::ParseStart(const char * el, const char ** attr) +int SEND_MESSAGE::PARSER::ParseStart(const char * el, const char ** attr) { depth++; if (depth == 1) @@ -43,12 +43,12 @@ if (depth == 1) return 0; } //----------------------------------------------------------------------------- -void PARSER_SEND_MESSAGE::ParseEnd(const char * /*el*/) +void SEND_MESSAGE::PARSER::ParseEnd(const char * /*el*/) { depth--; } //----------------------------------------------------------------------------- -void PARSER_SEND_MESSAGE::ParseAnswer(const char * /*el*/, const char **attr) +void SEND_MESSAGE::PARSER::ParseAnswer(const char * /*el*/, const char **attr) { if (!callback) return; @@ -58,7 +58,7 @@ else callback(false, "Invalid response.", data); } //----------------------------------------------------------------------------- -void PARSER_SEND_MESSAGE::SetCallback(CALLBACK f, void * d) +void SEND_MESSAGE::PARSER::SetCallback(CALLBACK f, void * d) { callback = f; data = d; diff --git a/stglibs/srvconf.lib/parser_send_message.h b/stglibs/srvconf.lib/parser_send_message.h new file mode 100644 index 00000000..fc1f020d --- /dev/null +++ b/stglibs/srvconf.lib/parser_send_message.h @@ -0,0 +1,53 @@ +/* + * 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_SEND_MESSAGE_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__ + +#include "stg/parser.h" +#include "stg/servconf_types.h" + +#include + +namespace STG +{ +namespace SEND_MESSAGE +{ + +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 SEND_MESSAGE +} // namespace STG + +#endif diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 1b90f77c..3684dd54 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -26,6 +26,8 @@ #include "parser_check_user.h" #include "parser_get_users.h" #include "parser_get_user.h" +#include "parser_chg_user.h" +#include "parser_send_message.h" #include "stg/common.h" @@ -44,9 +46,9 @@ public: int GetUsers(GET_USERS::CALLBACK f, void * data); int GetUser(const std::string & login, GET_USER::CALLBACK f, void * data); - int ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data); + int ChgUser(const std::string & request, 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 SendMessage(const std::string & request, SEND_MESSAGE::CALLBACK f, void * data); int ServerInfo(SERVER_INFO::CALLBACK f, void * data); int CheckUser(const std::string & login, const std::string & password, CHECK_USER::CALLBACK f, void * data); @@ -59,9 +61,9 @@ private: GET_USER::PARSER parserGetUser; AUTH_BY::PARSER parserAuthBy; SERVER_INFO::PARSER parserServerInfo; - PARSER_CHG_USER parserChgUser; + CHG_USER::PARSER parserChgUser; CHECK_USER::PARSER parserCheckUser; - PARSER_SEND_MESSAGE parserSendMessage; + SEND_MESSAGE::PARSER parserSendMessage; NETTRANSACT nt; @@ -110,7 +112,7 @@ int SERVCONF::GetUser(const std::string & login, GET_USER::CALLBACK f, void * da return pImpl->GetUser(login, f, data); } -int SERVCONF::ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data) +int SERVCONF::ChgUser(const std::string & request, CHG_USER::CALLBACK f, void * data) { return pImpl->ChgUser(request, f, data); } @@ -120,7 +122,7 @@ int SERVCONF::AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data return pImpl->AuthBy(login, f, data); } -int SERVCONF::SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALLBACK f, void * data) +int SERVCONF::SendMessage(const std::string & request, SEND_MESSAGE::CALLBACK f, void * data) { return pImpl->SendMessage(request, f, data); } @@ -173,13 +175,13 @@ parserServerInfo.SetCallback(f, data); return Exec("", parserServerInfo); } //----------------------------------------------------------------------------- -int SERVCONF::IMPL::ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data) +int SERVCONF::IMPL::ChgUser(const std::string & request, CHG_USER::CALLBACK f, void * data) { parserChgUser.SetCallback(f, data); return Exec(request, parserChgUser); } //----------------------------------------------------------------------------- -int SERVCONF::IMPL::SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALLBACK f, void * data) +int SERVCONF::IMPL::SendMessage(const std::string & request, SEND_MESSAGE::CALLBACK f, void * data) { parserSendMessage.SetCallback(f, data); return Exec(request, parserSendMessage);