Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions
datastore.c File Reference

Asterisk datastore objects. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/datastore.h"
#include "asterisk/utils.h"
#include "asterisk/astobj2.h"
#include "asterisk/uuid.h"
#include "asterisk/module.h"
Include dependency graph for datastore.c:

Go to the source code of this file.

Macros

#define DATASTORE_BUCKETS   53
 Number of buckets for datastore container. More...
 

Functions

struct ast_datastore__ast_datastore_alloc (const struct ast_datastore_info *info, const char *uid, struct ast_module *mod, const char *file, int line, const char *function)
 Create a data store object. More...
 
 AO2_STRING_FIELD_CMP_FN (ast_datastore, uid)
 
 AO2_STRING_FIELD_HASH_FN (ast_datastore, uid)
 
int ast_datastore_free (struct ast_datastore *datastore)
 Free a data store object. More...
 
int ast_datastores_add (struct ao2_container *datastores, struct ast_datastore *datastore)
 Add a data store to a container. More...
 
struct ao2_containerast_datastores_alloc (void)
 Allocate a specialized data stores container. More...
 
struct ast_datastoreast_datastores_alloc_datastore (const struct ast_datastore_info *info, const char *uid)
 Allocate a datastore for use with the datastores container. More...
 
struct ast_datastoreast_datastores_find (struct ao2_container *datastores, const char *name)
 Find a data store in a container. More...
 
void ast_datastores_remove (struct ao2_container *datastores, const char *name)
 Remove a data store from a container. More...
 
static void datastore_destroy (void *obj)
 

Detailed Description

Asterisk datastore objects.

Definition in file datastore.c.

Macro Definition Documentation

◆ DATASTORE_BUCKETS

#define DATASTORE_BUCKETS   53

Number of buckets for datastore container.

Definition at line 37 of file datastore.c.

Referenced by ast_datastores_alloc().

Function Documentation

◆ __ast_datastore_alloc()

struct ast_datastore* __ast_datastore_alloc ( const struct ast_datastore_info info,
const char *  uid,
struct ast_module mod,
const char *  file,
int  line,
const char *  function 
)

Create a data store object.

Parameters
[in]infoinformation describing the data store object
[in]uidunique identifer
[in]modThe module to hold until this datastore is freed.
file,line,function
Version
1.6.1 moved here and renamed from ast_channel_datastore_alloc

Definition at line 39 of file datastore.c.

References __ast_calloc(), ast_free, ast_module_ref, ast_strdup, ast_strlen_zero, ast_datastore::info, sip_to_pjsip::info(), ast_datastore::mod, NULL, and ast_datastore::uid.

42 {
43  struct ast_datastore *datastore = NULL;
44 
45  /* Make sure we at least have type so we can identify this */
46  if (!info) {
47  return NULL;
48  }
49 
50  datastore = __ast_calloc(1, sizeof(*datastore), file, line, function);
51  if (!datastore) {
52  return NULL;
53  }
54 
55  datastore->info = info;
56  datastore->mod = mod;
57 
58  if (!ast_strlen_zero(uid) && !(datastore->uid = ast_strdup(uid))) {
59  ast_free(datastore);
60  datastore = NULL;
61  }
62 
63  ast_module_ref(mod);
64 
65  return datastore;
66 }
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc
Definition: astmm.c:1635
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
Structure for a data store object.
Definition: datastore.h:68
#define NULL
Definition: resample.c:96
const char * uid
Definition: datastore.h:69
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct ast_module * mod
Definition: datastore.h:72
const struct ast_datastore_info * info
Definition: datastore.h:71
def info(msg)
#define ast_free(a)
Definition: astmm.h:182
#define ast_module_ref(mod)
Hold a reference to the module.
Definition: module.h:443

◆ AO2_STRING_FIELD_CMP_FN()

AO2_STRING_FIELD_CMP_FN ( ast_datastore  ,
uid   
)

Referenced by ast_datastore_free().

◆ AO2_STRING_FIELD_HASH_FN()

AO2_STRING_FIELD_HASH_FN ( ast_datastore  ,
uid   
)

Referenced by ast_datastore_free().

◆ ast_datastore_free()

int ast_datastore_free ( struct ast_datastore datastore)

Free a data store object.

Parameters
[in]datastoredatastore to free
Version
1.6.1 moved here and renamed from ast_channel_datastore_free

Definition at line 68 of file datastore.c.

References AO2_STRING_FIELD_CMP_FN(), AO2_STRING_FIELD_HASH_FN(), ast_free, ast_module_unref, ast_datastore::data, ast_datastore_info::destroy, ast_datastore::info, ast_datastore::mod, NULL, and ast_datastore::uid.

