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. | |
| 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. | |
Persistant data storage (akin to *doze registry)
Definition in file astdb.h.
| int ast_db_del | ( | const char * | family, |
| const char * | key | ||
| ) |
Delete entry in astdb.
Definition at line 314 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(), __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.
| -1 | An error occurred |
| >= | 0 Number of records deleted |
Definition at line 223 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 599 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 | ||
| ) |
Get key value specified by family/key.
Definition at line 270 of file db.c.
References MAX_DB_FIELD, ast_mutex_lock, dblock, dbinit(), ast_mutex_unlock, ast_debug, ast_copy_string(), ast_log(), and LOG_NOTICE.
Referenced by database_increment(), auth_exec(), reload_queue_members(), destroy_all_channels(), mkintf(), create_addr(), check_access(), reg_source_db(), handle_cli_database_get(), manager_dbget(), blacklist_read(), function_db_read(), function_db_exists(), function_db_delete(), custom_devstate_callback(), iax_provision_version(), cache_lookup_internal(), load_password(), populate_addr(), ast_privacy_check(), and handle_dbget().
{
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));
memset(value, 0, valuelen);
key.data = fullkey;
key.size = fullkeylen + 1;
res = astdb->get(astdb, &key, &data, 0);
/* Be sure to NULL terminate our data either way */
if (res) {
ast_debug(1, "Unable to find key '%s' in family '%s'\n", keys, family);
} else {
#if 0
printf("Got value of size %d\n", data.size);
#endif
if (data.size) {
((char *)data.data)[data.size - 1] = '\0';
/* Make sure that we don't write too much to the dst pointer or we don't read too much from the source pointer */
ast_copy_string(value, data.data, (valuelen > data.size) ? data.size : valuelen);
} else {
ast_log(LOG_NOTICE, "Strange, empty value for /%s/%s\n", family, keys);
}
}
/* Data is not fully isolated for concurrency, so the lock must be extended
* to after the copy to the output buffer. */
ast_mutex_unlock(&dblock);
return res;
}
| 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 574 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 242 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(), 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;
}