Mon Oct 8 12:39:11 2012

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

00319 {
00320    char fullkey[MAX_DB_FIELD];
00321    DBT key;
00322    int res, fullkeylen;
00323 
00324    ast_mutex_lock(&dblock);
00325    if (dbinit()) {
00326       ast_mutex_unlock(&dblock);
00327       return -1;
00328    }
00329    
00330    fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
00331    memset(&key, 0, sizeof(key));
00332    key.data = fullkey;
00333    key.size = fullkeylen + 1;
00334    
00335    res = astdb->del(astdb, &key, 0);
00336    db_sync();
00337    
00338    ast_mutex_unlock(&dblock);
00339 
00340    if (res) {
00341       ast_debug(1, "Unable to find key '%s' in family '%s'\n", keys, family);
00342    }
00343    return res;
00344 }

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

00228 {
00229    char prefix[MAX_DB_FIELD];
00230 
00231    if (family) {
00232       if (keytree) {
00233          snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree);
00234       } else {
00235          snprintf(prefix, sizeof(prefix), "/%s", family);
00236       }
00237    } else if (keytree) {
00238       return -1;
00239    } else {
00240       prefix[0] = '\0';
00241    }
00242 
00243    return process_db_keys(db_deltree_cb, NULL, prefix, 1);
00244 }

void ast_db_freetree ( struct ast_db_entry entry  ) 

Free structure created by ast_db_gettree().

Definition at line 607 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().

00608 {
00609    struct ast_db_entry *last;
00610    while (dbe) {
00611       last = dbe;
00612       dbe = dbe->next;
00613       ast_free(last);
00614    }
00615 }

int ast_db_get ( const char *  family,
const char *  key,
char *  out,
int  outlen 
)

Get key value specified by family/key.

Definition at line 274 of file db.c.

References ast_copy_string(), ast_debug, ast_log(), ast_mutex_lock, ast_mutex_unlock, dbinit(), dblock, LOG_NOTICE, and MAX_DB_FIELD.

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(), populate_addr(), reg_source_db(), and reload_queue_members().

00275 {
00276    char fullkey[MAX_DB_FIELD] = "";
00277    DBT key, data;
00278    int res, fullkeylen;
00279 
00280    ast_mutex_lock(&dblock);
00281    if (dbinit()) {
00282       ast_mutex_unlock(&dblock);
00283       return -1;
00284    }
00285 
00286    fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
00287    memset(&key, 0, sizeof(key));
00288    memset(&data, 0, sizeof(data));
00289    memset(value, 0, valuelen);
00290    key.data = fullkey;
00291    key.size = fullkeylen + 1;
00292 
00293    res = astdb->get(astdb, &key, &data, 0);
00294 
00295    /* Be sure to NULL terminate our data either way */
00296    if (res) {
00297       ast_debug(1, "Unable to find key '%s' in family '%s'\n", keys, family);
00298    } else {
00299 #if 0
00300       printf("Got value of size %d\n", data.size);
00301 #endif
00302       if (data.size) {
00303          ((char *)data.data)[data.size - 1] = '\0';
00304          /* Make sure that we don't write too much to the dst pointer or we don't read too much from the source pointer */
00305          ast_copy_string(value, data.data, (valuelen > data.size) ? data.size : valuelen);
00306       } else {
00307          ast_log(LOG_NOTICE, "Strange, empty value for /%s/%s\n", family, keys);
00308       }
00309    }
00310 
00311    /* Data is not fully isolated for concurrency, so the lock must be extended
00312     * to after the copy to the output buffer. */
00313    ast_mutex_unlock(&dblock);
00314 
00315    return res;
00316 }

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

00583 {
00584    char prefix[MAX_DB_FIELD];
00585    struct ast_db_entry *ret = NULL;
00586 
00587    if (!ast_strlen_zero(family)) {
00588       if (!ast_strlen_zero(keytree)) {
00589          /* Family and key tree */
00590          snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree);
00591       } else {
00592          /* Family only */
00593          snprintf(prefix, sizeof(prefix), "/%s", family);
00594       }
00595    } else {
00596       prefix[0] = '\0';
00597    }
00598 
00599    if (process_db_keys(db_gettree_cb, &ret, prefix, 0) < 0) {
00600       ast_log(LOG_WARNING, "Database unavailable\n");
00601       return NULL;
00602    }
00603 
00604    return ret;
00605 }

int ast_db_put ( const char *  family,
const char *  key,
const char *  value 
)

Store value addressed by family/key.

Definition at line 246 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().

00247 {
00248    char fullkey[MAX_DB_FIELD];
00249    DBT key, data;
00250    int res, fullkeylen;
00251 
00252    ast_mutex_lock(&dblock);
00253    if (dbinit()) {
00254       ast_mutex_unlock(&dblock);
00255       return -1;
00256    }
00257 
00258    fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
00259    memset(&key, 0, sizeof(key));
00260    memset(&data, 0, sizeof(data));
00261    key.data = fullkey;
00262    key.size = fullkeylen + 1;
00263    data.data = (char *) value;
00264    data.size = strlen(value) + 1;
00265    res = astdb->put(astdb, &key, &data, 0);
00266    db_sync();
00267    ast_mutex_unlock(&dblock);
00268    if (res)
00269       ast_log(LOG_WARNING, "Unable to put value '%s' for key '%s' in family '%s'\n", value, keys, family);
00270 
00271    return res;
00272 }


Generated on Mon Oct 8 12:39:11 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7