[Asterisk-code-review] app_queue.c: Don't escape commas in MONITOR_FILENAME. (asterisk[19])
Sean Bright
asteriskteam at digium.com
Mon Sep 19 09:16:27 CDT 2022
Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19302 )
Change subject: app_queue.c: Don't escape commas in MONITOR_FILENAME.
......................................................................
app_queue.c: Don't escape commas in MONITOR_FILENAME.
The contents of the MONITOR_FILENAME variable is evaluated when a
queue member is connected to a caller, allowing information about the
member to be included in the filename.
This is made possible by using ^{MEMBERINTERFACE} syntax instead of
${MEMBERINTERFACE} when assigning a value to MONITOR_FILENAME so that
evaluation does not occur immediately. The MONITOR_EXEC variable is
handled similarly.
Because of the way that MONITOR_EXEC works under the hood, the code
that performs the variable replacement also escapes commas before
doing so. However, this replacement should be taking place after the
variable replacement is done so that unescaped commas are not
erroneously passed to the MixMonitor start function.
Finally, having a comma in a filename is not problematic so we now
only escape commas after variable replacement is performed on
MONITOR_EXEC.
The main consequence of this change is that you can now use dialplan
functions with multiple arguments in MONITOR_FILENAME without the
commas being escaped before variable replacement occurs.
ASTERISK-30236 #close
Change-Id: Ib18481288c5292e27321e95364d7e63e8917252f
---
M apps/app_queue.c
A doc/CHANGES-staging/app_queue_monitor_filename_commas.txt
2 files changed, 58 insertions(+), 6 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/02/19302/1
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 288c0ff..f58667d 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -6820,8 +6820,13 @@
}
}
+enum escape_type {
+ MONITOR_FILENAME,
+ MONITOR_EXEC,
+};
+
static void escape_and_substitute(struct ast_channel *chan, const char *input,
- char *output, size_t size)
+ char *output, size_t size, enum escape_type type)
{
const char *m = input;
char escaped[size];
@@ -6834,9 +6839,6 @@
*p = '$';
}
break;
- case ',':
- *p++ = '\\';
- /* Fall through */
default:
*p = *m;
}
@@ -6849,6 +6851,15 @@
}
pbx_substitute_variables_helper(chan, escaped, output, size - 1);
+
+ if (type == MONITOR_EXEC) {
+ /* Commas are only significant to MONITOR_EXEC because of the way that we
+ handle argument passing in ast_mixmonitor_start(). The
+ MONITOR_FILENAME does not have the same limitation so we do not need
+ commas escaped there. */
+ ast_escape(escaped, output, size, ",");
+ ast_copy_string(output, escaped, size);
+ }
}
static void setup_mixmonitor(struct queue_ent *qe, const char *filename)
@@ -6863,7 +6874,8 @@
escaped_monitor_exec[0] = '\0';
if (filename) {
- escape_and_substitute(qe->chan, filename, escaped_filename, sizeof(escaped_filename));
+ escape_and_substitute(qe->chan, filename,
+ escaped_filename, sizeof(escaped_filename), MONITOR_FILENAME);
} else {
ast_copy_string(escaped_filename, ast_channel_uniqueid(qe->chan), sizeof(escaped_filename));
}
@@ -6880,7 +6892,8 @@
ast_channel_unlock(qe->chan);
if (monitor_exec) {
- escape_and_substitute(qe->chan, monitor_exec, escaped_monitor_exec, sizeof(escaped_monitor_exec));
+ escape_and_substitute(qe->chan, monitor_exec,
+ escaped_monitor_exec, sizeof(escaped_monitor_exec), MONITOR_EXEC);
}
snprintf(file_with_ext, sizeof(file_with_ext), "%s.%s", escaped_filename, qe->parent->monfmt);
diff --git a/doc/CHANGES-staging/app_queue_monitor_filename_commas.txt b/doc/CHANGES-staging/app_queue_monitor_filename_commas.txt
new file mode 100644
index 0000000..f303467
--- /dev/null
+++ b/doc/CHANGES-staging/app_queue_monitor_filename_commas.txt
@@ -0,0 +1,5 @@
+Subject: app_queue
+
+Commas in MONITOR_EXEC are now escaped after variable replacement
+occurs instead of before. Additionally, commas are no longer escaped
+at all in MONITOR_FILENAME.
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19302
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 19
Gerrit-Change-Id: Ib18481288c5292e27321e95364d7e63e8917252f
Gerrit-Change-Number: 19302
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220919/a98705b6/attachment-0001.html>
More information about the asterisk-code-review
mailing list