mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-01 18:09:41 +00:00
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. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@399021 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -4467,7 +4467,42 @@ static int bridge_sort_cmp(const void *obj_left, const void *obj_right, int flag
|
|||||||
return cmp;
|
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;
|
char *ret = NULL;
|
||||||
int wordlen = strlen(word), which = 0;
|
int wordlen = strlen(word), which = 0;
|
||||||
@@ -4475,7 +4510,8 @@ static char *complete_bridge(const char *word, int state)
|
|||||||
struct ao2_iterator iter;
|
struct ao2_iterator iter;
|
||||||
struct stasis_message *msg;
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4513,7 +4549,8 @@ static char *handle_bridge_show_all(struct ast_cli_entry *e, int cmd, struct ast
|
|||||||
return NULL;
|
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");
|
ast_cli(a->fd, "Failed to retrieve cached bridges\n");
|
||||||
return CLI_SUCCESS;
|
return CLI_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -4545,7 +4582,8 @@ static int bridge_show_specific_print_channel(void *obj, void *arg, int flags)
|
|||||||
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
|
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
|
||||||
struct ast_channel_snapshot *snapshot;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
snapshot = stasis_message_data(msg);
|
snapshot = stasis_message_data(msg);
|
||||||
@@ -4569,7 +4607,7 @@ static char *handle_bridge_show_specific(struct ast_cli_entry *e, int cmd, struc
|
|||||||
return NULL;
|
return NULL;
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
if (a->pos == 2) {
|
if (a->pos == 2) {
|
||||||
return complete_bridge(a->word, a->n);
|
return complete_bridge_stasis(a->word, a->n);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -4607,7 +4645,7 @@ static char *handle_bridge_destroy_specific(struct ast_cli_entry *e, int cmd, st
|
|||||||
return NULL;
|
return NULL;
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
if (a->pos == 2) {
|
if (a->pos == 2) {
|
||||||
return complete_bridge(a->word, a->n);
|
return complete_bridge_live(a->word, a->n);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -4670,7 +4708,7 @@ static char *handle_bridge_kick_channel(struct ast_cli_entry *e, int cmd, struct
|
|||||||
return NULL;
|
return NULL;
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
if (a->pos == 2) {
|
if (a->pos == 2) {
|
||||||
return complete_bridge(a->word, a->n);
|
return complete_bridge_live(a->word, a->n);
|
||||||
}
|
}
|
||||||
if (a->pos == 3) {
|
if (a->pos == 3) {
|
||||||
return complete_bridge_participant(a->argv[2], a->line, a->word, a->pos, a->n);
|
return complete_bridge_participant(a->argv[2], a->line, a->word, a->pos, a->n);
|
||||||
|
Reference in New Issue
Block a user