aboutsummaryrefslogtreecommitdiffhomepage
path: root/uzbl.c
diff options
context:
space:
mode:
authorGravatar Dequis <dx@dxzone.com.ar>2009-06-15 03:31:58 -0300
committerGravatar Dequis <dx@dxzone.com.ar>2009-06-15 03:49:46 -0300
commit7aba700fc160aadae7e26a2c4f0920b3fb500647 (patch)
treef364a2e5c78511b5972663b05c02390584e04922 /uzbl.c
parent50a2ba82d9a667b8e7ad700be399318a8349d338 (diff)
Working print command with uzblctrl
Also: Changed a few g_error to g_warning to avoid crashes on broken socket. Flush the channel after sending, shutdown before closing. Removed unused headers from uzblctrl.c. The socket protocol is straightforward: you send a command terminated with a newline, you receive a reply terminated with a newline. If you ever need newlines inside a reply, you'll have to change this. uzblctrl closes the connection after getting the reply, but any other client can stay connected and send/receive other commands.
Diffstat (limited to 'uzbl.c')
-rw-r--r--uzbl.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/uzbl.c b/uzbl.c
index e953d3d..407070e 100644
--- a/uzbl.c
+++ b/uzbl.c
@@ -706,7 +706,7 @@ print(WebKitWebView *page, GArray *argv, GString *result) {
gchar* buf;
buf = expand_vars(argv_idx(argv, 0));
- puts(buf); /*TODO: result?*/
+ g_string_assign(result, buf);
g_free(buf);
}
@@ -1313,8 +1313,8 @@ parse_command(const char *cmd, const char *param, GString *result) {
GString *result_print = g_string_new("");
c->function(uzbl.gui.web_view, a, result_print);
- if (uzbl.state.verbose)
- printf("%s returned %s\n", cmd, result_print->str);
+ if (result_print->len)
+ printf("%*s\n", result_print->len, result_print->str);
g_string_free(result_print, TRUE);
} else {
@@ -1817,22 +1817,27 @@ control_client_socket(GIOChannel *clientchan) {
ret = g_io_channel_read_line(clientchan, &ctl_line, &len, NULL, &error);
if (ret == G_IO_STATUS_ERROR) {
- g_error ("Error reading: %s\n", error->message);
+ g_warning ("Error reading: %s\n", error->message);
+ g_io_channel_shutdown(clientchan, TRUE, &error);
return FALSE;
} else if (ret == G_IO_STATUS_EOF) {
- /* socket closed, remove channel watch from main loop */
+ /* shutdown and remove channel watch from main loop */
+ g_io_channel_shutdown(clientchan, TRUE, &error);
return FALSE;
}
if (ctl_line) {
parse_cmd_line (ctl_line, result);
+ g_string_append_c(result, '\n');
ret = g_io_channel_write_chars (clientchan, result->str, result->len,
&len, &error);
if (ret == G_IO_STATUS_ERROR) {
- g_error ("Error writing: %s", error->message);
+ g_warning ("Error writing: %s", error->message);
}
+ g_io_channel_flush(clientchan, &error);
}
+ if (error) g_error_free (error);
g_string_free(result, TRUE);
g_free(ctl_line);
return TRUE;