From 44af2da9c23c918912a99682f89e4abd85709e72 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Wed, 7 Oct 2009 10:37:00 +0200 Subject: rearrange function order --- uzbl-core.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/uzbl-core.c b/uzbl-core.c index 1fcd434..a9f5326 100644 --- a/uzbl-core.c +++ b/uzbl-core.c @@ -468,19 +468,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) { @@ -499,7 +486,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; -- cgit v1.2.3 From 19806c1467b71d49881a9d76e28f3c656312e77b Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Tue, 13 Oct 2009 14:09:21 +0200 Subject: added multiple clients per socket support and --connect-socket argument --- events.c | 45 ++++++++++++++++++++++++++++++++------------- uzbl-core.c | 39 +++++++++++++++++++++++++++++++++------ uzbl-core.h | 4 +++- 3 files changed, 68 insertions(+), 20 deletions(-) diff --git a/events.c b/events.c index abd794b..32816a1 100644 --- a/events.c +++ b/events.c @@ -52,20 +52,19 @@ 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; + if(uzbl.comm.connect_chan && + uzbl.comm.connect_chan->is_writeable) { 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, + while(j < uzbl.state.event_buffer->len) { + tmp = g_ptr_array_index(uzbl.state.event_buffer, j++); + ret = g_io_channel_write_chars (uzbl.comm.connect_chan, tmp->str, tmp->len, &len, &error); /* is g_ptr_array_free(uzbl.state.event_buffer, TRUE) enough? */ @@ -73,15 +72,16 @@ send_event_socket(GString *msg) { if (ret == G_IO_STATUS_ERROR) { g_warning ("Error sending event to socket: %s", error->message); } - g_io_channel_flush(uzbl.comm.clientchan, &error); + g_io_channel_flush(uzbl.comm.connect_chan, &error); } 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, + ret == G_IO_STATUS_AGAIN) { + ret = g_io_channel_write_chars (uzbl.comm.connect_chan, msg->str, msg->len, &len, &error); } @@ -89,17 +89,36 @@ send_event_socket(GString *msg) { if (ret == G_IO_STATUS_ERROR) { g_warning ("Error sending event to socket: %s", error->message); } - g_io_channel_flush(uzbl.comm.clientchan, &error); + g_io_channel_flush(uzbl.comm.connect_chan, &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)); } + + 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 a9f5326..ad224e8 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, &uzbl.state.connect_socket_name, + "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, @@ -1517,20 +1519,42 @@ 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); + 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(gchar *name) { + int sockfd; + struct sockaddr_un local; + + 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 ((uzbl.comm.connect_chan = g_io_channel_unix_new(sockfd))) { + g_io_channel_set_encoding(uzbl.comm.connect_chan, NULL, NULL); + g_io_add_watch(uzbl.comm.connect_chan, G_IO_IN|G_IO_HUP, + (GIOFunc) control_client_socket, uzbl.comm.connect_chan); /* replay buffered events */ send_event_socket(NULL); + } } - - return TRUE; } gboolean @@ -1912,6 +1936,9 @@ settings_init () { printf ("No configuration file loaded.\n"); } + if(s->connect_socket_name) + init_connect_socket(s->connect_socket_name); + 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 f0b60ab..12c1716 100644 --- a/uzbl-core.h +++ b/uzbl-core.h @@ -81,7 +81,8 @@ typedef struct { GHashTable *proto_var; gchar *sync_stdout; - GIOChannel *clientchan; + GIOChannel *connect_chan; + GPtrArray *client_chan; } Communication; @@ -98,6 +99,7 @@ typedef struct { gchar* searchtx; gboolean verbose; GPtrArray *event_buffer; + gchar* connect_socket_name; } State; -- cgit v1.2.3 From 5b1f6a5deed654e651e1de249a81b895d0073313 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Tue, 13 Oct 2009 15:53:19 +0200 Subject: handle multiple calls to --conect-socket --- events.c | 66 ++++++++++++++++++++++++++++++++++--------------------------- uzbl-core.c | 48 ++++++++++++++++++++++++++++---------------- uzbl-core.h | 7 +++++-- 3 files changed, 73 insertions(+), 48 deletions(-) diff --git a/events.c b/events.c index 32816a1..6cb41f9 100644 --- a/events.c +++ b/events.c @@ -57,40 +57,47 @@ send_event_socket(GString *msg) { gsize len; guint i=0, j=0; - if(uzbl.comm.connect_chan && - uzbl.comm.connect_chan->is_writeable) { - if(uzbl.state.event_buffer) { - event_buffer_timeout(0); - - while(j < uzbl.state.event_buffer->len) { - tmp = g_ptr_array_index(uzbl.state.event_buffer, j++); - ret = g_io_channel_write_chars (uzbl.comm.connect_chan, - 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(uzbl.comm.connect_chan) { + while(i < uzbl.comm.connect_chan->len) { + gio = g_ptr_array_index(uzbl.comm.connect_chan, i++); + j=0; + + if(gio && gio->is_writeable) { + if(uzbl.state.event_buffer) { + event_buffer_timeout(0); + + 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(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.connect_chan, &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.connect_chan, - 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.connect_chan, &error); - } } /* buffer events until a socket is set and connected * or a timeout is encountered @@ -101,6 +108,7 @@ send_event_socket(GString *msg) { g_ptr_array_add(uzbl.state.event_buffer, (gpointer)g_string_new(msg->str)); } + 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++); diff --git a/uzbl-core.c b/uzbl-core.c index ad224e8..e6f8edf 100644 --- a/uzbl-core.c +++ b/uzbl-core.c @@ -51,7 +51,7 @@ 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, &uzbl.state.connect_socket_name, + { "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" }, @@ -1538,23 +1538,37 @@ control_socket(GIOChannel *chan) { } void -init_connect_socket(gchar *name) { - int sockfd; +init_connect_socket() { + int sockfd, replay = 0; struct sockaddr_un local; - - 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 ((uzbl.comm.connect_chan = g_io_channel_unix_new(sockfd))) { - g_io_channel_set_encoding(uzbl.comm.connect_chan, NULL, NULL); - g_io_add_watch(uzbl.comm.connect_chan, G_IO_IN|G_IO_HUP, - (GIOFunc) control_client_socket, uzbl.comm.connect_chan); - /* replay buffered events */ - send_event_socket(NULL); + 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++; + } } + name++; } + + /* replay buffered events */ + if(replay) + send_event_socket(NULL); } gboolean @@ -1936,8 +1950,8 @@ settings_init () { printf ("No configuration file loaded.\n"); } - if(s->connect_socket_name) - init_connect_socket(s->connect_socket_name); + 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 12c1716..32d92e3 100644 --- a/uzbl-core.h +++ b/uzbl-core.h @@ -81,7 +81,7 @@ typedef struct { GHashTable *proto_var; gchar *sync_stdout; - GIOChannel *connect_chan; + GPtrArray *connect_chan; GPtrArray *client_chan; } Communication; @@ -99,7 +99,7 @@ typedef struct { gchar* searchtx; gboolean verbose; GPtrArray *event_buffer; - gchar* connect_socket_name; + gchar** connect_socket_names; } State; @@ -424,6 +424,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; -- cgit v1.2.3 From 8fa27940fbc6e0bdde34567dc882d2c6aad6c3b8 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Wed, 14 Oct 2009 10:01:34 +0200 Subject: added view_source, added remove_socket_from_array() --- callbacks.c | 2 -- callbacks.h | 2 -- events.c | 5 ++++- uzbl-core.c | 20 +++++++++++++++++++- 4 files changed, 23 insertions(+), 6 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(); diff --git a/events.c b/events.c index 6cb41f9..48f3bc0 100644 --- a/events.c +++ b/events.c @@ -57,15 +57,17 @@ send_event_socket(GString *msg) { gsize len; 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; + 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, @@ -108,6 +110,7 @@ send_event_socket(GString *msg) { 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) { diff --git a/uzbl-core.c b/uzbl-core.c index e6f8edf..9e6833a 100644 --- a/uzbl-core.c +++ b/uzbl-core.c @@ -127,7 +127,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)}, @@ -1515,6 +1515,20 @@ create_stdin () { if (error) g_error_free (error); } +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; @@ -1563,6 +1577,8 @@ init_connect_socket() { replay++; } } + else + g_warning("Error connecting to socket: %s\n", *name); name++; } @@ -1582,9 +1598,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; -- cgit v1.2.3