aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cookie-jar.c
diff options
context:
space:
mode:
authorGravatar Brendan Taylor <whateley@gmail.com>2010-10-31 18:16:17 -0600
committerGravatar Brendan Taylor <whateley@gmail.com>2010-10-31 18:16:17 -0600
commit877e5dace26fd6482f56f211082492eac48cc588 (patch)
treefc90ef9897a14cfcff9bfaa24effaa63b85c336e /src/cookie-jar.c
parent5ed250ef5aafaaa578db68deae228f0af9cbda14 (diff)
if no handler is set, fall back to the internal soup cookie jar
Diffstat (limited to 'src/cookie-jar.c')
-rw-r--r--src/cookie-jar.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/cookie-jar.c b/src/cookie-jar.c
index 4bb1925..cd8e4b8 100644
--- a/src/cookie-jar.c
+++ b/src/cookie-jar.c
@@ -35,6 +35,7 @@ static bool has_socket_handler(UzblCookieJar *jar) {
static void
soup_cookie_jar_socket_init(UzblCookieJar *jar) {
+ jar->handler = NULL;
jar->socket_path = NULL;
jar->connection_fd = -1;
}
@@ -97,33 +98,43 @@ static void
request_started(SoupSessionFeature *feature, SoupSession *session,
SoupMessage *msg, SoupSocket *socket) {
(void) session; (void) socket;
+ gchar *cookies;
UzblCookieJar *jar = UZBL_COOKIE_JAR (feature);
SoupURI *uri = soup_message_get_uri(msg);
+ gboolean add_to_internal_jar = false;
- gchar *cookies = get_cookies(jar, uri);
+ if(jar->handler) {
+ cookies = get_cookies(jar, uri);
+ } else {
+ /* no handler is set, fall back to the internal soup cookie jar */
+ cookies = soup_cookie_jar_get_cookies(SOUP_COOKIE_JAR(jar), soup_message_get_uri (msg), TRUE);
+ }
- if (cookies && *cookies != 0) {
+ if (cookies && cookies[0] != 0) {
const gchar *next_cookie_start = cookies;
- /* add the cookie data that we just obtained from the cookie handler
- to the cookie jar so that javascript has access to them.
- we set this flag so that we don't trigger the PUT handler. */
- jar->in_get_callback = true;
- do {
- SoupCookie *soup_cookie = soup_cookie_parse(next_cookie_start, uri);
- if(soup_cookie)
- soup_cookie_jar_add_cookie(SOUP_COOKIE_JAR(uzbl.net.soup_cookie_jar), soup_cookie);
- next_cookie_start = strchr(next_cookie_start, ';');
- } while(next_cookie_start++ != NULL);
- jar->in_get_callback = false;
+ if (add_to_internal_jar) {
+ /* add the cookie data that we just obtained from the cookie handler
+ to the cookie jar so that javascript has access to them.
+ we set this flag so that we don't trigger the PUT handler. */
+ jar->in_get_callback = true;
+ do {
+ SoupCookie *soup_cookie = soup_cookie_parse(next_cookie_start, uri);
+ if(soup_cookie)
+ soup_cookie_jar_add_cookie(SOUP_COOKIE_JAR(uzbl.net.soup_cookie_jar), soup_cookie);
+ next_cookie_start = strchr(next_cookie_start, ';');
+ } while(next_cookie_start++ != NULL);
+ jar->in_get_callback = false;
+ }
soup_message_headers_replace (msg->request_headers, "Cookie", cookies);
-
- g_free (cookies);
} else {
soup_message_headers_remove (msg->request_headers, "Cookie");
}
+
+ if(cookies)
+ g_free (cookies);
}
static void
@@ -174,7 +185,7 @@ changed(SoupCookieJar *jar, SoupCookie *old_cookie, SoupCookie *new_cookie) {
static void
setup_handler(UzblCookieJar *jar) {
- if(strncmp(jar->handler, "talk_to_socket", strlen("talk_to_socket")) == 0) {
+ if(jar->handler && strncmp(jar->handler, "talk_to_socket", strlen("talk_to_socket")) == 0) {
/* extract the socket path from the handler. */
jar->socket_path = jar->handler + strlen("talk_to_socket");
while(isspace(*jar->socket_path))