diff options
author | Brendan Taylor <whateley@gmail.com> | 2009-10-14 17:52:38 -0600 |
---|---|---|
committer | Brendan Taylor <whateley@gmail.com> | 2009-10-14 17:52:38 -0600 |
commit | ab50c5241f32d6b9c28df33ff419ef10b6ba4071 (patch) | |
tree | 820395bae6096cb5d7ed276cae9e3007c1c0b255 | |
parent | ef7c7b2f2125a7226fcf58beb76f9891ab9908fc (diff) | |
parent | 8fa27940fbc6e0bdde34567dc882d2c6aad6c3b8 (diff) |
Merge branch 'experimental' of git://github.com/robm/uzbl
-rw-r--r-- | callbacks.c | 2 | ||||
-rw-r--r-- | callbacks.h | 2 | ||||
-rw-r--r-- | events.c | 94 | ||||
-rw-r--r-- | uzbl-core.c | 104 | ||||
-rw-r--r-- | uzbl-core.h | 7 |
5 files changed, 150 insertions, 59 deletions
diff --git a/callbacks.c b/callbacks.c index d65d09a..15b0a7e 100644 --- a/callbacks.c +++ b/callbacks.c @@ -289,13 +289,11 @@ cmd_useragent() { } /* requires webkit >=1.1.14 */ -/* void cmd_view_source() { webkit_web_view_set_view_source_mode(uzbl.gui.web_view, (gboolean) uzbl.behave.view_source); } -*/ void toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result) { diff --git a/callbacks.h b/callbacks.h index 16ff48a..8c43cf7 100644 --- a/callbacks.h +++ b/callbacks.h @@ -112,10 +112,8 @@ cmd_caret_browsing(); void cmd_set_geometry(); -/* void cmd_view_source(); -*/ void cmd_load_start(); @@ -52,54 +52,84 @@ void send_event_socket(GString *msg) { GError *error = NULL; GString *tmp; + GIOChannel *gio = NULL; GIOStatus ret = 0; gsize len; - guint i=0; - - if(uzbl.comm.socket_path && - uzbl.comm.clientchan && - uzbl.comm.clientchan->is_writeable) { + guint i=0, j=0; + + /* write to all --connect-socket sockets */ + if(uzbl.comm.connect_chan) { + while(i < uzbl.comm.connect_chan->len) { + gio = g_ptr_array_index(uzbl.comm.connect_chan, i++); + j=0; ret = 0; + + if(gio && gio->is_writeable) { + if(uzbl.state.event_buffer) { + event_buffer_timeout(0); + + /* replay buffered events */ + while(j < uzbl.state.event_buffer->len) { + tmp = g_ptr_array_index(uzbl.state.event_buffer, j++); + ret = g_io_channel_write_chars (gio, + tmp->str, tmp->len, + &len, &error); + + if (ret == G_IO_STATUS_ERROR) { + g_warning ("Error sending event to socket: %s", error->message); + } + g_io_channel_flush(gio, &error); + } + } - if(uzbl.state.event_buffer) { - event_buffer_timeout(0); - - while(i < uzbl.state.event_buffer->len) { - tmp = g_ptr_array_index(uzbl.state.event_buffer, i++); - ret = g_io_channel_write_chars (uzbl.comm.clientchan, - tmp->str, tmp->len, - &len, &error); - /* is g_ptr_array_free(uzbl.state.event_buffer, TRUE) enough? */ - //g_string_free(tmp, TRUE); - if (ret == G_IO_STATUS_ERROR) { - g_warning ("Error sending event to socket: %s", error->message); + if(msg) { + while(!ret || + ret == G_IO_STATUS_AGAIN) { + ret = g_io_channel_write_chars (gio, + msg->str, msg->len, + &len, &error); + } + + if (ret == G_IO_STATUS_ERROR) { + g_warning ("Error sending event to socket: %s", error->message); + } + g_io_channel_flush(gio, &error); } - g_io_channel_flush(uzbl.comm.clientchan, &error); } + } + if(uzbl.state.event_buffer) { g_ptr_array_free(uzbl.state.event_buffer, TRUE); uzbl.state.event_buffer = NULL; } - if(msg) { - while(!ret || - ret == G_IO_STATUS_AGAIN) { - ret = g_io_channel_write_chars (uzbl.comm.clientchan, - msg->str, msg->len, - &len, &error); - } - - if (ret == G_IO_STATUS_ERROR) { - g_warning ("Error sending event to socket: %s", error->message); - } - g_io_channel_flush(uzbl.comm.clientchan, &error); - } } /* buffer events until a socket is set and connected - * or a timeout is encountered + * or a timeout is encountered */ else { if(!uzbl.state.event_buffer) uzbl.state.event_buffer = g_ptr_array_new(); g_ptr_array_add(uzbl.state.event_buffer, (gpointer)g_string_new(msg->str)); } + + /* write to all client sockets */ + i=0; + if(msg && uzbl.comm.client_chan) { + while(i < uzbl.comm.client_chan->len) { + gio = g_ptr_array_index(uzbl.comm.client_chan, i++); + ret = 0; + + if(gio && gio->is_writeable && msg) { + while(!ret || ret == G_IO_STATUS_AGAIN) { + ret = g_io_channel_write_chars (gio, + msg->str, msg->len, + &len, &error); + } + + if (ret == G_IO_STATUS_ERROR) + g_warning ("Error sending event to socket: %s", error->message); + g_io_channel_flush(gio, &error); + } + } + } } void diff --git a/uzbl-core.c b/uzbl-core.c index 22f97b0..0187cdb 100644 --- a/uzbl-core.c +++ b/uzbl-core.c @@ -51,6 +51,8 @@ GOptionEntry entries[] = "Path to config file or '-' for stdin", "FILE" }, { "socket", 's', 0, G_OPTION_ARG_INT, &uzbl.state.socket_id, "Socket ID", "SOCKET" }, + { "connect-socket", 0, 0, G_OPTION_ARG_STRING_ARRAY, &uzbl.state.connect_socket_names, + "Socket Name", "CSOCKET" }, { "geometry", 'g', 0, G_OPTION_ARG_STRING, &uzbl.gui.geometry, "Set window geometry (format: WIDTHxHEIGHT+-X+-Y)", "GEOMETRY" }, { "version", 'V', 0, G_OPTION_ARG_NONE, &uzbl.behave.print_version, @@ -113,7 +115,7 @@ const struct var_name_to_ptr_t { { "max_conns_host", PTR_V_INT(uzbl.net.max_conns_host, 1, cmd_max_conns_host)}, { "useragent", PTR_V_STR(uzbl.net.useragent, 1, cmd_useragent)}, /* requires webkit >=1.1.14 */ - //{ "view_source", PTR_V_INT(uzbl.behave.view_source, 0, cmd_view_source)}, + { "view_source", PTR_V_INT(uzbl.behave.view_source, 0, cmd_view_source)}, /* exported WebKitWebSettings properties */ { "zoom_level", PTR_V_FLOAT(uzbl.behave.zoom_level, 1, cmd_zoom_level)}, @@ -456,19 +458,6 @@ parseenv (char* string) { return string; } -sigfunc* -setup_signal(int signr, sigfunc *shandler) { - struct sigaction nh, oh; - - nh.sa_handler = shandler; - sigemptyset(&nh.sa_mask); - nh.sa_flags = 0; - - if(sigaction(signr, &nh, &oh) < 0) - return SIG_ERR; - - return NULL; -} void clean_up(void) { @@ -487,7 +476,21 @@ clean_up(void) { unlink (uzbl.comm.socket_path); } -/* --- SIGNAL HANDLER --- */ +/* --- SIGNALS --- */ +sigfunc* +setup_signal(int signr, sigfunc *shandler) { + struct sigaction nh, oh; + + nh.sa_handler = shandler; + sigemptyset(&nh.sa_mask); + nh.sa_flags = 0; + + if(sigaction(signr, &nh, &oh) < 0) + return SIG_ERR; + + return NULL; +} + void catch_sigterm(int s) { (void) s; @@ -1518,25 +1521,77 @@ create_stdin () { } gboolean +remove_socket_from_array(GIOChannel *chan) { + gboolean ret = 0; + + /* TODO: Do wee need to manually free the IO channel or is this + * happening implicitly on unref? + */ + ret = g_ptr_array_remove_fast(uzbl.comm.connect_chan, chan); + if(!ret) + ret = g_ptr_array_remove_fast(uzbl.comm.client_chan, chan); + + return ret; +} + +gboolean control_socket(GIOChannel *chan) { struct sockaddr_un remote; unsigned int t = sizeof(remote); + GIOChannel *iochan; int clientsock; clientsock = accept (g_io_channel_unix_get_fd(chan), (struct sockaddr *) &remote, &t); - if ((uzbl.comm.clientchan = g_io_channel_unix_new(clientsock))) { - g_io_channel_set_encoding(uzbl.comm.clientchan, NULL, NULL); - g_io_add_watch(uzbl.comm.clientchan, G_IO_IN|G_IO_HUP, - (GIOFunc) control_client_socket, uzbl.comm.clientchan); - /* replay buffered events */ - send_event_socket(NULL); - } + if(!uzbl.comm.client_chan) + uzbl.comm.client_chan = g_ptr_array_new(); + if ((iochan = g_io_channel_unix_new(clientsock))) { + g_io_channel_set_encoding(iochan, NULL, NULL); + g_io_add_watch(iochan, G_IO_IN|G_IO_HUP, + (GIOFunc) control_client_socket, iochan); + g_ptr_array_add(uzbl.comm.client_chan, (gpointer)iochan); + } return TRUE; } +void +init_connect_socket() { + int sockfd, replay = 0; + struct sockaddr_un local; + GIOChannel *chan; + gchar **name = NULL; + + if(!uzbl.comm.connect_chan) + uzbl.comm.connect_chan = g_ptr_array_new(); + + name = uzbl.state.connect_socket_names; + + while(name && *name) { + sockfd = socket (AF_UNIX, SOCK_STREAM, 0); + local.sun_family = AF_UNIX; + strcpy (local.sun_path, *name); + + if(!connect(sockfd, (struct sockaddr *) &local, sizeof(local))) { + if ((chan = g_io_channel_unix_new(sockfd))) { + g_io_channel_set_encoding(chan, NULL, NULL); + g_io_add_watch(chan, G_IO_IN|G_IO_HUP, + (GIOFunc) control_client_socket, chan); + g_ptr_array_add(uzbl.comm.connect_chan, (gpointer)chan); + replay++; + } + } + else + g_warning("Error connecting to socket: %s\n", *name); + name++; + } + + /* replay buffered events */ + if(replay) + send_event_socket(NULL); +} + gboolean control_client_socket(GIOChannel *clientchan) { char *ctl_line; @@ -1548,9 +1603,11 @@ control_client_socket(GIOChannel *clientchan) { ret = g_io_channel_read_line(clientchan, &ctl_line, &len, NULL, &error); if (ret == G_IO_STATUS_ERROR) { g_warning ("Error reading: %s\n", error->message); + remove_socket_from_array(clientchan); g_io_channel_shutdown(clientchan, TRUE, &error); return FALSE; } else if (ret == G_IO_STATUS_EOF) { + remove_socket_from_array(clientchan); /* shutdown and remove channel watch from main loop */ g_io_channel_shutdown(clientchan, TRUE, &error); return FALSE; @@ -1916,6 +1973,9 @@ settings_init () { printf ("No configuration file loaded.\n"); } + if(s->connect_socket_names) + init_connect_socket(); + g_signal_connect_after(n->soup_session, "request-started", G_CALLBACK(handle_cookies), NULL); } diff --git a/uzbl-core.h b/uzbl-core.h index 270b595..77f3a84 100644 --- a/uzbl-core.h +++ b/uzbl-core.h @@ -82,7 +82,8 @@ typedef struct { GHashTable *proto_var; gchar *sync_stdout; - GIOChannel *clientchan; + GPtrArray *connect_chan; + GPtrArray *client_chan; } Communication; @@ -99,6 +100,7 @@ typedef struct { gchar* searchtx; gboolean verbose; GPtrArray *event_buffer; + gchar** connect_socket_names; } State; @@ -436,6 +438,9 @@ update_gui(WebKitWebView *page, GArray *argv, GString *result); void event(WebKitWebView *page, GArray *argv, GString *result); +void +init_connect_socket(); + typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result); typedef struct { Command function; |