Asterisk - The Open Source Telephony Project GIT-master-754dea3
|
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) |
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_del2 (const char *family, const char *key) |
Same as ast_db_del, but with more stringent error checking. More... | |
int | ast_db_deltree (const char *family, const char *keytree) |
Delete one or more entries in astdb. More... | |
int | ast_db_exists (const char *family, const char *key) |
Check if family/key exitsts. 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 char * | create_prefix (const char *family, const char *keytree, int *prefix_len) |
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_db_tree_get (struct mansession *s, const struct message *m) |
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 db.c.
#define DEFINE_SQL_STATEMENT | ( | stmt, | |
sql | |||
) |
|
static |
Definition at line 320 of file db.c.
References db_execute_sql(), and NULL.
Referenced by db_sync_thread().
|
static |
Definition at line 325 of file 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 472 of file db.c.
References ast_asprintf, ast_debug, ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, db_sync(), dblock, and LOG_WARNING.
Referenced by __expire_registry(), add_cert_key_to_astdb(), ast_privacy_set(), AST_TEST_DEFINE(), auth_exec(), cache_lookup_internal(), cleanup_cert_from_astdb_and_fs(), destroy_all_channels(), dialgroup_refreshdb(), do_register_expire(), dump_queue_members(), function_db_delete(), handle_dbdel(), media_cache_item_del_from_astdb(), media_cache_remove_from_astdb(), mkintf(), process_clearcache(), reload_queue_members(), sorcery_astdb_delete(), stasis_app_device_state_delete(), and update_registry().
int ast_db_del2 | ( | const char * | family, |
const char * | key | ||
) |
Same as ast_db_del, but with more stringent error checking.
Unlike ast_db_del, if the key does not exist in the first place, an error is emitted and -1 is returned.
-1 | An error occured (including key not found to begin with) |
0 | Successfully deleted |
Definition at line 501 of file db.c.
References ast_asprintf, ast_db_get(), ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, db_sync(), dblock, and LOG_WARNING.
Referenced by handle_cli_database_del(), and manager_dbdel().
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 559 of file db.c.
References ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero(), astdb, create_prefix(), db_sync(), dblock, LOG_WARNING, NULL, and prefix.
Referenced by ast_privacy_reset(), AST_TEST_DEFINE(), cleanup_cert_from_astdb_and_fs(), deinitialize_sorcery(), deltree_exec(), dundi_flush(), handle_cli_database_deltree(), handle_dbdeltree(), iax_provision_reload(), manager_dbdeltree(), media_cache_item_del_from_astdb(), and media_cache_remove_from_astdb().
int ast_db_exists | ( | const char * | family, |
const char * | key | ||
) |
Check if family/key exitsts.
family | |
key |
1 | if family/key exists |
0 | if family/key does not exist or an error occurred |
Definition at line 438 of file db.c.
References ast_asprintf, ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, dblock, LOG_WARNING, and result.
Referenced by cleanup_cert_from_astdb_and_fs(), and retrieve_cert_from_cache().
void ast_db_freetree | ( | struct ast_db_entry * | dbe | ) |
Free structure created by ast_db_gettree()
Definition at line 695 of file db.c.
References ast_free, last, and ast_db_entry::next.
Referenced by AST_TEST_DEFINE(), dundi_show_cache(), dundi_show_hints(), function_db_keycount(), 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 421 of file db.c.
References ast_assert, db_get_common(), NULL, and value.
Referenced by ast_db_del2(), 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(), handle_dbget(), iax_provision_version(), load_password(), mkintf(), populate_addr(), refresh_all_favorite(), reg_source_db(), retrieve_cert_from_cache(), 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 431 of file db.c.
References db_get_common(), NULL, and out.
Referenced by AST_TEST_DEFINE(), handle_cli_database_get(), manager_dbget(), 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 635 of file db.c.
References ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, create_prefix(), db_gettree_common(), dblock, LOG_WARNING, NULL, and prefix.
Referenced by AST_TEST_DEFINE(), dundi_show_cache(), dundi_show_hints(), function_db_keycount(), 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 667 of file db.c.
References ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, create_prefix(), db_gettree_common(), dblock, LOG_WARNING, 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 335 of file db.c.
References ast_asprintf, ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, db_sync(), dblock, LOG_WARNING, and value.
Referenced by __analog_ss_thread(), add_cert_expiration_to_astdb(), add_cert_key_to_astdb(), ast_privacy_set(), AST_TEST_DEFINE(), asterisk_daemon(), 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_cli_presencestate_change(), handle_command_response(), handle_dbput(), iax_provision_build(), manager_dbput(), media_cache_item_sync_to_astdb(), metadata_sync_to_astdb(), presence_write(), save_secret(), sorcery_astdb_create(), stasis_app_device_state_update(), and update_registry().
|
static |
Definition at line 330 of file db.c.
References db_execute_sql(), and NULL.
Referenced by db_sync_thread().
|
static |
Definition at line 1225 of file db.c.
References ARRAY_LEN, ast_cli_unregister_multiple(), ast_manager_unregister(), ast_mutex_lock, ast_mutex_unlock, astdb, clean_statements(), cli_database, db_sync(), dblock, doexit, NULL, and syncthread.
Referenced by astdb_init().
int astdb_init | ( | void | ) |
Provided by db.c
Definition at line 1250 of file 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(), cli_database, db_init(), db_sync_thread(), dbcond, EVENT_FLAG_REPORTING, EVENT_FLAG_SYSTEM, manager_db_tree_get(), manager_dbdel(), manager_dbdeltree(), manager_dbget(), manager_dbput(), NULL, and syncthread.
Referenced by asterisk_daemon().
|
static |
Definition at line 205 of file db.c.
References clean_stmt().
Referenced by astdb_atexit().
|
static |
Definition at line 190 of file db.c.
References ast_log, astdb, LOG_WARNING, and NULL.
Referenced by clean_statements().
|
static |
Definition at line 534 of file db.c.
References ast_asprintf, ast_log, ast_strdup, ast_strlen_zero(), LOG_WARNING, NULL, prefix, S_COR, and S_OR.
Referenced by ast_db_deltree(), ast_db_gettree(), ast_db_gettree_by_prefix(), handle_cli_database_show(), and manager_db_tree_get().
|
static |
Definition at line 236 of file db.c.
References ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, db_sync(), dblock, and LOG_WARNING.
Referenced by db_init().
|
static |
Definition at line 306 of file 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 381 of file db.c.
References ast_asprintf, ast_copy_string(), ast_debug, ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_strdup, astdb, dblock, LOG_WARNING, result, and value.
Referenced by ast_db_get(), and ast_db_get_allocated().
|
static |
Definition at line 596 of file 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 290 of file db.c.
References astdb, db_create_astdb(), db_open(), and init_statements().
Referenced by astdb_init().
|
static |
Definition at line 256 of file db.c.
References ast_config_AST_DB, ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, dblock, dbname, LOG_ERROR, and LOG_WARNING.
Referenced by db_init().
|
static |
Definition at line 1176 of file db.c.
References ast_cond_signal, dbcond, and dosync.
Referenced by ast_db_del(), ast_db_del2(), ast_db_deltree(), ast_db_put(), astdb_atexit(), db_create_astdb(), and handle_cli_database_query().
|
static |
Definition at line 1192 of file 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 148 of file db.c.
References ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, dblock, len(), LOG_WARNING, and NULL.
|
static |
Definition at line 935 of file db.c.
References a, ast_cli(), and columns.
Referenced by handle_cli_database_query().
|
static |
Definition at line 762 of file db.c.
References a, ast_cli(), ast_db_del2(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 789 of file db.c.
References a, ast_cli(), ast_db_deltree(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 732 of file db.c.
References a, ast_cli(), ast_db_get_allocated(), ast_free, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 705 of file db.c.
References a, ast_cli(), ast_db_put(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 948 of file db.c.
References a, 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 824 of file db.c.
References a, ast_cli(), ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, create_prefix(), dblock, LOG_WARNING, NULL, prefix, and ast_cli_entry::usage.
|
static |
Definition at line 890 of file db.c.
References a, 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, LOG_WARNING, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 220 of file db.c.
Referenced by db_init().
|
static |
Definition at line 1051 of file db.c.
References ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero(), astdb, astman_append(), astman_get_header(), astman_send_error(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), create_prefix(), dblock, LOG_WARNING, and prefix.
Referenced by astdb_init().
|
static |
Definition at line 1117 of file db.c.
References ast_db_del2(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), and astman_send_error().
Referenced by astdb_init().
|
static |
Definition at line 1142 of file 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 1009 of file db.c.
References ast_db_get_allocated(), ast_free, ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), and NULL.
Referenced by astdb_init().
|
static |
Definition at line 984 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 138 of file db.c.
Referenced by ast_db_del(), ast_db_del2(), ast_db_deltree(), ast_db_exists(), 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(), handle_cli_database_showkey(), and manager_db_tree_get().
|
static |
Definition at line 974 of file db.c.
Referenced by astdb_atexit(), and astdb_init().
|
static |
Definition at line 137 of file db.c.
Referenced by astdb_init(), db_sync(), and db_sync_thread().
|
static |
Definition at line 136 of file db.c.
Referenced by ast_db_del(), ast_db_del2(), ast_db_deltree(), ast_db_exists(), 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(), handle_cli_database_showkey(), and manager_db_tree_get().
|
static |
Definition at line 140 of file db.c.
Referenced by astdb_atexit(), and db_sync_thread().
|
static |
Definition at line 141 of file db.c.
Referenced by db_sync(), and db_sync_thread().
|
static |
Definition at line 139 of file db.c.
Referenced by astdb_atexit(), and astdb_init().