[hackers] [surf] using events for changing cookies || Enno Boland (tox)

From: <hg_AT_suckless.org>
Date: Sat, 17 Oct 2009 11:16:59 +0000 (UTC)

changeset: 133:18dd74d2564d
tag: tip
user: Enno Boland (tox) <tox_AT_s01.de>
date: Sat Oct 17 13:19:21 2009 +0200
files: surf.c
description:
using events for changing cookies

diff -r 9934372b17ad -r 18dd74d2564d surf.c
--- a/surf.c Sat Oct 17 12:41:40 2009 +0200
+++ b/surf.c Sat Oct 17 13:19:21 2009 +0200
@@ -73,6 +73,7 @@
 
 static const char *autouri(Client *c);
 static char *buildpath(const char *path);
+static void changecookie(SoupCookieJar *jar, SoupCookie *o, SoupCookie *n, gpointer p);
 static void cleanup(void);
 static void clipboard(Client *c, const Arg *arg);
 static void context(WebKitWebView *v, GtkMenu *m, Client *c);
@@ -156,6 +157,18 @@
 }
 
 void
+changecookie(SoupCookieJar *jar, SoupCookie *oc, SoupCookie *c, gpointer p) {
+ SoupDate *e;
+
+ if(c && c->expires == NULL) {
+ e = soup_date_new_from_time_t(time(NULL) + sessiontime);
+ c = soup_cookie_copy(c);
+ soup_cookie_set_expires(c, e);
+ soup_cookie_jar_add_cookie(cookiejar, c);
+ }
+}
+
+void
 cleanup(void) {
         while(clients)
                 destroyclient(clients);
@@ -630,22 +643,8 @@
 
 void
 reloadcookie(void) {
- GSList *p, *l;
- SoupCookie *c;
         SoupSession *s;
- SoupDate *e;
 
- e = soup_date_new_from_time_t(time(NULL) + sessiontime);
- for(l = p = soup_cookie_jar_all_cookies(cookiejar); p; p = p->next) {
- c = (SoupCookie *)l->data;
- if(c->expires == NULL) {
- soup_cookie_set_expires(c, e);
- soup_cookie_jar_add_cookie(cookiejar,
- soup_cookie_copy(c));
- }
- }
- soup_cookies_free(l);
- soup_date_free(e);
         /* This forces the cookie to be written to hdd */
         s = webkit_get_default_session();
         soup_session_remove_feature(s, SOUP_SESSION_FEATURE(cookiejar));
@@ -696,6 +695,7 @@
         s = webkit_get_default_session();
         cookiejar = soup_cookie_jar_text_new(cookiefile, FALSE);
         soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
+ g_signal_connect(cookiejar, "changed", G_CALLBACK(changecookie), NULL);
 }
 
 void
Received on Sat Oct 17 2009 - 11:16:59 UTC

This archive was generated by hypermail 2.2.0 : Sat Oct 17 2009 - 11:24:05 UTC