diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/callbacks.c | 40 | ||||
-rw-r--r-- | src/callbacks.h | 3 | ||||
-rw-r--r-- | src/cookie-jar.c | 316 | ||||
-rw-r--r-- | src/cookie-jar.h | 12 | ||||
-rwxr-xr-x | src/uzbl-browser | 7 | ||||
-rw-r--r-- | src/uzbl-core.c | 27 | ||||
-rw-r--r-- | src/uzbl-core.h | 5 |
7 files changed, 42 insertions, 368 deletions
diff --git a/src/callbacks.c b/src/callbacks.c index bc06a45..546b8ca 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -47,15 +47,20 @@ set_authentication_handler() { void set_status_background() { - GdkColor color; - gdk_color_parse (uzbl.behave.status_background, &color); /* labels and hboxes do not draw their own background. applying this * on the vbox/main_window is ok as the statusbar is the only affected * widget. (if not, we could also use GtkEventBox) */ - if (uzbl.gui.main_window) - gtk_widget_modify_bg (uzbl.gui.main_window, GTK_STATE_NORMAL, &color); - else if (uzbl.gui.plug) - gtk_widget_modify_bg (GTK_WIDGET(uzbl.gui.plug), GTK_STATE_NORMAL, &color); + GtkWidget* widget = uzbl.gui.main_window ? uzbl.gui.main_window : GTK_WIDGET (uzbl.gui.plug); + +#if GTK_CHECK_VERSION(2,91,0) + GdkRGBA color; + gdk_rgba_parse (&color, uzbl.behave.status_background); + gtk_widget_override_background_color (widget, GTK_STATE_NORMAL, &color); +#else + GdkColor color; + gdk_color_parse (uzbl.behave.status_background, &color); + gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &color); +#endif } void @@ -828,16 +833,19 @@ download_cb(WebKitWebView *web_view, WebKitDownload *download, gpointer user_dat g_object_get(download, "suggested-filename", &suggested_filename, NULL); /* get the mimetype of the download */ - const gchar *content_type; + const gchar *content_type = NULL; WebKitNetworkResponse *r = webkit_download_get_network_response(download); /* downloads can be initiated from the context menu, in that case there is no network response yet and trying to get one would crash. */ if(WEBKIT_IS_NETWORK_RESPONSE(r)) { - SoupMessage *m = webkit_network_response_get_message(r); - SoupMessageHeaders *h; + SoupMessage *m = webkit_network_response_get_message(r); + SoupMessageHeaders *h = NULL; g_object_get(m, "response-headers", &h, NULL); - content_type = soup_message_headers_get_one(h, "Content-Type"); - } else + if(h) /* some versions of libsoup don't have "response-headers" here */ + content_type = soup_message_headers_get_one(h, "Content-Type"); + } + + if(!content_type) content_type = "application/octet-stream"; /* get the filesize of the download, as given by the server. @@ -1006,13 +1014,3 @@ populate_popup_cb(WebKitWebView *v, GtkMenu *m, void *c) { } } } - -void -cmd_set_cookie_handler() { - if(uzbl.behave.cookie_handler[0] == 0) { - g_free(uzbl.behave.cookie_handler); - uzbl.behave.cookie_handler = NULL; - } - - uzbl_cookie_jar_set_handler(uzbl.net.soup_cookie_jar, uzbl.behave.cookie_handler); -} diff --git a/src/callbacks.h b/src/callbacks.h index 899e959..13cb83d 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -216,6 +216,3 @@ scroll_vert_cb(GtkAdjustment *adjust, void *w); gboolean scroll_horiz_cb(GtkAdjustment *adjust, void *w); - -void -cmd_set_cookie_handler(); diff --git a/src/cookie-jar.c b/src/cookie-jar.c index 9ddef3b..82a5269 100644 --- a/src/cookie-jar.c +++ b/src/cookie-jar.c @@ -1,51 +1,20 @@ -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <poll.h> -#include <unistd.h> -#include <sys/ioctl.h> -#include <string.h> -#include <errno.h> - -#include <libsoup/soup-uri.h> #include <libsoup/soup-cookie.h> #include "cookie-jar.h" #include "uzbl-core.h" #include "events.h" -static void -uzbl_cookie_jar_session_feature_init(SoupSessionFeatureInterface *iface, gpointer user_data); - -G_DEFINE_TYPE_WITH_CODE (UzblCookieJar, soup_cookie_jar_socket, SOUP_TYPE_COOKIE_JAR, - G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE, uzbl_cookie_jar_session_feature_init)) +G_DEFINE_TYPE (UzblCookieJar, soup_cookie_jar_socket, SOUP_TYPE_COOKIE_JAR) -static void request_started (SoupSessionFeature *feature, SoupSession *session, SoupMessage *msg, SoupSocket *socket); static void changed(SoupCookieJar *jar, SoupCookie *old_cookie, SoupCookie *new_cookie); -static void setup_handler(UzblCookieJar *jar); - -static void connect_cookie_socket(UzblCookieJar *jar); -static void disconnect_cookie_socket(UzblCookieJar *jar); - -static gchar *do_socket_request(UzblCookieJar *jar, gchar *request, int request_len); - -static bool has_socket_handler(UzblCookieJar *jar) { - return jar->socket_path != NULL; -} - static void soup_cookie_jar_socket_init(UzblCookieJar *jar) { - jar->handler = NULL; - jar->socket_path = NULL; - jar->connection_fd = -1; - jar->in_get_callback = 0; jar->in_manual_add = 0; } static void finalize(GObject *object) { - disconnect_cookie_socket(UZBL_COOKIE_JAR(object)); G_OBJECT_CLASS(soup_cookie_jar_socket_parent_class)->finalize(object); } @@ -55,130 +24,23 @@ soup_cookie_jar_socket_class_init(UzblCookieJarClass *socket_class) { SOUP_COOKIE_JAR_CLASS(socket_class)->changed = changed; } -/* override SoupCookieJar's request_started handler */ -static void -uzbl_cookie_jar_session_feature_init(SoupSessionFeatureInterface *iface, gpointer user_data) { - (void) user_data; - iface->request_started = request_started; -} - UzblCookieJar *uzbl_cookie_jar_new() { return g_object_new(UZBL_TYPE_COOKIE_JAR, NULL); } -void -uzbl_cookie_jar_set_handler(UzblCookieJar *jar, const gchar* handler) { - jar->handler = handler; - setup_handler(jar); -} - -char *get_cookies(UzblCookieJar *jar, SoupURI *uri) { - gchar *result, *path; - - path = uri->path[0] ? uri->path : "/"; - - if(has_socket_handler(jar)) { - GString *s = g_string_new ("GET"); - 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, 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 */ - if(result == NULL) - result = do_socket_request(jar, s->str, s->len); - - g_string_free(s, TRUE); - } else { - GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*)); - - const CommandInfo *c = parse_command_parts(jar->handler, a); - if(!c) { - g_array_free(a, TRUE); - return NULL; - } - - /* add our handler args */ - g_array_append_val(a, "GET"); - g_array_append_val(a, uri->scheme); - g_array_append_val(a, uri->host); - g_array_append_val(a, uri->path); - - GString *r = g_string_new (""); - run_parsed_command(c, a, r); - result = r->str; - g_string_free(r, FALSE); - g_array_free(a, TRUE); - } - - return result; -} - -/* this is a duplicate of SoupCookieJar's request_started that uses our get_cookies instead */ -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; - - 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] != 0) { - const gchar *next_cookie_start = cookies; - - 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); - } else { - soup_message_headers_remove (msg->request_headers, "Cookie"); - } - - if(cookies) - g_free (cookies); -} - static void changed(SoupCookieJar *jar, SoupCookie *old_cookie, SoupCookie *new_cookie) { - SoupCookie * cookie = new_cookie ? new_cookie : old_cookie; + SoupCookie *cookie = new_cookie ? new_cookie : old_cookie; UzblCookieJar *uzbl_jar = UZBL_COOKIE_JAR(jar); - /* when Uzbl begins an HTTP request, it GETs cookies from the handler - and then adds them to the cookie jar so that javascript can access - these cookies. this causes a 'changed' callback, which we don't want - to do anything, so we just return. - - (if SoupCookieJar let us override soup_cookie_jar_get_cookies we - wouldn't have to do this.) */ - if(uzbl_jar->in_get_callback) - return; - - gchar *scheme = cookie->secure ? "https" : "http"; - - /* send a ADD or DELETE -_COOKIE event depending on what have changed */ + /* send a ADD or DELETE -_COOKIE event depending on what has changed. these + * events aren't sent when a cookie changes due to an add/delete_cookie + * command because otherwise a loop would occur when a cookie change is + * propagated to other uzbl instances using add/delete_cookie. */ if(!uzbl_jar->in_manual_add) { + gchar *scheme = cookie->secure ? "https" : "http"; + gchar *expires = NULL; if(cookie->expires) expires = g_strdup_printf ("%d", soup_date_to_time_t (cookie->expires)); @@ -193,166 +55,4 @@ changed(SoupCookieJar *jar, SoupCookie *old_cookie, SoupCookie *new_cookie) { if(expires) g_free(expires); } - - /* the cookie daemon is only interested in new cookies and changed - ones, it can take care of deleting expired cookies on its own. */ - if(!new_cookie) - return; - - if(has_socket_handler(uzbl_jar)) { - GString *s = g_string_new ("PUT"); - g_string_append_c(s, 0); /* null-terminate the PUT */ - g_string_append_len(s, scheme, strlen(scheme)+1); - g_string_append_len(s, new_cookie->domain, strlen(new_cookie->domain)+1 ); - g_string_append_len(s, new_cookie->path, strlen(new_cookie->path)+1 ); - g_string_append_printf(s, "%s=%s", new_cookie->name, new_cookie->value); - - gchar *result = do_socket_request(uzbl_jar, s->str, s->len+1); - /* try it again; older cookie daemons closed the connection after each request */ - if(!result) - result = do_socket_request(uzbl_jar, s->str, s->len+1); - - g_free(result); - g_string_free(s, TRUE); - } else { - GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*)); - - const CommandInfo *c = parse_command_parts(uzbl_jar->handler, a); - if(!c) { - g_array_free(a, TRUE); - return; - } - - g_array_append_val(a, "PUT"); - g_array_append_val(a, scheme); - g_array_append_val(a, new_cookie->domain); - g_array_append_val(a, new_cookie->path); - - gchar *kv = g_strconcat(new_cookie->name, "=", new_cookie->value, NULL); - g_array_append_val(a, kv); - - run_parsed_command(c, a, NULL); - - g_free(kv); - g_array_free(a, TRUE); - } -} - -static void -setup_handler(UzblCookieJar *jar) { - 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)) - jar->socket_path++; - if(*jar->socket_path == 0) - return; /* there was no path specified. */ - disconnect_cookie_socket(jar); - connect_cookie_socket(jar); - } else { - jar->socket_path = NULL; - } -} - -static void -connect_cookie_socket(UzblCookieJar *jar) { - struct sockaddr_un sa; - int fd; - - g_strlcpy(sa.sun_path, jar->socket_path, sizeof(sa.sun_path)); - sa.sun_family = AF_UNIX; - - /* create socket file descriptor and connect it to path */ - fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); - if(fd == -1) { - g_printerr("connect_cookie_socket: creating socket failed (%s)\n", strerror(errno)); - return; - } - - if(connect(fd, (struct sockaddr*)&sa, sizeof(sa))) { - g_printerr("connect_cookie_socket: connect failed (%s)\n", strerror(errno)); - close(fd); - return; - } - - /* successful connection! */ - jar->connection_fd = fd; -} - -static void -disconnect_cookie_socket(UzblCookieJar *jar) { - if(jar->connection_fd > 0) { - close(jar->connection_fd); - jar->connection_fd = -1; - } -} - -static gchar *do_socket_request(UzblCookieJar *jar, gchar *request, int request_length) { - int len; - ssize_t ret; - struct pollfd pfd; - gchar *result = NULL; - - if(jar->connection_fd < 0) - connect_cookie_socket(jar); /* connection was lost, reconnect */ - - /* write request */ - ret = write(jar->connection_fd, request, request_length); - if(ret == -1) { - g_printerr("talk_to_socket: write failed (%s)\n", strerror(errno)); - disconnect_cookie_socket(jar); - return NULL; - } - - /* wait for a response, with a 500ms timeout */ - pfd.fd = jar->connection_fd; - pfd.events = POLLIN; - while(1) { - ret = poll(&pfd, 1, 500); - if(ret == 1) break; - if(ret == 0) errno = ETIMEDOUT; - if(errno == EINTR) continue; - g_printerr("talk_to_socket: poll failed while waiting for input (%s)\n", - strerror(errno)); - if(errno != ETIMEDOUT) - disconnect_cookie_socket(jar); - return NULL; - } - - /* get length of response */ - if(ioctl(jar->connection_fd, FIONREAD, &len) == -1) { - g_printerr("talk_to_socket: cannot find daemon response length, " - "ioctl failed (%s)\n", strerror(errno)); - disconnect_cookie_socket(jar); - return NULL; - } - - /* there was an empty response. */ - if(len == 0) - return g_strdup(""); - - /* there is a response, read it */ - result = g_malloc(len + 1); - if(!result) { - g_printerr("talk_to_socket: failed to allocate %d bytes\n", len); - return NULL; - } - result[len] = 0; /* ensure result is null terminated */ - - gchar *p = result; - while(len > 0) { - ret = read(jar->connection_fd, p, len); - if(ret == -1) { - g_printerr("talk_to_socket: failed to read from socket (%s)\n", - strerror(errno)); - disconnect_cookie_socket(jar); - g_free(result); - return NULL; - } else { - len -= ret; - p += ret; - } - } - - return result; } diff --git a/src/cookie-jar.h b/src/cookie-jar.h index f3e3733..05f4a6f 100644 --- a/src/cookie-jar.h +++ b/src/cookie-jar.h @@ -10,12 +10,6 @@ typedef struct { SoupCookieJar parent; - const gchar *handler; - - const gchar *socket_path; - int connection_fd; - - gboolean in_get_callback; gboolean in_manual_add; } UzblCookieJar; @@ -25,10 +19,4 @@ typedef struct { UzblCookieJar *uzbl_cookie_jar_new(); -void -uzbl_cookie_jar_set_handler(UzblCookieJar *jar, const gchar *handler); - -char -*get_cookies(UzblCookieJar *jar, SoupURI *uri); - #endif diff --git a/src/uzbl-browser b/src/uzbl-browser index faa2829..81645ca 100755 --- a/src/uzbl-browser +++ b/src/uzbl-browser @@ -64,13 +64,6 @@ then export UZBL_UTIL_DIR fi -# uzbl-cookie-manager will exit if another instance is already running. -# we could also check if its pid file exists to avoid having to spawn it. -#if [ ! -f "$XDG_CACHE_HOME"/uzbl/cookie_daemon_socket.pid ] -#then -# ${UZBL_COOKIE_DAEMON:-uzbl-cookie-manager} -#fi - # uzbl-event-manager will exit if one is already running. # we could also check if its pid file exists to avoid having to spawn it. DAEMON_SOCKET="$XDG_CACHE_HOME"/uzbl/event_daemon diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 0a90bb9..f1426e2 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -91,7 +91,6 @@ const struct var_name_to_ptr_t { { "title_format_short", PTR_V_STR(uzbl.behave.title_format_short, 1, NULL)}, { "icon", PTR_V_STR(uzbl.gui.icon, 1, set_icon)}, { "forward_keys", PTR_V_INT(uzbl.behave.forward_keys, 1, NULL)}, - { "cookie_handler", PTR_V_STR(uzbl.behave.cookie_handler, 1, cmd_set_cookie_handler)}, { "authentication_handler", PTR_V_STR(uzbl.behave.authentication_handler, 1, set_authentication_handler)}, { "scheme_handler", PTR_V_STR(uzbl.behave.scheme_handler, 1, NULL)}, { "download_handler", PTR_V_STR(uzbl.behave.download_handler, 1, NULL)}, @@ -568,8 +567,8 @@ VIEWFUNC(go_forward) /* -- command to callback/function map for things we cannot attach to any signals */ CommandInfo cmdlist[] = { /* key function no_split */ - { "back", view_go_back, 0 }, - { "forward", view_go_forward, 0 }, + { "back", view_go_back, 0 }, + { "forward", view_go_forward, 0 }, { "scroll", scroll_cmd, 0 }, { "reload", view_reload, 0 }, { "reload_ign_cache", view_reload_bypass_cache, 0 }, @@ -582,10 +581,10 @@ CommandInfo cmdlist[] = { "script", run_external_js, 0 }, { "toggle_status", toggle_status_cb, 0 }, { "spawn", spawn_async, 0 }, - { "sync_spawn", spawn_sync, 0 }, // needed for cookie handler + { "sync_spawn", spawn_sync, 0 }, { "sync_spawn_exec", spawn_sync_exec, 0 }, // needed for load_cookies.sh :( { "sh", spawn_sh_async, 0 }, - { "sync_sh", spawn_sh_sync, 0 }, // needed for cookie handler + { "sync_sh", spawn_sh_sync, 0 }, { "exit", close_uzbl, 0 }, { "search", search_forward_text, TRUE }, { "search_reverse", search_reverse_text, TRUE }, @@ -1661,21 +1660,16 @@ control_stdin(GIOChannel *gio, GIOCondition condition) { void create_stdin () { - GIOChannel *chan = NULL; - GError *error = NULL; - - chan = g_io_channel_unix_new(fileno(stdin)); + GIOChannel *chan = g_io_channel_unix_new(fileno(stdin)); if (chan) { if (!g_io_add_watch(chan, G_IO_IN|G_IO_HUP, (GIOFunc) control_stdin, NULL)) { - g_error ("Stdin: could not add watch\n"); - } else { - if (uzbl.state.verbose) - printf ("Stdin: watch added successfully\n"); + g_error ("create_stdin: could not add watch\n"); + } else if (uzbl.state.verbose) { + printf ("create_stdin: watch added successfully\n"); } } else { - g_error ("Stdin: Error while opening: %s\n", error->message); + g_error ("create_stdin: error while opening stdin\n"); } - if (error) g_error_free (error); } gboolean @@ -1984,7 +1978,8 @@ create_window () { /* if the window has been made small, it shouldn't try to resize itself due * to a long statusbar. */ GdkGeometry hints; - hints.min_width = 1; + hints.min_height = -1; + hints.min_width = 1; gtk_window_set_geometry_hints (GTK_WINDOW (window), window, &hints, GDK_HINT_MIN_SIZE); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy_cb), NULL); diff --git a/src/uzbl-core.h b/src/uzbl-core.h index 14b0571..28092b4 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -40,6 +40,10 @@ #include <sys/ioctl.h> #include <assert.h> +#if GTK_CHECK_VERSION(2,91,0) + #include <gtk/gtkx.h> +#endif + #include "cookie-jar.h" #define LENGTH(x) (sizeof x / sizeof x[0]) @@ -134,7 +138,6 @@ typedef struct { gchar* fifo_dir; gchar* socket_dir; - gchar* cookie_handler; gchar* authentication_handler; gchar* default_font_family; gchar* monospace_font_family; |