[xiph-commits] r18902 - icecast/trunk/icecast/src

ph3-der-loewe at svn.xiph.org ph3-der-loewe at svn.xiph.org
Tue Apr 2 11:46:44 PDT 2013


Author: ph3-der-loewe
Date: 2013-04-02 11:46:44 -0700 (Tue, 02 Apr 2013)
New Revision: 18902

Modified:
   icecast/trunk/icecast/src/admin.c
   icecast/trunk/icecast/src/auth.c
   icecast/trunk/icecast/src/auth_url.c
   icecast/trunk/icecast/src/cfgfile.c
   icecast/trunk/icecast/src/cfgfile.h
   icecast/trunk/icecast/src/client.c
   icecast/trunk/icecast/src/connection.c
   icecast/trunk/icecast/src/format.c
   icecast/trunk/icecast/src/slave.c
   icecast/trunk/icecast/src/source.c
   icecast/trunk/icecast/src/yp.c
Log:
Added support for a default mount. See #1914.
The default mount is a block in the config file that contains settings for
all mount points that do not have a block in configfile themself.
This is implemented by a <mount type="default">-block.
In this case the <mount>-block MUST NOT contain a <mount-name>-subblock.


Modified: icecast/trunk/icecast/src/admin.c
===================================================================
--- icecast/trunk/icecast/src/admin.c	2013-04-02 12:19:33 UTC (rev 18901)
+++ icecast/trunk/icecast/src/admin.c	2013-04-02 18:46:44 UTC (rev 18902)
@@ -236,7 +236,7 @@
             xmlNewChild(srcnode, NULL, XMLSTR("listeners"), XMLSTR(buf));
 
             config = config_get_config();
