diff options
-rw-r--r-- | commands.c | 23 | ||||
-rw-r--r-- | server_communication.c | 2 |
2 files changed, 24 insertions, 1 deletions
@@ -1,5 +1,7 @@ #include "commands.h" #include "music.h" +#include "servers.h" +#include "server_communication.h" #include <string.h> @@ -62,6 +64,8 @@ static void commands_find(GSocketConnection *connection, const gchar *cmd, GErro return; } + gboolean remote = g_strncasecmp(data[0], "rfind", 5) == 0 ? TRUE : FALSE; + GSList *list = NULL; if(g_ascii_strcasecmp(data[1], "artist") == 0) { list = music_find_artist(data[2]); @@ -83,6 +87,25 @@ static void commands_find(GSocketConnection *connection, const gchar *cmd, GErro } g_slist_free(list); + if(remote == TRUE) { + for(GSList *node = servers; node; node = g_slist_next(node)) { + struct server *server = node->data; + g_debug("fetching data from server %s", server->host); + gchar **temp = server_find(server, data[1], data[2]); + if(temp == NULL) { + continue; + } + for(gint i = 0; i < g_strv_length(temp); i++) { + if(strlen(temp[i]) == 0) { + break; + } + g_string_append_printf(string, "%s:%s\n", server->host, temp[i]); + } + g_strfreev(temp); + } + } + + 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) { diff --git a/server_communication.c b/server_communication.c index f331a35..e32f6bc 100644 --- a/server_communication.c +++ b/server_communication.c @@ -79,7 +79,7 @@ gchar **server_find(struct server *server, const gchar *type, const gchar *str) } gchar buffer[0x400]; - g_snprintf(buffer, 0x400, "find %s %s\nexit\n", type, str); + g_snprintf(buffer, 0x400, "rfind %s %s\nexit\n", type, str); g_socket_send(socket, buffer, strlen(buffer), NULL, NULL); gssize size; |