summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--commands.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/commands.c b/commands.c
index 823b132..faf12cc 100644
--- a/commands.c
+++ b/commands.c
@@ -54,6 +54,46 @@ static void commands_list(GSocketConnection *connection, const gchar *cmd) {
g_string_free(string, TRUE);
}
+static void commands_find(GSocketConnection *connection, const gchar *cmd) {
+ GError *error = NULL;
+ gchar **data = g_strsplit(cmd, " ", 3);
+
+ if(g_strv_length(data) != 3) {
+ const gchar *buf = "syntax: find (artist) search\n";
+ GSocket *socket = g_socket_connection_get_socket(connection);
+ g_socket_send(socket, buf, strlen(buf), NULL, NULL);
+ return;
+ }
+
+ GSList *list = NULL;
+ g_debug("strlen(%s) == %d", data[1], strlen(data[1]));
+ if(g_ascii_strcasecmp(data[1], "artist") == 0) {
+ g_debug("artist search");
+ list = music_find_artist(data[2]);
+ } else {
+ g_debug("unknown search");
+ }
+
+ GString *string = g_string_new(NULL);
+ g_string_append_printf(string, "%d\n", g_slist_length(list));
+ for(GSList *node = list; node; node = g_slist_next(node)) {
+ struct file *f = node->data;
+ gchar *relpath = g_build_filename(f->parent->path +
+ strlen(music_root->path), f->name, NULL);
+ g_string_append_printf(string, "%s\n", relpath);
+ g_free(relpath);
+ }
+ g_slist_free(list);
+
+ 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_ping(GSocketConnection *connection, const gchar *cmd) {
GError *error = NULL;
GSocket *socket = g_socket_connection_get_socket(connection);
@@ -69,6 +109,8 @@ void commands_handle(GSocketConnection *connection, const gchar *cmd) {
commands_ping(connection, cmd);
} else if(g_strncasecmp(cmd, "list", 4) == 0) {
commands_list(connection, cmd);
+ } else if(g_strncasecmp(cmd, "find", 4) == 0) {
+ commands_find(connection, cmd);
} else {
g_debug("unknown command");
gchar *buf = g_strdup_printf("error: unknown command %s\n", cmd);