[asterisk-commits] eliel: branch group/appdocsxml r139337 - in /team/group/appdocsxml: apps/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 21 14:58:08 CDT 2008


Author: eliel
Date: Thu Aug 21 14:58:08 2008
New Revision: 139337

URL: http://svn.digium.com/view/asterisk?view=rev&rev=139337
Log:
- Remove <para> elements inside the <value> node.
- Implement the <optionlist> parsing mechanism.
- Generalize xmldoc_build_syntax() to be used in <option> elements too.
- Fix some string formatting issues.

Modified:
    team/group/appdocsxml/apps/app_dial.c
    team/group/appdocsxml/main/pbx.c

Modified: team/group/appdocsxml/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/apps/app_dial.c?view=diff&rev=139337&r1=139336&r2=139337
==============================================================================
--- team/group/appdocsxml/apps/app_dial.c (original)
+++ team/group/appdocsxml/apps/app_dial.c Thu Aug 21 14:58:08 2008
@@ -221,20 +221,20 @@
 						<variable name="MACRO_RESULT">
 							<para>If set, this action will be taken after the macro finished executing.</para>
 							<value name="ABORT">
-								<para>Hangup both legs of the call</para>
+								Hangup both legs of the call
 							</value>
 							<value name="CONGESTION">
-								<para>Behave as if line congestion was encountered</para>
+								Behave as if line congestion was encountered
 							</value>
 							<value name="BUSY">
-								<para>Behave as if a busy signal was encountered</para>
+								Behave as if a busy signal was encountered<
 							</value>
 							<value name="CONTINUE">
-								<para>Hangup the called party and allow the calling party to continue dialplan execution at the next priority</para>
+								Hangup the called party and allow the calling party to continue dialplan execution at the next priority
 							</value>
 							<!-- TODO: Fix this syntax up, once we've figured out how to specify the GOTO syntax -->
 							<value name="GOTO:&lt;context&gt;^&lt;exten&gt;^&lt;priority&gt;">
-								<para>Transfer the call to the specified destination.</para>
+								Transfer the call to the specified destination.
 							</value>
 						</variable>
 					</variablelist>
@@ -314,23 +314,22 @@
 					<variablelist>
 						<variable name="GOSUB_RESULT">
 							<value name="ABORT">
-								<para>Hangup both legs of the call.</para>
+								Hangup both legs of the call.
 							</value>
 							<value name="CONGESTION">
-								<para>Behave as if line congestion was encountered.</para>
+								Behave as if line congestion was encountered.
 							</value>
 							<value name="BUSY">
-								<para>Behave as if a busy signal was encountered.</para>
+								Behave as if a busy signal was encountered.
 							</value>
 							<value name="CONTINUE">
-								<para>Hangup the called party and allow the calling party
-								to continue dialplan execution at the next priority.</para>
+								Hangup the called party and allow the calling party
+								to continue dialplan execution at the next priority.
 							</value>
 							<!-- TODO: Fix this syntax up, once we've figured out how to specify the GOTO syntax -->
 							<value name="GOTO:&lt;context&gt;^&lt;exten&gt;^&lt;priority&gt;">
-								<para>Transfer the call to the
-								specified priority. Optionally, an extension, or
-								extension and priority can be specified.</para>
+								Transfer the call to the specified priority. Optionally, an extension, or
+								extension and priority can be specified.
 							</value>
 						</variable>
 					</variablelist>

Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=139337&r1=139336&r2=139337
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Thu Aug 21 14:58:08 2008
@@ -2816,7 +2816,7 @@
 #ifdef XML_DOCUMENTATION
 /*! \internal
  *  \brief Calculate the space in bytes used by a format string
- *  that will be passed to a sprintf function.
+ *         that will be passed to a sprintf function.
  *  \param postbr The format string to use to calculate the length.
  *  \retval The postbr length.
  */
