[asterisk-commits] eliel: branch group/appdocsxml r144626 - /team/group/appdocsxml/main/pbx.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Sep 26 09:20:53 CDT 2008
Author: eliel
Date: Fri Sep 26 09:20:52 2008
New Revision: 144626
URL: http://svn.digium.com/view/asterisk?view=rev&rev=144626
Log:
Fix an issue while trying to generate the syntax for applications with this
type of parameters: (REQUIRED,...,OPTIONAL,...,REQUIRED) like ChannelRedirect.
They must be treated as reverse (right to left) and where generated with the normal way from
left to right.
Modified:
team/group/appdocsxml/main/pbx.c
Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=144626&r1=144625&r2=144626
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Fri Sep 26 09:20:52 2008
@@ -3263,9 +3263,10 @@
{
#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_node *node, *firstparam = NULL, *lastparam;
ast_xml_attr *paramtype, *paramname, *attrargsep;
- int reverse = 0, required = 0, paramcount = 0, openbrackets = 0, len = 0, hasparams=0;
+ int reverse, required, paramcount = 0, openbrackets = 0, len = 0, hasparams=0;
+ int reqfinode = 0, reqlanode = 0, optmidnode = 0;
char *syntax = NULL, *argsep;
if (ast_strlen_zero(rootname) || ast_strlen_zero(childname)) {
@@ -3273,11 +3274,15 @@
return NULL;
}
- node = rootnode;
-
+ if (!node || !node->AST_XML_CHILD) {
+ /* If the rootnode field is not found, at least print name. */
+ ast_asprintf(&syntax, "%s%s", rootname, (printparenthesis ? "()" : ""));
+ return syntax;
+ }
+
/* Get the argument separator from the root node attribute name 'argsep', if not found
defaults to ','. */
- attrargsep = ast_xml_get_attribute(node, "argsep");
+ attrargsep = ast_xml_get_attribute(rootnode, "argsep");
if (attrargsep) {
argsep = ast_strdupa(attrargsep);
ast_xml_free_attr(attrargsep);
@@ -3285,28 +3290,30 @@
argsep = ast_strdupa(",");
}
- if (!node || !node->AST_XML_CHILD) {
- /* If the rootnode field is not found, at least print name. */
- ast_asprintf(&syntax, "%s%s", rootname, (printparenthesis ? "()" : ""));
- return syntax;
- }
-
/* Get order of evaluation. */
- node = node->AST_XML_CHILD;
- firstparam = node;
+ node = rootnode->AST_XML_CHILD;
while (node) {
- if (!strcasecmp((char *)node->AST_XML_NAME, childname)) {
- hasparams = 1;
- paramtype = ast_xml_get_attribute(node, "required");
- reverse = 1;
- if (paramtype) {
- if (ast_true((char *)paramtype)) {
- reverse = 0;
- }
- ast_xml_free_attr(paramtype);
- }
- break;
- }
+ if (strcasecmp((char *)node->AST_XML_NAME, childname)) {
+ node = node->AST_XML_NEXT;
+ continue;
+ }
+ required = 0;
+ hasparams = 1;
+ if ((paramtype = ast_xml_get_attribute(node, "required"))) {
+ if (ast_true((char *)paramtype)) {
+ required = 1;
+ }
+ ast_xml_free_attr(paramtype);
+ }
+
+ lastparam = node;
+ reqlanode = required;
+
+ if (!firstparam) {
+ /* first parameter node */
+ firstparam = node;
+ reqfinode = required;
+ }
node = node->AST_XML_NEXT;
}
@@ -3316,50 +3323,33 @@
return syntax;
}
- if (reverse) {
- /* Go to the last element. */
+ if (reqfinode && reqlanode) {
+ /* check midnode */
+ node = rootnode->AST_XML_CHILD;
while (node) {
- if (!node->AST_XML_NEXT) {
- break;
+ if (strcasecmp((char *)node->AST_XML_NAME, childname)) {
+ node = node->AST_XML_NEXT;
+ continue;
+ }
+ if (node != firstparam && node != lastparam) {
+ if ((paramtype = ast_xml_get_attribute(node, "required"))) {
+ if (!ast_true((char *)paramtype)) {
+ optmidnode = 1;
+ break;
+ }
+ ast_xml_free_attr(paramtype);
+ }
}
node = node->AST_XML_NEXT;
}
}
- /* If starts with an optional parameter and ends with an optional paramenter,
- reverse = 0, and start from the first parameter.
- If starts with a required parameter reverse = 0.
- If starts with an optional parameter and ends with a required parameter
- reverse = 1 and start from the last parameter */
- if (reverse) {
- /* find the last parameter. */
- while (node) {
- /* Check if last element is also optional (is so,
- go to the begining again). */
- if (strcasecmp((char *)node->AST_XML_NAME, childname)) {
- node = GOTONEXT(reverse, node);
- continue;
- }
- break;
- }
-
- if (!node) {
- /* Huh? We must at least find one parameter! */
- ast_asprintf(&syntax, "%s%s", rootname, (printparenthesis ? "()" : ""));
- return syntax;
- }
-
- lastparam = node;
- paramtype = ast_xml_get_attribute(node, "required");
+ if ((!reqfinode && reqlanode) || (reqfinode && reqlanode && optmidnode)) {
+ reverse = 1;
+ node = lastparam;
+ } else {
reverse = 0;
node = firstparam;
- if (paramtype) {
- if (ast_true((char *)paramtype)) {
- node = lastparam;
- reverse = 1;
- }
- ast_xml_free_attr(paramtype);
- }
}
/* init syntax string. */
@@ -3388,8 +3378,7 @@
}
required = 0; /* Defaults to 'false'. */
- paramtype = ast_xml_get_attribute(node, "required");
- if (paramtype) {
+ if ((paramtype = ast_xml_get_attribute(node, "required"))) {
if (ast_true((char *)paramtype)) {
required = 1;
}
More information about the asterisk-commits
mailing list