From 9177beb0b910b03cecfa4ec5f98747cbb3d4280c Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Aug 2013 18:57:29 +0300 Subject: [PATCH 1/1] Made getters work. --- projects/sgconf/common_sg.cpp | 28 ++++++++--------- stglibs/srvconf.lib/netunit.cpp | 3 ++ stglibs/srvconf.lib/parser_get_user.cpp | 40 ++++++++++++------------- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index c0a4fd25..2901832a 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -317,10 +317,10 @@ if (info.login == "") } if (!data->request.cash.res_empty()) - cout << "cash=" << info.cash << endl; + cout << "cash = " << info.cash << endl; if (!data->request.credit.res_empty()) - cout << "credit=" << info.credit << endl; + cout << "credit = " << info.credit << endl; if (!data->request.creditExpire.res_empty()) { @@ -339,38 +339,38 @@ if (!data->request.creditExpire.res_empty()) strftime(buf, 32, "%Y-%m-%d", &brokenTime); - cout << "creditExpire=" << buf << endl; + cout << "creditExpire = " << buf << endl; } if (!data->request.down.res_empty()) - cout << "down=" << info.down << endl; + cout << "down = " << info.down << endl; if (!data->request.passive.res_empty()) - cout << "passive=" << info.passive << endl; + cout << "passive = " << info.passive << endl; if (!data->request.disableDetailStat.res_empty()) - cout << "disableDetailStat=" << info.disableDetailStat << endl; + cout << "disableDetailStat = " << info.disableDetailStat << endl; if (!data->request.alwaysOnline.res_empty()) - cout << "alwaysOnline=" << info.alwaysOnline << endl; + cout << "alwaysOnline = " << info.alwaysOnline << endl; if (!data->request.prepaidTraff.res_empty()) - cout << "prepaidTraff=" << info.prepaidTraff << endl; + cout << "prepaidTraff = " << info.prepaidTraff << endl; for (int i = 0; i < DIR_NUM; i++) { if (!data->request.sessionUpload[i].res_empty()) - cout << "session upload for dir" << i << "=" << info.stat.su[i] << endl; + cout << "session upload for dir " << i << " = " << info.stat.su[i] << endl; if (!data->request.sessionDownload[i].res_empty()) - cout << "session download for dir" << i << "=" << info.stat.sd[i] << endl; + cout << "session download for dir " << i << "=" << info.stat.sd[i] << endl; } for (int i = 0; i < DIR_NUM; i++) { if (!data->request.monthUpload[i].res_empty()) - cout << "month upload for dir" << i << "=" << info.stat.mu[i] << endl; + cout << "month upload for dir " << i << " = " << info.stat.mu[i] << endl; if (!data->request.monthDownload[i].res_empty()) - cout << "month download for dir" << i << "=" << info.stat.md[i] << endl; + cout << "month download for dir " << i << " = " << info.stat.md[i] << endl; } for (int i = 0; i < USERDATA_NUM; i++) @@ -379,7 +379,7 @@ for (int i = 0; i < USERDATA_NUM; i++) { string str; ConvertFromKOI8(info.userData[i], &str); - cout << "userdata" << i << "=" << str << endl; + cout << "user data " << i << " = " << str << endl; } } @@ -401,7 +401,7 @@ for (unsigned i = 0; i < sizeof(strReqParams) / sizeof(StringReqParams); i++) { string str; ConvertFromKOI8(*strReqParams[i].value, &str); - cout << strReqParams[i].name << "=" << str << endl; + cout << strReqParams[i].name << " = " << str << endl; } } data->result = true; diff --git a/stglibs/srvconf.lib/netunit.cpp b/stglibs/srvconf.lib/netunit.cpp index eab32e6a..aaba3df6 100644 --- a/stglibs/srvconf.lib/netunit.cpp +++ b/stglibs/srvconf.lib/netunit.cpp @@ -442,12 +442,15 @@ while (1) Decrypt(buffer, bufferS, &ctx); buffer[ENC_MSG_LEN] = 0; + printf("%s", buffer); + answerList.push_back(buffer); for (int j = 0; j < ENC_MSG_LEN; j++) { if (buffer[j] == 0) { + printf("\n"); if (RxCallBack) if (st_ok != RxCallBack(dataRxCallBack, &answerList)) return st_xml_parse_error; diff --git a/stglibs/srvconf.lib/parser_get_user.cpp b/stglibs/srvconf.lib/parser_get_user.cpp index 93017038..1039cb8d 100644 --- a/stglibs/srvconf.lib/parser_get_user.cpp +++ b/stglibs/srvconf.lib/parser_get_user.cpp @@ -97,22 +97,20 @@ if (checkValue(attr)) return value; } -template -void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, bool encoded = false); - -template -void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, bool /*encoded*/) +uint32_t getIPValue(const char ** attr) { - parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER(value, getValue))); +if (checkValue(attr)) + return inet_strington(attr[1]); +return 0; } -template <> -void addParser(PROPERTY_PARSERS & parsers, const std::string & name, std::string & value, bool encoded) +template +void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER::FUNC & func = getValue); + +template +void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER::FUNC & func) { - if (encoded) - parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER(value, getEncodedValue))); - else - parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER(value, getValue))); + parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER(value, func))); } void tryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr) @@ -141,19 +139,19 @@ PARSER_GET_USER::PARSER_GET_USER() addParser(propertyParsers, "disableDetailStat", info.disableDetailStat); addParser(propertyParsers, "connected", info.connected); addParser(propertyParsers, "alwaysOnline", info.alwaysOnline); - addParser(propertyParsers, "ip", info.ip); - addParser(propertyParsers, "ips", info.ips); + addParser(propertyParsers, "currIP", info.ip, getIPValue); + addParser(propertyParsers, "ip", info.ips); addParser(propertyParsers, "tariff", info.tariff); - addParser(propertyParsers, "group", info.group, true); - addParser(propertyParsers, "note", info.note, true); - addParser(propertyParsers, "email", info.email, true); - addParser(propertyParsers, "name", info.name, true); - addParser(propertyParsers, "address", info.address, true); - addParser(propertyParsers, "phone", info.phone, true); + 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, "traff", info.stat); for (size_t i = 0; i < USERDATA_NUM; ++i) - addParser(propertyParsers, "userData" + x2str(i), info.userData[i], true); + addParser(propertyParsers, "userData" + x2str(i), info.userData[i], getEncodedValue); } //----------------------------------------------------------------------------- PARSER_GET_USER::~PARSER_GET_USER() -- 2.44.2