Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement saving cookies

  • Loading branch information...
commit 12b0591ed2b5c65574eda699cbf5396bf89e8940 1 parent cc3a141
@age age authored
View
3  .gitignore
@@ -1,2 +1,3 @@
uzbl
-uzblctrl
+uzblctrl
+examples/data
View
2  Makefile
@@ -1,4 +1,4 @@
-CPPFLAGS=$(shell pkg-config --cflags gtk+-2.0 webkit-1.0) -Wall -W -std=c99 -pedantic
+CPPFLAGS=$(shell pkg-config --cflags gtk+-2.0 webkit-1.0) -Wall -W
LDFLAGS=$(shell pkg-config --libs gtk+-2.0 webkit-1.0)
all: uzbl uzblctrl
View
62 examples/scripts/cookies.sh
@@ -1,62 +1,2 @@
#!/bin/bash
-# this is an example script of how you could manage your cookies..
-# you probably want your cookies config file in your $XDG_CONFIG_HOME ( eg $HOME/.config/uzbl/cookies)
-
-# MAYBE TODO: allow user to edit cookie before saving. this cannot be done with zenity :(
-# TODO: different cookie paths per config (eg per group of uzbl instances)
-
-if [ -f /usr/share/uzbl/examples/configs/cookies ]
-then
- file=/usr/share/uzbl/examples/configs/cookies
-else
- file=./examples/configs/cookies #useful when developing
-fi
-
-if [ -d $XDG_DATA_HOME/uzbl/cookies ]
-then
- cookie_dir=$XDG_DATA_HOME/uzbl/cookies
-else
- cookie_dir=./examples/data
-fi
-
-which zenity &>/dev/null || exit 2
-
-uri=$6
-action=$8 # GET/PUT
-host=${uri/\/*/}
-
-
-
-# $1 = section (TRUSTED or DENY)
-# $2 =url
-function match () {
- sed -n "/$1/,/^\$/p" $file 2>/dev/null | grep -q "^$host"
-}
-
-function readcookie () {
- cookie=
- while read
- do
- cookie="$REPLY
-"
- done
-}
-
-function fetch_cookie () {
- cookie=`cat $cookie_dir/$host.cookie`
-}
-
-function store_cookie () {
- echo $cookie > $cookie_dir/$host.cookie
-}
-
-if match TRUSTED $host
-then
- [ $action == PUT ] && readcookie && store_cookie $host
- [ $action == GET ] && fetch_cookie && echo "$cookie"
-elif ! match DENY $host
-then
- [ $action == PUT ] && readcookie && zenity --question --title 'Uzbl Cookie handler' --text "Accept cookie from $host ? Contents:\n$cookie" && store_cookie $host
- [ $action == GET ] && fetch_cookie && zenity --question --title 'Uzbl Cookie handler' --text "Submit cookie to $host ? Contents:\n$cookie" && echo $cookie
-fi
-exit 0
+echo $8 - $9
View
15 uzbl.c
@@ -862,7 +862,8 @@ settings_init () {
static void handle_cookies (SoupSession *session,
SoupMessage *msg,
gpointer user_data){
- soup_message_add_header_handler(msg, "got-headers", "Set-Cookie", G_CALLBACK(save_cookies));
+ soup_message_add_header_handler(msg, "got-headers", "Set-Cookie", G_CALLBACK(save_cookies), NULL);
+
/* ask handler for cookies, if there are any, use
soup_message_headers_replace (msg->request_headers,
"Cookie", cookies);
@@ -873,7 +874,17 @@ static void handle_cookies (SoupSession *session,
static void
save_cookies (SoupMessage *msg,
gpointer user_data){
- /* give them to handler */
+ GSList *ck;
+ char *req, *cookie;
+ for (ck = soup_cookies_from_response(msg); ck; ck = ck->next){
+ cookie = soup_cookie_to_set_cookie_header(ck->data);
+ req = malloc(strlen(cookie) + 10);
+ sprintf(req, "PUT \"%s\"", cookie);
+ run_command_async(cookie_handler, req);
+ free(req);
+ free(cookie);
+ }
+ g_slist_free(ck);
}
int
View
19 uzbl.h
@@ -111,10 +111,17 @@ settings_init ();
/* SoupCookie *old_cookie, */
/* SoupCookie *new_cookie, */
/* gpointer user_data); */
-static void
-catch_cookies (SoupSession *session,
- SoupMessage *msg,
- gpointer user_data);
- /* SoupSocket *socket, */
- /* gpointer user_data); */
+/* static void */
+/* catch_cookies (SoupSession *session, */
+/* SoupMessage *msg, */
+/* gpointer user_data); */
+/* /\* SoupSocket *socket, *\/ */
+/* /\* gpointer user_data); *\/ */
+
+static void handle_cookies (SoupSession *session,
+ SoupMessage *msg,
+ gpointer user_data);
+static void
+save_cookies (SoupMessage *msg,
+ gpointer user_data);
/* vi: set et ts=4: */
Please sign in to comment.
Something went wrong with that request. Please try again.