diff options
Diffstat (limited to 'commands.c')
| -rw-r--r-- | commands.c | 23 | 
1 files changed, 9 insertions, 14 deletions
@@ -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);  	}  }  | 
