X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/9b75c67ad810fb5b256e59d387e143dfdb1a0071..76fb825a64343da7a8aa9b16c5dbcab709504832:/stglibs/srvconf.lib/parsers/server_info.cpp diff --git a/stglibs/srvconf.lib/parsers/server_info.cpp b/stglibs/srvconf.lib/parsers/server_info.cpp new file mode 100644 index 00000000..d4c610e0 --- /dev/null +++ b/stglibs/srvconf.lib/parsers/server_info.cpp @@ -0,0 +1,88 @@ +/* + * 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 "parser_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), + depth(0), + parsingAnswer(false) +{ + AddParser(propertyParsers, "uname", info.uname); + AddParser(propertyParsers, "version", info.version); + AddParser(propertyParsers, "tariff", info.tariffType); + AddParser(propertyParsers, "dir_num", info.dirNum); + AddParser(propertyParsers, "users_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); +} +//----------------------------------------------------------------------------- +int SERVER_INFO::PARSER::ParseStart(const char *el, const char **attr) +{ +depth++; +if (depth == 1) + if (strcasecmp(el, "ServerInfo") == 0) + parsingAnswer = true; +else + if (depth == 2 && parsingAnswer) + if (!TryParse(propertyParsers, ToLower(el), attr)) + error = "Invalid parameter."; +return 0; +} +//----------------------------------------------------------------------------- +void SERVER_INFO::PARSER::ParseEnd(const char * /*el*/) +{ +depth--; +if (depth == 0 && parsingAnswer) + { + if (callback) + callback(error.empty(), error, info, data); + error.clear(); + parsingAnswer = false; + } +} +//----------------------------------------------------------------------------- +void SERVER_INFO::PARSER::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +}