Asterisk - The Open Source Telephony Project
18.5.0
|
ODBC lookups. More...
#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/config.h"
#include "asterisk/res_odbc.h"
#include "asterisk/res_odbc_transaction.h"
#include "asterisk/app.h"
#include "asterisk/cli.h"
#include "asterisk/strings.h"
Go to the source code of this file.
Data Structures | |
struct | acf_odbc_query |
struct | dsn |
struct | odbc_datastore |
struct | odbc_datastore_row |
struct | queries |
Macros | |
#define | DEFAULT_SINGLE_DB_CONNECTION 0 |
#define | DSN_BUCKETS 37 |
Enumerations | |
enum | odbc_option_flags { OPT_ESCAPECOMMAS = (1 << 0), OPT_MULTIROW = (1 << 1) } |
Functions | |
static void | __init_coldata_buf (void) |
static void | __init_colnames_buf (void) |
static void | __init_sql2_buf (void) |
static void | __init_sql_buf (void) |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | acf_escape (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | acf_fetch (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | acf_odbc_read (struct ast_channel *chan, const char *cmd, char *s, char *buf, size_t len) |
static int | acf_odbc_write (struct ast_channel *chan, const char *cmd, char *s, const char *value) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static char * | cli_odbc_read (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | cli_odbc_write (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static int | connection_dead (struct odbc_obj *connection) |
Determine if the connection has died. More... | |
static struct dsn * | create_dsn (const char *name) |
Create a DSN and connect to the database. More... | |
static int | dsn_cmp (void *obj, void *arg, int flags) |
static void | dsn_destructor (void *obj) |
static int | dsn_hash (const void *obj, const int flags) |
static int | exec_odbcfinish (struct ast_channel *chan, const char *data) |
static SQLHSTMT | execute (struct odbc_obj *obj, void *data, int silent) |
Common execution function for SQL queries. More... | |
static int | free_acf_query (struct acf_odbc_query *query) |
static SQLHSTMT | generic_execute (struct odbc_obj *obj, void *data) |
static struct dsn * | get_dsn (const char *name) |
Retrieve a DSN, or create it if it does not exist. More... | |
static struct odbc_obj * | get_odbc_obj (const char *dsn_name, struct dsn **dsn) |
Get a DB handle via a DSN or directly. More... | |
static int | init_acf_query (struct ast_config *cfg, char *catg, struct acf_odbc_query **query) |
static int | load_module (void) |
static void | odbc_datastore_free (void *data) |
static void | release_obj_or_dsn (struct odbc_obj **obj, struct dsn **dsn) |
Release an ODBC obj or a DSN. More... | |
static int | reload (void) |
static SQLHSTMT | silent_execute (struct odbc_obj *obj, void *data) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "ODBC lookups" , .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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload, .requires = "res_odbc", } |
static char * | app_odbcfinish = "ODBCFinish" |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_cli_entry | cli_func_odbc [] |
static struct ast_threadstorage | coldata_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_coldata_buf , .custom_init = NULL , } |
static struct ast_threadstorage | colnames_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_colnames_buf , .custom_init = NULL , } |
static char * | config = "func_odbc.conf" |
struct ao2_container * | dsns |
static struct ast_custom_function | escape_function |
static struct ast_custom_function | fetch_function |
static const struct ast_datastore_info | odbc_info |
static struct queries | queries = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , } |
static int | resultcount = 0 |
static int | single_db_connection |
static ast_rwlock_t | single_db_connection_lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } |
static struct ast_threadstorage | sql2_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_sql2_buf , .custom_init = NULL , } |
static struct ast_threadstorage | sql_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_sql_buf , .custom_init = NULL , } |
ODBC lookups.
Definition in file func_odbc.c.
#define DEFAULT_SINGLE_DB_CONNECTION 0 |
Definition at line 103 of file func_odbc.c.
Referenced by load_module(), and reload().
#define DSN_BUCKETS 37 |
Definition at line 157 of file func_odbc.c.
Referenced by load_module(), and reload().
enum odbc_option_flags |
Enumerator | |
---|---|
OPT_ESCAPECOMMAS | |
OPT_MULTIROW |
Definition at line 109 of file func_odbc.c.
|
static |
Definition at line 422 of file func_odbc.c.
|
static |
Definition at line 423 of file func_odbc.c.
|
static |
Definition at line 421 of file func_odbc.c.
|
static |
Definition at line 420 of file func_odbc.c.
|
static |
Definition at line 1978 of file func_odbc.c.
|
static |
Definition at line 1978 of file func_odbc.c.
|
static |
Definition at line 1105 of file func_odbc.c.
References buf, ast_datastore::data, len(), and out.
|
static |
Definition at line 1127 of file func_odbc.c.
References ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_datastore_free(), ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_log, ast_datastore::data, odbc_datastore_row::data, odbc_datastore_row::list, LOG_WARNING, odbc_datastore::names, and pbx_builtin_setvar_helper().
Referenced by acf_odbc_read().
|
static |
Definition at line 725 of file func_odbc.c.
References acf_fetch(), args, AST_APP_ARG, ast_atomic_fetchadd_int(), ast_autoservice_start(), ast_autoservice_stop(), ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_copy_string(), ast_datastore_alloc, ast_datastore_free(), ast_debug, AST_DECLARE_APP_ARGS, ast_dummy_channel_alloc, AST_LIST_HEAD_INIT, AST_LIST_INSERT_TAIL, ast_log, ast_odbc_ast_str_SQLGetData(), ast_odbc_direct_execute(), ast_realloc, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_STANDARD_APP_ARGS, ast_str_append(), ast_str_append_escapecommas(), ast_str_buffer(), ast_str_make_space, ast_str_reset(), ast_str_strlen(), ast_str_substitute_variables(), ast_str_thread_get(), ast_strlen_zero, ast_test_flag, ast_verb, coldata_buf, colnames_buf, ast_datastore::data, generic_execute(), get_odbc_obj(), indicator, LOG_ERROR, LOG_WARNING, NULL, odbc_datastore_free(), OPT_ESCAPECOMMAS, OPT_MULTIROW, pbx_builtin_pushvar_helper(), pbx_builtin_setvar_helper(), release_obj_or_dsn(), sql_buf, status, tmp(), and ast_datastore::uid.
Referenced by init_acf_query().
|
static |
Definition at line 509 of file func_odbc.c.
References args, AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), ast_channel_unref, AST_DECLARE_APP_ARGS, ast_dummy_channel_alloc, ast_log, ast_odbc_direct_execute(), ast_odbc_retrieve_transaction_obj(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_STANDARD_APP_ARGS, ast_str_buffer(), ast_str_make_space, ast_str_substitute_variables(), ast_str_thread_get(), ast_strdupa, ast_strlen_zero, buf, generic_execute(), get_odbc_obj(), LOG_ERROR, LOG_WARNING, NULL, pbx_builtin_pushvar_helper(), pbx_builtin_setvar_helper(), release_obj_or_dsn(), sql2_buf, sql_buf, and status.
Referenced by init_acf_query().
struct ast_module* AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 1978 of file func_odbc.c.
|
static |
Definition at line 1430 of file func_odbc.c.
References ast_cli_args::argc, args, ast_cli_args::argv, AST_APP_ARG, ast_channel_unref, ast_cli(), ast_cli_complete(), ast_debug, AST_DECLARE_APP_ARGS, ast_dummy_channel_alloc, ast_odbc_ast_str_SQLGetData(), ast_odbc_direct_execute(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_STANDARD_APP_ARGS, ast_str_buffer(), ast_str_make_space, ast_str_set(), ast_str_substitute_variables(), ast_str_thread_get(), ast_strdup, ast_strdupa, ast_strlen_zero, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, coldata_buf, ast_cli_entry::command, ast_cli_args::fd, generic_execute(), get_odbc_obj(), indicator, ast_cli_args::n, NULL, pbx_builtin_pushvar_helper(), ast_cli_args::pos, release_obj_or_dsn(), sql_buf, ast_cli_entry::usage, and ast_cli_args::word.
|
static |
Definition at line 1643 of file func_odbc.c.
References ast_cli_args::argc, args, ast_cli_args::argv, AST_APP_ARG, ast_channel_unref, ast_cli(), ast_cli_complete(), ast_debug, AST_DECLARE_APP_ARGS, ast_dummy_channel_alloc, ast_odbc_direct_execute(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_STANDARD_APP_ARGS, ast_str_buffer(), ast_str_make_space, ast_str_substitute_variables(), ast_str_thread_get(), ast_strdup, ast_strdupa, ast_strlen_zero, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, generic_execute(), get_odbc_obj(), ast_cli_args::n, NULL, pbx_builtin_pushvar_helper(), ast_cli_args::pos, release_obj_or_dsn(), S_OR, sql_buf, ast_cli_entry::usage, and ast_cli_args::word.
|
static |
Determine if the connection has died.
connection | The connection to check |
1 | Yep, it's dead |
0 | It's alive and well |
Definition at line 265 of file func_odbc.c.
References ast_odbc_direct_execute(), and odbc_obj::con.
Referenced by get_dsn().
|
static |
Create a DSN and connect to the database.
name | The name of the DSN as found in res_odbc.conf |
NULL | Fail |
non-NULL | The newly-created structure |
Definition at line 226 of file func_odbc.c.
References ao2_alloc, ao2_link_flags, ao2_ref, ast_odbc_request_obj, dsn::connection, dsn, dsn_destructor(), dsn::name, NULL, OBJ_NOLOCK, and silent_execute().
Referenced by get_dsn().
|
static |
Definition at line 181 of file func_odbc.c.
References CMP_MATCH, dsn::name, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.
Referenced by load_module(), and reload().
|
static |
Definition at line 210 of file func_odbc.c.
References ast_odbc_release_obj(), and dsn::connection.
Referenced by create_dsn().
|
static |
Definition at line 161 of file func_odbc.c.
References ast_assert, ast_str_hash(), OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, and OBJ_SEARCH_OBJECT.
Referenced by load_module(), and reload().
|
static |
Definition at line 1173 of file func_odbc.c.
References ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_lock, ast_channel_unlock, and ast_datastore_free().
Referenced by load_module().
|
static |
Common execution function for SQL queries.
obj | DB connection |
data | The query to execute |
silent | If true, do not print warnings on failure |
NULL | Failed to execute query |
non-NULL | The executed statement |
Definition at line 454 of file func_odbc.c.
References ast_log, ast_odbc_execute_sql(), odbc_obj::con, odbc_datastore_row::data, LOG_WARNING, and NULL.
Referenced by ast_monitor_stop(), generic_execute(), silent_execute(), and test_execute_multiple().
|
static |
Definition at line 1187 of file func_odbc.c.
References ast_free, and ast_string_field_free_memory.
Referenced by init_acf_query(), reload(), and unload_module().
|
static |
Definition at line 496 of file func_odbc.c.
References execute().
Referenced by acf_odbc_read(), acf_odbc_write(), cli_odbc_read(), and cli_odbc_write().
|
static |
Retrieve a DSN, or create it if it does not exist.
The created DSN is returned locked. This should be inconsequential to callers in most cases.
When finished with the returned structure, the caller must call release_dsn
name | Name of the DSN as found in res_odbc.conf |
NULL | Unable to retrieve or create the DSN |
non-NULL | The retrieved/created locked DSN |
Definition at line 305 of file func_odbc.c.
References ao2_find, ao2_lock, ao2_ref, ao2_unlock, ast_odbc_release_obj(), ast_odbc_request_obj, dsn::connection, connection_dead(), create_dsn(), dsn, NULL, OBJ_NOLOCK, and OBJ_SEARCH_KEY.
Referenced by get_odbc_obj().
Get a DB handle via a DSN or directly.
If single db connection then get the DB handle via DSN else by requesting a connection directly
dsn_name | Name of the DSN as found in res_odbc.conf |
dsn | The pointer to the DSN |
NULL | Unable to retrieve the DB handle |
non-NULL | The retrieved DB handle |
Definition at line 359 of file func_odbc.c.
References ast_odbc_request_obj, ast_rwlock_rdlock, ast_rwlock_unlock, get_dsn(), NULL, single_db_connection, and single_db_connection_lock.
Referenced by acf_odbc_read(), acf_odbc_write(), cli_odbc_read(), and cli_odbc_write().
|
static |
Definition at line 1204 of file func_odbc.c.
References acf_odbc_read(), acf_odbc_write(), AST_APP_ARG, ast_asprintf, ast_calloc, ast_clear_flag, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_false(), ast_log, ast_set_flag, AST_STANDARD_APP_ARGS, ast_strdup, ast_strdupa, ast_string_field_build, ast_string_field_init, ast_string_field_set, ast_strlen_zero, ast_variable_retrieve(), desc, free_acf_query(), LOG_ERROR, LOG_WARNING, NULL, OPT_ESCAPECOMMAS, OPT_MULTIROW, synopsis, and tmp().
Referenced by load_module(), and reload().
|
static |
Definition at line 1798 of file func_odbc.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ARRAY_LEN, ast_category_browse(), ast_cli_register_multiple, ast_config_destroy(), ast_config_load, ast_custom_function_register, ast_log, AST_MODULE_LOAD_DECLINE, ast_register_application_xml, AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_rwlock_unlock, ast_rwlock_wrlock, ast_true(), ast_variable_retrieve(), config, CONFIG_STATUS_FILEINVALID, DEFAULT_SINGLE_DB_CONNECTION, DSN_BUCKETS, dsn_cmp(), dsn_hash(), exec_odbcfinish(), init_acf_query(), LOG_ERROR, LOG_NOTICE, NULL, single_db_connection, and single_db_connection_lock.
Referenced by reload().
|
static |
Definition at line 427 of file func_odbc.c.
References ast_free, AST_LIST_HEAD_DESTROY, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, odbc_datastore_row::list, and result.
Referenced by acf_odbc_read().
Release an ODBC obj or a DSN.
If single db connection then unlock and unreference the DSN else release the ODBC obj
obj | The pointer to the ODBC obj to release |
dsn | The pointer to the dsn to unlock and unreference |
Definition at line 388 of file func_odbc.c.
References ao2_ref, ao2_unlock, ast_odbc_get_max_connections(), ast_odbc_release_obj(), and NULL.
Referenced by acf_odbc_read(), acf_odbc_write(), cli_odbc_read(), and cli_odbc_write().
|
static |
Definition at line 1897 of file func_odbc.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_ref, ast_category_browse(), ast_config_destroy(), ast_config_load, ast_custom_function_register, ast_custom_function_unregister(), ast_log, AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_SUPPORT_CORE, AST_RWLIST_EMPTY, AST_RWLIST_INSERT_HEAD, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_rwlock_unlock, ast_rwlock_wrlock, ast_true(), ast_variable_retrieve(), ASTERISK_GPL_KEY, config, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, DEFAULT_SINGLE_DB_CONNECTION, DSN_BUCKETS, dsn_cmp(), dsn_hash(), free_acf_query(), init_acf_query(), load_module(), LOG_ERROR, LOG_WARNING, NULL, single_db_connection, single_db_connection_lock, and unload_module().
|
static |
Definition at line 501 of file func_odbc.c.
References execute().
Referenced by create_dsn().
|
static |
Definition at line 1867 of file func_odbc.c.
References ao2_ref, ARRAY_LEN, ast_cli_unregister_multiple(), ast_custom_function_unregister(), AST_RWLIST_EMPTY, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_unregister_application(), and free_acf_query().
Referenced by reload().
|
static |
Definition at line 1978 of file func_odbc.c.
|
static |
Definition at line 1171 of file func_odbc.c.
|
static |
Definition at line 1978 of file func_odbc.c.
|
static |
Definition at line 1793 of file func_odbc.c.
|
static |
Definition at line 422 of file func_odbc.c.
Referenced by acf_odbc_read(), and cli_odbc_read().
|
static |
Definition at line 423 of file func_odbc.c.
Referenced by acf_odbc_read().
|
static |
Definition at line 101 of file func_odbc.c.
Referenced by load_module(), and reload().
struct ao2_container* dsns |
Definition at line 159 of file func_odbc.c.
|
static |
Definition at line 1121 of file func_odbc.c.
|
static |
Definition at line 1165 of file func_odbc.c.
|
static |
Definition at line 129 of file func_odbc.c.
|
static |
|
static |
Definition at line 418 of file func_odbc.c.
|
static |
Definition at line 105 of file func_odbc.c.
Referenced by get_odbc_obj(), load_module(), and reload().
|
static |
Definition at line 107 of file func_odbc.c.
Referenced by get_odbc_obj(), load_module(), and reload().
|
static |
Definition at line 421 of file func_odbc.c.
Referenced by acf_odbc_write().
|
static |
Definition at line 420 of file func_odbc.c.
Referenced by acf_odbc_read(), acf_odbc_write(), cli_odbc_read(), and cli_odbc_write().