Asterisk - The Open Source Telephony Project
21.4.1
|
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. | |
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() | |
int | ast_db_get (const char *family, const char *key, char *value, int valuelen) |
Get key value specified by family/key. | |
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. | |
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 | |||
) |
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().
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 |
int ast_db_exists | ( | const char * | family, |
const char * | key | ||
) |
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.
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 610 of file main/db.c.
Referenced by reload_queue_members(), sorcery_astdb_retrieve_fields_common(), 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.
int astdb_init | ( | void | ) |
Provided by db.c
Definition at line 1228 of file main/db.c.
References ast_cli_register_multiple, ast_manager_register_xml_core, ast_register_atexit(), and db_sync_thread().