Add weeks in expiration textual representations
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 21 Sep 2018 07:28:39 +0000 (09:28 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 21 Sep 2018 07:28:39 +0000 (09:28 +0200)
Also set constants compliant to chump compilers.

Change-Id: Id22672f8077a9fe6377a10043efec3e78e8eb3a7
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/main-cynadm.c
src/main-cynarad.c

index e5318a1..fa44895 100644 (file)
@@ -33,9 +33,10 @@ char *str[40];
 int nstr;
 
 static const int MIN = 60;
-static const int HOUR = 60*MIN;
-static const int DAY = 24*HOUR;
-static const int YEAR = 365*DAY;
+static const int HOUR = 60*60;
+static const int DAY = 24*60*60;
+static const int WEEK = 7*24*60*60;
+static const int YEAR = 365*24*60*60;
 
 const char *client, *session, *user, *permission, *value;
 time_t expire;
@@ -56,6 +57,7 @@ time_t txt2exp(const char *txt)
                        x = 10 * x + (time_t)(*txt++ - '0');
                switch(*txt) {
                case 'y': r += x * YEAR; txt++; break;
+               case 'w': r += x * WEEK; txt++; break;
                case 'd': r += x *= DAY; txt++; break;
                case 'h': r += x *= HOUR; txt++; break;
                case 'm': r += x *= MIN; txt++; break;
@@ -81,6 +83,11 @@ const char *exp2txt(time_t expire)
                        (long long)(expire / YEAR));
                expire = expire % YEAR;
        }
+       if (expire >= WEEK) {
+               n += snprintf(&buffer[n], sizeof buffer - n, "%lldw",
+                       (long long)(expire / WEEK));
+               expire = expire % WEEK;
+       }
        if (expire >= DAY) {
                n += snprintf(&buffer[n], sizeof buffer - n, "%lldd",
                        (long long)(expire / DAY));
index 5744672..1829d74 100644 (file)
@@ -439,9 +439,10 @@ static void ensure_directory(const char *path, int uid, int gid)
 time_t txt2exp(const char *txt)
 {
        static const int MIN = 60;
-       static const int HOUR = 60*MIN;
-       static const int DAY = 24*HOUR;
-       static const int YEAR = 365*DAY;
+       static const int HOUR = 60*60;
+       static const int DAY = 24*60*60;
+       static const int WEEK = 7*24*60*60;
+       static const int YEAR = 365*24*60*60;
 
        time_t r, x;
 
@@ -454,6 +455,7 @@ time_t txt2exp(const char *txt)
                        x = 10 * x + (time_t)(*txt++ - '0');
                switch(*txt) {
                case 'y': r += x * YEAR; txt++; break;
+               case 'w': r += x *= WEEK; txt++; break;
                case 'd': r += x *= DAY; txt++; break;
                case 'h': r += x *= HOUR; txt++; break;
                case 'm': r += x *= MIN; txt++; break;