Merged revisions 38903-38904 via svnmerge from
authorRussell Bryant <russell@russellbryant.com>
Sat, 5 Aug 2006 05:26:29 +0000 (05:26 +0000)
committerRussell Bryant <russell@russellbryant.com>
Sat, 5 Aug 2006 05:26:29 +0000 (05:26 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r38903 | russell | 2006-08-05 01:07:39 -0400 (Sat, 05 Aug 2006) | 2 lines

suppress a compiler warning about the usage of a potentially uninitialized variable

........
r38904 | russell | 2006-08-05 01:08:50 -0400 (Sat, 05 Aug 2006) | 10 lines

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()

........

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@38905 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channel.c
channels/chan_h323.c
channels/chan_iax2.c
channels/chan_mgcp.c
channels/chan_misdn.c
channels/chan_phone.c
channels/chan_sip.c
channels/chan_skinny.c
channels/chan_zap.c

index eb2c963..fffcc8d 100644 (file)
--- a/channel.c
+++ b/channel.c
@@ -3625,7 +3625,7 @@ enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_cha
        }
 
        for (/* ever */;;) {
-               struct timeval now;
+               struct timeval now = { 0, };
                int to;
 
                to = -1;
index b5e3b18..5a4a400 100644 (file)
@@ -796,18 +796,19 @@ static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const c
                if (pvt->amaflags) {
                        ch->amaflags = pvt->amaflags;
                }
-               /*
-                * If cid_num and cd.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,
-                       !ast_strlen_zero(pvt->cid_name) ? pvt->cid_name : pvt->cd.call_source_name,
-                       !ast_strlen_zero(pvt->cid_num) ? pvt->cid_num : pvt->cd.call_source_e164);
-               if (!ast_strlen_zero(pvt->rdnis)) {
-                       ch->cid.cid_rdnis = strdup(pvt->rdnis);
+               
+               /* Don't use ast_set_callerid() here because it will
+                * generate a NewCallerID event before the NewChannel event */
+               if (!ast_strlen_zero(pvt->cid_num)) {
+                       ch->cid.cid_num = ast_strdup(pvt->cid_num);
+                       ch->cid.cid_ani = ast_strdup(pvt->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);
                }
+               ch->cid.cid_name = ast_strdup(pvt->cid_name);
+               ch->cid.cid_rdnis = ast_strdup(pvt->rdnis);
+               
                if (!ast_strlen_zero(pvt->exten) && strcmp(pvt->exten, "s")) {
                        ch->cid.cid_dnid = strdup(pvt->exten);
                }
index 5493d3a..9a14d1d 100644 (file)
@@ -3259,16 +3259,21 @@ static struct ast_channel *ast_iax2_new(int callno, int state, int capability)
        tmp->writeformat = ast_best_codec(capability);
        tmp->tech_pvt = CALLNO_TO_PTR(i->callno);
 
-       ast_set_callerid(tmp, i->cid_num, i->cid_name, S_OR(i->ani, i->cid_num));
-       if (!ast_strlen_zero(i->language))
-               ast_string_field_set(tmp, language, i->language);
-       if (!ast_strlen_zero(i->dnid))
-               tmp->cid.cid_dnid = ast_strdup(i->dnid);
-       if (!ast_strlen_zero(i->rdnis))
-               tmp->cid.cid_rdnis = ast_strdup(i->rdnis);
+       /* 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->ani))
+               tmp->cid.cid_ani = ast_strdup(i->ani);
+       else
+               tmp->cid.cid_ani = ast_strdup(i->cid_num);
+       tmp->cid.cid_dnid = ast_strdup(i->dnid);
+       tmp->cid.cid_rdnis = ast_strdup(i->rdnis);
        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_string_field_set(tmp, language, i->language);
        if (!ast_strlen_zero(i->accountcode))
                ast_string_field_set(tmp, accountcode, i->accountcode);
        if (i->amaflags)
index b70e171..7b56b8c 100644 (file)
@@ -1415,7 +1415,13 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state)
                ast_string_field_set(tmp, call_forward, i->call_forward);
                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);
+
+               /* 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_ani = ast_strdup(i->cid_num);
+               tmp->cid.cid_name = ast_strdup(i->cid_name);
+               
                if (!i->adsi)
                        tmp->adsicpe = AST_ADSI_UNAVAILABLE;
                tmp->priority = 1;
index 68f319c..f093af0 100644 (file)
@@ -3099,9 +3099,11 @@ static struct ast_channel *misdn_new(struct chan_list *chlist, int state,  char
                        char *cid_name, *cid_num;
       
                        ast_callerid_parse(callerid, &cid_name, &cid_num);
-                       ast_set_callerid(tmp, cid_num,cid_name,cid_num);
-               } else {
-                       ast_set_callerid(tmp, NULL,NULL,NULL);
+                       /* Don't use ast_set_callerid() here because it will
+                        * generate a NewCallerID event before the NewChannel 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);
                }
 
                {
index 12ccba5..668db2f 100644 (file)
@@ -864,7 +864,13 @@ static struct ast_channel *phone_new(struct phone_pvt *i, int state, char *conte
                        strncpy(tmp->exten, "s",  sizeof(tmp->exten) - 1);
                if (!ast_strlen_zero(i->language))
                        ast_string_field_set(tmp, language, i->language);
-               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 NewCallerID event before the NewChannel 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);
+
                i->owner = tmp;
                ast_mutex_lock(&usecnt_lock);
                usecnt++;
index 6fcd10d..3b5b100 100644 (file)
@@ -3682,11 +3682,17 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit
        ast_update_use_count();
        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->rdnis))
-               tmp->cid.cid_rdnis = ast_strdup(i->rdnis);
+
+       /* 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_ani = ast_strdup(i->cid_num);
+       tmp->cid.cid_name = ast_strdup(i->cid_name);
+       tmp->cid.cid_rdnis = ast_strdup(i->rdnis);
+       
        if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
                tmp->cid.cid_dnid = ast_strdup(i->exten);
+
        tmp->priority = 1;
        if (!ast_strlen_zero(i->uri))
                pbx_builtin_setvar_helper(tmp, "SIPURI", i->uri);
index c5feda2..00b54f0 100644 (file)
@@ -2582,7 +2582,13 @@ static struct ast_channel *skinny_new(struct skinny_line *l, int state)
                ast_string_field_set(tmp, call_forward, l->call_forward);
                ast_copy_string(tmp->context, l->context, sizeof(tmp->context));
                ast_copy_string(tmp->exten, l->exten, sizeof(tmp->exten));
-               ast_set_callerid(tmp, l->cid_num, l->cid_name, l->cid_num);
+
+               /* Don't use ast_set_callerid() here because it will
+                * generate a NewCallerID event before the NewChannel 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);
+
                tmp->priority = 1;
                tmp->adsicpe = AST_ADSI_UNAVAILABLE;
 
index b0578e7..ad3d228 100644 (file)
@@ -5217,9 +5217,18 @@ static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int
                tmp->cid.cid_dnid = ast_strdup(i->dnid);
 
 #ifdef PRI_ANI
-       ast_set_callerid(tmp, i->cid_num, i->cid_name, S_OR(i->cid_ani, i->cid_num));
+       /* 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))
+               tmp->cid.cid_ani = ast_strdup(i->cid_num);
+       else    
+               tmp->cid.cid_ani = ast_strdup(i->cid_num);
 #else
-       ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num);
+       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);
 #endif
        tmp->cid.cid_pres = i->callingpres;
        tmp->cid.cid_ton = i->cid_ton;