change odbc handling in code to be runtime instead of build time

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13936 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2009-06-24 16:02:43 +00:00
parent f7d99cf948
commit 6348359d95
25 changed files with 262 additions and 379 deletions

View File

@ -97,6 +97,7 @@ src/switch_xml.c\
src/switch_xml_config.c\ src/switch_xml_config.c\
src/switch_config.c\ src/switch_config.c\
src/switch_time.c\ src/switch_time.c\
src/switch_odbc.c \
libs/stfu/stfu.c\ libs/stfu/stfu.c\
src/switch_cpp.cpp\ src/switch_cpp.cpp\
src/g711.c\ src/g711.c\
@ -204,7 +205,6 @@ endif
if ADD_ODBC if ADD_ODBC
CORE_CFLAGS += -DSWITCH_HAVE_ODBC $(ODBC_INC_FLAGS) CORE_CFLAGS += -DSWITCH_HAVE_ODBC $(ODBC_INC_FLAGS)
libfreeswitch_la_SOURCES += src/switch_odbc.c
libfreeswitch_la_LDFLAGS += $(ODBC_LIB_FLAGS) libfreeswitch_la_LDFLAGS += $(ODBC_LIB_FLAGS)
endif endif

View File

@ -130,6 +130,8 @@
#include "switch_scheduler.h" #include "switch_scheduler.h"
#include "switch_config.h" #include "switch_config.h"
#include "switch_nat.h" #include "switch_nat.h"
#include "switch_odbc.h"
#include <libteletone.h> #include <libteletone.h>
/** \mainpage FreeSWITCH /** \mainpage FreeSWITCH

View File

@ -33,18 +33,11 @@
#define SWITCH_ODBC_H #define SWITCH_ODBC_H
#include <switch.h> #include <switch.h>
#include <sql.h>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4201)
#include <sqlext.h>
#pragma warning(pop)
#else
#include <sqlext.h>
#endif
#include <sqltypes.h>
SWITCH_BEGIN_EXTERN_C struct switch_odbc_handle; SWITCH_BEGIN_EXTERN_C
struct switch_odbc_handle;
typedef void * switch_odbc_statement_handle_t;
typedef enum { typedef enum {
SWITCH_ODBC_STATE_INIT, SWITCH_ODBC_STATE_INIT,
@ -63,7 +56,13 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_disconnect(switch_odbc_h
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_handle_t *handle); SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_handle_t *handle);
SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep); SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep);
SWITCH_DECLARE(switch_odbc_state_t) switch_odbc_handle_get_state(switch_odbc_handle_t *handle); SWITCH_DECLARE(switch_odbc_state_t) switch_odbc_handle_get_state(switch_odbc_handle_t *handle);
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, char *sql, SQLHSTMT * rstmt); SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, char *sql, switch_odbc_statement_handle_t * rstmt);
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec_string(switch_odbc_handle_t *handle,
char *sql,
char *resbuf,
size_t len);
SWITCH_DECLARE(switch_bool_t) switch_odbc_available(void);
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_statement_handle_free(switch_odbc_statement_handle_t * stmt);
/*! /*!
\brief Execute the sql query and issue a callback for each row returned \brief Execute the sql query and issue a callback for each row returned
@ -93,7 +92,7 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c
handle, sql, callback, pdata) handle, sql, callback, pdata)
SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, SQLHSTMT stmt); SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, switch_odbc_statement_handle_t stmt);
SWITCH_END_EXTERN_C SWITCH_END_EXTERN_C
#endif #endif
/* For Emacs: /* For Emacs:

View File

@ -1490,7 +1490,7 @@ struct switch_network_list;
typedef struct switch_network_list switch_network_list_t; typedef struct switch_network_list switch_network_list_t;
#define SWITCH_API_VERSION 3 #define SWITCH_API_VERSION 4
#define SWITCH_MODULE_LOAD_ARGS (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) #define SWITCH_MODULE_LOAD_ARGS (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool)
#define SWITCH_MODULE_RUNTIME_ARGS (void) #define SWITCH_MODULE_RUNTIME_ARGS (void)
#define SWITCH_MODULE_SHUTDOWN_ARGS (void) #define SWITCH_MODULE_SHUTDOWN_ARGS (void)

View File

@ -1,5 +1,4 @@
WANT_CURL=yes WANT_CURL=yes
BASE=../../../.. BASE=../../../..
include $(BASE)/build/modmake.rules include $(BASE)/build/modmake.rules
LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`

View File

@ -30,9 +30,6 @@
*/ */
#include <switch.h> #include <switch.h>
#ifdef SWITCH_HAVE_ODBC
#include <switch_odbc.h>
#endif
#include <curl/curl.h> #include <curl/curl.h>
/* Prototypes */ /* Prototypes */
@ -56,33 +53,11 @@ static struct {
char *odbc_dsn; char *odbc_dsn;
char *sql; char *sql;
#ifdef SWITCH_HAVE_ODBC
switch_mutex_t *db_mutex; switch_mutex_t *db_mutex;
#else
void *filler1;
#endif
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
#ifdef SWITCH_HAVE_ODBC
switch_odbc_handle_t *master_odbc; switch_odbc_handle_t *master_odbc;
#else
void *filler2;
#endif
} globals; } globals;
#ifdef SWITCH_HAVE_ODBC
struct odbc_obj {
switch_odbc_handle_t *handle;
SQLHSTMT stmt;
SQLCHAR *colbuf;
int32_t cblen;
SQLCHAR *code;
int32_t codelen;
};
typedef struct odbc_obj odbc_obj_t;
typedef odbc_obj_t *odbc_handle;
#endif
struct http_data { struct http_data {
switch_stream_handle_t stream; switch_stream_handle_t stream;
switch_size_t bytes; switch_size_t bytes;
@ -103,13 +78,17 @@ static switch_event_node_t *reload_xml_event = NULL;
static switch_status_t config_callback_dsn(switch_xml_config_item_t *data, const char *newvalue, switch_config_callback_type_t callback_type, switch_bool_t changed) static switch_status_t config_callback_dsn(switch_xml_config_item_t *data, const char *newvalue, switch_config_callback_type_t callback_type, switch_bool_t changed)
{ {
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
#ifdef SWITCH_HAVE_ODBC
char *odbc_user = NULL; char *odbc_user = NULL;
char *odbc_pass = NULL; char *odbc_pass = NULL;
char *odbc_dsn = NULL; char *odbc_dsn = NULL;
switch_odbc_handle_t *odbc = NULL; switch_odbc_handle_t *odbc = NULL;
if (!switch_odbc_available()) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC is not compiled in. Do not configure odbc-dsn parameter!\n");
return SWITCH_STATUS_FALSE;
}
if (globals.db_mutex) { if (globals.db_mutex) {
switch_mutex_lock(globals.db_mutex); switch_mutex_lock(globals.db_mutex);
} }
@ -152,18 +131,12 @@ static switch_status_t config_callback_dsn(switch_xml_config_item_t *data, const
} }
switch_goto_status(SWITCH_STATUS_SUCCESS, done); switch_goto_status(SWITCH_STATUS_SUCCESS, done);
#else
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC is not compiled in. Do not configure odbc-dsn parameter!\n");
switch_goto_status(SWITCH_STATUS_FALSE, done);
#endif
done: done:
#ifdef SWITCH_HAVE_ODBC
if (globals.db_mutex) { if (globals.db_mutex) {
switch_mutex_unlock(globals.db_mutex); switch_mutex_unlock(globals.db_mutex);
} }
switch_safe_free(odbc_dsn); switch_safe_free(odbc_dsn);
#endif
return status; return status;
} }
@ -193,7 +166,6 @@ static void event_handler(switch_event_t *event)
do_config(SWITCH_TRUE); do_config(SWITCH_TRUE);
} }
#ifdef SWITCH_HAVE_ODBC
static switch_bool_t cidlookup_execute_sql_callback(char *sql, switch_core_db_callback_func_t callback, void *pdata) static switch_bool_t cidlookup_execute_sql_callback(char *sql, switch_core_db_callback_func_t callback, void *pdata)
{ {
switch_bool_t retval = SWITCH_FALSE; switch_bool_t retval = SWITCH_FALSE;
@ -227,7 +199,6 @@ static int cidlookup_callback(void *pArg, int argc, char **argv, char **columnNa
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
#endif
/* make a new string with digits only */ /* make a new string with digits only */
static char *string_digitsonly(switch_memory_pool_t *pool, const char *str) static char *string_digitsonly(switch_memory_pool_t *pool, const char *str)
@ -365,7 +336,6 @@ static char *do_lookup_url(switch_memory_pool_t *pool, switch_event_t *event, co
return name; return name;
} }
#ifdef SWITCH_HAVE_ODBC
static char *do_db_lookup(switch_memory_pool_t *pool, switch_event_t *event, const char *num) { static char *do_db_lookup(switch_memory_pool_t *pool, switch_event_t *event, const char *num) {
char *name = NULL; char *name = NULL;
char *newsql = NULL; char *newsql = NULL;
@ -386,7 +356,6 @@ static char *do_db_lookup(switch_memory_pool_t *pool, switch_event_t *event, con
} }
return name; return name;
} }
#endif
static char *do_lookup(switch_memory_pool_t *pool, switch_event_t *event, const char *num, switch_bool_t skipurl) { static char *do_lookup(switch_memory_pool_t *pool, switch_event_t *event, const char *num, switch_bool_t skipurl) {
char *number = NULL; char *number = NULL;
@ -395,12 +364,11 @@ static char *do_lookup(switch_memory_pool_t *pool, switch_event_t *event, const
number = string_digitsonly(pool, num); number = string_digitsonly(pool, num);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "caller_id_number", number); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "caller_id_number", number);
#ifdef SWITCH_HAVE_ODBC
/* database always wins */ /* database always wins */
if (globals.master_odbc && globals.sql) { if (switch_odbc_available() && globals.master_odbc && globals.sql) {
name = do_db_lookup(pool, event, number); name = do_db_lookup(pool, event, number);
} }
#endif
if (!name && globals.url) { if (!name && globals.url) {
if (globals.cache) { if (globals.cache) {
name = check_cache(pool, number); name = check_cache(pool, number);
@ -510,11 +478,7 @@ SWITCH_STANDARD_API(cidlookup_function)
stream->write_function(stream, " odbc-dsn: %s\n sql: %s\n", stream->write_function(stream, " odbc-dsn: %s\n sql: %s\n",
globals.odbc_dsn, globals.odbc_dsn,
globals.sql); globals.sql);
#ifdef SWITCH_HAVE_ODBC stream->write_function(stream, " ODBC Compiled: %s\n", switch_odbc_available() ? "true" : "false");
stream->write_function(stream, " ODBC Compiled: true\n");
#else
stream->write_function(stream, " ODBC Compiled: false\n");
#endif
switch_goto_status(SWITCH_STATUS_SUCCESS, done); switch_goto_status(SWITCH_STATUS_SUCCESS, done);
} }
@ -556,13 +520,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cidlookup_load)
globals.pool = pool; globals.pool = pool;
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available() && !globals.db_mutex) {
if (!globals.db_mutex) {
if (switch_mutex_init(&globals.db_mutex, SWITCH_MUTEX_UNNESTED, globals.pool) != SWITCH_STATUS_SUCCESS) { if (switch_mutex_init(&globals.db_mutex, SWITCH_MUTEX_UNNESTED, globals.pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to initialize db_mutex\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to initialize db_mutex\n");
} }
} }
#endif
do_config(SWITCH_FALSE); do_config(SWITCH_FALSE);
@ -585,7 +547,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cidlookup_load)
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cidlookup_shutdown) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cidlookup_shutdown)
{ {
/* Cleanup dynamically allocated config settings */ /* Cleanup dynamically allocated config settings */
#ifdef SWITCH_HAVE_ODBC
if (globals.db_mutex) { if (globals.db_mutex) {
switch_mutex_destroy(globals.db_mutex); switch_mutex_destroy(globals.db_mutex);
} }
@ -593,7 +555,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cidlookup_shutdown)
switch_odbc_handle_disconnect(globals.master_odbc); switch_odbc_handle_disconnect(globals.master_odbc);
switch_odbc_handle_destroy(&globals.master_odbc); switch_odbc_handle_destroy(&globals.master_odbc);
} }
#endif
switch_event_unbind(&reload_xml_event); switch_event_unbind(&reload_xml_event);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }

