mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-19 00:00:09 +00:00
make sure that file calls other than OPEN work on all formats
if called with a NULL 'fmt' argument. (SVN 6898) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@17859 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
74
file.c
74
file.c
@@ -355,11 +355,12 @@ enum file_action {
|
|||||||
* unused for EXISTS and DELETE
|
* unused for EXISTS and DELETE
|
||||||
* destination file name (const char *) for COPY and RENAME
|
* destination file name (const char *) for COPY and RENAME
|
||||||
* struct ast_channel * for OPEN
|
* struct ast_channel * for OPEN
|
||||||
|
* if fmt is NULL, OPEN will return the first matching entry,
|
||||||
|
* whereas other functions will run on all matching entries.
|
||||||
*/
|
*/
|
||||||
static int ast_filehelper(const char *filename, const void *arg2, const char *fmt, const enum file_action action)
|
static int ast_filehelper(const char *filename, const void *arg2, const char *fmt, const enum file_action action)
|
||||||
{
|
{
|
||||||
struct ast_format *f;
|
struct ast_format *f;
|
||||||
char *ext = NULL, *fn = NULL;
|
|
||||||
int res = (action == ACTION_EXISTS) ? 0 : -1;
|
int res = (action == ACTION_EXISTS) ? 0 : -1;
|
||||||
|
|
||||||
if (AST_LIST_LOCK(&formats)) {
|
if (AST_LIST_LOCK(&formats)) {
|
||||||
@@ -368,7 +369,7 @@ static int ast_filehelper(const char *filename, const void *arg2, const char *fm
|
|||||||
}
|
}
|
||||||
/* Check for a specific format */
|
/* Check for a specific format */
|
||||||
AST_LIST_TRAVERSE(&formats, f, list) {
|
AST_LIST_TRAVERSE(&formats, f, list) {
|
||||||
char *stringp;
|
char *stringp, *ext = NULL;
|
||||||
|
|
||||||
if (fmt && !exts_compare(f->exts, fmt))
|
if (fmt && !exts_compare(f->exts, fmt))
|
||||||
continue;
|
continue;
|
||||||
@@ -377,10 +378,11 @@ static int ast_filehelper(const char *filename, const void *arg2, const char *fm
|
|||||||
* The file must exist, and for OPEN, must match
|
* The file must exist, and for OPEN, must match
|
||||||
* one of the formats supported by the channel.
|
* one of the formats supported by the channel.
|
||||||
*/
|
*/
|
||||||
stringp = ast_strdupa(f->exts);
|
stringp = ast_strdupa(f->exts); /* this is in the stack so does not need to be freed */
|
||||||
while ( (ext = strsep(&stringp, "|")) ) {
|
while ( (ext = strsep(&stringp, "|")) ) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
fn = build_filename(filename, ext);
|
char *fn = build_filename(filename, ext);
|
||||||
|
|
||||||
if (fn == NULL)
|
if (fn == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -427,44 +429,42 @@ static int ast_filehelper(const char *filename, const void *arg2, const char *fm
|
|||||||
chan->stream = s;
|
chan->stream = s;
|
||||||
else
|
else
|
||||||
chan->vstream = s;
|
chan->vstream = s;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break; /* found the file */
|
switch (action) {
|
||||||
}
|
case ACTION_OPEN:
|
||||||
if (ext)
|
break; /* will never get here */
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (ext) { /* break out on a valid 'ext', so fn is also valid */
|
|
||||||
char *nfn;
|
|
||||||
|
|
||||||
switch (action) {
|
case ACTION_EXISTS: /* return the matching format */
|
||||||
case ACTION_EXISTS: /* return the matching format */
|
res |= f->format;
|
||||||
res |= f->format;
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case ACTION_DELETE:
|
case ACTION_DELETE:
|
||||||
if ( (res = unlink(fn)) )
|
if ( (res = unlink(fn)) )
|
||||||
ast_log(LOG_WARNING, "unlink(%s) failed: %s\n", fn, strerror(errno));
|
ast_log(LOG_WARNING, "unlink(%s) failed: %s\n", fn, strerror(errno));
|
||||||
break;
|
break;
|
||||||
case ACTION_RENAME:
|
|
||||||
case ACTION_COPY:
|
case ACTION_RENAME:
|
||||||
nfn = build_filename((const char *)arg2, ext);
|
case ACTION_COPY: {
|
||||||
if (!nfn)
|
char *nfn = build_filename((const char *)arg2, ext);
|
||||||
ast_log(LOG_WARNING, "Out of memory\n");
|
if (!nfn)
|
||||||
else {
|
ast_log(LOG_WARNING, "Out of memory\n");
|
||||||
res = action == ACTION_COPY ? copy(fn, nfn) : rename(fn, nfn);
|
else {
|
||||||
if (res)
|
res = action == ACTION_COPY ? copy(fn, nfn) : rename(fn, nfn);
|
||||||
ast_log(LOG_WARNING, "%s(%s,%s) failed: %s\n",
|
if (res)
|
||||||
action == ACTION_COPY ? "copy" : "rename",
|
ast_log(LOG_WARNING, "%s(%s,%s) failed: %s\n",
|
||||||
fn, nfn, strerror(errno));
|
action == ACTION_COPY ? "copy" : "rename",
|
||||||
free(nfn);
|
fn, nfn, strerror(errno));
|
||||||
|
free(nfn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ast_log(LOG_WARNING, "Unknown helper %d\n", action);
|
||||||
}
|
}
|
||||||
break;
|
free(fn);
|
||||||
case ACTION_OPEN: /* all done already! */
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ast_log(LOG_WARNING, "Unknown helper %d\n", action);
|
|
||||||
}
|
}
|
||||||
free(fn);
|
|
||||||
}
|
}
|
||||||
AST_LIST_UNLOCK(&formats);
|
AST_LIST_UNLOCK(&formats);
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
Reference in New Issue
Block a user