From 11c6e1039cb806529a8911c7f2bbac74681c3e23 Mon Sep 17 00:00:00 2001 From: Karl Heyes Date: Thu, 17 Nov 2005 00:54:28 +0000 Subject: [PATCH] change status code for server/stream full cases (#738), also some others places where connections are terminated. svn path=/icecast/trunk/icecast/; revision=10393 --- src/auth.c | 6 +++--- src/client.c | 15 ++++++++------- src/client.h | 2 +- src/connection.c | 10 +++++----- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/auth.c b/src/auth.c index 7932161b..a9ebd3fc 100644 --- a/src/auth.c +++ b/src/auth.c @@ -389,7 +389,7 @@ void add_client (const char *mount, client_t *client) if (mountinfo && mountinfo->no_mount) { config_release_config (); - client_send_404 (client, "mountpoint unavailable"); + client_send_403 (client, "mountpoint unavailable"); return; } if (mountinfo && mountinfo->auth) @@ -400,7 +400,7 @@ void add_client (const char *mount, client_t *client) { config_release_config (); WARN0 ("too many clients awaiting authentication"); - client_send_404 (client, "busy, please try again later"); + client_send_403 (client, "busy, please try again later"); return; } auth_client_setup (mountinfo, client); @@ -429,7 +429,7 @@ void add_client (const char *mount, client_t *client) int ret = add_authenticated_client (mount, mountinfo, client); config_release_config (); if (ret < 0) - client_send_404 (client, "stream full"); + client_send_403 (client, "max listeners reached"); } } diff --git a/src/client.c b/src/client.c index e4c31525..f2da419d 100644 --- a/src/client.c +++ b/src/client.c @@ -190,14 +190,15 @@ void client_send_401(client_t *client) { fserve_add_client (client, NULL); } -void client_send_403(client_t *client) { - int bytes = sock_write(client->con->sock, - "HTTP/1.0 403 Forbidden\r\n" - "\r\n" - "Access restricted.\r\n"); - if(bytes > 0) client->con->sent_bytes = bytes; +void client_send_403(client_t *client, const char *reason) +{ + if (reason == NULL) + reason = "Forbidden"; + snprintf (client->refbuf->data, PER_CLIENT_REFBUF_SIZE, + "HTTP/1.0 403 %s\r\n\r\n", reason); client->respcode = 403; - client_destroy(client); + client->refbuf->len = strlen (client->refbuf->data); + fserve_add_client (client, NULL); } diff --git a/src/client.h b/src/client.h index d9216cea..91e5cbae 100644 --- a/src/client.h +++ b/src/client.h @@ -72,7 +72,7 @@ void client_destroy(client_t *client); void client_send_504(client_t *client, char *message); void client_send_404(client_t *client, char *message); void client_send_401(client_t *client); -void client_send_403(client_t *client); +void client_send_403(client_t *client, const char *reason); void client_send_400(client_t *client, char *message); int client_send_bytes (client_t *client, const void *buf, unsigned len); int client_read_bytes (client_t *client, void *buf, unsigned len); diff --git a/src/connection.c b/src/connection.c index dbadb06c..62557695 100644 --- a/src/connection.c +++ b/src/connection.c @@ -438,7 +438,7 @@ void connection_accept_loop(void) if (client_create (&client, con, NULL) < 0) { global_unlock(); - client_send_404 (client, "Icecast connection limit reached"); + client_send_403 (client, "Icecast connection limit reached"); continue; } global_unlock(); @@ -515,7 +515,7 @@ int connection_complete_source (source_t *source, int response) config_release_config(); if (response) { - client_send_404 (source->client, "Content-type not supported"); + client_send_403 (source->client, "Content-type not supported"); source->client = NULL; } WARN1("Content-type \"%s\" not supported, dropping source", contenttype); @@ -535,7 +535,7 @@ int connection_complete_source (source_t *source, int response) config_release_config(); if (response) { - client_send_404 (source->client, "internal format allocation problem"); + client_send_403 (source->client, "internal format allocation problem"); source->client = NULL; } WARN1 ("plugin format failed for \"%s\"", source->mount); @@ -566,7 +566,7 @@ int connection_complete_source (source_t *source, int response) if (response) { - client_send_404 (source->client, "too many sources connected"); + client_send_403 (source->client, "too many sources connected"); source->client = NULL; } @@ -776,7 +776,7 @@ static void _handle_source_request (client_t *client, char *uri, int auth_style) } else { - client_send_404 (client, "Mountpoint in use"); + client_send_403 (client, "Mountpoint in use"); WARN1 ("Mountpoint %s in use", uri); } }