From b463b9f9a916554458fc576342125ff2f22efdac Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 8 Aug 2013 17:56:57 +0300 Subject: [PATCH 01/16] Many changes related to getting user information via sgconf. --- projects/sgconf/common_sg.cpp | 109 ++++++------ projects/sgconf/common_sg.h | 4 +- projects/sgconf/main.cpp | 166 ++++-------------- projects/sgconf/request.h | 17 +- .../srvconf.lib/include/stg/parser_get_user.h | 5 +- stglibs/srvconf.lib/include/stg/servconf.h | 4 +- stglibs/srvconf.lib/parser_get_user.cpp | 31 ++-- stglibs/srvconf.lib/servconf.cpp | 8 +- 8 files changed, 135 insertions(+), 209 deletions(-) diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index a15f7588..9bbe62d7 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -47,10 +47,10 @@ const int usageInfo = 1; const int TO_KOI8 = 0; const int FROM_KOI8 = 1; //----------------------------------------------------------------------------- -struct GetUserCbData +struct GetUserData { - void * data; - bool * result; + REQUEST & request; + bool result; }; //--------------------------------------------------------------------------- struct HelpParams @@ -314,32 +314,29 @@ struct StringReqParams string * value; }; //----------------------------------------------------------------------------- -void RecvUserData(USERDATA * ud, void * d) +void GetUserCallback(const PARSER_GET_USER::INFO & info, void * d) { -GetUserCbData * gucbd; -gucbd = (GetUserCbData *)d; - -bool * result = gucbd->result; +GetUserData * data = static_cast(d); REQUEST * req = (REQUEST *)gucbd->data; -if (ud->login == "") +if (info.login == "") { - *result = false; + data->result = false; return; } -if (!req->cash.res_empty()) - cout << "cash=" << ud->cash << endl; +if (!data->request.cash.res_empty()) + cout << "cash=" << info.cash << endl; -if (!req->credit.res_empty()) - cout << "credit=" << ud->credit << endl; +if (!data->requst.credit.res_empty()) + cout << "credit=" << info.credit << endl; -if (!req->creditExpire.res_empty()) +if (!data->requst.creditExpire.res_empty()) { char buf[32]; struct tm brokenTime; - time_t tt = ud->creditExpire; + time_t tt = info.creditExpire; brokenTime.tm_wday = 0; brokenTime.tm_yday = 0; @@ -355,50 +352,58 @@ if (!req->creditExpire.res_empty()) cout << "creditExpire=" << buf << endl; } -if (!req->down.res_empty()) - cout << "down=" << ud->down << endl; +if (!data->requst.down.res_empty()) + cout << "down=" << info.down << endl; + +if (!data->requst.passive.res_empty()) + cout << "passive=" << info.passive << endl; -if (!req->passive.res_empty()) - cout << "passive=" << ud->passive << endl; +if (!data->requst.disableDetailStat.res_empty()) + cout << "disableDetailStat=" << info.disableDetailStat << endl; -if (!req->disableDetailStat.res_empty()) - cout << "disableDetailStat=" << ud->disableDetailStat << endl; +if (!data->requst.alwaysOnline.res_empty()) + cout << "alwaysOnline=" << info.alwaysOnline << endl; -if (!req->alwaysOnline.res_empty()) - cout << "alwaysOnline=" << ud->alwaysOnline << endl; +if (!data->requst.prepaidTraff.res_empty()) + cout << "prepaidTraff=" << info.prepaidTraff << endl; -if (!req->prepaidTraff.res_empty()) - cout << "prepaidTraff=" << ud->prepaidTraff << endl; +for (int i = 0; i < DIR_NUM; i++) + { + if (!data->requst.up[i].res_empty()) + cout << "session upload for dir" << i << "=" << info.stat.su[i] << endl; + if (!data->requst.down[i].res_empty()) + cout << "session download for dir" << i << "=" << info.stat.sd[i] << endl; + } for (int i = 0; i < DIR_NUM; i++) { - if (!req->u[i].res_empty()) - cout << "u" << i << "=" << ud->stat.mu[i] << endl; - if (!req->d[i].res_empty()) - cout << "d" << i << "=" << ud->stat.md[i] << endl; + if (!data->requst.monthUp[i].res_empty()) + cout << "month upload for dir" << i << "=" << info.stat.mu[i] << endl; + if (!data->requst.monthDown[i].res_empty()) + cout << "month download for dir" << i << "=" << info.stat.md[i] << endl; } for (int i = 0; i < USERDATA_NUM; i++) { - if (!req->ud[i].res_empty()) + if (!data->requst.ud[i].res_empty()) { string str; - ConvertFromKOI8(ud->userData[i], &str); + ConvertFromKOI8(info.userData[i], &str); cout << "userdata" << i << "=" << str << endl; } } StringReqParams strReqParams[] = { - {"note", req->note, &ud->note}, - {"name", req->name, &ud->name}, - {"address", req->address, &ud->address}, - {"email", req->email, &ud->email}, - {"phone", req->phone, &ud->phone}, - {"group", req->group, &ud->group}, - {"tariff", req->tariff, &ud->tariff}, - {"password", req->usrPasswd, &ud->password}, - {"ip", req->ips, &ud->ips} // IP-address of user + {"note", data->requst.note, &info.note}, + {"name", data->requst.name, &info.name}, + {"address", data->requst.address, &info.address}, + {"email", data->requst.email, &info.email}, + {"phone", data->requst.phone, &info.phone}, + {"group", data->requst.group, &info.group}, + {"tariff", data->requst.tariff, &info.tariff}, + {"password", data->requst.usrPasswd, &info.password}, + {"ip", data->requst.ips, &info.ips} // IP-address of user }; for (unsigned i = 0; i < sizeof(strReqParams) / sizeof(StringReqParams); i++) { @@ -409,7 +414,7 @@ for (unsigned i = 0; i < sizeof(strReqParams) / sizeof(StringReqParams); i++) cout << strReqParams[i].name << "=" << str << endl; } } -*result = true; +data->result = true; } //----------------------------------------------------------------------------- void RecvAuthByData(const PARSER_AUTH_BY::INFO & list, void *) @@ -432,9 +437,9 @@ SERVCONF sc; bool result = false; -sc.SetServer(server.c_str()); // õÓÔÁÎÁ×ÌÉ×ÁÅÍ ÉÍÑ ÓÅÒ×ÅÒÁ Ó ËÏÔÏÒÇÏ ÚÁÂÉÒÁÔØ ÉÎÆÕ -sc.SetPort(port); // ÁÄÍÉÎÓËÉÊ ÐÏÒÔ ÓÅÒ×ÅÒÁÐÏÒÔ -sc.SetAdmLogin(admLogin.c_str()); // ÷ÙÓÔÁ×ÌÑÅÍ ÌÏÇÉÎ É ÐÁÒÏÌØ ÁÄÍÉÎÁ +sc.SetServer(server.c_str()); +sc.SetPort(port); +sc.SetAdmLogin(admLogin.c_str()); sc.SetAdmPassword(admPasswd.c_str()); // TODO Good variable name :) @@ -473,24 +478,24 @@ int ProcessGetUser(const std::string &server, const std::string &admLogin, const std::string &admPasswd, const std::string &login, - void * data) + REQUEST & request) { SERVCONF sc; bool result = false; -sc.SetServer(server.c_str()); // õÓÔÁÎÁ×ÌÉ×ÁÅÍ ÉÍÑ ÓÅÒ×ÅÒÁ Ó ËÏÔÏÒÇÏ ÚÁÂÉÒÁÔØ ÉÎÆÕ -sc.SetPort(port); // ÁÄÍÉÎÓËÉÊ ÐÏÒÔ ÓÅÒ×ÅÒÁÐÏÒÔ -sc.SetAdmLogin(admLogin.c_str()); // ÷ÙÓÔÁ×ÌÑÅÍ ÌÏÇÉÎ É ÐÁÒÏÌØ ÁÄÍÉÎÁ +sc.SetServer(server.c_str()); +sc.SetPort(port); +sc.SetAdmLogin(admLogin.c_str()); sc.SetAdmPassword(admPasswd.c_str()); // TODO Good variable name :) GetUserCbData gucbd; -gucbd.data = data; +gucbd.data = &request; gucbd.result = &result; -sc.SetGetUserDataRecvCb(RecvUserData, &gucbd); +sc.SetGetUserCallback(GetUserCallback, &gucbd); sc.GetUser(login.c_str()); if (result) @@ -512,7 +517,7 @@ int ProcessAuthBy(const std::string &server, const std::string &admLogin, const std::string &admPasswd, const std::string &login, - void * data) + REQUEST & request) { SERVCONF sc; diff --git a/projects/sgconf/common_sg.h b/projects/sgconf/common_sg.h index a5cbffad..47069eae 100644 --- a/projects/sgconf/common_sg.h +++ b/projects/sgconf/common_sg.h @@ -50,14 +50,14 @@ int ProcessGetUser(const std::string &server, const std::string &admLogin, const std::string &admPasswd, const std::string &login, - void * data); + REQUEST & request); int ProcessAuthBy(const std::string &server, int port, const std::string &admLogin, const std::string &admPasswd, const std::string &login, - void * data); + REQUEST & request); int ProcessSetUser(const std::string &server, int port, diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index 2c02be27..fae181f6 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -66,37 +66,12 @@ struct option long_options_get[] = { {"passive", 0, 0, 'i'}, //passive {"disable-stat",0, 0, 'S'}, //disable detail stat {"always-online",0, 0, 'O'}, //always online -{"u0", 0, 0, 500}, //U0 -{"u1", 0, 0, 501}, //U1 -{"u2", 0, 0, 502}, //U2 -{"u3", 0, 0, 503}, //U3 -{"u4", 0, 0, 504}, //U4 -{"u5", 0, 0, 505}, //U5 -{"u6", 0, 0, 506}, //U6 -{"u7", 0, 0, 507}, //U7 -{"u8", 0, 0, 508}, //U8 -{"u9", 0, 0, 509}, //U9 -{"d0", 0, 0, 600}, //D0 -{"d1", 0, 0, 601}, //D1 -{"d2", 0, 0, 602}, //D2 -{"d3", 0, 0, 603}, //D3 -{"d4", 0, 0, 604}, //D4 -{"d5", 0, 0, 605}, //D5 -{"d6", 0, 0, 606}, //D6 -{"d7", 0, 0, 607}, //D7 -{"d8", 0, 0, 608}, //D8 -{"d9", 0, 0, 609}, //D9 - -{"ud0", 0, 0, 700}, //UserData0 -{"ud1", 0, 0, 701}, //UserData1 -{"ud2", 0, 0, 702}, //UserData2 -{"ud3", 0, 0, 703}, //UserData3 -{"ud4", 0, 0, 704}, //UserData4 -{"ud5", 0, 0, 705}, //UserData5 -{"ud6", 0, 0, 706}, //UserData6 -{"ud7", 0, 0, 707}, //UserData7 -{"ud8", 0, 0, 708}, //UserData8 -{"ud9", 0, 0, 709}, //UserData9 +{"session-upload-dir", 1, 0, 500}, //SU0 +{"session-download-dir", 1, 0, 501}, //SD0 +{"month-upload-dir", 1, 0, 502}, //MU0 +{"month-download-dir", 1, 0, 503}, //MD0 + +{"user-data", 1, 0, 700}, //UserData0 {"prepaid", 0, 0, 'e'}, //prepaid traff {"create", 0, 0, 'n'}, //create @@ -129,37 +104,12 @@ struct option long_options_set[] = { {"passive", 1, 0, 'i'}, //passive {"disable-stat",1, 0, 'S'}, //disable detail stat {"always-online",1, 0, 'O'}, //always online -{"u0", 1, 0, 500}, //U0 -{"u1", 1, 0, 501}, //U1 -{"u2", 1, 0, 502}, //U2 -{"u3", 1, 0, 503}, //U3 -{"u4", 1, 0, 504}, //U4 -{"u5", 1, 0, 505}, //U5 -{"u6", 1, 0, 506}, //U6 -{"u7", 1, 0, 507}, //U7 -{"u8", 1, 0, 508}, //U8 -{"u9", 1, 0, 509}, //U9 -{"d0", 1, 0, 600}, //D0 -{"d1", 1, 0, 601}, //D1 -{"d2", 1, 0, 602}, //D2 -{"d3", 1, 0, 603}, //D3 -{"d4", 1, 0, 604}, //D4 -{"d5", 1, 0, 605}, //D5 -{"d6", 1, 0, 606}, //D6 -{"d7", 1, 0, 607}, //D7 -{"d8", 1, 0, 608}, //D8 -{"d9", 1, 0, 609}, //D9 - -{"ud0", 1, 0, 700}, //UserData -{"ud1", 1, 0, 701}, //UserData1 -{"ud2", 1, 0, 702}, //UserData2 -{"ud3", 1, 0, 703}, //UserData3 -{"ud4", 1, 0, 704}, //UserData4 -{"ud5", 1, 0, 705}, //UserData5 -{"ud6", 1, 0, 706}, //UserData6 -{"ud7", 1, 0, 707}, //UserData7 -{"ud8", 1, 0, 708}, //UserData8 -{"ud9", 1, 0, 709}, //UserData9 +{"session-upload", 1, 0, 500}, //U0 +{"session-download", 1, 0, 501}, //U1 +{"month-upload", 1, 0, 502}, //U2 +{"month-download", 1, 0, 503}, //U3 + +{"user-data", 1, 0, 700}, //UserData {"prepaid", 1, 0, 'e'}, //prepaid traff {"create", 1, 0, 'n'}, //create @@ -792,7 +742,7 @@ while (1) case 'G': //Group req.group = " "; break; - + case 'I': //IP-address of user req.ips = " "; break; @@ -806,45 +756,25 @@ while (1) break; case 500: //U + //printf("U%d\n", c - 500); + req.sessionUp[optarg] = 1; + break; case 501: + //printf("U%d\n", c - 500); + req.sessionDown[optarg] = 1; + break; case 502: - case 503: - case 504: - case 505: - case 506: - case 507: - case 508: - case 509: //printf("U%d\n", c - 500); - req.u[c - 500] = 1; + req.monthUp[optarg] = 1; break; - - case 600: //D - case 601: - case 602: - case 603: - case 604: - case 605: - case 606: - case 607: - case 608: - case 609: - //printf("D%d\n", c - 600); - req.d[c - 600] = 1; + case 503: + //printf("U%d\n", c - 500); + req.monthDown[optarg] = 1; break; case 700: //UserData - case 701: - case 702: - case 703: - case 704: - case 705: - case 706: - case 707: - case 708: - case 709: //printf("UD%d\n", c - 700); - req.ud[c - 700] = " "; + req.ud[optarg] = " "; break; case 800: @@ -879,9 +809,9 @@ if (missedOptionArg || !CheckParametersGet(&req)) } if (req.authBy) - return ProcessAuthBy(req.server, req.port, req.admLogin, req.admPasswd, req.login, &req); + return ProcessAuthBy(req.server, req.port, req.admLogin, req.admPasswd, req.login, req); else - return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, &req); + return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, req); } //----------------------------------------------------------------------------- int mainSet(int argc, char **argv) @@ -1025,46 +955,26 @@ while (1) break; case 500: //U + //printf("U%d\n", c - 500); + req.sesionUpload[optarg] = ParseTraff(argv[optind++]); + break; case 501: + //printf("U%d\n", c - 500); + req.sessionDownload[optarg] = ParseTraff(argv[optind++]); + break; case 502: - case 503: - case 504: - case 505: - case 506: - case 507: - case 508: - case 509: //printf("U%d\n", c - 500); - req.u[c - 500] = ParseTraff(optarg); + req.monthUpload[optarg] = ParseTraff(argv[optind++]); break; - - case 600: //D - case 601: - case 602: - case 603: - case 604: - case 605: - case 606: - case 607: - case 608: - case 609: - //printf("D%d\n", c - 600); - req.d[c - 600] = ParseTraff(optarg); + case 503: + //printf("U%d\n", c - 500); + req.monthDownload[optarg] = ParseTraff(argv[optind++]); break; case 700: //UserData - case 701: - case 702: - case 703: - case 704: - case 705: - case 706: - case 707: - case 708: - case 709: - ParseAnyString(optarg, &str); + ParseAnyString(argv[optind++], &str); //printf("UD%d\n", c - 700); - req.ud[c - 700] = str; + req.userData[optarg] = str; break; case '?': diff --git a/projects/sgconf/request.h b/projects/sgconf/request.h index 61222127..5ce4d093 100644 --- a/projects/sgconf/request.h +++ b/projects/sgconf/request.h @@ -54,12 +54,14 @@ REQUEST() { for (int i = 0; i < DIR_NUM; i++) { - u[i].reset(); - d[i].reset(); + sessionUp[i].reset(); + sessionDown[i].reset(); + monthUp[i].reset(); + monthDown[i].reset(); } for (int i = 0; i < USERDATA_NUM; i++) - ud[i].reset(); + userData[i].reset(); } RESETABLE server; @@ -88,10 +90,13 @@ RESETABLE disableDetailStat; RESETABLE alwaysOnline; RESETABLE prepaidTraff; -RESETABLE u[DIR_NUM]; -RESETABLE d[DIR_NUM]; +RESETABLE sessionUp[DIR_NUM]; +RESETABLE sessionDown[DIR_NUM]; -RESETABLE ud[USERDATA_NUM]; +RESETABLE monthUp[DIR_NUM]; +RESETABLE monthDown[DIR_NUM]; + +RESETABLE userData[USERDATA_NUM]; RESETABLE note; RESETABLE name; diff --git a/stglibs/srvconf.lib/include/stg/parser_get_user.h b/stglibs/srvconf.lib/include/stg/parser_get_user.h index 575b0e46..db074af4 100644 --- a/stglibs/srvconf.lib/include/stg/parser_get_user.h +++ b/stglibs/srvconf.lib/include/stg/parser_get_user.h @@ -35,11 +35,12 @@ class BASE_PROPERTY_PARSER { public: - virtual bool Parse(const char ** attr) = 0; + virtual ~BASE_PROPERTY_PARSER() {} + virtual void Parse(const char ** attr) = 0; }; template -class PROPERTY_PARSER +class PROPERTY_PARSER : public BASE_PROPERTY_PARSER { public: typedef T (* FUNC)(const char **); diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index 714a4e79..f455730e 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -98,7 +98,7 @@ public: void SetAdmLogin(const char * login); void SetAdmPassword(const char * password); - void SetGetUsers(PARSER_GET_USERS::CALLBACK f, void * data); + void SetGetUsersCallback(PARSER_GET_USERS::CALLBACK f, void * data); void SetAuthByCallback(PARSER_AUTH_BY::CALLBACK f, void * data); void SetServerInfoCallback(PARSER_SERVER_INFO::CALLBACK f, void * data); void SetChgUserCb(RecvChgUserCb_t, void * data); @@ -147,9 +147,9 @@ private: PARSER_CHECK_USER::CALLBACK checkUserCallback; RecvSendMessageCb_t RecvSendMessageCb; + void * getUsersData; void * getUserData; void * authByData; - void * getUsersData; void * serverInfoData; void * chgUserDataCb; void * checkUserData; diff --git a/stglibs/srvconf.lib/parser_get_user.cpp b/stglibs/srvconf.lib/parser_get_user.cpp index 9af85d03..9ba86c14 100644 --- a/stglibs/srvconf.lib/parser_get_user.cpp +++ b/stglibs/srvconf.lib/parser_get_user.cpp @@ -23,6 +23,7 @@ #include "stg/common.h" +#include #include #include @@ -58,24 +59,24 @@ double getValue(const char ** attr) { double value = 0; if (checkValue(attr)) - if (strtodouble2(attr[1], value) == EINVAL) + if (strtodouble2(attr[1], value)) return 0; return value; } template <> -STAT getValue(const char ** attr) +PARSER_GET_USER::STAT getValue(const char ** attr) { -STAT value; +PARSER_GET_USER::STAT value; if (!attr) return value; std::map props; for (size_t i = 0; i < DIR_NUM; ++i) { - props.insert("su" + x2str(i), value.su[i]); - props.insert("sd" + x2str(i), value.sd[i]); - props.insert("mu" + x2str(i), value.mu[i]); - props.insert("md" + x2str(i), value.md[i]); + props.insert(std::pair("su" + x2str(i), value.su[i])); + props.insert(std::pair("sd" + x2str(i), value.sd[i])); + props.insert(std::pair("mu" + x2str(i), value.mu[i])); + props.insert(std::pair("md" + x2str(i), value.md[i])); } size_t pos = 0; while (attr[pos]) @@ -90,24 +91,28 @@ return value; std::string getEncodedValue(const char ** attr) { +std::string value; if (checkValue(attr)) - return Decode21str(attr[1]); -return ""; + Decode21str(value, attr[1]); +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*/) { - parsers.insert(ToLower(name), new PROPERTY_PARSER(value, getValue)); + parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER(value, getValue))); } template <> void addParser(PROPERTY_PARSERS & parsers, const std::string & name, std::string & value, bool encoded) { if (encoded) - parsers.insert(ToLower(name), new PROPERTY_PARSER(value, getEncodedValue)); + parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER(value, getEncodedValue))); else - parsers.insert(ToLower(name), new PROPERTY_PARSER(value, getValue)); + parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER(value, getValue))); } void tryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr) @@ -182,7 +187,7 @@ void PARSER_GET_USER::ParseUser(const char * el, const char ** attr) { if (strcasecmp(el, "user") == 0) if (strcasecmp(attr[1], "error") == 0) - user.login = ""; + info.login = ""; } //----------------------------------------------------------------------------- void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr) diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 7b2c85ec..3d82860b 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -94,16 +94,16 @@ SERVCONF::SERVCONF() : currParser(NULL), parseDepth(0), error(0), - RecvUserDataCb(NULL), - RecvGetUserDataCb(NULL), + getUsersCallback(NULL), + getUserCallback(NULL), authByCallback(NULL), serverInfoCallback(NULL), RecvChgUserCb(NULL), checkUserCallback(NULL), RecvSendMessageCb(NULL), - getUserDataDataCb(NULL), + getUsersData(NULL), + getUserData(NULL), authByData(NULL), - getUsersDataDataCb(NULL), serverInfoData(NULL), chgUserDataCb(NULL), checkUserData(NULL), -- 2.44.2 From c9104229b3f6ee0320752780053ad97f5385359a Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 8 Aug 2013 18:01:46 +0300 Subject: [PATCH 02/16] Small name fixes. --- projects/sgconf/common_sg.cpp | 8 ++++---- projects/sgconf/main.cpp | 16 ++++++++-------- projects/sgconf/request.h | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index 9bbe62d7..0f5c9cc9 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -369,17 +369,17 @@ if (!data->requst.prepaidTraff.res_empty()) for (int i = 0; i < DIR_NUM; i++) { - if (!data->requst.up[i].res_empty()) + if (!data->requst.sessionUpload[i].res_empty()) cout << "session upload for dir" << i << "=" << info.stat.su[i] << endl; - if (!data->requst.down[i].res_empty()) + if (!data->requst.sessionDownload[i].res_empty()) cout << "session download for dir" << i << "=" << info.stat.sd[i] << endl; } for (int i = 0; i < DIR_NUM; i++) { - if (!data->requst.monthUp[i].res_empty()) + if (!data->requst.monthUpload[i].res_empty()) cout << "month upload for dir" << i << "=" << info.stat.mu[i] << endl; - if (!data->requst.monthDown[i].res_empty()) + if (!data->requst.monthDownload[i].res_empty()) cout << "month download for dir" << i << "=" << info.stat.md[i] << endl; } diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index fae181f6..76a47824 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -66,10 +66,10 @@ struct option long_options_get[] = { {"passive", 0, 0, 'i'}, //passive {"disable-stat",0, 0, 'S'}, //disable detail stat {"always-online",0, 0, 'O'}, //always online -{"session-upload-dir", 1, 0, 500}, //SU0 -{"session-download-dir", 1, 0, 501}, //SD0 -{"month-upload-dir", 1, 0, 502}, //MU0 -{"month-download-dir", 1, 0, 503}, //MD0 +{"session-upload", 1, 0, 500}, //SU0 +{"session-download", 1, 0, 501}, //SD0 +{"month-upload", 1, 0, 502}, //MU0 +{"month-download", 1, 0, 503}, //MD0 {"user-data", 1, 0, 700}, //UserData0 @@ -757,19 +757,19 @@ while (1) case 500: //U //printf("U%d\n", c - 500); - req.sessionUp[optarg] = 1; + req.sessionUpload[optarg] = 1; break; case 501: //printf("U%d\n", c - 500); - req.sessionDown[optarg] = 1; + req.sessionDownload[optarg] = 1; break; case 502: //printf("U%d\n", c - 500); - req.monthUp[optarg] = 1; + req.monthUpload[optarg] = 1; break; case 503: //printf("U%d\n", c - 500); - req.monthDown[optarg] = 1; + req.monthDownload[optarg] = 1; break; case 700: //UserData diff --git a/projects/sgconf/request.h b/projects/sgconf/request.h index 5ce4d093..70c45059 100644 --- a/projects/sgconf/request.h +++ b/projects/sgconf/request.h @@ -90,11 +90,11 @@ RESETABLE disableDetailStat; RESETABLE alwaysOnline; RESETABLE prepaidTraff; -RESETABLE sessionUp[DIR_NUM]; -RESETABLE sessionDown[DIR_NUM]; +RESETABLE sessionUpload[DIR_NUM]; +RESETABLE sessionDownload[DIR_NUM]; -RESETABLE monthUp[DIR_NUM]; -RESETABLE monthDown[DIR_NUM]; +RESETABLE monthUpload[DIR_NUM]; +RESETABLE monthDownload[DIR_NUM]; RESETABLE userData[USERDATA_NUM]; -- 2.44.2 From 23d052c42f43430e4ff776a80b9643dbc7d1289d Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 9 Aug 2013 21:04:49 +0300 Subject: [PATCH 03/16] Foxed compilation errors. --- projects/sgconf/common_sg.cpp | 83 ++++----- projects/sgconf/main.cpp | 162 +++++++++++++----- projects/sgconf/request.h | 8 +- stglibs/srvconf.lib/Makefile | 1 + .../include/stg/parser_get_users.h | 2 + stglibs/srvconf.lib/parser_get_users.cpp | 6 +- 6 files changed, 160 insertions(+), 102 deletions(-) diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index 0f5c9cc9..c0a4fd25 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -49,6 +49,7 @@ const int FROM_KOI8 = 1; //----------------------------------------------------------------------------- struct GetUserData { + GetUserData(REQUEST & req, bool res) : request(req), result(res) {} REQUEST & request; bool result; }; @@ -291,18 +292,9 @@ ConvertKOI8(src, dst, TO_KOI8); //----------------------------------------------------------------------------- int RecvSetUserAnswer(const char * ans, void * d) { -GetUserCbData * gucbd; -gucbd = (GetUserCbData *)d; - -bool * result = gucbd->result; - -//REQUEST * req = (REQUEST *)gucbd->data; +GetUserData * data = static_cast(d); -//printf("ans=%s\n", ans); -if (strcasecmp("Ok", ans) == 0) - *result = true; -else - *result = false; +data->result = (strcasecmp("Ok", ans) == 0); return 0; } @@ -311,15 +303,13 @@ struct StringReqParams { string name; RESETABLE reqParam; - string * value; + const string * value; }; //----------------------------------------------------------------------------- void GetUserCallback(const PARSER_GET_USER::INFO & info, void * d) { GetUserData * data = static_cast(d); -REQUEST * req = (REQUEST *)gucbd->data; - if (info.login == "") { data->result = false; @@ -329,10 +319,10 @@ if (info.login == "") if (!data->request.cash.res_empty()) cout << "cash=" << info.cash << endl; -if (!data->requst.credit.res_empty()) +if (!data->request.credit.res_empty()) cout << "credit=" << info.credit << endl; -if (!data->requst.creditExpire.res_empty()) +if (!data->request.creditExpire.res_empty()) { char buf[32]; struct tm brokenTime; @@ -352,40 +342,40 @@ if (!data->requst.creditExpire.res_empty()) cout << "creditExpire=" << buf << endl; } -if (!data->requst.down.res_empty()) +if (!data->request.down.res_empty()) cout << "down=" << info.down << endl; -if (!data->requst.passive.res_empty()) +if (!data->request.passive.res_empty()) cout << "passive=" << info.passive << endl; -if (!data->requst.disableDetailStat.res_empty()) +if (!data->request.disableDetailStat.res_empty()) cout << "disableDetailStat=" << info.disableDetailStat << endl; -if (!data->requst.alwaysOnline.res_empty()) +if (!data->request.alwaysOnline.res_empty()) cout << "alwaysOnline=" << info.alwaysOnline << endl; -if (!data->requst.prepaidTraff.res_empty()) +if (!data->request.prepaidTraff.res_empty()) cout << "prepaidTraff=" << info.prepaidTraff << endl; for (int i = 0; i < DIR_NUM; i++) { - if (!data->requst.sessionUpload[i].res_empty()) + if (!data->request.sessionUpload[i].res_empty()) cout << "session upload for dir" << i << "=" << info.stat.su[i] << endl; - if (!data->requst.sessionDownload[i].res_empty()) + if (!data->request.sessionDownload[i].res_empty()) cout << "session download for dir" << i << "=" << info.stat.sd[i] << endl; } for (int i = 0; i < DIR_NUM; i++) { - if (!data->requst.monthUpload[i].res_empty()) + if (!data->request.monthUpload[i].res_empty()) cout << "month upload for dir" << i << "=" << info.stat.mu[i] << endl; - if (!data->requst.monthDownload[i].res_empty()) + if (!data->request.monthDownload[i].res_empty()) cout << "month download for dir" << i << "=" << info.stat.md[i] << endl; } for (int i = 0; i < USERDATA_NUM; i++) { - if (!data->requst.ud[i].res_empty()) + if (!data->request.userData[i].res_empty()) { string str; ConvertFromKOI8(info.userData[i], &str); @@ -395,15 +385,15 @@ for (int i = 0; i < USERDATA_NUM; i++) StringReqParams strReqParams[] = { - {"note", data->requst.note, &info.note}, - {"name", data->requst.name, &info.name}, - {"address", data->requst.address, &info.address}, - {"email", data->requst.email, &info.email}, - {"phone", data->requst.phone, &info.phone}, - {"group", data->requst.group, &info.group}, - {"tariff", data->requst.tariff, &info.tariff}, - {"password", data->requst.usrPasswd, &info.password}, - {"ip", data->requst.ips, &info.ips} // IP-address of user + {"note", data->request.note, &info.note}, + {"name", data->request.name, &info.name}, + {"address", data->request.address, &info.address}, + {"email", data->request.email, &info.email}, + {"phone", data->request.phone, &info.phone}, + {"group", data->request.group, &info.group}, + {"tariff", data->request.tariff, &info.tariff}, + {"password", data->request.usrPasswd, &info.password}, + {"ip", data->request.ips, &info.ips} // IP-address of user }; for (unsigned i = 0; i < sizeof(strReqParams) / sizeof(StringReqParams); i++) { @@ -436,26 +426,22 @@ SERVCONF sc; bool result = false; - sc.SetServer(server.c_str()); sc.SetPort(port); sc.SetAdmLogin(admLogin.c_str()); sc.SetAdmPassword(admPasswd.c_str()); -// TODO Good variable name :) -GetUserCbData gucbd; - -gucbd.data = data; -gucbd.result = &result; +REQUEST request; +GetUserData cbdata(request, false); if (isMessage) { - sc.SetSendMessageCb(RecvSetUserAnswer, &gucbd); + sc.SetSendMessageCb(RecvSetUserAnswer, &cbdata); sc.MsgUser(str.c_str()); } else { - sc.SetChgUserCb(RecvSetUserAnswer, &gucbd); + sc.SetChgUserCb(RecvSetUserAnswer, &cbdata); sc.ChgUser(str.c_str()); } @@ -482,23 +468,18 @@ int ProcessGetUser(const std::string &server, { SERVCONF sc; -bool result = false; - sc.SetServer(server.c_str()); sc.SetPort(port); sc.SetAdmLogin(admLogin.c_str()); sc.SetAdmPassword(admPasswd.c_str()); // TODO Good variable name :) -GetUserCbData gucbd; - -gucbd.data = &request; -gucbd.result = &result; +GetUserData data(request, false); -sc.SetGetUserCallback(GetUserCallback, &gucbd); +sc.SetGetUserCallback(GetUserCallback, &data); sc.GetUser(login.c_str()); -if (result) +if (data.result) { printf("Ok\n"); return 0; diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index 76a47824..507abaa5 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -43,7 +43,35 @@ #include "common_sg.h" #include "sg_error_codes.h" -using namespace std; +namespace +{ + +template +struct ARRAY_TYPE; + +template +struct ARRAY_TYPE +{ +typedef T type; +}; + +template +struct ARRAY_TYPE +{ +typedef T type; +}; + +template +bool SetArrayItem(T & array, const char * index, const typename ARRAY_TYPE::type & value) +{ +size_t pos = 0; +if (str2x(index, pos)) + return false; +array[pos] = value; +return true; +} + +} // namespace anonymous time_t stgTime; @@ -455,7 +483,7 @@ int uPresent = false; int dPresent = false; for (int i = 0; i < DIR_NUM; i++) { - if (!req->u[i].res_empty()) + if (!req->monthUpload[i].res_empty()) { if (!uPresent && !dPresent) { @@ -465,12 +493,12 @@ for (int i = 0; i < DIR_NUM; i++) } stringstream ss; - ss << req->u[i].const_data(); + ss << req->monthUpload[i].const_data(); //sprintf(str, "MU%d=\"%lld\" ", i, req->u[i].const_data()); sprintf(str, "MU%d=\"%s\" ", i, ss.str().c_str()); strcat(r, str); } - if (!req->d[i].res_empty()) + if (!req->monthDownload[i].res_empty()) { if (!uPresent && !dPresent) { @@ -480,7 +508,36 @@ for (int i = 0; i < DIR_NUM; i++) } stringstream ss; - ss << req->d[i].const_data(); + ss << req->monthDownload[i].const_data(); + sprintf(str, "MD%d=\"%s\" ", i, ss.str().c_str()); + strcat(r, str); + } + if (!req->sessionUpload[i].res_empty()) + { + if (!uPresent && !dPresent) + { + sprintf(str, "sessionUpload[i].const_data(); + //sprintf(str, "MU%d=\"%lld\" ", i, req->u[i].const_data()); + sprintf(str, "MU%d=\"%s\" ", i, ss.str().c_str()); + strcat(r, str); + } + if (!req->sessionDownload[i].res_empty()) + { + if (!uPresent && !dPresent) + { + sprintf(str, "sessionDownload[i].const_data(); sprintf(str, "MD%d=\"%s\" ", i, ss.str().c_str()); strcat(r, str); } @@ -562,10 +619,10 @@ if (!req->group.res_empty()) for (int i = 0; i < USERDATA_NUM; i++) { - if (!req->ud[i].res_empty()) + if (!req->userData[i].res_empty()) { string ud; - Encode12str(ud, req->ud[i]); + Encode12str(ud, req->userData[i]); sprintf(str, "", i, ud.c_str()); strcat(r, str); } @@ -576,16 +633,18 @@ strcat(r, "\n"); //----------------------------------------------------------------------------- int CheckParameters(REQUEST * req) { -int u = false; -int d = false; -int ud = false; -int a = !req->admLogin.res_empty() +bool su = false; +bool sd = false; +bool mu = false; +bool md = false; +bool ud = false; +bool a = !req->admLogin.res_empty() && !req->admPasswd.res_empty() && !req->server.res_empty() && !req->port.res_empty() && !req->login.res_empty(); -int b = !req->cash.res_empty() +bool b = !req->cash.res_empty() || !req->setCash.res_empty() || !req->credit.res_empty() || !req->prepaidTraff.res_empty() @@ -607,25 +666,43 @@ int b = !req->cash.res_empty() for (int i = 0; i < DIR_NUM; i++) { - if (req->u[i].res_empty()) + if (req->sessionUpload[i].res_empty()) { - u = true; + su = true; break; } } for (int i = 0; i < DIR_NUM; i++) { - if (req->d[i].res_empty()) + if (req->sessionDownload[i].res_empty()) { - d = true; + sd = true; break; } } for (int i = 0; i < DIR_NUM; i++) { - if (req->ud[i].res_empty()) + if (req->monthUpload[i].res_empty()) + { + mu = true; + break; + } + } + +for (int i = 0; i < DIR_NUM; i++) + { + if (req->monthDownload[i].res_empty()) + { + md = true; + break; + } + } + +for (int i = 0; i < DIR_NUM; i++) + { + if (req->userData[i].res_empty()) { ud = true; break; @@ -634,7 +711,7 @@ for (int i = 0; i < DIR_NUM; i++) //printf("a=%d, b=%d, u=%d, d=%d ud=%d\n", a, b, u, d, ud); -return a && (b || u || d || ud); +return a && (b || su || sd || mu || md || ud); } //----------------------------------------------------------------------------- int CheckParametersGet(REQUEST * req) @@ -743,9 +820,9 @@ while (1) req.group = " "; break; - case 'I': //IP-address of user - req.ips = " "; - break; + case 'I': //IP-address of user + req.ips = " "; + break; case 'S': //Detail stat status req.disableDetailStat = " "; @@ -756,25 +833,25 @@ while (1) break; case 500: //U - //printf("U%d\n", c - 500); - req.sessionUpload[optarg] = 1; + SetArrayItem(req.sessionUpload, optarg, 1); + //req.sessionUpload[optarg] = 1; break; case 501: - //printf("U%d\n", c - 500); - req.sessionDownload[optarg] = 1; + SetArrayItem(req.sessionDownload, optarg, 1); + //req.sessionDownload[optarg] = 1; break; case 502: - //printf("U%d\n", c - 500); - req.monthUpload[optarg] = 1; + SetArrayItem(req.monthUpload, optarg, 1); + //req.monthUpload[optarg] = 1; break; case 503: - //printf("U%d\n", c - 500); - req.monthDownload[optarg] = 1; + SetArrayItem(req.monthDownload, optarg, 1); + //req.monthDownload[optarg] = 1; break; case 700: //UserData - //printf("UD%d\n", c - 700); - req.ud[optarg] = " "; + SetArrayItem(req.userData, optarg, std::string(" ")); + //req.userData[optarg] = " "; break; case 800: @@ -783,7 +860,6 @@ while (1) case '?': case ':': - //printf ("Unknown option \n"); missedOptionArg = true; break; @@ -955,35 +1031,33 @@ while (1) break; case 500: //U - //printf("U%d\n", c - 500); - req.sesionUpload[optarg] = ParseTraff(argv[optind++]); + SetArrayItem(req.sessionUpload, optarg, ParseTraff(argv[optind++])); + //req.sessionUpload[optarg] = ParseTraff(argv[optind++]); break; case 501: - //printf("U%d\n", c - 500); - req.sessionDownload[optarg] = ParseTraff(argv[optind++]); + SetArrayItem(req.sessionDownload, optarg, ParseTraff(argv[optind++])); + //req.sessionDownload[optarg] = ParseTraff(argv[optind++]); break; case 502: - //printf("U%d\n", c - 500); - req.monthUpload[optarg] = ParseTraff(argv[optind++]); + SetArrayItem(req.monthUpload, optarg, ParseTraff(argv[optind++])); + //req.monthUpload[optarg] = ParseTraff(argv[optind++]); break; case 503: - //printf("U%d\n", c - 500); - req.monthDownload[optarg] = ParseTraff(argv[optind++]); + SetArrayItem(req.monthDownload, optarg, ParseTraff(argv[optind++])); + //req.monthDownload[optarg] = ParseTraff(argv[optind++]); break; case 700: //UserData ParseAnyString(argv[optind++], &str); - //printf("UD%d\n", c - 700); - req.userData[optarg] = str; + SetArrayItem(req.userData, optarg, str); + //req.userData[optarg] = str; break; case '?': - //printf("Missing option argument\n"); missedOptionArg = true; break; case ':': - //printf("Missing option argument\n"); missedOptionArg = true; break; diff --git a/projects/sgconf/request.h b/projects/sgconf/request.h index 70c45059..bca3c148 100644 --- a/projects/sgconf/request.h +++ b/projects/sgconf/request.h @@ -54,10 +54,10 @@ REQUEST() { for (int i = 0; i < DIR_NUM; i++) { - sessionUp[i].reset(); - sessionDown[i].reset(); - monthUp[i].reset(); - monthDown[i].reset(); + sessionUpload[i].reset(); + sessionDownload[i].reset(); + monthUpload[i].reset(); + monthDownload[i].reset(); } for (int i = 0; i < USERDATA_NUM; i++) diff --git a/stglibs/srvconf.lib/Makefile b/stglibs/srvconf.lib/Makefile index a2f12771..7e9d90e0 100644 --- a/stglibs/srvconf.lib/Makefile +++ b/stglibs/srvconf.lib/Makefile @@ -14,6 +14,7 @@ SRCS = netunit.cpp \ parser_server_info.cpp \ parser_check_user.cpp \ parser_get_user.cpp \ + parser_get_users.cpp \ servconf.cpp INCS = servconf.h \ diff --git a/stglibs/srvconf.lib/include/stg/parser_get_users.h b/stglibs/srvconf.lib/include/stg/parser_get_users.h index 07d76cc5..b35aa48c 100644 --- a/stglibs/srvconf.lib/include/stg/parser_get_users.h +++ b/stglibs/srvconf.lib/include/stg/parser_get_users.h @@ -25,6 +25,8 @@ #include "stg/parser.h" +#include "parser_get_user.h" + #include class PARSER_GET_USERS: public PARSER diff --git a/stglibs/srvconf.lib/parser_get_users.cpp b/stglibs/srvconf.lib/parser_get_users.cpp index 6996dbaf..d4e44d36 100644 --- a/stglibs/srvconf.lib/parser_get_users.cpp +++ b/stglibs/srvconf.lib/parser_get_users.cpp @@ -26,7 +26,7 @@ #include PARSER_GET_USERS::PARSER_GET_USERS() - : callabck(NULL), + : callback(NULL), data(NULL), depth(0) { @@ -53,7 +53,7 @@ if (depth > 0) if (depth == 0) if (callback) - callback(&info, data); + callback(info, data); } //----------------------------------------------------------------------------- void PARSER_GET_USERS::ParseUsers(const char * el, const char ** /*attr*/) @@ -70,7 +70,7 @@ info.push_back(userInfo); void PARSER_GET_USERS::SetCallback(CALLBACK f, void * d) { callback = f; -data = data; +data = d; } //----------------------------------------------------------------------------- void PARSER_GET_USERS::UserCallback(const PARSER_GET_USER::INFO & info, void * data) -- 2.44.2 From dd4d8887d9e281e81c4cd511026ed44e7dcf68b4 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Aug 2013 10:03:42 +0300 Subject: [PATCH 04/16] Cosmetic changes. --- .../store/postgresql/postgresql_store.cpp | 35 ++++++------------- .../postgresql/postgresql_store_utils.cpp | 20 +++++------ .../store/postgresql/postgresql_store_utils.h | 11 ------ 3 files changed, 20 insertions(+), 46 deletions(-) delete mode 100644 projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp index dd2fbbab..aabce23b 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp @@ -38,16 +38,15 @@ * */ -#include -#include -#include - -#include +#include "postgresql_store.h" #include "stg/module_settings.h" #include "stg/plugin_creator.h" -#include "postgresql_store_utils.h" -#include "postgresql_store.h" + +#include + +#include +#include namespace { @@ -93,37 +92,25 @@ pthread_mutex_destroy(&mutex); int POSTGRESQL_STORE::ParseSettings() { std::vector::iterator i; -std::string s; for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i) { - s = i->param; - std::transform(s.begin(), s.end(), s.begin(), ToLower()); + std::string param(ToLower(i->param)); if (s == "server") - { server = *(i->value.begin()); - } - if (s == "database") - { + else if (s == "database") database = *(i->value.begin()); - } - if (s == "user") - { + else if (s == "user") user = *(i->value.begin()); - } - if (s == "password") - { + else if (s == "password") password = *(i->value.begin()); - } - if (s == "retries") - { + else if (s == "retries") if (str2x(*(i->value.begin()), retries)) { strError = "Invalid 'retries' value"; printfd(__FILE__, "POSTGRESQL_STORE::ParseSettings(): '%s'\n", strError.c_str()); return -1; } - } } clientEncoding = "KOI8"; diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp index f5dec89f..ef705053 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp @@ -26,14 +26,15 @@ * */ +#include "postgresql_store.h" + +#include "stg/common.h" + #include #include #include -#include "stg/common.h" -#include "postgresql_store.h" - extern volatile time_t stgTime; int POSTGRESQL_STORE::StartTransaction() const @@ -93,10 +94,10 @@ int error = 0; char * buf = new char[(value.length() << 1) + 1]; PQescapeStringConn(connection, - buf, - value.c_str(), - value.length(), - &error); + buf, + value.c_str(), + value.length(), + &error); if (error) { @@ -114,7 +115,6 @@ return 0; std::string POSTGRESQL_STORE::Int2TS(time_t ts) const { -char buf[32]; struct tm brokenTime; brokenTime.tm_wday = 0; @@ -123,6 +123,7 @@ brokenTime.tm_isdst = 0; gmtime_r(&ts, &brokenTime); +char buf[32]; strftime(buf, 32, "%Y-%m-%d %H:%M:%S", &brokenTime); return buf; @@ -160,8 +161,6 @@ if (year) else { time_t curTime = stgTime; - /*time(&curTime);*/ - localtime_r(&curTime, &brokenTime); } @@ -173,4 +172,3 @@ strftime(buf, 32, "%Y-%m-%d", &brokenTime); date = buf; } - diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h b/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h deleted file mode 100644 index 4ffa6ecf..00000000 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef POSTGRESQL_UTILS_STORE_H -#define POSTGRESQL_UTILS_STORE_H - -#include - -struct ToLower : public std::unary_function -{ -char operator() (char c) const { return static_cast(std::tolower(c)); } -}; - -#endif -- 2.44.2 From d3819ef7b806ccd92a767ec4bb43e0388f879216 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Aug 2013 10:04:49 +0300 Subject: [PATCH 05/16] Renamed a variable. --- .../plugins/store/postgresql/postgresql_store.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp index aabce23b..5e2d8ae6 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp @@ -96,15 +96,15 @@ std::vector::iterator i; for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i) { std::string param(ToLower(i->param)); - if (s == "server") + if (param == "server") server = *(i->value.begin()); - else if (s == "database") + else if (param == "database") database = *(i->value.begin()); - else if (s == "user") + else if (param == "user") user = *(i->value.begin()); - else if (s == "password") + else if (param == "password") password = *(i->value.begin()); - else if (s == "retries") + else if (param == "retries") if (str2x(*(i->value.begin()), retries)) { strError = "Invalid 'retries' value"; -- 2.44.2 From 198f8204d13f3f0661233d910f474775a68a7337 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Aug 2013 10:51:39 +0300 Subject: [PATCH 06/16] Different small fixes plus error logging. --- .../plugins/configuration/sgconfig/parser.cpp | 2 +- stglibs/common.lib/include/stg/common.h | 4 ++-- stglibs/srvconf.lib/netunit.cpp | 18 +++++++++++------- stglibs/srvconf.lib/parser_get_user.cpp | 14 +++++++------- stglibs/srvconf.lib/servconf.cpp | 19 ++++++------------- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp index b6c49172..431d17f3 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp @@ -289,7 +289,7 @@ answerList->push_back(s); s = ""; std::vector list(u->GetAuthorizers()); for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) - s += ""; + s += ""; s += ""; answerList->push_back(s); diff --git a/stglibs/common.lib/include/stg/common.h b/stglibs/common.lib/include/stg/common.h index 6df89f73..3b1ea275 100644 --- a/stglibs/common.lib/include/stg/common.h +++ b/stglibs/common.lib/include/stg/common.h @@ -115,11 +115,11 @@ int str2x(const std::string & str, varT & x); template const std::string & x2str(varT x, std::string & s); template -const std::string & x2str(varT x) { std::string s; return x2str(x, s); } +std::string x2str(varT x) { std::string s; return x2str(x, s); } template const std::string & unsigned2str(varT x, std::string & s); template -const std::string & unsigned2str(varT x) { std::string s; return unsigned2str(x, s); } +std::string unsigned2str(varT x) { std::string s; return unsigned2str(x, s); } //----------------------------------------------------------------------------- template diff --git a/stglibs/srvconf.lib/netunit.cpp b/stglibs/srvconf.lib/netunit.cpp index 9a653d5b..eab32e6a 100644 --- a/stglibs/srvconf.lib/netunit.cpp +++ b/stglibs/srvconf.lib/netunit.cpp @@ -25,15 +25,17 @@ */ //--------------------------------------------------------------------------- -#include -#include -#include + +#include "stg/netunit.h" +#include "stg/common.h" #include +#include #include -#include "stg/netunit.h" -#include "stg/common.h" +#include +#include +#include //--------------------------------------------------------------------------- @@ -212,6 +214,7 @@ int ret; ret = recv(outerSocket, buffer, strlen(OK_HEADER), 0); if (ret <= 0) { + printf("Receive header answer error: '%s'\n", strerror(errno)); errorMsg = RECV_HEADER_ANSWER_ERROR; return st_recv_fail; } @@ -261,6 +264,7 @@ int ret; ret = recv(outerSocket, buffer, strlen(OK_LOGIN), 0); if (ret <= 0) { + printf("Receive login answer error: '%s'\n", strerror(errno)); errorMsg = RECV_LOGIN_ANSWER_ERROR; return st_recv_fail; } @@ -318,6 +322,7 @@ int ret; ret = recv(outerSocket, buffer, strlen(OK_LOGINS), 0); if (ret <= 0) { + printf("Receive secret login answer error: '%s'\n", strerror(errno)); errorMsg = RECV_LOGIN_ANSWER_ERROR; return st_recv_fail; } @@ -425,6 +430,7 @@ while (1) ret = recv(outerSocket, &bufferS[n++], 1, 0); if (ret <= 0) { + printf("Receive data error: '%s'\n", strerror(errno)); close(outerSocket); errorMsg = RECV_DATA_ANSWER_ERROR; return st_recv_fail; @@ -444,9 +450,7 @@ while (1) { if (RxCallBack) if (st_ok != RxCallBack(dataRxCallBack, &answerList)) - { return st_xml_parse_error; - } return st_ok; } } diff --git a/stglibs/srvconf.lib/parser_get_user.cpp b/stglibs/srvconf.lib/parser_get_user.cpp index 9ba86c14..93017038 100644 --- a/stglibs/srvconf.lib/parser_get_user.cpp +++ b/stglibs/srvconf.lib/parser_get_user.cpp @@ -70,21 +70,21 @@ PARSER_GET_USER::STAT getValue(const char ** attr) PARSER_GET_USER::STAT value; if (!attr) return value; -std::map props; +std::map props; for (size_t i = 0; i < DIR_NUM; ++i) { - props.insert(std::pair("su" + x2str(i), value.su[i])); - props.insert(std::pair("sd" + x2str(i), value.sd[i])); - props.insert(std::pair("mu" + x2str(i), value.mu[i])); - props.insert(std::pair("md" + x2str(i), value.md[i])); + props.insert(std::pair("su" + x2str(i), &value.su[i])); + props.insert(std::pair("sd" + x2str(i), &value.sd[i])); + props.insert(std::pair("mu" + x2str(i), &value.mu[i])); + props.insert(std::pair("md" + x2str(i), &value.md[i])); } size_t pos = 0; while (attr[pos]) { std::string name(ToLower(attr[pos++])); - std::map::iterator it(props.find(name)); + std::map::iterator it(props.find(name)); if (it != props.end()) - str2x(attr[pos++], it->second); + str2x(attr[pos++], *it->second); } return value; } diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 3d82860b..7848787b 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -35,31 +35,23 @@ using namespace std; //----------------------------------------------------------------------------- int AnsRecv(void * data, list * list1) { -//NODE * node; -SERVCONF * sc; -char ans[ENC_MSG_LEN + 1]; -int len, done = 0; - -sc = (SERVCONF*)data; +SERVCONF * sc = static_cast(data); XML_ParserReset(sc->parser, NULL); XML_SetElementHandler(sc->parser, Start, End); XML_SetUserData(sc->parser, data); +char ans[ENC_MSG_LEN + 1]; +int len, done = 0; + //loop parsing list::iterator node; node = list1->begin(); -if (node == list1->end()) - { - return st_ok; - } - while (node != list1->end()) { strncpy(ans, node->c_str(), ENC_MSG_LEN); ans[ENC_MSG_LEN] = 0; - //printf("---> %s\n", ans); len = strlen(ans); if (XML_Parse(sc->parser, ans, len, done) == XML_STATUS_ERROR) @@ -67,13 +59,14 @@ while (node != list1->end()) strprintf(&sc->errorMsg, "XML parse error at line %d: %s", static_cast(XML_GetCurrentLineNumber(sc->parser)), XML_ErrorString(XML_GetErrorCode(sc->parser))); + printf("%s\n", sc->errorMsg.c_str()); return st_xml_parse_error; } ++node; } -return 0; +return st_ok; } //----------------------------------------------------------------------------- void Start(void *data, const char *el, const char **attr) -- 2.44.2 From b7e8712548323c7d4bacd999710c9963295f8950 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Aug 2013 18:54:50 +0300 Subject: [PATCH 07/16] Fixed stupid bug in case conversion functions. --- stglibs/common.lib/common.cpp | 4 ++-- stglibs/common.lib/include/stg/common.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index c02f675c..763df532 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -824,7 +824,7 @@ std::string ToLower(const std::string & value) std::string res; for (std::string::size_type pos = 0; pos < value.length(); ++pos) res += tolower(value[pos]); - return value; + return res; } //--------------------------------------------------------------------------- std::string ToUpper(const std::string & value) @@ -832,7 +832,7 @@ std::string ToUpper(const std::string & value) std::string res; for (std::string::size_type pos = 0; pos < value.length(); ++pos) res += toupper(value[pos]); - return value; + return res; } //--------------------------------------------------------------------------- #ifdef WIN32 diff --git a/stglibs/common.lib/include/stg/common.h b/stglibs/common.lib/include/stg/common.h index 3b1ea275..6c71289b 100644 --- a/stglibs/common.lib/include/stg/common.h +++ b/stglibs/common.lib/include/stg/common.h @@ -155,7 +155,7 @@ int str2x(const std::string & str, varT & x) x += str[i] - '0'; } - x*= minus; + x *= minus; return 0; } -- 2.44.2 From 9177beb0b910b03cecfa4ec5f98747cbb3d4280c Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Aug 2013 18:57:29 +0300 Subject: [PATCH 08/16] 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 From e1b5c9b23eae58f71765d458321bdb1691b26288 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Aug 2013 22:55:25 +0300 Subject: [PATCH 09/16] Added license header. --- stglibs/srvconf.lib/include/stg/parser.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/stglibs/srvconf.lib/include/stg/parser.h b/stglibs/srvconf.lib/include/stg/parser.h index 66263692..f8c3af0c 100644 --- a/stglibs/srvconf.lib/include/stg/parser.h +++ b/stglibs/srvconf.lib/include/stg/parser.h @@ -1,3 +1,24 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + #ifndef __STG_STGLIBS_SRVCONF_PARSER_H__ #define __STG_STGLIBS_SRVCONF_PARSER_H__ -- 2.44.2 From 7e142f5d0a61138473602352e38c6f5a5e4bba61 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Aug 2013 22:55:38 +0300 Subject: [PATCH 10/16] Removed "stg" prefix from inclusion of parser.h --- stglibs/srvconf.lib/include/stg/parser_auth_by.h | 2 +- .../srvconf.lib/include/stg/parser_check_user.h | 2 +- stglibs/srvconf.lib/include/stg/parser_get_user.h | 2 +- .../srvconf.lib/include/stg/parser_get_users.h | 2 +- .../srvconf.lib/include/stg/parser_server_info.h | 2 +- stglibs/srvconf.lib/include/stg/servconf.h | 15 --------------- 6 files changed, 5 insertions(+), 20 deletions(-) diff --git a/stglibs/srvconf.lib/include/stg/parser_auth_by.h b/stglibs/srvconf.lib/include/stg/parser_auth_by.h index b9f33cf3..aa3ea7bc 100644 --- a/stglibs/srvconf.lib/include/stg/parser_auth_by.h +++ b/stglibs/srvconf.lib/include/stg/parser_auth_by.h @@ -21,7 +21,7 @@ #ifndef __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__ #define __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__ -#include "stg/parser.h" +#include "parser.h" #include #include diff --git a/stglibs/srvconf.lib/include/stg/parser_check_user.h b/stglibs/srvconf.lib/include/stg/parser_check_user.h index 55d5531e..8088a0c0 100644 --- a/stglibs/srvconf.lib/include/stg/parser_check_user.h +++ b/stglibs/srvconf.lib/include/stg/parser_check_user.h @@ -22,7 +22,7 @@ #ifndef __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__ #define __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__ -#include "stg/parser.h" +#include "parser.h" class PARSER_CHECK_USER: public PARSER { diff --git a/stglibs/srvconf.lib/include/stg/parser_get_user.h b/stglibs/srvconf.lib/include/stg/parser_get_user.h index db074af4..7b6032e0 100644 --- a/stglibs/srvconf.lib/include/stg/parser_get_user.h +++ b/stglibs/srvconf.lib/include/stg/parser_get_user.h @@ -22,7 +22,7 @@ #ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__ #define __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__ -#include "stg/parser.h" +#include "parser.h" #include "stg/os_int.h" #include "stg/const.h" diff --git a/stglibs/srvconf.lib/include/stg/parser_get_users.h b/stglibs/srvconf.lib/include/stg/parser_get_users.h index b35aa48c..5338a913 100644 --- a/stglibs/srvconf.lib/include/stg/parser_get_users.h +++ b/stglibs/srvconf.lib/include/stg/parser_get_users.h @@ -23,7 +23,7 @@ #ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__ #define __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__ -#include "stg/parser.h" +#include "parser.h" #include "parser_get_user.h" diff --git a/stglibs/srvconf.lib/include/stg/parser_server_info.h b/stglibs/srvconf.lib/include/stg/parser_server_info.h index 38e87186..ce7a70ae 100644 --- a/stglibs/srvconf.lib/include/stg/parser_server_info.h +++ b/stglibs/srvconf.lib/include/stg/parser_server_info.h @@ -22,7 +22,7 @@ #ifndef __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ #define __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ -#include "stg/parser.h" +#include "/parser.h" #include "stg/const.h" diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index f455730e..fddbcf7a 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -58,21 +58,6 @@ struct ADMINDATA char login[ADM_LOGIN_LEN]; }; //----------------------------------------------------------------------------- -class PARSER_CHG_USER: public PARSER -{ -public: - PARSER_CHG_USER(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseAnswer(const char *el, const char **attr); - void SetChgUserRecvCb(RecvChgUserCb_t, void * data); -private: - RecvChgUserCb_t RecvChgUserCb; - void * chgUserCbData; - int depth; - bool error; -}; -//----------------------------------------------------------------------------- class PARSER_SEND_MESSAGE: public PARSER { public: -- 2.44.2 From 02d8ff35c9a854ffd15a701e46a118bc51be3b7d Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Aug 2013 22:56:09 +0300 Subject: [PATCH 11/16] Added setter. --- .../srvconf.lib/include/stg/parser_chg_user.h | 42 +++++++++++++++++++ stglibs/srvconf.lib/parser_chg_user.cpp | 21 ++++++++++ 2 files changed, 63 insertions(+) create mode 100644 stglibs/srvconf.lib/include/stg/parser_chg_user.h create mode 100644 stglibs/srvconf.lib/parser_chg_user.cpp diff --git a/stglibs/srvconf.lib/include/stg/parser_chg_user.h b/stglibs/srvconf.lib/include/stg/parser_chg_user.h new file mode 100644 index 00000000..3191f370 --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/parser_chg_user.h @@ -0,0 +1,42 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__ + +#include "parser.h" + +class PARSER_CHG_USER: public PARSER +{ +public: + PARSER_CHG_USER(); + int ParseStart(const char *el, const char **attr); + void ParseEnd(const char *el); + void ParseAnswer(const char *el, const char **attr); + void SetChgUserRecvCb(RecvChgUserCb_t, void * data); +private: + RecvChgUserCb_t RecvChgUserCb; + void * chgUserCbData; + int depth; + bool error; +}; + +#endif diff --git a/stglibs/srvconf.lib/parser_chg_user.cpp b/stglibs/srvconf.lib/parser_chg_user.cpp new file mode 100644 index 00000000..bf48e648 --- /dev/null +++ b/stglibs/srvconf.lib/parser_chg_user.cpp @@ -0,0 +1,21 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + -- 2.44.2 From 6d5f129aad1a6cbaf4d1441c68398e00fa949185 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Aug 2013 23:35:00 +0300 Subject: [PATCH 12/16] Fixed compilation issues. --- projects/sgconf/common_sg.cpp | 23 +- projects/sgconf/common_sg.h | 4 +- projects/sgconf/main.cpp | 4 +- stglibs/crypto.lib/include/stg/blowfish.h | 3 + stglibs/srvconf.lib/Makefile | 1 + stglibs/srvconf.lib/include/stg/netunit.h | 8 +- .../srvconf.lib/include/stg/parser_chg_user.h | 16 +- .../include/stg/parser_server_info.h | 2 +- stglibs/srvconf.lib/include/stg/servconf.h | 38 +-- stglibs/srvconf.lib/parser.cpp | 53 +--- stglibs/srvconf.lib/parser_chg_user.cpp | 45 ++++ stglibs/srvconf.lib/servconf.cpp | 252 +++--------------- 12 files changed, 130 insertions(+), 319 deletions(-) diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index 2901832a..ca1aa50c 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -419,13 +419,10 @@ int ProcessSetUser(const std::string &server, const std::string &admLogin, const std::string &admPasswd, const std::string &str, - void * data, bool isMessage) { SERVCONF sc; -bool result = false; - sc.SetServer(server.c_str()); sc.SetPort(port); sc.SetAdmLogin(admLogin.c_str()); @@ -434,18 +431,19 @@ sc.SetAdmPassword(admPasswd.c_str()); REQUEST request; GetUserData cbdata(request, false); +int res = 0; if (isMessage) { sc.SetSendMessageCb(RecvSetUserAnswer, &cbdata); - sc.MsgUser(str.c_str()); + res = sc.MsgUser(str.c_str()); } else { - sc.SetChgUserCb(RecvSetUserAnswer, &cbdata); - sc.ChgUser(str.c_str()); + sc.SetChgUserCallback(RecvSetUserAnswer, &cbdata); + res = sc.ChgUser(str.c_str()); } -if (result) +if (res && cbdata.result) { printf("Ok\n"); return 0; @@ -477,9 +475,9 @@ sc.SetAdmPassword(admPasswd.c_str()); GetUserData data(request, false); sc.SetGetUserCallback(GetUserCallback, &data); -sc.GetUser(login.c_str()); +bool res = (sc.GetUser(login.c_str()) == st_ok); -if (data.result) +if (res && data.result) { printf("Ok\n"); return 0; @@ -497,8 +495,7 @@ int ProcessAuthBy(const std::string &server, int port, const std::string &admLogin, const std::string &admPasswd, - const std::string &login, - REQUEST & request) + const std::string &login) { SERVCONF sc; @@ -508,9 +505,9 @@ sc.SetAdmLogin(admLogin.c_str()); sc.SetAdmPassword(admPasswd.c_str()); sc.SetAuthByCallback(RecvAuthByData, NULL); -sc.AuthBy(login.c_str()); +bool res = (sc.AuthBy(login.c_str()) == st_ok); -if (sc.GetError()) +if (!res) { printf("Error\n"); return -1; diff --git a/projects/sgconf/common_sg.h b/projects/sgconf/common_sg.h index 47069eae..ca7eb36c 100644 --- a/projects/sgconf/common_sg.h +++ b/projects/sgconf/common_sg.h @@ -56,15 +56,13 @@ int ProcessAuthBy(const std::string &server, int port, const std::string &admLogin, const std::string &admPasswd, - const std::string &login, - REQUEST & request); + const std::string &login); int ProcessSetUser(const std::string &server, int port, const std::string &admLogin, const std::string &admPasswd, const std::string &str, - void * data, bool isMessage = false); #endif diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index 507abaa5..f8a394d4 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -885,7 +885,7 @@ if (missedOptionArg || !CheckParametersGet(&req)) } if (req.authBy) - return ProcessAuthBy(req.server, req.port, req.admLogin, req.admPasswd, req.login, req); + return ProcessAuthBy(req.server, req.port, req.admLogin, req.admPasswd, req.login); else return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, req); } @@ -1087,7 +1087,7 @@ char rstr[rLen]; memset(rstr, 0, rLen); CreateRequestSet(&req, rstr); -return ProcessSetUser(req.server, req.port, req.admLogin, req.admPasswd, rstr, NULL, isMessage); +return ProcessSetUser(req.server, req.port, req.admLogin, req.admPasswd, rstr, isMessage); } //----------------------------------------------------------------------------- int main(int argc, char **argv) diff --git a/stglibs/crypto.lib/include/stg/blowfish.h b/stglibs/crypto.lib/include/stg/blowfish.h index a8800d75..c9983340 100644 --- a/stglibs/crypto.lib/include/stg/blowfish.h +++ b/stglibs/crypto.lib/include/stg/blowfish.h @@ -13,7 +13,10 @@ #define MAXKEYBYTES 56 /* 448 bits */ #ifdef __cplusplus +#include // size_t extern "C" { +#else +#include // size_t #endif typedef struct { diff --git a/stglibs/srvconf.lib/Makefile b/stglibs/srvconf.lib/Makefile index 7e9d90e0..45f3899d 100644 --- a/stglibs/srvconf.lib/Makefile +++ b/stglibs/srvconf.lib/Makefile @@ -15,6 +15,7 @@ SRCS = netunit.cpp \ parser_check_user.cpp \ parser_get_user.cpp \ parser_get_users.cpp \ + parser_chg_user.cpp \ servconf.cpp INCS = servconf.h \ diff --git a/stglibs/srvconf.lib/include/stg/netunit.h b/stglibs/srvconf.lib/include/stg/netunit.h index e288df86..d40b4c6a 100644 --- a/stglibs/srvconf.lib/include/stg/netunit.h +++ b/stglibs/srvconf.lib/include/stg/netunit.h @@ -27,14 +27,14 @@ #ifndef NetUnitH #define NetUnitH -#include -#include -#include +#include "stg/blowfish.h" #include #include -#include "stg/blowfish.h" +#include +#include +#include #define STG_HEADER "SG04" #define OK_HEADER "OKHD" diff --git a/stglibs/srvconf.lib/include/stg/parser_chg_user.h b/stglibs/srvconf.lib/include/stg/parser_chg_user.h index 3191f370..d8920cde 100644 --- a/stglibs/srvconf.lib/include/stg/parser_chg_user.h +++ b/stglibs/srvconf.lib/include/stg/parser_chg_user.h @@ -27,16 +27,18 @@ class PARSER_CHG_USER: public PARSER { public: + typedef int (* CALLBACK)(const char * asnwer, void * data); + PARSER_CHG_USER(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseAnswer(const char *el, const char **attr); - void SetChgUserRecvCb(RecvChgUserCb_t, void * data); + int ParseStart(const char * el, const char ** attr); + void ParseEnd(const char * el); + void SetCallback(CALLBACK f, void * data); private: - RecvChgUserCb_t RecvChgUserCb; - void * chgUserCbData; + CALLBACK callback; + void * data; int depth; - bool error; + + void ParseAnswer(const char * el, const char ** attr); }; #endif diff --git a/stglibs/srvconf.lib/include/stg/parser_server_info.h b/stglibs/srvconf.lib/include/stg/parser_server_info.h index ce7a70ae..5adb2abb 100644 --- a/stglibs/srvconf.lib/include/stg/parser_server_info.h +++ b/stglibs/srvconf.lib/include/stg/parser_server_info.h @@ -22,7 +22,7 @@ #ifndef __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ #define __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ -#include "/parser.h" +#include "parser.h" #include "stg/const.h" diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index fddbcf7a..c62161be 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -34,6 +34,7 @@ #include "stg/parser_check_user.h" #include "stg/parser_get_user.h" #include "stg/parser_get_users.h" +#include "stg/parser_chg_user.h" #include "stg/os_int.h" #include "stg/const.h" @@ -44,14 +45,13 @@ #include -void Start(void *data, const char *el, const char **attr); -void End(void *data, const char *el); +void Start(void * data, const char * el, const char ** attr); +void End(void * data, const char * el); #define MAX_ERR_STR_LEN (64) #define IP_STRING_LEN (255) //----------------------------------------------------------------------------- -typedef int(*RecvChgUserCb_t)(const char * asnwer, void * data); -typedef int(*RecvSendMessageCb_t)(const char * answer, void * data); +typedef int (* RecvSendMessageCb_t)(const char * answer, void * data); //----------------------------------------------------------------------------- struct ADMINDATA { @@ -62,15 +62,14 @@ class PARSER_SEND_MESSAGE: public PARSER { public: PARSER_SEND_MESSAGE(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseAnswer(const char *el, const char **attr); + int ParseStart(const char * el, const char ** attr); + void ParseEnd(const char * el); + void ParseAnswer(const char * el, const char ** attr); void SetSendMessageRecvCb(RecvSendMessageCb_t, void * data); private: RecvSendMessageCb_t RecvSendMessageCb; void * sendMessageCbData; int depth; - bool error; }; //----------------------------------------------------------------------------- class SERVCONF @@ -86,7 +85,7 @@ public: void SetGetUsersCallback(PARSER_GET_USERS::CALLBACK f, void * data); void SetAuthByCallback(PARSER_AUTH_BY::CALLBACK f, void * data); void SetServerInfoCallback(PARSER_SERVER_INFO::CALLBACK f, void * data); - void SetChgUserCb(RecvChgUserCb_t, void * data); + void SetChgUserCallback(PARSER_CHG_USER::CALLBACK f, void * data); void SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data); void SetGetUserCallback(PARSER_GET_USER::CALLBACK f, void * data); void SetSendMessageCb(RecvSendMessageCb_t, void * data); @@ -102,9 +101,8 @@ public: int CheckUser(const char * login, const char * password); const std::string & GetStrError() const; - int GetError(); - int Start(const char *el, const char **attr); - void End(const char *el); + int Start(const char * el, const char ** attr); + void End(const char * el); private: PARSER * currParser; @@ -118,28 +116,16 @@ private: PARSER_SEND_MESSAGE parserSendMessage; NETTRANSACT nt; - int parseDepth; std::string errorMsg; - int error; XML_Parser parser; - PARSER_GET_USERS::CALLBACK getUsersCallback; - PARSER_GET_USER::CALLBACK getUserCallback; - PARSER_AUTH_BY::CALLBACK authByCallback; - PARSER_SERVER_INFO::CALLBACK serverInfoCallback; - RecvChgUserCb_t RecvChgUserCb; - PARSER_CHECK_USER::CALLBACK checkUserCallback; RecvSendMessageCb_t RecvSendMessageCb; - void * getUsersData; - void * getUserData; - void * authByData; - void * serverInfoData; - void * chgUserDataCb; - void * checkUserData; void * sendMessageDataCb; + int Exec(const char * request); + friend int AnsRecv(void * data, std::list * list); }; //----------------------------------------------------------------------------- diff --git a/stglibs/srvconf.lib/parser.cpp b/stglibs/srvconf.lib/parser.cpp index f259f581..78247f48 100644 --- a/stglibs/srvconf.lib/parser.cpp +++ b/stglibs/srvconf.lib/parser.cpp @@ -39,64 +39,13 @@ using namespace std; -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -PARSER_CHG_USER::PARSER_CHG_USER() - : RecvChgUserCb(NULL), - chgUserCbData(NULL), - depth(0), - error(false) -{ -} -//----------------------------------------------------------------------------- -int PARSER_CHG_USER::ParseStart(const char *el, const char **attr) -{ -depth++; -if (depth == 1) - { - if (strcasecmp(el, "SetUser") == 0) - { - ParseAnswer(el, attr); - } - else if (strcasecmp(el, "DelUser") == 0) - { - ParseAnswer(el, attr); - } - else if (strcasecmp(el, "AddUser") == 0) - { - ParseAnswer(el, attr); - } - } -return 0; -} -//----------------------------------------------------------------------------- -void PARSER_CHG_USER::ParseEnd(const char *) -{ -depth--; -} -//----------------------------------------------------------------------------- -void PARSER_CHG_USER::ParseAnswer(const char *, const char **attr) -{ -if (RecvChgUserCb) - { - RecvChgUserCb(attr[1], chgUserCbData); - } -} -//----------------------------------------------------------------------------- -void PARSER_CHG_USER::SetChgUserRecvCb(RecvChgUserCb_t f, void * data) -{ -RecvChgUserCb = f; -chgUserCbData = data; -} //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE() : RecvSendMessageCb(NULL), sendMessageCbData(NULL), - depth(0), - error(false) + depth(0) { } //----------------------------------------------------------------------------- diff --git a/stglibs/srvconf.lib/parser_chg_user.cpp b/stglibs/srvconf.lib/parser_chg_user.cpp index bf48e648..90d78f6c 100644 --- a/stglibs/srvconf.lib/parser_chg_user.cpp +++ b/stglibs/srvconf.lib/parser_chg_user.cpp @@ -19,3 +19,48 @@ * Author : Maxim Mamontov */ +#include "stg/parser_chg_user.h" + +#include + +#include + +PARSER_CHG_USER::PARSER_CHG_USER() + : callback(NULL), + data(NULL), + depth(0) +{ +} +//----------------------------------------------------------------------------- +int PARSER_CHG_USER::ParseStart(const char *el, const char **attr) +{ +depth++; +if (depth == 1) + { + if (strcasecmp(el, "SetUser") == 0) + ParseAnswer(el, attr); + else if (strcasecmp(el, "DelUser") == 0) + ParseAnswer(el, attr); + else if (strcasecmp(el, "AddUser") == 0) + ParseAnswer(el, attr); + } +return 0; +} +//----------------------------------------------------------------------------- +void PARSER_CHG_USER::ParseEnd(const char *) +{ +depth--; +} +//----------------------------------------------------------------------------- +void PARSER_CHG_USER::ParseAnswer(const char * /*el*/, const char ** attr) +{ +if (attr && attr[0] && attr[1]) + if (callback) + callback(attr[1], data); +} +//----------------------------------------------------------------------------- +void PARSER_CHG_USER::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +} diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 7848787b..b8507098 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -24,11 +24,12 @@ $Author: faust $ */ -#include -#include +#include "stg/servconf.h" #include "stg/common.h" -#include "stg/servconf.h" + +#include +#include using namespace std; @@ -85,24 +86,11 @@ sc->End(el); //----------------------------------------------------------------------------- SERVCONF::SERVCONF() : currParser(NULL), - parseDepth(0), - error(0), - getUsersCallback(NULL), - getUserCallback(NULL), - authByCallback(NULL), - serverInfoCallback(NULL), - RecvChgUserCb(NULL), - checkUserCallback(NULL), RecvSendMessageCb(NULL), - getUsersData(NULL), - getUserData(NULL), - authByData(NULL), - serverInfoData(NULL), - chgUserDataCb(NULL), - checkUserData(NULL), sendMessageDataCb(NULL) { parser = XML_ParserCreate(NULL); +nt.SetRxCallback(this, AnsRecv); } //----------------------------------------------------------------------------- void SERVCONF::SetServer(const char * server) @@ -129,31 +117,10 @@ int SERVCONF::GetUser(const char * l) { char request[255]; snprintf(request, 255, "", l); -int ret; currParser = &parserGetUser; -((PARSER_GET_USER*)currParser)->SetCallback(getUserCallback, getUserData); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::AuthBy(const char * l) @@ -162,59 +129,17 @@ char request[255]; snprintf(request, 255, "", l); currParser = &parserAuthBy; -((PARSER_AUTH_BY*)currParser)->SetCallback(authByCallback, authByData); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -int ret; -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::GetUsers() { char request[] = ""; -int ret; currParser = &parserGetUsers; -((PARSER_GET_USERS*)currParser)->SetCallback(getUsersCallback, getUsersData); -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } - -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::SendMessage(const char * login, const char * message, int prio) @@ -223,152 +148,47 @@ char request[1000]; char msg[500]; Encode12(msg, message, strlen(message)); snprintf(request, 1000, "", login, prio, msg); -int ret; currParser = &parserSendMessage; parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb); -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } - -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::ServerInfo() { char request[] = ""; -int ret; currParser = &parserServerInfo; -((PARSER_SERVER_INFO*)currParser)->SetCallback(serverInfoCallback, serverInfoData); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::ChgUser(const char * request) { -int ret; - currParser = &parserChgUser; -((PARSER_CHG_USER*)currParser)->SetChgUserRecvCb(RecvChgUserCb, chgUserDataCb); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- // TODO: remove this shit! //----------------------------------------------------------------------------- int SERVCONF::MsgUser(const char * request) { -int ret; - currParser = &parserSendMessage; parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb); -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } - -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::CheckUser(const char * login, const char * password) { char request[255]; snprintf(request, 255, "", login, password); -int ret; currParser = &parserCheckUser; -((PARSER_CHECK_USER*)currParser)->SetCallback(checkUserCallback, checkUserData); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } - -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::Start(const char *el, const char **attr) @@ -384,38 +204,32 @@ currParser->ParseEnd(el); //----------------------------------------------------------------------------- void SERVCONF::SetGetUsersCallback(PARSER_GET_USERS::CALLBACK f, void * data) { -getUsersCallback = f; -getUsersData = data; +parserGetUsers.SetCallback(f, data); } //----------------------------------------------------------------------------- void SERVCONF::SetGetUserCallback(PARSER_GET_USER::CALLBACK f, void * data) { -getUserCallback = f; -getUserData = data; +parserGetUser.SetCallback(f, data); } //----------------------------------------------------------------------------- void SERVCONF::SetAuthByCallback(PARSER_AUTH_BY::CALLBACK f, void * data) { -authByCallback = f; -authByData = data; +parserAuthBy.SetCallback(f, data); } //----------------------------------------------------------------------------- void SERVCONF::SetServerInfoCallback(PARSER_SERVER_INFO::CALLBACK f, void * data) { -serverInfoCallback = f; -serverInfoData = data; +parserServerInfo.SetCallback(f, data); } //----------------------------------------------------------------------------- -void SERVCONF::SetChgUserCb(RecvChgUserCb_t f, void * data) +void SERVCONF::SetChgUserCallback(PARSER_CHG_USER::CALLBACK f, void * data) { -RecvChgUserCb = f; -chgUserDataCb = data; +parserChgUser.SetCallback(f, data); } //----------------------------------------------------------------------------- void SERVCONF::SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data) { -checkUserCallback = f; -checkUserData = data; +parserCheckUser.SetCallback(f, data); } //----------------------------------------------------------------------------- void SERVCONF::SetSendMessageCb(RecvSendMessageCb_t f, void * data) @@ -429,10 +243,26 @@ const std::string & SERVCONF::GetStrError() const return errorMsg; } //----------------------------------------------------------------------------- -int SERVCONF::GetError() +int SERVCONF::Exec(const char * request) { -int e = error; -error = 0; -return e; +nt.Reset(); + +int ret = 0; +if ((ret = nt.Connect()) != st_ok) + { + errorMsg = nt.GetError(); + return ret; + } +if ((ret = nt.Transact(request)) != st_ok) + { + errorMsg = nt.GetError(); + return ret; + } +if ((ret = nt.Disconnect()) != st_ok) + { + errorMsg = nt.GetError(); + return ret; + } + +return st_ok; } -//----------------------------------------------------------------------------- -- 2.44.2 From 8b2d407ef1f52d42ca30d8f5e23c7a4277a2acd5 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 18 Aug 2013 12:45:56 +0300 Subject: [PATCH 13/16] Send message parser was moved to a separate files. --- stglibs/srvconf.lib/Makefile | 1 + .../include/stg/parser_send_message.h | 44 ++++++++++++++ stglibs/srvconf.lib/include/stg/servconf.h | 29 ++------- stglibs/srvconf.lib/parser.cpp | 40 ------------- stglibs/srvconf.lib/parser_send_message.cpp | 60 +++++++++++++++++++ stglibs/srvconf.lib/servconf.cpp | 27 ++------- 6 files changed, 114 insertions(+), 87 deletions(-) create mode 100644 stglibs/srvconf.lib/include/stg/parser_send_message.h create mode 100644 stglibs/srvconf.lib/parser_send_message.cpp diff --git a/stglibs/srvconf.lib/Makefile b/stglibs/srvconf.lib/Makefile index 45f3899d..296ae0f3 100644 --- a/stglibs/srvconf.lib/Makefile +++ b/stglibs/srvconf.lib/Makefile @@ -16,6 +16,7 @@ SRCS = netunit.cpp \ parser_get_user.cpp \ parser_get_users.cpp \ parser_chg_user.cpp \ + parser_send_message.cpp \ servconf.cpp INCS = servconf.h \ diff --git a/stglibs/srvconf.lib/include/stg/parser_send_message.h b/stglibs/srvconf.lib/include/stg/parser_send_message.h new file mode 100644 index 00000000..d14153e0 --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/parser_send_message.h @@ -0,0 +1,44 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__ + +#include "parser.h" + +class PARSER_SEND_MESSAGE: public PARSER +{ +public: + typedef int (* CALLBACK)(const char * answer, void * data); + + PARSER_SEND_MESSAGE(); + int ParseStart(const char * el, const char ** attr); + void ParseEnd(const char * el); + void SetCallback(CALLBACK f, void * data); +private: + CALLBACK callback; + void * data; + int depth; + + void ParseAnswer(const char * el, const char ** attr); +}; + +#endif diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index c62161be..b422f708 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -35,6 +35,7 @@ #include "stg/parser_get_user.h" #include "stg/parser_get_users.h" #include "stg/parser_chg_user.h" +#include "stg/parser_send_message.h" #include "stg/os_int.h" #include "stg/const.h" @@ -50,28 +51,12 @@ void End(void * data, const char * el); #define MAX_ERR_STR_LEN (64) #define IP_STRING_LEN (255) -//----------------------------------------------------------------------------- -typedef int (* RecvSendMessageCb_t)(const char * answer, void * data); -//----------------------------------------------------------------------------- + struct ADMINDATA { char login[ADM_LOGIN_LEN]; }; //----------------------------------------------------------------------------- -class PARSER_SEND_MESSAGE: public PARSER -{ -public: - PARSER_SEND_MESSAGE(); - int ParseStart(const char * el, const char ** attr); - void ParseEnd(const char * el); - void ParseAnswer(const char * el, const char ** attr); - void SetSendMessageRecvCb(RecvSendMessageCb_t, void * data); -private: - RecvSendMessageCb_t RecvSendMessageCb; - void * sendMessageCbData; - int depth; -}; -//----------------------------------------------------------------------------- class SERVCONF { public: @@ -88,15 +73,13 @@ public: void SetChgUserCallback(PARSER_CHG_USER::CALLBACK f, void * data); void SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data); void SetGetUserCallback(PARSER_GET_USER::CALLBACK f, void * data); - void SetSendMessageCb(RecvSendMessageCb_t, void * data); + void SetSendMessageCallback(PARSER_SEND_MESSAGE::CALLBACK f, void * data); int GetUsers(); int GetUser(const char * login); int ChgUser(const char * request); int AuthBy(const char * login); - // TODO: Remove this shit! - int MsgUser(const char * request); - int SendMessage(const char * login, const char * message, int prio); + int SendMessage(const char * request); int ServerInfo(); int CheckUser(const char * login, const char * password); @@ -120,10 +103,6 @@ private: std::string errorMsg; XML_Parser parser; - RecvSendMessageCb_t RecvSendMessageCb; - - void * sendMessageDataCb; - int Exec(const char * request); friend int AnsRecv(void * data, std::list * list); diff --git a/stglibs/srvconf.lib/parser.cpp b/stglibs/srvconf.lib/parser.cpp index 78247f48..2ebe9a91 100644 --- a/stglibs/srvconf.lib/parser.cpp +++ b/stglibs/srvconf.lib/parser.cpp @@ -39,43 +39,3 @@ using namespace std; -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE() - : RecvSendMessageCb(NULL), - sendMessageCbData(NULL), - depth(0) -{ -} -//----------------------------------------------------------------------------- -int PARSER_SEND_MESSAGE::ParseStart(const char *el, const char **attr) -{ -depth++; -if (depth == 1) - { - if (strcasecmp(el, "SendMessageResult") == 0) - { - ParseAnswer(el, attr); - } - } -return 0; -} -//----------------------------------------------------------------------------- -void PARSER_SEND_MESSAGE::ParseEnd(const char *) -{ -depth--; -} -//----------------------------------------------------------------------------- -void PARSER_SEND_MESSAGE::ParseAnswer(const char *, const char **attr) -{ -if (RecvSendMessageCb) - RecvSendMessageCb(attr[1], sendMessageCbData); -} -//----------------------------------------------------------------------------- -void PARSER_SEND_MESSAGE::SetSendMessageRecvCb(RecvSendMessageCb_t f, void * data) -{ -RecvSendMessageCb = f; -sendMessageCbData = data; -} -//----------------------------------------------------------------------------- diff --git a/stglibs/srvconf.lib/parser_send_message.cpp b/stglibs/srvconf.lib/parser_send_message.cpp new file mode 100644 index 00000000..77aba248 --- /dev/null +++ b/stglibs/srvconf.lib/parser_send_message.cpp @@ -0,0 +1,60 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#include "stg/parser_send_message.h" + +#include + +#include + +PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE() + : callback(NULL), + data(NULL), + depth(0) +{ +} +//----------------------------------------------------------------------------- +int PARSER_SEND_MESSAGE::ParseStart(const char * el, const char ** attr) +{ +depth++; +if (depth == 1) + if (strcasecmp(el, "SendMessageResult") == 0) + ParseAnswer(el, attr); +return 0; +} +//----------------------------------------------------------------------------- +void PARSER_SEND_MESSAGE::ParseEnd(const char * /*el*/) +{ +depth--; +} +//----------------------------------------------------------------------------- +void PARSER_SEND_MESSAGE::ParseAnswer(const char * /*el*/, const char **attr) +{ +if (attr && attr[0] && attr[1]) + if (callback) + callback(attr[1], data); +} +//----------------------------------------------------------------------------- +void PARSER_SEND_MESSAGE::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +} diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index b8507098..d48424e0 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -139,19 +139,6 @@ char request[] = ""; currParser = &parserGetUsers; -return Exec(request); -} -//----------------------------------------------------------------------------- -int SERVCONF::SendMessage(const char * login, const char * message, int prio) -{ -char request[1000]; -char msg[500]; -Encode12(msg, message, strlen(message)); -snprintf(request, 1000, "", login, prio, msg); - -currParser = &parserSendMessage; -parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb); - return Exec(request); } //----------------------------------------------------------------------------- @@ -171,12 +158,9 @@ currParser = &parserChgUser; return Exec(request); } //----------------------------------------------------------------------------- -// TODO: remove this shit! -//----------------------------------------------------------------------------- -int SERVCONF::MsgUser(const char * request) +int SERVCONF::SendMessage(const char * request) { currParser = &parserSendMessage; -parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb); return Exec(request); } @@ -191,13 +175,13 @@ currParser = &parserCheckUser; return Exec(request); } //----------------------------------------------------------------------------- -int SERVCONF::Start(const char *el, const char **attr) +int SERVCONF::Start(const char * el, const char ** attr) { currParser->ParseStart(el, attr); return 0; } //----------------------------------------------------------------------------- -void SERVCONF::End(const char *el) +void SERVCONF::End(const char * el) { currParser->ParseEnd(el); } @@ -232,10 +216,9 @@ void SERVCONF::SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data) parserCheckUser.SetCallback(f, data); } //----------------------------------------------------------------------------- -void SERVCONF::SetSendMessageCb(RecvSendMessageCb_t f, void * data) +void SERVCONF::SetSendMessageCallback(PARSER_SEND_MESSAGE::CALLBACK f, void * data) { -RecvSendMessageCb = f; -sendMessageDataCb = data; +parserSendMessage.SetCallback(f, data); } //----------------------------------------------------------------------------- const std::string & SERVCONF::GetStrError() const -- 2.44.2 From b263b465696c8cebe90a041061b0f162b46138e1 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 18 Aug 2013 12:46:39 +0300 Subject: [PATCH 14/16] Removed unused parser.cpp. --- stglibs/srvconf.lib/Makefile | 1 - stglibs/srvconf.lib/parser.cpp | 41 ---------------------------------- 2 files changed, 42 deletions(-) delete mode 100644 stglibs/srvconf.lib/parser.cpp diff --git a/stglibs/srvconf.lib/Makefile b/stglibs/srvconf.lib/Makefile index 296ae0f3..5cbc5d40 100644 --- a/stglibs/srvconf.lib/Makefile +++ b/stglibs/srvconf.lib/Makefile @@ -9,7 +9,6 @@ STGLIBS = -lstgcommon \ LIBS = -lexpat SRCS = netunit.cpp \ - parser.cpp \ parser_auth_by.cpp \ parser_server_info.cpp \ parser_check_user.cpp \ diff --git a/stglibs/srvconf.lib/parser.cpp b/stglibs/srvconf.lib/parser.cpp deleted file mode 100644 index 2ebe9a91..00000000 --- a/stglibs/srvconf.lib/parser.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.18 $ - $Date: 2010/08/04 00:40:00 $ - $Author: faust $ - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "stg/common.h" -#include "stg/const.h" -#include "stg/servconf.h" - -using namespace std; - -- 2.44.2 From 4d38b4974e27dded1c8d542da3f9ec9e5295fbaf Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 18 Aug 2013 12:56:51 +0300 Subject: [PATCH 15/16] Minor changes. --- projects/sgconf/common_sg.cpp | 4 ++-- stglibs/srvconf.lib/servconf.cpp | 25 ++++++------------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index ca1aa50c..38520c52 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -434,8 +434,8 @@ GetUserData cbdata(request, false); int res = 0; if (isMessage) { - sc.SetSendMessageCb(RecvSetUserAnswer, &cbdata); - res = sc.MsgUser(str.c_str()); + sc.SetSendMessageCallback(RecvSetUserAnswer, &cbdata); + res = sc.SendMessage(str.c_str()); } else { diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index d48424e0..f2498ef5 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -18,12 +18,6 @@ * Author : Boris Mikhailenko */ - /* - $Revision: 1.8 $ - $Date: 2010/08/04 00:40:38 $ - $Author: faust $ - */ - #include "stg/servconf.h" #include "stg/common.h" @@ -31,10 +25,8 @@ #include #include -using namespace std; - //----------------------------------------------------------------------------- -int AnsRecv(void * data, list * list1) +int AnsRecv(void * data, std::list * list1) { SERVCONF * sc = static_cast(data); @@ -46,7 +38,7 @@ char ans[ENC_MSG_LEN + 1]; int len, done = 0; //loop parsing -list::iterator node; +std::list::iterator node; node = list1->begin(); while (node != list1->end()) @@ -64,7 +56,6 @@ while (node != list1->end()) return st_xml_parse_error; } ++node; - } return st_ok; @@ -72,22 +63,18 @@ return st_ok; //----------------------------------------------------------------------------- void Start(void *data, const char *el, const char **attr) { -SERVCONF * sc; -sc = (SERVCONF*)data; +SERVCONF * sc = static_cast(data); sc->Start(el, attr); } //----------------------------------------------------------------------------- -void End(void *data, const char *el) +void End(void * data, const char * el) { -SERVCONF * sc; -sc = (SERVCONF*)data; +SERVCONF * sc = static_cast(data); sc->End(el); } //----------------------------------------------------------------------------- SERVCONF::SERVCONF() - : currParser(NULL), - RecvSendMessageCb(NULL), - sendMessageDataCb(NULL) + : currParser(NULL) { parser = XML_ParserCreate(NULL); nt.SetRxCallback(this, AnsRecv); -- 2.44.2 From 61b5cf35c82a5850ceb07fca5232a409e249444c Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 18 Aug 2013 13:16:42 +0300 Subject: [PATCH 16/16] Fixed error handling in SetUser. --- projects/sgconf/common_sg.cpp | 62 +++++++++++++++++------------------ projects/sgconf/common_sg.h | 5 ++- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index 38520c52..898c334f 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -25,21 +25,23 @@ */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "stg/common.h" #include "sg_error_codes.h" #include "common_sg.h" #include "version_sg.h" -using namespace std; +#include "stg/common.h" + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include const int usageConf = 0; const int usageInfo = 1; @@ -56,10 +58,10 @@ struct GetUserData //--------------------------------------------------------------------------- struct HelpParams { - string setActionName; - string getActionName; - string valueName; - string valueParam; + std::string setActionName; + std::string getActionName; + std::string valueName; + std::string valueParam; }; //--------------------------------------------------------------------------- void Usage(int usageType) @@ -168,7 +170,7 @@ short int ParseServerPort(const char * p) int port; if (str2x(p, port) != 0) { - printf("Incorresct server port %s\n", p); + printf("Incorrect server port %s\n", p); exit(NETWORK_ERR_CODE); } return (short)port; @@ -178,7 +180,7 @@ char * ParseAdminLogin(char * adm) { if (CheckLogin(adm)) { - printf("Incorresct admin login %s\n", adm); + printf("Incorrect admin login %s\n", adm); exit(PARAMETER_PARSING_ERR_CODE); } return adm; @@ -199,13 +201,13 @@ char * ParseUser(char * usr) { if (CheckLogin(usr)) { - printf("Incorresct user login %s\n", usr); + printf("Incorrect user login %s\n", usr); exit(PARAMETER_PARSING_ERR_CODE); } return usr; } //----------------------------------------------------------------------------- -void ConvertKOI8(const string & src, string * dst, int encType) +void ConvertKOI8(const std::string & src, std::string * dst, int encType) { iconv_t cd; char * ob = new char[src.size() * 2 + 1]; @@ -280,20 +282,17 @@ delete[] ob; delete[] ib; } //----------------------------------------------------------------------------- -void ConvertFromKOI8(const string & src, string * dst) +void ConvertFromKOI8(const std::string & src, std::string * dst) { ConvertKOI8(src, dst, FROM_KOI8); } //----------------------------------------------------------------------------- -void ConvertToKOI8(const string & src, string * dst) -{ -ConvertKOI8(src, dst, TO_KOI8); -} -//----------------------------------------------------------------------------- int RecvSetUserAnswer(const char * ans, void * d) { GetUserData * data = static_cast(d); +std::cout << ans << std::endl; + data->result = (strcasecmp("Ok", ans) == 0); return 0; @@ -301,9 +300,9 @@ return 0; //----------------------------------------------------------------------------- struct StringReqParams { - string name; - RESETABLE reqParam; - const string * value; + std::string name; + RESETABLE reqParam; + const std::string * value; }; //----------------------------------------------------------------------------- void GetUserCallback(const PARSER_GET_USER::INFO & info, void * d) @@ -377,7 +376,7 @@ for (int i = 0; i < USERDATA_NUM; i++) { if (!data->request.userData[i].res_empty()) { - string str; + std::string str; ConvertFromKOI8(info.userData[i], &str); cout << "user data " << i << " = " << str << endl; } @@ -443,7 +442,7 @@ else res = sc.ChgUser(str.c_str()); } -if (res && cbdata.result) +if (res == st_ok && cbdata.result) { printf("Ok\n"); return 0; @@ -451,6 +450,8 @@ if (res && cbdata.result) else { printf("Error\n"); + if (res != st_ok) + printf("%s\n", sc.GetStrError().c_str()); return -1; } @@ -471,7 +472,6 @@ sc.SetPort(port); sc.SetAdmLogin(admLogin.c_str()); sc.SetAdmPassword(admPasswd.c_str()); -// TODO Good variable name :) GetUserData data(request, false); sc.SetGetUserCallback(GetUserCallback, &data); diff --git a/projects/sgconf/common_sg.h b/projects/sgconf/common_sg.h index ca7eb36c..03090a76 100644 --- a/projects/sgconf/common_sg.h +++ b/projects/sgconf/common_sg.h @@ -28,11 +28,11 @@ #ifndef COMMON_SG_H #define COMMON_SG_H -#include - #include "stg/servconf.h" #include "request.h" +#include + void UsageConf(); void UsageInfo(); @@ -66,4 +66,3 @@ int ProcessSetUser(const std::string &server, bool isMessage = false); #endif - -- 2.44.2