summaryrefslogtreecommitdiff
path: root/commands.c
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-08-16 01:48:51 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-08-16 01:48:51 +0200
commit1a79de743029449f0728021157b324d8a14bef64 (patch)
tree5952cb4871b3a1a88e280e80ff103372f3cba76c /commands.c
parent4fcb7baeec6d7c2f9fb9c976a66b78e80fd8622e (diff)
Implemented the get_raw command.
Diffstat (limited to 'commands.c')
-rw-r--r--commands.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/commands.c b/commands.c
index dfdce42..f15c2c6 100644
--- a/commands.c
+++ b/commands.c
@@ -3,6 +3,7 @@
#include <glib.h>
#include <string.h>
+#include <gio/gio.h>
static void commands_list(GSocketConnection *connection, const gchar *cmd) {
gchar **data = g_strsplit(cmd, " ", 2);
@@ -12,6 +13,7 @@ static void commands_list(GSocketConnection *connection, const gchar *cmd) {
g_assert(data[0] != NULL && data[1] != NULL);
gchar *dirname = g_strdup(data[1]);
+ g_strfreev(data);
struct directory *directory = music_find_dir(dirname);
g_assert(directory != NULL);
@@ -31,9 +33,50 @@ static void commands_list(GSocketConnection *connection, const gchar *cmd) {
}
}
+static void commands_get_raw(GSocketConnection *connection, const gchar *cmd) {
+ GError *error = NULL;
+ gchar **data = g_strsplit(cmd, " ", 2);
+ g_assert(data[0] != NULL && data[1] != NULL);
+
+ gchar *path = g_strdup(data[1]);
+ g_strfreev(data);
+
+ struct file *f = music_find_file(path);
+
+ if(f == NULL) {
+ g_error("couldn't find %s", path);
+ }
+
+ GOutputStream *os = g_io_stream_get_output_stream((GIOStream*)connection);
+ GFile *file = g_file_new_for_path(path);
+ GFileInputStream *is = g_file_read(file, NULL, &error);
+
+ if(is == NULL) {
+ g_error(error->message);
+ }
+
+ gssize size = g_output_stream_splice(os, (GInputStream*)is,
+ G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE ||
+ G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
+ NULL, &error);
+ if(size == -1) {
+ g_error(error->message);
+ }
+ g_debug("wrote %lu bytes of file data", size);
+
+ g_object_unref(is);
+ g_object_unref(file);
+
+ g_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) {
+ commands_get_raw(connection, cmd);
+ } else {
+ g_warning("no command handlers found");
}
}