[asterisk-commits] seanbright: trunk r154923 - in /trunk: apps/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 5 16:19:22 CST 2008


Author: seanbright
Date: Wed Nov  5 16:19:22 2008
New Revision: 154923

URL: http://svn.digium.com/view/asterisk?view=rev&rev=154923
Log:
Update a couple places to use the new ast_channel_search_locked API call.

Modified:
    trunk/apps/app_directed_pickup.c
    trunk/main/features.c

Modified: trunk/apps/app_directed_pickup.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_directed_pickup.c?view=diff&rev=154923&r1=154922&r2=154923
==============================================================================
--- trunk/apps/app_directed_pickup.c (original)
+++ trunk/apps/app_directed_pickup.c Wed Nov  5 16:19:22 2008
@@ -172,42 +172,46 @@
 /* Attempt to pick up specified extension with context */
 static int pickup_by_exten(struct ast_channel *chan, const char *exten, const char *context)
 {
-	int res = -1;
-	struct ast_channel *target = NULL;
-
-	while ((target = ast_channel_walk_locked(target))) {
-		if ((!strcasecmp(target->macroexten, exten) || !strcasecmp(target->exten, exten)) &&
-			!strcasecmp(target->dialcontext, context) &&
-			can_pickup(target)) {
-			res = pickup_do(chan, target);
-			ast_channel_unlock(target);
-			break;
-		}
+	auto int find_by_exten(struct ast_channel *c);
+	int find_by_exten(struct ast_channel *c) {
+		return (!strcasecmp(c->macroexten, exten) || !strcasecmp(c->exten, exten)) &&
+			!strcasecmp(c->dialcontext, context) &&
+			can_pickup(c);
+	}
+
+	struct ast_channel *target = ast_channel_search_locked(find_by_exten);
+
+	if (target) {
+		int res = pickup_do(chan, target);
 		ast_channel_unlock(target);
-	}
-
-	return res;
+		target = NULL;
+		return res;
+	}
+
+	return -1;
 }
 
 /* Attempt to pick up specified mark */
 static int pickup_by_mark(struct ast_channel *chan, const char *mark)
 {
-	int res = -1;
-	const char *tmp = NULL;
-	struct ast_channel *target = NULL;
-
-	while ((target = ast_channel_walk_locked(target))) {
-		if ((tmp = pbx_builtin_getvar_helper(target, PICKUPMARK)) &&
-			!strcasecmp(tmp, mark) &&
-			can_pickup(target)) {
-			res = pickup_do(chan, target);
-			ast_channel_unlock(target);
-			break;
-		}
+	auto int find_by_mark(struct ast_channel *);
+	int find_by_mark(struct ast_channel *c) {
+		const char *tmp;
+		return (tmp = pbx_builtin_getvar_helper(c, PICKUPMARK)) &&
+            !strcasecmp(tmp, mark) &&
+            can_pickup(c);
+	}	
+
+	struct ast_channel *target = ast_channel_search_locked(find_by_mark);
+
+	if (target) {
+		int res = pickup_do(chan, target);
 		ast_channel_unlock(target);
-	}
-
-	return res;
+		target = NULL;
+		return res;
+	}
+
+	return -1;
 }
 
 /* application entry point for Pickup() */

Modified: trunk/main/features.c
URL: http://svn.digium.com/view/asterisk/trunk/main/features.c?view=diff&rev=154923&r1=154922&r2=154923
==============================================================================
--- trunk/main/features.c (original)
+++ trunk/main/features.c Wed Nov  5 16:19:22 2008
@@ -3997,20 +3997,18 @@
 */
 int ast_pickup_call(struct ast_channel *chan)
 {
-	struct ast_channel *cur = NULL;
-	int res = -1;
-
-	while ((cur = ast_channel_walk_locked(cur)) != NULL) {
-		if (!cur->pbx && 
-			(cur != chan) &&
-			(chan->pickupgroup & cur->callgroup) &&
-			((cur->_state == AST_STATE_RINGING) ||
-			 (cur->_state == AST_STATE_RING))) {
-			 	break;
-		}
-		ast_channel_unlock(cur);
-	}
+	auto int find_channel_by_group(struct ast_channel *);
+	int find_channel_by_group(struct ast_channel *c) {
+		return !c->pbx &&
+			(c != chan) &&
+			(chan->pickupgroup & c->callgroup) &&
+			((c->_state == AST_STATE_RINGING) ||
+			 (c->_state == AST_STATE_RING));
+	}
+	struct ast_channel *cur = ast_channel_search_locked(find_channel_by_group);
+
 	if (cur) {
+		int res = -1;
 		ast_debug(1, "Call pickup on chan '%s' by '%s'\n",cur->name, chan->name);
 		res = ast_answer(chan);
 		if (res)
@@ -4022,10 +4020,11 @@
 		if (res)
 			ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, cur->name);		/* Done */
 		ast_channel_unlock(cur);
+		return res;
 	} else	{
 		ast_debug(1, "No call pickup possible...\n");
 	}
-	return res;
+	return -1;
 }
 
 static char *app_bridge = "Bridge";




More information about the asterisk-commits mailing list