From ead7a68276c3e2c4f16484ad24563bba1adb3e0c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 17 Oct 2011 09:34:50 -0500 Subject: [PATCH] add to require connection to core db over odbc for startup --- src/include/switch_types.h | 3 ++- src/switch_core.c | 5 ++++- src/switch_core_sqldb.c | 22 ++++++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index a4f3c11884..d37daa268a 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -309,7 +309,8 @@ typedef enum { SCF_USE_NAT_MAPPING = (1 << 15), SCF_CLEAR_SQL = (1 << 16), SCF_THREADED_SYSTEM_EXEC = (1 << 17), - SCF_SYNC_CLOCK_REQUESTED = (1 << 18) + SCF_SYNC_CLOCK_REQUESTED = (1 << 18), + SCF_CORE_ODBC_REQ = (1 << 19) } switch_core_flag_enum_t; typedef uint32_t switch_core_flag_t; diff --git a/src/switch_core.c b/src/switch_core.c index 4a82464c35..a519da512e 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1493,7 +1493,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc switch_core_state_machine_init(runtime.memory_pool); if (switch_core_sqldb_start(runtime.memory_pool, switch_test_flag((&runtime), SCF_USE_SQL) ? SWITCH_TRUE : SWITCH_FALSE) != SWITCH_STATUS_SUCCESS) { - abort(); + *err = "Error activating database"; + return SWITCH_STATUS_FALSE; } switch_scheduler_task_thread_start(); @@ -1783,6 +1784,8 @@ static void switch_load_core_config(const char *file) } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n"); } + } else if (!strcasecmp(var, "core-odbc-required") && !zstr(val)) { + switch_set_flag((&runtime), SCF_CORE_ODBC_REQ); } else if (!strcasecmp(var, "core-dbtype") && !zstr(val)) { if (!strcasecmp(val, "MSSQL")) { runtime.odbc_dbtype = DBTYPE_MSSQL; diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 90112aeb4e..e55e08f741 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -188,19 +188,24 @@ SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t return SWITCH_STATUS_FALSE; } - if (!zstr(runtime.odbc_dsn)) { - options.odbc_options.dsn = runtime.odbc_dsn; - options.odbc_options.user = runtime.odbc_user; - options.odbc_options.pass = runtime.odbc_pass; + if (zstr(runtime.odbc_dsn)) { + if (switch_test_flag((&runtime), SCF_CORE_ODBC_REQ)) { + return SWITCH_STATUS_FALSE; + } - r = _switch_cache_db_get_db_handle(dbh, SCDB_TYPE_ODBC, &options, file, func, line); - } else { if (runtime.dbname) { options.core_db_options.db_path = runtime.dbname; } else { options.core_db_options.db_path = SWITCH_CORE_DB; } r = _switch_cache_db_get_db_handle(dbh, SCDB_TYPE_CORE_DB, &options, file, func, line); + + } else { + options.odbc_options.dsn = runtime.odbc_dsn; + options.odbc_options.user = runtime.odbc_user; + options.odbc_options.pass = runtime.odbc_pass; + + r = _switch_cache_db_get_db_handle(dbh, SCDB_TYPE_ODBC, &options, file, func, line); } /* I *think* we can do without this now, if not let me know @@ -1880,6 +1885,11 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_ if (switch_core_db_handle(&dbh) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n"); + if (switch_test_flag((&runtime), SCF_CORE_ODBC_REQ)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure! ODBC IS REQUIRED!\n"); + return SWITCH_STATUS_FALSE; + } + if (runtime.odbc_dsn) { runtime.odbc_dsn = NULL; runtime.odbc_user = NULL;