132 size_t maxlen = strlen(param) * 2 +
sizeof(
"\"\"");
149 while ((*tmp++ = *param++)) {
151 if (*(tmp - 1) == q) {
175 size_t maxlen = strlen(param) * 2 +
sizeof(
"\"\" =");
188 while ((*tmp++ = *param++)) {
195 if (*(tmp - 1) ==
' ') {
199 }
else if (*(tmp - 1) ==
'"') {
204 strcpy(tmp - 1,
"\" =");
226 const char *
name = arg;
240 sqlite3_close(db->
handle);
293 if (!strcasecmp(data,
"createclose")) {
295 }
else if (!strcasecmp(data,
"createchar")) {
329 usleep(1000 * db->
batch);
409 if (!strcasecmp(var->
name,
"dbfile")) {
411 }
else if (!strcasecmp(var->
name,
"requirements")) {
413 }
else if (!strcasecmp(var->
name,
"batch")) {
415 }
else if (!strcasecmp(var->
name,
"debug")) {
417 }
else if (!strcasecmp(var->
name,
"busy_timeout")) {
450 if (db->
debug != new->debug) {
456 db->
debug =
new->debug;
459 if (strcmp(db->
filename, new->filename)) {
460 sqlite3_close(db->
handle);
470 if (db->
batch != new->batch) {
471 if (db->
batch == 0) {
472 db->
batch =
new->batch;
474 }
else if (new->batch == 0) {
475 db->
batch =
new->batch;
478 db->
batch =
new->batch;
499 for (i = 1; i < num_columns; i++) {
524 for (i = 0; i < num_columns; i++) {
527 ast_log(
LOG_ERROR,
"Could not create new variable for '%s: %s', throwing away list\n", columns[i], values[i]);
547 const char *who_asked;
612 sqlite3_free(errmsg);
617 return res == 0 ? wrapper.
row_count : res;
668 if (sqlite3_exec(db->
handle, sql,
NULL,
NULL, &errmsg) != SQLITE_OK) {
670 sqlite3_free(errmsg);
673 res = sqlite3_changes(db->
handle);
712 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";
778 if (!(sql = sqlite3_mprintf(
static_sql, table, configfile))) {
796 #define IS_SQL_LIKE_CLAUSE(x) ((x) && ast_ends_with(x, " LIKE")) 814 for (field = fields; field; field = field->
next) {
897 for (field = fields; field; field = field->
next) {
939 for (field = lookup_fields; field; field = field->
next) {
949 for (field = update_fields; field; field = field->
next) {
991 for (field = fields; field; field = field->
next) {
1030 for (field = fields; field; field = field->
next) {
1093 while ((column = va_arg(ap,
typeof(column)))) {
1094 type = va_arg(ap,
typeof(type));
1095 sz = va_arg(ap,
typeof(sz));
1128 if (!(sql = sqlite3_mprintf(
"ALTER TABLE \"%q\" ADD COLUMN \"%q\" %s", table, column, sqltype))) {
1133 ast_log(
LOG_NOTICE,
"Creating column '%s' type %s for table %s\n", column, sqltype, table);
1147 return !strcasecmp((
const char *) obj, (
const char *) arg);
1162 strcpy(column, values[1]);
1206 if (!(sql = sqlite3_mprintf(
"PRAGMA table_info(\"%q\")", table))) {
1217 }
else if (res == 0) {
1228 while ((column = va_arg(ap,
typeof(column)))) {
1230 type = va_arg(ap,
typeof(type));
1231 sz = va_arg(ap,
typeof(sz));
1271 ast_debug(1,
"%s was unchanged, skipping parsing\n", config_filename);
1288 if (!strcasecmp(cat,
"general")) {
1352 #if defined(SQLITE_VERSION_NUMBER) 1358 ast_debug(3,
"SQLite3 has 'LIKE ... ESCAPE ...' support? %s\n",
1388 ast_log(
LOG_ERROR,
"The config API must have changed, this shouldn't happen.\n");
1402 .requires =
"extconfig",
static const char * sqlite3_escape_column(const char *param)
static int db_open(struct realtime_sqlite3_db *db)
Open a database and appropriately set debugging on the db handle.
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.
struct ast_variable * next
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
typedef typeof(dummy_tv_var_for_types.tv_sec) ast_time_t
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 struct ast_threadstorage escape_column_buf
static const char * sqlite3_escape_column_op(const char *param)
const ast_string_field name
static const char * sqlite3_escape_string_helper(struct ast_threadstorage *ts, const char *param)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static int row_counter_wrapper(void *arg, int num_columns, char **values, char **columns)
void db_stop_batch(struct realtime_sqlite3_db *db)
static void unlink_dirty_databases(void)
static void * db_sync_thread(void *data)
Wrap commands in transactions increased write performance.
int(* callback_t)(void *, int, char **, char **)
static const char * get_sqlite_column_type(int type)
Convert Asterisk realtime types to SQLite 3 types.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
callback_t wrapped_callback
static const char * static_sql
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
static int str_cmp_fn(void *obj, void *arg, int flags)
static int is_dirty_cb(void *obj, void *arg, int flags)
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.
#define ast_str_make_space(buf, new_len)
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define ao2_callback(c, flags, cb_fn, arg)
#define CONFIG_STATUS_FILEINVALID
static void trace_cb(void *arg, const char *sql)
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.
Structure for variables, used for configurations and for channel variables.
data for a thread locally stored variable
static int has_explicit_like_escaping
int ast_config_engine_deregister(struct ast_config_engine *del)
Deregister config engine.
static int realtime_sqlite3_store(const char *database, const char *table, const struct ast_variable *fields)
Realtime callback for inserting a row.
#define ast_cond_wait(cond, mutex)
int ast_config_engine_register(struct ast_config_engine *newconfig)
Register config engine.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define ast_cond_init(cond, attr)
static int stop_batch_cb(void *obj, void *arg, int flags)
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define ast_mutex_lock(a)
#define ast_strdup(str)
A wrapper for strdup()
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
struct ast_config_engine sqlite3_config_engine
static int realtime_sqlite3_exec_query_with_handle(struct realtime_sqlite3_db *, const char *, callback_t, void *)
static int realtime_sqlite3_unload(const char *database, const char *table)
Callback for clearing any cached info.
static void discover_sqlite3_caps(void)
void ast_category_destroy(struct ast_category *cat)
#define ast_cond_signal(cond)
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)
Configuration engine structure, used to define realtime drivers.
pthread_cond_t ast_cond_t
#define ast_strlen_zero(foo)
static int str_to_requirements(const char *data)
#define ast_pthread_create_background(a, b, c, d)
#define ast_category_new_anonymous()
Create a nameless category that is not backed by a file.
static int parse_config(int reload)
Parse the res_config_sqlite3 config file.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
void * ao2_object_get_lockaddr(void *obj)
Return the mutex lock address of an object.
Configuration File Parser.
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 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.
struct ast_category * cat
#define ast_debug(level,...)
Log a DEBUG message.
static void unref_db(struct realtime_sqlite3_db **db)
#define ast_config_load(filename, flags)
Load a config file.
static char * config_filename
Asterisk file paths, configured in asterisk.conf.
struct ao2_container * databases
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ao2_ref(o, delta)
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.
void ast_config_destroy(struct ast_config *config)
Destroys a config.
unsigned int has_batch_thread
static const char * sqlite3_escape_value(const char *param)
#define ast_variable_new(name, value, filename)
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_config * ast_config_new(void)
Create a new base configuration structure.
static int static_realtime_cb(void *arg, int num_columns, char **values, char **columns)
static int realtime_sqlite3_exec_query(const char *, const char *, callback_t, void *)
#define CONFIG_STATUS_FILEUNCHANGED
static void db_sync(struct realtime_sqlite3_db *db)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
void db_start_batch(struct realtime_sqlite3_db *db)
struct sla_ringing_trunk * first
#define ao2_alloc(data_size, destructor_fn)
static struct columns columns
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *result,...)
The argument parsing routine.
#define ast_category_new_dynamic(name)
Create a category that is not backed by a file.
Module has failed to load, may be in an inconsistent state.
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.
#define ao2_find(container, arg, flags)
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 db_hash_fn(const void *obj, const int flags)
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 void mark_all_databases_dirty(void)
Structure used to handle boolean flags.
static int realtime_sqlite3_exec_update(const char *, const char *)
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
static int unload_module(void)
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
#define CONFIG_STATUS_FILEMISSING
void ast_category_append(struct ast_config *config, struct ast_category *cat)
Appends a category to a config.
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
#define IS_SQL_LIKE_CLAUSE(x)
unsigned int requirements
static void db_destructor(void *obj)
static int realtime_sqlite3_require(const char *database, const char *table, va_list ap)
Callback for ast_realtime_require.
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
static const char * sqlite3_escape_table(const char *param)
static int mark_dirty_cb(void *obj, void *arg, int flags)
static struct ast_threadstorage escape_value_buf
static ast_mutex_t config_lock
static struct realtime_sqlite3_db * find_database(const char *database)
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
static int str_hash_fn(const void *obj, const int flags)
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.
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 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.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
static struct ast_threadstorage escape_table_buf
static int realtime_sqlite3_exec_update_with_handle(struct realtime_sqlite3_db *, const char *)
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
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 db_cmp_fn(void *obj, void *arg, int flags)
static int load_module(void)
Load the module.
#define AST_MUTEX_DEFINE_STATIC(mutex)
const ast_string_field filename
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
#define ast_mutex_unlock(a)
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ao2_link(container, obj)