Asterisk - The Open Source Telephony Project GIT-master-7e7a603
|
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_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 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_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 main/db.c.
#define DEFINE_SQL_STATEMENT | ( | stmt, | |
sql | |||
) |
|
static |
Definition at line 327 of file main/db.c.
References db_execute_sql(), and NULL.
Referenced by db_sync_thread().
|
static |
Definition at line 332 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 476 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(), 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 504 of file main/db.c.
References ast_db_get(), ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, db_sync(), dblock, LOG_WARNING, MAX_DB_FIELD, and tmp().
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 536 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(), 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 444 of file main/db.c.
References ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, dblock, LOG_WARNING, MAX_DB_FIELD, 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 677 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_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 427 of file main/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_cli_database_get(), handle_dbget(), iax_provision_version(), load_password(), manager_dbget(), 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 437 of file main/db.c.
References db_get_common(), NULL, and out.
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 610 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_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 650 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 342 of file main/db.c.
References ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, db_sync(), dblock, LOG_WARNING, MAX_DB_FIELD, 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 337 of file main/db.c.
References db_execute_sql(), and NULL.
Referenced by db_sync_thread().
|
static |
Definition at line 1203 of file main/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 1228 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(), 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 189 of file main/db.c.
References clean_stmt().
Referenced by astdb_atexit().
|
static |
Definition at line 174 of file main/db.c.
References ast_log, astdb, LOG_WARNING, and NULL.
Referenced by clean_statements().
|
static |
Definition at line 220 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 234 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 313 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 388 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 571 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 297 of file main/db.c.
References astdb, db_create_astdb(), db_open(), and init_statements().
Referenced by astdb_init().
|
static |
Definition at line 254 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 1154 of file main/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 1170 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 132 of file main/db.c.
References ast_log, ast_mutex_lock, ast_mutex_unlock, astdb, dblock, len(), LOG_WARNING, and NULL.
|
static |
Definition at line 913 of file main/db.c.
References a, ast_cli(), and columns.
Referenced by handle_cli_database_query().
|
static |
Definition at line 742 of file main/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 769 of file main/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 714 of file main/db.c.
References a, ast_cli(), ast_db_get(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, MAX_DB_FIELD, NULL, tmp(), and ast_cli_entry::usage.
|
static |
Definition at line 687 of file main/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 926 of file main/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 804 of file main/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, MAX_DB_FIELD, NULL, prefix, and ast_cli_entry::usage.
|
static |
Definition at line 868 of file main/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 204 of file main/db.c.
References init_stmt().
Referenced by db_init().
|
static |
Definition at line 1029 of file main/db.c.
References 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(), dblock, LOG_WARNING, MAX_DB_FIELD, and prefix.
Referenced by astdb_init().
|
static |
Definition at line 1095 of file main/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 1120 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 987 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 962 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 122 of file main/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 952 of file main/db.c.
Referenced by astdb_atexit(), and astdb_init().
|
static |
Definition at line 121 of file main/db.c.
Referenced by astdb_init(), db_sync(), and db_sync_thread().
|
static |
Definition at line 120 of file main/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 124 of file main/db.c.
Referenced by astdb_atexit(), and db_sync_thread().
|
static |
Definition at line 125 of file main/db.c.
Referenced by db_sync(), and db_sync_thread().
|
static |
Definition at line 123 of file main/db.c.
Referenced by astdb_atexit(), and astdb_init().