[Asterisk-code-review] app_voicemail.c: Support multiple file formats for forwarded messages. (...asterisk[13])

cmaj asteriskteam at digium.com
Thu Sep 26 18:57:31 CDT 2019


cmaj has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/12977


Change subject: app_voicemail.c: Support multiple file formats for forwarded messages.
......................................................................

app_voicemail.c: Support multiple file formats for forwarded messages.

If you specify multiple formats in voicemail.conf, eg. "format = gsm|wav"
and are using realtime ODBC backend, only the first format gets stored
in the database. So when you forward a message later on, there is a bug
generating the email, related to the stored format (GSM) being different
than the desired email format (WAV) specified for the user. Sox can
handle this, but Asterisk needs to tell sox exactly what to do.

ASTERISK-22192

Change-Id: I15951ef653b5dac08f0e5ec1da67f095dfcc38b5
---
M apps/app_voicemail.c
1 file changed, 48 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/77/12977/1

diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 1134ccd..51c4fd9 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -5497,12 +5497,36 @@
 	char sox_gain_tmpdir[PATH_MAX];
 	char *file_to_delete = NULL, *dir_to_delete = NULL;
 	int res;
+	char altfname[PATH_MAX] = "";
+	int altused = 0;
+	char altformat[80] = "";
+	char *c = NULL;
+	FILE *file, *altfile;
+
+	/* Users of multiple file formats need special attention. */
+	snprintf(fname, sizeof(fname), "%s.%s", attach, format);
+	if (!(file = fopen(fname, "rb"))) {
+		ast_copy_string(altformat, vmfmts, sizeof(altformat));
+		c = strchr(altformat, '|');
+		if (c)
+			*c = '\0';
+		ast_log(AST_LOG_WARNING, "Failed to open file: %s: %s - trying first/alternate format %s\n", fname, strerror(errno), altformat);
+		snprintf(altfname, sizeof(altfname), "%s.%s", attach, altformat);
+		if (!(altfile = fopen(altfname, "rb"))) {
+			ast_log(AST_LOG_WARNING, "Failed to open file: %s: %s - alternate format %s failure\n", altfname, strerror(errno), altformat);
+		} else {
+			fclose(altfile);
+			altused = 1;
+		}
+	} else {
+		fclose(file);
+    }
 
 	/* Eww. We want formats to tell us their own MIME type */
 	char *mime_type = (!strcasecmp(format, "ogg")) ? "application/" : "audio/x-";
 
 	/* This 'while' loop will only execute once. We use it so that we can 'break' */
-	while (vmu->volgain < -.001 || vmu->volgain > .001) {
+	while (vmu->volgain < -.001 || vmu->volgain > .001 || altused) {
 		char tmpdir[PATH_MAX];
 
 		create_dirpath(tmpdir, sizeof(tmpdir), vmu->context, vmu->mailbox, "tmp");
@@ -5528,8 +5552,29 @@
 				break;
 			}
 
-			res = snprintf(sox_gain_cmd, sizeof(sox_gain_cmd), "sox -v %.4f %s.%s %s",
-						   vmu->volgain, attach, format, fname);
+			if (!altused) {
+				res = snprintf(sox_gain_cmd, sizeof(sox_gain_cmd), "sox -v %.4f %s.%s %s",
+							   vmu->volgain, attach, format, fname);
+			} else {
+				if (!strcasecmp(format, "wav")) {
+					if (vmu->volgain < -.001 || vmu->volgain > .001) {
+						res = snprintf(sox_gain_cmd, sizeof(sox_gain_cmd), "sox -v %.4f %s.%s -e signed-integer -b 16 %s",
+									   vmu->volgain, attach, altformat, fname);
+					} else {
+						res = snprintf(sox_gain_cmd, sizeof(sox_gain_cmd), "sox %s.%s -e signed-integer -b 16 %s",
+									   attach, altformat, fname);
+					}
+				} else {
+					if (vmu->volgain < -.001 || vmu->volgain > .001) {
+						res = snprintf(sox_gain_cmd, sizeof(sox_gain_cmd), "sox -v %.4f %s.%s %s",
+									   vmu->volgain, attach, altformat, fname);
+					} else {
+						res = snprintf(sox_gain_cmd, sizeof(sox_gain_cmd), "sox %s.%s %s",
+									   attach, altformat, fname);
+					}
+				}
+			}
+
 			if (res >= sizeof(sox_gain_cmd)) {
 				ast_log(LOG_ERROR, "Failed to generate sox command, out of buffer space\n");
 				break;

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/12977
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: I15951ef653b5dac08f0e5ec1da67f095dfcc38b5
Gerrit-Change-Number: 12977
Gerrit-PatchSet: 1
Gerrit-Owner: cmaj <chris at penguinpbx.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190926/aede3d33/attachment-0001.html>


More information about the asterisk-code-review mailing list