diff options
-rw-r--r-- | channels/chan_agent.c | 8 | ||||
-rw-r--r-- | channels/chan_h323.c | 19 | ||||
-rw-r--r-- | channels/chan_iax2.c | 7 | ||||
-rw-r--r-- | channels/chan_jingle.c | 5 | ||||
-rw-r--r-- | channels/chan_mgcp.c | 38 | ||||
-rw-r--r-- | channels/chan_oss.c | 9 | ||||
-rw-r--r-- | channels/chan_phone.c | 5 | ||||
-rw-r--r-- | channels/chan_sip.c | 5 | ||||
-rw-r--r-- | channels/chan_skinny.c | 43 | ||||
-rw-r--r-- | channels/chan_vpb.c | 18 |
10 files changed, 49 insertions, 108 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c index a95c638c6..2e26d7c1c 100644 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -640,12 +640,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); - p->chan->cid.cid_num = ast_strdup(ast->cid.cid_num); - if (p->chan->cid.cid_name) - free(p->chan->cid.cid_name); - p->chan->cid.cid_name = ast_strdup(ast->cid.cid_name); + 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_h323.c b/channels/chan_h323.c index 36c0582b8..a638b19a7 100644 --- a/channels/chan_h323.c +++ b/channels/chan_h323.c @@ -786,16 +786,15 @@ 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 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); } diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 7eb42457e..db8eb4aa1 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -3287,12 +3287,7 @@ 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 = ast_strdup(i->cid_num); - if (!ast_strlen_zero(i->cid_name)) - tmp->cid.cid_name = ast_strdup(i->cid_name); - if (!ast_strlen_zero(i->ani)) - tmp->cid.cid_ani = ast_strdup(i->ani); + 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)) diff --git a/channels/chan_jingle.c b/channels/chan_jingle.c index 16bd521da..c5957e399 100644 --- a/channels/chan_jingle.c +++ b/channels/chan_jingle.c @@ -761,10 +761,7 @@ static struct ast_channel *jingle_new(struct jingle *client, struct jingle_pvt * 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)); - if (!ast_strlen_zero(i->cid_num)) - tmp->cid.cid_num = ast_strdup(i->cid_num); - if (!ast_strlen_zero(i->cid_name)) - tmp->cid.cid_name = ast_strdup(i->cid_name); + 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; diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index 9d9499fe6..df7db1b8a 100644 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -1485,8 +1485,7 @@ 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)); - tmp->cid.cid_num = ast_strdup(i->cid_num); - tmp->cid.cid_name = ast_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; @@ -2677,21 +2676,10 @@ static void *mgcp_ss(void *data) /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/ ast_indicate(chan, -1); ast_copy_string(chan->exten, exten, sizeof(chan->exten)); - 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 = ast_strdup(p->cid_num); - /* SC: free existing chan->callerid */ - if (chan->cid.cid_name) - free(chan->cid.cid_name); - chan->cid.cid_name = ast_strdup(p->cid_name); - } - if (chan->cid.cid_ani) - free(chan->cid.cid_ani); - chan->cid.cid_ani = ast_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) { @@ -2748,12 +2736,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; @@ -2832,14 +2815,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_oss.c b/channels/chan_oss.c index 98ca519de..ace9d50bb 100644 --- a/channels/chan_oss.c +++ b/channels/chan_oss.c @@ -991,12 +991,9 @@ static struct ast_channel *oss_new(struct chan_oss_pvt *o, ast_copy_string(c->exten, ext, sizeof(c->exten)); if (!ast_strlen_zero(o->language)) ast_string_field_set(c, language, o->language); - if (!ast_strlen_zero(o->cid_num)) - c->cid.cid_num = ast_strdup(o->cid_num); - if (!ast_strlen_zero(o->cid_name)) - c->cid.cid_name = ast_strdup(o->cid_name); - if (!ast_strlen_zero(ext)) - c->cid.cid_dnid = strdup(ext); + ast_set_callerid(c, o->cid_num, o->cid_name, o->cid_num); + if (!ast_strlen_zero(ext)) + c->cid.cid_dnid = ast_strdup(ext); o->owner = c; ast_setstate(c, state); diff --git a/channels/chan_phone.c b/channels/chan_phone.c index 86ad060cd..99ce67a71 100644 --- a/channels/chan_phone.c +++ b/channels/chan_phone.c @@ -857,10 +857,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)) ast_string_field_set(tmp, language, i->language); - 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 6e2472ac0..f7b9e2825 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -3687,10 +3687,7 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit 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 = ast_strdup(i->cid_num); - if (!ast_strlen_zero(i->cid_name)) - tmp->cid.cid_name = ast_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 = ast_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 0dc12419f..aaaf85609 100644 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -2093,12 +2093,10 @@ static void *skinny_ss(void *data) } else { ast_copy_string(chan->exten, exten, sizeof(chan->exten)); ast_copy_string(l->lastnumberdialed, exten, sizeof(l->lastnumberdialed)); - 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) { @@ -2525,8 +2523,7 @@ 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)); - tmp->cid.cid_num = ast_strdup(l->cid_num); - tmp->cid.cid_name = ast_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; @@ -2720,12 +2717,10 @@ static int handle_stimulus_message(skinny_req *req, struct skinnysession *s) if (ast_exists_extension(c, c->context, l->lastnumberdialed, 1, l->cid_num)) { if (!ast_matchmore_extension(c, c->context, l->lastnumberdialed, 1, l->cid_num)) { ast_copy_string(c->exten, l->lastnumberdialed, sizeof(c->exten)); - if (!ast_strlen_zero(l->cid_num)) { - if (!l->hidecallerid) { - c->cid.cid_num = strdup(l->cid_num); - c->cid.cid_ani = strdup(l->cid_num); - } - } + ast_set_callerid(c, + l->hidecallerid ? "" : l->cid_num, + l->hidecallerid ? "" : l->cid_name, + c->cid.cid_ani ? NULL : l->cid_num); ast_setstate(c, AST_STATE_RING); res = ast_pbx_run(c); if (res) { @@ -2766,12 +2761,10 @@ static int handle_stimulus_message(skinny_req *req, struct skinnysession *s) if (!ast_matchmore_extension(c, c->context, sd->exten, 1, l->cid_num)) { ast_copy_string(c->exten, sd->exten, sizeof(c->exten)); ast_copy_string(l->lastnumberdialed, sd->exten, sizeof(l->lastnumberdialed)); - if (!ast_strlen_zero(l->cid_num)) { - if (!l->hidecallerid) { - c->cid.cid_num = strdup(l->cid_num); - c->cid.cid_ani = strdup(l->cid_num); - } - } + ast_set_callerid(c, + l->hidecallerid ? "" : l->cid_num, + l->hidecallerid ? "" : l->cid_name, + c->cid.cid_ani ? NULL : l->cid_num); ast_setstate(c, AST_STATE_RING); res = ast_pbx_run(c); if (res) { @@ -3422,12 +3415,10 @@ static int handle_soft_key_event_message(skinny_req *req, struct skinnysession * if (ast_exists_extension(c, c->context, l->lastnumberdialed, 1, l->cid_num)) { if (!ast_matchmore_extension(c, c->context, l->lastnumberdialed, 1, l->cid_num)) { ast_copy_string(c->exten, l->lastnumberdialed, sizeof(c->exten)); - if (!ast_strlen_zero(l->cid_num)) { - if (!l->hidecallerid) { - c->cid.cid_num = strdup(l->cid_num); - c->cid.cid_ani = strdup(l->cid_num); - } - } + ast_set_callerid(c, + l->hidecallerid ? "" : l->cid_num, + l->hidecallerid ? "" : l->cid_name, + c->cid.cid_ani ? NULL : l->cid_num); ast_setstate(c, AST_STATE_RING); res = ast_pbx_run(c); if (res) { diff --git a/channels/chan_vpb.c b/channels/chan_vpb.c index 836150219..d615e606a 100644 --- a/channels/chan_vpb.c +++ b/channels/chan_vpb.c @@ -804,18 +804,14 @@ static void get_callerid_ast(struct vpb_pvt *p) } if (number) ast_shrink_phone_number(number); - if (!ast_strlen_zero(number)) { - owner->cid.cid_num = strdup(number); - owner->cid.cid_ani = strdup(number); - if (!ast_strlen_zero(name)){ - owner->cid.cid_name = strdup(name); - snprintf(p->callerid,(sizeof(p->callerid)-1),"%s %s",number,name); - } - else { - snprintf(p->callerid,(sizeof(p->callerid)-1),"%s",number); - } + ast_set_callerid(owner, + number, name, + owner->cid.cid_ani ? NULL : number); + if (!ast_strlen_zero(name)){ + snprintf(p->callerid,(sizeof(p->callerid)-1),"%s %s",number,name); + } else { + snprintf(p->callerid,(sizeof(p->callerid)-1),"%s",number); } - if (cs) callerid_free(cs); } |