[asterisk-commits] jpeeler: branch 1.6.2 r278709 - in /branches/1.6.2: ./ main/xmldoc.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jul 22 14:52:21 CDT 2010


Author: jpeeler
Date: Thu Jul 22 14:52:17 2010
New Revision: 278709

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=278709
Log:
Merged revisions 278708 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
  r278708 | jpeeler | 2010-07-22 14:45:30 -0500 (Thu, 22 Jul 2010) | 16 lines
  
  Add method for finding XML doc files for systems that don't support GLOB_BRACE.
  
  In particular, Solaris and perhaps others do not support the above mentioned
  GNU extension. In this case the paths are simply expanded without the braces
  and the calls to glob are made separately.
  
  Note: I could not explain memory allocation failures that were being reported
  from within libxml itself when making calls to glob without using GLOB_NOCHECK.
  This is the only reason why that flag is being used.
  
  (closes issue #15402)
  Reported by: snuffy
  Patches: 
        bug_xmlpatt-v3.diff uploaded by snuffy (license 35),
        modified by me
........

Modified:
    branches/1.6.2/   (props changed)
    branches/1.6.2/main/xmldoc.c

Propchange: branches/1.6.2/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.2/main/xmldoc.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/main/xmldoc.c?view=diff&rev=278709&r1=278708&r2=278709
==============================================================================
--- branches/1.6.2/main/xmldoc.c (original)
+++ branches/1.6.2/main/xmldoc.c Thu Jul 22 14:52:17 2010
@@ -1747,6 +1747,49 @@
 	return xmldoc_build_field(type, name, "description", 0);
 }
 
+#if !defined(HAVE_GLOB_NOMAGIC) || !defined(HAVE_GLOB_BRACE) || defined(DEBUG_NONGNU)
+static int xml_pathmatch(char *xmlpattern, int xmlpattern_maxlen, glob_t *globbuf)
+{
+	int globret;
+
+	snprintf(xmlpattern, xmlpattern_maxlen, "%s/documentation/thirdparty/*-%s.xml",
+		ast_config_AST_DATA_DIR, documentation_language);
+	if((globret = glob(xmlpattern, GLOB_NOCHECK, NULL, globbuf))) {
+		return globret;
+	}
+
+	snprintf(xmlpattern, xmlpattern_maxlen, "%s/documentation/thirdparty/*-%.2s_??.xml",
+		ast_config_AST_DATA_DIR, documentation_language);
+	if((globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf))) {
+		return globret;
+	}
+
+	snprintf(xmlpattern, xmlpattern_maxlen, "%s/documentation/thirdparty/*-%s.xml",
+		ast_config_AST_DATA_DIR, default_documentation_language);
+	if((globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf))) {
+		return globret;
+	}
+
+	snprintf(xmlpattern, xmlpattern_maxlen, "%s/documentation/*-%s.xml",
+		ast_config_AST_DATA_DIR, documentation_language);
+	if((globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf))) {
+		return globret;
+	}
+
+	snprintf(xmlpattern, xmlpattern_maxlen, "%s/documentation/*-%.2s_??.xml",
+		ast_config_AST_DATA_DIR, documentation_language);
+	if((globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf))) {
+		return globret;
+	}
+
+	snprintf(xmlpattern, xmlpattern_maxlen, "%s/documentation/*-%s.xml",
+		ast_config_AST_DATA_DIR, default_documentation_language);
+	globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf);
+
+	return globret;
+}
+#endif
+
 /*! \brief Close and unload XML documentation. */
 static void xmldoc_unload_documentation(void)
 {
@@ -1773,6 +1816,9 @@
 	struct ast_flags cnfflags = { 0 };
 	int globret, i, dup, duplicate;
 	glob_t globbuf;
+#if !defined(HAVE_GLOB_NOMAGIC) || !defined(HAVE_GLOB_BRACE) || defined(DEBUG_NONGNU)
+	int xmlpattern_maxlen;
+#endif
 
 	/* setup default XML documentation language */
 	snprintf(documentation_language, sizeof(documentation_language), default_documentation_language);
@@ -1794,17 +1840,26 @@
 	/* register function to be run when asterisk finish. */
 	ast_register_atexit(xmldoc_unload_documentation);
 
+	globbuf.gl_offs = 0;    /* slots to reserve in gl_pathv */
+
+#if !defined(HAVE_GLOB_NOMAGIC) || !defined(HAVE_GLOB_BRACE) || defined(DEBUG_NONGNU)
+	xmlpattern_maxlen = strlen(ast_config_AST_DATA_DIR) + strlen("/documentation/thirdparty") + strlen("/*-??_??.xml") + 1;
+	xmlpattern = ast_malloc(xmlpattern_maxlen);
+	globret = xml_pathmatch(xmlpattern, xmlpattern_maxlen, &globbuf);
+#else
 	/* Get every *-LANG.xml file inside $(ASTDATADIR)/documentation */
 	ast_asprintf(&xmlpattern, "%s/documentation{/thirdparty/,/}*-{%s,%.2s_??,%s}.xml", ast_config_AST_DATA_DIR,
-			documentation_language, documentation_language, default_documentation_language);
-	globbuf.gl_offs = 0;    /* initialize it to silence gcc */
+		documentation_language, documentation_language, default_documentation_language);
 	globret = glob(xmlpattern, MY_GLOB_FLAGS, NULL, &globbuf);
+#endif
+
+	ast_debug(3, "gl_pathc %zd\n", globbuf.gl_pathc);
 	if (globret == GLOB_NOSPACE) {
-		ast_log(LOG_WARNING, "Glob Expansion of pattern '%s' failed: Not enough memory\n", xmlpattern);
+		ast_log(LOG_WARNING, "XML load failure, glob expansion of pattern '%s' failed: Not enough memory\n", xmlpattern);
 		ast_free(xmlpattern);
 		return 1;
 	} else if (globret  == GLOB_ABORTED) {
-		ast_log(LOG_WARNING, "Glob Expansion of pattern '%s' failed: Read error\n", xmlpattern);
+		ast_log(LOG_WARNING, "XML load failure, glob expansion of pattern '%s' failed: Read error\n", xmlpattern);
 		ast_free(xmlpattern);
 		return 1;
 	}
@@ -1821,7 +1876,9 @@
 				break;
 			}
 		}
-		if (duplicate) {
+		if (duplicate || strchr(globbuf.gl_pathv[i], '*')) {
+		/* skip duplicates as well as pathnames not found 
+		 * (due to use of GLOB_NOCHECK in xml_pathmatch) */
 			continue;
 		}
 		tmpdoc = NULL;




More information about the asterisk-commits mailing list