From 0a2687358e50cb8950667f050455281af6d1e1ae Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 21 Sep 2013 00:53:18 +0300 Subject: [PATCH] Moved GET_USER and GET_USERS parsers from global scope. --- projects/sgconf/common_sg.cpp | 2 +- stglibs/srvconf.lib/include/stg/servconf.h | 6 +- .../srvconf.lib/include/stg/servconf_types.h | 55 ++++++++++++++++++- stglibs/srvconf.lib/parser_get_user.cpp | 18 +++--- .../{include/stg => }/parser_get_user.h | 54 +++--------------- stglibs/srvconf.lib/parser_get_users.cpp | 18 +++--- .../{include/stg => }/parser_get_users.h | 18 +++--- stglibs/srvconf.lib/servconf.cpp | 18 +++--- 8 files changed, 104 insertions(+), 85 deletions(-) rename stglibs/srvconf.lib/{include/stg => }/parser_get_user.h (55%) rename stglibs/srvconf.lib/{include/stg => }/parser_get_users.h (79%) diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index f3688649..6ccd4fe5 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -326,7 +326,7 @@ struct StringReqParams const std::string * value; }; //----------------------------------------------------------------------------- -void GetUserCallback(bool result, const std::string& reason, const PARSER_GET_USER::INFO & info, void * d) +void GetUserCallback(bool result, const std::string& reason, const GET_USER::INFO & info, void * d) { GetUserData * data = static_cast(d); data->result = false; diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index 40311ec2..8ecb59cd 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -27,8 +27,6 @@ #ifndef __STG_STGLIBS_SERVCONF_H__ #define __STG_STGLIBS_SERVCONF_H__ -#include "stg/parser_get_user.h" -#include "stg/parser_get_users.h" #include "stg/parser_chg_user.h" #include "stg/parser_send_message.h" @@ -48,8 +46,8 @@ public: const std::string & login, const std::string & password); ~SERVCONF(); - int GetUsers(PARSER_GET_USERS::CALLBACK f, void * data); - int GetUser(const std::string & login, PARSER_GET_USER::CALLBACK f, void * data); + 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 AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data); int SendMessage(const std::string & request, PARSER_SEND_MESSAGE::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 21abf0ed..81677c42 100644 --- a/stglibs/srvconf.lib/include/stg/servconf_types.h +++ b/stglibs/srvconf.lib/include/stg/servconf_types.h @@ -22,6 +22,7 @@ #define __STG_STGLIBS_SRVCONF_TYPES_H__ #include "stg/const.h" // DIR_NUM +#include "stg/os_int.h" // uint32_t, etc... #include #include @@ -93,7 +94,59 @@ namespace CHECK_USER typedef int (* CALLBACK)(bool result, const std::string & reason, void * data); -} +} // namespace CHECK_USER + +namespace GET_USER +{ + +struct STAT +{ + long long su[DIR_NUM]; + long long sd[DIR_NUM]; + long long mu[DIR_NUM]; + long long md[DIR_NUM]; + double freeMb; +}; + +struct INFO +{ + std::string login; + std::string password; + double cash; + double credit; + time_t creditExpire; + double lastCash; + double prepaidTraff; + int down; + int passive; + int disableDetailStat; + int connected; + int alwaysOnline; + uint32_t ip; + std::string ips; + std::string tariff; + std::string group; + std::string note; + std::string email; + std::string name; + std::string address; + std::string phone; + STAT stat; + std::string userData[USERDATA_NUM]; +}; + +typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); + +} // namespace GET_USER + +namespace GET_USERS +{ + +typedef std::vector INFO; +typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); + +} // namespace GET_USERS + } // namespace STG #endif diff --git a/stglibs/srvconf.lib/parser_get_user.cpp b/stglibs/srvconf.lib/parser_get_user.cpp index 0127eda2..45f5e6ea 100644 --- a/stglibs/srvconf.lib/parser_get_user.cpp +++ b/stglibs/srvconf.lib/parser_get_user.cpp @@ -19,7 +19,7 @@ * Author : Maxim Mamontov */ -#include "stg/parser_get_user.h" +#include "parser_get_user.h" #include "stg/common.h" @@ -32,7 +32,7 @@ using namespace STG; template <> -bool GetValue(const char ** attr, PARSER_GET_USER::STAT & value) +bool GetValue(const char ** attr, GET_USER::STAT & value) { if (!attr) return false; @@ -56,7 +56,7 @@ while (attr[pos]) return true; } -PARSER_GET_USER::PARSER_GET_USER() +GET_USER::PARSER::PARSER() : callback(NULL), data(NULL), depth(0), @@ -89,14 +89,14 @@ PARSER_GET_USER::PARSER_GET_USER() AddParser(propertyParsers, "userData" + x2str(i), info.userData[i], GetEncodedValue); } //----------------------------------------------------------------------------- -PARSER_GET_USER::~PARSER_GET_USER() +GET_USER::PARSER::~PARSER() { PROPERTY_PARSERS::iterator it(propertyParsers.begin()); while (it != propertyParsers.end()) delete (it++)->second; } //----------------------------------------------------------------------------- -int PARSER_GET_USER::ParseStart(const char * el, const char ** attr) +int GET_USER::PARSER::ParseStart(const char * el, const char ** attr) { depth++; if (depth == 1) @@ -108,7 +108,7 @@ if (depth == 2 && parsingAnswer) return 0; } //----------------------------------------------------------------------------- -void PARSER_GET_USER::ParseEnd(const char * /*el*/) +void GET_USER::PARSER::ParseEnd(const char * /*el*/) { depth--; if (depth == 0 && parsingAnswer) @@ -120,7 +120,7 @@ if (depth == 0 && parsingAnswer) } } //----------------------------------------------------------------------------- -void PARSER_GET_USER::ParseUser(const char * el, const char ** attr) +void GET_USER::PARSER::ParseUser(const char * el, const char ** attr) { if (strcasecmp(el, "user") == 0) if (attr && attr[0] && attr[1]) @@ -139,13 +139,13 @@ if (strcasecmp(el, "user") == 0) parsingAnswer = true; } //----------------------------------------------------------------------------- -void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr) +void GET_USER::PARSER::ParseUserParams(const char * el, const char ** attr) { if (!TryParse(propertyParsers, ToLower(el), attr)) error = "Invalid parameter."; } //----------------------------------------------------------------------------- -void PARSER_GET_USER::SetCallback(CALLBACK f, void * d) +void GET_USER::PARSER::SetCallback(CALLBACK f, void * d) { callback = f; data = d; diff --git a/stglibs/srvconf.lib/include/stg/parser_get_user.h b/stglibs/srvconf.lib/parser_get_user.h similarity index 55% rename from stglibs/srvconf.lib/include/stg/parser_get_user.h rename to stglibs/srvconf.lib/parser_get_user.h index a6fadeb8..871dd211 100644 --- a/stglibs/srvconf.lib/include/stg/parser_get_user.h +++ b/stglibs/srvconf.lib/parser_get_user.h @@ -22,12 +22,10 @@ #ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__ #define __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__ -#include "parser.h" +#include "stg/parser.h" -#include "property_parsers.h" - -#include "stg/os_int.h" -#include "stg/const.h" +#include "stg/property_parsers.h" +#include "stg/servconf_types.h" #include @@ -35,50 +33,15 @@ namespace STG { +namespace GET_USER +{ -class PARSER_GET_USER: public PARSER +class PARSER: public STG::PARSER { public: - struct STAT - { - long long su[DIR_NUM]; - long long sd[DIR_NUM]; - long long mu[DIR_NUM]; - long long md[DIR_NUM]; - double freeMb; - }; - - struct INFO - { - std::string login; - std::string password; - double cash; - double credit; - time_t creditExpire; - double lastCash; - double prepaidTraff; - int down; - int passive; - int disableDetailStat; - int connected; - int alwaysOnline; - uint32_t ip; - std::string ips; - std::string tariff; - std::string group; - std::string note; - std::string email; - std::string name; - std::string address; - std::string phone; - STAT stat; - std::string userData[USERDATA_NUM]; - }; - - typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); - PARSER_GET_USER(); - virtual ~PARSER_GET_USER(); + PARSER(); + virtual ~PARSER(); int ParseStart(const char *el, const char **attr); void ParseEnd(const char *el); void SetCallback(CALLBACK f, void * data); @@ -95,6 +58,7 @@ private: void ParseUserParams(const char *el, const char **attr); }; +} // namespace GET_USER } // namespace STG #endif diff --git a/stglibs/srvconf.lib/parser_get_users.cpp b/stglibs/srvconf.lib/parser_get_users.cpp index 80465afc..ecc2917c 100644 --- a/stglibs/srvconf.lib/parser_get_users.cpp +++ b/stglibs/srvconf.lib/parser_get_users.cpp @@ -19,7 +19,7 @@ * Author : Maxim Mamontov */ -#include "stg/parser_get_users.h" +#include "parser_get_users.h" #include @@ -27,16 +27,16 @@ using namespace STG; -PARSER_GET_USERS::PARSER_GET_USERS() +GET_USERS::PARSER::PARSER() : callback(NULL), data(NULL), depth(0), parsingAnswer(false) { - userParser.SetCallback(&PARSER_GET_USERS::UserCallback, this); + userParser.SetCallback(&GET_USERS::PARSER::UserCallback, this); } //----------------------------------------------------------------------------- -int PARSER_GET_USERS::ParseStart(const char * el, const char ** attr) +int GET_USERS::PARSER::ParseStart(const char * el, const char ** attr) { depth++; if (depth == 1 && strcasecmp(el, "users") == 0) @@ -48,7 +48,7 @@ if (depth > 1 && parsingAnswer) return 0; } //----------------------------------------------------------------------------- -void PARSER_GET_USERS::ParseEnd(const char * el) +void GET_USERS::PARSER::ParseEnd(const char * el) { depth--; if (depth > 0 && parsingAnswer) @@ -64,20 +64,20 @@ if (depth == 0 && parsingAnswer) } } //----------------------------------------------------------------------------- -void PARSER_GET_USERS::AddUser(const PARSER_GET_USER::INFO & userInfo) +void GET_USERS::PARSER::AddUser(const GET_USER::INFO & userInfo) { info.push_back(userInfo); } //----------------------------------------------------------------------------- -void PARSER_GET_USERS::SetCallback(CALLBACK f, void * d) +void GET_USERS::PARSER::SetCallback(CALLBACK f, void * d) { callback = f; data = d; } //----------------------------------------------------------------------------- -void PARSER_GET_USERS::UserCallback(bool result, const std::string & error, const PARSER_GET_USER::INFO & info, void * data) +void GET_USERS::PARSER::UserCallback(bool result, const std::string & error, const GET_USER::INFO & info, void * data) { - PARSER_GET_USERS * parser = static_cast(data); + GET_USERS::PARSER * parser = static_cast(data); if (!result) parser->SetError(error); else diff --git a/stglibs/srvconf.lib/include/stg/parser_get_users.h b/stglibs/srvconf.lib/parser_get_users.h similarity index 79% rename from stglibs/srvconf.lib/include/stg/parser_get_users.h rename to stglibs/srvconf.lib/parser_get_users.h index a8b8ac85..55258186 100644 --- a/stglibs/srvconf.lib/include/stg/parser_get_users.h +++ b/stglibs/srvconf.lib/parser_get_users.h @@ -23,7 +23,8 @@ #ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__ #define __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__ -#include "parser.h" +#include "stg/parser.h" +#include "stg/servconf_types.h" #include "parser_get_user.h" @@ -31,32 +32,33 @@ namespace STG { +namespace GET_USERS +{ -class PARSER_GET_USERS: public PARSER +class PARSER: public STG::PARSER { public: - typedef std::vector INFO; - typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); - PARSER_GET_USERS(); + 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; - PARSER_GET_USER userParser; + GET_USER::PARSER userParser; INFO info; int depth; bool parsingAnswer; std::string error; - void AddUser(const PARSER_GET_USER::INFO & userInfo); + void AddUser(const GET_USER::INFO & userInfo); void SetError(const std::string & e) { error = e; } - static void UserCallback(bool result, const std::string& reason, const PARSER_GET_USER::INFO & info, void * data); + static void UserCallback(bool result, const std::string& reason, const GET_USER::INFO & info, void * data); }; +} // namespace GET_USERS } // namespace STG #endif diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 49d3ab73..1b90f77c 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -24,6 +24,8 @@ #include "parser_auth_by.h" #include "parser_server_info.h" #include "parser_check_user.h" +#include "parser_get_users.h" +#include "parser_get_user.h" #include "stg/common.h" @@ -40,8 +42,8 @@ public: IMPL(const std::string & server, uint16_t port, const std::string & login, const std::string & password); - int GetUsers(PARSER_GET_USERS::CALLBACK f, void * data); - int GetUser(const std::string & login, PARSER_GET_USER::CALLBACK f, void * data); + 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 AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data); int SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALLBACK f, void * data); @@ -53,8 +55,8 @@ public: static void End(void * data, const char * el); private: - PARSER_GET_USERS parserGetUsers; - PARSER_GET_USER parserGetUser; + GET_USERS::PARSER parserGetUsers; + GET_USER::PARSER parserGetUser; AUTH_BY::PARSER parserAuthBy; SERVER_INFO::PARSER parserServerInfo; PARSER_CHG_USER parserChgUser; @@ -98,12 +100,12 @@ SERVCONF::~SERVCONF() delete pImpl; } -int SERVCONF::GetUsers(PARSER_GET_USERS::CALLBACK f, void * data) +int SERVCONF::GetUsers(GET_USERS::CALLBACK f, void * data) { return pImpl->GetUsers( f, data ); } -int SERVCONF::GetUser(const std::string & login, PARSER_GET_USER::CALLBACK f, void * data) +int SERVCONF::GetUser(const std::string & login, GET_USER::CALLBACK f, void * data) { return pImpl->GetUser(login, f, data); } @@ -147,7 +149,7 @@ parser = XML_ParserCreate(NULL); nt.SetRxCallback(this, AnsRecv); } //----------------------------------------------------------------------------- -int SERVCONF::IMPL::GetUser(const std::string & login, PARSER_GET_USER::CALLBACK f, void * data) +int SERVCONF::IMPL::GetUser(const std::string & login, GET_USER::CALLBACK f, void * data) { parserGetUser.SetCallback(f, data); return Exec("", parserGetUser); @@ -159,7 +161,7 @@ parserAuthBy.SetCallback(f, data); return Exec("", parserAuthBy); } //----------------------------------------------------------------------------- -int SERVCONF::IMPL::GetUsers(PARSER_GET_USERS::CALLBACK f, void * data) +int SERVCONF::IMPL::GetUsers(GET_USERS::CALLBACK f, void * data) { parserGetUsers.SetCallback(f, data); return Exec("", parserGetUsers); -- 2.44.2