109 static odbc_status odbc_obj_connect(struct
odbc_obj *obj);
110 static odbc_status odbc_obj_disconnect(struct
odbc_obj *obj);
111 static
void odbc_register_class(struct
odbc_class *class,
int connect);
126 unsigned int active:1;
134 if (iso == SQL_TXN_READ_COMMITTED) {
135 return "read_committed";
136 }
else if (iso == SQL_TXN_READ_UNCOMMITTED) {
137 return "read_uncommitted";
138 }
else if (iso == SQL_TXN_SERIALIZABLE) {
139 return "serializable";
140 }
else if (iso == SQL_TXN_REPEATABLE_READ) {
141 return "repeatable_read";
149 if (strncasecmp(txt,
"read_", 5) == 0) {
150 if (strncasecmp(txt + 5,
"c", 1) == 0) {
151 return SQL_TXN_READ_COMMITTED;
152 }
else if (strncasecmp(txt + 5,
"u", 1) == 0) {
153 return SQL_TXN_READ_UNCOMMITTED;
157 }
else if (strncasecmp(txt,
"ser", 3) == 0) {
158 return SQL_TXN_SERIALIZABLE;
159 }
else if (strncasecmp(txt,
"rep", 3) == 0) {
160 return SQL_TXN_REPEATABLE_READ;
166 static void odbc_class_destructor(
void *data)
174 if (class->username) {
175 ast_free(class->username);
177 if (class->password) {
178 ast_free(class->password);
180 if (class->sanitysql) {
181 ast_free(class->sanitysql);
188 SQLFreeHandle(SQL_HANDLE_ENV, class->env);
189 ast_mutex_destroy(&class->lock);
190 ast_cond_destroy(&class->cond);
191 ast_free(class->sql_text);
194 static void odbc_obj_destructor(
void *data)
198 odbc_obj_disconnect(obj);
205 ast_debug(1,
"Destroying table cache for %s\n", table->table);
208 while ((col = AST_RWLIST_REMOVE_HEAD(&table->columns, list))) {
238 SQLHSTMT stmt = NULL;
239 int res = 0, error = 0;
243 AST_RWLIST_TRAVERSE(&
odbc_tables, tableptr, list) {
244 if (strcmp(tableptr->connection, database) == 0 && strcmp(tableptr->table, tablename) == 0) {
255 ast_log(LOG_WARNING,
"Unable to retrieve database handle for table description '%s@%s'\n", tablename, database);
262 res = SQLAllocHandle(SQL_HANDLE_STMT, obj->
con, &stmt);
263 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
264 ast_log(LOG_WARNING,
"SQL Alloc Handle failed on connection '%s'!\n", database);
268 res = SQLColumns(stmt, NULL, 0, NULL, 0, (
unsigned char *)tablename, SQL_NTS, (
unsigned char *)
"%", SQL_NTS);
269 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
270 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
271 ast_log(LOG_ERROR,
"Unable to query database columns on connection '%s'.\n", database);
275 if (!(tableptr =
ast_calloc(
sizeof(
char),
sizeof(*tableptr) + strlen(database) + 1 + strlen(tablename) + 1))) {
276 ast_log(LOG_ERROR,
"Out of memory creating entry for table '%s' on connection '%s'\n", tablename, database);
280 tableptr->connection = (
char *)tableptr +
sizeof(*tableptr);
281 tableptr->table = (
char *)tableptr +
sizeof(*tableptr) + strlen(database) + 1;
282 strcpy(tableptr->connection, database);
283 strcpy(tableptr->table, tablename);
286 while ((res = SQLFetch(stmt)) != SQL_NO_DATA && res != SQL_ERROR) {
287 SQLGetData(stmt, 4, SQL_C_CHAR, columnname,
sizeof(columnname), &sqlptr);
289 if (!(entry =
ast_calloc(
sizeof(
char),
sizeof(*entry) + strlen(columnname) + 1))) {
290 ast_log(LOG_ERROR,
"Out of memory creating entry for column '%s' in table '%s' on connection '%s'\n", columnname, tablename, database);
294 entry->name = (
char *)entry +
sizeof(*entry);
295 strcpy(entry->name, columnname);
297 SQLGetData(stmt, 5, SQL_C_SHORT, &entry->type,
sizeof(entry->type), NULL);
298 SQLGetData(stmt, 7, SQL_C_LONG, &entry->size,
sizeof(entry->size), NULL);
299 SQLGetData(stmt, 9, SQL_C_SHORT, &entry->decimals,
sizeof(entry->decimals), NULL);
300 SQLGetData(stmt, 10, SQL_C_SHORT, &entry->radix,
sizeof(entry->radix), NULL);
301 SQLGetData(stmt, 11, SQL_C_SHORT, &entry->nullable,
sizeof(entry->nullable), NULL);
302 SQLGetData(stmt, 16, SQL_C_LONG, &entry->octetlen,
sizeof(entry->octetlen), NULL);
307 if (entry->octetlen == 0) {
308 entry->octetlen = entry->size;
311 ast_debug(3,
"Found %s column with type %hd with len %ld, octetlen %ld, and numlen (%hd,%hd)\n", entry->name, entry->type, (
long) entry->size, (
long) entry->octetlen, entry->decimals, entry->radix);
315 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
317 AST_RWLIST_INSERT_TAIL(&
odbc_tables, tableptr, list);
325 destroy_table_cache(tableptr);
335 AST_RWLIST_TRAVERSE(&table->columns, col, list) {
336 if (strcasecmp(col->name, colname) == 0) {
348 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&
odbc_tables, tableptr, list) {
349 if (strcmp(tableptr->connection, database) == 0 && strcmp(tableptr->table, tablename) == 0) {
351 destroy_table_cache(tableptr);
355 AST_RWLIST_TRAVERSE_SAFE_END
357 return tableptr ? 0 : -1;
362 struct timeval start;
369 stmt = exec_cb(obj, data);
375 ast_log(LOG_WARNING,
"SQL query '%s' took %ld milliseconds to execute on class '%s', this may indicate a database problem\n",
400 struct timeval start;
413 stmt = prepare_cb(obj, data);
418 res = SQLExecute(stmt);
419 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO) && (res != SQL_NO_DATA)) {
420 if (res == SQL_ERROR) {
424 ast_log(LOG_WARNING,
"SQL Execute error %d!\n", res);
425 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
431 ast_log(LOG_WARNING,
"SQL query '%s' took %ld milliseconds to execute on class '%s', this may indicate a database problem\n",
466 return SQLPrepare(stmt, (
unsigned char *)sql, SQL_NTS);
477 return SQLExecDirect(stmt, (
unsigned char *)sql, SQL_NTS);
484 res = SQLExecute(stmt);
485 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO) && (res != SQL_NO_DATA)) {
486 if (res == SQL_ERROR) {
503 if (SQLGetData(StatementHandle, ColumnNumber, TargetType,
ast_str_buffer(*buf), 0, StrLen_or_Ind) == SQL_SUCCESS_WITH_INFO) {
504 ast_str_make_space(buf, *StrLen_or_Ind + 1);
506 }
else if (pmaxlen > 0) {
507 ast_str_make_space(buf, pmaxlen);
518 SQLINTEGER nativeerror = 0;
519 SQLSMALLINT diagbytes = 0;
521 unsigned char state[10];
522 unsigned char diagnostic[256];
526 while (SQLGetDiagRec(handle_type, handle, ++i, state, &nativeerror,
527 diagnostic,
sizeof(diagnostic), &diagbytes) == SQL_SUCCESS) {
529 ast_log(LOG_WARNING,
"%s returned an error: %s: %s\n", operation, state, diagnostic);
532 ast_log(LOG_WARNING,
"There are more than 10 diagnostic records! Ignore the rest.\n");
542 return class->isolation;
547 return class->forcecommit;
555 static int load_odbc_config(
void)
557 static char *cfg =
"res_odbc.conf";
561 const char *dsn, *username, *password, *sanitysql;
563 struct timeval ncache = { 0, 0 };
564 int preconnect = 0, res = 0;
570 if (config == CONFIG_STATUS_FILEMISSING || config == CONFIG_STATUS_FILEINVALID) {
571 ast_log(LOG_WARNING,
"Unable to load config file res_odbc.conf\n");
575 if (!strcasecmp(cat,
"ENV")) {
576 for (v = ast_variable_browse(config, cat); v; v = v->
next) {
578 ast_log(LOG_NOTICE,
"Adding ENV var: %s=%s\n", v->
name, v->
value);
582 dsn = username = password = sanitysql = NULL;
588 isolation = SQL_TXN_READ_COMMITTED;
591 slowquerylimit = 5000;
592 for (v = ast_variable_browse(config, cat); v; v = v->
next) {
593 if (!strcasecmp(v->
name,
"pooling") ||
594 !strncasecmp(v->
name,
"share", 5) ||
595 !strcasecmp(v->
name,
"limit") ||
596 !strcasecmp(v->
name,
"idlecheck")) {
597 ast_log(LOG_WARNING,
"The 'pooling', 'shared_connections', 'limit', and 'idlecheck' options were replaced by 'max_connections'. See res_odbc.conf.sample.\n");
598 }
else if (!strcasecmp(v->
name,
"enabled")) {
600 }
else if (!strcasecmp(v->
name,
"pre-connect")) {
602 }
else if (!strcasecmp(v->
name,
"dsn")) {
604 }
else if (!strcasecmp(v->
name,
"username")) {
606 }
else if (!strcasecmp(v->
name,
"password")) {
608 }
else if (!strcasecmp(v->
name,
"sanitysql")) {
609 sanitysql = v->
value;
610 }
else if (!strcasecmp(v->
name,
"backslash_is_escape")) {
612 }
else if (!strcasecmp(v->
name,
"connect_timeout")) {
613 if (sscanf(v->
value,
"%d", &conntimeout) != 1 || conntimeout < 1) {
614 ast_log(LOG_WARNING,
"connect_timeout must be a positive integer\n");
617 }
else if (!strcasecmp(v->
name,
"negative_connection_cache")) {
619 if (sscanf(v->
value,
"%lf", &dncache) != 1 || dncache < 0) {
620 ast_log(LOG_WARNING,
"negative_connection_cache must be a non-negative integer\n");
625 ncache.tv_sec = (int)dncache;
626 ncache.tv_usec = (dncache - ncache.tv_sec) * 1000000;
628 }
else if (!strcasecmp(v->
name,
"forcecommit")) {
630 }
else if (!strcasecmp(v->
name,
"isolation")) {
632 ast_log(LOG_ERROR,
"Unrecognized value for 'isolation': '%s' in section '%s'\n", v->
value, cat);
633 isolation = SQL_TXN_READ_COMMITTED;
635 }
else if (!strcasecmp(v->
name,
"max_connections")) {
636 if (sscanf(v->
value,
"%30d", &maxconnections) != 1 || maxconnections < 1) {
637 ast_log(LOG_WARNING,
"max_connections must be a positive integer\n");
640 }
else if (!strcasecmp(v->
name,
"logging")) {
642 }
else if (!strcasecmp(v->
name,
"slow_query_limit")) {
643 if (sscanf(v->
value,
"%30d", &slowquerylimit) != 1) {
644 ast_log(LOG_WARNING,
"slow_query_limit must be a positive integer\n");
645 slowquerylimit = 5000;
650 if (enabled && !ast_strlen_zero(dsn)) {
651 new = ao2_alloc(
sizeof(*
new), odbc_class_destructor);
658 SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &new->env);
659 res = SQLSetEnvAttr(new->env, SQL_ATTR_ODBC_VERSION, (
void *) SQL_OV_ODBC3, 0);
661 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
662 ast_log(LOG_WARNING,
"res_odbc: Error SetEnv\n");
667 new->backslash_is_escape = bse ? 1 : 0;
668 new->forcecommit = forcecommit ? 1 : 0;
671 new->negative_connection_cache = ncache;
680 if (username && !(new->username =
ast_strdup(username))) {
684 if (password && !(new->password =
ast_strdup(password))) {
688 if (sanitysql && !(new->sanitysql =
ast_strdup(sanitysql))) {
693 ast_mutex_init(&new->lock);
694 ast_cond_init(&new->cond, NULL);
696 odbc_register_class(
new, preconnect);
697 ast_log(LOG_NOTICE,
"Registered ODBC class '%s' dsn->[%s]\n", cat, dsn);
719 "Usage: odbc show [class]\n"
720 " List settings of a particular ODBC class or,\n"
721 " if not specified, all classes.\n";
726 length = strlen(a->word);
728 while ((
class = ao2_iterator_next(&aoi))) {
729 if (!strncasecmp(a->word, class->name, length) && ++which > a->n) {
738 if (!ret && !strncasecmp(a->word,
"all", length) && ++which > a->n) {
744 ast_cli(a->fd,
"\nODBC DSN Settings\n");
745 ast_cli(a->fd,
"-----------------\n\n");
747 while ((
class = ao2_iterator_next(&aoi))) {
748 if ((a->argc == 2) || (a->argc == 3 && !strcmp(a->argv[2],
"all")) || (!strcmp(a->argv[2], class->name))) {
752 ast_cli(a->fd,
" Name: %s\n DSN: %s\n", class->name, class->dsn);
754 if (class->last_negative_connect.tv_sec > 0) {
756 ast_strftime(timestr,
sizeof(timestr),
"%Y-%m-%d %T", &tm);
757 ast_cli(a->fd,
" Last fail connection attempt: %s\n", timestr);
760 ast_cli(a->fd,
" Number of active connections: %zd (out of %d)\n", class->connection_cnt, class->maxconnections);
761 ast_cli(a->fd,
" Logging: %s\n", class->logging ?
"Enabled" :
"Disabled");
762 if (class->logging) {
763 ast_cli(a->fd,
" Number of prepares executed: %d\n", class->prepares_executed);
764 ast_cli(a->fd,
" Number of queries executed: %d\n", class->queries_executed);
765 ast_mutex_lock(&class->lock);
766 if (class->sql_text) {
767 ast_cli(a->fd,
" Longest running SQL query: %s (%ld milliseconds)\n", class->sql_text, class->longest_query_execution_time);
769 ast_mutex_unlock(&class->lock);
771 ast_cli(a->fd,
"\n");
781 AST_CLI_DEFINE(handle_cli_odbc_show,
"List ODBC DSN(s)")
784 static void odbc_register_class(
struct odbc_class *
class,
int preconnect)
808 ast_debug(2,
"Releasing ODBC handle %p into pool\n", obj);
825 ast_mutex_lock(&class->lock);
827 ast_cond_signal(&class->cond);
828 ast_mutex_unlock(&class->lock);
838 static int aoro2_class_cb(
void *obj,
void *arg,
int flags)
842 if (!strcmp(class->name, name) && !class->delme) {
851 unsigned int max_connections;
853 class =
ao2_callback(class_container, 0, aoro2_class_cb, (char *) name);
858 max_connections =
class->maxconnections;
861 return max_connections;
874 char *test_sql =
"select 1";
879 res = SQLGetConnectAttr(connection->
con, SQL_ATTR_CONNECTION_DEAD, &dead, 0, 0);
880 if (SQL_SUCCEEDED(res)) {
881 return dead == SQL_CD_TRUE ? 1 : 0;
887 res = SQLAllocHandle(SQL_HANDLE_STMT, connection->
con, &stmt);
888 if (!SQL_SUCCEEDED(res)) {
892 if (!ast_strlen_zero(class->sanitysql)) {
893 test_sql =
class->sanitysql;
896 res = SQLPrepare(stmt, (
unsigned char *)test_sql, SQL_NTS);
897 if (!SQL_SUCCEEDED(res)) {
898 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
902 res = SQLExecute(stmt);
903 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
905 return SQL_SUCCEEDED(res) ? 0 : 1;
908 struct odbc_obj *_ast_odbc_request_obj2(
const char *name,
struct ast_flags flags,
const char *file,
const char *
function,
int lineno)
913 if (!(
class =
ao2_callback(class_container, 0, aoro2_class_cb, (
char *) name))) {
914 ast_debug(1,
"Class '%s' not found!\n", name);
919 ast_mutex_lock(&class->lock);
923 ast_mutex_unlock(&class->lock);
926 ast_mutex_lock(&class->lock);
928 if (class->connection_cnt < class->maxconnections) {
933 obj = ao2_alloc(
sizeof(*obj), odbc_obj_destructor);
935 ast_mutex_unlock(&class->lock);
941 class->connection_cnt++;
943 ast_mutex_unlock(&class->lock);
945 if (odbc_obj_connect(obj) == ODBC_FAIL) {
946 ast_mutex_lock(&class->lock);
947 class->connection_cnt--;
948 ast_mutex_unlock(&class->lock);
955 ast_mutex_lock(&class->lock);
957 ast_debug(2,
"Created ODBC handle %p on class '%s', new count is %zd\n", obj,
958 name, class->connection_cnt);
965 ast_cond_wait(&class->cond, &class->lock);
968 ast_mutex_unlock(&class->lock);
977 ast_mutex_lock(&class->lock);
979 class->connection_cnt--;
980 ast_debug(2,
"ODBC handle %p dead - removing from class '%s', new count is %zd\n",
981 obj, name, class->connection_cnt);
983 ast_mutex_unlock(&class->lock);
989 ast_debug(2,
"Reusing ODBC handle %p from class '%s'\n", obj, name);
998 struct odbc_obj *_ast_odbc_request_obj(
const char *name,
int check,
const char *file,
const char *
function,
int lineno)
1000 struct ast_flags flags = { check ? RES_ODBC_SANITY_CHECK : 0 };
1006 return _ast_odbc_request_obj2(name, flags, file,
function, lineno);
1009 static odbc_status odbc_obj_disconnect(
struct odbc_obj *obj)
1014 unsigned char msg[200],
state[10];
1019 return ODBC_SUCCESS;
1024 res = SQLDisconnect(con);
1026 if ((res = SQLFreeHandle(SQL_HANDLE_DBC, con)) == SQL_SUCCESS) {
1027 ast_debug(3,
"Database handle %p (connection %p) deallocated\n", obj, con);
1029 SQLGetDiagRec(SQL_HANDLE_DBC, con, 1, state, &err, msg, 100, &mlen);
1030 ast_log(LOG_WARNING,
"Unable to deallocate database handle %p? %d errno=%d %s\n", con, res, (
int)err, msg);
1033 return ODBC_SUCCESS;
1036 static odbc_status odbc_obj_connect(
struct odbc_obj *obj)
1041 unsigned char msg[200], state[10];
1043 SQLINTEGER enable = 1;
1044 char *tracefile =
"/tmp/odbc.trace";
1047 long int negative_cache_expiration;
1049 ast_assert(obj->
con == NULL);
1054 if (time(NULL) < negative_cache_expiration) {
1055 char secs[AST_TIME_T_LEN];
1057 ast_log(LOG_WARNING,
"Not connecting to %s. Negative connection cache for %s seconds\n", obj->
parent->name, secs);
1061 res = SQLAllocHandle(SQL_HANDLE_DBC, obj->
parent->env, &con);
1063 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
1064 ast_log(LOG_WARNING,
"res_odbc: Error AllocHDB %d\n", res);
1068 SQLSetConnectAttr(con, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)(
long) obj->
parent->
conntimeout, 0);
1069 SQLSetConnectAttr(con, SQL_ATTR_CONNECTION_TIMEOUT, (SQLPOINTER *)(
long) obj->
parent->
conntimeout, 0);
1071 SQLSetConnectAttr(con, SQL_ATTR_TRACE, &enable, SQL_IS_INTEGER);
1072 SQLSetConnectAttr(con, SQL_ATTR_TRACEFILE, tracefile, strlen(tracefile));
1075 res = SQLConnect(con,
1076 (SQLCHAR *) obj->
parent->dsn, SQL_NTS,
1077 (SQLCHAR *) obj->
parent->username, SQL_NTS,
1078 (SQLCHAR *) obj->
parent->password, SQL_NTS);
1080 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
1081 SQLGetDiagRec(SQL_HANDLE_DBC, con, 1, state, &err, msg, 100, &mlen);
1083 ast_log(LOG_WARNING,
"res_odbc: Error SQLConnect=%d errno=%d %s\n", res, (
int)err, msg);
1084 if ((res = SQLFreeHandle(SQL_HANDLE_DBC, con)) != SQL_SUCCESS) {
1085 SQLGetDiagRec(SQL_HANDLE_DBC, con, 1, state, &err, msg, 100, &mlen);
1086 ast_log(LOG_WARNING,
"Unable to deallocate database handle %p? %d errno=%d %s\n", con, res, (
int)err, msg);
1094 return ODBC_SUCCESS;
1097 static int reload(
void)
1104 while ((
class = ao2_iterator_next(&aoi))) {
1113 while ((
class = ao2_iterator_next(&aoi))) {
1123 while ((table = AST_RWLIST_REMOVE_HEAD(&
odbc_tables, list))) {
1124 destroy_table_cache(table);
1131 static int unload_module(
void)
1133 ao2_cleanup(class_container);
1139 static int load_module(
void)
1142 if (!class_container) {
1146 if (load_odbc_config() == -1) {
1156 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER,
"ODBC resource",
1157 .support_level = AST_MODULE_SUPPORT_CORE,
1158 .load = load_module,
1159 .unload = unload_module,
1162 .requires =
"res_odbc_transaction",
struct ast_variable * next
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
const char * ast_odbc_isolation2text(int iso)
Convert from numeric transaction isolation values to their textual counterparts.
Main Channel structure associated with a channel.
#define AST_RWLIST_HEAD_DESTROY(head)
Destroys an rwlist head structure.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
struct odbc_cache_tables * ast_odbc_find_table(const char *database, const char *tablename)
Find or create an entry describing the table specified.
int ast_odbc_backslash_is_escape(struct odbc_obj *obj)
Checks if the database natively supports backslash as an escape character.
unsigned int maxconnections
SQLRETURN ast_odbc_execute_sql(struct odbc_obj *obj, SQLHSTMT *stmt, const char *sql)
Execute a unprepared SQL query.
String manipulation functions.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
int ast_time_t_to_string(time_t time, char *buf, size_t length)
Converts to a string representation of a time_t as decimal seconds since the epoch. Returns -1 on failure, zero otherwise.
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Time-related functions and macros.
struct ast_str * ast_odbc_print_errors(SQLSMALLINT handle_type, SQLHANDLE handle, const char *operation)
Shortcut for printing errors to logs after a failed SQL operation.
#define ast_odbc_request_obj(name, check)
Get a ODBC connection object.
descriptor for a cli entry.
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)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
unsigned int slowquerylimit
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Structure for variables, used for configurations and for channel variables.
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
#define ast_strdup(str)
A wrapper for strdup()
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
#define AST_RWLIST_HEAD_INIT(head)
Initializes an rwlist head structure.
Definitions to aid in the use of thread local storage.
These structures are used for adaptive capabilities.
struct timeval negative_connection_cache
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
SQLHSTMT ast_odbc_direct_execute(struct odbc_obj *obj, SQLHSTMT(*exec_cb)(struct odbc_obj *obj, void *data), void *data)
Executes an non prepared statement and returns the resulting statement handle.
unsigned int ast_odbc_class_get_isolation(struct odbc_class *class)
Get the transaction isolation setting for an ODBC class.
SQLHSTMT ast_odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT(*prepare_cb)(struct odbc_obj *obj, void *data), void *data)
Prepares, executes, and returns the resulting statement handle.
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Configuration File Parser.
#define ast_config_load(filename, flags)
Load a config file.
General Asterisk PBX channel definitions.
unsigned int ast_odbc_get_max_connections(const char *name)
Return the current configured maximum number of connections for a class.
struct odbc_class::@449 connections
static int connection_dead(struct odbc_obj *connection, struct odbc_class *class)
Determine if the connection has died.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
int ast_odbc_clear_cache(const char *database, const char *tablename)
Remove a cache entry from memory This function may be called to clear entries created and cached by t...
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
void ast_odbc_release_obj(struct odbc_obj *obj)
Releases an ODBC object previously allocated by ast_odbc_request_obj()
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
struct odbc_class * parent
Core PBX routines and definitions.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
int ast_odbc_text2isolation(const char *txt)
Convert from textual transaction isolation values to their numeric constants.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
unsigned int backslash_is_escape
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".
Support for dynamic strings.
#define ao2_unlink(container, obj)
Remove an object from a container.
#define ast_module_shutdown_ref(mod)
Prevent unload of the module before shutdown.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
int ao2_match_by_addr(void *obj, void *arg, int flags)
A common ao2_callback is one that matches by address.
#define ast_calloc(num, len)
A wrapper for calloc()
int ast_odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt)
Executes a prepared statement handle.
Module has failed to load, may be in an inconsistent state.
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
SQLRETURN ast_odbc_ast_str_SQLGetData(struct ast_str **buf, int pmaxlen, SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType, SQLLEN *StrLen_or_Ind)
Wrapper for SQLGetData to use with dynamic strings.
Structure used to handle boolean flags.
struct odbc_cache_columns * ast_odbc_find_column(struct odbc_cache_tables *table, const char *colname)
Find a column entry within a cached table structure.
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Standard Command Line Interface.
static int enabled
Whether or not we are storing history.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
struct timeval last_negative_connect
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
const char * ast_odbc_class_get_name(struct odbc_class *class)
Get the name of an ODBC class.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
Structure for mutex and tracking information.
long longest_query_execution_time
int ast_odbc_prepare(struct odbc_obj *obj, SQLHSTMT *stmt, const char *sql)
Prepares a SQL query on a statement.
unsigned int ast_odbc_class_get_forcecommit(struct odbc_class *class)
Get the transaction forcecommit setting for an ODBC class.
#define ao2_link(container, obj)
Add an object to a container.