@@ -2838,7 +2838,7 @@
 
 /*! \internal
  *  \brief Setup postbr to be used while wrapping the text. 
- *  Add to postbr array all the spaces and tabs at the beginning of the line.
+ *         Add to postbr array all the spaces and tabs at the beginning of the line.
  *  \param postbr output array. 
  *  \param len array length.
  *  \param text Text with format string before the actual string.
@@ -2858,7 +2858,8 @@
 	postbr[postbrlen] = '\0';
 }
 
-/*! \brief Justify a text to a number of columns. 
+/*! \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.
  *  \param maxdiff Try to not cut a word when goinf down.
@@ -2958,7 +2959,7 @@
 
 /*! \internal
  *  \brief Cleanup spaces and tabs after a \n, and skips the spaces at the 
- *  beginning and at the end of the string.
+ *         beginning and at the end of the string.
  *  \param text String to be cleaned up.
  *  \retval NULL on error.
  *  \retval A malloc'ed string with the output.
@@ -3099,43 +3100,41 @@
 } while (0) \
 
 /*! \internal
- *  \brief Build the syntax for an application or a function.
- *  \param type 'application' or 'function' ?
- *  \param name Name of the application or function to build the syntax.
+ *  \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.
  *  \retval NULL on error.
- *  \retval A ast_malloc'ed string with the syntax generated. */
-static char *xmldoc_build_syntax(const char *type, const char *name) 
+ *  \retval An ast_malloc'ed string with the syntax generated. */
+static char *xmldoc_build_syntax(ast_xml_node *rootnode, const char *rootname, const char *childname, int printparenthesis)
 {
 #define GOTONEXT(__rev, __a) (__rev ? __a->AST_XML_PREV : __a->AST_XML_NEXT)
 #define ISLAST(__rev, __a)  (__rev == 1 ? (__a->AST_XML_PREV ? 0 : 1) : (__a->AST_XML_NEXT ? 0 : 1))
 	ast_xml_node *node, *firstparam, *lastparam;
-	ast_xml_attr *paramtype, *paramname;
-	int reverse = 0, required = 0, paramcount = 0, openbrackets = 0, len = 0;
-	char *syntax = NULL;
-
-	if (ast_strlen_zero(type) || ast_strlen_zero(name)) {
-		ast_log(LOG_WARNING, "Tried to look in XML tree with faulty values.\n");
+	ast_xml_attr *paramtype, *paramname, *attrargsep;
+	int reverse = 0, required = 0, paramcount = 0, openbrackets = 0, len = 0, hasparams=0;
+	char *syntax = NULL, *argsep;
+
+	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;
 	}
 
-	node = xmldoc_get_node(documentation_tree, type, name, documentation_language);
+	node = rootnode;
+	
+	/* Get the argument separator from the root node attribute name 'argsep', if not found
+	defaults to ','. */
+	attrargsep = ast_xml_get_attribute(node, "argsep");
+	if (attrargsep) {
+		argsep = ast_strdupa(attrargsep);
+		ast_xml_free_attr(attrargsep);
+	} else {
+		argsep = ast_strdupa(",");
+	}
+
 	if (!node || !node->AST_XML_CHILD) {
-		return NULL;
-	}
-
-	/* Find the syntax field. */
-	node = node->AST_XML_CHILD;
-	while (node) {
-		if (!strcasecmp((char *)node->AST_XML_NAME, "syntax")) {
-			break;
-		}
-		node = node->AST_XML_NEXT;
-	}
-	
-	if (!node || !node->AST_XML_CHILD) {
-		/* If the syntax field is not found, at least print the
-		   application/function name. */
-		ast_asprintf(&syntax, "%s()", name);
+		/* If the rootnode field is not found, at least print name. */
+		ast_asprintf(&syntax, "%s%s", rootname, (printparenthesis ? "()" : ""));
 		return syntax;
 	}
 
@@ -3143,7 +3142,8 @@
 	node = node->AST_XML_CHILD;
 	firstparam = node;
 	while (node) {
-		if (!strcasecmp((char *)node->AST_XML_NAME, "parameter")) {
+		if (!strcasecmp((char *)node->AST_XML_NAME, childname)) {
+			hasparams = 1;
 			paramtype = ast_xml_get_attribute(node, "required");
 			reverse = 1;
 			if (paramtype) {
@@ -3155,6 +3155,12 @@
 			break;
 		}
 		node = node->AST_XML_NEXT;
+	}
+
+	if (!hasparams) {
+		/* This application, function, option, etc, doesn't have any params. */
+		ast_asprintf(&syntax, "%s%s", rootname, (printparenthesis ? "()" : ""));
+		return syntax;
 	}
 
 	if (reverse) {
@@ -3177,7 +3183,7 @@
 		while (node) {
 			/* Check if last element is also optional (is so,
 			   go to the begining again). */
-			if (strcasecmp((char *)node->AST_XML_NAME, "parameter")) {
+			if (strcasecmp((char *)node->AST_XML_NAME, childname)) {
 				node = GOTONEXT(reverse, node);
 				continue;
 			}
@@ -3186,7 +3192,8 @@
 
 		if (!node) {
 			/* Huh? We must at least find one parameter! */
-			return NULL;
+			ast_asprintf(&syntax, "%s%s", rootname, (printparenthesis ? "()" : ""));
+			return syntax;
 		}
 
 		lastparam = node;
@@ -3206,24 +3213,24 @@
 	if (reverse) {
 		__xmldoc_reverse_helper(reverse, &len, &syntax, ")");
 	} else {
-		__xmldoc_reverse_helper(reverse, &len, &syntax, "%s(", name);
+		__xmldoc_reverse_helper(reverse, &len, &syntax, "%s(", rootname);
 	}
 
 	while (node) {
-		if (strcasecmp((char *)node->AST_XML_NAME, "parameter")) {
+		if (strcasecmp((char *)node->AST_XML_NAME, childname)) {
 			node = GOTONEXT(reverse, node);
 			continue;
 		}
 
 		paramname = ast_xml_get_attribute(node, "name");
 		if (!paramname) {
-			ast_log(LOG_WARNING, "Malformed XML %s/%s: no parameter name\n", type, name);
+			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? */
-			ast_asprintf(&syntax, "%s()", name);
+			ast_asprintf(&syntax, "%s%s", rootname, (printparenthesis ? "()" : ""));
 			return syntax;
 		}
 
@@ -3247,7 +3254,11 @@
 					xmldoc_reverse_helper(reverse, &len, &syntax, "]", "[");
 					openbrackets--;
 				}
-				xmldoc_reverse_helper(reverse, &len, &syntax, ",%s", "%s,", paramname);
+				if (reverse) {
+					__xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s", paramname, argsep);
+				} else {
+					__xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s", argsep, paramname);
+				}
 			}
 		} else {
 			/* First parameter */
@@ -3255,9 +3266,17 @@
 				xmldoc_reverse_helper(reverse, &len, &syntax, "[%s]", "[%s]", paramname);
 			} else {
 				if (ISLAST(reverse, node)) {
-					xmldoc_reverse_helper(reverse, &len, &syntax, ",[%s]", "[%s],", paramname);
+					if (reverse) {
+						__xmldoc_reverse_helper(reverse, &len, &syntax, "[%s]%s", paramname, argsep);
+					} else {
+						__xmldoc_reverse_helper(reverse, &len, &syntax, "%s[%s]", argsep, paramname);
+					}
 				} else {
-					xmldoc_reverse_helper(reverse, &len, &syntax, "[,%s", "%s,]", paramname);
+					if (reverse) {
+						__xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s]", paramname, argsep);
+					} else {
+						__xmldoc_reverse_helper(reverse, &len, &syntax, "[%s%s", argsep, paramname);
+					}
 					openbrackets++;
 				}
 			}
@@ -3276,7 +3295,7 @@
 
 	/* close syntax string. */
 	if (reverse) {
-		__xmldoc_reverse_helper(reverse, &len, &syntax, "%s(", name);
+		__xmldoc_reverse_helper(reverse, &len, &syntax, "%s(", rootname);
 	} else {
 		__xmldoc_reverse_helper(reverse, &len, &syntax, ")");
 	}
@@ -3284,6 +3303,37 @@
 	return syntax;
 #undef ISLAST
 #undef GOTONEXT
+}
+
+/*! \internal
+ *  \brief Get the syntax for a specified application or function.
+ *  \param type Application or Function ?
+ *  \param name Name of the application or function.
+ *  \retval NULL on error.
+ *  \retval The generated syntax in a ast_malloc'ed string.
+ */
+static char *xmldoc_get_syntax(const char *type, const char *name)
+{
+	ast_xml_node *node;
+	char *syntax = NULL;
+
+	node = xmldoc_get_node(documentation_tree, type, name, documentation_language);
+	if (!node || !node->AST_XML_CHILD) {
+		return NULL;
+	}
+
+	node = node->AST_XML_CHILD;
+	while (node) {
+		if (!strcasecmp((char *)node->AST_XML_NAME, "syntax")) {
+			break;
+		}
+		node = node->AST_XML_NEXT;
+	}
+	
+	if (node) {
+		syntax = xmldoc_build_syntax(node, name, "parameter", 1);
+	}
+	return syntax;
 }
 
 /*! \internal
@@ -3291,25 +3341,29 @@
  *  \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 len buffer length (will be modified if data is appended in buffer).
  *  \param buffer This must be NULL or an ast_malloc'ed buffer. It will be used
  *         to store the result (if already has something it will be appended to the current
  *         string).
- *  \retval 1 on succes.
+ *  \retval 1 If 'node' is a named 'para'.
+ *  \retval 2 If data is appended in buffer.
  *  \retval 0 on error.
  */
 static int xmldoc_parse_para(ast_xml_node *node, const char *tabs, const char *posttabs, int *len, char **buffer)
 {
 	ast_xml_text *tmptext;
 	char *cleantext;
+	int ret = 0;
 
 	if (!node || !node->AST_XML_CHILD) {
-		return 0;
+		return ret;
 	}
 
 	if (strcasecmp((char *)node->AST_XML_NAME, "para")) {
-		return 0;
-	}
-
+		return ret;
+	}
+
+	ret = 1;
 	/* Get the text inside the <para> element and append it to buffer. */
 	tmptext = ast_xml_get_text(node);
 	if (tmptext) {
@@ -3320,72 +3374,287 @@
 			*buffer = ast_realloc(*buffer, *len + strlen(tabs) + strlen(cleantext) + strlen(posttabs) + 1);
 			*len += sprintf(*buffer + *len, "%s%s%s", tabs, cleantext, posttabs);
 			ast_free(cleantext);
-		}
-	}
-
-	return 1;
+			ret = 2;
+		}
+	}
+
+	return ret;
+}
+
+/*! \internal
+ *  \brief Parse an <argument> element from the xml documentation.
+ *  \param tabs What to be printed before the argument name.
+ *  \param buffer Output buffer to put values found inside the <argument> element.
+ *  \param len Output buffer length (will be modified if data is appended to buffer).
+ *  \param fixnode Pointer to the 'argument' xml node.
+ */
+static int xmldoc_parse_argument(const char *tabs, char **buffer, int *len, ast_xml_node *fixnode)
+{
+	ast_xml_node *node = fixnode;
+	ast_xml_attr *argname;
+	int count=0, ret = 0;
+
+	if (!node || !node->AST_XML_CHILD) {
+		return ret;
+	}
+
+	/* Print the argument names */
+	argname = ast_xml_get_attribute(node, "name");
+	if (argname) {
+		*buffer = ast_realloc(*buffer, *len + strlen(argname) + strlen(tabs) + 1);
+		*len += sprintf(*buffer + *len, "%s%s", tabs, argname);
+		ast_xml_free_attr(argname);
+
+		node = node->AST_XML_CHILD;
+		while (node) {
+			if (count > 0) {
+				if (xmldoc_parse_para(node, tabs, "\n", len, buffer) == 2) {
+					count++;
+					ret = 1;
+				}
+			} else {
+				if (xmldoc_parse_para(node, " - ", "\n", len, buffer) == 2) {
+					count++;
+					ret = 1;
+				}
+			}
+			node = node->AST_XML_NEXT;
+		}
+	}
+
+	return ret;
+}
+
+/*! \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 len The current length of the buffer (if output is appended it will be modified).
+ *  \param buffer This must be NULL or an ast_malloc'ed buffer. 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.
+ */
+static int xmldoc_parse_variable(ast_xml_node *node, const char *tabs, int *len, char **buffer)
+{
+	ast_xml_node *tmp;
+	ast_xml_attr *valname;
+	ast_xml_text *tmptext;
+	char *clean;
+	int ret = 0;
+
+	if (!node || !node->AST_XML_CHILD) {
+		return ret;
+	}
+
+	tmp = node->AST_XML_CHILD;
+	while (tmp) {
+		if (xmldoc_parse_para(tmp, (ret ? tabs : ""), "\n", len, buffer)) {
+			tmp = tmp->AST_XML_NEXT;
+			continue;
+		}
+
+		if (!strcasecmp((char *)tmp->AST_XML_NAME, "value")) {
+			/* We do this first just to know if there is any comment inside <value>
+			   and know how to print the name of the value. */
+			tmptext = ast_xml_get_text(tmp);
+
+			/* Parse each <value name='valuename'>desciption</value> */
+			valname = ast_xml_get_attribute(tmp, "name");
+			if (valname) {
+				if (!ret) {
+					*buffer = ast_realloc(*buffer, *len + 2);
+					*len += sprintf(*buffer + *len, "\n");
+				}
+				ret = 1;
+				*buffer = ast_realloc(*buffer, *len + strlen(valname) + strlen(tabs) + 3);
+				*len += sprintf(*buffer + *len, "%s%s%c", tabs, valname, (tmptext ? ':' : '\n'));
+				ast_xml_free_attr(valname);
+			}
+			/* Check inside this node for any explanation about its meaning. */
+			if (tmptext) {
+				/* Cleanup text. */
+				clean = xmldoc_string_cleanup(tmptext);
+				ast_xml_free_text(tmptext);
+				if (clean) {
+					*buffer = ast_realloc(*buffer, *len + strlen(clean) + 3);
+					*len += sprintf(*buffer + *len, " %s\n", clean);
+					ast_free(clean);
+				}
+			}
+		}
+		tmp = tmp->AST_XML_NEXT;
+	}
+
+	return ret;
+}
+
+/*! \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 len The current length of the buffer (if output is appended it will be modified).
+ *  \param buffer This must be NULL, or a ast_malloc'ed buffer. 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.
+ */
+static int xmldoc_parse_variablelist(ast_xml_node *node, const char *tabs, int *len, char **buffer)
+{
+	ast_xml_node *tmp;
+	ast_xml_attr *varname;
+	char *vartabs;
+	int ret = 0;
+
+	if (!node || !node->AST_XML_CHILD) {
+		return ret;
+	}
+
+	if (strcasecmp((char *)node->AST_XML_NAME, "variablelist")) {
+		return ret;
+	}
+
+	ast_asprintf(&vartabs, "%s    ", tabs);
+
+	tmp = node->AST_XML_CHILD;
+	while (tmp) {
+		/* We can have a <para> element inside the variable list */
+		if ((xmldoc_parse_para(tmp, (ret ? tabs : ""), "\n", len, buffer))) {
+			ret = 1;
+			tmp = tmp->AST_XML_NEXT;
+			continue;
+		}
+
+		if (!strcasecmp((char *)tmp->AST_XML_NAME, "variable")) {
+			/* Store the variable name in buffer. */
+			varname = ast_xml_get_attribute(tmp, "name");
+			if (varname) {
+				*buffer = ast_realloc(*buffer, *len + strlen(varname) + strlen(tabs) + 4);
+				if (buffer) {
+					*len += sprintf(*buffer + *len, "%s%s: ", tabs, varname);
+					ast_xml_free_attr(varname);
+					/* Parse the <variable> possible values. */
+					xmldoc_parse_variable(tmp, vartabs, len, buffer);
+					ret = 1;
+				}
+			}
+		}
+		tmp = tmp->AST_XML_NEXT;
+	}
+
+	ast_free(vartabs);
+
+	return ret;
+}
+
+/*! \internal
+ *  \brief Parse an <option> node.
+ *  \param buffer The output buffer.
+ *  \param len The buffer length, (it will be changed if data is appended to buffer).
+ *  \param fixnode An ast_xml pointer to the <option> node.
+ *  \retval 0 if not option node is parsed.
+ *  \retval 1 if an option node is parsed.
+ */
+static int xmldoc_parse_option(char **buffer, int *len, ast_xml_node *fixnode)
+{
+	ast_xml_node *node = fixnode;
+	int ret = 0;
+
+	if (!node || !node->AST_XML_CHILD) {
+		return ret;
+	}
+
+	node = node->AST_XML_CHILD;
+	while (node) {
+		if (!strcasecmp((char *)node->AST_XML_NAME, "argument")) {
+			if (!ret && node->AST_XML_CHILD) {
+				/* print \n */
+				*buffer = ast_realloc(*buffer, *len + 2);
+				*len += sprintf(*buffer + *len, "\n");
+			}
+			if (xmldoc_parse_argument("        ", buffer, len, node)) {
+				ret = 1;
+			}
+			node = node->AST_XML_NEXT;
+			continue;
+		}
+
+		if (xmldoc_parse_para(node, (ret ? "    " :  ""), "\n", len, buffer)) {
+			ret = 1;
+		}
+		
+		if (xmldoc_parse_variablelist(node, "        ", len, buffer)) {
+			*buffer = ast_realloc(*buffer, *len + 2);
+			*len += sprintf(*buffer + *len, "\n");
+		}
+
+		node = node->AST_XML_NEXT;	
+	}
+			
+	return ret;
 }
 
 /*! \internal
  *  \brief Parse an <optionlist> element from the xml documentation.
  *  \param buffer Output buffer to put what is inside the optionlist tag.
  *  \param len Length of the passed 'buffer', it will be incremented if something
- *  is appended into buffer.
- *  \param node Pointer to the optionlist xml node.
+ *         is appended into buffer.
+ *  \param fixnode Pointer to the optionlist xml node.
  */
 static void xmldoc_parse_optionlist(char **buffer, int *len, ast_xml_node *fixnode)
 {
 	ast_xml_node *node = fixnode;
+	ast_xml_attr *optname;
+	char *optionsyntax;
 
 	if (!node || !node->AST_XML_CHILD) {
 		return;
 	}
 
-	
+	node = node->AST_XML_CHILD;
+	while (node) {
+		/* Start appending every option tag. */
+		if (strcasecmp((char *)node->AST_XML_NAME, "option")) {
+			node = node->AST_XML_NEXT;
+			continue;
+		}
+
+		/* Get the option name. */
+		optname = ast_xml_get_attribute(node, "name");
+		if (!optname) {
+			node = node->AST_XML_NEXT;
+			continue;	
+		}
+
+		optionsyntax = xmldoc_build_syntax(node, optname, "argument", 0);
+		if (!optionsyntax) {
+			node = node->AST_XML_NEXT;
+			continue;
+		}
+
+		*buffer = ast_realloc(*buffer, *len + strlen(optionsyntax) + 7);
+		*len += sprintf(*buffer + *len, "    %s: ", optionsyntax);
+
+		if (!xmldoc_parse_option(buffer, len, node)) {
+			*buffer = ast_realloc(*buffer, *len + 2);
+			*len += sprintf(*buffer + *len, "\n");
+		}
+
+		node = node->AST_XML_NEXT;
+	}
 
 	return;
-}
-
-/*! \internal
- *  \brief Parse an <argument> element from the xml documentation.
- *  \param buffer Output buffer to put values found inside the <argument> element.
- *  \param len Output buffer length (will be modified if data is appended to buffer).
- *  \param node Pointer to the 'argument' xml node.
- */
-static void xmldoc_parse_argument(char **buffer, int *len, ast_xml_node *fixnode)
-{
-	ast_xml_node *node = fixnode;
-	ast_xml_attr *argname;
-
-	if (!node || !node->AST_XML_CHILD) {
-		return;
-	}
-
-	/* Print the argument names */	
-	argname = ast_xml_get_attribute(node, "name");
-	if (argname) {
-		*buffer = ast_realloc(*buffer, *len + strlen(argname) + 3);
-		*len += sprintf(*buffer + *len, "\t%s\n", argname);
-		ast_xml_free_attr(argname);
-
-		node = node->AST_XML_CHILD;
-		while (node) {
-			xmldoc_parse_para(node, "\t\t", "\n", len, buffer);
-			node = node->AST_XML_NEXT;
-		}
-
-	} else {
-		/* Argument without name, huh? */
-		return;
-	}
-
 }
 
 /*! \internal
  *  \brief Parse a 'parameter' tag inside a syntax element.
  *  \param buffer String buffer to put values found inside the parameter element.
  *  \param len Buffer length (will be modified if data is appended to buffer).
- *  \param node A pointer to the 'parameter' xml node.
+ *  \param fixnode A pointer to the 'parameter' xml node.
  */
 static void xmldoc_parse_parameter(char **buffer, int *len, ast_xml_node *fixnode)
 {
@@ -3413,8 +3682,8 @@
 		if (!strcasecmp((char *)node->AST_XML_NAME, "optionlist")) {
 			xmldoc_parse_optionlist(buffer, len, node);
 		} else if (!strcasecmp((char *)node->AST_XML_NAME, "argument")) {
-			xmldoc_parse_argument(buffer, len, node);
-		} else if ((xmldoc_parse_para(node, "\t", "\n", len, buffer))) {
+			xmldoc_parse_argument("        ", buffer, len, node);
+		} else if ((xmldoc_parse_para(node, "    ", "\n", len, buffer))) {
 			node = node->AST_XML_NEXT;
 			continue;
 		}
@@ -3475,113 +3744,6 @@
 	}
 
 	return ret;
