From: Maxim Mamontov Date: Fri, 20 Sep 2013 21:53:18 +0000 (+0300) Subject: Moved GET_USER and GET_USERS parsers from global scope. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/0a2687358e50cb8950667f050455281af6d1e1ae Moved GET_USER and GET_USERS parsers from global scope. --- 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/parser_get_user.h b/stglibs/srvconf.lib/include/stg/parser_get_user.h deleted file mode 100644 index a6fadeb8..00000000 --- a/stglibs/srvconf.lib/include/stg/parser_get_user.h +++ /dev/null @@ -1,100 +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_GET_USER_H__ -#define __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__ - -#include "parser.h" - -#include "property_parsers.h" - -#include "stg/os_int.h" -#include "stg/const.h" - -#include - -#include - -namespace STG -{ - -class PARSER_GET_USER: public 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(); - 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; - INFO info; - int depth; - bool parsingAnswer; - std::string error; - - void ParseUser(const char *el, const char **attr); - 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 deleted file mode 100644 index a8b8ac85..00000000 --- a/stglibs/srvconf.lib/include/stg/parser_get_users.h +++ /dev/null @@ -1,62 +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_GET_USERS_H__ -#define __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__ - -#include "parser.h" - -#include "parser_get_user.h" - -#include - -namespace STG -{ - -class PARSER_GET_USERS: public PARSER -{ -public: - typedef std::vector INFO; - typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); - - PARSER_GET_USERS(); - 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; - INFO info; - int depth; - bool parsingAnswer; - std::string error; - - void AddUser(const PARSER_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); -}; - -} // namespace STG - -#endif 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/parser_get_user.h b/stglibs/srvconf.lib/parser_get_user.h new file mode 100644 index 00000000..871dd211 --- /dev/null +++ b/stglibs/srvconf.lib/parser_get_user.h @@ -0,0 +1,64 @@ +/* + * 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_GET_USER_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__ + +#include "stg/parser.h" + +#include "stg/property_parsers.h" +#include "stg/servconf_types.h" + +#include + +#include + +namespace STG +{ +namespace GET_USER +{ + +class PARSER: public STG::PARSER +{ +public: + + PARSER(); + virtual ~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; + INFO info; + int depth; + bool parsingAnswer; + std::string error; + + void ParseUser(const char *el, const char **attr); + 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/parser_get_users.h b/stglibs/srvconf.lib/parser_get_users.h new file mode 100644 index 00000000..55258186 --- /dev/null +++ b/stglibs/srvconf.lib/parser_get_users.h @@ -0,0 +1,64 @@ + +/* + * 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_GET_USERS_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__ + +#include "stg/parser.h" +#include "stg/servconf_types.h" + +#include "parser_get_user.h" + +#include + +namespace STG +{ +namespace GET_USERS +{ + +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; + GET_USER::PARSER userParser; + INFO info; + int depth; + bool parsingAnswer; + std::string error; + + 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 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);