Asterisk - The Open Source Telephony Project
21.4.1
|
SQLite 3 configuration engine. More...
#include "asterisk.h"
#include <sqlite3.h>
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/paths.h"
#include "asterisk/astobj2.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
Go to the source code of this file.
Data Structures | |
struct | cfg_entry_args |
struct | realtime_sqlite3_db |
struct | row_counter_args |
Macros | |
#define | DB_BUCKETS 7 |
#define | IS_SQL_LIKE_CLAUSE(x) ((x) && ast_ends_with(x, " LIKE")) |
Typedefs | |
typedef int(* | callback_t) (void *, int, char **, char **) |
Enumerations | |
enum | { REALTIME_SQLITE3_REQ_WARN, REALTIME_SQLITE3_REQ_CLOSE, REALTIME_SQLITE3_REQ_CHAR } |
enum | { COL_CATEGORY, COL_VAR_NAME, COL_VAR_VAL, COL_COLUMNS } |
Functions | |
static void | __init_escape_column_buf (void) |
static void | __init_escape_table_buf (void) |
static void | __init_escape_value_buf (void) |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | add_column_name (void *arg, int num_columns, char **values, char **columns) |
Callback for creating a hash of column names for comparison in realtime_sqlite3_require. | |
static int | append_row_to_cfg (void *arg, int num_columns, char **values, char **columns) |
Callback for creating an ast_config from a successive sqlite3 result rows. | |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static int | db_cmp_fn (void *obj, void *arg, int flags) |
static void | db_destructor (void *obj) |
static int | db_hash_fn (const void *obj, const int flags) |
static int | db_open (struct realtime_sqlite3_db *db) |
Open a database and appropriately set debugging on the db handle. | |
void | db_start_batch (struct realtime_sqlite3_db *db) |
void | db_stop_batch (struct realtime_sqlite3_db *db) |
static void | db_sync (struct realtime_sqlite3_db *db) |
static void * | db_sync_thread (void *data) |
Wrap commands in transactions increased write performance. | |
static void | discover_sqlite3_caps (void) |
static struct realtime_sqlite3_db * | find_database (const char *database) |
static const char * | get_sqlite_column_type (int type) |
Convert Asterisk realtime types to SQLite 3 types. More... | |
static int | handle_missing_column (struct realtime_sqlite3_db *db, const char *table, const char *column, int type, size_t sz) |
If ast_realtime_require sends info about a column we don't have, create it. | |
static int | handle_missing_table (struct realtime_sqlite3_db *db, const char *table, va_list ap) |
Create a table if ast_realtime_require shows that we are configured to handle the data. | |
static int | is_dirty_cb (void *obj, void *arg, int flags) |
static int | load_module (void) |
Load the module. More... | |
static void | mark_all_databases_dirty (void) |
static int | mark_dirty_cb (void *obj, void *arg, int flags) |
static struct realtime_sqlite3_db * | new_realtime_sqlite3_db (struct ast_config *config, const char *cat) |
Create a db object based on a config category. More... | |
static int | parse_config (int reload) |
Parse the res_config_sqlite3 config file. | |
static struct ast_variable * | realtime_sqlite3 (const char *database, const char *table, const struct ast_variable *fields) |
Realtime callback for a single row query. More... | |
static int | realtime_sqlite3_destroy (const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields) |
Realtime callback for deleting a row. More... | |
static int | realtime_sqlite3_exec_query (const char *, const char *, callback_t, void *) |
static int | realtime_sqlite3_exec_query_with_handle (struct realtime_sqlite3_db *, const char *, callback_t, void *) |
static int | realtime_sqlite3_exec_update (const char *, const char *) |
static int | realtime_sqlite3_exec_update_with_handle (struct realtime_sqlite3_db *, const char *) |
static int | realtime_sqlite3_helper (const char *database, const char *table, const struct ast_variable *fields, int is_multi, void *arg) |
Helper function for single and multi-row realtime load functions. | |
static struct ast_config * | realtime_sqlite3_load (const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file, const char *who_asked) |
Realtime callback for static realtime. More... | |
static struct ast_config * | realtime_sqlite3_multi (const char *database, const char *table, const struct ast_variable *fields) |
Realtime callback for a multi-row query. More... | |
static int | realtime_sqlite3_require (const char *database, const char *table, va_list ap) |
Callback for ast_realtime_require. More... | |
static int | realtime_sqlite3_store (const char *database, const char *table, const struct ast_variable *fields) |
Realtime callback for inserting a row. More... | |
static int | realtime_sqlite3_unload (const char *database, const char *table) |
Callback for clearing any cached info. More... | |
static int | realtime_sqlite3_update (const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields) |
Realtime callback for updating a row based on a single criteria. More... | |
static int | realtime_sqlite3_update2 (const char *database, const char *table, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields) |
Realtime callback for updating a row based on multiple criteria. More... | |
static int | reload (void) |
static int | row_counter_wrapper (void *arg, int num_columns, char **values, char **columns) |
static int | row_to_varlist (void *arg, int num_columns, char **values, char **columns) |
Create a varlist from a single sqlite3 result row. | |
static const char * | sqlite3_escape_column (const char *param) |
static const char * | sqlite3_escape_column_op (const char *param) |
static const char * | sqlite3_escape_string_helper (struct ast_threadstorage *ts, const char *param) |
static const char * | sqlite3_escape_table (const char *param) |
static const char * | sqlite3_escape_value (const char *param) |
static int | static_realtime_cb (void *arg, int num_columns, char **values, char **columns) |
static int | stop_batch_cb (void *obj, void *arg, int flags) |
static int | str_cmp_fn (void *obj, void *arg, int flags) |
static int | str_hash_fn (const void *obj, const int flags) |
static int | str_to_requirements (const char *data) |
static void | trace_cb (void *arg, const char *sql) |
static void | unlink_dirty_databases (void) |
static int | unload_module (void) |
static void | unref_db (struct realtime_sqlite3_db **db) |
static int | update_realtime_sqlite3_db (struct realtime_sqlite3_db *db, struct ast_config *config, const char *cat) |
Update an existing db object based on config data. More... | |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "SQLite 3 realtime config engine" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "da6642af068ee5e6490c5b1d2cc1d238" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_REALTIME_DRIVER, .requires = "extconfig", } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static ast_mutex_t | config_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } |
struct ao2_container * | databases |
static struct ast_threadstorage | escape_column_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_escape_column_buf , .custom_init = NULL , } |
static struct ast_threadstorage | escape_table_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_escape_table_buf , .custom_init = NULL , } |
static struct ast_threadstorage | escape_value_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_escape_value_buf , .custom_init = NULL , } |
static int | has_explicit_like_escaping |
struct ast_config_engine | sqlite3_config_engine |
static const char * | static_sql = "SELECT category, var_name, var_val FROM \"%q\" WHERE filename = %Q AND commented = 0 ORDER BY cat_metric ASC, var_metric ASC" |
SQLite 3 configuration engine.
This is a realtime configuration engine for the SQLite 3 Database
Definition in file res_config_sqlite3.c.
|
static |
Convert Asterisk realtime types to SQLite 3 types.
Definition at line 1050 of file res_config_sqlite3.c.
Referenced by handle_missing_column(), and handle_missing_table().
|
static |
Load the module.
Module loading including tests for configuration or dependencies. This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails tests return AST_MODULE_LOAD_FAILURE. If the module can not load the configuration file or other non-critical problem return AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
Definition at line 1369 of file res_config_sqlite3.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_ref, ast_config_engine_register(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and parse_config().
|
static |
Create a db object based on a config category.
Definition at line 385 of file res_config_sqlite3.c.
References ast_app_parse_timelen(), ast_parse_arg(), ast_string_field_init, ast_string_field_set, ast_true(), ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by parse_config(), and update_realtime_sqlite3_db().
|
static |
Realtime callback for a single row query.
Definition at line 848 of file res_config_sqlite3.c.
References realtime_sqlite3_helper().
|
static |
Realtime callback for deleting a row.
Definition at line 1012 of file res_config_sqlite3.c.
References ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_variable::name, ast_variable::next, and ast_variable::value.
|
static |
Realtime callback for static realtime.
Definition at line 765 of file res_config_sqlite3.c.
|
static |
Realtime callback for a multi-row query.
Definition at line 860 of file res_config_sqlite3.c.
References ast_config_destroy(), ast_config_new(), and realtime_sqlite3_helper().
|
static |
Callback for ast_realtime_require.
0 | Required fields met specified standards |
-1 | One or more fields was missing or insufficient |
Definition at line 1171 of file res_config_sqlite3.c.
References add_column_name(), AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_ref, columns, handle_missing_column(), handle_missing_table(), OBJ_POINTER, and OBJ_UNLINK.
|
static |
Realtime callback for inserting a row.
Definition at line 968 of file res_config_sqlite3.c.
References ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_variable::name, ast_variable::next, and ast_variable::value.
|
static |
Callback for clearing any cached info.
0 | If any cache was purged |
-1 | If no cache was found |
Definition at line 1251 of file res_config_sqlite3.c.
|
static |
Realtime callback for updating a row based on a single criteria.
Definition at line 879 of file res_config_sqlite3.c.
References ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_variable::name, ast_variable::next, and ast_variable::value.
|
static |
Realtime callback for updating a row based on multiple criteria.
Definition at line 915 of file res_config_sqlite3.c.
References ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_variable::name, ast_variable::next, and ast_variable::value.
|
static |
Definition at line 300 of file res_config_sqlite3.c.
References ast_debug.
Referenced by db_open(), and update_realtime_sqlite3_db().
|
static |
Update an existing db object based on config data.
db | The database object to update |
config | The configuration data with which to update the db |
cat | The config category (which becomes db->name) |
Definition at line 435 of file res_config_sqlite3.c.
References ast_string_field_set, db_open(), new_realtime_sqlite3_db(), and trace_cb().
Referenced by parse_config().
|
static |
Definition at line 709 of file res_config_sqlite3.c.