X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/1b2ab8e6d556a8ed30d4feadc72263b3f4c86665..908dee0db9288bb455e9f1b68dd81ab50897a677:/stglibs/srvconf.lib/parsers/chg_user.cpp diff --git a/stglibs/srvconf.lib/parsers/chg_user.cpp b/stglibs/srvconf.lib/parsers/chg_user.cpp index ed2002bc..3f7effd9 100644 --- a/stglibs/srvconf.lib/parsers/chg_user.cpp +++ b/stglibs/srvconf.lib/parsers/chg_user.cpp @@ -25,13 +25,36 @@ #include "stg/user_conf.h" #include "stg/user_stat.h" +#include "stg/common.h" #include +#include #include using namespace STG; +namespace +{ + +RESETABLE MaybeEncode(const RESETABLE & value) +{ +RESETABLE res; +if (!value.empty()) + res = Encode12str(value.data()); +return res; +} + +RESETABLE MaybeIconv(const RESETABLE & value, const std::string & fromEncoding, const std::string & toEncoding) +{ +RESETABLE res; +if (!value.empty()) + res = IconvString(value.data(), fromEncoding, toEncoding); +return res; +} + +} + CHG_USER::PARSER::PARSER(SIMPLE::CALLBACK f, void * d) : callback(f), data(d), @@ -69,7 +92,7 @@ else callback(false, "Invalid response.", data); } -std::string CHG_USER::Serialize(const USER_CONF_RES & conf, const USER_STAT_RES & stat) +std::string CHG_USER::Serialize(const USER_CONF_RES & conf, const USER_STAT_RES & stat, const std::string & encoding) { std::ostringstream stream; @@ -87,24 +110,33 @@ appendResetable(stream, "ip", conf.ips); // TODO: ip -> ips if (!conf.nextTariff.empty()) stream << ""; else if (!conf.tariffName.empty()) - stream << ""; + stream << ""; -appendResetable(stream, "note", conf.note); -appendResetable(stream, "name", conf.realName); // TODO: name -> realName -appendResetable(stream, "address", conf.address); -appendResetable(stream, "email", conf.email); -appendResetable(stream, "phone", conf.phone); -appendResetable(stream, "group", conf.group); +appendResetable(stream, "note", MaybeIconv(MaybeEncode(conf.note), "koi8-ru", encoding)); +appendResetable(stream, "name", MaybeIconv(MaybeEncode(conf.realName), "koi8-ru", encoding)); // TODO: name -> realName +appendResetable(stream, "address", MaybeIconv(MaybeEncode(conf.address), "koi8-ru", encoding)); +appendResetable(stream, "email", MaybeIconv(MaybeEncode(conf.email), "koi8-ru", encoding)); +appendResetable(stream, "phone", MaybeIconv(MaybeEncode(conf.phone), "koi8-ru", encoding)); +appendResetable(stream, "group", MaybeIconv(MaybeEncode(conf.group), "koi8-ru", encoding)); +appendResetable(stream, "corp", conf.corp); for (size_t i = 0; i < conf.userdata.size(); ++i) - appendResetable(stream, "userdata", i, conf.userdata[i]); + appendResetable(stream, "userdata", i, MaybeIconv(MaybeEncode(conf.userdata[i]), "koi8-ru", encoding)); + +if (!conf.services.empty()) + { + stream << ""; + for (size_t i = 0; i < conf.services.data().size(); ++i) + stream << ""; + stream << ""; + } // Stat if (!stat.cashAdd.empty()) - stream << ""; + stream << ""; else if (!stat.cashSet.empty()) - stream << ""; + stream << ""; appendResetable(stream, "freeMb", stat.freeMb); @@ -126,5 +158,6 @@ std::string traffData = traff.str(); if (!traffData.empty()) stream << ""; +std::cerr << stream.str() << "\n"; return stream.str(); }