-}
-
-/*! \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 len The current length of the buffer (if output is appended it will be modified).
- *  \param buffer This must be NULL or an ast_malloc'ed buffer. It will be used
- *  	   to store the result (if already has something it will be appended to the current
- *  	   string).
- *  \param varnamelen Variable name len.
- */
-static void xmldoc_parse_variable(ast_xml_node *node, const char *tabs, int *len, char **buffer, int varnamelen)
-{
-	ast_xml_node *tmp;
-	ast_xml_attr *valname;
-	ast_xml_text *tmptext;
-	char *clean;
-
-	if (!node || !node->AST_XML_CHILD) {
-		return;
-	}
-
-	tmp = node->AST_XML_CHILD;
-	while (tmp) {
-		if (xmldoc_parse_para(tmp, "", "", len, buffer)) {
-			tmp = tmp->AST_XML_NEXT;
-			continue;
-		}
-
-		if (!strcasecmp((char *)tmp->AST_XML_NAME, "value")) {
-			/* We do this first just to know if there is any comment inside <value>
-			and know how to print the name of the value. */
-			tmptext = ast_xml_get_text(tmp);
-
-			/* Parse each <value name='valuename'>desciption</value> */
-			valname = ast_xml_get_attribute(tmp, "name");
-			if (valname) {
-				*buffer = ast_realloc(*buffer, *len + strlen(valname) + strlen(tabs) + 3);
-				*len += sprintf(*buffer + *len, "\n%s%s%c", tabs, valname, (tmptext ? ':' : ' '));
-				ast_xml_free_attr(valname);
-			}
-			/* Check inside this node for any explanation about its meaning. */
-			if (tmptext) {
-				/* Cleanup text. */			
-				clean = xmldoc_string_cleanup(tmptext);
-				ast_xml_free_text(tmptext);
-				if (clean) {
-					*buffer = ast_realloc(*buffer, *len + strlen(clean) + 2);
-					*len += sprintf(*buffer + *len, " %s", clean);
-					ast_free(clean);
-				}
-			}
-		}
-		tmp = tmp->AST_XML_NEXT;
-	}
-	
-}
-
-/*! \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 NULL, or a ast_malloc'ed buffer. It will be used
- *  	   to store the result (if already has something it will be appended to the current
- *  	   string).
- *  \param len The current length of the buffer (if output is appended it will be modified). 
- *  \retval 1 If a <variablelist> element is parsed.
- *  \retval 0 On error.
- */
-static int xmldoc_parse_variablelist(ast_xml_node *node, const char *tabs, int *len, char **buffer)
-{
-	ast_xml_node *tmp;
-	ast_xml_attr *varname;
-
-	if (!node || !node->AST_XML_CHILD) {
-		return 0;
-	}
-
-	if (strcasecmp((char *)node->AST_XML_NAME, "variablelist")) {
-		return 0;	
-	}
-
-	tmp = node->AST_XML_CHILD;
-	while (tmp) {
-		/* We can have a <para> element inside the variable list ?? */
-		if ((xmldoc_parse_para(tmp, "", "", len, buffer))) {
-			tmp = tmp->AST_XML_NEXT;
-			continue;
-		}
-
-		if (!strcasecmp((char *)tmp->AST_XML_NAME, "variable")) {
-			/* Store the variable name in buffer. */
-			varname = ast_xml_get_attribute(tmp, "name");
-			if (varname) {
-				*buffer = ast_realloc(*buffer, *len + strlen(varname) + strlen(tabs) + 4);
-				*len += sprintf(*buffer + *len, "%s%s: ", tabs, varname);
-				ast_xml_free_attr(varname);
-			}
-			/* Parse the <variable> possible values. */
-			xmldoc_parse_variable(tmp, "\t", len, buffer, strlen(varname) + strlen(tabs) + 2);
-		}
-		tmp = tmp->AST_XML_NEXT;
-	}
-	return 1;
 }
 
 /*! \internal
@@ -3600,7 +3762,7 @@
 	int len = 0;
 
 	if (!node || !node->AST_XML_CHILD) {
-		return NULL;
+		return ret;
 	}
 
 	if (raw_output) {
@@ -3616,7 +3778,7 @@
 				continue;
 			}
 			/* if found, parse a <variablelist> element. */
