From 02f779da234da8c17300ca849f9a2c1f8d4a48e0 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 20 Aug 2010 19:10:27 +0200 Subject: Added some error reporting to the server command handling. --- command_service.c | 2 +- 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"); diff --git a/commands.c b/commands.c index 1e59449..5a2d69e 100644 --- a/commands.c +++ b/commands.c @@ -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 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); } } -- cgit v1.2.3