From: Enno Boland (tox) Date: Tue, 20 Oct 2009 17:51:14 +0000 (+0200) Subject: using another way to handle cookies. X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=f277dbd3d2493c019ed341f62ac6d16c09a806bc;p=surf.git using another way to handle cookies. --- f277dbd3d2493c019ed341f62ac6d16c09a806bc diff --cc surf.c index 6c386fa,49c7c34..dca14de --- a/surf.c +++ b/surf.c @@@ -62,12 -62,14 +62,15 @@@ typedef struct static Display *dpy; static Atom uriprop; -static SoupCookieJar *cookiejar; ++static SoupCookieJar *cookies; + static SoupSession *session; static Client *clients = NULL; static GdkNativeWindow embed = 0; static gboolean showxid = FALSE; static gboolean ignore_once = FALSE; static char winid[64]; static char *progname; ++static gboolean lockcookie = FALSE; static const char *autouri(Client *c); static char *buildpath(const char *path); @@@ -100,10 -104,9 +104,9 @@@ static void pasteuri(GtkClipboard *clip static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d); static void print(Client *c, const Arg *arg); static void progresschange(WebKitWebView *v, gint p, Client *c); ++static void reloadcookies(); static void reload(Client *c, const Arg *arg); - static void request(SoupSession *s, SoupMessage *m, gpointer p); -static void reloadcookie(); static void sigchld(int unused); - static void setcookie(SoupMessage *m, gpointer p); static void setup(void); static void spawn(Client *c, const Arg *arg); static void scroll(Client *c, const Arg *arg); @@@ -153,6 -156,18 +156,27 @@@ buildpath(const char *path) return apath; } + void -changecookie(SoupCookieJar *jar, SoupCookie *oc, SoupCookie *c, gpointer p) { ++changecookie(SoupCookieJar *j, SoupCookie *oc, SoupCookie *c, gpointer p) { + SoupDate *e; ++ SoupCookieJar *jar; + ++ if(lockcookie) ++ return; + 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); + } ++ ++ jar = soup_cookie_jar_text_new(cookiefile, FALSE); ++ if(c) ++ soup_cookie_jar_add_cookie(jar, soup_cookie_copy(c)); ++ else ++ soup_cookie_jar_delete_cookie(jar, oc); ++ g_object_unref(jar); + } + void cleanup(void) { while(clients) @@@ -396,6 -407,11 +416,8 @@@ loadcommit(WebKitWebView *view, WebKitW XChangeProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), uriprop, XA_STRING, 8, PropModeReplace, (unsigned char *)uri, strlen(uri) + 1); -} + -void -loadfinished(WebKitWebView *v, WebKitWebFrame *f, Client *c) { - reloadcookie(); ++ reloadcookies(); } void @@@ -622,6 -640,16 +644,23 @@@ reload(Client *c, const Arg *arg) webkit_web_view_reload(c->view); } + void -reloadcookie(void) { - SoupSession *s; - - /* This forces the cookie to be written to hdd */ - s = webkit_get_default_session(); - soup_session_remove_feature(s, SOUP_SESSION_FEATURE(cookiejar)); - soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar)); -} ++reloadcookies() { ++ SoupCookieJar *jar; ++ GSList *l, *e; ++ ++ lockcookie = TRUE; ++ for(l = e = soup_cookie_jar_all_cookies(cookies); e; e = e->next) ++ soup_cookie_jar_delete_cookie(cookies, (SoupCookie *)e->data); ++ soup_cookies_free(l); ++ jar = soup_cookie_jar_text_new(cookiefile, TRUE); ++ for(l = e = soup_cookie_jar_all_cookies(jar); e; e = e->next) ++ soup_cookie_jar_add_cookie(cookies, (SoupCookie *)e->data); ++ g_slist_free(l); ++ lockcookie = FALSE; ++ g_object_unref(jar); ++} + void scroll(Client *c, const Arg *arg) { gdouble v; @@@ -699,7 -692,9 +703,10 @@@ setup(void) /* cookie persistance */ s = webkit_get_default_session(); - g_signal_connect_after(s, "request-queued", G_CALLBACK(request), NULL); - 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); ++ cookies = soup_cookie_jar_new(); ++ soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookies)); ++ g_signal_connect(cookies, "changed", G_CALLBACK(changecookie), NULL); ++ reloadcookies(); } void