-            mountinfo = config_find_mount (config, source->mount);
+            mountinfo = config_find_mount (config, source->mount, MOUNT_TYPE_NORMAL);
             if (mountinfo && mountinfo->auth)
             {
                 xmlNewChild(srcnode, NULL, XMLSTR("authenticator"),
@@ -742,7 +742,7 @@
     char *message = NULL;
     int ret = AUTH_OK;
     ice_config_t *config = config_get_config ();
-    mount_proxy *mountinfo = config_find_mount (config, source->mount);
+    mount_proxy *mountinfo = config_find_mount (config, source->mount, MOUNT_TYPE_NORMAL);
 
     do
     {

Modified: icecast/trunk/icecast/src/auth.c
===================================================================
--- icecast/trunk/icecast/src/auth.c	2013-04-02 12:19:33 UTC (rev 18901)
+++ icecast/trunk/icecast/src/auth.c	2013-04-02 18:46:44 UTC (rev 18902)
@@ -485,7 +485,7 @@
     client_t *client = auth_user->client;
     ice_config_t *config = config_get_config();
 
-    mount_proxy *mountinfo = config_find_mount (config, auth_user->mount);
+    mount_proxy *mountinfo = config_find_mount (config, auth_user->mount, MOUNT_TYPE_NORMAL);
 
     ret = add_authenticated_listener (auth_user->mount, mountinfo, client);
     config_release_config();
@@ -530,7 +530,7 @@
     mount_proxy *mountinfo; 
     ice_config_t *config = config_get_config();
 
-    mountinfo = config_find_mount (config, mount);
+    mountinfo = config_find_mount (config, mount, MOUNT_TYPE_NORMAL);
     if (mountinfo && mountinfo->no_mount)
     {
         config_release_config ();

Modified: icecast/trunk/icecast/src/auth_url.c
===================================================================
--- icecast/trunk/icecast/src/auth_url.c	2013-04-02 12:19:33 UTC (rev 18901)
+++ icecast/trunk/icecast/src/auth_url.c	2013-04-02 18:46:44 UTC (rev 18902)
@@ -412,7 +412,7 @@
 {
     char *mount, *server;
     ice_config_t *config = config_get_config ();
-    mount_proxy *mountinfo = config_find_mount (config, auth_user->mount);
+    mount_proxy *mountinfo = config_find_mount (config, auth_user->mount, MOUNT_TYPE_NORMAL);
     auth_t *auth = mountinfo->auth;
     auth_url *url = auth->state;
     char *stream_start_url;
@@ -464,7 +464,7 @@
 {
     char *mount, *server;
     ice_config_t *config = config_get_config ();
-    mount_proxy *mountinfo = config_find_mount (config, auth_user->mount);
+    mount_proxy *mountinfo = config_find_mount (config, auth_user->mount, MOUNT_TYPE_NORMAL);
     auth_t *auth = mountinfo->auth;
     auth_url *url = auth->state;
     char *stream_end_url;

Modified: icecast/trunk/icecast/src/cfgfile.c
===================================================================
--- icecast/trunk/icecast/src/cfgfile.c	2013-04-02 12:19:33 UTC (rev 18901)
+++ icecast/trunk/icecast/src/cfgfile.c	2013-04-02 18:46:44 UTC (rev 18902)
@@ -466,7 +466,7 @@
         } else if (xmlStrcmp (node->name, XMLSTR("relay")) == 0) {
             _parse_relay(doc, node->xmlChildrenNode, configuration);
         } else if (xmlStrcmp (node->name, XMLSTR("mount")) == 0) {
-            _parse_mount(doc, node->xmlChildrenNode, configuration);
+            _parse_mount(doc, node, configuration);
         } else if (xmlStrcmp (node->name, XMLSTR("directory")) == 0) {
             _parse_directory(doc, node->xmlChildrenNode, configuration);
         } else if (xmlStrcmp (node->name, XMLSTR("paths")) == 0) {
@@ -548,12 +548,30 @@
     mount_proxy *last=NULL;
     
     /* default <mount> settings */
+    mount->mounttype = MOUNT_TYPE_NORMAL;
     mount->max_listeners = -1;
     mount->burst_size = -1;
     mount->mp3_meta_interval = -1;
     mount->yp_public = -1;
     mount->next = NULL;
 
+    tmp = (char *)xmlGetProp(node, XMLSTR("type"));
+    if (tmp) {
+        if (strcmp(tmp, "normal") == 0) {
+	    mount->mounttype = MOUNT_TYPE_NORMAL;
+	}
+	else if (strcmp(tmp, "default") == 0) {
+	    mount->mounttype = MOUNT_TYPE_DEFAULT;
+	}
+	else {
+	    WARN1("Unknown mountpoint type: %s", tmp);
+            config_clear_mount (mount);
+            return;
+	}
+    }
+
+    node = node->xmlChildrenNode;
+
     do {
         if (node == NULL) break;
         if (xmlIsBlankNode(node)) continue;
@@ -684,7 +702,7 @@
     } while ((node = node->next));
 
     /* make sure we have at least the mountpoint name */
-    if (mount->mountname == NULL)
+    if (mount->mountname == NULL && mount->mounttype != MOUNT_TYPE_DEFAULT)
     {
         config_clear_mount (mount);
         return;
@@ -1126,16 +1144,26 @@
 
 
 /* return the mount details that match the supplied mountpoint */
-mount_proxy *config_find_mount (ice_config_t *config, const char *mount)
+mount_proxy *config_find_mount (ice_config_t *config, const char *mount, mount_type type)
 {
     mount_proxy *mountinfo = config->mounts;
 
-    while (mountinfo)
+    for (; mountinfo; mountinfo = mountinfo->next)
     {
-        if (strcmp (mountinfo->mountname, mount) == 0)
+        if (mountinfo->mounttype != type)
+	    continue;
+
+	if (mount == NULL || mountinfo->mountname == NULL)
             break;
-        mountinfo = mountinfo->next;
+
+	if (strcmp (mountinfo->mountname, mount) == 0)
+            break;
     }
+
+    /* retry with default mount */
+    if (!mountinfo && type == MOUNT_TYPE_NORMAL)
+            mountinfo = config_find_mount(config, mount, MOUNT_TYPE_DEFAULT);
+
     return mountinfo;
 }
 

Modified: icecast/trunk/icecast/src/cfgfile.h
===================================================================
--- icecast/trunk/icecast/src/cfgfile.h	2013-04-02 12:19:33 UTC (rev 18901)
+++ icecast/trunk/icecast/src/cfgfile.h	2013-04-02 18:46:44 UTC (rev 18902)
@@ -44,9 +44,16 @@
     struct _config_options *next;
 } config_options_t;
 
+typedef enum _mount_type {
+ MOUNT_TYPE_NORMAL,
+ MOUNT_TYPE_DEFAULT
+} mount_type;
+
 typedef struct _mount_proxy {
     char *mountname; /* The mountpoint this proxy is used for */
 
+    mount_type mounttype; /* The type of the mount point */
+
     char *username; /* Username and password for this mountpoint. If unset, */
     char *password; /* falls back to global source password */
 
@@ -198,7 +205,7 @@
 void config_set_config(ice_config_t *config);
 listener_t *config_clear_listener (listener_t *listener);
 void config_clear(ice_config_t *config);
-mount_proxy *config_find_mount (ice_config_t *config, const char *mount);
+mount_proxy *config_find_mount (ice_config_t *config, const char *mount, mount_type type);
 listener_t *config_get_listen_sock (ice_config_t *config, connection_t *con);
 
 int config_rehash(void);

Modified: icecast/trunk/icecast/src/client.c
===================================================================
--- icecast/trunk/icecast/src/client.c	2013-04-02 12:19:33 UTC (rev 18901)
+++ icecast/trunk/icecast/src/client.c	2013-04-02 18:46:44 UTC (rev 18902)
@@ -133,7 +133,7 @@
     char *pass = config->source_password;
     char *user = "source";
     int ret = -1;
-    mount_proxy *mountinfo = config_find_mount (config, mount);
+    mount_proxy *mountinfo = config_find_mount (config, mount, MOUNT_TYPE_NORMAL);
 
     do
     {

Modified: icecast/trunk/icecast/src/connection.c
===================================================================
--- icecast/trunk/icecast/src/connection.c	2013-04-02 12:19:33 UTC (rev 18901)
+++ icecast/trunk/icecast/src/connection.c	2013-04-02 18:46:44 UTC (rev 18902)
@@ -851,7 +851,7 @@
         global_unlock();
 
         source->running = 1;
-        mountinfo = config_find_mount (config, source->mount);
+        mountinfo = config_find_mount (config, source->mount, MOUNT_TYPE_NORMAL);
         source_update_settings (config, source, mountinfo);
         config_release_config();
         slave_rebuild_mounts();
@@ -1178,7 +1178,7 @@
     if (node->shoutcast == 1)
     {
         char *source_password, *ptr, *headers;
-        mount_proxy *mountinfo = config_find_mount (config, shoutcast_mount);
+        mount_proxy *mountinfo = config_find_mount (config, shoutcast_mount, MOUNT_TYPE_NORMAL);
 
         if (mountinfo && mountinfo->password)
             source_password = strdup (mountinfo->password);

Modified: icecast/trunk/icecast/src/format.c
===================================================================
--- icecast/trunk/icecast/src/format.c	2013-04-02 12:19:33 UTC (rev 18901)
+++ icecast/trunk/icecast/src/format.c	2013-04-02 18:46:44 UTC (rev 18902)
@@ -339,7 +339,7 @@
 		    mount_proxy *mountinfo;
 
 		    config = config_get_config();
-		    mountinfo = config_find_mount (config, source->mount);
+		    mountinfo = config_find_mount (config, source->mount, MOUNT_TYPE_NORMAL);
 
 		    if (mountinfo && mountinfo->stream_name)
 		        bytes = snprintf (ptr, remaining, "icy-name:%s\r\n", mountinfo->stream_name);

Modified: icecast/trunk/icecast/src/slave.c
===================================================================
--- icecast/trunk/icecast/src/slave.c	2013-04-02 12:19:33 UTC (rev 18901)
+++ icecast/trunk/icecast/src/slave.c	2013-04-02 18:46:44 UTC (rev 18902)
@@ -407,7 +407,7 @@
             if (relay->on_demand)
             {
                 ice_config_t *config = config_get_config ();
-                mount_proxy *mountinfo = config_find_mount (config, relay->localmount);
+                mount_proxy *mountinfo = config_find_mount (config, relay->localmount, MOUNT_TYPE_NORMAL);
                 if (mountinfo == NULL)
                     source_update_settings (config, relay->source, mountinfo);
                 config_release_config ();
@@ -474,7 +474,7 @@
         if (relay->on_demand && relay->source)
         {
             ice_config_t *config = config_get_config ();
-            mount_proxy *mountinfo = config_find_mount (config, relay->localmount);
+            mount_proxy *mountinfo = config_find_mount (config, relay->localmount, MOUNT_TYPE_NORMAL);
             source_update_settings (config, relay->source, mountinfo);
             config_release_config ();
             stats_event (relay->localmount, "listeners", "0");

Modified: icecast/trunk/icecast/src/source.c
===================================================================
--- icecast/trunk/icecast/src/source.c	2013-04-02 12:19:33 UTC (rev 18901)
+++ icecast/trunk/icecast/src/source.c	2013-04-02 18:46:44 UTC (rev 18902)
@@ -170,7 +170,7 @@
         /* we either have a source which is not active (relay) or no source
          * at all. Check the mounts list for fallback settings
          */
-        mountinfo = config_find_mount (config, mount);
+        mountinfo = config_find_mount (config, mount, MOUNT_TYPE_NORMAL);
         source = NULL;
 
         if (mountinfo == NULL)
@@ -662,7 +662,7 @@
     source->prev_listeners = -1;
     source->running = 1;
 
-    mountinfo = config_find_mount (config_get_config(), source->mount);
+    mountinfo = config_find_mount (config_get_config(), source->mount, MOUNT_TYPE_NORMAL);
     if (mountinfo)
     {
         if (mountinfo->on_connect)
@@ -870,7 +870,7 @@
     source->running = 0;
     INFO1("Source \"%s\" exiting", source->mount);
 
-    mountinfo = config_find_mount (config_get_config(), source->mount);
+    mountinfo = config_find_mount (config_get_config(), source->mount, MOUNT_TYPE_NORMAL);
     if (mountinfo)
     {
         if (mountinfo->on_disconnect)
@@ -1423,8 +1423,11 @@
     if (update_all)
         stats_clear_virtual_mounts ();
 
-    while (mount)
+    for (; mount; mount = mount->next)
     {
+        if (mount->mounttype != MOUNT_TYPE_NORMAL)
+	    continue;
+
         source_t *source = source_find_mount (mount->mountname);
 
         if (source)
@@ -1432,7 +1435,7 @@
             source = source_find_mount_raw (mount->mountname);
             if (source)
             {
-                mount_proxy *mountinfo = config_find_mount (config, source->mount);
+                mount_proxy *mountinfo = config_find_mount (config, source->mount, MOUNT_TYPE_NORMAL);
                 source_update_settings (config, source, mountinfo);
             }
             else if (update_all)
@@ -1460,8 +1463,6 @@
                         strdup (mount->fallback_mount), THREAD_DETACHED);
             }
         }
-
-        mount = mount->next;
     }
     avl_tree_unlock (global.source_tree);
     config_release_config();

Modified: icecast/trunk/icecast/src/yp.c
===================================================================
--- icecast/trunk/icecast/src/yp.c	2013-04-02 12:19:33 UTC (rev 18901)
+++ icecast/trunk/icecast/src/yp.c	2013-04-02 18:46:44 UTC (rev 18902)
@@ -593,7 +593,7 @@
             snprintf (url, ret, "http://%s:%d%s", config->hostname, config->port, mount);
         }
 
-        mountproxy = config_find_mount (config, mount);
+        mountproxy = config_find_mount (config, mount, MOUNT_TYPE_NORMAL);
         if (mountproxy && mountproxy->cluster_password)
             add_yp_info (yp, mountproxy->cluster_password, YP_CLUSTER_PASSWORD);
         config_release_config();



More information about the commits mailing list