[svn-commits] russell: branch group/appdocsxml r152437 - in /team/group/appdocsxml: include...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Oct 28 13:22:23 CDT 2008


Author: russell
Date: Tue Oct 28 13:22:23 2008
New Revision: 152437

URL: http://svn.digium.com/view/asterisk?view=rev&rev=152437
Log:
Make the ast_xml_node and ast_xml_doc types completely opaque.  This removes the
casting associated with these objects in pbx.c, prevents direct implementation
specific access to object details, and also removes the need for an implementation
specific header file.  Now, the implementation in xml.c is the only place where
casting magic has to be done.

Removed:
    team/group/appdocsxml/include/asterisk/xml_libxml2.h
Modified:
    team/group/appdocsxml/include/asterisk/xml.h
    team/group/appdocsxml/main/pbx.c
    team/group/appdocsxml/main/xml.c

Modified: team/group/appdocsxml/include/asterisk/xml.h
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/include/asterisk/xml.h?view=diff&rev=152437&r1=152436&r2=152437
==============================================================================
--- team/group/appdocsxml/include/asterisk/xml.h (original)
+++ team/group/appdocsxml/include/asterisk/xml.h Tue Oct 28 13:22:23 2008
@@ -21,11 +21,8 @@
  *  \brief Asterisk XML abstraction layer
  */
 
-/* Include here the XML implementation header. */
-#include "asterisk/xml_libxml2.h"
-
-/* Compile this if we have a working XML implementation. */
-#ifdef AST_XML_H_IMPLEMENTATION
+struct ast_xml_node;
+struct ast_xml_doc;
 
 /*! \brief Initialize the XML library implementation. 
  *         This function is used to setup everything needed
@@ -46,25 +43,25 @@
  *  \retval NULL on error.
  *  \retval The ast_xml_doc reference to the open document.
  */
-ast_xml_doc *ast_xml_open(char *filename);
+struct ast_xml_doc *ast_xml_open(char *filename);
 
 /*! \brief Close an already open document and free the used
  *        structure.
  *  \retval doc The document reference.
  */
-void ast_xml_close(ast_xml_doc *doc);
+void ast_xml_close(struct ast_xml_doc *doc);
 
 /*! \brief Get the document root node.
  *  \param doc Document reference
  *  \retval NULL on error
  *  \retval The root node on success.
  */
-ast_xml_node *ast_xml_get_root(ast_xml_doc *doc);
+struct ast_xml_node *ast_xml_get_root(struct ast_xml_doc *doc);
 
 /*! \brief Free node 
  *  \param node Node to be released.
  */
-void ast_xml_free_node(ast_xml_node *node);
+void ast_xml_free_node(struct ast_xml_node *node);
 
 /*! \brief Free an attribute returned by ast_xml_get_attribute()
  *  \param data pointer to be freed.
@@ -82,7 +79,7 @@
  *  \retval NULL on error
  *  \retval The attribute value on success.
  */
-const char *ast_xml_get_attribute(ast_xml_node *node, const char *attrname);
+const char *ast_xml_get_attribute(struct ast_xml_node *node, const char *attrname);
 
 /*! \brief Find a node element by name.
  *  \param node This is the node starting point.
@@ -92,19 +89,27 @@
  *  \retval NULL if not found
  *  \retval The node on success.
  */
-ast_xml_node *ast_xml_find_element(ast_xml_node *root_node, const char *name, const char *attrname, const char *attrvalue);
+struct ast_xml_node *ast_xml_find_element(struct ast_xml_node *root_node, const char *name, const char *attrname, const char *attrvalue);
 
 /*! \brief Get an element content string.
  *  \param node Node from where to get the string.
  *  \retval NULL on error.
  *  \retval The text content of node.
  */
-const char *ast_xml_get_text(ast_xml_node *node);
+const char *ast_xml_get_text(struct ast_xml_node *node);
+
+const char *ast_xml_node_get_name(struct ast_xml_node *node);
+
+struct ast_xml_node *ast_xml_node_get_children(struct ast_xml_node *node);
+
+struct ast_xml_node *ast_xml_node_get_next(struct ast_xml_node *node);
+
+struct ast_xml_node *ast_xml_node_get_prev(struct ast_xml_node *node);
+
+struct ast_xml_node *ast_xml_node_get_parent(struct ast_xml_node *node);
 
 /* Features using ast_xml_ */
 #define AST_XML_DOCS
 
