aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-08-10 15:46:39 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-08-10 15:46:39 +0000
commit4b2e61e8eeafee64f1c97703a1b18d3db8d4d6fa (patch)
tree9b15ecb40b5f646a2456af30a572531db27ba6f9 /main
parent818953e1c7855c6986de2079c9be2eb0789eee4c (diff)
Fix up some issues with getting a channel by "name".
Even though the get_channel_by_name() API advertised that you could search by name or uniqueid (just as the old API did), searching by uniqueid was not actually implemented. This patch fixes that problem. The ast_channel_get_full() function now makes a second search attempt by uniqueid if the parameter was a name. The channel comparison function also now knows how to compare by unqieueid. Finally, a bug was fixed in passing where OBJ_POINTER was being passed in some scenarios where it should not have been. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@211390 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/channel.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/main/channel.c b/main/channel.c
index a86ec3b34..f4f5d9013 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -1377,6 +1377,7 @@ static struct ast_channel *ast_channel_get_full(const char *name, size_t name_le
* gets changed, then the compare callback must be changed, too. */
.rings = name_len,
};
+ struct ast_channel *chan;
if (exten) {
ast_copy_string(tmp_chan.exten, exten, sizeof(tmp_chan.exten));
@@ -1386,7 +1387,25 @@ static struct ast_channel *ast_channel_get_full(const char *name, size_t name_le
ast_copy_string(tmp_chan.context, context, sizeof(tmp_chan.context));
}
- return ao2_find(channels, &tmp_chan, OBJ_POINTER);
+ if ((chan = ao2_find(channels, &tmp_chan, !ast_strlen_zero(name) ? OBJ_POINTER : 0))) {
+ return chan;
+ }
+
+ if (!name) {
+ return NULL;
+ }
+
+ /* If name was specified, but the result was NULL,
+ * try a search on uniqueid, instead. */
+
+ {
+ struct ast_channel tmp_chan2 = {
+ .uniqueid = name,
+ .rings = name_len,
+ };
+
+ return ao2_find(channels, &tmp_chan2, 0);
+ }
}
struct ast_channel *ast_channel_get_by_name(const char *name)
@@ -6228,6 +6247,11 @@ static int ast_channel_cmp_cb(void *obj, void *arg, int flags)
strcasecmp(chan->macroexten, cmp_args->exten)) {
ret = 0; /* exten match failed */
}
+ } else if (cmp_args->uniqueid) {
+ if ((!name_len && strcasecmp(chan->uniqueid, cmp_args->uniqueid)) ||
+ (name_len && strncasecmp(chan->uniqueid, cmp_args->uniqueid, name_len))) {
+ ret = 0; /* uniqueid match failed */
+ }
}
ast_channel_unlock(chan);