From 4066a89c01bc4fa884625fdfcbbc4f12a3c7490a Mon Sep 17 00:00:00 2001 From: Karl Heyes Date: Thu, 9 Dec 2004 17:08:52 +0000 Subject: [PATCH] allow a relay to provide user/pass when connecting svn path=/icecast/trunk/icecast/; revision=8358 --- doc/icecast2_config_file.html | 12 ++++++++++++ src/cfgfile.c | 8 ++++++++ src/slave.c | 36 ++++++++++++++++++++++++++++++++++- src/slave.h | 2 ++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/doc/icecast2_config_file.html b/doc/icecast2_config_file.html index e7e382c8..e7fb8ac8 100644 --- a/doc/icecast2_config_file.html +++ b/doc/icecast2_config_file.html @@ -208,6 +208,8 @@ certain formats. <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> @@ -279,6 +281,8 @@ A server is configured as a Specific Mountpoint Server relay by specifying a < <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> @@ -300,6 +304,14 @@ The mountpoint located on the remote server. If you are relaying a shoutcast st
The name to use for the local mountpoint. This is what the mount will be named on the RELAY SERVER.
+

username

+
+The source of the relay may require authentication itself, if so state the username here. +
+

password

+
+The source of the relay may require authentication itself, if so state the password here. +

relay-shoutcast-metadata

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). diff --git a/src/cfgfile.c b/src/cfgfile.c index 9ac4c0ec..4a4f94f9 100644 --- a/src/cfgfile.c +++ b/src/cfgfile.c @@ -668,6 +668,14 @@ static void _parse_relay(xmlDocPtr doc, xmlNodePtr node, 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); diff --git a/src/slave.c b/src/slave.c index ba2e85a4..53c7d077 100644 --- a/src/slave.c +++ b/src/slave.c @@ -74,6 +74,10 @@ relay_server *relay_free (relay_server *relay) 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 @@ relay_server *relay_copy (relay_server *r) 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 @@ static void *start_relay_stream (void *arg) 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 @@ static void *start_relay_stream (void *arg) } 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 @@ static void *start_relay_stream (void *arg) 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) { diff --git a/src/slave.h b/src/slave.h index e21056ec..6d219179 100644 --- a/src/slave.h +++ b/src/slave.h @@ -19,6 +19,8 @@ typedef struct _relay_server { char *server; int port; char *mount; + char *username; + char *password; char *localmount; struct source_tag *source; int mp3metadata;