<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13808">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_mixmonitor: Set MIXMONITOR_FILENAME to correct value when wav49 is used<br><br>When opening a file for writing, Asterisk silently converts filenames<br>ending with 'wav49' to 'WAV.' We aren't taking that in to account when<br>setting the MIXMONITOR_FILENAME variable in MixMonitor.<br><br>* If the user wants to write to a wav49 file, make sure that it is<br>  reflected properly in MIXMONITOR_FILENAME.<br><br>* Add a note to the documentation describing this behavior.<br><br>* Add a note in main/file.c indicating that app_mixmonitor needs to be<br>  changed if the logic in build_filename was changed.<br><br>ASTERISK-24798 #close<br>Reported by: xrobau<br><br>Change-Id: I384691ce624eb55c80a125b9ca206d2d691c574c<br>---<br>M apps/app_mixmonitor.c<br>A doc/CHANGES-staging/app_mixmonitor_wav49.txt<br>M main/file.c<br>3 files changed, 36 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c</span><br><span>index ecb0830..ad3ac99 100644</span><br><span>--- a/apps/app_mixmonitor.c</span><br><span>+++ b/apps/app_mixmonitor.c</span><br><span>@@ -156,6 +156,11 @@</span><br><span>                         <para>This application does not automatically answer and should be preceeded by</span><br><span>                        an application such as Answer or Progress().</para></span><br><span>                    <note><para>MixMonitor runs as an audiohook.</para></note></span><br><span style="color: hsl(120, 100%, 40%);">+                    <note><para>If a filename passed to MixMonitor ends with</span><br><span style="color: hsl(120, 100%, 40%);">+                  <literal>.wav49</literal>, Asterisk will silently convert the extension to</span><br><span style="color: hsl(120, 100%, 40%);">+                        <literal>.WAV</literal> for legacy reasons. <variable>MIXMONITOR_FILENAME</variable></span><br><span style="color: hsl(120, 100%, 40%);">+                  will contain the actual filename that Asterisk is writing to, not necessarily the</span><br><span style="color: hsl(120, 100%, 40%);">+                     value that was passed in.</para></note></span><br><span>                  <variablelist></span><br><span>                                 <variable name="MIXMONITOR_FILENAME"></span><br><span>                                        <para>Will contain the filename used to record.</para></span><br><span>@@ -1003,17 +1008,35 @@</span><br><span> static char *filename_parse(char *filename, char *buffer, size_t len)</span><br><span> {</span><br><span>   char *slash;</span><br><span style="color: hsl(120, 100%, 40%);">+  char *ext;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  ast_assert(len > 0);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>    if (ast_strlen_zero(filename)) {</span><br><span>             ast_log(LOG_WARNING, "No file name was provided for a file save option.\n");</span><br><span style="color: hsl(0, 100%, 40%);">-  } else if (filename[0] != '/') {</span><br><span style="color: hsl(0, 100%, 40%);">-                char *build;</span><br><span style="color: hsl(0, 100%, 40%);">-            build = ast_alloca(strlen(ast_config_AST_MONITOR_DIR) + strlen(filename) + 3);</span><br><span style="color: hsl(120, 100%, 40%);">+                buffer[0] = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+                return buffer;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* If we don't have an absolute path, make one */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (*filename != '/') {</span><br><span style="color: hsl(120, 100%, 40%);">+               char *build = ast_alloca(strlen(ast_config_AST_MONITOR_DIR) + strlen(filename) + 3);</span><br><span>                 sprintf(build, "%s/%s", ast_config_AST_MONITOR_DIR, filename);</span><br><span>             filename = build;</span><br><span>    }</span><br><span> </span><br><span>        ast_copy_string(buffer, filename, len);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+   /* If the provided filename has a .wav49 extension, we need to convert it to .WAV to</span><br><span style="color: hsl(120, 100%, 40%);">+     match the behavior of build_filename in main/file.c. Otherwise MIXMONITOR_FILENAME</span><br><span style="color: hsl(120, 100%, 40%);">+    ends up referring to a file that does not/will not exist */</span><br><span style="color: hsl(120, 100%, 40%);">+        ext = strrchr(buffer, '.');</span><br><span style="color: hsl(120, 100%, 40%);">+   if (ext && !strcmp(ext, ".wav49")) {</span><br><span style="color: hsl(120, 100%, 40%);">+                /* Change to WAV - we know we have at least 6 writeable bytes where 'ext' points,</span><br><span style="color: hsl(120, 100%, 40%);">+              * so this is safe */</span><br><span style="color: hsl(120, 100%, 40%);">+         memcpy(ext, ".WAV", sizeof(".WAV"));</span><br><span style="color: hsl(120, 100%, 40%);">+      }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  if ((slash = strrchr(filename, '/'))) {</span><br><span>              *slash = '\0';</span><br><span>       }</span><br><span>diff --git a/doc/CHANGES-staging/app_mixmonitor_wav49.txt b/doc/CHANGES-staging/app_mixmonitor_wav49.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..f3218d7</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/app_mixmonitor_wav49.txt</span><br><span>@@ -0,0 +1,8 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: app_mixmonitor</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+If the 'filename' argument to MixMonitor() ended with '.wav49,'</span><br><span style="color: hsl(120, 100%, 40%);">+Asterisk would silently convert the extension to '.WAV' when opening</span><br><span style="color: hsl(120, 100%, 40%);">+the file for writing. This caused the MIXMONITOR_FILENAME variable to</span><br><span style="color: hsl(120, 100%, 40%);">+reference the wrong file. The MIXMONITOR_FILENAME variable will now</span><br><span style="color: hsl(120, 100%, 40%);">+reflect the name of the file that Asterisk actually used instead of</span><br><span style="color: hsl(120, 100%, 40%);">+the filename that was passed to the application.</span><br><span>diff --git a/main/file.c b/main/file.c</span><br><span>index 7510007..bc10de9 100644</span><br><span>--- a/main/file.c</span><br><span>+++ b/main/file.c</span><br><span>@@ -316,6 +316,8 @@</span><br><span> {</span><br><span>         char *fn = NULL;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+  /* The wav49 -> WAV translation is duplicated in apps/app_mixmonitor.c, so</span><br><span style="color: hsl(120, 100%, 40%);">+    if you change it here you need to change it there as well */</span><br><span>      if (!strcmp(ext, "wav49"))</span><br><span>                 ext = "WAV";</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13808">change 13808</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/13808"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I384691ce624eb55c80a125b9ca206d2d691c574c </div>
<div style="display:none"> Gerrit-Change-Number: 13808 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-CC: Michael L. Young <elgueromexicano@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>