[svn-commits] bkruse: branch group/appdocsxml r128341 - in /team/group/appdocsxml: apps/ fu...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Jul 5 23:38:52 CDT 2008


Author: bkruse
Date: Sat Jul  5 23:38:51 2008
New Revision: 128341

URL: http://svn.digium.com/view/asterisk?view=rev&rev=128341
Log:
Going to sleep, currently in a b0rked state.

Have to figure out why it is pulling out the wrong
nodes for a very specific search...

Modified:
    team/group/appdocsxml/apps/app_chanisavail.c
    team/group/appdocsxml/apps/app_dial.c
    team/group/appdocsxml/funcs/func_shell.c
    team/group/appdocsxml/include/asterisk/module.h
    team/group/appdocsxml/main/pbx.c

Modified: team/group/appdocsxml/apps/app_chanisavail.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/apps/app_chanisavail.c?view=diff&rev=128341&r1=128340&r2=128341
==============================================================================
--- team/group/appdocsxml/apps/app_chanisavail.c (original)
+++ team/group/appdocsxml/apps/app_chanisavail.c Sat Jul  5 23:38:51 2008
@@ -222,7 +222,7 @@
 
 static int load_module(void)
 {
-	return ast_register_application_xml(app, chanavail_exec) ?
+	return ast_register_application(app, chanavail_exec, NULL, NULL) ?
 		AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
 }
 

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=128341&r1=128340&r2=128341
==============================================================================
--- team/group/appdocsxml/apps/app_dial.c (original)
+++ team/group/appdocsxml/apps/app_dial.c Sat Jul  5 23:38:51 2008
@@ -112,11 +112,11 @@
 			</value>
 			<value name="INVALIDARGS" />
 		</variable>
-		<option name="Technology/Resource" required="true" argsep="&">
+		<option name="Technology/Resource" required="true" argsep="&amp;">
 			<argument name="Technology2/Resource2">
 				Optional extra 'devices' to dial.
 				If you need more then one enter them like this:
-				Technology2/Resource2&Technology3/Resourse3&.....
+				Technology2/Resource2&amp;Technology3/Resourse3&amp;.....
 			</argument>
 			Device to dial
 		</option>
@@ -265,7 +265,7 @@
 				<value name="CONTINUE">
 					Hangup the called party and allow the calling party to continue dialplan execution at the next priority.
 				</value>
-				<value name="GOTO:<context>^<exten>^<priority>">
+				<value name="GOTO:&lt;context&gt;^&lt;exten&gt;^&lt;priority&gt;">
 					Transfer the call to the specified priority. Optionally, an extension, or extension and priority can be specified.
 				</value>
 			</variable>
@@ -352,7 +352,7 @@
 					Hangup the called party and allow the calling party
 					to continue dialplan execution at the next priority.
 				</value>
-				<value name="GOTO:<context>^<exten>^<priority>">
+				<value name="GOTO:&lt;context&gt;^&lt;exten&gt;^&lt;priority&gt;">
 					Transfer the call to the
 					specified priority. Optionally, an extension, or
 					extension and priority can be specified.
@@ -2504,8 +2504,8 @@
 	else
 		ast_add_extension2(con, 1, "s", 1, NULL, NULL, "KeepAlive", ast_strdup(""), ast_free_ptr, "app_dial");
 
-	res = ast_register_application_xml(app, dial_exec);
-	res |= ast_register_application_xml(rapp, retrydial_exec);
+	res = ast_register_application(app, dial_exec, NULL, NULL);
+	res |= ast_register_application(rapp, retrydial_exec, NULL, NULL);
 
 	return res;
 }

Modified: team/group/appdocsxml/funcs/func_shell.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/funcs/func_shell.c?view=diff&rev=128341&r1=128340&r2=128341
==============================================================================
--- team/group/appdocsxml/funcs/func_shell.c (original)
+++ team/group/appdocsxml/funcs/func_shell.c Sat Jul  5 23:38:51 2008
@@ -63,19 +63,29 @@
 	return 0;
 }
 
