[asterisk-commits] rizzo: trunk r48559 - in /trunk: apps/ include/asterisk/ main/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Dec 18 08:38:50 MST 2006


Author: rizzo
Date: Mon Dec 18 09:38:50 2006
New Revision: 48559

URL: http://svn.digium.com/view/asterisk?view=rev&rev=48559
Log:
convert the final clients of ast_build_string to use ast_str_*()

Now the only module left using it is chan_sip.c


Modified:
    trunk/apps/app_dumpchan.c
    trunk/apps/app_queue.c
    trunk/include/asterisk/cdr.h
    trunk/include/asterisk/pbx.h
    trunk/main/cdr.c
    trunk/main/cli.c
    trunk/main/pbx.c

Modified: trunk/apps/app_dumpchan.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_dumpchan.c?view=diff&rev=48559&r1=48558&r2=48559
==============================================================================
--- trunk/apps/app_dumpchan.c (original)
+++ trunk/apps/app_dumpchan.c Mon Dec 18 09:38:50 2006
@@ -137,7 +137,7 @@
 static int dumpchan_exec(struct ast_channel *chan, void *data)
 {
 	struct ast_module_user *u;
-	char vars[BUFSIZ * 4];
+	struct ast_str *vars = ast_str_alloca(BUFSIZ * 4); /* XXX very large! */
 	char info[1024];
 	int level = 0;
 	static char *line = "================================================================================";
@@ -147,10 +147,10 @@
 	if (!ast_strlen_zero(data)) 
 		level = atoi(data);
 
-	pbx_builtin_serialize_variables(chan, vars, sizeof(vars));
+	pbx_builtin_serialize_variables(chan, &vars);
 	serialize_showchan(chan, info, sizeof(info));
 	if (option_verbose >= level)
-		ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n", chan->name, line, info, vars, line);
+		ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n", chan->name, line, info, vars->str, line);
 
 	ast_module_user_remove(u);
 	

Modified: trunk/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_queue.c?view=diff&rev=48559&r1=48558&r2=48559
==============================================================================
--- trunk/apps/app_queue.c (original)
+++ trunk/apps/app_queue.c Mon Dec 18 09:38:50 2006
@@ -1565,13 +1565,15 @@
 
 static char *vars2manager(struct ast_channel *chan, char *vars, size_t len)
 {
-	char *tmp = alloca(len);
-
-	if (pbx_builtin_serialize_variables(chan, tmp, len)) {
+	struct ast_str *buf = ast_str_alloca(len + 1);
+	char *tmp;
+
+	if (pbx_builtin_serialize_variables(chan, &buf)) {
 		int i, j;
 
 		/* convert "\n" to "\nVariable: " */
 		strcpy(vars, "Variable: ");
+		tmp = buf->str;
 
 		for (i = 0, j = 10; (i < len - 1) && (j < len - 1); i++, j++) {
 			vars[j] = tmp[i];

Modified: trunk/include/asterisk/cdr.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/cdr.h?view=diff&rev=48559&r1=48558&r2=48559
==============================================================================
--- trunk/include/asterisk/cdr.h (original)
+++ trunk/include/asterisk/cdr.h Mon Dec 18 09:38:50 2006
@@ -96,7 +96,7 @@
 
 void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw);
 int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int recur);
-int ast_cdr_serialize_variables(struct ast_cdr *cdr, char *buf, size_t size, char delim, char sep, int recur);
+int ast_cdr_serialize_variables(struct ast_cdr *cdr, struct ast_str **buf, char delim, char sep, int recur);
 void ast_cdr_free_vars(struct ast_cdr *cdr, int recur);
 int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr);
 

Modified: trunk/include/asterisk/pbx.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/pbx.h?view=diff&rev=48559&r1=48558&r2=48559
==============================================================================
--- trunk/include/asterisk/pbx.h (original)
+++ trunk/include/asterisk/pbx.h Mon Dec 18 09:38:50 2006
@@ -793,7 +793,7 @@
 	struct ast_ignorepat *ip);
 struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw);
 
-int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size);
+int pbx_builtin_serialize_variables(struct ast_channel *chan, struct ast_str **buf);
 const char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name);
 void pbx_builtin_pushvar_helper(struct ast_channel *chan, const char *name, const char *value);
 void pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value);

Modified: trunk/main/cdr.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cdr.c?view=diff&rev=48559&r1=48558&r2=48559
==============================================================================
--- trunk/main/cdr.c (original)
+++ trunk/main/cdr.c Mon Dec 18 09:38:50 2006
@@ -344,7 +344,7 @@
 	return x;
 }
 
