[asterisk-commits] tilghman: branch 1.4 r257266 - /branches/1.4/apps/app_voicemail.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 14 18:08:14 CDT 2010
Author: tilghman
Date: Wed Apr 14 18:08:11 2010
New Revision: 257266
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=257266
Log:
When forwarding a message, ensure that prepending works correctly.
This is a regression in 1.4, only.
(closes issue #17103)
Reported by: mglazer
Patches:
20100408__issue17103.diff.txt uploaded by tilghman (license 14)
Tested by: tilghman
Modified:
branches/1.4/apps/app_voicemail.c
Modified: branches/1.4/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/apps/app_voicemail.c?view=diff&rev=257266&r1=257265&r2=257266
==============================================================================
--- branches/1.4/apps/app_voicemail.c (original)
+++ branches/1.4/apps/app_voicemail.c Wed Apr 14 18:08:11 2010
@@ -5082,26 +5082,28 @@
int retries = 0, prepend_duration = 0, already_recorded = 0;
signed char zero_gain = 0;
struct ast_config *msg_cfg;
- const char *duration_str;
- char msgfile[PATH_MAX], backup[PATH_MAX], backup_textfile[PATH_MAX];
+ const char *duration_cstr;
+ char msgfile[PATH_MAX], backup[PATH_MAX];
char textfile[PATH_MAX];
-
+ struct ast_category *msg_cat;
+ char duration_str[12] = "";
+
+ ast_log(LOG_NOTICE, "curdir=%s\n", curdir);
/* Must always populate duration correctly */
make_file(msgfile, sizeof(msgfile), curdir, curmsg);
strcpy(textfile, msgfile);
strcpy(backup, msgfile);
- strcpy(backup_textfile, msgfile);
strncat(textfile, ".txt", sizeof(textfile) - strlen(textfile) - 1);
strncat(backup, "-bak", sizeof(backup) - strlen(backup) - 1);
- strncat(backup_textfile, "-bak.txt", sizeof(backup_textfile) - strlen(backup_textfile) - 1);
if (!(msg_cfg = ast_config_load(textfile))) {
return -1;
}
*duration = 0;
- if ((duration_str = ast_variable_retrieve(msg_cfg, "message", "duration")))
- *duration = atoi(duration_str);
+ if ((duration_cstr = ast_variable_retrieve(msg_cfg, "message", "duration"))) {
+ *duration = atoi(duration_cstr);
+ }
while ((cmd >= 0) && (cmd != 't') && (cmd != '*')) {
if (cmd)
@@ -5112,19 +5114,11 @@
{
prepend_duration = 0;
- /* if we can't read the message metadata, stop now */
- if (!msg_cfg) {
- cmd = 0;
- break;
- }
-
/* Back up the original file, so we can retry the prepend */
if (already_recorded) {
ast_filecopy(backup, msgfile, NULL);
- copy(backup_textfile, textfile);
} else {
ast_filecopy(msgfile, backup, NULL);
- copy(textfile, backup_textfile);
}
already_recorded = 1;
@@ -5136,16 +5130,7 @@
ast_channel_setoption(chan, AST_OPTION_RXGAIN, &zero_gain, sizeof(zero_gain), 0);
if (prepend_duration) {
- struct ast_category *msg_cat;
- /* need enough space for a maximum-length message duration */
- char duration_str[12];
-
prepend_duration += *duration;
- msg_cat = ast_category_get(msg_cfg, "message");
- snprintf(duration_str, 11, "%d", prepend_duration);
- if (!ast_variable_update(msg_cat, "duration", duration_str, NULL, 0)) {
- config_text_file_save(textfile, msg_cfg, "app_voicemail");
- }
}
break;
@@ -5171,14 +5156,22 @@
}
}
+ if (already_recorded && cmd == -1) {
+ /* Restore original files, if operation cancelled */
+ ast_filerename(backup, msgfile, NULL);
+ if (duration_cstr) {
+ ast_copy_string(duration_str, duration_cstr, sizeof(duration_str));
+ }
+ } else if (prepend_duration) {
+ *duration = prepend_duration;
+ snprintf(duration_str, sizeof(duration_str), "%d", prepend_duration);
+ }
+
+ msg_cat = ast_category_get(msg_cfg, "message");
+ if (!ast_strlen_zero(duration_str) && !ast_variable_update(msg_cat, "duration", duration_str, NULL, 0)) {
+ config_text_file_save(textfile, msg_cfg, "app_voicemail");
+ }
ast_config_destroy(msg_cfg);
- if (already_recorded) {
- /* Restore original files */
- ast_filerename(backup, msgfile, NULL);
- rename(backup_textfile, textfile);
- }
- if (prepend_duration)
- *duration = prepend_duration;
if (cmd == 't' || cmd == 'S')
cmd = 0;
@@ -5394,19 +5387,12 @@
} else {
/* Forward VoiceMail */
long duration = 0;
- char origmsgfile[PATH_MAX], msgfile[PATH_MAX];
+ char msgfile[PATH_MAX];
struct vm_state vmstmp;
memcpy(&vmstmp, vms, sizeof(vmstmp));
- make_file(origmsgfile, sizeof(origmsgfile), dir, curmsg);
- create_dirpath(vmstmp.curdir, sizeof(vmstmp.curdir), sender->context, vmstmp.username, "tmp");
- make_file(msgfile, sizeof(msgfile), vmstmp.curdir, curmsg);
-
- RETRIEVE(dir, curmsg, sender);
-
- /* Alter a surrogate file, only */
- copy_plain_file(origmsgfile, msgfile);
+ RETRIEVE(dir, curmsg, sender);
cmd = vm_forwardoptions(chan, sender, vmstmp.curdir, curmsg, vmfmts, S_OR(context, "default"), record_gain, &duration, &vmstmp);
if (!cmd) {
@@ -5437,7 +5423,7 @@
/* NULL category for IMAP storage */
sendmail(myserveremail, vmtmp, todircount, vmtmp->context, vmtmp->mailbox, dstvms->curbox, S_OR(chan->cid.cid_num, NULL), S_OR(chan->cid.cid_name, NULL), vms->fn, fmt, duration, attach_user_voicemail, chan, NULL);
#else
- copy_message(chan, sender, -1, curmsg, duration, vmtmp, fmt, vmstmp.curdir);
+ copy_message(chan, sender, 0, curmsg, duration, vmtmp, fmt, dir);
#endif
saved_messages++;
AST_LIST_REMOVE_CURRENT(&extensions, list);
@@ -5472,9 +5458,6 @@
}
#endif
}
-
- /* Remove surrogate file */
- vm_delete(msgfile);
DISPOSE(dir, curmsg);
}
More information about the asterisk-commits
mailing list