Remove size restiction on remote console command completion (bug 1360)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2634 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
James Golovich
2004-04-06 07:42:01 +00:00
parent 852422f4ab
commit 8cfed866d3
3 changed files with 38 additions and 5 deletions

13
cli.c
View File

@@ -352,13 +352,17 @@ static char *__ast_cli_generator(char *text, char *word, int state, int lock);
static int handle_commandmatchesarray(int fd, int argc, char *argv[])
{
char buf[2048];
char *buf;
int buflen = 2048;
int len = 0;
char **matches;
int x;
if (argc != 4)
return RESULT_SHOWUSAGE;
buf = malloc(buflen);
if (!buf)
return RESULT_FAILURE;
buf[len] = '\0';
matches = ast_cli_completion_matches(argv[2], argv[3]);
if (matches) {
@@ -366,6 +370,10 @@ static int handle_commandmatchesarray(int fd, int argc, char *argv[])
#if 0
printf("command matchesarray for '%s' %s got '%s'\n", argv[2], argv[3], matches[x]);
#endif
if (len + strlen(matches[x]) >= buflen) {
buflen += strlen(matches[x]) * 3;
buf = realloc(buf, buflen);
}
len += sprintf( buf + len, "%s ", matches[x]);
free(matches[x]);
matches[x] = NULL;
@@ -377,7 +385,8 @@ static int handle_commandmatchesarray(int fd, int argc, char *argv[])
#endif
if (buf) {
ast_cli(fd, buf);
ast_cli(fd, "%s%s",buf, AST_CLI_COMPLETE_EOF);
free(buf);
} else
ast_cli(fd, "NULL\n");