View File

@ -1,3 +0,0 @@
BASE=../../../..
include $(BASE)/build/modmake.rules
LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`

View File

@ -38,10 +38,6 @@
#include <switch.h> #include <switch.h>
#ifdef SWITCH_HAVE_ODBC
#include <switch_odbc.h>
#endif
typedef struct easyroute_results{ typedef struct easyroute_results{
char limit[16]; char limit[16];
char dialstring[256]; char dialstring[256];
@ -68,11 +64,7 @@ static struct {
char *default_gateway; char *default_gateway;
switch_mutex_t *mutex; switch_mutex_t *mutex;
char *custom_query; char *custom_query;
#ifdef SWITCH_HAVE_ODBC
switch_odbc_handle_t *master_odbc; switch_odbc_handle_t *master_odbc;
#else
void *filler1;
#endif
} globals; } globals;
SWITCH_MODULE_LOAD_FUNCTION(mod_easyroute_load); SWITCH_MODULE_LOAD_FUNCTION(mod_easyroute_load);
@ -86,7 +78,6 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_default_techprofile, globals.defaul
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_default_gateway, globals.default_gateway); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_default_gateway, globals.default_gateway);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_custom_query, globals.custom_query); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_custom_query, globals.custom_query);
#ifdef SWITCH_HAVE_ODBC
static int route_callback(void *pArg, int argc, char **argv, char **columnNames) static int route_callback(void *pArg, int argc, char **argv, char **columnNames)
{ {
route_callback_t *cbt = (route_callback_t *) pArg; route_callback_t *cbt = (route_callback_t *) pArg;
@ -100,7 +91,6 @@ static int route_callback(void *pArg, int argc, char **argv, char **columnNames)
return 0; return 0;
} }
#endif
static switch_status_t load_config(void) static switch_status_t load_config(void)
{ {
@ -145,9 +135,7 @@ done:
set_global_db_dsn("easyroute"); set_global_db_dsn("easyroute");
} }
if (switch_odbc_available() && globals.db_dsn) {
#ifdef SWITCH_HAVE_ODBC
if (globals.db_dsn) {
if (!(globals.master_odbc = switch_odbc_handle_new(globals.db_dsn, globals.db_username, globals.db_password))) { if (!(globals.master_odbc = switch_odbc_handle_new(globals.db_dsn, globals.db_username, globals.db_password))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
@ -171,15 +159,12 @@ done:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot find SQL Database! (Where\'s the gateways table\?\?)\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot find SQL Database! (Where\'s the gateways table\?\?)\n");
} }
} }
} else { } else if (globals.db_dsn) {
#endif
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Connection (did you enable it?!)\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Connection (did you enable it?!)\n");
#ifdef SWITCH_HAVE_ODBC
} }
reallydone: reallydone:
#endif
if (xml) { if (xml) {
switch_xml_free(xml); switch_xml_free(xml);
} }
@ -192,17 +177,20 @@ reallydone:
return status; return status;
} }
#ifdef SWITCH_HAVE_ODBC
static char SQL_LOOKUP[] = "SELECT gateways.gateway_ip, gateways.group, gateways.limit, gateways.techprofile, numbers.acctcode, numbers.translated from gateways, numbers where numbers.number = '%q' and numbers.gateway_id = gateways.gateway_id limit 1;"; static char SQL_LOOKUP[] = "SELECT gateways.gateway_ip, gateways.group, gateways.limit, gateways.techprofile, numbers.acctcode, numbers.translated from gateways, numbers where numbers.number = '%q' and numbers.gateway_id = gateways.gateway_id limit 1;";
#endif
static switch_status_t route_lookup(char *dn, easyroute_results_t *results, int noat, char *seperator) static switch_status_t route_lookup(char *dn, easyroute_results_t *results, int noat, char *seperator)
{ {
switch_status_t sstatus = SWITCH_STATUS_SUCCESS; switch_status_t sstatus = SWITCH_STATUS_SUCCESS;
#ifdef SWITCH_HAVE_ODBC
char *sql = NULL; char *sql = NULL;
route_callback_t pdata; route_callback_t pdata;
if (!switch_odbc_available()) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"mod_easyroute requires core ODBC support. Please refer to the documentation on how to enable this\n");
return sstatus;
}
memset(&pdata, 0, sizeof(pdata)); memset(&pdata, 0, sizeof(pdata));
if (!globals.custom_query){ if (!globals.custom_query){
sql = switch_mprintf(SQL_LOOKUP, dn); sql = switch_mprintf(SQL_LOOKUP, dn);
@ -278,9 +266,6 @@ static switch_status_t route_lookup(char *dn, easyroute_results_t *results, int
} }
switch_safe_free(sql); switch_safe_free(sql);
#else
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "mod_easyroute requires core ODBC support. Please refer to the documentation on how to enable this\n");
#endif
if (globals.mutex){ if (globals.mutex){
switch_mutex_unlock(globals.mutex); switch_mutex_unlock(globals.mutex);
@ -347,11 +332,11 @@ SWITCH_STANDARD_API(easyroute_function)
goto done; goto done;
} }
#ifndef SWITCH_HAVE_ODBC if (!switch_odbc_available()) {
stream->write_function(stream, "mod_easyroute requires you enable core odbc support\n"); stream->write_function(stream, "mod_easyroute requires you enable core odbc support\n");
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
goto done; goto done;
#endif }
if (!cmd || !(mydata = strdup(cmd))) { if (!cmd || !(mydata = strdup(cmd))) {
stream->write_function(stream, "Usage: easyroute <number>\n"); stream->write_function(stream, "Usage: easyroute <number>\n");
@ -430,10 +415,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_easyroute_load)
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_easyroute_shutdown) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_easyroute_shutdown)
{ {
#ifdef SWITCH_HAVE_ODBC
switch_odbc_handle_disconnect(globals.master_odbc); switch_odbc_handle_disconnect(globals.master_odbc);
#endif
switch_safe_free(globals.db_username); switch_safe_free(globals.db_username);
switch_safe_free(globals.db_password); switch_safe_free(globals.db_password);
switch_safe_free(globals.db_dsn); switch_safe_free(globals.db_dsn);

View File

@ -29,9 +29,6 @@
* *
*/ */
#include <switch.h> #include <switch.h>
#ifdef SWITCH_HAVE_ODBC
#include <switch_odbc.h>
#endif
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown);
SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load); SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load);
@ -264,12 +261,7 @@ static struct {
char *dbname; char *dbname;
char *odbc_dsn; char *odbc_dsn;
int node_thread_running; int node_thread_running;
#ifdef SWITCH_HAVE_ODBC
switch_odbc_handle_t *master_odbc; switch_odbc_handle_t *master_odbc;
#else
void *filler1;
#endif
} globals; } globals;
@ -282,9 +274,9 @@ static switch_status_t fifo_execute_sql(char *sql, switch_mutex_t *mutex)
if (mutex) { if (mutex) {
switch_mutex_lock(mutex); switch_mutex_lock(mutex);
} }
#ifdef SWITCH_HAVE_ODBC
if (globals.odbc_dsn) { if (switch_odbc_available() && globals.odbc_dsn) {
SQLHSTMT stmt; switch_odbc_statement_handle_t stmt;
if (switch_odbc_handle_exec(globals.master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) { if (switch_odbc_handle_exec(globals.master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
err_str = switch_odbc_handle_get_error(globals.master_odbc, stmt); err_str = switch_odbc_handle_get_error(globals.master_odbc, stmt);
@ -294,9 +286,8 @@ static switch_status_t fifo_execute_sql(char *sql, switch_mutex_t *mutex)
switch_safe_free(err_str); switch_safe_free(err_str);
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
} }
SQLFreeHandle(SQL_HANDLE_STMT, stmt); switch_odbc_statement_handle_free(&stmt);
} else { } else {
#endif
if (!(db = switch_core_db_open_file(globals.dbname))) { if (!(db = switch_core_db_open_file(globals.dbname))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname);
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
@ -309,12 +300,8 @@ static switch_status_t fifo_execute_sql(char *sql, switch_mutex_t *mutex)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error [%s]\n[%s]\n", sql, err_str); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error [%s]\n[%s]\n", sql, err_str);
free(err_str); free(err_str);
} }
switch_core_db_close(db); switch_core_db_close(db);
#ifdef SWITCH_HAVE_ODBC
} }
#endif
end: end:
if (mutex) { if (mutex) {
@ -334,11 +321,9 @@ static switch_bool_t fifo_execute_sql_callback(switch_mutex_t *mutex, char *sql,
switch_mutex_lock(mutex); switch_mutex_lock(mutex);
} }
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available() && globals.odbc_dsn) {
if (globals.odbc_dsn) {
switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata); switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata);
} else { } else {
#endif
if (!(db = switch_core_db_open_file(globals.dbname))) { if (!(db = switch_core_db_open_file(globals.dbname))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname);
goto end; goto end;
@ -354,9 +339,7 @@ static switch_bool_t fifo_execute_sql_callback(switch_mutex_t *mutex, char *sql,
if (db) { if (db) {
switch_core_db_close(db); switch_core_db_close(db);
} }
#ifdef SWITCH_HAVE_ODBC
} }
#endif
end: end:
if (mutex) { if (mutex) {
@ -1766,17 +1749,17 @@ static switch_status_t load_config(int reload, int del_all)
val = (char *) switch_xml_attr_soft(param, "value"); val = (char *) switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "odbc-dsn") && !switch_strlen_zero(val)) { if (!strcasecmp(var, "odbc-dsn") && !switch_strlen_zero(val)) {
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available()) {
globals.odbc_dsn = switch_core_strdup(globals.pool, val); globals.odbc_dsn = switch_core_strdup(globals.pool, val);
if ((odbc_user = strchr(globals.odbc_dsn, ':'))) { if ((odbc_user = strchr(globals.odbc_dsn, ':'))) {
*odbc_user++ = '\0'; *odbc_user++ = '\0';
if ((odbc_pass = strchr(odbc_user, ':'))) { if ((odbc_pass = strchr(odbc_user, ':'))) {
*odbc_pass++ = '\0'; *odbc_pass++ = '\0';
}
} }
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
} }
#else
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
#endif
} }
} }
} }
@ -1786,8 +1769,7 @@ static switch_status_t load_config(int reload, int del_all)
globals.dbname = "fifo"; globals.dbname = "fifo";
} }
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available() && globals.odbc_dsn) {
if (globals.odbc_dsn) {
if (!(globals.master_odbc = switch_odbc_handle_new(globals.odbc_dsn, odbc_user, odbc_pass))) { if (!(globals.master_odbc = switch_odbc_handle_new(globals.odbc_dsn, odbc_user, odbc_pass))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
@ -1806,7 +1788,6 @@ static switch_status_t load_config(int reload, int del_all)
} }
} }
} else { } else {
#endif
if ((db = switch_core_db_open_file(globals.dbname))) { if ((db = switch_core_db_open_file(globals.dbname))) {
switch_core_db_test_reactive(db, "delete from fifo_outbound", NULL, (char *)outbound_sql); switch_core_db_test_reactive(db, "delete from fifo_outbound", NULL, (char *)outbound_sql);
} else { } else {
@ -1815,9 +1796,7 @@ static switch_status_t load_config(int reload, int del_all)
goto done; goto done;
} }
switch_core_db_close(db); switch_core_db_close(db);
#ifdef SWITCH_HAVE_ODBC
} }
#endif
if (reload) { if (reload) {
switch_hash_index_t *hi; switch_hash_index_t *hi;

View File

@ -1,3 +0,0 @@
BASE=../../../..
LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`
include $(BASE)/build/modmake.rules

