[asterisk-commits] russell: branch 1.2 r38904 - /branches/1.2/channels/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Aug 4 22:08:51 MST 2006


Author: russell
Date: Sat Aug  5 00:08:50 2006
New Revision: 38904

URL: http://svn.digium.com/view/asterisk?rev=38904&view=rev
Log:
Fix an issue that would cause a NewCallerID manager event to be generated
before the channel's NewChannel event.  This was due to a somewhat recent
change that included using ast_set_callerid() where it wasn't before.  This
function should not be used in the channel driver "new" functions.
(issue #7654, fixed by me)

Also, fix a couple minor bugs in usecount handling.  chan_iax2 could have
increased the usecount but then returned an error.  The place where chan_sip
increased the usecount did not call ast_update_usecount()

Modified:
    branches/1.2/channels/chan_h323.c
    branches/1.2/channels/chan_iax2.c
    branches/1.2/channels/chan_mgcp.c
    branches/1.2/channels/chan_misdn.c
    branches/1.2/channels/chan_modem.c
    branches/1.2/channels/chan_phone.c
    branches/1.2/channels/chan_sip.c
    branches/1.2/channels/chan_skinny.c
    branches/1.2/channels/chan_vpb.c
    branches/1.2/channels/chan_zap.c

Modified: branches/1.2/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_h323.c?rev=38904&r1=38903&r2=38904&view=diff
==============================================================================
--- branches/1.2/channels/chan_h323.c (original)
+++ branches/1.2/channels/chan_h323.c Sat Aug  5 00:08:50 2006
@@ -770,15 +770,15 @@
 			ch->amaflags = pvt->amaflags;
 		}
 
-		/*
-		 * If cid_num and cdi.call_source_e164 are both null, then
-		 * ast_set_callerid will do the right thing and leave the
-		 * cid_num and cid_ani for the channel alone.
-		 */
-		ast_set_callerid(ch,
-			!ast_strlen_zero(pvt->cid_num) ? pvt->cid_num : pvt->cd.call_source_e164,
-			pvt->cid_name,
-			!ast_strlen_zero(pvt->cid_num) ? pvt->cid_num : pvt->cd.call_source_e164);
+		if (!ast_strlen_zero(pvt->cid_num)) {
+			ch->cid.cid_num = strdup(pvt->cid_num);
+			ch->cid.cid_ani = strdup(pvt->cid_num);
+		} else if (!ast_strlen_zero(pvt->cd.call_source_e164)) {
+			ch->cid.cid_num = strdup(pvt->cd.call_source_e164);
+			ch->cid.cid_ani = strdup(pvt->cd.call_source_e164);
+		}
+		if (!ast_strlen_zero(pvt->cid_name))
+			ch->cid.cid_name = strdup(pvt->cid_name);
 
 		if (!ast_strlen_zero(pvt->rdnis)) {
 			ch->cid.cid_rdnis = strdup(pvt->rdnis);

Modified: branches/1.2/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_iax2.c?rev=38904&r1=38903&r2=38904&view=diff
==============================================================================
--- branches/1.2/channels/chan_iax2.c (original)
+++ branches/1.2/channels/chan_iax2.c Sat Aug  5 00:08:50 2006
@@ -3442,15 +3442,22 @@
 		tmp->writeformat = ast_best_codec(capability);
 		tmp->tech_pvt = CALLNO_TO_PTR(i->callno);
 
-		ast_set_callerid(tmp, i->cid_num, i->cid_name,
-			i->ani ? i->ani : i->cid_num);
+		if (!ast_strlen_zero(i->cid_num))
+			tmp->cid.cid_num = strdup(i->cid_num);
+		if (!ast_strlen_zero(i->cid_name))
+			tmp->cid.cid_name = strdup(i->cid_name);
+		if (!ast_strlen_zero(i->ani))
+			tmp->cid.cid_ani = strdup(i->ani);
+		else if (!ast_strlen_zero(i->cid_num))
+			tmp->cid.cid_ani = strdup(i->cid_num);
+		tmp->cid.cid_pres = i->calling_pres;
+		tmp->cid.cid_ton = i->calling_ton;
+		tmp->cid.cid_tns = i->calling_tns;
+
 		if (!ast_strlen_zero(i->language))
 			ast_copy_string(tmp->language, i->language, sizeof(tmp->language));
 		if (!ast_strlen_zero(i->dnid))
 			tmp->cid.cid_dnid = strdup(i->dnid);
-		tmp->cid.cid_pres = i->calling_pres;
-		tmp->cid.cid_ton = i->calling_ton;
-		tmp->cid.cid_tns = i->calling_tns;
 		if (!ast_strlen_zero(i->accountcode))
 			ast_copy_string(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode));
 		if (i->amaflags)
@@ -3461,10 +3468,6 @@
 		i->owner = tmp;
 		i->capability = capability;
 		ast_setstate(tmp, state);
