[xiph-commits] r9123 - icecast/branches/kh/icecast/src
karl at motherfish-iii.xiph.org
karl at motherfish-iii.xiph.org
Thu Apr 7 09:01:27 PDT 2005
Author: karl
Date: 2005-04-07 09:01:23 -0700 (Thu, 07 Apr 2005)
New Revision: 9123
Modified:
icecast/branches/kh/icecast/src/auth.c
icecast/branches/kh/icecast/src/auth.h
icecast/branches/kh/icecast/src/auth_url.c
icecast/branches/kh/icecast/src/source.c
Log:
extend url auth to allow a request on source start and shutdown, in case
of sudden server outage.
Modified: icecast/branches/kh/icecast/src/auth.c
===================================================================
--- icecast/branches/kh/icecast/src/auth.c 2005-04-07 12:52:23 UTC (rev 9122)
+++ icecast/branches/kh/icecast/src/auth.c 2005-04-07 16:01:23 UTC (rev 9123)
@@ -483,6 +483,47 @@
}
+void auth_stream_start (const char *mount)
+{
+ mount_proxy *mountinfo;
+ ice_config_t *config = config_get_config();
+
+ mountinfo = config_find_mount (config, mount);
+ if (mountinfo && mountinfo->auth && mountinfo->auth->stream_start)
+ {
+ auth_client *auth_user = calloc (1, sizeof (auth_client));
+ if (auth_user)
+ {
+ auth_user->mount = strdup (mount);
+ auth_user->process = mountinfo->auth->stream_start;
+
+ queue_auth_client (auth_user);
+ }
+ }
+ config_release_config ();
+}
+
+void auth_stream_end (const char *mount)
+{
+ mount_proxy *mountinfo;
+ ice_config_t *config = config_get_config();
+
+ mountinfo = config_find_mount (config, mount);
+ if (mountinfo && mountinfo->auth && mountinfo->auth->stream_end)
+ {
+ auth_client *auth_user = calloc (1, sizeof (auth_client));
+ if (auth_user)
+ {
+ auth_user->mount = strdup (mount);
+ auth_user->process = mountinfo->auth->stream_end;
+
+ queue_auth_client (auth_user);
+ }
+ }
+ config_release_config ();
+}
+
+
/* these are called at server start and termination */
void auth_initialise ()
Modified: icecast/branches/kh/icecast/src/auth.h
===================================================================
--- icecast/branches/kh/icecast/src/auth.h 2005-04-07 12:52:23 UTC (rev 9122)
+++ icecast/branches/kh/icecast/src/auth.h 2005-04-07 16:01:23 UTC (rev 9123)
@@ -54,6 +54,12 @@
auth_result (*authenticate)(auth_client *aclient);
auth_result (*release_client)(auth_client *auth_user);
+ /* callbacks to specific auth for notifying auth server on source
+ * startup or shutdown
+ */
+ auth_result (*stream_start)(auth_client *auth_user);
+ auth_result (*stream_end)(auth_client *auth_user);
+
void (*free)(struct auth_tag *self);
auth_result (*adduser)(struct auth_tag *auth, const char *username, const char *password);
auth_result (*deleteuser)(struct auth_tag *auth, const char *username);
@@ -74,6 +80,14 @@
auth_t *auth_get_authenticator (xmlNodePtr node);
void auth_release (auth_t *authenticator);
+/* call to send a url request when source starts */
+void auth_stream_start (const char *mount);
+
+/* call to send a url request when source ends */
+void auth_stream_end (const char *mount);
+
+/* called from auth thread, after the client has successfully authenticated
+ * and requires adding to source or fserve. */
int auth_postprocess_client (auth_client *auth_user);
#endif
Modified: icecast/branches/kh/icecast/src/auth_url.c
===================================================================
--- icecast/branches/kh/icecast/src/auth_url.c 2005-04-07 12:52:23 UTC (rev 9122)
+++ icecast/branches/kh/icecast/src/auth_url.c 2005-04-07 16:01:23 UTC (rev 9123)
@@ -32,6 +32,13 @@
* client refers to the icecast client identification number, mount refers
* to the mountpoint (beginning with /) and duration is the amount of time in
* seconds
+ *
+ * On stream start and end, another url can be issued to help clear any user
+ * info stored at the auth server. Useful for abnormal outage/termination
+ * cases.
+ *
+ * action=start&mount=/live&server=myserver.com
+ * action=end&mount=/live&server=myserver.com
*/
#ifdef HAVE_CONFIG_H
@@ -62,6 +69,8 @@
typedef struct {
char *addurl;
char *removeurl;
+ char *stream_start;
+ char *stream_end;
char *username;
char *password;
CURL *handle;
@@ -87,7 +96,7 @@
unsigned bytes = size * nmemb;
client_t *client = auth_user->client;
- if (strncasecmp (ptr, "icecast-auth-user: 1\r\n", 22) == 0)
+ if (client && strncasecmp (ptr, "icecast-auth-user: 1\r\n", 22) == 0)
client->authenticated = 1;
return (int)bytes;
@@ -190,7 +199,81 @@
}
+/* called by auth thread when a source starts, there is no client_t in
+ * this case
+ */
+static auth_result url_stream_start (auth_client *auth_user)
+{
+ char *mount, *server;
+ ice_config_t *config = config_get_config ();
+ mount_proxy *mountinfo = config_find_mount (config, auth_user->mount);
+ auth_t *auth = mountinfo->auth;
+ auth_url *url = auth->state;
+ char *stream_start_url;
+ char post [4096];
+ server = util_url_escape (config->hostname);
+ stream_start_url = strdup (url->stream_start);
+ /* we don't want this auth disappearing from under us while
+ * the connection is in progress */
+ mountinfo->auth->refcount++;
+ config_release_config ();
+ mount = util_url_escape (auth_user->mount);
+
+ snprintf (post, sizeof (post),
+ "action=start&mount=%s&server=%s", mount, server);
+ free (server);
+ free (mount);
+
+ curl_easy_setopt (url->handle, CURLOPT_URL, stream_start_url);
+ curl_easy_setopt (url->handle, CURLOPT_POSTFIELDS, post);
+ curl_easy_setopt (url->handle, CURLOPT_WRITEHEADER, auth_user);
+
+ if (curl_easy_perform (url->handle))
+ WARN2 ("auth to server %s failed with %s", stream_start_url, url->errormsg);
+
+ auth_release (auth);
+ free (stream_start_url);
+ return AUTH_OK;
+}
+
+
+static auth_result url_stream_end (auth_client *auth_user)
+{
+ char *mount, *server;
+ ice_config_t *config = config_get_config ();
+ mount_proxy *mountinfo = config_find_mount (config, auth_user->mount);
+ auth_t *auth = mountinfo->auth;
+ auth_url *url = auth->state;
+ char *stream_end_url;
+ char post [4096];
+
+ server = util_url_escape (config->hostname);
+ stream_end_url = strdup (url->stream_end);
+ /* we don't want this auth disappearing from under us while
+ * the connection is in progress */
+ mountinfo->auth->refcount++;
+ config_release_config ();
+ mount = util_url_escape (auth_user->mount);
+
+ snprintf (post, sizeof (post),
+ "action=end&mount=%s&server=%s", mount, server);
+ free (server);
+ free (mount);
+
+ curl_easy_setopt (url->handle, CURLOPT_URL, stream_end_url);
+ curl_easy_setopt (url->handle, CURLOPT_POSTFIELDS, post);
+ curl_easy_setopt (url->handle, CURLOPT_WRITEHEADER, auth_user);
+
+ if (curl_easy_perform (url->handle))
+ WARN2 ("auth to server %s failed with %s", stream_end_url, url->errormsg);
+
+ auth_release (auth);
+ free (stream_end_url);
+ return AUTH_OK;
+}
+
+
static auth_result auth_url_adduser(auth_t *auth, const char *username, const char *password)
{
return AUTH_FAILED;
@@ -216,6 +299,8 @@
authenticator->deleteuser = auth_url_deleteuser;
authenticator->listuser = auth_url_listuser;
authenticator->release_client = auth_removeurl_client;
+ authenticator->stream_start = url_stream_start;
+ authenticator->stream_end = url_stream_end;
url_info = calloc(1, sizeof(auth_url));
@@ -228,6 +313,10 @@
url_info->addurl = strdup (options->value);
if(!strcmp(options->name, "remove"))
url_info->removeurl = strdup (options->value);
+ if(!strcmp(options->name, "start"))
+ url_info->stream_start = strdup (options->value);
+ if(!strcmp(options->name, "end"))
+ url_info->stream_end = strdup (options->value);
options = options->next;
}
url_info->handle = curl_easy_init ();
Modified: icecast/branches/kh/icecast/src/source.c
===================================================================
--- icecast/branches/kh/icecast/src/source.c 2005-04-07 12:52:23 UTC (rev 9122)
+++ icecast/branches/kh/icecast/src/source.c 2005-04-07 16:01:23 UTC (rev 9123)
@@ -801,6 +801,8 @@
stats_event (source->mount, "audio_info", str);
}
+ auth_stream_start (source->mount);
+
thread_mutex_unlock (&source->lock);
if (source->on_connect)
@@ -892,6 +894,7 @@
INFO1("Source \"%s\" exiting", source->mount);
source->running = 0;
+ auth_stream_end (source->mount);
if (source->on_disconnect)
source_run_script (source->on_disconnect, source->mount);
More information about the commits
mailing list