View File

@ -31,8 +31,6 @@
*/ */
#include <switch.h> #include <switch.h>
#include <switch_odbc.h>
#define LCR_SYNTAX "lcr <digits> [<lcr profile>] [caller_id] [intrastate]" #define LCR_SYNTAX "lcr <digits> [<lcr profile>] [caller_id] [intrastate]"
#define LCR_ADMIN_SYNTAX "lcr_admin show profiles" #define LCR_ADMIN_SYNTAX "lcr_admin show profiles"
@ -75,15 +73,6 @@ static char headers[LCR_HEADERS_COUNT][32] = {
/* sql for random function */ /* sql for random function */
static char *db_random = NULL; static char *db_random = NULL;
struct odbc_obj {
switch_odbc_handle_t *handle;
SQLHSTMT stmt;
SQLCHAR *colbuf;
int32_t cblen;
SQLCHAR *code;
int32_t codelen;
};
struct lcr_obj { struct lcr_obj {
char *carrier_name; char *carrier_name;
char *gw_prefix; char *gw_prefix;
@ -112,9 +101,6 @@ struct max_obj {
size_t dialstring; size_t dialstring;
}; };
typedef struct odbc_obj odbc_obj_t;
typedef odbc_obj_t *odbc_handle;
typedef struct lcr_obj lcr_obj_t; typedef struct lcr_obj lcr_obj_t;
typedef lcr_obj_t *lcr_route; typedef lcr_obj_t *lcr_route;
@ -1384,11 +1370,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lcr_load)
*module_interface = switch_loadable_module_create_module_interface(pool, modname); *module_interface = switch_loadable_module_create_module_interface(pool, modname);
#ifndef SWITCH_HAVE_ODBC if (!switch_odbc_available()) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "You must have ODBC support in FreeSWITCH to use this module\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "You must have ODBC support in FreeSWITCH to use this module\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "\t./configure --enable-core-odbc-support\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "\t./configure --enable-core-odbc-support\n");
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
#endif }
globals.pool = pool; globals.pool = pool;
@ -1417,10 +1403,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lcr_load)
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_lcr_shutdown) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_lcr_shutdown)
{ {
#ifdef SWITCH_HAVE_ODBC
switch_odbc_handle_disconnect(globals.master_odbc); switch_odbc_handle_disconnect(globals.master_odbc);
switch_odbc_handle_destroy(&globals.master_odbc); switch_odbc_handle_destroy(&globals.master_odbc);
#endif
switch_core_hash_destroy(&globals.profile_hash); switch_core_hash_destroy(&globals.profile_hash);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;

View File

@ -1,3 +0,0 @@
BASE=../../../..
include $(BASE)/build/modmake.rules
LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`

View File

@ -33,9 +33,6 @@
*/ */
#include <switch.h> #include <switch.h>
#ifdef SWITCH_HAVE_ODBC
#include <switch_odbc.h>
#endif
#define LIMIT_EVENT_USAGE "limit::usage" #define LIMIT_EVENT_USAGE "limit::usage"
@ -53,11 +50,7 @@ static struct {
switch_hash_t *limit_hash; switch_hash_t *limit_hash;
switch_mutex_t *db_hash_mutex; switch_mutex_t *db_hash_mutex;
switch_hash_t *db_hash; switch_hash_t *db_hash;
#ifdef SWITCH_HAVE_ODBC
switch_odbc_handle_t *master_odbc; switch_odbc_handle_t *master_odbc;
#else
void *filler1;
#endif
} globals; } globals;
typedef struct { typedef struct {
@ -102,9 +95,9 @@ static switch_status_t limit_execute_sql(char *sql, switch_mutex_t *mutex)
if (mutex) { if (mutex) {
switch_mutex_lock(mutex); switch_mutex_lock(mutex);
} }
#ifdef SWITCH_HAVE_ODBC
if (globals.odbc_dsn) { if (switch_odbc_available() && globals.odbc_dsn) {
SQLHSTMT stmt; switch_odbc_statement_handle_t stmt;
if (switch_odbc_handle_exec(globals.master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) { if (switch_odbc_handle_exec(globals.master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
char *err_str; char *err_str;
err_str = switch_odbc_handle_get_error(globals.master_odbc, stmt); err_str = switch_odbc_handle_get_error(globals.master_odbc, stmt);
@ -114,21 +107,16 @@ static switch_status_t limit_execute_sql(char *sql, switch_mutex_t *mutex)
switch_safe_free(err_str); switch_safe_free(err_str);
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
} }
SQLFreeHandle(SQL_HANDLE_STMT, stmt); switch_odbc_statement_handle_free(&stmt);
} else { } else {
#endif
if (!(db = switch_core_db_open_file(globals.dbname))) { if (!(db = switch_core_db_open_file(globals.dbname))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname);
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
goto end; goto end;
} }
status = switch_core_db_persistant_execute(db, sql, 1); status = switch_core_db_persistant_execute(db, sql, 1);
switch_core_db_close(db); switch_core_db_close(db);
#ifdef SWITCH_HAVE_ODBC
} }
#endif
end: end:
if (mutex) { if (mutex) {
@ -148,11 +136,9 @@ static switch_bool_t limit_execute_sql_callback(switch_mutex_t *mutex, char *sql
switch_mutex_lock(mutex); switch_mutex_lock(mutex);
} }
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available() && globals.odbc_dsn) {
if (globals.odbc_dsn) {
switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata); switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata);
} else { } else {
#endif
if (!(db = switch_core_db_open_file(globals.dbname))) { if (!(db = switch_core_db_open_file(globals.dbname))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname);
goto end; goto end;
@ -168,9 +154,7 @@ static switch_bool_t limit_execute_sql_callback(switch_mutex_t *mutex, char *sql
if (db) { if (db) {
switch_core_db_close(db); switch_core_db_close(db);
} }
#ifdef SWITCH_HAVE_ODBC
} }
#endif
end: end:
if (mutex) { if (mutex) {
@ -202,17 +186,15 @@ static switch_status_t do_config()
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }
if (globals.odbc_dsn) { if (switch_odbc_available() && globals.odbc_dsn) {
#ifdef SWITCH_HAVE_ODBC
if ((odbc_user = strchr(globals.odbc_dsn, ':'))) { if ((odbc_user = strchr(globals.odbc_dsn, ':'))) {
*odbc_user++ = '\0'; *odbc_user++ = '\0';
if ((odbc_pass = strchr(odbc_user, ':'))) { if ((odbc_pass = strchr(odbc_user, ':'))) {
*odbc_pass++ = '\0'; *odbc_pass++ = '\0';
} }
} }
#else } else if (globals.odbc_dsn) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
#endif
} }
@ -220,8 +202,7 @@ static switch_status_t do_config()
globals.dbname = "call_limit"; globals.dbname = "call_limit";
} }
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available() && globals.odbc_dsn) {
if (globals.odbc_dsn) {
int x; int x;
char *indexes[] = { char *indexes[] = {
"create index ld_hostname on limit_data (hostname)", "create index ld_hostname on limit_data (hostname)",
@ -269,7 +250,6 @@ static switch_status_t do_config()
switch_odbc_handle_exec(globals.master_odbc, indexes[x], NULL); switch_odbc_handle_exec(globals.master_odbc, indexes[x], NULL);
} }
} else { } else {
#endif
if ((db = switch_core_db_open_file(globals.dbname))) { if ((db = switch_core_db_open_file(globals.dbname))) {
switch_core_db_test_reactive(db, "select * from limit_data", NULL, limit_sql); switch_core_db_test_reactive(db, "select * from limit_data", NULL, limit_sql);
switch_core_db_test_reactive(db, "select * from db_data", NULL, db_sql); switch_core_db_test_reactive(db, "select * from db_data", NULL, db_sql);
@ -292,9 +272,7 @@ static switch_status_t do_config()
goto done; goto done;
} }
switch_core_db_close(db); switch_core_db_close(db);
#ifdef SWITCH_HAVE_ODBC
} }
#endif
done: done:
@ -1129,11 +1107,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_limit_load)
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_limit_shutdown) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_limit_shutdown)
{ {
#ifdef SWITCH_HAVE_ODBC
if (globals.master_odbc) { if (globals.master_odbc) {
switch_odbc_handle_destroy(&globals.master_odbc); switch_odbc_handle_destroy(&globals.master_odbc);
} }
#endif
switch_event_free_subclass(LIMIT_EVENT_USAGE); switch_event_free_subclass(LIMIT_EVENT_USAGE);

View File

@ -1,3 +0,0 @@
BASE=../../../..
include $(BASE)/build/modmake.rules
LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`

View File

@ -49,15 +49,9 @@
#include <switch.h> #include <switch.h>
#ifdef SWITCH_HAVE_ODBC
#include <switch_odbc.h>
#endif
/* Defaults */ /* Defaults */
#ifdef SWITCH_HAVE_ODBC
static char SQL_LOOKUP[] = "SELECT %s FROM %s WHERE %s='%s'"; static char SQL_LOOKUP[] = "SELECT %s FROM %s WHERE %s='%s'";
static char SQL_SAVE[] = "UPDATE %s SET %s=%s-%f WHERE %s='%s'"; static char SQL_SAVE[] = "UPDATE %s SET %s=%s-%f WHERE %s='%s'";
#endif
typedef struct typedef struct
{ {
@ -109,11 +103,7 @@ static struct
char *db_table; char *db_table;
char *db_column_cash; char *db_column_cash;
char *db_column_account; char *db_column_account;
#ifdef SWITCH_HAVE_ODBC
switch_odbc_handle_t *master_odbc; switch_odbc_handle_t *master_odbc;
#else
void *padding1; /* Keep structures same size */
#endif
} globals; } globals;
static void nibblebill_pause(switch_core_session_t *session); static void nibblebill_pause(switch_core_session_t *session);
@ -141,7 +131,6 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_percall_action, globals.percall_act
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_lowbal_action, globals.lowbal_action); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_lowbal_action, globals.lowbal_action);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_nobal_action, globals.nobal_action); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_nobal_action, globals.nobal_action);
#ifdef SWITCH_HAVE_ODBC
static int nibblebill_callback(void *pArg, int argc, char **argv, char **columnNames) static int nibblebill_callback(void *pArg, int argc, char **argv, char **columnNames)
{ {
nibblebill_results_t *cbt = (nibblebill_results_t *) pArg; nibblebill_results_t *cbt = (nibblebill_results_t *) pArg;
@ -150,7 +139,6 @@ static int nibblebill_callback(void *pArg, int argc, char **argv, char **columnN
return 0; return 0;
} }
#endif
static switch_status_t load_config(void) static switch_status_t load_config(void)
{ {
@ -220,8 +208,7 @@ setdefaults:
set_global_nobal_action("hangup"); set_global_nobal_action("hangup");
} }
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available() && globals.db_dsn) {
if (globals.db_dsn) {
if (!(globals.master_odbc = switch_odbc_handle_new(globals.db_dsn, globals.db_username, globals.db_password))) { if (!(globals.master_odbc = switch_odbc_handle_new(globals.db_dsn, globals.db_username, globals.db_password))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot create handle to ODBC Database!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot create handle to ODBC Database!\n");
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
@ -231,7 +218,9 @@ setdefaults:
} }
if (switch_odbc_handle_connect(globals.master_odbc) != SWITCH_ODBC_SUCCESS) { if (switch_odbc_handle_connect(globals.master_odbc) != SWITCH_ODBC_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot connect to ODBC driver/database %s (user: %s / pass %s)!\n", globals.db_dsn, globals.db_username, globals.db_password); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"Cannot connect to ODBC driver/database %s (user: %s / pass %s)!\n",
globals.db_dsn, globals.db_username, globals.db_password);
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
goto done; goto done;
} else { } else {
@ -239,16 +228,11 @@ setdefaults:
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", globals.db_dsn); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", globals.db_dsn);
} else { } else {
#endif switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "ODBC does not appear to be installed in the core. You need to run ./configure --enable-core-odbc-support\n"); "ODBC does not appear to be installed in the core. You need to run ./configure --enable-core-odbc-support\n");
#ifdef SWITCH_HAVE_ODBC
} }
#endif
#ifdef SWITCH_HAVE_ODBC
done: done:
#endif
if (xml) { if (xml) {
switch_xml_free(xml); switch_xml_free(xml);
} }
@ -314,9 +298,12 @@ static void transfer_call(switch_core_session_t *session, char *destination)
/* At this time, billing never succeeds if you don't have a database. */ /* At this time, billing never succeeds if you don't have a database. */
static switch_status_t bill_event(float billamount, const char *billaccount) static switch_status_t bill_event(float billamount, const char *billaccount)
{ {
#ifdef SWITCH_HAVE_ODBC
char sql[1024] = ""; char sql[1024] = "";
SQLHSTMT stmt; switch_odbc_statement_handle_t stmt;
if (!switch_odbc_available()) {
return SWITCH_STATUS_SUCCESS;
}
switch_snprintf(sql, 1024, SQL_SAVE, globals.db_table, globals.db_column_cash, globals.db_column_cash, billamount, globals.db_column_account, billaccount); switch_snprintf(sql, 1024, SQL_SAVE, globals.db_table, globals.db_column_cash, globals.db_column_cash, billamount, globals.db_column_account, billaccount);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doing update query\n[%s]\n", sql); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doing update query\n[%s]\n", sql);
@ -327,36 +314,35 @@ static switch_status_t bill_event(float billamount, const char *billaccount)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
switch_safe_free(err_str); switch_safe_free(err_str);
} else { } else {
#endif
/* TODO: Failover to a flat/text file if DB is unavailable */ /* TODO: Failover to a flat/text file if DB is unavailable */
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
#ifdef SWITCH_HAVE_ODBC
} }
SQLFreeHandle(SQL_HANDLE_STMT, stmt); switch_odbc_statement_handle_free(&stmt);
#endif
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static float get_balance(const char *billaccount) static float get_balance(const char *billaccount)
{ {
#ifdef SWITCH_HAVE_ODBC
char sql[1024] = ""; char sql[1024] = "";
nibblebill_results_t pdata; nibblebill_results_t pdata;
float balance = 0.00f; float balance = 0.00f;
if (!switch_odbc_available()) {
return -1.00f;
}
memset(&pdata, 0, sizeof(pdata)); memset(&pdata, 0, sizeof(pdata));
snprintf(sql, 1024, SQL_LOOKUP, globals.db_column_cash, globals.db_table, globals.db_column_account, billaccount); snprintf(sql, 1024, SQL_LOOKUP, globals.db_column_cash, globals.db_table, globals.db_column_account, billaccount);
if (switch_odbc_handle_callback_exec(globals.master_odbc, sql, nibblebill_callback, &pdata) != SWITCH_ODBC_SUCCESS) { if (switch_odbc_handle_callback_exec(globals.master_odbc, sql, nibblebill_callback, &pdata) != SWITCH_ODBC_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error running this query: [%s]\n", sql); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error running this query: [%s]\n", sql);
#endif
/* Return -1 for safety */ /* Return -1 for safety */
return -1.00; return -1.00f;
#ifdef SWITCH_HAVE_ODBC
} else { } else {
/* Successfully retrieved! */ /* Successfully retrieved! */
balance = pdata.balance; balance = pdata.balance;
@ -365,7 +351,6 @@ static float get_balance(const char *billaccount)
} }
return balance; return balance;
#endif
} }
/* This is where we actually charge the guy /* This is where we actually charge the guy
@ -879,10 +864,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_nibblebill_shutdown)
{ {
switch_event_unbind(&globals.node); switch_event_unbind(&globals.node);
switch_core_remove_state_handler(&nibble_state_handler); switch_core_remove_state_handler(&nibble_state_handler);
#ifdef SWITCH_HAVE_ODBC
switch_odbc_handle_disconnect(globals.master_odbc); switch_odbc_handle_disconnect(globals.master_odbc);
#endif
return SWITCH_STATUS_UNLOAD; return SWITCH_STATUS_UNLOAD;
} }

View File

@ -1,3 +0,0 @@
BASE=../../../..
include $(BASE)/build/modmake.rules
LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`

View File

@ -33,10 +33,6 @@
*/ */
#include <switch.h> #include <switch.h>
#ifdef SWITCH_HAVE_ODBC
#include <switch_odbc.h>
#endif
#ifdef _MSC_VER /* compilers are stupid sometimes */ #ifdef _MSC_VER /* compilers are stupid sometimes */
#define TRY_CODE(code) for(;;) {status = code; if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} #define TRY_CODE(code) for(;;) {status = code; if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;}
#else #else
@ -156,9 +152,8 @@ static switch_status_t vm_execute_sql(vm_profile_t *profile, char *sql, switch_m
switch_mutex_lock(mutex); switch_mutex_lock(mutex);
} }
if (profile->odbc_dsn) { if (switch_odbc_available() && profile->odbc_dsn) {
#ifdef SWITCH_HAVE_ODBC switch_odbc_statement_handle_t stmt;
SQLHSTMT stmt;
if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) { if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
char *err_str; char *err_str;
err_str = switch_odbc_handle_get_error(profile->master_odbc, stmt); err_str = switch_odbc_handle_get_error(profile->master_odbc, stmt);
@ -166,8 +161,7 @@ static switch_status_t vm_execute_sql(vm_profile_t *profile, char *sql, switch_m
switch_safe_free(err_str); switch_safe_free(err_str);
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
} }
SQLFreeHandle(SQL_HANDLE_STMT, stmt); switch_odbc_statement_handle_free(&stmt);
#endif
} else { } else {
if (!(db = switch_core_db_open_file(profile->dbname))) { if (!(db = switch_core_db_open_file(profile->dbname))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
@ -196,10 +190,8 @@ static switch_bool_t vm_execute_sql_callback(vm_profile_t *profile, switch_mutex
switch_mutex_lock(mutex); switch_mutex_lock(mutex);
} }
if (profile->odbc_dsn) { if (switch_odbc_available() && profile->odbc_dsn) {
#ifdef SWITCH_HAVE_ODBC
switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata); switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
#endif
} else { } else {
if (!(db = switch_core_db_open_file(profile->dbname))) { if (!(db = switch_core_db_open_file(profile->dbname))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
@ -266,12 +258,10 @@ static char *vm_index_list[] = {
static void free_profile(vm_profile_t *profile) static void free_profile(vm_profile_t *profile)
{ {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroying Profile %s\n", profile->name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroying Profile %s\n", profile->name);
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available() && profile->odbc_dsn && profile->master_odbc) {
if (profile->odbc_dsn && profile->master_odbc) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Closing ODBC Database! %s\n", profile->name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Closing ODBC Database! %s\n", profile->name);
switch_odbc_handle_destroy(&profile->master_odbc); switch_odbc_handle_destroy(&profile->master_odbc);
} }
#endif
switch_core_destroy_memory_pool(&profile->pool); switch_core_destroy_memory_pool(&profile->pool);
} }
@ -669,8 +659,7 @@ static vm_profile_t * load_profile(const char *profile_name)
} }
profile->dbname = switch_core_sprintf(profile->pool, "voicemail_%s", profile_name); profile->dbname = switch_core_sprintf(profile->pool, "voicemail_%s", profile_name);
if (profile->odbc_dsn) { if (switch_odbc_available() && profile->odbc_dsn) {
#ifdef SWITCH_HAVE_ODBC
if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) { if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
goto end; goto end;
@ -713,7 +702,6 @@ static vm_profile_t * load_profile(const char *profile_name)
for (x = 0; vm_index_list[x]; x++) { for (x = 0; vm_index_list[x]; x++) {
switch_odbc_handle_exec(profile->master_odbc, vm_index_list[x], NULL); switch_odbc_handle_exec(profile->master_odbc, vm_index_list[x], NULL);
} }
#endif
} else { } else {
if ((db = switch_core_db_open_file(profile->dbname))) { if ((db = switch_core_db_open_file(profile->dbname))) {
char *errmsg; char *errmsg;
@ -4006,12 +3994,11 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_voicemail_shutdown)
switch_thread_rwlock_wrlock(profile->rwlock); switch_thread_rwlock_wrlock(profile->rwlock);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroying Profile %s\n", profile->name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroying Profile %s\n", profile->name);
#ifdef SWITCH_HAVE_ODBC
if (profile->odbc_dsn && profile->master_odbc) { if (switch_odbc_available() && profile->odbc_dsn && profile->master_odbc) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Closing ODBC Database! %s\n", profile->name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Closing ODBC Database! %s\n", profile->name);
switch_odbc_handle_destroy(&profile->master_odbc); switch_odbc_handle_destroy(&profile->master_odbc);
} }
#endif
switch_core_destroy_memory_pool(&profile->pool); switch_core_destroy_memory_pool(&profile->pool);
profile = NULL; profile = NULL;
} }

