RTS API Documentation  1.10.11
Data Structures | Macros | Enumerations | Functions | Variables
switch_core_pvt.h File Reference
#include "switch_profile.h"
#include <switch_private.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
+ Include dependency graph for switch_core_pvt.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  switch_core_session
 
struct  switch_media_bug
 
struct  switch_runtime
 
struct  switch_session_manager
 

Macros

#define DO_EVENTS
 
#define SWITCH_EVENT_QUEUE_LEN   256
 
#define SWITCH_MESSAGE_QUEUE_LEN   256
 
#define SWITCH_BUFFER_BLOCK_FRAMES   25
 
#define SWITCH_BUFFER_START_FRAMES   50
 

Enumerations

enum  switch_session_flag_t {
  SSF_NONE = 0, SSF_DESTROYED = (1 << 0), SSF_WARN_TRANSCODE = (1 << 1), SSF_HANGUP = (1 << 2),
  SSF_THREAD_STARTED = (1 << 3), SSF_THREAD_RUNNING = (1 << 4), SSF_READ_TRANSCODE = (1 << 5), SSF_WRITE_TRANSCODE = (1 << 6),
  SSF_READ_CODEC_RESET = (1 << 7), SSF_WRITE_CODEC_RESET = (1 << 8), SSF_DESTROYABLE = (1 << 9), SSF_MEDIA_BUG_TAP_ONLY = (1 << 10)
}
 
enum  switch_dbtype_t { DBTYPE_DEFAULT = 0, DBTYPE_MSSQL = 1 }
 

Functions

switch_status_t switch_core_sqldb_init (const char **err)
 
void switch_core_sqldb_destroy (void)
 
switch_status_t switch_core_sqldb_start (switch_memory_pool_t *pool, switch_bool_t manage)
 
void switch_core_sqldb_stop (void)
 
void switch_core_session_init (switch_memory_pool_t *pool)
 
void switch_core_session_uninit (void)
 
void switch_core_state_machine_init (switch_memory_pool_t *pool)
 
switch_memory_pool_tswitch_core_memory_init (void)
 
void switch_core_memory_stop (void)
 

Variables

struct switch_runtime runtime
 
struct switch_session_manager session_manager
 

Macro Definition Documentation

◆ DO_EVENTS

#define DO_EVENTS

Definition at line 63 of file switch_core_pvt.h.

◆ SWITCH_BUFFER_BLOCK_FRAMES

#define SWITCH_BUFFER_BLOCK_FRAMES   25

◆ SWITCH_BUFFER_START_FRAMES

#define SWITCH_BUFFER_START_FRAMES   50

◆ SWITCH_EVENT_QUEUE_LEN

#define SWITCH_EVENT_QUEUE_LEN   256

Definition at line 65 of file switch_core_pvt.h.

Referenced by switch_core_session_request_uuid().

◆ SWITCH_MESSAGE_QUEUE_LEN

#define SWITCH_MESSAGE_QUEUE_LEN   256

Definition at line 66 of file switch_core_pvt.h.

Referenced by switch_core_session_request_uuid().

Enumeration Type Documentation

◆ switch_dbtype_t

Enumerator
DBTYPE_DEFAULT 
DBTYPE_MSSQL 

Definition at line 219 of file switch_core_pvt.h.

◆ switch_session_flag_t

Enumerator
SSF_NONE 
SSF_DESTROYED 
SSF_WARN_TRANSCODE 
SSF_HANGUP 
SSF_THREAD_STARTED 
SSF_THREAD_RUNNING 
SSF_READ_TRANSCODE 
SSF_WRITE_TRANSCODE 
SSF_READ_CODEC_RESET 
SSF_WRITE_CODEC_RESET 
SSF_DESTROYABLE 
SSF_MEDIA_BUG_TAP_ONLY 

Definition at line 71 of file switch_core_pvt.h.

Function Documentation

◆ switch_core_memory_init()

switch_memory_pool_t* switch_core_memory_init ( void  )

Definition at line 689 of file switch_core_memory.c.

References memory_manager, memset(), pool_thread(), switch_assert, switch_cond_next(), switch_mutex_init(), SWITCH_MUTEX_NESTED, switch_queue_create(), switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), and switch_threadattr_stacksize_set().

Referenced by switch_core_init().

