From: Maxim Mamontov Date: Fri, 6 Sep 2013 17:55:55 +0000 (+0300) Subject: [NY Flight] Improvements in parser dispatching. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/01ee16d4dc8527fce90f353b60d3df9c313f54ce?ds=inline [NY Flight] Improvements in parser dispatching. --- 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);