PARSER_GET_USER::STAT value;
if (!attr)
return value;
-std::map<std::string, long long &> props;
+std::map<std::string, long long *> props;
for (size_t i = 0; i < DIR_NUM; ++i)
{
- props.insert(std::pair<std::string, long long &>("su" + x2str(i), value.su[i]));
- props.insert(std::pair<std::string, long long &>("sd" + x2str(i), value.sd[i]));
- props.insert(std::pair<std::string, long long &>("mu" + x2str(i), value.mu[i]));
- props.insert(std::pair<std::string, long long &>("md" + x2str(i), value.md[i]));
+ props.insert(std::pair<std::string, long long *>("su" + x2str(i), &value.su[i]));
+ props.insert(std::pair<std::string, long long *>("sd" + x2str(i), &value.sd[i]));
+ props.insert(std::pair<std::string, long long *>("mu" + x2str(i), &value.mu[i]));
+ props.insert(std::pair<std::string, long long *>("md" + x2str(i), &value.md[i]));
}
size_t pos = 0;
while (attr[pos])
{
std::string name(ToLower(attr[pos++]));
- std::map<std::string, long long &>::iterator it(props.find(name));
+ std::map<std::string, long long *>::iterator it(props.find(name));
if (it != props.end())
- str2x(attr[pos++], it->second);
+ str2x(attr[pos++], *it->second);
}
return value;
}
return value;
}
-template <typename T>
-void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, bool encoded = false);
-
-template <typename T>
-void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, bool /*encoded*/)
+uint32_t getIPValue(const char ** attr)
{
- parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER<T>(value, getValue<T>)));
+if (checkValue(attr))
+ return inet_strington(attr[1]);
+return 0;
}
-template <>
-void addParser<std::string>(PROPERTY_PARSERS & parsers, const std::string & name, std::string & value, bool encoded)
+template <typename T>
+void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER<T>::FUNC & func = getValue<T>);
+
+template <typename T>
+void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER<T>::FUNC & func)
{
- if (encoded)
- parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER<std::string>(value, getEncodedValue)));
- else
- parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER<std::string>(value, getValue<std::string>)));
+ parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER<T>(value, func)));
}
void tryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr)
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()