return res;
}
+RESETABLE<std::string> MaybeIconv(const RESETABLE<std::string> & value, const std::string & fromEncoding, const std::string & toEncoding)
+{
+RESETABLE<std::string> res;
+if (!value.empty())
+ res = IconvString(value.data(), fromEncoding, toEncoding);
+return res;
+}
+
}
CHG_USER::PARSER::PARSER(SIMPLE::CALLBACK f, void * d)
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;
else if (!conf.tariffName.empty())
stream << "<tariff now=\"" << conf.tariffName.data() << "\"/>";
-appendResetable(stream, "note", MaybeEncode(conf.note));
-appendResetable(stream, "name", MaybeEncode(conf.realName)); // TODO: name -> realName
-appendResetable(stream, "address", MaybeEncode(conf.address));
-appendResetable(stream, "email", MaybeEncode(conf.email));
-appendResetable(stream, "phone", MaybeEncode(conf.phone));
-appendResetable(stream, "group", MaybeEncode(conf.group));
-appendResetable(stream, "corp", 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, MaybeEncode(conf.userdata[i]));
+ appendResetable(stream, "userdata", i, MaybeIconv(MaybeEncode(conf.userdata[i]), "koi8-ru", encoding));
if (!conf.services.empty())
{
// Stat
if (!stat.cashAdd.empty())
- stream << "<cash add=\"" << stat.cashAdd.data().first << "\" msg=\"" << Encode12str(stat.cashAdd.data().second) << "\"/>";
+ stream << "<cash add=\"" << stat.cashAdd.data().first << "\" msg=\"" << IconvString(Encode12str(stat.cashAdd.data().second), "koi8-ru", encoding) << "\"/>";
else if (!stat.cashSet.empty())
- stream << "<cash set=\"" << stat.cashSet.data().first << "\" msg=\"" << Encode12str(stat.cashSet.data().second) << "\"/>";
+ stream << "<cash set=\"" << stat.cashSet.data().first << "\" msg=\"" << IconvString(Encode12str(stat.cashSet.data().second), "koi8-ru", encoding) << "\"/>";
appendResetable(stream, "freeMb", stat.freeMb);
void ParseAnswer(const char * el, const char ** attr);
};
-std::string Serialize(const USER_CONF_RES & conf, const USER_STAT_RES & stat);
+std::string Serialize(const USER_CONF_RES & conf, const USER_STAT_RES & stat, const std::string & encoding);
} // namespace CHG_USER
} // namespace STG
using namespace STG;
-GET_CORP::PARSER::PARSER(CALLBACK f, void * d)
+GET_CORP::PARSER::PARSER(CALLBACK f, void * d, const std::string & e)
: callback(f),
data(d),
+ encoding(e),
depth(0),
parsingAnswer(false)
{
//-----------------------------------------------------------------------------
void GET_CORP::PARSER::ParseCorpParams(const char * el, const char ** attr)
{
-if (!TryParse(propertyParsers, ToLower(el), attr))
+if (!TryParse(propertyParsers, ToLower(el), attr, encoding))
error = "Invalid parameter.";
}
public:
typedef GET_CORP::INFO INFO;
- PARSER(CALLBACK f, void * data);
+ PARSER(CALLBACK f, void * data, const std::string & encoding);
virtual ~PARSER();
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
CALLBACK callback;
void * data;
INFO info;
+ std::string encoding;
int depth;
bool parsingAnswer;
std::string error;
using namespace STG;
-GET_SERVICE::PARSER::PARSER(CALLBACK f, void * d)
+GET_SERVICE::PARSER::PARSER(CALLBACK f, void * d, const std::string & e)
: callback(f),
data(d),
+ encoding(e),
depth(0),
parsingAnswer(false)
{
//-----------------------------------------------------------------------------
void GET_SERVICE::PARSER::ParseServiceParams(const char * el, const char ** attr)
{
-if (!TryParse(propertyParsers, ToLower(el), attr))
+if (!TryParse(propertyParsers, ToLower(el), attr, encoding))
error = "Invalid parameter.";
}
{
public:
typedef GET_SERVICE::INFO INFO;
- PARSER(CALLBACK f, void * data);
+ PARSER(CALLBACK f, void * data, const std::string & encoding);
virtual ~PARSER();
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
CALLBACK callback;
void * data;
INFO info;
+ std::string encoding;
int depth;
bool parsingAnswer;
std::string error;
public:
typedef bool (* FUNC)(const char **, A &, T A::value_type:: *);
AOS_PARSER(A & a, T A::value_type:: * fld, FUNC f) : array(a), field(fld), func(f) {}
- virtual bool Parse(const char ** attr, const std::string & /*attrName*/) { return func(attr, array, field); }
+ virtual bool Parse(const char ** attr, const std::string & /*attrName*/, const std::string & /*fromEncoding*/) { return func(attr, array, field); }
private:
A & array;
T A::value_type:: * field;
} // namespace anonymous
-GET_TARIFF::PARSER::PARSER(CALLBACK f, void * d)
+GET_TARIFF::PARSER::PARSER(CALLBACK f, void * d, const std::string & e)
: callback(f),
data(d),
+ encoding(e),
depth(0),
parsingAnswer(false)
{
//-----------------------------------------------------------------------------
void GET_TARIFF::PARSER::ParseTariffParams(const char * el, const char ** attr)
{
-if (!TryParse(propertyParsers, ToLower(el), attr))
+if (!TryParse(propertyParsers, ToLower(el), attr, encoding))
error = std::string("Invalid parameter '") + el + "'.";
}
public:
typedef GET_TARIFF::INFO INFO;
- PARSER(CALLBACK f, void * data);
+ PARSER(CALLBACK f, void * data, const std::string & encoding);
virtual ~PARSER();
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
PROPERTY_PARSERS propertyParsers;
CALLBACK callback;
void * data;
+ std::string encoding;
INFO info;
int depth;
bool parsingAnswer;
}
-GET_USER::PARSER::PARSER(CALLBACK f, void * d)
+GET_USER::PARSER::PARSER(CALLBACK f, void * d, const std::string & e)
: callback(f),
data(d),
+ encoding(e),
depth(0),
parsingAnswer(false)
{
AddParser(propertyParsers, "currIP", info.ip, GetIPValue);
AddParser(propertyParsers, "ip", info.ips);
AddParser(propertyParsers, "tariff", info.tariff);
- 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, "group", info.group, "koi8-ru", GetEncodedValue);
+ AddParser(propertyParsers, "note", info.note, "koi8-ru", GetEncodedValue);
+ AddParser(propertyParsers, "email", info.email, "koi8-ru", GetEncodedValue);
+ AddParser(propertyParsers, "name", info.name, "koi8-ru", GetEncodedValue);
+ AddParser(propertyParsers, "address", info.address, "koi8-ru", GetEncodedValue);
+ AddParser(propertyParsers, "phone", info.phone, "koi8-ru", GetEncodedValue);
AddParser(propertyParsers, "corp", info.corp);
AddParser(propertyParsers, "traff", info.stat);
AddParser(propertyParsers, "pingTime", info.pingTime);
AddParser(propertyParsers, "lastActivityTime", info.lastActivityTime);
for (size_t i = 0; i < USERDATA_NUM; ++i)
- AddParser(propertyParsers, "userData" + unsigned2str(i), info.userData[i], GetEncodedValue);
+ AddParser(propertyParsers, "userData" + unsigned2str(i), info.userData[i], "koi8-ru", GetEncodedValue);
}
//-----------------------------------------------------------------------------
GET_USER::PARSER::~PARSER()
void GET_USER::PARSER::ParseUserParams(const char * el, const char ** attr)
{
if (strcasecmp(el, "AuthorizedBy") != 0 &&
- !TryParse(propertyParsers, ToLower(el), attr))
+ !TryParse(propertyParsers, ToLower(el), attr, encoding))
error = "Invalid parameter.";
else if (strcasecmp(el, "Services") != 0 &&
- !TryParse(propertyParsers, ToLower(el), attr))
+ !TryParse(propertyParsers, ToLower(el), attr, encoding))
error = "Invalid parameter.";
}
//-----------------------------------------------------------------------------
public:
typedef GET_USER::INFO INFO;
- PARSER(CALLBACK f, void * data);
+ PARSER(CALLBACK f, void * data, const std::string & encoding);
virtual ~PARSER();
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
PROPERTY_PARSERS propertyParsers;
CALLBACK callback;
void * data;
+ std::string encoding;
INFO info;
int depth;
bool parsingAnswer;
}
-SERVER_INFO::PARSER::PARSER(CALLBACK f, void * d)
+SERVER_INFO::PARSER::PARSER(CALLBACK f, void * d, const std::string & e)
: callback(f),
data(d),
+ encoding(e),
depth(0),
parsingAnswer(false)
{
else
{
if (depth == 2 && parsingAnswer)
- if (!TryParse(propertyParsers, ToLower(el), attr))
+ if (!TryParse(propertyParsers, ToLower(el), attr, encoding))
error = "Invalid parameter.";
}
return 0;
class PARSER: public STG::PARSER
{
public:
- PARSER(CALLBACK f, void * data);
+ PARSER(CALLBACK f, void * data, const std::string & encoding);
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
void Failure(const std::string & reason) { callback(false, reason, info, data); }
PROPERTY_PARSERS propertyParsers;
CALLBACK callback;
void * data;
+ std::string encoding;
int depth;
bool parsingAnswer;
INFO info;