| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2008, Eliel C. Sardanons (LU1ALY) <eliels@gmail.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							|  |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \file
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \brief XML Documentation API | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \author Eliel C. Sardanons (LU1ALY) <eliels@gmail.com> | 
					
						
							| 
									
										
										
										
											2009-04-14 14:20:10 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-09-21 17:14:59 +00:00
										 |  |  |  * libxml2 http://www.xmlsoft.org/
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-15 16:20:16 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<support_level>core</support_level> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk/_private.h"
 | 
					
						
							|  |  |  | #include "asterisk/paths.h"
 | 
					
						
							|  |  |  | #include "asterisk/linkedlists.h"
 | 
					
						
							|  |  |  | #include "asterisk/config.h"
 | 
					
						
							|  |  |  | #include "asterisk/term.h"
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | #include "asterisk/astobj2.h"
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | #include "asterisk/xmldoc.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | #include "asterisk/cli.h"
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef AST_XML_DOCS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \brief Default documentation language. */ | 
					
						
							|  |  |  | static const char default_documentation_language[] = "en_US"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-06 14:36:40 +01:00
										 |  |  | /*! \brief Number of columns to print when showing the XML documentation with a
 | 
					
						
							|  |  |  |  *         'core show application/function *' CLI command. Used in text wrapping.*/ | 
					
						
							|  |  |  | static const int xmldoc_text_columns = 79; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*! \brief XML documentation language. */ | 
					
						
							|  |  |  | static char documentation_language[6]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \brief XML documentation tree */ | 
					
						
							|  |  |  | struct documentation_tree { | 
					
						
							|  |  |  | 	char *filename;					/*!< XML document filename. */ | 
					
						
							|  |  |  | 	struct ast_xml_doc *doc;			/*!< Open document pointer. */ | 
					
						
							|  |  |  | 	AST_RWLIST_ENTRY(documentation_tree) entry; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | static char *xmldoc_get_syntax_cmd(struct ast_xml_node *fixnode, const char *name, int printname); | 
					
						
							| 
									
										
										
										
											2009-05-15 13:23:37 +00:00
										 |  |  | static int xmldoc_parse_enumlist(struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer); | 
					
						
							| 
									
										
										
										
											2013-12-11 13:06:30 +00:00
										 |  |  | static void xmldoc_parse_parameter(struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer); | 
					
						
							| 
									
										
										
										
											2012-07-19 22:17:13 +00:00
										 |  |  | static int xmldoc_parse_info(struct 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); | 
					
						
							|  |  |  | static int xmldoc_parse_specialtags(struct ast_xml_node *fixnode, const char *tabs, const char *posttabs, struct ast_str **buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Container of documentation trees | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note A RWLIST is a sufficient container type to use here for now. | 
					
						
							|  |  |  |  *       However, some changes will need to be made to implement ref counting | 
					
						
							|  |  |  |  *       if reload support is added in the future. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static AST_RWLIST_HEAD_STATIC(xmldoc_tree, documentation_tree); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct strcolorized_tags { | 
					
						
							|  |  |  | 	const char *init;      /*!< Replace initial tag with this string. */ | 
					
						
							|  |  |  | 	const char *end;       /*!< Replace end tag with this string. */ | 
					
						
							|  |  |  | 	const int colorfg;     /*!< Foreground color. */ | 
					
						
							|  |  |  | 	const char *inittag;   /*!< Initial tag description. */ | 
					
						
							|  |  |  | 	const char *endtag;    /*!< Ending tag description. */ | 
					
						
							|  |  |  | } colorized_tags[] = { | 
					
						
							|  |  |  | 	{ "<",  ">",  COLOR_GREEN,  "<replaceable>", "</replaceable>" }, | 
					
						
							|  |  |  | 	{ "\'", "\'", COLOR_BLUE,   "<literal>",     "</literal>" }, | 
					
						
							|  |  |  | 	{ "*",  "*",  COLOR_RED,    "<emphasis>",    "</emphasis>" }, | 
					
						
							|  |  |  | 	{ "\"", "\"", COLOR_YELLOW, "<filename>",    "</filename>" }, | 
					
						
							|  |  |  | 	{ "\"", "\"", COLOR_CYAN,   "<directory>",   "</directory>" }, | 
					
						
							|  |  |  | 	{ "${", "}",  COLOR_GREEN,  "<variable>",    "</variable>" }, | 
					
						
							|  |  |  | 	{ "",   "",   COLOR_BLUE,   "<value>",       "</value>" }, | 
					
						
							|  |  |  | 	{ "",   "",   COLOR_BLUE,   "<enum>",        "</enum>" }, | 
					
						
							|  |  |  | 	{ "\'", "\'", COLOR_GRAY,   "<astcli>",      "</astcli>" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Special tags */ | 
					
						
							|  |  |  | 	{ "", "", COLOR_YELLOW, "<note>",   "</note>" }, | 
					
						
							| 
									
										
										
										
											2014-07-31 11:49:40 +00:00
										 |  |  | 	{ "", "", COLOR_RED,   "<warning>", "</warning>" }, | 
					
						
							|  |  |  | 	{ "", "", COLOR_WHITE, "<example>", "</example>" }, | 
					
						
							|  |  |  | 	{ "", "", COLOR_GRAY, "<exampletext>", "</exampletext>"}, | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct strspecial_tags { | 
					
						
							|  |  |  | 	const char *tagname;		/*!< Special tag name. */ | 
					
						
							|  |  |  | 	const char *init;		/*!< Print this at the beginning. */ | 
					
						
							|  |  |  | 	const char *end;		/*!< Print this at the end. */ | 
					
						
							|  |  |  | } special_tags[] = { | 
					
						
							|  |  |  | 	{ "note",    "<note>NOTE:</note> ",             "" }, | 
					
						
							| 
									
										
										
										
											2014-07-31 11:49:40 +00:00
										 |  |  | 	{ "warning", "<warning>WARNING!!!:</warning> ", "" }, | 
					
						
							|  |  |  | 	{ "example", "<example>Example:</example> ", "" }, | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Calculate the space in bytes used by a format string | 
					
						
							|  |  |  |  *        that will be passed to a sprintf function. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param postbr The format string to use to calculate the length. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval The postbr length. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static int xmldoc_postbrlen(const char *postbr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int postbrreallen = 0, i; | 
					
						
							|  |  |  | 	size_t postbrlen; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!postbr) { | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	postbrlen = strlen(postbr); | 
					
						
							|  |  |  | 	for (i = 0; i < postbrlen; i++) { | 
					
						
							|  |  |  | 		if (postbr[i] == '\t') { | 
					
						
							|  |  |  | 			postbrreallen += 8 - (postbrreallen % 8); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			postbrreallen++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return postbrreallen; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Setup postbr to be used while wrapping the text. | 
					
						
							|  |  |  |  *        Add to postbr array all the spaces and tabs at the beginning of text. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param postbr output array. | 
					
						
							|  |  |  |  * \param len text array length. | 
					
						
							|  |  |  |  * \param text Text with format string before the actual string. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static void xmldoc_setpostbr(char *postbr, size_t len, const char *text) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int c, postbrlen = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!text) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (c = 0; c < len; c++) { | 
					
						
							|  |  |  | 		if (text[c] == '\t' || text[c] == ' ') { | 
					
						
							|  |  |  | 			postbr[postbrlen++] = text[c]; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	postbr[postbrlen] = '\0'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Justify a text to a number of columns. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param text Input text to be justified. | 
					
						
							|  |  |  |  * \param columns Number of columns to preserve in the text. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval NULL on error. | 
					
						
							|  |  |  |  * \retval The wrapped text. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-11-06 14:36:40 +01:00
										 |  |  | static char *xmldoc_string_wrap(const char *text, int columns) | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ast_str *tmp; | 
					
						
							|  |  |  | 	char *ret, postbr[160]; | 
					
						
							| 
									
										
										
										
											2015-11-06 14:36:40 +01:00
										 |  |  | 	int count, i, textlen, postbrlen, lastbreak; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* sanity check */ | 
					
						
							| 
									
										
										
										
											2015-11-06 14:36:40 +01:00
										 |  |  | 	if (!text || columns <= 0) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Passing wrong arguments while trying to wrap the text\n"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tmp = ast_str_create(strlen(text) * 3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!tmp) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Check for blanks and tabs and put them in postbr. */ | 
					
						
							|  |  |  | 	xmldoc_setpostbr(postbr, sizeof(postbr), text); | 
					
						
							| 
									
										
										
										
											2015-11-06 14:36:40 +01:00
										 |  |  | 	postbrlen = xmldoc_postbrlen(postbr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	count = 0; | 
					
						
							|  |  |  | 	lastbreak = 0; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	textlen = strlen(text); | 
					
						
							|  |  |  | 	for (i = 0; i < textlen; i++) { | 
					
						
							|  |  |  | 		if (text[i] == '\n') { | 
					
						
							|  |  |  | 			xmldoc_setpostbr(postbr, sizeof(postbr), &text[i] + 1); | 
					
						
							| 
									
										
										
										
											2015-11-06 14:36:40 +01:00
										 |  |  | 			postbrlen = xmldoc_postbrlen(postbr); | 
					
						
							|  |  |  | 			count = 0; | 
					
						
							|  |  |  | 			lastbreak = 0; | 
					
						
							|  |  |  | 		} else if (text[i] == ESC) { | 
					
						
							|  |  |  | 			/* Walk over escape sequences without counting them. */ | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			do { | 
					
						
							|  |  |  | 				ast_str_append(&tmp, 0, "%c", text[i]); | 
					
						
							|  |  |  | 				i++; | 
					
						
							|  |  |  | 			} while (i < textlen && text[i] != 'm'); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2015-11-06 14:36:40 +01:00
										 |  |  | 			if (text[i] == ' ') { | 
					
						
							|  |  |  | 				lastbreak = i; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			count++; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-11-06 14:36:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (count > columns) { | 
					
						
							|  |  |  | 			/* Seek backwards if it was at most 30 characters ago. */ | 
					
						
							|  |  |  | 			int back = i - lastbreak; | 
					
						
							|  |  |  | 			if (lastbreak && back > 0 && back < 30) { | 
					
						
							|  |  |  | 				ast_str_truncate(tmp, -back); | 
					
						
							|  |  |  | 				i = lastbreak; /* go back a bit */ | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			ast_str_append(&tmp, 0, "\n%s", postbr); | 
					
						
							|  |  |  | 			count = postbrlen; | 
					
						
							|  |  |  | 			lastbreak = 0; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			ast_str_append(&tmp, 0, "%c", text[i]); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 	ret = ast_strdup(ast_str_buffer(tmp)); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	ast_free(tmp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | char *ast_xmldoc_printable(const char *bwinput, int withcolors) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_str *colorized; | 
					
						
							|  |  |  | 	char *wrapped = NULL; | 
					
						
							|  |  |  | 	int i, c, len, colorsection; | 
					
						
							|  |  |  | 	char *tmp; | 
					
						
							|  |  |  | 	size_t bwinputlen; | 
					
						
							|  |  |  | 	static const int base_fg = COLOR_CYAN; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!bwinput) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bwinputlen = strlen(bwinput); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(colorized = ast_str_create(256))) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (withcolors) { | 
					
						
							|  |  |  | 		ast_term_color_code(&colorized, base_fg, 0); | 
					
						
							|  |  |  | 		if (!colorized) { | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < bwinputlen; i++) { | 
					
						
							|  |  |  | 		colorsection = 0; | 
					
						
							|  |  |  | 		/* Check if we are at the beginning of a tag to be colorized. */ | 
					
						
							|  |  |  | 		for (c = 0; c < ARRAY_LEN(colorized_tags); c++) { | 
					
						
							|  |  |  | 			if (strncasecmp(bwinput + i, colorized_tags[c].inittag, strlen(colorized_tags[c].inittag))) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!(tmp = strcasestr(bwinput + i + strlen(colorized_tags[c].inittag), colorized_tags[c].endtag))) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			len = tmp - (bwinput + i + strlen(colorized_tags[c].inittag)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* Setup color */ | 
					
						
							|  |  |  | 			if (withcolors) { | 
					
						
							| 
									
										
										
										
											2012-12-10 01:41:50 +00:00
										 |  |  | 				if (ast_opt_light_background) { | 
					
						
							|  |  |  | 					/* Turn off *bright* colors */ | 
					
						
							|  |  |  | 					ast_term_color_code(&colorized, colorized_tags[c].colorfg & 0x7f, 0); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					/* Turn on *bright* colors */ | 
					
						
							|  |  |  | 					ast_term_color_code(&colorized, colorized_tags[c].colorfg | 0x80, 0); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 				if (!colorized) { | 
					
						
							|  |  |  | 					return NULL; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* copy initial string replace */ | 
					
						
							|  |  |  | 			ast_str_append(&colorized, 0, "%s", colorized_tags[c].init); | 
					
						
							|  |  |  | 			if (!colorized) { | 
					
						
							|  |  |  | 				return NULL; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				char buf[len + 1]; | 
					
						
							|  |  |  | 				ast_copy_string(buf, bwinput + i + strlen(colorized_tags[c].inittag), sizeof(buf)); | 
					
						
							|  |  |  | 				ast_str_append(&colorized, 0, "%s", buf); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (!colorized) { | 
					
						
							|  |  |  | 				return NULL; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* copy the ending string replace */ | 
					
						
							|  |  |  | 			ast_str_append(&colorized, 0, "%s", colorized_tags[c].end); | 
					
						
							|  |  |  | 			if (!colorized) { | 
					
						
							|  |  |  | 				return NULL; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* Continue with the last color. */ | 
					
						
							|  |  |  | 			if (withcolors) { | 
					
						
							|  |  |  | 				ast_term_color_code(&colorized, base_fg, 0); | 
					
						
							|  |  |  | 				if (!colorized) { | 
					
						
							|  |  |  | 					return NULL; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			i += len + strlen(colorized_tags[c].endtag) + strlen(colorized_tags[c].inittag) - 1; | 
					
						
							|  |  |  | 			colorsection = 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!colorsection) { | 
					
						
							|  |  |  | 			ast_str_append(&colorized, 0, "%c", bwinput[i]); | 
					
						
							|  |  |  | 			if (!colorized) { | 
					
						
							|  |  |  | 				return NULL; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (withcolors) { | 
					
						
							| 
									
										
										
										
											2014-05-28 22:54:12 +00:00
										 |  |  | 		ast_str_append(&colorized, 0, "%s", ast_term_reset()); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		if (!colorized) { | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Wrap the text, notice that string wrap will avoid cutting an ESC sequence. */ | 
					
						
							| 
									
										
										
										
											2015-11-06 14:36:40 +01:00
										 |  |  | 	wrapped = xmldoc_string_wrap(ast_str_buffer(colorized), xmldoc_text_columns); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ast_free(colorized); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return wrapped; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Cleanup spaces and tabs after a \n | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param text String to be cleaned up. | 
					
						
							|  |  |  |  * \param output buffer (not already allocated). | 
					
						
							|  |  |  |  * \param lastspaces Remove last spaces in the string. | 
					
						
							| 
									
										
										
										
											2014-07-31 11:49:40 +00:00
										 |  |  |  * \param maintain_newlines Preserve new line characters (\n \r) discovered in the string | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-07-31 11:49:40 +00:00
										 |  |  | static void xmldoc_string_cleanup(const char *text, struct ast_str **output, int lastspaces, int maintain_newlines) | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	size_t textlen; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!text) { | 
					
						
							|  |  |  | 		*output = NULL; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	textlen = strlen(text); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	*output = ast_str_create(textlen); | 
					
						
							|  |  |  | 	if (!(*output)) { | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Problem allocating output buffer\n"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < textlen; i++) { | 
					
						
							|  |  |  | 		if (text[i] == '\n' || text[i] == '\r') { | 
					
						
							| 
									
										
										
										
											2014-07-31 11:49:40 +00:00
										 |  |  | 			if (maintain_newlines) { | 
					
						
							|  |  |  | 				ast_str_append(output, 0, "%c", text[i]); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			/* remove spaces/tabs/\n after a \n. */ | 
					
						
							|  |  |  | 			while (text[i + 1] == '\t' || text[i + 1] == '\r' || text[i + 1] == '\n') { | 
					
						
							|  |  |  | 				i++; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			ast_str_append(output, 0, " "); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			ast_str_append(output, 0, "%c", text[i]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-02 15:57:02 +00:00
										 |  |  | 	/* remove last spaces (we don't want always to remove the trailing spaces). */ | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	if (lastspaces) { | 
					
						
							|  |  |  | 		ast_str_trim_blanks(*output); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  |  * \brief Check if the given attribute on the given node matches the given value. | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  |  * \param node the node to match | 
					
						
							|  |  |  |  * \param attr the name of the attribute | 
					
						
							|  |  |  |  * \param value the expected value of the attribute | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  |  * \retval true if the given attribute contains the given value | 
					
						
							|  |  |  |  * \retval false if the given attribute does not exist or does not contain the given value | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int xmldoc_attribute_match(struct ast_xml_node *node, const char *attr, const char *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *attr_value = ast_xml_get_attribute(node, attr); | 
					
						
							|  |  |  | 	int match = attr_value && !strcmp(attr_value, value); | 
					
						
							|  |  |  | 	ast_xml_free_attr(attr_value); | 
					
						
							|  |  |  | 	return match; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Get the application/function node for 'name' application/function with language 'language' | 
					
						
							|  |  |  |  *        and module 'module' if we don't find any, get the first application | 
					
						
							|  |  |  |  *        with 'name' no matter which language or module. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param type 'application', 'function', ... | 
					
						
							|  |  |  |  * \param name Application or Function name. | 
					
						
							|  |  |  |  * \param module Module item is in. | 
					
						
							|  |  |  |  * \param language Try to get this language (if not found try with en_US) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval NULL on error. | 
					
						
							|  |  |  |  * \retval A node of type ast_xml_node. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | static struct ast_xml_node *xmldoc_get_node(const char *type, const char *name, const char *module, const char *language) | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *node = NULL; | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | 	struct ast_xml_node *first_match = NULL; | 
					
						
							|  |  |  | 	struct ast_xml_node *lang_match = NULL; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	struct documentation_tree *doctree; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	AST_RWLIST_RDLOCK(&xmldoc_tree); | 
					
						
							|  |  |  | 	AST_LIST_TRAVERSE(&xmldoc_tree, doctree, entry) { | 
					
						
							|  |  |  | 		/* the core xml documents have priority over thirdparty document. */ | 
					
						
							|  |  |  | 		node = ast_xml_get_root(doctree->doc); | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | 		if (!node) { | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		node = ast_xml_node_get_children(node); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		while ((node = ast_xml_find_element(node, type, "name", name))) { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | 			if (!ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 				/* ignore empty nodes */ | 
					
						
							|  |  |  | 				node = ast_xml_node_get_next(node); | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!first_match) { | 
					
						
							|  |  |  | 				first_match = node; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			/* Check language */ | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | 			if (xmldoc_attribute_match(node, "language", language)) { | 
					
						
							|  |  |  | 				if (!lang_match) { | 
					
						
							|  |  |  | 					lang_match = node; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* if module is empty we have a match */ | 
					
						
							|  |  |  | 				if (ast_strlen_zero(module)) { | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* Check module */ | 
					
						
							|  |  |  | 				if (xmldoc_attribute_match(node, "module", module)) { | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			node = ast_xml_node_get_next(node); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | 		/* if we matched lang and module return this match */ | 
					
						
							|  |  |  | 		if (node) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | 		/* we didn't match lang and module, just return the first
 | 
					
						
							|  |  |  | 		 * result with a matching language if we have one */ | 
					
						
							|  |  |  | 		if (lang_match) { | 
					
						
							|  |  |  | 			node = lang_match; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* we didn't match with only the language, just return the
 | 
					
						
							|  |  |  | 		 * first match */ | 
					
						
							|  |  |  | 		if (first_match) { | 
					
						
							|  |  |  | 			node = first_match; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	AST_RWLIST_UNLOCK(&xmldoc_tree); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return node; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Helper function used to build the syntax, it allocates the needed buffer (or reallocates it), | 
					
						
							|  |  |  |  *        and based on the reverse value it makes use of fmt to print the parameter list inside the | 
					
						
							|  |  |  |  *        realloced buffer (syntax). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param reverse We are going backwards while generating the syntax? | 
					
						
							|  |  |  |  * \param len Current length of 'syntax' buffer. | 
					
						
							|  |  |  |  * \param syntax Output buffer for the concatenated values. | 
					
						
							|  |  |  |  * \param fmt A format string that will be used in a sprintf call. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-11-29 17:57:39 +00:00
										 |  |  | static void __attribute__((format(printf, 4, 5))) xmldoc_reverse_helper(int reverse, int *len, char **syntax, const char *fmt, ...) | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-10 18:05:47 +00:00
										 |  |  | 	int totlen; | 
					
						
							|  |  |  | 	int tmpfmtlen; | 
					
						
							|  |  |  | 	char *tmpfmt; | 
					
						
							|  |  |  | 	char *new_syntax; | 
					
						
							|  |  |  | 	char tmp; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	va_list ap; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	va_start(ap, fmt); | 
					
						
							|  |  |  | 	if (ast_vasprintf(&tmpfmt, fmt, ap) < 0) { | 
					
						
							|  |  |  | 		va_end(ap); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	va_end(ap); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tmpfmtlen = strlen(tmpfmt); | 
					
						
							|  |  |  | 	totlen = *len + tmpfmtlen + 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-10 18:05:47 +00:00
										 |  |  | 	new_syntax = ast_realloc(*syntax, totlen); | 
					
						
							|  |  |  | 	if (!new_syntax) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		ast_free(tmpfmt); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-09-10 18:05:47 +00:00
										 |  |  | 	*syntax = new_syntax; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (reverse) { | 
					
						
							|  |  |  | 		memmove(*syntax + tmpfmtlen, *syntax, *len); | 
					
						
							|  |  |  | 		/* Save this char, it will be overwritten by the \0 of strcpy. */ | 
					
						
							|  |  |  | 		tmp = (*syntax)[0]; | 
					
						
							|  |  |  | 		strcpy(*syntax, tmpfmt); | 
					
						
							|  |  |  | 		/* Restore the already saved char. */ | 
					
						
							|  |  |  | 		(*syntax)[tmpfmtlen] = tmp; | 
					
						
							|  |  |  | 		(*syntax)[totlen - 1] = '\0'; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		strcpy(*syntax + *len, tmpfmt); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	*len = totlen - 1; | 
					
						
							|  |  |  | 	ast_free(tmpfmt); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \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 'what' element is found inside 'node'. | 
					
						
							|  |  |  |  * \retval 0 If no 'what' is found inside 'node'. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | static int xmldoc_has_inside(struct ast_xml_node *fixnode, const char *what) | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *node = fixnode; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) { | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | 		if (!strcasecmp(ast_xml_node_get_name(node), what)) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \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'. | 
					
						
							| 
									
										
										
										
											2008-12-08 04:23:50 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \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'. | 
					
						
							| 
									
										
										
										
											2008-12-08 04:23:50 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \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. | 
					
						
							|  |  |  |  * \param childname The name of each parameter node. | 
					
						
							|  |  |  |  * \param printparenthesis Boolean if we must print parenthesis if not parameters are found in the rootnode. | 
					
						
							|  |  |  |  * \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. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | static char *xmldoc_get_syntax_fun(struct ast_xml_node *rootnode, const char *rootname, const char *childname, int printparenthesis, int printrootname) | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | #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 : ""))
 | 
					
						
							|  |  |  | 	struct ast_xml_node *node = NULL, *firstparam = NULL, *lastparam = NULL; | 
					
						
							| 
									
										
										
										
											2008-11-15 15:37:11 +00:00
										 |  |  | 	const char *paramtype, *multipletype, *paramnameattr, *attrargsep, *parenthesis, *argname; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	int reverse, required, paramcount = 0, openbrackets = 0, len = 0, hasparams=0; | 
					
						
							| 
									
										
										
										
											2008-11-15 15:37:11 +00:00
										 |  |  | 	int reqfinode = 0, reqlanode = 0, optmidnode = 0, prnparenthesis, multiple; | 
					
						
							|  |  |  | 	char *syntax = NULL, *argsep, *paramname; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_strlen_zero(rootname) || ast_strlen_zero(childname)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Tried to look in XML tree with faulty rootname or childname while creating a syntax.\n"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!rootnode || !ast_xml_node_get_children(rootnode)) { | 
					
						
							|  |  |  | 		/* If the rootnode field is not found, at least print name. */ | 
					
						
							| 
									
										
										
										
											2012-08-21 21:01:11 +00:00
										 |  |  | 		if (ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : "")) < 0) { | 
					
						
							|  |  |  | 			syntax = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		return syntax; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Get the argument separator from the root node attribute name 'argsep', if not found
 | 
					
						
							| 
									
										
										
										
											2013-04-02 11:40:05 +00:00
										 |  |  | 	defaults to ','. */ | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	attrargsep = ast_xml_get_attribute(rootnode, "argsep"); | 
					
						
							|  |  |  | 	if (attrargsep) { | 
					
						
							|  |  |  | 		argsep = ast_strdupa(attrargsep); | 
					
						
							|  |  |  | 		ast_xml_free_attr(attrargsep); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2013-04-02 11:40:05 +00:00
										 |  |  | 		argsep = ast_strdupa(","); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Get order of evaluation. */ | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 		hasparams = 1; | 
					
						
							|  |  |  | 		if ((paramtype = ast_xml_get_attribute(node, "required"))) { | 
					
						
							|  |  |  | 			if (ast_true(paramtype)) { | 
					
						
							|  |  |  | 				required = 1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			ast_xml_free_attr(paramtype); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		lastparam = node; | 
					
						
							|  |  |  | 		reqlanode = required; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!firstparam) { | 
					
						
							|  |  |  | 			/* first parameter node */ | 
					
						
							|  |  |  | 			firstparam = node; | 
					
						
							|  |  |  | 			reqfinode = required; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!hasparams) { | 
					
						
							|  |  |  | 		/* This application, function, option, etc, doesn't have any params. */ | 
					
						
							| 
									
										
										
										
											2012-08-21 21:01:11 +00:00
										 |  |  | 		if (ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : "")) < 0) { | 
					
						
							|  |  |  | 			syntax = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		return syntax; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (reqfinode && reqlanode) { | 
					
						
							|  |  |  | 		/* check midnode */ | 
					
						
							|  |  |  | 		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) { | 
					
						
							|  |  |  | 				if ((paramtype = ast_xml_get_attribute(node, "required"))) { | 
					
						
							|  |  |  | 					if (!ast_true(paramtype)) { | 
					
						
							|  |  |  | 						optmidnode = 1; | 
					
						
							| 
									
										
										
										
											2013-03-07 16:21:52 +00:00
										 |  |  | 						ast_xml_free_attr(paramtype); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					ast_xml_free_attr(paramtype); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((!reqfinode && reqlanode) || (reqfinode && reqlanode && optmidnode)) { | 
					
						
							|  |  |  | 		reverse = 1; | 
					
						
							|  |  |  | 		node = lastparam; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		reverse = 0; | 
					
						
							|  |  |  | 		node = firstparam; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* init syntax string. */ | 
					
						
							|  |  |  | 	if (reverse) { | 
					
						
							|  |  |  | 		xmldoc_reverse_helper(reverse, &len, &syntax, | 
					
						
							|  |  |  | 			(printrootname ? (printrootname == 2 ? ")]" : ")"): "")); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s", (printrootname ? rootname : ""), | 
					
						
							|  |  |  | 			(printrootname ? (printrootname == 2 ? "[(" : "(") : "")); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (; node; node = GOTONEXT(reverse, node)) { | 
					
						
							|  |  |  | 		if (strcasecmp(ast_xml_node_get_name(node), childname)) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Get the argument name, if it is not the leaf, go inside that parameter. */ | 
					
						
							| 
									
										
										
										
											2008-11-13 13:53:13 +00:00
										 |  |  | 		if (xmldoc_has_inside(node, "argument")) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			parenthesis = ast_xml_get_attribute(node, "hasparams"); | 
					
						
							|  |  |  | 			prnparenthesis = 0; | 
					
						
							|  |  |  | 			if (parenthesis) { | 
					
						
							|  |  |  | 				prnparenthesis = ast_true(parenthesis); | 
					
						
							|  |  |  | 				if (!strcasecmp(parenthesis, "optional")) { | 
					
						
							|  |  |  | 					prnparenthesis = 2; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				ast_xml_free_attr(parenthesis); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			argname = ast_xml_get_attribute(node, "name"); | 
					
						
							|  |  |  | 			if (argname) { | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | 				paramname = xmldoc_get_syntax_fun(node, argname, "argument", prnparenthesis, prnparenthesis); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 				ast_xml_free_attr(argname); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				/* Malformed XML, print **UNKOWN** */ | 
					
						
							|  |  |  | 				paramname = ast_strdup("**unknown**"); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2008-11-15 15:37:11 +00:00
										 |  |  | 			paramnameattr = ast_xml_get_attribute(node, "name"); | 
					
						
							|  |  |  | 			if (!paramnameattr) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Malformed XML %s: no %s name\n", rootname, childname); | 
					
						
							|  |  |  | 				if (syntax) { | 
					
						
							|  |  |  | 					/* Free already allocated syntax */ | 
					
						
							|  |  |  | 					ast_free(syntax); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				/* to give up is ok? */ | 
					
						
							| 
									
										
										
										
											2012-08-21 21:01:11 +00:00
										 |  |  | 				if (ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : "")) < 0) { | 
					
						
							|  |  |  | 					syntax = NULL; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 				return syntax; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-11-15 15:37:11 +00:00
										 |  |  | 			paramname = ast_strdup(paramnameattr); | 
					
						
							|  |  |  | 			ast_xml_free_attr(paramnameattr); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-21 21:01:11 +00:00
										 |  |  | 		if (!paramname) { | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		/* Defaults to 'false'. */ | 
					
						
							|  |  |  | 		multiple = 0; | 
					
						
							|  |  |  | 		if ((multipletype = ast_xml_get_attribute(node, "multiple"))) { | 
					
						
							|  |  |  | 			if (ast_true(multipletype)) { | 
					
						
							|  |  |  | 				multiple = 1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			ast_xml_free_attr(multipletype); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		required = 0;	/* Defaults to 'false'. */ | 
					
						
							|  |  |  | 		if ((paramtype = ast_xml_get_attribute(node, "required"))) { | 
					
						
							|  |  |  | 			if (ast_true(paramtype)) { | 
					
						
							|  |  |  | 				required = 1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			ast_xml_free_attr(paramtype); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* build syntax core. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (required) { | 
					
						
							|  |  |  | 			/* First parameter */ | 
					
						
							|  |  |  | 			if (!paramcount) { | 
					
						
							|  |  |  | 				xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s%s%s", paramname, MP("["), MP(argsep), MP("...]")); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				/* Time to close open brackets. */ | 
					
						
							|  |  |  | 				while (openbrackets > 0) { | 
					
						
							|  |  |  | 					xmldoc_reverse_helper(reverse, &len, &syntax, (reverse ? "[" : "]")); | 
					
						
							|  |  |  | 					openbrackets--; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (reverse) { | 
					
						
							|  |  |  | 					xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s", paramname, argsep); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s", argsep, paramname); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s%s", MP("["), MP(argsep), MP("...]")); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			/* First parameter */ | 
					
						
							|  |  |  | 			if (!paramcount) { | 
					
						
							|  |  |  | 				xmldoc_reverse_helper(reverse, &len, &syntax, "[%s%s%s%s]", paramname, MP("["), MP(argsep), MP("...]")); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				if (ISLAST(reverse, node)) { | 
					
						
							|  |  |  | 					/* This is the last parameter. */ | 
					
						
							|  |  |  | 					if (reverse) { | 
					
						
							|  |  |  | 						xmldoc_reverse_helper(reverse, &len, &syntax, "[%s%s%s%s]%s", paramname, | 
					
						
							|  |  |  | 									MP("["), MP(argsep), MP("...]"), argsep); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						xmldoc_reverse_helper(reverse, &len, &syntax, "%s[%s%s%s%s]", argsep, paramname, | 
					
						
							|  |  |  | 									MP("["), MP(argsep), MP("...]")); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					if (reverse) { | 
					
						
							|  |  |  | 						xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s%s%s%s]", paramname, argsep, | 
					
						
							|  |  |  | 									MP("["), MP(argsep), MP("...]")); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						xmldoc_reverse_helper(reverse, &len, &syntax, "[%s%s%s%s%s", argsep, paramname, | 
					
						
							|  |  |  | 									MP("["), MP(argsep), MP("...]")); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					openbrackets++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-11-15 15:37:11 +00:00
										 |  |  | 		ast_free(paramname); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		paramcount++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Time to close open brackets. */ | 
					
						
							|  |  |  | 	while (openbrackets > 0) { | 
					
						
							|  |  |  | 		xmldoc_reverse_helper(reverse, &len, &syntax, (reverse ? "[" : "]")); | 
					
						
							|  |  |  | 		openbrackets--; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* close syntax string. */ | 
					
						
							|  |  |  | 	if (reverse) { | 
					
						
							|  |  |  | 		xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s", (printrootname ? rootname : ""), | 
					
						
							|  |  |  | 			(printrootname ? (printrootname == 2 ? "[(" : "(") : "")); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		xmldoc_reverse_helper(reverse, &len, &syntax, (printrootname ? (printrootname == 2 ? ")]" : ")") : "")); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return syntax; | 
					
						
							|  |  |  | #undef ISLAST
 | 
					
						
							|  |  |  | #undef GOTONEXT
 | 
					
						
							|  |  |  | #undef MP
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse an enumlist inside a <parameter> to generate a COMMAND syntax. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param fixnode A pointer to the <enumlist> node. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval {<unknown>} on error. | 
					
						
							|  |  |  |  * \retval A string inside brackets {} with the enum's separated by pipes |. | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static char *xmldoc_parse_cmd_enumlist(struct ast_xml_node *fixnode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *node = fixnode; | 
					
						
							|  |  |  | 	struct ast_str *paramname; | 
					
						
							|  |  |  | 	char *enumname, *ret; | 
					
						
							|  |  |  | 	int first = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	paramname = ast_str_create(128); | 
					
						
							|  |  |  | 	if (!paramname) { | 
					
						
							|  |  |  | 		return ast_strdup("{<unkown>}"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_str_append(¶mname, 0, "{"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		enumname = xmldoc_get_syntax_cmd(node, "", 0); | 
					
						
							|  |  |  | 		if (!enumname) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (!first) { | 
					
						
							|  |  |  | 			ast_str_append(¶mname, 0, "|"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		ast_str_append(¶mname, 0, "%s", enumname); | 
					
						
							|  |  |  | 		first = 0; | 
					
						
							|  |  |  | 		ast_free(enumname); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_str_append(¶mname, 0, "}"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 	ret = ast_strdup(ast_str_buffer(paramname)); | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | 	ast_free(paramname); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Generate a syntax of COMMAND type. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param fixnode The <syntax> node pointer. | 
					
						
							|  |  |  |  * \param name The name of the 'command'. | 
					
						
							|  |  |  |  * \param printname Print the name of the command before the paramters? | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval On error, return just 'name'. | 
					
						
							|  |  |  |  * \retval On success return the generated syntax. | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static char *xmldoc_get_syntax_cmd(struct ast_xml_node *fixnode, const char *name, int printname) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_str *syntax; | 
					
						
							|  |  |  | 	struct ast_xml_node *tmpnode, *node = fixnode; | 
					
						
							| 
									
										
										
										
											2008-11-12 17:28:02 +00:00
										 |  |  | 	char *ret, *paramname; | 
					
						
							|  |  |  | 	const char *paramtype, *attrname, *literal; | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | 	int required, isenum, first = 1, isliteral; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 	if (!fixnode) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | 	syntax = ast_str_create(128); | 
					
						
							|  |  |  | 	if (!syntax) { | 
					
						
							|  |  |  | 		/* at least try to return something... */ | 
					
						
							|  |  |  | 		return ast_strdup(name); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* append name to output string. */ | 
					
						
							|  |  |  | 	if (printname) { | 
					
						
							|  |  |  | 		ast_str_append(&syntax, 0, "%s", name); | 
					
						
							|  |  |  | 		first = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { | 
					
						
							|  |  |  | 		if (strcasecmp(ast_xml_node_get_name(node), "parameter")) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (xmldoc_has_inside(node, "parameter")) { | 
					
						
							|  |  |  | 			/* is this a recursive parameter. */ | 
					
						
							|  |  |  | 			paramname = xmldoc_get_syntax_cmd(node, "", 0); | 
					
						
							|  |  |  | 			isenum = 1; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			for (tmpnode = ast_xml_node_get_children(node); tmpnode; tmpnode = ast_xml_node_get_next(tmpnode)) { | 
					
						
							|  |  |  | 				if (!strcasecmp(ast_xml_node_get_name(tmpnode), "enumlist")) { | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
											
												Resolve FORWARD_NULL static analysis warnings
This resolves core findings from ASTERISK-19650 numbers 0-2, 6, 7, 9-11, 14-20,
22-24, 28, 30-32, 34-36, 42-56, 82-84, 87, 89-90, 93-102, 104, 105, 109-111,
and 115. Finding numbers 26, 33, and 29 were already resolved.  Those skipped
were either extended/deprecated or in areas of code that shouldn't be
disturbed.
(Closes issue ASTERISK-19650)
........
Merged revisions 366167 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 366168 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@366169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2012-05-10 20:56:09 +00:00
										 |  |  | 			if (tmpnode) { | 
					
						
							|  |  |  | 				/* parse enumlist (note that this is a special enumlist
 | 
					
						
							|  |  |  | 				that is used to describe a syntax like {<param1>|<param2>|...} */ | 
					
						
							|  |  |  | 				paramname = xmldoc_parse_cmd_enumlist(tmpnode); | 
					
						
							|  |  |  | 				isenum = 1; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				/* this is a simple parameter. */ | 
					
						
							|  |  |  | 				attrname = ast_xml_get_attribute(node, "name"); | 
					
						
							|  |  |  | 				if (!attrname) { | 
					
						
							|  |  |  | 					/* ignore this bogus parameter and continue. */ | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				paramname = ast_strdup(attrname); | 
					
						
							|  |  |  | 				ast_xml_free_attr(attrname); | 
					
						
							|  |  |  | 				isenum = 0; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Is this parameter required? */ | 
					
						
							|  |  |  | 		required = 0; | 
					
						
							|  |  |  | 		paramtype = ast_xml_get_attribute(node, "required"); | 
					
						
							|  |  |  | 		if (paramtype) { | 
					
						
							|  |  |  | 			required = ast_true(paramtype); | 
					
						
							|  |  |  | 			ast_xml_free_attr(paramtype); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Is this a replaceable value or a fixed parameter value? */ | 
					
						
							|  |  |  | 		isliteral = 0; | 
					
						
							|  |  |  | 		literal = ast_xml_get_attribute(node, "literal"); | 
					
						
							|  |  |  | 		if (literal) { | 
					
						
							|  |  |  | 			isliteral = ast_true(literal); | 
					
						
							|  |  |  | 			ast_xml_free_attr(literal); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* if required="false" print with [...].
 | 
					
						
							|  |  |  | 		 * if literal="true" or is enum print without <..>. | 
					
						
							|  |  |  | 		 * if not first print a space at the beginning. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		ast_str_append(&syntax, 0, "%s%s%s%s%s%s", | 
					
						
							|  |  |  | 				(first ? "" : " "), | 
					
						
							|  |  |  | 				(required ? "" : "["), | 
					
						
							|  |  |  | 				(isenum || isliteral ? "" : "<"), | 
					
						
							|  |  |  | 				paramname, | 
					
						
							|  |  |  | 				(isenum || isliteral ? "" : ">"), | 
					
						
							|  |  |  | 				(required ? "" : "]")); | 
					
						
							|  |  |  | 		first = 0; | 
					
						
							| 
									
										
										
										
											2008-11-12 17:28:02 +00:00
										 |  |  | 		ast_free(paramname); | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* return a common string. */ | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 	ret = ast_strdup(ast_str_buffer(syntax)); | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | 	ast_free(syntax); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Generate an AMI action/event syntax. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param fixnode The manager action/event node pointer. | 
					
						
							|  |  |  |  * \param name The name of the manager action/event. | 
					
						
							|  |  |  |  * \param manager_type "Action" or "Event" | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval The generated syntax. | 
					
						
							|  |  |  |  * \retval NULL on error. | 
					
						
							| 
									
										
										
										
											2009-05-22 17:52:35 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | static char *xmldoc_get_syntax_manager(struct ast_xml_node *fixnode, const char *name, const char *manager_type) | 
					
						
							| 
									
										
										
										
											2009-05-22 17:52:35 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ast_str *syntax; | 
					
						
							|  |  |  | 	struct ast_xml_node *node = fixnode; | 
					
						
							|  |  |  | 	const char *paramtype, *attrname; | 
					
						
							|  |  |  | 	int required; | 
					
						
							|  |  |  | 	char *ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 	if (!fixnode) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-22 17:52:35 +00:00
										 |  |  | 	syntax = ast_str_create(128); | 
					
						
							|  |  |  | 	if (!syntax) { | 
					
						
							|  |  |  | 		return ast_strdup(name); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 	ast_str_append(&syntax, 0, "%s: %s", manager_type, name); | 
					
						
							| 
									
										
										
										
											2009-05-22 17:52:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { | 
					
						
							|  |  |  | 		if (strcasecmp(ast_xml_node_get_name(node), "parameter")) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Is this parameter required? */ | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 		required = !strcasecmp(manager_type, "event") ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2009-05-22 17:52:35 +00:00
										 |  |  | 		paramtype = ast_xml_get_attribute(node, "required"); | 
					
						
							|  |  |  | 		if (paramtype) { | 
					
						
							|  |  |  | 			required = ast_true(paramtype); | 
					
						
							|  |  |  | 			ast_xml_free_attr(paramtype); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		attrname = ast_xml_get_attribute(node, "name"); | 
					
						
							|  |  |  | 		if (!attrname) { | 
					
						
							|  |  |  | 			/* ignore this bogus parameter and continue. */ | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ast_str_append(&syntax, 0, "\n%s%s:%s <value>", | 
					
						
							|  |  |  | 			(required ? "" : "["), | 
					
						
							|  |  |  | 			attrname, | 
					
						
							|  |  |  | 			(required ? "" : "]")); | 
					
						
							|  |  |  | 		ast_xml_free_attr(attrname); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* return a common string. */ | 
					
						
							|  |  |  | 	ret = ast_strdup(ast_str_buffer(syntax)); | 
					
						
							|  |  |  | 	ast_free(syntax); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | static char *xmldoc_get_syntax_config_object(struct ast_xml_node *fixnode, const char *name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *matchinfo, *tmp; | 
					
						
							|  |  |  | 	int match; | 
					
						
							|  |  |  | 	const char *attr_value; | 
					
						
							|  |  |  | 	const char *text; | 
					
						
							|  |  |  | 	RAII_VAR(struct ast_str *, syntax, ast_str_create(128), ast_free); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!syntax || !fixnode) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!(matchinfo = ast_xml_find_element(ast_xml_node_get_children(fixnode), "matchInfo", NULL, NULL))) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!(tmp  = ast_xml_find_element(ast_xml_node_get_children(matchinfo), "category", NULL, NULL))) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	attr_value = ast_xml_get_attribute(tmp, "match"); | 
					
						
							|  |  |  | 	if (attr_value) { | 
					
						
							|  |  |  | 		match = ast_true(attr_value); | 
					
						
							|  |  |  | 		text = ast_xml_get_text(tmp); | 
					
						
							|  |  |  | 		ast_str_set(&syntax, 0, "category %s /%s/", match ? "=~" : "!~", text); | 
					
						
							|  |  |  | 		ast_xml_free_attr(attr_value); | 
					
						
							| 
									
										
										
										
											2013-03-07 15:36:52 +00:00
										 |  |  | 		ast_xml_free_text(text); | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((tmp = ast_xml_find_element(ast_xml_node_get_children(matchinfo), "field", NULL, NULL))) { | 
					
						
							|  |  |  | 		text = ast_xml_get_text(tmp); | 
					
						
							|  |  |  | 		attr_value = ast_xml_get_attribute(tmp, "name"); | 
					
						
							|  |  |  | 		ast_str_append(&syntax, 0, " matchfield: %s = %s", S_OR(attr_value, "Unknown"), text); | 
					
						
							|  |  |  | 		ast_xml_free_attr(attr_value); | 
					
						
							| 
									
										
										
										
											2013-03-07 15:36:52 +00:00
										 |  |  | 		ast_xml_free_text(text); | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return ast_strdup(ast_str_buffer(syntax)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char *xmldoc_get_syntax_config_option(struct ast_xml_node *fixnode, const char *name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *type; | 
					
						
							|  |  |  | 	const char *default_value; | 
					
						
							|  |  |  | 	const char *regex; | 
					
						
							|  |  |  | 	RAII_VAR(struct ast_str *, syntax, ast_str_create(128), ast_free); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!syntax || !fixnode) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	type = ast_xml_get_attribute(fixnode, "type"); | 
					
						
							|  |  |  | 	default_value = ast_xml_get_attribute(fixnode, "default"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	regex = ast_xml_get_attribute(fixnode, "regex"); | 
					
						
							|  |  |  | 	ast_str_set(&syntax, 0, "%s = [%s] (Default: %s) (Regex: %s)\n", | 
					
						
							|  |  |  | 		name, | 
					
						
							| 
									
										
										
										
											2015-03-20 18:27:22 +00:00
										 |  |  | 		type ?: "", | 
					
						
							| 
									
										
										
										
											2013-07-09 21:06:21 +00:00
										 |  |  | 		default_value ?: "n/a", | 
					
						
							|  |  |  | 		regex ?: "False"); | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ast_xml_free_attr(type); | 
					
						
							|  |  |  | 	ast_xml_free_attr(default_value); | 
					
						
							|  |  |  | 	ast_xml_free_attr(regex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ast_strdup(ast_str_buffer(syntax)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | /*! \brief Types of syntax that we are able to generate. */ | 
					
						
							|  |  |  | enum syntaxtype { | 
					
						
							|  |  |  | 	FUNCTION_SYNTAX, | 
					
						
							| 
									
										
										
										
											2009-05-22 17:52:35 +00:00
										 |  |  | 	MANAGER_SYNTAX, | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 	MANAGER_EVENT_SYNTAX, | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 	CONFIG_INFO_SYNTAX, | 
					
						
							|  |  |  | 	CONFIG_FILE_SYNTAX, | 
					
						
							|  |  |  | 	CONFIG_OPTION_SYNTAX, | 
					
						
							|  |  |  | 	CONFIG_OBJECT_SYNTAX, | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | 	COMMAND_SYNTAX | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \brief Mapping between type of node and type of syntax to generate. */ | 
					
						
							| 
									
										
										
										
											2009-06-15 17:34:30 +00:00
										 |  |  | static struct strsyntaxtype { | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | 	const char *type; | 
					
						
							|  |  |  | 	enum syntaxtype stxtype; | 
					
						
							|  |  |  | } stxtype[] = { | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  |     { "function",     FUNCTION_SYNTAX      }, | 
					
						
							|  |  |  |     { "application",  FUNCTION_SYNTAX      }, | 
					
						
							|  |  |  |     { "manager",      MANAGER_SYNTAX       }, | 
					
						
							|  |  |  |     { "managerEvent", MANAGER_EVENT_SYNTAX }, | 
					
						
							|  |  |  |     { "configInfo",   CONFIG_INFO_SYNTAX   }, | 
					
						
							|  |  |  |     { "configFile",   CONFIG_FILE_SYNTAX   }, | 
					
						
							|  |  |  |     { "configOption", CONFIG_OPTION_SYNTAX }, | 
					
						
							|  |  |  |     { "configObject", CONFIG_OBJECT_SYNTAX }, | 
					
						
							|  |  |  |     { "agi",          COMMAND_SYNTAX       }, | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Get syntax type based on type of node. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param type Type of node. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval The type of syntax to generate based on the type of node. | 
					
						
							| 
									
										
										
										
											2008-11-12 00:17:43 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static enum syntaxtype xmldoc_get_syntax_type(const char *type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	for (i=0; i < ARRAY_LEN(stxtype); i++) { | 
					
						
							|  |  |  | 		if (!strcasecmp(stxtype[i].type, type)) { | 
					
						
							|  |  |  | 			return stxtype[i].stxtype; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return FUNCTION_SYNTAX; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Build syntax information for an item | 
					
						
							|  |  |  |  * \param node	The syntax node to parse | 
					
						
							|  |  |  |  * \param type	The source type | 
					
						
							|  |  |  |  * \param name	The name of the item that the syntax describes | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note This method exists for when you already have the node.  This | 
					
						
							|  |  |  |  * prevents having to lock the documentation tree twice | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * \retval A malloc'd character pointer to the syntax of the item | 
					
						
							|  |  |  |  * \retval NULL on failure | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \since 11 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | static char *_ast_xmldoc_build_syntax(struct ast_xml_node *root_node, const char *type, const char *name) | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *syntax = NULL; | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 	struct ast_xml_node *node = root_node; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 	switch (xmldoc_get_syntax_type(type)) { | 
					
						
							|  |  |  | 	case FUNCTION_SYNTAX: | 
					
						
							|  |  |  | 		syntax = xmldoc_get_syntax_fun(node, name, "parameter", 1, 1); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case COMMAND_SYNTAX: | 
					
						
							|  |  |  | 		syntax = xmldoc_get_syntax_cmd(node, name, 1); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case MANAGER_SYNTAX: | 
					
						
							|  |  |  | 		syntax = xmldoc_get_syntax_manager(node, name, "Action"); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case MANAGER_EVENT_SYNTAX: | 
					
						
							|  |  |  | 		syntax = xmldoc_get_syntax_manager(node, name, "Event"); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 	case CONFIG_OPTION_SYNTAX: | 
					
						
							|  |  |  | 		syntax = xmldoc_get_syntax_config_option(root_node, name); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case CONFIG_OBJECT_SYNTAX: | 
					
						
							|  |  |  | 		syntax = xmldoc_get_syntax_config_object(node, name); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		syntax = xmldoc_get_syntax_fun(node, name, "parameter", 1, 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	return syntax; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | char *ast_xmldoc_build_syntax(const char *type, const char *name, const char *module) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *node; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	node = xmldoc_get_node(type, name, module, documentation_language); | 
					
						
							|  |  |  | 	if (!node) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return _ast_xmldoc_build_syntax(node, type, name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse common internal elements.  This includes paragraphs, special | 
					
						
							|  |  |  |  *        tags, and information nodes. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param node The element to parse | 
					
						
							|  |  |  |  * \param tabs Add this string before the content of the parsed element. | 
					
						
							|  |  |  |  * \param posttabs Add this string after the content of the parsed element. | 
					
						
							|  |  |  |  * \param buffer This must be an already allocated ast_str. It will be used to | 
					
						
							|  |  |  |  *               store the result (if something has already been placed in the | 
					
						
							|  |  |  |  *               buffer, the parsed elements will be appended) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval 1 if any data was appended to the buffer | 
					
						
							|  |  |  |  * \retval 2 if the data appended to the buffer contained a text paragraph | 
					
						
							|  |  |  |  * \retval 0 if no data was appended to the buffer | 
					
						
							| 
									
										
										
										
											2012-07-19 22:17:13 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static int xmldoc_parse_common_elements(struct ast_xml_node *node, const char *tabs, const char *posttabs, struct ast_str **buffer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (xmldoc_parse_para(node, tabs, posttabs, buffer) | 
					
						
							|  |  |  | 		|| xmldoc_parse_specialtags(node, tabs, posttabs, buffer) | 
					
						
							|  |  |  | 		|| xmldoc_parse_info(node, tabs, posttabs, buffer)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse a <para> element. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param node The <para> element pointer. | 
					
						
							|  |  |  |  * \param tabs Added this string before the content of the <para> element. | 
					
						
							|  |  |  |  * \param posttabs Added this string after the content of the <para> element. | 
					
						
							|  |  |  |  * \param buffer This must be an already allocated ast_str. It will be used | 
					
						
							|  |  |  |  *        to store the result (if already has something it will be appended to the current | 
					
						
							|  |  |  |  *        string). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval 1 If 'node' is a named 'para'. | 
					
						
							|  |  |  |  * \retval 2 If data is appended in buffer. | 
					
						
							|  |  |  |  * \retval 0 on error. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static int xmldoc_parse_para(struct ast_xml_node *node, const char *tabs, const char *posttabs, struct ast_str **buffer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *tmptext; | 
					
						
							|  |  |  | 	struct ast_xml_node *tmp; | 
					
						
							|  |  |  | 	int ret = 0; | 
					
						
							|  |  |  | 	struct ast_str *tmpstr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!node || !ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (strcasecmp(ast_xml_node_get_name(node), "para")) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_str_append(buffer, 0, "%s", tabs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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) { | 
					
						
							|  |  |  | 			/* Strip \n etc. */ | 
					
						
							| 
									
										
										
										
											2014-07-31 11:49:40 +00:00
										 |  |  | 			xmldoc_string_cleanup(tmptext, &tmpstr, 0, 0); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			ast_xml_free_text(tmptext); | 
					
						
							|  |  |  | 			if (tmpstr) { | 
					
						
							|  |  |  | 				if (strcasecmp(ast_xml_node_get_name(tmp), "text")) { | 
					
						
							| 
									
										
										
										
											2008-11-13 13:08:34 +00:00
										 |  |  | 					ast_str_append(buffer, 0, "<%s>%s</%s>", ast_xml_node_get_name(tmp), | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 							ast_str_buffer(tmpstr), ast_xml_node_get_name(tmp)); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 					ast_str_append(buffer, 0, "%s", ast_str_buffer(tmpstr)); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				ast_free(tmpstr); | 
					
						
							|  |  |  | 				ret = 2; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_str_append(buffer, 0, "%s", posttabs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-31 11:49:40 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse an <example> node. | 
					
						
							|  |  |  |  * \since 13.0.0 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param fixnode An ast xml pointer to the <example> node. | 
					
						
							|  |  |  |  * \param buffer The output buffer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval 0 if no example node is parsed. | 
					
						
							|  |  |  |  * \retval 1 if an example node is parsed. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int xmldoc_parse_example(struct ast_xml_node *fixnode, struct ast_str **buffer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *node = fixnode; | 
					
						
							|  |  |  | 	const char *tmptext; | 
					
						
							|  |  |  | 	const char *title; | 
					
						
							|  |  |  | 	struct ast_str *stripped_text; | 
					
						
							|  |  |  | 	int ret = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!node || !ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (strcasecmp(ast_xml_node_get_name(node), "example")) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	title = ast_xml_get_attribute(node, "title"); | 
					
						
							|  |  |  | 	if (title) { | 
					
						
							|  |  |  | 		ast_str_append(buffer, 0, "%s", title); | 
					
						
							|  |  |  | 		ast_xml_free_attr(title); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ast_str_append(buffer, 0, "\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { | 
					
						
							|  |  |  | 		tmptext = ast_xml_get_text(node); | 
					
						
							|  |  |  | 		if (tmptext) { | 
					
						
							|  |  |  | 			xmldoc_string_cleanup(tmptext, &stripped_text, 0, 1); | 
					
						
							|  |  |  | 			if (stripped_text) { | 
					
						
							|  |  |  | 				ast_str_append(buffer, 0, "<exampletext>%s</exampletext>\n", ast_str_buffer(stripped_text)); | 
					
						
							|  |  |  | 				ast_xml_free_text(tmptext); | 
					
						
							|  |  |  | 				ast_free(stripped_text); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse special elements defined in 'struct special_tags' special elements must have a <para> element inside them. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param fixnode special tag node pointer. | 
					
						
							|  |  |  |  * \param tabs put tabs before printing the node content. | 
					
						
							|  |  |  |  * \param posttabs put posttabs after printing node content. | 
					
						
							|  |  |  |  * \param buffer Output buffer, the special tags will be appended here. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval 0 if no special element is parsed. | 
					
						
							|  |  |  |  * \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. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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 || !ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < ARRAY_LEN(special_tags); i++) { | 
					
						
							|  |  |  | 		if (strcasecmp(ast_xml_node_get_name(node), special_tags[i].tagname)) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ret = 1; | 
					
						
							|  |  |  | 		/* This is a special tag. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* concat data */ | 
					
						
							|  |  |  | 		if (!ast_strlen_zero(special_tags[i].init)) { | 
					
						
							|  |  |  | 			ast_str_append(buffer, 0, "%s%s", tabs, special_tags[i].init); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-31 11:49:40 +00:00
										 |  |  | 		if (xmldoc_parse_example(node, buffer)) { | 
					
						
							|  |  |  | 			ret = 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		/* parse <para> elements inside special tags. */ | 
					
						
							|  |  |  | 		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. */ | 
					
						
							| 
									
										
										
										
											2012-07-19 22:17:13 +00:00
										 |  |  | 			if ((xmldoc_parse_para(node, (!count ? "" : tabs), posttabs, buffer) == 2) | 
					
						
							|  |  |  | 				|| (xmldoc_parse_info(node, (!count ? "": tabs), posttabs, buffer) == 2)) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 				ret = 2; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!ast_strlen_zero(special_tags[i].end)) { | 
					
						
							|  |  |  | 			ast_str_append(buffer, 0, "%s%s", special_tags[i].end, posttabs); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse an <argument> element from the xml documentation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param fixnode Pointer to the 'argument' xml node. | 
					
						
							|  |  |  |  * \param insideparameter If we are parsing an <argument> inside a <parameter>. | 
					
						
							|  |  |  |  * \param paramtabs pre tabs if we are inside a parameter element. | 
					
						
							|  |  |  |  * \param tabs What to be printed before the argument name. | 
					
						
							|  |  |  |  * \param buffer Output buffer to put values found inside the <argument> element. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \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. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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 || !ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Print the argument names */ | 
					
						
							|  |  |  | 	argname = ast_xml_get_attribute(node, "name"); | 
					
						
							|  |  |  | 	if (!argname) { | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-07-19 22:17:13 +00:00
										 |  |  | 	if (xmldoc_has_inside(node, "para") || xmldoc_has_inside(node, "info") || xmldoc_has_specialtags(node)) { | 
					
						
							| 
									
										
										
										
											2008-12-08 04:23:50 +00:00
										 |  |  | 		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; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { | 
					
						
							| 
									
										
										
										
											2012-07-19 22:17:13 +00:00
										 |  |  | 		if (xmldoc_parse_common_elements(node, (insideparameter ? paramtabs : (!count ? " - " : tabs)), "\n", buffer) == 2) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			count++; | 
					
						
							|  |  |  | 			ret = 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse a <variable> node inside a <variablelist> node. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param node The variable node to parse. | 
					
						
							|  |  |  |  * \param tabs A string to be appended at the begining of the output that will be stored | 
					
						
							|  |  |  |  *        in buffer. | 
					
						
							|  |  |  |  * \param buffer This must be an already created ast_str. It will be used | 
					
						
							|  |  |  |  *        to store the result (if already has something it will be appended to the current | 
					
						
							|  |  |  |  *        string). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval 0 if no data is appended. | 
					
						
							|  |  |  |  * \retval 1 if data is appended. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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 = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) { | 
					
						
							| 
									
										
										
										
											2012-07-19 22:17:13 +00:00
										 |  |  | 		if (xmldoc_parse_common_elements(tmp, (ret ? tabs : ""), "\n", buffer)) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			printedpara = 1; | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (strcasecmp(ast_xml_node_get_name(tmp), "value")) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Parse a <value> tag only. */ | 
					
						
							|  |  |  | 		if (!printedpara) { | 
					
						
							|  |  |  | 			ast_str_append(buffer, 0, "\n"); | 
					
						
							|  |  |  | 			printedpara = 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* Parse each <value name='valuename'>desciption</value> */ | 
					
						
							|  |  |  | 		valname = ast_xml_get_attribute(tmp, "name"); | 
					
						
							|  |  |  | 		if (valname) { | 
					
						
							|  |  |  | 			ret = 1; | 
					
						
							|  |  |  | 			ast_str_append(buffer, 0, "%s<value>%s</value>", tabs, valname); | 
					
						
							|  |  |  | 			ast_xml_free_attr(valname); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		tmptext = ast_xml_get_text(tmp); | 
					
						
							|  |  |  | 		/* Check inside this node for any explanation about its meaning. */ | 
					
						
							|  |  |  | 		if (tmptext) { | 
					
						
							|  |  |  | 			/* Cleanup text. */ | 
					
						
							| 
									
										
										
										
											2014-07-31 11:49:40 +00:00
										 |  |  | 			xmldoc_string_cleanup(tmptext, &cleanstr, 1, 0); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			ast_xml_free_text(tmptext); | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 			if (cleanstr && ast_str_strlen(cleanstr) > 0) { | 
					
						
							|  |  |  | 				ast_str_append(buffer, 0, ":%s", ast_str_buffer(cleanstr)); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			ast_free(cleanstr); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		ast_str_append(buffer, 0, "\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse a <variablelist> node and put all the output inside 'buffer'. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param node The variablelist node pointer. | 
					
						
							|  |  |  |  * \param tabs A string to be appended at the begining of the output that will be stored | 
					
						
							|  |  |  |  *        in buffer. | 
					
						
							|  |  |  |  * \param buffer This must be an already created ast_str. It will be used | 
					
						
							|  |  |  |  *        to store the result (if already has something it will be appended to the current | 
					
						
							|  |  |  |  *        string). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval 1 If a <variablelist> element is parsed. | 
					
						
							|  |  |  |  * \retval 0 On error. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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 || !ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (strcasecmp(ast_xml_node_get_name(node), "variablelist")) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* use this spacing (add 4 spaces) inside a variablelist node. */ | 
					
						
							| 
									
										
										
										
											2012-08-21 21:01:11 +00:00
										 |  |  | 	if (ast_asprintf(&vartabs, "%s    ", tabs) < 0) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	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 */ | 
					
						
							| 
									
										
										
										
											2012-07-19 22:17:13 +00:00
										 |  |  | 		if (xmldoc_parse_common_elements(tmp, (ret ? tabs : ""), "\n", buffer)) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			ret = 1; | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!strcasecmp(ast_xml_node_get_name(tmp), "variable")) { | 
					
						
							|  |  |  | 			/* Store the variable name in buffer. */ | 
					
						
							|  |  |  | 			varname = ast_xml_get_attribute(tmp, "name"); | 
					
						
							|  |  |  | 			if (varname) { | 
					
						
							|  |  |  | 				ast_str_append(buffer, 0, "%s<variable>%s</variable>: ", tabs, varname); | 
					
						
							|  |  |  | 				ast_xml_free_attr(varname); | 
					
						
							|  |  |  | 				/* Parse the <variable> possible values. */ | 
					
						
							|  |  |  | 				xmldoc_parse_variable(tmp, vartabs, buffer); | 
					
						
							|  |  |  | 				ret = 1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_free(vartabs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Build seealso information for an item | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \param node	The seealso node to parse | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note This method exists for when you already have the node.  This | 
					
						
							|  |  |  |  * prevents having to lock the documentation tree twice | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * \retval A malloc'd character pointer to the seealso information of the item | 
					
						
							|  |  |  |  * \retval NULL on failure | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \since 11 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static char *_ast_xmldoc_build_seealso(struct ast_xml_node *node) | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *output; | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 	struct ast_str *outputstr; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	const char *typename; | 
					
						
							|  |  |  | 	const char *content; | 
					
						
							|  |  |  | 	int first = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Find the <see-also> node. */ | 
					
						
							|  |  |  | 	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 || !ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 		/* we couldnt find a <see-also> node. */ | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* prepare the output string. */ | 
					
						
							|  |  |  | 	outputstr = ast_str_create(128); | 
					
						
							|  |  |  | 	if (!outputstr) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* get into the <see-also> node. */ | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* parse the <ref> node. 'type' attribute is required. */ | 
					
						
							|  |  |  | 		typename = ast_xml_get_attribute(node, "type"); | 
					
						
							|  |  |  | 		if (!typename) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		content = ast_xml_get_text(node); | 
					
						
							|  |  |  | 		if (!content) { | 
					
						
							|  |  |  | 			ast_xml_free_attr(typename); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (!strcasecmp(typename, "application")) { | 
					
						
							|  |  |  | 			ast_str_append(&outputstr, 0, "%s%s()",	(first ? "" : ", "), content); | 
					
						
							|  |  |  | 		} else if (!strcasecmp(typename, "function")) { | 
					
						
							|  |  |  | 			ast_str_append(&outputstr, 0, "%s%s", (first ? "" : ", "), content); | 
					
						
							|  |  |  | 		} else if (!strcasecmp(typename, "astcli")) { | 
					
						
							|  |  |  | 			ast_str_append(&outputstr, 0, "%s<astcli>%s</astcli>", (first ? "" : ", "), content); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			ast_str_append(&outputstr, 0, "%s%s", (first ? "" : ", "), content); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		first = 0; | 
					
						
							|  |  |  | 		ast_xml_free_text(content); | 
					
						
							| 
									
										
										
										
											2008-12-31 22:53:55 +00:00
										 |  |  | 		ast_xml_free_attr(typename); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 	output = ast_strdup(ast_str_buffer(outputstr)); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	ast_free(outputstr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return output; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | char *ast_xmldoc_build_seealso(const char *type, const char *name, const char *module) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *output; | 
					
						
							|  |  |  | 	struct ast_xml_node *node; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_strlen_zero(type) || ast_strlen_zero(name)) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* get the application/function root node. */ | 
					
						
							|  |  |  | 	node = xmldoc_get_node(type, name, module, documentation_language); | 
					
						
							|  |  |  | 	if (!node || !ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	output = _ast_xmldoc_build_seealso(node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return output; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse a <enum> node. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param fixnode An ast_xml_node pointer to the <enum> node. | 
					
						
							|  |  |  |  * \param buffer The output buffer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \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. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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; | 
					
						
							| 
									
										
										
										
											2009-05-15 13:23:37 +00:00
										 |  |  | 	char *optiontabs; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-21 21:01:11 +00:00
										 |  |  | 	if (ast_asprintf(&optiontabs, "%s    ", tabs) < 0) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { | 
					
						
							| 
									
										
										
										
											2012-07-19 22:17:13 +00:00
										 |  |  | 		if (xmldoc_parse_common_elements(node, (ret ? tabs : " - "), "\n", buffer)) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			ret = 1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-05-15 13:23:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		xmldoc_parse_enumlist(node, optiontabs, buffer); | 
					
						
							| 
									
										
										
										
											2013-12-11 13:06:30 +00:00
										 |  |  | 		xmldoc_parse_parameter(node, optiontabs, buffer); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-15 13:23:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ast_free(optiontabs); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse a <enumlist> node. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param fixnode As ast_xml pointer to the <enumlist> node. | 
					
						
							|  |  |  |  * \param buffer The ast_str output buffer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval 0 if no <enumlist> node was parsed. | 
					
						
							|  |  |  |  * \retval 1 if a <enumlist> node was parsed. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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 = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { | 
					
						
							|  |  |  | 		if (strcasecmp(ast_xml_node_get_name(node), "enum")) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		enumname = ast_xml_get_attribute(node, "name"); | 
					
						
							|  |  |  | 		if (enumname) { | 
					
						
							|  |  |  | 			ast_str_append(buffer, 0, "%s<enum>%s</enum>", tabs, enumname); | 
					
						
							|  |  |  | 			ast_xml_free_attr(enumname); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* parse only enum elements inside a enumlist node. */ | 
					
						
							|  |  |  | 			if ((xmldoc_parse_enum(node, tabs, buffer))) { | 
					
						
							|  |  |  | 				ret = 1; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				ast_str_append(buffer, 0, "\n"); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse an <option> node. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param fixnode An ast_xml pointer to the <option> node. | 
					
						
							|  |  |  |  * \param tabs A string to be appended at the begining of each line being added to the | 
					
						
							|  |  |  |  *             buffer string. | 
					
						
							|  |  |  |  * \param buffer The output buffer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval 0 if no option node is parsed. | 
					
						
							|  |  |  |  * \retval 1 if an option node is parsed. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-21 21:01:11 +00:00
										 |  |  | 	if (ast_asprintf(&optiontabs, "%s    ", tabs) < 0) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	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 && ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 				/* print \n */ | 
					
						
							|  |  |  | 				ast_str_append(buffer, 0, "\n"); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (xmldoc_parse_argument(node, 0, NULL, optiontabs, buffer)) { | 
					
						
							|  |  |  | 				ret = 1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-19 22:17:13 +00:00
										 |  |  | 		if (xmldoc_parse_common_elements(node, (ret ? tabs :  ""), "\n", buffer)) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			ret = 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		xmldoc_parse_variablelist(node, optiontabs, buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		xmldoc_parse_enumlist(node, optiontabs, buffer); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ast_free(optiontabs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse an <optionlist> element from the xml documentation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param fixnode Pointer to the optionlist xml node. | 
					
						
							|  |  |  |  * \param tabs A string to be appended at the begining of each line being added to the | 
					
						
							|  |  |  |  *             buffer string. | 
					
						
							|  |  |  |  * \param buffer Output buffer to put what is inside the optionlist tag. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static void xmldoc_parse_optionlist(struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *node; | 
					
						
							| 
									
										
										
										
											2008-11-13 15:46:06 +00:00
										 |  |  | 	const char *optname, *hasparams; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	char *optionsyntax; | 
					
						
							| 
									
										
										
										
											2008-11-13 15:46:06 +00:00
										 |  |  | 	int optparams; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) { | 
					
						
							|  |  |  | 		/* Start appending every option tag. */ | 
					
						
							|  |  |  | 		if (strcasecmp(ast_xml_node_get_name(node), "option")) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Get the option name. */ | 
					
						
							|  |  |  | 		optname = ast_xml_get_attribute(node, "name"); | 
					
						
							|  |  |  | 		if (!optname) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-13 15:46:06 +00:00
										 |  |  | 		optparams = 1; | 
					
						
							|  |  |  | 		hasparams = ast_xml_get_attribute(node, "hasparams"); | 
					
						
							|  |  |  | 		if (hasparams && !strcasecmp(hasparams, "optional")) { | 
					
						
							|  |  |  | 			optparams = 2; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		optionsyntax = xmldoc_get_syntax_fun(node, optname, "argument", 0, optparams); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		if (!optionsyntax) { | 
					
						
							| 
									
										
										
										
											2008-11-13 15:46:06 +00:00
										 |  |  | 			ast_xml_free_attr(optname); | 
					
						
							|  |  |  | 			ast_xml_free_attr(hasparams); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ast_str_append(buffer, 0, "%s%s: ", tabs, optionsyntax); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!xmldoc_parse_option(node, tabs, buffer)) { | 
					
						
							|  |  |  | 			ast_str_append(buffer, 0, "\n"); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-08-15 11:25:11 +00:00
										 |  |  | 		ast_str_append(buffer, 0, "\n"); | 
					
						
							| 
									
										
										
										
											2008-11-13 15:46:06 +00:00
										 |  |  | 		ast_xml_free_attr(optname); | 
					
						
							|  |  |  | 		ast_xml_free_attr(hasparams); | 
					
						
							| 
									
										
										
										
											2012-05-18 14:43:44 +00:00
										 |  |  | 		ast_free(optionsyntax); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse a 'parameter' tag inside a syntax element. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param fixnode A pointer to the 'parameter' xml node. | 
					
						
							|  |  |  |  * \param tabs A string to be appended at the beginning of each line being printed inside | 
					
						
							|  |  |  |  *             'buffer'. | 
					
						
							|  |  |  |  * \param buffer String buffer to put values found inside the parameter element. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static void xmldoc_parse_parameter(struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *paramname; | 
					
						
							|  |  |  | 	struct ast_xml_node *node = fixnode; | 
					
						
							|  |  |  | 	int hasarguments, printed = 0; | 
					
						
							|  |  |  | 	char *internaltabs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (strcasecmp(ast_xml_node_get_name(node), "parameter")) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-13 13:53:13 +00:00
										 |  |  | 	hasarguments = xmldoc_has_inside(node, "argument"); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	if (!(paramname = ast_xml_get_attribute(node, "name"))) { | 
					
						
							|  |  |  | 		/* parameter MUST have an attribute name. */ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-21 21:01:11 +00:00
										 |  |  | 	if (ast_asprintf(&internaltabs, "%s    ", tabs) < 0) { | 
					
						
							|  |  |  | 		ast_xml_free_attr(paramname); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-08 04:23:50 +00:00
										 |  |  | 	if (!hasarguments && xmldoc_has_nodes(node)) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		ast_str_append(buffer, 0, "%s\n", paramname); | 
					
						
							|  |  |  | 		ast_xml_free_attr(paramname); | 
					
						
							|  |  |  | 		printed = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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(ast_xml_node_get_name(node), "enumlist")) { | 
					
						
							|  |  |  | 			xmldoc_parse_enumlist(node, internaltabs, buffer); | 
					
						
							|  |  |  | 		} else if (!strcasecmp(ast_xml_node_get_name(node), "argument")) { | 
					
						
							|  |  |  | 			xmldoc_parse_argument(node, 1, internaltabs, (!hasarguments ? "        " : ""), buffer); | 
					
						
							|  |  |  | 		} 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); | 
					
						
							|  |  |  | 				printed = 1; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-05-10 18:35:14 +00:00
										 |  |  | 			if (xmldoc_parse_para(node, internaltabs, "\n", buffer)) { | 
					
						
							|  |  |  | 				/* If anything ever goes in below this condition before the continue below,
 | 
					
						
							|  |  |  | 				 * we should probably continue immediately. */ | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2012-07-19 22:17:13 +00:00
										 |  |  | 		} else if (!strcasecmp(ast_xml_node_get_name(node), "info")) { | 
					
						
							|  |  |  | 			if (!printed) { | 
					
						
							|  |  |  | 				ast_str_append(buffer, 0, "%s\n", paramname); | 
					
						
							|  |  |  | 				ast_xml_free_attr(paramname); | 
					
						
							|  |  |  | 				printed = 1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (xmldoc_parse_info(node, internaltabs, "\n", buffer)) { | 
					
						
							|  |  |  | 				/* If anything ever goes in below this condition before the continue below,
 | 
					
						
							|  |  |  | 				 * we should probably continue immediately. */ | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		} else if ((xmldoc_parse_specialtags(node, internaltabs, "\n", buffer))) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-08 04:23:50 +00:00
										 |  |  | 	if (!printed) { | 
					
						
							|  |  |  | 		ast_xml_free_attr(paramname); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	ast_free(internaltabs); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-11 13:06:30 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Parse an 'info' tag inside an element. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param node A pointer to the 'info' xml node. | 
					
						
							|  |  |  |  * \param tabs A string to be appended at the beginning of each line being printed | 
					
						
							|  |  |  |  *             inside 'buffer' | 
					
						
							|  |  |  |  * \param posttabs Add this string after the content of the <para> element, if one exists | 
					
						
							|  |  |  |  * \param String buffer to put values found inide the info element. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval 2 if the information contained a para element, and it returned a value of 2 | 
					
						
							|  |  |  |  * \retval 1 if information was put into the buffer | 
					
						
							|  |  |  |  * \retval 0 if no information was put into the buffer or error | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int xmldoc_parse_info(struct ast_xml_node *node, const char *tabs, const char *posttabs, struct ast_str **buffer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *tech; | 
					
						
							|  |  |  | 	char *internaltabs; | 
					
						
							|  |  |  | 	int internal_ret; | 
					
						
							|  |  |  | 	int ret = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (strcasecmp(ast_xml_node_get_name(node), "info")) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_asprintf(&internaltabs, "%s    ", tabs); | 
					
						
							|  |  |  | 	if (!internaltabs) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tech = ast_xml_get_attribute(node, "tech"); | 
					
						
							|  |  |  | 	if (tech) { | 
					
						
							|  |  |  | 		ast_str_append(buffer, 0, "%s<note>Technology: %s</note>\n", internaltabs, tech); | 
					
						
							|  |  |  | 		ast_xml_free_attr(tech); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { | 
					
						
							|  |  |  | 		if (!strcasecmp(ast_xml_node_get_name(node), "enumlist")) { | 
					
						
							|  |  |  | 			xmldoc_parse_enumlist(node, internaltabs, buffer); | 
					
						
							|  |  |  | 		} else if (!strcasecmp(ast_xml_node_get_name(node), "parameter")) { | 
					
						
							|  |  |  | 			xmldoc_parse_parameter(node, internaltabs, buffer); | 
					
						
							|  |  |  | 		} else if ((internal_ret = xmldoc_parse_common_elements(node, internaltabs, posttabs, buffer))) { | 
					
						
							|  |  |  | 			if (internal_ret > ret) { | 
					
						
							|  |  |  | 				ret = internal_ret; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ast_free(internaltabs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Build the arguments for an item | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \param node	The arguments node to parse | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note This method exists for when you already have the node.  This | 
					
						
							|  |  |  |  * prevents having to lock the documentation tree twice | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * \retval A malloc'd character pointer to the arguments for the item | 
					
						
							|  |  |  |  * \retval NULL on failure | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \since 11 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static char *_ast_xmldoc_build_arguments(struct ast_xml_node *node) | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *retstr = NULL; | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 	struct ast_str *ret; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 	ret = ast_str_create(128); | 
					
						
							|  |  |  | 	if (!ret) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Find the syntax field. */ | 
					
						
							|  |  |  | 	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 || !ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 		/* We couldn't find the syntax node. */ | 
					
						
							| 
									
										
										
										
											2012-05-18 14:43:44 +00:00
										 |  |  | 		ast_free(ret); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { | 
					
						
							|  |  |  | 		xmldoc_parse_parameter(node, "", &ret); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 	if (ast_str_strlen(ret) > 0) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		/* remove last '\n' */ | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 		char *buf = ast_str_buffer(ret); | 
					
						
							|  |  |  | 		if (buf[ast_str_strlen(ret) - 1] == '\n') { | 
					
						
							|  |  |  | 			ast_str_truncate(ret, -1); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 		retstr = ast_strdup(ast_str_buffer(ret)); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	ast_free(ret); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return retstr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | char *ast_xmldoc_build_arguments(const char *type, const char *name, const char *module) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *node; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_strlen_zero(type) || ast_strlen_zero(name)) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	node = xmldoc_get_node(type, name, module, documentation_language); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!node || !ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return _ast_xmldoc_build_arguments(node); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Return the string within a node formatted with <para> and <variablelist> elements. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param node Parent node where content resides. | 
					
						
							|  |  |  |  * \param raw If set, return the node's content without further processing. | 
					
						
							|  |  |  |  * \param raw_wrap Wrap raw text. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval NULL on error | 
					
						
							|  |  |  |  * \retval Node content on success. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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; | 
					
						
							| 
									
										
										
										
											2012-08-17 20:52:43 +00:00
										 |  |  | 	struct ast_str *ret; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (raw_output) { | 
					
						
							| 
									
										
										
										
											2012-08-17 20:52:43 +00:00
										 |  |  | 		/* xmldoc_string_cleanup will allocate the ret object */ | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		notcleanret = ast_xml_get_text(node); | 
					
						
							|  |  |  | 		tmpstr = notcleanret; | 
					
						
							| 
									
										
										
										
											2014-07-31 11:49:40 +00:00
										 |  |  | 		xmldoc_string_cleanup(ast_skip_blanks(notcleanret), &ret, 0, 0); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		ast_xml_free_text(tmpstr); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2012-08-17 20:52:43 +00:00
										 |  |  | 		ret = ast_str_create(128); | 
					
						
							| 
									
										
										
										
											2015-03-17 22:15:42 +00:00
										 |  |  | 		if (!ret) { | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) { | 
					
						
							| 
									
										
										
										
											2014-07-31 11:49:40 +00:00
										 |  |  | 			/* if found, parse children elements. */ | 
					
						
							| 
									
										
										
										
											2012-07-19 22:17:13 +00:00
										 |  |  | 			if (xmldoc_parse_common_elements(tmp, "", "\n", &ret)) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-07-31 11:49:40 +00:00
										 |  |  | 			if (xmldoc_parse_variablelist(tmp, "", &ret)) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (xmldoc_parse_enumlist(tmp, "    ", &ret)) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (xmldoc_parse_specialtags(tmp, "", "", &ret)) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		/* remove last '\n' */ | 
					
						
							|  |  |  | 		/* XXX Don't modify ast_str internals manually */ | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 		tmpstr = ast_str_buffer(ret); | 
					
						
							|  |  |  | 		if (tmpstr[ast_str_strlen(ret) - 1] == '\n') { | 
					
						
							|  |  |  | 			ast_str_truncate(ret, -1); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | /*!
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Get the content of a field (synopsis, description, etc) from an asterisk document tree node | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param node The node to obtain the information from | 
					
						
							|  |  |  |  * \param var Name of field to return (synopsis, description, etc). | 
					
						
							|  |  |  |  * \param raw Field only contains text, no other elements inside it. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval NULL On error. | 
					
						
							|  |  |  |  * \retval Field text content on success. | 
					
						
							|  |  |  |  * \since 11 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static char *_xmldoc_build_field(struct ast_xml_node *node, const char *var, int raw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *ret = NULL; | 
					
						
							|  |  |  | 	struct ast_str *formatted; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	node = ast_xml_find_element(ast_xml_node_get_children(node), var, NULL, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!node || !ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	formatted = xmldoc_get_formatted(node, raw, raw); | 
					
						
							| 
									
										
										
										
											2015-03-17 22:15:42 +00:00
										 |  |  | 	if (formatted && ast_str_strlen(formatted) > 0) { | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 		ret = ast_strdup(ast_str_buffer(formatted)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ast_free(formatted); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | /*!
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * \internal | 
					
						
							| 
									
										
										
										
											2012-09-22 20:43:30 +00:00
										 |  |  |  * \brief Get the content of a field (synopsis, description, etc) from an asterisk document tree | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-09-22 20:43:30 +00:00
										 |  |  |  * \param type Type of element (application, function, ...). | 
					
						
							|  |  |  |  * \param name Name of element (Dial, Echo, Playback, ...). | 
					
						
							|  |  |  |  * \param var Name of field to return (synopsis, description, etc). | 
					
						
							|  |  |  |  * \param module | 
					
						
							|  |  |  |  * \param raw Field only contains text, no other elements inside it. | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-09-22 20:43:30 +00:00
										 |  |  |  * \retval NULL On error. | 
					
						
							|  |  |  |  * \retval Field text content on success. | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | static char *xmldoc_build_field(const char *type, const char *name, const char *module, const char *var, int raw) | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *node; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_strlen_zero(type) || ast_strlen_zero(name)) { | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Tried to look in XML tree with faulty values.\n"); | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | 	node = xmldoc_get_node(type, name, module, documentation_language); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!node) { | 
					
						
							| 
									
										
										
										
											2010-03-17 00:40:51 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Couldn't find %s %s in XML documentation\n", type, name); | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 	return _xmldoc_build_field(node, var, raw); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \brief Build the synopsis for an item | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \param node The synopsis node | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note This method exists for when you already have the node.  This | 
					
						
							|  |  |  |  * prevents having to lock the documentation tree twice | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * \retval A malloc'd character pointer to the synopsis information | 
					
						
							|  |  |  |  * \retval NULL on failure | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \since 11 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static char *_ast_xmldoc_build_synopsis(struct ast_xml_node *node) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return _xmldoc_build_field(node, "synopsis", 1); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | char *ast_xmldoc_build_synopsis(const char *type, const char *name, const char *module) | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | 	return xmldoc_build_field(type, name, module, "synopsis", 1); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Build the descripton for an item | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \param node	The description node to parse | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note This method exists for when you already have the node.  This | 
					
						
							|  |  |  |  * prevents having to lock the documentation tree twice | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * \retval A malloc'd character pointer to the arguments for the item | 
					
						
							|  |  |  |  * \retval NULL on failure | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \since 11 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static char *_ast_xmldoc_build_description(struct ast_xml_node *node) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return _xmldoc_build_field(node, "description", 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | char *ast_xmldoc_build_description(const char *type, const char *name, const char *module) | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:16:27 +00:00
										 |  |  | 	return xmldoc_build_field(type, name, module, "description", 0); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief ast_xml_doc_item ao2 destructor | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \since 11 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void ast_xml_doc_item_destructor(void *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_doc_item *doc = obj; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!doc) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_free(doc->syntax); | 
					
						
							|  |  |  | 	ast_free(doc->seealso); | 
					
						
							|  |  |  | 	ast_free(doc->arguments); | 
					
						
							|  |  |  | 	ast_free(doc->synopsis); | 
					
						
							|  |  |  | 	ast_free(doc->description); | 
					
						
							|  |  |  | 	ast_string_field_free_memory(doc); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | 	if (AST_LIST_NEXT(doc, next)) { | 
					
						
							|  |  |  | 		ao2_ref(AST_LIST_NEXT(doc, next), -1); | 
					
						
							|  |  |  | 		AST_LIST_NEXT(doc, next) = NULL; | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \brief Create an ao2 ref counted ast_xml_doc_item | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \param name The name of the item | 
					
						
							|  |  |  |  * \param type The item's source type | 
					
						
							|  |  |  |  * \since 11 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static struct ast_xml_doc_item *ast_xml_doc_item_alloc(const char *name, const char *type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_doc_item *item; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(item = ao2_alloc(sizeof(*item), ast_xml_doc_item_destructor))) { | 
					
						
							|  |  |  | 		ast_log(AST_LOG_ERROR, "Failed to allocate memory for ast_xml_doc_item instance\n"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (   !(item->syntax = ast_str_create(128)) | 
					
						
							|  |  |  | 		|| !(item->seealso = ast_str_create(128)) | 
					
						
							|  |  |  | 		|| !(item->arguments = ast_str_create(128)) | 
					
						
							|  |  |  | 		|| !(item->synopsis = ast_str_create(128)) | 
					
						
							|  |  |  | 		|| !(item->description = ast_str_create(128))) { | 
					
						
							|  |  |  | 		ast_log(AST_LOG_ERROR, "Failed to allocate strings for ast_xml_doc_item instance\n"); | 
					
						
							|  |  |  | 		goto ast_xml_doc_item_failure; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_string_field_init(item, 64)) { | 
					
						
							|  |  |  | 		ast_log(AST_LOG_ERROR, "Failed to initialize string field for ast_xml_doc_item instance\n"); | 
					
						
							|  |  |  | 		goto ast_xml_doc_item_failure; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ast_string_field_set(item, name, name); | 
					
						
							|  |  |  | 	ast_string_field_set(item, type, type); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return item; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ast_xml_doc_item_failure: | 
					
						
							|  |  |  | 	ao2_ref(item, -1); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \brief ao2 item hash function for ast_xml_doc_item | 
					
						
							|  |  |  |  * \since 11 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int ast_xml_doc_item_hash(const void *obj, const int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const struct ast_xml_doc_item *item = obj; | 
					
						
							|  |  |  | 	const char *name = (flags & OBJ_KEY) ? obj : item->name; | 
					
						
							|  |  |  | 	return ast_str_case_hash(name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \brief ao2 item comparison function for ast_xml_doc_item | 
					
						
							|  |  |  |  * \since 11 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int ast_xml_doc_item_cmp(void *obj, void *arg, int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_doc_item *left = obj; | 
					
						
							|  |  |  | 	struct ast_xml_doc_item *right = arg; | 
					
						
							|  |  |  | 	const char *match = (flags & OBJ_KEY) ? arg : right->name; | 
					
						
							|  |  |  | 	return strcasecmp(left->name, match) ? 0 : (CMP_MATCH | CMP_STOP); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \brief Build an XML documentation item | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \param node The root node for the item | 
					
						
							|  |  |  |  * \param name The name of the item | 
					
						
							|  |  |  |  * \param type The item's source type | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-08-16 17:33:21 +00:00
										 |  |  |  * \retval NULL on failure | 
					
						
							|  |  |  |  * \retval An ao2 ref counted object | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  |  * \since 11 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static struct ast_xml_doc_item *xmldoc_build_documentation_item(struct ast_xml_node *node, const char *name, const char *type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_doc_item *item; | 
					
						
							|  |  |  | 	char *syntax; | 
					
						
							|  |  |  | 	char *seealso; | 
					
						
							|  |  |  | 	char *arguments; | 
					
						
							|  |  |  | 	char *synopsis; | 
					
						
							|  |  |  | 	char *description; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(item = ast_xml_doc_item_alloc(name, type))) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 	item->node = node; | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	syntax = _ast_xmldoc_build_syntax(node, type, name); | 
					
						
							|  |  |  | 	seealso = _ast_xmldoc_build_seealso(node); | 
					
						
							|  |  |  | 	arguments = _ast_xmldoc_build_arguments(node); | 
					
						
							|  |  |  | 	synopsis = _ast_xmldoc_build_synopsis(node); | 
					
						
							|  |  |  | 	description = _ast_xmldoc_build_description(node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (syntax) { | 
					
						
							|  |  |  | 		ast_str_set(&item->syntax, 0, "%s", syntax); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (seealso) { | 
					
						
							|  |  |  | 		ast_str_set(&item->seealso, 0, "%s", seealso); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (arguments) { | 
					
						
							|  |  |  | 		ast_str_set(&item->arguments, 0, "%s", arguments); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (synopsis) { | 
					
						
							|  |  |  | 		ast_str_set(&item->synopsis, 0, "%s", synopsis); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (description) { | 
					
						
							|  |  |  | 		ast_str_set(&item->description, 0, "%s", description); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_free(syntax); | 
					
						
							|  |  |  | 	ast_free(seealso); | 
					
						
							|  |  |  | 	ast_free(arguments); | 
					
						
							|  |  |  | 	ast_free(synopsis); | 
					
						
							|  |  |  | 	ast_free(description); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return item; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Build the list responses for an item | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param manager_action The action node to parse | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note This method exists for when you already have the node.  This | 
					
						
							|  |  |  |  * prevents having to lock the documentation tree twice | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval A list of ast_xml_doc_items | 
					
						
							|  |  |  |  * \retval NULL on failure | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \since 13.0.0 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static struct ast_xml_doc_item *xmldoc_build_list_responses(struct ast_xml_node *manager_action) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *event; | 
					
						
							|  |  |  | 	struct ast_xml_node *responses; | 
					
						
							|  |  |  | 	struct ast_xml_node *list_elements; | 
					
						
							|  |  |  | 	struct ast_xml_doc_item_list root; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	AST_LIST_HEAD_INIT(&root); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	responses = ast_xml_find_element(ast_xml_node_get_children(manager_action), "responses", NULL, NULL); | 
					
						
							|  |  |  | 	if (!responses) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list_elements = ast_xml_find_element(ast_xml_node_get_children(responses), "list-elements", NULL, NULL); | 
					
						
							|  |  |  | 	if (!list_elements) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Iterate over managerEvent nodes */ | 
					
						
							|  |  |  | 	for (event = ast_xml_node_get_children(list_elements); event; event = ast_xml_node_get_next(event)) { | 
					
						
							|  |  |  | 		struct ast_xml_node *event_instance; | 
					
						
							| 
									
										
										
										
											2015-01-30 16:49:59 +00:00
										 |  |  | 		RAII_VAR(const char *, name, ast_xml_get_attribute(event, "name"), | 
					
						
							|  |  |  | 			ast_xml_free_attr); | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | 		struct ast_xml_doc_item *new_item; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!name || strcmp(ast_xml_node_get_name(event), "managerEvent")) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		event_instance = ast_xml_find_element(ast_xml_node_get_children(event), | 
					
						
							|  |  |  | 			"managerEventInstance", NULL, NULL); | 
					
						
							|  |  |  | 		new_item = xmldoc_build_documentation_item(event_instance, name, "managerEvent"); | 
					
						
							|  |  |  | 		if (!new_item) { | 
					
						
							|  |  |  | 			ao2_cleanup(AST_LIST_FIRST(&root)); | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		AST_LIST_INSERT_TAIL(&root, new_item, next); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return AST_LIST_FIRST(&root); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct ast_xml_doc_item *ast_xmldoc_build_list_responses(const char *type, const char *name, const char *module) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *node; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_strlen_zero(type) || ast_strlen_zero(name)) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	node = xmldoc_get_node(type, name, module, documentation_language); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!node || !ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return xmldoc_build_list_responses(node); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Build the final response for an item | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param manager_action The action node to parse | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note This method exists for when you already have the node.  This | 
					
						
							|  |  |  |  * prevents having to lock the documentation tree twice | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval An ast_xml_doc_item | 
					
						
							|  |  |  |  * \retval NULL on failure | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \since 13.0.0 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static struct ast_xml_doc_item *xmldoc_build_final_response(struct ast_xml_node *manager_action) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *responses; | 
					
						
							|  |  |  | 	struct ast_xml_node *final_response_event; | 
					
						
							|  |  |  | 	struct ast_xml_node *event_instance; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	responses = ast_xml_find_element(ast_xml_node_get_children(manager_action), | 
					
						
							|  |  |  | 		"responses", NULL, NULL); | 
					
						
							|  |  |  | 	if (!responses) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	final_response_event = ast_xml_find_element(ast_xml_node_get_children(responses), | 
					
						
							|  |  |  | 		"managerEvent", NULL, NULL); | 
					
						
							|  |  |  | 	if (!final_response_event) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	event_instance = ast_xml_find_element(ast_xml_node_get_children(final_response_event), | 
					
						
							|  |  |  | 		"managerEventInstance", NULL, NULL); | 
					
						
							|  |  |  | 	if (!event_instance) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2015-01-30 16:49:59 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		const char *name; | 
					
						
							|  |  |  | 		struct ast_xml_doc_item *res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		name = ast_xml_get_attribute(final_response_event, "name"); | 
					
						
							|  |  |  | 		res = xmldoc_build_documentation_item(event_instance, name, "managerEvent"); | 
					
						
							|  |  |  | 		ast_xml_free_attr(name); | 
					
						
							|  |  |  | 		return res; | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct ast_xml_doc_item *ast_xmldoc_build_final_response(const char *type, const char *name, const char *module) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *node; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_strlen_zero(type) || ast_strlen_zero(name)) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	node = xmldoc_get_node(type, name, module, documentation_language); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!node || !ast_xml_node_get_children(node)) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return xmldoc_build_final_response(node); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | struct ast_xml_xpath_results *__attribute__((format(printf, 1, 2))) ast_xmldoc_query(const char *fmt, ...) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_xpath_results *results = NULL; | 
					
						
							|  |  |  | 	struct documentation_tree *doctree; | 
					
						
							|  |  |  | 	RAII_VAR(struct ast_str *, xpath_str, ast_str_create(128), ast_free); | 
					
						
							|  |  |  | 	va_list ap; | 
					
						
							| 
									
										
										
										
											2015-10-19 15:27:40 -05:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!xpath_str) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	va_start(ap, fmt); | 
					
						
							| 
									
										
										
										
											2015-10-19 15:27:40 -05:00
										 |  |  | 	res = ast_str_set_va(&xpath_str, 0, fmt, ap); | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 	va_end(ap); | 
					
						
							| 
									
										
										
										
											2015-10-19 15:27:40 -05:00
										 |  |  | 	if (res == AST_DYNSTR_BUILD_FAILED) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	AST_RWLIST_RDLOCK(&xmldoc_tree); | 
					
						
							|  |  |  | 	AST_LIST_TRAVERSE(&xmldoc_tree, doctree, entry) { | 
					
						
							|  |  |  | 		if (!(results = ast_xml_query(doctree->doc, ast_str_buffer(xpath_str)))) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	AST_RWLIST_UNLOCK(&xmldoc_tree); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return results; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | static void build_config_docs(struct ast_xml_node *cur, struct ast_xml_doc_item_list *root) | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *iter; | 
					
						
							|  |  |  | 	struct ast_xml_doc_item *item; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (iter = ast_xml_node_get_children(cur); iter; iter = ast_xml_node_get_next(iter)) { | 
					
						
							| 
									
										
										
										
											2013-03-07 16:21:52 +00:00
										 |  |  | 		const char *iter_name; | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 		if (strncasecmp(ast_xml_node_get_name(iter), "config", 6)) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-03-07 16:21:52 +00:00
										 |  |  | 		iter_name = ast_xml_get_attribute(iter, "name"); | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 		/* Now add all of the child config-related items to the list */ | 
					
						
							| 
									
										
										
										
											2013-03-07 16:21:52 +00:00
										 |  |  | 		if (!(item = xmldoc_build_documentation_item(iter, iter_name, ast_xml_node_get_name(iter)))) { | 
					
						
							|  |  |  | 			ast_log(LOG_ERROR, "Could not build documentation for '%s:%s'\n", ast_xml_node_get_name(iter), iter_name); | 
					
						
							|  |  |  | 			ast_xml_free_attr(iter_name); | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-03-07 16:21:52 +00:00
										 |  |  | 		ast_xml_free_attr(iter_name); | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 		if (!strcasecmp(ast_xml_node_get_name(iter), "configOption")) { | 
					
						
							| 
									
										
										
										
											2013-03-07 16:21:52 +00:00
										 |  |  | 			const char *name = ast_xml_get_attribute(cur, "name"); | 
					
						
							|  |  |  | 			ast_string_field_set(item, ref, name); | 
					
						
							|  |  |  | 			ast_xml_free_attr(name); | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | 		AST_LIST_INSERT_TAIL(root, item, next); | 
					
						
							|  |  |  | 		build_config_docs(iter, root); | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int ast_xmldoc_regenerate_doc_item(struct ast_xml_doc_item *item) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *name; | 
					
						
							|  |  |  | 	char *syntax; | 
					
						
							|  |  |  | 	char *seealso; | 
					
						
							|  |  |  | 	char *arguments; | 
					
						
							|  |  |  | 	char *synopsis; | 
					
						
							|  |  |  | 	char *description; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!item || !item->node) { | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	name = ast_xml_get_attribute(item->node, "name"); | 
					
						
							|  |  |  | 	if (!name) { | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	syntax = _ast_xmldoc_build_syntax(item->node, item->type, name); | 
					
						
							|  |  |  | 	seealso = _ast_xmldoc_build_seealso(item->node); | 
					
						
							|  |  |  | 	arguments = _ast_xmldoc_build_arguments(item->node); | 
					
						
							|  |  |  | 	synopsis = _ast_xmldoc_build_synopsis(item->node); | 
					
						
							|  |  |  | 	description = _ast_xmldoc_build_description(item->node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (syntax) { | 
					
						
							|  |  |  | 		ast_str_set(&item->syntax, 0, "%s", syntax); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (seealso) { | 
					
						
							|  |  |  | 		ast_str_set(&item->seealso, 0, "%s", seealso); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (arguments) { | 
					
						
							|  |  |  | 		ast_str_set(&item->arguments, 0, "%s", arguments); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (synopsis) { | 
					
						
							|  |  |  | 		ast_str_set(&item->synopsis, 0, "%s", synopsis); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (description) { | 
					
						
							|  |  |  | 		ast_str_set(&item->description, 0, "%s", description); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_free(syntax); | 
					
						
							|  |  |  | 	ast_free(seealso); | 
					
						
							|  |  |  | 	ast_free(arguments); | 
					
						
							|  |  |  | 	ast_free(synopsis); | 
					
						
							|  |  |  | 	ast_free(description); | 
					
						
							|  |  |  | 	ast_xml_free_attr(name); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | struct ao2_container *ast_xmldoc_build_documentation(const char *type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ao2_container *docs; | 
					
						
							|  |  |  | 	struct ast_xml_node *node = NULL, *instance = NULL; | 
					
						
							|  |  |  | 	struct documentation_tree *doctree; | 
					
						
							|  |  |  | 	const char *name; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(docs = ao2_container_alloc(127, ast_xml_doc_item_hash, ast_xml_doc_item_cmp))) { | 
					
						
							|  |  |  | 		ast_log(AST_LOG_ERROR, "Failed to create container for xml document item instances\n"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	AST_RWLIST_RDLOCK(&xmldoc_tree); | 
					
						
							|  |  |  | 	AST_LIST_TRAVERSE(&xmldoc_tree, doctree, entry) { | 
					
						
							|  |  |  | 		/* the core xml documents have priority over thirdparty document. */ | 
					
						
							|  |  |  | 		node = ast_xml_get_root(doctree->doc); | 
					
						
							|  |  |  | 		if (!node) { | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | 			struct ast_xml_doc_item *item = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 			/* Ignore empty nodes or nodes that aren't of the type requested */ | 
					
						
							|  |  |  | 			if (!ast_xml_node_get_children(node) || strcasecmp(ast_xml_node_get_name(node), type)) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			name = ast_xml_get_attribute(node, "name"); | 
					
						
							| 
									
										
										
										
											2012-11-04 00:48:24 +00:00
										 |  |  | 			if (!name) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			switch (xmldoc_get_syntax_type(type)) { | 
					
						
							|  |  |  | 			case MANAGER_EVENT_SYNTAX: | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				struct ast_xml_doc_item_list root; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				AST_LIST_HEAD_INIT(&root); | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 				for (instance = ast_xml_node_get_children(node); instance; instance = ast_xml_node_get_next(instance)) { | 
					
						
							|  |  |  | 					struct ast_xml_doc_item *temp; | 
					
						
							|  |  |  | 					if (!ast_xml_node_get_children(instance) || strcasecmp(ast_xml_node_get_name(instance), "managerEventInstance")) { | 
					
						
							|  |  |  | 						continue; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					temp = xmldoc_build_documentation_item(instance, name, type); | 
					
						
							|  |  |  | 					if (!temp) { | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | 					AST_LIST_INSERT_TAIL(&root, temp, next); | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | 				item = AST_LIST_FIRST(&root); | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 			case CONFIG_INFO_SYNTAX: | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2013-03-07 16:48:19 +00:00
										 |  |  | 				RAII_VAR(const char *, name, ast_xml_get_attribute(node, "name"), ast_xml_free_attr); | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				if (!ast_xml_node_get_children(node) || strcasecmp(ast_xml_node_get_name(node), "configInfo")) { | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-07-24 13:00:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				item = xmldoc_build_documentation_item(node, name, "configInfo"); | 
					
						
							|  |  |  | 				if (item) { | 
					
						
							|  |  |  | 					struct ast_xml_doc_item_list root; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					AST_LIST_HEAD_INIT(&root); | 
					
						
							|  |  |  | 					AST_LIST_INSERT_TAIL(&root, item, next); | 
					
						
							|  |  |  | 					build_config_docs(node, &root); | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 			default: | 
					
						
							|  |  |  | 				item = xmldoc_build_documentation_item(node, name, type); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-11-04 00:48:24 +00:00
										 |  |  | 			ast_xml_free_attr(name); | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (item) { | 
					
						
							|  |  |  | 				ao2_link(docs, item); | 
					
						
							| 
									
										
										
										
											2012-10-02 01:47:16 +00:00
										 |  |  | 				ao2_t_ref(item, -1, "Dispose of creation ref"); | 
					
						
							| 
									
										
										
										
											2012-06-25 17:59:34 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	AST_RWLIST_UNLOCK(&xmldoc_tree); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return docs; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | int ast_xmldoc_regenerate_doc_item(struct ast_xml_doc_item *item); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 19:45:30 +00:00
										 |  |  | #if !defined(HAVE_GLOB_NOMAGIC) || !defined(HAVE_GLOB_BRACE) || defined(DEBUG_NONGNU)
 | 
					
						
							|  |  |  | static int xml_pathmatch(char *xmlpattern, int xmlpattern_maxlen, glob_t *globbuf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int globret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	snprintf(xmlpattern, xmlpattern_maxlen, "%s/documentation/thirdparty/*-%s.xml", | 
					
						
							|  |  |  | 		ast_config_AST_DATA_DIR, documentation_language); | 
					
						
							|  |  |  | 	if((globret = glob(xmlpattern, GLOB_NOCHECK, NULL, globbuf))) { | 
					
						
							|  |  |  | 		return globret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	snprintf(xmlpattern, xmlpattern_maxlen, "%s/documentation/thirdparty/*-%.2s_??.xml", | 
					
						
							|  |  |  | 		ast_config_AST_DATA_DIR, documentation_language); | 
					
						
							|  |  |  | 	if((globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf))) { | 
					
						
							|  |  |  | 		return globret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	snprintf(xmlpattern, xmlpattern_maxlen, "%s/documentation/thirdparty/*-%s.xml", | 
					
						
							|  |  |  | 		ast_config_AST_DATA_DIR, default_documentation_language); | 
					
						
							|  |  |  | 	if((globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf))) { | 
					
						
							|  |  |  | 		return globret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	snprintf(xmlpattern, xmlpattern_maxlen, "%s/documentation/*-%s.xml", | 
					
						
							|  |  |  | 		ast_config_AST_DATA_DIR, documentation_language); | 
					
						
							|  |  |  | 	if((globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf))) { | 
					
						
							|  |  |  | 		return globret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	snprintf(xmlpattern, xmlpattern_maxlen, "%s/documentation/*-%.2s_??.xml", | 
					
						
							|  |  |  | 		ast_config_AST_DATA_DIR, documentation_language); | 
					
						
							|  |  |  | 	if((globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf))) { | 
					
						
							|  |  |  | 		return globret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	snprintf(xmlpattern, xmlpattern_maxlen, "%s/documentation/*-%s.xml", | 
					
						
							|  |  |  | 		ast_config_AST_DATA_DIR, default_documentation_language); | 
					
						
							|  |  |  | 	globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return globret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | static char *handle_dump_docs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct documentation_tree *doctree; | 
					
						
							|  |  |  | 	FILE *f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (cmd) { | 
					
						
							|  |  |  | 	case CLI_INIT: | 
					
						
							|  |  |  | 		e->command = "xmldoc dump"; | 
					
						
							|  |  |  | 		e->usage = | 
					
						
							|  |  |  | 			"Usage: xmldoc dump <filename>\n" | 
					
						
							|  |  |  | 			"  Dump XML documentation to a file\n"; | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	case CLI_GENERATE: | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (a->argc != 3) { | 
					
						
							|  |  |  | 		return CLI_SHOWUSAGE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!(f = fopen(a->argv[2], "w"))) { | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Could not open file '%s': %s\n", a->argv[2], strerror(errno)); | 
					
						
							|  |  |  | 		return CLI_FAILURE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	AST_RWLIST_RDLOCK(&xmldoc_tree); | 
					
						
							|  |  |  | 	AST_LIST_TRAVERSE(&xmldoc_tree, doctree, entry) { | 
					
						
							|  |  |  | 		ast_xml_doc_dump_file(f, doctree->doc); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	AST_RWLIST_UNLOCK(&xmldoc_tree); | 
					
						
							|  |  |  | 	fclose(f); | 
					
						
							|  |  |  | 	return CLI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ast_cli_entry cli_dump_xmldocs = AST_CLI_DEFINE(handle_dump_docs, "Dump the XML docs to the specified file"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | /*! \brief Close and unload XML documentation. */ | 
					
						
							|  |  |  | static void xmldoc_unload_documentation(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-04 00:48:24 +00:00
										 |  |  | 	struct documentation_tree *doctree; | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 	ast_cli_unregister(&cli_dump_xmldocs); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	AST_RWLIST_WRLOCK(&xmldoc_tree); | 
					
						
							|  |  |  | 	while ((doctree = AST_RWLIST_REMOVE_HEAD(&xmldoc_tree, entry))) { | 
					
						
							|  |  |  | 		ast_free(doctree->filename); | 
					
						
							|  |  |  | 		ast_xml_close(doctree->doc); | 
					
						
							| 
									
										
										
										
											2012-11-04 00:48:24 +00:00
										 |  |  | 		ast_free(doctree); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	AST_RWLIST_UNLOCK(&xmldoc_tree); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_xml_finish(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int ast_xmldoc_load_documentation(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_xml_node *root_node; | 
					
						
							|  |  |  | 	struct ast_xml_doc *tmpdoc; | 
					
						
							|  |  |  | 	struct documentation_tree *doc_tree; | 
					
						
							|  |  |  | 	char *xmlpattern; | 
					
						
							|  |  |  | 	struct ast_config *cfg = NULL; | 
					
						
							|  |  |  | 	struct ast_variable *var = NULL; | 
					
						
							|  |  |  | 	struct ast_flags cnfflags = { 0 }; | 
					
						
							|  |  |  | 	int globret, i, dup, duplicate; | 
					
						
							|  |  |  | 	glob_t globbuf; | 
					
						
							| 
									
										
										
										
											2010-07-22 19:45:30 +00:00
										 |  |  | #if !defined(HAVE_GLOB_NOMAGIC) || !defined(HAVE_GLOB_BRACE) || defined(DEBUG_NONGNU)
 | 
					
						
							|  |  |  | 	int xmlpattern_maxlen; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* setup default XML documentation language */ | 
					
						
							|  |  |  | 	snprintf(documentation_language, sizeof(documentation_language), default_documentation_language); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-19 19:25:14 +00:00
										 |  |  | 	if ((cfg = ast_config_load2("asterisk.conf", "" /* core can't reload */, cnfflags)) && cfg != CONFIG_STATUS_FILEINVALID) { | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		for (var = ast_variable_browse(cfg, "options"); var; var = var->next) { | 
					
						
							|  |  |  | 			if (!strcasecmp(var->name, "documentation_language")) { | 
					
						
							|  |  |  | 				if (!ast_strlen_zero(var->value)) { | 
					
						
							|  |  |  | 					snprintf(documentation_language, sizeof(documentation_language), "%s", var->value); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		ast_config_destroy(cfg); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* initialize the XML library. */ | 
					
						
							|  |  |  | 	ast_xml_init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 13:38:12 +00:00
										 |  |  | 	ast_cli_register(&cli_dump_xmldocs); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	/* register function to be run when asterisk finish. */ | 
					
						
							| 
									
										
										
										
											2015-03-26 22:24:26 +00:00
										 |  |  | 	ast_register_cleanup(xmldoc_unload_documentation); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 19:45:30 +00:00
										 |  |  | 	globbuf.gl_offs = 0;    /* slots to reserve in gl_pathv */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined(HAVE_GLOB_NOMAGIC) || !defined(HAVE_GLOB_BRACE) || defined(DEBUG_NONGNU)
 | 
					
						
							|  |  |  | 	xmlpattern_maxlen = strlen(ast_config_AST_DATA_DIR) + strlen("/documentation/thirdparty") + strlen("/*-??_??.xml") + 1; | 
					
						
							|  |  |  | 	xmlpattern = ast_malloc(xmlpattern_maxlen); | 
					
						
							|  |  |  | 	globret = xml_pathmatch(xmlpattern, xmlpattern_maxlen, &globbuf); | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	/* Get every *-LANG.xml file inside $(ASTDATADIR)/documentation */ | 
					
						
							| 
									
										
										
										
											2012-08-21 21:01:11 +00:00
										 |  |  | 	if (ast_asprintf(&xmlpattern, "%s/documentation{/thirdparty/,/}*-{%s,%.2s_??,%s}.xml", ast_config_AST_DATA_DIR, | 
					
						
							|  |  |  | 		documentation_language, documentation_language, default_documentation_language) < 0) { | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	globret = glob(xmlpattern, MY_GLOB_FLAGS, NULL, &globbuf); | 
					
						
							| 
									
										
										
										
											2010-07-22 19:45:30 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-22 23:11:32 +00:00
										 |  |  | 	ast_debug(3, "gl_pathc %zu\n", (size_t)globbuf.gl_pathc); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 	if (globret == GLOB_NOSPACE) { | 
					
						
							| 
									
										
										
										
											2010-07-22 19:45:30 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "XML load failure, glob expansion of pattern '%s' failed: Not enough memory\n", xmlpattern); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		ast_free(xmlpattern); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} else if (globret  == GLOB_ABORTED) { | 
					
						
							| 
									
										
										
										
											2010-07-22 19:45:30 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "XML load failure, glob expansion of pattern '%s' failed: Read error\n", xmlpattern); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 		ast_free(xmlpattern); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ast_free(xmlpattern); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	AST_RWLIST_WRLOCK(&xmldoc_tree); | 
					
						
							|  |  |  | 	/* loop over expanded files */ | 
					
						
							|  |  |  | 	for (i = 0; i < globbuf.gl_pathc; i++) { | 
					
						
							|  |  |  | 		/* check for duplicates (if we already [try to] open the same file. */ | 
					
						
							|  |  |  | 		duplicate = 0; | 
					
						
							|  |  |  | 		for (dup = 0; dup < i; dup++) { | 
					
						
							|  |  |  | 			if (!strcmp(globbuf.gl_pathv[i], globbuf.gl_pathv[dup])) { | 
					
						
							|  |  |  | 				duplicate = 1; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-07-22 19:45:30 +00:00
										 |  |  | 		if (duplicate || strchr(globbuf.gl_pathv[i], '*')) { | 
					
						
							| 
									
										
										
										
											2012-03-22 19:51:16 +00:00
										 |  |  | 		/* skip duplicates as well as pathnames not found
 | 
					
						
							| 
									
										
										
										
											2010-07-22 19:45:30 +00:00
										 |  |  | 		 * (due to use of GLOB_NOCHECK in xml_pathmatch) */ | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		tmpdoc = NULL; | 
					
						
							|  |  |  | 		tmpdoc = ast_xml_open(globbuf.gl_pathv[i]); | 
					
						
							|  |  |  | 		if (!tmpdoc) { | 
					
						
							|  |  |  | 			ast_log(LOG_ERROR, "Could not open XML documentation at '%s'\n", globbuf.gl_pathv[i]); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* Get doc root node and check if it starts with '<docs>' */ | 
					
						
							|  |  |  | 		root_node = ast_xml_get_root(tmpdoc); | 
					
						
							|  |  |  | 		if (!root_node) { | 
					
						
							| 
									
										
										
										
											2012-04-06 18:19:03 +00:00
										 |  |  | 			ast_log(LOG_ERROR, "Error getting documentation root node\n"); | 
					
						
							| 
									
										
										
										
											2008-11-10 13:53:23 +00:00
										 |  |  | 			ast_xml_close(tmpdoc); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* Check root node name for malformed xmls. */ | 
					
						
							|  |  |  | 		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; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		doc_tree = ast_calloc(1, sizeof(*doc_tree)); | 
					
						
							|  |  |  | 		if (!doc_tree) { | 
					
						
							|  |  |  | 			ast_log(LOG_ERROR, "Unable to allocate documentation_tree structure!\n"); | 
					
						
							|  |  |  | 			ast_xml_close(tmpdoc); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		doc_tree->doc = tmpdoc; | 
					
						
							|  |  |  | 		doc_tree->filename = ast_strdup(globbuf.gl_pathv[i]); | 
					
						
							|  |  |  | 		AST_RWLIST_INSERT_TAIL(&xmldoc_tree, doc_tree, entry); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	AST_RWLIST_UNLOCK(&xmldoc_tree); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	globfree(&globbuf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* AST_XML_DOCS */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |