From d04ab3c6450f3d92aa004ae9d6e0e7da51f702a3 Mon Sep 17 00:00:00 2001 From: Matthew Jordan Date: Fri, 15 Feb 2013 13:38:12 +0000 Subject: Add CLI configuration documentation This patch allows a module to define its configuration in XML in source, such that it can be parsed by the XML documentation engine. Documentation is generated in a two-pass approach: 1. The documentation is first generated from the XML pulled from the source 2. The documentation is then enhanced by the registration of configuration options that use the configuration framework This patch include configuration documentation for the following modules: * chan_motif * res_xmpp * app_confbridge * app_skel * udptl Two new CLI commands have been added: * config show help - show configuration help by module, category, and item * xmldoc dump - dump the in-memory representation of the XML documentation to a new XML file. Review: https://reviewboard.asterisk.org/r/2278 Review: https://reviewboard.asterisk.org/r/2058 patches: on review 2058 uploaded by twilson git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@381527 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/xml.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'main/xml.c') diff --git a/main/xml.c b/main/xml.c index bdf983e51..5ca4d4ff1 100644 --- a/main/xml.c +++ b/main/xml.c @@ -28,6 +28,7 @@ #include "asterisk.h" #include "asterisk/xml.h" #include "asterisk/logger.h" +#include "asterisk/utils.h" ASTERISK_FILE_VERSION(__FILE__, "$Revision$") @@ -35,6 +36,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include #include #include +#include /* libxml2 ast_xml implementation. */ @@ -316,5 +318,42 @@ struct ast_xml_node *ast_xml_node_get_parent(struct ast_xml_node *node) return (struct ast_xml_node *) ((xmlNode *) node)->parent; } +struct ast_xml_node *ast_xml_xpath_get_first_result(struct ast_xml_xpath_results *results) +{ + return (struct ast_xml_node *) ((xmlXPathObjectPtr) results)->nodesetval->nodeTab[0]; +} + +void ast_xml_xpath_results_free(struct ast_xml_xpath_results *results) +{ + xmlXPathFreeObject((xmlXPathObjectPtr) results); +} + +int ast_xml_xpath_num_results(struct ast_xml_xpath_results *results) +{ + return ((xmlXPathObjectPtr) results)->nodesetval->nodeNr; +} + +struct ast_xml_xpath_results *ast_xml_query(struct ast_xml_doc *doc, const char *xpath_str) +{ + xmlXPathContextPtr context; + xmlXPathObjectPtr result; + if (!(context = xmlXPathNewContext((xmlDoc *) doc))) { + ast_log(LOG_ERROR, "Could not create XPath context!\n"); + return NULL; + } + result = xmlXPathEvalExpression((xmlChar *) xpath_str, context); + xmlXPathFreeContext(context); + if (!result) { + ast_log(LOG_WARNING, "Error for query: %s\n", xpath_str); + return NULL; + } + if (xmlXPathNodeSetIsEmpty(result->nodesetval)) { + xmlXPathFreeObject(result); + ast_debug(5, "No results for query: %s\n", xpath_str); + return NULL; + } + return (struct ast_xml_xpath_results *) result; +} + #endif /* defined(HAVE_LIBXML2) */ -- cgit v1.2.3