[asterisk-commits] murf: branch murf/bug_7506 r47070 - in /team/murf/bug_7506: channels/ include...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Nov 2 21:16:01 MST 2006


Author: murf
Date: Thu Nov  2 22:16:00 2006
New Revision: 47070

URL: http://svn.digium.com/view/asterisk?rev=47070&view=rev
Log:
Checking this partially in. Still more to do, vm, features, etc. But this is a good start.

Modified:
    team/murf/bug_7506/channels/chan_agent.c
    team/murf/bug_7506/channels/chan_alsa.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_iax2.c
    team/murf/bug_7506/channels/chan_jingle.c
    team/murf/bug_7506/channels/chan_local.c
    team/murf/bug_7506/channels/chan_mgcp.c
    team/murf/bug_7506/channels/chan_misdn.c
    team/murf/bug_7506/channels/chan_nbs.c
    team/murf/bug_7506/channels/chan_oss.c
    team/murf/bug_7506/channels/chan_phone.c
    team/murf/bug_7506/channels/chan_sip.c
    team/murf/bug_7506/channels/chan_skinny.c
    team/murf/bug_7506/channels/chan_vpb.cc
    team/murf/bug_7506/channels/chan_zap.c
    team/murf/bug_7506/include/asterisk/channel.h
    team/murf/bug_7506/include/asterisk/stringfields.h
    team/murf/bug_7506/main/channel.c
    team/murf/bug_7506/main/utils.c

Modified: team/murf/bug_7506/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_agent.c?rev=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_agent.c (original)
+++ team/murf/bug_7506/channels/chan_agent.c Thu Nov  2 22:16:00 2006
@@ -905,7 +905,10 @@
 		return NULL;
 	}
 #endif	
-	tmp = ast_channel_alloc(0);
+	if (p->pending)
+		tmp = ast_channel_alloc(0, state, 0, 0, "Agent/P%s-%d", p->agent, ast_random() & 0xffff);
+	else
+		tmp = ast_channel_alloc(0, state, 0, 0, "Agent/%s", p->agent);
 	if (!tmp) {
 		ast_log(LOG_WARNING, "Unable to allocate agent channel structure\n");
 		return NULL;
@@ -929,12 +932,7 @@
 		tmp->readformat = AST_FORMAT_SLINEAR;
 		tmp->rawreadformat = AST_FORMAT_SLINEAR;
 	}
-	if (p->pending)
-		ast_string_field_build(tmp, name, "Agent/P%s-%d", p->agent, ast_random() & 0xffff);
-	else
-		ast_string_field_build(tmp, name, "Agent/%s", p->agent);
 	/* Safe, agentlock already held */
-	ast_setstate(tmp, state);
 	tmp->tech_pvt = p;
 	p->owner = tmp;
 	/* XXX: this needs fixing */

Modified: team/murf/bug_7506/channels/chan_alsa.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_alsa.c?rev=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_alsa.c (original)
+++ team/murf/bug_7506/channels/chan_alsa.c Thu Nov  2 22:16:00 2006
@@ -793,11 +793,10 @@
 {
 	struct ast_channel *tmp = NULL;
 
-	if (!(tmp = ast_channel_alloc(1)))
+	if (!(tmp = ast_channel_alloc(1, state, 0, 0, "ALSA/%s", indevname)))
 		return NULL;
 
 	tmp->tech = &alsa_tech;
-	ast_string_field_build(tmp, name, "ALSA/%s", indevname);
 	tmp->fds[0] = readdev;
 	tmp->nativeformats = AST_FORMAT_SLINEAR;
 	tmp->readformat = AST_FORMAT_SLINEAR;
@@ -810,7 +809,6 @@
 	if (!ast_strlen_zero(language))
 		ast_string_field_set(tmp, language, language);
 	p->owner = tmp;
-	ast_setstate(tmp, state);
 	ast_mutex_lock(&usecnt_lock);
 	usecnt++;
 	ast_mutex_unlock(&usecnt_lock);

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=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_features.c (original)
+++ team/murf/bug_7506/channels/chan_features.c Thu Nov  2 22:16:00 2006
@@ -460,7 +460,7 @@
 		ast_log(LOG_WARNING, "Called to put index %d already there!\n", index);
 		return NULL;
 	}
