[svn-commits] murf: branch murf/bug_7506 r47109 - in /team/murf/bug_7506: apps/ channels/ i...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Fri Nov 3 10:54:35 MST 2006


Author: murf
Date: Fri Nov  3 11:54:34 2006
New Revision: 47109

URL: http://svn.digium.com/view/asterisk?rev=47109&view=rev
Log:
Still not done, but cleanly compiles. Will also do full code inspect before merging.

Modified:
    team/murf/bug_7506/apps/app_voicemail.c
    team/murf/bug_7506/channels/chan_features.c
    team/murf/bug_7506/channels/chan_gtalk.c
    team/murf/bug_7506/channels/chan_h323.c
    team/murf/bug_7506/channels/chan_jingle.c
    team/murf/bug_7506/channels/chan_mgcp.c
    team/murf/bug_7506/channels/chan_misdn.c
    team/murf/bug_7506/channels/chan_oss.c
    team/murf/bug_7506/channels/chan_sip.c
    team/murf/bug_7506/channels/chan_skinny.c
    team/murf/bug_7506/channels/chan_zap.c
    team/murf/bug_7506/include/asterisk/channel.h
    team/murf/bug_7506/main/channel.c
    team/murf/bug_7506/main/pbx.c

Modified: team/murf/bug_7506/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/apps/app_voicemail.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/apps/app_voicemail.c (original)
+++ team/murf/bug_7506/apps/app_voicemail.c Fri Nov  3 11:54:34 2006
@@ -1893,7 +1893,7 @@
 
 		if (*fromstring) {
 			struct ast_channel *ast;
-			if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "nix"))) {
+			if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, 0))) {
 				char *passdata;
 				int vmlen = strlen(fromstring)*3 + 200;
 				if ((passdata = alloca(vmlen))) {
@@ -1912,7 +1912,7 @@
 
 		if (emailsubject) {
 			struct ast_channel *ast;
-			if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "nix"))) {
+			if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, 0))) {
 				char *passdata;
 				int vmlen = strlen(emailsubject)*3 + 200;
 				if ((passdata = alloca(vmlen))) {
@@ -1967,7 +1967,7 @@
 		fprintf(p, "Content-Type: text/plain; charset=%s\nContent-Transfer-Encoding: 8bit\n\n", charset);
 		if (emailbody) {
 			struct ast_channel *ast;
-			if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "nix"))) {
+			if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, 0))) {
 				char *passdata;
 				int vmlen = strlen(emailbody)*3 + 200;
 				if ((passdata = alloca(vmlen))) {
@@ -2066,7 +2066,7 @@
 
 		if (*pagerfromstring) {
 			struct ast_channel *ast;
-			if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "nix"))) {
+			if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, 0))) {
 				char *passdata;
 				int vmlen = strlen(fromstring)*3 + 200;
 				if ((passdata = alloca(vmlen))) {
@@ -2083,7 +2083,7 @@
 		fprintf(p, "To: %s\n", pager);
 		if (pagersubject) {
 			struct ast_channel *ast;
-			if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "nix"))) {
+			if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, 0))) {
 				char *passdata;
 				int vmlen = strlen(pagersubject) * 3 + 200;
 				if ((passdata = alloca(vmlen))) {
@@ -2099,7 +2099,7 @@
 		strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm);
 		if (pagerbody) {
 			struct ast_channel *ast;
-			if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "nix"))) {
+			if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, 0))) {
 				char *passdata;
 				int vmlen = strlen(pagerbody)*3 + 200;
 				if ((passdata = alloca(vmlen))) {

Modified: team/murf/bug_7506/channels/chan_features.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_features.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_features.c (original)
+++ team/murf/bug_7506/channels/chan_features.c Fri Nov  3 11:54:34 2006
@@ -449,6 +449,7 @@
 {
 	struct ast_channel *tmp;
 	int x,y;
+	char *b2 = 0;
 	if (!p->subchan) {
 		ast_log(LOG_WARNING, "Called upon channel with no subchan:(\n");
 		return NULL;
@@ -457,24 +458,29 @@
 		ast_log(LOG_WARNING, "Called to put index %d already there!\n", index);
 		return NULL;
 	}
-	tmp = ast_channel_alloc(0, state, 0,0, "Feature/%s/%s-%d", p->tech, p->dest, x);
-	if (!tmp) {
-		ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
-		return NULL;
-	}
-	tmp->tech = &features_tech;
+	/* figure out what you want the name to be */
 	for (x=1;x<4;x++) {
-		ast_string_field_build(tmp, name, "Feature/%s/%s-%d", p->tech, p->dest, x);
+		if (b2)
+			free(b2);
+		b2 = ast_safe_string_alloc("Feature/%s/%s-%d", p->tech, p->dest, x);
 		for (y=0;y<3;y++) {
 			if (y == index)
 				continue;
-			if (p->subs[y].owner && !strcasecmp(p->subs[y].owner->name, tmp->name))
+			if (p->subs[y].owner && !strcasecmp(p->subs[y].owner->name, b2))
 				break;
 		}
 		if (y >= 3)
 			break;
 	}
-	ast_setstate(tmp, state);
+	tmp = ast_channel_alloc(0, state, 0,0, b2);
+	/* free up the name, it was copied into the channel name */
+	if (b2)
+		free(b2);
+	if (!tmp) {
+		ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
+		return NULL;
+	}
+	tmp->tech = &features_tech;
 	tmp->writeformat = p->subchan->writeformat;
 	tmp->rawwriteformat = p->subchan->rawwriteformat;
 	tmp->readformat = p->subchan->readformat;

Modified: team/murf/bug_7506/channels/chan_gtalk.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_gtalk.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_gtalk.c (original)
+++ team/murf/bug_7506/channels/chan_gtalk.c Fri Nov  3 11:54:34 2006
@@ -951,7 +951,11 @@
 	i->owner = tmp;
 	ast_copy_string(tmp->context, client->context, sizeof(tmp->context));
 	ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
-	/* ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num); */
+	/* Don't use ast_set_callerid() here because it will
+	 * generate a needless NewCallerID event */
+	tmp->cid.cid_num = ast_strdup(l->cid_num);
+	tmp->cid.cid_ani = ast_strdup(l->cid_num);
+	tmp->cid.cid_name = ast_strdup(l->cid_name);
 	if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
 		tmp->cid.cid_dnid = ast_strdup(i->exten);
 	tmp->priority = 1;

Modified: team/murf/bug_7506/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_h323.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_h323.c (original)
+++ team/murf/bug_7506/channels/chan_h323.c Fri Nov  3 11:54:34 2006
@@ -1075,7 +1075,7 @@
 		}
 
 		/* Don't use ast_set_callerid() here because it will
-		 * generate a NewCallerID event before the NewChannel event */
+		 * generate a needless NewCallerID event */
 		ch->cid.cid_num = ast_strdup(cid_num);
 		ch->cid.cid_ani = ast_strdup(cid_num);
 		ch->cid.cid_name = ast_strdup(cid_name);

Modified: team/murf/bug_7506/channels/chan_jingle.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_jingle.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_jingle.c (original)
+++ team/murf/bug_7506/channels/chan_jingle.c Fri Nov  3 11:54:34 2006
@@ -754,11 +754,13 @@
 	struct ast_channel *tmp;
 	int fmt;
 	int what;
+	char *str;
 
 	if (title)
-		tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "Jingle/%s-%04lx", title, ast_random() & 0xffff);
+		str = title;
 	else
-		tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "Jingle/%s-%04lx", i->from, ast_random() & 0xffff);
+		str = i->from;
+	tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "Jingle/%s-%04lx", str, ast_random() & 0xffff);
 	if (!tmp) {
 		ast_log(LOG_WARNING, "Unable to allocate Jingle channel structure!\n");
 		return NULL;
@@ -807,7 +809,11 @@
 	i->owner = tmp;
 	ast_copy_string(tmp->context, client->context, sizeof(tmp->context));
 	ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
-	ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num);
+	/* Don't use ast_set_callerid() here because it will
+	 * generate an unnecessary NewCallerID event  */
+	tmp->cid.cid_num = ast_strdup(i->cid_num);
+	tmp->cid.cid_ani = ast_strdup(i->cid_num);
+	tmp->cid.cid_name = ast_strdup(i->cid_name);
 	if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
 		tmp->cid.cid_dnid = ast_strdup(i->exten);
 	tmp->priority = 1;

