summaryrefslogtreecommitdiff
path: root/channels
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2013-05-01 21:55:53 +0000
committerRichard Mudgett <rmudgett@digium.com>2013-05-01 21:55:53 +0000
commiteea6df46d514d518bdfdfc4143aa8476a052d2fa (patch)
tree44d8c2c3a9a525c6a4f5960bc388d9915b208a4f /channels
parente4db1903a29d8f17ee92b09e69432facf227aef4 (diff)
Simplify chan_local.c:manager_optimize_away() using ao2_find().
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387261 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_local.c35
1 files changed, 12 insertions, 23 deletions
diff --git a/channels/chan_local.c b/channels/chan_local.c
index 5918ed188..be4586fc8 100644
--- a/channels/chan_local.c
+++ b/channels/chan_local.c
@@ -1354,10 +1354,9 @@ static struct ast_cli_entry cli_local[] = {
static int manager_optimize_away(struct mansession *s, const struct message *m)
{
const char *channel;
- struct local_pvt *p, *tmp = NULL;
- struct ast_channel *c;
- int found = 0;
- struct ao2_iterator it;
+ struct local_pvt *p;
+ struct local_pvt *found;
+ struct ast_channel *chan;
channel = astman_get_header(m, "Channel");
if (ast_strlen_zero(channel)) {
@@ -1365,31 +1364,21 @@ static int manager_optimize_away(struct mansession *s, const struct message *m)
return 0;
}
- c = ast_channel_get_by_name(channel);
- if (!c) {
+ chan = ast_channel_get_by_name(channel);
+ if (!chan) {
astman_send_error(s, m, "Channel does not exist.");
return 0;
}
- p = ast_channel_tech_pvt(c);
- ast_channel_unref(c);
- c = NULL;
-
- it = ao2_iterator_init(locals, 0);
- while ((tmp = ao2_iterator_next(&it))) {
- if (tmp == p) {
- ao2_lock(tmp);
- found = 1;
- ast_clear_flag(tmp, LOCAL_NO_OPTIMIZATION);
- ao2_unlock(tmp);
- ao2_ref(tmp, -1);
- break;
- }
- ao2_ref(tmp, -1);
- }
- ao2_iterator_destroy(&it);
+ p = ast_channel_tech_pvt(chan);
+ ast_channel_unref(chan);
+ found = p ? ao2_find(locals, p, 0) : NULL;
if (found) {
+ ao2_lock(found);
+ ast_clear_flag(found, LOCAL_NO_OPTIMIZATION);
+ ao2_unlock(found);
+ ao2_ref(found, -1);
astman_send_ack(s, m, "Queued channel to be optimized away");
} else {
astman_send_error(s, m, "Unable to find channel");