Wed Nov 28 2012 04:18:25

Asterisk developer's documentation


astdb.h File Reference

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

This graph shows which files directly or indirectly include this file:

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.
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.
void ast_db_freetree (struct ast_db_entry *entry)
 Free structure created by ast_db_gettree()
int ast_db_get (const char *family, const char *key, char *out, int outlen)
 Get key value specified by family/key.
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.
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.
int ast_db_put (const char *family, const char *key, const char *value)
 Store value addressed by family/key.

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 361 of file db.c.

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

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

{
   char fullkey[MAX_DB_FIELD];
   DBT key;
   int res, fullkeylen;

   ast_mutex_lock(&dblock);
   if (dbinit()) {
      ast_mutex_unlock(&dblock);
      return -1;
   }
   
   fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
   memset(&key, 0, sizeof(key));
   key.data = fullkey;
   key.size = fullkeylen + 1;
   
   res = astdb->del(astdb, &key, 0);
   db_sync();
   
   ast_mutex_unlock(&dblock);

   if (res) {
      ast_debug(1, "Unable to find key '%s' in family '%s'\n", keys, family);
   }
   return res;
}
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 237 of file db.c.

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

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

{
   char prefix[MAX_DB_FIELD];

   if (family) {
      if (keytree) {
         snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree);
      } else {
         snprintf(prefix, sizeof(prefix), "/%s", family);
      }
   } else if (keytree) {
      return -1;
   } else {
      prefix[0] = '\0';
   }

   return process_db_keys(db_deltree_cb, NULL, prefix, 1);
}
void ast_db_freetree ( struct ast_db_entry *  entry)

Free structure created by ast_db_gettree()

Definition at line 652 of file db.c.

References last, ast_db_entry::next, and ast_free.

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

{
   struct ast_db_entry *last;
   while (dbe) {
      last = dbe;
      dbe = dbe->next;
      ast_free(last);
   }
}
int ast_db_get ( const char *  family,
const char *  key,
char *  out,
int  outlen 
)
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 354 of file db.c.

References db_get_common().

Referenced by reload_queue_members().

{
   *out = NULL;

   return db_get_common(family, keys, out, -1);
}
struct ast_db_entry* ast_db_gettree ( const char *  family,
const char *  keytree 
) [read]

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 627 of file db.c.

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

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

{
   char prefix[MAX_DB_FIELD];
   struct ast_db_entry *ret = NULL;

   if (!ast_strlen_zero(family)) {
      if (!ast_strlen_zero(keytree)) {
         /* Family and key tree */
         snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree);
      } else {
         /* Family only */
         snprintf(prefix, sizeof(prefix), "/%s", family);
      }
   } else {
      prefix[0] = '\0';
   }

   if (process_db_keys(db_gettree_cb, &ret, prefix, 0) < 0) {
      ast_log(LOG_WARNING, "Database unavailable\n");
      return NULL;
   }

   return ret;
}
int ast_db_put ( const char *  family,
const char *  key,
const char *  value 
)

Store value addressed by family/key.

Definition at line 256 of file db.c.

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

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

{
   char fullkey[MAX_DB_FIELD];
   DBT key, data;
   int res, fullkeylen;

   ast_mutex_lock(&dblock);
   if (dbinit()) {
      ast_mutex_unlock(&dblock);
      return -1;
   }

   fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
   memset(&key, 0, sizeof(key));
   memset(&data, 0, sizeof(data));
   key.data = fullkey;
   key.size = fullkeylen + 1;
   data.data = (char *) value;
   data.size = strlen(value) + 1;
   res = astdb->put(astdb, &key, &data, 0);
   db_sync();
   ast_mutex_unlock(&dblock);
   if (res)
      ast_log(LOG_WARNING, "Unable to put value '%s' for key '%s' in family '%s'\n", value, keys, family);

   return res;
}