{
std::vector<SGCONF::API_ACTION::PARAM> params;
params.push_back(SGCONF::API_ACTION::PARAM("password", "<password>", "\tuser's password"));
-params.push_back(SGCONF::API_ACTION::PARAM("cash", "<cash>", "\t\tuser's cash"));
+params.push_back(SGCONF::API_ACTION::PARAM("cash-add", "<cash[:message]>", "cash to add (with optional comment)"));
+params.push_back(SGCONF::API_ACTION::PARAM("cash-set", "<cash[:message]>", "cash to set (with optional comment)"));
params.push_back(SGCONF::API_ACTION::PARAM("credit", "<amount>", "\tuser's credit"));
params.push_back(SGCONF::API_ACTION::PARAM("credit-expire", "<date>", "\tcredit expiration"));
params.push_back(SGCONF::API_ACTION::PARAM("free", "<free mb>", "\tprepaid traffic"));
params.push_back(SGCONF::API_ACTION::PARAM("name", "<real name>", "\tuser's real name"));
params.push_back(SGCONF::API_ACTION::PARAM("address", "<address>", "\tuser's postal address"));
params.push_back(SGCONF::API_ACTION::PARAM("phone", "<phone>", "\t\tuser's phone number"));
-params.push_back(SGCONF::API_ACTION::PARAM("corp", "<corp name>", "\t\tcorporation name"));
+params.push_back(SGCONF::API_ACTION::PARAM("corp", "<corp name>", "\tcorporation name"));
params.push_back(SGCONF::API_ACTION::PARAM("session-traffic", "<up/dn, ...>", "coma-separated session upload and download"));
params.push_back(SGCONF::API_ACTION::PARAM("month-traffic", "<up/dn, ...>", "coma-separated month upload and download"));
params.push_back(SGCONF::API_ACTION::PARAM("user-data", "<value, ...>", "coma-separated user data values"));
Splice(res, Split<std::vector<RESETABLE<std::string> > >(value, ',', ConvString));
}
+void ConvServices(std::string value, RESETABLE<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, RESETABLE<time_t> & res)
{
struct tm brokenTime;
}
}
+void ConvCashInfo(const std::string & value, RESETABLE<CASH_INFO> & res)
+{
+CASH_INFO 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;
+}
+
void SimpleCallback(bool result,
const std::string & reason,
void * /*data*/)
SGCONF::MaybeSet(options, "note", conf.note);
SGCONF::MaybeSet(options, "name", conf.realName);
SGCONF::MaybeSet(options, "corp", conf.corp);
-SGCONF::MaybeSet(options, "services", conf.services, ConvStringList);
+SGCONF::MaybeSet(options, "services", conf.services, ConvServices);
SGCONF::MaybeSet(options, "group", conf.group);
SGCONF::MaybeSet(options, "next-tariff", conf.nextTariff);
SGCONF::MaybeSet(options, "user-data", conf.userdata, ConvStringList);
SGCONF::MaybeSet(options, "credit-expire", conf.creditExpire, ConvCreditExpire);
SGCONF::MaybeSet(options, "ips", conf.ips, ConvIPs);
USER_STAT_RES stat;
-SGCONF::MaybeSet(options, "cash", stat.cash);
+SGCONF::MaybeSet(options, "cash-set", stat.cashSet, ConvCashInfo);
SGCONF::MaybeSet(options, "free", stat.freeMb);
SGCONF::MaybeSet(options, "session-traffic", stat, ConvSessionTraff);
SGCONF::MaybeSet(options, "month-traffic", stat, ConvMonthTraff);
SGCONF::MaybeSet(options, "note", conf.note);
SGCONF::MaybeSet(options, "name", conf.realName);
SGCONF::MaybeSet(options, "corp", conf.corp);
-SGCONF::MaybeSet(options, "services", conf.services, ConvStringList);
+SGCONF::MaybeSet(options, "services", conf.services, ConvServices);
SGCONF::MaybeSet(options, "group", conf.group);
SGCONF::MaybeSet(options, "next-tariff", conf.nextTariff);
SGCONF::MaybeSet(options, "user-data", conf.userdata, ConvStringList);
SGCONF::MaybeSet(options, "credit-expire", conf.creditExpire, ConvCreditExpire);
SGCONF::MaybeSet(options, "ips", conf.ips, ConvIPs);
USER_STAT_RES stat;
-SGCONF::MaybeSet(options, "cash", stat.cash);
+SGCONF::MaybeSet(options, "cash-add", stat.cashAdd, ConvCashInfo);
+SGCONF::MaybeSet(options, "cash-set", stat.cashSet, ConvCashInfo);
SGCONF::MaybeSet(options, "free", stat.freeMb);
SGCONF::MaybeSet(options, "session-traffic", stat, ConvSessionTraff);
SGCONF::MaybeSet(options, "month-traffic", stat, ConvMonthTraff);
#include "stg/user_conf.h"
#include "stg/user_stat.h"
+#include "stg/common.h"
#include <sstream>
+#include <iostream>
#include <strings.h>
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;
+}
+
+}
+
CHG_USER::PARSER::PARSER(SIMPLE::CALLBACK f, void * d)
: callback(f),
data(d),
else if (!conf.tariffName.empty())
stream << "<tariff now=\"" << conf.nextTariff.data() << "\"/>";
-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", 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);
for (size_t i = 0; i < conf.userdata.size(); ++i)
- appendResetable(stream, "userdata", i, conf.userdata[i]);
+ appendResetable(stream, "userdata", i, MaybeEncode(conf.userdata[i]));
+
+if (!conf.services.empty())
+ {
+ stream << "<services>";
+ for (size_t i = 0; i < conf.services.data().size(); ++i)
+ stream << "<service name=\"" << conf.services.data()[i] << "\"/>";
+ stream << "</services>";
+ }
// Stat
if (!stat.cashAdd.empty())
- stream << "<cash add=\"" << stat.cashAdd.data().first << "\" msg=\"" << stat.cashAdd.data().second << "\"/>";
+ stream << "<cash add=\"" << stat.cashAdd.data().first << "\" msg=\"" << Encode12str(stat.cashAdd.data().second) << "\"/>";
else if (!stat.cashSet.empty())
- stream << "<cash set=\"" << stat.cashAdd.data().first << "\" msg=\"" << stat.cashAdd.data().second << "\"/>";
+ stream << "<cash set=\"" << stat.cashAdd.data().first << "\" msg=\"" << Encode12str(stat.cashAdd.data().second) << "\"/>";
appendResetable(stream, "freeMb", stat.freeMb);
if (!traffData.empty())
stream << "<traff" << traffData << "/>";
+std::cerr << stream.str() << "\n";
return stream.str();
}