690 {
691 #ifndef INSTANTLY_DESTROY_POOLS
692  switch_threadattr_t *thd_attr;
693 #endif
694 #ifdef PER_POOL_LOCK
695  fspr_allocator_t *my_allocator = NULL;
696  fspr_thread_mutex_t *my_mutex;
697 #endif
698 
699  memset(&memory_manager, 0, sizeof(memory_manager));
700 
701 #ifdef PER_POOL_LOCK
702  if ((fspr_allocator_create(&my_allocator)) != APR_SUCCESS) {
703  abort();
704  }
705 
706  if ((fspr_pool_create_ex(&memory_manager.memory_pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
707  fspr_allocator_destroy(my_allocator);
708  my_allocator = NULL;
709  abort();
710  }
711 
712  if ((fspr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED, memory_manager.memory_pool)) != APR_SUCCESS) {
713  abort();
714  }
715 
716  fspr_allocator_mutex_set(my_allocator, my_mutex);
717  fspr_pool_mutex_set(memory_manager.memory_pool, my_mutex);
718  fspr_allocator_owner_set(my_allocator, memory_manager.memory_pool);
719  fspr_pool_tag(memory_manager.memory_pool, "core_pool");
720 #else
721  fspr_pool_create(&memory_manager.memory_pool, NULL);
722  switch_assert(memory_manager.memory_pool != NULL);
723 #endif
724 
725 #ifdef USE_MEM_LOCK
727 #endif
728 
729 #ifdef INSTANTLY_DESTROY_POOLS
730  {
731  void *foo;
732  foo = (void *) (intptr_t) pool_thread;
733  }
734 #else
735 
736  switch_queue_create(&memory_manager.pool_queue, 50000, memory_manager.memory_pool);
737  switch_queue_create(&memory_manager.pool_recycle_queue, 50000, memory_manager.memory_pool);
738 
739  switch_threadattr_create(&thd_attr, memory_manager.memory_pool);
740 
742  switch_thread_create(&pool_thread_p, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
743 
744  while (!memory_manager.pool_thread_running) {
746  }
747 #endif
748 
749  return memory_manager.memory_pool;
750 }
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:683
static void *SWITCH_THREAD_FUNC pool_thread(switch_thread_t *thread, void *obj)
static struct @3 memory_manager
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:584
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
void switch_cond_next(void)
Definition: switch_time.c:658
static switch_thread_t * pool_thread_p
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:665
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:698
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1233
#define switch_assert(expr)
memset(buf, 0, buflen)

◆ switch_core_memory_stop()

void switch_core_memory_stop ( void  )

Definition at line 671 of file switch_core_memory.c.

References memory_manager, SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(), switch_queue_trypop(), SWITCH_STATUS_SUCCESS, and switch_thread_join().

Referenced by switch_core_destroy().

672 {
673 #ifndef INSTANTLY_DESTROY_POOLS
674  switch_status_t st;
675  void *pop = NULL;
676 
677  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping memory pool queue.\n");
678 
679  memory_manager.pool_thread_running = 0;
681 
682 
683  while (switch_queue_trypop(memory_manager.pool_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
684  fspr_pool_destroy(pop);
685  }
686 #endif
687 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
static struct @3 memory_manager
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1379
static switch_thread_t * pool_thread_p
switch_status_t
Common return values.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.

◆ switch_core_session_init()

void switch_core_session_init ( switch_memory_pool_t pool)

Definition at line 2625 of file switch_core_session.c.

References switch_session_manager::cond, switch_session_manager::memory_pool, memset(), switch_session_manager::mutex, pool, switch_session_manager::session_id, switch_session_manager::session_limit, session_manager, switch_session_manager::session_table, switch_core_hash_init, SWITCH_MUTEX_DEFAULT, switch_mutex_init(), switch_queue_create(), switch_thread_cond_create(), and switch_session_manager::thread_queue.

Referenced by switch_core_init().

2626 {
2627  memset(&session_manager, 0, sizeof(session_manager));
2635 }
#define SWITCH_MUTEX_DEFAULT
Definition: switch_apr.h:317
struct switch_session_manager session_manager
switch_status_t switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool)
Definition: switch_apr.c:373
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1431
switch_queue_t * thread_queue
switch_memory_pool_t * pool
switch_thread_cond_t * cond
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
switch_memory_pool_t * memory_pool
switch_hash_t * session_table
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1233
switch_mutex_t * mutex
memset(buf, 0, buflen)

◆ switch_core_session_uninit()

void switch_core_session_uninit ( void  )

Definition at line 2637 of file switch_core_session.c.

References switch_session_manager::cond, switch_session_manager::mutex, switch_session_manager::running, session_manager, switch_session_manager::session_table, switch_core_hash_destroy(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_term(), switch_thread_cond_timedwait(), and switch_session_manager::thread_queue.

Referenced by switch_core_destroy().

2638 {
2645 }
struct switch_session_manager session_manager
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
switch_queue_t * thread_queue
switch_status_t switch_thread_cond_timedwait(switch_thread_cond_t *cond, switch_mutex_t *mutex, switch_interval_time_t timeout)
Definition: switch_apr.c:383
switch_thread_cond_t * cond
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_hash_t * session_table
switch_status_t switch_queue_term(switch_queue_t *queue)
Definition: switch_apr.c:1274
switch_mutex_t * mutex

◆ switch_core_sqldb_destroy()

void switch_core_sqldb_destroy ( void  )

Definition at line 3013 of file switch_core.c.

References SCF_USE_SQL, switch_core_sqldb_stop(), and switch_test_flag.

Referenced by switch_loadable_module_shutdown().

3014 {
3017  }
3018 }
struct switch_runtime runtime
Definition: switch_core.c:86
void switch_core_sqldb_stop(void)
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693

◆ switch_core_sqldb_init()

switch_status_t switch_core_sqldb_init ( const char **  err)

Definition at line 2428 of file switch_core.c.

References switch_runtime::memory_pool, SCF_USE_SQL, switch_core_check_core_db_dsn(), switch_core_sqldb_start(), SWITCH_FALSE, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_test_flag, and SWITCH_TRUE.

Referenced by switch_loadable_module_init().

2429 {
2431  *err = "NO SUITABLE DATABASE INTERFACE IS AVAILABLE TO SERVE 'core-db-dsn'!\n";
2432  return SWITCH_STATUS_GENERR;
2433  }
2434 
2436  *err = "Error activating database";
2437  return SWITCH_STATUS_GENERR;
2438  }
2439 
2440  return SWITCH_STATUS_SUCCESS;
2441 }
switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_t manage)
struct switch_runtime runtime
Definition: switch_core.c:86
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
switch_memory_pool_t * memory_pool
switch_status_t switch_core_check_core_db_dsn(void)
Returns error if no suitable database interface found to serve core db dsn.

