mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-29 22:54:18 +00:00
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:
1 parent
f7d99cf948
commit
6348359d95
25 files changed
+262
-379
No files matched your search
@@ -2,7 +2,6 @@ BASE=../../../..
|
||||
|
||||
LOCAL_CFLAGS = `$(BASE)/libs/apr/apr-1-config --cflags --cppflags --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
|
||||
|
||||
IKS_DIR=$(BASE)/libs/iksemel
|
||||
|
||||
@@ -32,9 +32,6 @@
|
||||
#include <switch.h>
|
||||
#include <switch_stun.h>
|
||||
#include <libdingaling.h>
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
#include <switch_odbc.h>
|
||||
#endif
|
||||
|
||||
#define DL_CAND_WAIT 10000000
|
||||
#define DL_CAND_INITIAL_WAIT 2000000
|
||||
@@ -128,17 +125,10 @@ struct mdl_profile {
|
||||
char *timer_name;
|
||||
char *dbname;
|
||||
char *avatar;
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
char *odbc_dsn;
|
||||
char *odbc_user;
|
||||
char *odbc_pass;
|
||||
switch_odbc_handle_t *master_odbc;
|
||||
#else
|
||||
void *filler1;
|
||||
void *filler2;
|
||||
void *filler3;
|
||||
void *filler4;
|
||||
#endif
|
||||
switch_mutex_t *mutex;
|
||||
ldl_handle_t *handle;
|
||||
uint32_t flags;
|
||||
@@ -273,30 +263,24 @@ static void mdl_execute_sql(mdl_profile_t *profile, char *sql, switch_mutex_t *m
|
||||
if (mutex) {
|
||||
switch_mutex_lock(mutex);
|
||||
}
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
if (profile->odbc_dsn) {
|
||||
SQLHSTMT stmt;
|
||||
|
||||
if (switch_odbc_available() && profile->odbc_dsn) {
|
||||
switch_odbc_statement_handle_t stmt;
|
||||
if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
|
||||
char *err_str;
|
||||
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_safe_free(err_str);
|
||||
}
|
||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||
switch_odbc_statement_handle_free(&stmt);
|
||||
} else {
|
||||
#endif
|
||||
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);
|
||||
goto end;
|
||||
}
|
||||
|
||||
switch_core_db_persistant_execute(db, sql, 1);
|
||||
switch_core_db_close(db);
|
||||
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
end:
|
||||
if (mutex) {
|
||||
@@ -316,20 +300,13 @@ static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
|
||||
switch_mutex_lock(mutex);
|
||||
}
|
||||
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
if (profile->odbc_dsn) {
|
||||
if (switch_odbc_available() && profile->odbc_dsn) {
|
||||
switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
|
||||
} else {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
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);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
switch_core_db_exec(db, sql, callback, pdata, &errmsg);
|
||||
|
||||
if (errmsg) {
|
||||
@@ -340,10 +317,7 @@ static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
|
||||
if (db) {
|
||||
switch_core_db_close(db);
|
||||
}
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
end:
|
||||
|
||||
@@ -351,10 +325,7 @@ static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
|
||||
switch_mutex_unlock(mutex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
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")) {
|
||||
profile->avatar = switch_core_strdup(module_pool, val);
|
||||
} else if (!strcasecmp(var, "odbc-dsn") && !switch_strlen_zero(val)) {
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
profile->odbc_dsn = switch_core_strdup(module_pool, val);
|
||||
if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) {
|
||||
*profile->odbc_user++ = '\0';
|
||||
if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) {
|
||||
*profile->odbc_pass++ = '\0';
|
||||
if (switch_odbc_available()) {
|
||||
profile->odbc_dsn = switch_core_strdup(module_pool, val);
|
||||
if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) {
|
||||
*profile->odbc_user++ = '\0';
|
||||
if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) {
|
||||
*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)) {
|
||||
switch_set_flag(profile, TFLAG_TIMER);
|
||||
} 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);
|
||||
profile->dbname = switch_core_strdup(module_pool, dbname);
|
||||
|
||||
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
if (profile->odbc_dsn) {
|
||||
if (switch_odbc_available() && profile->odbc_dsn) {
|
||||
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");
|
||||
continue;
|
||||
@@ -2299,7 +2267,6 @@ static switch_status_t load_config(void)
|
||||
switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL);
|
||||
//mdl_execute_sql(profile, sub_sql, NULL);
|
||||
} else {
|
||||
#endif
|
||||
if ((db = switch_core_db_open_file(profile->dbname))) {
|
||||
switch_core_db_test_reactive(db, "select * from jabber_subscriptions", NULL, sub_sql);
|
||||
} else {
|
||||
@@ -2307,9 +2274,7 @@ static switch_status_t load_config(void)
|
||||
continue;
|
||||
}
|
||||
switch_core_db_close(db);
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (profile) {
|
||||
|
||||
@@ -42,9 +42,6 @@
|
||||
#define HAVE_APR
|
||||
#include <switch.h>
|
||||
#include <switch_version.h>
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
#include <switch_odbc.h>
|
||||
#endif
|
||||
#define SOFIA_NAT_SESSION_TIMEOUT 20
|
||||
#define SOFIA_MAX_ACL 100
|
||||
#ifdef _MSC_VER
|
||||
|
||||
@@ -2068,17 +2068,17 @@ switch_status_t config_sofia(int reload, char *profile_name)
|
||||
} else if (!strcasecmp(var, "sip-trace") && switch_true(val)) {
|
||||
sofia_set_flag(profile, TFLAG_TPORT_LOG);
|
||||
} else if (!strcasecmp(var, "odbc-dsn") && !switch_strlen_zero(val)) {
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
profile->odbc_dsn = switch_core_strdup(profile->pool, val);
|
||||
if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) {
|
||||
*profile->odbc_user++ = '\0';
|
||||
if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) {
|
||||
*profile->odbc_pass++ = '\0';
|
||||
if (switch_odbc_available()) {
|
||||
profile->odbc_dsn = switch_core_strdup(profile->pool, val);
|
||||
if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) {
|
||||
*profile->odbc_user++ = '\0';
|
||||
if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) {
|
||||
*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")) {
|
||||
profile->user_agent = switch_core_strdup(profile->pool, val);
|
||||
} else if (!strcasecmp(var, "auto-restart")) {
|
||||
|
||||
@@ -3616,8 +3616,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
|
||||
" expires INTEGER\n"
|
||||
");\n";
|
||||
|
||||
if (profile->odbc_dsn) {
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
if (switch_odbc_available() && profile->odbc_dsn) {
|
||||
int x;
|
||||
char *indexes[] = {
|
||||
"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");
|
||||
#endif
|
||||
} else {
|
||||
if (!(profile->master_db = switch_core_db_open_file(profile->dbname))) {
|
||||
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);
|
||||
}
|
||||
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
if (profile->odbc_dsn) {
|
||||
if (switch_odbc_available() && profile->odbc_dsn) {
|
||||
return profile->master_odbc ? 1 : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return profile->master_db ? 1 : 0;
|
||||
}
|
||||
|
||||
void sofia_glue_sql_close(sofia_profile_t *profile)
|
||||
{
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
if (profile->master_odbc) {
|
||||
if (switch_odbc_available() && 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if (profile->odbc_dsn) {
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
SQLHSTMT stmt;
|
||||
if (switch_odbc_available() && profile->odbc_dsn) {
|
||||
switch_odbc_statement_handle_t stmt;
|
||||
if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
|
||||
char *err_str;
|
||||
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);
|
||||
}
|
||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||
#else
|
||||
switch_odbc_statement_handle_free(&stmt);
|
||||
} else if (profile->odbc_dsn) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
|
||||
#endif
|
||||
} else {
|
||||
if (master) {
|
||||
db = profile->master_db;
|
||||
@@ -3948,12 +3939,10 @@ switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
|
||||
}
|
||||
|
||||
|
||||
if (profile->odbc_dsn) {
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
if (switch_odbc_available() && profile->odbc_dsn) {
|
||||
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");
|
||||
#endif
|
||||
} else {
|
||||
|
||||
if (master) {
|
||||
@@ -3984,36 +3973,17 @@ switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
|
||||
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)
|
||||
{
|
||||
char *ret = NULL;
|
||||
SQLHSTMT stmt;
|
||||
SQLCHAR name[1024];
|
||||
SQLLEN m = 0;
|
||||
|
||||
if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) == 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);
|
||||
if (switch_odbc_handle_exec_string(profile->master_odbc, sql, resbuf, len) == SWITCH_ODBC_SUCCESS) {
|
||||
ret = resbuf;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
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;
|
||||
char *ret = NULL;
|
||||
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
if (profile->odbc_dsn) {
|
||||
if (switch_odbc_available() && profile->odbc_dsn) {
|
||||
return sofia_glue_execute_sql2str_odbc(profile, mutex, sql, resbuf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (mutex) {
|
||||
switch_mutex_lock(mutex);
|
||||
|
||||
@@ -581,22 +581,17 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot)
|
||||
{
|
||||
char sql[1024];
|
||||
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
if (profile->odbc_dsn) {
|
||||
if (switch_odbc_available() && profile->odbc_dsn) {
|
||||
if (!profile->master_odbc) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
if (!profile->master_db) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
|
||||
return;
|
||||
}
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
switch_mutex_lock(profile->ireg_mutex);
|
||||
|
||||
|
||||
Reference in new issue
Block a user