129 size_t maxlen = strlen(param) * 2 +
sizeof(
"\"\"");
146 while ((*
tmp++ = *param++)) {
148 if (*(
tmp - 1) == q) {
172 size_t maxlen = strlen(param) * 2 +
sizeof(
"\"\" =");
185 while ((*
tmp++ = *param++)) {
192 if (*(
tmp - 1) ==
' ') {
196 }
else if (*(
tmp - 1) ==
'"') {
201 strcpy(
tmp - 1,
"\" =");
223 const char *
name = arg;
237 sqlite3_close(
db->handle);
290 if (!strcasecmp(data,
"createclose")) {
292 }
else if (!strcasecmp(data,
"createchar")) {
326 usleep(1000 *
db->batch);
339 if (sqlite3_open(
db->filename, &
db->handle) != SQLITE_OK) {
344 sqlite3_busy_timeout(
db->handle,
db->busy_timeout);
374 if (
db->has_batch_thread) {
375 db->has_batch_thread = 0;
378 pthread_join(
db->syncthread,
NULL);
403 db->busy_timeout = 1000;
406 if (!strcasecmp(
var->name,
"dbfile")) {
408 }
else if (!strcasecmp(
var->name,
"requirements")) {
410 }
else if (!strcasecmp(
var->name,
"batch")) {
412 }
else if (!strcasecmp(
var->name,
"debug")) {
414 }
else if (!strcasecmp(
var->name,
"busy_timeout")) {
416 ast_log(
LOG_WARNING,
"Invalid busy_timeout value '%s' at res_config_sqlite3.conf:%d. Using 1000 instead.\n",
var->value,
var->lineno);
444 db->requirements =
new->requirements;
447 if (
db->debug != new->debug) {
453 db->debug =
new->debug;
456 if (strcmp(
db->filename, new->filename)) {
457 sqlite3_close(
db->handle);
462 if (
db->busy_timeout != new->busy_timeout) {
463 db->busy_timeout =
new->busy_timeout;
464 sqlite3_busy_timeout(
db->handle,
db->busy_timeout);
467 if (
db->batch != new->batch) {
468 if (
db->batch == 0) {
469 db->batch =
new->batch;
471 }
else if (new->batch == 0) {
472 db->batch =
new->batch;
475 db->batch =
new->batch;
496 for (i = 1; i < num_columns; i++) {
521 for (i = 0; i < num_columns; i++) {
609 sqlite3_free(errmsg);
614 return res == 0 ? wrapper.
row_count : res;
665 if (sqlite3_exec(
db->handle, sql,
NULL,
NULL, &errmsg) != SQLITE_OK) {
667 sqlite3_free(errmsg);
670 res = sqlite3_changes(
db->handle);
709static 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";
793#define IS_SQL_LIKE_CLAUSE(x) ((x) && ast_ends_with(x, " LIKE"))
811 for (field = fields; field; field = field->
next) {
894 for (field = fields; field; field = field->
next) {
936 for (field = lookup_fields; field; field = field->
next) {
946 for (field = update_fields; field; field = field->
next) {
988 for (field = fields; field; field = field->
next) {
1027 for (field = fields; field; field = field->
next) {
1090 while ((column = va_arg(ap,
typeof(column)))) {
1092 sz = va_arg(ap,
typeof(sz));
1125 if (!(sql = sqlite3_mprintf(
"ALTER TABLE \"%q\" ADD COLUMN \"%q\" %s",
table, column, sqltype))) {
1144 return !strcasecmp((
const char *) obj, (
const char *) arg);
1159 strcpy(column,
values[1]);
1203 if (!(sql = sqlite3_mprintf(
"PRAGMA table_info(\"%q\")",
table))) {
1214 }
else if (res == 0) {
1225 while ((column = va_arg(ap,
typeof(column)))) {
1228 sz = va_arg(ap,
typeof(sz));
1285 if (!strcasecmp(cat,
"general")) {
1349#if defined(SQLITE_VERSION_NUMBER)
1355 ast_debug(3,
"SQLite3 has 'LIKE ... ESCAPE ...' support? %s\n",
1385 ast_log(
LOG_ERROR,
"The config API must have changed, this shouldn't happen.\n");
1399 .
requires =
"extconfig",
struct sla_ringing_trunk * first
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdup(str)
A wrapper for strdup()
#define ao2_link(container, obj)
Add an object to a container.
@ AO2_ALLOC_OPT_LOCK_MUTEX
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
#define ao2_find(container, arg, flags)
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
void * ao2_object_get_lockaddr(void *obj)
Return the mutex lock address of an object.
#define ao2_alloc(data_size, destructor_fn)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
static const char config[]
static char * config_filename
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen defunit)
Common routine to parse time lengths, with optional time unit specifier.
Configuration File Parser.
#define ast_config_load(filename, flags)
Load a config file.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
#define CONFIG_STATUS_FILEMISSING
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
void ast_category_append(struct ast_config *config, struct ast_category *category)
Appends a category to a config.
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
#define ast_category_new_anonymous()
Create a nameless category that is not backed by a file.
#define ast_variable_new(name, value, filename)
int ast_config_engine_deregister(struct ast_config_engine *del)
Deregister config engine.
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *p_result,...)
The argument parsing routine.
void ast_category_destroy(struct ast_category *cat)
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
struct ast_config * ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked)
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
#define ast_category_new_dynamic(name)
Create a category that is not backed by a file.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
int ast_config_engine_register(struct ast_config_engine *newconfig)
Register config engine.
@ CONFIG_FLAG_FILEUNCHANGED
#define ast_debug(level,...)
Log a DEBUG message.
Asterisk locking-related definitions:
#define ast_cond_wait(cond, mutex)
#define ast_cond_init(cond, attr)
#define ast_mutex_unlock(a)
pthread_cond_t ast_cond_t
#define ast_mutex_lock(a)
#define AST_MUTEX_DEFINE_STATIC(mutex)
#define ast_cond_signal(cond)
Asterisk module definitions.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODPRI_REALTIME_DRIVER
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Asterisk file paths, configured in asterisk.conf.
static int realtime_sqlite3_exec_query(const char *, const char *, callback_t, void *)
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 db_cmp_fn(void *obj, void *arg, int flags)
static int parse_config(int reload)
Parse the res_config_sqlite3 config file.
static int is_dirty_cb(void *obj, void *arg, int flags)
static struct ast_threadstorage escape_table_buf
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 struct ast_variable * realtime_sqlite3(const char *database, const char *table, const struct ast_variable *fields)
Realtime callback for a single row query.
static int realtime_sqlite3_exec_query_with_handle(struct realtime_sqlite3_db *, const char *, callback_t, void *)
static const char * sqlite3_escape_table(const char *param)
static int stop_batch_cb(void *obj, void *arg, int flags)
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.
static int realtime_sqlite3_unload(const char *database, const char *table)
Callback for clearing any cached info.
static int row_to_varlist(void *arg, int num_columns, char **values, char **columns)
Create a varlist from a single sqlite3 result row.
static int realtime_sqlite3_store(const char *database, const char *table, const struct ast_variable *fields)
Realtime callback for inserting a row.
int(* callback_t)(void *, int, char **, char **)
static int db_hash_fn(const void *obj, const int flags)
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 void unref_db(struct realtime_sqlite3_db **db)
static ast_mutex_t config_lock
static const char * sqlite3_escape_string_helper(struct ast_threadstorage *ts, const char *param)
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.
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 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.
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.
static int realtime_sqlite3_exec_update(const char *, const char *)
#define IS_SQL_LIKE_CLAUSE(x)
void db_stop_batch(struct realtime_sqlite3_db *db)
static const char * sqlite3_escape_value(const char *param)
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.
static int static_realtime_cb(void *arg, int num_columns, char **values, char **columns)
static const char * get_sqlite_column_type(int type)
Convert Asterisk realtime types to SQLite 3 types.
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.
static const char * static_sql
static int str_hash_fn(const void *obj, const int flags)
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.
static void trace_cb(void *arg, const char *sql)
static void db_destructor(void *obj)
static void * db_sync_thread(void *data)
Wrap commands in transactions increased write performance.
static int mark_dirty_cb(void *obj, void *arg, int flags)
static int realtime_sqlite3_exec_update_with_handle(struct realtime_sqlite3_db *, const char *)
static void db_sync(struct realtime_sqlite3_db *db)
static struct realtime_sqlite3_db * find_database(const char *database)
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.
static void mark_all_databases_dirty(void)
static int str_to_requirements(const char *data)
static int str_cmp_fn(void *obj, void *arg, int flags)
static int db_open(struct realtime_sqlite3_db *db)
Open a database and appropriately set debugging on the db handle.
static struct ast_threadstorage escape_column_buf
static int row_counter_wrapper(void *arg, int num_columns, char **values, char **columns)
static int load_module(void)
Load the module.
static int has_explicit_like_escaping
static int realtime_sqlite3_require(const char *database, const char *table, va_list ap)
Callback for ast_realtime_require.
static const char * sqlite3_escape_column_op(const char *param)
static int unload_module(void)
static void unlink_dirty_databases(void)
@ REALTIME_SQLITE3_REQ_WARN
@ REALTIME_SQLITE3_REQ_CLOSE
@ REALTIME_SQLITE3_REQ_CHAR
struct ast_config_engine sqlite3_config_engine
struct ao2_container * databases
static void discover_sqlite3_caps(void)
static const char * sqlite3_escape_column(const char *param)
static struct ast_threadstorage escape_value_buf
void db_start_batch(struct realtime_sqlite3_db *db)
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
static force_inline int attribute_pure ast_strlen_zero(const char *s)
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
#define ast_str_make_space(buf, new_len)
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Configuration engine structure, used to define realtime drivers.
Structure used to handle boolean flags.
Support for dynamic strings.
data for a thread locally stored variable
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
struct ast_category * cat
unsigned int requirements
const ast_string_field filename
const ast_string_field name
unsigned int has_batch_thread
callback_t wrapped_callback
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
typedef typeof(dummy_tv_var_for_types.tv_sec) ast_time_t
#define ast_pthread_create_background(a, b, c, d)