summaryrefslogtreecommitdiff
path: root/commands.c
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-08-20 14:40:48 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-08-20 14:40:48 +0200
commit5241f71a41f4125281f9215dd30b8fc4dfc546b1 (patch)
tree4fe2b1b060534e72de2c95e7ddb4a20987d2e715 /commands.c
parent566d311638aca1ed21da78a5dce320e94134160b (diff)
Added a service for server commands and moved the list command in there.
Diffstat (limited to 'commands.c')
-rw-r--r--commands.c56
1 files changed, 1 insertions, 55 deletions
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);