[svn-commits] seanbright: trunk r196520 - /trunk/cdr/cdr_custom.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat May 23 10:17:06 CDT 2009


Author: seanbright
Date: Sat May 23 10:16:59 2009
New Revision: 196520

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=196520
Log:
Fix errors in cdr_custom that cause reference errors when non-CDR variable
substitution is done.

cdr_custom was creating a ast_channel struct directly and passing it into the
core for variable substition.  This was fine as long as the format string
contained only calls to the CDR() function.  Doing something like ${EPOCH} on
the other hand tried to lock the channel, which would fail and throw an error
because the passed channel hadn't been allocated as an ao2 object.  So now we
create the dummy channel with ast_channel_alloc, and everything works as
expected.

Modified:
    trunk/cdr/cdr_custom.c

Modified: trunk/cdr/cdr_custom.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/cdr/cdr_custom.c?view=diff&rev=196520&r1=196519&r2=196520
==============================================================================
--- trunk/cdr/cdr_custom.c (original)
+++ trunk/cdr/cdr_custom.c Sat May 23 10:16:59 2009
@@ -115,7 +115,7 @@
 
 static int custom_log(struct ast_cdr *cdr)
 {
-	struct ast_channel dummy;
+	struct ast_channel *dummy;
 	struct ast_str *str;
 	struct cdr_config *config;
 
@@ -124,17 +124,24 @@
 		return -1;
 	}
 
-	/* Quite possibly the first use of a static struct ast_channel, we need it so the var funcs will work */
-	memset(&dummy, 0, sizeof(dummy));
-	dummy.cdr = cdr;
+	dummy = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Substitution/%p", cdr);
+
+	if (!dummy) {
+		ast_log(LOG_ERROR, "Unable to allocate channel for variable subsitution.\n");
+		return -1;
+	}
+
+	/* We need to dup here since the cdr actually belongs to the other channel,
+	   so when we release this channel we don't want the CDR getting cleaned
+	   up prematurely. */
+	dummy->cdr = ast_cdr_dup(cdr);
 
 	AST_RWLIST_RDLOCK(&sinks);
 
 	AST_LIST_TRAVERSE(&sinks, config, list) {
 		FILE *out;
 
-		ast_str_reset(str);
-		ast_str_substitute_variables(&str, 0, &dummy, config->format);
+		ast_str_substitute_variables(&str, 0, dummy, config->format);
 
 		/* Even though we have a lock on the list, we could be being chased by
 		   another thread and this lock ensures that we won't step on anyone's
@@ -158,6 +165,8 @@
 
 	AST_RWLIST_UNLOCK(&sinks);
 
+	ast_channel_release(dummy);
+
 	return 0;
 }
 




More information about the svn-commits mailing list