summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-08-20 19:10:27 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-08-20 19:10:27 +0200
commit02f779da234da8c17300ca849f9a2c1f8d4a48e0 (patch)
tree4a43f5591a6dc6ace9748cc9c32740b114ad9d9c
parentba6253a26a9ae21b5a65e8d9ece6bddbdd521b97 (diff)
Added some error reporting to the server command handling.
-rw-r--r--command_service.c2
-rw-r--r--commands.c23
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 <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);
}
}