Paul Donohue
2004-Aug-06 14:57 UTC
[icecast-dev] [PATCH] IceCast2 - socket-based default mount
I wrote a patch which makes client connections retain info about which socket they connected to - this way, you can change the server's behavior based on which <listen-socket> is being connected to. In addition, I added a field to the <listen-socket> section of the config file called <default-mount> which specifies a default file in the case that one isn't specified (it doesn't have to be a mount point - it can be any valid URI) - this way, if the user doesn't specify a specific file or stream or whatever, you can have it default to something. So, now http://myserver.com:8000/ actually does something :) and http://myserver.com:8001/ can do something else without running a separate instance of the server -Paul -------------- next part -------------- diff -ur icecast/CVS/Entries IceCast/CVS/Entries --- icecast/CVS/Entries 2003-04-18 09:15:58.000000000 -0400 +++ IceCast/CVS/Entries 2003-04-17 22:14:16.000000000 -0400 @@ -1,4 +1,3 @@ -/.cvsignore/1.3/Wed Jan 15 05:36:15 2003// /AUTHORS/1.2/Fri Aug 9 15:55:01 2002// /COPYING/1.2/Thu Feb 14 00:58:04 2002// /HACKING/1.2/Thu Aug 8 08:26:21 2002// @@ -10,4 +9,9 @@ /acinclude.m4/1.3/Fri Mar 14 00:45:49 2003// /autogen.sh/1.2/Thu Jul 11 03:54:11 2002// /configure.in/1.27/Thu Mar 27 17:09:33 2003// -D +D/conf//// +D/doc//// +D/src//// +D/web//// +D/win32//// +/.cvsignore/1.3/Fri Apr 18 02:14:16 2003// diff -ur icecast/CVS/Entries.Log IceCast/CVS/Entries.Log --- icecast/CVS/Entries.Log 2003-04-18 09:15:59.000000000 -0400 +++ IceCast/CVS/Entries.Log 2003-04-18 09:15:58.000000000 -0400 @@ -1,5 +1 @@ -A D/conf//// -A D/doc//// -A D/src//// -A D/web//// -A D/win32//// +A D/icecast//// Only in IceCast: Makefile Only in IceCast: Makefile.in Only in IceCast: aclocal.m4 Only in IceCast: autom4te.cache Only in IceCast: compile Only in IceCast/conf: Makefile Only in IceCast/conf: Makefile.in diff -ur icecast/conf/icecast.xml IceCast/conf/icecast.xml --- icecast/conf/icecast.xml 2003-04-10 23:14:26.000000000 -0400 +++ IceCast/conf/icecast.xml 2003-04-18 10:01:45.000000000 -0400 @@ -41,6 +41,7 @@ <listen-socket> <port>8000</port> <!-- <bind-address>127.0.0.1</bind-address> --> + <default-mount>/index.html</default-mount> </listen-socket> <!-- <listen-socket> Only in IceCast: config.guess Only in IceCast: config.log Only in IceCast: config.status Only in IceCast: config.sub Only in IceCast: configure Only in IceCast: depcomp Only in IceCast/doc: Makefile Only in IceCast/doc: Makefile.in Only in IceCast: install-sh Only in IceCast: libtool Only in IceCast: ltmain.sh Only in IceCast: missing Only in IceCast: mkinstalldirs Only in IceCast/src: .deps Only in IceCast/src: .libs diff -ur icecast/src/CVS/Entries IceCast/src/CVS/Entries --- icecast/src/CVS/Entries 2003-04-18 09:15:59.000000000 -0400 +++ IceCast/src/CVS/Entries 2003-04-18 09:14:25.000000000 -0400 @@ -6,11 +6,7 @@ /client.c/1.8/Sat Mar 15 02:10:17 2003// /client.h/1.8/Sat Mar 15 02:10:17 2003// /compat.h/1.1/Sat Oct 20 21:28:09 2001// -/config.c/1.32/Sat Mar 15 02:10:17 2003// -/config.h/1.20/Sat Mar 15 02:10:17 2003// /configtest.c/1.5/Sat Mar 15 02:10:17 2003// -/connection.c/1.67/Thu Mar 27 17:09:41 2003// -/connection.h/1.9/Sat Mar 15 02:10:17 2003// /event.c/1.2/Sat Mar 15 02:10:17 2003// /event.h/1.1/Wed Mar 5 13:03:35 2003// /format.c/1.20/Sat Mar 15 02:10:17 2003// @@ -33,7 +29,6 @@ /refbuf.h/1.3/Sat Mar 15 02:10:17 2003// /sighandler.c/1.4/Sat Mar 15 02:10:17 2003// /sighandler.h/1.1.1.1/Mon Sep 10 02:21:49 2001// -/slave.c/1.24/Thu Mar 27 17:10:02 2003// /slave.h/1.1/Mon Aug 5 14:48:01 2002// /source.c/1.51/Thu Apr 17 03:23:18 2003// /source.h/1.13/Sun Mar 30 13:52:27 2003// @@ -45,4 +40,14 @@ /xslt.h/1.3/Tue Aug 13 12:46:45 2002// /yp.c/1.8/Fri Apr 11 03:00:24 2003// /yp.h/1.6/Thu Mar 27 17:10:14 2003// -D +D/avl//// +D/log//// +D/net//// +D/httpp//// +D/thread//// +D/timing//// +/config.c/1.32/Fri Apr 18 13:14:25 2003// +/config.h/1.20/Fri Apr 18 13:14:25 2003// +/connection.c/1.67/Fri Apr 18 13:14:25 2003// +/connection.h/1.9/Fri Apr 18 13:14:25 2003// +/slave.c/1.24/Fri Apr 18 13:14:25 2003// Only in icecast/src/CVS: Entries.Log Only in IceCast/src: Makefile Only in IceCast/src: Makefile.in Only in IceCast/src: admin.o Only in IceCast/src/avl: .deps Only in IceCast/src/avl: .libs Only in IceCast/src/avl: Makefile Only in IceCast/src/avl: Makefile.in Only in IceCast/src/avl: libiceavl.la Only in IceCast/src/avl: libiceavl_la-avl.lo Only in IceCast/src/avl: libiceavl_la-avl.o Only in IceCast/src: client.o diff -ur icecast/src/config.c IceCast/src/config.c --- icecast/src/config.c 2003-03-14 21:10:17.000000000 -0500 +++ IceCast/src/config.c 2003-04-18 10:15:44.000000000 -0400 @@ -127,6 +127,7 @@ xmlFree(c->error_log); for(i=0; i < MAX_LISTEN_SOCKETS; i++) { if (c->listeners[i].bind_address) xmlFree(c->listeners[i].bind_address); + if (c->listeners[i].default_mount) xmlFree(c->listeners[i].default_mount); } if (c->master_server) xmlFree(c->master_server); if (c->master_password) xmlFree(c->master_password); @@ -266,6 +267,7 @@ configuration->port = 0; configuration->listeners[0].port = 0; configuration->listeners[0].bind_address = NULL; + configuration->listeners[0].default_mount = NULL; configuration->master_server = NULL; configuration->master_server_port = 0; configuration->master_update_interval = CONFIG_MASTER_UPDATE_INTERVAL; @@ -333,6 +335,10 @@ if (configuration->listeners[0].bind_address) xmlFree(configuration->listeners[0].bind_address); configuration->listeners[0].bind_address = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); + } else if (strcmp(node->name, "default-mount") == 0) { + if (configuration->listeners[0].default_mount) + xmlFree(configuration->listeners[0].default_mount); + configuration->listeners[0].default_mount = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } else if (strcmp(node->name, "master-server") == 0) { if (configuration->master_server) xmlFree(configuration->master_server); configuration->master_server = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); @@ -532,6 +538,10 @@ listener->bind_address = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } + else if (strcmp(node->name, "default-mount") == 0) { + listener->default_mount = (char *)xmlNodeListGetString(doc, + node->xmlChildrenNode, 1); + } } while ((node = node->next)); } diff -ur icecast/src/config.h IceCast/src/config.h --- icecast/src/config.h 2003-03-14 21:10:17.000000000 -0500 +++ IceCast/src/config.h 2003-04-18 09:13:10.000000000 -0400 @@ -46,6 +46,7 @@ typedef struct { int port; char *bind_address; + char *default_mount; } listener_t; typedef struct ice_config_tag Only in IceCast/src: config.o diff -ur icecast/src/connection.c IceCast/src/connection.c --- icecast/src/connection.c 2003-03-27 12:09:41.000000000 -0500 +++ IceCast/src/connection.c 2003-04-18 09:44:50.000000000 -0400 @@ -109,11 +109,12 @@ return id; } -connection_t *create_connection(sock_t sock, char *ip) { +connection_t *create_connection(sock_t sock, sock_t serversock, char *ip) { connection_t *con; con = (connection_t *)malloc(sizeof(connection_t)); memset(con, 0, sizeof(connection_t)); con->sock = sock; + con->serversock = serversock; con->con_time = time(NULL); con->id = _next_connection_id(); con->ip = ip; @@ -203,7 +204,7 @@ sock = sock_accept(serversock, ip, MAX_ADDR_LEN); if (sock >= 0) { - con = create_connection(sock, ip); + con = create_connection(sock, serversock, ip); return con; } @@ -648,6 +649,8 @@ int fileserve; char *host; int port; + int i; + char *default_mount; ice_config_t *config; int client_limit; @@ -655,6 +658,13 @@ fileserve = config->fileserve; host = config->hostname; port = config->port; + default_mount = NULL; + for(i = 0; i < MAX_LISTEN_SOCKETS; i++) { + if(global.serversock[i] == con->serversock) { + default_mount = config->listeners[i].default_mount; + break; + } + } client_limit = config->client_limit; config_release_config(); @@ -668,13 +678,22 @@ /* there are several types of HTTP GET clients ** media clients, which are looking for a source (eg, URI = /stream.ogg) ** stats clients, which are looking for /admin/stats.xml - ** and director server authorizers, which are looking for /GUID-xxxxxxxx + ** and directory server authorizers, which are looking for /GUID-xxxxxxxx ** (where xxxxxx is the GUID in question) - this isn't implemented yet. ** we need to handle the latter two before the former, as the latter two ** aren't subject to the limits. */ /* TODO: add GUID-xxxxxx */ + /* Handle default requests */ + if(strcmp(uri, "/") == 0) { + if(default_mount == NULL) { + client_send_404(client, "The file you requested could not be found"); + return; + } + uri = default_mount; + } + /* Dispatch all admin requests */ if (strncmp(uri, "/admin/", 7) == 0) { admin_handle_request(client, uri); @@ -705,6 +724,12 @@ } else if(fileserve && stat(fullpath, &statbuf) == 0) { + if(!S_ISREG(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)) + { + client_send_404(client, "Access denied"); + free(fullpath); + return; + } fserve_client_create(client, fullpath); free(fullpath); return; diff -ur icecast/src/connection.h IceCast/src/connection.h --- icecast/src/connection.h 2003-03-14 21:10:17.000000000 -0500 +++ IceCast/src/connection.h 2003-04-18 09:13:23.000000000 -0400 @@ -17,6 +17,7 @@ uint64_t sent_bytes; int sock; + int serversock; int error; char *ip; @@ -31,7 +32,7 @@ void connection_shutdown(void); void connection_accept_loop(void); void connection_close(connection_t *con); -connection_t *create_connection(sock_t sock, char *ip); +connection_t *create_connection(sock_t sock, sock_t serversock, char *ip); int connection_create_source(struct _client_tag *client, connection_t *con, http_parser_t *parser, char *mount); Only in IceCast/src: connection.o Only in IceCast/src: event.o Only in IceCast/src: format.o Only in IceCast/src: format_mp3.o Only in IceCast/src: format_vorbis.o Only in IceCast/src: fserve.o Only in IceCast/src: geturl.o Only in IceCast/src: global.o Only in IceCast/src/httpp: .deps Only in IceCast/src/httpp: .libs Only in IceCast/src/httpp: Makefile Only in IceCast/src/httpp: Makefile.in Only in IceCast/src/httpp: libicehttpp.la Only in IceCast/src/httpp: libicehttpp_la-httpp.lo Only in IceCast/src/httpp: libicehttpp_la-httpp.o Only in IceCast/src: icecast Only in IceCast/src/log: .deps Only in IceCast/src/log: .libs Only in IceCast/src/log: Makefile Only in IceCast/src/log: Makefile.in Only in IceCast/src/log: libicelog.la Only in IceCast/src/log: log.lo Only in IceCast/src/log: log.o Only in IceCast/src: logging.o Only in IceCast/src: main.o Only in IceCast/src/net: .deps Only in IceCast/src/net: .libs Only in IceCast/src/net: Makefile Only in IceCast/src/net: Makefile.in Only in IceCast/src/net: libicenet.la Only in IceCast/src/net: libicenet_la-resolver.lo Only in IceCast/src/net: libicenet_la-resolver.o Only in IceCast/src/net: libicenet_la-sock.lo Only in IceCast/src/net: libicenet_la-sock.o Only in IceCast/src: refbuf.o Only in IceCast/src: sighandler.o diff -ur icecast/src/slave.c IceCast/src/slave.c --- icecast/src/slave.c 2003-03-27 12:10:02.000000000 -0500 +++ IceCast/src/slave.c 2003-04-18 09:13:27.000000000 -0400 @@ -91,7 +91,7 @@ WARN2("Failed to relay stream from master server, couldn't connect to http://%s:%d", server, port); return; } - con = create_connection(streamsock, NULL); + con = create_connection(streamsock, -1, NULL); if(mp3) { /* Some mp3 servers are bitchy, send a user-agent string to make them * send the right response. Only in IceCast/src: slave.o Only in IceCast/src: source.o Only in IceCast/src: stats.o Only in IceCast/src/thread: .deps Only in IceCast/src/thread: .libs Only in IceCast/src/thread: Makefile Only in IceCast/src/thread: Makefile.in Only in IceCast/src/thread: libicethread.la Only in IceCast/src/thread: libicethread_la-thread.lo Only in IceCast/src/thread: libicethread_la-thread.o Only in IceCast/src/timing: .deps Only in IceCast/src/timing: .libs Only in IceCast/src/timing: Makefile Only in IceCast/src/timing: Makefile.in Only in IceCast/src/timing: libicetiming.la Only in IceCast/src/timing: libicetiming_la-timing.lo Only in IceCast/src/timing: libicetiming_la-timing.o Only in IceCast/src: util.o Only in IceCast/src: xslt.o Only in IceCast/src: yp.o Only in IceCast/web: Makefile Only in IceCast/web: Makefile.in diff -ur icecast/win32/CVS/Entries IceCast/win32/CVS/Entries --- icecast/win32/CVS/Entries 2003-04-18 09:15:59.000000000 -0400 +++ IceCast/win32/CVS/Entries 2003-04-17 22:14:16.000000000 -0400 @@ -35,4 +35,4 @@ /resource.h/1.4/Wed Aug 28 20:37:44 2002// /running.bmp/1.1/Fri Aug 9 15:55:01 2002/-kb/ /stopped.bmp/1.1/Fri Aug 9 15:55:01 2002/-kb/ -D +D/res//// Only in icecast/win32/CVS: Entries.Log Only in IceCast/win32: Makefile Only in IceCast/win32: Makefile.in Only in IceCast/win32/res: Makefile Only in IceCast/win32/res: Makefile.in
Possibly Parallel Threads
- [PATCH] IceCast2 - aliasing (reimplementation of the patch I posted earlier)
- [RFC] RTP support
- [PATCH] Config: Rename mp3-metadata-interval to icy-metadata-interval
- [PATCH] Add per-listener and per-mount connection time limits.
- [PATCH] icecast video preview 2