X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/c9104229b3f6ee0320752780053ad97f5385359a..97f1f905311bcb76c3b500e3e49c1b9f49dff491:/projects/sgconf/main.cpp?ds=sidebyside diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index 76a47824..2c2a8a7b 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -34,21 +34,44 @@ #include #include #include -#include #include #include "stg/common.h" -#include "stg/netunit.h" #include "request.h" #include "common_sg.h" #include "sg_error_codes.h" -using namespace std; +namespace +{ -time_t stgTime; +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; +} -int ParseReplyGet(void * data, list * ans); -//int ParseReplySet(void * data, list * ans); +} // namespace anonymous + +time_t stgTime; struct option long_options_get[] = { {"server", 1, 0, 's'}, //Server @@ -455,7 +478,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 +488,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 +503,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 +614,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 +628,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 +661,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()) + { + su = true; + break; + } + } + +for (int i = 0; i < DIR_NUM; i++) + { + if (req->sessionDownload[i].res_empty()) + { + sd = true; + break; + } + } + +for (int i = 0; i < DIR_NUM; i++) + { + if (req->monthUpload[i].res_empty()) { - u = true; + mu = true; break; } } for (int i = 0; i < DIR_NUM; i++) { - if (req->d[i].res_empty()) + if (req->monthDownload[i].res_empty()) { - d = true; + md = true; break; } } for (int i = 0; i < DIR_NUM; i++) { - if (req->ud[i].res_empty()) + if (req->userData[i].res_empty()) { ud = true; break; @@ -634,7 +706,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) @@ -647,7 +719,7 @@ int CheckParametersSet(REQUEST * req) return CheckParameters(req); } //----------------------------------------------------------------------------- -int mainGet(int argc, char **argv) +bool mainGet(int argc, char **argv) { int c; REQUEST req; @@ -743,9 +815,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 +828,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 +855,6 @@ while (1) case '?': case ':': - //printf ("Unknown option \n"); missedOptionArg = true; break; @@ -809,12 +880,12 @@ 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); } //----------------------------------------------------------------------------- -int mainSet(int argc, char **argv) +bool mainSet(int argc, char **argv) { string str; @@ -955,35 +1026,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; @@ -1013,7 +1082,10 @@ char rstr[rLen]; memset(rstr, 0, rLen); CreateRequestSet(&req, rstr); -return ProcessSetUser(req.server, req.port, req.admLogin, req.admPasswd, rstr, NULL, isMessage); +if (isMessage) + return ProcessSendMessage(req.server, req.port, req.admLogin, req.admPasswd, rstr); + +return ProcessSetUser(req.server, req.port, req.admLogin, req.admPasswd, rstr); } //----------------------------------------------------------------------------- int main(int argc, char **argv) @@ -1032,7 +1104,9 @@ if (strcmp(argv[1], "get") == 0) else if (strcmp(argv[1], "set") == 0) { //printf("set\n"); - return mainSet(argc - 1, argv + 1); + if (mainSet(argc - 1, argv + 1) ) + return 0; + return -1; } else {