Wed Aug 7 17:15:51 2019

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.
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_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.
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 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(), manager_dbdel(), mkintf(), process_clearcache(), reload_queue_members(), and update_registry().

00366 {
00367    char fullkey[MAX_DB_FIELD];
00368    DBT key;
00369    int res, fullkeylen;
00370 
00371    ast_mutex_lock(&dblock);
00372    if (dbinit()) {
00373       ast_mutex_unlock(&dblock);
00374       return -1;
00375    }
00376    
00377    fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
00378    memset(&key, 0, sizeof(key));
00379    key.data = fullkey;
00380    key.size = fullkeylen + 1;
00381    
00382    res = astdb->del(astdb, &key, 0);
00383    db_sync();
00384    
00385    ast_mutex_unlock(&dblock);
00386 
00387    if (res) {
00388       ast_debug(1, "Unable to find key '%s' in family '%s'\n", keys, family);
00389    }
00390    return res;
00391 }

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:
-1 An 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().

00242 {
00243    char prefix[MAX_DB_FIELD];
00244 
00245    if (family) {
00246       if (keytree) {
00247          snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree);
00248       } else {
00249          snprintf(prefix, sizeof(prefix), "/%s", family);
00250       }
00251    } else if (keytree) {
00252       return -1;
00253    } else {
00254       prefix[0] = '\0';
00255    }
00256 
00257    return process_db_keys(db_deltree_cb, NULL, prefix, 1);
00258 }

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().

00657 {
00658    struct ast_db_entry *last;
00659    while (dbe) {
00660       last = dbe;
00661       dbe = dbe->next;
00662       ast_free(last);
00663    }
00664 }

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:
-1 An error occurred
0 Success

Definition at line 358 of file db.c.

References db_get_common().

Referenced by reload_queue_members().

00359 {
00360    *out = NULL;
00361 
00362    return db_get_common(family, keys, out, -1);
00363 }

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 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().

00632 {
00633    char prefix[MAX_DB_FIELD];
00634    struct ast_db_entry *ret = NULL;
00635 
00636    if (!ast_strlen_zero(family)) {
00637       if (!ast_strlen_zero(keytree)) {
00638          /* Family and key tree */
00639          snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree);
00640       } else {
00641          /* Family only */
00642          snprintf(prefix, sizeof(prefix), "/%s", family);
00643       }
00644    } else {
00645       prefix[0] = '\0';
00646    }
00647 
00648    if (process_db_keys(db_gettree_cb, &ret, prefix, 0) < 0) {
00649       ast_log(LOG_WARNING, "Database unavailable\n");
00650       return NULL;
00651    }
00652 
00653    return ret;
00654 }

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(), iax_provision_build(), manager_dbput(), mgcp_ss(), parse_register_contact(), save_secret(), and update_registry().

00261 {
00262    char fullkey[MAX_DB_FIELD];
00263    DBT key, data;
00264    int res, fullkeylen;
00265 
00266    ast_mutex_lock(&dblock);
00267    if (dbinit()) {
00268       ast_mutex_unlock(&dblock);
00269       return -1;
00270    }
00271 
00272    fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
00273    memset(&key, 0, sizeof(key));
00274    memset(&data, 0, sizeof(data));
00275    key.data = fullkey;
00276    key.size = fullkeylen + 1;
00277    data.data = (char *) value;
00278    data.size = strlen(value) + 1;
00279    res = astdb->put(astdb, &key, &data, 0);
00280    db_sync();
00281    ast_mutex_unlock(&dblock);
00282    if (res)
00283       ast_log(LOG_WARNING, "Unable to put value '%s' for key '%s' in family '%s'\n", value, keys, family);
00284 
00285    return res;
00286 }


Generated on 7 Aug 2019 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1