X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/abe068d00ecc304c855886f5e511b563b352dd0a..2ecac495e165f5247a5e33669588a4ca8c2e8266:/stglibs/srvconf.lib/parsers/get_user.cpp diff --git a/stglibs/srvconf.lib/parsers/get_user.cpp b/stglibs/srvconf.lib/parsers/get_user.cpp index 71e6cba6..03327c4d 100644 --- a/stglibs/srvconf.lib/parsers/get_user.cpp +++ b/stglibs/srvconf.lib/parsers/get_user.cpp @@ -25,7 +25,6 @@ #include #include -#include #include @@ -35,17 +34,17 @@ namespace STG { template <> -bool GetValue(const char ** attr, GET_USER::STAT & value) +bool GetValue(const char ** attr, GET_USER::STAT & value, const std::string & /*attrName*/) { if (!attr) return false; std::map props; for (size_t i = 0; i < DIR_NUM; ++i) { - props.insert(std::pair("su" + x2str(i), &value.su[i])); - props.insert(std::pair("sd" + x2str(i), &value.sd[i])); - props.insert(std::pair("mu" + x2str(i), &value.mu[i])); - props.insert(std::pair("md" + x2str(i), &value.md[i])); + props.insert(std::pair("su" + unsigned2str(i), &value.su[i])); + props.insert(std::pair("sd" + unsigned2str(i), &value.sd[i])); + props.insert(std::pair("mu" + unsigned2str(i), &value.mu[i])); + props.insert(std::pair("md" + unsigned2str(i), &value.md[i])); } size_t pos = 0; while (attr[pos]) @@ -61,9 +60,10 @@ return true; } -GET_USER::PARSER::PARSER() - : callback(NULL), - data(NULL), +GET_USER::PARSER::PARSER(CALLBACK f, void * d, const std::string & e) + : callback(f), + data(d), + encoding(e), depth(0), parsingAnswer(false) { @@ -72,26 +72,30 @@ GET_USER::PARSER::PARSER() AddParser(propertyParsers, "cash", info.cash); AddParser(propertyParsers, "credit", info.credit); AddParser(propertyParsers, "creditExpire", info.creditExpire); - AddParser(propertyParsers, "lastCash", info.lastCash); - AddParser(propertyParsers, "prepaidTraff", info.prepaidTraff); - AddParser(propertyParsers, "down", info.down); + AddParser(propertyParsers, "lastCash", info.lastCashAdd); + AddParser(propertyParsers, "lastTimeCash", info.lastCashAddTime); + AddParser(propertyParsers, "freeMb", info.prepaidTraff); + AddParser(propertyParsers, "down", info.disabled); AddParser(propertyParsers, "passive", info.passive); AddParser(propertyParsers, "disableDetailStat", info.disableDetailStat); - AddParser(propertyParsers, "connected", info.connected); + AddParser(propertyParsers, "status", info.connected); AddParser(propertyParsers, "aonline", info.alwaysOnline); AddParser(propertyParsers, "currIP", info.ip, GetIPValue); AddParser(propertyParsers, "ip", info.ips); AddParser(propertyParsers, "tariff", info.tariff); - AddParser(propertyParsers, "group", info.group, GetEncodedValue); - AddParser(propertyParsers, "note", info.note, GetEncodedValue); - AddParser(propertyParsers, "email", info.email, GetEncodedValue); - AddParser(propertyParsers, "name", info.name, GetEncodedValue); - AddParser(propertyParsers, "address", info.address, GetEncodedValue); - AddParser(propertyParsers, "phone", info.phone, GetEncodedValue); + AddParser(propertyParsers, "group", info.group, "koi8-ru", GetEncodedValue); + AddParser(propertyParsers, "note", info.note, "koi8-ru", GetEncodedValue); + AddParser(propertyParsers, "email", info.email, "koi8-ru", GetEncodedValue); + AddParser(propertyParsers, "name", info.name, "koi8-ru", GetEncodedValue); + AddParser(propertyParsers, "address", info.address, "koi8-ru", GetEncodedValue); + AddParser(propertyParsers, "phone", info.phone, "cp1251", GetEncodedValue); + AddParser(propertyParsers, "corp", info.corp); AddParser(propertyParsers, "traff", info.stat); + AddParser(propertyParsers, "pingTime", info.pingTime); + AddParser(propertyParsers, "lastActivityTime", info.lastActivityTime); for (size_t i = 0; i < USERDATA_NUM; ++i) - AddParser(propertyParsers, "userData" + x2str(i), info.userData[i], GetEncodedValue); + AddParser(propertyParsers, "userData" + unsigned2str(i), info.userData[i], "koi8-ru", GetEncodedValue); } //----------------------------------------------------------------------------- GET_USER::PARSER::~PARSER() @@ -110,6 +114,12 @@ if (depth == 1) if (depth == 2 && parsingAnswer) ParseUserParams(el, attr); +if (depth == 3 && parsingAnswer) + { + ParseAuthBy(el, attr); + ParseServices(el, attr); + } + return 0; } //----------------------------------------------------------------------------- @@ -128,6 +138,7 @@ if (depth == 0 && parsingAnswer) void GET_USER::PARSER::ParseUser(const char * el, const char ** attr) { if (strcasecmp(el, "user") == 0) + { if (attr && attr[0] && attr[1]) { if (strcasecmp(attr[1], "error") == 0) @@ -137,21 +148,35 @@ if (strcasecmp(el, "user") == 0) else error = "User not found."; } - else - parsingAnswer = true; + else if (strcasecmp(attr[0], "login") == 0 && attr[1]) + info.login = attr[1]; } - else - parsingAnswer = true; + parsingAnswer = true; + } } //----------------------------------------------------------------------------- void GET_USER::PARSER::ParseUserParams(const char * el, const char ** attr) { -if (!TryParse(propertyParsers, ToLower(el), attr)) +if (strcasecmp(el, "AuthorizedBy") != 0 && + !TryParse(propertyParsers, ToLower(el), attr, encoding)) error = "Invalid parameter."; +else if (strcasecmp(el, "Services") != 0 && + !TryParse(propertyParsers, ToLower(el), attr, encoding)) + error = "Invalid parameter."; +} +//----------------------------------------------------------------------------- +void GET_USER::PARSER::ParseAuthBy(const char * el, const char ** attr) +{ +if (strcasecmp(el, "Auth") == 0 && + attr && attr[0] && attr[1] && + strcasecmp(attr[0], "name") == 0) + info.authBy.push_back(attr[1]); } //----------------------------------------------------------------------------- -void GET_USER::PARSER::SetCallback(CALLBACK f, void * d) +void GET_USER::PARSER::ParseServices(const char * el, const char ** attr) { -callback = f; -data = d; +if (strcasecmp(el, "Service") == 0 && + attr && attr[0] && attr[1] && + strcasecmp(attr[0], "name") == 0) + info.services.push_back(attr[1]); }