Modified: team/murf/bug_7506/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_mgcp.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_mgcp.c (original)
+++ team/murf/bug_7506/channels/chan_mgcp.c Fri Nov  3 11:54:34 2006
@@ -1473,7 +1473,7 @@
 		ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
 
 		/* Don't use ast_set_callerid() here because it will
-		 * generate a NewCallerID event before the NewChannel event */
+		 * generate a needless NewCallerID event */
 		tmp->cid.cid_num = ast_strdup(i->cid_num);
 		tmp->cid.cid_ani = ast_strdup(i->cid_num);
 		tmp->cid.cid_name = ast_strdup(i->cid_name);

Modified: team/murf/bug_7506/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_misdn.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_misdn.c (original)
+++ team/murf/bug_7506/channels/chan_misdn.c Fri Nov  3 11:54:34 2006
@@ -3152,7 +3152,7 @@
       
 			ast_callerid_parse(callerid, &cid_name, &cid_num);
 			/* Don't use ast_set_callerid() here because it will
-			 * generate a NewCallerID event before the NewChannel event */
+			 * generate a needless NewCallerID event */
 			tmp->cid.cid_num = ast_strdup(cid_num);
 			tmp->cid.cid_ani = ast_strdup(cid_num);
 			tmp->cid.cid_name = ast_strdup(cid_name);

