aboutsummaryrefslogtreecommitdiffstats
path: root/pbx
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-06-14 21:43:16 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-06-14 21:43:16 +0000
commit197f42b07ba4ec83db727d16f23a0aa96c4c891b (patch)
tree199ff03b4d6f2a008f96eccb1ed8018496e70539 /pbx
parent0b45dbb5bb9b01efa5f5d913755b6b6391064ee6 (diff)
Allow escaping of commas as well as ability to use quotes (bug #1826)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3209 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'pbx')
-rwxr-xr-xpbx/pbx_config.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/pbx/pbx_config.c b/pbx/pbx_config.c
index 0c0cbd1b6..47a4c9638 100755
--- a/pbx/pbx_config.c
+++ b/pbx/pbx_config.c
@@ -98,6 +98,36 @@ static char reload_extensions_help[] =
"Example: extensions reload\n";
/*
+ * Static code
+ */
+static char* process_quotes_and_slashes( char* start, char find, char replace_with )
+{
+ char* dataPut = start;
+ int inEscape = 0;
+ int inQuotes = 0;
+ for( ; *start; start++ ) {
+ if( inEscape ) {
+ *dataPut++ = *start; /* Always goes verbatim */
+ inEscape = 0;
+ }
+ else {
+ if( *start == '\\' ) {
+ inEscape = 1; /* Do not copy \ into the data */
+ }
+ else if( *start == '\"' ) {
+ inQuotes = 1-inQuotes; /* Do not copy " into the data */
+ }
+ else {
+ /* Replace , with |, unless in quotes */
+ *dataPut++ = inQuotes ? *start : ((*start==find) ? replace_with : *start);
+ }
+ }
+ }
+ *dataPut = 0;
+ return dataPut;
+}
+
+/*
* Implementation of functions provided by this module
*/
@@ -1144,9 +1174,7 @@ static int handle_context_add_extension(int fd, int argc, char *argv[])
if (app && (start = strchr(app, '(')) && (end = strrchr(app, ')'))) {
*start = *end = '\0';
app_data = start + 1;
- for (start = app_data; *start; start++)
- if (*start == ',')
- *start = '|';
+ process_quotes_and_slashes(app_data,',','|');
} else
app_data = whole_exten;
@@ -1615,9 +1643,7 @@ static int pbx_load_module(void)
if (start && (end = strrchr(appl, ')'))) {
*start = *end = '\0';
data = start + 1;
- for (start = data; *start; start++)
- if (*start == ',')
- *start = '|';
+ process_quotes_and_slashes(data,',','|');
} else if (stringp!=NULL && *stringp=='"') {
stringp++;
data = strsep(&stringp, "\"");