-		ast_mutex_lock(&usecnt_lock);
-		usecnt++;
-		ast_mutex_unlock(&usecnt_lock);
-		ast_update_use_count();
 		if (state != AST_STATE_DOWN) {
 			if (ast_pbx_start(tmp)) {
 				ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
@@ -3475,6 +3478,10 @@
 		for (v = i->vars ; v ; v = v->next)
 			pbx_builtin_setvar_helper(tmp,v->name,v->value);
 		
+		ast_mutex_lock(&usecnt_lock);
+		usecnt++;
+		ast_mutex_unlock(&usecnt_lock);
+		ast_update_use_count();
 	}
 	return tmp;
 }

Modified: branches/1.2/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_mgcp.c?rev=38904&r1=38903&r2=38904&view=diff
==============================================================================
--- branches/1.2/channels/chan_mgcp.c (original)
+++ branches/1.2/channels/chan_mgcp.c Sat Aug  5 00:08:50 2006
@@ -1428,7 +1428,14 @@
 		strncpy(tmp->call_forward, i->call_forward, sizeof(tmp->call_forward) - 1);
 		strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
 		strncpy(tmp->exten, i->exten, sizeof(tmp->exten)-1);
-		ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num);
+
+		if (!ast_strlen_zero(i->cid_num)) {
+			tmp->cid.cid_num = strdup(i->cid_num);
+			tmp->cid.cid_ani = strdup(i->cid_num);
+		}
+		if (!ast_strlen_zero(i->cid_name))
+			tmp->cid.cid_name = strdup(i->cid_name);
+		
 		if (!i->adsi)
 			tmp->adsicpe = AST_ADSI_UNAVAILABLE;
 		tmp->priority = 1;

Modified: branches/1.2/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_misdn.c?rev=38904&r1=38903&r2=38904&view=diff
==============================================================================
--- branches/1.2/channels/chan_misdn.c (original)
+++ branches/1.2/channels/chan_misdn.c Sat Aug  5 00:08:50 2006
@@ -2164,7 +2164,12 @@
 			char *cid_name, *cid_num;
       
 			ast_callerid_parse(callerid, &cid_name, &cid_num);
-			ast_set_callerid(tmp, cid_num, cid_name, cid_num);
+			if (!ast_strlen_zero(cid_num)) {
+				tmp->cid.cid_num = strdup(cid_num);
+				tmp->cid.cid_ani = strdup(cid_num);
+			}
+			if (!ast_strlen_zero(cid_name))
+				tmp->cid.cid_name = strdup(cid_name);
 		}
 
 		{

Modified: branches/1.2/channels/chan_modem.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_modem.c?rev=38904&r1=38903&r2=38904&view=diff
==============================================================================
--- branches/1.2/channels/chan_modem.c (original)
+++ branches/1.2/channels/chan_modem.c Sat Aug  5 00:08:50 2006
@@ -573,7 +573,12 @@
 		tmp->tech_pvt = i;
 		strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
 
-		ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num);
+		if (!ast_strlen_zero(i->cid_num)) {
+			tmp->cid.cid_num = strdup(i->cid_num);
+			tmp->cid.cid_ani = strdup(i->cid_num);
+		}
+		if (!ast_strlen_zero(i->cid_name))
+			tmp->cid.cid_name = strdup(i->cid_name);
 
 		if (!ast_strlen_zero(i->language))
 			strncpy(tmp->language,i->language, sizeof(tmp->language)-1);

Modified: branches/1.2/channels/chan_phone.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_phone.c?rev=38904&r1=38903&r2=38904&view=diff
==============================================================================
--- branches/1.2/channels/chan_phone.c (original)
+++ branches/1.2/channels/chan_phone.c Sat Aug  5 00:08:50 2006
@@ -825,7 +825,14 @@
 			strncpy(tmp->exten, "s",  sizeof(tmp->exten) - 1);
 		if (!ast_strlen_zero(i->language))
 			strncpy(tmp->language, i->language, sizeof(tmp->language)-1);
-		ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num);
+
+		if (!ast_strlen_zero(i->cid_num)) {
+			tmp->cid.cid_num = strdup(i->cid_num);
+			tmp->cid.cid_ani = strdup(i->cid_num);
+		}
+		if (!ast_strlen_zero(i->cid_name))
+			tmp->cid.cid_name = strdup(i->cid_name);
+
 		i->owner = tmp;
 		ast_mutex_lock(&usecnt_lock);
 		usecnt++;

Modified: branches/1.2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_sip.c?rev=38904&r1=38903&r2=38904&view=diff
==============================================================================
--- branches/1.2/channels/chan_sip.c (original)
+++ branches/1.2/channels/chan_sip.c Sat Aug  5 00:08:50 2006
@@ -2821,16 +2821,20 @@
 	if (!ast_strlen_zero(i->musicclass))
 		ast_copy_string(tmp->musicclass, i->musicclass, sizeof(tmp->musicclass));
 	i->owner = tmp;
-	ast_mutex_lock(&usecnt_lock);
-	usecnt++;
-	ast_mutex_unlock(&usecnt_lock);
 	ast_copy_string(tmp->context, i->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);
+
+	if (!ast_strlen_zero(i->cid_num)) {
+		tmp->cid.cid_num = strdup(i->cid_num);
+		tmp->cid.cid_ani = strdup(i->cid_num);
+	}
+	if (!ast_strlen_zero(i->cid_name))
+		tmp->cid.cid_name = strdup(i->cid_name);
 	if (!ast_strlen_zero(i->rdnis))
 		tmp->cid.cid_rdnis = strdup(i->rdnis);
 	if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
 		tmp->cid.cid_dnid = strdup(i->exten);
+
 	tmp->priority = 1;
 	if (!ast_strlen_zero(i->uri)) {
 		pbx_builtin_setvar_helper(tmp, "SIPURI", i->uri);
@@ -2860,6 +2864,11 @@
 	for (v = i->chanvars ; v ; v = v->next)
 		pbx_builtin_setvar_helper(tmp,v->name,v->value);
 				
+	ast_mutex_lock(&usecnt_lock);
+	usecnt++;
+	ast_mutex_unlock(&usecnt_lock);
+	ast_update_use_count();	
+	
 	return tmp;
 }
 

Modified: branches/1.2/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_skinny.c?rev=38904&r1=38903&r2=38904&view=diff
==============================================================================
--- branches/1.2/channels/chan_skinny.c (original)
+++ branches/1.2/channels/chan_skinny.c Sat Aug  5 00:08:50 2006
@@ -2279,7 +2279,14 @@
 		strncpy(tmp->call_forward, l->call_forward, sizeof(tmp->call_forward) - 1);
 		strncpy(tmp->context, l->context, sizeof(tmp->context)-1);
 		strncpy(tmp->exten,l->exten, sizeof(tmp->exten)-1);
-		ast_set_callerid(tmp, l->cid_num, l->cid_name, l->cid_num);
+
+		if (!ast_strlen_zero(l->cid_num)) {
+			tmp->cid.cid_num = strdup(l->cid_num);
+			tmp->cid.cid_ani = strdup(l->cid_num);
+		}
+		if (!ast_strlen_zero(l->cid_name))
+			tmp->cid.cid_name = strdup(l->cid_name);
+
 		tmp->priority = 1;
 		tmp->adsicpe = AST_ADSI_UNAVAILABLE;
 

Modified: branches/1.2/channels/chan_vpb.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_vpb.c?rev=38904&r1=38903&r2=38904&view=diff
==============================================================================
--- branches/1.2/channels/chan_vpb.c (original)
+++ branches/1.2/channels/chan_vpb.c Sat Aug  5 00:08:50 2006
@@ -2647,7 +2647,12 @@
 			cid_name[0] = '\0';
 			cid_num[0] = '\0';
 			ast_callerid_split(me->callerid, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
-			ast_set_callerid(tmp, cid_num, cid_name, cid_num);
+			if (!ast_strlen_zero(cid_num)) {
+				tmp->cid.cid_num = strdup(cid_num);
+				tmp->cid.cid_ani = strdup(cid_num);
+			}
+			if (!ast_strlen_zero(cid_name))
+				tmp->cid.cid_name = strdup(cid_name);
 		}
 		tmp->tech_pvt = me;
 		

Modified: branches/1.2/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_zap.c?rev=38904&r1=38903&r2=38904&view=diff
==============================================================================
--- branches/1.2/channels/chan_zap.c (original)
+++ branches/1.2/channels/chan_zap.c Sat Aug  5 00:08:50 2006
@@ -5118,9 +5118,21 @@
 			tmp->cid.cid_dnid = strdup(i->dnid);
 
 #ifdef PRI_ANI
-		ast_set_callerid(tmp, i->cid_num, i->cid_name, ast_strlen_zero(i->cid_ani) ? i->cid_num : i->cid_ani);
+		if (!ast_strlen_zero(i->cid_num))
+			tmp->cid.cid_num = strdup(i->cid_num);
+		if (!ast_strlen_zero(i->cid_name))
+			tmp->cid.cid_name = strdup(i->cid_name);
+		if (!ast_strlen_zero(i->cid_ani))
+			tmp->cid.cid_ani = strdup(i->cid_num);
+		else if (!ast_strlen_zero(i->cid_num))	
+			tmp->cid.cid_ani = strdup(i->cid_num);
 #else
-		ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num);
+		if (!ast_strlen_zero(i->cid_num)) {
+			tmp->cid.cid_num = strdup(i->cid_num);
+			tmp->cid.cid_ani = strdup(i->cid_num);
+		}
+		if (!ast_strlen_zero(i->cid_name))
+			tmp->cid.cid_name = strdup(i->cid_name);
 #endif
 		tmp->cid.cid_pres = i->callingpres;
 		tmp->cid.cid_ton = i->cid_ton;



More information about the asterisk-commits mailing list