X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/17dab87336302938de1f031008cc4c4af31d2590..61b5cf35c82a5850ceb07fca5232a409e249444c:/stglibs/srvconf.lib/parser_get_user.cpp diff --git a/stglibs/srvconf.lib/parser_get_user.cpp b/stglibs/srvconf.lib/parser_get_user.cpp index 9af85d03..1039cb8d 100644 --- a/stglibs/srvconf.lib/parser_get_user.cpp +++ b/stglibs/srvconf.lib/parser_get_user.cpp @@ -23,6 +23,7 @@ #include "stg/common.h" +#include #include #include @@ -58,56 +59,58 @@ double getValue(const char ** attr) { double value = 0; if (checkValue(attr)) - if (strtodouble2(attr[1], value) == EINVAL) + if (strtodouble2(attr[1], value)) return 0; return value; } template <> -STAT getValue(const char ** attr) +PARSER_GET_USER::STAT getValue(const char ** attr) { -STAT value; +PARSER_GET_USER::STAT value; if (!attr) return value; -std::map props; +std::map props; for (size_t i = 0; i < DIR_NUM; ++i) { - props.insert("su" + x2str(i), value.su[i]); - props.insert("sd" + x2str(i), value.sd[i]); - props.insert("mu" + x2str(i), value.mu[i]); - props.insert("md" + x2str(i), value.md[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])); } size_t pos = 0; while (attr[pos]) { std::string name(ToLower(attr[pos++])); - std::map::iterator it(props.find(name)); + std::map::iterator it(props.find(name)); if (it != props.end()) - str2x(attr[pos++], it->second); + str2x(attr[pos++], *it->second); } return value; } std::string getEncodedValue(const char ** attr) { +std::string value; if (checkValue(attr)) - return Decode21str(attr[1]); -return ""; + Decode21str(value, attr[1]); +return value; } -template -void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, bool /*encoded*/) +uint32_t getIPValue(const char ** attr) { - parsers.insert(ToLower(name), new PROPERTY_PARSER(value, getValue)); +if (checkValue(attr)) + return inet_strington(attr[1]); +return 0; } -template <> -void addParser(PROPERTY_PARSERS & parsers, const std::string & name, std::string & value, bool encoded) +template +void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER::FUNC & func = getValue); + +template +void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER::FUNC & func) { - if (encoded) - parsers.insert(ToLower(name), new PROPERTY_PARSER(value, getEncodedValue)); - else - parsers.insert(ToLower(name), new PROPERTY_PARSER(value, getValue)); + parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER(value, func))); } void tryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr) @@ -136,19 +139,19 @@ PARSER_GET_USER::PARSER_GET_USER() addParser(propertyParsers, "disableDetailStat", info.disableDetailStat); addParser(propertyParsers, "connected", info.connected); addParser(propertyParsers, "alwaysOnline", info.alwaysOnline); - addParser(propertyParsers, "ip", info.ip); - addParser(propertyParsers, "ips", info.ips); + addParser(propertyParsers, "currIP", info.ip, getIPValue); + addParser(propertyParsers, "ip", info.ips); addParser(propertyParsers, "tariff", info.tariff); - addParser(propertyParsers, "group", info.group, true); - addParser(propertyParsers, "note", info.note, true); - addParser(propertyParsers, "email", info.email, true); - addParser(propertyParsers, "name", info.name, true); - addParser(propertyParsers, "address", info.address, true); - addParser(propertyParsers, "phone", info.phone, true); + 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, "traff", info.stat); for (size_t i = 0; i < USERDATA_NUM; ++i) - addParser(propertyParsers, "userData" + x2str(i), info.userData[i], true); + addParser(propertyParsers, "userData" + x2str(i), info.userData[i], getEncodedValue); } //----------------------------------------------------------------------------- PARSER_GET_USER::~PARSER_GET_USER() @@ -182,7 +185,7 @@ void PARSER_GET_USER::ParseUser(const char * el, const char ** attr) { if (strcasecmp(el, "user") == 0) if (strcasecmp(attr[1], "error") == 0) - user.login = ""; + info.login = ""; } //----------------------------------------------------------------------------- void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr)