Index: apps/app_voicemail.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_voicemail.c,v retrieving revision 1.83 diff -u -r1.83 app_voicemail.c --- apps/app_voicemail.c 30 Apr 2004 02:29:56 -0000 1.83 +++ apps/app_voicemail.c 1 May 2004 21:51:27 -0000 @@ -144,6 +144,7 @@ static int advanced_options(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms, int msg, int option); static int dialout(struct ast_channel *chan, struct ast_vm_user *vmu, char *num, char *outgoing_context); static int play_record_review(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt, int outsidecaller, struct ast_vm_user *vmu, int *duration); +static int vm_delete(char *file); @@ -753,7 +754,7 @@ return 1; } -static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *mailbox, char *callerid, char *attach, char *format, long duration, int attach_user_voicemail) +static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *mailbox, char *callerid, char *attach, char *format, int duration, int attach_user_voicemail) { FILE *p=NULL; int pfd; @@ -789,7 +790,7 @@ else { snprintf(who, sizeof(who), "%s@%s", srcemail, host); } - snprintf(dur, sizeof(dur), "%ld:%02ld", duration / 60, duration % 60); + snprintf(dur, sizeof(dur), "%d:%02d", duration / 60, duration % 60); time(&t); /* Does this user have a timezone specified? */ @@ -889,7 +890,7 @@ return 0; } -static int sendpage(char *srcemail, char *pager, int msgnum, char *mailbox, char *callerid, long duration, struct ast_vm_user *vmu) +static int sendpage(char *srcemail, char *pager, int msgnum, char *mailbox, char *callerid, int duration, struct ast_vm_user *vmu) { FILE *p=NULL; int pfd; @@ -919,7 +920,7 @@ else { snprintf(who, sizeof(who), "%s@%s", srcemail, host); } - snprintf(dur, sizeof(dur), "%ld:%02ld", duration / 60, duration % 60); + snprintf(dur, sizeof(dur), "%d:%02d", duration / 60, duration % 60); time(&t); /* Does this user have a timezone specified? */ @@ -1013,7 +1014,7 @@ return d; } -static int play_and_prepend(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt, int beep) +static int play_and_prepend(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt, int *duration, int beep) { char d = 0, *fmts; char comment[256]; @@ -1031,7 +1032,13 @@ int rfmt=0; char prependfile[80]; - ast_log(LOG_DEBUG,"play_and_preped: %s, %s, '%s'\n", playfile ? playfile : "", recordfile, fmt); + /* barf if no pointer passed to store duration in */ + if (duration == NULL) { + ast_log(LOG_WARNING, "Error play_and_prepend called without duration pointer\n"); + return -1; + } + + ast_log(LOG_DEBUG,"play_and_prepend: %s, %s, '%s'\n", playfile ? playfile : "", recordfile, fmt); snprintf(comment,sizeof(comment),"Playing %s, Recording to: %s on %s\n", playfile ? playfile : "", recordfile, chan->name); if (playfile || beep) { @@ -1062,8 +1069,8 @@ sfmt[fmtcnt++] = ast_strdupa(fmt); } - if (maxtime) - time(&start); + time(&start); + end=start; /* pre-initialize end to be same as start in case we never get into loop */ for (x=0;x 2) ast_verbose( VERBOSE_PREFIX_3 "User hung up\n"); @@ -1184,6 +1192,7 @@ } else { ast_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", prependfile, sfmt[x]); } + *duration = end - start; #if 0 if (outmsg > 1) { #else @@ -1228,7 +1237,7 @@ return res; } -static int play_and_record(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt) +static int play_and_record(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt, int *duration) { char d, *fmts; char comment[256]; @@ -1244,6 +1253,12 @@ int gotsilence = 0; /* did we timeout for silence? */ int rfmt=0; + /* barf if no pointer passed to store duration in */ + if (duration == NULL) { + ast_log(LOG_WARNING, "Error play_and_record called without duration pointer\n"); + return -1; + } + ast_log(LOG_DEBUG,"play_and_record: %s, %s, '%s'\n", playfile ? playfile : "", recordfile, fmt); snprintf(comment,sizeof(comment),"Playing %s, Recording to: %s on %s\n", playfile ? playfile : "", recordfile, chan->name); @@ -1272,8 +1287,8 @@ sfmt[fmtcnt++] = ast_strdupa(fmt); } - if (maxtime) - time(&start); + time(&start); + end=start; /* pre-initialize end to be same as start in case we never get into loop */ for (x=0;x 2) ast_verbose( VERBOSE_PREFIX_3 "User hung up\n"); @@ -1395,6 +1411,8 @@ ast_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", recordfile, sfmt[x]); } + *duration = end - start; + for (x=0;x -1) { txt = fdopen(fd, "a"); if (txt) { - time(&end); - fprintf(txt, "duration=%ld\n", (long)(duration)); + fprintf(txt, "duration=%d\n", duration); fclose(txt); } else close(fd); } - if (end - start < vmminmessage) { - ast_filedelete(fn, NULL); + if (duration < vmminmessage) { + vm_delete(fn); goto leave_vm_out; } stringp = fmt; @@ -1629,13 +1643,13 @@ attach_user_voicemail = vmu->attach; if (strlen(vmu->serveremail)) myserveremail = vmu->serveremail; - sendmail(myserveremail, vmu, msgnum, ext, chan->callerid, fn, fmt, end - start, attach_user_voicemail); + sendmail(myserveremail, vmu, msgnum, ext, chan->callerid, fn, fmt, duration, attach_user_voicemail); } if (strlen(vmu->pager)) { char *myserveremail = serveremail; if (strlen(vmu->serveremail)) myserveremail = vmu->serveremail; - sendpage(myserveremail, vmu->pager, msgnum, ext, chan->callerid, end - start, vmu); + sendpage(myserveremail, vmu->pager, msgnum, ext, chan->callerid, duration, vmu); } } else { res = ast_streamfile(chan, "vm-mailboxfull", chan->language); @@ -2307,6 +2321,7 @@ { int cmd = 0; int retries = 0; + int duration = 0; while((cmd >= 0) && (cmd != 't') && (cmd != '*')) { if (cmd) @@ -2317,7 +2332,7 @@ { char file[200]; snprintf(file, sizeof(file), "%s/msg%04d", curdir, curmsg); - cmd = play_and_prepend(chan, NULL, file, 0, vmfmts, 1); + cmd = play_and_prepend(chan, NULL, file, 0, vmfmts, &duration, 1); break; } case '2': @@ -2349,7 +2364,7 @@ char sys[256]; char todir[256]; int todircount=0; - long duration; + int duration; struct ast_config *mif; char miffile[256]; char fn[256]; @@ -2434,7 +2449,7 @@ snprintf(callerid, sizeof(callerid), "FWD from: %s from %s", sender->fullname, ast_variable_retrieve(mif, NULL, "callerid")); s = ast_variable_retrieve(mif, NULL, "duration"); if (s) - duration = atol(s); + duration = atoi(s); else duration = 0; if (strlen(vmtmp->email)) { @@ -2717,9 +2732,7 @@ make_file(vms->fn, sizeof(vms->fn), vms->curdir, x); if (ast_fileexists(vms->fn, NULL, NULL) < 1) break; - snprintf(txt, sizeof(txt), "%s.txt", vms->fn); - ast_filedelete(vms->fn, NULL); - unlink(txt); + vm_delete(vms->fn); } } memset(vms->deleted, 0, sizeof(vms->deleted)); @@ -2821,6 +2834,7 @@ { int cmd = 0; int retries = 0; + int duration = 0; char newpassword[80] = ""; char newpassword2[80] = ""; char prefile[256]=""; @@ -2842,15 +2856,15 @@ switch (cmd) { case '1': snprintf(prefile,sizeof(prefile),"voicemail/%s/%s/unavail",vmu->context, vms->username); - cmd = play_record_review(chan,"vm-rec-unv",prefile, maxgreet, fmtc, 0, vmu, 0); + cmd = play_record_review(chan,"vm-rec-unv",prefile, maxgreet, fmtc, 0, vmu, &duration); break; case '2': snprintf(prefile,sizeof(prefile),"voicemail/%s/%s/busy",vmu->context, vms->username); - cmd = play_record_review(chan,"vm-rec-busy",prefile, maxgreet, fmtc, 0, vmu, 0); + cmd = play_record_review(chan,"vm-rec-busy",prefile, maxgreet, fmtc, 0, vmu, &duration); break; case '3': snprintf(prefile,sizeof(prefile),"voicemail/%s/%s/greet",vmu->context, vms->username); - cmd = play_record_review(chan,"vm-rec-name",prefile, maxgreet, fmtc, 0, vmu, 0); + cmd = play_record_review(chan,"vm-rec-name",prefile, maxgreet, fmtc, 0, vmu, &duration); break; case '4': newpassword[1] = '\0'; @@ -4116,11 +4130,15 @@ int max_attempts = 3; int attempts = 0; int recorded = 0; - time_t start = 0; - time_t end = 0; int message_exists = 0; /* Note that urgent and private are for flagging messages as such in the future */ + /* barf if no pointer passed to store duration in */ + if (duration == NULL) { + ast_log(LOG_WARNING, "Error play_record_review called without duration pointer\n"); + return -1; + } + cmd = '3'; /* Want to start by recording */ while((cmd >= 0) && (cmd != 't')) { @@ -4154,35 +4172,29 @@ } recorded = 1; /* After an attempt has been made to record message, we have to take care of INTRO and beep for incoming messages, but not for greetings */ - /* twisted says: don't touch the pointer if it's null! */ - if (duration) *duration = 0; - time(&start); - cmd = play_and_record(chan, playfile, recordfile, maxtime, fmt); - time(&end); - /* twisted says: don't touch the pointer if it's null! */ - if (duration) *duration = end - start; + cmd = play_and_record(chan, playfile, recordfile, maxtime, fmt, duration); if (cmd == -1) /* User has hung up, no options to give */ return res; if (cmd == '0') { /* Erase the message if 0 pushed during playback */ play_and_wait(chan, "vm-deleted"); - ast_filedelete(recordfile, NULL); + vm_delete(recordfile); } else if (cmd == '*') { break; } #if 0 - else if (vmu->review && ((int)&end - (int)&start < 5)) { + else if (vmu->review && (*duration < 5)) { /* Message is too short */ ast_verbose(VERBOSE_PREFIX_3 "Message too short\n"); cmd = play_and_wait(chan, "vm-tooshort"); - cmd = ast_filedelete(recordfile, NULL); + cmd = vm_delete(recordfile); break; } - else if (vmu->review && (cmd == 2 && duration < (maxsilence + 3))) { + else if (vmu->review && (cmd == 2 && *duration < (maxsilence + 3))) { /* Message is all silence */ ast_verbose(VERBOSE_PREFIX_3 "Nothing recorded\n"); - cmd = ast_filedelete(recordfile, NULL); + cmd = vm_delete(recordfile); cmd = play_and_wait(chan, "vm-nothingrecorded"); if (!cmd) cmd = play_and_wait(chan, "vm-speakup"); @@ -4211,7 +4223,7 @@ case '*': /* Cancel recording, delete message, offer to take another message*/ cmd = play_and_wait(chan, "vm-deleted"); - cmd = ast_filedelete(recordfile, NULL); + cmd = vm_delete(recordfile); if (outsidecaller) { res = vm_exec(chan, NULL); return res; @@ -4269,6 +4281,15 @@ } +static int vm_delete(char *file) +{ + char *txt; + txt = (char *)malloc((strlen(file) + 5)*sizeof(char)); + sprintf(txt, "%s.txt", file); + unlink(txt); + free(txt); + return ast_filedelete(file, NULL); +} int usecount(void) {