Asterisk - The Open Source Telephony Project
21.4.1
|
Bucket File API. More...
#include "asterisk.h"
#include <uriparser/Uri.h>
#include "asterisk/logger.h"
#include "asterisk/sorcery.h"
#include "asterisk/bucket.h"
#include "asterisk/config_options.h"
#include "asterisk/astobj2.h"
#include "asterisk/strings.h"
#include "asterisk/json.h"
#include "asterisk/file.h"
#include "asterisk/module.h"
#include "asterisk/paths.h"
Go to the source code of this file.
Data Structures | |
struct | ast_bucket_scheme |
Structure for available schemes. More... | |
Macros | |
#define | METADATA_BUCKETS 53 |
Number of buckets for the container of metadata in a file. | |
#define | SCHEME_BUCKETS 53 |
Number of buckets for the container of schemes. | |
Functions | |
int | __ast_bucket_scheme_register (const char *name, struct ast_sorcery_wizard *bucket, struct ast_sorcery_wizard *file, bucket_file_create_cb create_cb, bucket_file_destroy_cb destroy_cb, struct ast_module *module) |
Register support for a specific scheme. More... | |
struct ast_bucket * | ast_bucket_alloc (const char *uri) |
Allocate a new bucket. More... | |
struct ast_bucket * | ast_bucket_clone (struct ast_bucket *bucket) |
Clone a bucket. More... | |
int | ast_bucket_create (struct ast_bucket *bucket) |
Create a new bucket in backend storage. More... | |
int | ast_bucket_delete (struct ast_bucket *bucket) |
Delete a bucket from backend storage. More... | |
struct ast_bucket_file * | ast_bucket_file_alloc (const char *uri) |
Allocate a new bucket file. More... | |
struct ast_bucket_file * | ast_bucket_file_clone (struct ast_bucket_file *file) |
Clone a bucket file. More... | |
struct ast_bucket_file * | ast_bucket_file_copy (struct ast_bucket_file *file, const char *uri) |
Copy a bucket file to a new URI. More... | |
int | ast_bucket_file_create (struct ast_bucket_file *file) |
Create a new bucket file in backend storage. More... | |
int | ast_bucket_file_delete (struct ast_bucket_file *file) |
Delete a bucket file from backend storage. More... | |
int | ast_bucket_file_is_stale (struct ast_bucket_file *file) |
Retrieve whether or not the backing datastore views the bucket file as stale. More... | |
struct ast_json * | ast_bucket_file_json (const struct ast_bucket_file *file) |
Get a JSON representation of a bucket file. More... | |
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. More... | |
struct ast_bucket_metadata * | ast_bucket_file_metadata_get (struct ast_bucket_file *file, const char *name) |
Retrieve a metadata attribute from a file. More... | |
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. More... | |
int | ast_bucket_file_metadata_unset (struct ast_bucket_file *file, const char *name) |
Unset a specific metadata attribute on a file. More... | |
int | ast_bucket_file_observer_add (const struct ast_sorcery_observer *callbacks) |
Add an observer for bucket file creation and deletion operations. More... | |
void | ast_bucket_file_observer_remove (const struct ast_sorcery_observer *callbacks) |
Remove an observer from bucket file creation and deletion. More... | |
struct ast_bucket_file * | ast_bucket_file_retrieve (const char *uri) |
Retrieve a bucket file. More... | |
int | ast_bucket_file_temporary_create (struct ast_bucket_file *file) |
Common file snapshot creation callback for creating a temporary file. More... | |
void | ast_bucket_file_temporary_destroy (struct ast_bucket_file *file) |
Common file snapshot destruction callback for deleting a temporary file. More... | |
int | ast_bucket_file_update (struct ast_bucket_file *file) |
Update an existing bucket file in backend storage. More... | |
int | ast_bucket_init (void) |
Initialize bucket support. More... | |
int | ast_bucket_is_stale (struct ast_bucket *bucket) |
Retrieve whether or not the backing datastore views the bucket as stale. More... | |
struct ast_json * | ast_bucket_json (const struct ast_bucket *bucket) |
Get a JSON representation of a bucket. More... | |
int | ast_bucket_observer_add (const struct ast_sorcery_observer *callbacks) |
Add an observer for bucket creation and deletion operations. More... | |
void | ast_bucket_observer_remove (const struct ast_sorcery_observer *callbacks) |
Remove an observer from bucket creation and deletion. More... | |
struct ast_bucket * | ast_bucket_retrieve (const char *uri) |
Retrieve information about a bucket. More... | |
static void * | bucket_alloc (const char *name) |
Allocator for buckets. | |
static void | bucket_cleanup (void) |
Hashing function for scheme container. More... | |
static int | bucket_copy (const char *infile, const char *outfile) |
Copy a file, shamelessly taken from file.c. | |
static int | bucket_copy_handler (const void *src, void *dst) |
static void | bucket_destroy (void *obj) |
Destructor for buckets. | |
static void * | bucket_file_alloc (const char *name) |
Allocator for bucket files. | |
static int | bucket_file_copy_handler (const void *src, void *dst) |
static void | bucket_file_destroy (void *obj) |
Hashing function for file metadata. More... | |
static int | bucket_file_wizard_create (const struct ast_sorcery *sorcery, void *data, void *object) |
Callback function for creating a bucket file. | |
static int | bucket_file_wizard_delete (const struct ast_sorcery *sorcery, void *data, void *object) |
Callback function for deleting a bucket file. | |
static int | bucket_file_wizard_is_stale (const struct ast_sorcery *sorcery, void *data, void *object) |
Callback function for determining if a bucket is stale. | |
static void * | bucket_file_wizard_retrieve (const struct ast_sorcery *sorcery, void *data, const char *type, const char *id) |
Callback function for retrieving a bucket file. | |
static int | bucket_file_wizard_update (const struct ast_sorcery *sorcery, void *data, void *object) |
Callback function for updating a bucket file. | |
static struct ast_bucket_metadata * | bucket_metadata_alloc (const char *name, const char *value) |
Allocator for metadata attributes. | |
static int | bucket_rbtree_str_sort_cmp (const void *obj_left, const void *obj_right, int flags) |
Sorting function for red black tree string container. | |
static int | bucket_wizard_create (const struct ast_sorcery *sorcery, void *data, void *object) |
Callback function for creating a bucket. | |
static int | bucket_wizard_delete (const struct ast_sorcery *sorcery, void *data, void *object) |
Callback function for deleting a bucket. | |
static int | bucket_wizard_is_stale (const struct ast_sorcery *sorcery, void *data, void *object) |
Callback function for determining if a bucket is stale. | |
static void * | bucket_wizard_retrieve (const struct ast_sorcery *sorcery, void *data, const char *type, const char *id) |
Callback function for retrieving a bucket. | |
static int | timeval_str2struct (const struct aco_option *opt, struct ast_variable *var, void *obj) |
Custom handler for translating from a string timeval to actual structure. | |
static int | timeval_struct2str (const void *obj, const intptr_t *args, char **buf) |
Custom handler for translating from an actual structure timeval to string. | |
Variables | |
static struct ast_sorcery_wizard | bucket_file_wizard |
Intermediary file wizard. | |
static struct ast_sorcery * | bucket_sorcery |
Sorcery instance for all bucket operations. | |
static struct ast_sorcery_wizard | bucket_wizard |
Intermediary bucket wizard. | |
static struct ao2_container * | schemes |
Container of registered schemes. | |
Bucket File API.
Definition in file bucket.c.
int __ast_bucket_scheme_register | ( | const char * | name, |
struct ast_sorcery_wizard * | bucket, | ||
struct ast_sorcery_wizard * | file, | ||
bucket_file_create_cb | create_cb, | ||
bucket_file_destroy_cb | destroy_cb, | ||
struct ast_module * | module | ||
) |
Register support for a specific scheme.
name | Name of the scheme, used to find based on scheme in URIs |
bucket | Sorcery wizard used for buckets |
file | Sorcery wizard used for files |
create_cb | Required file snapshot creation callback |
destroy_cb | Optional file snapshot destruction callback |
module | The module which implements this scheme |
0 | success |
-1 | failure |
Definition at line 277 of file bucket.c.
References ao2_link_flags, ast_module_shutdown_ref, ast_sorcery_wizard::create, ast_sorcery_wizard::delete, lock, OBJ_KEY, OBJ_NOLOCK, RAII_VAR, ast_sorcery_wizard::retrieve_id, and SCOPED_AO2WRLOCK.
struct ast_bucket* ast_bucket_alloc | ( | const char * | uri | ) |
Allocate a new bucket.
uri | Complete URI for the bucket |
non-NULL | success |
NULL | failure |
Definition at line 431 of file bucket.c.
References ao2_ref, ast_alloca, ast_copy_string(), ast_sorcery_alloc(), ast_strdupa, ast_string_field_set, OBJ_KEY, RAII_VAR, ast_bucket::scheme, and ast_bucket::scheme_impl.
struct ast_bucket* ast_bucket_clone | ( | struct ast_bucket * | bucket | ) |
Clone a bucket.
This will create a copy of the passed in ast_bucket
structure. While all properties of the ast_bucket
structure are copied, any metadata in the original structure simply has its reference count increased.
bucket | The bucket to clone |
non-NULL | success |
NULL | failure |
ast_bucket
instances are immutable Definition at line 510 of file bucket.c.
References ast_sorcery_copy().
int ast_bucket_create | ( | struct ast_bucket * | bucket | ) |
Create a new bucket in backend storage.
bucket | The bucket |
0 | success |
-1 | failure |
Definition at line 488 of file bucket.c.
References ast_sorcery_create().
int ast_bucket_delete | ( | struct ast_bucket * | bucket | ) |
Delete a bucket from backend storage.
bucket | The bucket |
0 | success |
-1 | failure |
Definition at line 539 of file bucket.c.
References ast_sorcery_delete().
struct ast_bucket_file* ast_bucket_file_alloc | ( | const char * | uri | ) |
Allocate a new bucket file.
uri | Complete URI for the bucket file |
non-NULL | success |
NULL | failure |
Definition at line 663 of file bucket.c.
References ao2_ref, ast_alloca, ast_copy_string(), ast_sorcery_alloc(), ast_strdupa, ast_string_field_set, OBJ_KEY, RAII_VAR, ast_bucket_file::scheme, and ast_bucket_file::scheme_impl.
Referenced by ast_bucket_file_copy(), and ast_media_cache_create_or_update().
struct ast_bucket_file* ast_bucket_file_clone | ( | struct ast_bucket_file * | file | ) |
Clone a bucket file.
This will create a copy of the passed in ast_bucket_file
structure. While all properties of the ast_bucket_file
structure are copied, any metadata in the original structure simply has its reference count increased. Note that this copies the structure, not the underlying file.
file | The bucket file to clone |
non-NULL | success |
NULL | failure |
ast_bucket_file
instances are immutable Definition at line 810 of file bucket.c.
References ast_sorcery_copy().
Referenced by ast_media_cache_create_or_update().
struct ast_bucket_file* ast_bucket_file_copy | ( | struct ast_bucket_file * | file, |
const char * | uri | ||
) |
Copy a bucket file to a new URI.
file | The source bucket file |
uri | The new URI |
non-NULL | success |
NULL | failure |
Definition at line 791 of file bucket.c.
References ao2_container_clone, ao2_ref, ast_bucket_file_alloc(), bucket_copy(), copy(), ast_bucket_file::metadata, ast_bucket_file::path, and RAII_VAR.
int ast_bucket_file_create | ( | struct ast_bucket_file * | file | ) |
Create a new bucket file in backend storage.
file | The bucket file |
0 | success |
-1 | failure |
Definition at line 725 of file bucket.c.
References ast_sorcery_create().
Referenced by ast_media_cache_create_or_update().
int ast_bucket_file_delete | ( | struct ast_bucket_file * | file | ) |
Delete a bucket file from backend storage.
file | The bucket file |
0 | success |
-1 | failure |
Definition at line 844 of file bucket.c.
References ast_sorcery_delete().
Referenced by ast_media_cache_delete(), and ast_media_cache_retrieve().
int ast_bucket_file_is_stale | ( | struct ast_bucket_file * | file | ) |
Retrieve whether or not the backing datastore views the bucket file as stale.
This function will ask whatever data storage backs the bucket file's schema type if the current instance of the object is stale. It will not update the bucket file object itself, as said objects are immutable. If the caller of this function would like to update the object, it should perform a retrieve operation.
file | The bucket file object to check |
0 | if file is not stale |
1 | if file is stale |
Definition at line 824 of file bucket.c.
References ast_sorcery_is_stale().
Referenced by ast_media_cache_retrieve().
struct ast_json* ast_bucket_file_json | ( | const struct ast_bucket_file * | file | ) |
Get a JSON representation of a bucket file.
file | The specific bucket file |
non-NULL | success |
NULL | failure |
Definition at line 849 of file bucket.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_ref, ast_json_object_create(), ast_json_object_set(), ast_json_ref(), ast_json_string_create(), ast_json_unref(), ast_sorcery_object_get_id(), ast_sorcery_objectset_json_create(), ast_bucket_file::metadata, ast_bucket_metadata::name, RAII_VAR, and ast_bucket_metadata::value.
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.
file | The bucket file |
cb | An ao2 callback function that will be called with each ast_bucket_metadata associated with file |
arg | An optional argument to pass to cb |
Definition at line 364 of file bucket.c.
References ao2_callback, and ast_bucket_file::metadata.
struct ast_bucket_metadata* ast_bucket_file_metadata_get | ( | struct ast_bucket_file * | file, |
const char * | name | ||
) |
Retrieve a metadata attribute from a file.
file | The bucket file |
name | Name of the attribute |
non-NULL | if found |
NULL | if not found |
Definition at line 359 of file bucket.c.
References ast_bucket_file::metadata, and OBJ_KEY.
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.
file | The bucket file |
name | Name of the attribute |
value | Value of the attribute |
0 | success |
-1 | failure |
Definition at line 334 of file bucket.c.
References ao2_link, bucket_metadata_alloc(), ast_bucket_file::metadata, OBJ_KEY, OBJ_NODATA, OBJ_UNLINK, and RAII_VAR.
Referenced by ast_media_cache_create_or_update().
int ast_bucket_file_metadata_unset | ( | struct ast_bucket_file * | file, |
const char * | name | ||
) |
Unset a specific metadata attribute on a file.
file | The bucket file |
name | Name of the attribute |
0 | success |
-1 | failure |
Definition at line 348 of file bucket.c.
References ast_bucket_file::metadata, OBJ_KEY, OBJ_UNLINK, and RAII_VAR.
int ast_bucket_file_observer_add | ( | const struct ast_sorcery_observer * | callbacks | ) |
Add an observer for bucket file creation and deletion operations.
callbacks | Implementation of the sorcery observer interface |
0 | success |
-1 | failure |
Definition at line 829 of file bucket.c.
References ast_sorcery_observer_add().
void ast_bucket_file_observer_remove | ( | const struct ast_sorcery_observer * | callbacks | ) |
Remove an observer from bucket file creation and deletion.
callbacks | Implementation of the sorcery observer interface |
Definition at line 834 of file bucket.c.
References ast_sorcery_observer_remove().
struct ast_bucket_file* ast_bucket_file_retrieve | ( | const char * | uri | ) |
Retrieve a bucket file.
uri | Complete URI of the bucket file |
non-NULL | if found |
NULL | if not found |
Definition at line 815 of file bucket.c.
References ast_sorcery_retrieve_by_id().
Referenced by ast_media_cache_exists(), and ast_media_cache_retrieve().
int ast_bucket_file_temporary_create | ( | struct ast_bucket_file * | file | ) |
Common file snapshot creation callback for creating a temporary file.
file | Pointer to the file snapshot |
0 | success |
-1 | failure |
Definition at line 899 of file bucket.c.
References ast_bucket_file::path.
void ast_bucket_file_temporary_destroy | ( | struct ast_bucket_file * | file | ) |
Common file snapshot destruction callback for deleting a temporary file.
file | Pointer to the file snapshot |
Definition at line 914 of file bucket.c.
References ast_bucket_file::path.
int ast_bucket_file_update | ( | struct ast_bucket_file * | file | ) |
Update an existing bucket file in backend storage.
file | The bucket file |
0 | success |
-1 | failure |
Definition at line 839 of file bucket.c.
References ast_sorcery_update().
int ast_bucket_init | ( | void | ) |
Initialize bucket support.
0 | success |
-1 | failure |
Definition at line 954 of file bucket.c.
References __ast_sorcery_wizard_register(), AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_container_alloc_hash, ast_register_cleanup(), AST_SORCERY_APPLY_FAIL, ast_sorcery_object_field_register, ast_sorcery_object_field_register_custom, ast_sorcery_object_register, ast_sorcery_object_set_copy_handler(), ast_sorcery_open, bucket_alloc(), bucket_cleanup(), bucket_file_alloc(), FLDSET, OPT_STRINGFIELD_T, SCHEME_BUCKETS, STRFLDSET, timeval_str2struct(), and timeval_struct2str().
int ast_bucket_is_stale | ( | struct ast_bucket * | bucket | ) |
Retrieve whether or not the backing datastore views the bucket as stale.
This function will ask whatever data storage backs the bucket's schema type if the current instance of the object is stale. It will not update the bucket object itself, as said objects are immutable. If the caller of this function would like to update the object, it should perform a retrieve operation.
bucket | The bucket object to check |
0 | if bucket is not stale |
1 | if bucket is stale |
Definition at line 524 of file bucket.c.
References ast_sorcery_is_stale().
struct ast_json* ast_bucket_json | ( | const struct ast_bucket * | bucket | ) |
Get a JSON representation of a bucket.
bucket | The specific bucket |
non-NULL | success |
NULL | failure |
Definition at line 544 of file bucket.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_ref, ast_json_array_append(), ast_json_array_create(), ast_json_object_set(), ast_json_ref(), ast_json_string_create(), ast_json_unref(), ast_sorcery_object_get_id(), ast_sorcery_objectset_json_create(), ast_bucket::buckets, ast_bucket::files, and RAII_VAR.
int ast_bucket_observer_add | ( | const struct ast_sorcery_observer * | callbacks | ) |
Add an observer for bucket creation and deletion operations.
callbacks | Implementation of the sorcery observer interface |
0 | success |
-1 | failure |
Definition at line 529 of file bucket.c.
References ast_sorcery_observer_add().
void ast_bucket_observer_remove | ( | const struct ast_sorcery_observer * | callbacks | ) |
Remove an observer from bucket creation and deletion.
callbacks | Implementation of the sorcery observer interface |
Definition at line 534 of file bucket.c.
References ast_sorcery_observer_remove().
struct ast_bucket* ast_bucket_retrieve | ( | const char * | uri | ) |
Retrieve information about a bucket.
uri | Complete URI of the bucket |
non-NULL | if found |
NULL | if not found |
Definition at line 515 of file bucket.c.
References ast_sorcery_retrieve_by_id().
|
static |
Hashing function for scheme container.
Comparison function for scheme container
Cleanup function for graceful shutdowns
Definition at line 928 of file bucket.c.
References ast_sorcery_unref, and ast_sorcery_wizard_unregister().
Referenced by ast_bucket_init().
|
static |
Hashing function for file metadata.
Comparison function for file metadata
Destructor for bucket files
Definition at line 627 of file bucket.c.
References ast_bucket_scheme::destroy, ast_bucket_file::metadata, and ast_bucket_file::scheme_impl.
Referenced by bucket_file_alloc().