From 60f32b41b9db75c382cc8339aa4e2c713b3b5b2a Mon Sep 17 00:00:00 2001 From: russell Date: Mon, 3 Jul 2006 04:19:09 +0000 Subject: use ast_set_callerid to be more consistent and to make sure that the "callerid" option in the conf files is always handled the same way and sets ANI (issue #7285, gkloepfer) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.2@36725 f38db490-d61c-443f-a65b-d21fe96a405b --- channels/chan_agent.c | 14 ++------------ channels/chan_features.c | 17 +++-------------- channels/chan_h323.c | 21 +++++++++++---------- channels/chan_iax2.c | 8 ++------ channels/chan_local.c | 16 +++------------- channels/chan_mgcp.c | 40 +++++++--------------------------------- channels/chan_misdn.c | 5 +---- channels/chan_modem.c | 5 +---- channels/chan_phone.c | 5 +---- channels/chan_sip.c | 5 +---- channels/chan_skinny.c | 38 ++++++++------------------------------ 11 files changed, 40 insertions(+), 134 deletions(-) diff --git a/channels/chan_agent.c b/channels/chan_agent.c index 0d0c9eba1..e41ee0994 100644 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -661,18 +661,8 @@ static int agent_call(struct ast_channel *ast, char *dest, int timeout) /* Call on this agent */ if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "outgoing agentcall, to agent '%s', on '%s'\n", p->agent, p->chan->name); - if (p->chan->cid.cid_num) - free(p->chan->cid.cid_num); - if (ast->cid.cid_num) - p->chan->cid.cid_num = strdup(ast->cid.cid_num); - else - p->chan->cid.cid_num = NULL; - if (p->chan->cid.cid_name) - free(p->chan->cid.cid_name); - if (ast->cid.cid_name) - p->chan->cid.cid_name = strdup(ast->cid.cid_name); - else - p->chan->cid.cid_name = NULL; + ast_set_callerid(p->chan, + ast->cid.cid_num, ast->cid.cid_name, NULL); ast_channel_inherit_variables(ast, p->chan); res = ast_call(p->chan, p->loginchan, 0); CLEANUP(ast,p); diff --git a/channels/chan_features.c b/channels/chan_features.c index 97bbdf8ed..38565ee41 100644 --- a/channels/chan_features.c +++ b/channels/chan_features.c @@ -328,26 +328,15 @@ static int features_call(struct ast_channel *ast, char *dest, int timeout) ast_mutex_lock(&p->lock); x = indexof(p, ast, 0); if (!x && p->subchan) { - if (p->owner->cid.cid_num) - p->subchan->cid.cid_num = strdup(p->owner->cid.cid_num); - else - p->subchan->cid.cid_num = NULL; - - if (p->owner->cid.cid_name) - p->subchan->cid.cid_name = strdup(p->owner->cid.cid_name); - else - p->subchan->cid.cid_name = NULL; + ast_set_callerid(p->subchan, + p->owner->cid.cid_num, p->owner->cid.cid_name, + p->owner->cid.cid_ani ? p->owner->cid.cid_ani : p->owner->cid.cid_num); if (p->owner->cid.cid_rdnis) p->subchan->cid.cid_rdnis = strdup(p->owner->cid.cid_rdnis); else p->subchan->cid.cid_rdnis = NULL; - if (p->owner->cid.cid_ani) - p->subchan->cid.cid_ani = strdup(p->owner->cid.cid_ani); - else - p->subchan->cid.cid_ani = NULL; - p->subchan->cid.cid_pres = p->owner->cid.cid_pres; strncpy(p->subchan->language, p->owner->language, sizeof(p->subchan->language) - 1); strncpy(p->subchan->accountcode, p->owner->accountcode, sizeof(p->subchan->accountcode) - 1); diff --git a/channels/chan_h323.c b/channels/chan_h323.c index ee0bdbd1d..d9057a16c 100644 --- a/channels/chan_h323.c +++ b/channels/chan_h323.c @@ -769,16 +769,17 @@ static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const c if (pvt->amaflags) { ch->amaflags = pvt->amaflags; } - if (!ast_strlen_zero(pvt->cid_num)) { - ch->cid.cid_num = strdup(pvt->cid_num); - } else if (!ast_strlen_zero(pvt->cd.call_source_e164)) { - ch->cid.cid_num = strdup(pvt->cd.call_source_e164); - } - if (!ast_strlen_zero(pvt->cid_name)) { - ch->cid.cid_name = strdup(pvt->cid_name); - } else if (!ast_strlen_zero(pvt->cd.call_source_name)) { - ch->cid.cid_name = strdup(pvt->cd.call_source_name); - } + + /* + * 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->rdnis)) { ch->cid.cid_rdnis = strdup(pvt->rdnis); } diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 387e673f6..1f0afe67b 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -3412,12 +3412,8 @@ 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); - 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); + ast_set_callerid(tmp, i->cid_num, i->cid_name, + i->ani ? i->ani : i->cid_num); if (!ast_strlen_zero(i->language)) ast_copy_string(tmp->language, i->language, sizeof(tmp->language)); if (!ast_strlen_zero(i->dnid)) diff --git a/channels/chan_local.c b/channels/chan_local.c index 8dc46033c..069005902 100644 --- a/channels/chan_local.c +++ b/channels/chan_local.c @@ -336,26 +336,16 @@ static int local_call(struct ast_channel *ast, char *dest, int timeout) size_t len, namelen; ast_mutex_lock(&p->lock); - if (p->owner->cid.cid_num) - p->chan->cid.cid_num = strdup(p->owner->cid.cid_num); - else - p->chan->cid.cid_num = NULL; - if (p->owner->cid.cid_name) - p->chan->cid.cid_name = strdup(p->owner->cid.cid_name); - else - p->chan->cid.cid_name = NULL; + ast_set_callerid(p->chan, + p->owner->cid.cid_num, p->owner->cid.cid_name, + p->owner->cid.cid_ani ? p->chan->cid.cid_ani : p->owner->cid.cid_num); if (p->owner->cid.cid_rdnis) p->chan->cid.cid_rdnis = strdup(p->owner->cid.cid_rdnis); else p->chan->cid.cid_rdnis = NULL; - if (p->owner->cid.cid_ani) - p->chan->cid.cid_ani = strdup(p->owner->cid.cid_ani); - else - p->chan->cid.cid_ani = NULL; - p->chan->cid.cid_pres = p->owner->cid.cid_pres; strncpy(p->chan->language, p->owner->language, sizeof(p->chan->language) - 1); diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index 7538fd9d7..9fca447b0 100644 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -1428,10 +1428,7 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state) 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); - 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); + ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num); if (!i->adsi) tmp->adsicpe = AST_ADSI_UNAVAILABLE; tmp->priority = 1; @@ -2621,21 +2618,10 @@ static void *mgcp_ss(void *data) /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/ ast_indicate(chan, -1); strncpy(chan->exten, exten, sizeof(chan->exten)-1); - if (!ast_strlen_zero(p->cid_num)) { - if (!p->hidecallerid) { - /* SC: free existing chan->callerid */ - if (chan->cid.cid_num) - free(chan->cid.cid_num); - chan->cid.cid_num = strdup(p->cid_num); - /* SC: free existing chan->callerid */ - if (chan->cid.cid_name) - free(chan->cid.cid_name); - chan->cid.cid_name = strdup(p->cid_name); - } - if (chan->cid.cid_ani) - free(chan->cid.cid_ani); - chan->cid.cid_ani = strdup(p->cid_num); - } + ast_set_callerid(chan, + p->hidecallerid ? "" : p->cid_num, + p->hidecallerid ? "" : p->cid_name, + chan->cid.cid_ani ? NULL : p->cid_num); ast_setstate(chan, AST_STATE_RING); /*zt_enable_ec(p);*/ if (p->dtmfmode & MGCP_DTMF_HYBRID) { @@ -2692,12 +2678,7 @@ static void *mgcp_ss(void *data) } /* Disable Caller*ID if enabled */ p->hidecallerid = 1; - if (chan->cid.cid_num) - free(chan->cid.cid_num); - chan->cid.cid_num = NULL; - if (chan->cid.cid_name) - free(chan->cid.cid_name); - chan->cid.cid_name = NULL; + ast_set_callerid(chan, "", "", NULL); /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/ transmit_notify_request(sub, "L/sl"); len = 0; @@ -2776,14 +2757,7 @@ static void *mgcp_ss(void *data) } /* Enable Caller*ID if enabled */ p->hidecallerid = 0; - if (chan->cid.cid_num) - free(chan->cid.cid_num); - if (!ast_strlen_zero(p->cid_num)) - chan->cid.cid_num = strdup(p->cid_num); - if (chan->cid.cid_name) - free(chan->cid.cid_name); - if (!ast_strlen_zero(p->cid_name)) - chan->cid.cid_name = strdup(p->cid_name); + ast_set_callerid(chan, p->cid_num, p->cid_name, NULL); /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/ transmit_notify_request(sub, "L/sl"); len = 0; diff --git a/channels/chan_misdn.c b/channels/chan_misdn.c index 46296c18f..2538d3583 100644 --- a/channels/chan_misdn.c +++ b/channels/chan_misdn.c @@ -2164,10 +2164,7 @@ struct ast_channel *misdn_new(struct chan_list *chlist, int state, char * name, char *cid_name, *cid_num; ast_callerid_parse(callerid, &cid_name, &cid_num); - if (cid_name) - tmp->cid.cid_name=strdup(cid_name); - if (cid_num) - tmp->cid.cid_num=strdup(cid_num); + ast_set_callerid(tmp, cid_num, cid_name, cid_num); } { diff --git a/channels/chan_modem.c b/channels/chan_modem.c index 09adc4733..8e5e8d79f 100644 --- a/channels/chan_modem.c +++ b/channels/chan_modem.c @@ -576,10 +576,7 @@ struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state) tmp->tech_pvt = i; strncpy(tmp->context, i->context, sizeof(tmp->context)-1); - 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); + ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num); if (!ast_strlen_zero(i->language)) strncpy(tmp->language,i->language, sizeof(tmp->language)-1); diff --git a/channels/chan_phone.c b/channels/chan_phone.c index c1d552716..0cb57fc11 100644 --- a/channels/chan_phone.c +++ b/channels/chan_phone.c @@ -825,10 +825,7 @@ 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)) strncpy(tmp->language, i->language, sizeof(tmp->language)-1); - 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); + ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num); i->owner = tmp; ast_mutex_lock(&usecnt_lock); usecnt++; diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 1490cdf9d..7a200da49 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -2817,10 +2817,7 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, char *title) 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)); - 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); + ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num); if (!ast_strlen_zero(i->rdnis)) tmp->cid.cid_rdnis = strdup(i->rdnis); if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s")) diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c index 37321a355..c35b02810 100644 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -1741,11 +1741,12 @@ static void *skinny_ss(void *data) getforward = 0; } else { strncpy(chan->exten, exten, sizeof(chan->exten)-1); + if (!ast_strlen_zero(l->cid_num)) { - if (!l->hidecallerid) { - chan->cid.cid_num = strdup(l->cid_num); - chan->cid.cid_ani = strdup(l->cid_num); - } + ast_set_callerid(chan, + l->hidecallerid ? "" : l->cid_num, + l->hidecallerid ? "" : l->cid_name, + chan->cid.cid_ani ? NULL : l->cid_num); ast_setstate(chan, AST_STATE_RING); res = ast_pbx_run(chan); if (res) { @@ -1792,14 +1793,7 @@ static void *skinny_ss(void *data) } /* Disable Caller*ID if enabled */ l->hidecallerid = 1; - if (chan->cid.cid_num) { - free(chan->cid.cid_num); - } - chan->cid.cid_num = NULL; - if (chan->cid.cid_name) { - free(chan->cid.cid_name); - } - chan->cid.cid_name = NULL; + ast_set_callerid(chan, "", "", NULL); transmit_tone(s, SKINNY_DIALTONE); len = 0; memset(exten, 0, sizeof(exten)); @@ -1873,18 +1867,7 @@ static void *skinny_ss(void *data) } /* Enable Caller*ID if enabled */ l->hidecallerid = 0; - if (chan->cid.cid_num) { - free(chan->cid.cid_num); - } - if (!ast_strlen_zero(l->cid_num)) { - chan->cid.cid_num = strdup(l->cid_num); - } - if (chan->cid.cid_name) { - free(chan->cid.cid_name); - } - if (!ast_strlen_zero(l->cid_name)) { - chan->cid.cid_name = strdup(l->cid_name); - } + ast_set_callerid(chan, l->cid_num, l->cid_name, NULL); transmit_tone(s, SKINNY_DIALTONE); len = 0; memset(exten, 0, sizeof(exten)); @@ -2296,12 +2279,7 @@ static struct ast_channel *skinny_new(struct skinny_subchannel *sub, int state) 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); - if (!ast_strlen_zero(l->cid_num)) { - tmp->cid.cid_num = strdup(l->cid_num); - } - if (!ast_strlen_zero(l->cid_name)) { - tmp->cid.cid_name = strdup(l->cid_name); - } + ast_set_callerid(tmp, l->cid_num, l->cid_name, l->cid_num); tmp->priority = 1; tmp->adsicpe = AST_ADSI_UNAVAILABLE; -- cgit v1.2.3