<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12983">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
George Joseph: Looks good to me, approved
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_voicemail.c: Support multiple file formats for forwarded messages.<br><br>If you specify multiple formats in voicemail.conf, eg. "format = gsm|wav"<br>and are using realtime ODBC backend, only the first format gets stored<br>in the database. So when you forward a message later on, there is a bug<br>generating the email, related to the stored format (GSM) being different<br>than the desired email format (WAV) specified for the user. Sox can<br>handle this, but Asterisk needs to tell sox exactly what to do.<br><br>ASTERISK-22192<br><br>Change-Id: I7321e7f7e7c58adbf41dd4fd7191c887b9b2eafd<br>---<br>M apps/app_voicemail.c<br>1 file changed, 45 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c</span><br><span>index 7343bb2..57f22cd 100644</span><br><span>--- a/apps/app_voicemail.c</span><br><span>+++ b/apps/app_voicemail.c</span><br><span>@@ -5398,12 +5398,33 @@</span><br><span> char sox_gain_tmpdir[PATH_MAX];</span><br><span> char *file_to_delete = NULL, *dir_to_delete = NULL;</span><br><span> int res;</span><br><span style="color: hsl(120, 100%, 40%);">+ char altfname[PATH_MAX] = "";</span><br><span style="color: hsl(120, 100%, 40%);">+ int altused = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ char altformat[80] = "";</span><br><span style="color: hsl(120, 100%, 40%);">+ char *c = NULL;</span><br><span> </span><br><span> /* Eww. We want formats to tell us their own MIME type */</span><br><span> char *mime_type = (!strcasecmp(format, "ogg")) ? "application/" : "audio/x-";</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Users of multiple file formats need special attention. */</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(fname, sizeof(fname), "%s.%s", attach, format);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_file_is_readable(fname)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_copy_string(altformat, vmfmts, sizeof(altformat));</span><br><span style="color: hsl(120, 100%, 40%);">+ c = strchr(altformat, '|');</span><br><span style="color: hsl(120, 100%, 40%);">+ if (c) {</span><br><span style="color: hsl(120, 100%, 40%);">+ *c = '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_WARNING, "Failed to open file: %s: %s - trying first/alternate format %s\n", fname, strerror(errno), altformat);</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(altfname, sizeof(altfname), "%s.%s", attach, altformat);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_file_is_readable(altfname)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_WARNING, "Failed to open file: %s: %s - alternate format %s failure\n", altfname, strerror(errno), altformat);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ altused = 1;</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%);">+</span><br><span> /* This 'while' loop will only execute once. We use it so that we can 'break' */</span><br><span style="color: hsl(0, 100%, 40%);">- while (vmu->volgain < -.001 || vmu->volgain > .001) {</span><br><span style="color: hsl(120, 100%, 40%);">+ while (vmu->volgain < -.001 || vmu->volgain > .001 || altused) {</span><br><span> char tmpdir[PATH_MAX];</span><br><span> </span><br><span> create_dirpath(tmpdir, sizeof(tmpdir), vmu->context, vmu->mailbox, "tmp");</span><br><span>@@ -5429,8 +5450,29 @@</span><br><span> break;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- res = snprintf(sox_gain_cmd, sizeof(sox_gain_cmd), "sox -v %.4f %s.%s %s",</span><br><span style="color: hsl(0, 100%, 40%);">- vmu->volgain, attach, format, fname);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!altused) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = snprintf(sox_gain_cmd, sizeof(sox_gain_cmd), "sox -v %.4f %s.%s %s",</span><br><span style="color: hsl(120, 100%, 40%);">+ vmu->volgain, attach, format, fname);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strcasecmp(format, "wav")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (vmu->volgain < -.001 || vmu->volgain > .001) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = snprintf(sox_gain_cmd, sizeof(sox_gain_cmd), "sox -v %.4f %s.%s -e signed-integer -b 16 %s",</span><br><span style="color: hsl(120, 100%, 40%);">+ vmu->volgain, attach, altformat, fname);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = snprintf(sox_gain_cmd, sizeof(sox_gain_cmd), "sox %s.%s -e signed-integer -b 16 %s",</span><br><span style="color: hsl(120, 100%, 40%);">+ attach, altformat, fname);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (vmu->volgain < -.001 || vmu->volgain > .001) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = snprintf(sox_gain_cmd, sizeof(sox_gain_cmd), "sox -v %.4f %s.%s %s",</span><br><span style="color: hsl(120, 100%, 40%);">+ vmu->volgain, attach, altformat, fname);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = snprintf(sox_gain_cmd, sizeof(sox_gain_cmd), "sox %s.%s %s",</span><br><span style="color: hsl(120, 100%, 40%);">+ attach, altformat, fname);</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%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (res >= sizeof(sox_gain_cmd)) {</span><br><span> ast_log(LOG_ERROR, "Failed to generate sox command, out of buffer space\n");</span><br><span> break;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/12983">change 12983</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/+/12983"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 17 </div>
<div style="display:none"> Gerrit-Change-Id: I7321e7f7e7c58adbf41dd4fd7191c887b9b2eafd </div>
<div style="display:none"> Gerrit-Change-Number: 12983 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: cmaj <chris@penguinpbx.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@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>