X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/26d5d878270d01123669ba6a38c306c398ed7b8d..68ff250b88c43acf959cdf80eb9c3a519157a3f7:/stglibs/srvconf.lib/parser_get_users.cpp?ds=inline diff --git a/stglibs/srvconf.lib/parser_get_users.cpp b/stglibs/srvconf.lib/parser_get_users.cpp index 8f83211f..2f380c82 100644 --- a/stglibs/srvconf.lib/parser_get_users.cpp +++ b/stglibs/srvconf.lib/parser_get_users.cpp @@ -21,10 +21,15 @@ #include "stg/parser_get_users.h" +#include + +#include + PARSER_GET_USERS::PARSER_GET_USERS() - : callabck(NULL), + : callback(NULL), data(NULL), - depth(0) + depth(0), + parsingAnswer(false) { userParser.SetCallback(&PARSER_GET_USERS::UserCallback, this); } @@ -32,10 +37,10 @@ PARSER_GET_USERS::PARSER_GET_USERS() int PARSER_GET_USERS::ParseStart(const char * el, const char ** attr) { depth++; -if (depth == 1) - ParseUsers(el, attr); +if (depth == 1 && strcasecmp(el, "users") == 0) + parsingAnswer = true; -if (depth > 1) +if (depth > 1 && parsingAnswer) userParser.ParseStart(el, attr); return 0; @@ -44,18 +49,17 @@ return 0; void PARSER_GET_USERS::ParseEnd(const char * el) { depth--; -if (depth > 0) +if (depth > 0 && parsingAnswer) userParser.ParseEnd(el); -if (depth == 0) +if (depth == 0 && parsingAnswer) + { if (callback) - callback(&info, data); -} -//----------------------------------------------------------------------------- -void PARSER_GET_USERS::ParseUsers(const char * el, const char ** /*attr*/) -{ -if (strcasecmp(el, "users") == 0) + callback(error.empty(), error, info, data); + error.clear(); info.clear(); + parsingAnswer = false; + } } //----------------------------------------------------------------------------- void PARSER_GET_USERS::AddUser(const PARSER_GET_USER::INFO & userInfo) @@ -66,11 +70,14 @@ info.push_back(userInfo); void PARSER_GET_USERS::SetCallback(CALLBACK f, void * d) { callback = f; -data = data; +data = d; } //----------------------------------------------------------------------------- -void PARSER_GET_USERS::UserCallback(const PARSER_GET_USER::INFO & info, void * data) +void PARSER_GET_USERS::UserCallback(bool result, const std::string & error, const PARSER_GET_USER::INFO & info, void * data) { PARSER_GET_USERS * parser = static_cast(data); - parser->AddUser(info); + if (!result) + parser->SetError(error); + else + parser->AddUser(info); }