Asterisk - The Open Source Telephony Project
21.4.1
|
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 = "da6642af068ee5e6490c5b1d2cc1d238" , .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.
|
static |
Definition at line 526 of file func_odbc.c.
References AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), ast_channel_unref, AST_DECLARE_APP_ARGS, ast_dummy_channel_alloc, ast_odbc_direct_execute(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, AST_STANDARD_APP_ARGS, ast_str_buffer(), ast_str_substitute_variables(), ast_str_thread_get(), ast_strdupa, get_odbc_obj(), pbx_builtin_pushvar_helper(), pbx_builtin_setvar_helper(), and release_obj_or_dsn().
|
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(), 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 243 of file func_odbc.c.
References ao2_link_flags, ao2_ref, ast_odbc_request_obj, dsn::connection, dsn::name, and OBJ_NOLOCK.
Referenced by get_dsn().
|
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_odbc_execute_sql(), and odbc_obj::con.
Referenced by load_pbx_builtins().
|
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_ref, ast_odbc_release_obj(), ast_odbc_request_obj, dsn::connection, connection_dead(), create_dsn(), 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, and get_dsn().
Referenced by acf_odbc_write().
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, ast_odbc_get_max_connections(), and ast_odbc_release_obj().
Referenced by acf_odbc_write().
|
static |
Definition at line 1826 of file func_odbc.c.
|
static |
Definition at line 1154 of file func_odbc.c.
|
static |
Definition at line 1143 of file func_odbc.c.
|
static |
Definition at line 1198 of file func_odbc.c.
|
static |
Definition at line 146 of file func_odbc.c.