X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/a8689998a9b2cfc17dc260b423cce8ff2e407adb..d3819ef7b806ccd92a767ec4bb43e0388f879216:/stglibs/srvconf.lib/parser_get_user.cpp?ds=sidebyside diff --git a/stglibs/srvconf.lib/parser_get_user.cpp b/stglibs/srvconf.lib/parser_get_user.cpp index cef40da2..9ba86c14 100644 --- a/stglibs/srvconf.lib/parser_get_user.cpp +++ b/stglibs/srvconf.lib/parser_get_user.cpp @@ -23,6 +23,11 @@ #include "stg/common.h" +#include +#include + +#include + namespace { @@ -54,24 +59,24 @@ 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; 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]) @@ -86,24 +91,28 @@ 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 = false); + template void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, bool /*encoded*/) { - parsers.insert(ToLower(name), new PROPERTY_PARSER(value, getValue)); + parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER(value, getValue))); } template <> void addParser(PROPERTY_PARSERS & parsers, const std::string & name, std::string & value, bool encoded) { if (encoded) - parsers.insert(ToLower(name), new PROPERTY_PARSER(value, getEncodedValue)); + parsers.insert(std::make_pair(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, getValue))); } void tryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr) @@ -178,7 +187,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)