aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cookie-jar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cookie-jar.c')
-rw-r--r--src/cookie-jar.c57
1 files changed, 36 insertions, 21 deletions
diff --git a/src/cookie-jar.c b/src/cookie-jar.c
index 4bb1925..f2e340b 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;
}
@@ -69,14 +70,16 @@ uzbl_cookie_jar_set_handler(UzblCookieJar *jar, const gchar* handler) {
}
char *get_cookies(UzblCookieJar *jar, SoupURI *uri) {
- gchar *result;
+ gchar *result, *path;
GString *s = g_string_new ("GET");
+ path = uri->path[0] ? uri->path : "/";
+
if(has_socket_handler(jar)) {
g_string_append_c(s, 0); /* null-terminate the GET */
g_string_append_len(s, uri->scheme, strlen(uri->scheme)+1);
g_string_append_len(s, uri->host, strlen(uri->host)+1 );
- g_string_append_len(s, uri->path, strlen(uri->path)+1 );
+ g_string_append_len(s, path, strlen(path)+1 );
result = do_socket_request(jar, s->str, s->len);
/* try it again; older cookie daemons closed the connection after each request */
@@ -97,33 +100,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
@@ -149,7 +162,8 @@ changed(SoupCookieJar *jar, SoupCookie *old_cookie, SoupCookie *new_cookie) {
GString *s = g_string_new ("PUT");
- gchar *scheme = (new_cookie->secure == TRUE) ? "https" : "http";
+ gchar *scheme = new_cookie->secure ? "https" : "http";
+
if(has_socket_handler(uzbl_jar)) {
g_string_append_c(s, 0); /* null-terminate the PUT */
g_string_append_len(s, scheme, strlen(scheme)+1);
@@ -174,7 +188,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))
@@ -228,7 +242,7 @@ static gchar *do_socket_request(UzblCookieJar *jar, gchar *request, int request_
gchar *result = NULL;
if(jar->connection_fd < 0)
- connect_cookie_socket(jar); /* connection was lost, reconnect */
+ connect_cookie_socket(jar); /* connection was lost, reconnect */
/* write request */
ret = write(jar->connection_fd, request, request_length);
@@ -248,7 +262,8 @@ static gchar *do_socket_request(UzblCookieJar *jar, gchar *request, int request_
if(errno == EINTR) continue;
g_printerr("talk_to_socket: poll failed while waiting for input (%s)\n",
strerror(errno));
- disconnect_cookie_socket(jar);
+ if(errno != ETIMEDOUT)
+ disconnect_cookie_socket(jar);
return NULL;
}