[xiph-commits] r18664 - icecast/branches/ph3/icecast/src

ph3-der-loewe at svn.xiph.org ph3-der-loewe at svn.xiph.org
Sat Oct 13 16:15:38 PDT 2012


Author: ph3-der-loewe
Date: 2012-10-13 16:15:38 -0700 (Sat, 13 Oct 2012)
New Revision: 18664

Modified:
   icecast/branches/ph3/icecast/src/cfgfile.c
   icecast/branches/ph3/icecast/src/cfgfile.h
   icecast/branches/ph3/icecast/src/plugins.c
Log:
added CPI support

Modified: icecast/branches/ph3/icecast/src/cfgfile.c
===================================================================
--- icecast/branches/ph3/icecast/src/cfgfile.c	2012-10-13 21:39:21 UTC (rev 18663)
+++ icecast/branches/ph3/icecast/src/cfgfile.c	2012-10-13 23:15:38 UTC (rev 18664)
@@ -179,6 +179,19 @@
     return next;
 }
 
+cpi_t *config_clear_cpi (cpi_t *cpi)
+{
+    cpi_t *next = NULL;
+    if (cpi)
+    {
+        next = cpi->next;
+        if (cpi->protocol) xmlFree (cpi->protocol);
+        if (cpi->host) xmlFree (cpi->host);
+        free (cpi);
+    }
+    return next;
+}
+
 void config_clear(ice_config_t *c)
 {
     ice_config_dir_t *dirnode, *nextdirnode;
@@ -273,6 +286,8 @@
 
     while ((c->plugins = config_clear_plugin (c->plugins)))
         ;
+    while ((c->cpis = config_clear_cpi (c->cpis)))
+        ;
 
     memset(c, 0, sizeof(ice_config_t));
 }
@@ -892,28 +907,86 @@
         ret->args = (char*)xmlStrdup (XMLSTR(ret->args));
 }
 
+static void _parse_cpi(xmlDocPtr doc, xmlNodePtr node, cpi_t **cpi)
+{
+    cpi_t *ret = calloc (1, sizeof(cpi_t));
+    const char * tmp;
+
+    *cpi = ret;
+
+    if (!ret)
+        return;
+
+    ret->protocol = (char*)xmlGetProp(node, XMLSTR("protocol"));
+    if (!ret->protocol)
+    {
+        free (ret);
+        *cpi = NULL;
+        return;
+    }
+    ret->protocol = (char*)xmlStrdup (XMLSTR(ret->protocol));
+
+    ret->host = (char*)xmlGetProp(node, XMLSTR("host"));
+    if (!ret->host) {
+        xmlFree (ret->protocol);
+        free (ret);
+        *cpi = NULL;
+        return;
+    }
+    ret->host = (char*)xmlStrdup (XMLSTR(ret->host));
+
+    tmp = (const char*)xmlGetProp(node, XMLSTR("port"));
+    if (tmp)
+        ret->port = atoi (tmp);
+    else
+        ret->port = 12347; // just a random port.
+
+    tmp = (const char*)xmlGetProp(node, XMLSTR("autoload"));
+    if (tmp)
+        ret->autoload = atoi (tmp);
+    else
+        ret->autoload = 0;
+}
+
 static void _parse_plugins(xmlDocPtr doc, xmlNodePtr node, ice_config_t *c) {
-    plugin_t **tail = NULL;
-    plugin_t *next;
+    plugin_t **p_tail = NULL;
+    plugin_t *p_next;
+    cpi_t **c_tail = NULL;
+    cpi_t *c_next;
 
-    tail = &c->plugins;
-    while (*tail)
-        tail = &(*tail)->next;
+    p_tail = &c->plugins;
+    while (*p_tail)
+        p_tail = &(*p_tail)->next;
 
+    c_tail = &c->cpis;
+    while (*c_tail)
+        c_tail = &(*c_tail)->next;
+
     do {
         if (node == NULL) break;
         if (xmlIsBlankNode(node)) continue;
         if (xmlStrcmp (node->name, XMLSTR("plugin")) == 0)
 	{
-	    next = NULL;
-	    _parse_plugin(doc, node, &next);
-	    if (next)
+	    p_next = NULL;
+	    _parse_plugin(doc, node, &p_next);
+	    if (p_next)
 	    {
-	        *tail = next;
-		tail = &next->next;
-		*tail = NULL;
+	        *p_tail = p_next;
+		p_tail = &p_next->next;
+		*p_tail = NULL;
 	    }
 	}
+        else if (xmlStrcmp (node->name, XMLSTR("cpi")) == 0)
+        {
+            c_next = NULL;
+            _parse_cpi(doc, node, &c_next);
+            if (c_next)
+            {
+                *c_tail = c_next;
+                c_tail = &c_next->next;
+                *c_tail = NULL;
+            }
+        }
     } while ((node = node->next));
 }
 

Modified: icecast/branches/ph3/icecast/src/cfgfile.h
===================================================================
--- icecast/branches/ph3/icecast/src/cfgfile.h	2012-10-13 21:39:21 UTC (rev 18663)
+++ icecast/branches/ph3/icecast/src/cfgfile.h	2012-10-13 23:15:38 UTC (rev 18664)
@@ -116,6 +116,14 @@
     char *args;
 } plugin_t;
 
