[svn-commits] twilson: branch twilson/config_docs r370516 - in /team/twilson/config_docs: d...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jul 25 23:47:19 CDT 2012


Author: twilson
Date: Wed Jul 25 23:47:15 2012
New Revision: 370516

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=370516
Log:
Add handling for config option syntax


Modified:
    team/twilson/config_docs/doc/appdocsxml.dtd
    team/twilson/config_docs/include/asterisk/xmldoc.h
    team/twilson/config_docs/main/config_options.c
    team/twilson/config_docs/main/xml.c
    team/twilson/config_docs/main/xmldoc.c

Modified: team/twilson/config_docs/doc/appdocsxml.dtd
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_docs/doc/appdocsxml.dtd?view=diff&rev=370516&r1=370515&r2=370516
==============================================================================
--- team/twilson/config_docs/doc/appdocsxml.dtd (original)
+++ team/twilson/config_docs/doc/appdocsxml.dtd Wed Jul 25 23:47:15 2012
@@ -43,7 +43,7 @@
   <!ELEMENT configFile (configObject+)>
   <!ATTLIST configFile name CDATA #REQUIRED>
 
-  <!ELEMENT configObject (synopsis?,description?,syntax?,configOption+)>
+  <!ELEMENT configObject (synopsis?|description?|syntax?|configOption)*>
   <!ATTLIST configObject name ID #REQUIRED>
 
   <!ELEMENT configOption (synopsis,description?,syntax?)*>
@@ -51,10 +51,9 @@
   <!ATTLIST configOption regex (yes|no|true|false) "false">
   <!ATTLIST configOption default CDATA #IMPLIED>
 
-  <!ELEMENT matchInfo (category,field?)>
+  <!ELEMENT matchInfo (category|field?)>
 
   <!ELEMENT category (#PCDATA)>
-  <!ATTLIST category regex CDATA #REQUIRED>
   <!ATTLIST category match (yes|no|true|false) #REQUIRED>
 
   <!ELEMENT field (#PCDATA)>
@@ -77,7 +76,7 @@
 
   <!ELEMENT synopsis (#PCDATA)>
 
-  <!ELEMENT syntax (parameter|dataType|category|xi:include)*>
+  <!ELEMENT syntax (parameter|dataType|category|matchInfo|xi:include)*>
   <!ATTLIST syntax argsep CDATA ",">
 
   <!ELEMENT description (para|note|warning|variablelist|enumlist|info|xi:include)*>

Modified: team/twilson/config_docs/include/asterisk/xmldoc.h
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_docs/include/asterisk/xmldoc.h?view=diff&rev=370516&r1=370515&r2=370516
==============================================================================
--- team/twilson/config_docs/include/asterisk/xmldoc.h (original)
+++ team/twilson/config_docs/include/asterisk/xmldoc.h Wed Jul 25 23:47:15 2012
@@ -71,7 +71,8 @@
 	unsigned int regex;
 };
 
-void ast_xml_doc_update_config_option(const char *module, const char *name, const char *object_name, const char *default_value, unsigned int regex);
+void ast_xmldoc_update_config_option(const char *module, const char *name, const char *object_name, const char *default_value, unsigned int regex);
+void ast_xmldoc_update_config_type(const char *module, const char *name, const char *category, const char *matchfield, const char *matchvalue, unsigned int matches);
 
 /*!
  *  \brief Get the syntax for a specified application or function.

Modified: team/twilson/config_docs/main/config_options.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_docs/main/config_options.c?view=diff&rev=370516&r1=370515&r2=370516
==============================================================================
--- team/twilson/config_docs/main/config_options.c (original)
+++ team/twilson/config_docs/main/config_options.c Wed Jul 25 23:47:15 2012
@@ -147,7 +147,7 @@
 	return regex;
 }
 
-static int link_option_to_types(struct aco_type **types, struct aco_option *opt)
+static int link_option_to_types(struct aco_info *info, struct aco_type **types, struct aco_option *opt)
 {
 	size_t idx = 0;
 	struct aco_type *type;
@@ -160,7 +160,7 @@
 			return -1;
 		}
 #ifdef AST_XML_DOCS
-		ast_xml_doc_update_config_option(AST_MODULE, opt->name, type->name, opt->default_val, opt->match_type == ACO_REGEX);
+		ast_xmldoc_update_config_option(info->module, opt->name, type->name, opt->default_val, opt->match_type == ACO_REGEX);
 #endif
 	}
 	return 0;
@@ -183,7 +183,7 @@
 	opt->deprecated = 1;
 	opt->match_type = ACO_EXACT;
 
-	if (link_option_to_types(types, opt)) {
+	if (link_option_to_types(info, types, opt)) {
 		ao2_ref(opt, -1);
 		return -1;
 	}
@@ -194,7 +194,7 @@
 #ifdef AST_XML_DOCS
 /*! \brief Find a particular ast_xml_doc_item by module, types, and name
  */
-static struct ast_xml_doc_item *find_docs(struct ast_xml_doc_item *config_info, struct aco_type **types, const char *name)
+static struct ast_xml_doc_item *find_xmldoc_option(struct ast_xml_doc_item *config_info, struct aco_type **types, const char *name)
 {
 	struct ast_xml_doc_item *iter = config_info;
 
@@ -215,6 +215,22 @@
 		}
 	}
 	return NULL;
+}
+
+static struct ast_xml_doc_item *find_xmldoc_type(struct ast_xml_doc_item *config_info, const char *name)
+{
+	struct ast_xml_doc_item *iter = config_info;
+	if (!iter) {
+		return NULL;
+	}
+	/* First is just the config Info, skip it */
+	while ((iter = iter->next)) {
+		if (strcasecmp(iter->type, "configObject") || strcasecmp(iter->name, name)) {
+			continue;
+		}
+		break;
+	}
+	return iter;
 }
 #endif
 
