diff options
author | Richard Mudgett <rmudgett@digium.com> | 2013-05-01 21:35:53 +0000 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2013-05-01 21:35:53 +0000 |
commit | e4db1903a29d8f17ee92b09e69432facf227aef4 (patch) | |
tree | a9b7d5c28f9765692b9cf5e76fc77de8ea69320e /channels | |
parent | f054420df24dfd0a80359620fdd60be0a0578046 (diff) |
Cleanup chan_local.c:local_new().
* Remove t and ama local variables. There is no way they could be
anything other than default because p->owner can only be NULL at this
point.
* Rename tmp and tmp2 to owner and chan respectively.
* Remove redundant initialization of channel context, exten, priority.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387260 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_local.c | 91 |
1 files changed, 40 insertions, 51 deletions
diff --git a/channels/chan_local.c b/channels/chan_local.c index 3fef79248..5918ed188 100644 --- a/channels/chan_local.c +++ b/channels/chan_local.c @@ -1216,75 +1216,64 @@ static struct local_pvt *local_alloc(const char *data, struct ast_format_cap *ca /*! \brief Start new local channel */ static struct ast_channel *local_new(struct local_pvt *p, int state, const char *linkedid, struct ast_callid *callid) { - struct ast_channel *tmp = NULL, *tmp2 = NULL; + struct ast_channel *owner; + struct ast_channel *chan; struct ast_format fmt; int generated_seqno = ast_atomic_fetchadd_int((int *)&name_sequence, +1); - const char *t; - int ama; - - /* Allocate two new Asterisk channels */ - /* safe accountcode */ - if (p->owner && ast_channel_accountcode(p->owner)) - t = ast_channel_accountcode(p->owner); - else - t = ""; - - if (p->owner) - ama = ast_channel_amaflags(p->owner); - else - ama = 0; - - /* Make sure that the ;2 channel gets the same linkedid as ;1. You can't pass linkedid to both - * allocations since if linkedid isn't set, then each channel will generate its own linkedid. */ - if (!(tmp = ast_channel_alloc(1, state, 0, 0, t, p->exten, p->context, linkedid, ama, "Local/%s@%s-%08x;1", p->exten, p->context, generated_seqno)) - || !(tmp2 = ast_channel_alloc(1, AST_STATE_RING, 0, 0, t, p->exten, p->context, ast_channel_linkedid(tmp), ama, "Local/%s@%s-%08x;2", p->exten, p->context, generated_seqno))) { - if (tmp) { - tmp = ast_channel_release(tmp); + + /* + * Allocate two new Asterisk channels + * + * Make sure that the ;2 channel gets the same linkedid as ;1. + * You can't pass linkedid to both allocations since if linkedid + * isn't set, then each channel will generate its own linkedid. + */ + if (!(owner = ast_channel_alloc(1, state, NULL, NULL, NULL, + p->exten, p->context, linkedid, 0, + "Local/%s@%s-%08x;1", p->exten, p->context, generated_seqno)) + || !(chan = ast_channel_alloc(1, AST_STATE_RING, NULL, NULL, NULL, + p->exten, p->context, ast_channel_linkedid(owner), 0, + "Local/%s@%s-%08x;2", p->exten, p->context, generated_seqno))) { + if (owner) { + owner = ast_channel_release(owner); } ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n"); return NULL; } if (callid) { - ast_channel_callid_set(tmp, callid); - ast_channel_callid_set(tmp2, callid); + ast_channel_callid_set(owner, callid); + ast_channel_callid_set(chan, callid); } - ast_channel_tech_set(tmp, &local_tech); - ast_channel_tech_set(tmp2, &local_tech); + ast_channel_tech_set(owner, &local_tech); + ast_channel_tech_set(chan, &local_tech); + ast_channel_tech_pvt_set(owner, p); + ast_channel_tech_pvt_set(chan, p); - ast_format_cap_copy(ast_channel_nativeformats(tmp), p->reqcap); - ast_format_cap_copy(ast_channel_nativeformats(tmp2), p->reqcap); + ast_format_cap_copy(ast_channel_nativeformats(owner), p->reqcap); + ast_format_cap_copy(ast_channel_nativeformats(chan), p->reqcap); /* Determine our read/write format and set it on each channel */ ast_best_codec(p->reqcap, &fmt); - ast_format_copy(ast_channel_writeformat(tmp), &fmt); - ast_format_copy(ast_channel_writeformat(tmp2), &fmt); - ast_format_copy(ast_channel_rawwriteformat(tmp), &fmt); - ast_format_copy(ast_channel_rawwriteformat(tmp2), &fmt); - ast_format_copy(ast_channel_readformat(tmp), &fmt); - ast_format_copy(ast_channel_readformat(tmp2), &fmt); - ast_format_copy(ast_channel_rawreadformat(tmp), &fmt); - ast_format_copy(ast_channel_rawreadformat(tmp2), &fmt); - - ast_channel_tech_pvt_set(tmp, p); - ast_channel_tech_pvt_set(tmp2, p); - - ast_set_flag(ast_channel_flags(tmp), AST_FLAG_DISABLE_DEVSTATE_CACHE); - ast_set_flag(ast_channel_flags(tmp2), AST_FLAG_DISABLE_DEVSTATE_CACHE); + ast_format_copy(ast_channel_writeformat(owner), &fmt); + ast_format_copy(ast_channel_writeformat(chan), &fmt); + ast_format_copy(ast_channel_rawwriteformat(owner), &fmt); + ast_format_copy(ast_channel_rawwriteformat(chan), &fmt); + ast_format_copy(ast_channel_readformat(owner), &fmt); + ast_format_copy(ast_channel_readformat(chan), &fmt); + ast_format_copy(ast_channel_rawreadformat(owner), &fmt); + ast_format_copy(ast_channel_rawreadformat(chan), &fmt); - p->owner = tmp; - p->chan = tmp2; + ast_set_flag(ast_channel_flags(owner), AST_FLAG_DISABLE_DEVSTATE_CACHE); + ast_set_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE); - ast_channel_context_set(tmp, p->context); - ast_channel_context_set(tmp2, p->context); - ast_channel_exten_set(tmp2, p->exten); - ast_channel_priority_set(tmp, 1); - ast_channel_priority_set(tmp2, 1); + p->owner = owner; + p->chan = chan; - ast_jb_configure(tmp, &p->jb_conf); + ast_jb_configure(owner, &p->jb_conf); - return tmp; + return owner; } /*! \brief Part of PBX interface */ |