+typedef struct _cpi_t {
+    struct _cpi_t *next;
+    char *protocol;
+    char *host;
+    int port;
+    int autoload;
+} cpi_t;
+
 typedef struct ice_config_tag
 {
     char *config_filename;
@@ -191,6 +199,7 @@
     int num_yp_directories;
 
     plugin_t *plugins;
+    cpi_t *cpis;
 } ice_config_t;
 
 typedef struct {

Modified: icecast/branches/ph3/icecast/src/plugins.c
===================================================================
--- icecast/branches/ph3/icecast/src/plugins.c	2012-10-13 21:39:21 UTC (rev 18663)
+++ icecast/branches/ph3/icecast/src/plugins.c	2012-10-13 23:15:38 UTC (rev 18664)
@@ -29,6 +29,7 @@
 static struct roar_plugincontainer * container = NULL;
 static int plugins_running = 0;
 static struct roar_scheduler * sched = NULL;
+static struct roar_scheduler_source source_cpi_service = {.type = ROAR_SCHEDULER_CPI_SERVICE};
 static struct roar_scheduler_source source_container = {.type = ROAR_SCHEDULER_PLUGINCONTAINER};
 static struct roar_scheduler_source source_timeout = {.type = ROAR_SCHEDULER_TIMEOUT, .handle.timeout = {0, 500000000L}};
 
@@ -45,6 +46,7 @@
     roar_plugincontainer_set_autoappsched(container, 1);
     sched = roar_scheduler_new(ROAR_SCHEDULER_FLAG_DEFAULT, ROAR_SCHEDULER_STRATEGY_DEFAULT);
     source_container.handle.container = container;
+    roar_scheduler_source_add(sched, &source_cpi_service);
     roar_scheduler_source_add(sched, &source_container);
     roar_scheduler_source_add(sched, &source_timeout);
     roarapi_unlock();
@@ -82,16 +84,67 @@
 #ifdef HAVE_ROARAUDIO
     struct roar_dl_librarypara * para = NULL;
 
-    if (plugin->args)
+    para = roar_dl_para_new(plugin->args, NULL, ICECAST_HOST_STRING, PACKAGE_VERSION);
+    if (!para)
+        return;
+
+    roar_plugincontainer_load(container, plugin->name, para);
+    roar_dl_para_unref(para);
+#else
+    ERROR1("Can not load plugin \"%s\" as RoarAudio support is not compiled in.", plugin->name);
+#endif
+}
+
+static void to_lower(char * p)
+{
+    for (; *p; p++)
+        if ( *p >= 'A' && *p <= 'Z' )
+	    *p += 'a' - 'A';
+}
+
+static void plugins_load_cpi(cpi_t *cpi)
+{
+#ifdef HAVE_ROARAUDIO
+    struct roar_scheduler_source * source = roar_mm_malloc(sizeof(*source));
+    char protoname[80];
+    plugin_t plugin;
+
+    if (!source)
+        return;
+
+    memset(source, 0, sizeof(*source));
+    source->flags = ROAR_SCHEDULER_FLAG_FREE;
+    source->type  = ROAR_SCHEDULER_CPI_LISTEN;
+    source->handle.cpi.proto = roar_str2proto(cpi->protocol);
+
+    source->vio   = roar_mm_malloc(sizeof(struct roar_vio_calls));
+    if (!source->vio)
     {
-        para = roar_dl_para_new(plugin->args, NULL, ICECAST_HOST_STRING, PACKAGE_VERSION);
-	if (!para)
-	    return;
+        roar_mm_free(source);
+	return;
     }
 
-    roar_plugincontainer_load(container, plugin->name, para);
+    if ( roar_vio_open_socket_listen(source->vio, ROAR_SOCKET_TYPE_UNKNOWN, cpi->host, cpi->port) == -1 )
+    {
+        roar_mm_free(source->vio);
+        roar_mm_free(source);
+	return;
+    }
+
+    source->vio->flags |= ROAR_VIO_FLAGS_FREESELF;
+
+    roar_scheduler_source_add(sched, source);
+
+    if ((source->flags & ROAR_SCHEDULER_FLAG_STUB) && cpi->autoload)
+    {
+        snprintf (protoname, sizeof(protoname), "protocol-%s", roar_proto2str(source->handle.cpi.proto));
+	to_lower(protoname);
+	memset(&plugin, 0, sizeof(plugin));
+	plugin.name = protoname;
+	plugins_load_one(&plugin);
+    }
 #else
-    ERROR1("Can not load plugin \"%s\" as RoarAudio support is not compiled in.". plugin->name);
+    ERROR0("Can not load CPI as RoarAudio support is not compiled in.");
 #endif
 }
 
@@ -99,7 +152,8 @@
 {
     static int done = 0;
     int need_release = 0;
-    plugin_t *next;
+    plugin_t *p_next;
+    cpi_t *c_next;
 
     // ensure this is not done twice as the current code does not support this.
     if (done)
@@ -113,12 +167,18 @@
     }
 
     roarapi_lock();
-    next = config->plugins;
-    while (next)
+    p_next = config->plugins;
+    while (p_next)
     {
-	plugins_load_one(next);
-        next = next->next;
+	plugins_load_one(p_next);
+        p_next = p_next->next;
     }
+    c_next = config->cpis;
+    while (c_next)
+    {
+        plugins_load_cpi(c_next);
+        c_next = c_next->next;
+    }
     roarapi_unlock();
 
     if (need_release)



More information about the commits mailing list