res_pjsip: Fix CLI tab completion issues
This fixes several issues with the new res_pjsip CLI tab completion such as output of headers during tab completion and being able to tab-complete more items than the code actually handled (further items would simply be ignored). (closes issue ASTERISK-23081) Review: https://reviewboard.asterisk.org/r/3115/ Reported by: xrobau ........ Merged revisions 405338 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@405339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
8585340b87
commit
f1497fe220
1 changed files with 30 additions and 26 deletions
|
@ -132,7 +132,6 @@ static char *cli_traverse_objects(struct ast_cli_entry *e, int cmd,
|
||||||
const char *object_id = NULL;
|
const char *object_id = NULL;
|
||||||
char formatter_type[64];
|
char formatter_type[64];
|
||||||
struct ast_sip_cli_formatter_entry *formatter_entry;
|
struct ast_sip_cli_formatter_entry *formatter_entry;
|
||||||
int is_plural = 0;
|
|
||||||
|
|
||||||
struct ast_sip_cli_context context = {
|
struct ast_sip_cli_context context = {
|
||||||
.peers_mon_online = 0,
|
.peers_mon_online = 0,
|
||||||
|
@ -141,6 +140,9 @@ static char *cli_traverse_objects(struct ast_cli_entry *e, int cmd,
|
||||||
.peers_unmon_offline = 0,
|
.peers_unmon_offline = 0,
|
||||||
.a = a,
|
.a = a,
|
||||||
.indent_level = 0,
|
.indent_level = 0,
|
||||||
|
.show_details = 0,
|
||||||
|
.show_details_only_level_0 = 0,
|
||||||
|
.recurse = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (cmd == CLI_INIT) {
|
if (cmd == CLI_INIT) {
|
||||||
|
@ -153,35 +155,35 @@ static char *cli_traverse_objects(struct ast_cli_entry *e, int cmd,
|
||||||
|
|
||||||
if (!ast_ends_with(cmd2, "s")) {
|
if (!ast_ends_with(cmd2, "s")) {
|
||||||
ast_copy_string(formatter_type, cmd2, strlen(cmd2)+1);
|
ast_copy_string(formatter_type, cmd2, strlen(cmd2)+1);
|
||||||
is_plural = 0;
|
is_container = 0;
|
||||||
} else {
|
} else {
|
||||||
ast_copy_string(formatter_type, cmd2, strlen(cmd2));
|
ast_copy_string(formatter_type, cmd2, strlen(cmd2));
|
||||||
is_plural = 1;
|
is_container = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(cmd1, "show")) {
|
if (!strcmp(cmd1, "show")) {
|
||||||
if (is_plural) {
|
context.show_details_only_level_0 = !is_container;
|
||||||
context.recurse = 1;
|
context.recurse = 1;
|
||||||
context.show_details = 0;
|
|
||||||
context.show_details_only_level_0 = 0;
|
|
||||||
is_container = 1;
|
|
||||||
} else {
|
} else {
|
||||||
context.recurse = 1;
|
|
||||||
context.show_details = 0;
|
|
||||||
context.show_details_only_level_0 = 1;
|
|
||||||
is_container = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
context.recurse = 0;
|
|
||||||
context.show_details = 0;
|
|
||||||
context.show_details_only_level_0 = 0;
|
|
||||||
is_container = 1;
|
is_container = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cmd == CLI_GENERATE
|
||||||
|
&& (is_container
|
||||||
|
|| a->argc > 4
|
||||||
|
|| (a->argc == 4 && ast_strlen_zero(a->word)))) {
|
||||||
|
return CLI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
context.output_buffer = ast_str_create(256);
|
context.output_buffer = ast_str_create(256);
|
||||||
|
if (!context.output_buffer) {
|
||||||
|
return CLI_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
formatter_entry = ast_sip_lookup_cli_formatter(formatter_type);
|
formatter_entry = ast_sip_lookup_cli_formatter(formatter_type);
|
||||||
if (!formatter_entry) {
|
if (!formatter_entry) {
|
||||||
ast_log(LOG_ERROR, "CLI TRAVERSE failure. No container found for object type %s\n", formatter_type);
|
ast_log(LOG_ERROR, "CLI TRAVERSE failure. No container found for object type %s\n", formatter_type);
|
||||||
|
ast_free(context.output_buffer);
|
||||||
return CLI_FAILURE;
|
return CLI_FAILURE;
|
||||||
}
|
}
|
||||||
ast_str_append(&context.output_buffer, 0, "\n");
|
ast_str_append(&context.output_buffer, 0, "\n");
|
||||||
|
@ -192,11 +194,13 @@ static char *cli_traverse_objects(struct ast_cli_entry *e, int cmd,
|
||||||
container = formatter_entry->get_container(sip_sorcery);
|
container = formatter_entry->get_container(sip_sorcery);
|
||||||
if (!container) {
|
if (!container) {
|
||||||
ast_cli(a->fd, "CLI TRAVERSE failure. No container found for object type %s\n", formatter_type);
|
ast_cli(a->fd, "CLI TRAVERSE failure. No container found for object type %s\n", formatter_type);
|
||||||
|
ast_free(context.output_buffer);
|
||||||
return CLI_FAILURE;
|
return CLI_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_container && cmd == CLI_GENERATE) {
|
if (cmd == CLI_GENERATE) {
|
||||||
|
ast_free(context.output_buffer);
|
||||||
return complete_show_sorcery_object(container, a->word, a->n);
|
return complete_show_sorcery_object(container, a->word, a->n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue