using namespace STG;
-AUTH_BY::PARSER::PARSER(CALLBACK f, void * d)
+AUTH_BY::PARSER::PARSER(CALLBACK f, void * d, const std::string & e)
: callback(f),
data(d),
+ encoding(e),
depth(0),
parsingAnswer(false)
{
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); }
private:
CALLBACK callback;
void * data;
+ std::string encoding;
int depth;
bool parsingAnswer;
INFO info;
using namespace STG;
-std::string CHG_ADMIN::Serialize(const ADMIN_CONF_RES & conf)
+std::string CHG_ADMIN::Serialize(const ADMIN_CONF_RES & conf, const std::string & /*encoding*/)
{
std::string params;
if (!conf.login.empty())
namespace CHG_ADMIN
{
-std::string Serialize(const ADMIN_CONF_RES & conf);
+std::string Serialize(const ADMIN_CONF_RES & conf, const std::string & encoding);
} // namespace CHG_ADMIN
} // namespace STG
using namespace STG;
-std::string CHG_CORP::Serialize(const CORP_CONF_RES & conf)
+std::string CHG_CORP::Serialize(const CORP_CONF_RES & conf, const std::string & /*encoding*/)
{
std::ostringstream stream;
namespace CHG_CORP
{
-std::string Serialize(const CORP_CONF_RES & conf);
+std::string Serialize(const CORP_CONF_RES & conf, const std::string & encoding);
} // namespace CHG_CORP
} // namespace STG
using namespace STG;
-std::string CHG_SERVICE::Serialize(const SERVICE_CONF_RES & conf)
+std::string CHG_SERVICE::Serialize(const SERVICE_CONF_RES & conf, const std::string & encoding)
{
std::ostringstream stream;
appendResetable(stream, "name", conf.name);
-appendResetable(stream, "comment", conf.comment);
+appendResetable(stream, "comment", MaybeIconv(conf.comment, "koi8-ru", encoding));
appendResetable(stream, "cost", conf.cost);
appendResetable(stream, "payDay", conf.payDay);
namespace CHG_SERVICE
{
-std::string Serialize(const SERVICE_CONF_RES & conf);
+std::string Serialize(const SERVICE_CONF_RES & conf, const std::string & encoding);
} // namespace CHG_SERVICE
} // namespace STG
} // namespace anonymous
-std::string CHG_TARIFF::Serialize(const TARIFF_DATA_RES & data)
+std::string CHG_TARIFF::Serialize(const TARIFF_DATA_RES & data, const std::string & /*encoding*/)
{
std::ostringstream stream;
namespace CHG_TARIFF
{
-std::string Serialize(const TARIFF_DATA_RES & data);
+std::string Serialize(const TARIFF_DATA_RES & data, const std::string & encoding);
} // namespace CHG_TARIFF
} // namespace STG
using namespace STG;
-namespace
-{
-
-RESETABLE<std::string> MaybeEncode(const RESETABLE<std::string> & value)
-{
-RESETABLE<std::string> res;
-if (!value.empty())
- res = Encode12str(value.data());
-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)
+CHG_USER::PARSER::PARSER(SIMPLE::CALLBACK f, void * d, const std::string & e)
: callback(f),
data(d),
+ encoding(e),
depth(0)
{
}
class PARSER: public STG::PARSER
{
public:
- PARSER(SIMPLE::CALLBACK f, void * data);
+ PARSER(SIMPLE::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, data); }
private:
SIMPLE::CALLBACK callback;
void * data;
+ std::string encoding;
int depth;
void ParseAnswer(const char * el, const char ** attr);
} // namespace STG
-GET_ADMIN::PARSER::PARSER(CALLBACK f, void * d)
+GET_ADMIN::PARSER::PARSER(CALLBACK f, void * d, const std::string & e)
: callback(f),
data(d),
+ encoding(e),
depth(0),
parsingAnswer(false)
{
public:
typedef GET_ADMIN::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;
public:
typedef std::vector<typename ELEMENT_PARSER::INFO> INFO;
typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
- PARSER(const std::string & t, CALLBACK f, void * d)
- : tag(t), callback(f), data(d),
- elementParser(&PARSER<ELEMENT_PARSER>::ElementCallback, this),
+ PARSER(const std::string & t, CALLBACK f, void * d, const std::string & e)
+ : tag(t), callback(f), data(d), encoding(e),
+ elementParser(&PARSER<ELEMENT_PARSER>::ElementCallback, this, e),
depth(0), parsingAnswer(false)
{}
int ParseStart(const char * el, const char ** attr)
std::string tag;
CALLBACK callback;
void * data;
+ std::string encoding;
ELEMENT_PARSER elementParser;
INFO info;
int depth;
parsingAnswer(false)
{
AddParser(propertyParsers, "name", info.name);
- AddParser(propertyParsers, "comment", info.comment);
+ AddParser(propertyParsers, "comment", info.comment, "koi8-ru", GetEncodedValue);
AddParser(propertyParsers, "cost", info.cost);
AddParser(propertyParsers, "payDay", info.payDay);
}
#define __STG_STGLIBS_SRVCONF_RESETABLE_UTILS_H__
#include "stg/resetable.h"
+#include "stg/common.h"
#include <string>
#include <ostream>
{
template <typename T>
+inline
void appendResetable(std::ostream & stream, const std::string & name, const T & value)
{
if (!value.empty())
}
template <typename T>
+inline
void appendResetable(std::ostream & stream, const std::string & name, size_t suffix, const T & value)
{
if (!value.empty())
stream << "<" << name << suffix << " value=\"" << value.data() << "\"/>";
}
+inline
+RESETABLE<std::string> MaybeEncode(const RESETABLE<std::string> & value)
+{
+RESETABLE<std::string> res;
+if (!value.empty())
+ res = Encode12str(value.data());
+return res;
+}
+
+inline
+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;
+}
+
} // namespace STG
#endif
using namespace STG;
-SIMPLE::PARSER::PARSER(const std::string & t, CALLBACK f, void * d)
+SIMPLE::PARSER::PARSER(const std::string & t, CALLBACK f, void * d, const std::string & e)
: tag(t),
callback(f),
data(d),
+ encoding(e),
depth(0)
{
}
class PARSER: public STG::PARSER
{
public:
- PARSER(const std::string & tag, CALLBACK f, void * data);
+ PARSER(const std::string & tag, 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, data); }
std::string tag;
CALLBACK callback;
void * data;
+ std::string encoding;
int depth;
void ParseAnswer(const char * el, const char ** attr);
#include <cstdio>
#include <cstring>
+#include <clocale>
#include <expat.h>
+#include <langinfo.h>
using namespace STG;
return ExecImpl(request, cp);
}
+ const std::string & Encoding() const { return encoding; }
+
private:
NETTRANSACT nt;
int SERVCONF::ChgAdmin(const ADMIN_CONF_RES & conf, SIMPLE::CALLBACK f, void * data)
{
-return pImpl->Exec<SIMPLE::PARSER>("ChgAdmin", "<ChgAdmin" + CHG_ADMIN::Serialize(conf, encoding) + "/>", f, data);
+return pImpl->Exec<SIMPLE::PARSER>("ChgAdmin", "<ChgAdmin" + CHG_ADMIN::Serialize(conf, pImpl->Encoding()) + "/>", f, data);
}
int SERVCONF::AddAdmin(const std::string & login,
int res = pImpl->Exec<SIMPLE::PARSER>("AddAdmin", "<AddAdmin login=\"" + login + "\"/>", f, data);
if (res != st_ok)
return res;
-return pImpl->Exec<SIMPLE::PARSER>("ChgAdmin", "<ChgAdmin" + CHG_ADMIN::Serialize(conf, encoding) + "/>", f, data);
+return pImpl->Exec<SIMPLE::PARSER>("ChgAdmin", "<ChgAdmin" + CHG_ADMIN::Serialize(conf, pImpl->Encoding()) + "/>", f, data);
}
int SERVCONF::DelAdmin(const std::string & login, SIMPLE::CALLBACK f, void * data)
int SERVCONF::ChgTariff(const TARIFF_DATA_RES & tariffData, SIMPLE::CALLBACK f, void * data)
{
-return pImpl->Exec<SIMPLE::PARSER>("SetTariff", "<SetTariff name=\"" + tariffData.tariffConf.name.data() + "\">" + CHG_TARIFF::Serialize(tariffData, encoding) + "</SetTariff>", f, data);
+return pImpl->Exec<SIMPLE::PARSER>("SetTariff", "<SetTariff name=\"" + tariffData.tariffConf.name.data() + "\">" + CHG_TARIFF::Serialize(tariffData, pImpl->Encoding()) + "</SetTariff>", f, data);
}
int SERVCONF::AddTariff(const std::string & name,
int res = pImpl->Exec<SIMPLE::PARSER>("AddTariff", "<AddTariff name=\"" + name + "\"/>", f, data);
if (res != st_ok)
return res;
-return pImpl->Exec<SIMPLE::PARSER>("SetTariff", "<SetTariff name=\"" + name + "\">" + CHG_TARIFF::Serialize(tariffData, encoding) + "</SetTariff>", f, data);
+return pImpl->Exec<SIMPLE::PARSER>("SetTariff", "<SetTariff name=\"" + name + "\">" + CHG_TARIFF::Serialize(tariffData, pImpl->Encoding()) + "</SetTariff>", f, data);
}
int SERVCONF::DelTariff(const std::string & name, SIMPLE::CALLBACK f, void * data)
const USER_STAT_RES & stat,
SIMPLE::CALLBACK f, void * data)
{
-return pImpl->Exec<CHG_USER::PARSER>("<SetUser><Login value=\"" + login + "\"/>" + CHG_USER::Serialize(conf, stat, encoding) + "</SetUser>", f, data);
+return pImpl->Exec<CHG_USER::PARSER>("<SetUser><Login value=\"" + login + "\"/>" + CHG_USER::Serialize(conf, stat, pImpl->Encoding()) + "</SetUser>", f, data);
}
int SERVCONF::DelUser(const std::string & login, SIMPLE::CALLBACK f, void * data)
int res = pImpl->Exec<SIMPLE::PARSER>("AddUser", "<AddUser><Login value=\"" + login + "\"/></AddUser>", f, data);
if (res != st_ok)
return res;
-return pImpl->Exec<CHG_USER::PARSER>("<SetUser><Login value=\"" + login + "\"/>" + CHG_USER::Serialize(conf, stat, encoding) + "</SetUser>", f, data);
+return pImpl->Exec<CHG_USER::PARSER>("<SetUser><Login value=\"" + login + "\"/>" + CHG_USER::Serialize(conf, stat, pImpl->Encoding()) + "</SetUser>", f, data);
}
int SERVCONF::AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data)
int SERVCONF::ChgService(const SERVICE_CONF_RES & conf, SIMPLE::CALLBACK f, void * data)
{
-return pImpl->Exec<SIMPLE::PARSER>("SetService", "<SetService name=\"" + conf.name.data() + "\">" + CHG_SERVICE::Serialize(conf, encoding) + "</SetService>", f, data);
+return pImpl->Exec<SIMPLE::PARSER>("SetService", "<SetService name=\"" + conf.name.data() + "\">" + CHG_SERVICE::Serialize(conf, pImpl->Encoding()) + "</SetService>", f, data);
}
int SERVCONF::AddService(const std::string & name,
int res = pImpl->Exec<SIMPLE::PARSER>("AddService", "<AddService name=\"" + name + "\"/>", f, data);
if (res != st_ok)
return res;
-return pImpl->Exec<SIMPLE::PARSER>("SetService", "<SetService name=\"" + name + "\">" + CHG_SERVICE::Serialize(conf, encoding) + "</SetService>", f, data);
+return pImpl->Exec<SIMPLE::PARSER>("SetService", "<SetService name=\"" + name + "\">" + CHG_SERVICE::Serialize(conf, pImpl->Encoding()) + "</SetService>", f, data);
}
int SERVCONF::DelService(const std::string & name, SIMPLE::CALLBACK f, void * data)
int SERVCONF::ChgCorp(const CORP_CONF_RES & conf, SIMPLE::CALLBACK f, void * data)
{
-return pImpl->Exec<SIMPLE::PARSER>("SetCorp", "<SetCorp name=\"" + conf.name.data() + "\">" + CHG_CORP::Serialize(conf, encoding) + "</SetCorp>", f, data);
+return pImpl->Exec<SIMPLE::PARSER>("SetCorp", "<SetCorp name=\"" + conf.name.data() + "\">" + CHG_CORP::Serialize(conf, pImpl->Encoding()) + "</SetCorp>", f, data);
}
int SERVCONF::AddCorp(const std::string & name,
int res = pImpl->Exec<SIMPLE::PARSER>("AddCorp", "<AddCorp name=\"" + name + "\"/>", f, data);
if (res != st_ok)
return res;
-return pImpl->Exec<SIMPLE::PARSER>("SetCorp", "<SetCorp name=\"" + name + "\">" + CHG_CORP::Serialize(conf, encoding) + "</SetCorp>", f, data);
+return pImpl->Exec<SIMPLE::PARSER>("SetCorp", "<SetCorp name=\"" + name + "\">" + CHG_CORP::Serialize(conf, pImpl->Encoding()) + "</SetCorp>", f, data);
}
int SERVCONF::DelCorp(const std::string & name, SIMPLE::CALLBACK f, void * data)