From 620f79b3d022a59bec20c2d39be9f93b366d57fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Marie?= Date: Sun, 19 Oct 2014 06:41:25 +0200 Subject: [PATCH] cookie-expire-time - 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 | 7 +++++++ src/cookiejar.c | 23 +++++++++++++++++++---- src/main.h | 1 + src/setting.c | 2 ++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/doc/vimb.1 b/doc/vimb.1 index 593ce90..94a00e3 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -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 diff --git a/src/cookiejar.c b/src/cookiejar.c index af82b5a..44b6dd9 100644 --- a/src/cookiejar.c +++ b/src/cookiejar.c @@ -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); diff --git a/src/main.h b/src/main.h index 5f2e7d9..5a93bde 100644 --- a/src/main.h +++ b/src/main.h @@ -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; diff --git a/src/setting.c b/src/setting.c index 897d187..bcb07ff 100644 --- a/src/setting.c +++ b/src/setting.c @@ -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); -- 2.20.1