mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
Make sure two voicemails can't take the same message space (bug #3394)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4881 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
84
app.c
84
app.c
@@ -497,7 +497,7 @@ int ast_play_and_wait(struct ast_channel *chan, const char *fn)
|
||||
static int global_silence_threshold = 128;
|
||||
static int global_maxsilence = 0;
|
||||
|
||||
int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int silencethreshold, int maxsilence)
|
||||
int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int silencethreshold, int maxsilence, const char *path)
|
||||
{
|
||||
char d, *fmts;
|
||||
char comment[256];
|
||||
@@ -507,7 +507,7 @@ int ast_play_and_record(struct ast_channel *chan, const char *playfile, const ch
|
||||
char *sfmt[MAX_OTHER_FORMATS];
|
||||
char *stringp=NULL;
|
||||
time_t start, end;
|
||||
struct ast_dsp *sildet; /* silence detector dsp */
|
||||
struct ast_dsp *sildet=NULL; /* silence detector dsp */
|
||||
int totalsilence = 0;
|
||||
int dspsilence = 0;
|
||||
int gotsilence = 0; /* did we timeout for silence? */
|
||||
@@ -564,18 +564,23 @@ int ast_play_and_record(struct ast_channel *chan, const char *playfile, const ch
|
||||
}
|
||||
}
|
||||
|
||||
sildet = ast_dsp_new(); /* Create the silence detector */
|
||||
if (!sildet) {
|
||||
ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
|
||||
return -1;
|
||||
}
|
||||
ast_dsp_set_threshold(sildet, silencethreshold);
|
||||
if (path)
|
||||
ast_unlock_path(path);
|
||||
|
||||
|
||||
|
||||
if (maxsilence > 0) {
|
||||
sildet = ast_dsp_new(); /* Create the silence detector */
|
||||
if (!sildet) {
|
||||
ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
|
||||
return -1;
|
||||
}
|
||||
ast_dsp_set_threshold(sildet, silencethreshold);
|
||||
rfmt = chan->readformat;
|
||||
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
|
||||
ast_dsp_free(sildet);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -619,13 +624,13 @@ int ast_play_and_record(struct ast_channel *chan, const char *playfile, const ch
|
||||
totalsilence = 0;
|
||||
|
||||
if (totalsilence > maxsilence) {
|
||||
/* Ended happily with silence */
|
||||
if (option_verbose > 2)
|
||||
ast_verbose( VERBOSE_PREFIX_3 "Recording automatically stopped after a silence of %d seconds\n", totalsilence/1000);
|
||||
ast_frfree(f);
|
||||
gotsilence = 1;
|
||||
outmsg=2;
|
||||
break;
|
||||
/* Ended happily with silence */
|
||||
if (option_verbose > 2)
|
||||
ast_verbose( VERBOSE_PREFIX_3 "Recording automatically stopped after a silence of %d seconds\n", totalsilence/1000);
|
||||
ast_frfree(f);
|
||||
gotsilence = 1;
|
||||
outmsg=2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Exit on any error */
|
||||
@@ -704,6 +709,8 @@ int ast_play_and_record(struct ast_channel *chan, const char *playfile, const ch
|
||||
if(!ast_streamfile(chan, "auth-thankyou", chan->language))
|
||||
ast_waitstream(chan, "");
|
||||
}
|
||||
if (sildet)
|
||||
ast_dsp_free(sildet);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1061,7 +1068,50 @@ int ast_seperate_app_args(char *buf, char delim, char **array, int arraylen)
|
||||
return x;
|
||||
}
|
||||
|
||||
int ast_record_review(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration)
|
||||
int ast_lock_path(const char *path)
|
||||
{
|
||||
char *s;
|
||||
char *fs;
|
||||
int res;
|
||||
int fd;
|
||||
time_t start;
|
||||
s = alloca(strlen(path) + 10);
|
||||
fs = alloca(strlen(path) + 20);
|
||||
if (!fs || !s) {
|
||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
||||
return -1;
|
||||
}
|
||||
snprintf(fs, strlen(path) + 19, "%s/%s-%08x", path, ".lock", rand());
|
||||
fd = open(fs, O_WRONLY | O_CREAT | O_EXCL, 0600);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Unable to create lock file: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock");
|
||||
time(&start);
|
||||
while (((res = link(fs, s)) < 0) && (errno == EEXIST) && (time(NULL) - start < 5))
|
||||
usleep(1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n", path, strerror(errno));
|
||||
}
|
||||
unlink(fs);
|
||||
ast_log(LOG_DEBUG, "Locked path '%s'\n", path);
|
||||
return res;
|
||||
}
|
||||
|
||||
int ast_unlock_path(const char *path)
|
||||
{
|
||||
char *s;
|
||||
s = alloca(strlen(path) + 10);
|
||||
if (!s)
|
||||
return -1;
|
||||
snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock");
|
||||
ast_log(LOG_DEBUG, "Unlocked path '%s'\n", path);
|
||||
return unlink(s);
|
||||
}
|
||||
|
||||
int ast_record_review(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path)
|
||||
{
|
||||
int silencethreshold = 128;
|
||||
int maxsilence=0;
|
||||
@@ -1108,7 +1158,7 @@ int ast_record_review(struct ast_channel *chan, const char *playfile, const char
|
||||
else
|
||||
ast_verbose(VERBOSE_PREFIX_3 "Recording\n");
|
||||
recorded = 1;
|
||||
cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, silencethreshold, maxsilence);
|
||||
cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, silencethreshold, maxsilence, path);
|
||||
if (cmd == -1) {
|
||||
/* User has hung up, no options to give */
|
||||
return cmd;
|
||||
|
Reference in New Issue
Block a user