Fri Jan 18 19:57:26 2013

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

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

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

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

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 ast_free, last, and ast_db_entry::next.

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

00653 {
00654    struct ast_db_entry *last;
00655    while (dbe) {
00656       last = dbe;
00657       dbe = dbe->next;
00658       ast_free(last);
00659    }
00660 }

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

References db_get_common().

Referenced by reload_queue_members().

00355 {
00356    *out = NULL;
00357 
00358    return db_get_common(family, keys, out, -1);
00359 }

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

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

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

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


Generated on 18 Jan 2013 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1