◆ switch_core_sqldb_start()

switch_status_t switch_core_sqldb_start ( switch_memory_pool_t pool,
switch_bool_t  manage 
)

Definition at line 3565 of file switch_core_sqldb.c.

References basic_calls_sql, CDF_NONEXPIRING, switch_database_interface::commit, core_event_handler(), create_alias_sql, create_calls_sql, create_channels_sql, create_complete_sql, create_interfaces_sql, create_nat_sql, create_registrations_sql, create_row_size_limited_channels_sql, create_tasks_sql, DBTYPE_DEFAULT, detailed_calls_sql, manage, switch_runtime::odbc_dbtype, switch_cache_db_handle::pool, recovery_sql, runtime, SCDB_TYPE_CORE_DB, SCDB_TYPE_DATABASE_INTERFACE, SCDB_TYPE_ODBC, SCF_CLEAR_SQL, SCF_CORE_NON_SQLITE_DB_REQ, SCF_USE_SQL, db_job::sql, sql_manager, switch_database_interface::sql_set_auto_commit_attr, switch_cache_db_create_schema(), switch_cache_db_execute_sql(), switch_cache_db_execute_sql_real(), switch_cache_db_release_db_handle(), switch_cache_db_test_reactive(), switch_cache_db_test_reactive_ex(), SWITCH_CHANNEL_LOG, switch_clear_flag, switch_core_db_handle, switch_core_get_hostname(), switch_core_get_switchname(), switch_core_sql_db_thread(), switch_core_sqldb_start_thread(), SWITCH_EVENT_ADD_SCHEDULE, SWITCH_EVENT_ALL, switch_event_bind(), SWITCH_EVENT_CALL_SECURE, SWITCH_EVENT_CALL_UPDATE, SWITCH_EVENT_CHANNEL_ANSWER, SWITCH_EVENT_CHANNEL_BRIDGE, SWITCH_EVENT_CHANNEL_CALLSTATE, SWITCH_EVENT_CHANNEL_CREATE, SWITCH_EVENT_CHANNEL_DESTROY, SWITCH_EVENT_CHANNEL_EXECUTE, SWITCH_EVENT_CHANNEL_HOLD, SWITCH_EVENT_CHANNEL_ORIGINATE, SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA, SWITCH_EVENT_CHANNEL_STATE, SWITCH_EVENT_CHANNEL_UNBRIDGE, SWITCH_EVENT_CHANNEL_UNHOLD, SWITCH_EVENT_CHANNEL_UUID, SWITCH_EVENT_CODEC, SWITCH_EVENT_DEL_SCHEDULE, SWITCH_EVENT_EXE_SCHEDULE, SWITCH_EVENT_LOG, SWITCH_EVENT_MODULE_LOAD, SWITCH_EVENT_MODULE_UNLOAD, SWITCH_EVENT_NAT, SWITCH_EVENT_RE_SCHEDULE, SWITCH_EVENT_SHUTDOWN, SWITCH_EVENT_SUBCLASS_ANY, SWITCH_LOG_CRIT, SWITCH_LOG_ERROR, SWITCH_LOG_INFO, switch_log_printf(), switch_mutex_init(), SWITCH_MUTEX_NESTED, switch_odbc_SQLEndTran(), switch_odbc_SQLSetAutoCommitAttr(), SWITCH_ODBC_SUCCESS, SWITCH_PRI_REALTIME, switch_safe_free, switch_set_flag, switch_snprintfv(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_string_replace(), switch_stristr(), switch_test_flag, switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_priority_set(), switch_threadattr_stacksize_set(), and SWITCH_TRUE.

Referenced by switch_core_sqldb_init().

3566 {
3567  switch_threadattr_t *thd_attr;
3568 
3569  sql_manager.memory_pool = pool;
3570  sql_manager.manage = manage;
3571 
3574 
3575  if (!sql_manager.manage) goto skip;
3576 
3577  top:
3578 
3579  /* Activate SQL database */
3581  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
3582 
3584  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure! ODBC IS REQUIRED!\n");
3585  return SWITCH_STATUS_FALSE;
3586  }
3587 
3588  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CORE DATABASE INITIALIZATION FAILURE! CHECK `core-db-dsn`!\n");
3589 
3591  return SWITCH_STATUS_FALSE;
3592  }
3593 
3594 
3596 
3597  switch (sql_manager.dbh->type) {
3599  case SCDB_TYPE_ODBC:
3601  char sql[512] = "";
3602  char *tables[] = { "channels", "calls", "tasks", NULL };
3603  int i;
3604  const char *hostname = switch_core_get_switchname();
3605 
3606  for (i = 0; tables[i]; i++) {
3607  switch_snprintfv(sql, sizeof(sql), "delete from %q where hostname='%q'", tables[i], hostname);
3608  switch_cache_db_execute_sql(sql_manager.dbh, sql, NULL);
3609  }
3610  }
3611  break;
3612  case SCDB_TYPE_CORE_DB:
3613  {
3614  switch_cache_db_execute_sql(sql_manager.dbh, "drop table channels", NULL);
3615  switch_cache_db_execute_sql(sql_manager.dbh, "drop table calls", NULL);
3616  switch_cache_db_execute_sql(sql_manager.dbh, "drop view detailed_calls", NULL);
3617  switch_cache_db_execute_sql(sql_manager.dbh, "drop view basic_calls", NULL);
3618  switch_cache_db_execute_sql(sql_manager.dbh, "drop table interfaces", NULL);
3619  switch_cache_db_execute_sql(sql_manager.dbh, "drop table tasks", NULL);
3620  switch_cache_db_execute_sql(sql_manager.dbh, "PRAGMA synchronous=OFF;", NULL);
3621  switch_cache_db_execute_sql(sql_manager.dbh, "PRAGMA count_changes=OFF;", NULL);
3622  switch_cache_db_execute_sql(sql_manager.dbh, "PRAGMA default_cache_size=8000", NULL);
3623  switch_cache_db_execute_sql(sql_manager.dbh, "PRAGMA temp_store=MEMORY;", NULL);
3624  switch_cache_db_execute_sql(sql_manager.dbh, "PRAGMA journal_mode=OFF;", NULL);
3625  }
3626  break;
3627  }
3628 
3629  switch_cache_db_test_reactive(sql_manager.dbh, "select hostname from aliases", "DROP TABLE aliases", create_alias_sql);
3630  switch_cache_db_test_reactive(sql_manager.dbh, "select hostname from complete", "DROP TABLE complete", create_complete_sql);
3631  switch_cache_db_test_reactive(sql_manager.dbh, "select hostname from nat", "DROP TABLE nat", create_nat_sql);
3632  switch_cache_db_test_reactive(sql_manager.dbh, "delete from registrations where reg_user=''",
3633  "DROP TABLE registrations", create_registrations_sql);
3634 
3635  switch_cache_db_test_reactive(sql_manager.dbh, "select metadata from registrations", NULL, "ALTER TABLE registrations ADD COLUMN metadata VARCHAR(256)");
3636 
3637 
3638  switch_cache_db_test_reactive(sql_manager.dbh, "select hostname from recovery", "DROP TABLE recovery", recovery_sql);
3639  switch_cache_db_create_schema(sql_manager.dbh, "create index recovery1 on recovery(technology)", NULL);
3640  switch_cache_db_create_schema(sql_manager.dbh, "create index recovery2 on recovery(profile_name)", NULL);
3641  switch_cache_db_create_schema(sql_manager.dbh, "create index recovery3 on recovery(uuid)", NULL);
3642  switch_cache_db_create_schema(sql_manager.dbh, "create index recovery4 on recovery(runtime_uuid)", NULL);
3643 
3644 
3645 
3646 
3647  switch (sql_manager.dbh->type) {
3649  case SCDB_TYPE_ODBC:
3650  {
3651  char *err;
3652  int result = 0;
3653 
3654  switch_cache_db_test_reactive_ex(sql_manager.dbh, "select call_uuid, read_bit_rate, sent_callee_name, initial_cid_name, initial_cid_num, initial_ip_addr, initial_dest, initial_dialplan, initial_context, accountcode from channels", "DROP TABLE channels", create_channels_sql, create_row_size_limited_channels_sql);
3655  switch_cache_db_test_reactive(sql_manager.dbh, "select call_uuid from calls", "DROP TABLE calls", create_calls_sql);
3656  switch_cache_db_test_reactive(sql_manager.dbh, "select * from basic_calls where sent_callee_name=''", "DROP VIEW basic_calls", basic_calls_sql);
3657  switch_cache_db_test_reactive(sql_manager.dbh, "select * from detailed_calls where sent_callee_name=''", "DROP VIEW detailed_calls", detailed_calls_sql);
3659  switch_cache_db_test_reactive(sql_manager.dbh, "delete from registrations where reg_user=''",
3660  "DROP TABLE registrations", create_registrations_sql);
3661  } else {
3662  char *tmp = switch_string_replace(create_registrations_sql, "url TEXT", "url VARCHAR(max)");
3663  switch_cache_db_test_reactive(sql_manager.dbh, "delete from registrations where reg_user=''",
3664  "DROP TABLE registrations", tmp);
3665  free(tmp);
3666  }
3667  switch_cache_db_test_reactive(sql_manager.dbh, "select ikey from interfaces", "DROP TABLE interfaces", create_interfaces_sql);
3668  switch_cache_db_test_reactive(sql_manager.dbh, "select task_id, task_desc, task_group, task_runtime, task_sql_manager, hostname from tasks",
3669  "DROP TABLE tasks", create_tasks_sql);
3670 
3671 
3672  switch(sql_manager.dbh->type) {
3673  case SCDB_TYPE_CORE_DB:
3674  {
3675  switch_cache_db_execute_sql_real(sql_manager.dbh, "BEGIN EXCLUSIVE", &err);
3676  }
3677  break;
3678  case SCDB_TYPE_ODBC:
3679  {
3680  switch_odbc_status_t result;
3681 
3682  if ((result = switch_odbc_SQLSetAutoCommitAttr(sql_manager.dbh->native_handle.odbc_dbh, 0)) != SWITCH_ODBC_SUCCESS) {
3683  char tmp[100];
3684  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
3685  err = strdup(tmp);
3686  }
3687  }
3688  break;
3690  {
3691  switch_database_interface_t *database_interface = sql_manager.dbh->native_handle.database_interface_dbh->connection_options.database_interface;
3692  switch_status_t result;
3693 
3694  if ((result = database_interface->sql_set_auto_commit_attr(sql_manager.dbh->native_handle.database_interface_dbh, 0)) != SWITCH_STATUS_SUCCESS) {
3695  char tmp[100];
3696  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
3697  err = strdup(tmp);
3698  }
3699  }
3700  break;
3701  }
3702 
3703  switch_cache_db_execute_sql(sql_manager.dbh, "delete from channels where hostname=''", &err);
3704  if (!err) {
3705  switch_cache_db_execute_sql(sql_manager.dbh, "delete from channels where hostname=''", &err);
3706 
3707  switch(sql_manager.dbh->type) {
3708  case SCDB_TYPE_CORE_DB:
3709  {
3710  switch_cache_db_execute_sql_real(sql_manager.dbh, "COMMIT", &err);
3711  }
3712  break;
3713  case SCDB_TYPE_ODBC:
3714  {
3715  if (switch_odbc_SQLEndTran(sql_manager.dbh->native_handle.odbc_dbh, 1) != SWITCH_ODBC_SUCCESS ||
3716  switch_odbc_SQLSetAutoCommitAttr(sql_manager.dbh->native_handle.odbc_dbh, 1) != SWITCH_ODBC_SUCCESS) {
3717  char tmp[100];
3718  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to commit transaction.", result);
3719  err = strdup(tmp);
3720  }
3721  }
3722  break;
3724  {
3725  switch_database_interface_t *database_interface = sql_manager.dbh->native_handle.database_interface_dbh->connection_options.database_interface;
3726  switch_status_t result;
3727 
3728  if ((result = database_interface->commit(sql_manager.dbh->native_handle.database_interface_dbh)) != SWITCH_STATUS_SUCCESS) {
3729  char tmp[100];
3730  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to commit transaction", result);
3731  err = strdup(tmp);
3732  }
3733  }
3734  break;
3735  }
3736  }
3737 
3738 
3739  if (err) {
3740  //runtime.odbc_dsn = NULL;
3741  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database Error [%s]\n", err);
3742  //switch_cache_db_release_db_handle(&sql_manager.dbh);
3743  if (switch_stristr("read-only", err)) {
3744  switch_safe_free(err);
3745  } else {
3746  switch_safe_free(err);
3747  goto top;
3748  }
3749  }
3750  }
3751  break;
3752  case SCDB_TYPE_CORE_DB:
3753  {
3760 
3761  if (sql_manager.dbh->native_handle.core_db_dbh->in_memory == SWITCH_TRUE) {
3763  }
3764  }
3765  break;
3766  }
3767 
3769  char sql[512] = "";
3770  char *tables[] = { "complete", "aliases", "nat", NULL };
3771  int i;
3772  const char *hostname = switch_core_get_hostname();
3773 
3774  for (i = 0; tables[i]; i++) {
3775  switch_snprintfv(sql, sizeof(sql), "delete from %q where sticky=0 and hostname='%q'", tables[i], hostname);
3776  switch_cache_db_execute_sql(sql_manager.dbh, sql, NULL);
3777  }
3778 
3779  switch_snprintfv(sql, sizeof(sql), "delete from interfaces where hostname='%q'", hostname);
3780  switch_cache_db_execute_sql(sql_manager.dbh, sql, NULL);
3781  }
3782 
3783  switch_cache_db_create_schema(sql_manager.dbh, "create index alias1 on aliases (alias)", NULL);
3784  switch_cache_db_create_schema(sql_manager.dbh, "create index tasks1 on tasks (hostname,task_id)", NULL);
3785  switch_cache_db_create_schema(sql_manager.dbh, "create index complete1 on complete (a1,hostname)", NULL);
3786  switch_cache_db_create_schema(sql_manager.dbh, "create index complete2 on complete (a2,hostname)", NULL);
3787  switch_cache_db_create_schema(sql_manager.dbh, "create index complete3 on complete (a3,hostname)", NULL);
3788  switch_cache_db_create_schema(sql_manager.dbh, "create index complete4 on complete (a4,hostname)", NULL);
3789  switch_cache_db_create_schema(sql_manager.dbh, "create index complete5 on complete (a5,hostname)", NULL);
3790  switch_cache_db_create_schema(sql_manager.dbh, "create index complete6 on complete (a6,hostname)", NULL);
3791  switch_cache_db_create_schema(sql_manager.dbh, "create index complete7 on complete (a7,hostname)", NULL);
3792  switch_cache_db_create_schema(sql_manager.dbh, "create index complete8 on complete (a8,hostname)", NULL);
3793  switch_cache_db_create_schema(sql_manager.dbh, "create index complete9 on complete (a9,hostname)", NULL);
3794  switch_cache_db_create_schema(sql_manager.dbh, "create index complete10 on complete (a10,hostname)", NULL);
3795  switch_cache_db_create_schema(sql_manager.dbh, "create index complete11 on complete (a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,hostname)", NULL);
3796  switch_cache_db_create_schema(sql_manager.dbh, "create index nat_map_port_proto on nat (port,proto,hostname)", NULL);
3797  switch_cache_db_create_schema(sql_manager.dbh, "create index chidx1 on channels (hostname)", NULL);
3798  switch_cache_db_create_schema(sql_manager.dbh, "create index uuindex on channels (uuid, hostname)", NULL);
3799  switch_cache_db_create_schema(sql_manager.dbh, "create index uuindex2 on channels (call_uuid)", NULL);
3800  switch_cache_db_create_schema(sql_manager.dbh, "create index callsidx1 on calls (hostname)", NULL);
3801  switch_cache_db_create_schema(sql_manager.dbh, "create index eruuindex on calls (caller_uuid, hostname)", NULL);
3802  switch_cache_db_create_schema(sql_manager.dbh, "create index eeuuindex on calls (callee_uuid)", NULL);
3803  switch_cache_db_create_schema(sql_manager.dbh, "create index eeuuindex2 on calls (call_uuid)", NULL);
3804  switch_cache_db_create_schema(sql_manager.dbh, "create index regindex1 on registrations (reg_user,realm,hostname)", NULL);
3805 
3806 
3807  skip:
3808 
3809  if (sql_manager.manage) {
3810  /* Initiate switch_sql_queue_manager */
3811  switch_threadattr_create(&thd_attr, sql_manager.memory_pool);
3815  switch_thread_create(&sql_manager.db_thread, thd_attr, switch_core_sql_db_thread, NULL, sql_manager.memory_pool);
3816 
3817  /* switch_sql_queue_manager initiated, now we can bind to core_event_handler */
3818 #ifdef SWITCH_SQL_BIND_EVERY_EVENT
3820 #else
3846 #endif
3847  }
3848 
3850 
3851  return SWITCH_STATUS_SUCCESS;
3852 }
switch_status_t switch_cache_db_create_schema(switch_cache_db_handle_t *dbh, char *sql, char **err)
Executes the create schema sql.
const char * switch_core_get_switchname(void)
Definition: switch_core.c:361
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
switch_odbc_status_t
Definition: switch_odbc.h:49
#define SWITCH_CHANNEL_LOG
switch_status_t(* commit)(switch_database_interface_handle_t *dih)
static char create_interfaces_sql[]
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:683
switch_status_t(* sql_set_auto_commit_attr)(switch_database_interface_handle_t *dih, switch_bool_t on)
#define SWITCH_EVENT_SUBCLASS_ANY
Definition: switch_event.h:128
switch_memory_pool_t * pool
static char create_tasks_sql[]
struct switch_runtime runtime
Definition: switch_core.c:86
static void switch_core_sqldb_start_thread(void)
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:724
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
static char recovery_sql[]
switch_status_t switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data)
Bind an event callback to a specific event.
switch_dbtype_t odbc_dbtype
static char create_channels_sql[]
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:584
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
static char create_nat_sql[]
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
switch_bool_t manage
char * switch_snprintfv(char *zBuf, int n, const char *zFormat,...)
static char create_calls_sql[]
static char detailed_calls_sql[]
#define switch_core_db_handle(_a)
Definition: switch_core.h:2729
void switch_cache_db_release_db_handle(switch_cache_db_handle_t **dbh)
Returns the handle to the pool, handle is NOT available to other threads until the allocating thread ...
switch_status_t
Common return values.
static char basic_calls_sql[]
char * switch_string_replace(const char *string, const char *search, const char *replace)
static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t *dbh, const char *sql, char **err)
static void *SWITCH_THREAD_FUNC switch_core_sql_db_thread(switch_thread_t *thread, void *obj)
const char * switch_core_get_hostname(void)
Definition: switch_core.c:356
static struct @4 sql_manager
switch_odbc_status_t switch_odbc_SQLEndTran(switch_odbc_handle_t *handle, switch_bool_t commit)
Definition: switch_odbc.c:835
switch_bool_t switch_cache_db_test_reactive(switch_cache_db_handle_t *dbh, const char *test_sql, const char *drop_sql, const char *reactive_sql)
Performs test_sql and if it fails performs drop_sql and reactive_sql.
static char create_registrations_sql[]
switch_bool_t switch_cache_db_test_reactive_ex(switch_cache_db_handle_t *dbh, const char *test_sql, const char *drop_sql, const char *reactive_sql, const char *row_size_limited_reactive_sql)
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
const char * switch_stristr(const char *instr, const char *str)
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:665
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:698
switch_status_t switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err)
Executes the sql.
static char create_complete_sql[]
static void core_event_handler(switch_event_t *event)
Abstract interface to a database module.
switch_odbc_status_t switch_odbc_SQLSetAutoCommitAttr(switch_odbc_handle_t *handle, switch_bool_t on)
Definition: switch_odbc.c:818
static char create_row_size_limited_channels_sql[]
static char create_alias_sql[]
switch_status_t switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority)
Definition: switch_apr.c:688

