X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=uzblctrl.c;h=2547bc7317f914aac68943fb32b99205c7609d87;hb=a3adc8f8c27fb8246bc8aa584aab4a589625a70c;hp=55a3aac929f84b291521f200d9167c37a83647aa;hpb=b428ad76e4949e578e55ed129663ee3dbbc2df53;p=uzbl-mobile diff --git a/uzblctrl.c b/uzblctrl.c index 55a3aac..2547bc7 100644 --- a/uzblctrl.c +++ b/uzblctrl.c @@ -2,17 +2,9 @@ /* Socket code more or less completely copied from here: http://www.ecst.csuchico.edu/~beej/guide/ipc/usock.html */ #include -#include -#include -#include -#include #include -#include -#include -#include #include #include -#include #include #include #include @@ -23,7 +15,7 @@ static gchar* command; static GOptionEntry entries[] = { - { "socket", 's', 0, G_OPTION_ARG_STRING, &sockpath, "Socket path of the client uzbl", NULL }, + { "socket", 's', 0, G_OPTION_ARG_STRING, &sockpath, "Path to the uzbl socket", NULL }, { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "The uzbl command to execute", NULL }, { NULL, 0, 0, 0, NULL, NULL, NULL } }; @@ -31,7 +23,7 @@ static GOptionEntry entries[] = int main(int argc, char* argv[]) { GError *error = NULL; - GOptionContext* context = g_option_context_new ("- some stuff here maybe someday"); + GOptionContext* context = g_option_context_new ("- utility for controlling and interacting with uzbl through its socket file"); /* TODO: get stuff back from uzbl */ g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, &error); @@ -40,32 +32,39 @@ main(int argc, char* argv[]) { if (sockpath && command) { int s, len; struct sockaddr_un remote; - + char tmp; + if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) == -1) { perror ("socket"); - exit (1); + exit (EXIT_FAILURE); } - + remote.sun_family = AF_UNIX; strcpy (remote.sun_path, (char *) sockpath); len = strlen (remote.sun_path) + sizeof (remote.sun_family); - + if (connect (s, (struct sockaddr *) &remote, len) == -1) { perror ("connect"); - exit (1); + exit (EXIT_FAILURE); } - - if (send (s, command, strlen (command), 0) == -1) { + + if ((send (s, command, strlen (command), 0) == -1) || + (send (s, "\n", 1, 0) == -1)) { perror ("send"); - exit (1); + exit (EXIT_FAILURE); + } + + while ((len = recv (s, &tmp, 1, 0))) { + putchar(tmp); + if (tmp == '\n') + break; } - + close(s); - + return 0; } else { - printf ("You need to specify the -s and -c parameters for uzblctrl to do anything of use.\n"); - printf ("Usage: uzblctrl -s /path/to/socket -c \"command\"\n"); + fprintf(stderr, "Usage: uzblctrl -s /path/to/socket -c \"command\""); return 1; } }