summaryrefslogtreecommitdiff
path: root/commands.c
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-08-16 00:51:20 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-08-16 00:51:20 +0200
commitb4cbca161a1638e96d9e0a6fe12a29ed43173e43 (patch)
tree296cc7512f6e4baf1e357cedd628356bc2cf5aa5 /commands.c
Committed some work.
Diffstat (limited to 'commands.c')
-rw-r--r--commands.c31
1 files changed, 31 insertions, 0 deletions
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 <glib.h>
+#include <string.h>
+
+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);
+ }
+}