From: Alan T. DeKok Date: Tue, 3 Sep 2019 21:57:52 +0000 (-0400) Subject: allow trailing space for tab completion X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47adba8deaba2485d4c1806bf8df962aef99ba15;p=thirdparty%2Ffreeradius-server.git allow trailing space for tab completion --- diff --git a/src/modules/proto_control/proto_control_unix.c b/src/modules/proto_control/proto_control_unix.c index ae65cf9ea47..a31b44325ef 100644 --- a/src/modules/proto_control/proto_control_unix.c +++ b/src/modules/proto_control/proto_control_unix.c @@ -197,6 +197,8 @@ static ssize_t mod_read_command(fr_listen_t *li, UNUSED void **packet_ctx, UNUSE start = (string[0] << 8) | string[1]; thread->misc_conduit = FR_CONDUIT_COMPLETE; + + fprintf(stderr, "COMPLETE %d %d %s\n", hdr->length - 2, start, string + 2); fr_radmin_complete(thread->misc, string + 2, start); thread->misc_conduit = FR_CONDUIT_STDOUT; status = FR_CONDUIT_SUCCESS; diff --git a/src/modules/proto_control/radmin.c b/src/modules/proto_control/radmin.c index 7fdd384dba9..6fafd1edacd 100644 --- a/src/modules/proto_control/radmin.c +++ b/src/modules/proto_control/radmin.c @@ -501,6 +501,14 @@ static ssize_t cmd_copy(char const *cmd) if (stack_depth > 0) *(p++) = ' '; + /* + * No input, allow a trailing space so that tab + * completion works. + */ + if (!*cmd) { + return p - cmd_buffer; + } + len = strlcpy(p, cmd, cmd_buffer + sizeof(cmd_buffer) - p); if ((p + len) >= (cmd_buffer + sizeof(cmd_buffer))) { fprintf(stderr, "Command too long\n"); @@ -578,16 +586,16 @@ radmin_completion(const char *text, int start, UNUSED int end) radmin_num_expansions = 0; - start += stack[stack_depth] - cmd_buffer; + len = cmd_copy(rl_line_buffer); + if (len < 0) return NULL; + + start += len; if (start > 65535) return NULL; io_buffer[0] = (start >> 8) & 0xff; io_buffer[1] = start & 0xff; - len = cmd_copy(rl_line_buffer); - if (len < 0) return NULL; - /* * Note that "text" is the PARTIAL thing we're trying to complete. * And "start" is the OFFSET from rl_line_buffer where we want to