[asterisk-commits] russell: trunk r211390 - /trunk/main/channel.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Aug 10 10:46:43 CDT 2009


Author: russell
Date: Mon Aug 10 10:46:39 2009
New Revision: 211390

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=211390
Log:
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.

Modified:
    trunk/main/channel.c

Modified: trunk/main/channel.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/main/channel.c?view=diff&rev=211390&r1=211389&r2=211390
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Mon Aug 10 10:46:39 2009
@@ -1377,6 +1377,7 @@
 		 * 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 @@
 		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 @@
 				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);




More information about the asterisk-commits mailing list