-			xmldoc_parse_variablelist(tmp, "\n", &len, &ret);
+			xmldoc_parse_variablelist(tmp, "", &len, &ret);
 			
 			tmp = tmp->AST_XML_NEXT;
 		}
@@ -3639,27 +3801,27 @@
 
 	if (ast_strlen_zero(type) || ast_strlen_zero(name)) {
 		ast_log(LOG_WARNING, "Tried to look in XML tree with faulty values.\n");
-		return NULL;
+		return ret;
 	}
 
 	/* not fully initted yet */
 	if (!documentation_tree) {
 		ast_log(LOG_DEBUG, "Parsing Documentation XML Error\n");
-		return NULL; 
+		return ret; 
 	}
 
 	node = xmldoc_get_node(documentation_tree, type, name, documentation_language);
 		
 	if (!node) {
 		ast_log(LOG_ERROR, "Counldn't find %s %s in XML documentation\n", type, name);
-		return NULL;
+		return ret;
 	}
 
 	node = ast_xml_find_element(node->AST_XML_CHILD, var, NULL, NULL);
 
 	if (!node || !node->AST_XML_CHILD) {
 		ast_log(LOG_DEBUG, "Cannot find variable '%s' in tree '%s'\n", name, var);
-		return NULL;
+		return ret;
 	}
 
 	formatted = xmldoc_get_formatted(node, raw, raw);
@@ -3688,7 +3850,7 @@
 	if (ast_strlen_zero(acf->desc) && ast_strlen_zero(acf->synopsis)) {
 		acf->synopsis = xmldoc_get_field("function", acf->name, "synopsis", 1);
 		acf->desc = xmldoc_get_field("function", acf->name, "description", 0);
-		acf->syntax = xmldoc_build_syntax("function", acf->name);
+		acf->syntax = xmldoc_get_syntax("function", acf->name);
 		acf->arguments = xmldoc_build_arguments("function", acf->name);
 		acf->docsrc = AST_XML_DOC;
 	}
@@ -5401,7 +5563,7 @@
 	if (ast_strlen_zero(synopsis) && ast_strlen_zero(description)) {
 		tmp->synopsis = xmldoc_get_field("application", app, "synopsis", 1);
 		tmp->description = xmldoc_get_field("application", app, "description", 0);
-		tmp->syntax = xmldoc_build_syntax("application", app);
+		tmp->syntax = xmldoc_get_syntax("application", app);
 		tmp->arguments = xmldoc_build_arguments("application", app);
 		tmp->docsrc = AST_XML_DOC;
 	} else {




More information about the asterisk-commits mailing list