80 if (!
array || !stringp) {
84 while ((ext =
strsep(&stringp, sep))) {
130 if (!strcasecmp(f->
name, tmp->
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));
156 ast_verb(2,
"Registered file format %s, extension(s) %s\n", f->
name, f->
exts);
169 if (!strcasecmp(name, tmp->
name)) {
180 ast_verb(2,
"Unregistered format %s\n", name);
218 ast_debug(1,
"Opened video output file\n");
257 if ((res = fs->
fmt->
write(fs, trf))) {
271 static int copy(
const char *infile,
const char *outfile)
276 if ((ifd = open(infile, O_RDONLY)) < 0) {
280 if ((ofd = open(outfile, O_WRONLY | O_TRUNC | O_CREAT,
AST_FILE_MODE)) < 0) {
285 while ( (len = read(ifd, buf,
sizeof(buf)) ) ) {
292 res = write(ofd, buf, len);
320 if (!strcmp(ext,
"wav49"))
323 if (filename[0] ==
'/') {
338 static int type_in_list(
const char *list,
const char *
type,
int (*cmp)(
const char *s1,
const char *s2))
343 if (!cmp(
item, type)) {
351 #define exts_compare(list, type) (type_in_list((list), (type), strcmp)) 413 waitpid(pid, &status, 0);
448 s->
buf = (
char *)(s + 1);
476 else if (mode == WRAP_REWRITE && f->
rewrite && f->
rewrite(s, comment))
523 char storage[strlen(f->
exts) + 1];
533 strcpy(storage, f->
exts);
535 while ( (ext =
strsep(&stringp,
"|")) ) {
542 if ( stat(fn, &st) ) {
560 if ( (bfile = fopen(fn,
"r")) ==
NULL) {
575 if (st.st_size == 0) {
610 if ( (res = unlink(fn)) )
624 fn, nfn, strerror(
errno));
642 return filename[0] ==
'/';
647 return strstr(filename,
"://") ? 1 : 0;
669 snprintf(buf, buflen,
"%s/%s", lang, filename);
671 snprintf(buf, buflen,
"%s", filename);
674 strcpy(buf, filename);
677 const char *
c = strrchr(filename,
'/');
678 int offset = c ? c - filename + 1 : 0;
679 snprintf(buf + offset, buflen - offset,
"%s/%s", lang, filename + offset);
732 if ((end = strrchr(lang,
'_')) !=
NULL) {
778 if (preflang ==
NULL)
780 buflen = strlen(preflang) + strlen(filename) + 4;
822 if (preflang ==
NULL) {
825 buflen = strlen(preflang) + strlen(filename) + 4;
882 if (!(fr = s->
fmt->
read(s, whennext))) {
945 rate = (
unsigned int)
roundf(samp_rate / ((
float) whennext));
1040 return fs->
fmt->
seek(fs, sample_offset, whence);
1091 if (preflang ==
NULL)
1093 buflen = strlen(preflang) + strlen(filename) + 4;
1114 void *obj,
int max_depth)
1117 struct dirent *
entry;
1120 if (!(dir = opendir(path))) {
1122 path, strerror(
errno));
1130 while ((entry = readdir(dir)) !=
NULL && !
errno) {
1135 if (!strcmp(entry->d_name,
".") || !strcmp(entry->d_name,
"..")) {
1144 #ifdef _DIRENT_HAVE_D_TYPE 1145 if (entry->d_type != DT_UNKNOWN && entry->d_type != DT_LNK) {
1146 is_file = entry->d_type == DT_REG;
1147 is_dir = entry->d_type == DT_DIR;
1151 struct stat statbuf;
1157 full_path =
ast_malloc(strlen(path) + strlen(entry->d_name) + 2);
1161 sprintf(full_path,
"%s/%s", path, entry->d_name);
1163 if (stat(full_path, &statbuf)) {
1165 full_path, strerror(
errno));
1173 is_file = S_ISREG(statbuf.st_mode);
1174 is_dir = S_ISDIR(statbuf.st_mode);
1179 if ((res = on_file(path, entry->d_name, obj))) {
1187 ast_debug(5,
"Skipping %s: not a regular file or directory\n", full_path);
1192 if (max_depth != 0) {
1195 full_path =
ast_malloc(strlen(path) + strlen(entry->d_name) + 2);
1199 sprintf(full_path,
"%s/%s", path, entry->d_name);
1210 if (!res &&
errno) {
1212 path, strerror(
errno));
1219 #if !defined(__GLIBC__) 1237 #if !defined(__GLIBC__) 1243 #if !defined(__GLIBC__) 1271 pos = ftello(fs->
f);
1272 seekattempt = fseeko(fs->
f, -1, SEEK_END);
1274 if (
errno == EINVAL) {
1281 fseeko(fs->
f, pos, SEEK_SET);
1315 int format_found = 0;
1331 bfile = fopen(fn,
"r");
1363 int fd, myflags = 0;
1370 int format_found = 0;
1376 if (flags & O_APPEND) {
1382 myflags |= O_WRONLY | O_CREAT;
1388 char *fn, *orig_fn =
NULL;
1401 fd = open(fn, flags | myflags, mode);
1404 bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ?
"w+" :
"w");
1421 for (c = fn; *
c; c++)
1432 fd = open(fn, flags | myflags, mode);
1435 bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ?
"w+" :
"w");
1490 f->
seek(fs, 0, SEEK_END);
1491 }
else if (
errno != EEXIST) {
1537 cb(c, ms_len, type);
1552 const char *breakon,
1553 const char *forward,
1554 const char *reverse,
1611 if (!rchan && (outfd < 0) && (ms)) {
1618 }
else if (outfd > -1) {
1624 res = rchan ? 1 : 0;
1645 if (strchr(forward, res)) {
1647 }
else if (strchr(reverse, res)) {
1649 }
else if (strchr(breakon, res)) {
1735 const char *breakon,
1736 const char *forward,
1737 const char *reverse,
1742 -1 , -1 ,
NULL , cb);
1761 switch (return_value) {
1773 return return_value;
1804 -1, -1, context,
NULL );
1831 char *stringp, *
type;
1833 int i, j, x,
first, found = 0;
1834 int len = strlen(fmts) + 1;
1862 for (i = 0; i < x; i++) {
1871 res = snprintf(fmts, len,
"%s", fmts_str[i]);
1879 for (j = 0; j < i; j++) {
1881 if (fmts_ptr[j] == fmts_ptr[i]) {
1888 res = snprintf(fmts, len,
"|%s", fmts_str[i]);
1904 #define FORMAT "%-10s %-10s %-20s\n" 1905 #define FORMAT2 "%-10s %-10s %-20s\n" 1911 e->
command =
"core show file formats";
1913 "Usage: core show file formats\n" 1914 " Displays currently registered file formats (if any).\n";
1932 ast_cli(a->
fd,
"%d file formats registered.\n", count_fmt);
1960 size_t item_len = strcspn(f->
exts,
"|");
1961 size_t bytes_written = snprintf(buffer, capacity,
".%.*s", (
int) item_len, f->
exts);
1962 if (bytes_written < capacity) {
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
static enum fsread_res ast_readvideo_callback(struct ast_filestream *s)
int ast_channel_vstreamid(const struct ast_channel *chan)
#define ast_channel_lock(chan)
static char exten[AST_MAX_EXTENSION]
Main Channel structure associated with a channel.
#define AST_CLI_DEFINE(fn, txt,...)
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence)
Seeks into stream.
struct ast_filestream * ast_channel_vstream(const struct ast_channel *chan)
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)
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
void ast_channel_set_oldwriteformat(struct ast_channel *chan, struct ast_format *format)
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.
#define ast_test_flag(p, flag)
Support for translation of data formats. translate.c.
static struct ast_cli_entry cli_file[]
#define exts_compare(list, type)
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.
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
static void filestream_close(struct ast_filestream *f)
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
descriptor for a cli entry.
#define VERBOSITY_ATLEAST(level)
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
struct ast_format * ast_channel_oldwriteformat(struct ast_channel *chan)
int ast_settimeout_full(struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data, unsigned int is_ao2_obj)
int ast_stream_rewind(struct ast_filestream *fs, off_t ms)
Rewind stream ms.
static struct ast_filestream * get_filestream(struct ast_format_def *fmt, FILE *bfile)
void ast_channel_vstream_set(struct ast_channel *chan, struct ast_filestream *value)
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
static int rewrite_wrapper(struct ast_filestream *s, const char *comment)
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.
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.
static char * handle_cli_core_show_file_formats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static struct aco_type item
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.
#define ast_mutex_lock(a)
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...
#define ast_str_alloca(init_len)
#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.
void ast_cli(int fd, const char *fmt,...)
static void file_shutdown(void)
struct ast_channel * ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms)
Waits for activity on a group of channels.
#define ast_verb(level,...)
static int ast_fsread_video(const void *data)
struct ast_frame_subclass subclass
static int open_wrapper(struct ast_filestream *s)
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
#define ast_module_unref(mod)
Release a reference to the module.
#define ast_strlen_zero(foo)
void ast_channel_stream_set(struct ast_channel *chan, struct ast_filestream *value)
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 SCOPED_RDLOCK(varname, lock)
scoped lock specialization for read locks
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define AST_RWLIST_INSERT_HEAD
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.
#define ast_debug(level,...)
Log a DEBUG message.
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...
static int fn_wrapper(struct ast_filestream *s, const char *comment, enum wrap_fn mode)
static int is_absolute_path(const char *filename)
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.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
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 AST_RWLIST_TRAVERSE
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 ao2_ref(o, delta)
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
const char * orig_chan_name
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
#define AST_RWLIST_REMOVE_CURRENT
#define ast_strdupa(s)
duplicate a string in memory from the stack
A set of macros to manage forward-linked lists.
#define ast_malloc(len)
A wrapper for malloc()
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
#define AST_SCHED_DEL_ACCESSOR(sched, obj, getter, setter)
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.
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
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)
Applys 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_channel_timingfd(const struct ast_channel *chan)
const char * ast_config_AST_DATA_DIR
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.
struct ast_sched_context * ast_channel_sched(const struct ast_channel *chan)
struct ast_generator * ast_channel_generator(const struct ast_channel *chan)
static int filehelper(const char *filename, const void *arg2, const char *fmt, const enum file_action action)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
int ast_stopstream(struct ast_channel *tmp)
Stops a stream.
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...
void ast_channel_set_flag(struct ast_channel *chan, unsigned int flag)
Set a flag on a channel.
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)
int ast_channel_streamid(const struct ast_channel *chan)
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
static int sanitize_waitstream_return(int return_value)
int ast_truncstream(struct ast_filestream *fs)
Trunc stream at current location.
struct ast_channel * owner
void ast_channel_streamid_set(struct ast_channel *chan, int value)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
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 sla_ringing_trunk * first
#define ao2_alloc(data_size, destructor_fn)
struct stasis_topic * ast_system_topic(void)
A Stasis Message Bus API topic which publishes messages regarding system changes. ...
struct ast_trans_pvt * trans
int ast_format_def_unregister(const char *name)
Unregisters a file format.
#define ast_channel_unlock(chan)
#define ast_opt_cache_record_files
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
#define ast_calloc(num, len)
A wrapper for calloc()
struct ast_format * lastwriteformat
static struct ast_frame * read_frame(struct ast_filestream *s, int *whennext)
struct ast_filestream * ast_channel_stream(const struct ast_channel *chan)
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.
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
char record_cache_dir[AST_CACHE_DIR_LEN]
#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)
int ast_channel_softhangup_internal_flag(struct ast_channel *chan)
char * strsep(char **str, const char *delims)
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)
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Standard Command Line Interface.
const char * ast_channel_name(const struct ast_channel *chan)
#define DEFAULT_SAMPLES_PER_MS
static int ast_fsread_audio(const void *data)
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...
static void waitstream_control(struct ast_channel *c, enum ast_waitstream_fr_cb_values type, ast_waitstream_fr_cb cb, int skip_ms)
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.
const char * ast_channel_language(const struct ast_channel *chan)
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.
static enum fsread_res ast_readaudio_callback(struct ast_filestream *s)
static int __ast_file_read_dirs(const char *path, ast_file_on_file on_file, void *obj, int max_depth)
const char * ast_channel_context(const struct ast_channel *chan)
static int publish_format_update(const struct ast_format_def *f, struct stasis_message_type *type)
union ast_frame::@263 data
ast_media_type
Types of media.
enum ast_frame_type frametype
STASIS_MESSAGE_TYPE_DEFN(ast_format_register_type)
static int copy(const char *infile, const char *outfile)
struct ast_filestream * vfs
static char context[AST_MAX_CONTEXT]
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
static struct ast_json * json_array_from_list(const char *list, const char *sep)
struct ast_format * format
static int is_remote_path(const char *filename)
static void filestream_destructor(void *arg)
Asterisk module definitions.
int ast_language_is_prefix
The following variable controls the layout of localized sound files. If 0, use the historical layout ...
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan)
static snd_pcm_format_t format
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_channel_vstreamid_set(struct ast_channel *chan, int value)
#define AST_RWLIST_TRAVERSE_SAFE_END
#define AST_MUTEX_DEFINE_STATIC(mutex)
void ast_translator_free_path(struct ast_trans_pvt *tr)
Frees a translator path Frees the given translator path structure.
#define ast_mutex_unlock(a)
static int type_in_list(const char *list, const char *type, int(*cmp)(const char *s1, const char *s2))