Modified: team/murf/bug_7506/channels/chan_oss.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_oss.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_oss.c (original)
+++ team/murf/bug_7506/channels/chan_oss.c Fri Nov  3 11:54:34 2006
@@ -1008,7 +1008,11 @@
 		ast_copy_string(c->exten, ext, sizeof(c->exten));
 	if (!ast_strlen_zero(o->language))
 		ast_string_field_set(c, language, o->language);
-	ast_set_callerid(c, o->cid_num, o->cid_name, o->cid_num); /* is this a mistake? */
+	/* Don't use ast_set_callerid() here because it will
+	 * generate a needless NewCallerID event */
+	c->cid.cid_num = ast_strdup(o->cid_num);
+	c->cid.cid_ani = ast_strdup(o->cid_num);
+	c->cid.cid_name = ast_strdup(o->cid_name);
 	if (!ast_strlen_zero(ext))
 		c->cid.cid_dnid = ast_strdup(ext);
 

Modified: team/murf/bug_7506/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_sip.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_sip.c (original)
+++ team/murf/bug_7506/channels/chan_sip.c Fri Nov  3 11:54:34 2006
@@ -3787,8 +3787,8 @@
 
 		tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "SIP/%s-%08x", my_name, (int)(long) i);
 
-		sip_pvt_lock(i);
-	}
+	}
+	sip_pvt_lock(i);
 	if (!tmp) {
 		ast_log(LOG_WARNING, "Unable to allocate AST channel structure for SIP channel\n");
 		return NULL;
@@ -3879,7 +3879,7 @@
 	ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
 
 	/* Don't use ast_set_callerid() here because it will
-	 * generate a NewCallerID event before the NewChannel event */
+	 * generate an unnecessary NewCallerID event  */
 	tmp->cid.cid_num = ast_strdup(i->cid_num);
 	tmp->cid.cid_ani = ast_strdup(i->cid_num);
 	tmp->cid.cid_name = ast_strdup(i->cid_name);

Modified: team/murf/bug_7506/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_skinny.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_skinny.c (original)
+++ team/murf/bug_7506/channels/chan_skinny.c Fri Nov  3 11:54:34 2006
@@ -2755,7 +2755,7 @@
 		ast_copy_string(tmp->exten, l->exten, sizeof(tmp->exten));
 
 		/* Don't use ast_set_callerid() here because it will
-		 * generate a NewCallerID event before the NewChannel event */
+		 * generate a needless NewCallerID event */
 		tmp->cid.cid_num = ast_strdup(l->cid_num);
 		tmp->cid.cid_ani = ast_strdup(l->cid_num);
 		tmp->cid.cid_name = ast_strdup(l->cid_name);

Modified: team/murf/bug_7506/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_zap.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_zap.c (original)
+++ team/murf/bug_7506/channels/chan_zap.c Fri Nov  3 11:54:34 2006
@@ -5486,15 +5486,34 @@
 	int res;
 	int x,y;
 	int features;
+	char *b2 = 0;
 	ZT_PARAMS ps;
 	if (i->subs[index].owner) {
 		ast_log(LOG_WARNING, "Channel %d already has a %s call\n", i->channel,subnames[index]);
 		return NULL;
 	}
-	if (i->channel == CHAN_PSEUDO)
-		tmp = ast_channel_alloc(0, state, 0, 0, "Zap/pseudo-%d", ast_random());
-	else	
-		tmp = ast_channel_alloc(0, state, 0, 0, "Zap/%d-%d", i->channel, y);
+	y = 1;
+	do {
+		if (b2)
+			free(b2);
+#ifdef HAVE_PRI
+		if (i->bearer || (i->pri && (i->sig == SIG_FXSKS)))
+			b2 = ast_safe_string_alloc("Zap/%d:%d-%d", i->pri->trunkgroup, i->channel, y);
+		else
+#endif
+		if (i->channel == CHAN_PSEUDO)
+			b2 = ast_safe_string_alloc("Zap/pseudo-%d", ast_random());
+		else	
+			b2 = ast_safe_string_alloc("Zap/%d-%d", i->channel, y);
+		for (x = 0; x < 3; x++) {
+			if ((index != x) && i->subs[x].owner && !strcasecmp(b2, i->subs[x].owner->name))
+				break;
+		}
+		y++;
+	} while (x < 3);
+	tmp = ast_channel_alloc(0, state, 0, 0, b2);
+	if (b2) /*!> b2 can be freed now, it's been copied into the channel structure */
+		free(b2);
 	if (!tmp)
 		return NULL;
 	tmp->tech = &zap_tech;
@@ -5514,23 +5533,6 @@
 		else
 			deflaw = AST_FORMAT_ULAW;
 	}
