From 23d052c42f43430e4ff776a80b9643dbc7d1289d Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 9 Aug 2013 21:04:49 +0300 Subject: [PATCH 1/1] 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