+/*** DOCUMENTATION
+	<function name="SHELL" language="en">
+		<synopsis>
+			Executes a command as if you were at a shell.
+		</synopsis>
+		<description>
+			  Returns the value from a system command
+			Example:  Set(foo=${SHELL(echo \bar\)})
+			Note:  When using the SHELL() dialplan function, your \SHELL\ is /bin/sh,
+			which may differ as to the underlying shell, depending upon your production
+			platform.  Also keep in mind that if you are using a common path, you should
+			be mindful of race conditions that could result from two calls running
+			SHELL() simultaneously.
+		</description>
+		<option name="command" required="true">
+			This is the argument to the function, the command you want to pass to the shell.
+		</option> 
+	</function>
+ ***/
 static struct ast_custom_function shell_function = {
 	.name = "SHELL",
-	.synopsis = "Executes a command as if you were at a shell.",
 	.syntax = "SHELL(<command>)",
 	.read = shell_helper,
-	.desc =
-"Returns the value from a system command\n"
-"  Example:  Set(foo=${SHELL(echo \"bar\")})\n"
-"  Note:  When using the SHELL() dialplan function, your \"SHELL\" is /bin/sh,\n"
-"  which may differ as to the underlying shell, depending upon your production\n"
-"  platform.  Also keep in mind that if you are using a common path, you should\n"
-"  be mindful of race conditions that could result from two calls running\n"
-"  SHELL() simultaneously.\n",
 };
 
 static int unload_module(void)

Modified: team/group/appdocsxml/include/asterisk/module.h
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/include/asterisk/module.h?view=diff&rev=128341&r1=128340&r2=128341
==============================================================================
--- team/group/appdocsxml/include/asterisk/module.h (original)
+++ team/group/appdocsxml/include/asterisk/module.h Sat Jul  5 23:38:51 2008
@@ -401,27 +401,6 @@
 int ast_register_application2(const char *app, int (*execute)(struct ast_channel *, void *),
 				     const char *synopsis, const char *description, void *mod);
 
-#define ast_register_application_xml(app, execute) ast_register_application_xml_real(app, execute, ast_module_info->self)
-/*!
- * \brief Register an application.
- *
- * \param app Short name of the application
- * \param execute a function callback to execute the application. It should return
- *                non-zero if the channel needs to be hung up.
- * \param mod module this application belongs to
- *
- * This registers an application with Asterisk's internal application list.
- * \note The individual applications themselves are responsible for registering and unregistering
- *       and unregistering their own CLI commands.
- *
- * \note Pulls all application documentation from compile-time composed XML file
- *
- * \retval 0 success
- * \retval -1 failure.
- */
-int ast_register_application_xml_real(const char *app, int (*execute)(struct ast_channel *, void *), void *mod);
-
-
 /*! 
  * \brief Unregister an application
  * 

Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=128341&r1=128340&r2=128341
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Sat Jul  5 23:38:51 2008
@@ -338,6 +338,8 @@
 static void __ast_internal_context_destroy( struct ast_context *con);
 #ifdef XML_DOCUMENTATION
 mxml_node_t *documentation_tree = NULL;
+static char *ast_mxml_get_field(const char *type, const char *name, const char *var); 
+void _mxml_error(const char *cb);
 #endif
 
 /* a func for qsort to use to sort a char array */
@@ -2609,6 +2611,63 @@
 	return cur ? 0 : -1;
 }
 
+/* XXX Really not sure if I did this memory allocation correctly... */
+static char *ast_mxml_get_field(const char *type, const char *name, const char *var) {
+	
+	char *fail = malloc(6);
+	char *tmp;
+	mxml_node_t *node, *lang_node, *ret;
+
+	node = lang_node = ret = NULL;
+
+	sprintf(fail, "%s", "(None)");	
+
+	if(ast_strlen_zero(type) || ast_strlen_zero(name)) {
+		ast_log(LOG_WARNING, "Tried to look in XML tree with faulty values.\n");
+		return fail;
+	}
+
+	/* not fully initted yet */
+	if(documentation_tree == NULL) {
+		ast_log(LOG_DEBUG, "Parsing XML Tree Error\n");
+		return fail; 
+	}
+
+	node = mxmlFindElement(documentation_tree, documentation_tree, type, "name", name, MXML_DESCEND);
+	//node = mxmlFindElement(documentation_tree, documentation_tree, "function", "name", "SHELL", MXML_DESCEND);
+
+	if (!node) {
+		ast_log(LOG_WARNING, "Cannot find Documentation name:'%s' type:'%s' var:'%s'\n", name, type, var);
+		return fail;
+	}
+
+	lang_node = mxmlFindElement(node, documentation_tree, type, "language", documentation_language, MXML_DESCEND);	
+	
+	/* Could not find language, use the default one without a language */
+	if (!lang_node) {
+		lang_node = node;
+	}
+
+	ret = mxmlFindElement(lang_node, documentation_tree, var, NULL, NULL, MXML_DESCEND);
+    
+	if (!ret || !ret->child) {
+		ast_log(LOG_WARNING, "Cannot find varible '%s' in tree '%s'\n", name, var);
+		return fail;
+	}
+
+	/* Dont need fail anymore */
+	free(fail);
+	tmp = malloc(sizeof(ret->child->value.opaque));
+	if(!tmp) {
+		ast_log(LOG_ERROR, "Malloc Failed, uh oh.\n");
+		return fail;
+	}
+
+	ast_log(LOG_ERROR, "Value for name:'%s', type:'%s', var:'%s', value:'%s'\n\n", name, type, var, ret->child->value.opaque);
+	snprintf(tmp, sizeof(tmp), "%s", ret->child->value.opaque);
+	return tmp;
+}
+
 int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_module *mod)
 {
 	struct ast_custom_function *cur;
@@ -2620,38 +2679,11 @@
 	acf->mod = mod;
 
 	/* Let's try to find it in the Documentation XML */
-	if (!acf->desc || !acf->synopsis) {
-		mxml_node_t *node, *lang_node, *desc, *syn;
-		node = lang_node = desc = syn = NULL;
-		if (!documentation_tree) {
-			ast_log(LOG_WARNING, "Cannot get description or synopsis for Dialplan Function, Not Registering It.\n");
-			return -1;
-		}
-		node = mxmlFindElement(documentation_tree, documentation_tree, "function", "name", acf->name, MXML_DESCEND);
-
-		if (!node) {
-			ast_log(LOG_WARNING, "Cannot find Function Documentation for Func: '%s'\n", acf->name);
-			return -1;
-		}
-
-	
-		lang_node = mxmlFindElement(node, documentation_tree, "application", "language", documentation_language, MXML_DESCEND);	
-	
-		/* Could not find language, use the default one without a language */
-		if (!lang_node) {
-			lang_node = node;
-		}
-	
-		syn = mxmlFindElement(lang_node, documentation_tree, "synopsis", NULL, NULL, MXML_DESCEND);
-		desc = mxmlFindElement(lang_node, documentation_tree, "description", NULL, NULL, MXML_DESCEND);
-	    
-		if (!syn || !desc || !syn->child || !desc->child) {
-			ast_log(LOG_WARNING, "Cannot find Application description or synopsis for app: '%s'\n", acf->name);
-			return -1;
-		}
-
-		acf->synopsis =  syn->child->value.opaque;
-		acf->desc = desc->child->value.opaque;
+	if (ast_strlen_zero(acf->desc) && ast_strlen_zero(acf->synopsis)) {
+
+		acf->synopsis = ast_mxml_get_field("function", acf->name, "synopsis");
+		acf->desc = ast_mxml_get_field("function", acf->name, "description");
+
 	}
 
 	AST_RWLIST_WRLOCK(&acf_root);
@@ -4357,10 +4389,17 @@
 		return -1;
 	}
 
+	/* Try to lookup the docs in our XML documentation database */
+	if (ast_strlen_zero(synopsis) && ast_strlen_zero(description)) {
+		tmp->synopsis = ast_mxml_get_field("application", app, "synopsis");
+		tmp->description = ast_mxml_get_field("application", app, "description");
+	} else {
+		tmp->synopsis = synopsis;
+		tmp->description = description;
+	}	
+
 	strcpy(tmp->name, app);
 	tmp->execute = execute;
-	tmp->synopsis = synopsis;
-	tmp->description = description;
 	tmp->module = mod;
 
 	/* Store in alphabetical order */
@@ -4381,8 +4420,10 @@
 	return 0;
 }
 
-/* todo: If we cannot read the file, don't allow people to try to register
- * with ast_register_application_xml */
+void _mxml_error(const char *cb) {
+	ast_log(LOG_ERROR, "Loading XML Problem: '%s'\n", cb);
+	documentation_tree = NULL;
+}
 
 /*! \brief Load XML Document into buffer for parsing into a list */
 static int ast_load_documentation(void) {
@@ -4392,8 +4433,10 @@
 	/* For now, I just throw away cdata */
 	xmldoc = fopen(FILE_XML_DOC, "r");
 
+	mxmlSetErrorCallback(_mxml_error);
+
 	if (!xmldoc) {
-		ast_log(LOG_ERROR, "Could not open XML Doc at '%s'", FILE_XML_DOC);
+		ast_log(LOG_ERROR, "Could not open XML Doc at '%s'\n", FILE_XML_DOC);
 		return 1;
 	}
 
@@ -4407,89 +4450,6 @@
 
 	/* Ok, let's now process it. */
 	/* Check for errors in loading the doc */
-
-	return 0;
-}
-
-/*! \brief Dynamically register a new dial plan application */
-int ast_register_application_xml_real(const char *app, int (*execute)(struct ast_channel *, void *), void *mod)
-{
-	struct ast_app *tmp, *cur = NULL;
-	char tmps[80];
-	char *strapp;
-	int length, res;
-	mxml_node_t *node, *lang_node, *desc, *syn;
-
-	node = desc = syn = lang_node = NULL;
-
-	/* XXX If we do not have documentation, should we still register the application? */
-	if (!documentation_tree) {
-		ast_log(LOG_WARNING, "Cannot get description or synopsis for application, loading XML documentation failed.\n");
-		return -1;
-	}
-
-	AST_RWLIST_WRLOCK(&apps);
-	AST_RWLIST_TRAVERSE(&apps, tmp, list) {
-		if (!(res = strcasecmp(app, tmp->name))) {
-			ast_log(LOG_WARNING, "Already have an application '%s'\n", app);
-			AST_RWLIST_UNLOCK(&apps);
-			return -1;
-		} else if (res < 0)
-			break;
-	}
-
-	length = sizeof(*tmp) + strlen(app) + 1;
-
-	if (!(tmp = ast_calloc(1, length))) {
-		AST_RWLIST_UNLOCK(&apps);
-		return -1;
-	}
-	
-	strapp = ast_strdup(app);
-	node = mxmlFindElement(documentation_tree, documentation_tree, "application", "name", strapp, MXML_DESCEND);
-
-	if (!node) {
-		ast_log(LOG_WARNING, "Cannot find Application Documentation for app: '%s'\n", app);
-		return -1;
-	}
-
-
-	lang_node = mxmlFindElement(node, documentation_tree, "application", "language", documentation_language, MXML_DESCEND);	
-
-	/* Could not find language, use the default one without a language */
-	if (!lang_node) {
-		lang_node = node;
-	}
-
-	syn = mxmlFindElement(lang_node, documentation_tree, "synopsis", NULL, NULL, MXML_DESCEND);
-	desc = mxmlFindElement(lang_node, documentation_tree, "description", NULL, NULL, MXML_DESCEND);
-    
-	if (!syn || !desc || !syn->child || !desc->child) {
-		ast_log(LOG_WARNING, "Cannot find Application description or synopsis for app: '%s'\n", app);
-		return -1;
-	}
-
-	strcpy(tmp->name, app);
-	tmp->execute = execute;
-	tmp->synopsis = syn->child->value.opaque;
-	tmp->description = desc->child->value.opaque;
-	tmp->module = mod;
-
-	/* Store in alphabetical order */
-	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
-		if (strcasecmp(tmp->name, cur->name) < 0) {
-			AST_RWLIST_INSERT_BEFORE_CURRENT(tmp, list);
-			break;
-		}
-	}
-	AST_RWLIST_TRAVERSE_SAFE_END;
-	if (!cur) {
-		AST_RWLIST_INSERT_TAIL(&apps, tmp, list);
-	}
-
-	ast_verb(2, "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps)));
-
-	AST_RWLIST_UNLOCK(&apps);
 
 	return 0;
 }
@@ -8216,16 +8176,6 @@
 	struct ast_flags cnfflags = { 0 };
 #endif
 
-	/* Initialize the PBX */
-	ast_verb(1, "Asterisk PBX Core Initializing\n");
-	if (!(device_state_tps = ast_taskprocessor_get("pbx-core", 0))) {
-		ast_log(LOG_WARNING, "failed to create pbx-core taskprocessor\n");
-	}
-
-	ast_verb(1, "Registering builtin applications:\n");
-	ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(struct ast_cli_entry));
-	__ast_custom_function_register(&exception_function, NULL);
-
 #ifdef XML_DOCUMENTATION
 	snprintf(documentation_language, sizeof(documentation_language), "en");
 	if (!(cfg = ast_config_load("asterisk.conf", cnfflags))) {
@@ -8242,6 +8192,16 @@
 	/* Load Documentation XML Blob */
 	ast_load_documentation();
 #endif
+
+	/* Initialize the PBX */
+	ast_verb(1, "Asterisk PBX Core Initializing\n");
+	if (!(device_state_tps = ast_taskprocessor_get("pbx-core", 0))) {
+		ast_log(LOG_WARNING, "failed to create pbx-core taskprocessor\n");
+	}
+
+	ast_verb(1, "Registering builtin applications:\n");
+	ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(struct ast_cli_entry));
+	__ast_custom_function_register(&exception_function, NULL);
 
 	/* Register builtin applications */
 	for (x = 0; x < sizeof(builtins) / sizeof(struct pbx_builtin); x++) {




More information about the svn-commits mailing list