[Asterisk-code-review] app_mixmonitor: Set MIXMONITOR_FILENAME to correct value when wav49 i... (asterisk[17])
George Joseph
asteriskteam at digium.com
Thu Feb 20 09:25:25 CST 2020
George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/13799 )
Change subject: app_mixmonitor: Set MIXMONITOR_FILENAME to correct value when wav49 is used
......................................................................
app_mixmonitor: Set MIXMONITOR_FILENAME to correct value when wav49 is used
When opening a file for writing, Asterisk silently converts filenames
ending with 'wav49' to 'WAV.' We aren't taking that in to account when
setting the MIXMONITOR_FILENAME variable in MixMonitor.
* If the user wants to write to a wav49 file, make sure that it is
reflected properly in MIXMONITOR_FILENAME.
* Add a note to the documentation describing this behavior.
* Add a note in main/file.c indicating that app_mixmonitor needs to be
changed if the logic in build_filename was changed.
ASTERISK-24798 #close
Reported by: xrobau
Change-Id: I384691ce624eb55c80a125b9ca206d2d691c574c
---
M apps/app_mixmonitor.c
A doc/CHANGES-staging/app_mixmonitor_wav49.txt
M main/file.c
3 files changed, 36 insertions(+), 3 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c
index 6746c47..a5c27bf 100644
--- a/apps/app_mixmonitor.c
+++ b/apps/app_mixmonitor.c
@@ -154,6 +154,11 @@
<para>This application does not automatically answer and should be preceeded by
an application such as Answer or Progress().</para>
<note><para>MixMonitor runs as an audiohook.</para></note>
+ <note><para>If a filename passed to MixMonitor ends with
+ <literal>.wav49</literal>, Asterisk will silently convert the extension to
+ <literal>.WAV</literal> for legacy reasons. <variable>MIXMONITOR_FILENAME</variable>
+ will contain the actual filename that Asterisk is writing to, not necessarily the
+ value that was passed in.</para></note>
<variablelist>
<variable name="MIXMONITOR_FILENAME">
<para>Will contain the filename used to record.</para>
@@ -998,17 +1003,35 @@
static char *filename_parse(char *filename, char *buffer, size_t len)
{
char *slash;
+ char *ext;
+
+ ast_assert(len > 0);
+
if (ast_strlen_zero(filename)) {
ast_log(LOG_WARNING, "No file name was provided for a file save option.\n");
- } else if (filename[0] != '/') {
- char *build;
- build = ast_alloca(strlen(ast_config_AST_MONITOR_DIR) + strlen(filename) + 3);
+ buffer[0] = 0;
+ return buffer;
+ }
+
+ /* If we don't have an absolute path, make one */
+ if (*filename != '/') {
+ char *build = ast_alloca(strlen(ast_config_AST_MONITOR_DIR) + strlen(filename) + 3);
sprintf(build, "%s/%s", ast_config_AST_MONITOR_DIR, filename);
filename = build;
}
ast_copy_string(buffer, filename, len);
+ /* If the provided filename has a .wav49 extension, we need to convert it to .WAV to
+ match the behavior of build_filename in main/file.c. Otherwise MIXMONITOR_FILENAME
+ ends up referring to a file that does not/will not exist */
+ ext = strrchr(buffer, '.');
+ if (ext && !strcmp(ext, ".wav49")) {
+ /* Change to WAV - we know we have at least 6 writeable bytes where 'ext' points,
+ * so this is safe */
+ memcpy(ext, ".WAV", sizeof(".WAV"));
+ }
+
if ((slash = strrchr(filename, '/'))) {
*slash = '\0';
}
diff --git a/doc/CHANGES-staging/app_mixmonitor_wav49.txt b/doc/CHANGES-staging/app_mixmonitor_wav49.txt
new file mode 100644
index 0000000..f3218d7
--- /dev/null
+++ b/doc/CHANGES-staging/app_mixmonitor_wav49.txt
@@ -0,0 +1,8 @@
+Subject: app_mixmonitor
+
+If the 'filename' argument to MixMonitor() ended with '.wav49,'
+Asterisk would silently convert the extension to '.WAV' when opening
+the file for writing. This caused the MIXMONITOR_FILENAME variable to
+reference the wrong file. The MIXMONITOR_FILENAME variable will now
+reflect the name of the file that Asterisk actually used instead of
+the filename that was passed to the application.
diff --git a/main/file.c b/main/file.c
index a0616c8..b426609 100644
--- a/main/file.c
+++ b/main/file.c
@@ -315,6 +315,8 @@
{
char *fn = NULL;
+ /* The wav49 -> WAV translation is duplicated in apps/app_mixmonitor.c, so
+ if you change it here you need to change it there as well */
if (!strcmp(ext, "wav49"))
ext = "WAV";
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13799
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 17
Gerrit-Change-Id: I384691ce624eb55c80a125b9ca206d2d691c574c
Gerrit-Change-Number: 13799
Gerrit-PatchSet: 3
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200220/c058613b/attachment.html>
More information about the asterisk-code-review
mailing list