Commit 4066a89c authored by Karl Heyes's avatar Karl Heyes

allow a relay to provide user/pass when connecting

svn path=/icecast/trunk/icecast/; revision=8358
parent 1924d22b
......@@ -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>
</pre>
......@@ -279,6 +281,8 @@ A server is configured as a Specific Mountpoint Server relay by specifying a &lt
&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 @@ The mountpoint located on the remote server. If you are relaying a shoutcast st
<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).
......
......@@ -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);
......
......@@ -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)
{
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment