cookie-expire-time
authorSébastien Marie <semarie@users.noreply.github.com>
Sun, 19 Oct 2014 04:41:25 +0000 (06:41 +0200)
committerSébastien Marie <semarie@users.noreply.github.com>
Sun, 19 Oct 2014 15:55:34 +0000 (17:55 +0200)
- document new cookie feature and configuration setting

- add configuration setting

- small refactoring in cookie handling
  - first manage cookie-expire-time
  - and next, cookie-timeout

- convert cookie to session-cookie if cookie-expire-time=0
- enforce expire-time if cookie-expire-time>0

doc/vimb.1
src/cookiejar.c
src/main.h
src/setting.c

index 593ce90..94a00e3 100644 (file)
@@ -1108,6 +1108,13 @@ cookies)}.
 .B cookie-timeout (int)
 Cookie timeout in seconds.
 .TP
+.B cookie-expire-time (int)
+Enforce expire-time on cookies. The default value `-1' keep expire-time as
+defined by server side. The value `0' convert all cookies as session-only
+cookies (`cookie-timeout' setting is used as for any other session-cookie). Any
+other value enforce the expire-time (the expire-time value will be the lower
+between server-side request and time defined with `cookie-expire-time').
+.TP
 .B download-command (string)
 A command with placeholder '%s' that will be invoked to download a uri.
 .RS
index af82b5a..44b6dd9 100644 (file)
@@ -49,10 +49,25 @@ static void cookiejar_changed(SoupCookieJar *self, SoupCookie *old_cookie, SoupC
 {
     FLOCK(COOKIEJAR(self)->lock, F_WRLCK);
     SoupDate *expire;
-    if (new_cookie && !new_cookie->expires && vb.config.cookie_timeout) {
-        expire = soup_date_new_from_now(vb.config.cookie_timeout);
-        soup_cookie_set_expires(new_cookie, expire);
-        soup_date_free(expire);
+    if (new_cookie) {
+       /* session-expire-time handling */
+       if (vb.config.cookie_expire_time == 0) {
+           soup_cookie_set_expires(new_cookie, NULL);
+
+       } else if (vb.config.cookie_expire_time > 0 && new_cookie->expires) {
+           expire = soup_date_new_from_now(vb.config.cookie_expire_time);
+           if (soup_date_to_time_t(expire) < soup_date_to_time_t(new_cookie->expires)) {
+               soup_cookie_set_expires(new_cookie, expire);
+           }
+           soup_date_free(expire);
+       }
+
+       /* session-cookie handling */
+       if (!new_cookie->expires && vb.config.cookie_timeout) {
+           expire = soup_date_new_from_now(vb.config.cookie_timeout);
+           soup_cookie_set_expires(new_cookie, expire);
+           soup_date_free(expire);
+       }
     }
     SOUP_COOKIE_JAR_CLASS(cookiejar_parent_class)->changed(self, old_cookie, new_cookie);
     FLOCK(COOKIEJAR(self)->lock, F_UNLCK);
index 5f2e7d9..5a93bde 100644 (file)
@@ -309,6 +309,7 @@ typedef struct {
 typedef struct {
 #ifdef FEATURE_COOKIE
     time_t       cookie_timeout;
+    int                 cookie_expire_time;
 #endif
     int          scrollstep;
     char         *download_dir;
index 897d187..bcb07ff 100644 (file)
@@ -163,6 +163,8 @@ void setting_init()
     setting_add("cookie-accept", TYPE_CHAR, &"always", cookie_accept, 0, NULL);
     i = 4800;
     setting_add("cookie-timeout", TYPE_INTEGER, &i, internal, 0, &vb.config.cookie_timeout);
+    i = -1;
+    setting_add("cookie-expire-time", TYPE_INTEGER, &i, internal, 0, &vb.config.cookie_expire_time);
 #endif
     setting_add("strict-ssl", TYPE_BOOLEAN, &on, soup, 0, "ssl-strict");
     setting_add("strict-focus", TYPE_BOOLEAN, &off, internal, 0, &vb.config.strict_focus);