54 #include "asterisk/stasis_system.h"
74 static struct ast_json *json_array_from_list(
const char *list,
const char *sep)
80 if (!array || !stringp) {
84 while ((ext = strsep(&stringp, sep))) {
105 "extensions", json_array_from_list(f->
exts,
"|"));
129 AST_RWLIST_TRAVERSE(&
formats, tmp, list) {
130 if (!strcasecmp(f->
name, tmp->
name)) {
132 ast_log(LOG_WARNING,
"Tried to register '%s' format, already registered\n", f->
name);
147 struct _test_align {
void *a, *b; } p;
148 int align = (
char *)&p.b - (
char *)&p.a;
152 memset(&tmp->
list, 0,
sizeof(tmp->
list));
154 AST_RWLIST_INSERT_HEAD(&
formats, tmp, list);
156 ast_verb(5,
"Registered file format %s, extension(s) %s\n", f->
name, f->
exts);
168 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&
formats, tmp, list) {
169 if (!strcasecmp(name, tmp->
name)) {
170 AST_RWLIST_REMOVE_CURRENT(list);
176 AST_RWLIST_TRAVERSE_SAFE_END;
180 ast_verb(5,
"Unregistered format %s\n", name);
182 ast_log(LOG_WARNING,
"Tried to unregister format %s, already unregistered\n", name);
190 int pfd = mkstemp(template_name);
191 chmod(template_name, mode);
193 p = fdopen(pfd,
"w+");
206 if (
ast_asprintf(filename,
"%s/%s", path, template_name) < 0) {
207 ast_log(LOG_ERROR,
"Failed to set up temporary file path\n");
213 if ((fd = mkstemp(*filename)) < 0) {
214 ast_log(LOG_NOTICE,
"Failed to create temporary file\n");
224 ast_channel_lock(tmp);
227 if (ast_channel_stream(tmp)) {
229 ast_channel_stream_set(tmp, NULL);
230 if (ast_channel_oldwriteformat(tmp) &&
ast_set_write_format(tmp, ast_channel_oldwriteformat(tmp)))
231 ast_log(LOG_WARNING,
"Unable to restore format back to %s\n",
ast_format_get_name(ast_channel_oldwriteformat(tmp)));
234 if (ast_channel_vstream(tmp) != NULL) {
236 ast_channel_vstream_set(tmp, NULL);
239 ast_channel_unlock(tmp);
250 if (!fs->
vfs && fs->filename) {
253 ast_debug(1,
"Opened video output file\n");
261 ast_log(LOG_WARNING,
"Tried to write non-voice frame\n");
267 ast_log(LOG_WARNING,
"Natural write failed\n");
269 ast_log(LOG_WARNING,
"Huh??\n");
281 ast_log(LOG_WARNING,
"Unable to translate to format %s, source format %s\n",
292 if ((res = fs->
fmt->
write(fs, trf))) {
293 ast_log(LOG_WARNING,
"Translated frame write failed\n");
306 static int copy(
const char *infile,
const char *outfile)
311 if ((ifd = open(infile, O_RDONLY)) < 0) {
312 ast_log(LOG_WARNING,
"Unable to open %s in read-only mode\n", infile);
315 if ((ofd = open(outfile, O_WRONLY | O_TRUNC | O_CREAT, AST_FILE_MODE)) < 0) {
316 ast_log(LOG_WARNING,
"Unable to open %s in write-only mode\n", outfile);
320 while ( (len = read(ifd, buf,
sizeof(buf)) ) ) {
323 ast_log(LOG_WARNING,
"Read failed on %s: %s\n", infile, strerror(errno));
327 res = write(ofd, buf, len);
329 ast_log(LOG_WARNING,
"Write failed on %s (%d of %d): %s\n", outfile, res, len, strerror(errno));
355 if (!strcmp(ext,
"wav49"))
358 if (filename[0] ==
'/') {
364 ast_config_AST_DATA_DIR, filename, ext) < 0) {
373 static int type_in_list(
const char *list,
const char *type,
int (*cmp)(
const char *s1,
const char *s2))
377 while ((item = strsep(&stringp,
"|"))) {
378 if (!cmp(item, type)) {
386 #define exts_compare(list, type) (type_in_list((list), (type), strcmp))
403 case AST_MEDIA_TYPE_AUDIO:
404 ast_channel_stream_set(f->owner, NULL);
405 AST_SCHED_DEL_ACCESSOR(ast_channel_sched(f->owner), f->owner, ast_channel_streamid, ast_channel_streamid_set);
408 case AST_MEDIA_TYPE_VIDEO:
409 ast_channel_vstream_set(f->owner, NULL);
410 AST_SCHED_DEL_ACCESSOR(ast_channel_sched(f->owner), f->owner, ast_channel_vstreamid, ast_channel_vstreamid_set);
413 ast_log(AST_LOG_WARNING,
"Unable to schedule deletion of filestream with unsupported type %s\n", f->
fmt->
name);
418 static void filestream_destructor(
void *arg)
440 if (f->realfilename && f->filename) {
443 execl(
"/bin/mv",
"mv",
"-f", f->filename, f->realfilename, SENTINEL);
448 waitpid(pid, &status, 0);
452 ast_free(f->filename);
453 ast_free(f->realfilename);
456 ast_free(f->write_buffer);
457 ast_free((
void *)f->orig_chan_name);
458 ao2_cleanup(f->lastwriteformat);
472 s = ao2_alloc(l, filestream_destructor);
483 s->
buf = (
char *)(s + 1);
501 enum wrap_fn { WRAP_OPEN, WRAP_REWRITE };
503 static int fn_wrapper(
struct ast_filestream *s,
const char *comment,
enum wrap_fn mode)
509 if (mode == WRAP_OPEN && (openfn = f->
open) && openfn(s))
510 ast_log(LOG_WARNING,
"Unable to open format %s\n", f->
name);
511 else if (mode == WRAP_REWRITE && f->
rewrite && f->
rewrite(s, comment))
512 ast_log(LOG_WARNING,
"Unable to rewrite format %s\n", f->
name);
520 static int rewrite_wrapper(
struct ast_filestream *s,
const char *comment)
522 return fn_wrapper(s, comment, WRAP_REWRITE);
527 return fn_wrapper(s, NULL, WRAP_OPEN);
549 static int filehelper(
const char *filename,
const void *arg2,
const char *fmt,
const enum file_action action)
552 int res = (action == ACTION_EXISTS) ? 0 : -1;
556 AST_RWLIST_TRAVERSE(&
formats, f, list) {
558 char storage[strlen(f->
exts) + 1];
561 if (fmt && !exts_compare(f->
exts, fmt))
568 strcpy(storage, f->
exts);
570 while ( (ext = strsep(&stringp,
"|")) ) {
577 if ( stat(fn, &st) ) {
584 if (action == ACTION_OPEN) {
595 if ( (bfile = fopen(fn,
"r")) == NULL) {
599 s = get_filestream(f, bfile);
605 if (open_wrapper(s)) {
610 if (st.st_size == 0) {
611 ast_log(LOG_WARNING,
"File %s detected to have zero size.\n", fn);
620 if (ast_channel_stream(chan))
622 ast_channel_stream_set(chan, s);
624 if (ast_channel_vstream(chan))
626 ast_channel_vstream_set(chan, s);
645 if ( (res = unlink(fn)) )
646 ast_log(LOG_WARNING,
"unlink(%s) failed: %s\n", fn, strerror(errno));
653 ast_log(LOG_WARNING,
"Out of memory\n");
655 res = action == ACTION_COPY ?
copy(fn, nfn) : rename(fn, nfn);
657 ast_log(LOG_WARNING,
"%s(%s,%s) failed: %s\n",
658 action == ACTION_COPY ?
"copy" :
"rename",
659 fn, nfn, strerror(errno));
666 ast_log(LOG_WARNING,
"Unknown helper %u\n", action);
675 static int is_absolute_path(
const char *filename)
677 return filename[0] ==
'/';
680 static int is_remote_path(
const char *filename)
682 return strstr(filename,
"://") ? 1 : 0;
699 return filehelper(buf, result_cap, NULL, ACTION_EXISTS);
704 snprintf(buf, buflen,
"%s/%s", lang, filename);
706 snprintf(buf, buflen,
"%s", filename);
709 strcpy(buf, filename);
712 const char *c = strrchr(filename,
'/');
713 int offset = c ? c - filename + 1 : 0;
714 snprintf(buf + offset, buflen - offset,
"%s/%s", lang, filename + offset);
718 return filehelper(buf, result_cap, fmt, ACTION_EXISTS);
741 static int fileexists_core(
const char *filename,
const char *fmt,
const char *preflang,
760 while (!ast_strlen_zero(lang)) {
767 if ((end = strrchr(lang,
'_')) != NULL) {
781 if ((ast_strlen_zero(preflang) || strcmp(preflang, DEFAULT_LANGUAGE)) && (ast_strlen_zero(lang) || strcmp(lang, DEFAULT_LANGUAGE))) {
782 if ((
fileexists_test(filename, fmt, DEFAULT_LANGUAGE, buf, buflen, result_cap)) > 0) {
796 const char *filename,
const char *preflang,
int asis)
811 if (ast_channel_generator(chan))
814 if (preflang == NULL)
816 buflen = strlen(preflang) + strlen(filename) + 4;
822 if (!
fileexists_core(filename, NULL, preflang, buf, buflen, file_fmt_cap) ||
825 ast_log(LOG_WARNING,
"File %s does not exist in any format\n", filename);
831 ast_channel_lock(chan);
832 ast_channel_set_oldwriteformat(chan, ast_channel_writeformat(chan));
835 ast_channel_unlock(chan);
842 res = filehelper(buf, chan, NULL, ACTION_OPEN);
844 return ast_channel_stream(chan);
849 const char *filename,
const char *preflang)
859 if (preflang == NULL) {
862 buflen = strlen(preflang) + strlen(filename) + 4;
865 ast_channel_lock(chan);
866 nativeformats =
ao2_bump(ast_channel_nativeformats(chan));
867 ast_channel_unlock(chan);
871 ao2_cleanup(nativeformats);
875 ao2_cleanup(nativeformats);
879 if (!
fileexists_core(filename, NULL, preflang, buf, buflen, tmp_cap)) {
881 ao2_cleanup(nativeformats);
899 ao2_cleanup(nativeformats);
900 return ast_channel_vstream(chan);
902 ast_log(LOG_WARNING,
"File %s has video but couldn't be opened\n", filename);
906 ao2_cleanup(nativeformats);
919 if (!(fr = s->
fmt->
read(s, whennext))) {
940 return read_frame(s, &whennext);
945 FSREAD_SUCCESS_SCHED,
946 FSREAD_SUCCESS_NOSCHED,
949 static int ast_fsread_audio(
const void *
data);
951 static enum fsread_res ast_readaudio_callback(
struct ast_filestream *s)
958 if (s->orig_chan_name && strcasecmp(ast_channel_name(s->owner), s->orig_chan_name)) {
962 fr = read_frame(s, &whennext);
977 if (whennext != s->lasttimeout) {
978 if (ast_channel_timingfd(s->owner) > -1) {
982 rate = (
unsigned int) roundf(samp_rate / ((
float) whennext));
984 ast_settimeout_full(s->owner, rate, ast_fsread_audio, s, 1);
988 s->lasttimeout = whennext;
989 return FSREAD_SUCCESS_NOSCHED;
991 return FSREAD_SUCCESS_SCHED;
994 ast_channel_streamid_set(s->owner, -1);
996 return FSREAD_FAILURE;
999 static int ast_fsread_audio(
const void *
data)
1002 enum fsread_res res;
1004 res = ast_readaudio_callback(fs);
1006 if (res == FSREAD_SUCCESS_SCHED)
1012 static int ast_fsread_video(
const void *data);
1014 static enum fsread_res ast_readvideo_callback(
struct ast_filestream *s)
1019 struct ast_frame *fr = read_frame(s, &whennext);
1023 ast_debug(2,
"Failed to write frame\n");
1026 ast_channel_vstreamid_set(s->owner, -1);
1027 return FSREAD_FAILURE;
1035 if (whennext != s->lasttimeout) {
1037 s->lasttimeout = whennext;
1038 return FSREAD_SUCCESS_NOSCHED;
1041 return FSREAD_SUCCESS_SCHED;
1044 static int ast_fsread_video(
const void *data)
1047 enum fsread_res res;
1049 res = ast_readvideo_callback(fs);
1051 if (res == FSREAD_SUCCESS_SCHED)
1065 enum fsread_res res;
1068 res = ast_readaudio_callback(s);
1070 res = ast_readvideo_callback(s);
1072 return (res == FSREAD_FAILURE) ? -1 : 0;
1077 return fs->
fmt->
seek(fs, sample_offset, whence);
1097 return ast_seekstream(fs, ms * DEFAULT_SAMPLES_PER_MS, SEEK_CUR);
1103 if (ms * DEFAULT_SAMPLES_PER_MS > offset) {
1105 ast_debug(1,
"Restarting, rather than seeking to negative offset %ld\n", (
long) (offset - (ms * DEFAULT_SAMPLES_PER_MS)));
1108 return ast_seekstream(fs, -ms * DEFAULT_SAMPLES_PER_MS, SEEK_CUR);
1120 filestream_close(f);
1134 if (preflang == NULL)
1136 buflen = strlen(preflang) + strlen(filename) + 4;
1138 return fileexists_core(filename, fmt, preflang, buf, buflen, NULL) ? 1 : 0;
1143 return filehelper(filename, NULL, fmt, ACTION_DELETE);
1148 return filehelper(filename, filename2, fmt, ACTION_RENAME);
1151 int ast_filecopy(
const char *filename,
const char *filename2,
const char *fmt)
1153 return filehelper(filename, filename2, fmt, ACTION_COPY);
1156 static int __ast_file_read_dirs(
const char *path,
ast_file_on_file on_file,
1157 void *obj,
int max_depth)
1160 struct dirent *
entry;
1163 if (!(dir = opendir(path))) {
1164 ast_log(LOG_ERROR,
"Error opening directory - %s: %s\n",
1165 path, strerror(errno));
1173 while ((entry = readdir(dir)) != NULL && !errno) {
1176 RAII_VAR(
char *, full_path, NULL, ast_free);
1178 if (!strcmp(entry->d_name,
".") || !strcmp(entry->d_name,
"..")) {
1187 #ifdef _DIRENT_HAVE_D_TYPE
1188 if (entry->d_type != DT_UNKNOWN && entry->d_type != DT_LNK) {
1189 is_file = entry->d_type == DT_REG;
1190 is_dir = entry->d_type == DT_DIR;
1194 struct stat statbuf;
1200 full_path =
ast_malloc(strlen(path) + strlen(entry->d_name) + 2);
1204 sprintf(full_path,
"%s/%s", path, entry->d_name);
1206 if (stat(full_path, &statbuf)) {
1207 ast_log(LOG_ERROR,
"Error reading path stats - %s: %s\n",
1208 full_path, strerror(errno));
1216 is_file = S_ISREG(statbuf.st_mode);
1217 is_dir = S_ISDIR(statbuf.st_mode);
1222 if ((res = on_file(path, entry->d_name, obj))) {
1230 ast_debug(5,
"Skipping %s: not a regular file or directory\n", full_path);
1235 if (max_depth != 0) {
1238 full_path =
ast_malloc(strlen(path) + strlen(entry->d_name) + 2);
1242 sprintf(full_path,
"%s/%s", path, entry->d_name);
1245 if ((res = __ast_file_read_dirs(full_path, on_file, obj, max_depth))) {
1253 if (!res && errno) {
1254 ast_log(LOG_ERROR,
"Error while reading directories - %s: %s\n",
1255 path, strerror(errno));
1262 #if !defined(__GLIBC__)
1280 #if !defined(__GLIBC__)
1284 res = __ast_file_read_dirs(dir_name, on_file, obj, max_depth);
1286 #if !defined(__GLIBC__)
1294 const char *preflang)
1301 char custom_filename[256];
1307 if (ast_opt_sounds_search_custom && !is_absolute_path(filename)) {
1308 memset(custom_filename, 0,
sizeof(custom_filename));
1309 snprintf(custom_filename,
sizeof(custom_filename),
"custom/%s", filename);
1312 tmp_filename = custom_filename;
1313 ast_debug(3,
"Found file %s in custom directory\n", filename);
1321 ast_channel_lock(chan);
1322 ast_log(LOG_WARNING,
"Unable to open %s (format %s): %s\n",
1324 ast_channel_unlock(chan);
1327 tmp_filename = (
char *)filename;
1333 pos = ftello(fs->f);
1334 seekattempt = fseeko(fs->f, -1, SEEK_END);
1336 if (errno == EINVAL) {
1343 fseeko(fs->f, pos, SEEK_SET);
1352 fs->orig_chan_name =
ast_strdup(ast_channel_name(chan));
1362 if (VERBOSITY_ATLEAST(3)) {
1363 ast_channel_lock(chan);
1364 ast_verb(3,
"<%s> Playing '%s.%s' (language '%s')\n", ast_channel_name(chan), tmp_filename,
ast_format_get_name(ast_channel_writeformat(chan)), preflang ? preflang :
"default");
1365 ast_channel_unlock(chan);
1377 int format_found = 0;
1381 AST_RWLIST_TRAVERSE(&
formats, f, list) {
1383 if (!exts_compare(f->
exts, type))
1393 bfile = fopen(fn,
"r");
1395 if (!bfile || (fs = get_filestream(f, bfile)) == NULL || open_wrapper(fs) ) {
1396 ast_log(LOG_WARNING,
"Unable to open %s\n", fn);
1418 ast_log(LOG_WARNING,
"No such format '%s'\n", type);
1425 int fd, myflags = 0;
1432 int format_found = 0;
1438 if (flags & O_APPEND) {
1444 myflags |= O_WRONLY | O_CREAT;
1449 AST_RWLIST_TRAVERSE(&
formats, f, list) {
1450 char *fn, *orig_fn = NULL;
1454 if (!exts_compare(f->
exts, type))
1463 fd = open(fn, flags | myflags, mode);
1466 bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ?
"w+" :
"w");
1468 ast_log(LOG_WARNING,
"Whoa, fdopen failed: %s!\n", strerror(errno));
1474 if (ast_opt_cache_record_files && (fd > -1)) {
1483 for (c = fn; *c; c++)
1487 size = strlen(fn) + strlen(record_cache_dir) + 2;
1489 strcpy(buf, record_cache_dir);
1494 fd = open(fn, flags | myflags, mode);
1497 bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ?
"w+" :
"w");
1499 ast_log(LOG_WARNING,
"Whoa, fdopen failed: %s!\n", strerror(errno));
1507 fs = get_filestream(f, bfile);
1509 if ((fs->write_buffer =
ast_malloc(32768))) {
1510 setvbuf(fs->f, fs->write_buffer, _IOFBF, 32768);
1513 if (!fs || rewrite_wrapper(fs, comment)) {
1514 ast_log(LOG_WARNING,
"Unable to rewrite %s\n", fn);
1538 fs->realfilename = orig_fn;
1547 fs->realfilename = NULL;
1552 f->
seek(fs, 0, SEEK_END);
1553 }
else if (errno != EEXIST) {
1554 ast_log(LOG_WARNING,
"Unable to open file %s: %s\n", fn, strerror(errno));
1566 ast_log(LOG_WARNING,
"No such format '%s'\n", type);
1571 static void waitstream_control(
struct ast_channel *c,
1578 case AST_WAITSTREAM_CB_FASTFORWARD:
1582 eoftest = fgetc(ast_channel_stream(c)->f);
1583 if (feof(ast_channel_stream(c)->f)) {
1586 ungetc(eoftest, ast_channel_stream(c)->f);
1590 case AST_WAITSTREAM_CB_REWIND:
1599 cb(c, ms_len, type);
1605 ast_channel_name(c),
1606 (type == AST_WAITSTREAM_CB_FASTFORWARD) ?
"FastForward" :
"Rewind",
1614 const char *breakon,
1615 const char *forward,
1616 const char *reverse,
1620 const char *context,
1623 const char *orig_chan_name = NULL;
1638 orig_chan_name =
ast_strdupa(ast_channel_name(c));
1640 if (ast_channel_stream(c) && cb) {
1642 cb(c, ms_len, AST_WAITSTREAM_CB_START);
1645 while (ast_channel_stream(c)) {
1649 if (orig_chan_name && strcasecmp(orig_chan_name, ast_channel_name(c))) {
1657 if (ms < 0 && !ast_channel_timingfunc(c)) {
1666 ast_log(LOG_WARNING,
"Select failed (%s)\n", strerror(errno));
1673 if (!rchan && (outfd < 0) && (ms)) {
1677 ast_log(LOG_WARNING,
"Wait failed (%s)\n", strerror(errno));
1680 }
else if (outfd > -1) {
1686 res = rchan ? 1 : 0;
1699 S_COR(ast_channel_caller(c)->
id.
number.valid, ast_channel_caller(c)->
id.
number.str, NULL))) {
1707 if (strchr(forward, res)) {
1708 waitstream_control(c, AST_WAITSTREAM_CB_FASTFORWARD, cb, skip_ms);
1709 }
else if (strchr(reverse, res)) {
1710 waitstream_control(c, AST_WAITSTREAM_CB_REWIND, cb, skip_ms);
1711 }
else if (strchr(breakon, res)) {
1714 ast_channel_name(c),
1731 ast_channel_name(c),
1741 waitstream_control(c, AST_WAITSTREAM_CB_REWIND, cb, skip_ms);
1747 waitstream_control(c, AST_WAITSTREAM_CB_FASTFORWARD, cb, skip_ms);
1774 ast_log(LOG_WARNING,
"Unexpected control subclass '%d'\n", fr->
subclass.
integer);
1780 if (write(audiofd, fr->
data.ptr, fr->
datalen) < 0) {
1781 ast_log(LOG_WARNING,
"write() failed: %s\n", strerror(errno));
1795 return (err || ast_channel_softhangup_internal_flag(c)) ? -1 : 0;
1799 const char *breakon,
1800 const char *forward,
1801 const char *reverse,
1806 -1 , -1 , NULL , cb);
1812 -1 , -1 , NULL , NULL );
1823 static int sanitize_waitstream_return(
int return_value)
1825 switch (return_value) {
1837 return return_value;
1844 res =
waitstream_core(c, breakon, NULL, NULL, 0, -1, -1, NULL, NULL );
1846 return sanitize_waitstream_return(res);
1854 audiofd, cmdfd, NULL , NULL );
1856 return sanitize_waitstream_return(res);
1866 context = ast_channel_context(c);
1868 -1, -1, context, NULL );
1870 return sanitize_waitstream_return(res);
1881 if (!ast_strlen_zero(file)) {
1899 char *stringp, *type;
1901 int i, j, x, first, found = 0;
1902 int len = strlen(fmts) + 1;
1906 ast_log(LOG_WARNING,
"Unable to lock format list\n");
1912 for (x = 0; (type = strsep(&stringp,
"|")) && x <
AST_MAX_FORMATS; x++) {
1913 AST_RWLIST_TRAVERSE(&
formats, f, list) {
1914 if (exts_compare(f->
exts, type)) {
1930 for (i = 0; i < x; i++) {
1933 ast_log(LOG_WARNING,
"ignoring unknown format '%s'\n", fmts_str[i]);
1939 res = snprintf(fmts, len,
"%s", fmts_str[i]);
1947 for (j = 0; j < i; j++) {
1949 if (fmts_ptr[j] == fmts_ptr[i]) {
1956 res = snprintf(fmts, len,
"|%s", fmts_str[i]);
1963 ast_log(LOG_WARNING,
"no known formats found in format list (%s)\n", orig);
1972 #define FORMAT "%-10s %-10s %-20s\n"
1973 #define FORMAT2 "%-10s %-10s %-20s\n"
1979 e->
command =
"core show file formats";
1981 "Usage: core show file formats\n"
1982 " Displays currently registered file formats (if any).\n";
1989 return CLI_SHOWUSAGE;
1991 ast_cli(a->fd, FORMAT,
"Format",
"Name",
"Extensions");
1992 ast_cli(a->fd, FORMAT,
"------",
"----",
"----------");
1995 AST_RWLIST_TRAVERSE(&
formats, f, list) {
2000 ast_cli(a->fd,
"%d file formats registered.\n", count_fmt);
2010 AST_RWLIST_TRAVERSE(&
formats, f, list) {
2011 if (exts_compare(f->
exts, file_ext)) {
2024 ast_assert(buffer && capacity);
2026 AST_RWLIST_TRAVERSE(&
formats, f, list) {
2027 if (type_in_list(f->
mime_types, mime_type, strcasecmp)) {
2028 size_t item_len = strcspn(f->
exts,
"|");
2029 size_t bytes_written = snprintf(buffer, capacity,
".%.*s", (
int) item_len, f->
exts);
2030 if (bytes_written < capacity) {
2041 AST_CLI_DEFINE(handle_cli_core_show_file_formats,
"Displays file formats")
2044 static void file_shutdown(
void)
Main Channel structure associated with a channel.
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
void( ast_waitstream_fr_cb)(struct ast_channel *chan, long ms, enum ast_waitstream_fr_cb_values val)
callback used during dtmf controlled file playback to indicate location of playback in a file after r...
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
struct stasis_topic * ast_system_topic(void)
A Stasis Message Bus API topic which publishes messages regarding system changes. ...
int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence)
Seeks into stream.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
static int waitstream_core(struct ast_channel *c, const char *breakon, const char *forward, const char *reverse, int skip_ms, int audiofd, int cmdfd, const char *context, ast_waitstream_fr_cb cb)
the core of all waitstream() functions
int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int cmdfd)
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
int ast_filecopy(const char *filename, const char *filename2, const char *fmt)
Copies a file.
int ast_waitstream_exten(struct ast_channel *c, const char *context)
Waits for a stream to stop or digit matching a valid one digit exten to be pressed.
struct ast_json_payload * ast_json_payload_create(struct ast_json *json)
Create an ao2 object to pass json blobs as data payloads for stasis.
Support for translation of data formats. translate.c.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
descriptor for a cli entry.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
int ast_stream_rewind(struct ast_filestream *fs, off_t ms)
Rewind stream ms.
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
Clear a flag on a channel.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
static int fileexists_core(const char *filename, const char *fmt, const char *preflang, char *buf, int buflen, struct ast_format_cap *result_cap)
helper routine to locate a file with a given format and language preference.
ast_waitstream_fr_cb_values
#define ast_cli_register_multiple(e, len)
Register multiple commands.
int ast_filedelete(const char *filename, const char *fmt)
Deletes a file.
static ast_mutex_t read_dirs_lock
Lock to hold when iterating over directories.
static int copy(char *infile, char *outfile)
Utility function to copy a file.
struct ast_frame * ast_translate(struct ast_trans_pvt *tr, struct ast_frame *f, int consume)
translates one or more frames Apply an input frame into the translator and receive zero or one output...
struct ast_channel * ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds, int nfds, int *exception, int *outfd, int *ms)
Waits for activity on a group of channels.
#define ast_strdup(str)
A wrapper for strdup()
int ast_closestream(struct ast_filestream *f)
Closes a stream.
int ast_waitstream_fr(struct ast_channel *c, const char *breakon, const char *forward, const char *reverse, int ms)
Same as waitstream but allows stream to be forwarded or rewound.
int ast_playstream(struct ast_filestream *s)
Play a open stream on a channel.
struct ast_frame_subclass subclass
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
struct ast_filestream * ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang)
Opens stream for use in seeking, playing.
int ast_filerename(const char *filename, const char *filename2, const char *fmt)
Renames a file.
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
#define SCOPED_RDLOCK(varname, lock)
scoped lock specialization for read locks
int ast_writestream(struct ast_filestream *fs, struct ast_frame *f)
Writes a frame to a stream.
struct ast_filestream * ast_openstream_full(struct ast_channel *chan, const char *filename, const char *preflang, int asis)
Opens stream for use in seeking, playing.
struct ast_filestream * ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
Starts writing a file.
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
int ast_set_write_format_from_cap(struct ast_channel *chan, struct ast_format_cap *formats)
Sets write format on channel chan Set write format for channel to whichever component of "format" is ...
int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
Checks for the existence of a given file.
off_t ast_tellstream(struct ast_filestream *fs)
Tell where we are in a stream.
static char * build_filename(const char *filename, const char *ext)
construct a filename. Absolute pathnames are preserved, relative names are prefixed by the sounds/ di...
struct ast_trans_pvt * ast_translator_build_path(struct ast_format *dest, struct ast_format *source)
Builds a translator path Build a path (possibly NULL) from source to dest.
General Asterisk PBX channel definitions.
struct ast_filestream * ast_readfile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
Starts reading from a file.
Asterisk JSON abstraction layer.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Asterisk file paths, configured in asterisk.conf.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
#define ast_strdupa(s)
duplicate a string in memory from the stack
char * ast_format_str_reduce(char *fmts)
int ast_file_read_dirs(const char *dir_name, ast_file_on_file on_file, void *obj, int max_depth)
Recursively iterate through files and directories up to max_depth.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
int ast_settimeout(struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data)
Enable or disable timer ticks for a channel.
Scheduler Routines (derived from cheops)
struct ast_format_def * fmt
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
int ast_ratestream(struct ast_filestream *fs)
Return the sample rate of the stream's format.
struct ast_frame fr
frame produced by read, typically
A set of macros to manage forward-linked lists.
#define ast_malloc(len)
A wrapper for malloc()
#define ast_debug(level,...)
Log a DEBUG message.
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
int ast_get_extension_for_mime_type(const char *mime_type, char *buffer, size_t capacity)
Get a suitable filename extension for the given MIME type.
Core PBX routines and definitions.
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
int ast_applystream(struct ast_channel *chan, struct ast_filestream *s)
Applies a open stream to a channel.
#define ast_test_suite_event_notify(s, f,...)
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
int(* ast_file_on_file)(const char *dir_name, const char *filename, void *obj)
Callback called for each file found when reading directories.
struct ast_filestream * ast_openvstream(struct ast_channel *chan, const char *filename, const char *preflang)
Opens stream for use in seeking, playing.
#define STASIS_MESSAGE_TYPE_DEFN(name,...)
Boiler-plate messaging macro for defining public message types.
Support for dynamic strings.
int ast_stopstream(struct ast_channel *tmp)
Stops a stream.
void ast_channel_set_flag(struct ast_channel *chan, unsigned int flag)
Set a flag on a channel.
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
int ast_truncstream(struct ast_filestream *fs)
Trunc stream at current location.
int ast_streamfile(struct ast_channel *chan, const char *filename, const char *preflang)
Streams a file.
int ast_safe_fork(int stop_reaper)
Common routine to safely fork without a chance of a signal handler firing badly in the child...
struct ast_trans_pvt * trans
int ast_format_def_unregister(const char *name)
Unregisters a file format.
FILE * ast_file_mkftemp(char *template_name, mode_t mode)
same as mkstemp, but return a FILE
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
union ast_frame::@224 data
#define ast_calloc(num, len)
A wrapper for calloc()
static int fileexists_test(const char *filename, const char *fmt, const char *lang, char *buf, int buflen, struct ast_format_cap *result_cap)
test if a file exists for a given format.
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Prototypes for public functions only of internal interest,.
#define ast_frisolate(fr)
Makes a frame independent of any static storage.
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event.
#define ast_module_unref(mod)
Release a reference to the module.
#define ast_module_running_ref(mod)
Hold a reference to the module if it is running.
struct ast_format * ast_get_format_for_file_ext(const char *file_ext)
Get the ast_format associated with the given file extension.
void ast_deactivate_generator(struct ast_channel *chan)
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Standard Command Line Interface.
int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits)
stream file until digit If the file name is non-empty, try to play it.
int ast_waitstream_fr_w_cb(struct ast_channel *c, const char *breakon, const char *forward, const char *reverse, int ms, ast_waitstream_fr_cb cb)
Same as waitstream_fr but allows a callback to be alerted when a user fastforwards or rewinds the fil...
int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place.
Data structure associated with a single frame of data.
struct ast_frame * ast_readframe(struct ast_filestream *s)
Read a frame from a filestream.
Abstract JSON element (object, array, string, int, ...).
int __ast_format_def_register(const struct ast_format_def *f, struct ast_module *mod)
Register a new file format capability. Adds a format to Asterisk's format abilities.
ast_media_type
Types of media.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
enum ast_frame_type frametype
struct ast_filestream * vfs
struct ast_format * format
Asterisk module definitions.
int ast_language_is_prefix
The following variable controls the layout of localized sound files. If 0, use the historical layout ...
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int ast_stream_fastforward(struct ast_filestream *fs, off_t ms)
Fast forward stream ms.
void ast_translator_free_path(struct ast_trans_pvt *tr)
Frees a translator path Frees the given translator path structure.
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
int ast_file_fdtemp(const char *path, char **filename, const char *template_name)
Create a temporary file located at path.