[asterisk-commits] kmoore: branch 12 r405338 - /branches/12/res/res_pjsip/pjsip_cli.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jan 13 07:29:01 CST 2014
Author: kmoore
Date: Mon Jan 13 07:28:55 2014
New Revision: 405338
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=405338
Log:
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
Modified:
branches/12/res/res_pjsip/pjsip_cli.c
Modified: branches/12/res/res_pjsip/pjsip_cli.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip/pjsip_cli.c?view=diff&rev=405338&r1=405337&r2=405338
==============================================================================
--- branches/12/res/res_pjsip/pjsip_cli.c (original)
+++ branches/12/res/res_pjsip/pjsip_cli.c Mon Jan 13 07:28:55 2014
@@ -132,7 +132,6 @@
const char *object_id = NULL;
char formatter_type[64];
struct ast_sip_cli_formatter_entry *formatter_entry;
- int is_plural = 0;
struct ast_sip_cli_context context = {
.peers_mon_online = 0,
@@ -141,6 +140,9 @@
.peers_unmon_offline = 0,
.a = a,
.indent_level = 0,
+ .show_details = 0,
+ .show_details_only_level_0 = 0,
+ .recurse = 0,
};
if (cmd == CLI_INIT) {
@@ -153,35 +155,35 @@
if (!ast_ends_with(cmd2, "s")) {
ast_copy_string(formatter_type, cmd2, strlen(cmd2)+1);
- is_plural = 0;
+ is_container = 0;
} else {
ast_copy_string(formatter_type, cmd2, strlen(cmd2));
- is_plural = 1;
+ is_container = 1;
}
if (!strcmp(cmd1, "show")) {
- if (is_plural) {
- context.recurse = 1;
- context.show_details = 0;
- context.show_details_only_level_0 = 0;
- is_container = 1;
- } else {
- context.recurse = 1;
- context.show_details = 0;
- context.show_details_only_level_0 = 1;
- is_container = 0;
- }
+ context.show_details_only_level_0 = !is_container;
+ context.recurse = 1;
} else {
- context.recurse = 0;
- context.show_details = 0;
- context.show_details_only_level_0 = 0;
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);
+ if (!context.output_buffer) {
+ return CLI_FAILURE;
+ }
+
formatter_entry = ast_sip_lookup_cli_formatter(formatter_type);
if (!formatter_entry) {
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;
}
ast_str_append(&context.output_buffer, 0, "\n");
@@ -192,11 +194,13 @@
container = formatter_entry->get_container(sip_sorcery);
if (!container) {
ast_cli(a->fd, "CLI TRAVERSE failure. No container found for object type %s\n", formatter_type);
- return CLI_FAILURE ;
- }
- }
-
- if (!is_container && cmd == CLI_GENERATE) {
+ ast_free(context.output_buffer);
+ return CLI_FAILURE;
+ }
+ }
+
+ if (cmd == CLI_GENERATE) {
+ ast_free(context.output_buffer);
return complete_show_sorcery_object(container, a->word, a->n);
}
@@ -204,7 +208,7 @@
if (!ao2_container_count(container)) {
dump_str_and_free(a->fd, context.output_buffer);
ast_cli(a->fd, "No objects found.\n\n");
- return CLI_SUCCESS ;
+ return CLI_SUCCESS;
}
if (!strcmp(formatter_type, "channel") || !strcmp(formatter_type, "contact")) {
@@ -221,14 +225,14 @@
ast_sip_get_sorcery(), formatter_type, object_id))) {
dump_str_and_free(a->fd, context.output_buffer);
ast_cli(a->fd, "Unable to retrieve object %s\n", object_id);
- return CLI_FAILURE ;
+ return CLI_FAILURE;
}
formatter_entry->print_body(object, &context, 0);
}
ast_str_append(&context.output_buffer, 0, "\n");
dump_str_and_free(a->fd, context.output_buffer);
- return CLI_SUCCESS ;
+ return CLI_SUCCESS;
}
static struct ast_cli_entry cli_commands[] = {
More information about the asterisk-commits
mailing list