-int ast_cdr_serialize_variables(struct ast_cdr *cdr, char *buf, size_t size, char delim, char sep, int recur) 
+int ast_cdr_serialize_variables(struct ast_cdr *cdr, struct ast_str **buf, char delim, char sep, int recur) 
 {
 	struct ast_var_t *variables;
 	const char *var, *val;
@@ -352,17 +352,18 @@
 	char workspace[256];
 	int total = 0, x = 0, i;
 
-	memset(buf, 0, size);
+	(*buf)->used = 0;
+	(*buf)->str[0] = '\0';
 
 	for (; cdr; cdr = recur ? cdr->next : NULL) {
 		if (++x > 1)
-			ast_build_string(&buf, &size, "\n");
+			ast_str_append(buf, 0, "\n");
 
 		AST_LIST_TRAVERSE(&cdr->varshead, variables, entries) {
 			if (variables &&
 			    (var = ast_var_name(variables)) && (val = ast_var_value(variables)) &&
 			    !ast_strlen_zero(var) && !ast_strlen_zero(val)) {
-				if (ast_build_string(&buf, &size, "level %d: %s%c%s%c", x, var, delim, val, sep)) {
+				if (ast_str_append(buf, 0, "level %d: %s%c%s%c", x, var, delim, val, sep) < 0) {
  					ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
  					break;
 				} else
@@ -376,7 +377,7 @@
 			if (!tmp)
 				continue;
 			
-			if (ast_build_string(&buf, &size, "level %d: %s%c%s%c", x, cdr_readonly_vars[i], delim, tmp, sep)) {
+			if (ast_str_append(buf, 0, "level %d: %s%c%s%c", x, cdr_readonly_vars[i], delim, tmp, sep) < 0) {
 				ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
 				break;
 			} else

Modified: trunk/main/cli.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cli.c?view=diff&rev=48559&r1=48558&r2=48559
==============================================================================
--- trunk/main/cli.c (original)
+++ trunk/main/cli.c Mon Dec 18 09:38:50 2006
@@ -766,7 +766,7 @@
 {
 	struct ast_channel *c=NULL;
 	struct timeval now;
-	char buf[2048];
+	struct ast_str *out = ast_str_alloca(2048);
 	char cdrtime[256];
 	char nf[256], wf[256], rf[256];
 	long elapsed_seconds=0;
@@ -837,10 +837,10 @@
 		( c-> data ? S_OR(c->data, "(Empty)") : "(None)"),
 		(ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
 	
-	if(pbx_builtin_serialize_variables(c,buf,sizeof(buf)))
-		ast_cli(fd,"      Variables:\n%s\n",buf);
-	if(c->cdr && ast_cdr_serialize_variables(c->cdr,buf, sizeof(buf), '=', '\n', 1))
-		ast_cli(fd,"  CDR Variables:\n%s\n",buf);
+	if(pbx_builtin_serialize_variables(c, &out))
+		ast_cli(fd,"      Variables:\n%s\n", out->str);
+	if(c->cdr && ast_cdr_serialize_variables(c->cdr, &out, '=', '\n', 1))
+		ast_cli(fd,"  CDR Variables:\n%s\n", out->str);
 	
 	ast_channel_unlock(c);
 	return RESULT_SUCCESS;

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=48559&r1=48558&r2=48559
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Mon Dec 18 09:38:50 2006
@@ -5644,7 +5644,7 @@
 }
 
 
-int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size)
+int pbx_builtin_serialize_variables(struct ast_channel *chan, struct ast_str **buf)
 {
 	struct ast_var_t *variables;
 	const char *var, *val;
@@ -5653,13 +5653,14 @@
 	if (!chan)
 		return 0;
 
-	memset(buf, 0, size);
+	(*buf)->used = 0;
+	(*buf)->str[0] = '\0';
 
 	AST_LIST_TRAVERSE(&chan->varshead, variables, entries) {
 		if ((var=ast_var_name(variables)) && (val=ast_var_value(variables))
 		   /* && !ast_strlen_zero(var) && !ast_strlen_zero(val) */
 		   ) {
-			if (ast_build_string(&buf, &size, "%s=%s\n", var, val)) {
+			if (ast_str_append(buf, 0, "%s=%s\n", var, val) < 0) {
 				ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
 				break;
 			} else



More information about the asterisk-commits mailing list