From: Maxim Mamontov Date: Sun, 20 Oct 2013 10:32:56 +0000 (+0300) Subject: Replaces vector parsers with a single one. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/2d0dedb8abc45c661e35e729b5ff71724d4d749a?ds=sidebyside;hp=--cc Replaces vector parsers with a single one. --- 2d0dedb8abc45c661e35e729b5ff71724d4d749a diff --git a/stglibs/srvconf.lib/Makefile b/stglibs/srvconf.lib/Makefile index d66d2b3e..d7bc80c0 100644 --- a/stglibs/srvconf.lib/Makefile +++ b/stglibs/srvconf.lib/Makefile @@ -11,20 +11,15 @@ LIBS = -lexpat SRCS = parsers/property.cpp \ parsers/simple.cpp \ parsers/server_info.cpp \ - parsers/get_admins.cpp \ parsers/get_admin.cpp \ parsers/chg_admin.cpp \ - parsers/get_tariffs.cpp \ parsers/get_tariff.cpp \ parsers/chg_tariff.cpp \ parsers/auth_by.cpp \ parsers/get_user.cpp \ - parsers/get_users.cpp \ parsers/chg_user.cpp \ - parsers/get_services.cpp \ parsers/get_service.cpp \ parsers/chg_service.cpp \ - parsers/get_corporations.cpp \ parsers/get_corp.cpp \ parsers/chg_corp.cpp \ netunit.cpp \ diff --git a/stglibs/srvconf.lib/parsers/get_admin.h b/stglibs/srvconf.lib/parsers/get_admin.h index 04ed892c..d8e2fe9e 100644 --- a/stglibs/srvconf.lib/parsers/get_admin.h +++ b/stglibs/srvconf.lib/parsers/get_admin.h @@ -37,6 +37,8 @@ namespace GET_ADMIN class PARSER: public STG::PARSER { public: + typedef GET_ADMIN::INFO INFO; + PARSER(CALLBACK f, void * data); virtual ~PARSER(); int ParseStart(const char * el, const char ** attr); diff --git a/stglibs/srvconf.lib/parsers/get_admins.cpp b/stglibs/srvconf.lib/parsers/get_admins.cpp deleted file mode 100644 index 947a9ce4..00000000 --- a/stglibs/srvconf.lib/parsers/get_admins.cpp +++ /dev/null @@ -1,76 +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 : Maxim Mamontov - */ - -#include "get_admins.h" - -#include - -using namespace STG; - -GET_ADMINS::PARSER::PARSER(CALLBACK f, void * d) - : callback(f), - data(d), - adminParser(&GET_ADMINS::PARSER::AdminCallback, this), - depth(0), - parsingAnswer(false) -{ -} -//----------------------------------------------------------------------------- -int GET_ADMINS::PARSER::ParseStart(const char * el, const char ** attr) -{ -depth++; -if (depth == 1 && strcasecmp(el, "admins") == 0) - parsingAnswer = true; - -if (depth > 1 && parsingAnswer) - adminParser.ParseStart(el, attr); - -return 0; -} -//----------------------------------------------------------------------------- -void GET_ADMINS::PARSER::ParseEnd(const char * el) -{ -depth--; -if (depth > 0 && parsingAnswer) - adminParser.ParseEnd(el); - -if (depth == 0 && parsingAnswer) - { - if (callback) - callback(error.empty(), error, info, data); - error.clear(); - info.clear(); - parsingAnswer = false; - } -} -//----------------------------------------------------------------------------- -void GET_ADMINS::PARSER::AddAdmin(const GET_ADMIN::INFO & adminInfo) -{ -info.push_back(adminInfo); -} -//----------------------------------------------------------------------------- -void GET_ADMINS::PARSER::AdminCallback(bool result, const std::string & error, const GET_ADMIN::INFO & info, void * data) -{ - GET_ADMINS::PARSER * parser = static_cast(data); - if (!result) - parser->SetError(error); - else - parser->AddAdmin(info); -} diff --git a/stglibs/srvconf.lib/parsers/get_admins.h b/stglibs/srvconf.lib/parsers/get_admins.h deleted file mode 100644 index 4b6d122f..00000000 --- a/stglibs/srvconf.lib/parsers/get_admins.h +++ /dev/null @@ -1,61 +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 : Maxim Mamontov - */ - -#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_ADMINS_H__ -#define __STG_STGLIBS_SRVCONF_PARSER_GET_ADMINS_H__ - -#include "base.h" -#include "get_admin.h" - -#include "stg/servconf_types.h" - -#include - -namespace STG -{ -namespace GET_ADMINS -{ - -class PARSER: public STG::PARSER -{ -public: - PARSER(CALLBACK f, void * data); - int ParseStart(const char * el, const char ** attr); - void ParseEnd(const char * el); - -private: - CALLBACK callback; - void * data; - GET_ADMIN::PARSER adminParser; - INFO info; - int depth; - bool parsingAnswer; - std::string error; - - void AddAdmin(const GET_ADMIN::INFO & adminInfo); - void SetError(const std::string & e) { error = e; } - - static void AdminCallback(bool result, const std::string& reason, const GET_ADMIN::INFO & info, void * data); -}; - -} // namespace GET_ADMINS -} // namespace STG - -#endif diff --git a/stglibs/srvconf.lib/parsers/get_container.h b/stglibs/srvconf.lib/parsers/get_container.h new file mode 100644 index 00000000..31bb4250 --- /dev/null +++ b/stglibs/srvconf.lib/parsers/get_container.h @@ -0,0 +1,100 @@ +/* + * 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 : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_CONTAINER_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_GET_CONTAINER_H__ + +#include "base.h" + +#include + +namespace STG +{ +namespace GET_CONTAINER +{ + +template +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(const std::string & t, CALLBACK f, void * d) + : tag(t), callback(f), data(d), + elementParser(&PARSER::ElementCallback, this), + depth(0), parsingAnswer(false) + {} + int ParseStart(const char * el, const char ** attr) + { + depth++; + if (depth == 1 && strcasecmp(el, tag.c_str()) == 0) + parsingAnswer = true; + + if (depth > 1 && parsingAnswer) + elementParser.ParseStart(el, attr); + + return 0; + } + void ParseEnd(const char * el) + { + depth--; + if (depth > 0 && parsingAnswer) + elementParser.ParseEnd(el); + + if (depth == 0 && parsingAnswer) + { + if (callback) + callback(error.empty(), error, info, data); + error.clear(); + info.clear(); + parsingAnswer = false; + } + } + +private: + std::string tag; + CALLBACK callback; + void * data; + ELEMENT_PARSER elementParser; + INFO info; + int depth; + bool parsingAnswer; + std::string error; + + void AddElement(const typename ELEMENT_PARSER::INFO & elementInfo) + { + info.push_back(elementInfo); + } + void SetError(const std::string & e) { error = e; } + + static void ElementCallback(bool result, const std::string& reason, const typename ELEMENT_PARSER::INFO & info, void * data) + { + PARSER * parser = static_cast *>(data); + if (!result) + parser->SetError(reason); + else + parser->AddElement(info); + } +}; + +} // namespace GET_CONTAINER +} // namespace STG + +#endif diff --git a/stglibs/srvconf.lib/parsers/get_corp.h b/stglibs/srvconf.lib/parsers/get_corp.h index 80b1e943..a01fe262 100644 --- a/stglibs/srvconf.lib/parsers/get_corp.h +++ b/stglibs/srvconf.lib/parsers/get_corp.h @@ -37,6 +37,8 @@ namespace GET_CORP class PARSER: public STG::PARSER { public: + typedef GET_CORP::INFO INFO; + PARSER(CALLBACK f, void * data); virtual ~PARSER(); int ParseStart(const char * el, const char ** attr); diff --git a/stglibs/srvconf.lib/parsers/get_corporations.cpp b/stglibs/srvconf.lib/parsers/get_corporations.cpp deleted file mode 100644 index 0a9a68ad..00000000 --- a/stglibs/srvconf.lib/parsers/get_corporations.cpp +++ /dev/null @@ -1,76 +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 : Maxim Mamontov - */ - -#include "get_corporations.h" - -#include - -using namespace STG; - -GET_CORPORATIONS::PARSER::PARSER(CALLBACK f, void * d) - : callback(f), - data(d), - corpParser(&GET_CORPORATIONS::PARSER::CorpCallback, this), - depth(0), - parsingAnswer(false) -{ -} -//----------------------------------------------------------------------------- -int GET_CORPORATIONS::PARSER::ParseStart(const char * el, const char ** attr) -{ -depth++; -if (depth == 1 && strcasecmp(el, "corporations") == 0) - parsingAnswer = true; - -if (depth > 1 && parsingAnswer) - corpParser.ParseStart(el, attr); - -return 0; -} -//----------------------------------------------------------------------------- -void GET_CORPORATIONS::PARSER::ParseEnd(const char * el) -{ -depth--; -if (depth > 0 && parsingAnswer) - corpParser.ParseEnd(el); - -if (depth == 0 && parsingAnswer) - { - if (callback) - callback(error.empty(), error, info, data); - error.clear(); - info.clear(); - parsingAnswer = false; - } -} -//----------------------------------------------------------------------------- -void GET_CORPORATIONS::PARSER::AddCorp(const GET_CORP::INFO & corpInfo) -{ -info.push_back(corpInfo); -} -//----------------------------------------------------------------------------- -void GET_CORPORATIONS::PARSER::CorpCallback(bool result, const std::string & error, const GET_CORP::INFO & info, void * data) -{ - GET_CORPORATIONS::PARSER * parser = static_cast(data); - if (!result) - parser->SetError(error); - else - parser->AddCorp(info); -} diff --git a/stglibs/srvconf.lib/parsers/get_corporations.h b/stglibs/srvconf.lib/parsers/get_corporations.h deleted file mode 100644 index 192367d1..00000000 --- a/stglibs/srvconf.lib/parsers/get_corporations.h +++ /dev/null @@ -1,61 +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 : Maxim Mamontov - */ - -#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_CORPORATIONS_H__ -#define __STG_STGLIBS_SRVCONF_PARSER_GET_CORPORATIONS_H__ - -#include "base.h" -#include "get_corp.h" - -#include "stg/servconf_types.h" - -#include - -namespace STG -{ -namespace GET_CORPORATIONS -{ - -class PARSER: public STG::PARSER -{ -public: - PARSER(CALLBACK f, void * data); - int ParseStart(const char * el, const char ** attr); - void ParseEnd(const char * el); - -private: - CALLBACK callback; - void * data; - GET_CORP::PARSER corpParser; - INFO info; - int depth; - bool parsingAnswer; - std::string error; - - void AddCorp(const GET_CORP::INFO & corpInfo); - void SetError(const std::string & e) { error = e; } - - static void CorpCallback(bool result, const std::string& reason, const GET_CORP::INFO & info, void * data); -}; - -} // namespace GET_CORPORATIONS -} // namespace STG - -#endif diff --git a/stglibs/srvconf.lib/parsers/get_service.h b/stglibs/srvconf.lib/parsers/get_service.h index 24c04849..847d8bfd 100644 --- a/stglibs/srvconf.lib/parsers/get_service.h +++ b/stglibs/srvconf.lib/parsers/get_service.h @@ -37,6 +37,7 @@ namespace GET_SERVICE class PARSER: public STG::PARSER { public: + typedef GET_SERVICE::INFO INFO; PARSER(CALLBACK f, void * data); virtual ~PARSER(); int ParseStart(const char * el, const char ** attr); diff --git a/stglibs/srvconf.lib/parsers/get_services.cpp b/stglibs/srvconf.lib/parsers/get_services.cpp deleted file mode 100644 index c34a7099..00000000 --- a/stglibs/srvconf.lib/parsers/get_services.cpp +++ /dev/null @@ -1,76 +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 : Maxim Mamontov - */ - -#include "get_services.h" - -#include - -using namespace STG; - -GET_SERVICES::PARSER::PARSER(CALLBACK f, void * d) - : callback(f), - data(d), - serviceParser(&GET_SERVICES::PARSER::ServiceCallback, this), - depth(0), - parsingAnswer(false) -{ -} -//----------------------------------------------------------------------------- -int GET_SERVICES::PARSER::ParseStart(const char * el, const char ** attr) -{ -depth++; -if (depth == 1 && strcasecmp(el, "services") == 0) - parsingAnswer = true; - -if (depth > 1 && parsingAnswer) - serviceParser.ParseStart(el, attr); - -return 0; -} -//----------------------------------------------------------------------------- -void GET_SERVICES::PARSER::ParseEnd(const char * el) -{ -depth--; -if (depth > 0 && parsingAnswer) - serviceParser.ParseEnd(el); - -if (depth == 0 && parsingAnswer) - { - if (callback) - callback(error.empty(), error, info, data); - error.clear(); - info.clear(); - parsingAnswer = false; - } -} -//----------------------------------------------------------------------------- -void GET_SERVICES::PARSER::AddService(const GET_SERVICE::INFO & serviceInfo) -{ -info.push_back(serviceInfo); -} -//----------------------------------------------------------------------------- -void GET_SERVICES::PARSER::ServiceCallback(bool result, const std::string & error, const GET_SERVICE::INFO & info, void * data) -{ - GET_SERVICES::PARSER * parser = static_cast(data); - if (!result) - parser->SetError(error); - else - parser->AddService(info); -} diff --git a/stglibs/srvconf.lib/parsers/get_services.h b/stglibs/srvconf.lib/parsers/get_services.h deleted file mode 100644 index c7ce9b58..00000000 --- a/stglibs/srvconf.lib/parsers/get_services.h +++ /dev/null @@ -1,61 +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 : Maxim Mamontov - */ - -#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_SERVICES_H__ -#define __STG_STGLIBS_SRVCONF_PARSER_GET_SERVICES_H__ - -#include "base.h" -#include "get_service.h" - -#include "stg/servconf_types.h" - -#include - -namespace STG -{ -namespace GET_SERVICES -{ - -class PARSER: public STG::PARSER -{ -public: - PARSER(CALLBACK f, void * data); - int ParseStart(const char * el, const char ** attr); - void ParseEnd(const char * el); - -private: - CALLBACK callback; - void * data; - GET_SERVICE::PARSER serviceParser; - INFO info; - int depth; - bool parsingAnswer; - std::string error; - - void AddService(const GET_SERVICE::INFO & serviceInfo); - void SetError(const std::string & e) { error = e; } - - static void ServiceCallback(bool result, const std::string& reason, const GET_SERVICE::INFO & info, void * data); -}; - -} // namespace GET_SERVICES -} // namespace STG - -#endif diff --git a/stglibs/srvconf.lib/parsers/get_tariff.h b/stglibs/srvconf.lib/parsers/get_tariff.h index 1c03d655..e6558259 100644 --- a/stglibs/srvconf.lib/parsers/get_tariff.h +++ b/stglibs/srvconf.lib/parsers/get_tariff.h @@ -37,6 +37,8 @@ namespace GET_TARIFF class PARSER: public STG::PARSER { public: + typedef GET_TARIFF::INFO INFO; + PARSER(CALLBACK f, void * data); virtual ~PARSER(); int ParseStart(const char * el, const char ** attr); diff --git a/stglibs/srvconf.lib/parsers/get_tariffs.cpp b/stglibs/srvconf.lib/parsers/get_tariffs.cpp deleted file mode 100644 index b5d0fe6e..00000000 --- a/stglibs/srvconf.lib/parsers/get_tariffs.cpp +++ /dev/null @@ -1,76 +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 : Maxim Mamontov - */ - -#include "get_tariffs.h" - -#include - -using namespace STG; - -GET_TARIFFS::PARSER::PARSER(CALLBACK f, void * d) - : callback(f), - data(d), - tariffParser(&GET_TARIFFS::PARSER::TariffCallback, this), - depth(0), - parsingAnswer(false) -{ -} -//----------------------------------------------------------------------------- -int GET_TARIFFS::PARSER::ParseStart(const char * el, const char ** attr) -{ -depth++; -if (depth == 1 && strcasecmp(el, "tariffs") == 0) - parsingAnswer = true; - -if (depth > 1 && parsingAnswer) - tariffParser.ParseStart(el, attr); - -return 0; -} -//----------------------------------------------------------------------------- -void GET_TARIFFS::PARSER::ParseEnd(const char * el) -{ -depth--; -if (depth > 0 && parsingAnswer) - tariffParser.ParseEnd(el); - -if (depth == 0 && parsingAnswer) - { - if (callback) - callback(error.empty(), error, info, data); - error.clear(); - info.clear(); - parsingAnswer = false; - } -} -//----------------------------------------------------------------------------- -void GET_TARIFFS::PARSER::AddTariff(const GET_TARIFF::INFO & tariffInfo) -{ -info.push_back(tariffInfo); -} -//----------------------------------------------------------------------------- -void GET_TARIFFS::PARSER::TariffCallback(bool result, const std::string & error, const GET_TARIFF::INFO & info, void * data) -{ - GET_TARIFFS::PARSER * parser = static_cast(data); - if (!result) - parser->SetError(error); - else - parser->AddTariff(info); -} diff --git a/stglibs/srvconf.lib/parsers/get_tariffs.h b/stglibs/srvconf.lib/parsers/get_tariffs.h deleted file mode 100644 index d011f9b8..00000000 --- a/stglibs/srvconf.lib/parsers/get_tariffs.h +++ /dev/null @@ -1,61 +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 : Maxim Mamontov - */ - -#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_TARIFFS_H__ -#define __STG_STGLIBS_SRVCONF_PARSER_GET_TARIFFS_H__ - -#include "base.h" -#include "get_tariff.h" - -#include "stg/servconf_types.h" - -#include - -namespace STG -{ -namespace GET_TARIFFS -{ - -class PARSER: public STG::PARSER -{ -public: - PARSER(CALLBACK f, void * data); - int ParseStart(const char * el, const char ** attr); - void ParseEnd(const char * el); - -private: - CALLBACK callback; - void * data; - GET_TARIFF::PARSER tariffParser; - INFO info; - int depth; - bool parsingAnswer; - std::string error; - - void AddTariff(const GET_TARIFF::INFO & tariffInfo); - void SetError(const std::string & e) { error = e; } - - static void TariffCallback(bool result, const std::string& reason, const GET_TARIFF::INFO & info, void * data); -}; - -} // namespace GET_TARIFFS -} // namespace STG - -#endif diff --git a/stglibs/srvconf.lib/parsers/get_user.h b/stglibs/srvconf.lib/parsers/get_user.h index 12050752..519d67b6 100644 --- a/stglibs/srvconf.lib/parsers/get_user.h +++ b/stglibs/srvconf.lib/parsers/get_user.h @@ -37,6 +37,8 @@ namespace GET_USER class PARSER: public STG::PARSER { public: + typedef GET_USER::INFO INFO; + PARSER(CALLBACK f, void * data); virtual ~PARSER(); int ParseStart(const char * el, const char ** attr); diff --git a/stglibs/srvconf.lib/parsers/get_users.cpp b/stglibs/srvconf.lib/parsers/get_users.cpp deleted file mode 100644 index 6c385b0c..00000000 --- a/stglibs/srvconf.lib/parsers/get_users.cpp +++ /dev/null @@ -1,77 +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 - */ - -#include "get_users.h" - -#include - -using namespace STG; - -GET_USERS::PARSER::PARSER(CALLBACK f, void * d) - : callback(f), - data(d), - userParser(&GET_USERS::PARSER::UserCallback, this), - depth(0), - parsingAnswer(false) -{ -} -//----------------------------------------------------------------------------- -int GET_USERS::PARSER::ParseStart(const char * el, const char ** attr) -{ -depth++; -if (depth == 1 && strcasecmp(el, "users") == 0) - parsingAnswer = true; - -if (depth > 1 && parsingAnswer) - userParser.ParseStart(el, attr); - -return 0; -} -//----------------------------------------------------------------------------- -void GET_USERS::PARSER::ParseEnd(const char * el) -{ -depth--; -if (depth > 0 && parsingAnswer) - userParser.ParseEnd(el); - -if (depth == 0 && parsingAnswer) - { - if (callback) - callback(error.empty(), error, info, data); - error.clear(); - info.clear(); - parsingAnswer = false; - } -} -//----------------------------------------------------------------------------- -void GET_USERS::PARSER::AddUser(const GET_USER::INFO & userInfo) -{ -info.push_back(userInfo); -} -//----------------------------------------------------------------------------- -void GET_USERS::PARSER::UserCallback(bool result, const std::string & error, const GET_USER::INFO & info, void * data) -{ - GET_USERS::PARSER * parser = static_cast(data); - if (!result) - parser->SetError(error); - else - parser->AddUser(info); -} diff --git a/stglibs/srvconf.lib/parsers/get_users.h b/stglibs/srvconf.lib/parsers/get_users.h deleted file mode 100644 index d1289e3a..00000000 --- a/stglibs/srvconf.lib/parsers/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 "base.h" -#include "get_user.h" - -#include "stg/servconf_types.h" - -#include - -namespace STG -{ -namespace GET_USERS -{ - -class PARSER: public STG::PARSER -{ -public: - PARSER(CALLBACK f, void * data); - int ParseStart(const char * el, const char ** attr); - void ParseEnd(const char * el); - -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 e80c3ffa..a9881f05 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -24,27 +24,23 @@ #include "netunit.h" #include "parsers/simple.h" +#include "parsers/get_container.h" #include "parsers/server_info.h" -#include "parsers/get_admins.h" #include "parsers/get_admin.h" #include "parsers/chg_admin.h" -#include "parsers/get_tariffs.h" #include "parsers/get_tariff.h" #include "parsers/chg_tariff.h" #include "parsers/auth_by.h" -#include "parsers/get_users.h" #include "parsers/get_user.h" #include "parsers/chg_user.h" -#include "parsers/get_services.h" #include "parsers/get_service.h" #include "parsers/chg_service.h" -#include "parsers/get_corporations.h" #include "parsers/get_corp.h" #include "parsers/chg_corp.h" @@ -143,7 +139,7 @@ return pImpl->RawXML(request, f, data); int SERVCONF::GetAdmins(GET_ADMINS::CALLBACK f, void * data) { -return pImpl->Exec("", f, data); +return pImpl->Exec >("admins", "", f, data); } int SERVCONF::GetAdmin(const std::string & login, GET_ADMIN::CALLBACK f, void * data) @@ -175,7 +171,7 @@ return pImpl->Exec("DelAdmin", "Exec("", f, data); +return pImpl->Exec >("tariffs", "", f, data); } int SERVCONF::GetTariff(const std::string & name, GET_TARIFF::CALLBACK f, void * data) @@ -207,7 +203,7 @@ return pImpl->Exec("DelTariff", "Exec("", f, data); +return pImpl->Exec >("users", "", f, data); } int SERVCONF::GetUser(const std::string & login, GET_USER::CALLBACK f, void * data) @@ -252,7 +248,7 @@ return pImpl->Exec("CheckUser", "Exec("", f, data); +return pImpl->Exec >("services", "", f, data); } int SERVCONF::GetService(const std::string & name, GET_SERVICE::CALLBACK f, void * data) @@ -284,7 +280,7 @@ return pImpl->Exec("DelService", "Exec("", f, data); +return pImpl->Exec >("corporations", "", f, data); } int SERVCONF::GetCorp(const std::string & name, GET_CORP::CALLBACK f, void * data)