+void ConvBool(const std::string & value, std::optional<int> & res)
+{
+res = !value.empty() && value[0] == 'y';
+}
+
+void Splice(std::vector<std::optional<std::string> > & lhs, const std::vector<std::optional<std::string> > & rhs)
+{
+for (size_t i = 0; i < lhs.size() && i < rhs.size(); ++i)
+ STG::splice(lhs[i], rhs[i]);
+}
+
+std::optional<std::string> ConvString(const std::string & value)
+{
+return std::optional<std::string>(value);
+}
+
+void ConvStringList(std::string value, std::vector<std::optional<std::string> > & res)
+{
+Splice(res, Split<std::vector<std::optional<std::string> > >(value, ',', ConvString));
+}
+
+void ConvServices(std::string value, std::optional<std::vector<std::string> > & res)
+{
+value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
+res = Split<std::vector<std::string> >(value, ',');
+}
+
+void ConvCreditExpire(const std::string & value, std::optional<time_t> & res)
+{
+struct tm brokenTime;
+if (stg_strptime(value.c_str(), "%Y-%m-%d %H:%M:%S", &brokenTime) == NULL)
+ throw SGCONF::ACTION::ERROR("Credit expiration should be in format 'YYYY-MM-DD HH:MM:SS'. Got: '" + value + "'");
+res = stg_timegm(&brokenTime);
+}
+
+void ConvIPs(const std::string & value, std::optional<STG::UserIPs> & res)
+{
+res = STG::UserIPs::parse(value);
+}
+
+struct TRAFF
+{
+ uint64_t up;
+ uint64_t down;
+};
+
+TRAFF ConvTraff(const std::string & value)
+{
+TRAFF res;
+size_t slashPos = value.find_first_of('/');
+if (slashPos == std::string::npos)
+ throw SGCONF::ACTION::ERROR("Traffic record should be in format 'upload/download'. Got: '" + value + "'");
+
+if (str2x(value.substr(0, slashPos), res.up) < 0)
+ throw SGCONF::ACTION::ERROR("Traffic value should be an integer. Got: '" + value.substr(0, slashPos) + "'");
+if (str2x(value.substr(slashPos + 1, value.length() - slashPos), res.down) < 0)
+ throw SGCONF::ACTION::ERROR("Traffic value should be an integer. Got: '" + value.substr(slashPos + 1, value.length() - slashPos) + "'");
+return res;
+}
+
+void ConvSessionTraff(std::string value, STG::UserStatOpt & res)
+{
+value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
+std::vector<TRAFF> traff(Split<std::vector<TRAFF> >(value, ',', ConvTraff));
+if (traff.size() != DIR_NUM)
+ throw SGCONF::ACTION::ERROR("There should be prcisely " + std::to_string(DIR_NUM) + " records of session traffic.");
+for (size_t i = 0; i < DIR_NUM; ++i)
+ {
+ res.sessionUp[i] = traff[i].up;
+ res.sessionDown[i] = traff[i].down;
+ }
+}
+
+void ConvMonthTraff(std::string value, STG::UserStatOpt & res)
+{
+value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
+std::vector<TRAFF> traff(Split<std::vector<TRAFF> >(value, ',', ConvTraff));
+if (traff.size() != DIR_NUM)
+ throw SGCONF::ACTION::ERROR("There should be prcisely " + std::to_string(DIR_NUM) + " records of month traffic.");
+for (size_t i = 0; i < DIR_NUM; ++i)
+ {
+ res.monthUp[i] = traff[i].up;
+ res.monthDown[i] = traff[i].down;
+ }
+}
+
+void ConvCashInfo(const std::string & value, std::optional<STG::CashInfo> & res)
+{
+STG::CashInfo info;
+size_t pos = value.find_first_of(':');
+if (pos == std::string::npos)
+ {
+ if (str2x(value, info.first) < 0)
+ throw SGCONF::ACTION::ERROR("Cash should be a double value. Got: '" + value + "'");
+ }
+else
+ {
+ if (str2x(value.substr(0, pos), info.first) < 0)
+ throw SGCONF::ACTION::ERROR("Cash should be a double value. Got: '" + value + "'");
+ info.second = value.substr(pos + 1);
+ }
+res = info;
+}
+