changeset 1612:3eb2cd09244d

use tm for max-age
author corvid <corvid@lavabit.com>
date Wed, 10 Mar 2010 03:04:45 +0000
parents 0c8aeadcead3
children 0f26b1d4ac2e
files dpi/cookies.c
diffstat 1 files changed, 6 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/dpi/cookies.c	Wed Mar 10 02:47:51 2010 +0000
+++ b/dpi/cookies.c	Wed Mar 10 03:04:45 2010 +0000
@@ -62,8 +62,6 @@
 #define _MSG(...)
 #define MSG(...)  printf("[cookies dpi]: " __VA_ARGS__)
 
-#define DILLO_TIME_MAX ((time_t) ((1UL << (sizeof(time_t) * 8 - 1)) - 1))
-
 /*
  * a_List_add()
  *
@@ -739,13 +737,14 @@
          if (isdigit(*value) || *value == '-') {
             time_t now = time(NULL);
             long age = strtol(value, NULL, 10);
+            struct tm *tm = gmtime(&now);
 
-            cookie->expires_at = now + age;
-            if (age > 0 &&
-                difftime(cookie->expires_at, cookies_epoch_time) < 0) {
-               /* handle overflow */
-               cookie->expires_at = DILLO_TIME_MAX;
+            tm->tm_sec += age;
+            cookie->expires_at = mktime(tm);
+            if (age > 0 && cookie->expires_at == (time_t) -1) {
+               cookie->expires_at = cookies_future_time;
             }
+            MSG("Cookie to expire at %s", ctime(&cookie->expires_at));
             expires = max_age = TRUE;
          }
          dFree(value);