[asterisk-commits] eliel: trunk r161637 - /trunk/main/xmldoc.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Dec 7 22:23:52 CST 2008


Author: eliel
Date: Sun Dec  7 22:23:50 2008
New Revision: 161637

URL: http://svn.digium.com/view/asterisk?view=rev&rev=161637
Log:
- Fix a leak while printing an argument description.
- Avoid printing the name of an argument in the [Arguments] tag if there is no description
  for that argument.

Modified:
    trunk/main/xmldoc.c

Modified: trunk/main/xmldoc.c
URL: http://svn.digium.com/view/asterisk/trunk/main/xmldoc.c?view=diff&rev=161637&r1=161636&r2=161637
==============================================================================
--- trunk/main/xmldoc.c (original)
+++ trunk/main/xmldoc.c Sun Dec  7 22:23:50 2008
@@ -553,8 +553,8 @@
  *  \brief Check if the passed node has 'what' tags inside it.
  *  \param node Root node to search 'what' elements.
  *  \param what node name to search inside node.
- *  \retval 1 If a <argument> element is found inside 'node'.
- *  \retval 0 If no <argument> is found inside 'node'.
+ *  \retval 1 If a 'what' element is found inside 'node'.
+ *  \retval 0 If no 'what' is found inside 'node'.
  */
 static int xmldoc_has_inside(struct ast_xml_node *fixnode, const char *what)
 {
@@ -563,6 +563,45 @@
 	for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) {
 		if (!strcasecmp(ast_xml_node_get_name(node), what)) {
 			return 1;
+		}
+	}
+	return 0;
+}
+
+/*! \internal
+ *  \brief Check if the passed node has at least one node inside it.
+ *  \param node Root node to search node elements.
+ *  \retval 1 If a node element is found inside 'node'.
+ *  \retval 0 If no node is found inside 'node'.
+ */
+static int xmldoc_has_nodes(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), "text")) {
+			return 1;
+		}
+	}
+	return 0;
+}
+
+/*! \internal
+ *  \brief Check if the passed node has at least one specialtag.
+ *  \param node Root node to search "specialtags" elements.
+ *  \retval 1 If a "specialtag" element is found inside 'node'.
+ *  \retval 0 If no "specialtag" is found inside 'node'.
+ */
+static int xmldoc_has_specialtags(struct ast_xml_node *fixnode)
+{
+	struct ast_xml_node *node = fixnode;
+	int i;
+
+	for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) {
+		for (i = 0; i < ARRAY_LEN(special_tags); i++) {
+			if (!strcasecmp(ast_xml_node_get_name(node), special_tags[i].tagname)) {
+				return 1;
+			}
 		}
 	}
 	return 0;
@@ -1135,8 +1174,13 @@
 	if (!argname) {
 		return 0;
 	}
-	ast_str_append(buffer, 0, "%s%s%s", tabs, argname, (insideparameter ? "\n" : ""));
-	ast_xml_free_attr(argname);
+	if (xmldoc_has_inside(node, "para") || xmldoc_has_specialtags(node)) {
+		ast_str_append(buffer, 0, "%s%s%s", tabs, argname, (insideparameter ? "\n" : ""));
+		ast_xml_free_attr(argname);
+	} else {
+		ast_xml_free_attr(argname);
+		return 0;
+	}
 
 	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) {
@@ -1524,7 +1568,7 @@
 		return;
 	}
 
-	if (!hasarguments) {
+	if (!hasarguments && xmldoc_has_nodes(node)) {
 		ast_str_append(buffer, 0, "%s\n", paramname);
 		ast_xml_free_attr(paramname);
 		printed = 1;
@@ -1548,6 +1592,9 @@
 		} else if ((xmldoc_parse_specialtags(node, internaltabs, "\n", buffer))) {
 			continue;
 		}
+	}
+	if (!printed) {
+		ast_xml_free_attr(paramname);
 	}
 	ast_free(internaltabs);
 }




More information about the asterisk-commits mailing list