Asterisk - The Open Source Telephony Project GIT-master-754dea3
|
Bucket File API. More...
#include "asterisk/sorcery.h"
Go to the source code of this file.
Data Structures | |
struct | ast_bucket |
Bucket structure, contains other buckets and files. More... | |
struct | ast_bucket_file |
Bucket file structure, contains reference to file and information about it. More... | |
struct | ast_bucket_metadata |
Bucket metadata structure, AO2 key value pair. More... | |
Macros | |
#define | ast_bucket_scheme_register(name, bucket, file, create_cb, destroy_cb) __ast_bucket_scheme_register(name, bucket, file, create_cb, destroy_cb, AST_MODULE_SELF) |
Register support for a specific scheme. More... | |
Typedefs | |
typedef int(* | bucket_file_create_cb) (struct ast_bucket_file *file) |
A callback function invoked when creating a file snapshot. More... | |
typedef void(* | bucket_file_destroy_cb) (struct ast_bucket_file *file) |
A callback function invoked when destroying a file snapshot. More... | |
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... | |
Bucket File API.
Definition in file bucket.h.
#define ast_bucket_scheme_register | ( | name, | |
bucket, | |||
file, | |||
create_cb, | |||
destroy_cb | |||
) | __ast_bucket_scheme_register(name, bucket, file, create_cb, destroy_cb, AST_MODULE_SELF) |
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 |
0 | success |
-1 | failure |
typedef int(* bucket_file_create_cb) (struct ast_bucket_file *file) |
typedef void(* bucket_file_destroy_cb) (struct ast_bucket_file *file) |
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 247 of file bucket.c.
References ao2_alloc, ao2_cleanup, ao2_find, ao2_link_flags, ast_module_shutdown_ref, ast_strlen_zero(), ast_verb, ast_sorcery_wizard::create, ast_sorcery_wizard::delete, make_ari_stubs::file, lock, ast_sorcery_wizard::module, name, NULL, OBJ_KEY, OBJ_NOLOCK, RAII_VAR, ast_sorcery_wizard::retrieve_id, schemes, 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 401 of file bucket.c.
References ao2_cleanup, ao2_find, ao2_ref, ast_alloca, ast_copy_string(), ast_sorcery_alloc(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), bucket_sorcery, len(), NULL, OBJ_KEY, RAII_VAR, ast_bucket::scheme, ast_bucket::scheme_impl, schemes, and state.
Referenced by AST_TEST_DEFINE(), and bucket_test_wizard_retrieve_id().
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 480 of file bucket.c.
References ast_sorcery_copy(), and bucket_sorcery.
Referenced by AST_TEST_DEFINE().
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 458 of file bucket.c.
References ast_sorcery_create(), and bucket_sorcery.
Referenced by AST_TEST_DEFINE().
int ast_bucket_delete | ( | struct ast_bucket * | bucket | ) |
Delete a bucket from backend storage.
bucket | The bucket |
0 | success |
-1 | failure |
Definition at line 509 of file bucket.c.
References ast_sorcery_delete(), and bucket_sorcery.
Referenced by AST_TEST_DEFINE().
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 633 of file bucket.c.
References ao2_cleanup, ao2_find, ao2_ref, ast_alloca, ast_copy_string(), ast_sorcery_alloc(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), bucket_sorcery, make_ari_stubs::file, len(), NULL, OBJ_KEY, RAII_VAR, ast_bucket_file::scheme, schemes, and state.
Referenced by ast_bucket_file_copy(), ast_media_cache_create_or_update(), AST_TEST_DEFINE(), bucket_http_test_wizard_retrieve_id(), bucket_http_wizard_retrieve_id(), bucket_test_wizard_retrieve_id(), and media_cache_item_populate_from_astdb().
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 780 of file bucket.c.
References ast_sorcery_copy(), bucket_sorcery, and make_ari_stubs::file.
Referenced by ast_media_cache_create_or_update(), and AST_TEST_DEFINE().
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 761 of file bucket.c.
References ao2_cleanup, ao2_container_clone, ao2_ref, ast_bucket_file_alloc(), bucket_copy(), copy(), make_ari_stubs::file, NULL, and RAII_VAR.
Referenced by AST_TEST_DEFINE().
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 695 of file bucket.c.
References ast_sorcery_create(), bucket_sorcery, and make_ari_stubs::file.
Referenced by ast_media_cache_create_or_update(), and AST_TEST_DEFINE().
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 814 of file bucket.c.
References ast_sorcery_delete(), bucket_sorcery, and make_ari_stubs::file.
Referenced by ast_media_cache_delete(), ast_media_cache_retrieve(), AST_TEST_DEFINE(), and bucket_file_cleanup().
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 794 of file bucket.c.
References ast_sorcery_is_stale(), bucket_sorcery, and make_ari_stubs::file.
Referenced by ast_media_cache_retrieve(), and AST_TEST_DEFINE().
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 819 of file bucket.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, 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(), bucket_sorcery, make_ari_stubs::file, id, ast_bucket_metadata::name, NULL, RAII_VAR, ast_bucket_metadata::value, and value.
Referenced by AST_TEST_DEFINE().
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 334 of file bucket.c.
References ao2_callback, and make_ari_stubs::file.
Referenced by media_cache_item_sync_to_astdb().
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 329 of file bucket.c.
References ao2_find, make_ari_stubs::file, name, and OBJ_KEY.
Referenced by AST_TEST_DEFINE(), bucket_file_always_revalidate(), bucket_file_expired(), bucket_file_set_expiration(), bucket_file_update_path(), bucket_http_wizard_is_stale(), and file_extension_from_content_type().
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 304 of file bucket.c.
References ao2_cleanup, ao2_find, ao2_link, bucket_metadata_alloc(), make_ari_stubs::file, name, OBJ_KEY, OBJ_NODATA, OBJ_UNLINK, RAII_VAR, and value.
Referenced by ast_media_cache_create_or_update(), AST_TEST_DEFINE(), bucket_file_set_expiration(), bucket_file_set_extension(), curl_header_callback(), and media_cache_item_populate_from_astdb().
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 318 of file bucket.c.
References ao2_cleanup, ao2_find, make_ari_stubs::file, name, OBJ_KEY, OBJ_UNLINK, and RAII_VAR.
Referenced by AST_TEST_DEFINE().
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 799 of file bucket.c.
References ast_sorcery_observer_add(), bucket_sorcery, and callbacks.
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 804 of file bucket.c.
References ast_sorcery_observer_remove(), bucket_sorcery, and callbacks.
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 785 of file bucket.c.
References ast_sorcery_retrieve_by_id(), ast_strlen_zero(), bucket_sorcery, and NULL.
Referenced by ast_media_cache_exists(), ast_media_cache_retrieve(), and AST_TEST_DEFINE().
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 869 of file bucket.c.
References ast_config_AST_CACHE_DIR, and make_ari_stubs::file.
Referenced by AST_TEST_DEFINE(), bucket_http_test_wizard_retrieve_id(), bucket_http_wizard_retrieve_id(), and load_module().
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 884 of file bucket.c.
References ast_strlen_zero(), and make_ari_stubs::file.
Referenced by load_module().
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 809 of file bucket.c.
References ast_sorcery_update(), bucket_sorcery, and make_ari_stubs::file.
Referenced by AST_TEST_DEFINE().
int ast_bucket_init | ( | void | ) |
Initialize bucket support.
0 | success |
-1 | failure |
Definition at line 924 of file bucket.c.
References __ast_sorcery_wizard_register(), AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_container_alloc_hash, ast_log, ast_register_cleanup(), ast_sorcery_apply_default, AST_SORCERY_APPLY_FAIL, ast_sorcery_internal_object_register, ast_sorcery_object_field_register_custom_nodoc, ast_sorcery_object_field_register_nodoc, ast_sorcery_object_set_copy_handler(), ast_sorcery_open, bucket_alloc(), bucket_cleanup(), bucket_copy_handler(), bucket_file_alloc(), bucket_file_copy_handler(), bucket_file_wizard, bucket_sorcery, bucket_wizard, FLDSET, LOG_ERROR, NULL, OPT_STRINGFIELD_T, SCHEME_BUCKETS, schemes, STRFLDSET, timeval_str2struct(), and timeval_struct2str().
Referenced by asterisk_daemon().
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 494 of file bucket.c.
References ast_sorcery_is_stale(), and bucket_sorcery.
Referenced by AST_TEST_DEFINE().
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 514 of file bucket.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, 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(), bucket_sorcery, ast_bucket::buckets, ast_bucket::files, id, NULL, and RAII_VAR.
Referenced by AST_TEST_DEFINE().
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 499 of file bucket.c.
References ast_sorcery_observer_add(), bucket_sorcery, and callbacks.
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 504 of file bucket.c.
References ast_sorcery_observer_remove(), bucket_sorcery, and callbacks.
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 485 of file bucket.c.
References ast_sorcery_retrieve_by_id(), ast_strlen_zero(), bucket_sorcery, and NULL.
Referenced by AST_TEST_DEFINE().