42 #define AST_DB_FAMILY "MediaCache" 45 #define AST_DB_FAMILY_LEN 12 48 #define AO2_BUCKETS 61 84 const char *hash = arg;
135 char *params = strchr(content_type,
';');
139 while (params > content_type && (*params ==
' ' || *params ==
'\t')) {
151 const char *preferred_file_name)
155 if (!
ast_strlen_zero(preferred_file_name) && strcmp(bucket_file->
path, preferred_file_name)) {
158 rename(bucket_file->
path, preferred_file_name);
160 sizeof(bucket_file->
path));
164 char new_path[
PATH_MAX +
sizeof(found_ext)];
191 snprintf(new_path,
sizeof(new_path),
"%s%s", bucket_file->
path, ext);
192 rename(bucket_file->
path, new_path);
198 char *file_path,
size_t len)
217 if ((ext = strrchr(file_path,
'.'))) {
222 ast_debug(5,
"Returning media at local file: %s\n", file_path);
237 ast_debug(2,
"Failed to obtain media at '%s'\n", uri);
247 if ((ext = strrchr(file_path,
'.'))) {
253 ast_debug(5,
"Returning media at local file: %s\n", file_path);
302 if (stat(file_path, &st)) {
333 strcpy(bucket_file->
path, file_path);
334 bucket_file->
created.tv_sec = st.st_ctime;
335 bucket_file->
modified.tv_sec = st.st_mtime;
337 snprintf(tmp,
sizeof(tmp),
"%ld", (
long)st.st_atime);
340 snprintf(tmp,
sizeof(tmp),
"%jd", (intmax_t)st.st_size);
343 ext = strrchr(file_path_ptr,
'.');
348 for (it_metadata = metadata; it_metadata; it_metadata = it_metadata->
next) {
419 for (db_entry = db_tree; db_entry; db_entry = db_entry->
next) {
420 const char *key = strchr(db_entry->
key + 1,
'/');
427 if (!strcasecmp(key,
"path")) {
428 strcpy(bucket_file->path, db_entry->
data);
430 if (stat(bucket_file->path, &st)) {
432 bucket_file->path, uri);
445 ast_log(
LOG_WARNING,
"Failed to restore media cache item for '%s' from AstDB: no 'path' specified\n",
466 for (db_entry = db_tree; db_entry; db_entry = db_entry->
next) {
480 #define FORMAT_ROW "%-40s\n\t%-40s\n" 494 e->
command =
"media cache show all";
496 "Usage: media cache show all\n" 497 " Display a summary of all current items in the media cache.\n";
522 int wordlen = strlen(word);
538 #define FORMAT_ROW "\t%20s: %-40.40s\n" 545 e->
command =
"media cache show";
547 "Usage: media cache show <uri>\n" 548 " Display all information about a particular item in the media cache.\n";
560 ast_cli(a->
fd,
"Unable to find '%s' in the media cache\n", a->
argv[3]);
565 ast_cli(a->
fd,
"%s\n",
"----------------------------------------");
584 e->
command =
"media cache delete";
586 "Usage: media cache delete <uri>\n" 587 " Delete an item from the media cache.\n\n" 588 " Note that this will also remove any local storage of the media associated\n" 589 " with the URI, and will inform the backend supporting the URI scheme that\n" 590 " it should remove the item.\n";
603 ast_cli(a->
fd,
"Deleted '%s' from the media cache\n", a->
argv[3]);
615 e->
command =
"media cache refresh";
617 "Usage: media cache refresh <uri>\n" 618 " Ask for a refresh of a particular URI.\n\n" 619 " If the item does not already exist in the media cache, the item will be\n" 620 " populated from the backend supporting the URI scheme.\n";
633 ast_cli(a->
fd,
"Refreshed '%s' to local storage '%s'\n", a->
argv[3], file_path);
643 e->
command =
"media cache create";
645 "Usage: media cache create <uri> <file>\n" 646 " Create an item in the media cache by associating a local media file with\n" 658 ast_cli(a->
fd,
"Unable to create '%s' associated with local file '%s'\n",
661 ast_cli(a->
fd,
"Created '%s' for '%s' in the media cache\n",
struct ast_bucket_metadata * ast_bucket_file_metadata_get(struct ast_bucket_file *file, const char *name)
Retrieve a metadata attribute from a file.
struct ast_variable * next
#define AST_CLI_DEFINE(fn, txt,...)
Asterisk main include file. File version handling, generic pbx functions.
int ast_bucket_file_metadata_set(struct ast_bucket_file *file, const char *name, const char *value)
Set a metadata attribute on a file to a specific value.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
The arg parameter is a search key, but is not an object.
descriptor for a cli entry.
int ast_file_is_readable(const char *filename)
Test that a file exists and is readable by the effective user.
void ast_db_freetree(struct ast_db_entry *entry)
Free structure created by ast_db_gettree()
#define ao2_callback(c, flags, cb_fn, arg)
struct ast_bucket_file * ast_bucket_file_retrieve(const char *uri)
Retrieve a bucket file.
Structure for variables, used for configurations and for channel variables.
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
Assume that the ao2_container is already locked.
int ast_db_get_allocated(const char *family, const char *key, char **out)
Get key value specified by family/key as a heap allocated string.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ao2_link_flags(container, obj, flags)
#define ast_strdup(str)
A wrapper for strdup()
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
struct ast_bucket_file * ast_bucket_file_alloc(const char *uri)
Allocate a new bucket file.
void ast_cli(int fd, const char *fmt,...)
struct timeval modified
When this file was last modified.
int args
This gets set in ast_cli_register()
#define ast_strlen_zero(foo)
Configuration File Parser.
struct timeval created
When this file was created.
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_db_entry * next
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
struct ast_bucket_file * ast_bucket_file_clone(struct ast_bucket_file *file)
Clone a bucket file.
#define ao2_ref(o, delta)
int ast_bucket_file_delete(struct ast_bucket_file *file)
Delete a bucket file from backend storage.
#define ast_strdupa(s)
duplicate a string in memory from the stack
int ast_bucket_file_is_stale(struct ast_bucket_file *file)
Retrieve whether or not the backing datastore views the bucket file as stale.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
void ast_bucket_file_metadata_callback(struct ast_bucket_file *file, ao2_callback_fn cb, void *arg)
Execute a callback function on the metadata associated with a file.
Bucket file structure, contains reference to file and information about it.
void ast_sha1_hash(char *output, const char *input)
Produces SHA1 hash based on input string.
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
struct ast_db_entry * ast_db_gettree(const char *family, const char *keytree)
Get a list of values within the astdb tree.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ao2_iterator_next(iter)
struct ao2_container * metadata
Container of metadata attributes about file.
#define SCOPED_AO2LOCK(varname, obj)
scoped lock specialization for ao2 mutexes.
#define ao2_find(container, arg, flags)
struct ast_format * ast_get_format_for_file_ext(const char *file_ext)
Get the ast_format associated with the given file extension.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Standard Command Line Interface.
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
int ast_sorcery_object_id_hash(const void *obj, int flags)
ao2 object hasher based on sorcery id.
#define ao2_unlink_flags(container, obj, flags)
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Persistant data storage (akin to *doze registry)
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.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
char path[PATH_MAX]
Local path to this file.
int ast_bucket_file_create(struct ast_bucket_file *file)
Create a new bucket file in backend storage.
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb.
#define ao2_link(container, obj)