[svn-commits] tilghman: branch 1.4 r257544 - in /branches/1.4: include/asterisk/ main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Apr 15 16:23:29 CDT 2010


Author: tilghman
Date: Thu Apr 15 16:23:24 2010
New Revision: 257544

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=257544
Log:
Allow application options with arguments to contain parentheses, through a variety of escaping techniques.

Fixes SWP-1194 (ABE-2143).

Review: https://reviewboard.asterisk.org/r/604/

Modified:
    branches/1.4/include/asterisk/app.h
    branches/1.4/main/app.c

Modified: branches/1.4/include/asterisk/app.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/include/asterisk/app.h?view=diff&rev=257544&r1=257543&r2=257544
==============================================================================
--- branches/1.4/include/asterisk/app.h (original)
+++ branches/1.4/include/asterisk/app.h Thu Apr 15 16:23:24 2010
@@ -370,7 +370,7 @@
 
   	... do any argument parsing here ...
 
-	if (ast_parseoptions(my_app_options, &opts, opt_args, options)) {
+	if (ast_app_parse_options(my_app_options, &opts, opt_args, options)) {
 		LOCAL_USER_REMOVE(u);
 		return -1;
 	}

Modified: branches/1.4/main/app.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/main/app.c?view=diff&rev=257544&r1=257543&r2=257544
==============================================================================
--- branches/1.4/main/app.c (original)
+++ branches/1.4/main/app.c Thu Apr 15 16:23:24 2010
@@ -1438,8 +1438,40 @@
 		curarg = *s++ & 0x7f;	/* the array (in app.h) has 128 entries */
 		argloc = options[curarg].arg_index;
 		if (*s == '(') {
+			int paren = 1, quote = 0;
+			int parsequotes = (s[1] == '"') ? 1 : 0;
+
 			/* Has argument */
 			arg = ++s;
+			for (; *s; s++) {
+				if (*s == '(' && !quote) {
+					paren++;
+				} else if (*s == ')' && !quote) {
+					/* Count parentheses, unless they're within quotes (or backslashed, below) */
+					paren--;
+				} else if (*s == '"' && parsequotes) {
+					/* Leave embedded quotes alone, unless they are the first character */
+					quote = quote ? 0 : 1;
+					ast_copy_string(s, s + 1, INT_MAX);
+					s--;
+				} else if (*s == '\\') {
+					if (!quote) {
+						/* If a backslash is found outside of quotes, remove it */
+						ast_copy_string(s, s + 1, INT_MAX);
+					} else if (quote && s[1] == '"') {
+						/* Backslash for a quote character within quotes, remove the backslash */
+						ast_copy_string(s, s + 1, INT_MAX);
+					} else {
+						/* Backslash within quotes, keep both characters */
+						s++;
+					}
+				}
+
+				if (paren == 0) {
+					break;
+				}
+			}
+			/* This will find the closing paren we found above, or none, if the string ended before we found one. */
 			if ((s = strchr(s, ')'))) {
 				if (argloc)
 					args[argloc - 1] = arg;




More information about the svn-commits mailing list