Asterisk - The Open Source Telephony Project
18.5.0
|
ASTdb Management. More...
#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/paths.h"
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#include <dirent.h>
#include <sqlite3.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/manager.h"
Go to the source code of this file.
Macros | |
#define | DEFINE_SQL_STATEMENT(stmt, sql) |
#define | MAX_DB_FIELD 256 |
Functions | |
static int | ast_db_begin_transaction (void) |
static int | ast_db_commit_transaction (void) |
int | ast_db_del (const char *family, const char *key) |
Delete entry in astdb. More... | |
int | ast_db_deltree (const char *family, const char *keytree) |
Delete one or more entries in astdb. 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 *key, char *value, int valuelen) |
Get key value specified by family/key. More... | |
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. More... | |
struct ast_db_entry * | ast_db_gettree (const char *family, const char *keytree) |
Get a list of values within the astdb tree. More... | |
struct ast_db_entry * | ast_db_gettree_by_prefix (const char *family, const char *key_prefix) |
Get a list of values with the given key prefix. More... | |
int | ast_db_put (const char *family, const char *key, const char *value) |
Store value addressed by family/key. More... | |
static int | ast_db_rollback_transaction (void) |
static void | astdb_atexit (void) |
int | astdb_init (void) |
static void | clean_statements (void) |
static int | clean_stmt (sqlite3_stmt **stmt, const char *sql) |
static int | convert_bdb_to_sqlite3 (void) |
static int | db_create_astdb (void) |
static int | db_execute_sql (const char *sql, int(*callback)(void *, int, char **, char **), void *arg) |
static int | db_get_common (const char *family, const char *key, char **buffer, int bufferlen) |
static struct ast_db_entry * | db_gettree_common (sqlite3_stmt *stmt) |
static int | db_init (void) |
static int | db_open (void) |
static void | db_sync (void) |
static void * | db_sync_thread (void *data) |
DEFINE_SQL_STATEMENT (put_stmt, "INSERT OR REPLACE INTO astdb (key, value) VALUES (?, ?)") | |
static int | display_results (void *arg, int columns, char **values, char **colnames) |
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_query (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 | init_statements (void) |
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) |
Variables | |
static sqlite3 * | 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, 0} } |
static int | doexit |
static int | dosync |
static pthread_t | syncthread |
ASTdb Management.
Definition in file main/db.c.
#define DEFINE_SQL_STATEMENT | ( | stmt, | |
sql | |||
) |
#define MAX_DB_FIELD 256 |
Definition at line 107 of file main/db.c.
Referenced by ast_db_del(), ast_db_deltree(), ast_db_gettree(), ast_db_gettree_by_prefix(), ast_db_put(), db_get_common(), handle_cli_database_get(), handle_cli_database_show(), and manager_dbget().
|
static |
Definition at line 312 of file main/db.c.
References db_execute_sql(), and NULL.
Referenced by db_sync_thread().
|
static |
Definition at line 317 of file main/db.c.
References db_execute_sql(), and NULL.
Referenced by db_sync_thread().
int ast_db_del | ( | const char * | family, |
const char * | key | ||
) |
Delete entry in astdb.
Definition at line 429 of file main/db.c.
References ast_debug, ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, db_sync(), dblock, LOG_WARNING, and MAX_DB_FIELD.
Referenced by __expire_registry(), ast_privacy_set(), AST_TEST_DEFINE(), auth_exec(), cache_lookup_internal(), dahdi_cc_callback(), destroy_all_channels(), destroy_association(), dialgroup_refreshdb(), do_register_expire(), dump_queue_members(), function_db_delete(), handle_cli_database_del(), handle_dbdel(), manager_dbdel(), media_cache_item_del_from_astdb(), media_cache_remove_from_astdb(), mkintf(), presence_change_common(), process_clearcache(), reload_queue_members(), remove_public_key_from_astdb(), sorcery_astdb_delete(), stasis_app_device_state_delete(), 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 457 of file main/db.c.
References ast_log, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero, astdb, db_sync(), dblock, LOG_WARNING, MAX_DB_FIELD, and prefix.
Referenced by ast_privacy_reset(), AST_TEST_DEFINE(), deinitialize_sorcery(), deltree_exec(), dundi_flush(), handle_cli_database_deltree(), handle_dbdeltree(), iax_provision_reload(), manager_dbdeltree(), media_cache_item_del_from_astdb(), media_cache_remove_from_astdb(), and remove_public_key_from_astdb().
void ast_db_freetree | ( | struct ast_db_entry * | dbe | ) |
Free structure created by ast_db_gettree()
Definition at line 598 of file main/db.c.
References ast_free, last, and ast_db_entry::next.
Referenced by AST_TEST_DEFINE(), dundi_show_cache(), dundi_show_hints(), function_db_keys(), handle_cli_devstate_list(), handle_cli_presencestate_list(), load_module(), media_cache_item_populate_from_astdb(), media_cache_populate_from_astdb(), populate_cache(), process_clearcache(), reload_queue_members(), sorcery_astdb_retrieve_fields_common(), sorcery_astdb_retrieve_prefix(), sorcery_astdb_retrieve_regex(), and stasis_app_device_states_to_json().
int ast_db_get | ( | const char * | family, |
const char * | key, | ||
char * | value, | ||
int | valuelen | ||
) |
Get key value specified by family/key.
Definition at line 412 of file main/db.c.
References ast_assert, db_get_common(), and NULL.
Referenced by ast_pbx_uuid_get(), ast_privacy_check(), AST_TEST_DEFINE(), auth_exec(), blacklist_read(), cache_lookup_internal(), check_access(), create_addr(), custom_devstate_callback(), custom_presence_callback(), database_increment(), destroy_all_channels(), function_db_delete(), function_db_exists(), function_db_read(), get_path_to_public_key(), handle_cli_database_get(), handle_dbget(), iax_provision_version(), load_password(), manager_dbget(), mkintf(), populate_addr(), public_key_is_expired(), refresh_all_favorite(), reg_source_db(), remove_public_key_from_astdb(), sorcery_astdb_delete(), sorcery_astdb_update(), and stasis_device_state_cb().
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 422 of file main/db.c.
References db_get_common(), and NULL.
Referenced by AST_TEST_DEFINE(), media_cache_item_del_from_astdb(), reload_queue_members(), and sorcery_astdb_retrieve_id().
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 531 of file main/db.c.
References ast_log, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero, astdb, db_gettree_common(), dblock, LOG_WARNING, MAX_DB_FIELD, NULL, and prefix.
Referenced by AST_TEST_DEFINE(), dundi_show_cache(), dundi_show_hints(), function_db_keys(), handle_cli_devstate_list(), handle_cli_presencestate_list(), load_module(), media_cache_item_populate_from_astdb(), media_cache_populate_from_astdb(), populate_cache(), process_clearcache(), reload_queue_members(), sorcery_astdb_retrieve_fields_common(), sorcery_astdb_retrieve_regex(), and stasis_app_device_states_to_json().
struct ast_db_entry* ast_db_gettree_by_prefix | ( | const char * | family, |
const char * | key_prefix | ||
) |
Get a list of values with the given key prefix.
family | The family to search under |
key_prefix | The key prefix to search under |
NULL | An error occurred |
Definition at line 571 of file main/db.c.
References ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, db_gettree_common(), dblock, LOG_WARNING, MAX_DB_FIELD, NULL, and prefix.
Referenced by sorcery_astdb_retrieve_prefix().
int ast_db_put | ( | const char * | family, |
const char * | key, | ||
const char * | value | ||
) |
Store value addressed by family/key.
Definition at line 327 of file main/db.c.
References ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, db_sync(), dblock, LOG_WARNING, and MAX_DB_FIELD.
Referenced by __analog_ss_thread(), add_public_key_to_astdb(), ast_privacy_set(), AST_TEST_DEFINE(), asterisk_daemon(), cache_save(), cache_save_hint(), dahdi_cc_callback(), database_increment(), devstate_write(), dialgroup_refreshdb(), dump_queue_members(), function_db_write(), handle_cli_database_put(), handle_cli_devstate_change(), handle_cli_presencestate_change(), handle_command_response(), handle_dbput(), iax_provision_build(), manager_dbput(), media_cache_item_sync_to_astdb(), metadata_sync_to_astdb(), mgcp_ss(), parse_register_contact(), presence_write(), save_secret(), set_public_key_expiration(), sorcery_astdb_create(), stasis_app_device_state_update(), test_stir_shaken_add_fake_astdb_entry(), and update_registry().
|
static |
Definition at line 322 of file main/db.c.
References db_execute_sql(), and NULL.
Referenced by db_sync_thread().
|
static |
Definition at line 1058 of file main/db.c.
References ARRAY_LEN, ast_cli_unregister_multiple(), ast_manager_unregister(), ast_mutex_lock, ast_mutex_unlock, astdb, clean_statements(), db_sync(), dblock, doexit, NULL, and syncthread.
Referenced by astdb_init().
int astdb_init | ( | void | ) |
Provided by db.c
Definition at line 1082 of file main/db.c.
References ARRAY_LEN, ast_cli_register_multiple, ast_cond_init, ast_manager_register_xml_core, ast_pthread_create_background, ast_register_atexit(), astdb_atexit(), db_init(), db_sync_thread(), dbcond, EVENT_FLAG_REPORTING, EVENT_FLAG_SYSTEM, manager_dbdel(), manager_dbdeltree(), manager_dbget(), manager_dbput(), NULL, and syncthread.
Referenced by asterisk_daemon().
|
static |
|
static |
Definition at line 161 of file main/db.c.
References ast_log, astdb, LOG_WARNING, and NULL.
Referenced by clean_statements().
|
static |
Definition at line 205 of file main/db.c.
References ast_asprintf, ast_config_AST_DB, ast_config_AST_SBIN_DIR, ast_free, and ast_safe_system().
Referenced by db_open().
|
static |
Definition at line 219 of file main/db.c.
References ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, db_sync(), dblock, init_stmt(), and LOG_WARNING.
Referenced by db_init().
|
static |
Definition at line 298 of file main/db.c.
References ast_log, astdb, LOG_WARNING, and NULL.
Referenced by ast_db_begin_transaction(), ast_db_commit_transaction(), ast_db_rollback_transaction(), and handle_cli_database_query().
|
static |
Definition at line 373 of file main/db.c.
References ast_copy_string(), ast_debug, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_strdup, astdb, dblock, LOG_WARNING, MAX_DB_FIELD, result, and value.
Referenced by ast_db_get(), and ast_db_get_allocated().
|
static |
Definition at line 492 of file main/db.c.
References ast_malloc, ast_db_entry::key, NULL, and value.
Referenced by ast_db_gettree(), and ast_db_gettree_by_prefix().
|
static |
Definition at line 282 of file main/db.c.
References astdb, db_create_astdb(), db_open(), and init_statements().
Referenced by astdb_init().
|
static |
Definition at line 239 of file main/db.c.
References ast_alloca, ast_config_AST_DB, ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, convert_bdb_to_sqlite3(), dblock, dbname, LOG_ERROR, LOG_NOTICE, and LOG_WARNING.
Referenced by db_init().
|
static |
Definition at line 1009 of file main/db.c.
References ast_cond_signal, dbcond, and dosync.
Referenced by ast_db_del(), ast_db_deltree(), ast_db_put(), astdb_atexit(), db_create_astdb(), and handle_cli_database_query().
|
static |
Definition at line 1025 of file main/db.c.
References ast_cond_wait, ast_db_begin_transaction(), ast_db_commit_transaction(), ast_db_rollback_transaction(), ast_mutex_lock, ast_mutex_unlock, dbcond, dblock, doexit, dosync, and NULL.
Referenced by astdb_init().
Definition at line 120 of file main/db.c.
References ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, dblock, LOG_WARNING, and NULL.
|
static |
Definition at line 834 of file main/db.c.
References a, ast_cli(), columns, and ast_cli_args::fd.
Referenced by handle_cli_database_query().
|
static |
Definition at line 663 of file main/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, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 690 of file main/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, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 635 of file main/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, NULL, tmp(), and ast_cli_entry::usage.
|
static |
Definition at line 608 of file main/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, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 847 of file main/db.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_mutex_lock, ast_mutex_unlock, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, db_execute_sql(), db_sync(), dblock, display_results(), NULL, and ast_cli_entry::usage.
|
static |
Definition at line 725 of file main/db.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_log, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero, astdb, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, dblock, ast_cli_args::fd, LOG_WARNING, MAX_DB_FIELD, NULL, prefix, and ast_cli_entry::usage.
|
static |
Definition at line 789 of file main/db.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_log, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero, astdb, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, dblock, ast_cli_args::fd, LOG_WARNING, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 190 of file main/db.c.
References init_stmt().
Referenced by db_init().
|
static |
Definition at line 950 of file main/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 975 of file main/db.c.
References ast_db_deltree(), ast_strlen_zero, astman_get_header(), astman_send_ack(), astman_send_error(), and NULL.
Referenced by astdb_init().
|
static |
Definition at line 908 of file main/db.c.
References ast_db_get(), ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), MAX_DB_FIELD, and tmp().
Referenced by astdb_init().
|
static |
Definition at line 883 of file main/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 110 of file main/db.c.
Referenced by ast_db_del(), ast_db_deltree(), ast_db_gettree(), ast_db_gettree_by_prefix(), ast_db_put(), astdb_atexit(), clean_stmt(), db_create_astdb(), db_execute_sql(), db_get_common(), db_init(), db_open(), DEFINE_SQL_STATEMENT(), handle_cli_database_show(), and handle_cli_database_showkey().
|
static |
|
static |
Definition at line 109 of file main/db.c.
Referenced by astdb_init(), db_sync(), and db_sync_thread().
|
static |
Definition at line 108 of file main/db.c.
Referenced by ast_db_del(), ast_db_deltree(), ast_db_gettree(), ast_db_gettree_by_prefix(), ast_db_put(), astdb_atexit(), db_create_astdb(), db_get_common(), db_open(), db_sync_thread(), DEFINE_SQL_STATEMENT(), handle_cli_database_query(), handle_cli_database_show(), and handle_cli_database_showkey().
|
static |
Definition at line 112 of file main/db.c.
Referenced by ast_monitor_change_fname(), astdb_atexit(), and db_sync_thread().
|
static |
Definition at line 113 of file main/db.c.
Referenced by db_sync(), and db_sync_thread().
|
static |
Definition at line 111 of file main/db.c.
Referenced by astdb_atexit(), and astdb_init().