From 2e508d0b567a21a8ad8ae011c5478ab8c971d2f9 Mon Sep 17 00:00:00 2001 From: eliel Date: Mon, 8 Dec 2008 04:23:50 +0000 Subject: - 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 --- main/xmldoc.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) (limited to 'main/xmldoc.c') 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 element is found inside 'node'. - * \retval 0 If no 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) { @@ -568,6 +568,45 @@ static int xmldoc_has_inside(struct ast_xml_node *fixnode, const char *what) 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; +} + /*! \internal * \brief Build the syntax for a specified starting node. * \param rootnode A pointer to the ast_xml root node. @@ -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); } -- cgit v1.2.3