[xiph-commits] r8358 - in icecast/trunk/icecast: doc src

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Thu Dec 9 09:08:53 PST 2004


Author: karl
Date: 2004-12-09 09:08:52 -0800 (Thu, 09 Dec 2004)
New Revision: 8358

Modified:
   icecast/trunk/icecast/doc/icecast2_config_file.html
   icecast/trunk/icecast/src/cfgfile.c
   icecast/trunk/icecast/src/slave.c
   icecast/trunk/icecast/src/slave.h
Log:
allow a relay to provide user/pass when connecting


Modified: icecast/trunk/icecast/doc/icecast2_config_file.html
===================================================================
--- icecast/trunk/icecast/doc/icecast2_config_file.html	2004-12-09 17:04:06 UTC (rev 8357)
+++ icecast/trunk/icecast/doc/icecast2_config_file.html	2004-12-09 17:08:52 UTC (rev 8358)
@@ -208,6 +208,8 @@
         <port>8001</port>
         <mount>/example.ogg</mount>
         <local-mount>/different.ogg</local-mount>
+        <username>joe</username>
+        <password>soap</password>
         <relay-shoutcast-metadata>0</relay-shoutcast-metadata>
     </relay>
 </pre>
@@ -279,6 +281,8 @@
         &lt;port&gt;8001&lt;/port&gt;
         &lt;mount&gt;/example.ogg&lt;/mount&gt;
         &lt;local-mount&gt;/different.ogg&lt;/local-mount&gt;
+        &lt;username&gt;joe&lt;/username&gt;
+        &lt;password&gt;soap&lt;/password&gt;
         &lt;relay-shoutcast-metadata&gt;0&lt;/relay-shoutcast-metadata&gt;
     &lt;/relay&gt;
 </pre>
@@ -300,6 +304,14 @@
 <div class="indentedbox">
 The name to use for the local mountpoint.  This is what the mount will be named on the RELAY SERVER.
 </div>
+<h4>username</h4>
+<div class="indentedbox">
+The source of the relay may require authentication itself, if so state the username here.
+</div>
+<h4>password</h4>
+<div class="indentedbox">
+The source of the relay may require authentication itself, if so state the password here.
+</div>
 <h4>relay-shoutcast-metadata</h4>
 <div class="indentedbox">
 If you are relaying a Shoutcast stream, you need to specify this indicator to also relay the metadata (song titles) that is part of the Shoutcast stream (1=enabled, 0=disabled).

Modified: icecast/trunk/icecast/src/cfgfile.c
===================================================================
--- icecast/trunk/icecast/src/cfgfile.c	2004-12-09 17:04:06 UTC (rev 8357)
+++ icecast/trunk/icecast/src/cfgfile.c	2004-12-09 17:08:52 UTC (rev 8358)
@@ -668,6 +668,14 @@
             relay->mp3metadata = atoi(tmp);
             if(tmp) xmlFree(tmp);
         }
+        else if (strcmp(node->name, "username") == 0) {
+            relay->username = (char *)xmlNodeListGetString(doc,
+                    node->xmlChildrenNode, 1);
+        }
+        else if (strcmp(node->name, "password") == 0) {
+            relay->password = (char *)xmlNodeListGetString(doc,
+                    node->xmlChildrenNode, 1);
+        }
     } while ((node = node->next));
     if (relay->localmount == NULL)
         relay->localmount = xmlStrdup (relay->mount);

Modified: icecast/trunk/icecast/src/slave.c
===================================================================
--- icecast/trunk/icecast/src/slave.c	2004-12-09 17:04:06 UTC (rev 8357)
+++ icecast/trunk/icecast/src/slave.c	2004-12-09 17:08:52 UTC (rev 8358)
@@ -74,6 +74,10 @@
     xmlFree (relay->server);
     xmlFree (relay->mount);
     xmlFree (relay->localmount);
+    if (relay->username)
+        xmlFree (relay->username);
+    if (relay->password)
+        xmlFree (relay->password);
     free (relay);
     return next;
 }
@@ -88,6 +92,10 @@
         copy->server = xmlStrdup (r->server);
         copy->mount = xmlStrdup (r->mount);
         copy->localmount = xmlStrdup (r->localmount);
+        if (r->username)
+            copy->username = xmlStrdup (r->username);
+        if (r->password)
+            copy->password = xmlStrdup (r->password);
         copy->port = r->port;
         copy->mp3metadata = r->mp3metadata;
     }
@@ -149,6 +157,8 @@
     INFO1("Starting relayed source at mountpoint \"%s\"", relay->localmount);
     do
     {
+        char *auth_header;
+
         streamsock = sock_connect_wto (relay->server, relay->port, 30);
         if (streamsock == SOCK_ERROR)
         {
@@ -158,6 +168,26 @@
         }
         con = create_connection (streamsock, -1, NULL);
 
+        if (relay->username && relay->password)
+        {
+            char *esc_authorisation;
+            unsigned len = strlen(relay->username) + strlen(relay->password) + 2;
+
+            auth_header = malloc (len);
+            snprintf (auth_header, len, "%s:%s", relay->username, relay->password);
+            esc_authorisation = util_base64_encode(auth_header);
+            free(auth_header);
+            len = strlen (esc_authorisation) + 24;
+            auth_header = malloc (len);
+            snprintf (auth_header, len,
+                    "Authorization: Basic %s\r\n", esc_authorisation);
+            free(esc_authorisation);
+        }
+        else
+        {
+            auth_header = strdup ("");
+        }
+
         /* At this point we may not know if we are relaying an mp3 or vorbis
          * stream, but only send the icy-metadata header if the relay details
          * state so (the typical case).  It's harmless in the vorbis case. If
@@ -166,8 +196,12 @@
         sock_write(streamsock, "GET %s HTTP/1.0\r\n"
                 "User-Agent: " ICECAST_VERSION_STRING "\r\n"
                 "%s"
+                "%s"
                 "\r\n",
-                relay->mount, relay->mp3metadata?"Icy-MetaData: 1\r\n":"");
+                relay->mount,
+                relay->mp3metadata?"Icy-MetaData: 1\r\n":"",
+                auth_header);
+        free (auth_header);
         memset (header, 0, sizeof(header));
         if (util_read_header (con->sock, header, 4096, READ_ENTIRE_HEADER) == 0)
         {

Modified: icecast/trunk/icecast/src/slave.h
===================================================================
--- icecast/trunk/icecast/src/slave.h	2004-12-09 17:04:06 UTC (rev 8357)
+++ icecast/trunk/icecast/src/slave.h	2004-12-09 17:08:52 UTC (rev 8358)
@@ -19,6 +19,8 @@
     char *server;
     int port;
     char *mount;
+    char *username;
+    char *password;
     char *localmount;
     struct source_tag *source;
     int mp3metadata;



More information about the commits mailing list