33 #include <sys/types.h> 59 return recording->
file;
98 const char *file_portion;
105 last_slash = strrchr(relative_dir,
'/');
108 file_portion = last_slash + 1;
114 *relative_dir =
'\0';
121 real_dir = realpath(absolute_dir,
NULL);
128 return (*dir && *file) ? 0 : -1;
138 const char *
ext = strrchr(filename,
'.');
147 ast_debug(5,
"Recording %s: unrecognized format %s\n",
154 return ext - filename - 1;
163 if (!(num =
is_recording(filename)) || strncmp(data->
file, filename, num)) {
189 .file_with_ext =
NULL 221 static int recording_sort(
const void *obj_left,
const void *obj_right,
int flags)
225 const char *right_key = obj_right;
230 right_key = object_right->
name;
233 cmp = strcmp(object_left->
name, right_key);
240 cmp = strncmp(object_left->
name, right_key, strlen(right_key));
251 static int handle_scan_file(
const char *dir_name,
const char *filename,
void *obj)
255 char *dot, *filepath;
262 if (
ast_asprintf(&filepath,
"%s/%s", dir_name, filename) < 0) {
278 dot = strrchr(recording->
file,
'.');
280 recording->
format = dot + 1;
323 struct stat file_stat;
359 prefix_len = strlen(real_basedir);
373 recording->format = strrchr(recording->file_with_ext,
'.');
374 if (!recording->format) {
377 ++(recording->format);
384 if (!S_ISREG(file_stat.st_mode)) {
404 format = strrchr(dst_file,
'.');
410 last_slash = strrchr(dst_file,
'/');
419 tmp_path, 0777) != 0) {
434 ast_verb(4,
"Copying recording %s to %s (format %s)\n", src_recording->
file,
435 full_path, src_recording->
format);
459 "name", recording->
name,
460 "format", recording->
format);
int ast_filecopy(const char *oldname, const char *newname, const char *fmt)
Copies a file.
Stasis Application Recording API. See StasisApplication API" for detailed documentation.
void ast_std_free(void *ptr)
Asterisk main include file. File version handling, generic pbx functions.
const char * stasis_app_stored_recording_get_file(struct stasis_app_stored_recording *recording)
Returns the filename for this recording, for use with streamfile.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
int stasis_app_stored_recording_delete(struct stasis_app_stored_recording *recording)
Delete a recording from disk.
static void stored_recording_dtor(void *obj)
static char * find_recording(const char *dir_name, const char *file)
Finds a recording in the given directory.
const ast_string_field file_with_ext
static struct stasis_app_stored_recording * recording_alloc(void)
Allocate a recording object.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define ast_strdup(str)
A wrapper for strdup()
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_verb(level,...)
static int handle_find_recording(const char *dir_name, const char *filename, void *obj)
static int handle_scan_file(const char *dir_name, const char *filename, void *obj)
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
struct ao2_container * stasis_app_stored_recording_find_all(void)
Find all stored recordings on disk.
#define ast_debug(level,...)
Log a DEBUG message.
static struct stasis_rest_handlers recordings
REST handler for /api-docs/recordings.json.
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.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ao2_ref(o, delta)
#define ast_strdupa(s)
duplicate a string in memory from the stack
const char * stasis_app_stored_recording_get_extension(struct stasis_app_stored_recording *recording)
Returns the extension for this recording.
int stasis_app_stored_recording_copy(struct stasis_app_stored_recording *src_recording, const char *dst, struct stasis_app_stored_recording **dst_recording)
Copy a recording.
const char * stasis_app_stored_recording_get_filename(struct stasis_app_stored_recording *recording)
Returns the full filename, with extension, for this recording.
static int split_path(const char *path, char **dir, char **file)
Split a path into directory and file, resolving canonical directory.
const ast_string_field name
#define ao2_alloc(data_size, destructor_fn)
struct ast_json * stasis_app_stored_recording_to_json(struct stasis_app_stored_recording *recording)
Convert stored recording info to JSON.
int ast_safe_mkdir(const char *base_path, const char *path, int mode)
Recursively create directory path, but only if it resolves within the given base_path.
struct ast_format * ast_get_format_for_file_ext(const char *file_ext)
Get the ast_format associated with the given file extension.
#define ast_string_field_build(x, field, fmt, args...)
Set a field to a complex (built) value.
const ast_string_field file
struct stasis_app_stored_recording * stasis_app_stored_recording_find_by_name(const char *name)
Creates a stored recording object, with the given name.
Replace objects with duplicate keys in container.
const char * ast_config_AST_RECORDING_DIR
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
static int recording_sort(const void *obj_left, const void *obj_right, int flags)
Abstract JSON element (object, array, string, int, ...).
#define ao2_container_alloc_rbtree(ao2_options, container_options, sort_fn, cmp_fn)
#define ast_file_read_dir(dir_name, on_file, obj)
Iterate over each file in a given directory.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
static int is_recording(const char *filename)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ao2_link(container, obj)