mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 11:42:27 +00:00
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:
28
asterisk.c
28
asterisk.c
@@ -985,6 +985,8 @@ static char **ast_el_strtoarr(char *buf)
|
|||||||
match_list_len = 1;
|
match_list_len = 1;
|
||||||
while ( (retstr = strsep(&buf, " ")) != NULL) {
|
while ( (retstr = strsep(&buf, " ")) != NULL) {
|
||||||
|
|
||||||
|
if (!strcmp(retstr, AST_CLI_COMPLETE_EOF))
|
||||||
|
break;
|
||||||
if (matches + 1 >= match_list_len) {
|
if (matches + 1 >= match_list_len) {
|
||||||
match_list_len <<= 1;
|
match_list_len <<= 1;
|
||||||
match_list = realloc(match_list, match_list_len * sizeof(char *));
|
match_list = realloc(match_list, match_list_len * sizeof(char *));
|
||||||
@@ -1091,12 +1093,32 @@ static char *cli_complete(EditLine *el, int ch)
|
|||||||
nummatches = atoi(buf);
|
nummatches = atoi(buf);
|
||||||
|
|
||||||
if (nummatches > 0) {
|
if (nummatches > 0) {
|
||||||
|
char *mbuf;
|
||||||
|
int mlen = 0, maxmbuf = 2048;
|
||||||
|
/* Start with a 2048 byte buffer */
|
||||||
|
mbuf = malloc(maxmbuf);
|
||||||
|
if (!mbuf)
|
||||||
|
return (CC_ERROR);
|
||||||
snprintf(buf, sizeof(buf),"_COMMAND MATCHESARRAY \"%s\" \"%s\"", lf->buffer, ptr);
|
snprintf(buf, sizeof(buf),"_COMMAND MATCHESARRAY \"%s\" \"%s\"", lf->buffer, ptr);
|
||||||
fdprint(ast_consock, buf);
|
fdprint(ast_consock, buf);
|
||||||
res = read(ast_consock, buf, sizeof(buf));
|
res = 0;
|
||||||
buf[res] = '\0';
|
while (!strstr(mbuf, AST_CLI_COMPLETE_EOF) && res != -1) {
|
||||||
|
if (mlen + 1024 > maxmbuf) {
|
||||||
|
/* Every step increment buffer 1024 bytes */
|
||||||
|
maxmbuf += 1024;
|
||||||
|
mbuf = realloc(mbuf, maxmbuf);
|
||||||
|
if (!mbuf)
|
||||||
|
return (CC_ERROR);
|
||||||
|
}
|
||||||
|
/* Only read 1024 bytes at a time */
|
||||||
|
res = read(ast_consock, mbuf + mlen, 1024);
|
||||||
|
if (res > 0)
|
||||||
|
mlen += res;
|
||||||
|
}
|
||||||
|
mbuf[mlen] = '\0';
|
||||||
|
|
||||||
matches = ast_el_strtoarr(buf);
|
matches = ast_el_strtoarr(mbuf);
|
||||||
|
free(mbuf);
|
||||||
} else
|
} else
|
||||||
matches = (char **) NULL;
|
matches = (char **) NULL;
|
||||||
|
|
||||||
|
13
cli.c
13
cli.c
@@ -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[])
|
static int handle_commandmatchesarray(int fd, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char buf[2048];
|
char *buf;
|
||||||
|
int buflen = 2048;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
char **matches;
|
char **matches;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
if (argc != 4)
|
if (argc != 4)
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
|
buf = malloc(buflen);
|
||||||
|
if (!buf)
|
||||||
|
return RESULT_FAILURE;
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
matches = ast_cli_completion_matches(argv[2], argv[3]);
|
matches = ast_cli_completion_matches(argv[2], argv[3]);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
@@ -366,6 +370,10 @@ static int handle_commandmatchesarray(int fd, int argc, char *argv[])
|
|||||||
#if 0
|
#if 0
|
||||||
printf("command matchesarray for '%s' %s got '%s'\n", argv[2], argv[3], matches[x]);
|
printf("command matchesarray for '%s' %s got '%s'\n", argv[2], argv[3], matches[x]);
|
||||||
#endif
|
#endif
|
||||||
|
if (len + strlen(matches[x]) >= buflen) {
|
||||||
|
buflen += strlen(matches[x]) * 3;
|
||||||
|
buf = realloc(buf, buflen);
|
||||||
|
}
|
||||||
len += sprintf( buf + len, "%s ", matches[x]);
|
len += sprintf( buf + len, "%s ", matches[x]);
|
||||||
free(matches[x]);
|
free(matches[x]);
|
||||||
matches[x] = NULL;
|
matches[x] = NULL;
|
||||||
@@ -377,7 +385,8 @@ static int handle_commandmatchesarray(int fd, int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (buf) {
|
if (buf) {
|
||||||
ast_cli(fd, buf);
|
ast_cli(fd, "%s%s",buf, AST_CLI_COMPLETE_EOF);
|
||||||
|
free(buf);
|
||||||
} else
|
} else
|
||||||
ast_cli(fd, "NULL\n");
|
ast_cli(fd, "NULL\n");
|
||||||
|
|
||||||
|
@@ -31,6 +31,8 @@ extern void ast_cli(int fd, char *fmt, ...)
|
|||||||
|
|
||||||
#define AST_MAX_ARGS 64
|
#define AST_MAX_ARGS 64
|
||||||
|
|
||||||
|
#define AST_CLI_COMPLETE_EOF "_EOF_"
|
||||||
|
|
||||||
//! A command line entry */
|
//! A command line entry */
|
||||||
struct ast_cli_entry {
|
struct ast_cli_entry {
|
||||||
/*! Null terminated list of the words of the command */
|
/*! Null terminated list of the words of the command */
|
||||||
|
Reference in New Issue
Block a user