View File

@ -2,7 +2,6 @@ BASE=../../../..
LOCAL_CFLAGS = `$(BASE)/libs/apr/apr-1-config --cflags --cppflags --includes` LOCAL_CFLAGS = `$(BASE)/libs/apr/apr-1-config --cflags --cppflags --includes`
LOCAL_CFLAGS += `$(BASE)/libs/apr-util/apu-1-config --includes` LOCAL_CFLAGS += `$(BASE)/libs/apr-util/apu-1-config --includes`
LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`
#LOCAL_CFLAGS += -w #LOCAL_CFLAGS += -w
IKS_DIR=$(BASE)/libs/iksemel IKS_DIR=$(BASE)/libs/iksemel

View File

@ -32,9 +32,6 @@
#include <switch.h> #include <switch.h>
#include <switch_stun.h> #include <switch_stun.h>
#include <libdingaling.h> #include <libdingaling.h>
#ifdef SWITCH_HAVE_ODBC
#include <switch_odbc.h>
#endif
#define DL_CAND_WAIT 10000000 #define DL_CAND_WAIT 10000000
#define DL_CAND_INITIAL_WAIT 2000000 #define DL_CAND_INITIAL_WAIT 2000000
@ -128,17 +125,10 @@ struct mdl_profile {
char *timer_name; char *timer_name;
char *dbname; char *dbname;
char *avatar; char *avatar;
#ifdef SWITCH_HAVE_ODBC
char *odbc_dsn; char *odbc_dsn;
char *odbc_user; char *odbc_user;
char *odbc_pass; char *odbc_pass;
switch_odbc_handle_t *master_odbc; switch_odbc_handle_t *master_odbc;
#else
void *filler1;
void *filler2;
void *filler3;
void *filler4;
#endif
switch_mutex_t *mutex; switch_mutex_t *mutex;
ldl_handle_t *handle; ldl_handle_t *handle;
uint32_t flags; uint32_t flags;
@ -273,30 +263,24 @@ static void mdl_execute_sql(mdl_profile_t *profile, char *sql, switch_mutex_t *m
if (mutex) { if (mutex) {
switch_mutex_lock(mutex); switch_mutex_lock(mutex);
} }
#ifdef SWITCH_HAVE_ODBC
if (profile->odbc_dsn) { if (switch_odbc_available() && profile->odbc_dsn) {
SQLHSTMT stmt; switch_odbc_statement_handle_t stmt;
if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) { if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
char *err_str; char *err_str;
err_str = switch_odbc_handle_get_error(profile->master_odbc, stmt); err_str = switch_odbc_handle_get_error(profile->master_odbc, stmt);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
switch_safe_free(err_str); switch_safe_free(err_str);
} }
SQLFreeHandle(SQL_HANDLE_STMT, stmt); switch_odbc_statement_handle_free(&stmt);
} else { } else {
#endif
if (!(db = switch_core_db_open_file(profile->dbname))) { if (!(db = switch_core_db_open_file(profile->dbname))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
goto end; goto end;
} }
switch_core_db_persistant_execute(db, sql, 1); switch_core_db_persistant_execute(db, sql, 1);
switch_core_db_close(db); switch_core_db_close(db);
#ifdef SWITCH_HAVE_ODBC
} }
#endif
end: end:
if (mutex) { if (mutex) {
@ -316,20 +300,13 @@ static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
switch_mutex_lock(mutex); switch_mutex_lock(mutex);
} }
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available() && profile->odbc_dsn) {
if (profile->odbc_dsn) {
switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata); switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
} else { } else {
#endif
if (!(db = switch_core_db_open_file(profile->dbname))) { if (!(db = switch_core_db_open_file(profile->dbname))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
goto end; goto end;
} }
switch_core_db_exec(db, sql, callback, pdata, &errmsg); switch_core_db_exec(db, sql, callback, pdata, &errmsg);
if (errmsg) { if (errmsg) {
@ -340,10 +317,7 @@ static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
if (db) { if (db) {
switch_core_db_close(db); switch_core_db_close(db);
} }
#ifdef SWITCH_HAVE_ODBC
} }
#endif
end: end:
@ -351,10 +325,7 @@ static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
switch_mutex_unlock(mutex); switch_mutex_unlock(mutex);
} }
return ret; return ret;
} }
static int sub_callback(void *pArg, int argc, char **argv, char **columnNames) static int sub_callback(void *pArg, int argc, char **argv, char **columnNames)
@ -1949,18 +1920,17 @@ static void set_profile_val(mdl_profile_t *profile, char *var, char *val)
} else if (!strcasecmp(var, "avatar")) { } else if (!strcasecmp(var, "avatar")) {
profile->avatar = switch_core_strdup(module_pool, val); profile->avatar = switch_core_strdup(module_pool, val);
} else if (!strcasecmp(var, "odbc-dsn") && !switch_strlen_zero(val)) { } else if (!strcasecmp(var, "odbc-dsn") && !switch_strlen_zero(val)) {
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available()) {
profile->odbc_dsn = switch_core_strdup(module_pool, val); profile->odbc_dsn = switch_core_strdup(module_pool, val);
if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) { if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) {
*profile->odbc_user++ = '\0'; *profile->odbc_user++ = '\0';
if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) { if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) {
*profile->odbc_pass++ = '\0'; *profile->odbc_pass++ = '\0';
}
} }
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
} }
#else
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
#endif
} else if (!strcasecmp(var, "use-rtp-timer") && switch_true(val)) { } else if (!strcasecmp(var, "use-rtp-timer") && switch_true(val)) {
switch_set_flag(profile, TFLAG_TIMER); switch_set_flag(profile, TFLAG_TIMER);
} else if (!strcasecmp(var, "dialplan") && !switch_strlen_zero(val)) { } else if (!strcasecmp(var, "dialplan") && !switch_strlen_zero(val)) {
@ -2282,9 +2252,7 @@ static switch_status_t load_config(void)
switch_snprintf(dbname, sizeof(dbname), "dingaling_%s", profile->name); switch_snprintf(dbname, sizeof(dbname), "dingaling_%s", profile->name);
profile->dbname = switch_core_strdup(module_pool, dbname); profile->dbname = switch_core_strdup(module_pool, dbname);
if (switch_odbc_available() && profile->odbc_dsn) {
#ifdef SWITCH_HAVE_ODBC
if (profile->odbc_dsn) {
if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) { if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
continue; continue;
@ -2299,7 +2267,6 @@ static switch_status_t load_config(void)
switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL); switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL);
//mdl_execute_sql(profile, sub_sql, NULL); //mdl_execute_sql(profile, sub_sql, NULL);
} else { } else {
#endif
if ((db = switch_core_db_open_file(profile->dbname))) { if ((db = switch_core_db_open_file(profile->dbname))) {
switch_core_db_test_reactive(db, "select * from jabber_subscriptions", NULL, sub_sql); switch_core_db_test_reactive(db, "select * from jabber_subscriptions", NULL, sub_sql);
} else { } else {
@ -2307,9 +2274,7 @@ static switch_status_t load_config(void)
continue; continue;
} }
switch_core_db_close(db); switch_core_db_close(db);
#ifdef SWITCH_HAVE_ODBC
} }
#endif
} }
if (profile) { if (profile) {

View File

@ -42,9 +42,6 @@
#define HAVE_APR #define HAVE_APR
#include <switch.h> #include <switch.h>
#include <switch_version.h> #include <switch_version.h>
#ifdef SWITCH_HAVE_ODBC
#include <switch_odbc.h>
#endif
#define SOFIA_NAT_SESSION_TIMEOUT 20 #define SOFIA_NAT_SESSION_TIMEOUT 20
#define SOFIA_MAX_ACL 100 #define SOFIA_MAX_ACL 100
#ifdef _MSC_VER #ifdef _MSC_VER

View File

@ -2068,17 +2068,17 @@ switch_status_t config_sofia(int reload, char *profile_name)
} else if (!strcasecmp(var, "sip-trace") && switch_true(val)) { } else if (!strcasecmp(var, "sip-trace") && switch_true(val)) {
sofia_set_flag(profile, TFLAG_TPORT_LOG); sofia_set_flag(profile, TFLAG_TPORT_LOG);
} else if (!strcasecmp(var, "odbc-dsn") && !switch_strlen_zero(val)) { } else if (!strcasecmp(var, "odbc-dsn") && !switch_strlen_zero(val)) {
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available()) {
profile->odbc_dsn = switch_core_strdup(profile->pool, val); profile->odbc_dsn = switch_core_strdup(profile->pool, val);
if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) { if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) {
*profile->odbc_user++ = '\0'; *profile->odbc_user++ = '\0';
if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) { if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) {
*profile->odbc_pass++ = '\0'; *profile->odbc_pass++ = '\0';
}
} }
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
} }
#else
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
#endif
} else if (!strcasecmp(var, "user-agent-string")) { } else if (!strcasecmp(var, "user-agent-string")) {
profile->user_agent = switch_core_strdup(profile->pool, val); profile->user_agent = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "auto-restart")) { } else if (!strcasecmp(var, "auto-restart")) {

View File

@ -3616,8 +3616,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
" expires INTEGER\n" " expires INTEGER\n"
");\n"; ");\n";
if (profile->odbc_dsn) { if (switch_odbc_available() && profile->odbc_dsn) {
#ifdef SWITCH_HAVE_ODBC
int x; int x;
char *indexes[] = { char *indexes[] = {
"create index sr_call_id on sip_registrations (call_id)", "create index sr_call_id on sip_registrations (call_id)",
@ -3735,9 +3734,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
} }
#else } else if (profile->odbc_dsn) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
#endif
} else { } else {
if (!(profile->master_db = switch_core_db_open_file(profile->dbname))) { if (!(profile->master_db = switch_core_db_open_file(profile->dbname))) {
return 0; return 0;
@ -3835,28 +3833,23 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
switch_core_db_exec(profile->master_db, "create index if not exists sa_hostname on sip_authentication (hostname)", NULL, NULL, NULL); switch_core_db_exec(profile->master_db, "create index if not exists sa_hostname on sip_authentication (hostname)", NULL, NULL, NULL);
} }
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available() && profile->odbc_dsn) {
if (profile->odbc_dsn) {
return profile->master_odbc ? 1 : 0; return profile->master_odbc ? 1 : 0;
} }
#endif
return profile->master_db ? 1 : 0; return profile->master_db ? 1 : 0;
} }
void sofia_glue_sql_close(sofia_profile_t *profile) void sofia_glue_sql_close(sofia_profile_t *profile)
{ {
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available() && profile->master_odbc) {
if (profile->master_odbc) {
switch_odbc_handle_destroy(&profile->master_odbc); switch_odbc_handle_destroy(&profile->master_odbc);
} else {
switch_core_db_close(profile->master_db);
profile->master_db = NULL;
} }
#else
switch_core_db_close(profile->master_db);
profile->master_db = NULL;
#endif
} }
void sofia_glue_execute_sql(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic) void sofia_glue_execute_sql(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic)
{ {
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
@ -3899,9 +3892,8 @@ void sofia_glue_actually_execute_sql(sofia_profile_t *profile, switch_bool_t mas
switch_mutex_lock(mutex); switch_mutex_lock(mutex);
} }
if (profile->odbc_dsn) { if (switch_odbc_available() && profile->odbc_dsn) {
#ifdef SWITCH_HAVE_ODBC switch_odbc_statement_handle_t stmt;
SQLHSTMT stmt;
if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) { if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
char *err_str; char *err_str;
err_str = switch_odbc_handle_get_error(profile->master_odbc, stmt); err_str = switch_odbc_handle_get_error(profile->master_odbc, stmt);
@ -3910,10 +3902,9 @@ void sofia_glue_actually_execute_sql(sofia_profile_t *profile, switch_bool_t mas
} }
switch_safe_free(err_str); switch_safe_free(err_str);
} }
SQLFreeHandle(SQL_HANDLE_STMT, stmt); switch_odbc_statement_handle_free(&stmt);
#else } else if (profile->odbc_dsn) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
#endif
} else { } else {
if (master) { if (master) {
db = profile->master_db; db = profile->master_db;
@ -3948,12 +3939,10 @@ switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
} }
if (profile->odbc_dsn) { if (switch_odbc_available() && profile->odbc_dsn) {
#ifdef SWITCH_HAVE_ODBC
switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata); switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
#else } else if (profile->odbc_dsn) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
#endif
} else { } else {
if (master) { if (master) {
@ -3984,36 +3973,17 @@ switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
return ret; return ret;
} }
#ifdef SWITCH_HAVE_ODBC
static char *sofia_glue_execute_sql2str_odbc(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len) static char *sofia_glue_execute_sql2str_odbc(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len)
{ {
char *ret = NULL; char *ret = NULL;
SQLHSTMT stmt;
SQLCHAR name[1024];
SQLLEN m = 0;
if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) == SWITCH_ODBC_SUCCESS) { if (switch_odbc_handle_exec_string(profile->master_odbc, sql, resbuf, len) == SWITCH_ODBC_SUCCESS) {
SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
SQLULEN ColumnSize;
SQLRowCount(stmt, &m);
if (m <= 0) {
return NULL;
}
if (SQLFetch(stmt) != SQL_SUCCESS) {
return NULL;
}
SQLDescribeCol(stmt, 1, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
SQLGetData(stmt, 1, SQL_C_CHAR, (SQLCHAR *) resbuf, (SQLLEN) len, NULL);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
ret = resbuf; ret = resbuf;
} }
return ret; return ret;
} }
#endif
char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len) char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len)
{ {
@ -4021,11 +3991,9 @@ char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex
switch_core_db_stmt_t *stmt; switch_core_db_stmt_t *stmt;
char *ret = NULL; char *ret = NULL;
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available() && profile->odbc_dsn) {
if (profile->odbc_dsn) {
return sofia_glue_execute_sql2str_odbc(profile, mutex, sql, resbuf, len); return sofia_glue_execute_sql2str_odbc(profile, mutex, sql, resbuf, len);
} }
#endif
if (mutex) { if (mutex) {
switch_mutex_lock(mutex); switch_mutex_lock(mutex);

View File

@ -581,22 +581,17 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot)
{ {
char sql[1024]; char sql[1024];
#ifdef SWITCH_HAVE_ODBC if (switch_odbc_available() && profile->odbc_dsn) {
if (profile->odbc_dsn) {
if (!profile->master_odbc) { if (!profile->master_odbc) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
return; return;
} }
} else { } else {
#endif
if (!profile->master_db) { if (!profile->master_db) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
return; return;
} }
#ifdef SWITCH_HAVE_ODBC
} }
#endif
switch_mutex_lock(profile->ireg_mutex); switch_mutex_lock(profile->ireg_mutex);

View File

@ -30,7 +30,17 @@
* *
*/ */
#include "mod_spidermonkey.h" #include "mod_spidermonkey.h"
#include <switch_odbc.h>
#include <sql.h>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4201)
#include <sqlext.h>
#pragma warning(pop)
#else
#include <sqlext.h>
#endif
#include <sqltypes.h>
static const char modname[] = "ODBC"; static const char modname[] = "ODBC";

View File

@ -30,7 +30,18 @@
*/ */
#include <switch.h> #include <switch.h>
#include <switch_odbc.h>
#ifdef SWITCH_HAVE_ODBC
#include <sql.h>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4201)
#include <sqlext.h>
#pragma warning(pop)
#else
#include <sqlext.h>
#endif
#include <sqltypes.h>
#if (ODBCVER < 0x0300) #if (ODBCVER < 0x0300)
#define SQL_NO_DATA SQL_SUCCESS #define SQL_NO_DATA SQL_SUCCESS
@ -46,9 +57,11 @@ struct switch_odbc_handle {
char odbc_driver[256]; char odbc_driver[256];
BOOL is_firebird; BOOL is_firebird;
}; };
#endif
SWITCH_DECLARE(switch_odbc_handle_t *) switch_odbc_handle_new(char *dsn, char *username, char *password) SWITCH_DECLARE(switch_odbc_handle_t *) switch_odbc_handle_new(char *dsn, char *username, char *password)
{ {
#ifdef SWITCH_HAVE_ODBC
switch_odbc_handle_t *new_handle; switch_odbc_handle_t *new_handle;
if (!(new_handle = malloc(sizeof(*new_handle)))) { if (!(new_handle = malloc(sizeof(*new_handle)))) {
@ -86,13 +99,20 @@ SWITCH_DECLARE(switch_odbc_handle_t *) switch_odbc_handle_new(char *dsn, char *u
switch_safe_free(new_handle); switch_safe_free(new_handle);
} }
#endif
return NULL; return NULL;
} }
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_disconnect(switch_odbc_handle_t *handle) SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_disconnect(switch_odbc_handle_t *handle)
{ {
#ifdef SWITCH_HAVE_ODBC
int result; int result;
if (!handle) {
return SWITCH_ODBC_FAIL;
}
if (handle->state == SWITCH_ODBC_STATE_CONNECTED) { if (handle->state == SWITCH_ODBC_STATE_CONNECTED) {
result = SQLDisconnect(handle->con); result = SQLDisconnect(handle->con);
if (result == SWITCH_ODBC_SUCCESS) { if (result == SWITCH_ODBC_SUCCESS) {
@ -105,10 +125,14 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_disconnect(switch_odbc_h
handle->state = SWITCH_ODBC_STATE_DOWN; handle->state = SWITCH_ODBC_STATE_DOWN;
return SWITCH_ODBC_SUCCESS; return SWITCH_ODBC_SUCCESS;
#else
return SWITCH_ODBC_FAIL;
#endif
} }
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_handle_t *handle) SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_handle_t *handle)
{ {
#ifdef SWITCH_HAVE_ODBC
int result; int result;
SQLINTEGER err; SQLINTEGER err;
int16_t mlen; int16_t mlen;
@ -186,10 +210,14 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_hand
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connected to [%s]\n", handle->dsn); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connected to [%s]\n", handle->dsn);
handle->state = SWITCH_ODBC_STATE_CONNECTED; handle->state = SWITCH_ODBC_STATE_CONNECTED;
return SWITCH_ODBC_SUCCESS; return SWITCH_ODBC_SUCCESS;
#else
return SWITCH_ODBC_FAIL;
#endif
} }
static int db_is_up(switch_odbc_handle_t *handle) static int db_is_up(switch_odbc_handle_t *handle)
{ {
#ifdef SWITCH_HAVE_ODBC
int ret = 0; int ret = 0;
SQLHSTMT stmt = NULL; SQLHSTMT stmt = NULL;
SQLLEN m = 0; SQLLEN m = 0;
@ -288,10 +316,68 @@ static int db_is_up(switch_odbc_handle_t *handle)
} }
return ret; return ret;
#else
return SWITCH_ODBC_FAIL;
#endif
} }
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, char *sql, SQLHSTMT * rstmt) SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_statement_handle_free(switch_odbc_statement_handle_t * stmt)
{ {
if (!stmt || ! *stmt) {
return SWITCH_ODBC_FAIL;
}
#ifdef SWITCH_HAVE_ODBC
SQLFreeHandle(SQL_HANDLE_STMT, *stmt);
*stmt = NULL;
return SWITCH_ODBC_SUCCESS;
#else
return SWITCH_ODBC_FAIL;
#endif
}
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec_string(switch_odbc_handle_t *handle,
char *sql,
char *resbuf,
size_t len)
{
#ifdef SWITCH_HAVE_ODBC
switch_odbc_status_t sstatus = SWITCH_ODBC_FAIL;
switch_odbc_statement_handle_t stmt = NULL;
SQLCHAR name[1024];
SQLLEN m = 0;
if (switch_odbc_handle_exec(handle, sql, &stmt) == SWITCH_ODBC_SUCCESS) {
SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
SQLULEN ColumnSize;
SQLRowCount(stmt, &m);
if (m <= 0) {
goto done;
}
if (SQLFetch(stmt) != SQL_SUCCESS) {
goto done;
}
SQLDescribeCol(stmt, 1, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
SQLGetData(stmt, 1, SQL_C_CHAR, (SQLCHAR *) resbuf, (SQLLEN) len, NULL);
sstatus = SWITCH_ODBC_SUCCESS;
} else {
return sstatus;
}
done:
switch_odbc_statement_handle_free(&stmt);
return sstatus;
#else
return SWITCH_ODBC_FAIL;
#endif
}
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, char *sql, switch_odbc_statement_handle_t * rstmt)
{
#ifdef SWITCH_HAVE_ODBC
SQLHSTMT stmt = NULL; SQLHSTMT stmt = NULL;
int result; int result;
@ -327,6 +413,7 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_
} else if (stmt) { } else if (stmt) {
SQLFreeHandle(SQL_HANDLE_STMT, stmt); SQLFreeHandle(SQL_HANDLE_STMT, stmt);
} }
#endif
return SWITCH_ODBC_FAIL; return SWITCH_ODBC_FAIL;
} }
@ -334,6 +421,7 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c
switch_odbc_handle_t *handle, switch_odbc_handle_t *handle,
char *sql, switch_core_db_callback_func_t callback, void *pdata) char *sql, switch_core_db_callback_func_t callback, void *pdata)
{ {
#ifdef SWITCH_HAVE_ODBC
SQLHSTMT stmt = NULL; SQLHSTMT stmt = NULL;
SQLSMALLINT c = 0, x = 0; SQLSMALLINT c = 0, x = 0;
SQLLEN m = 0, t = 0; SQLLEN m = 0, t = 0;
@ -445,11 +533,14 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c
SQLFreeHandle(SQL_HANDLE_STMT, stmt); SQLFreeHandle(SQL_HANDLE_STMT, stmt);
} }
#endif
return SWITCH_ODBC_FAIL; return SWITCH_ODBC_FAIL;
} }
SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep) SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep)
{ {
#ifdef SWITCH_HAVE_ODBC
switch_odbc_handle_t *handle = NULL; switch_odbc_handle_t *handle = NULL;
if (!handlep) { if (!handlep) {
@ -468,15 +559,24 @@ SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep)
free(handle); free(handle);
} }
*handlep = NULL; *handlep = NULL;
#else
return;
#endif
} }
SWITCH_DECLARE(switch_odbc_state_t) switch_odbc_handle_get_state(switch_odbc_handle_t *handle) SWITCH_DECLARE(switch_odbc_state_t) switch_odbc_handle_get_state(switch_odbc_handle_t *handle)
{ {
#ifdef SWITCH_HAVE_ODBC
return handle ? handle->state : SWITCH_ODBC_STATE_INIT; return handle ? handle->state : SWITCH_ODBC_STATE_INIT;
#else
return SWITCH_ODBC_STATE_ERROR;
#endif
} }
SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, SQLHSTMT stmt) SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, switch_odbc_statement_handle_t stmt)
{ {
#ifdef SWITCH_HAVE_ODBC
char buffer[SQL_MAX_MESSAGE_LENGTH + 1] = ""; char buffer[SQL_MAX_MESSAGE_LENGTH + 1] = "";
char sqlstate[SQL_SQLSTATE_SIZE + 1] = ""; char sqlstate[SQL_SQLSTATE_SIZE + 1] = "";
SQLINTEGER sqlcode; SQLINTEGER sqlcode;
@ -488,6 +588,18 @@ SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle
}; };
return ret; return ret;
#else
return NULL;
#endif
}
SWITCH_DECLARE(switch_bool_t) switch_odbc_available(void)
{
#ifdef SWITCH_HAVE_ODBC
return SWITCH_TRUE;
#else
return SWITCH_FALSE;
#endif
} }