diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-08-27 22:52:34 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-08-27 22:52:34 +0200 |
commit | f8d1c20542111b9f359f4362638423ab23ed81c5 (patch) | |
tree | 9292b69c85ce54080cd71c4ebc48f1ec9873cb89 | |
parent | 6bb47a8f11ee8f6dff980f60758c4df48eeb9455 (diff) |
Split find into findl and findr, for local and remote search, respectively.
'find' without any suffix implicates a findl+findr search.
-rw-r--r-- | commands.c | 46 | ||||
-rw-r--r-- | server_communication.c | 15 |
2 files changed, 36 insertions, 25 deletions
@@ -58,33 +58,37 @@ static void commands_find(GSocketConnection *connection, const gchar *cmd, GErro gchar **data = g_strsplit(cmd, " ", 3); if(g_strv_length(data) != 3) { - *error = g_error_new(commands_quark(), 0, "syntax: find artist|title|album search"); + *error = g_error_new(commands_quark(), 0, "syntax: find[r|l] artist|title|album search"); return; } - gboolean remote = g_strncasecmp(data[0], "findr", 5) == 0 ? FALSE : TRUE; - - GSList *list = NULL; - if(g_ascii_strcasecmp(data[1], "artist") == 0) { - list = music_find_artist(data[2]); - } else if(g_ascii_strcasecmp(data[1] , "title") == 0) { - list = music_find_title(data[2]); - } else if(g_ascii_strcasecmp(data[1], "album") == 0) { - list = music_find_album(data[2]); - } else { - *error = g_error_new(commands_quark(), 0, "unknown search method %s", data[1]); - return; - } + gboolean remote = g_strncasecmp(data[0], "findl", 5) == 0 ? FALSE : TRUE; + gboolean local = g_strncasecmp(data[0], "findr", 5) == 0 ? FALSE : TRUE; GString *string = g_string_new(NULL); - 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); + + if(local == TRUE) { + GSList *list = NULL; + if(g_ascii_strcasecmp(data[1], "artist") == 0) { + list = music_find_artist(data[2]); + } else if(g_ascii_strcasecmp(data[1] , "title") == 0) { + list = music_find_title(data[2]); + } else if(g_ascii_strcasecmp(data[1], "album") == 0) { + list = music_find_album(data[2]); + } else { + *error = g_error_new(commands_quark(), 0, "unknown search method %s", data[1]); + return; + } + + 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); } - g_slist_free(list); if(remote == TRUE) { for(GSList *node = servers; node; node = g_slist_next(node)) { diff --git a/server_communication.c b/server_communication.c index 64de9dc..448ebbf 100644 --- a/server_communication.c +++ b/server_communication.c @@ -71,17 +71,16 @@ gboolean server_ping(struct server *server) { return result; } -gchar **server_find(struct server *server, const gchar *type, const gchar *str) { +static gchar **server_get_stringlist(struct server *server, const gchar *cmd) { GSocket *socket = server_connect(server); if(socket == NULL) { return NULL; } - gchar buffer[0x400]; - g_snprintf(buffer, 0x400, "findr %s %s\nexit\n", type, str); - g_socket_send(socket, buffer, strlen(buffer), NULL, NULL); + g_socket_send(socket, cmd, strlen(cmd), NULL, NULL); + gchar buffer[0x400]; gssize size; GString *string = g_string_new(NULL); while((size = g_socket_receive(socket, buffer, 0x400, NULL, NULL)) > 0) { @@ -95,3 +94,11 @@ gchar **server_find(struct server *server, const gchar *type, const gchar *str) return data; } + +gchar **server_find(struct server *server, const gchar *type, const gchar *str) { + gchar *cmd = g_strdup_printf("findl %s %s\nexit\n", type, str); + gchar **data = server_get_stringlist(server, cmd); + g_free(cmd); + + return data; +} |