Referenced by __after_bridge_set_goto(), acf_curlopt_write(), acf_fetch(), acf_iaxvar_write(), acf_odbc_read(), add_features_datastore(), add_to_agi(), adjust_frame_for_plc(), after_bridge_cb_setup(), apply_plc(), ast_bridge_discard_after_goto(), ast_bridge_setup_after_goto(), ast_cel_fabricate_channel_from_event(), ast_channel_destructor(), ast_channel_unsuppress(), ast_do_pickup(), ast_dummy_channel_destructor(), ast_iax2_new(), ast_jb_create_framehook(), ast_setup_cc_recall_datastore(), audiohook_volume_get(), authenticate_reply(), bridge_channel_impart_add(), bridge_features_ds_set_full(), bridge_timeout(), cc_interfaces_datastore_init(), chan_cleanup(), channel_feature_hooks_set_full(), create_parked_subscription_full(), create_transaction(), detect_write(), dial_masquerade_datastore_add(), dial_masquerade_fixup(), disable_jack_hook(), dtmfstore_exec(), enable_jack_hook(), exec_odbcfinish(), fixup_callback(), frame_drop_helper(), frame_trace_helper(), func_confbridge_helper(), get_lock(), gosub_exec(), init_hook(), lua_get_state(), max_forwards_datastore_alloc(), mixmonitor_ds_remove_and_free(), msg_datastore_find_or_create(), pitchshift_helper(), raise_exception(), remove_detect(), remove_dial_masquerade(), remove_dial_masquerade_caller(), remove_dtmf_store(), remove_hold_intercept(), remove_masquerade_store(), remove_scrambler(), remove_stasis_end_published(), remove_talk_detect(), save_dialstring(), scramble_write(), session_destructor(), set_dial_masquerade(), set_hold_intercept(), set_talk_detect(), setup_async_playback_datastore(), setup_bridge_roles_datastore(), setup_park_common_datastore(), shared_write(), socket_process_helper(), speech_datastore_destroy(), speex_write(), srv_query_read(), stop_mixmonitor_full(), volume_write(), wipe_park_common_datastore(), and wipe_subscription_datastore().

69 {
70  int res = 0;
71 
72  /* Using the destroy function (if present) destroy the data */
73  if (datastore->info->destroy != NULL && datastore->data != NULL) {
74  datastore->info->destroy(datastore->data);
75  datastore->data = NULL;
76  }
77 
78  /* Free allocated UID memory */
79  if (datastore->uid != NULL) {
80  ast_free((void *) datastore->uid);
81  datastore->uid = NULL;
82  }
83 
84  ast_module_unref(datastore->mod);
85 
86  /* Finally free memory used by ourselves */
87  ast_free(datastore);
88 
89  return res;
90 }
#define NULL
Definition: resample.c:96
const char * uid
Definition: datastore.h:69
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:469
struct ast_module * mod
Definition: datastore.h:72
const struct ast_datastore_info * info
Definition: datastore.h:71
void(* destroy)(void *data)
Definition: datastore.h:34
#define ast_free(a)
Definition: astmm.h:182
void * data
Definition: datastore.h:70

◆ ast_datastores_add()

int ast_datastores_add ( struct ao2_container datastores,
struct ast_datastore datastore 
)

Add a data store to a container.

Parameters
[in]datastorescontainer to store datastore in
[in]datastoredatastore to add
Return values
0success
-1failure
Since
14.0.0

Definition at line 101 of file datastore.c.

References ao2_link, ast_assert, ast_strlen_zero, ast_datastore::info, NULL, and ast_datastore::uid.

Referenced by ast_sip_publication_add_datastore(), ast_sip_subscription_add_datastore(), and dialog_info_generate_body_content().

102 {
103  ast_assert(datastore != NULL);
104  ast_assert(datastore->info != NULL);
105  ast_assert(!ast_strlen_zero(datastore->uid));
106 
107  if (!ao2_link(datastores, datastore)) {
108  return -1;
109  }
110 
111  return 0;
112 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
const char * uid
Definition: datastore.h:69
#define ast_strlen_zero(foo)
Definition: strings.h:52
const struct ast_datastore_info * info
Definition: datastore.h:71
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ ast_datastores_alloc()

struct ao2_container* ast_datastores_alloc ( void  )

Allocate a specialized data stores container.

Returns
a container for storing data stores
Since
14.0.0

Definition at line 95 of file datastore.c.

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, DATASTORE_BUCKETS, and NULL.

Referenced by allocate_subscription(), publisher_start(), and sip_create_publication().

96 {
98  DATASTORE_BUCKETS, ast_datastore_hash_fn, NULL, ast_datastore_cmp_fn);
99 }
#define NULL
Definition: resample.c:96
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
#define DATASTORE_BUCKETS
Number of buckets for datastore container.
Definition: datastore.c:37

