Re: [PATCH] include mount point from single text files in a given directory

marco <[email protected]>
Newsgroups gmane.comp.audio.icecast.devel
Message-ID <[email protected]>
Il giorno 19/feb/2012, alle ore 10:28, marco ha scritto:

> This patch introduces a new configuration directive, mount-include, which syntax is basically:

i reattach the patch with some minor modifications. Added a check that what we are merging in the XML config is a "mount" element.

marco

_______________________________________________
Icecast-dev mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/icecast-dev
patch-mount-include.02.patch (application/octet-stream, 3.8 KB)
diff -uNr ../icecast-2.3.2/AUTHORS ./AUTHORS
--- ../icecast-2.3.2/AUTHORS	2005-07-04 00:11:52.000000000 +0200
+++ ./AUTHORS	2012-02-19 10:22:45.000000000 +0100
@@ -2,3 +2,4 @@
 Michael Smith <[email protected]>
 oddsock <[email protected]>
 Karl Heyes <[email protected]>
+Marco Miralto <[email protected]>
diff -uNr ../icecast-2.3.2/src/cfgfile.c ./src/cfgfile.c
--- ../icecast-2.3.2/src/cfgfile.c	2008-05-02 04:56:58.000000000 +0200
+++ ./src/cfgfile.c	2012-02-19 15:47:12.000000000 +0100
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
+#include <dirent.h>
 
 #include "thread/thread.h"
 #include "cfgfile.h"
@@ -80,6 +81,7 @@
 static void _parse_paths(xmlDocPtr doc, xmlNodePtr node, ice_config_t *c);
 static void _parse_logging(xmlDocPtr doc, xmlNodePtr node, ice_config_t *c);
 static void _parse_security(xmlDocPtr doc, xmlNodePtr node, ice_config_t *c);
+static void _parse_mountinclude(xmlDocPtr doc, xmlNodePtr node, ice_config_t *c);
 static void _parse_authentication(xmlDocPtr doc, xmlNodePtr node, 
         ice_config_t *c);
 static void _parse_relay(xmlDocPtr doc, xmlNodePtr node, ice_config_t *c);
@@ -479,6 +481,8 @@
             _parse_logging(doc, node->xmlChildrenNode, configuration);
         } else if (xmlStrcmp (node->name, XMLSTR("security")) == 0) {
             _parse_security(doc, node->xmlChildrenNode, configuration);
+        } else if (xmlStrcmp (node->name, XMLSTR("mount-include")) == 0) {
+            _parse_mountinclude(doc, node, configuration);
         }
     } while ((node = node->next));
 
@@ -564,6 +568,7 @@
 
         if (xmlStrcmp (node->name, XMLSTR("mount-name")) == 0) {
             mount->mountname = (char *)xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
+            printf("Loading mountpoint %s\n", mount->mountname);
         }
         else if (xmlStrcmp (node->name, XMLSTR("username")) == 0) {
             mount->username = (char *)xmlNodeListGetString(
@@ -1065,6 +1070,65 @@
    } while ((node = node->next));
 }
 
+static void _parse_mountinclude(xmlDocPtr doc, xmlNodePtr node,
+        ice_config_t *configuration)
+{
+    char *tmp;
+    DIR *mount_dir;
+    struct dirent *ent;
+    char *file_full;
+    
+    xmlNodePtr parent = node;
+    node = node->xmlChildrenNode;
+
+
+    do {
+        if (node == NULL) break;
+        if (xmlIsBlankNode(node)) continue;
+
+        if (xmlStrcmp (node->name, XMLSTR("dir")) == 0) {
+            tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
+        }
+    } while ((node = node->next));
+
+    mount_dir = opendir(tmp);
+    
+    if (mount_dir != NULL) {
+        while ((ent = readdir(mount_dir))) {
+            if (ent->d_type & DT_REG){
+                file_full = (char *) malloc (sizeof(char) * (strlen(tmp)+strlen(ent->d_name)+1));
+                sprintf(file_full,"%s%s", tmp, ent->d_name);
+                
+                xmlDocPtr mount_doc;
+                xmlNodePtr mount_node;
+
+                mount_doc = xmlParseFile(file_full);
+                if (mount_doc != NULL) {
+                    mount_node = xmlDocGetRootElement(mount_doc);
+
+                    if (xmlStrcmp (mount_node->name, XMLSTR("mount")) == 0){
+
+                        xmlNodePtr n;
+                        n = xmlAddSibling(parent, mount_node);
+                    }
+
+                    xmlFreeDoc(mount_doc);
+                         
+                } else {
+                    xmlFreeDoc(mount_doc);
+                } 
+                
+                free(file_full);
+            }
+        }
+        closedir(mount_dir);
+    }
+    else {
+        printf ("Could not open mount-include directory %s\n", tmp);
+    }
+}
+
+
 static void _add_server(xmlDocPtr doc, xmlNodePtr node, 
         ice_config_t *configuration)
 {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.