Wed Jan 8 2020 09:49:57

Asterisk developer's documentation


astdb.h File Reference

Persistant data storage (akin to *doze registry) More...

Go to the source code of this file.

Data Structures

struct  ast_db_entry
 

Functions

int ast_db_del (const char *family, const char *key)
 Delete entry in astdb. More...
 
int ast_db_deltree (const char *family, const char *keytree)
 Delete one or more entries in astdb If both parameters are NULL, the entire database will be purged. If only keytree is NULL, all entries within the family will be purged. It is an error for keytree to have a value when family is NULL. More...
 
void ast_db_freetree (struct ast_db_entry *entry)
 Free structure created by ast_db_gettree() More...
 
int ast_db_get (const char *family, const char *key, char *out, int outlen)
 Get key value specified by family/key. More...
 
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. More...
 
struct ast_db_entryast_db_gettree (const char *family, const char *keytree)
 Get a list of values within the astdb tree If family is specified, only those keys will be returned. If keytree is specified, subkeys are expected to exist (separated from the key with a slash). If subkeys do not exist and keytree is specified, the tree will consist of either a single entry or NULL will be returned. More...
 
int ast_db_put (const char *family, const char *key, const char *value)
 Store value addressed by family/key. More...
 

Detailed Description

Persistant data storage (akin to *doze registry)

Definition in file astdb.h.

Function Documentation

int ast_db_del ( const char *  family,
const char *  key 
)

Delete entry in astdb.

Definition at line 365 of file db.c.

References ast_debug, ast_mutex_lock, ast_mutex_unlock, db_sync(), dbinit(), dblock, and MAX_DB_FIELD.

Referenced by __expire_registry(), ast_privacy_set(), auth_exec(), cache_lookup_internal(), del_exec(), destroy_all_channels(), destroy_association(), dialgroup_refreshdb(), dump_queue_members(), function_db_delete(), handle_cli_database_del(), handle_dbdel(), handle_pri_service_generic(), manager_dbdel(), mkintf(), pri_dchannel(), process_clearcache(), reload_queue_members(), and update_registry().

366 {
367  char fullkey[MAX_DB_FIELD];
368  DBT key;
369  int res, fullkeylen;
370 
372  if (dbinit()) {
374  return -1;
375  }
376 
377  fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
378  memset(&key, 0, sizeof(key));
379  key.data = fullkey;
380  key.size = fullkeylen + 1;
381 
382  res = astdb->del(astdb, &key, 0);
383  db_sync();
384 
386 
387  if (res) {
388  ast_debug(1, "Unable to find key '%s' in family '%s'\n", keys, family);
389  }
390  return res;
391 }
#define ast_mutex_lock(a)
Definition: lock.h:155
static ast_mutex_t dblock
Definition: db.c:110
static int dbinit(void)
Definition: db.c:118
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static DB * astdb
Definition: db.c:109
static void db_sync(void)
Definition: db.c:800
#define MAX_DB_FIELD
Definition: db.c:107
#define ast_mutex_unlock(a)
Definition: lock.h:156
int ast_db_deltree ( const char *  family,
const char *  keytree 
)

Delete one or more entries in astdb If both parameters are NULL, the entire database will be purged. If only keytree is NULL, all entries within the family will be purged. It is an error for keytree to have a value when family is NULL.

Return values
-1An error occurred
>=0 Number of records deleted

Definition at line 241 of file db.c.

References db_deltree_cb(), MAX_DB_FIELD, prefix, and process_db_keys().

Referenced by ast_privacy_reset(), deltree_exec(), dundi_flush(), handle_cli_database_deltree(), handle_dbdeltree(), iax_provision_reload(), and manager_dbdeltree().

242 {
243  char prefix[MAX_DB_FIELD];
244 
245  if (family) {
246  if (keytree) {
247  snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree);
248  } else {
249  snprintf(prefix, sizeof(prefix), "/%s", family);
250  }
251  } else if (keytree) {
252  return -1;
253  } else {
254  prefix[0] = '\0';
255  }
256 
257  return process_db_keys(db_deltree_cb, NULL, prefix, 1);
258 }
static int process_db_keys(process_keys_cb cb, void *data, const char *filter, int sync)
Definition: db.c:184
static int db_deltree_cb(DBT *key, DBT *value, const char *filter, void *data)
Definition: db.c:230
#define MAX_DB_FIELD
Definition: db.c:107
static char prefix[MAX_PREFIX]
Definition: http.c:107
void ast_db_freetree ( struct ast_db_entry entry)

Free structure created by ast_db_gettree()

Definition at line 656 of file db.c.

References ast_free, last, and ast_db_entry::next.

Referenced by handle_cli_devstate_list(), load_module(), process_clearcache(), and reload_queue_members().

657 {
658  struct ast_db_entry *last;
659  while (dbe) {
660  last = dbe;
661  dbe = dbe->next;
662  ast_free(last);
663  }
664 }
struct ast_db_entry * next
Definition: astdb.h:31
struct sla_ringing_trunk * last
Definition: app_meetme.c:965
Definition: astdb.h:30
#define ast_free(a)
Definition: astmm.h:97
int ast_db_get ( const char *  family,
const char *  key,
char *  out,
int  outlen 
)

Get key value specified by family/key.

Definition at line 348 of file db.c.

