FreeSWITCH API Documentation  1.7.0
Data Structures | Macros | Enumerations | Functions | Variables
switch_core_pvt.h File Reference
#include "spandsp.h"
#include "switch_profile.h"
#include <switch_private.h>
#include <apr_pools.h>
#include <apr_hash.h>
#include <apr_strings.h>
#include <apr_general.h>
#include <apr_portable.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 SPANDSP_NO_TIFF   1
 
#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_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

#define DO_EVENTS

Definition at line 82 of file switch_core_pvt.h.

#define SPANDSP_NO_TIFF   1

Definition at line 34 of file switch_core_pvt.h.

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

Definition at line 84 of file switch_core_pvt.h.

Referenced by switch_core_session_request_uuid().

#define SWITCH_MESSAGE_QUEUE_LEN   256

Definition at line 85 of file switch_core_pvt.h.

Referenced by switch_core_session_request_uuid().

Enumeration Type Documentation

Enumerator
DBTYPE_DEFAULT 
DBTYPE_MSSQL 

Definition at line 234 of file switch_core_pvt.h.

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 90 of file switch_core_pvt.h.

Function Documentation

switch_memory_pool_t* switch_core_memory_init ( void  )

Definition at line 614 of file switch_core_memory.c.

References memory_manager, memset(), pool_thread(), pool_thread_p, 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().