◆ switch_core_sqldb_stop()

void switch_core_sqldb_stop ( void  )

Definition at line 3918 of file switch_core_sqldb.c.

References core_event_handler(), sql_close(), sql_manager, switch_cache_db_flush_handles(), switch_core_sqldb_stop_thread(), switch_event_unbind_callback(), and switch_thread_join().

Referenced by switch_core_sqldb_destroy().

3919 {
3920  switch_status_t st;
3921 
3923 
3924  if (sql_manager.db_thread && sql_manager.db_thread_running) {
3925  sql_manager.db_thread_running = -1;
3926  switch_thread_join(&st, sql_manager.db_thread);
3927  }
3928 
3930 
3932  sql_close(0);
3933 }
void switch_cache_db_flush_handles(void)
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1379
switch_status_t
Common return values.
static struct @4 sql_manager
static void switch_core_sqldb_stop_thread(void)
switch_status_t switch_event_unbind_callback(switch_event_callback_t callback)
static void core_event_handler(switch_event_t *event)
static void sql_close(time_t prune)

◆ switch_core_state_machine_init()

void switch_core_state_machine_init ( switch_memory_pool_t pool)

Definition at line 420 of file switch_core_state_machine.c.

Referenced by switch_core_init().

421 {
422  return;
423 }

