From: Maxim Mamontov Date: Wed, 9 Mar 2011 14:34:00 +0000 (+0200) Subject: Add support of -E key for sgconf (credit timeout) X-Git-Tag: 2.407-rc3~158^2 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/f204a070a53f7a2f05686d5ecad30da3fe2f0d27?hp=5622b5d1aa70abbdb3cc4a03f085f560eab06dbe Add support of -E key for sgconf (credit timeout) --- diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index 09fcfd77..1fc0685a 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -81,6 +81,7 @@ HelpParams hp[] = { {"set tariff", "get tariff", "-t", ""}, {"set credit", "get credit", "-r", ""}, + {"set credit expire", "get credit expire", "-E", ""}, {"set password", "get password", "-o", ""}, {"set prepaid traffic", "get prepaid traffic", "-e", ""}, {"set IP-addresses", "get IP-addresses", "-I", "<*|ip_addr[,ip_addr...]>"}, @@ -330,6 +331,26 @@ if (!req->cash.res_empty()) if (!req->credit.res_empty()) cout << "credit=" << ud->credit << endl; +if (!req->creditExpire.res_empty()) + { + char buf[32]; + struct tm brokenTime; + time_t tt = ud->creditExpire; + + brokenTime.tm_wday = 0; + brokenTime.tm_yday = 0; + brokenTime.tm_isdst = 0; + brokenTime.tm_hour = 0; + brokenTime.tm_min = 0; + brokenTime.tm_sec = 0; + + gmtime_r(&tt, &brokenTime); + + strftime(buf, 32, "%Y-%m-%d", &brokenTime); + + cout << "creditExpire=" << buf << endl; + } + if (!req->down.res_empty()) cout << "down=" << ud->down << endl; @@ -475,5 +496,3 @@ else return 0; } //----------------------------------------------------------------------------- - - diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index ce8af73f..ec7dadc7 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -312,6 +312,22 @@ delete[] s; return ss; } //----------------------------------------------------------------------------- +time_t ParseCreditExpire(const char * str) +{ +struct tm brokenTime; + +brokenTime.tm_wday = 0; +brokenTime.tm_yday = 0; +brokenTime.tm_isdst = 0; +brokenTime.tm_hour = 0; +brokenTime.tm_min = 0; +brokenTime.tm_sec = 0; + +stg_strptime(str, "%Y-%m-%d", &brokenTime); + +return stg_timegm(&brokenTime); +} +//----------------------------------------------------------------------------- void ParseAnyString(const char * c, string * msg, const char * enc) { iconv_t cd; @@ -419,6 +435,12 @@ if (!req->credit.res_empty()) strcat(r, str); } +if (!req->creditExpire.res_empty()) + { + sprintf(str, "\n", req->creditExpire.const_data()); + strcat(r, str); + } + if (!req->prepaidTraff.res_empty()) { sprintf(str, "\n", req->prepaidTraff.const_data()); @@ -681,7 +703,7 @@ REQUEST req; RESETABLE t1; int missedOptionArg = false; -const char * short_options_get = "s:p:a:w:u:crtmodieNADLPGISO"; +const char * short_options_get = "s:p:a:w:u:crtmodieNADLPGISOE"; int option_index = -1; while (1) @@ -726,6 +748,10 @@ while (1) req.credit = 1; break; + case 'E': //credit expire + req.creditExpire = 1; + break; + case 'd': //down req.down = 1; break; @@ -860,7 +886,7 @@ REQUEST req; RESETABLE t1; -const char * short_options_set = "s:p:a:w:u:c:r:t:m:o:d:i:e:v:nlN:A:D:L:P:G:I:S:O:"; +const char * short_options_set = "s:p:a:w:u:c:r:t:m:o:d:i:e:v:nlN:A:D:L:P:G:I:S:O:E:"; int missedOptionArg = false; @@ -912,6 +938,10 @@ while (1) req.credit = ParseCredit(optarg); break; + case 'E': //credit expire + req.creditExpire = ParseCreditExpire(optarg); + break; + case 'd': //down req.down = ParseDownPassive(optarg); break; diff --git a/projects/sgconf/request.h b/projects/sgconf/request.h index 2f2408ca..6878f656 100644 --- a/projects/sgconf/request.h +++ b/projects/sgconf/request.h @@ -77,6 +77,7 @@ bool deleteUser; RESETABLE usrMsg; RESETABLE credit; +RESETABLE creditExpire; RESETABLE usrPasswd; RESETABLE down; RESETABLE passive; diff --git a/stglibs/srvconf.lib/parser.cpp b/stglibs/srvconf.lib/parser.cpp index 139c91bc..89b2457c 100644 --- a/stglibs/srvconf.lib/parser.cpp +++ b/stglibs/srvconf.lib/parser.cpp @@ -165,6 +165,14 @@ if (strcasecmp(el, "credit") == 0) } } +if (strcasecmp(el, "creditExpire") == 0) + { + if (str2x(attr[1], user.creditExpire) < 0) + { + return; + } + } + /*if (strcasecmp(el, "freemb") == 0) { if (strtodouble2(attr[1], user.freeMb) < 0) @@ -518,6 +526,14 @@ if (strcasecmp(el, "currip") == 0) user.ip = inet_addr(attr[1]); } +if (strcasecmp(el, "creditExpire") == 0) + { + if (str2x(attr[1], user.creditExpire) < 0) + { + return; + } + } + for (int i = 0; i < USERDATA_NUM; i++) { string num; diff --git a/stglibs/srvconf.lib/servconf.h b/stglibs/srvconf.lib/servconf.h index 9edbe6dd..29151d62 100644 --- a/stglibs/srvconf.lib/servconf.h +++ b/stglibs/srvconf.lib/servconf.h @@ -72,6 +72,7 @@ struct USERDATA std::string password; double cash; double credit; + time_t creditExpire; double lastCash; double prepaidTraff; int down;