Add command menu for messages received from loopback.
[cascardo/f2fchat.git] / message.c
index 4d3150a..2074549 100644 (file)
--- a/message.c
+++ b/message.c
@@ -18,6 +18,7 @@
 
 #include "message.h"
 #include "friend.h"
+#include "menu.h"
 #include <glib.h>
 #include <gio/gio.h>
 
@@ -33,9 +34,12 @@ gboolean ping_timeout(gpointer data)
 static GIOChannel *uchannel;
 static GSocket *gusock;
 
-static void command(char *buffer, size_t len)
+static void command(char *buffer, size_t len, GSocketAddress *address)
 {
-       printf("message from loopback: %d %.*s\n", len, len, buffer);
+       gchar **args;
+       args = g_strsplit(buffer, " ", -1);
+       menu_run(args, address);
+       g_strfreev(args);
 }
 
 gboolean message_incoming(GIOChannel *channel, GIOCondition cond, gpointer data)
@@ -55,7 +59,7 @@ gboolean message_incoming(GIOChannel *channel, GIOCondition cond, gpointer data)
        len = g_socket_receive_from(gusock, &address, buffer, len, NULL, NULL);
        iaddress = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(address));
        if (g_inet_address_get_is_loopback(iaddress)) {
-               command(buffer, len);
+               command(buffer, len, address);
        } else {
                struct friend *friend;
                uint16_t port = g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(address));