From 01ee16d4dc8527fce90f353b60d3df9c313f54ce Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 6 Sep 2013 20:55:55 +0300 Subject: [PATCH 1/1] [NY Flight] Improvements in parser dispatching. --- stglibs/srvconf.lib/include/stg/servconf.h | 2 +- stglibs/srvconf.lib/servconf.cpp | 38 +++++++--------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index 7cc18c4a..23a73c7b 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -96,7 +96,7 @@ private: std::string errorMsg; XML_Parser parser; - int Exec(const char * request); + int Exec(const char * request, PARSER & cp); friend bool AnsRecv(void * data, const std::string & chunk, bool final); }; diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 06a31a81..621cced0 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -28,13 +28,12 @@ namespace { -//----------------------------------------------------------------------------- -void ElementStart(void *data, const char *el, const char **attr) +void ElementStart(void * data, const char * el, const char ** attr) { SERVCONF * sc = static_cast(data); sc->Start(el, attr); } -//----------------------------------------------------------------------------- + void ElementEnd(void * data, const char * el) { SERVCONF * sc = static_cast(data); @@ -46,7 +45,6 @@ sc->End(el); bool AnsRecv(void * data, const std::string & chunk, bool final) { SERVCONF * sc = static_cast(data); -printf("Chunk: '%s', length: %d, final: %d\n", chunk.c_str(), chunk.length(), final); if (XML_Parse(sc->parser, chunk.c_str(), chunk.length(), final) == XML_STATUS_ERROR) { @@ -75,9 +73,7 @@ int SERVCONF::GetUser(const char * l) char request[255]; snprintf(request, 255, "", l); -currParser = &parserGetUser; - -return Exec(request); +return Exec(request, parserGetUser); } //----------------------------------------------------------------------------- int SERVCONF::AuthBy(const char * l) @@ -85,41 +81,31 @@ int SERVCONF::AuthBy(const char * l) char request[255]; snprintf(request, 255, "", l); -currParser = &parserAuthBy; - -return Exec(request); +return Exec(request, parserAuthBy); } //----------------------------------------------------------------------------- int SERVCONF::GetUsers() { char request[] = ""; -currParser = &parserGetUsers; - -return Exec(request); +return Exec(request, parserGetUsers); } //----------------------------------------------------------------------------- int SERVCONF::ServerInfo() { char request[] = ""; -currParser = &parserServerInfo; - -return Exec(request); +return Exec(request, parserServerInfo); } //----------------------------------------------------------------------------- int SERVCONF::ChgUser(const char * request) { -currParser = &parserChgUser; - -return Exec(request); +return Exec(request, parserChgUser); } //----------------------------------------------------------------------------- int SERVCONF::SendMessage(const char * request) { -currParser = &parserSendMessage; - -return Exec(request); +return Exec(request, parserSendMessage); } //----------------------------------------------------------------------------- int SERVCONF::CheckUser(const char * login, const char * password) @@ -127,9 +113,7 @@ int SERVCONF::CheckUser(const char * login, const char * password) char request[255]; snprintf(request, 255, "", login, password); -currParser = &parserCheckUser; - -return Exec(request); +return Exec(request, parserCheckUser); } //----------------------------------------------------------------------------- int SERVCONF::Start(const char * el, const char ** attr) @@ -183,8 +167,10 @@ const std::string & SERVCONF::GetStrError() const return errorMsg; } //----------------------------------------------------------------------------- -int SERVCONF::Exec(const char * request) +int SERVCONF::Exec(const char * request, PARSER & cp) { +currParser = &cp; + XML_ParserReset(parser, NULL); XML_SetElementHandler(parser, ElementStart, ElementEnd); XML_SetUserData(parser, this); -- 2.44.2