ASTdb Management. More...
#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/paths.h"
#include <sys/time.h>
#include <signal.h>
#include <dirent.h>
#include "asterisk/channel.h"
#include "asterisk/file.h"
#include "asterisk/app.h"
#include "asterisk/dsp.h"
#include "asterisk/astdb.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/manager.h"
#include "db1-ast/include/db.h"
Go to the source code of this file.
Macros | |
#define | MAX_DB_FIELD 256 |
Typedefs | |
typedef int(* | process_keys_cb )(DBT *key, DBT *value, const char *filter, void *data) |
Functions | |
int | ast_db_del (const char *family, const char *keys) |
Delete entry in astdb. More... | |
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. More... | |
void | ast_db_freetree (struct ast_db_entry *dbe) |
Free structure created by ast_db_gettree() More... | |
int | ast_db_get (const char *family, const char *keys, char *value, int valuelen) |
Get key value specified by family/key. More... | |
int | ast_db_get_allocated (const char *family, const char *keys, char **out) |
Get key value specified by family/key as a heap allocated string. More... | |
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. More... | |
int | ast_db_put (const char *family, const char *keys, const char *value) |
Store value addressed by family/key. More... | |
int | astdb_init (void) |
static void | astdb_shutdown (void) |
static int | db_deltree_cb (DBT *key, DBT *value, const char *filter, void *data) |
static int | db_get_common (const char *family, const char *keys, char **buffer, int bufferlen) |
static int | db_gettree_cb (DBT *key, DBT *value, const char *filter, void *data) |
static int | db_show_cb (DBT *key, DBT *value, const char *filter, void *data) |
static int | db_showkey_cb (DBT *key, DBT *value, const char *filter, void *data) |
static void | db_sync (void) |
static void * | db_sync_thread (void *data) |
static int | dbinit (void) |
static const char * | dbt_data2str (DBT *dbt) |
static const char * | dbt_data2str_full (DBT *dbt, const char *def) |
static char * | handle_cli_database_del (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | handle_cli_database_deltree (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | handle_cli_database_get (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | handle_cli_database_put (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | handle_cli_database_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | handle_cli_database_showkey (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static int | keymatch (const char *key, const char *prefix) |
static int | manager_dbdel (struct mansession *s, const struct message *m) |
static int | manager_dbdeltree (struct mansession *s, const struct message *m) |
static int | manager_dbget (struct mansession *s, const struct message *m) |
static int | manager_dbput (struct mansession *s, const struct message *m) |
static int | process_db_keys (process_keys_cb cb, void *data, const char *filter, int sync) |
static int | subkeymatch (const char *key, const char *suffix) |
Variables | |
static DB * | astdb |
static struct ast_cli_entry | cli_database [] |
static ast_cond_t | dbcond |
static ast_mutex_t | dblock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } |
static int | doexit |
static pthread_t | syncthread |
ASTdb Management.
Definition in file db.c.
#define MAX_DB_FIELD 256 |
Definition at line 107 of file db.c.
Referenced by ast_db_del(), ast_db_deltree(), ast_db_gettree(), ast_db_put(), db_get_common(), handle_cli_database_get(), handle_cli_database_show(), handle_cli_database_showkey(), manager_dbget(), and process_db_keys().
int ast_db_del | ( | const char * | family, |
const char * | keys | ||
) |
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(), handle_pri_service_generic(), manager_dbdel(), mkintf(), pri_dchannel(), process_clearcache(), reload_queue_members(), and update_registry().
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 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().
void ast_db_freetree | ( | struct ast_db_entry * | dbe | ) |
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().
int ast_db_get | ( | const char * | family, |
const char * | keys, | ||
char * | value, | ||
int | valuelen | ||
) |
Get key value specified by family/key.
Definition at line 348 of file db.c.
References ast_assert, and db_get_common().
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(), mkintf(), populate_addr(), and reg_source_db().
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().
-1 | An error occurred |
0 | Success |
Definition at line 358 of file db.c.
References db_get_common().
Referenced by reload_queue_members().
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 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().
int ast_db_put | ( | const char * | family, |
const char * | keys, | ||
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(), handle_pri_service_generic(), iax_provision_build(), manager_dbput(), mgcp_ss(), parse_register_contact(), pri_dchannel(), save_secret(), and update_registry().
int astdb_init | ( | void | ) |
Provided by db.c
Definition at line 880 of file db.c.
References ARRAY_LEN, ast_cli_register_multiple(), ast_cond_init, ast_manager_register_xml, ast_mutex_lock, ast_mutex_unlock, ast_pthread_create_background, ast_register_atexit(), astdb_shutdown(), db_sync_thread(), dbinit(), dblock, EVENT_FLAG_REPORTING, EVENT_FLAG_SYSTEM, manager_dbdel(), manager_dbdeltree(), manager_dbget(), and manager_dbput().
Referenced by main().
|
static |
Definition at line 854 of file db.c.
References ARRAY_LEN, ast_cli_unregister_multiple(), ast_manager_unregister(), ast_mutex_lock, ast_mutex_unlock, db_sync(), and dblock.
Referenced by astdb_init().
|
static |
Definition at line 230 of file db.c.
References dbt_data2str_full(), and keymatch().
Referenced by ast_db_deltree().
|
static |
Definition at line 302 of file db.c.
References ast_copy_string(), ast_debug, ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_strdup, dbinit(), dblock, LOG_NOTICE, and MAX_DB_FIELD.
Referenced by ast_db_get(), and ast_db_get_allocated().
|
static |
Definition at line 611 of file db.c.
References ast_malloc, ast_db_entry::data, dbt_data2str_full(), ast_db_entry::key, keymatch(), and ast_db_entry::next.
Referenced by ast_db_gettree().
|
static |
Definition at line 510 of file db.c.
References ast_cli(), dbt_data2str_full(), ast_cli_args::fd, and keymatch().
Referenced by handle_cli_database_show().
|
static |
Definition at line 565 of file db.c.
References ast_cli(), dbt_data2str_full(), ast_cli_args::fd, and subkeymatch().
Referenced by handle_cli_database_showkey().
|
static |
Definition at line 800 of file db.c.
References ast_cond_signal.
Referenced by ast_db_del(), ast_db_put(), astdb_shutdown(), and process_db_keys().
|
static |
Definition at line 815 of file db.c.
References ast_assert, ast_cond_wait, ast_mutex_lock, ast_mutex_unlock, and dblock.
Referenced by astdb_init().
|
static |
Definition at line 118 of file db.c.
References ast_config_AST_DB, AST_FILE_MODE, ast_log(), errno, and LOG_WARNING.
Referenced by ast_db_del(), ast_db_put(), astdb_init(), db_get_common(), load_module(), and process_db_keys().
|
static |
Definition at line 157 of file db.c.
Referenced by dbt_data2str_full().
|
inlinestatic |
Definition at line 169 of file db.c.
References dbt_data2str(), and S_OR.
Referenced by db_deltree_cb(), db_gettree_cb(), db_show_cb(), db_showkey_cb(), and process_db_keys().
|
static |
Definition at line 448 of file db.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_db_del(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
|
static |
Definition at line 475 of file db.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_db_deltree(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
|
static |
Definition at line 420 of file db.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_db_get(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, MAX_DB_FIELD, and ast_cli_entry::usage.
|
static |
Definition at line 393 of file db.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_db_put(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
|
static |
Definition at line 524 of file db.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, db_show_cb(), ast_cli_args::fd, MAX_DB_FIELD, prefix, process_db_keys(), and ast_cli_entry::usage.
|
static |
Definition at line 579 of file db.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, db_showkey_cb(), ast_cli_args::fd, MAX_DB_FIELD, process_db_keys(), and ast_cli_entry::usage.
|
inlinestatic |
Definition at line 130 of file db.c.
Referenced by db_deltree_cb(), db_gettree_cb(), and db_show_cb().
|
static |
Definition at line 741 of file db.c.
References ast_db_del(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), and astman_send_error().
Referenced by astdb_init().
|
static |
Definition at line 766 of file db.c.
References ast_db_deltree(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), and astman_send_error().
Referenced by astdb_init().
|
static |
Definition at line 700 of file db.c.
References ast_db_get(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_ack(), astman_send_error(), and MAX_DB_FIELD.
Referenced by astdb_init().
|
static |
Definition at line 675 of file db.c.
References ast_db_put(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), and S_OR.
Referenced by astdb_init().
|
static |
Definition at line 184 of file db.c.
References ast_mutex_lock, ast_mutex_unlock, db_sync(), dbinit(), dblock, dbt_data2str_full(), last, MAX_DB_FIELD, and MIN.
Referenced by ast_db_deltree(), ast_db_gettree(), handle_cli_database_show(), and handle_cli_database_showkey().
|
inlinestatic |
Definition at line 144 of file db.c.
Referenced by db_showkey_cb().
|
static |
|
static |
|
static |
Definition at line 110 of file db.c.
Referenced by ast_db_del(), ast_db_put(), astdb_init(), astdb_shutdown(), db_get_common(), db_sync_thread(), and process_db_keys().
|
static |
Definition at line 113 of file db.c.
Referenced by ast_monitor_change_fname().