diff options
author | martinp <martinp@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-12-19 18:06:29 +0000 |
---|---|---|
committer | martinp <martinp@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-12-19 18:06:29 +0000 |
commit | 13f7800712388e79866583ac20833397c290c919 (patch) | |
tree | 3997e72cf3a9689d8db898fd55da97c677d3f94c /file.c | |
parent | f803ef19f9a9d3fd813274f76b7ffcdea4b00965 (diff) |
Add voicemail prepending feature plus forwarding to many extensions if you specify exten1*exten2*.....#
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1872 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'file.c')
-rwxr-xr-x | file.c | 68 |
1 files changed, 64 insertions, 4 deletions
@@ -499,6 +499,15 @@ struct ast_filestream *ast_openvstream(struct ast_channel *chan, char *filename, return NULL; } +struct ast_frame *ast_readframe(struct ast_filestream *s) +{ + struct ast_frame *f = NULL; + int whennext = 0; + if (s && s->fmt) + f = s->fmt->read(s, &whennext); + return f; +} + static int ast_readaudio_callback(void *data) { struct ast_filestream *s = data; @@ -726,10 +735,58 @@ int ast_streamfile(struct ast_channel *chan, char *filename, char *preflang) return -1; } +struct ast_filestream *ast_readfile(char *filename, char *type, char *comment, int flags, int check, mode_t mode) +{ + int fd,myflags = 0; + struct ast_format *f; + struct ast_filestream *fs=NULL; + char *fn; + char *ext; + if (ast_mutex_lock(&formatlock)) { + ast_log(LOG_WARNING, "Unable to lock format list\n"); + return NULL; + } + f = formats; + while(f) { + if (!strcasecmp(f->name, type)) { + char *stringp=NULL; + /* XXX Implement check XXX */ + ext = strdup(f->exts); + stringp=ext; + ext = strsep(&stringp, "|"); + fn = build_filename(filename, ext); + fd = open(fn, flags | myflags); + if (fd >= 0) { + errno = 0; + if ((fs = f->open(fd))) { + fs->trans = NULL; + fs->fmt = f; + fs->flags = flags; + fs->mode = mode; + fs->filename = strdup(filename); + fs->vfs = NULL; + } else { + ast_log(LOG_WARNING, "Unable to open %s\n", fn); + close(fd); + unlink(fn); + } + } else if (errno != EEXIST) + ast_log(LOG_WARNING, "Unable to open file %s: %s\n", fn, strerror(errno)); + free(fn); + free(ext); + break; + } + f = f->next; + } + ast_mutex_unlock(&formatlock); + if (!f) + ast_log(LOG_WARNING, "No such format '%s'\n", type); + return fs; +} struct ast_filestream *ast_writefile(char *filename, char *type, char *comment, int flags, int check, mode_t mode) { - int fd,myflags; + int fd,myflags = 0; struct ast_format *f; struct ast_filestream *fs=NULL; char *fn; @@ -738,9 +795,12 @@ struct ast_filestream *ast_writefile(char *filename, char *type, char *comment, ast_log(LOG_WARNING, "Unable to lock format list\n"); return NULL; } - myflags = 0; /* set the O_TRUNC flag if and only if there is no O_APPEND specified */ - if (!(flags & O_APPEND)) myflags = O_TRUNC; + if (!(flags & O_APPEND)) + myflags = O_TRUNC; + + myflags |= O_WRONLY | O_CREAT; + f = formats; while(f) { if (!strcasecmp(f->name, type)) { @@ -750,7 +810,7 @@ struct ast_filestream *ast_writefile(char *filename, char *type, char *comment, stringp=ext; ext = strsep(&stringp, "|"); fn = build_filename(filename, ext); - fd = open(fn, flags | myflags | O_WRONLY | O_CREAT, mode); + fd = open(fn, flags | myflags, mode); if (fd >= 0) { errno = 0; if ((fs = f->rewrite(fd, comment))) { |