mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-11 04:18:21 +00:00
main/bridge: Use ast_cli_completion_add.
Change-Id: I3775a696d6a57139fdf09651ecb786bcf1774509
This commit is contained in:
102
main/bridge.c
102
main/bridge.c
@@ -4962,46 +4962,29 @@ struct ast_bridge *ast_bridge_find_by_id(const char *bridge_id)
|
|||||||
return ao2_find(bridges, bridge_id, OBJ_SEARCH_KEY);
|
return ao2_find(bridges, bridge_id, OBJ_SEARCH_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bridge_complete {
|
static int complete_bridge_live_search(void *obj, void *arg, int flags)
|
||||||
/*! 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;
|
struct ast_bridge *bridge = obj;
|
||||||
|
|
||||||
if (++search->which > search->state) {
|
if (ast_cli_completion_add(ast_strdup(bridge->uniqueid))) {
|
||||||
return CMP_MATCH;
|
return CMP_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *complete_bridge_live(const char *word, int state)
|
static char *complete_bridge_live(const char *word)
|
||||||
{
|
{
|
||||||
char *ret;
|
ao2_callback(bridges, ast_strlen_zero(word) ? 0 : OBJ_PARTIAL_KEY,
|
||||||
struct ast_bridge *bridge;
|
complete_bridge_live_search, (char *) word);
|
||||||
struct bridge_complete search = {
|
|
||||||
.state = state,
|
|
||||||
};
|
|
||||||
|
|
||||||
bridge = ao2_callback_data(bridges, ast_strlen_zero(word) ? 0 : OBJ_PARTIAL_KEY,
|
return NULL;
|
||||||
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)
|
static char *complete_bridge_stasis(const char *word)
|
||||||
{
|
{
|
||||||
char *ret = NULL;
|
int wordlen = strlen(word);
|
||||||
int wordlen = strlen(word), which = 0;
|
struct ao2_container *cached_bridges;
|
||||||
RAII_VAR(struct ao2_container *, cached_bridges, NULL, ao2_cleanup);
|
|
||||||
struct ao2_iterator iter;
|
struct ao2_iterator iter;
|
||||||
struct stasis_message *msg;
|
struct stasis_message *msg;
|
||||||
|
|
||||||
@@ -5014,15 +4997,17 @@ static char *complete_bridge_stasis(const char *word, int state)
|
|||||||
for (; (msg = ao2_iterator_next(&iter)); ao2_ref(msg, -1)) {
|
for (; (msg = ao2_iterator_next(&iter)); ao2_ref(msg, -1)) {
|
||||||
struct ast_bridge_snapshot *snapshot = stasis_message_data(msg);
|
struct ast_bridge_snapshot *snapshot = stasis_message_data(msg);
|
||||||
|
|
||||||
if (!strncasecmp(word, snapshot->uniqueid, wordlen) && (++which > state)) {
|
if (!strncasecmp(word, snapshot->uniqueid, wordlen)) {
|
||||||
ret = ast_strdup(snapshot->uniqueid);
|
if (ast_cli_completion_add(ast_strdup(snapshot->uniqueid))) {
|
||||||
ao2_ref(msg, -1);
|
ao2_ref(msg, -1);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ao2_iterator_destroy(&iter);
|
ao2_iterator_destroy(&iter);
|
||||||
|
ao2_ref(cached_bridges, -1);
|
||||||
|
|
||||||
return ret;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *handle_bridge_show_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
static char *handle_bridge_show_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||||
@@ -5103,7 +5088,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_stasis(a->word, a->n);
|
return complete_bridge_stasis(a->word);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -5142,7 +5127,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_live(a->word, a->n);
|
return complete_bridge_live(a->word);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -5164,11 +5149,10 @@ static char *handle_bridge_destroy_specific(struct ast_cli_entry *e, int cmd, st
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char *complete_bridge_participant(const char *bridge_name, const char *line, const char *word, int pos, int state)
|
static char *complete_bridge_participant(const char *bridge_name, const char *word)
|
||||||
{
|
{
|
||||||
struct ast_bridge *bridge;
|
struct ast_bridge *bridge;
|
||||||
struct ast_bridge_channel *bridge_channel;
|
struct ast_bridge_channel *bridge_channel;
|
||||||
int which;
|
|
||||||
int wordlen;
|
int wordlen;
|
||||||
|
|
||||||
bridge = ast_bridge_find_by_id(bridge_name);
|
bridge = ast_bridge_find_by_id(bridge_name);
|
||||||
@@ -5176,19 +5160,17 @@ static char *complete_bridge_participant(const char *bridge_name, const char *li
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
wordlen = strlen(word);
|
||||||
SCOPED_LOCK(bridge_lock, bridge, ast_bridge_lock, ast_bridge_unlock);
|
|
||||||
|
|
||||||
which = 0;
|
ast_bridge_lock(bridge);
|
||||||
wordlen = strlen(word);
|
AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
|
||||||
AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
|
if (!strncasecmp(ast_channel_name(bridge_channel->chan), word, wordlen)) {
|
||||||
if (!strncasecmp(ast_channel_name(bridge_channel->chan), word, wordlen)
|
if (ast_cli_completion_add(ast_strdup(ast_channel_name(bridge_channel->chan)))) {
|
||||||
&& ++which > state) {
|
break;
|
||||||
ao2_ref(bridge, -1);
|
|
||||||
return ast_strdup(ast_channel_name(bridge_channel->chan));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ast_bridge_unlock(bridge);
|
||||||
|
|
||||||
ao2_ref(bridge, -1);
|
ao2_ref(bridge, -1);
|
||||||
|
|
||||||
@@ -5198,7 +5180,6 @@ static char *complete_bridge_participant(const char *bridge_name, const char *li
|
|||||||
static char *handle_bridge_kick_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
static char *handle_bridge_kick_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||||
{
|
{
|
||||||
static const char * const completions[] = { "all", NULL };
|
static const char * const completions[] = { "all", NULL };
|
||||||
char *complete;
|
|
||||||
struct ast_bridge *bridge;
|
struct ast_bridge *bridge;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
@@ -5212,14 +5193,11 @@ 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_live(a->word, a->n);
|
return complete_bridge_live(a->word);
|
||||||
}
|
}
|
||||||
if (a->pos == 3) {
|
if (a->pos == 3) {
|
||||||
complete = ast_cli_complete(a->word, completions, a->n);
|
ast_cli_complete(a->word, completions, -1);
|
||||||
if (!complete) {
|
return complete_bridge_participant(a->argv[2], a->word);
|
||||||
complete = complete_bridge_participant(a->argv[2], a->line, a->word, a->pos, a->n - 1);
|
|
||||||
}
|
|
||||||
return complete;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -5320,24 +5298,22 @@ static char *handle_bridge_technology_show(struct ast_cli_entry *e, int cmd, str
|
|||||||
#undef FORMAT
|
#undef FORMAT
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *complete_bridge_technology(const char *word, int state)
|
static char *complete_bridge_technology(const char *word)
|
||||||
{
|
{
|
||||||
struct ast_bridge_technology *cur;
|
struct ast_bridge_technology *cur;
|
||||||
char *res;
|
|
||||||
int which;
|
|
||||||
int wordlen;
|
int wordlen;
|
||||||
|
|
||||||
which = 0;
|
|
||||||
wordlen = strlen(word);
|
wordlen = strlen(word);
|
||||||
AST_RWLIST_RDLOCK(&bridge_technologies);
|
AST_RWLIST_RDLOCK(&bridge_technologies);
|
||||||
AST_RWLIST_TRAVERSE(&bridge_technologies, cur, entry) {
|
AST_RWLIST_TRAVERSE(&bridge_technologies, cur, entry) {
|
||||||
if (!strncasecmp(cur->name, word, wordlen) && ++which > state) {
|
if (!strncasecmp(cur->name, word, wordlen)) {
|
||||||
res = ast_strdup(cur->name);
|
if (ast_cli_completion_add(ast_strdup(cur->name))) {
|
||||||
AST_RWLIST_UNLOCK(&bridge_technologies);
|
break;
|
||||||
return res;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AST_RWLIST_UNLOCK(&bridge_technologies);
|
AST_RWLIST_UNLOCK(&bridge_technologies);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5356,7 +5332,7 @@ static char *handle_bridge_technology_suspend(struct ast_cli_entry *e, int cmd,
|
|||||||
return NULL;
|
return NULL;
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
if (a->pos == 3) {
|
if (a->pos == 3) {
|
||||||
return complete_bridge_technology(a->word, a->n);
|
return complete_bridge_technology(a->word);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user