[Asterisk-cvs] asterisk app.c,1.70,1.71

markster markster
Sat Aug 6 12:49:05 CDT 2005


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

Modified Files:
	app.c 
Log Message:
Properly handle | within ()'s when doing app arg parsing... (bug #4911)


Index: app.c
===================================================================
RCS file: /usr/cvsroot/asterisk/app.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- app.c	15 Jul 2005 23:00:46 -0000	1.70
+++ app.c	6 Aug 2005 16:52:56 -0000	1.71
@@ -1066,9 +1066,9 @@
 
 int ast_separate_app_args(char *buf, char delim, char **array, int arraylen)
 {
-	int x;
+	int argc;
 	char *scan;
-	char delims[2];
+	int paren = 0;
 
 	if (!buf || !array || !arraylen)
 		return 0;
@@ -1076,21 +1076,26 @@
 	memset(array, 0, arraylen * sizeof(*array));
 
 	scan = buf;
-	delims[0] = delim;
-	delims[1] = '\0';
-	x = 0;
 
-	while (x < arraylen - 1) {
-		array[x] = strsep(&scan, delims);
-		x++;
-		if (!scan)
-			break;
+	for (argc = 0; *scan && (argc < arraylen - 1); argc++) {
+		array[argc] = scan;
+		for (; *scan; scan++) {
+			if (*scan == '(')
+				paren++;
+			else if (*scan == ')') {
+				if (paren)
+					paren--;
+			} else if ((*scan == delim) && !paren) {
+				*scan++ = '\0';
+				break;
+			}
+		}
 	}
 
-	if (scan)
-		array[x++] = scan;
+	if (*scan)
+		array[argc++] = scan;
 
-	return x;
+	return argc;
 }
 
 enum AST_LOCK_RESULT ast_lock_path(const char *path)




More information about the svn-commits mailing list