@@ -264,7 +280,7 @@
 		return -1;
 	};
 
-	if (link_option_to_types(types, opt)) {
+	if (link_option_to_types(info, types, opt)) {
 		ao2_ref(opt, -1);
 		return -1;
 	}
@@ -275,7 +291,7 @@
 		RAII_VAR(struct ast_xml_doc_item *, config_info, ao2_find(xmldocs, info->module, OBJ_KEY), ao2_cleanup);
 		struct ast_xml_doc_item *config_option;
 
-		if (!config_info || !(config_option = find_docs(config_info, types, name))) {
+		if (!config_info || !(config_option = find_xmldoc_option(config_info, types, name))) {
 			ast_log(LOG_ERROR, "XML Documentation for option '%s' in modules '%s' not found!\n", name, info->module);
 			/* ao2_ref(opt, -1);
 			 * return -1; */
@@ -669,19 +685,43 @@
 	return 0;
 }
 
+static void update_runtime_type_docs(const char *module, struct aco_type *type)
+{
+	RAII_VAR(struct ast_xml_doc_item *, config_info, ao2_find(xmldocs, module, OBJ_KEY), ao2_cleanup);
+	struct ast_xml_doc_item *config_type;
+
+	if (!config_info || !(config_type = find_xmldoc_type(config_info, type->name))) {
+		return;
+	}
+	if (ast_str_strlen(config_type->syntax)) {
+		return;
+	}
+
+	ast_str_set(&config_type->syntax, 0, "category %s /%s/\n", type->category_match == ACO_WHITELIST ? "=~" : "!~", type->category);
+	if (!ast_strlen_zero(type->matchfield)) {
+		ast_str_append(&config_type->syntax, 0, "matchfield: %s = %s\n", type->matchfield, type->matchvalue);
+	}
+}
+
 int aco_info_init(struct aco_info *info)
 {
-	size_t x, y;
+	size_t x = 0, y = 0;
+	struct aco_file *file;
+	struct aco_type *type;
 
 	if (!(info->internal = ast_calloc(1, sizeof(*info->internal)))) {
 		return -1;
 	}
 
-	for (x = 0; info->files[x]; x++) {
-		for (y = 0; info->files[x]->types[y]; y++) {
-			if (internal_type_init(info->files[x]->types[y])) {
+	while ((file = info->files[x++])) {
+		while ((type = file->types[y++])) {
+			if (internal_type_init(type)) {
 				goto error;
 			}
+#ifdef AST_XML_DOCS
+			ast_xmldoc_update_config_type(info->module, type->name, type->category, type->matchfield, type->matchvalue, type->category_match == ACO_WHITELIST);
+			update_runtime_type_docs(info->module, type);
+#endif
 		}
 	}
 

Modified: team/twilson/config_docs/main/xml.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_docs/main/xml.c?view=diff&rev=370516&r1=370515&r2=370516
==============================================================================
--- team/twilson/config_docs/main/xml.c (original)
+++ team/twilson/config_docs/main/xml.c Wed Jul 25 23:47:15 2012
@@ -28,6 +28,7 @@
 #include "asterisk.h"
 #include "asterisk/xml.h"
 #include "asterisk/logger.h"
+#include "asterisk/utils.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
@@ -348,7 +349,7 @@
 	}
 	if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
 		xmlXPathFreeObject(result);
-		ast_log(LOG_WARNING, "No results for query: %s\n", xpath_str);
+		ast_debug(5, "No results for query: %s\n", xpath_str);
 		return NULL;
 	}
 	return (struct ast_xml_xpath_results *) result;

Modified: team/twilson/config_docs/main/xmldoc.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_docs/main/xmldoc.c?view=diff&rev=370516&r1=370515&r2=370516
==============================================================================
--- team/twilson/config_docs/main/xmldoc.c (original)
+++ team/twilson/config_docs/main/xmldoc.c Wed Jul 25 23:47:15 2012
@@ -1105,7 +1105,7 @@
 
 static char *xmldoc_get_syntax_config_object(struct ast_xml_node *fixnode, const char *name)
 {
-	struct ast_xml_node *node;
+	struct ast_xml_node *matchinfo, *tmp;
 	int match;
 	const char *text;
 	RAII_VAR(struct ast_str *, syntax, ast_str_create(128), ast_free);
@@ -1113,13 +1113,20 @@
 	if (!syntax) {
 		return NULL;
 	}
-	if (!(node = ast_xml_find_element(ast_xml_node_get_children(fixnode), "category", NULL, NULL))) {
+	if (!(matchinfo = ast_xml_find_element(ast_xml_node_get_children(fixnode), "matchInfo", NULL, NULL))) {
 		return NULL;
 	}
-	match = ast_true(ast_xml_get_attribute(node, "match"));
-	text = ast_xml_get_text(node);
+	if (!(tmp  = ast_xml_find_element(ast_xml_node_get_children(matchinfo), "category", NULL, NULL))) {
+		return NULL;
+	}
+	match = ast_true(ast_xml_get_attribute(tmp, "match"));
+	text = ast_xml_get_text(tmp);
 	ast_str_set(&syntax, 0, "category %s /%s/\n", match ? "=~" : "!~", text);
 
+	if ((tmp = ast_xml_find_element(ast_xml_node_get_children(matchinfo), "field", NULL, NULL))) {
+		text = ast_xml_get_text(tmp);
+		ast_str_append(&syntax, 0, "matchfield: %s = %s\n", ast_xml_get_attribute(tmp, "name"), text);
+	}
 	return ast_strdup(ast_str_buffer(syntax));
 }
 
@@ -2263,13 +2270,20 @@
 	return item;
 }
 
-static struct ast_xml_xpath_results *find_config_option(const char *module, const char * object_name, const char *name)
+static struct ast_xml_xpath_results * __attribute__((format(printf, 1, 2))) query_xmldocs(const char *fmt, ...)
 {
 	struct ast_xml_xpath_results *results = NULL;
 	struct documentation_tree *doctree;
 	RAII_VAR(struct ast_str *, xpath_str, ast_str_create(128), ast_free);
-
-	ast_str_set(&xpath_str, 0, "//configObject[@name='%s']/configOption[@name='%s']", object_name, name);
+	va_list ap;
+
+	if (!xpath_str) {
+		return NULL;
+	}
+
+	va_start(ap, fmt);
+	ast_str_set_va(&xpath_str, 0, fmt, ap);
+	va_end(ap);
 
 	AST_RWLIST_RDLOCK(&xmldoc_tree);
 	AST_LIST_TRAVERSE(&xmldoc_tree, doctree, entry) {
@@ -2283,13 +2297,53 @@
 	return results;
 }
 
-void ast_xml_doc_update_config_option(const char *module, const char *name, const char *object_name, const char *default_value, unsigned int regex)
-{
-	RAII_VAR(struct ast_xml_xpath_results *, results, find_config_option(module, object_name, name), ast_xml_xpath_results_free);
+void ast_xmldoc_update_config_type(const char *module, const char *name, const char *category, const char *matchfield, const char *matchvalue, unsigned int matches)
+{
+	RAII_VAR(struct ast_xml_xpath_results *, results, NULL, ast_xml_xpath_results_free);
+	struct ast_xml_node *type, *syntax, *matchinfo, *tmp;
+
+	/* If we already have a syntax element, bail */
+	if ((results = query_xmldocs("//configInfo[@name='%s']/*/configObject[@name='%s']/syntax", module, name))) {
+		return;
+	}
+
+	if (!(results = query_xmldocs("//configInfo[@name='%s']/*/configObject[@name='%s']", module, name))) {
+		return;
+	}
+
+	if (!(type = ast_xml_xpath_results(results))) {
+		return;
+	}
+
+	if (!(syntax = ast_xml_new_child(type, "syntax"))) {
+		return;
+	}
+
+	if (!(matchinfo = ast_xml_new_child(syntax, "matchInfo"))) {
+		return;
+	}
+
+	if (!(tmp = ast_xml_new_child(matchinfo, "category"))) {
+		return;
+	}
+
+	ast_xml_set_text(tmp, category);
+	ast_xml_set_attribute(tmp, "match", matches ? "true" : "false");
+
+	if (!ast_strlen_zero(matchfield) && !(tmp = ast_xml_new_child(matchinfo, "field"))) {
+		return;
+	}
+
+	ast_xml_set_attribute(tmp, "name", matchfield);
+	ast_xml_set_text(tmp, matchvalue);
+}
+
+void ast_xmldoc_update_config_option(const char *module, const char *name, const char *object_name, const char *default_value, unsigned int regex)
+{
+	RAII_VAR(struct ast_xml_xpath_results *, results, NULL, ast_xml_xpath_results_free);
 	struct ast_xml_node *option;
 
-
-	if (!results) {
+	if (!(results = query_xmldocs("//configInfo[@name='%s']/*/configObject[@name='%s']/configOption[@name='%s']", module, object_name, name))) {
 		return;
 	}
 




More information about the svn-commits mailing list