diff options
-rw-r--r-- | command_service.c | 2 | ||||
-rw-r--r-- | commands.c | 23 |
2 files changed, 10 insertions, 15 deletions
diff --git a/command_service.c b/command_service.c index 3a594aa..562c7f4 100644 --- a/command_service.c +++ b/command_service.c @@ -22,7 +22,7 @@ static gboolean service_incoming(GSocketService *service, break; } - g_debug("size == %d", size); + g_debug("size == %ld", size); g_debug(buffer); gchar *pos = g_strstr_len(buffer, size, "\r"); @@ -1,19 +1,7 @@ #include "commands.h" #include "music.h" -static void send_404(GSocketConnection *connection) { - GError *error = NULL; - GString *string = g_string_new(NULL); - g_string_append(string, "HTTP/1.1 404 Not Found\r\n"); - g_string_append(string, "\r\n"); - - 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); - } -} +#include <string.h> static void commands_list(GSocketConnection *connection, const gchar *cmd) { GError *error = NULL; @@ -35,7 +23,10 @@ static void commands_list(GSocketConnection *connection, const gchar *cmd) { struct directory *directory = music_find_dir(dirname); if(directory == NULL) { g_warning("couldn't find directory %s", dirname); - send_404(connection); + gchar *buf = g_strdup_printf("error: couldn't find directory %s\n", dirname); + GSocket *socket = g_socket_connection_get_socket(connection); + g_socket_send(socket, buf, strlen(buf), NULL, NULL); + g_free(buf); return; } @@ -69,5 +60,9 @@ void commands_handle(GSocketConnection *connection, const gchar *cmd) { commands_list(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); } } |