From 5241f71a41f4125281f9215dd30b8fc4dfc546b1 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 20 Aug 2010 14:40:48 +0200 Subject: Added a service for server commands and moved the list command in there. --- commands.c | 56 +------------------------------------------------------- 1 file changed, 1 insertion(+), 55 deletions(-) (limited to 'commands.c') diff --git a/commands.c b/commands.c index 5a2230f..c77d7c8 100644 --- a/commands.c +++ b/commands.c @@ -22,58 +22,6 @@ static void send_404(GSocketConnection *connection) { } } -static void commands_list(GSocketConnection *connection, const gchar *cmd) { - GError *error = NULL; - 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]); - g_strfreev(data); - - struct directory *directory = music_find_dir(dirname); - if(directory == NULL) { - g_warning("couldn't find directory %s", dirname); - send_404(connection); - return; - } - - GString *list_string = g_string_new(NULL); - - for(GSList *node = directory->sub; node; node = g_slist_next(node)) { - struct directory *d = node->data; - gchar *name = g_path_get_basename(d->path); - g_string_append_printf(list_string, "%s\n", name); - g_free(name); - } - - for(GSList *node = directory->files; node; node = g_slist_next(node)) { - struct file *f = node->data; - g_string_append_printf(list_string, "%s\n", f->name); - } - - GString *string = g_string_new(NULL); - - g_string_append(string, "HTTP/1.1 200 OK\r\n"); - g_string_append(string, "content-type: text/plain\r\n"); - g_string_append_printf(string, "content-length: %lu\r\n", list_string->len); - g_string_append(string, "\r\n"); - g_string_append(string, list_string->str); - - g_string_free(list_string, TRUE); - - GOutputStream *os = g_io_stream_get_output_stream((GIOStream*)connection); - if(g_output_stream_write_all(os, string->str, string->len, NULL, NULL, - &error) == FALSE) { - g_warning(error->message); - g_error_free(error); - } - - g_string_free(string, TRUE); -} - static void commands_get_raw(GSocketConnection *connection, const gchar *cmd) { GError *error = NULL; gchar **data = g_strsplit(cmd, " ", 2); @@ -225,9 +173,7 @@ commands_get_mp3_free_path: 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); - } else if(g_ascii_strncasecmp(cmd, "/get_raw", 8) == 0) { + if(g_ascii_strncasecmp(cmd, "/get_raw", 8) == 0) { commands_get_raw(connection, cmd); } else if(g_ascii_strncasecmp(cmd, "/get_mp3", 8) == 0) { commands_get_mp3(connection, cmd); -- cgit v1.2.3