◆ ast_datastores_alloc_datastore()

struct ast_datastore* ast_datastores_alloc_datastore ( const struct ast_datastore_info info,
const char *  uid 
)

Allocate a datastore for use with the datastores container.

Parameters
[in]infoinformation about the datastore
[in]uidunique identifier for the datastore
Return values
non-NULLsuccess
NULLfailure
Since
14.0.0

Definition at line 138 of file datastore.c.

References ao2_alloc, ao2_ref, ast_strdup, ast_strlen_zero, ast_uuid_generate_str(), AST_UUID_STR_LEN, datastore_destroy(), ast_datastore::info, sip_to_pjsip::info(), NULL, and ast_datastore::uid.

Referenced by ast_sip_subscription_alloc_datastore(), and dialog_info_generate_body_content().

139 {
140  struct ast_datastore *datastore;
141  char uuid_buf[AST_UUID_STR_LEN];
142  const char *uid_ptr = uid;
143 
144  if (!info) {
145  return NULL;
146  }
147 
148  datastore = ao2_alloc(sizeof(*datastore), datastore_destroy);
149  if (!datastore) {
150  return NULL;
151  }
152 
153  datastore->info = info;
154  if (ast_strlen_zero(uid)) {
155  /* They didn't provide an ID so we'll provide one ourself */
156  uid_ptr = ast_uuid_generate_str(uuid_buf, sizeof(uuid_buf));
157  }
158 
159  datastore->uid = ast_strdup(uid_ptr);
160  if (!datastore->uid) {
161  ao2_ref(datastore, -1);
162  return NULL;
163  }
164 
165  return datastore;
166 }
#define AST_UUID_STR_LEN
Definition: uuid.h:27
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
Structure for a data store object.
Definition: datastore.h:68
#define NULL
Definition: resample.c:96
const char * uid
Definition: datastore.h:69
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ao2_ref(o, delta)
Definition: astobj2.h:464
const struct ast_datastore_info * info
Definition: datastore.h:71
def info(msg)
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
char * ast_uuid_generate_str(char *buf, size_t size)
Generate a UUID string.
Definition: uuid.c:143
static void datastore_destroy(void *obj)
Definition: datastore.c:124

◆ ast_datastores_find()

struct ast_datastore* ast_datastores_find ( struct ao2_container datastores,
const char *  name 
)

Find a data store in a container.

Parameters
[in]datastorescontainer to find datastore in
[in]namename of the data store to find
Return values
non-NULLsuccess
NULLfailure
Since
14.0.0

Definition at line 119 of file datastore.c.

References ao2_find, and OBJ_SEARCH_KEY.

Referenced by ast_sip_publication_get_datastore(), ast_sip_subscription_get_datastore(), and dialog_info_generate_body_content().

120 {
121  return ao2_find(datastores, name, OBJ_SEARCH_KEY);
122 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
static const char name[]
Definition: cdr_mysql.c:74
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756

◆ ast_datastores_remove()

void ast_datastores_remove ( struct ao2_container datastores,
const char *  name 
)

Remove a data store from a container.

Parameters
[in]datastorescontainer to remove datastore from
[in]namename of the data store to remove
Since
14.0.0

Definition at line 114 of file datastore.c.

References ao2_find, OBJ_NODATA, OBJ_SEARCH_KEY, and OBJ_UNLINK.

Referenced by ast_sip_publication_remove_datastore(), and ast_sip_subscription_remove_datastore().

115 {
117 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
static const char name[]
Definition: cdr_mysql.c:74
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756

◆ datastore_destroy()

static void datastore_destroy ( void *  obj)
static

Definition at line 124 of file datastore.c.

References ast_free, ast_datastore::data, ast_datastore_info::destroy, ast_datastore::info, NULL, and ast_datastore::uid.

Referenced by ast_datastores_alloc_datastore().

125 {
126  struct ast_datastore *datastore = obj;
127 
128  /* Using the destroy function (if present) destroy the data */
129  if (datastore->info->destroy != NULL && datastore->data != NULL) {
130  datastore->info->destroy(datastore->data);
131  datastore->data = NULL;
132  }
133 
134  ast_free((void *) datastore->uid);
135  datastore->uid = NULL;
136 }
Structure for a data store object.
Definition: datastore.h:68
#define NULL
Definition: resample.c:96
const char * uid
Definition: datastore.h:69
const struct ast_datastore_info * info
Definition: datastore.h:71
void(* destroy)(void *data)
Definition: datastore.h:34
#define ast_free(a)
Definition: astmm.h:182
void * data
Definition: datastore.h:70