diff options
author | Eliel C. Sardanons <eliels@gmail.com> | 2008-12-08 04:23:50 +0000 |
---|---|---|
committer | Eliel C. Sardanons <eliels@gmail.com> | 2008-12-08 04:23:50 +0000 |
commit | bc0332325101252fefb52aed89d72aa453366a67 (patch) | |
tree | 0673bdd734a62ab245e05852f8a613bd3dedd8a7 | |
parent | 5e9dc5e1f3f7c212cafb60f19704a264bd34e0d9 (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: https://origsvn.digium.com/svn/asterisk/trunk@161637 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r-- | main/xmldoc.c | 57 |
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); } |