- case TARIFF::ALLOW: return "allow";
- case TARIFF::TO_CHEAP: return "to_cheap";
- case TARIFF::TO_EXPENSIVE: return "to_expensive";
- case TARIFF::DENY: return "deny";
+ case STG::Tariff::ALLOW: return "allow";
+ case STG::Tariff::TO_CHEAP: return "to_cheap";
+ case STG::Tariff::TO_EXPENSIVE: return "to_expensive";
+ case STG::Tariff::DENY: return "deny";
else
throw SGCONF::ACTION::ERROR("Change policy should be 'allow', 'to_cheap', 'to_expensive' or 'deny'. Got: '" + value + "'");
}
else
throw SGCONF::ACTION::ERROR("Change policy should be 'allow', 'to_cheap', 'to_expensive' or 'deny'. Got: '" + value + "'");
}
-void ConvTraffType(const std::string & value, RESETABLE<TARIFF::TRAFF_TYPE> & res)
+void ConvChangePolicyTimeout(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 ConvTraffType(const std::string & value, std::optional<STG::Tariff::TraffType> & res)
{
std::string lowered = ToLower(value);
lowered.erase(std::remove(lowered.begin(), lowered.end(), ' '), lowered.end());
if (lowered == "upload")
{
std::string lowered = ToLower(value);
lowered.erase(std::remove(lowered.begin(), lowered.end(), ' '), lowered.end());
if (lowered == "upload")
else
throw SGCONF::ACTION::ERROR("Traff type should be 'upload', 'download', 'upload + download' or 'max'. Got: '" + value + "'");
}
else
throw SGCONF::ACTION::ERROR("Traff type should be 'upload', 'download', 'upload + download' or 'max'. Got: '" + value + "'");
}
size_t toColon = value.find_first_of(':', dashPos);
if (toColon == std::string::npos)
throw SGCONF::ACTION::ERROR("Time span should be in format 'hh:mm-hh:mm'. Got: '" + value + "'");
size_t toColon = value.find_first_of(':', dashPos);
if (toColon == std::string::npos)
throw SGCONF::ACTION::ERROR("Time span should be in format 'hh:mm-hh:mm'. Got: '" + value + "'");
throw SGCONF::ACTION::ERROR("Invalid 'from' hours. Got: '" + value.substr(0, fromColon) + "'");
res.mDay = FromString<int>(value.substr(fromColon + 1, dashPos - fromColon - 1));
throw SGCONF::ACTION::ERROR("Invalid 'from' hours. Got: '" + value.substr(0, fromColon) + "'");
res.mDay = FromString<int>(value.substr(fromColon + 1, dashPos - fromColon - 1));
throw SGCONF::ACTION::ERROR("Invalid 'from' minutes. Got: '" + value.substr(fromColon + 1, dashPos - fromColon - 1) + "'");
res.hNight = FromString<int>(value.substr(dashPos + 1, toColon - dashPos - 1));
throw SGCONF::ACTION::ERROR("Invalid 'from' minutes. Got: '" + value.substr(fromColon + 1, dashPos - fromColon - 1) + "'");
res.hNight = FromString<int>(value.substr(dashPos + 1, toColon - dashPos - 1));
throw SGCONF::ACTION::ERROR("Invalid 'to' hours. Got: '" + value.substr(dashPos + 1, toColon - dashPos - 1) + "'");
res.mNight = FromString<int>(value.substr(toColon + 1, value.length() - toColon));
throw SGCONF::ACTION::ERROR("Invalid 'to' hours. Got: '" + value.substr(dashPos + 1, toColon - dashPos - 1) + "'");
res.mNight = FromString<int>(value.substr(toColon + 1, value.length() - toColon));
{
value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
{
value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
-Splice(res, Split<std::vector<DIRPRICE_DATA_RES> >(value, ',', ConvTimeSpan));
+splice(res, Split<std::vector<STG::DirPriceDataOpt> >(value, ',', ConvTimeSpan));
ConvPrice(MemPtr before, MemPtr after)
: m_before(before), m_after(after)
{}
ConvPrice(MemPtr before, MemPtr after)
: m_before(before), m_after(after)
{}
- DIRPRICE_DATA_RES res;
- size_t slashPos = value.find_first_of('/');
- if (slashPos == std::string::npos)
+ STG::DirPriceDataOpt res;
+ size_t slashPos = value.find_first_of('/');
+ if (slashPos == std::string::npos)
- double price = 0;
- if (str2x(value, price) < 0)
- throw SGCONF::ACTION::ERROR("Price should be a floating point number. Got: '" + value + "'");
- (res.*m_before) = (res.*m_after) = price;
- res.noDiscount = true;
+ double price = 0;
+ if (str2x(value, price) < 0)
+ throw SGCONF::ACTION::ERROR("Price should be a floating point number. Got: '" + value + "'");
+ (res.*m_before) = (res.*m_after) = price;
+ res.noDiscount = true;
- double price = 0;
- if (str2x(value.substr(0, slashPos), price) < 0)
- throw SGCONF::ACTION::ERROR("Price should be a floating point number. Got: '" + value.substr(0, slashPos) + "'");
- (res.*m_before) = price;
- if (str2x(value.substr(slashPos + 1, value.length() - slashPos), price) < 0)
- throw SGCONF::ACTION::ERROR("Price should be a floating point number. Got: '" + value.substr(slashPos + 1, value.length() - slashPos) + "'");
- (res.*m_after) = price;
- res.noDiscount = false;
+ double price = 0;
+ if (str2x(value.substr(0, slashPos), price) < 0)
+ throw SGCONF::ACTION::ERROR("Price should be a floating point number. Got: '" + value.substr(0, slashPos) + "'");
+ (res.*m_before) = price;
+ if (str2x(value.substr(slashPos + 1, value.length() - slashPos), price) < 0)
+ throw SGCONF::ACTION::ERROR("Price should be a floating point number. Got: '" + value.substr(slashPos + 1, value.length() - slashPos) + "'");
+ (res.*m_after) = price;
+ res.noDiscount = false;
{
value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
{
value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
-Splice(res, Split<std::vector<DIRPRICE_DATA_RES> >(value, ',', ConvPrice(&DIRPRICE_DATA_RES::priceDayA, &DIRPRICE_DATA_RES::priceDayB)));
+splice(res, Split<std::vector<STG::DirPriceDataOpt> >(value, ',', ConvPrice(&STG::DirPriceDataOpt::priceDayA, &STG::DirPriceDataOpt::priceDayB)));
{
value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
{
value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
-Splice(res, Split<std::vector<DIRPRICE_DATA_RES> >(value, ',', ConvPrice(&DIRPRICE_DATA_RES::priceNightA, &DIRPRICE_DATA_RES::priceNightB)));
+splice(res, Split<std::vector<STG::DirPriceDataOpt> >(value, ',', ConvPrice(&STG::DirPriceDataOpt::priceNightA, &STG::DirPriceDataOpt::priceNightB)));
double threshold = 0;
if (str2x(value, threshold) < 0)
throw SGCONF::ACTION::ERROR("Threshold should be a floating point value. Got: '" + value + "'");
double threshold = 0;
if (str2x(value, threshold) < 0)
throw SGCONF::ACTION::ERROR("Threshold should be a floating point value. Got: '" + value + "'");
{
value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
{
value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
-Splice(res, Split<std::vector<DIRPRICE_DATA_RES> >(value, ',', ConvThreshold));
+splice(res, Split<std::vector<STG::DirPriceDataOpt> >(value, ',', ConvThreshold));
{
std::string night = TimeToString(data.hNight, data.mNight);
std::string day = TimeToString(data.hDay, data.mDay);
{
std::string night = TimeToString(data.hNight, data.mNight);
std::string day = TimeToString(data.hDay, data.mDay);
{
std::cout << Indent(level, true) << "name: " << conf.name << "\n"
<< Indent(level) << "fee: " << conf.fee << "\n"
{
std::cout << Indent(level, true) << "name: " << conf.name << "\n"
<< Indent(level) << "fee: " << conf.fee << "\n"
{
PrintTariffConf(info.tariffConf, level);
std::cout << Indent(level) << "dir prices:\n";
{
PrintTariffConf(info.tariffConf, level);
std::cout << Indent(level) << "dir prices:\n";
void GetTariffsCallback(bool result,
const std::string & reason,
void GetTariffsCallback(bool result,
const std::string & reason,
void GetTariffCallback(bool result,
const std::string & reason,
void GetTariffCallback(bool result,
const std::string & reason,
const std::string & /*arg*/,
const std::map<std::string, std::string> & /*options*/)
{
const std::string & /*arg*/,
const std::map<std::string, std::string> & /*options*/)
{
-STG::SERVCONF proto(config.server.data(),
- config.port.data(),
- config.localAddress.data(),
- config.localPort.data(),
- config.userName.data(),
- config.userPass.data());
-return proto.GetTariffs(GetTariffsCallback, NULL) == STG::st_ok;
+return makeProto(config).GetTariffs(GetTariffsCallback, NULL) == STG::st_ok;
}
bool GetTariffFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & /*options*/)
{
}
bool GetTariffFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & /*options*/)
{
-STG::SERVCONF proto(config.server.data(),
- config.port.data(),
- config.localAddress.data(),
- config.localPort.data(),
- config.userName.data(),
- config.userPass.data());
// STG currently doesn't support <GetTariff name="..."/>.
// So get a list of tariffs and filter it. 'data' param holds a pointer to 'name'.
std::string name(arg);
// STG currently doesn't support <GetTariff name="..."/>.
// So get a list of tariffs and filter it. 'data' param holds a pointer to 'name'.
std::string name(arg);
}
bool DelTariffFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & /*options*/)
{
}
bool DelTariffFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & /*options*/)
{
-STG::SERVCONF proto(config.server.data(),
- config.port.data(),
- config.localAddress.data(),
- config.localPort.data(),
- config.userName.data(),
- config.userPass.data());
-return proto.DelTariff(arg, SimpleCallback, NULL) == STG::st_ok;
+return makeProto(config).DelTariff(arg, SimpleCallback, NULL) == STG::st_ok;
}
bool AddTariffFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & options)
{
}
bool AddTariffFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & options)
{
conf.tariffConf.name = arg;
SGCONF::MaybeSet(options, "fee", conf.tariffConf.fee);
SGCONF::MaybeSet(options, "free", conf.tariffConf.free);
conf.tariffConf.name = arg;
SGCONF::MaybeSet(options, "fee", conf.tariffConf.fee);
SGCONF::MaybeSet(options, "free", conf.tariffConf.free);
SGCONF::MaybeSet(options, "traff-type", conf.tariffConf.traffType, ConvTraffType);
SGCONF::MaybeSet(options, "period", conf.tariffConf.period, ConvPeriod);
SGCONF::MaybeSet(options, "change-policy", conf.tariffConf.changePolicy, ConvChangePolicy);
SGCONF::MaybeSet(options, "traff-type", conf.tariffConf.traffType, ConvTraffType);
SGCONF::MaybeSet(options, "period", conf.tariffConf.period, ConvPeriod);
SGCONF::MaybeSet(options, "change-policy", conf.tariffConf.changePolicy, ConvChangePolicy);
SGCONF::MaybeSet(options, "times", conf.dirPrice, ConvTimes);
SGCONF::MaybeSet(options, "day-prices", conf.dirPrice, ConvDayPrices);
SGCONF::MaybeSet(options, "night-prices", conf.dirPrice, ConvNightPrices);
SGCONF::MaybeSet(options, "thresholds", conf.dirPrice, ConvThresholds);
for (size_t i = 0; i < conf.dirPrice.size(); ++i)
{
SGCONF::MaybeSet(options, "times", conf.dirPrice, ConvTimes);
SGCONF::MaybeSet(options, "day-prices", conf.dirPrice, ConvDayPrices);
SGCONF::MaybeSet(options, "night-prices", conf.dirPrice, ConvNightPrices);
SGCONF::MaybeSet(options, "thresholds", conf.dirPrice, ConvThresholds);
for (size_t i = 0; i < conf.dirPrice.size(); ++i)
{
- if (!conf.dirPrice[i].priceDayA.empty() &&
- !conf.dirPrice[i].priceNightA.empty() &&
- !conf.dirPrice[i].priceDayB.empty() &&
- !conf.dirPrice[i].priceNightB.empty())
- conf.dirPrice[i].singlePrice = conf.dirPrice[i].priceDayA.data() == conf.dirPrice[i].priceNightA.data() &&
- conf.dirPrice[i].priceDayB.data() == conf.dirPrice[i].priceNightB.data();
+ if (conf.dirPrice[i].priceDayA ||
+ conf.dirPrice[i].priceNightA ||
+ conf.dirPrice[i].priceDayB ||
+ conf.dirPrice[i].priceNightB)
+ conf.dirPrice[i].singlePrice = conf.dirPrice[i].priceDayA.value() == conf.dirPrice[i].priceNightA.value() &&
+ conf.dirPrice[i].priceDayB.value() == conf.dirPrice[i].priceNightB.value();
-STG::SERVCONF proto(config.server.data(),
- config.port.data(),
- config.localAddress.data(),
- config.localPort.data(),
- config.userName.data(),
- config.userPass.data());
-return proto.AddTariff(arg, conf, SimpleCallback, NULL) == STG::st_ok;
+return makeProto(config).AddTariff(arg, conf, SimpleCallback, NULL) == STG::st_ok;
}
bool ChgTariffFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & options)
{
}
bool ChgTariffFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & options)
{
conf.tariffConf.name = arg;
SGCONF::MaybeSet(options, "fee", conf.tariffConf.fee);
SGCONF::MaybeSet(options, "free", conf.tariffConf.free);
conf.tariffConf.name = arg;
SGCONF::MaybeSet(options, "fee", conf.tariffConf.fee);
SGCONF::MaybeSet(options, "free", conf.tariffConf.free);
SGCONF::MaybeSet(options, "traff-type", conf.tariffConf.traffType, ConvTraffType);
SGCONF::MaybeSet(options, "period", conf.tariffConf.period, ConvPeriod);
SGCONF::MaybeSet(options, "change-policy", conf.tariffConf.changePolicy, ConvChangePolicy);
SGCONF::MaybeSet(options, "traff-type", conf.tariffConf.traffType, ConvTraffType);
SGCONF::MaybeSet(options, "period", conf.tariffConf.period, ConvPeriod);
SGCONF::MaybeSet(options, "change-policy", conf.tariffConf.changePolicy, ConvChangePolicy);
SGCONF::MaybeSet(options, "times", conf.dirPrice, ConvTimes);
SGCONF::MaybeSet(options, "day-prices", conf.dirPrice, ConvDayPrices);
SGCONF::MaybeSet(options, "night-prices", conf.dirPrice, ConvNightPrices);
SGCONF::MaybeSet(options, "thresholds", conf.dirPrice, ConvThresholds);
for (size_t i = 0; i < conf.dirPrice.size(); ++i)
{
SGCONF::MaybeSet(options, "times", conf.dirPrice, ConvTimes);
SGCONF::MaybeSet(options, "day-prices", conf.dirPrice, ConvDayPrices);
SGCONF::MaybeSet(options, "night-prices", conf.dirPrice, ConvNightPrices);
SGCONF::MaybeSet(options, "thresholds", conf.dirPrice, ConvThresholds);
for (size_t i = 0; i < conf.dirPrice.size(); ++i)
{
- if (!conf.dirPrice[i].priceDayA.empty() &&
- !conf.dirPrice[i].priceNightA.empty() &&
- !conf.dirPrice[i].priceDayB.empty() &&
- !conf.dirPrice[i].priceNightB.empty())
- conf.dirPrice[i].singlePrice = conf.dirPrice[i].priceDayA.data() == conf.dirPrice[i].priceNightA.data() &&
- conf.dirPrice[i].priceDayB.data() == conf.dirPrice[i].priceNightB.data();
+ if (conf.dirPrice[i].priceDayA ||
+ conf.dirPrice[i].priceNightA ||
+ conf.dirPrice[i].priceDayB ||
+ conf.dirPrice[i].priceNightB)
+ conf.dirPrice[i].singlePrice = conf.dirPrice[i].priceDayA.value() == conf.dirPrice[i].priceNightA.value() &&
+ conf.dirPrice[i].priceDayB.value() == conf.dirPrice[i].priceNightB.value();
-STG::SERVCONF proto(config.server.data(),
- config.port.data(),
- config.localAddress.data(),
- config.localPort.data(),
- config.userName.data(),
- config.userPass.data());
-return proto.ChgTariff(conf, SimpleCallback, NULL) == STG::st_ok;
+return makeProto(config).ChgTariff(conf, SimpleCallback, NULL) == STG::st_ok;