[Asterisk-cvs] asterisk channel.c,1.241,1.242
kpfleming
kpfleming
Thu Sep 15 12:36:16 CDT 2005
Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv12593
Modified Files:
channel.c
Log Message:
add API for searching active channels by context/exten
Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.241
retrieving revision 1.242
diff -u -d -r1.241 -r1.242
--- channel.c 14 Sep 2005 20:46:49 -0000 1.241
+++ channel.c 15 Sep 2005 16:34:39 -0000 1.242
@@ -660,8 +660,15 @@
}
/*
- * Helper function to return the channel after prev, or the one matching name,
- * with the channel's lock held. If getting the individual lock fails,
+ * Helper function to find channels. It supports these modes:
+ *
+ * prev != NULL : get channel next in list after prev
+ * name != NULL : get channel with matching name
+ * name != NULL && namelen != 0 : get channel whose name starts with prefix
+ * exten != NULL : get channel whose exten or macroexten matches
+ * context != NULL && exten != NULL : get channel whose context or macrocontext
+ *
+ * It returns with the channel's lock held. If getting the individual lock fails,
* unlock and retry quickly up to 10 times, then give up.
*
* XXX Note that this code has cost O(N) because of the need to verify
@@ -675,7 +682,8 @@
* We should definitely go for a better scheme that is deadlock-free.
*/
static struct ast_channel *channel_find_locked(const struct ast_channel *prev,
- const char *name, const int namelen)
+ const char *name, const int namelen,
+ const char *context, const char *exten)
{
const char *msg = prev ? "deadlock" : "initial deadlock";
int retries, done;
@@ -684,20 +692,33 @@
for (retries = 0; retries < 10; retries++) {
ast_mutex_lock(&chlock);
for (c = channels; c; c = c->next) {
- if (prev == NULL) {
+ if (!prev) {
/* want head of list */
- if (!name)
+ if (!name && !exten)
break;
- /* want match by full name */
- if (!namelen) {
- if (!strcasecmp(c->name, name))
+ if (name) {
+ /* want match by full name */
+ if (!namelen) {
+ if (!strcasecmp(c->name, name))
+ break;
+ else
+ continue;
+ }
+ /* want match by name prefix */
+ if (!strncasecmp(c->name, name, namelen))
break;
- else
+ } else if (exten) {
+ /* want match by context and exten */
+ if (context && (strcasecmp(c->context, context) &&
+ strcasecmp(c->macrocontext, context)))
continue;
+ /* match by exten */
+ if (strcasecmp(c->exten, exten) &&
+ strcasecmp(c->macroexten, exten))
+ continue;
+ else
+ break;
}
- /* want match by name prefix */
- if (!strncasecmp(c->name, name, namelen))
- break;
} else if (c == prev) { /* found, return c->next */
c = c->next;
break;
@@ -726,19 +747,25 @@
/*--- ast_channel_walk_locked: Browse channels in use */
struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev)
{
- return channel_find_locked(prev, NULL, 0);
+ return channel_find_locked(prev, NULL, 0, NULL, NULL);
}
/*--- ast_get_channel_by_name_locked: Get channel by name and lock it */
struct ast_channel *ast_get_channel_by_name_locked(const char *name)
{
- return channel_find_locked(NULL, name, 0);
+ return channel_find_locked(NULL, name, 0, NULL, NULL);
}
/*--- ast_get_channel_by_name_prefix_locked: Get channel by name prefix and lock it */
struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen)
{
- return channel_find_locked(NULL, name, namelen);
+ return channel_find_locked(NULL, name, namelen, NULL, NULL);
+}
+
+/*--- ast_get_channel_by_exten_locked: Get channel by exten (and optionally context) and lock it */
+struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context)
+{
+ return channel_find_locked(NULL, NULL, 0, context, exten);
}
/*--- ast_safe_sleep_conditional: Wait, look for hangups and condition arg */
More information about the svn-commits
mailing list