[svn-commits] rmudgett: branch 12 r397892 - in /branches/12: funcs/func_cdr.c main/cdr.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Aug 28 17:21:48 CDT 2013


Author: rmudgett
Date: Wed Aug 28 17:21:46 2013
New Revision: 397892

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=397892
Log:
Some CDR code optimization.

Modified:
    branches/12/funcs/func_cdr.c
    branches/12/main/cdr.c

Modified: branches/12/funcs/func_cdr.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/funcs/func_cdr.c?view=diff&rev=397892&r1=397891&r2=397892
==============================================================================
--- branches/12/funcs/func_cdr.c (original)
+++ branches/12/funcs/func_cdr.c Wed Aug 28 17:21:46 2013
@@ -204,7 +204,6 @@
 static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse,
 		    char *buf, size_t len)
 {
-	char format_buf[128];
 	char *value = NULL;
 	struct ast_flags flags = { 0 };
 	char tempbuf[512];
@@ -252,7 +251,7 @@
 			return 0;
 		}
 		dtime = (double)(ms / 1000.0);
-		sprintf(tempbuf, "%lf", dtime);
+		snprintf(tempbuf, sizeof(tempbuf), "%lf", dtime);
 	} else if (!ast_test_flag(&flags, OPT_UNPARSED)) {
 		if (!strcasecmp("start", args.variable)
 			|| !strcasecmp("end", args.variable)
@@ -278,8 +277,7 @@
 					args.variable, tempbuf, ast_channel_name(chan));
 				return 0;
 			}
-			sprintf(format_buf, "%s", ast_cdr_disp2str(disposition));
-			strcpy(tempbuf, format_buf);
+			snprintf(tempbuf, sizeof(tempbuf), "%s", ast_cdr_disp2str(disposition));
 		} else if (!strcasecmp("amaflags", args.variable)) {
 			int amaflags;
 
@@ -288,8 +286,7 @@
 					args.variable, tempbuf, ast_channel_name(chan));
 				return 0;
 			}
-			sprintf(format_buf, "%s", ast_channel_amaflags2string(amaflags));
-			strcpy(tempbuf, format_buf);
+			snprintf(tempbuf, sizeof(tempbuf), "%s", ast_channel_amaflags2string(amaflags));
 		}
 	}
 

Modified: branches/12/main/cdr.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/cdr.c?view=diff&rev=397892&r1=397891&r2=397892
==============================================================================
--- branches/12/main/cdr.c (original)
+++ branches/12/main/cdr.c Wed Aug 28 17:21:46 2013
@@ -692,17 +692,25 @@
  */
 static int copy_variables(struct varshead *to_list, struct varshead *from_list)
 {
-	struct ast_var_t *variables, *newvariable = NULL;
-	const char *var, *val;
+	struct ast_var_t *variables;
+	struct ast_var_t *newvariable;
+	const char *var;
+	const char *val;
 	int x = 0;
 
 	AST_LIST_TRAVERSE(from_list, variables, entries) {
-		if (variables &&
-		    (var = ast_var_name(variables)) && (val = ast_var_value(variables)) &&
-		    !ast_strlen_zero(var) && !ast_strlen_zero(val) &&
-		    (newvariable = ast_var_assign(var, val))) {
+		var = ast_var_name(variables);
+		if (ast_strlen_zero(var)) {
+			continue;
+		}
+		val = ast_var_value(variables);
+		if (ast_strlen_zero(val)) {
+			continue;
+		}
+		newvariable = ast_var_assign(var, val);
+		if (newvariable) {
 			AST_LIST_INSERT_HEAD(to_list, newvariable, entries);
-			x++;
+			++x;
 		}
 	}
 
@@ -2720,8 +2728,8 @@
 		return NULL;
 	}
 
-	memcpy(newcdr, cdr, sizeof(*newcdr));
-	memset(&newcdr->varshead, 0, sizeof(newcdr->varshead));
+	*newcdr = *cdr;
+	AST_LIST_HEAD_INIT_NOLOCK(&newcdr->varshead);
 	copy_variables(&newcdr->varshead, &cdr->varshead);
 	newcdr->next = NULL;
 
@@ -2731,19 +2739,18 @@
 static const char *cdr_format_var_internal(struct ast_cdr *cdr, const char *name)
 {
 	struct ast_var_t *variables;
-	struct varshead *headp = &cdr->varshead;
 
 	if (ast_strlen_zero(name)) {
 		return NULL;
 	}
 
-	AST_LIST_TRAVERSE(headp, variables, entries) {
+	AST_LIST_TRAVERSE(&cdr->varshead, variables, entries) {
 		if (!strcasecmp(name, ast_var_name(variables))) {
 			return ast_var_value(variables);
 		}
 	}
 
-	return '\0';
+	return NULL;
 }
 
 static void cdr_get_tv(struct timeval when, const char *fmt, char *buf, int bufsize)
@@ -2880,6 +2887,7 @@
 		ao2_lock(cdr);
 		for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
 			struct varshead *headp = NULL;
+
 			if (it_cdr->fn_table == &finalized_state_fn_table) {
 				continue;
 			}




More information about the svn-commits mailing list