-	y = 1;
-	do {
-#ifdef HAVE_PRI
-		if (i->bearer || (i->pri && (i->sig == SIG_FXSKS)))
-			ast_string_field_build(tmp, name, "Zap/%d:%d-%d", i->pri->trunkgroup, i->channel, y);
-		else
-#endif
-		if (i->channel == CHAN_PSEUDO)
-			ast_string_field_build(tmp, name, "Zap/pseudo-%d", ast_random());
-		else	
-			ast_string_field_build(tmp, name, "Zap/%d-%d", i->channel, y);
-		for (x = 0; x < 3; x++) {
-			if ((index != x) && i->subs[x].owner && !strcasecmp(tmp->name, i->subs[x].owner->name))
-				break;
-		}
-		y++;
-	} while (x < 3);
 	tmp->fds[0] = i->subs[index].zfd;
 	tmp->nativeformats = AST_FORMAT_SLINEAR | deflaw;
 	/* Start out assuming ulaw since it's smaller :) */
@@ -5621,9 +5623,9 @@
 	if (!ast_strlen_zero(i->dnid))
 		tmp->cid.cid_dnid = ast_strdup(i->dnid);
 
+	/* Don't use ast_set_callerid() here because it will
+	 * generate a needless NewCallerID event */
 #ifdef PRI_ANI
-	/* Don't use ast_set_callerid() here because it will
-	 * generate a NewCallerID event before the NewChannel event */
 	tmp->cid.cid_num = ast_strdup(i->cid_num);
 	tmp->cid.cid_name = ast_strdup(i->cid_name);
 	if (!ast_strlen_zero(i->cid_ani))
@@ -5650,7 +5652,6 @@
 	i->fake_event = 0;
 	/* Assure there is no confmute on this channel */
 	zt_confmute(i, 0);
-	ast_setstate(tmp, state);
 	/* Configure the new channel jb */
 	ast_jb_configure(tmp, &global_jbconf);
 	if (startpbx) {

Modified: team/murf/bug_7506/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/include/asterisk/channel.h?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/include/asterisk/channel.h (original)
+++ team/murf/bug_7506/include/asterisk/channel.h Fri Nov  3 11:54:34 2006
@@ -579,7 +579,7 @@
 	by default set to the "default" context and
 	extension "s"
  */
-struct ast_channel *ast_channel_alloc(int needalertpipe, int state, char *cid_num, char *cid_name, char *name_fmt, ...);
+struct ast_channel *ast_channel_alloc(int needalertpipe, int state, const char *cid_num, const char *cid_name, const char *name_fmt, ...);
 
 /*! \brief Queue an outgoing frame */
 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
@@ -1105,6 +1105,12 @@
 void ast_deactivate_generator(struct ast_channel *chan);
 
 void ast_set_callerid(struct ast_channel *chan, const char *cidnum, const char *cidname, const char *ani);
+
+
+/*! return a mallocd string with the result of sprintf of the fmt and following args */
+char *ast_safe_string_alloc(const char *fmt, ...);
+
+
 
 /*! Start a tone going */
 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);

Modified: team/murf/bug_7506/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/main/channel.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/main/channel.c (original)
+++ team/murf/bug_7506/main/channel.c Fri Nov  3 11:54:34 2006
@@ -29,6 +29,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdarg.h>
 #include <string.h>
 #include <sys/time.h>
 #include <signal.h>
@@ -330,6 +331,21 @@
 	return res;
 }
 
+/*! \brief printf the string into a correctly sized mallocd buffer, and return the buffer */
+char *ast_safe_string_alloc(const char *fmt, ...)
+{
+	char *b2,buf[1];
+	int len;
+
+	va_list args;
+	va_start(args, fmt);
+	len = vsnprintf(buf, 1, fmt, args);
+	b2 = ast_malloc(len+1);
+	vsnprintf(b2, len+1,  fmt, args);
+	va_end(args);
+	return b2;
+}
+
 /*! \brief Initiate system shutdown */
 void ast_begin_shutdown(int hangup)
 {
@@ -608,7 +624,7 @@
 };
 
 /*! \brief Create a new channel structure */
