[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]> |
This patch introduces a new configuration directive, mount-include, which syntax is basically: <mount-include> <dir>/a/directory/path/here/</dir> </mount-include> The <dir> element points to a directory. The path must be absolute and must include a trailing slash. Inside the directory pointed by the did element we place n files each one with a mount section, which will be loaded at the start of the server or after a kill -HUP of the icecast process. e.g. # vim /a/directory/path/here/radiomount <mount> <mount-name>/radiomount</mount-name> <username>radiomount</username> <password>hackme</password> </mount> The patch: - parses the mount-include element and takes the dir path - takes all the regular files (or link to regular files) in the directory - xmlParse them - takes the root element and add a sibling to mount-include. At this point the parsed mount directives are added to the xml configuration and the configuration parser will do its work as usual. Don't know if it is of any help, but it keeps my life simple when adding or removing a mountpoint. This patch applies to src/cfgfile.c, no other files were modified (of course you have to change the configuration file). I also added an entry in AUTHORS, but i do not know what is your policy about that. marco _______________________________________________ Icecast-dev mailing list [email protected] http://lists.xiph.org/mailman/listinfo/icecast-dev
patch-mount-include.patch
(application/octet-stream, 3.6 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 10:14:37.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,62 @@ } 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); + + 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) {