From 84a76ac3eef0c33ed2f4f45113a92e9fed045aa8 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sat, 10 Aug 2002 08:01:56 +0000 Subject: [PATCH] status.xsl updates, better now. Automatically create .m3u responses for any existing streams. If /stream.ogg exists, you can now request /stream.ogg.m3u in your browser. svn path=/trunk/icecast/; revision=3797 --- src/connection.c | 50 +++++++++++++++++++++++++++++++++++---------- src/format.h | 2 ++ src/format_mp3.c | 1 + src/format_vorbis.c | 1 + src/source.c | 3 +++ src/util.c | 11 +++++++++- src/util.h | 1 + web/status.xsl | 35 ++++++++++++++++++++++++++++--- 8 files changed, 89 insertions(+), 15 deletions(-) diff --git a/src/connection.c b/src/connection.c index a9ecc498..b7429afc 100644 --- a/src/connection.c +++ b/src/connection.c @@ -344,6 +344,7 @@ static void *_handle_connection(void *arg) int bytes; struct stat statbuf; char fullPath[4096]; + char *uri; while (global.running == ICE_RUNNING) { memset(header, 0, 4096); @@ -376,13 +377,14 @@ static void *_handle_connection(void *arg) continue; } + uri = httpp_getvar(parser, HTTPP_VAR_URI); + if (parser->req_type == httpp_req_source) { - INFO1("Source logging in at mountpoint \"%s\"", - httpp_getvar(parser, HTTPP_VAR_URI)); + INFO1("Source logging in at mountpoint \"%s\"", uri); 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) { - INFO1("Source (%s) attempted to login with bad password", httpp_getvar(parser, HTTPP_VAR_URI)); + INFO1("Source (%s) attempted to login with bad password", uri); connection_close(con); httpp_destroy(parser); continue; @@ -393,8 +395,8 @@ static void *_handle_connection(void *arg) */ avl_tree_rlock(global.source_tree); - if (source_find_mount(httpp_getvar(parser, HTTPP_VAR_URI)) != NULL) { - INFO1("Source tried to log in as %s, but is already used", httpp_getvar(parser, HTTPP_VAR_URI)); + if (source_find_mount(uri) != NULL) { + INFO1("Source tried to log in as %s, but is already used", uri); connection_close(con); httpp_destroy(parser); avl_tree_unlock(global.source_tree); @@ -402,7 +404,7 @@ static void *_handle_connection(void *arg) } avl_tree_unlock(global.source_tree); - if (!connection_create_source(con, parser, httpp_getvar(parser, HTTPP_VAR_URI))) { + if (!connection_create_source(con, parser, uri)) { connection_close(con); httpp_destroy(parser); } @@ -443,7 +445,7 @@ static void *_handle_connection(void *arg) ** aren't subject to the limits. */ // TODO: add GUID-xxxxxx - if (strcmp(httpp_getvar(parser, HTTPP_VAR_URI), "/stats.xml") == 0) { + if (strcmp(uri, "/stats.xml") == 0) { DEBUG0("Stats request, sending xml stats"); stats_sendxml(client); client_destroy(client); @@ -454,8 +456,8 @@ static void *_handle_connection(void *arg) ** if the extension is .xsl, if so, then process ** this request as an XSLT request */ - if (util_check_valid_extension(httpp_getvar(parser, HTTPP_VAR_URI)) == XSLT_CONTENT) { - util_get_full_path(httpp_getvar(parser, HTTPP_VAR_URI), fullPath, sizeof(fullPath)); + if (util_check_valid_extension(uri) == XSLT_CONTENT) { + util_get_full_path(uri, fullPath, sizeof(fullPath)); /* If the file exists, then transform it, otherwise, write a 404 error */ if (stat(fullPath, &statbuf) == 0) { @@ -473,7 +475,33 @@ static void *_handle_connection(void *arg) continue; } - if (strcmp(httpp_getvar(parser, HTTPP_VAR_URI), "/allstreams.txt") == 0) { + if(strcmp(util_get_extension(uri), "m3u") == 0) { + char *sourceuri = strdup(uri); + char *dot = strrchr(sourceuri, '.'); + *dot = 0; + avl_tree_rlock(global.source_tree); + source = source_find_mount(sourceuri); + if (source) { + client->respcode = 200; + bytes = sock_write(client->con->sock, + "HTTP/1.0 200 OK\r\nContent-Type: audio/x-mpegurl\r\n\r\nhttp://%s:%d%s", + config_get_config()->hostname, + config_get_config()->port, + sourceuri + ); + } + else { + client->respcode = 404; + bytes = sock_write(client->con->sock, + "HTTP/1.0 404 Not Found\r\nContent-Type: text/html\r\nThe file you requested could not be found\r\n"); + } + avl_tree_unlock(global.source_tree); + if(bytes > 0) client->con->sent_bytes = bytes; + client_destroy(client); + continue; + } + + if (strcmp(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) { INFO0("Client attempted to fetch allstreams.txt with bad password"); if (parser->req_type == httpp_req_get) { @@ -518,7 +546,7 @@ static void *_handle_connection(void *arg) global_unlock(); avl_tree_rlock(global.source_tree); - source = source_find_mount(httpp_getvar(parser, HTTPP_VAR_URI)); + source = source_find_mount(uri); if (source) { DEBUG0("Source found for client"); diff --git a/src/format.h b/src/format.h index 9c7d7f46..946bc224 100644 --- a/src/format.h +++ b/src/format.h @@ -19,6 +19,8 @@ typedef struct _format_plugin_tag /* we need to know the mount to report statistics */ char *mount; + char *format_description; + /* set this is the data format has a header that ** we must send before regular data */ diff --git a/src/format_mp3.c b/src/format_mp3.c index d21e3ee2..50253b21 100644 --- a/src/format_mp3.c +++ b/src/format_mp3.c @@ -28,6 +28,7 @@ format_plugin_t *format_mp3_get_plugin(void) plugin->get_buffer = format_mp3_get_buffer; plugin->get_predata = format_mp3_get_predata; plugin->free_plugin = format_mp3_free_plugin; + plugin->format_description = "MP3 audio"; plugin->_state = NULL; diff --git a/src/format_vorbis.c b/src/format_vorbis.c index 4b0116fd..0f0a0267 100644 --- a/src/format_vorbis.c +++ b/src/format_vorbis.c @@ -52,6 +52,7 @@ format_plugin_t *format_vorbis_get_plugin(void) plugin->get_buffer = format_vorbis_get_buffer; plugin->get_predata = format_vorbis_get_predata; plugin->free_plugin = format_vorbis_free_plugin; + plugin->format_description = "Ogg Vorbis"; state = (vstate_t *)calloc(1, sizeof(vstate_t)); ogg_sync_init(&state->oy); diff --git a/src/source.c b/src/source.c index 9ed9c4c6..2144929c 100644 --- a/src/source.c +++ b/src/source.c @@ -139,10 +139,13 @@ void *source_main(void *arg) stats_event(source->mount, "name", s); if ((s = httpp_getvar(source->parser, "ice-url"))) stats_event(source->mount, "url", s); + if ((s = httpp_getvar(source->parser, "ice-genre"))) + stats_event(source->mount, "genre", s); if ((s = httpp_getvar(source->parser, "ice-bitrate"))) stats_event(source->mount, "bitrate", s); if ((s = httpp_getvar(source->parser, "ice-description"))) stats_event(source->mount, "description", s); + stats_event(source->mount, "type", source->format->format_description); while (global.running == ICE_RUNNING) { ret = source->format->get_buffer(source->format, NULL, 0, &refbuf); diff --git a/src/util.c b/src/util.c index 76687b85..1fd6975c 100644 --- a/src/util.c +++ b/src/util.c @@ -96,12 +96,21 @@ int util_get_full_path(char *uri, char *fullPath, int fullPathLen) { int ret = 0; if (uri) { memset(fullPath, '\000', fullPathLen); - snprintf(fullPath, fullPathLen-1, "%s%s%s", config_get_config()->webroot_dir, PATH_SEPARATOR, uri); + snprintf(fullPath, fullPathLen-1, "%s%s", config_get_config()->webroot_dir, uri); ret = 1; } return ret; } +char *util_get_extension(char *path) { + char *ext = strrchr(path, '.'); + + if(ext == NULL) + return ""; + else + return ext+1; +} + int util_check_valid_extension(char *uri) { int ret = 0; char *p2; diff --git a/src/util.h b/src/util.h index f034794b..95a844c8 100644 --- a/src/util.h +++ b/src/util.h @@ -8,5 +8,6 @@ int util_timed_wait_for_fd(int fd, int timeout); int util_read_header(int sock, char *buff, unsigned long len); int util_get_full_path(char *uri, char *fullPath, int fullPathLen); int util_check_valid_extension(char *uri); +char *util_get_extension(char *path); #endif /* __UTIL_H__ */ diff --git a/web/status.xsl b/web/status.xsl index 5de2dad7..e4e060e6 100755 --- a/web/status.xsl +++ b/web/status.xsl @@ -55,9 +55,16 @@ a:hover {color: black; font-family:Verdana}
+ + Current Stream Information

+
+ +Stream Information (stream not currently available) + +
@@ -80,14 +87,27 @@ a:hover {color: black; font-family:Verdana} -Stream Status: +Stream Type: - listeners + + + + +Stream Listeners: + + + + + + + + + Stream Title: @@ -98,6 +118,8 @@ a:hover {color: black; font-family:Verdana} + + Stream Genre: @@ -108,6 +130,8 @@ a:hover {color: black; font-family:Verdana} + + Stream Description: @@ -118,6 +142,8 @@ a:hover {color: black; font-family:Verdana} + + Stream URL: @@ -130,6 +156,7 @@ a:hover {color: black; font-family:Verdana} + Current Song: @@ -140,16 +167,18 @@ a:hover {color: black; font-family:Verdana} + Listen: -Here +Here +