X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/76fb825a64343da7a8aa9b16c5dbcab709504832..0d5bff91a33dc190351adc0010f8218c81423799:/stglibs/srvconf.lib/parsers/server_info.cpp?ds=sidebyside diff --git a/stglibs/srvconf.lib/parsers/server_info.cpp b/stglibs/srvconf.lib/parsers/server_info.cpp index d4c610e0..f0033611 100644 --- a/stglibs/srvconf.lib/parsers/server_info.cpp +++ b/stglibs/srvconf.lib/parsers/server_info.cpp @@ -19,29 +19,20 @@ * Author : Maxim Mamontov */ -#include "parser_server_info.h" +#include "server_info.h" #include "stg/common.h" #include // sprintf -#include #include using namespace STG; -namespace -{ - -const size_t UNAME_LEN = 256; -const size_t SERV_VER_LEN = 64; -const size_t DIRNAME_LEN = 16; - -} - -SERVER_INFO::PARSER::PARSER() - : callback(NULL), - data(NULL), +SERVER_INFO::PARSER::PARSER(CALLBACK f, void * d, const std::string & e) + : callback(f), + data(d), + encoding(e), depth(0), parsingAnswer(false) { @@ -49,23 +40,27 @@ SERVER_INFO::PARSER::PARSER() AddParser(propertyParsers, "version", info.version); AddParser(propertyParsers, "tariff", info.tariffType); AddParser(propertyParsers, "dir_num", info.dirNum); - AddParser(propertyParsers, "users_num", info.usersNum); + AddParser(propertyParsers, "user_num", info.usersNum); AddParser(propertyParsers, "tariff_num", info.tariffNum); for (size_t i = 0; i < DIR_NUM; i++) - AddParser(propertyParsers, "dir_name_" + x2str(i), info.dirName[i], GetEncodedValue); + AddParser(propertyParsers, "dir_name_" + unsigned2str(i), info.dirName[i], GetEncodedValue); } //----------------------------------------------------------------------------- int SERVER_INFO::PARSER::ParseStart(const char *el, const char **attr) { depth++; if (depth == 1) - if (strcasecmp(el, "ServerInfo") == 0) + { + if (strcasecmp(el, "GetServerInfo") == 0) parsingAnswer = true; + } else + { if (depth == 2 && parsingAnswer) - if (!TryParse(propertyParsers, ToLower(el), attr)) + if (!TryParse(propertyParsers, ToLower(el), attr, encoding)) error = "Invalid parameter."; + } return 0; } //----------------------------------------------------------------------------- @@ -80,9 +75,3 @@ if (depth == 0 && parsingAnswer) parsingAnswer = false; } } -//----------------------------------------------------------------------------- -void SERVER_INFO::PARSER::SetCallback(CALLBACK f, void * d) -{ -callback = f; -data = d; -}