Variable Documentation

◆ runtime

struct switch_runtime runtime

Definition at line 86 of file switch_core.c.

Referenced by _switch_cache_db_get_db_handle(), _switch_core_db_handle(), switch_cache_db_create_schema(), switch_cache_db_test_reactive_ex(), switch_cond_next(), switch_cond_yield(), switch_core_add_registration(), switch_core_check_core_db_dsn(), switch_core_db_test_reactive(), switch_core_del_registration(), switch_core_expire_registration(), switch_core_idle_cpu(), switch_core_min_idle_cpu(), switch_core_pool_stats(), switch_core_port_allocator_new(), switch_core_session_event_send(), switch_core_session_findall(), switch_core_session_findall_matching_var(), switch_core_session_hangup_state(), switch_core_session_hupall(), switch_core_session_hupall_endpoint(), switch_core_session_hupall_matching_vars_ans(), switch_core_session_id_dec(), switch_core_session_message_send(), switch_core_session_perform_destroy(), switch_core_session_perform_force_locate(), switch_core_session_perform_locate(), switch_core_session_read_frame(), switch_core_session_read_text_frame(), switch_core_session_read_video_frame(), switch_core_session_request_uuid(), switch_core_session_set_external_id(), switch_core_session_set_uuid(), switch_core_session_sync_clock(), switch_core_session_thread_launch(), switch_core_sessions_per_second(), switch_core_sql_db_thread(), switch_core_sql_exec(), switch_core_sqldb_start(), switch_core_sqldb_start_thread(), switch_event_fire_detailed(), switch_event_shutdown(), switch_log_meta_vprintf(), switch_micro_time_now(), SWITCH_MODULE_LOAD_FUNCTION(), SWITCH_MODULE_RUNTIME_FUNCTION(), switch_new_profile_timer(), switch_simple_email(), switch_sql_concat(), switch_time_calibrate_clock(), switch_time_sync(), switch_user_sql_thread(), switch_uuid_get(), timer_destroy(), timer_init(), and timer_next().

◆ session_manager

struct switch_session_manager session_manager