summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--commands.c46
-rw-r--r--server_communication.c15
2 files changed, 36 insertions, 25 deletions
diff --git a/commands.c b/commands.c
index e8f552a..98d775c 100644
--- a/commands.c
+++ b/commands.c
@@ -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;
+}