aboutsummaryrefslogtreecommitdiffstats
path: root/main/xmldoc.c
diff options
context:
space:
mode:
authoreliel <eliel@f38db490-d61c-443f-a65b-d21fe96a405b>2008-12-08 04:23:50 +0000
committereliel <eliel@f38db490-d61c-443f-a65b-d21fe96a405b>2008-12-08 04:23:50 +0000
commit2e508d0b567a21a8ad8ae011c5478ab8c971d2f9 (patch)
tree0673bdd734a62ab245e05852f8a613bd3dedd8a7 /main/xmldoc.c
parente4b32ccc0050638b086106e53c0f329ca57a0eae (diff)
- 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. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@161637 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/xmldoc.c')
-rw-r--r--main/xmldoc.c57
1 files changed, 52 insertions, 5 deletions
diff --git a/main/xmldoc.c b/main/xmldoc.c
index 55b61ed77..3185a3a56 100644
--- a/main/xmldoc.c
+++ b/main/xmldoc.c
@@ -553,8 +553,8 @@ static void __attribute__((format(printf, 4, 5))) xmldoc_reverse_helper(int reve
* \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)
{
@@ -569,6 +569,45 @@ static int xmldoc_has_inside(struct ast_xml_node *fixnode, const char *what)
}
/*! \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;
+}
+
+/*! \internal
* \brief Build the syntax for a specified starting node.
* \param rootnode A pointer to the ast_xml root node.
* \param rootname Name of the application, function, option, etc. to build the syntax.
@@ -1135,8 +1174,13 @@ static int xmldoc_parse_argument(struct ast_xml_node *fixnode, int insideparamet
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 @@ static void xmldoc_parse_parameter(struct ast_xml_node *fixnode, const char *tab
return;
}
- if (!hasarguments) {
+ if (!hasarguments && xmldoc_has_nodes(node)) {
ast_str_append(buffer, 0, "%s\n", paramname);
ast_xml_free_attr(paramname);
printed = 1;
@@ -1549,6 +1593,9 @@ static void xmldoc_parse_parameter(struct ast_xml_node *fixnode, const char *tab
continue;
}
}
+ if (!printed) {
+ ast_xml_free_attr(paramname);
+ }
ast_free(internaltabs);
}