[icecast-dev] [PATCH] IceCast2 - aliasing (reimplementation of the patch I posted earlier)

Paul Donohue icecast at TopQuark.net
Fri Apr 18 17:58:12 PDT 2003


Reimplementation of my earlier patch - more proper aliasing - at the
suggestion of Mike

-Paul

-------------- next part --------------
diff -ur icecast/CVS/Entries IceCast/CVS/Entries
--- icecast/CVS/Entries	2003-04-18 11:00:19.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//
@@ -15,3 +14,4 @@
 D/src////
 D/web////
 D/win32////
+/.cvsignore/1.3/Fri Apr 18 02:14:16 2003//
Only in IceCast/CVS: Entries.Log
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 20:25:41.000000000 -0400
@@ -83,6 +83,11 @@
              be relative to the new root, not the original root -->
 		<logdir>/usr/local/icecast/logs</logdir>
 		<webroot>/usr/local/icecast/web</webroot>
+
+                <alias source="/foo" dest="/bar"></alias>
+                <alias source="/fred" dest="/bob" port="8000"></alias>
+                <alias source="/soylent" dest="/green" bind-address="127.0.0.1"></alias>
+                <alias source="/your" dest="/mom" port="8000" bind-address="127.0.0.1"></alias>
 	</paths>
 
 	<logging>
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 11:00:19.000000000 -0400
+++ IceCast/src/CVS/Entries	2003-04-18 09:14:25.000000000 -0400
@@ -6,10 +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.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//
@@ -32,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//
@@ -50,4 +46,8 @@
 D/httpp////
 D/thread////
 D/timing////
-/connection.c/1.68/Fri Apr 18 15:00:19 2003//
+/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: 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 20:20:31.000000000 -0400
@@ -98,6 +98,7 @@
     ice_config_dir_t *dirnode, *nextdirnode;
     relay_server *relay, *nextrelay;
     mount_proxy *mount, *nextmount;
+    aliases *alias, *nextalias;
     int i;
 
     if (c->config_filename)
@@ -160,6 +161,16 @@
     }
     thread_mutex_unlock(&(_locks.mounts_lock));
 
+    alias = c->aliases;
+    while(alias) {
+        nextalias = alias->next;
+        xmlFree(alias->source);
+        xmlFree(alias->destination);
+        xmlFree(alias->bind_address);
+        free(alias);
+        alias = nextalias;
+    }
+
     dirnode = c->dir_list;
     while(dirnode) {
         nextdirnode = dirnode->next;
@@ -423,6 +434,7 @@
         configuration->mounts = mount;
 
     mount->max_listeners = -1;
+    mount->next = NULL;
 
     do {
         if (node == NULL) break;
@@ -474,6 +486,8 @@
     else
         configuration->relay = relay;
 
+    relay->next = NULL;
+
     do {
         if (node == NULL) break;
         if (xmlIsBlankNode(node)) continue;
@@ -606,6 +620,9 @@
 static void _parse_paths(xmlDocPtr doc, xmlNodePtr node,
         ice_config_t *configuration)
 {
+    char *temp;
+    aliases *alias, *current, *last;
+
     do {
         if (node == NULL) break;
         if (xmlIsBlankNode(node)) continue;
@@ -621,7 +638,39 @@
             configuration->webroot_dir = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
             if(configuration->webroot_dir[strlen(configuration->webroot_dir)-1] == '/')
                 configuration->webroot_dir[strlen(configuration->webroot_dir)-1] = 0;
-
+        } else if (strcmp(node->name, "alias") == 0) {
+            alias = malloc(sizeof(aliases));
+            alias->next = NULL;
+            alias->source = xmlGetProp(node, "source");
+            if(alias->source == NULL) {
+                free(alias);
+                continue;
+            }
+            alias->destination = xmlGetProp(node, "dest");
+            if(alias->destination == NULL) {
+                xmlFree(alias->source);
+                free(alias);
+                continue;
+            }
+            temp = NULL;
+            temp = xmlGetProp(node, "port");
+            if(temp != NULL) {
+                alias->port = atoi(temp);
+                xmlFree(temp);
+            }
+            else
+                alias->port = -1;
+            alias->bind_address = xmlGetProp(node, "bind-address");
+            current = configuration->aliases;
+            last = NULL;
+            while(current) {
+                last = current;
+                current = current->next;
+            }
+            if(last)
+                last->next = alias;
+            else
+                configuration->aliases = alias;
         }
     } 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 18:34:46.000000000 -0400
@@ -43,6 +43,14 @@
     struct _mount_proxy *next;
 } mount_proxy;
 
+typedef struct _aliases {
+    char *source;
+    char *destination;
+    int port;
+    char *bind_address;
+    struct _aliases *next;
+}aliases;
+
 typedef struct {
     int port;
     char *bind_address;
@@ -89,6 +97,7 @@
     char *base_dir;
     char *log_dir;
     char *webroot_dir;
+    aliases *aliases;
 
     char *access_log;
     char *error_log;
Only in IceCast/src: config.o
diff -ur icecast/src/connection.c IceCast/src/connection.c
--- icecast/src/connection.c	2003-04-18 11:00:19.000000000 -0400
+++ IceCast/src/connection.c	2003-04-18 20:45:54.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,10 @@
     int fileserve;
     char *host;
     int port;
+    int i;
+    char *serverhost;
+    int serverport;
+    aliases *alias;
     ice_config_t *config;
     int client_limit;
 
@@ -655,6 +660,14 @@
     fileserve = config->fileserve;
     host = config->hostname;
     port = config->port;
+    for(i = 0; i < MAX_LISTEN_SOCKETS; i++) {
+        if(global.serversock[i] == con->serversock) {
+            serverhost = config->listeners[i].bind_address;
+            serverport = config->listeners[i].port;
+            break;
+        }
+    }
+    alias = config->aliases;
     client_limit = config->client_limit;
     config_release_config();
 
@@ -668,13 +681,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 aliases */
+    while(alias) {
+        if(strcmp(uri, alias->source) == 0 && (alias->port == -1 || alias->port == serverport) && (alias->bind_address == NULL || (serverhost != NULL && strcmp(alias->bind_address, serverhost) == 0))) {
+            uri = alias->destination;
+            break;
+        }
+        alias = alias->next;
+    }
+
     /* Dispatch all admin requests */
     if (strncmp(uri, "/admin/", 7) == 0) {
         admin_handle_request(client, uri);
@@ -703,8 +725,7 @@
         free(fullpath);
         return;
     }
-    else if(fileserve && stat(fullpath, &statbuf) == 0 && 
-            S_ISREG(statbuf.st_mode)) 
+    else if(fileserve && stat(fullpath, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) 
     {
         fserve_client_create(client, fullpath);
         free(fullpath);
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
Only in IceCast/win32: Makefile
Only in IceCast/win32: Makefile.in
Only in IceCast/win32/res: Makefile
Only in IceCast/win32/res: Makefile.in


More information about the Icecast-dev mailing list