[asterisk-commits] eliel: branch group/appdocsxml r151721 - /team/group/appdocsxml/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Oct 23 09:25:11 CDT 2008


Author: eliel
Date: Thu Oct 23 09:25:10 2008
New Revision: 151721

URL: http://svn.digium.com/view/asterisk?view=rev&rev=151721
Log:
Make thirdparty XML documents overwrite core documents.
Also don't open duplicated files.
When asterisk stops running unload documentation.

Modified:
    team/group/appdocsxml/main/pbx.c

Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=151721&r1=151720&r2=151721
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Thu Oct 23 09:25:10 2008
@@ -6329,6 +6329,21 @@
 }
 
 #ifdef XML_DOCUMENTATION
+/*! \brief Close and unload XML documentation. */
+static void xmldoc_unload_documentation(void)
+{
+        struct documentation_tree *doctree;
+
+	AST_RWLIST_WRLOCK(&xmldoc_tree);
+	while ((doctree = AST_RWLIST_REMOVE_HEAD(&xmldoc_tree, entry))) {
+		ast_free(doctree->filename);
+		ast_xml_close(doctree->doc);
+	}
+	AST_RWLIST_UNLOCK(&xmldoc_tree);
+
+	ast_xml_finish();
+}
+
 int ast_load_documentation(void) 
 {
 	ast_xml_node *root_node;
@@ -6338,7 +6353,7 @@
 	struct ast_config *cfg = NULL;
 	struct ast_variable *var = NULL;
 	struct ast_flags cnfflags = { 0 };
-	int globret, i;
+	int globret, i, dup, duplicate;
 	glob_t globbuf;
 
 	/* setup default XML documentation language */
@@ -6360,8 +6375,12 @@
 	/* initialize the XML library. */
 	ast_xml_init();
 
+	/* register function to be run when asterisk finish. */
+	ast_register_atexit(xmldoc_unload_documentation);
+
 	/* Get every *-LANG.xml file inside $(ASTDATADIR)/documentation */
-	ast_asprintf(&xmlpattern, "%s/documentation{/,/thirdparty/}*-{%.2s_??,en_US}.xml", ast_config_AST_DATA_DIR, documentation_language);
+	ast_asprintf(&xmlpattern, "%s/documentation{/thirdparty/,/}*-{%.2s_??,%s}.xml", ast_config_AST_DATA_DIR,
+			documentation_language, default_documentation_language);
 	globbuf.gl_offs = 0;    /* initialize it to silence gcc */
 	globret = glob(xmlpattern, MY_GLOB_FLAGS | GLOB_BRACE, NULL, &globbuf);
 	if (globret == GLOB_NOSPACE) {
@@ -6378,6 +6397,17 @@
 	AST_RWLIST_WRLOCK(&xmldoc_tree);
 	/* loop over expanded files */
 	for (i = 0; i < globbuf.gl_pathc; i++) {
+		/* check for duplicates (if we already [try to] open the same file. */
+		duplicate = 0;
+		for (dup = 0; dup < i; dup++) {
+			if (!strcmp(globbuf.gl_pathv[i], globbuf.gl_pathv[dup])) {
+				duplicate = 1;
+				break;
+			}
+		}
+		if (duplicate) {
+			continue;
+		}
 		tmpdoc = NULL;
 		tmpdoc = ast_xml_open(globbuf.gl_pathv[i]);
 		if (!tmpdoc) {




More information about the asterisk-commits mailing list