[asterisk-commits] tilghman: branch tilghman/str_substitution r178985 - in /team/tilghman/str_su...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Feb 26 18:26:41 CST 2009


Author: tilghman
Date: Thu Feb 26 18:26:37 2009
New Revision: 178985

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=178985
Log:
Add a read2_max item, to make it less necessary to convert legacy functions with very small results.

Modified:
    team/tilghman/str_substitution/funcs/func_callerid.c
    team/tilghman/str_substitution/funcs/func_db.c
    team/tilghman/str_substitution/funcs/func_dialplan.c
    team/tilghman/str_substitution/funcs/func_env.c
    team/tilghman/str_substitution/funcs/func_extstate.c
    team/tilghman/str_substitution/funcs/func_groupcount.c
    team/tilghman/str_substitution/funcs/func_lock.c
    team/tilghman/str_substitution/funcs/func_logic.c
    team/tilghman/str_substitution/funcs/func_md5.c
    team/tilghman/str_substitution/funcs/func_module.c
    team/tilghman/str_substitution/funcs/func_rand.c
    team/tilghman/str_substitution/funcs/func_sha1.c
    team/tilghman/str_substitution/funcs/func_speex.c
    team/tilghman/str_substitution/funcs/func_strings.c
    team/tilghman/str_substitution/funcs/func_sysinfo.c
    team/tilghman/str_substitution/funcs/func_timeout.c
    team/tilghman/str_substitution/funcs/func_vmcount.c
    team/tilghman/str_substitution/include/asterisk/pbx.h
    team/tilghman/str_substitution/main/pbx.c

Modified: team/tilghman/str_substitution/funcs/func_callerid.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_callerid.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_callerid.c (original)
+++ team/tilghman/str_substitution/funcs/func_callerid.c Thu Feb 26 18:26:37 2009
@@ -274,12 +274,14 @@
 static struct ast_custom_function callerid_function = {
 	.name = "CALLERID",
 	.read = callerid_read,
+	.read2_max = 256,
 	.write = callerid_write,
 };
 
 static struct ast_custom_function callerpres_function = {
 	.name = "CALLERPRES",
 	.read = callerpres_read,
+	.read2_max = 50,
 	.write = callerpres_write,
 };
 

Modified: team/tilghman/str_substitution/funcs/func_db.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_db.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_db.c (original)
+++ team/tilghman/str_substitution/funcs/func_db.c Thu Feb 26 18:26:37 2009
@@ -201,6 +201,7 @@
 static struct ast_custom_function db_exists_function = {
 	.name = "DB_EXISTS",
 	.read = function_db_exists,
+	.read2_max = 2,
 };
 
 static int function_db_delete(struct ast_channel *chan, const char *cmd,

Modified: team/tilghman/str_substitution/funcs/func_dialplan.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_dialplan.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_dialplan.c (original)
+++ team/tilghman/str_substitution/funcs/func_dialplan.c Thu Feb 26 18:26:37 2009
@@ -105,6 +105,7 @@
 static struct ast_custom_function isexten_function = {
 	.name = "DIALPLAN_EXISTS",
 	.read = isexten_function_read,
+	.read2_max = 2,
 };
 
 static int unload_module(void)

Modified: team/tilghman/str_substitution/funcs/func_env.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_env.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_env.c (original)
+++ team/tilghman/str_substitution/funcs/func_env.c Thu Feb 26 18:26:37 2009
@@ -210,7 +210,8 @@
 
 static struct ast_custom_function stat_function = {
 	.name = "STAT",
-	.read = stat_read
+	.read = stat_read,
+	.read2_max = 12,
 };
 
 static struct ast_custom_function file_function = {

Modified: team/tilghman/str_substitution/funcs/func_extstate.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_extstate.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_extstate.c (original)
+++ team/tilghman/str_substitution/funcs/func_extstate.c Thu Feb 26 18:26:37 2009
@@ -122,6 +122,7 @@
 static struct ast_custom_function extstate_function = {
 	.name = "EXTENSION_STATE",
 	.read = extstate_read,
+	.read2_max = 12,
 };
 
 static int unload_module(void)

Modified: team/tilghman/str_substitution/funcs/func_groupcount.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_groupcount.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_groupcount.c (original)
+++ team/tilghman/str_substitution/funcs/func_groupcount.c Thu Feb 26 18:26:37 2009
@@ -134,6 +134,7 @@
 static struct ast_custom_function group_count_function = {
 	.name = "GROUP_COUNT",
 	.read = group_count_function_read,
+	.read2_max = 12,
 };
 
 static int group_match_count_function_read(struct ast_channel *chan,
@@ -159,6 +160,7 @@
 static struct ast_custom_function group_match_count_function = {
 	.name = "GROUP_MATCH_COUNT",
 	.read = group_match_count_function_read,
+	.read2_max = 12,
 	.write = NULL,
 };
 

Modified: team/tilghman/str_substitution/funcs/func_lock.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_lock.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_lock.c (original)
+++ team/tilghman/str_substitution/funcs/func_lock.c Thu Feb 26 18:26:37 2009
@@ -324,16 +324,19 @@
 static struct ast_custom_function lock_function = {
 	.name = "LOCK",
 	.read = lock_read,
+	.read2_max = 2,
 };
 
 static struct ast_custom_function trylock_function = {
 	.name = "TRYLOCK",
 	.read = trylock_read,
+	.read2_max = 2,
 };
 
 static struct ast_custom_function unlock_function = {
 	.name = "UNLOCK",
 	.read = unlock_read,
+	.read2_max = 2,
 };
 
 static int unload_module(void)

Modified: team/tilghman/str_substitution/funcs/func_logic.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_logic.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_logic.c (original)
+++ team/tilghman/str_substitution/funcs/func_logic.c Thu Feb 26 18:26:37 2009
@@ -223,21 +223,35 @@
 	return 0;
 }
 
-static int acf_import(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
+static int set2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, int len)
+{
+	if (len > -1) {
+		ast_str_make_space(str, len == 0 ? strlen(data) : len);
+	}
+	return set(chan, cmd, data, ast_str_buffer(*str), ast_str_size(*str));
+}
+
+static int import_helper(struct ast_channel *chan, const char *cmd, char *data, char *buf, struct ast_str **str, int len)
 {
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(channel);
 		AST_APP_ARG(varname);
 	);
 	AST_STANDARD_APP_ARGS(args, data);
-	buf[0] = 0;
+	if (buf) {
+		*buf = '\0';
+	}
 	if (!ast_strlen_zero(args.varname)) {
 		struct ast_channel *chan2 = ast_get_channel_by_name_locked(args.channel);
 		if (chan2) {
 			char *s = alloca(strlen(args.varname) + 4);
 			if (s) {
 				sprintf(s, "${%s}", args.varname);
-				pbx_substitute_variables_helper(chan2, s, buf, len);
+				if (buf) {
+					pbx_substitute_variables_helper(chan2, s, buf, len);
+				} else {
+					ast_str_substitute_variables(str, len, chan2, s);
+				}
 			}
 			ast_channel_unlock(chan2);
 		}
@@ -245,19 +259,32 @@
 	return 0;
 }
 
+static int import_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
+{
+	return import_helper(chan, cmd, data, buf, NULL, len);
+}
+
+static int import_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, int len)
+{
+	return import_helper(chan, cmd, data, NULL, str, len);
+}
+
 static struct ast_custom_function isnull_function = {
 	.name = "ISNULL",
 	.read = isnull,
+	.read2_max = 2,
 };
 
 static struct ast_custom_function set_function = {
 	.name = "SET",
 	.read = set,
+	.read2 = set2,
 };
 
 static struct ast_custom_function exists_function = {
 	.name = "EXISTS",
 	.read = exists,
+	.read2_max = 2,
 };
 
 static struct ast_custom_function if_function = {
@@ -272,7 +299,8 @@
 
 static struct ast_custom_function import_function = {
 	.name = "IMPORT",
-	.read = acf_import,
+	.read = import_read,
+	.read2 = import_read2,
 };
 
 static int unload_module(void)

Modified: team/tilghman/str_substitution/funcs/func_md5.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_md5.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_md5.c (original)
+++ team/tilghman/str_substitution/funcs/func_md5.c Thu Feb 26 18:26:37 2009
@@ -64,6 +64,7 @@
 static struct ast_custom_function md5_function = {
 	.name = "MD5",
 	.read = md5,
+	.read2_max = 33,
 };
 
 static int unload_module(void)

Modified: team/tilghman/str_substitution/funcs/func_module.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_module.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_module.c (original)
+++ team/tilghman/str_substitution/funcs/func_module.c Thu Feb 26 18:26:37 2009
@@ -65,6 +65,7 @@
 static struct ast_custom_function ifmodule_function = {
 	.name = "IFMODULE",
 	.read = ifmodule_read,
+	.read2_max = 2,
 };
 
 

Modified: team/tilghman/str_substitution/funcs/func_rand.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_rand.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_rand.c (original)
+++ team/tilghman/str_substitution/funcs/func_rand.c Thu Feb 26 18:26:37 2009
@@ -87,6 +87,7 @@
 static struct ast_custom_function acf_rand = {
 	.name = "RAND",
 	.read = acf_rand_exec,
+	.read2_max = 12,
 };
 
 static int unload_module(void)

Modified: team/tilghman/str_substitution/funcs/func_sha1.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_sha1.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_sha1.c (original)
+++ team/tilghman/str_substitution/funcs/func_sha1.c Thu Feb 26 18:26:37 2009
@@ -74,6 +74,7 @@
 static struct ast_custom_function sha1_function = {
 	.name = "SHA1",
 	.read = sha1,
+	.read2_max = 42,
 };
 
 static int unload_module(void)

Modified: team/tilghman/str_substitution/funcs/func_speex.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_speex.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_speex.c (original)
+++ team/tilghman/str_substitution/funcs/func_speex.c Thu Feb 26 18:26:37 2009
@@ -337,13 +337,15 @@
 static struct ast_custom_function agc_function = {
 	.name = "AGC",
 	.write = speex_write,
-	.read = speex_read
+	.read = speex_read,
+	.read2_max = 22,
 };
 
 static struct ast_custom_function denoise_function = {
 	.name = "DENOISE",
 	.write = speex_write,
-	.read = speex_read
+	.read = speex_read,
+	.read2_max = 22,
 };
 
 static int unload_module(void)

Modified: team/tilghman/str_substitution/funcs/func_strings.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_strings.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_strings.c (original)
+++ team/tilghman/str_substitution/funcs/func_strings.c Thu Feb 26 18:26:37 2009
@@ -828,6 +828,7 @@
 static struct ast_custom_function len_function = {
 	.name = "LEN",
 	.read = len,
+	.read2_max = 12,
 };
 
 static int acf_strftime(struct ast_channel *chan, const char *cmd, char *parse,

Modified: team/tilghman/str_substitution/funcs/func_sysinfo.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_sysinfo.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_sysinfo.c (original)
+++ team/tilghman/str_substitution/funcs/func_sysinfo.c Thu Feb 26 18:26:37 2009
@@ -86,6 +86,7 @@
 	.synopsis = "Returns system information specified by parameter.",
 	.syntax = "SYSINFO(<parameter>)",
 	.read = sysinfo_helper,
+	.read2_max = 22,
 	.desc = 
 "Returns information from a given parameter\n"
 "  Options:\n"

Modified: team/tilghman/str_substitution/funcs/func_timeout.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_timeout.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_timeout.c (original)
+++ team/tilghman/str_substitution/funcs/func_timeout.c Thu Feb 26 18:26:37 2009
@@ -191,6 +191,7 @@
 static struct ast_custom_function timeout_function = {
 	.name = "TIMEOUT",
 	.read = timeout_read,
+	.read2_max = 22,
 	.write = timeout_write,
 };
 

Modified: team/tilghman/str_substitution/funcs/func_vmcount.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_vmcount.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/funcs/func_vmcount.c (original)
+++ team/tilghman/str_substitution/funcs/func_vmcount.c Thu Feb 26 18:26:37 2009
@@ -97,6 +97,7 @@
 struct ast_custom_function acf_vmcount = {
 	.name = "VMCOUNT",
 	.read = acf_vmcount_exec,
+	.read2_max = 12,
 };
 
 static int unload_module(void)

Modified: team/tilghman/str_substitution/include/asterisk/pbx.h
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/include/asterisk/pbx.h?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/include/asterisk/pbx.h (original)
+++ team/tilghman/str_substitution/include/asterisk/pbx.h Thu Feb 26 18:26:37 2009
@@ -90,6 +90,7 @@
 	enum ast_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 (*read2)(struct ast_channel *, const char *, char *, struct ast_str **, int);	/*!< Read function, if read is supported */
+	size_t read2_max;                                                           /*!< If no read2 function is provided, what maximum size? */
 	int (*write)(struct ast_channel *, const char *, char *, const char *);		/*!< Write function, if write is supported */
 	struct ast_module *mod;         /*!< Module this custom function belongs to */
 	AST_RWLIST_ENTRY(ast_custom_function) acflist;

Modified: team/tilghman/str_substitution/main/pbx.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/main/pbx.c?view=diff&rev=178985&r1=178984&r2=178985
==============================================================================
--- team/tilghman/str_substitution/main/pbx.c (original)
+++ team/tilghman/str_substitution/main/pbx.c Thu Feb 26 18:26:37 2009
@@ -3435,10 +3435,20 @@
 			res = acfptr->read2(chan, copy, args, str, maxlen);
 		} else {
 			/* Legacy function pointer, allocate buffer for result */
+			int maxsize = ast_str_size(*str);
 			if (maxlen > -1) {
-				ast_str_make_space(str, maxlen ? maxlen : VAR_BUF_SIZE);
-			}
-			res = acfptr->read(chan, copy, args, ast_str_buffer(*str), maxlen > 0 ? maxlen : maxlen < 0 ? ast_str_size(*str) : VAR_BUF_SIZE);
+				if (maxlen == 0) {
+					if (acfptr->read2_max) {
+						maxsize = acfptr->read2_max;
+					} else {
+						maxsize = VAR_BUF_SIZE;
+					}
+				} else {
+					maxsize = maxlen;
+				}
+				ast_str_make_space(str, maxsize);
+			}
+			res = acfptr->read(chan, copy, args, ast_str_buffer(*str), maxsize);
 		}
 		if (acfptr->mod && u) {
 			__ast_module_user_remove(acfptr->mod, u);




More information about the asterisk-commits mailing list