<p>cmaj has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12981">View Change</a></p><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, 48 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/81/12981/1</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 1134ccd..c1d9e42 100644</span><br><span>--- a/apps/app_voicemail.c</span><br><span>+++ b/apps/app_voicemail.c</span><br><span>@@ -5497,12 +5497,36 @@</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 style="color: hsl(120, 100%, 40%);">+ FILE *file, *altfile;</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 (!(file = fopen(fname, "rb"))) {</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%);">+ 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 (!(altfile = fopen(altfname, "rb"))) {</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%);">+ fclose(altfile);</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%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ fclose(file);</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>@@ -5528,8 +5552,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/+/12981">change 12981</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/+/12981"/><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: I7321e7f7e7c58adbf41dd4fd7191c887b9b2eafd </div>
<div style="display:none"> Gerrit-Change-Number: 12981 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: cmaj <chris@penguinpbx.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>