Asterisk - The Open Source Telephony Project GIT-master-0bf3178
|
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 |
Data source name. More... | |
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, char character) |
static int | acf_escape_backslashes (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | acf_escape_ticks (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 = AST_BUILDOPT_SUM, .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_backslashes_function |
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 120 of file func_odbc.c.
#define DSN_BUCKETS 37 |
Definition at line 174 of file func_odbc.c.
enum odbc_option_flags |
Enumerator | |
---|---|
OPT_ESCAPECOMMAS | |
OPT_MULTIROW |
Definition at line 126 of file func_odbc.c.
|
static |
Definition at line 439 of file func_odbc.c.
|
static |
Definition at line 440 of file func_odbc.c.
|
static |
Definition at line 438 of file func_odbc.c.
|
static |
Definition at line 437 of file func_odbc.c.
|
static |
Definition at line 2013 of file func_odbc.c.
|
static |
Definition at line 2013 of file func_odbc.c.
|
static |
Definition at line 1122 of file func_odbc.c.
References buf, ast_datastore::data, len(), and out.
Referenced by acf_escape_backslashes(), and acf_escape_ticks().
|
static |
Definition at line 1149 of file func_odbc.c.
References acf_escape(), buf, and len().
|
static |
Definition at line 1138 of file func_odbc.c.
References acf_escape(), buf, ast_datastore::data, and len().
|
static |
Definition at line 1160 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, buf, odbc_datastore_row::data, ast_datastore::data, len(), odbc_datastore_row::list, LOG_WARNING, odbc_datastore::names, odbc_info, and pbx_builtin_setvar_helper().
Referenced by acf_odbc_read().
|
static |
Definition at line 742 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, buf, coldata_buf, colnames_buf, ast_datastore::data, generic_execute(), get_odbc_obj(), indicator, len(), LOG_ERROR, LOG_WARNING, NULL, odbc_datastore_free(), odbc_info, OPT_ESCAPECOMMAS, OPT_MULTIROW, pbx_builtin_pushvar_helper(), pbx_builtin_setvar_helper(), release_obj_or_dsn(), resultcount, sql_buf, status, tmp(), and ast_datastore::uid.
Referenced by init_acf_query().
|
static |
Definition at line 526 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, status, and value.
Referenced by init_acf_query().
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 2013 of file func_odbc.c.
|
static |
Definition at line 1463 of file func_odbc.c.
References a, args, 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, generic_execute(), get_odbc_obj(), indicator, NULL, pbx_builtin_pushvar_helper(), release_obj_or_dsn(), sql_buf, and ast_cli_entry::usage.
|
static |
Definition at line 1676 of file func_odbc.c.
References a, args, 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, generic_execute(), get_odbc_obj(), NULL, pbx_builtin_pushvar_helper(), release_obj_or_dsn(), S_OR, sql_buf, and ast_cli_entry::usage.
|
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 282 of file func_odbc.c.
References ast_odbc_direct_execute(), odbc_obj::con, dsn::connection, and silent_execute().
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 243 of file func_odbc.c.
References ao2_alloc, ao2_link_flags, ao2_ref, ast_odbc_request_obj, dsn::connection, dsn, dsn_destructor(), dsns, dsn::name, name, NULL, and OBJ_NOLOCK.
Referenced by get_dsn().
|
static |
Definition at line 198 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 227 of file func_odbc.c.
References ast_odbc_release_obj(), and dsn::connection.
Referenced by create_dsn().
|
static |
Definition at line 178 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 1206 of file func_odbc.c.
References ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_lock, ast_channel_unlock, ast_datastore_free(), ast_datastore::data, and odbc_info.
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 471 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_register_application2(), generic_execute(), load_pbx_builtins(), and silent_execute().
|
static |
Definition at line 1220 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 513 of file func_odbc.c.
References odbc_datastore_row::data, and 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_obj_or_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 322 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, dsns, name, 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 376 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 1237 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 1831 of file func_odbc.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, app_odbcfinish, 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(), cli_func_odbc, config, CONFIG_STATUS_FILEINVALID, DEFAULT_SINGLE_DB_CONNECTION, DSN_BUCKETS, dsn_cmp(), dsn_hash(), dsns, escape_backslashes_function, escape_function, exec_odbcfinish(), fetch_function, init_acf_query(), LOG_ERROR, LOG_NOTICE, NULL, single_db_connection, and single_db_connection_lock.
|
static |
Definition at line 444 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 405 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 1932 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_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(), config, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, DEFAULT_SINGLE_DB_CONNECTION, DSN_BUCKETS, dsn_cmp(), dsn_hash(), dsns, free_acf_query(), init_acf_query(), LOG_ERROR, LOG_WARNING, NULL, single_db_connection, and single_db_connection_lock.
|
static |
Definition at line 518 of file func_odbc.c.
References odbc_datastore_row::data, and execute().
Referenced by connection_dead().
|
static |
Definition at line 1901 of file func_odbc.c.
References ao2_ref, app_odbcfinish, 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(), cli_func_odbc, dsns, escape_backslashes_function, escape_function, fetch_function, and free_acf_query().
|
static |
Definition at line 2013 of file func_odbc.c.
|
static |
Definition at line 1204 of file func_odbc.c.
Referenced by load_module(), and unload_module().
|
static |
Definition at line 2013 of file func_odbc.c.
|
static |
Definition at line 1826 of file func_odbc.c.
Referenced by load_module(), and unload_module().
|
static |
Definition at line 439 of file func_odbc.c.
Referenced by acf_odbc_read(), and cli_odbc_read().
|
static |
Definition at line 440 of file func_odbc.c.
Referenced by acf_odbc_read().
|
static |
Definition at line 118 of file func_odbc.c.
Referenced by load_module(), and reload().
struct ao2_container* dsns |
Definition at line 176 of file func_odbc.c.
Referenced by create_dsn(), get_dsn(), load_module(), reload(), and unload_module().
|
static |
Definition at line 1154 of file func_odbc.c.
Referenced by load_module(), and unload_module().
|
static |
Definition at line 1143 of file func_odbc.c.
Referenced by load_module(), and unload_module().
|
static |
Definition at line 1198 of file func_odbc.c.
Referenced by load_module(), and unload_module().
|
static |
Definition at line 146 of file func_odbc.c.
Referenced by acf_fetch(), acf_odbc_read(), and exec_odbcfinish().
|
static |
|
static |
Definition at line 435 of file func_odbc.c.
Referenced by acf_odbc_read().
|
static |
Definition at line 122 of file func_odbc.c.
Referenced by get_odbc_obj(), load_module(), and reload().
|
static |
Definition at line 124 of file func_odbc.c.
Referenced by get_odbc_obj(), load_module(), and reload().
|
static |
Definition at line 438 of file func_odbc.c.
Referenced by acf_odbc_write().
|
static |
Definition at line 437 of file func_odbc.c.
Referenced by acf_odbc_read(), acf_odbc_write(), cli_odbc_read(), and cli_odbc_write().