Mon Mar 19 11:30:36 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 314 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().

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

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

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

void ast_db_freetree ( struct ast_db_entry entry  ) 

Free structure created by ast_db_gettree().

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

00604 {
00605    struct ast_db_entry *last;
00606    while (dbe) {
00607       last = dbe;
00608       dbe = dbe->next;
00609       ast_free(last);
00610    }
00611 }

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

Get key value specified by family/key.

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

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

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

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

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

Store value addressed by family/key.

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

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


Generated on Mon Mar 19 11:30:36 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7