-	tmp = ast_channel_alloc(0);
+	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;

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=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_gtalk.c (original)
+++ team/murf/bug_7506/channels/chan_gtalk.c Thu Nov  2 22:16:00 2006
@@ -898,8 +898,13 @@
 	struct ast_channel *tmp;
 	int fmt;
 	int what;
-
-	tmp = ast_channel_alloc(1);
+	char *n2;
+
+	if (title)
+		n2 = title;
+	else
+		n2 = i->us;
+	tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "Gtalk/%s-%04lx", n2, ast_random() & 0xffff);
 	if (!tmp) {
 		ast_log(LOG_WARNING, "Unable to allocate Gtalk channel structure!\n");
 		return NULL;
@@ -917,11 +922,6 @@
 		what = global_capability;
 	tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
 	fmt = ast_best_codec(tmp->nativeformats);
-
-	if (title)
-		ast_string_field_build(tmp, name, "Gtalk/%s-%04lx", title, ast_random() & 0xffff);
-	else
-		ast_string_field_build(tmp, name, "Gtalk/%s-%04lx", i->us, ast_random() & 0xffff);
 
 	if (i->rtp) {
 		tmp->fds[0] = ast_rtp_fd(i->rtp);
@@ -957,11 +957,10 @@
 	ast_mutex_unlock(&usecnt_lock);
 	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);
+	/* ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num); */
 	if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
 		tmp->cid.cid_dnid = ast_strdup(i->exten);
 	tmp->priority = 1;
-	ast_setstate(tmp, state);
 	if (i->rtp)
 		ast_jb_configure(tmp, &global_jbconf);
 	if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {

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=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_h323.c (original)
+++ team/murf/bug_7506/channels/chan_h323.c Thu Nov  2 22:16:00 2006
@@ -1006,17 +1006,27 @@
 static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const char *host)
 {
 	struct ast_channel *ch;
+	char *cid_num, *cid_name;
 	int fmt;
 
+	if (!ast_strlen_zero(pvt->options.cid_num))
+		cid_num = pvt->options.cid_num;
+	else
+		cid_num = pvt->cd.call_source_e164;
+
+	if (!ast_strlen_zero(pvt->options.cid_name))
+		cid_name = pvt->options.cid_name;
+	else
+		cid_name = pvt->cd.call_source_name;
+	
 	/* Don't hold a oh323_pvt lock while we allocate a chanel */
 	ast_mutex_unlock(&pvt->lock);
-	ch = ast_channel_alloc(1);
+	ch = ast_channel_alloc(1, state, cid_num, cid_name, "H323/%s", host);
 	/* Update usage counter */
 	ast_module_ref(ast_module_info->self);
 	ast_mutex_lock(&pvt->lock);
 	if (ch) {
 		ch->tech = &oh323_tech;
-		ast_string_field_build(ch, name, "H323/%s", host);
 		if (!(fmt = pvt->jointcapability) && !(fmt = pvt->options.capability))
 			fmt = global_options.capability;
 		ch->nativeformats = ast_codec_choose(&pvt->options.prefs, fmt, 1)/* | (pvt->jointcapability & AST_FORMAT_VIDEO_MASK)*/;
@@ -1066,17 +1076,10 @@
 
 		/* Don't use ast_set_callerid() here because it will
 		 * generate a NewCallerID event before the NewChannel event */
-		if (!ast_strlen_zero(pvt->options.cid_num)) {
-			ch->cid.cid_num = ast_strdup(pvt->options.cid_num);
-			ch->cid.cid_ani = ast_strdup(pvt->options.cid_num);
-		} else {
-			ch->cid.cid_num = ast_strdup(pvt->cd.call_source_e164);
-			ch->cid.cid_ani = ast_strdup(pvt->cd.call_source_e164);
-		}
-		if (!ast_strlen_zero(pvt->options.cid_name))
-			ch->cid.cid_name = ast_strdup(pvt->options.cid_name);
-		else
-			ch->cid.cid_name = ast_strdup(pvt->cd.call_source_name);
+		ch->cid.cid_num = ast_strdup(cid_num);
+		ch->cid.cid_ani = ast_strdup(cid_num);
+		ch->cid.cid_name = ast_strdup(cid_name);
+
 		if (pvt->cd.redirect_reason >= 0) {
 			ch->cid.cid_rdnis = ast_strdup(pvt->cd.redirect_number);
 			pbx_builtin_setvar_helper(ch, "PRIREDIRECTREASON", redirectingreason2str(pvt->cd.redirect_reason));
@@ -1089,7 +1092,6 @@
 		}
 		if (pvt->cd.transfer_capability >= 0)
 			ch->transfercapability = pvt->cd.transfer_capability;
-		ast_setstate(ch, state);
 		if (state != AST_STATE_DOWN) {
 			if (ast_pbx_start(ch)) {
 				ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ch->name);

Modified: team/murf/bug_7506/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_iax2.c?rev=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_iax2.c (original)
+++ team/murf/bug_7506/channels/chan_iax2.c Thu Nov  2 22:16:00 2006
@@ -3265,12 +3265,11 @@
 
 	/* Don't hold call lock */
 	ast_mutex_unlock(&iaxsl[callno]);
-	tmp = ast_channel_alloc(1);
+	tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "IAX2/%s-%d", i->host, i->callno);
 	ast_mutex_lock(&iaxsl[callno]);
 	if (!tmp)
 		return NULL;
 	tmp->tech = &iax2_tech;
-	ast_string_field_build(tmp, name, "IAX2/%s-%d", i->host, i->callno);
 	/* We can support any format by default, until we get restricted */
 	tmp->nativeformats = capability;
 	tmp->readformat = ast_best_codec(capability);
@@ -3304,7 +3303,6 @@
 		tmp->adsicpe = AST_ADSI_UNAVAILABLE;
 	i->owner = tmp;
 	i->capability = capability;
-	ast_setstate(tmp, state);
 	if (state != AST_STATE_DOWN) {
 		if (ast_pbx_start(tmp)) {
 			ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
@@ -6112,10 +6110,10 @@
 	struct iax_dual *d;
 	struct ast_channel *chan1m, *chan2m;
 	pthread_t th;
-	chan1m = ast_channel_alloc(0);
-	chan2m = ast_channel_alloc(0);
+	tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "IAX2/%s-%d", i->host, i->callno);
+	chan1m = ast_channel_alloc(0, state, 0, 0, "Parking/%s", chan1->name);
+	chan2m = ast_channel_alloc(0, state, 0, 0, "IAXPeer/%s",chan2->name);
 	if (chan2m && chan1m) {
-		ast_string_field_build(chan1m, name, "Parking/%s", chan1->name);
 		/* Make formats okay */
 		chan1m->readformat = chan1->readformat;
 		chan1m->writeformat = chan1->writeformat;
@@ -6127,7 +6125,6 @@
 		
 		/* We make a clone of the peer channel too, so we can play
 		   back the announcement */
-		ast_string_field_build(chan2m, name, "IAXPeer/%s",chan2->name);
 		/* Make formats okay */
 		chan2m->readformat = chan2->readformat;
 		chan2m->writeformat = chan2->writeformat;

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=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_jingle.c (original)
+++ team/murf/bug_7506/channels/chan_jingle.c Thu Nov  2 22:16:00 2006
@@ -758,7 +758,10 @@
 	int fmt;
 	int what;
 
-	tmp = ast_channel_alloc(1);
+	if (title)
+		tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "Jingle/%s-%04lx", title, ast_random() & 0xffff);
+	else
+		tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "Jingle/%s-%04lx", i->from, ast_random() & 0xffff);
 	if (!tmp) {
 		ast_log(LOG_WARNING, "Unable to allocate Jingle channel structure!\n");
 		return NULL;
@@ -775,11 +778,6 @@
 		what = global_capability;
 	tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
 	fmt = ast_best_codec(tmp->nativeformats);
-
-	if (title)
-		ast_string_field_build(tmp, name, "Jingle/%s-%04lx", title, ast_random() & 0xffff);
-	else
-		ast_string_field_build(tmp, name, "Jingle/%s-%04lx", i->from, ast_random() & 0xffff);
 
 	if (i->rtp) {
 		tmp->fds[0] = ast_rtp_fd(i->rtp);
@@ -819,7 +817,6 @@
 	if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
 		tmp->cid.cid_dnid = ast_strdup(i->exten);
 	tmp->priority = 1;
-	ast_setstate(tmp, state);
 	if (i->rtp)
 		ast_jb_configure(tmp, &global_jbconf);
 	if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {

Modified: team/murf/bug_7506/channels/chan_local.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_local.c?rev=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_local.c (original)
+++ team/murf/bug_7506/channels/chan_local.c Thu Nov  2 22:16:00 2006
@@ -541,7 +541,8 @@
 	int randnum = ast_random() & 0xffff, fmt = 0;
 
 	/* Allocate two new Asterisk channels */
-	if (!(tmp = ast_channel_alloc(1)) || !(tmp2 = ast_channel_alloc(1))) {
+	if (!(tmp = ast_channel_alloc(1, state, 0, 0, "Local/%s@%s-%04x,1", p->exten, p->context, randnum)) 
+			|| !(tmp2 = ast_channel_alloc(1, AST_STATE_RING, 0, 0, "Local/%s@%s-%04x,2", p->exten, p->context, randnum))) {
 		if (tmp)
 			ast_channel_free(tmp);
 		if (tmp2)
@@ -554,12 +555,6 @@
 
 	tmp->nativeformats = p->reqformat;
 	tmp2->nativeformats = p->reqformat;
-
-	ast_string_field_build(tmp, name, "Local/%s@%s-%04x,1", p->exten, p->context, randnum);
-	ast_string_field_build(tmp2, name, "Local/%s@%s-%04x,2", p->exten, p->context, randnum);
-
-	ast_setstate(tmp, state);
-	ast_setstate(tmp2, AST_STATE_RING);
 
 	/* Determine our read/write format and set it on each channel */
 	fmt = ast_best_codec(p->reqformat);

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=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_mgcp.c (original)
+++ team/murf/bug_7506/channels/chan_mgcp.c Thu Nov  2 22:16:00 2006
@@ -1433,7 +1433,7 @@
 	struct mgcp_endpoint *i = sub->parent;
 	int fmt;
 
-	tmp = ast_channel_alloc(1);
+	tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "MGCP/%s@%s-%d", i->name, i->parent->name, sub->id);
 	if (tmp) {
 		tmp->tech = &mgcp_tech;
 		tmp->nativeformats = i->capability;
@@ -1451,7 +1451,6 @@
 		} else {
 			i->dsp = NULL;
 		}
-		ast_setstate(tmp, state);
 		if (state == AST_STATE_RING)
 			tmp->rings = 1;
 		tmp->writeformat = fmt;

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=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_misdn.c (original)
+++ team/murf/bug_7506/channels/chan_misdn.c Thu Nov  2 22:16:00 2006
@@ -3103,14 +3103,25 @@
 static struct ast_channel *misdn_new(struct chan_list *chlist, int state,  char *exten, char *callerid, int format, int port, int c)
 {
 	struct ast_channel *tmp;
-	
-	tmp = ast_channel_alloc(1);
+	char *cid_name = 0, *cid_num = 0;
+	int chan_offset=0;
+	int tmp_port = misdn_cfg_get_next_port(0);
+
+	for (; tmp_port > 0; tmp_port=misdn_cfg_get_next_port(tmp_port)) {
+	if (tmp_port == port) break;
+		chan_offset+=misdn_lib_port_is_pri(tmp_port)?30:2;	
+	}
+	if (c<0) c=0;
+
+	
+	if (callerid) 
+		ast_callerid_parse(callerid, &cid_name, &cid_num);
+
+	tmp = ast_channel_alloc(1, state, cid_num, cid_name, "%s/%d-u%d", misdn_type, chan_offset + c, glob_channel++);
 	
 	if (tmp) {
 		chan_misdn_log(2, 0, " --> * NEW CHANNEL dad:%s oad:%s\n",exten,callerid);
 		
-		update_name(tmp,port,c);
-	
 		tmp->nativeformats = prefformat;
 
 		tmp->readformat = format;
@@ -3155,7 +3166,6 @@
 			
 		}
 		
-		ast_setstate(tmp, state);
 		if (state == AST_STATE_RING)
 			tmp->rings = 1;
 		else

Modified: team/murf/bug_7506/channels/chan_nbs.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_nbs.c?rev=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_nbs.c (original)
+++ team/murf/bug_7506/channels/chan_nbs.c Thu Nov  2 22:16:00 2006
@@ -233,17 +233,15 @@
 static struct ast_channel *nbs_new(struct nbs_pvt *i, int state)
 {
 	struct ast_channel *tmp;
-	tmp = ast_channel_alloc(1);
+	tmp = ast_channel_alloc(1, state, 0, 0, "NBS/%s", i->stream);
 	if (tmp) {
 		tmp->tech = &nbs_tech;
-		ast_string_field_build(tmp, name, "NBS/%s", i->stream);
 		tmp->fds[0] = nbs_fd(i->nbs);
 		tmp->nativeformats = prefformat;
 		tmp->rawreadformat = prefformat;
 		tmp->rawwriteformat = prefformat;
 		tmp->writeformat = prefformat;
 		tmp->readformat = prefformat;
-		ast_setstate(tmp, state);
 		if (state == AST_STATE_RING)
 			tmp->rings = 1;
 		tmp->tech_pvt = i;

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=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_oss.c (original)
+++ team/murf/bug_7506/channels/chan_oss.c Thu Nov  2 22:16:00 2006
@@ -990,11 +990,10 @@
 {
 	struct ast_channel *c;
 
-	c = ast_channel_alloc(1);
+	c = ast_channel_alloc(1, state, o->cid_num, o->cid_name, "OSS/%s", o->device + 5);
 	if (c == NULL)
 		return NULL;
 	c->tech = &oss_tech;
-	ast_string_field_build(c, name, "OSS/%s", o->device + 5);
 	if (o->sounddev < 0)
 		setformat(o, O_RDWR);
 	c->fds[0] = o->sounddev;	/* -1 if device closed, override later */
@@ -1009,12 +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);
+	ast_set_callerid(c, o->cid_num, o->cid_name, o->cid_num); /* is this a mistake? */
 	if (!ast_strlen_zero(ext))
 		c->cid.cid_dnid = ast_strdup(ext);
 
 	o->owner = c;
-	ast_setstate(c, state);
 	ast_jb_configure(c, &global_jbconf);
 	if (state != AST_STATE_DOWN) {
 		if (ast_pbx_start(c)) {

Modified: team/murf/bug_7506/channels/chan_phone.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_phone.c?rev=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_phone.c (original)
+++ team/murf/bug_7506/channels/chan_phone.c Thu Nov  2 22:16:00 2006
@@ -844,10 +844,9 @@
 {
 	struct ast_channel *tmp;
 	struct phone_codec_data codec;
-	tmp = ast_channel_alloc(1);
+	tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "Phone/%s", i->dev + 5);
 	if (tmp) {
 		tmp->tech = cur_tech;
-		ast_string_field_build(tmp, name, "Phone/%s", i->dev + 5);
 		tmp->fds[0] = i->fd;
 		/* XXX Switching formats silently causes kernel panics XXX */
 		if (i->mode == MODE_FXS &&
@@ -869,7 +868,7 @@
 			tmp->rawreadformat = prefformat;
 			tmp->rawwriteformat = prefformat;
 		}
-		ast_setstate(tmp, state);
+		/* no need to call ast_setstate: the channel_alloc already did its job */
 		if (state == AST_STATE_RING)
 			tmp->rings = 1;
 		tmp->tech_pvt = i;

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=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_sip.c (original)
+++ team/murf/bug_7506/channels/chan_sip.c Thu Nov  2 22:16:00 2006
@@ -3771,11 +3771,23 @@
 	int fmt;
 	int what;
 	int needvideo = 0;
+	{
+		const char *my_name;	/* pick a good name */
 	
-	sip_pvt_unlock(i);
-	/* Don't hold a sip pvt lock while we allocate a channel */
-	tmp = ast_channel_alloc(1);
-	sip_pvt_lock(i);
+		if (title)
+			my_name = title;
+		else if ( (my_name = strchr(i->fromdomain,':')) )
+			my_name++;	/* skip ':' */
+		else
+			my_name = i->fromdomain;
+
+		sip_pvt_unlock(i);
+		/* Don't hold a sip pvt lock while we allocate a channel */
+
+		tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "SIP/%s-%08x", my_name, (int)(long) i);
+
+		sip_pvt_lock(i);
+	}
 	if (!tmp) {
 		ast_log(LOG_WARNING, "Unable to allocate AST channel structure for SIP channel\n");
 		return NULL;
@@ -3825,16 +3837,6 @@
 	}
 
 
-	{
-		const char *my_name;	/* pick a good name */
-		if (title)
-			my_name = title;
-		else if ( (my_name = strchr(i->fromdomain,':')) )
-			my_name++;	/* skip ':' */
-		else
-			my_name = i->fromdomain;
-		ast_string_field_build(tmp, name, "SIP/%s-%08x", my_name, (int)(long) i);
-	}
 
 	if (ast_test_flag(&i->flags[0], SIP_DTMF) ==  SIP_DTMF_INBAND) {
 		i->vad = ast_dsp_new();
@@ -3893,7 +3895,6 @@
 		pbx_builtin_setvar_helper(tmp, "SIPDOMAIN", i->domain);
 	if (!ast_strlen_zero(i->callid))
 		pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid);
-	ast_setstate(tmp, state);
 	if (i->rtp)
 		ast_jb_configure(tmp, &global_jbconf);
 	if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
@@ -12496,8 +12497,8 @@
 		/* Chan2m: The transferer, chan1m: The transferee */
 	pthread_t th;
 
-	transferee = ast_channel_alloc(0);
-	transferer = ast_channel_alloc(0);
+	transferee = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "Parking/%s", chan1->name);
+	transferer = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "SIPPeer/%s", chan2->name);
 	if ((!transferer) || (!transferee)) {
 		if (transferee) {
 			transferee->hangupcause = AST_CAUSE_SWITCH_CONGESTION;
@@ -12509,7 +12510,6 @@
 		}
 		return -1;
 	}
-	ast_string_field_build(transferee, name,  "Parking/%s", chan1->name);
 
 	/* Make formats okay */
 	transferee->readformat = chan1->readformat;
@@ -12525,7 +12525,6 @@
 		
 	/* We make a clone of the peer channel too, so we can play
 	   back the announcement */
-	ast_string_field_build(transferer, name, "SIPPeer/%s", chan2->name);
 
 	/* Make formats okay */
 	transferer->readformat = chan2->readformat;

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=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_skinny.c (original)
+++ team/murf/bug_7506/channels/chan_skinny.c Thu Nov  2 22:16:00 2006
@@ -2703,7 +2703,7 @@
 	struct skinny_device *d = l->parent;
 	int fmt;
 
-	tmp = ast_channel_alloc(1);
+	tmp = ast_channel_alloc(1, state, l->cid_num, l->cid_name, "Skinny/%s@%s-%d", l->name, d->name, callnums);
 	if (!tmp) {
 		ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
 		return NULL;
@@ -2735,11 +2735,9 @@
 		fmt = ast_best_codec(tmp->nativeformats);
 		if (skinnydebug)
 			ast_verbose("skinny_new: tmp->nativeformats=%d fmt=%d\n", tmp->nativeformats, fmt);
-		ast_string_field_build(tmp, name, "Skinny/%s@%s-%d", l->name, d->name, sub->callid);
 		if (sub->rtp) {
 			tmp->fds[0] = ast_rtp_fd(sub->rtp);
 		}
-		ast_setstate(tmp, state);
 		if (state == AST_STATE_RING) {
 			tmp->rings = 1;
 		}

Modified: team/murf/bug_7506/channels/chan_vpb.cc
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/channels/chan_vpb.cc?rev=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_vpb.cc (original)
+++ team/murf/bug_7506/channels/chan_vpb.cc Thu Nov  2 22:16:00 2006
@@ -2634,7 +2634,7 @@
 	if (option_verbose > 3)
 		ast_verbose("%s: New call for context [%s]\n",me->dev,context);
 	    
-	tmp = ast_channel_alloc(1);
+	tmp = ast_channel_alloc(1, state, 0, 0, me->dev);
 	if (tmp) {
 		if (use_ast_ind == 1){
 			tmp->tech = &vpb_tech_indicate;
@@ -2643,8 +2643,6 @@
 			tmp->tech = &vpb_tech;
 		}
 
-		ast_string_field_set(tmp, name, me->dev);
-		
 		tmp->callgroup = me->callgroup;
 		tmp->pickupgroup = me->pickupgroup;
 	       
@@ -2655,7 +2653,6 @@
 		tmp->nativeformats = prefformat;
 		tmp->rawreadformat = AST_FORMAT_SLINEAR;
 		tmp->rawwriteformat =  AST_FORMAT_SLINEAR;
-		ast_setstate(tmp, state);
 		if (state == AST_STATE_RING) {
 			tmp->rings = 1;
 			cid_name[0] = '\0';

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=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/channels/chan_zap.c (original)
+++ team/murf/bug_7506/channels/chan_zap.c Thu Nov  2 22:16:00 2006
@@ -5491,7 +5491,11 @@
 		ast_log(LOG_WARNING, "Channel %d already has a %s call\n", i->channel,subnames[index]);
 		return NULL;
 	}
-	if (!(tmp = ast_channel_alloc(0)))
+	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);
+	if (!tmp)
 		return NULL;
 	tmp->tech = &zap_tech;
 	ps.channo = i->channel;

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=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/include/asterisk/channel.h (original)
+++ team/murf/bug_7506/include/asterisk/channel.h Thu Nov  2 22:16:00 2006
@@ -579,7 +579,7 @@
 	by default set to the "default" context and
 	extension "s"
  */
-struct ast_channel *ast_channel_alloc(int needalertpipe);
+struct ast_channel *ast_channel_alloc(int needalertpipe, int state, char *cid_num, char *cid_name, char *name_fmt, ...);
 
 /*! \brief Queue an outgoing frame */
 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);

Modified: team/murf/bug_7506/include/asterisk/stringfields.h
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/include/asterisk/stringfields.h?rev=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/include/asterisk/stringfields.h (original)
+++ team/murf/bug_7506/include/asterisk/stringfields.h Thu Nov  2 22:16:00 2006
@@ -168,6 +168,22 @@
 				    int index, const char *format, ...);
 
 /*!
+  \internal
+  \brief Set a field to a complex (built) value
+  \param mgr Pointer to the pool manager structure
+  \param fields Pointer to the first entry of the field array
+  \param num_fields Number of fields in the array
+  \param index Index position of the field within the structure
+  \param format printf-style format string
+  \param args va_list of the args for the format_string
+  \param args_again a copy of the first va_list for the sake of bsd not having a copy routine
+  \return nothing
+*/
+void __ast_string_field_index_build_va(struct ast_string_field_mgr *mgr,
+				    ast_string_field *fields, int num_fields,
+				    int index, const char *format, va_list a1, va_list a2);
+
+/*!
   \brief Declare a string field
   \param name The field name
 */
@@ -276,6 +292,18 @@
 	__ast_string_field_index_build(&(x)->__field_mgr, &(x)->__begin_field[0], ast_string_field_count(x), index, fmt, args)
 
 /*!
+  \brief Set a field to a complex (built) value with prebuilt va_lists.
+  \param x Pointer to a structure containing fields
+  \param index Index position of the field within the structure
+  \param fmt printf-style format string
+  \param args1 Arguments for format string in va_list format
+  \param args2 a second copy of the va_list for the sake of bsd, with no va_list copy operation
+  \return nothing
+*/
+#define ast_string_field_index_build_va(x, index, fmt, args1, args2) \
+	__ast_string_field_index_build_va(&(x)->__field_mgr, &(x)->__begin_field[0], ast_string_field_count(x), index, fmt, args1, args2)
+
+/*!
   \brief Set a field to a complex (built) value
   \param x Pointer to a structure containing fields
   \param field Name of the field to set
@@ -285,6 +313,17 @@
 */
 #define ast_string_field_build(x, field, fmt, args...) \
 	ast_string_field_index_build(x, ast_string_field_index(x, field), fmt, args)
+
+/*!
+  \brief Set a field to a complex (built) value
+  \param x Pointer to a structure containing fields
+  \param field Name of the field to set
+  \param fmt printf-style format string
+  \param argslist a va_list of the args
+  \return nothing
+*/
+#define ast_string_field_build_va(x, field, fmt, argslist) \
+	ast_string_field_index_build_va(x, ast_string_field_index(x, field), fmt, argslist)
 
 /*!
   \brief Free a field's value.

Modified: team/murf/bug_7506/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/main/channel.c?rev=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/main/channel.c (original)
+++ team/murf/bug_7506/main/channel.c Thu Nov  2 22:16:00 2006
@@ -608,12 +608,13 @@
 };
 
 /*! \brief Create a new channel structure */
-struct ast_channel *ast_channel_alloc(int needqueue)
+struct ast_channel *ast_channel_alloc(int needqueue, int state, char *cid_num, char *cid_name, char *name_fmt, ...)
 {
 	struct ast_channel *tmp;
 	int x;
 	int flags;
 	struct varshead *headp;
+	va_list ap1, ap2;
 
 	/* If shutting down, don't allocate any new channels */
 	if (shutting_down) {
@@ -671,10 +672,10 @@
 	/* And timing pipe */
 	tmp->fds[AST_TIMING_FD] = tmp->timingfd;
 	ast_string_field_set(tmp, name, "**Unknown**");
-	
+
 	/* Initial state */
-	tmp->_state = AST_STATE_DOWN;
-	
+	tmp->_state = state;
+
 	tmp->streamid = -1;
 	
 	tmp->fin = global_fin;
@@ -687,6 +688,35 @@
 		ast_string_field_build(tmp, uniqueid, "%s-%li.%d", ast_config_AST_SYSTEM_NAME, 
 			(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, fmt);
+	va_start(ap2, fmt);
+	ast_string_field_build_va(tmp, 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);
@@ -2858,19 +2888,8 @@
 		
 		if (!(c = chan->tech->requester(type, capabilities | videoformat, data, cause)))
 			return NULL;
-
-		if (c->_state == AST_STATE_DOWN) {
-			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",
-				      c->name, ast_state2str(c->_state),
-				      S_OR(c->cid.cid_num, "<unknown>"),
-				      S_OR(c->cid.cid_name, "<unknown>"),
-				      c->uniqueid);
-		}
+		
+		/* no need to generate a Newchannel event here; it is done in the channel_alloc call */
 		return c;
 	}
 

Modified: team/murf/bug_7506/main/utils.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7506/main/utils.c?rev=47070&r1=47069&r2=47070&view=diff
==============================================================================
--- team/murf/bug_7506/main/utils.c (original)
+++ team/murf/bug_7506/main/utils.c Thu Nov  2 22:16:00 2006
@@ -877,36 +877,45 @@
 	return result;
 }
 
+void __ast_string_field_index_build_va(struct ast_string_field_mgr *mgr,
+				    ast_string_field *fields, int num_fields,
+				    int index, const char *format, va_list ap1, va_list ap2)
+{
+	size_t needed;
+
+	needed = vsnprintf(mgr->pool->base + mgr->used, mgr->space, format, ap1) + 1;
+
+	va_end(ap1);
+
+	if (needed > mgr->space) {
+		size_t new_size = mgr->size * 2;
+
+		while (new_size < needed)
+			new_size *= 2;
+
+		if (add_string_pool(mgr, new_size))
+			return;
+
+		vsprintf(mgr->pool->base + mgr->used, format, ap2);
+	}
+
+	fields[index] = mgr->pool->base + mgr->used;
+	mgr->used += needed;
+	mgr->space -= needed;
+}
+
 void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
 				    ast_string_field *fields, int num_fields,
 				    int index, const char *format, ...)
 {
-	size_t needed;
 	va_list ap1, ap2;
 
 	va_start(ap1, format);
 	va_start(ap2, format);		/* va_copy does not exist on FreeBSD */
 
-	needed = vsnprintf(mgr->pool->base + mgr->used, mgr->space, format, ap1) + 1;
+	__ast_string_field_index_build_va(mgr, fields, num_fields, index, format, ap1, ap2);
 
 	va_end(ap1);
-
-	if (needed > mgr->space) {
-		size_t new_size = mgr->size * 2;
-
-		while (new_size < needed)
-			new_size *= 2;
-
-		if (add_string_pool(mgr, new_size))
-			return;
-
-		vsprintf(mgr->pool->base + mgr->used, format, ap2);
-	}
-
-	fields[index] = mgr->pool->base + mgr->used;
-	mgr->used += needed;
-	mgr->space -= needed;
-
 	va_end(ap2);
 }
 



More information about the asterisk-commits mailing list