From 04a5223d6abb42c42acc31c8b50ed11a049c59db Mon Sep 17 00:00:00 2001 From: keis Date: Tue, 30 Nov 2010 21:45:57 +0100 Subject: cookies rework * send events on cookie changes * add command to add a new cookie parses same syntax as events no ADD_COOKIE event is raised for these cookies * add command to delete a cookie parses same syntax as events, ignoring everything after 5th argument no DELETE_COOKIE event is raised for these cookies --- src/cookie-jar.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/cookie-jar.c') diff --git a/src/cookie-jar.c b/src/cookie-jar.c index f2e340b..626e454 100644 --- a/src/cookie-jar.c +++ b/src/cookie-jar.c @@ -12,6 +12,7 @@ #include "cookie-jar.h" #include "uzbl-core.h" +#include "events.h" static void uzbl_cookie_jar_session_feature_init(SoupSessionFeatureInterface *iface, gpointer user_data); @@ -38,6 +39,8 @@ soup_cookie_jar_socket_init(UzblCookieJar *jar) { jar->handler = NULL; jar->socket_path = NULL; jar->connection_fd = -1; + jar->in_get_callback = 0; + jar->in_manual_add = 0; } static void @@ -141,7 +144,7 @@ request_started(SoupSessionFeature *feature, SoupSession *session, static void changed(SoupCookieJar *jar, SoupCookie *old_cookie, SoupCookie *new_cookie) { - (void) old_cookie; + SoupCookie * cookie = new_cookie ? new_cookie : old_cookie; UzblCookieJar *uzbl_jar = UZBL_COOKIE_JAR(jar); @@ -155,6 +158,25 @@ changed(SoupCookieJar *jar, SoupCookie *old_cookie, SoupCookie *new_cookie) { if(uzbl_jar->in_get_callback) return; + gchar *scheme = cookie->secure ? "https" : "http"; + + /* send a ADD or DELETE -_COOKIE event depending on what have changed */ + if(!uzbl_jar->in_manual_add) { + gchar *expires = NULL; + if(cookie->expires) + expires = g_strdup_printf ("%d", soup_date_to_time_t (cookie->expires)); + + gchar * eventstr = g_strdup_printf ("'%s' '%s' '%s' '%s' '%s' '%s'", + cookie->domain, cookie->path, cookie->name, cookie->value, scheme, expires?expires:""); + if(new_cookie) + send_event(ADD_COOKIE, eventstr, NULL); + else + send_event(DELETE_COOKIE, eventstr, NULL); + g_free(eventstr); + if(expires) + g_free(expires); + } + /* the cookie daemon is only interested in new cookies and changed ones, it can take care of deleting expired cookies on its own. */ if(!new_cookie) @@ -162,8 +184,6 @@ changed(SoupCookieJar *jar, SoupCookie *old_cookie, SoupCookie *new_cookie) { GString *s = g_string_new ("PUT"); - gchar *scheme = new_cookie->secure ? "https" : "http"; - if(has_socket_handler(uzbl_jar)) { g_string_append_c(s, 0); /* null-terminate the PUT */ g_string_append_len(s, scheme, strlen(scheme)+1); -- cgit v1.2.3