summaryrefslogtreecommitdiff
path: root/control_commands.c
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-08-26 22:36:07 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-08-26 22:36:07 +0200
commit9c7db46be9933e36e79b4caac86a5bdc3183122d (patch)
tree7d31a4ed584d975befe634207ac84925b21ee592 /control_commands.c
parent3991db2df701b5b6a0401e6974811db3e15edb39 (diff)
Merged commands.c and control_commands.c.
Diffstat (limited to 'control_commands.c')
-rw-r--r--control_commands.c89
1 files changed, 0 insertions, 89 deletions
diff --git a/control_commands.c b/control_commands.c
deleted file mode 100644
index 41e8965..0000000
--- a/control_commands.c
+++ /dev/null
@@ -1,89 +0,0 @@
-#include "control_commands.h"
-#include "servers.h"
-#include "music.h"
-#include "server_communication.h"
-
-#include <glib.h>
-#include <string.h>
-
-static void list_servers(GSocketConnection *connection, const gchar *cmd) {
- GSocket *socket = g_socket_connection_get_socket(connection);
-
- for(GSList *node = servers; node; node = g_slist_next(node)) {
- struct server *s = node->data;
- gchar *buffer = g_strdup_printf("%s:%d\n", s->host, s->port);
- g_socket_send(socket, buffer, strlen(buffer), NULL, NULL);
- }
-}
-
-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) {
- 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 {
- g_debug("unknown search");
- }
-
- 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);
- }
- g_slist_free(list);
-
- 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) {
- g_warning(error->message);
- g_error_free(error);
- }
- g_string_free(string, TRUE);
-}
-
-void control_commands_handle(GSocketConnection *connection, const gchar *cmd) {
- if(g_strcmp0(cmd, "servers") == 0) {
- list_servers(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);
- GSocket *socket = g_socket_connection_get_socket(connection);
- g_socket_send(socket, buf, strlen(buf), NULL, NULL);
- g_free(buf);
- }
-}