615 {
616 #ifndef INSTANTLY_DESTROY_POOLS
617  switch_threadattr_t *thd_attr;
618 #endif
619 #ifdef PER_POOL_LOCK
620  apr_allocator_t *my_allocator = NULL;
621  apr_thread_mutex_t *my_mutex;
622 #endif
623 
624  memset(&memory_manager, 0, sizeof(memory_manager));
625 
626 #ifdef PER_POOL_LOCK
627  if ((apr_allocator_create(&my_allocator)) != APR_SUCCESS) {
628  abort();
629  }
630 
631  if ((apr_pool_create_ex(&memory_manager.memory_pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
632  apr_allocator_destroy(my_allocator);
633  my_allocator = NULL;
634  abort();
635  }
636 
637  if ((apr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED, memory_manager.memory_pool)) != APR_SUCCESS) {
638  abort();
639  }
640 
641  apr_allocator_mutex_set(my_allocator, my_mutex);
642  apr_pool_mutex_set(memory_manager.memory_pool, my_mutex);
643  apr_allocator_owner_set(my_allocator, memory_manager.memory_pool);
644  apr_pool_tag(memory_manager.memory_pool, "core_pool");
645 #else
646  apr_pool_create(&memory_manager.memory_pool, NULL);
647  switch_assert(memory_manager.memory_pool != NULL);
648 #endif
649 
650 #ifdef USE_MEM_LOCK
652 #endif
653 
654 #ifdef INSTANTLY_DESTROY_POOLS
655  {
656  void *foo;
657  foo = (void *) (intptr_t) pool_thread;
658  }
659 #else
660 
661  switch_queue_create(&memory_manager.pool_queue, 50000, memory_manager.memory_pool);
662  switch_queue_create(&memory_manager.pool_recycle_queue, 50000, memory_manager.memory_pool);
663 
664  switch_threadattr_create(&thd_attr, memory_manager.memory_pool);
665 
667  switch_thread_create(&pool_thread_p, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
668 
669  while (!memory_manager.pool_thread_running) {
671  }
672 #endif
673 
674  return memory_manager.memory_pool;
675 }
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:660
static void *SWITCH_THREAD_FUNC pool_thread(switch_thread_t *thread, void *obj)
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:551
static struct @2 memory_manager
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
void switch_cond_next(void)
Definition: switch_time.c:638
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:642
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:675
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1109
#define switch_assert(expr)
memset(buf, 0, buflen)
void switch_core_memory_stop ( void  )

Definition at line 596 of file switch_core_memory.c.

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

Referenced by switch_core_destroy().

597 {
598 #ifndef INSTANTLY_DESTROY_POOLS
599  switch_status_t st;
600  void *pop = NULL;
601 
602  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping memory pool queue.\n");
603 
604  memory_manager.pool_thread_running = 0;
606 
607 
608  while (switch_queue_trypop(memory_manager.pool_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
609  apr_pool_destroy(pop);
610  }
611 #endif
612 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1140
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1255
static struct @2 memory_manager
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.
void switch_core_session_init ( switch_memory_pool_t pool)

Definition at line 2462 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().

2463 {
2464  memset(&session_manager, 0, sizeof(session_manager));
2472 }
#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:350
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1390
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:270
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:1109
switch_mutex_t * mutex
memset(buf, 0, buflen)
void switch_core_session_uninit ( void  )

Definition at line 2474 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().

2475 {
2482 }
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:360
switch_thread_cond_t * cond
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_hash_t * session_table
switch_status_t switch_queue_term(switch_queue_t *queue)
Definition: switch_apr.c:1150
switch_mutex_t * mutex
switch_status_t switch_core_sqldb_start ( switch_memory_pool_t pool,
switch_bool_t  manage 
)

Definition at line 3344 of file switch_core_sqldb.c.

References basic_calls_sql, 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_tasks_sql, DBTYPE_DEFAULT, detailed_calls_sql, manage, switch_runtime::odbc_dbtype, switch_runtime::odbc_dsn, pool, recovery_sql, runtime, SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_PGSQL, SCF_CLEAR_SQL, SCF_CORE_NON_SQLITE_DB_REQ, SCF_USE_SQL, skip(), db_job::sql, sql_manager, 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_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_LOG_WARNING, switch_mutex_init(), SWITCH_MUTEX_NESTED, switch_odbc_SQLEndTran(), switch_odbc_SQLSetAutoCommitAttr(), SWITCH_ODBC_SUCCESS, switch_pgsql_finish_results, switch_pgsql_SQLEndTran(), switch_pgsql_SQLSetAutoCommitAttr(), SWITCH_PGSQL_SUCCESS, SWITCH_PRI_REALTIME, switch_safe_free, 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(), and switch_threadattr_stacksize_set().

Referenced by switch_core_init().

3345 {
3346  switch_threadattr_t *thd_attr;
3347 
3348  sql_manager.memory_pool = pool;
3349  sql_manager.manage = manage;
3350 
3354 
3355  if (!sql_manager.manage) goto skip;
3356 
3357  top:
3358 
3359  /* Activate SQL database */
3361  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
3362 
3364  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure! ODBC IS REQUIRED!\n");
3365  return SWITCH_STATUS_FALSE;
3366  }
3367 
3368  if (runtime.odbc_dsn) {
3369  runtime.odbc_dsn = NULL;
3371  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Falling back to core_db.\n");
3372  goto top;
3373  }
3374 
3375 
3377  return SWITCH_STATUS_FALSE;
3378  }
3379 
3380 
3382 
3383  switch (sql_manager.dbh->type) {
3384  case SCDB_TYPE_PGSQL:
3385  case SCDB_TYPE_ODBC:
3387  char sql[512] = "";
3388  char *tables[] = { "channels", "calls", "tasks", NULL };
3389  int i;
3390  const char *hostname = switch_core_get_switchname();
3391 
3392  for (i = 0; tables[i]; i++) {
3393  switch_snprintfv(sql, sizeof(sql), "delete from %q where hostname='%q'", tables[i], hostname);
3394  switch_cache_db_execute_sql(sql_manager.dbh, sql, NULL);
3395  }
3396  }
3397  break;
3398  case SCDB_TYPE_CORE_DB:
3399  {
3400  switch_cache_db_execute_sql(sql_manager.dbh, "drop table channels", NULL);
3401  switch_cache_db_execute_sql(sql_manager.dbh, "drop table calls", NULL);
3402  switch_cache_db_execute_sql(sql_manager.dbh, "drop view detailed_calls", NULL);
3403  switch_cache_db_execute_sql(sql_manager.dbh, "drop view basic_calls", NULL);
3404  switch_cache_db_execute_sql(sql_manager.dbh, "drop table interfaces", NULL);
3405  switch_cache_db_execute_sql(sql_manager.dbh, "drop table tasks", NULL);
3406  switch_cache_db_execute_sql(sql_manager.dbh, "PRAGMA synchronous=OFF;", NULL);
3407  switch_cache_db_execute_sql(sql_manager.dbh, "PRAGMA count_changes=OFF;", NULL);
3408  switch_cache_db_execute_sql(sql_manager.dbh, "PRAGMA default_cache_size=8000", NULL);
3409  switch_cache_db_execute_sql(sql_manager.dbh, "PRAGMA temp_store=MEMORY;", NULL);
3410  switch_cache_db_execute_sql(sql_manager.dbh, "PRAGMA journal_mode=OFF;", NULL);
3411  }
3412  break;
3413  }
3414 
3415  switch_cache_db_test_reactive(sql_manager.dbh, "select hostname from aliases", "DROP TABLE aliases", create_alias_sql);
3416  switch_cache_db_test_reactive(sql_manager.dbh, "select hostname from complete", "DROP TABLE complete", create_complete_sql);
3417  switch_cache_db_test_reactive(sql_manager.dbh, "select hostname from nat", "DROP TABLE nat", create_nat_sql);
3418  switch_cache_db_test_reactive(sql_manager.dbh, "delete from registrations where reg_user=''",
3419  "DROP TABLE registrations", create_registrations_sql);
3420 
3421  switch_cache_db_test_reactive(sql_manager.dbh, "select metadata from registrations", NULL, "ALTER TABLE registrations ADD COLUMN metadata VARCHAR(256)");
3422 
3423 
3424  switch_cache_db_test_reactive(sql_manager.dbh, "select hostname from recovery", "DROP TABLE recovery", recovery_sql);
3425  switch_cache_db_create_schema(sql_manager.dbh, "create index recovery1 on recovery(technology)", NULL);
3426  switch_cache_db_create_schema(sql_manager.dbh, "create index recovery2 on recovery(profile_name)", NULL);
3427  switch_cache_db_create_schema(sql_manager.dbh, "create index recovery3 on recovery(uuid)", NULL);
3428  switch_cache_db_create_schema(sql_manager.dbh, "create index recovery3 on recovery(runtime_uuid)", NULL);
3429 
3430 
3431 
3432 
3433  switch (sql_manager.dbh->type) {
3434  case SCDB_TYPE_PGSQL:
3435  case SCDB_TYPE_ODBC:
3436  {
3437  char *err;
3438  int result = 0;
3439 
3440  switch_cache_db_test_reactive(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 from channels", "DROP TABLE channels", create_channels_sql);
3441  switch_cache_db_test_reactive(sql_manager.dbh, "select call_uuid from calls", "DROP TABLE calls", create_calls_sql);
3442  switch_cache_db_test_reactive(sql_manager.dbh, "select * from basic_calls where sent_callee_name=''", "DROP VIEW basic_calls", basic_calls_sql);
3443  switch_cache_db_test_reactive(sql_manager.dbh, "select * from detailed_calls where sent_callee_name=''", "DROP VIEW detailed_calls", detailed_calls_sql);
3445  switch_cache_db_test_reactive(sql_manager.dbh, "delete from registrations where reg_user=''",
3446  "DROP TABLE registrations", create_registrations_sql);
3447  } else {
3448  char *tmp = switch_string_replace(create_registrations_sql, "url TEXT", "url VARCHAR(max)");
3449  switch_cache_db_test_reactive(sql_manager.dbh, "delete from registrations where reg_user=''",
3450  "DROP TABLE registrations", tmp);
3451  free(tmp);
3452  }
3453  switch_cache_db_test_reactive(sql_manager.dbh, "select ikey from interfaces", "DROP TABLE interfaces", create_interfaces_sql);
3454  switch_cache_db_test_reactive(sql_manager.dbh, "select task_id, task_desc, task_group, task_runtime, task_sql_manager, hostname from tasks",
3455  "DROP TABLE tasks", create_tasks_sql);
3456 
3457 
3458  switch(sql_manager.dbh->type) {
3459  case SCDB_TYPE_CORE_DB:
3460  {
3461  switch_cache_db_execute_sql_real(sql_manager.dbh, "BEGIN EXCLUSIVE", &err);
3462  }
3463  break;
3464  case SCDB_TYPE_ODBC:
3465  {
3466  switch_odbc_status_t result;
3467 
3468  if ((result = switch_odbc_SQLSetAutoCommitAttr(sql_manager.dbh->native_handle.odbc_dbh, 0)) != SWITCH_ODBC_SUCCESS) {
3469  char tmp[100];
3470  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
3471  err = strdup(tmp);
3472  }
3473  }
3474  break;
3475  case SCDB_TYPE_PGSQL:
3476  {
3477  switch_pgsql_status_t result;
3478 
3479  if ((result = switch_pgsql_SQLSetAutoCommitAttr(sql_manager.dbh->native_handle.pgsql_dbh, 0)) != SWITCH_PGSQL_SUCCESS) {
3480  char tmp[100];
3481  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
3482  err = strdup(tmp);
3483  }
3484  }
3485  break;
3486  }
3487 
3488  switch_cache_db_execute_sql(sql_manager.dbh, "delete from channels where hostname=''", &err);
3489  if (!err) {
3490  switch_cache_db_execute_sql(sql_manager.dbh, "delete from channels where hostname=''", &err);
3491 
3492  switch(sql_manager.dbh->type) {
3493  case SCDB_TYPE_CORE_DB:
3494  {
3495  switch_cache_db_execute_sql_real(sql_manager.dbh, "COMMIT", &err);
3496  }
3497  break;
3498  case SCDB_TYPE_ODBC:
3499  {
3500  if (switch_odbc_SQLEndTran(sql_manager.dbh->native_handle.odbc_dbh, 1) != SWITCH_ODBC_SUCCESS ||
3501  switch_odbc_SQLSetAutoCommitAttr(sql_manager.dbh->native_handle.odbc_dbh, 1) != SWITCH_ODBC_SUCCESS) {
3502  char tmp[100];
3503  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to commit transaction.", result);
3504  err = strdup(tmp);
3505  }
3506  }
3507  break;
3508  case SCDB_TYPE_PGSQL:
3509  {
3510  if (switch_pgsql_SQLEndTran(sql_manager.dbh->native_handle.pgsql_dbh, 1) != SWITCH_PGSQL_SUCCESS ||
3511  switch_pgsql_SQLSetAutoCommitAttr(sql_manager.dbh->native_handle.pgsql_dbh, 1) != SWITCH_PGSQL_SUCCESS ||
3512  switch_pgsql_finish_results(sql_manager.dbh->native_handle.pgsql_dbh) != SWITCH_PGSQL_SUCCESS) {
3513  char tmp[100];
3514  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to commit transaction.", result);
3515  err = strdup(tmp);
3516  }
3517  }
3518  break;
3519  }
3520  }
3521 
3522 
3523  if (err) {
3524  //runtime.odbc_dsn = NULL;
3525  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database Error [%s]\n", err);
3526  //switch_cache_db_release_db_handle(&sql_manager.dbh);
3527  if (switch_stristr("read-only", err)) {
3528  switch_safe_free(err);
3529  } else {
3530  switch_safe_free(err);
3531  goto top;
3532  }
3533  }
3534  }
3535  break;
3536  case SCDB_TYPE_CORE_DB:
3537  {
3544  }
3545  break;
3546  }
3547 
3549  char sql[512] = "";
3550  char *tables[] = { "complete", "aliases", "nat", NULL };
3551  int i;
3552  const char *hostname = switch_core_get_hostname();
3553 
3554  for (i = 0; tables[i]; i++) {
3555  switch_snprintfv(sql, sizeof(sql), "delete from %q where sticky=0 and hostname='%q'", tables[i], hostname);
3556  switch_cache_db_execute_sql(sql_manager.dbh, sql, NULL);
3557  }
3558 
3559  switch_snprintfv(sql, sizeof(sql), "delete from interfaces where hostname='%q'", hostname);
3560  switch_cache_db_execute_sql(sql_manager.dbh, sql, NULL);
3561  }
3562 
3563  switch_cache_db_create_schema(sql_manager.dbh, "create index alias1 on aliases (alias)", NULL);
3564  switch_cache_db_create_schema(sql_manager.dbh, "create index tasks1 on tasks (hostname,task_id)", NULL);
3565  switch_cache_db_create_schema(sql_manager.dbh, "create index complete1 on complete (a1,hostname)", NULL);
3566  switch_cache_db_create_schema(sql_manager.dbh, "create index complete2 on complete (a2,hostname)", NULL);
3567  switch_cache_db_create_schema(sql_manager.dbh, "create index complete3 on complete (a3,hostname)", NULL);
3568  switch_cache_db_create_schema(sql_manager.dbh, "create index complete4 on complete (a4,hostname)", NULL);
3569  switch_cache_db_create_schema(sql_manager.dbh, "create index complete5 on complete (a5,hostname)", NULL);
3570  switch_cache_db_create_schema(sql_manager.dbh, "create index complete6 on complete (a6,hostname)", NULL);
3571  switch_cache_db_create_schema(sql_manager.dbh, "create index complete7 on complete (a7,hostname)", NULL);
3572  switch_cache_db_create_schema(sql_manager.dbh, "create index complete8 on complete (a8,hostname)", NULL);
3573  switch_cache_db_create_schema(sql_manager.dbh, "create index complete9 on complete (a9,hostname)", NULL);
3574  switch_cache_db_create_schema(sql_manager.dbh, "create index complete10 on complete (a10,hostname)", NULL);
3575  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);
3576  switch_cache_db_create_schema(sql_manager.dbh, "create index nat_map_port_proto on nat (port,proto,hostname)", NULL);
3577  switch_cache_db_create_schema(sql_manager.dbh, "create index channels1 on channels(hostname)", NULL);
3578  switch_cache_db_create_schema(sql_manager.dbh, "create index calls1 on calls(hostname)", NULL);
3579  switch_cache_db_create_schema(sql_manager.dbh, "create index chidx1 on channels (hostname)", NULL);
3580  switch_cache_db_create_schema(sql_manager.dbh, "create index uuindex on channels (uuid, hostname)", NULL);
3581  switch_cache_db_create_schema(sql_manager.dbh, "create index uuindex2 on channels (call_uuid)", NULL);
3582  switch_cache_db_create_schema(sql_manager.dbh, "create index callsidx1 on calls (hostname)", NULL);
3583  switch_cache_db_create_schema(sql_manager.dbh, "create index eruuindex on calls (caller_uuid, hostname)", NULL);
3584  switch_cache_db_create_schema(sql_manager.dbh, "create index eeuuindex on calls (callee_uuid)", NULL);
3585  switch_cache_db_create_schema(sql_manager.dbh, "create index eeuuindex2 on calls (call_uuid)", NULL);
3586  switch_cache_db_create_schema(sql_manager.dbh, "create index regindex1 on registrations (reg_user,realm,hostname)", NULL);
3587 
3588 
3589  skip:
3590 
3591  if (sql_manager.manage) {
3592 #ifdef SWITCH_SQL_BIND_EVERY_EVENT
3594 #else
3620 #endif
3621 
3622  switch_threadattr_create(&thd_attr, sql_manager.memory_pool);
3626  switch_thread_create(&sql_manager.db_thread, thd_attr, switch_core_sql_db_thread, NULL, sql_manager.memory_pool);
3627 
3628  }
3629 
3631 
3632  return SWITCH_STATUS_SUCCESS;
3633 }
switch_status_t switch_cache_db_create_schema(switch_cache_db_handle_t *dbh, char *sql, char **err)
Executes the create schema sql.
switch_pgsql_status_t
Definition: switch_pgsql.h:53
const char * switch_core_get_switchname(void)
Definition: switch_core.c:349
switch_odbc_status_t
Definition: switch_odbc.h:49
#define SWITCH_CHANNEL_LOG
static char create_interfaces_sql[]
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:660
switch_pgsql_status_t switch_pgsql_SQLEndTran(switch_pgsql_handle_t *handle, switch_bool_t commit)
Definition: switch_pgsql.c:865
#define SWITCH_EVENT_SUBCLASS_ANY
Definition: switch_event.h:128
switch_memory_pool_t * pool
static char create_tasks_sql[]
switch_pgsql_status_t switch_pgsql_SQLSetAutoCommitAttr(switch_pgsql_handle_t *handle, switch_bool_t on)
Definition: switch_pgsql.c:828
struct switch_runtime runtime
Definition: switch_core.c:64
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:655
#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:551
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
static char create_nat_sql[]
#define switch_pgsql_finish_results(handle)
Definition: switch_pgsql.h:107
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
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:2606
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 ...
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:344
switch_odbc_status_t switch_odbc_SQLEndTran(switch_odbc_handle_t *handle, switch_bool_t commit)
Definition: switch_odbc.c:760
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[]
static const char * skip(const char *in)
Definition: switch_json.c:270
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
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:642
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:675
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)
switch_odbc_status_t switch_odbc_SQLSetAutoCommitAttr(switch_odbc_handle_t *handle, switch_bool_t on)
Definition: switch_odbc.c:747
static char create_alias_sql[]
static struct @3 sql_manager
switch_status_t switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority)
Definition: switch_apr.c:665
void switch_core_sqldb_stop ( void  )

Definition at line 3699 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_destroy().

3700 {
3701  switch_status_t st;
3702 
3704 
3705  if (sql_manager.db_thread && sql_manager.db_thread_running) {
3706  sql_manager.db_thread_running = -1;
3707  switch_thread_join(&st, sql_manager.db_thread);
3708  }
3709 
3711 
3713  sql_close(0);
3714 }
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1255
void switch_cache_db_flush_handles(void)
switch_status_t
Common return values.
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)
static struct @3 sql_manager
void switch_core_state_machine_init ( switch_memory_pool_t pool)

Definition at line 423 of file switch_core_state_machine.c.

Referenced by switch_core_init().

424 {
425  return;
426 }

Variable Documentation

struct switch_runtime runtime

Definition at line 64 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(), switch_cond_next(), switch_cond_yield(), switch_core_add_registration(), switch_core_db_test_reactive(), switch_core_del_registration(), switch_core_expire_registration(), switch_core_idle_cpu(), switch_core_min_idle_cpu(), 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_var_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_video_frame(), switch_core_session_request_uuid(), 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_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().

struct switch_session_manager session_manager