From b4cbca161a1638e96d9e0a6fe12a29ed43173e43 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 16 Aug 2010 00:51:20 +0200 Subject: Committed some work. --- commands.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 commands.c (limited to 'commands.c') diff --git a/commands.c b/commands.c new file mode 100644 index 0000000..b11b09c --- /dev/null +++ b/commands.c @@ -0,0 +1,31 @@ +#include "commands.h" +#include "music.h" + +#include +#include + +static void commands_list(GSocketConnection *connection, const gchar *cmd) { + gchar **data = g_strsplit(cmd, " ", 2); + for(gint i = 0; data[i]; i++) { + g_debug("\tdata[%d] = %s", i, data[i]); + } + g_assert(data[0] != NULL && data[1] != NULL); + + gchar *dirname = g_strdup(data[1]); + + struct directory *directory = music_find_dir(dirname); + g_assert(directory != NULL); + + GSocket *socket = g_socket_connection_get_socket(connection); + for(struct file *f = directory->files; f; f = f->next) { + g_socket_send(socket, f->name, strlen(f->name), NULL, NULL); + g_socket_send(socket, "\n", 1, NULL, NULL); + } +} + +void commands_handle(GSocketConnection *connection, const gchar *cmd) { + g_debug("handling command string %s", cmd); + if(g_ascii_strncasecmp(cmd, "/list", 5) == 0) { + commands_list(connection, cmd); + } +} -- cgit v1.2.3