diff options
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_iax2.c | 26 | ||||
-rw-r--r-- | channels/chan_motif.c | 3 | ||||
-rw-r--r-- | channels/chan_pjsip.c | 10 | ||||
-rw-r--r-- | channels/chan_sip.c | 19 |
4 files changed, 38 insertions, 20 deletions
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 424f5add7..59f794454 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -5879,12 +5879,14 @@ static int iax2_getpeertrunk(struct ast_sockaddr addr) /*! \brief Create new call, interface with the PBX core */ static struct ast_channel *ast_iax2_new(int callno, int state, iax2_format capability, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, unsigned int cachable) { - struct ast_channel *tmp; + struct ast_channel *tmp = NULL; struct chan_iax2_pvt *i; + struct iax2_peer *peer; struct ast_variable *v = NULL; struct ast_format_cap *native; struct ast_format *tmpfmt; struct ast_callid *callid; + char *peer_name = NULL; if (!(i = iaxs[callno])) { ast_log(LOG_WARNING, "No IAX2 pvt found for callno '%d' !\n", callno); @@ -5896,9 +5898,27 @@ static struct ast_channel *ast_iax2_new(int callno, int state, iax2_format capab return NULL; } - /* Don't hold call lock */ + if (!ast_strlen_zero(i->peer)) { + peer_name = ast_strdupa(i->peer); + } else if (!ast_strlen_zero(i->host)) { + peer_name = ast_strdupa(i->host); + } + + /* Don't hold call lock while making a channel or looking up a peer */ ast_mutex_unlock(&iaxsl[callno]); - tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, assignedids, requestor, i->amaflags, "IAX2/%s-%d", i->host, i->callno); + + if (!ast_strlen_zero(peer_name)) { + peer = find_peer(peer_name, 1); + if (peer && peer->endpoint) { + tmp = ast_channel_alloc_with_endpoint(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, assignedids, requestor, i->amaflags, peer->endpoint, "IAX2/%s-%d", i->host, i->callno); + } + ao2_cleanup(peer); + } + + if (!tmp) { + tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, assignedids, requestor, i->amaflags, "IAX2/%s-%d", i->host, i->callno); + } + ast_mutex_lock(&iaxsl[callno]); if (i != iaxs[callno]) { if (tmp) { diff --git a/channels/chan_motif.c b/channels/chan_motif.c index 1bdc8aa6b..e29485206 100644 --- a/channels/chan_motif.c +++ b/channels/chan_motif.c @@ -75,6 +75,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/causes.h" #include "asterisk/abstract_jb.h" #include "asterisk/xmpp.h" +#include "asterisk/endpoints.h" #include "asterisk/stasis_channels.h" #include "asterisk/format_cache.h" @@ -783,7 +784,7 @@ static struct ast_channel *jingle_new(struct jingle_endpoint *endpoint, struct j return NULL; } - if (!(chan = ast_channel_alloc(1, state, S_OR(title, ""), S_OR(cid_name, ""), "", "", "", assignedids, requestor, 0, "Motif/%s-%04lx", str, (unsigned long)(ast_random() & 0xffff)))) { + if (!(chan = ast_channel_alloc_with_endpoint(1, state, S_OR(title, ""), S_OR(cid_name, ""), "", "", "", assignedids, requestor, 0, endpoint->connection->endpoint, "Motif/%s-%04lx", str, (unsigned long)(ast_random() & 0xffff)))) { ao2_ref(caps, -1); return NULL; } diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c index 5812360c5..f638a1e35 100644 --- a/channels/chan_pjsip.c +++ b/channels/chan_pjsip.c @@ -371,8 +371,12 @@ static struct ast_channel *chan_pjsip_new(struct ast_sip_session *session, int s return NULL; } - if (!(chan = ast_channel_alloc(1, state, S_OR(session->id.number.str, ""), S_OR(session->id.name.str, ""), session->endpoint->accountcode, "", "", assignedids, requestor, 0, "PJSIP/%s-%08x", ast_sorcery_object_get_id(session->endpoint), - (unsigned)ast_atomic_fetchadd_int((int *)&chan_idx, +1)))) { + chan = ast_channel_alloc_with_endpoint(1, state, S_OR(session->id.number.str, ""), + S_OR(session->id.name.str, ""), session->endpoint->accountcode, "", + "", assignedids, requestor, 0, session->endpoint->persistent, + "PJSIP/%s-%08x", ast_sorcery_object_get_id(session->endpoint), + (unsigned)ast_atomic_fetchadd_int((int *)&chan_idx, +1)); + if (!chan) { ao2_ref(caps, -1); return NULL; } @@ -455,8 +459,6 @@ static struct ast_channel *chan_pjsip_new(struct ast_sip_session *session, int s ast_rtp_instance_set_channel_id(pvt->media[SIP_MEDIA_VIDEO]->rtp, ast_channel_uniqueid(chan)); } - ast_endpoint_add_channel(session->endpoint->persistent, chan); - return chan; } diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 44629dc3d..2a32971dc 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -8071,9 +8071,14 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit my_name = ast_strdupa(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, i->accountcode, i->exten, i->context, assignedids, requestor, i->amaflags, "SIP/%s-%08x", my_name, (unsigned)ast_atomic_fetchadd_int((int *)&chan_idx, +1)); + sip_pvt_unlock(i); + + if (i->relatedpeer && i->relatedpeer->endpoint) { + tmp = ast_channel_alloc_with_endpoint(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, assignedids, requestor, i->amaflags, i->relatedpeer->endpoint, "SIP/%s-%08x", my_name, (unsigned)ast_atomic_fetchadd_int((int *)&chan_idx, +1)); + } else { + tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, assignedids, requestor, i->amaflags, "SIP/%s-%08x", my_name, (unsigned)ast_atomic_fetchadd_int((int *)&chan_idx, +1)); + } } if (!tmp) { ast_log(LOG_WARNING, "Unable to allocate AST channel structure for SIP channel\n"); @@ -8082,16 +8087,6 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit return NULL; } - if (i->relatedpeer && i->relatedpeer->endpoint) { - if (ast_endpoint_add_channel(i->relatedpeer->endpoint, tmp)) { - ast_channel_unlock(tmp); - ast_channel_unref(tmp); - ao2_ref(caps, -1); - sip_pvt_lock(i); - return NULL; - } - } - ast_channel_stage_snapshot(tmp); /* If we sent in a callid, bind it to the channel. */ |