[Asterisk-cvs] asterisk asterisk.c,1.51.2.10,1.51.2.11 cli.c,1.30.2.4,1.30.2.5

citats at lists.digium.com citats at lists.digium.com
Tue Apr 6 03:42:03 CDT 2004


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv24725

Modified Files:
      Tag: v1-0_stable
	asterisk.c cli.c 
Log Message:
Remove size restiction on remote console command completion (bug 1360)



Index: asterisk.c
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.c,v
retrieving revision 1.51.2.10
retrieving revision 1.51.2.11
diff -u -d -r1.51.2.10 -r1.51.2.11
--- asterisk.c	29 Mar 2004 04:12:27 -0000	1.51.2.10
+++ asterisk.c	6 Apr 2004 07:42:19 -0000	1.51.2.11
@@ -861,6 +861,8 @@
         match_list_len = 1;
 	while ( (retstr = strsep(&buf, " ")) != NULL) {
 
+		if (!strcmp(retstr, AST_CLI_COMPLETE_EOF))
+			break;
                 if (matches + 1 >= match_list_len) {
                         match_list_len <<= 1;
                         match_list = realloc(match_list, match_list_len * sizeof(char *));
@@ -967,12 +969,32 @@
 		nummatches = atoi(buf);
 
 		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); 
 			fdprint(ast_consock, buf);
-			res = read(ast_consock, buf, sizeof(buf));
-			buf[res] = '\0';
+			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
 			matches = (char **) NULL;
 

Index: cli.c
===================================================================
RCS file: /usr/cvsroot/asterisk/cli.c,v
retrieving revision 1.30.2.4
retrieving revision 1.30.2.5
diff -u -d -r1.30.2.4 -r1.30.2.5
--- cli.c	14 Mar 2004 09:12:13 -0000	1.30.2.4
+++ cli.c	6 Apr 2004 07:42:19 -0000	1.30.2.5
@@ -352,13 +352,17 @@
 
 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 @@
 #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 @@
 #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");
 




More information about the svn-commits mailing list