X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/17dab87336302938de1f031008cc4c4af31d2590..c9104229b3f6ee0320752780053ad97f5385359a:/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 9af85d03..9ba86c14 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,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]) @@ -90,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) @@ -182,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)