]> git.stg.codes - stg.git/commitdiff
Add creditExpire setting/getting via sgconf
authorMaxim Mamontov <faust@gts.dp.ua>
Fri, 4 Mar 2011 16:23:44 +0000 (18:23 +0200)
committerMaxim Mamontov <faust@gts.dp.ua>
Fri, 4 Mar 2011 16:23:44 +0000 (18:23 +0200)
projects/sgconf/common_sg.cpp
projects/sgconf/main.cpp
projects/sgconf/request.h
stglibs/srvconf.lib/parser.cpp
stglibs/srvconf.lib/servconf.h

index 09fcfd776cbe618c3dbd9e47557997f516e1916f..1fc0685a83699ca451157b0312c7455dbf076ce3 100644 (file)
@@ -81,6 +81,7 @@ HelpParams hp[] =
 {
     {"set tariff",              "get tariff",           "-t",   "<tariff:now|delayed>"},
     {"set credit",              "get credit",           "-r",   "<credit>"},
+    {"set credit expire",       "get credit expire",    "-E",   "<credit_expire_date>"},
     {"set password",            "get password",         "-o",   "<new_password>"},
     {"set prepaid traffic",     "get prepaid traffic",  "-e",   "<prepaid>"},
     {"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;
 }
 //-----------------------------------------------------------------------------
-
-
index ce8af73f7cbae348e8b9411598b1069b1e7324b1..ec7dadc77b1a7479e143d2b7959702389ec2626f 100644 (file)
@@ -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, "<creditExpire value=\"%ld\"/>\n", req->creditExpire.const_data());
+    strcat(r, str);
+    }
+
 if (!req->prepaidTraff.res_empty())
     {
     sprintf(str, "<FreeMb value=\"%f\"/>\n", req->prepaidTraff.const_data());
@@ -681,7 +703,7 @@ REQUEST req;
 RESETABLE<string>   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<string>   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;
index 2f2408caaea5925ce7dfeff9abe19ede09e5f0aa..6878f6562fe590bdd6f46f7e5a43d458b8a2a3c7 100644 (file)
@@ -77,6 +77,7 @@ bool                deleteUser;
 
 RESETABLE<string>   usrMsg;
 RESETABLE<double>   credit;
+RESETABLE<time_t>   creditExpire;
 RESETABLE<string>   usrPasswd;
 RESETABLE<bool>     down;
 RESETABLE<bool>     passive;
index 139c91bc6dc0a1b775ec11df1977523cda393498..89b2457cc1de9830604645e5e7d5eedf081008ed 100644 (file)
@@ -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;
index 9edbe6dd0016127a383b337597bebd7014834b6e..29151d62b4b59ad2912cf319e9f867b72b99806d 100644 (file)
@@ -72,6 +72,7 @@ struct USERDATA
     std::string     password;
     double          cash;
     double          credit;
+    time_t          creditExpire;
     double          lastCash;
     double          prepaidTraff;
     int             down;