[asterisk-commits] russell: branch russell/chan_refcount r82303 - /team/russell/chan_refcount/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 12 17:54:20 CDT 2007


Author: russell
Date: Wed Sep 12 17:54:20 2007
New Revision: 82303

URL: http://svn.digium.com/view/asterisk?view=rev&rev=82303
Log:
create the channels container and add the hash and compare callbacks

Modified:
    team/russell/chan_refcount/main/channel.c

Modified: team/russell/chan_refcount/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/main/channel.c?view=diff&rev=82303&r1=82302&r2=82303
==============================================================================
--- team/russell/chan_refcount/main/channel.c (original)
+++ team/russell/chan_refcount/main/channel.c Wed Sep 12 17:54:20 2007
@@ -4613,8 +4613,50 @@
 		ast_moh_cleanup_ptr(chan);
 }
 
+static int ast_channel_hash_cb(const void *obj, const int flags)
+{
+	const struct ast_channel *chan = obj;
+
+	/* If the name isn't set, return 0 so that the ao2_find() search will
+	 * start in the first bucket. */
+	if (ast_strlen_zero(chan->name))
+		return 0;
+
+	return ast_str_hash(chan->name);
+}
+
+static int ast_channel_cmp_cb(void *obj, void *arg, int flags)
+{
+	struct ast_channel *chan = obj, *cmp_args = arg;
+	size_t name_len;
+	int ret = CMP_MATCH;
+
+	/* This is sort of a hack.  Basically, we're using an arbitrary field
+	 * in ast_channel to pass the name_len for a prefix match.  If this
+	 * gets changed, then the uses of ao2_find() must be changed, too. */
+	name_len = cmp_args->rings;
+
+	if (cmp_args->name) { /* match by name */
+		if ((!name_len && strcasecmp(chan->name, cmp_args->name)) ||
+			(name_len && strncasecmp(chan->name, cmp_args->name, name_len)))
+			ret = 0; /* name match failed */
+	} else if (cmp_args->exten) {
+		if (cmp_args->context && strcasecmp(chan->context, cmp_args->context) &&
+			strcasecmp(chan->macrocontext, cmp_args->context))
+			ret = 0; /* context match failed */
+		if (ret && strcasecmp(chan->exten, cmp_args->exten) &&
+			strcasecmp(chan->macroexten, cmp_args->exten))
+			ret = 0; /* exten match failed */
+	}
+
+	return ret;
+}
+
 void ast_channels_init(void)
 {
+	channels = ao2_container_alloc(MAX_CHANNEL_BUCKETS,
+		ast_channel_hash_cb, ast_channel_cmp_cb);
+
 	ast_cli_register_multiple(cli_channel, sizeof(cli_channel) / sizeof(struct ast_cli_entry));
 }
 




More information about the asterisk-commits mailing list