[asterisk-commits] rmudgett: trunk r399022 - in /trunk: ./ main/bridge.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 12 18:42:24 CDT 2013


Author: rmudgett
Date: Thu Sep 12 18:42:23 2013
New Revision: 399022

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=399022
Log:
CLI bridge: Fix "bridge destroy <id>" and "bridge kick <id> <chan>" tab completion.

These two commands must deal with the live bridges container for tab
completion and not the stasis cache.
........

Merged revisions 399021 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/main/bridge.c

Propchange: trunk/
------------------------------------------------------------------------------
--- branch-12-merged (original)
+++ branch-12-merged Thu Sep 12 18:42:23 2013
@@ -1,1 +1,1 @@
-/branches/12:1-398558,398560-398577,398579-398927,398938,398991,399017,399019
+/branches/12:1-398558,398560-398577,398579-398927,398938,398991,399017,399019,399021

Modified: trunk/main/bridge.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/bridge.c?view=diff&rev=399022&r1=399021&r2=399022
==============================================================================
--- trunk/main/bridge.c (original)
+++ trunk/main/bridge.c Thu Sep 12 18:42:23 2013
@@ -4467,7 +4467,42 @@
 	return cmp;
 }
 
-static char *complete_bridge(const char *word, int state)
+struct bridge_complete {
+	/*! Nth match to return. */
+	int state;
+	/*! Which match currently on. */
+	int which;
+};
+
+static int complete_bridge_live_search(void *obj, void *arg, void *data, int flags)
+{
+	struct bridge_complete *search = data;
+
+	if (++search->which > search->state) {
+		return CMP_MATCH;
+	}
+	return 0;
+}
+
+static char *complete_bridge_live(const char *word, int state)
+{
+	char *ret;
+	struct ast_bridge *bridge;
+	struct bridge_complete search = {
+		.state = state,
+		};
+
+	bridge = ao2_callback_data(bridges, ast_strlen_zero(word) ? 0 : OBJ_PARTIAL_KEY,
+		complete_bridge_live_search, (char *) word, &search);
+	if (!bridge) {
+		return NULL;
+	}
+	ret = ast_strdup(bridge->uniqueid);
+	ao2_ref(bridge, -1);
+	return ret;
+}
+
+static char *complete_bridge_stasis(const char *word, int state)
 {
 	char *ret = NULL;
 	int wordlen = strlen(word), which = 0;
@@ -4475,7 +4510,8 @@
 	struct ao2_iterator iter;
 	struct stasis_message *msg;
 
-	if (!(cached_bridges = stasis_cache_dump(ast_bridge_cache(), ast_bridge_snapshot_type()))) {
+	cached_bridges = stasis_cache_dump(ast_bridge_cache(), ast_bridge_snapshot_type());
+	if (!cached_bridges) {
 		return NULL;
 	}
 
@@ -4513,7 +4549,8 @@
 		return NULL;
 	}
 
-	if (!(cached_bridges = stasis_cache_dump(ast_bridge_cache(), ast_bridge_snapshot_type()))) {
+	cached_bridges = stasis_cache_dump(ast_bridge_cache(), ast_bridge_snapshot_type());
+	if (!cached_bridges) {
 		ast_cli(a->fd, "Failed to retrieve cached bridges\n");
 		return CLI_SUCCESS;
 	}
@@ -4545,7 +4582,8 @@
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 	struct ast_channel_snapshot *snapshot;
 
-	if (!(msg = stasis_cache_get(ast_channel_cache(), ast_channel_snapshot_type(), uniqueid))) {
+	msg = stasis_cache_get(ast_channel_cache(), ast_channel_snapshot_type(), uniqueid);
+	if (!msg) {
 		return 0;
 	}
 	snapshot = stasis_message_data(msg);
@@ -4569,7 +4607,7 @@
 		return NULL;
 	case CLI_GENERATE:
 		if (a->pos == 2) {
-			return complete_bridge(a->word, a->n);
+			return complete_bridge_stasis(a->word, a->n);
 		}
 		return NULL;
 	}
@@ -4607,7 +4645,7 @@
 		return NULL;
 	case CLI_GENERATE:
 		if (a->pos == 2) {
-			return complete_bridge(a->word, a->n);
+			return complete_bridge_live(a->word, a->n);
 		}
 		return NULL;
 	}
@@ -4670,7 +4708,7 @@
 		return NULL;
 	case CLI_GENERATE:
 		if (a->pos == 2) {
-			return complete_bridge(a->word, a->n);
+			return complete_bridge_live(a->word, a->n);
 		}
 		if (a->pos == 3) {
 			return complete_bridge_participant(a->argv[2], a->line, a->word, a->pos, a->n);




More information about the asterisk-commits mailing list