Commit 8d75eb0b authored by Michael Smith's avatar Michael Smith

Logging cleanups, and a config file fix.

svn path=/trunk/icecast/; revision=3773
parent 9b6b2afe
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<paths> <paths>
<basedir>/usr/local/icecast</basedir> <basedir>/usr/local/icecast</basedir>
<logdir>/tmp</logdir> <logdir>/tmp</logdir>
<webroot>/usr/local/icecast/webroot</basedir> <webroot>/usr/local/icecast/webroot</webroot>
</paths> </paths>
<logging> <logging>
......
...@@ -151,7 +151,6 @@ static void _add_connection(connection_t *con) ...@@ -151,7 +151,6 @@ static void _add_connection(connection_t *con)
_queue = node; _queue = node;
thread_mutex_unlock(&_queue_mutex); thread_mutex_unlock(&_queue_mutex);
printf("connection added....\n");
} }
static void _signal_pool(void) static void _signal_pool(void)
...@@ -294,7 +293,6 @@ int connection_create_source(connection_t *con, http_parser_t *parser, char *mou ...@@ -294,7 +293,6 @@ int connection_create_source(connection_t *con, http_parser_t *parser, char *mou
*/ */
global_lock(); global_lock();
if (global.sources >= config_get_config()->source_limit) { if (global.sources >= config_get_config()->source_limit) {
printf("TOO MANY SOURCE, KICKING THIS ONE\n");
INFO1("Source (%s) logged in, but there are too many sources", mount); INFO1("Source (%s) logged in, but there are too many sources", mount);
global_unlock(); global_unlock();
return 0; return 0;
...@@ -310,18 +308,26 @@ int connection_create_source(connection_t *con, http_parser_t *parser, char *mou ...@@ -310,18 +308,26 @@ int connection_create_source(connection_t *con, http_parser_t *parser, char *mou
format_type_t format = format_get_type(contenttype); format_type_t format = format_get_type(contenttype);
if (format < 0) { if (format < 0) {
WARN1("Content-type \"%s\" not supported, dropping source", contenttype); WARN1("Content-type \"%s\" not supported, dropping source", contenttype);
return 0; goto fail;
} else { } else {
source = source_create(con, parser, mount, format); source = source_create(con, parser, mount, format);
} }
} else { } else {
WARN0("No content-type header, cannot handle source"); WARN0("No content-type header, cannot handle source");
return 0; goto fail;
} }
source->shutdown_rwlock = &_source_shutdown_rwlock; source->shutdown_rwlock = &_source_shutdown_rwlock;
sock_set_blocking(con->sock, SOCK_NONBLOCK); sock_set_blocking(con->sock, SOCK_NONBLOCK);
thread_create("Source Thread", source_main, (void *)source, THREAD_DETACHED); thread_create("Source Thread", source_main, (void *)source, THREAD_DETACHED);
return 1; return 1;
fail:
global_lock();
global.sources--;
global_unlock();
stats_event_dec(NULL, "sources");
return 0;
} }
static void *_handle_connection(void *arg) static void *_handle_connection(void *arg)
...@@ -363,18 +369,18 @@ static void *_handle_connection(void *arg) ...@@ -363,18 +369,18 @@ static void *_handle_connection(void *arg)
/* handle the connection or something */ /* handle the connection or something */
if (strcmp("ICE", httpp_getvar(parser, HTTPP_VAR_PROTOCOL)) != 0 && strcmp("HTTP", httpp_getvar(parser, HTTPP_VAR_PROTOCOL)) != 0) { if (strcmp("ICE", httpp_getvar(parser, HTTPP_VAR_PROTOCOL)) != 0 && strcmp("HTTP", httpp_getvar(parser, HTTPP_VAR_PROTOCOL)) != 0) {
printf("DEBUG: bad protocol\n"); ERROR0("Bad HTTP protocol detected");
connection_close(con); connection_close(con);
httpp_destroy(parser); httpp_destroy(parser);
continue; continue;
} }
if (parser->req_type == httpp_req_source) { if (parser->req_type == httpp_req_source) {
printf("DEBUG: source logging in\n"); INFO1("Source logging in at mountpoint \"%s\"",
httpp_getvar(parser, HTTPP_VAR_URI));
stats_event_inc(NULL, "source_connections"); stats_event_inc(NULL, "source_connections");
if (strcmp((httpp_getvar(parser, "ice-password") != NULL) ? httpp_getvar(parser, "ice-password") : "", (config_get_config()->source_password != NULL) ? config_get_config()->source_password : "") != 0) { if (strcmp((httpp_getvar(parser, "ice-password") != NULL) ? httpp_getvar(parser, "ice-password") : "", (config_get_config()->source_password != NULL) ? config_get_config()->source_password : "") != 0) {
printf("DEBUG: bad password\n");
INFO1("Source (%s) attempted to login with bad password", httpp_getvar(parser, HTTPP_VAR_URI)); INFO1("Source (%s) attempted to login with bad password", httpp_getvar(parser, HTTPP_VAR_URI));
connection_close(con); connection_close(con);
httpp_destroy(parser); httpp_destroy(parser);
...@@ -387,7 +393,6 @@ static void *_handle_connection(void *arg) ...@@ -387,7 +393,6 @@ static void *_handle_connection(void *arg)
avl_tree_rlock(global.source_tree); avl_tree_rlock(global.source_tree);
if (source_find_mount(httpp_getvar(parser, HTTPP_VAR_URI)) != NULL) { if (source_find_mount(httpp_getvar(parser, HTTPP_VAR_URI)) != NULL) {
printf("Source attempted to connect with an already used mountpoint.\n");
INFO1("Source tried to log in as %s, but is already used", httpp_getvar(parser, HTTPP_VAR_URI)); INFO1("Source tried to log in as %s, but is already used", httpp_getvar(parser, HTTPP_VAR_URI));
connection_close(con); connection_close(con);
httpp_destroy(parser); httpp_destroy(parser);
...@@ -403,11 +408,10 @@ static void *_handle_connection(void *arg) ...@@ -403,11 +408,10 @@ static void *_handle_connection(void *arg)
continue; continue;
} else if (parser->req_type == httpp_req_stats) { } else if (parser->req_type == httpp_req_stats) {
printf("DEBUG: stats connection...\n");
stats_event_inc(NULL, "stats_connections"); stats_event_inc(NULL, "stats_connections");
if (strcmp((httpp_getvar(parser, "ice-password") != NULL) ? httpp_getvar(parser, "ice-password") : "", (config_get_config()->source_password != NULL) ? config_get_config()->source_password : "") != 0) { if (strcmp((httpp_getvar(parser, "ice-password") != NULL) ? httpp_getvar(parser, "ice-password") : "", (config_get_config()->source_password != NULL) ? config_get_config()->source_password : "") != 0) {
printf("DEBUG: bad password\n"); ERROR0("Bad password for stats connection");
connection_close(con); connection_close(con);
httpp_destroy(parser); httpp_destroy(parser);
continue; continue;
...@@ -424,7 +428,7 @@ static void *_handle_connection(void *arg) ...@@ -424,7 +428,7 @@ static void *_handle_connection(void *arg)
continue; continue;
} else if (parser->req_type == httpp_req_play || parser->req_type == httpp_req_get) { } else if (parser->req_type == httpp_req_play || parser->req_type == httpp_req_get) {
printf("DEBUG: client coming in...\n"); DEBUG0("Client connected");
/* make a client */ /* make a client */
client = client_create(con, parser); client = client_create(con, parser);
...@@ -439,7 +443,7 @@ static void *_handle_connection(void *arg) ...@@ -439,7 +443,7 @@ static void *_handle_connection(void *arg)
*/ */
// TODO: add GUID-xxxxxx // TODO: add GUID-xxxxxx
if (strcmp(httpp_getvar(parser, HTTPP_VAR_URI), "/stats.xml") == 0) { if (strcmp(httpp_getvar(parser, HTTPP_VAR_URI), "/stats.xml") == 0) {
printf("sending stats.xml\n"); DEBUG0("Stats request, sending xml stats");
stats_sendxml(client); stats_sendxml(client);
client_destroy(client); client_destroy(client);
continue; continue;
...@@ -454,6 +458,7 @@ static void *_handle_connection(void *arg) ...@@ -454,6 +458,7 @@ static void *_handle_connection(void *arg)
/* If the file exists, then transform it, otherwise, write a 404 error */ /* If the file exists, then transform it, otherwise, write a 404 error */
if (stat(fullPath, &statbuf) == 0) { if (stat(fullPath, &statbuf) == 0) {
DEBUG0("Stats request, sending XSL transformed stats");
sock_write(client->con->sock, "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"); sock_write(client->con->sock, "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
stats_transform_xslt(client, fullPath); stats_transform_xslt(client, fullPath);
} }
...@@ -467,7 +472,6 @@ static void *_handle_connection(void *arg) ...@@ -467,7 +472,6 @@ static void *_handle_connection(void *arg)
if (strcmp(httpp_getvar(parser, HTTPP_VAR_URI), "/allstreams.txt") == 0) { if (strcmp(httpp_getvar(parser, HTTPP_VAR_URI), "/allstreams.txt") == 0) {
if (strcmp((httpp_getvar(parser, "ice-password") != NULL) ? httpp_getvar(parser, "ice-password") : "", (config_get_config()->source_password != NULL) ? config_get_config()->source_password : "") != 0) { if (strcmp((httpp_getvar(parser, "ice-password") != NULL) ? httpp_getvar(parser, "ice-password") : "", (config_get_config()->source_password != NULL) ? config_get_config()->source_password : "") != 0) {
printf("DEBUG: bad password for allstreams.txt\n");
INFO0("Client attempted to fetch allstreams.txt with bad password"); INFO0("Client attempted to fetch allstreams.txt with bad password");
if (parser->req_type == httpp_req_get) { if (parser->req_type == httpp_req_get) {
client->respcode = 404; client->respcode = 404;
...@@ -508,7 +512,7 @@ static void *_handle_connection(void *arg) ...@@ -508,7 +512,7 @@ static void *_handle_connection(void *arg)
avl_tree_rlock(global.source_tree); avl_tree_rlock(global.source_tree);
source = source_find_mount(httpp_getvar(parser, HTTPP_VAR_URI)); source = source_find_mount(httpp_getvar(parser, HTTPP_VAR_URI));
if (source) { if (source) {
printf("DEBUG: source found for client\n"); DEBUG0("Source found for client");
global_lock(); global_lock();
if (global.clients >= config_get_config()->client_limit) { if (global.clients >= config_get_config()->client_limit) {
...@@ -534,7 +538,6 @@ static void *_handle_connection(void *arg) ...@@ -534,7 +538,6 @@ static void *_handle_connection(void *arg)
while (node) { while (node) {
var = (http_var_t *)node->key; var = (http_var_t *)node->key;
if (strcasecmp(var->name, "ice-password") && !strncasecmp("ice-", var->name, 4)) { if (strcasecmp(var->name, "ice-password") && !strncasecmp("ice-", var->name, 4)) {
printf("DEBUG: sending %s: %s\n", var->name, var->value);
sock_write(client->con->sock, "%s: %s\r\n", var->name, var->value); sock_write(client->con->sock, "%s: %s\r\n", var->name, var->value);
} }
node = avl_get_next(node); node = avl_get_next(node);
...@@ -554,7 +557,7 @@ static void *_handle_connection(void *arg) ...@@ -554,7 +557,7 @@ static void *_handle_connection(void *arg)
avl_tree_unlock(global.source_tree); avl_tree_unlock(global.source_tree);
if (!source) { if (!source) {
printf("DEBUG: source not found for client\n"); DEBUG0("Source not found for client");
if (parser->req_type == httpp_req_get) { if (parser->req_type == httpp_req_get) {
client->respcode = 404; client->respcode = 404;
bytes = sock_write(client->con->sock, "HTTP/1.0 404 Source Not Found\r\nContent-Type: text/html\r\n\r\n"\ bytes = sock_write(client->con->sock, "HTTP/1.0 404 Source Not Found\r\nContent-Type: text/html\r\n\r\n"\
...@@ -566,13 +569,13 @@ static void *_handle_connection(void *arg) ...@@ -566,13 +569,13 @@ static void *_handle_connection(void *arg)
continue; continue;
} else { } else {
printf("DEBUG: wrong request type\n"); ERROR0("Wrong request type from client");
connection_close(con); connection_close(con);
httpp_destroy(parser); httpp_destroy(parser);
continue; continue;
} }
} else { } else {
printf("DEBUG: parsing failed\n"); ERROR0("HTTP request parsing failed");
connection_close(con); connection_close(con);
httpp_destroy(parser); httpp_destroy(parser);
continue; continue;
......
...@@ -82,7 +82,7 @@ static void *_slave_thread(void *arg) { ...@@ -82,7 +82,7 @@ static void *_slave_thread(void *arg) {
mastersock = sock_connect_wto(config_get_config()->master_server, config_get_config()->master_server_port, 0); mastersock = sock_connect_wto(config_get_config()->master_server, config_get_config()->master_server_port, 0);
if (mastersock == SOCK_ERROR) { if (mastersock == SOCK_ERROR) {
printf("DEBUG: failed to contact master server\n"); WARN0("Relay slave failed to contact master server to fetch stream list");
continue; continue;
} }
sock_write(mastersock, "GET /allstreams.txt HTTP/1.0\r\nice-password: %s\r\n\r\n", config_get_config()->source_password); sock_write(mastersock, "GET /allstreams.txt HTTP/1.0\r\nice-password: %s\r\n\r\n", config_get_config()->source_password);
...@@ -91,10 +91,11 @@ static void *_slave_thread(void *arg) { ...@@ -91,10 +91,11 @@ static void *_slave_thread(void *arg) {
avl_tree_rlock(global.source_tree); avl_tree_rlock(global.source_tree);
if (!source_find_mount(buf)) { if (!source_find_mount(buf)) {
avl_tree_unlock(global.source_tree); avl_tree_unlock(global.source_tree);
printf("DEBUG: adding source for %s\n", buf);
DEBUG1("Adding source at mountpoint \"%s\"", buf);
streamsock = sock_connect_wto(config_get_config()->master_server, config_get_config()->master_server_port, 0); streamsock = sock_connect_wto(config_get_config()->master_server, config_get_config()->master_server_port, 0);
if (streamsock == SOCK_ERROR) { if (streamsock == SOCK_ERROR) {
printf("DEBUG: failed to get stream from master server\n"); WARN0("Failed to relay stream from master server");
continue; continue;
} }
con = create_connection(streamsock, NULL); con = create_connection(streamsock, NULL);
......
...@@ -173,8 +173,7 @@ void *source_main(void *arg) ...@@ -173,8 +173,7 @@ void *source_main(void *arg)
} }
if (bytes <= 0) { if (bytes <= 0) {
printf("DEBUG: got 0 bytes reading data, the source must have disconnected...\n"); INFO0("Removing source following disconnection");
INFO0("Disconnecting lame source...");
break; break;
} }
...@@ -225,10 +224,10 @@ void *source_main(void *arg) ...@@ -225,10 +224,10 @@ void *source_main(void *arg)
} }
if (sbytes < 0) { if (sbytes < 0) {
if (!sock_recoverable(sock_error())) { if (!sock_recoverable(sock_error())) {
printf("SOURCE: Client had unrecoverable error catching up (%ld/%ld)\n", sbytes, bytes); DEBUG0("Client has unrecoverable error catching up. Client has probably disconnected");
client->con->error = 1; client->con->error = 1;
} else { } else {
printf("SOURCE: client had recoverable error...\n"); DEBUG1("Client had recoverable error %ld", sock_error());
/* put the refbuf back on top of the queue, since we didn't finish with it */ /* put the refbuf back on top of the queue, since we didn't finish with it */
refbuf_queue_insert(&client->queue, abuf); refbuf_queue_insert(&client->queue, abuf);
} }
...@@ -262,10 +261,10 @@ void *source_main(void *arg) ...@@ -262,10 +261,10 @@ void *source_main(void *arg)
if (sbytes < 0) { if (sbytes < 0) {
bytes = sock_error(); bytes = sock_error();
if (!sock_recoverable(bytes)) { if (!sock_recoverable(bytes)) {
printf("SOURCE: client had unrecoverable error %ld with new data (%ld/%ld)\n", bytes, sbytes, refbuf->len); DEBUG0("Client had unrecoverable error with new data, probably due to client disconnection");
client->con->error = 1; client->con->error = 1;
} else { } else {
printf("SOURCE: recoverable error %ld\n", bytes); DEBUG1("Client had recoverable error %ld", bytes);
client->pos = 0; client->pos = 0;
refbuf_addref(refbuf); refbuf_addref(refbuf);
refbuf_queue_insert(&client->queue, refbuf); refbuf_queue_insert(&client->queue, refbuf);
...@@ -280,7 +279,7 @@ void *source_main(void *arg) ...@@ -280,7 +279,7 @@ void *source_main(void *arg)
** TODO: put queue_limit in a config file ** TODO: put queue_limit in a config file
*/ */
if (refbuf_queue_size(&client->queue) > 25) { if (refbuf_queue_size(&client->queue) > 25) {
printf("SOURCE: client is too lagged... kicking\n"); DEBUG0("Client has fallen too far behind, removing");
client->con->error = 1; client->con->error = 1;
} }
...@@ -311,7 +310,7 @@ void *source_main(void *arg) ...@@ -311,7 +310,7 @@ void *source_main(void *arg)
global_unlock(); global_unlock();
stats_event_dec(NULL, "clients"); stats_event_dec(NULL, "clients");
stats_event_args(source->mount, "listeners", "%d", listeners); stats_event_args(source->mount, "listeners", "%d", listeners);
printf("DEBUG: Client dropped...\n"); DEBUG0("Client removed");
continue; continue;
} }
client_node = avl_get_next(client_node); client_node = avl_get_next(client_node);
...@@ -325,7 +324,7 @@ void *source_main(void *arg) ...@@ -325,7 +324,7 @@ void *source_main(void *arg)
while (client_node) { while (client_node) {
avl_insert(source->client_tree, client_node->key); avl_insert(source->client_tree, client_node->key);
listeners++; listeners++;
printf("Client added\n"); DEBUG0("Client added");
stats_event_inc(NULL, "clients"); stats_event_inc(NULL, "clients");
stats_event_inc(source->mount, "connections"); stats_event_inc(source->mount, "connections");
stats_event_args(source->mount, "listeners", "%d", listeners); stats_event_args(source->mount, "listeners", "%d", listeners);
...@@ -355,7 +354,7 @@ void *source_main(void *arg) ...@@ -355,7 +354,7 @@ void *source_main(void *arg)
done: done:
printf("DEBUG: we're going down...\n"); DEBUG0("Source exiting");
/* we need to empty the client and pending trees */ /* we need to empty the client and pending trees */
avl_tree_wlock(source->pending_tree); avl_tree_wlock(source->pending_tree);
...@@ -373,8 +372,6 @@ done: ...@@ -373,8 +372,6 @@ done:
stats_event_dec(NULL, "sources"); stats_event_dec(NULL, "sources");
stats_event(source->mount, "listeners", NULL); stats_event(source->mount, "listeners", NULL);
printf("DEBUG: source_main() is now exiting...\n");
global_lock(); global_lock();
global.sources--; global.sources--;
global_unlock(); global_unlock();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment