[asterisk-commits] eliel: branch group/appdocsxml r151418 - in /team/group/appdocsxml: funcs/ in...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 21 16:14:00 CDT 2008


Author: eliel
Date: Tue Oct 21 16:14:00 2008
New Revision: 151418

URL: http://svn.digium.com/view/asterisk?view=rev&rev=151418
Log:
Implement ast_custom_function with STRING_FIELDS.

Modified:
    team/group/appdocsxml/funcs/func_odbc.c
    team/group/appdocsxml/include/asterisk/pbx.h
    team/group/appdocsxml/main/pbx.c

Modified: team/group/appdocsxml/funcs/func_odbc.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/funcs/func_odbc.c?view=diff&rev=151418&r1=151417&r2=151418
==============================================================================
--- team/group/appdocsxml/funcs/func_odbc.c (original)
+++ team/group/appdocsxml/funcs/func_odbc.c Tue Oct 21 16:14:00 2008
@@ -755,6 +755,12 @@
 		*query = NULL;
 		return ENOMEM;
 	}
+	if (ast_string_field_init((*query)->acf, 128)) {
+		ast_free((*query)->acf);
+		ast_free(*query);
+		*query = NULL;
+		return ENOMEM;
+	}
 
 	if ((tmp = ast_variable_retrieve(cfg, catg, "prefix")) && !ast_strlen_zero(tmp)) {
 		asprintf((char **)&((*query)->acf->name), "%s_%s", tmp, catg);
@@ -763,6 +769,7 @@
 	}
 
 	if (!((*query)->acf->name)) {
+		ast_string_field_free_memory((*query)->acf);
 		ast_free((*query)->acf);
 		ast_free(*query);
 		*query = NULL;
@@ -770,12 +777,69 @@
 	}
 
 	if ((tmp = ast_variable_retrieve(cfg, catg, "syntax")) && !ast_strlen_zero(tmp)) {
-		asprintf((char **)&((*query)->acf->syntax), "%s(%s)", (*query)->acf->name, tmp);
+		ast_string_field_build((*query)->acf, syntax, "%s(%s)", (*query)->acf->name, tmp);
 	} else {
-		asprintf((char **)&((*query)->acf->syntax), "%s(<arg1>[...[,<argN>]])", (*query)->acf->name);
-	}
-
-	if (!((*query)->acf->syntax)) {
+		ast_string_field_build((*query)->acf, syntax, "%s(<arg1>[...[,<argN>]])", (*query)->acf->name);
+	}
+
+	if (ast_strlen_zero((*query)->acf->syntax)) {
+		ast_free((char *)(*query)->acf->name);
+		ast_string_field_free_memory((*query)->acf);
+		ast_free((*query)->acf);
+		ast_free(*query);
+		*query = NULL;
+		return ENOMEM;
+	}
+
+	if ((tmp = ast_variable_retrieve(cfg, catg, "synopsis")) && !ast_strlen_zero(tmp)) {
+		ast_string_field_set((*query)->acf, synopsis, tmp);
+	} else {
+		ast_string_field_set((*query)->acf, synopsis, "Runs the referenced query with the specified arguments");
+	}
+
+	if (ast_strlen_zero((*query)->acf->synopsis)) {
+		ast_free((char *)(*query)->acf->name);
+		ast_string_field_free_memory((*query)->acf);
+		ast_free((*query)->acf);
+		ast_free(*query);
+		*query = NULL;
+		return ENOMEM;
+	}
+
+	if (!ast_strlen_zero((*query)->sql_read) && !ast_strlen_zero((*query)->sql_write)) {
+		ast_string_field_build((*query)->acf, desc,
+						"Runs the following query, as defined in func_odbc.conf, performing\n"
+					   	"substitution of the arguments into the query as specified by ${ARG1},\n"
+						"${ARG2}, ... ${ARGn}.  When setting the function, the values are provided\n"
+						"either in whole as ${VALUE} or parsed as ${VAL1}, ${VAL2}, ... ${VALn}.\n"
+						"\nRead:\n%s\n\nWrite:\n%s\n",
+						(*query)->sql_read,
+						(*query)->sql_write);
+	} else if (!ast_strlen_zero((*query)->sql_read)) {
+		ast_string_field_build((*query)->acf, desc,
+						"Runs the following query, as defined in func_odbc.conf, performing\n"
+					   	"substitution of the arguments into the query as specified by ${ARG1},\n"
+						"${ARG2}, ... ${ARGn}.  This function may only be read, not set.\n\nSQL:\n%s\n",
+						(*query)->sql_read);
+	} else if (!ast_strlen_zero((*query)->sql_write)) {
+		ast_string_field_build((*query)->acf, desc,
+						"Runs the following query, as defined in func_odbc.conf, performing\n"
+					   	"substitution of the arguments into the query as specified by ${ARG1},\n"
+						"${ARG2}, ... ${ARGn}.  The values are provided either in whole as\n"
+						"${VALUE} or parsed as ${VAL1}, ${VAL2}, ... ${VALn}.\n"
+						"This function may only be set.\nSQL:\n%s\n",
+						(*query)->sql_write);
+	} else {
+		ast_string_field_free_memory((*query)->acf);
+		ast_free((char *)(*query)->acf->name);
+		ast_free((*query)->acf);
+		ast_free(*query);
+		ast_log(LOG_WARNING, "Section %s was found, but there was no SQL to execute.  Ignoring.\n", catg);
+		return EINVAL;
+	}
+
+	if (ast_strlen_zero((*query)->acf->desc)) {
+		ast_string_field_free_memory((*query)->acf);
 		ast_free((char *)(*query)->acf->name);
 		ast_free((*query)->acf);
 		ast_free(*query);
@@ -783,64 +847,6 @@
 		return ENOMEM;
 	}
 
-	if ((tmp = ast_variable_retrieve(cfg, catg, "synopsis")) && !ast_strlen_zero(tmp)) {
-		(*query)->acf->synopsis = ast_strdup(tmp);
-	} else {
-		(*query)->acf->synopsis = ast_strdup("Runs the referenced query with the specified arguments");
-	}
-
-	if (!((*query)->acf->synopsis)) {
-		ast_free((char *)(*query)->acf->name);
-		ast_free((char *)(*query)->acf->syntax);
-		ast_free((*query)->acf);
-		ast_free(*query);
-		*query = NULL;
-		return ENOMEM;
-	}
-
-	if (!ast_strlen_zero((*query)->sql_read) && !ast_strlen_zero((*query)->sql_write)) {
-		asprintf((char **)&((*query)->acf->desc),
-					"Runs the following query, as defined in func_odbc.conf, performing\n"
-				   	"substitution of the arguments into the query as specified by ${ARG1},\n"
-					"${ARG2}, ... ${ARGn}.  When setting the function, the values are provided\n"
-					"either in whole as ${VALUE} or parsed as ${VAL1}, ${VAL2}, ... ${VALn}.\n"
-					"\nRead:\n%s\n\nWrite:\n%s\n",
-					(*query)->sql_read,
-					(*query)->sql_write);
-	} else if (!ast_strlen_zero((*query)->sql_read)) {
-		asprintf((char **)&((*query)->acf->desc),
-					"Runs the following query, as defined in func_odbc.conf, performing\n"
-				   	"substitution of the arguments into the query as specified by ${ARG1},\n"
-					"${ARG2}, ... ${ARGn}.  This function may only be read, not set.\n\nSQL:\n%s\n",
-					(*query)->sql_read);
-	} else if (!ast_strlen_zero((*query)->sql_write)) {
-		asprintf((char **)&((*query)->acf->desc),
-					"Runs the following query, as defined in func_odbc.conf, performing\n"
-				   	"substitution of the arguments into the query as specified by ${ARG1},\n"
-					"${ARG2}, ... ${ARGn}.  The values are provided either in whole as\n"
-					"${VALUE} or parsed as ${VAL1}, ${VAL2}, ... ${VALn}.\n"
-					"This function may only be set.\nSQL:\n%s\n",
-					(*query)->sql_write);
-	} else {
-		ast_free((char *)(*query)->acf->synopsis);
-		ast_free((char *)(*query)->acf->syntax);
-		ast_free((char *)(*query)->acf->name);
-		ast_free((*query)->acf);
-		ast_free(*query);
-		ast_log(LOG_WARNING, "Section %s was found, but there was no SQL to execute.  Ignoring.\n", catg);
-		return EINVAL;
-	}
-
-	if (! ((*query)->acf->desc)) {
-		ast_free((char *)(*query)->acf->synopsis);
-		ast_free((char *)(*query)->acf->syntax);
-		ast_free((char *)(*query)->acf->name);
-		ast_free((*query)->acf);
-		ast_free(*query);
-		*query = NULL;
-		return ENOMEM;
-	}
-
 	if (ast_strlen_zero((*query)->sql_read)) {
 		(*query)->acf->read = NULL;
 	} else {
@@ -862,12 +868,7 @@
 		if (query->acf) {
 			if (query->acf->name)
 				ast_free((char *)query->acf->name);
-			if (query->acf->syntax)
-				ast_free((char *)query->acf->syntax);
-			if (query->acf->synopsis)
-				ast_free((char *)query->acf->synopsis);
-			if (query->acf->desc)
-				ast_free((char *)query->acf->desc);
+			ast_string_field_free_memory(query->acf);
 			ast_free(query->acf);
 		}
 		ast_free(query);

Modified: team/group/appdocsxml/include/asterisk/pbx.h
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/include/asterisk/pbx.h?view=diff&rev=151418&r1=151417&r2=151418
==============================================================================
--- team/group/appdocsxml/include/asterisk/pbx.h (original)
+++ team/group/appdocsxml/include/asterisk/pbx.h Tue Oct 21 16:14:00 2008
@@ -26,6 +26,7 @@
 #include "asterisk/sched.h"
 #include "asterisk/chanvars.h"
 #include "asterisk/hashtab.h"
+#include "asterisk/stringfields.h"
 
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
@@ -80,12 +81,14 @@
 
 /*! \brief Data structure associated with a custom dialplan function */
 struct ast_custom_function {
-	const char *name;		/*!< Name */
-	char *synopsis;		/*!< Short description for "show functions" */
-	char *desc;		/*!< Help text that explains it all */
-	char *syntax;		/*!< Syntax description */
-	char *arguments;	/*!< Arguments description */
-	char *seealso;		/*!< See also */
+	const char *name;			/*!< Name */
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(synopsis);     /*!< Synopsis text for 'show functions' */
+		AST_STRING_FIELD(desc);		/*!< Description (help text) for 'show functions &lt;name&gt;' */
+		AST_STRING_FIELD(syntax);       /*!< Syntax text for 'core show functions' */
+		AST_STRING_FIELD(arguments);    /*!< Arguments description */
+		AST_STRING_FIELD(seealso);      /*!< See also */
+	);
 	enum doc_src docsrc;		/*!< Where the documentation come from */
 	int (*read)(struct ast_channel *, const char *, char *, char *, size_t);	/*!< Read function, if read is supported */
 	int (*write)(struct ast_channel *, const char *, char *, const char *);		/*!< Write function, if write is supported */

Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=151418&r1=151417&r2=151418
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Tue Oct 21 16:14:00 2008
@@ -59,7 +59,6 @@
 #include "asterisk/musiconhold.h"
 #include "asterisk/app.h"
 #include "asterisk/devicestate.h"
-#include "asterisk/stringfields.h"
 #include "asterisk/event.h"
 #include "asterisk/hashtab.h"
 #include "asterisk/module.h"
@@ -3016,7 +3015,7 @@
 		return CLI_FAILURE;
 	}
 
-	if (acf->syntax)
+	if (!ast_strlen_zero(acf->syntax))
 		syntax_size = strlen(acf->syntax) + 23;
 	else
 		syntax_size = strlen("Not available") + 23;
@@ -3029,41 +3028,41 @@
 	term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
 	term_color(destitle, "[Description]\n", COLOR_MAGENTA, 0, 40);
 	term_color(seealsotitle, "[See Also]\n", COLOR_MAGENTA, 0, 40);
-	term_color(syntax, acf->syntax ? acf->syntax : "Not available", COLOR_CYAN, 0, syntax_size);
+	term_color(syntax, S_OR(acf->syntax, "Not available"), COLOR_CYAN, 0, syntax_size);
 #ifdef XML_DOCUMENTATION
-	arguments = xmldoc_colorization(acf->arguments ? acf->arguments : "Not available", COLOR_CYAN, COLOR_BLACK);
-	synopsis = xmldoc_colorization(acf->synopsis ? acf->synopsis : "Not available", COLOR_CYAN, COLOR_BLACK);
-	description = xmldoc_colorization(acf->desc ? acf->desc : "Not available", COLOR_CYAN, COLOR_BLACK);
-	seealso = xmldoc_colorization(acf->seealso ? acf->seealso : "Not available", COLOR_CYAN, COLOR_BLACK);
+	arguments = xmldoc_colorization(S_OR(acf->arguments, "Not available"), COLOR_CYAN, COLOR_BLACK);
+	synopsis = xmldoc_colorization(S_OR(acf->synopsis, "Not available"), COLOR_CYAN, COLOR_BLACK);
+	description = xmldoc_colorization(S_OR(acf->desc, "Not available"), COLOR_CYAN, COLOR_BLACK);
+	seealso = xmldoc_colorization(S_OR(acf->seealso, "Not available"), COLOR_CYAN, COLOR_BLACK);
 #else
-	if (acf->synopsis)
+	if (!ast_strlen_zero(acf->synopsis))
 		synopsis_size = strlen(acf->synopsis) + 23;
 	else
 		synopsis_size = strlen("Not available") + 23;
 	synopsis = ast_malloc(synopsis_size);
 
-	if (acf->desc)
+	if (!ast_strlen_zero(acf->desc))
 		description_size = strlen(acf->desc) + 23;
 	else
 		description_size = strlen("Not available") + 23;
 	description = ast_malloc(description_size);
 
-	if (acf->arguments)
+	if (!ast_strlen_zero(acf->arguments))
 		arguments_size = strlen(acf->arguments) + 23;
 	else
 		arguments_size = strlen("Not available") + 23;
 	arguments = ast_malloc(arguments_size);
 
-	if (acf->seealso)
+	if (!ast_strlen_zero(acf->seealso))
 		seealso_size = strlen(acf->seealso) + 23;
 	else
 		seealso_size = strlen("Not available") + 23;
 	seealso = ast_malloc(seealso_size);
 
-	term_color(arguments, acf->arguments ? acf->arguments : "Not available", COLOR_CYAN, 0, arguments_size);
-	term_color(synopsis, acf->synopsis ? acf->synopsis : "Not available", COLOR_CYAN, 0, synopsis_size);
-	term_color(description, acf->desc ? acf->desc : "Not available", COLOR_CYAN, 0, description_size);
-	term_color(seealso, acf->seealso ? acf->seealso : "Not available", COLOR_CYAN, 0, seealso_size);
+	term_color(arguments, S_OR(acf->arguments, "Not available"), COLOR_CYAN, 0, arguments_size);
+	term_color(synopsis, S_OR(acf->synopsis, "Not available"), COLOR_CYAN, 0, synopsis_size);
+	term_color(description, S_OR(acf->desc, "Not available"), COLOR_CYAN, 0, description_size);
+	term_color(seealso, S_OR(acf->seealso, "Not available"), COLOR_CYAN, 0, seealso_size);
 #endif
 
 	ast_cli(a->fd,"%s%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n", infotitle, stxtitle, syntax, argtitle, arguments, 
@@ -3103,15 +3102,7 @@
 	if ((cur = AST_RWLIST_REMOVE(&acf_root, acf, acflist))) {
 #ifdef XML_DOCUMENTATION
 		if (cur->docsrc == AST_XML_DOC) {
-			if (cur->desc) {
-				ast_free(cur->desc);
-			}
-			if (cur->synopsis) {
-				ast_free(cur->synopsis);
-			}
-			if (cur->syntax) {
-				ast_free(cur->syntax);
-			}
+			ast_string_field_free_memory(acf);
 		}
 #endif
 		ast_verb(2, "Unregistered custom function %s\n", cur->name);
@@ -4495,6 +4486,9 @@
 {
 	struct ast_custom_function *cur;
 	char tmps[80];
+#ifdef XML_DOCUMENTATION
+	char *tmpxml;
+#endif
 
 	if (!acf)
 		return -1;
@@ -4505,11 +4499,35 @@
 #ifdef XML_DOCUMENTATION
 	/* Let's try to find it in the Documentation XML */
 	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_get_syntax("function", acf->name);
-		acf->arguments = xmldoc_build_arguments("function", acf->name);
-		acf->seealso = xmldoc_parse_seealso("function", acf->name);
+		if (ast_string_field_init(acf, 128)) {
+			return -1;
+		}
+
+		/* load synopsis */			
+		tmpxml = xmldoc_get_field("function", acf->name, "synopsis", 1);
+		ast_string_field_set(acf, synopsis, tmpxml);
+		ast_free(tmpxml);
+
+		/* load description */	
+		tmpxml = xmldoc_get_field("function", acf->name, "description", 0);
+		ast_string_field_set(acf, desc, tmpxml);
+		ast_free(tmpxml);
+
+		/* load syntax */
+		tmpxml = xmldoc_get_syntax("function", acf->name);
+		ast_string_field_set(acf, syntax, tmpxml);
+		ast_free(tmpxml);
+
+		/* load arguments */
+		tmpxml = xmldoc_build_arguments("function", acf->name);
+		ast_string_field_set(acf, arguments, tmpxml);
+		ast_free(tmpxml);
+
+		/* load seealso */
+		tmpxml = xmldoc_parse_seealso("function", acf->name);
+		ast_string_field_set(acf, seealso, tmpxml);
+		ast_free(tmpxml);
+
 		acf->docsrc = AST_XML_DOC;
 	}
 #endif




More information about the asterisk-commits mailing list