-struct ast_channel *ast_channel_alloc(int needqueue, int state, char *cid_num, char *cid_name, char *name_fmt, ...)
+struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_num, const char *cid_name, const char *name_fmt, ...)
 {
 	struct ast_channel *tmp;
 	int x;
@@ -689,35 +705,37 @@
 			(long) time(NULL), ast_atomic_fetchadd_int(&uniqueint, 1));
 	}
 
-	/* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call.
-	 * And they all use slightly different formats for their name string.
-	 * This means, to set the name here, we have to accept variable args, and call the string_field_build from here.
-	 * This means, that the stringfields must have a routine that takes the va_lists directly, and 
-	 * uses them to build the string, instead of forming the va_lists internally from the vararg ... list.
-	 * This new function was written so this can be accomplished.
-	 */
-	va_start(ap1, name_fmt);
-	va_start(ap2, name_fmt);
-	ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2);
-	va_end(ap1);
-	va_end(ap2);
-
-	/* and now, since the channel structure is built, and has its name, let's call the
-	 * manager event generator with this Newchannel event. This is the proper and correct
-	 * place to make this call, but you sure do have to pass a lot of data into this func
-	 * to do it here!
-	 */
-	manager_event(EVENT_FLAG_CALL, "Newchannel",
-		      "Channel: %s\r\n"
-		      "State: %s\r\n"
-		      "CallerIDNum: %s\r\n"
-		      "CallerIDName: %s\r\n"
-		      "Uniqueid: %s\r\n",
-		      tmp->name, ast_state2str(state),
-		      S_OR(cid_num, "<unknown>"),
-		      S_OR(cid_name, "<unknown>"),
-		      tmp->uniqueid);
-
+	if (!ast_strlen_zero(name_fmt)) {
+		/* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call.
+		 * And they all use slightly different formats for their name string.
+		 * This means, to set the name here, we have to accept variable args, and call the string_field_build from here.
+		 * This means, that the stringfields must have a routine that takes the va_lists directly, and 
+		 * uses them to build the string, instead of forming the va_lists internally from the vararg ... list.
+		 * This new function was written so this can be accomplished.
+		 */
+		va_start(ap1, name_fmt);
+		va_start(ap2, name_fmt);
+		ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2);
+		va_end(ap1);
+		va_end(ap2);
+
+		/* and now, since the channel structure is built, and has its name, let's call the
+		 * manager event generator with this Newchannel event. This is the proper and correct
+		 * place to make this call, but you sure do have to pass a lot of data into this func
+		 * to do it here!
+		 */
+		manager_event(EVENT_FLAG_CALL, "Newchannel",
+			      "Channel: %s\r\n"
+			      "State: %s\r\n"
+			      "CallerIDNum: %s\r\n"
+			      "CallerIDName: %s\r\n"
+			      "Uniqueid: %s\r\n",
+			      tmp->name, ast_state2str(state),
+			      S_OR(cid_num, "<unknown>"),
+			      S_OR(cid_name, "<unknown>"),
+			      tmp->uniqueid);
+	}
+	
 	headp = &tmp->varshead;
 	AST_LIST_HEAD_INIT_NOLOCK(headp);
 	
@@ -3537,8 +3555,9 @@
 
 	chan->_state = state;
 	ast_device_state_changed_literal(chan->name);
+	/* setstate used to conditionally report Newchannel; this is no more */
 	manager_event(EVENT_FLAG_CALL,
-		      (oldstate == AST_STATE_DOWN) ? "Newchannel" : "Newstate",
+		      "Newstate",
 		      "Channel: %s\r\n"
 		      "State: %s\r\n"
 		      "CallerIDNum: %s\r\n"

Modified: team/murf/bug_7506/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/main/pbx.c?rev=47109&r1=47108&r2=47109&view=diff
==============================================================================
--- team/murf/bug_7506/main/pbx.c (original)
+++ team/murf/bug_7506/main/pbx.c Fri Nov  3 11:54:34 2006
@@ -4861,7 +4861,7 @@
 static int ast_pbx_outgoing_cdr_failed(void)
 {
 	/* allocate a channel */
-	struct ast_channel *chan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "nix");
+	struct ast_channel *chan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, 0);
 
 	if (!chan)
 		return -1;  /* failure */



More information about the svn-commits mailing list