-#endif /* AST_XML_H_IMPLEMENTATION */
-
 #endif /* _ASTERISK_XML_H */
 

Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=152437&r1=152436&r2=152437
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Tue Oct 28 13:22:23 2008
@@ -841,7 +841,7 @@
 /*! \brief XML documentation tree */
 struct documentation_tree {
 	char *filename;
-	ast_xml_doc *doc;
+	struct ast_xml_doc *doc;
 	AST_RWLIST_ENTRY(documentation_tree) entry;
 };
 
@@ -3514,9 +3514,9 @@
  *  \retval NULL on error.
  *  \retval A node of type ast_xml_node.
  */
-static ast_xml_node *xmldoc_get_node(const char *type, const char *name, const char *language)
-{
-	ast_xml_node *node = NULL;
+static struct ast_xml_node *xmldoc_get_node(const char *type, const char *name, const char *language)
+{
+	struct ast_xml_node *node = NULL;
 	struct documentation_tree *doctree;
 	const char *lang;
 
@@ -3535,15 +3535,15 @@
 			}
 		}
 
-		if (node && node->AST_XML_CHILD) {
+		if (node && ast_xml_node_get_children(node)) {
 			break;
 		}
 
 		/* We didn't find the application documentation for the specified language,
 		so, try to load documentation for any language */
 		node = ast_xml_get_root(doctree->doc);
-		if (node->AST_XML_CHILD) {
-			if ((node = ast_xml_find_element(node->AST_XML_CHILD, type, "name", name))) {
+		if (ast_xml_node_get_children(node)) {
+			if ((node = ast_xml_find_element(ast_xml_node_get_children(node), type, "name", name))) {
 				break;
 			}
 		}
@@ -3607,12 +3607,12 @@
  *  \retval 1 If a <argument> element is found inside 'node'.
  *  \retval 0 If no <argument> is found inside 'node'.
  */
-static int xmldoc_has_arguments(ast_xml_node *fixnode)
-{
-	ast_xml_node *node = fixnode;
-
-	for (node = fixnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (!strcasecmp((const char *) node->AST_XML_NAME, "argument")) {
+static int xmldoc_has_arguments(struct ast_xml_node *fixnode)
+{
+	struct ast_xml_node *node = fixnode;
+
+	for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) {
+		if (!strcasecmp(ast_xml_node_get_name(node), "argument")) {
 			return 1;
 		}
 	}
@@ -3628,12 +3628,12 @@
  *  \param printrootname Boolean if we must print the rootname before the syntax and parenthesis at the begining/end.
  *  \retval NULL on error.
  *  \retval An ast_malloc'ed string with the syntax generated. */
-static char *xmldoc_get_syntax(ast_xml_node *rootnode, const char *rootname, const char *childname, int printparenthesis, int printrootname)
-{
-#define GOTONEXT(__rev, __a) (__rev ? __a->AST_XML_PREV : __a->AST_XML_NEXT)
-#define ISLAST(__rev, __a)  (__rev == 1 ? (__a->AST_XML_PREV ? 0 : 1) : (__a->AST_XML_NEXT ? 0 : 1))
+static char *xmldoc_get_syntax(struct ast_xml_node *rootnode, const char *rootname, const char *childname, int printparenthesis, int printrootname)
+{
+#define GOTONEXT(__rev, __a) (__rev ? ast_xml_node_get_prev(__a) : ast_xml_node_get_next(__a))
+#define ISLAST(__rev, __a)  (__rev == 1 ? (ast_xml_node_get_prev(__a) ? 0 : 1) : (ast_xml_node_get_next(__a) ? 0 : 1))
 #define MP(__a) ((multiple ? __a : ""))
-	ast_xml_node *node = NULL, *firstparam = NULL, *lastparam = NULL;
+	struct ast_xml_node *node = NULL, *firstparam = NULL, *lastparam = NULL;
 	const char *paramtype, *multipletype, *paramname, *attrargsep;
 	int reverse, required, paramcount = 0, openbrackets = 0, len = 0, hasparams=0;
 	int reqfinode = 0, reqlanode = 0, optmidnode = 0;
@@ -3645,7 +3645,7 @@
 		return NULL;
 	}
 
-	if (!rootnode || !rootnode->AST_XML_CHILD) {
+	if (!rootnode || !ast_xml_node_get_children(rootnode)) {
 		/* If the rootnode field is not found, at least print name. */
 		ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : ""));
 		return syntax;
@@ -3662,8 +3662,8 @@
 	}
 
 	/* Get order of evaluation. */
-	for (node = rootnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (strcasecmp((const char *) node->AST_XML_NAME, childname)) {
+	for (node = ast_xml_node_get_children(rootnode); node; node = ast_xml_node_get_next(node)) {
+		if (strcasecmp(ast_xml_node_get_name(node), childname)) {
 			continue;
 		}
 		required = 0;
@@ -3693,8 +3693,8 @@
 
 	if (reqfinode && reqlanode) {
 		/* check midnode */
-		for (node = rootnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-			if (strcasecmp((const char *) node->AST_XML_NAME, childname)) {
+		for (node = ast_xml_node_get_children(rootnode); node; node = ast_xml_node_get_next(node)) {
+			if (strcasecmp(ast_xml_node_get_name(node), childname)) {
 				continue;
 			}
 			if (node != firstparam && node != lastparam) {
@@ -3725,7 +3725,7 @@
 	}
 
 	for (; node; node = GOTONEXT(reverse, node)) {
-		if (strcasecmp((const char *) node->AST_XML_NAME, childname)) {
+		if (strcasecmp(ast_xml_node_get_name(node), childname)) {
 			continue;
 		}
 
@@ -3843,7 +3843,7 @@
  */
 static char *xmldoc_build_syntax(const char *type, const char *name)
 {
-	ast_xml_node *node;
+	struct ast_xml_node *node;
 	char *syntax = NULL;
 
 	node = xmldoc_get_node(type, name, documentation_language);
@@ -3851,8 +3851,8 @@
 		return NULL;
 	}
 
-	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (!strcasecmp((const char *) node->AST_XML_NAME, "syntax")) {
+	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
+		if (!strcasecmp(ast_xml_node_get_name(node), "syntax")) {
 			break;
 		}
 	}
@@ -3875,18 +3875,18 @@
  *  \retval 2 If data is appended in buffer.
  *  \retval 0 on error.
  */
-static int xmldoc_parse_para(ast_xml_node *node, const char *tabs, const char *posttabs, struct ast_str **buffer)
+static int xmldoc_parse_para(struct ast_xml_node *node, const char *tabs, const char *posttabs, struct ast_str **buffer)
 {
 	const char *tmptext;
-	ast_xml_node *tmp;
+	struct ast_xml_node *tmp;
 	int ret = 0;
 	struct ast_str *tmpstr;
 
-	if (!node || !node->AST_XML_CHILD) {
+	if (!node || !ast_xml_node_get_children(node)) {
 		return ret;
 	}
 
-	if (strcasecmp((const char *) node->AST_XML_NAME, "para")) {
+	if (strcasecmp(ast_xml_node_get_name(node), "para")) {
 		return ret;
 	}
 
@@ -3894,7 +3894,7 @@
 
 	ret = 1;
 
-	for (tmp = node->AST_XML_CHILD; tmp; tmp = tmp->AST_XML_NEXT) {
+	for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) {
 		/* Get the text inside the <para> element and append it to buffer. */
 		tmptext = ast_xml_get_text(tmp);
 		if (tmptext) {
@@ -3902,8 +3902,9 @@
 			xmldoc_string_cleanup(tmptext, &tmpstr, 0);
 			ast_xml_free_text(tmptext);
 			if (tmpstr) {
-				if (strcasecmp((const char *) tmp->AST_XML_NAME, "text")) {
-					ast_str_append(buffer, 0, "<%s>%s</%s>", tmp->AST_XML_NAME, tmpstr->str, tmp->AST_XML_NAME);
+				if (strcasecmp(ast_xml_node_get_name(tmp), "text")) {
+					ast_str_append(buffer, 0, "<%s>%s</%s>", ast_xml_node_get_name(tmp), 
+							tmpstr->str, ast_xml_node_get_name(tmp));
 				} else {
 					ast_str_append(buffer, 0, "%s", tmpstr->str);
 				}
@@ -3928,17 +3929,17 @@
  *  \retval 1 if a special element is parsed (data is appended to buffer).
  *  \retval 2 if a special element is parsed and also a <para> element is parsed inside the specialtag.
  */
-static int xmldoc_parse_specialtags(ast_xml_node *fixnode, const char *tabs, const char *posttabs, struct ast_str **buffer)
-{
-	ast_xml_node *node = fixnode;
+static int xmldoc_parse_specialtags(struct ast_xml_node *fixnode, const char *tabs, const char *posttabs, struct ast_str **buffer)
+{
+	struct ast_xml_node *node = fixnode;
 	int ret = 0, i, count = 0;
 
-	if (!node || !node->AST_XML_CHILD) {
+	if (!node || !ast_xml_node_get_children(node)) {
 		return ret;
 	}
 
 	for (i = 0; i < ARRAY_LEN(special_tags); i++) {
-		if (strcasecmp((const char *) node->AST_XML_NAME, special_tags[i].tagname)) {
+		if (strcasecmp(ast_xml_node_get_name(node), special_tags[i].tagname)) {
 			continue;
 		}
 
@@ -3951,7 +3952,7 @@
 		}
 
 		/* parse <para> elements inside special tags. */
-		for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
+		for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
 			/* first <para> just print it without tabs at the begining. */
 			if (xmldoc_parse_para(node, (!count ? "" : tabs), posttabs, buffer) == 2) {
 				ret = 2;
@@ -3978,13 +3979,13 @@
  *  \retval 1 If there is content inside the argument.
  *  \retval 0 If the argument element is not parsed, or there is no content inside it.
  */
-static int xmldoc_parse_argument(ast_xml_node *fixnode, int insideparameter, const char *paramtabs, const char *tabs, struct ast_str **buffer)
-{
-	ast_xml_node *node = fixnode;
+static int xmldoc_parse_argument(struct ast_xml_node *fixnode, int insideparameter, const char *paramtabs, const char *tabs, struct ast_str **buffer)
+{
+	struct ast_xml_node *node = fixnode;
 	const char *argname;
 	int count=0, ret = 0;
 
-	if (!node || !node->AST_XML_CHILD) {
+	if (!node || !ast_xml_node_get_children(node)) {
 		return ret;
 	}
 
@@ -3996,7 +3997,7 @@
 	ast_str_append(buffer, 0, "%s%s%s", tabs, argname, (insideparameter ? "\n" : ""));
 	ast_xml_free_attr(argname);
 
-	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
+	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
 		if (xmldoc_parse_para(node, (insideparameter ? paramtabs : (!count ? " - " : tabs)), "\n", buffer) == 2) {
 			count++;
 			ret = 1;
@@ -4020,15 +4021,15 @@
  *  \retval 0 if no data is appended.
  *  \retval 1 if data is appended.
  */
-static int xmldoc_parse_variable(ast_xml_node *node, const char *tabs, struct ast_str **buffer)
-{
-	ast_xml_node *tmp;
+static int xmldoc_parse_variable(struct ast_xml_node *node, const char *tabs, struct ast_str **buffer)
+{
+	struct ast_xml_node *tmp;
 	const char *valname;
 	const char *tmptext;
 	struct ast_str *cleanstr;
 	int ret = 0, printedpara=0;
 
-	for (tmp = node->AST_XML_CHILD; tmp; tmp = tmp->AST_XML_NEXT) {
+	for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) {
 		if (xmldoc_parse_para(tmp, (ret ? tabs : ""), "\n", buffer)) {
 			printedpara = 1;
 			continue;
@@ -4037,7 +4038,7 @@
 			continue;
 		}
 
-		if (strcasecmp((const char *) tmp->AST_XML_NAME, "value")) {
+		if (strcasecmp(ast_xml_node_get_name(tmp), "value")) {
 			continue;
 		}
 
@@ -4081,18 +4082,18 @@
  *  \retval 1 If a <variablelist> element is parsed.
  *  \retval 0 On error.
  */
-static int xmldoc_parse_variablelist(ast_xml_node *node, const char *tabs, struct ast_str **buffer)
-{
-	ast_xml_node *tmp;
+static int xmldoc_parse_variablelist(struct ast_xml_node *node, const char *tabs, struct ast_str **buffer)
+{
+	struct ast_xml_node *tmp;
 	const char *varname;
 	char *vartabs;
 	int ret = 0;
 
-	if (!node || !node->AST_XML_CHILD) {
+	if (!node || !ast_xml_node_get_children(node)) {
 		return ret;
 	}
 
-	if (strcasecmp((const char *) node->AST_XML_NAME, "variablelist")) {
+	if (strcasecmp(ast_xml_node_get_name(node), "variablelist")) {
 		return ret;
 	}
 
@@ -4101,7 +4102,7 @@
 	if (!vartabs) {
 		return ret;
 	}
-	for (tmp = node->AST_XML_CHILD; tmp; tmp = tmp->AST_XML_NEXT) {
+	for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) {
 		/* We can have a <para> element inside the variable list */
 		if ((xmldoc_parse_para(tmp, (ret ? tabs : ""), "\n", buffer))) {
 			ret = 1;
@@ -4111,7 +4112,7 @@
 			continue;
 		}
 
-		if (!strcasecmp((const char *) tmp->AST_XML_NAME, "variable")) {
+		if (!strcasecmp(ast_xml_node_get_name(tmp), "variable")) {
 			/* Store the variable name in buffer. */
 			varname = ast_xml_get_attribute(tmp, "name");
 			if (varname) {
@@ -4140,7 +4141,7 @@
 {
 	struct ast_str *outputstr;
 	char *output;
-	ast_xml_node *node;
+	struct ast_xml_node *node;
 	const char *typename;
 	const char *content;
 
@@ -4150,18 +4151,18 @@
 
 	/* get the application/function root node. */
 	node = xmldoc_get_node(type, name, documentation_language);
-	if (!node || !node->AST_XML_CHILD) {
+	if (!node || !ast_xml_node_get_children(node)) {
 		return NULL;
 	}
 
 	/* Find the <see-also> node. */
-	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (!strcasecmp((const char *) node->AST_XML_NAME, "see-also")) {
+	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
+		if (!strcasecmp(ast_xml_node_get_name(node), "see-also")) {
 			break;
 		}
 	}
 
-	if (!node || !node->AST_XML_CHILD) {
+	if (!node || !ast_xml_node_get_children(node)) {
 		/* we couldnt find a <see-also> node. */
 		return NULL;
 	}
@@ -4173,8 +4174,8 @@
 	}
 
 	/* get into the <see-also> node. */
-	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (strcasecmp((const char *) node->AST_XML_NAME, "ref")) {
+	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
+		if (strcasecmp(ast_xml_node_get_name(node), "ref")) {
 			continue;
 		}
 
@@ -4214,12 +4215,12 @@
  *  \retval 0 if content is not found inside the enum element (data is not appended to buffer).
  *  \retval 1 if content is found and data is appended to buffer.
  */
-static int xmldoc_parse_enum(ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
-{
-	ast_xml_node *node = fixnode;
+static int xmldoc_parse_enum(struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
+{
+	struct ast_xml_node *node = fixnode;
 	int ret = 0;
 
-	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
+	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
 		if ((xmldoc_parse_para(node, (ret ? tabs : " - "), "\n", buffer))) {
 			ret = 1;
 		} else if ((xmldoc_parse_specialtags(node, (ret ? tabs : " - "), "\n", buffer))) {
@@ -4236,14 +4237,14 @@
  *  \retval 0 if no <enumlist> node was parsed.
  *  \retval 1 if a <enumlist> node was parsed.
  */
-static int xmldoc_parse_enumlist(ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
-{
-	ast_xml_node *node = fixnode;
+static int xmldoc_parse_enumlist(struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
+{
+	struct ast_xml_node *node = fixnode;
 	const char *enumname;
 	int ret = 0;
 
-	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (strcasecmp((const char *) node->AST_XML_NAME, "enum")) {
+	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
+		if (strcasecmp(ast_xml_node_get_name(node), "enum")) {
 			continue;
 		}
 
@@ -4272,9 +4273,9 @@
  *  \retval 0 if no option node is parsed.
  *  \retval 1 if an option node is parsed.
  */
-static int xmldoc_parse_option(ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
-{
-	ast_xml_node *node;
+static int xmldoc_parse_option(struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
+{
+	struct ast_xml_node *node;
 	int ret = 0;
 	char *optiontabs;
 
@@ -4282,10 +4283,10 @@
 	if (!optiontabs) {
 		return ret;
 	}
-	for (node = fixnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (!strcasecmp((const char *) node->AST_XML_NAME, "argument")) {
+	for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) {
+		if (!strcasecmp(ast_xml_node_get_name(node), "argument")) {
 			/* if this is the first data appended to buffer, print a \n*/
-			if (!ret && node->AST_XML_CHILD) {
+			if (!ret && ast_xml_node_get_children(node)) {
 				/* print \n */
 				ast_str_append(buffer, 0, "\n");
 			}
@@ -4317,15 +4318,15 @@
  *              buffer string.
  *  \param buffer Output buffer to put what is inside the optionlist tag.
  */
-static void xmldoc_parse_optionlist(ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
-{
-	ast_xml_node *node;
+static void xmldoc_parse_optionlist(struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
+{
+	struct ast_xml_node *node;
 	const char *optname;
 	char *optionsyntax;
 
-	for (node = fixnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
+	for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) {
 		/* Start appending every option tag. */
-		if (strcasecmp((const char *) node->AST_XML_NAME, "option")) {
+		if (strcasecmp(ast_xml_node_get_name(node), "option")) {
 			continue;
 		}
 
@@ -4355,14 +4356,14 @@
  *              'buffer'.
  *  \param buffer String buffer to put values found inside the parameter element.
  */
-static void xmldoc_parse_parameter(ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
+static void xmldoc_parse_parameter(struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
 {
 	const char *paramname;
-	ast_xml_node *node = fixnode;
+	struct ast_xml_node *node = fixnode;
 	int hasarguments, printed = 0;
 	char *internaltabs;
 
-	if (strcasecmp((const char *) node->AST_XML_NAME, "parameter")) {
+	if (strcasecmp(ast_xml_node_get_name(node), "parameter")) {
 		return;
 	}
 
@@ -4383,14 +4384,14 @@
 		printed = 1;
 	}
 
-	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (!strcasecmp((const char *) node->AST_XML_NAME, "optionlist")) {
+	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
+		if (!strcasecmp(ast_xml_node_get_name(node), "optionlist")) {
 			xmldoc_parse_optionlist(node, internaltabs, buffer);
-		} else if (!strcasecmp((const char *) node->AST_XML_NAME, "enumlist")) {
+		} else if (!strcasecmp(ast_xml_node_get_name(node), "enumlist")) {
 			xmldoc_parse_enumlist(node, internaltabs, buffer);
-		} else if (!strcasecmp((const char *) node->AST_XML_NAME, "argument")) {
+		} else if (!strcasecmp(ast_xml_node_get_name(node), "argument")) {
 			xmldoc_parse_argument(node, 1, internaltabs, (!hasarguments ? "        " : ""), buffer);
-		} else if (!strcasecmp((const char *) node->AST_XML_NAME, "para")) {
+		} else if (!strcasecmp(ast_xml_node_get_name(node), "para")) {
 			if (!printed) {
 				ast_str_append(buffer, 0, "%s\n", paramname);
 				ast_xml_free_attr(paramname);
@@ -4415,7 +4416,7 @@
  */
 static char *xmldoc_build_arguments(const char *type, const char *name)
 {
-	ast_xml_node *node;
+	struct ast_xml_node *node;
 	struct ast_str *ret = ast_str_create(128);
 	char *retstr = NULL;
 
@@ -4425,23 +4426,23 @@
 
 	node = xmldoc_get_node(type, name, documentation_language);
 
-	if (!node || !node->AST_XML_CHILD) {
+	if (!node || !ast_xml_node_get_children(node)) {
 		return NULL;
 	}
 
 	/* Find the syntax field. */
-	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (!strcasecmp((const char *) node->AST_XML_NAME, "syntax")) {
+	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
+		if (!strcasecmp(ast_xml_node_get_name(node), "syntax")) {
 			break;
 		}
 	}
 
-	if (!node || !node->AST_XML_CHILD) {
+	if (!node || !ast_xml_node_get_children(node)) {
 		/* We couldn't find the syntax node. */
 		return NULL;
 	}
 
-	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
+	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
 		xmldoc_parse_parameter(node, "", &ret);
 	}
 
@@ -4466,9 +4467,9 @@
  *  \retval NULL on error
  *  \retval Node content on success.
  */
-static struct ast_str *xmldoc_get_formatted(ast_xml_node *node, int raw_output, int raw_wrap)
-{
-	ast_xml_node *tmp;
+static struct ast_str *xmldoc_get_formatted(struct ast_xml_node *node, int raw_output, int raw_wrap)
+{
+	struct ast_xml_node *tmp;
 	const char *notcleanret, *tmpstr;
 	struct ast_str *ret = ast_str_create(128);
 
@@ -4478,7 +4479,7 @@
 		xmldoc_string_cleanup(ast_skip_blanks(notcleanret), &ret, 0);
 		ast_xml_free_text(tmpstr);
 	} else {
-		for (tmp = node->AST_XML_CHILD; tmp; tmp = tmp->AST_XML_NEXT) {
+		for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) {
 			/* if found, parse a <para> element. */
 			if (xmldoc_parse_para(tmp, "", "\n", &ret)) {
 				continue;
@@ -4510,7 +4511,7 @@
  */
 static char *xmldoc_build_field(const char *type, const char *name, const char *var, int raw)
 {
-	ast_xml_node *node;
+	struct ast_xml_node *node;
 	char *ret = NULL;
 	struct ast_str *formatted;
 
@@ -4526,9 +4527,9 @@
 		return ret;
 	}
 
-	node = ast_xml_find_element(node->AST_XML_CHILD, var, NULL, NULL);
-
-	if (!node || !node->AST_XML_CHILD) {
+	node = ast_xml_find_element(ast_xml_node_get_children(node), var, NULL, NULL);
+
+	if (!node || !ast_xml_node_get_children(node)) {
 		ast_log(LOG_DEBUG, "Cannot find variable '%s' in tree '%s'\n", name, var);
 		return ret;
 	}
@@ -6395,8 +6396,8 @@
 
 int ast_load_documentation(void)
 {
-	ast_xml_node *root_node;
-	ast_xml_doc *tmpdoc;
+	struct ast_xml_node *root_node;
+	struct ast_xml_doc *tmpdoc;
 	struct documentation_tree *doc_tree;
 	char *xmlpattern;
 	struct ast_config *cfg = NULL;
@@ -6471,7 +6472,7 @@
 			continue;
 		}
 		/* Check root node name for malformed xmls. */
-		if (strcmp((const char *)root_node->AST_XML_NAME, "docs")) {
+		if (strcmp(ast_xml_node_get_name(root_node), "docs")) {
 			ast_log(LOG_ERROR, "Documentation file is not well formed!\n");
 			ast_xml_close(tmpdoc);
 			continue;

Modified: team/group/appdocsxml/main/xml.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/xml.c?view=diff&rev=152437&r1=152436&r2=152437
==============================================================================
--- team/group/appdocsxml/main/xml.c (original)
+++ team/group/appdocsxml/main/xml.c Tue Oct 28 13:22:23 2008
@@ -26,7 +26,10 @@
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
-#if defined(HAVE_LIBXML2) && !defined(AST_XML_IMPLEMENTATION)
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+#if defined(HAVE_LIBXML2)
 #define AST_XML_IMPLEMENTATION
 /* libxml2 ast_xml implementation. */
 
@@ -45,7 +48,7 @@
 	return 0;
 }
 
-ast_xml_doc *ast_xml_open(char *filename)
+struct ast_xml_doc *ast_xml_open(char *filename)
 {
 	xmlDoc *doc;
 
@@ -55,22 +58,22 @@
 
 	doc = xmlReadFile(filename, NULL, XML_PARSE_RECOVER);
 
-	return doc;
+	return (struct ast_xml_doc *) doc;
 }
 
 
-void ast_xml_close(ast_xml_doc *doc)
+void ast_xml_close(struct ast_xml_doc *doc)
 {
 	if (!doc) {
 		return;
 	}
 
-	xmlFreeDoc(doc);
+	xmlFreeDoc((xmlDoc *) doc);
 	doc = NULL;
 }
 
 
-ast_xml_node *ast_xml_get_root(ast_xml_doc *doc)
+struct ast_xml_node *ast_xml_get_root(struct ast_xml_doc *doc)
 {
 	xmlNode *root_node;
 
@@ -78,18 +81,18 @@
 		return NULL;
 	}
 
-	root_node = xmlDocGetRootElement(doc);
+	root_node = xmlDocGetRootElement((xmlDoc *) doc);
 
-	return root_node;
+	return (struct ast_xml_node *) root_node;
 }
 
-void ast_xml_free_node(ast_xml_node *node)
+void ast_xml_free_node(struct ast_xml_node *node)
 {
 	if (!node) {
 		return;
 	}
 
-	xmlFreeNode(node);
+	xmlFreeNode((xmlNode *) node);
 	node = NULL;
 }
 
@@ -107,7 +110,7 @@
 	}
 }
 
-const char *ast_xml_get_attribute(ast_xml_node *node, const char *attrname)
+const char *ast_xml_get_attribute(struct ast_xml_node *node, const char *attrname)
 {
 	xmlChar *attrvalue;
 
@@ -119,23 +122,23 @@
 		return NULL;
 	}
 
-	attrvalue = xmlGetProp(node, (xmlChar *)attrname);
+	attrvalue = xmlGetProp((xmlNode *) node, (xmlChar *) attrname);
 
 	return (const char *) attrvalue;
 }
 
-ast_xml_node *ast_xml_find_element(ast_xml_node *root_node, const char *name, const char *attrname, const char *attrvalue)
+struct ast_xml_node *ast_xml_find_element(struct ast_xml_node *root_node, const char *name, const char *attrname, const char *attrvalue)
 {
-	xmlNodePtr cur;
+	struct ast_xml_node *cur;
 	const char *attr;
 
 	if (!root_node) {
 		return NULL;
 	}
 
-	for (cur = root_node; cur; cur = cur->next) {
+	for (cur = root_node; cur; ast_xml_node_get_next(cur)) {
 		/* Check if the name matchs */
-		if (strcmp((const char *) cur->name, name)) {
+		if (strcmp(ast_xml_node_get_name(cur), name)) {
 			continue;
 		}
 		/* We need to check for a specific attribute name? */
@@ -156,14 +159,39 @@
 	return NULL;
 }
 
-const char *ast_xml_get_text(ast_xml_node *node)
+const char *ast_xml_get_text(struct ast_xml_node *node)
 {
 	if (!node) {
 		return NULL;
 	}
 
-	return (const char *) xmlNodeGetContent(node);
+	return (const char *) xmlNodeGetContent((xmlNode *) node);
 }
 
-#endif /* defined(HAVE_LIBXML2) && !defined(AST_XML_IMPLEMENTATION) */
+const char *ast_xml_node_get_name(struct ast_xml_node *node)
+{
+	return (const char *) ((xmlNode *) node)->name;
+}
 
+struct ast_xml_node *ast_xml_node_get_children(struct ast_xml_node *node)
+{
+	return (struct ast_xml_node *) ((xmlNode *) node)->children;
+}
+
+struct ast_xml_node *ast_xml_node_get_next(struct ast_xml_node *node)
+{
+	return (struct ast_xml_node *) ((xmlNode *) node)->next;
+}
+
+struct ast_xml_node *ast_xml_node_get_prev(struct ast_xml_node *node)
+{
+	return (struct ast_xml_node *) ((xmlNode *) node)->prev;
+}
+
+struct ast_xml_node *ast_xml_node_get_parent(struct ast_xml_node *node)
+{
+	return (struct ast_xml_node *) ((xmlNode *) node)->parent;
+}
+
+#endif /* defined(HAVE_LIBXML2) */
+




More information about the svn-commits mailing list