[hackers] [surf] minimal cookie implementation. still using also old one. || Enno Boland (tox)

From: <hg_AT_suckless.org>
Date: Sun, 6 Sep 2009 11:14:24 +0000 (UTC)

changeset: 49:0ab6436bf28f
tag: tip
user: Enno Boland (tox) <tox_AT_s01.de>
date: Sun Sep 06 13:15:53 2009 +0200
files: surf.c
description:
minimal cookie implementation. still using also old one.

diff -r 4b3a487ea1f7 -r 0ab6436bf28f surf.c
--- a/surf.c Sun Sep 06 10:56:09 2009 +0200
+++ b/surf.c Sun Sep 06 13:15:53 2009 +0200
@@ -28,8 +28,19 @@
         gint progress;
         struct Client *next;
 } Client;
+
+typedef struct Cookie {
+ char *name;
+ char *value;
+ char *domain;
+ char *path;
+ struct Cookie *next;
+} Cookie;
+
 SoupCookieJar *cookiejar;
+SoupSession *session;
 Client *clients = NULL;
+Cookie *cookies = NULL;
 gboolean embed = FALSE;
 gboolean showxid = FALSE;
 gboolean ignore_once = FALSE;
@@ -37,6 +48,7 @@
 extern int optind;
 
 static void cleanup(void);
+static void proccookies(SoupMessage *m, Client *c);
 static void destroyclient(Client *c);
 static void destroywin(GtkWidget* w, Client *c);
 static void die(char *str);
@@ -56,11 +68,14 @@
 static void pasteurl(GtkClipboard *clipboard, const gchar *text, gpointer d);
 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
 static void progresschange(WebKitWebView *view, gint p, Client *c);
+static void request(SoupSession *s, SoupMessage *m, Client *c);
+static void setcookie(char *name, char *val, char *dom, char *path, long exp);
 static void setup(void);
 static void showsearch(Client *c);
 static void showurl(Client *c);
 static void stop(Client *c);
-static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, const gchar* title, Client *c);
+static void titlechange(WebKitWebView* view, WebKitWebFrame* frame,
+ const gchar* title, Client *c);
 static void usage();
 static void updatetitle(Client *c, const gchar *title);
 
@@ -71,6 +86,20 @@
 }
 
 void
+proccookies(SoupMessage *m, Client *c) {
+ GSList *l;
+ SoupCookie *co;
+ long t;
+
+ for (l = soup_cookies_from_response(m); l; l = l->next){
+ co = (SoupCookie *)l->data;
+ t = co->expires ? soup_date_to_time_t(co->expires) : 0;
+ setcookie(co->name, co->value, co->domain, co->value, t);
+ }
+ g_slist_free(l);
+}
+
+void
 destroyclient(Client *c) {
         Client *p;
 
@@ -355,6 +384,7 @@
         g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c);
         g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(newwindow), c);
         g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c);
+ g_signal_connect_after(session, "request-started", G_CALLBACK(request), c);
 
         /* urlbar */
         c->urlbar = gtk_entry_new();
@@ -441,8 +471,21 @@
         updatetitle(c, NULL);
 }
 
-void setup(void) {
+void
+request(SoupSession *s, SoupMessage *m, Client *c) {
+ soup_message_add_header_handler(m, "got-headers", "Set-Cookie",
+ G_CALLBACK(proccookies), c);
+}
+
+void
+setcookie(char *name, char *val, char *dom, char *path, long exp) {
+ printf("%s %s %s %s %li\n", name, val, dom, path, exp);
+}
+
+void
+setup(void) {
         dpy = GDK_DISPLAY();
+ session = webkit_get_default_session();
         urlprop = XInternAtom(dpy, "_SURF_URL", False);
 }
 
Received on Sun Sep 06 2009 - 11:14:24 UTC

This archive was generated by hypermail 2.2.0 : Sun Sep 06 2009 - 11:24:05 UTC