References ast_assert, and db_get_common().

Referenced by ast_privacy_check(), auth_exec(), blacklist_read(), cache_lookup_internal(), check_access(), create_addr(), custom_devstate_callback(), database_increment(), destroy_all_channels(), function_db_delete(), function_db_exists(), function_db_read(), handle_cli_database_get(), handle_dbget(), iax_provision_version(), load_password(), manager_dbget(), mkintf(), populate_addr(), and reg_source_db().

349 {
350  ast_assert(value != NULL);
351 
352  /* Make sure we initialize */
353  value[0] = 0;
354 
355  return db_get_common(family, keys, &value, valuelen);
356 }
#define ast_assert(a)
Definition: utils.h:738
int value
Definition: syslog.c:39
static int db_get_common(const char *family, const char *keys, char **buffer, int bufferlen)
Definition: db.c:302
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.

Given a family and key, sets out to a pointer to a heap allocated string. In the event of an error, out will be set to NULL. The string must be freed by calling ast_free().

Return values
-1An error occurred
0Success

Definition at line 358 of file db.c.

References db_get_common().

Referenced by reload_queue_members().

359 {
360  *out = NULL;
361 
362  return db_get_common(family, keys, out, -1);
363 }
static int db_get_common(const char *family, const char *keys, char **buffer, int bufferlen)
Definition: db.c:302
struct ast_db_entry* ast_db_gettree ( const char *  family,
const char *  keytree 
)

Get a list of values within the astdb tree If family is specified, only those keys will be returned. If keytree is specified, subkeys are expected to exist (separated from the key with a slash). If subkeys do not exist and keytree is specified, the tree will consist of either a single entry or NULL will be returned.

Resulting tree should be freed by passing the return value to ast_db_freetree() when usage is concluded.

Definition at line 631 of file db.c.

References ast_log(), ast_strlen_zero(), db_gettree_cb(), LOG_WARNING, MAX_DB_FIELD, prefix, and process_db_keys().

Referenced by handle_cli_devstate_list(), load_module(), process_clearcache(), and reload_queue_members().

632 {
633  char prefix[MAX_DB_FIELD];
634  struct ast_db_entry *ret = NULL;
635 
636  if (!ast_strlen_zero(family)) {
637  if (!ast_strlen_zero(keytree)) {
638  /* Family and key tree */
639  snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree);
640  } else {
641  /* Family only */
642  snprintf(prefix, sizeof(prefix), "/%s", family);
643  }
644  } else {
645  prefix[0] = '\0';
646  }
647 
648  if (process_db_keys(db_gettree_cb, &ret, prefix, 0) < 0) {
649  ast_log(LOG_WARNING, "Database unavailable\n");
650  return NULL;
651  }
652 
653  return ret;
654 }
#define LOG_WARNING
Definition: logger.h:144
static int db_gettree_cb(DBT *key, DBT *value, const char *filter, void *data)
Definition: db.c:611
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static int process_db_keys(process_keys_cb cb, void *data, const char *filter, int sync)
Definition: db.c:184
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
Definition: astdb.h:30
#define MAX_DB_FIELD
Definition: db.c:107
static char prefix[MAX_PREFIX]
Definition: http.c:107
int ast_db_put ( const char *  family,
const char *  key,
const char *  value 
)

Store value addressed by family/key.

Definition at line 260 of file db.c.

References ast_log(), ast_mutex_lock, ast_mutex_unlock, db_sync(), dbinit(), dblock, LOG_WARNING, and MAX_DB_FIELD.

Referenced by __analog_ss_thread(), ast_privacy_set(), cache_save(), cache_save_hint(), database_increment(), devstate_write(), dialgroup_refreshdb(), dump_queue_members(), function_db_write(), handle_cli_database_put(), handle_cli_devstate_change(), handle_command_response(), handle_dbput(), handle_pri_service_generic(), iax_provision_build(), manager_dbput(), mgcp_ss(), parse_register_contact(), pri_dchannel(), save_secret(), and update_registry().

261 {
262  char fullkey[MAX_DB_FIELD];
263  DBT key, data;
264  int res, fullkeylen;
265 
267  if (dbinit()) {
269  return -1;
270  }
271 
272  fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
273  memset(&key, 0, sizeof(key));
274  memset(&data, 0, sizeof(data));
275  key.data = fullkey;
276  key.size = fullkeylen + 1;
277  data.data = (char *) value;
278  data.size = strlen(value) + 1;
279  res = astdb->put(astdb, &key, &data, 0);
280  db_sync();
282  if (res)
283  ast_log(LOG_WARNING, "Unable to put value '%s' for key '%s' in family '%s'\n", value, keys, family);
284 
285  return res;
286 }
#define LOG_WARNING
Definition: logger.h:144
#define ast_mutex_lock(a)
Definition: lock.h:155
static ast_mutex_t dblock
Definition: db.c:110
int value
Definition: syslog.c:39
static int dbinit(void)
Definition: db.c:118
static DB * astdb
Definition: db.c:109
static void db_sync(void)
Definition: db.c:800
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
char data[0]
Definition: astdb.h:33
#define MAX_DB_FIELD
Definition: db.c:107
#define ast_mutex_unlock(a)
Definition: lock.h:156
char * key
Definition: astdb.h:32