From 82c7b78d7b7cf797f0663c96f44b092103802035 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 21 Sep 2013 00:17:50 +0300 Subject: [PATCH] Moved AUTH_BY parser from global scope. --- projects/sgconf/common_sg.cpp | 4 ++- stglibs/srvconf.lib/include/stg/parser.h | 5 ++++ .../include/stg/parser_check_user.h | 5 ++++ .../srvconf.lib/include/stg/parser_chg_user.h | 5 ++++ .../srvconf.lib/include/stg/parser_get_user.h | 5 ++++ .../include/stg/parser_get_users.h | 5 ++++ .../include/stg/parser_send_message.h | 5 ++++ .../include/stg/parser_server_info.h | 5 ++++ stglibs/srvconf.lib/include/stg/servconf.h | 17 +++++++---- .../srvconf.lib/include/stg/servconf_types.h | 15 ++++++++++ stglibs/srvconf.lib/netunit.cpp | 2 ++ stglibs/srvconf.lib/parser_auth_by.cpp | 12 ++++---- .../{include/stg => }/parser_auth_by.h | 19 +++++++++---- stglibs/srvconf.lib/parser_check_user.cpp | 2 ++ stglibs/srvconf.lib/parser_chg_user.cpp | 2 ++ stglibs/srvconf.lib/parser_get_user.cpp | 2 ++ stglibs/srvconf.lib/parser_get_users.cpp | 2 ++ stglibs/srvconf.lib/parser_send_message.cpp | 2 ++ stglibs/srvconf.lib/parser_server_info.cpp | 2 ++ stglibs/srvconf.lib/servconf.cpp | 28 +++++-------------- 20 files changed, 105 insertions(+), 39 deletions(-) rename stglibs/srvconf.lib/{include/stg => }/parser_auth_by.h (84%) diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index 1db7c9c4..f3688649 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -43,6 +43,8 @@ #include #include +using namespace STG; + const int usageConf = 0; const int usageInfo = 1; @@ -302,7 +304,7 @@ data->reason = reason; } //----------------------------------------------------------------------------- void RecvAuthByData(bool result, const std::string & reason, - const PARSER_AUTH_BY::INFO & list, void * d) + const AUTH_BY::INFO & list, void * d) { ResultData * data = static_cast(d); data->result = result; diff --git a/stglibs/srvconf.lib/include/stg/parser.h b/stglibs/srvconf.lib/include/stg/parser.h index f8c3af0c..8d695a3a 100644 --- a/stglibs/srvconf.lib/include/stg/parser.h +++ b/stglibs/srvconf.lib/include/stg/parser.h @@ -22,6 +22,9 @@ #ifndef __STG_STGLIBS_SRVCONF_PARSER_H__ #define __STG_STGLIBS_SRVCONF_PARSER_H__ +namespace STG +{ + class PARSER { public: @@ -30,4 +33,6 @@ public: virtual void ParseEnd(const char *el) = 0; }; +} // namespace STG + #endif diff --git a/stglibs/srvconf.lib/include/stg/parser_check_user.h b/stglibs/srvconf.lib/include/stg/parser_check_user.h index e0bea221..4e1f498c 100644 --- a/stglibs/srvconf.lib/include/stg/parser_check_user.h +++ b/stglibs/srvconf.lib/include/stg/parser_check_user.h @@ -26,6 +26,9 @@ #include +namespace STG +{ + class PARSER_CHECK_USER: public PARSER { public: @@ -43,4 +46,6 @@ private: void ParseAnswer(const char * el, const char ** attr); }; +} // namespace STG + #endif diff --git a/stglibs/srvconf.lib/include/stg/parser_chg_user.h b/stglibs/srvconf.lib/include/stg/parser_chg_user.h index cc6e9f18..75431ae1 100644 --- a/stglibs/srvconf.lib/include/stg/parser_chg_user.h +++ b/stglibs/srvconf.lib/include/stg/parser_chg_user.h @@ -26,6 +26,9 @@ #include +namespace STG +{ + class PARSER_CHG_USER: public PARSER { public: @@ -43,4 +46,6 @@ private: void ParseAnswer(const char * el, const char ** attr); }; +} // namespace STG + #endif diff --git a/stglibs/srvconf.lib/include/stg/parser_get_user.h b/stglibs/srvconf.lib/include/stg/parser_get_user.h index 7f6faaad..a6fadeb8 100644 --- a/stglibs/srvconf.lib/include/stg/parser_get_user.h +++ b/stglibs/srvconf.lib/include/stg/parser_get_user.h @@ -33,6 +33,9 @@ #include +namespace STG +{ + class PARSER_GET_USER: public PARSER { public: @@ -92,4 +95,6 @@ private: void ParseUserParams(const char *el, const char **attr); }; +} // namespace STG + #endif diff --git a/stglibs/srvconf.lib/include/stg/parser_get_users.h b/stglibs/srvconf.lib/include/stg/parser_get_users.h index 35fcd126..a8b8ac85 100644 --- a/stglibs/srvconf.lib/include/stg/parser_get_users.h +++ b/stglibs/srvconf.lib/include/stg/parser_get_users.h @@ -29,6 +29,9 @@ #include +namespace STG +{ + class PARSER_GET_USERS: public PARSER { public: @@ -54,4 +57,6 @@ private: static void UserCallback(bool result, const std::string& reason, const PARSER_GET_USER::INFO & info, void * data); }; +} // 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 index 9b3ca5ef..912d507e 100644 --- a/stglibs/srvconf.lib/include/stg/parser_send_message.h +++ b/stglibs/srvconf.lib/include/stg/parser_send_message.h @@ -26,6 +26,9 @@ #include +namespace STG +{ + class PARSER_SEND_MESSAGE: public PARSER { public: @@ -43,4 +46,6 @@ private: void ParseAnswer(const char * el, const char ** attr); }; +} // namespace STG + #endif diff --git a/stglibs/srvconf.lib/include/stg/parser_server_info.h b/stglibs/srvconf.lib/include/stg/parser_server_info.h index ff31ae71..cb57bffd 100644 --- a/stglibs/srvconf.lib/include/stg/parser_server_info.h +++ b/stglibs/srvconf.lib/include/stg/parser_server_info.h @@ -29,6 +29,9 @@ #include +namespace STG +{ + class PARSER_SERVER_INFO: public PARSER { public: @@ -58,4 +61,6 @@ private: std::string error; }; +} + #endif diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index 32ee1cd4..e55cff2c 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -24,10 +24,9 @@ $Author: faust $ */ -#ifndef SERVCONF_H -#define SERVCONF_H +#ifndef __STG_STGLIBS_SERVCONF_H__ +#define __STG_STGLIBS_SERVCONF_H__ -#include "stg/parser_auth_by.h" #include "stg/parser_server_info.h" #include "stg/parser_check_user.h" #include "stg/parser_get_user.h" @@ -35,10 +34,15 @@ #include "stg/parser_chg_user.h" #include "stg/parser_send_message.h" +#include "stg/servconf_types.h" + #include "stg/os_int.h" #include +namespace STG +{ + class SERVCONF { public: @@ -49,7 +53,7 @@ public: int GetUsers(PARSER_GET_USERS::CALLBACK f, void * data); int GetUser(const std::string & login, PARSER_GET_USER::CALLBACK f, void * data); int ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data); - int AuthBy(const std::string & login, PARSER_AUTH_BY::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 CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data); @@ -60,6 +64,7 @@ private: class IMPL; IMPL * pImpl; }; -//----------------------------------------------------------------------------- -#endif /* _SERVCONF_H_ */ +} // namespace STG + +#endif diff --git a/stglibs/srvconf.lib/include/stg/servconf_types.h b/stglibs/srvconf.lib/include/stg/servconf_types.h index d7fb8478..7ffc5811 100644 --- a/stglibs/srvconf.lib/include/stg/servconf_types.h +++ b/stglibs/srvconf.lib/include/stg/servconf_types.h @@ -21,6 +21,9 @@ #ifndef __STG_STGLIBS_SRVCONF_TYPES_H__ #define __STG_STGLIBS_SRVCONF_TYPES_H__ +#include +#include + #define STG_HEADER "SG04" #define OK_HEADER "OKHD" #define ERR_HEADER "ERHD" @@ -31,6 +34,9 @@ #define ENC_MSG_LEN (8) +namespace STG +{ + enum status { st_ok = 0, @@ -55,4 +61,13 @@ confLoginCipher, confData }; +namespace AUTH_BY +{ + +typedef std::vector INFO; +typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); + +} // namespace AUTH_BY +} // namespace STG + #endif diff --git a/stglibs/srvconf.lib/netunit.cpp b/stglibs/srvconf.lib/netunit.cpp index 73f0f485..aabb7780 100644 --- a/stglibs/srvconf.lib/netunit.cpp +++ b/stglibs/srvconf.lib/netunit.cpp @@ -44,6 +44,8 @@ #include #include +using namespace STG; + namespace { diff --git a/stglibs/srvconf.lib/parser_auth_by.cpp b/stglibs/srvconf.lib/parser_auth_by.cpp index 06981aae..b3904a1b 100644 --- a/stglibs/srvconf.lib/parser_auth_by.cpp +++ b/stglibs/srvconf.lib/parser_auth_by.cpp @@ -18,13 +18,15 @@ * Author : Maxim Mamontov */ -#include "stg/parser_auth_by.h" +#include "parser_auth_by.h" #include #include // strcasecmp -PARSER_AUTH_BY::PARSER_AUTH_BY() +using namespace STG; + +AUTH_BY::PARSER::PARSER() : callback(NULL), data(NULL), depth(0), @@ -32,7 +34,7 @@ PARSER_AUTH_BY::PARSER_AUTH_BY() { } //----------------------------------------------------------------------------- -int PARSER_AUTH_BY::ParseStart(const char *el, const char **attr) +int AUTH_BY::PARSER::ParseStart(const char *el, const char **attr) { depth++; if (depth == 1) @@ -66,7 +68,7 @@ else return 0; } //----------------------------------------------------------------------------- -void PARSER_AUTH_BY::ParseEnd(const char * /*el*/) +void AUTH_BY::PARSER::ParseEnd(const char * /*el*/) { depth--; if (depth == 0) @@ -78,7 +80,7 @@ if (depth == 0) } } //----------------------------------------------------------------------------- -void PARSER_AUTH_BY::SetCallback(CALLBACK f, void * d) +void AUTH_BY::PARSER::SetCallback(AUTH_BY::CALLBACK f, void * d) { callback = f; data = d; diff --git a/stglibs/srvconf.lib/include/stg/parser_auth_by.h b/stglibs/srvconf.lib/parser_auth_by.h similarity index 84% rename from stglibs/srvconf.lib/include/stg/parser_auth_by.h rename to stglibs/srvconf.lib/parser_auth_by.h index 00c997d5..4e94267c 100644 --- a/stglibs/srvconf.lib/include/stg/parser_auth_by.h +++ b/stglibs/srvconf.lib/parser_auth_by.h @@ -21,18 +21,22 @@ #ifndef __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__ #define __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__ -#include "parser.h" +#include "stg/parser.h" + +#include "stg/servconf_types.h" #include #include -class PARSER_AUTH_BY: public PARSER +namespace STG +{ +namespace AUTH_BY { -public: - typedef std::vector INFO; - typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); - PARSER_AUTH_BY(); +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); @@ -45,4 +49,7 @@ private: std::string error; }; +} // namespace AUTH_BY +} // namespace STG + #endif diff --git a/stglibs/srvconf.lib/parser_check_user.cpp b/stglibs/srvconf.lib/parser_check_user.cpp index eed03f30..8c150357 100644 --- a/stglibs/srvconf.lib/parser_check_user.cpp +++ b/stglibs/srvconf.lib/parser_check_user.cpp @@ -25,6 +25,8 @@ #include +using namespace STG; + PARSER_CHECK_USER::PARSER_CHECK_USER() : callback(NULL), data(NULL), diff --git a/stglibs/srvconf.lib/parser_chg_user.cpp b/stglibs/srvconf.lib/parser_chg_user.cpp index 53ce941d..084b0cc8 100644 --- a/stglibs/srvconf.lib/parser_chg_user.cpp +++ b/stglibs/srvconf.lib/parser_chg_user.cpp @@ -25,6 +25,8 @@ #include +using namespace STG; + PARSER_CHG_USER::PARSER_CHG_USER() : callback(NULL), data(NULL), diff --git a/stglibs/srvconf.lib/parser_get_user.cpp b/stglibs/srvconf.lib/parser_get_user.cpp index 43d720e8..0127eda2 100644 --- a/stglibs/srvconf.lib/parser_get_user.cpp +++ b/stglibs/srvconf.lib/parser_get_user.cpp @@ -29,6 +29,8 @@ #include +using namespace STG; + template <> bool GetValue(const char ** attr, PARSER_GET_USER::STAT & value) { diff --git a/stglibs/srvconf.lib/parser_get_users.cpp b/stglibs/srvconf.lib/parser_get_users.cpp index 2f380c82..80465afc 100644 --- a/stglibs/srvconf.lib/parser_get_users.cpp +++ b/stglibs/srvconf.lib/parser_get_users.cpp @@ -25,6 +25,8 @@ #include +using namespace STG; + PARSER_GET_USERS::PARSER_GET_USERS() : callback(NULL), data(NULL), diff --git a/stglibs/srvconf.lib/parser_send_message.cpp b/stglibs/srvconf.lib/parser_send_message.cpp index c1955fce..08b60462 100644 --- a/stglibs/srvconf.lib/parser_send_message.cpp +++ b/stglibs/srvconf.lib/parser_send_message.cpp @@ -25,6 +25,8 @@ #include +using namespace STG; + PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE() : callback(NULL), data(NULL), diff --git a/stglibs/srvconf.lib/parser_server_info.cpp b/stglibs/srvconf.lib/parser_server_info.cpp index 645f6099..38a373b8 100644 --- a/stglibs/srvconf.lib/parser_server_info.cpp +++ b/stglibs/srvconf.lib/parser_server_info.cpp @@ -28,6 +28,8 @@ #include +using namespace STG; + namespace { diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index c45dfb9b..a7663f0e 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -21,7 +21,7 @@ #include "stg/servconf.h" #include "netunit.h" -#include "stg/servconf_types.h" +#include "parser_auth_by.h" #include "stg/common.h" @@ -30,6 +30,8 @@ #include +using namespace STG; + class SERVCONF::IMPL { public: @@ -39,7 +41,7 @@ public: int GetUsers(PARSER_GET_USERS::CALLBACK f, void * data); int GetUser(const std::string & login, PARSER_GET_USER::CALLBACK f, void * data); int ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data); - int AuthBy(const std::string & login, PARSER_AUTH_BY::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 CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data); @@ -51,7 +53,7 @@ public: private: PARSER_GET_USERS parserGetUsers; PARSER_GET_USER parserGetUser; - PARSER_AUTH_BY parserAuthBy; + AUTH_BY::PARSER parserAuthBy; PARSER_SERVER_INFO parserServerInfo; PARSER_CHG_USER parserChgUser; PARSER_CHECK_USER parserCheckUser; @@ -67,22 +69,6 @@ private: static bool AnsRecv(void * data, const std::string & chunk, bool final); }; -/*namespace -{ - -void ElementStart(void * data, const char * el, const char ** attr) -{ -static_cast(data)->Start(el, attr); -} - -void ElementEnd(void * data, const char * el) -{ -static_cast(data)->End(el); -} - -} // namespace anonymous -*/ - bool SERVCONF::IMPL::AnsRecv(void * data, const std::string & chunk, bool final) { SERVCONF::IMPL * sc = static_cast(data); @@ -125,7 +111,7 @@ int SERVCONF::ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, return pImpl->ChgUser(request, f, data); } -int SERVCONF::AuthBy(const std::string & login, PARSER_AUTH_BY::CALLBACK f, void * data) +int SERVCONF::AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data) { return pImpl->AuthBy(login, f, data); } @@ -165,7 +151,7 @@ parserGetUser.SetCallback(f, data); return Exec("", parserGetUser); } //----------------------------------------------------------------------------- -int SERVCONF::IMPL::AuthBy(const std::string & login, PARSER_AUTH_BY::CALLBACK f, void * data) +int SERVCONF::IMPL::AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data) { parserAuthBy.SetCallback(f, data); return Exec("", parserAuthBy); -- 2.43.2