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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 9 18:41:34 CST 2009


Author: tilghman
Date: Mon Feb  9 18:41:34 2009
New Revision: 174367

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=174367
Log:
A few more less significant conversions

Modified:
    team/tilghman/str_substitution/funcs/func_curl.c
    team/tilghman/str_substitution/funcs/func_strings.c
    team/tilghman/str_substitution/main/pbx.c

Modified: team/tilghman/str_substitution/funcs/func_curl.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_curl.c?view=diff&rev=174367&r1=174366&r2=174367
==============================================================================
--- team/tilghman/str_substitution/funcs/func_curl.c (original)
+++ team/tilghman/str_substitution/funcs/func_curl.c Mon Feb  9 18:41:34 2009
@@ -391,7 +391,7 @@
 
 AST_THREADSTORAGE_CUSTOM(curl_instance, curl_instance_init, curl_instance_cleanup);
 
-static int acf_curl_exec(struct ast_channel *chan, const char *cmd, char *info, char *buf, size_t len)
+static int acf_curl_helper(struct ast_channel *chan, const char *cmd, char *info, char *buf, struct ast_str **input_str, int len)
 {
 	struct ast_str *str = ast_str_create(16);
 	int ret = -1;
@@ -483,11 +483,19 @@
 				rowcount++;
 			}
 			pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", ast_str_buffer(fields));
-			ast_copy_string(buf, ast_str_buffer(values), len);
+			if (buf) {
+				ast_copy_string(buf, ast_str_buffer(values), len);
+			} else {
+				ast_str_set(input_str, len, "%s", ast_str_buffer(values));
+			}
 			ast_free(fields);
 			ast_free(values);
 		} else {
-			ast_copy_string(buf, ast_str_buffer(str), len);
+			if (buf) {
+				ast_copy_string(buf, ast_str_buffer(str), len);
+			} else {
+				ast_str_set(input_str, len, "%s", ast_str_buffer(str));
+			}
 		}
 		ret = 0;
 	}
@@ -497,6 +505,16 @@
 		ast_autoservice_stop(chan);
 	
 	return ret;
+}
+
+static int acf_curl_exec(struct ast_channel *chan, const char *cmd, char *info, char *buf, size_t len)
+{
+	return acf_curl_helper(chan, cmd, info, buf, NULL, len);
+}
+
+static int acf_curl2_exec(struct ast_channel *chan, const char *cmd, char *info, struct ast_str **buf, int len)
+{
+	return acf_curl_helper(chan, cmd, info, NULL, buf, len);
 }
 
 struct ast_custom_function acf_curl = {
@@ -507,6 +525,7 @@
 	"  url       - URL to retrieve\n"
 	"  post-data - Optional data to send as a POST (GET is default action)\n",
 	.read = acf_curl_exec,
+	.read2 = acf_curl2_exec,
 };
 
 struct ast_custom_function acf_curlopt = {

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=174367&r1=174366&r2=174367
==============================================================================
--- team/tilghman/str_substitution/funcs/func_strings.c (original)
+++ team/tilghman/str_substitution/funcs/func_strings.c Mon Feb  9 18:41:34 2009
@@ -273,10 +273,11 @@
 	</function>
  ***/
 
-static int function_fieldqty(struct ast_channel *chan, const char *cmd,
-			     char *parse, char *buf, size_t len)
-{
-	char *varsubst, varval[8192], *varval2 = varval;
+static int function_fieldqty_helper(struct ast_channel *chan, const char *cmd,
+			     char *parse, char *buf, struct ast_str **sbuf, int len)
+{
+	char *varsubst;
+	struct ast_str *str = ast_str_create(16);
 	int fieldcount = 0;
 	AST_DECLARE_APP_ARGS(args,
 			     AST_APP_ARG(varname);
@@ -285,6 +286,10 @@
 	char delim[2] = "";
 	size_t delim_used;
 
+	if (!str) {
+		return -1;
+	}
+
 	AST_STANDARD_APP_ARGS(args, parse);
 	if (args.delim) {
 		ast_get_encoded_char(args.delim, delim, &delim_used);
@@ -292,24 +297,44 @@
 		varsubst = alloca(strlen(args.varname) + 4);
 
 		sprintf(varsubst, "${%s}", args.varname);
-		pbx_substitute_variables_helper(chan, varsubst, varval, sizeof(varval) - 1);
-		if (ast_strlen_zero(varval2))
+		ast_str_substitute_variables(&str, 0, chan, varsubst);
+		if (ast_str_strlen(str) == 0) {
 			fieldcount = 0;
-		else {
-			while (strsep(&varval2, delim))
+		} else {
+			char *varval = ast_str_buffer(str);
+			while (strsep(&varval, delim)) {
 				fieldcount++;
+			}
 		}
 	} else {
 		fieldcount = 1;
 	}
-	snprintf(buf, len, "%d", fieldcount);
-
-	return 0;
+	if (sbuf) {
+		ast_str_set(sbuf, len, "%d", fieldcount);
+	} else {
+		snprintf(buf, len, "%d", fieldcount);
+	}
+
+	ast_free(str);
+	return 0;
+}
+
+static int function_fieldqty(struct ast_channel *chan, const char *cmd,
+			     char *parse, char *buf, size_t len)
+{
+	return function_fieldqty_helper(chan, cmd, parse, buf, NULL, len);
+}
+
+static int function_fieldqty_str(struct ast_channel *chan, const char *cmd,
+				 char *parse, struct ast_str **buf, int len)
+{
+	return function_fieldqty_helper(chan, cmd, parse, NULL, buf, len);
 }
 
 static struct ast_custom_function fieldqty_function = {
 	.name = "FIELDQTY",
 	.read = function_fieldqty,
+	.read2 = function_fieldqty_str,
 };
 
 static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
@@ -609,22 +634,44 @@
 static int hashkeys_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
 	struct ast_var_t *newvar;
-	int plen;
-	char prefix[80];
-	snprintf(prefix, sizeof(prefix), HASH_PREFIX, data);
-	plen = strlen(prefix);
-
+	struct ast_str *prefix = ast_str_alloca(80);
+
+	ast_str_set(&prefix, -1, HASH_PREFIX, data);
 	memset(buf, 0, len);
+
 	AST_LIST_TRAVERSE(&chan->varshead, newvar, entries) {
-		if (strncasecmp(prefix, ast_var_name(newvar), plen) == 0) {
+		if (strncasecmp(ast_str_buffer(prefix), ast_var_name(newvar), ast_str_strlen(prefix)) == 0) {
 			/* Copy everything after the prefix */
-			strncat(buf, ast_var_name(newvar) + plen, len - strlen(buf) - 1);
+			strncat(buf, ast_var_name(newvar) + ast_str_strlen(prefix), len - strlen(buf) - 1);
 			/* Trim the trailing ~ */
 			buf[strlen(buf) - 1] = ',';
 		}
 	}
 	/* Trim the trailing comma */
 	buf[strlen(buf) - 1] = '\0';
+	return 0;
+}
+
+static int hashkeys_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, int len)
+{
+	struct ast_var_t *newvar;
+	struct ast_str *prefix = ast_str_alloca(80);
+	char *tmp;
+
+	ast_str_set(&prefix, -1, HASH_PREFIX, data);
+
+	AST_LIST_TRAVERSE(&chan->varshead, newvar, entries) {
+		if (strncasecmp(ast_str_buffer(prefix), ast_var_name(newvar), ast_str_strlen(prefix)) == 0) {
+			/* Copy everything after the prefix */
+			ast_str_append(buf, len, "%s", ast_var_name(newvar) + ast_str_strlen(prefix));
+			/* Trim the trailing ~ */
+			tmp = ast_str_buffer(*buf);
+			tmp[ast_str_strlen(*buf) - 1] = ',';
+		}
+	}
+	/* Trim the trailing comma */
+	tmp = ast_str_buffer(*buf);
+	tmp[ast_str_strlen(*buf) - 1] = '\0';
 	return 0;
 }
 
@@ -703,6 +750,7 @@
 static struct ast_custom_function hashkeys_function = {
 	.name = "HASHKEYS",
 	.read = hashkeys_read,
+	.read2 = hashkeys_read2,
 };
 
 static struct ast_custom_function array_function = {
@@ -845,9 +893,23 @@
 	return 0;
 }
 
+static int function_eval2(struct ast_channel *chan, const char *cmd, char *data,
+			 struct ast_str **buf, int buflen)
+{
+	if (ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n");
+		return -1;
+	}
+
+	ast_str_substitute_variables(buf, buflen, chan, data);
+
+	return 0;
+}
+
 static struct ast_custom_function eval_function = {
 	.name = "EVAL",
 	.read = function_eval,
+	.read2 = function_eval2,
 };
 
 static int keypadhash(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

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=174367&r1=174366&r2=174367
==============================================================================
--- team/tilghman/str_substitution/main/pbx.c (original)
+++ team/tilghman/str_substitution/main/pbx.c Mon Feb  9 18:41:34 2009
@@ -3397,6 +3397,7 @@
 			u = __ast_module_user_add(acfptr->mod, chan);
 		if (acfptr->read2) {
 			/* ast_str enabled */
+			ast_str_reset(*str);
 			res = acfptr->read2(chan, copy, args, str, maxlen);
 		} else {
 			/* Legacy function pointer, allocate buffer for result */




More information about the asterisk-commits mailing list