FreeSWITCH API Documentation  1.7.0
Data Structures | Macros | Typedefs | Enumerations | Functions
switch_core.h File Reference

Core Library. More...

#include <switch.h>
+ Include dependency graph for switch_core.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_time_duration
 
struct  switch_app_log
 
struct  switch_thread_data_s
 
struct  switch_hold_record_s
 
struct  device_uuid_node_s
 
struct  switch_device_stats_s
 
struct  switch_device_record_s
 
struct  dtls_fp_s
 
struct  switch_core_session_message
 A message object designed to allow unlike technologies to exchange data. More...
 
struct  switch_core_thread_session
 A generic object to pass as a thread's session object to allow mutiple arguements and a pool. More...
 
union  switch_cache_db_native_handle_t
 
struct  switch_cache_db_core_db_options_t
 
struct  switch_cache_db_odbc_options_t
 
struct  switch_cache_db_pgsql_options_t
 
union  switch_cache_db_connection_options_t
 

Macros

#define SWITCH_MAX_CORE_THREAD_SESSION_OBJS   128
 
#define SWITCH_MAX_STREAMS   128
 
#define DTLS_SRTP_FNAME   "dtls-srtp"
 
#define MAX_FPLEN   64
 
#define MAX_FPSTRLEN   192
 
#define MESSAGE_STAMP_FFL(_m)   _m->_file = __FILE__; _m->_func = __SWITCH_FUNC__; _m->_line = __LINE__
 
#define MESSAGE_STRING_ARG_MAX   10
 
#define switch_core_session_get_name(_s)   switch_channel_get_name(switch_core_session_get_channel(_s))
 
#define switch_core_media_bug_remove_all(_s)   switch_core_media_bug_remove_all_function(_s, NULL)
 
#define switch_core_new_memory_pool(p)   switch_core_perform_new_memory_pool(p, __FILE__, __SWITCH_FUNC__, __LINE__)
 Create a new sub memory pool from the core's master pool. More...
 
#define switch_core_destroy_memory_pool(p)   switch_core_perform_destroy_memory_pool(p, __FILE__, __SWITCH_FUNC__, __LINE__)
 Returns a subpool back to the main pool. More...
 
#define switch_core_permanent_alloc(_memory)   switch_core_perform_permanent_alloc(_memory, __FILE__, __SWITCH_FUNC__, __LINE__)
 Allocate memory from the main pool with no intention of returning it. More...
 
#define switch_core_alloc(_pool, _mem)   switch_core_perform_alloc(_pool, _mem, __FILE__, __SWITCH_FUNC__, __LINE__)
 Allocate memory directly from a memory pool. More...
 
#define switch_core_session_alloc(_session, _memory)   switch_core_perform_session_alloc(_session, _memory, __FILE__, __SWITCH_FUNC__, __LINE__)
 Allocate memory from a session's pool. More...
 
#define switch_core_permanent_strdup(_todup)   switch_core_perform_permanent_strdup(_todup, __FILE__, __SWITCH_FUNC__, __LINE__)
 Copy a string using permanent memory allocation. More...
 
#define switch_core_session_strdup(_session, _todup)   switch_core_perform_session_strdup(_session, _todup, __FILE__, __SWITCH_FUNC__, __LINE__)
 Copy a string using memory allocation from a session's pool. More...
 
#define switch_core_strdup(_pool, _todup)   switch_core_perform_strdup(_pool, _todup, __FILE__, __SWITCH_FUNC__, __LINE__)
 Copy a string using memory allocation from a given pool. More...
 
#define switch_core_session_request(_ep, _d, _f, _p)   switch_core_session_request_uuid(_ep, _d, _f, _p, NULL)
 
#define switch_core_session_destroy(session)   switch_core_session_perform_destroy(session, __FILE__, __SWITCH_FUNC__, __LINE__)
 Destroy a session and return the memory pool to the core. More...
 
#define switch_core_session_locate(uuid_str)   switch_core_session_perform_locate(uuid_str, __FILE__, __SWITCH_FUNC__, __LINE__)
 Locate a session based on it's uuid. More...
 
#define switch_core_session_force_locate(uuid_str)   switch_core_session_perform_force_locate(uuid_str, __FILE__, __SWITCH_FUNC__, __LINE__)
 Locate a session based on it's uuid even if the channel is not ready. More...
 
#define switch_core_session_hupall_matching_var(_vn, _vv, _c)   switch_core_session_hupall_matching_var_ans(_vn, _vv, _c, SHT_UNANSWERED | SHT_ANSWERED)
 
#define switch_core_session_get_partner(_session, _partner)   switch_core_session_perform_get_partner(_session, _partner, __FILE__, __SWITCH_FUNC__, __LINE__)
 
#define switch_core_session_execute_application(_a, _b, _c)   switch_core_session_execute_application_get_flags(_a, _b, _c, NULL)
 Execute an application on a session. More...
 
#define switch_core_session_get_private(_s)   switch_core_session_get_private_class(_s, SWITCH_PVT_PRIMARY)
 
#define switch_core_session_set_private(_s, _p)   switch_core_session_set_private_class(_s, _p, SWITCH_PVT_PRIMARY)
 
#define switch_core_service_session(_s)   switch_core_service_session_av(_s, SWITCH_TRUE, SWITCH_FALSE)
 
#define switch_core_session_receive_message(_session, _message)
 
#define switch_core_session_kill_channel(session, sig)   switch_core_session_perform_kill_channel(session, __FILE__, __SWITCH_FUNC__, __LINE__, sig)
 Send a signal to a channel. More...
 
#define switch_core_hash_init(_hash)   switch_core_hash_init_case(_hash, SWITCH_TRUE)
 
#define switch_core_hash_init_nocase(_hash)   switch_core_hash_init_case(_hash, SWITCH_FALSE)
 
#define switch_core_hash_insert(_h, _k, _d)   switch_core_hash_insert_destructor(_h, _k, _d, NULL)
 
#define switch_core_hash_first(_h)   switch_core_hash_first_iter(_h, NULL)
 
#define switch_core_codec_init(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, _flags, _codec_settings, _pool)   switch_core_codec_init_with_bitrate(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, 0, _flags, _codec_settings, _pool)
 Initialize a codec handle. More...
 
#define switch_core_file_open(_fh, _file_path, _channels, _rate, _flags, _pool)   switch_core_perform_file_open(__FILE__, __SWITCH_FUNC__, __LINE__, _fh, _file_path, _channels, _rate, _flags, _pool)
 Open a media file using file format modules. More...
 
#define switch_check_network_list_ip(_ip_str, _list_name)   switch_check_network_list_ip_token(_ip_str, _list_name, NULL)
 
#define CACHE_DB_LEN   256
 
#define switch_cache_db_get_db_handle(_a, _b, _c)   _switch_cache_db_get_db_handle(_a, _b, _c, __FILE__, __SWITCH_FUNC__, __LINE__)
 
#define switch_cache_db_get_db_handle_dsn(_a, _b)   _switch_cache_db_get_db_handle_dsn(_a, _b, __FILE__, __SWITCH_FUNC__, __LINE__)
 
#define switch_core_db_handle(_a)   _switch_core_db_handle(_a, __FILE__, __SWITCH_FUNC__, __LINE__)
 
#define switch_cache_db_persistant_execute_trans(_d, _s, _r)   switch_cache_db_persistant_execute_trans_full(_d, _s, _r, NULL, NULL, NULL, NULL)
 
#define switch_sql_queue_manager_init(_q, _n, _d, _m, _p1, _p2, _ip1, _ip2)   switch_sql_queue_manager_init_name(__FILE__, _q, _n, _d, _m, _p1, _p2, _ip1, _ip2)
 

Typedefs

typedef struct switch_thread_data_s switch_thread_data_t
 
typedef struct switch_hold_record_s switch_hold_record_t
 
typedef struct device_uuid_node_s switch_device_node_t
 
typedef struct
switch_device_stats_s 
switch_device_stats_t
 
typedef struct
switch_device_record_s 
switch_device_record_t
 
typedef void(* switch_device_state_function_t )(switch_core_session_t *session, switch_channel_callstate_t callstate, switch_device_record_t *drec)
 
typedef struct dtls_fp_s dtls_fingerprint_t
 
typedef int(* switch_core_db_event_callback_func_t )(void *pArg, switch_event_t *event)
 
typedef struct
switch_cache_db_handle 
switch_cache_db_handle_t
 

Enumerations

enum  dtls_type_t { DTLS_TYPE_CLIENT = (1 << 0), DTLS_TYPE_SERVER = (1 << 1), DTLS_TYPE_RTP = (1 << 2), DTLS_TYPE_RTCP = (1 << 3) }
 
enum  dtls_state_t {
  DS_OFF, DS_HANDSHAKE, DS_SETUP, DS_READY,
  DS_FAIL, DS_INVALID
}
 
enum  switch_hup_type_t { SHT_NONE = 0, SHT_UNANSWERED = (1 << 0), SHT_ANSWERED = (1 << 1) }
 
enum  cache_db_flag_t { CDF_INUSE = (1 << 0), CDF_PRUNE = (1 << 1) }
 
enum  switch_cache_db_handle_type_t { SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_PGSQL }
 

Functions

static void * switch_must_malloc (size_t _b)
 
static void * switch_must_realloc (void *_b, size_t _z)
 
static char * switch_must_strdup (const char *_s)
 
void switch_core_screen_size (int *x, int *y)
 
void switch_core_session_sched_heartbeat (switch_core_session_t *session, uint32_t seconds)
 
void switch_core_session_unsched_heartbeat (switch_core_session_t *session)
 
void switch_core_session_enable_heartbeat (switch_core_session_t *session, uint32_t seconds)
 
void switch_core_session_disable_heartbeat (switch_core_session_t *session)
 
switch_status_t switch_core_media_bug_pop (switch_core_session_t *orig_session, const char *function, switch_media_bug_t **pop)
 
switch_status_t switch_core_media_bug_exec_all (switch_core_session_t *orig_session, const char *function, switch_media_bug_exec_cb_t cb, void *user_data)
 
uint32_t switch_core_media_bug_patch_video (switch_core_session_t *orig_session, switch_frame_t *frame)
 
uint32_t switch_core_media_bug_count (switch_core_session_t *orig_session, const char *function)
 
void switch_media_bug_set_spy_fmt (switch_media_bug_t *bug, switch_vid_spy_fmt_t spy_fmt)
 
switch_status_t switch_core_media_bug_push_spy_frame (switch_media_bug_t *bug, switch_frame_t *frame, switch_rw_t rw)
 
switch_status_t switch_core_media_bug_patch_spy_frame (switch_media_bug_t *bug, switch_image_t *img, switch_rw_t rw)
 
switch_vid_spy_fmt_t switch_media_bug_parse_spy_fmt (const char *name)
 
switch_status_t switch_core_media_bug_add (_In_ switch_core_session_t *session, _In_ const char *function, _In_ const char *target, _In_ switch_media_bug_callback_t callback, _In_opt_ void *user_data, _In_ time_t stop_time, _In_ switch_media_bug_flag_t flags, _Out_ switch_media_bug_t **new_bug)
 Add a media bug to the session. More...
 
void switch_core_media_bug_pause (switch_core_session_t *session)
 Pause a media bug on the session. More...
 
void switch_core_media_bug_resume (switch_core_session_t *session)
 Resume a media bug on the session. More...
 
void switch_core_media_bug_inuse (switch_media_bug_t *bug, switch_size_t *readp, switch_size_t *writep)
 
void * switch_core_media_bug_get_user_data (_In_ switch_media_bug_t *bug)
 Obtain private data from a media bug. More...
 
switch_frame_tswitch_core_media_bug_get_write_replace_frame (_In_ switch_media_bug_t *bug)
 Obtain a replace frame from a media bug. More...
 
switch_frame_tswitch_core_media_bug_get_native_read_frame (switch_media_bug_t *bug)
 
switch_frame_tswitch_core_media_bug_get_native_write_frame (switch_media_bug_t *bug)
 
switch_frame_tswitch_core_media_bug_get_video_ping_frame (switch_media_bug_t *bug)
 
void switch_core_media_bug_set_write_replace_frame (_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame)
 Set a return replace frame. More...
 
switch_frame_tswitch_core_media_bug_get_read_replace_frame (_In_ switch_media_bug_t *bug)
 Obtain a replace frame from a media bug. More...
 
void switch_core_media_bug_set_read_demux_frame (_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame)
 
switch_core_session_tswitch_core_media_bug_get_session (_In_ switch_media_bug_t *bug)
 Obtain the session from a media bug. More...
 
uint32_t switch_core_media_bug_test_flag (_In_ switch_media_bug_t *bug, _In_ uint32_t flag)
 Test for the existance of a flag on an media bug. More...
 
uint32_t switch_core_media_bug_set_flag (_In_ switch_media_bug_t *bug, _In_ uint32_t flag)
 
uint32_t switch_core_media_bug_clear_flag (_In_ switch_media_bug_t *bug, _In_ uint32_t flag)
 
void switch_core_media_bug_set_read_replace_frame (_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame)
 Set a return replace frame. More...
 
uint32_t switch_core_cpu_count (void)
 
switch_status_t switch_core_media_bug_remove (_In_ switch_core_session_t *session, _Inout_ switch_media_bug_t **bug)
 Remove a media bug from the session. More...
 
uint32_t switch_core_media_bug_prune (switch_core_session_t *session)
 
switch_status_t switch_core_media_bug_remove_callback (switch_core_session_t *session, switch_media_bug_callback_t callback)
 Remove media bug callback. More...
 
switch_status_t switch_core_media_bug_close (_Inout_ switch_media_bug_t **bug)
 Close and destroy a media bug. More...
 
switch_status_t switch_core_media_bug_remove_all_function (_In_ switch_core_session_t *session, const char *function)
 Remove all media bugs from the session. More...
 
switch_status_t switch_core_media_bug_enumerate (switch_core_session_t *session, switch_stream_handle_t *stream)
 
switch_status_t switch_core_media_bug_transfer_recordings (switch_core_session_t *orig_session, switch_core_session_t *new_session)
 
switch_status_t switch_core_media_bug_transfer_callback (switch_core_session_t *orig_session, switch_core_session_t *new_session, switch_media_bug_callback_t callback, void *(*user_data_dup_func)(switch_core_session_t *, void *))
 
switch_status_t switch_core_media_bug_read (_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame, switch_bool_t fill)
 Read a frame from the bug. More...
 
void switch_core_media_bug_flush (_In_ switch_media_bug_t *bug)
 Flush the read and write buffers for the bug. More...
 
switch_status_t switch_core_media_bug_flush_all (_In_ switch_core_session_t *session)
 Flush the read/write buffers for all media bugs on the session. More...
 
switch_status_t switch_core_media_bug_set_pre_buffer_framecount (switch_media_bug_t *bug, uint32_t framecount)
 
switch_status_t switch_core_port_allocator_new (_In_ const char *ip, _In_ switch_port_t start, _In_ switch_port_t end, _In_ switch_port_flag_t flags, _Out_ switch_core_port_allocator_t **new_allocator)
 Initilize the port allocator. More...
 
switch_status_t switch_core_port_allocator_request_port (_In_ switch_core_port_allocator_t *alloc, _Out_ switch_port_t *port_ptr)
 Get a port from the port allocator. More...
 
switch_status_t switch_core_port_allocator_free_port (_In_ switch_core_port_allocator_t *alloc, _In_ switch_port_t port)
 Return unused port to the port allocator. More...
 
void switch_core_port_allocator_destroy (_Inout_ switch_core_port_allocator_t **alloc)
 destroythe port allocator More...
 
int switch_core_test_flag (int flag)
 
switch_status_t switch_core_init (_In_ switch_core_flag_t flags, _In_ switch_bool_t console, _Out_ const char **err)
 Initilize the core. More...
 
switch_status_t switch_core_init_and_modload (_In_ switch_core_flag_t flags, _In_ switch_bool_t console, _Out_ const char **err)
 Initilize the core and load modules. More...
 
uint32_t switch_core_session_limit (_In_ uint32_t new_limit)
 Set/Get Session Limit. More...
 
uint32_t switch_core_sessions_per_second (_In_ uint32_t new_limit)
 Set/Get Session Rate Limit. More...
 
switch_status_t switch_core_destroy (void)
 Destroy the core. More...
 
switch_status_t switch_core_session_io_read_lock (switch_core_session_t *session)
 
switch_status_t switch_core_session_io_write_lock (switch_core_session_t *session)
 
switch_status_t switch_core_session_io_rwunlock (switch_core_session_t *session)
 
switch_status_t switch_core_session_read_lock (_In_ switch_core_session_t *session)
 Acquire a read lock on the session. More...
 
switch_status_t switch_core_session_read_lock_hangup (_In_ switch_core_session_t *session)
 Acquire a read lock on the session. More...
 
void switch_core_session_write_lock (_In_ switch_core_session_t *session)
 Acquire a write lock on the session. More...
 
void switch_core_session_rwunlock (_In_ switch_core_session_t *session)
 Unlock a read or write lock on as given session. More...
 
int switch_core_add_state_handler (_In_ const switch_state_handler_table_t *state_handler)
 Add a global state handler. More...
 
void switch_core_remove_state_handler (_In_ const switch_state_handler_table_t *state_handler)
 Remove a global state handler. More...
 
const
switch_state_handler_table_t
switch_core_get_state_handler (_In_ int index)
 Access a state handler. More...
 
void switch_core_memory_pool_tag (switch_memory_pool_t *pool, const char *tag)
 
switch_status_t switch_core_perform_new_memory_pool (_Out_ switch_memory_pool_t **pool, _In_z_ const char *file, _In_z_ const char *func, _In_ int line)
 
int switch_core_session_sync_clock (void)
 
switch_status_t switch_core_perform_destroy_memory_pool (_Inout_ switch_memory_pool_t **pool, _In_z_ const char *file, _In_z_ const char *func, _In_ int line)
 
void switch_core_memory_pool_set_data (switch_memory_pool_t *pool, const char *key, void *data)
 
void * switch_core_memory_pool_get_data (switch_memory_pool_t *pool, const char *key)
 
void switch_core_session_run (_In_ switch_core_session_t *session)
 Start the session's state machine. More...
 
unsigned int switch_core_session_running (_In_ switch_core_session_t *session)
 determine if the session's state machine is running More...
 
unsigned int switch_core_session_started (_In_ switch_core_session_t *session)
 
void * switch_core_perform_permanent_alloc (_In_ switch_size_t memory, _In_z_ const char *file, _In_z_ const char *func, _In_ int line)
 
void * switch_core_perform_alloc (_In_ switch_memory_pool_t *pool, _In_ switch_size_t memory, _In_z_ const char *file, _In_z_ const char *func, _In_ int line)
 
_Ret_ void * switch_core_perform_session_alloc (_In_ switch_core_session_t *session, _In_ switch_size_t memory, const char *file, const char *func, int line)
 
char * switch_core_perform_permanent_strdup (_In_z_ const char *todup, _In_z_ const char *file, _In_z_ const char *func, _In_ int line)
 
char * switch_core_perform_session_strdup (_In_ switch_core_session_t *session, _In_z_ const char *todup, _In_z_ const char *file, _In_z_ const char *func, _In_ int line)
 
char * switch_core_perform_strdup (_In_ switch_memory_pool_t *pool, _In_z_ const char *todup, _In_z_ const char *file, _In_z_ const char *func, _In_ int line)
 
char * switch_core_session_sprintf (_In_ switch_core_session_t *session, _In_z_ _Printf_format_string_ const char *fmt,...)
 printf-style style printing routine. The data is output to a string allocated from the session More...
 
char * switch_core_session_vsprintf (switch_core_session_t *session, const char *fmt, va_list ap)
 printf-style style printing routine. The data is output to a string allocated from the session More...
 
char * switch_core_sprintf (_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt,...)
 printf-style style printing routine. The data is output to a string allocated from the pool More...
 
char * switch_core_vsprintf (switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt, va_list ap)
 printf-style style printing routine. The data is output to a string allocated from the pool More...
 
switch_memory_pool_tswitch_core_session_get_pool (_In_ switch_core_session_t *session)
 Retrieve the memory pool from a session. More...
 
switch_core_session_tswitch_core_session_request_xml (switch_endpoint_interface_t *endpoint_interface, switch_memory_pool_t **pool, switch_xml_t xml)
 
switch_core_session_tswitch_core_session_request_uuid (_In_ switch_endpoint_interface_t *endpoint_interface, _In_ switch_call_direction_t direction, switch_originate_flag_t originate_flags, _Inout_opt_ switch_memory_pool_t **pool, _In_opt_z_ const char *use_uuid)
 Allocate and return a new session from the core. More...
 
switch_status_t switch_core_session_set_uuid (_In_ switch_core_session_t *session, _In_z_ const char *use_uuid)
 
void switch_core_session_perform_destroy (_Inout_ switch_core_session_t **session, _In_z_ const char *file, _In_z_ const char *func, _In_ int line)
 
void switch_core_session_destroy_state (switch_core_session_t *session)
 
void switch_core_session_reporting_state (switch_core_session_t *session)
 
void switch_core_session_hangup_state (switch_core_session_t *session, switch_bool_t force)
 
uint32_t switch_core_session_count (void)
 Provide the total number of sessions. More...
 
switch_size_t switch_core_session_get_id (_In_ switch_core_session_t *session)
 
switch_size_t switch_core_session_id (void)
 Provide the current session_id. More...
 
switch_size_t switch_core_session_id_dec (void)
 
switch_core_session_tswitch_core_session_request_by_name (_In_z_ const char *endpoint_name, _In_ switch_call_direction_t direction, _Inout_ switch_memory_pool_t **pool)
 Allocate and return a new session from the core based on a given endpoint module name. More...
 
switch_status_t switch_core_session_thread_launch (_In_ switch_core_session_t *session)
 Launch the session thread (state machine) on a given session. More...
 
switch_status_t switch_thread_pool_launch_thread (switch_thread_data_t **tdp)
 
switch_status_t switch_core_session_thread_pool_launch (switch_core_session_t *session)
 
_Ret_ switch_channel_tswitch_core_session_get_channel (_In_ switch_core_session_t *session)
 Retrieve a pointer to the channel object associated with a given session. More...
 
switch_mutex_tswitch_core_session_get_mutex (switch_core_session_t *session)
 Signal a session's state machine thread that a state change has occured. More...
 
switch_status_t switch_core_session_wake_session_thread (_In_ switch_core_session_t *session)
 
void switch_core_session_signal_state_change (_In_ switch_core_session_t *session)
 
char * switch_core_session_get_uuid (_In_ switch_core_session_t *session)
 Retrieve the unique identifier from a session. More...
 
switch_status_t switch_core_session_set_loglevel (switch_core_session_t *session, switch_log_level_t loglevel)
 Sets the log level for a session. More...
 
switch_log_level_t switch_core_session_get_loglevel (switch_core_session_t *session)
 Get the log level for a session. More...
 
switch_jb_tswitch_core_session_get_jb (switch_core_session_t *session, switch_media_type_t type)
 
void switch_core_session_soft_lock (switch_core_session_t *session, uint32_t sec)
 
void switch_core_session_soft_unlock (switch_core_session_t *session)
 
void switch_core_session_set_dmachine (switch_core_session_t *session, switch_ivr_dmachine_t *dmachine, switch_digit_action_target_t target)
 
switch_ivr_dmachine_tswitch_core_session_get_dmachine (switch_core_session_t *session, switch_digit_action_target_t target)
 
switch_digit_action_target_t switch_ivr_dmachine_get_target (switch_ivr_dmachine_t *dmachine)
 
void switch_ivr_dmachine_set_target (switch_ivr_dmachine_t *dmachine, switch_digit_action_target_t target)
 
switch_status_t switch_ivr_dmachine_set_terminators (switch_ivr_dmachine_t *dmachine, const char *terminators)
 
switch_status_t switch_core_session_set_codec_slin (switch_core_session_t *session, switch_slin_data_t *data)
 
void switch_core_session_raw_read (switch_core_session_t *session)
 
char * switch_core_get_uuid (void)
 Retrieve the unique identifier from the core. More...
 
switch_core_session_tswitch_core_session_perform_locate (const char *uuid_str, const char *file, const char *func, int line)
 
switch_core_session_tswitch_core_session_perform_force_locate (const char *uuid_str, const char *file, const char *func, int line)
 
char * switch_core_get_variable (_In_z_ const char *varname)
 Retrieve a global variable from the core. More...
 
char * switch_core_get_variable_dup (_In_z_ const char *varname)
 
char * switch_core_get_variable_pdup (_In_z_ const char *varname, switch_memory_pool_t *pool)
 
const char * switch_core_get_hostname (void)
 
const char * switch_core_get_switchname (void)
 
char * switch_core_get_domain (switch_bool_t dup)
 
void switch_core_set_variable (_In_z_ const char *varname, _In_opt_z_ const char *value)
 Add a global variable to the core. More...
 
switch_status_t switch_core_get_variables (switch_event_t **event)
 
switch_bool_t switch_core_set_var_conditional (_In_z_ const char *varname, _In_opt_z_ const char *value, _In_opt_z_ const char *val2)
 Conditionally add a global variable to the core. More...
 
void switch_core_dump_variables (_In_ switch_stream_handle_t *stream)
 
void switch_core_session_hupall (_In_ switch_call_cause_t cause)
 Hangup all sessions. More...
 
uint32_t switch_core_session_hupall_matching_var_ans (_In_ const char *var_name, _In_ const char *var_val, _In_ switch_call_cause_t cause, switch_hup_type_t type)
 Hangup all sessions which match a specific channel variable. More...
 
switch_console_callback_match_tswitch_core_session_findall_matching_var (const char *var_name, const char *var_val)
 
switch_console_callback_match_tswitch_core_session_findall (void)
 
void switch_core_session_hupall_endpoint (const switch_endpoint_interface_t *endpoint_interface, switch_call_cause_t cause)
 Hangup all sessions that belong to an endpoint. More...
 
switch_status_t switch_core_session_perform_get_partner (switch_core_session_t *session, switch_core_session_t **partner, const char *file, const char *func, int line)
 Get the session's partner (the session its bridged to) More...
 
switch_status_t switch_core_session_message_send (_In_z_ const char *uuid_str, _In_ switch_core_session_message_t *message)
 Send a message to another session using it's uuid. More...
 
switch_status_t switch_core_session_queue_message (_In_ switch_core_session_t *session, _In_ switch_core_session_message_t *message)
 Queue a message on a session. More...
 
void switch_core_session_free_message (switch_core_session_message_t **message)
 
switch_status_t switch_core_session_queue_signal_data (switch_core_session_t *session, void *signal_data)
 
switch_status_t switch_core_session_dequeue_signal_data (switch_core_session_t *session, void **signal_data)
 
switch_status_t switch_core_session_pass_indication (_In_ switch_core_session_t *session, _In_ switch_core_session_message_types_t indication)
 pass an indication message on a session More...
 
switch_status_t switch_core_session_queue_indication (_In_ switch_core_session_t *session, _In_ switch_core_session_message_types_t indication)
 Queue an indication message on a session. More...
 
switch_status_t switch_core_session_dequeue_message (_In_ switch_core_session_t *session, _Out_ switch_core_session_message_t **message)
 DE-Queue an message on a given session. More...
 
switch_status_t switch_core_session_flush_message (_In_ switch_core_session_t *session)
 Flush a message queue on a given session. More...
 
switch_status_t switch_core_session_event_send (_In_z_ const char *uuid_str, _Inout_ switch_event_t **event)
 Queue an event on another session using its uuid. More...
 
switch_app_log_tswitch_core_session_get_app_log (_In_ switch_core_session_t *session)
 
switch_status_t switch_core_session_exec (_In_ switch_core_session_t *session, _In_ const switch_application_interface_t *application_interface, _In_opt_z_ const char *arg)
 Execute an application on a session. More...
 
void switch_core_session_video_reset (switch_core_session_t *session)
 
switch_status_t switch_core_session_execute_application_get_flags (_In_ switch_core_session_t *session, _In_ const char *app, _In_opt_z_ const char *arg, _Out_opt_ int32_t *flags)
 Execute an application on a session. More...
 
switch_status_t switch_core_session_execute_application_async (switch_core_session_t *session, const char *app, const char *arg)
 
switch_status_t switch_core_session_get_app_flags (const char *app, int32_t *flags)
 
switch_status_t switch_core_session_execute_exten (_In_ switch_core_session_t *session, _In_z_ const char *exten, _In_opt_z_ const char *dialplan, _In_opt_z_ const char *context)
 Run a dialplan and execute an extension. More...
 
switch_status_t switch_core_session_receive_event (_In_ switch_core_session_t *session, _Inout_ switch_event_t **event)
 Send an event to a session translating it to it's native message format. More...
 
void * switch_core_session_get_private_class (_In_ switch_core_session_t *session, _In_ switch_pvt_class_t index)
 Retrieve private user data from a session. More...
 
switch_status_t switch_core_session_set_private_class (_In_ switch_core_session_t *session, _In_ void *private_info, _In_ switch_pvt_class_t index)
 Add private user data to a session. More...
 
int switch_core_session_add_stream (_In_ switch_core_session_t *session, _In_opt_ void *private_info)
 Add a logical stream to a session. More...
 
void * switch_core_session_get_stream (_In_ switch_core_session_t *session, _In_ int index)
 Retreive a logical stream from a session. More...
 
int switch_core_session_get_stream_count (_In_ switch_core_session_t *session)
 Determine the number of logical streams a session has. More...
 
void switch_core_session_launch_thread (_In_ switch_core_session_t *session, _In_ void *(*func)(switch_thread_t *, void *), _In_opt_ void *obj)
 Launch a thread designed to exist within the scope of a given session. More...
 
void switch_core_thread_session_end (_In_ switch_core_session_t *session)
 Signal a thread using a thread session to terminate. More...
 
void switch_core_service_session_av (_In_ switch_core_session_t *session, switch_bool_t audio, switch_bool_t video)
 Launch a service thread on a session to drop inbound data. More...
 
switch_call_cause_t switch_core_session_outgoing_channel (_In_opt_ switch_core_session_t *session, _In_opt_ switch_event_t *var_event, _In_z_ const char *endpoint_name, _In_ switch_caller_profile_t *caller_profile, _Inout_ switch_core_session_t **new_session, _Inout_ switch_memory_pool_t **pool, _In_ switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
 Request an outgoing session spawned from an existing session using a desired endpoing module. More...
 
switch_status_t switch_core_session_perform_receive_message (_In_ switch_core_session_t *session, _In_ switch_core_session_message_t *message, const char *file, const char *func, int line)
 Receive a message on a given session. More...
 
switch_status_t switch_core_session_queue_event (_In_ switch_core_session_t *session, _Inout_ switch_event_t **event)
 Queue an event on a given session. More...
 
uint32_t switch_core_session_event_count (_In_ switch_core_session_t *session)
 Indicate the number of waiting events on a session. More...
 
uint32_t switch_core_session_messages_waiting (switch_core_session_t *session)
 
switch_status_t switch_core_session_dequeue_event (_In_ switch_core_session_t *session, _Out_ switch_event_t **event, switch_bool_t force)
 DE-Queue an event on a given session. More...
 
switch_status_t switch_core_session_queue_private_event (_In_ switch_core_session_t *session, _Inout_ switch_event_t **event, switch_bool_t priority)
 Queue a private event on a given session. More...
 
uint32_t switch_core_session_private_event_count (_In_ switch_core_session_t *session)
 Indicate the number of waiting private events on a session. More...
 
switch_status_t switch_core_session_dequeue_private_event (_In_ switch_core_session_t *session, _Out_ switch_event_t **event)
 DE-Queue a private event on a given session. More...
 
uint32_t switch_core_session_flush_private_events (switch_core_session_t *session)
 Flush the private event queue of a session. More...
 
switch_status_t switch_core_session_read_frame (_In_ switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
 Read a frame from a session. More...
 
switch_status_t switch_core_session_read_video_frame (_In_ switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
 Read a video frame from a session. More...
 
switch_status_t switch_core_session_write_video_frame (_In_ switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
 Write a video frame to a session. More...
 
switch_status_t switch_core_session_write_encoded_video_frame (switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
 
switch_status_t switch_core_session_set_read_impl (switch_core_session_t *session, const switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_set_write_impl (switch_core_session_t *session, const switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_set_video_read_impl (switch_core_session_t *session, const switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_set_video_write_impl (switch_core_session_t *session, const switch_codec_implementation_t *impp)
 
void switch_core_session_reset (_In_ switch_core_session_t *session, switch_bool_t flush_dtmf, switch_bool_t reset_read_codec)
 Reset the buffers and resampler on a session. More...
 
switch_status_t switch_core_session_write_frame (_In_ switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
 Write a frame to a session. More...
 
switch_status_t switch_core_session_perform_kill_channel (_In_ switch_core_session_t *session, const char *file, const char *func, int line, switch_signal_t sig)
 
switch_status_t switch_core_session_send_dtmf (_In_ switch_core_session_t *session, const switch_dtmf_t *dtmf)
 Send DTMF to a session. More...
 
switch_status_t switch_core_session_send_dtmf_string (switch_core_session_t *session, const char *dtmf_string)
 Send DTMF to a session. More...
 
switch_status_t switch_core_session_recv_dtmf (_In_ switch_core_session_t *session, const switch_dtmf_t *dtmf)
 RECV DTMF on a session. More...
 
switch_status_t switch_core_hash_init_case (_Out_ switch_hash_t **hash, switch_bool_t case_sensitive)
 Initialize a hash table. More...
 
switch_status_t switch_core_hash_destroy (_Inout_ switch_hash_t **hash)
 Destroy an existing hash table. More...
 
switch_status_t switch_core_hash_insert_destructor (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data, hashtable_destructor_t destructor)
 Insert data into a hash. More...
 
switch_status_t switch_core_hash_insert_locked (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data, _In_opt_ switch_mutex_t *mutex)
 Insert data into a hash. More...
 
switch_status_t switch_core_hash_insert_wrlock (switch_hash_t *hash, const char *key, const void *data, switch_thread_rwlock_t *rwlock)
 Retrieve data from a given hash. More...
 
void * switch_core_hash_delete (_In_ switch_hash_t *hash, _In_z_ const char *key)
 Delete data from a hash based on desired key. More...
 
void * switch_core_hash_delete_locked (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_mutex_t *mutex)
 Delete data from a hash based on desired key. More...
 
void * switch_core_hash_delete_wrlock (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_thread_rwlock_t *rwlock)
 Delete data from a hash based on desired key. More...
 
switch_status_t switch_core_hash_delete_multi (_In_ switch_hash_t *hash, _In_ switch_hash_delete_callback_t callback, _In_opt_ void *pData)
 Delete data from a hash based on callback function. More...
 
void * switch_core_hash_find (_In_ switch_hash_t *hash, _In_z_ const char *key)
 Retrieve data from a given hash. More...
 
void * switch_core_hash_find_locked (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex)
 Retrieve data from a given hash. More...
 
void * switch_core_hash_find_rdlock (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_thread_rwlock_t *rwlock)
 Retrieve data from a given hash. More...
 
switch_hash_index_tswitch_core_hash_first_iter (_In_ switch_hash_t *hash, switch_hash_index_t *hi)
 Gets the first element of a hashtable. More...
 
switch_bool_t switch_core_hash_empty (switch_hash_t *hash)
 tells if a hash is empty More...
 
switch_hash_index_tswitch_core_hash_next (_In_ switch_hash_index_t **hi)
 Gets the next element of a hashtable. More...
 
void switch_core_hash_this (_In_ switch_hash_index_t *hi, _Out_opt_ptrdiff_cap_(klen) const void **key, _Out_opt_ switch_ssize_t *klen, _Out_ void **val)
 Gets the key and value of the current hash element. More...
 
void switch_core_hash_this_val (switch_hash_index_t *hi, void *val)
 
switch_status_t switch_core_inthash_init (switch_inthash_t **hash)
 
switch_status_t switch_core_inthash_destroy (switch_inthash_t **hash)
 
switch_status_t switch_core_inthash_insert (switch_inthash_t *hash, uint32_t key, const void *data)
 
void * switch_core_inthash_delete (switch_inthash_t *hash, uint32_t key)
 
void * switch_core_inthash_find (switch_inthash_t *hash, uint32_t key)
 
switch_status_t switch_core_timer_init (switch_timer_t *timer, const char *timer_name, int interval, int samples, switch_memory_pool_t *pool)
 Request a timer handle using given time module. More...
 
void switch_time_calibrate_clock (void)
 
switch_status_t switch_core_timer_next (switch_timer_t *timer)
 Wait for one cycle on an existing timer. More...
 
switch_status_t switch_core_timer_step (switch_timer_t *timer)
 Step the timer one step. More...
 
switch_status_t switch_core_timer_sync (switch_timer_t *timer)
 
switch_status_t switch_core_timer_check (switch_timer_t *timer, switch_bool_t step)
 Check if the current step has been exceeded. More...
 
switch_status_t switch_core_timer_destroy (switch_timer_t *timer)
 Destroy an allocated timer. More...
 
switch_status_t switch_core_codec_init_with_bitrate (switch_codec_t *codec, const char *codec_name, const char *fmtp, const char *modname, uint32_t rate, int ms, int channels, uint32_t bitrate, uint32_t flags, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool)
 
switch_status_t switch_core_codec_copy (switch_codec_t *codec, switch_codec_t *new_codec, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool)
 
switch_status_t switch_core_codec_parse_fmtp (const char *codec_name, const char *fmtp, uint32_t rate, switch_codec_fmtp_t *codec_fmtp)
 
switch_status_t switch_core_codec_reset (switch_codec_t *codec)
 
switch_status_t switch_core_codec_encode (switch_codec_t *codec, switch_codec_t *other_codec, void *decoded_data, uint32_t decoded_data_len, uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
 Encode data using a codec handle. More...
 
switch_status_t switch_core_codec_decode (switch_codec_t *codec, switch_codec_t *other_codec, void *encoded_data, uint32_t encoded_data_len, uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
 Decode data using a codec handle. More...
 
switch_status_t switch_core_codec_encode_video (switch_codec_t *codec, switch_frame_t *frame)
 Encode video data using a codec handle. More...
 
switch_status_t switch_core_codec_control (switch_codec_t *codec, switch_codec_control_command_t cmd, switch_codec_control_type_t ctype, void *cmd_data, switch_codec_control_type_t atype, void *cmd_arg, switch_codec_control_type_t *rtype, void **ret_data)
 send control data using a codec handle More...
 
switch_status_t switch_core_codec_decode_video (switch_codec_t *codec, switch_frame_t *frame)
 Decode video data using a codec handle. More...
 
switch_status_t switch_core_codec_destroy (switch_codec_t *codec)
 Destroy an initalized codec handle. More...
 
switch_status_t switch_core_session_set_read_codec (_In_ switch_core_session_t *session, switch_codec_t *codec)
 Assign the read codec to a given session. More...
 
switch_status_t switch_core_session_set_real_read_codec (_In_ switch_core_session_t *session, switch_codec_t *codec)
 Assign the original read codec to a given session. This is the read codec used by an endpoint. More...
 
void switch_core_session_unset_read_codec (_In_ switch_core_session_t *session)
 
void switch_core_session_unset_write_codec (_In_ switch_core_session_t *session)
 
void switch_core_session_lock_codec_write (_In_ switch_core_session_t *session)
 
void switch_core_session_unlock_codec_write (_In_ switch_core_session_t *session)
 
void switch_core_session_lock_codec_read (_In_ switch_core_session_t *session)
 
void switch_core_session_unlock_codec_read (_In_ switch_core_session_t *session)
 
switch_status_t switch_core_session_get_read_impl (switch_core_session_t *session, switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_get_real_read_impl (switch_core_session_t *session, switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_get_write_impl (switch_core_session_t *session, switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_get_video_read_impl (switch_core_session_t *session, switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_get_video_write_impl (switch_core_session_t *session, switch_codec_implementation_t *impp)
 
switch_codec_tswitch_core_session_get_read_codec (_In_ switch_core_session_t *session)
 Retrieve the read codec from a given session. More...
 
switch_codec_tswitch_core_session_get_effective_read_codec (_In_ switch_core_session_t *session)
 Retrieve the effevtive read codec from a given session. More...
 
switch_status_t switch_core_session_set_write_codec (_In_ switch_core_session_t *session, switch_codec_t *codec)
 Assign the write codec to a given session. More...
 
switch_codec_tswitch_core_session_get_write_codec (_In_ switch_core_session_t *session)
 Retrieve the write codec from a given session. More...
 
switch_codec_tswitch_core_session_get_effective_write_codec (_In_ switch_core_session_t *session)
 Retrieve the effevtive write codec from a given session. More...
 
switch_status_t switch_core_session_set_video_read_codec (_In_ switch_core_session_t *session, switch_codec_t *codec)
 Assign the video_read codec to a given session. More...
 
switch_codec_tswitch_core_session_get_video_read_codec (_In_ switch_core_session_t *session)
 Retrieve the video_read codec from a given session. More...
 
switch_status_t switch_core_session_set_video_write_codec (_In_ switch_core_session_t *session, switch_codec_t *codec)
 Assign the video_write codec to a given session. More...
 
switch_codec_tswitch_core_session_get_video_write_codec (_In_ switch_core_session_t *session)
 Retrieve the video_write codec from a given session. More...
 
switch_core_db_tswitch_core_db_open_file (const char *filename)
 Open a core db (SQLite) file. More...
 
switch_status_t switch_core_db_persistant_execute (switch_core_db_t *db, char *sql, uint32_t retries)
 Execute a sql stmt until it is accepted. More...
 
switch_status_t switch_core_db_persistant_execute_trans (switch_core_db_t *db, char *sql, uint32_t retries)
 
void switch_core_db_test_reactive (switch_core_db_t *db, char *test_sql, char *drop_sql, char *reactive_sql)
 perform a test query then perform a reactive query if the first one fails More...
 
switch_status_t switch_core_perform_file_open (const char *file, const char *func, int line, _In_ switch_file_handle_t *fh, _In_opt_z_ const char *file_path, _In_ uint32_t channels, _In_ uint32_t rate, _In_ unsigned int flags, _In_opt_ switch_memory_pool_t *pool)
 
switch_status_t switch_core_file_read (_In_ switch_file_handle_t *fh, void *data, switch_size_t *len)
 Read media from a file handle. More...
 
switch_status_t switch_core_file_write (_In_ switch_file_handle_t *fh, void *data, switch_size_t *len)
 Write media to a file handle. More...
 
switch_status_t switch_core_file_write_video (_In_ switch_file_handle_t *fh, switch_frame_t *frame)
 Write media to a file handle. More...
 
switch_status_t switch_core_file_read_video (switch_file_handle_t *fh, switch_frame_t *frame, switch_video_read_flag_t flags)
 
switch_status_t switch_core_file_seek (_In_ switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples, int whence)
 Seek a position in a file. More...
 
switch_status_t switch_core_file_set_string (_In_ switch_file_handle_t *fh, switch_audio_col_t col, const char *string)
 Set metadata to the desired string. More...
 
switch_status_t switch_core_file_get_string (_In_ switch_file_handle_t *fh, switch_audio_col_t col, const char **string)
 get metadata of the desired string More...
 
switch_status_t switch_core_file_close (_In_ switch_file_handle_t *fh)
 Close an open file handle. More...
 
switch_status_t switch_core_file_command (switch_file_handle_t *fh, switch_file_command_t command)
 
switch_status_t switch_core_file_truncate (switch_file_handle_t *fh, int64_t offset)
 
switch_bool_t switch_core_file_has_video (switch_file_handle_t *fh, switch_bool_t CHECK_OPEN)
 
switch_status_t switch_core_speech_open (_In_ switch_speech_handle_t *sh, const char *module_name, const char *voice_name, _In_ unsigned int rate, _In_ unsigned int interval, _In_ unsigned int channels, switch_speech_flag_t *flags, _In_opt_ switch_memory_pool_t *pool)
 Open a speech handle. More...
 
switch_status_t switch_core_speech_feed_tts (switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
 Feed text to the TTS module. More...
 
void switch_core_speech_flush_tts (switch_speech_handle_t *sh)
 Flush TTS audio on a given handle. More...
 
void switch_core_speech_text_param_tts (switch_speech_handle_t *sh, char *param, const char *val)
 Set a text parameter on a TTS handle. More...
 
void switch_core_speech_numeric_param_tts (switch_speech_handle_t *sh, char *param, int val)
 Set a numeric parameter on a TTS handle. More...
 
void switch_core_speech_float_param_tts (switch_speech_handle_t *sh, char *param, double val)
 Set a float parameter on a TTS handle. More...
 
switch_status_t switch_core_speech_read_tts (switch_speech_handle_t *sh, void *data, switch_size_t *datalen, switch_speech_flag_t *flags)
 Read rendered audio from the TTS module. More...
 
switch_status_t switch_core_speech_close (switch_speech_handle_t *sh, switch_speech_flag_t *flags)
 Close an open speech handle. More...
 
switch_status_t switch_core_asr_open (switch_asr_handle_t *ah, const char *module_name, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags, switch_memory_pool_t *pool)
 Open an asr handle. More...
 
switch_status_t switch_core_asr_close (switch_asr_handle_t *ah, switch_asr_flag_t *flags)
 Close an asr handle. More...
 
switch_status_t switch_core_asr_feed (switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
 Feed audio data to an asr handle. More...
 
switch_status_t switch_core_asr_feed_dtmf (switch_asr_handle_t *ah, const switch_dtmf_t *dtmf, switch_asr_flag_t *flags)
 Feed DTMF to an asr handle. More...
 
switch_status_t switch_core_asr_check_results (switch_asr_handle_t *ah, switch_asr_flag_t *flags)
 Check an asr handle for results. More...
 
switch_status_t switch_core_asr_get_results (switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags)
 Get results from an asr handle. More...
 
switch_status_t switch_core_asr_get_result_headers (switch_asr_handle_t *ah, switch_event_t **headers, switch_asr_flag_t *flags)
 Get result headers from an asr handle. More...
 
switch_status_t switch_core_asr_load_grammar (switch_asr_handle_t *ah, const char *grammar, const char *name)
 Load a grammar to an asr handle. More...
 
switch_status_t switch_core_asr_unload_grammar (switch_asr_handle_t *ah, const char *name)
 Unload a grammar from an asr handle. More...
 
switch_status_t switch_core_asr_enable_grammar (switch_asr_handle_t *ah, const char *name)
 Enable a grammar from an asr handle. More...
 
switch_status_t switch_core_asr_disable_grammar (switch_asr_handle_t *ah, const char *name)
 Disable a grammar from an asr handle. More...
 
switch_status_t switch_core_asr_disable_all_grammars (switch_asr_handle_t *ah)
 Disable all grammars from an asr handle. More...
 
switch_status_t switch_core_asr_pause (switch_asr_handle_t *ah)
 Pause detection on an asr handle. More...
 
switch_status_t switch_core_asr_resume (switch_asr_handle_t *ah)
 Resume detection on an asr handle. More...
 
switch_status_t switch_core_asr_start_input_timers (switch_asr_handle_t *ah)
 Start input timers on an asr handle. More...
 
void switch_core_asr_text_param (switch_asr_handle_t *ah, char *param, const char *val)
 Set a text parameter on an asr handle. More...
 
void switch_core_asr_numeric_param (switch_asr_handle_t *ah, char *param, int val)
 Set a numeric parameter on an asr handle. More...
 
void switch_core_asr_float_param (switch_asr_handle_t *ah, char *param, double val)
 Set a float parameter on an asr handle. More...
 
switch_status_t switch_core_directory_open (switch_directory_handle_t *dh, char *module_name, char *source, char *dsn, char *passwd, switch_memory_pool_t *pool)
 Open a directory handle. More...
 
switch_status_t switch_core_directory_query (switch_directory_handle_t *dh, char *base, char *query)
 Query a directory handle. More...
 
switch_status_t switch_core_directory_next (switch_directory_handle_t *dh)
 Obtain the next record in a lookup. More...
 
switch_status_t switch_core_directory_next_pair (switch_directory_handle_t *dh, char **var, char **val)
 Obtain the next name/value pair in the current record. More...
 
switch_status_t switch_core_directory_close (switch_directory_handle_t *dh)
 Close an open directory handle. More...
 
FILE * switch_core_data_channel (switch_text_channel_t channel)
 Retrieve a FILE stream of a given text channel name. More...
 
switch_bool_t switch_core_ready (void)
 Determines if the core is ready to take calls. More...
 
switch_bool_t switch_core_running (void)
 
switch_bool_t switch_core_ready_inbound (void)
 Determines if the core is ready to take inbound calls. More...
 
switch_bool_t switch_core_ready_outbound (void)
 Determines if the core is ready to place outbound calls. More...
 
switch_core_flag_t switch_core_flags (void)
 return core flags More...
 
switch_status_t switch_core_management_exec (char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
 Execute a management operation. More...
 
int32_t switch_core_set_process_privileges (void)
 Switch on the privilege awareness for the process and request required privileges. More...
 
int32_t set_normal_priority (void)
 Set the maximum priority the process can obtain. More...
 
int32_t set_auto_priority (void)
 
int32_t set_realtime_priority (void)
 
int32_t set_low_priority (void)
 
int32_t change_user_group (const char *user, const char *group)
 Change user and/or group of the running process. More...
 
void switch_core_runtime_loop (int bg)
 Run endlessly until the system is shutdown. More...
 
switch_status_t switch_core_set_console (const char *console)
 Set the output console to the desired file. More...
 
void switch_core_measure_time (switch_time_t total_ms, switch_core_time_duration_t *duration)
 Breakdown a number of milliseconds into various time spec. More...
 
switch_time_t switch_core_uptime (void)
 Number of microseconds the system has been up. More...
 
int32_t switch_core_session_ctl (switch_session_ctl_t cmd, void *val)
 send a control message to the core More...
 
FILE * switch_core_get_console (void)
 Get the output console. More...
 
switch_thread_tswitch_core_launch_thread (void *(SWITCH_THREAD_FUNC *func)(switch_thread_t *, void *), void *obj, switch_memory_pool_t *pool)
 Launch a thread. More...
 
void switch_core_set_globals (void)
 Initiate Globals. More...
 
uint8_t switch_core_session_compare (switch_core_session_t *a, switch_core_session_t *b)
 Checks if 2 sessions are using the same endpoint module. More...
 
uint8_t switch_core_session_check_interface (switch_core_session_t *session, const switch_endpoint_interface_t *endpoint_interface)
 Checks if a session is using a specific endpoint. More...
 
switch_status_t switch_core_session_set_video_read_callback (switch_core_session_t *session, switch_core_video_thread_callback_func_t func, void *user_data)
 
switch_status_t switch_core_session_video_read_callback (switch_core_session_t *session, switch_frame_t *frame)
 
switch_hash_index_tswitch_core_mime_index (void)
 
const char * switch_core_mime_ext2type (const char *ext)
 
const char * switch_core_mime_type2ext (const char *type)
 
switch_status_t switch_core_mime_add_type (const char *type, const char *ext)
 
switch_loadable_module_interface_tswitch_loadable_module_create_module_interface (switch_memory_pool_t *pool, const char *name)
 
void * switch_loadable_module_create_interface (switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname)
 
switch_time_t switch_micro_time_now (void)
 Get the current epoch time in microseconds. More...
 
switch_time_t switch_mono_micro_time_now (void)
 
void switch_core_memory_reclaim (void)
 
void switch_core_memory_reclaim_events (void)
 
void switch_core_memory_reclaim_logger (void)
 
void switch_core_memory_reclaim_all (void)
 
void switch_core_setrlimits (void)
 
switch_time_t switch_time_ref (void)
 
void switch_time_sync (void)
 
time_t switch_epoch_time_now (time_t *t)
 Get the current epoch time. More...
 
const char * switch_lookup_timezone (const char *tz_name)
 
switch_status_t switch_strftime_tz (const char *tz, const char *format, char *date, size_t len, switch_time_t thetime)
 
switch_status_t switch_time_exp_tz_name (const char *tz, switch_time_exp_t *tm, switch_time_t thetime)
 
void switch_load_network_lists (switch_bool_t reload)
 
switch_bool_t switch_check_network_list_ip_token (const char *ip_str, const char *list_name, const char **token)
 
void switch_time_set_monotonic (switch_bool_t enable)
 
void switch_time_set_timerfd (int enable)
 
void switch_time_set_nanosleep (switch_bool_t enable)
 
void switch_time_set_matrix (switch_bool_t enable)
 
void switch_time_set_cond_yield (switch_bool_t enable)
 
void switch_time_set_use_system_time (switch_bool_t enable)
 
uint32_t switch_core_min_dtmf_duration (uint32_t duration)
 
uint32_t switch_core_max_dtmf_duration (uint32_t duration)
 
double switch_core_min_idle_cpu (double new_limit)
 
double switch_core_idle_cpu (void)
 
uint32_t switch_core_default_dtmf_duration (uint32_t duration)
 
switch_status_t switch_console_set_complete (const char *string)
 
switch_status_t switch_console_set_alias (const char *string)
 
int switch_system (const char *cmd, switch_bool_t wait)
 
int switch_stream_system (const char *cmd, switch_stream_handle_t *stream)
 
void switch_cond_yield (switch_interval_time_t t)
 
void switch_cond_next (void)
 
switch_status_t switch_core_chat_send_args (const char *dest_proto, const char *proto, const char *from, const char *to, const char *subject, const char *body, const char *type, const char *hint, switch_bool_t blocking)
 
switch_status_t switch_core_chat_send (const char *dest_proto, switch_event_t *message_event)
 
switch_status_t switch_core_chat_deliver (const char *dest_proto, switch_event_t **message_event)
 
switch_status_t switch_ivr_preprocess_session (switch_core_session_t *session, const char *cmds)
 
void switch_core_sqldb_pause (void)
 
void switch_core_sqldb_resume (void)
 
static const char * switch_cache_db_type_name (switch_cache_db_handle_type_t type)
 
switch_cache_db_handle_type_t switch_cache_db_get_type (switch_cache_db_handle_t *dbh)
 
void switch_cache_db_dismiss_db_handle (switch_cache_db_handle_t **dbh)
 Returns the handle to the pool, immediately available for other threads to use. More...
 
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 actually terminates. More...
 
switch_status_t _switch_cache_db_get_db_handle (switch_cache_db_handle_t **dbh, switch_cache_db_handle_type_t type, switch_cache_db_connection_options_t *connection_options, const char *file, const char *func, int line)
 Gets a new cached handle from the pool, potentially creating a new connection. The connection is bound to the thread until it (the thread) terminates unless you dismiss rather than release. More...
 
switch_status_t _switch_cache_db_get_db_handle_dsn (switch_cache_db_handle_t **dbh, const char *dsn, const char *file, const char *func, int line)
 
switch_status_t switch_cache_db_create_schema (switch_cache_db_handle_t *dbh, char *sql, char **err)
 Executes the create schema sql. More...
 
char * switch_cache_db_execute_sql2str (switch_cache_db_handle_t *dbh, char *sql, char *str, size_t len, char **err)
 Executes the sql and returns the result as a string. More...
 
switch_status_t switch_cache_db_execute_sql (switch_cache_db_handle_t *dbh, char *sql, char **err)
 Executes the sql. More...
 
switch_status_t switch_cache_db_execute_sql_callback (switch_cache_db_handle_t *dbh, const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err)
 Executes the sql and uses callback for row-by-row processing. More...
 
switch_status_t switch_cache_db_execute_sql_callback_err (switch_cache_db_handle_t *dbh, const char *sql, switch_core_db_callback_func_t callback, switch_core_db_err_callback_func_t err_callback, void *pdata, char **err)
 Executes the sql and uses callback for row-by-row processing. More...
 
int switch_cache_db_affected_rows (switch_cache_db_handle_t *dbh)
 Get the affected rows of the last performed query. More...
 
int switch_cache_db_load_extension (switch_cache_db_handle_t *dbh, const char *extension)
 load an external extension to db More...
 
void switch_cache_db_status (switch_stream_handle_t *stream)
 Provides some feedback as to the status of the db connection pool. More...
 
switch_status_t _switch_core_db_handle (switch_cache_db_handle_t **dbh, const char *file, const char *func, int line)
 Open the default system database. More...
 
switch_bool_t switch_cache_db_test_reactive (switch_cache_db_handle_t *db, 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. More...
 
switch_status_t switch_cache_db_persistant_execute (switch_cache_db_handle_t *dbh, const char *sql, uint32_t retries)
 
switch_status_t switch_cache_db_persistant_execute_trans_full (switch_cache_db_handle_t *dbh, char *sql, uint32_t retries, const char *pre_trans_execute, const char *post_trans_execute, const char *inner_pre_trans_execute, const char *inner_post_trans_execute)
 
void switch_core_set_signal_handlers (void)
 
uint32_t switch_core_debug_level (void)
 
void switch_cache_db_flush_handles (void)
 
const char * switch_core_banner (void)
 
switch_bool_t switch_core_session_in_thread (switch_core_session_t *session)
 
uint32_t switch_default_ptime (const char *name, uint32_t number)
 
uint32_t switch_default_rate (const char *name, uint32_t number)
 
switch_status_t switch_core_add_registration (const char *user, const char *realm, const char *token, const char *url, uint32_t expires, const char *network_ip, const char *network_port, const char *network_proto, const char *metadata)
 Add user registration. More...
 
switch_status_t switch_core_del_registration (const char *user, const char *realm, const char *token)
 Delete user registration. More...
 
switch_status_t switch_core_expire_registration (int force)
 Expire user registrations. More...
 
uint16_t switch_core_get_rtp_port_range_start_port (void)
 Get RTP port range start value. More...
 
uint16_t switch_core_get_rtp_port_range_end_port (void)
 Get RTP port range end value. More...
 
char * switch_say_file_handle_get_variable (switch_say_file_handle_t *sh, const char *var)
 
char * switch_say_file_handle_get_path (switch_say_file_handle_t *sh)
 
char * switch_say_file_handle_detach_path (switch_say_file_handle_t *sh)
 
void switch_say_file_handle_destroy (switch_say_file_handle_t **sh)
 
switch_status_t switch_say_file_handle_create (switch_say_file_handle_t **sh, const char *ext, switch_event_t **var_event)
 
void switch_say_file (switch_say_file_handle_t *sh, const char *fmt,...)
 
int switch_max_file_desc (void)
 
void switch_close_extra_files (int *keep, int keep_ttl)
 
switch_status_t switch_core_thread_set_cpu_affinity (int cpu)
 
void switch_os_yield (void)
 
switch_status_t switch_core_get_stacksizes (switch_size_t *cur, switch_size_t *max)
 
void switch_core_gen_encoded_silence (unsigned char *data, const switch_codec_implementation_t *read_impl, switch_size_t len)
 
switch_cache_db_handle_type_t switch_core_dbtype (void)
 
void switch_core_sql_exec (const char *sql)
 
int switch_core_recovery_recover (const char *technology, const char *profile_name)
 
void switch_core_recovery_untrack (switch_core_session_t *session, switch_bool_t force)
 
void switch_core_recovery_track (switch_core_session_t *session)
 
void switch_core_recovery_flush (const char *technology, const char *profile_name)
 
void switch_sql_queue_manager_pause (switch_sql_queue_manager_t *qm, switch_bool_t flush)
 
void switch_sql_queue_manager_resume (switch_sql_queue_manager_t *qm)
 
int switch_sql_queue_manager_size (switch_sql_queue_manager_t *qm, uint32_t index)
 
switch_status_t switch_sql_queue_manager_push_confirm (switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
 
switch_status_t switch_sql_queue_manager_push (switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
 
switch_status_t switch_sql_queue_manager_destroy (switch_sql_queue_manager_t **qmp)
 
switch_status_t switch_sql_queue_manager_init_name (const char *name, switch_sql_queue_manager_t **qmp, uint32_t numq, const char *dsn, uint32_t max_trans, const char *pre_trans_execute, const char *post_trans_execute, const char *inner_pre_trans_execute, const char *inner_post_trans_execute)
 
switch_status_t switch_sql_queue_manager_start (switch_sql_queue_manager_t *qm)
 
switch_status_t switch_sql_queue_manager_stop (switch_sql_queue_manager_t *qm)
 
switch_status_t switch_cache_db_execute_sql_event_callback (switch_cache_db_handle_t *dbh, const char *sql, switch_core_db_event_callback_func_t callback, void *pdata, char **err)
 
void switch_sql_queue_manager_execute_sql_callback (switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_callback_func_t callback, void *pdata)
 
void switch_sql_queue_manager_execute_sql_callback_err (switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_callback_func_t callback, switch_core_db_err_callback_func_t err_callback, void *pdata)
 
void switch_sql_queue_manager_execute_sql_event_callback (switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_event_callback_func_t callback, void *pdata)
 
void switch_sql_queue_manager_execute_sql_event_callback_err (switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_event_callback_func_t callback, switch_core_db_err_callback_func_t err_callback, void *pdata)
 
pid_t switch_fork (void)
 
int switch_core_gen_certs (const char *prefix)
 
int switch_core_cert_gen_fingerprint (const char *prefix, dtls_fingerprint_t *fp)
 
int switch_core_cert_expand_fingerprint (dtls_fingerprint_t *fp, const char *str)
 
int switch_core_cert_verify (dtls_fingerprint_t *fp)
 
switch_status_t switch_core_session_request_video_refresh (switch_core_session_t *session)
 
switch_status_t switch_core_session_send_and_request_video_refresh (switch_core_session_t *session)
 
int switch_stream_system_fork (const char *cmd, switch_stream_handle_t *stream)
 
switch_call_direction_t switch_ice_direction (switch_core_session_t *session)
 
void switch_core_session_debug_pool (switch_stream_handle_t *stream)
 
const char * switch_version_major (void)
 
const char * switch_version_minor (void)
 
const char * switch_version_micro (void)
 
const char * switch_version_revision (void)
 
const char * switch_version_revision_human (void)
 
const char * switch_version_full (void)
 
const char * switch_version_full_human (void)
 
void switch_core_autobind_cpu (void)
 

Detailed Description

Core Library.

This module is the main core library and is the intended location of all fundamental operations.

Definition in file switch_core.h.

Macro Definition Documentation

#define CACHE_DB_LEN   256

Definition at line 2440 of file switch_core.h.

Referenced by _switch_cache_db_get_db_handle(), and switch_cache_db_status().

#define DTLS_SRTP_FNAME   "dtls-srtp"
#define MAX_FPLEN   64

Definition at line 147 of file switch_core.h.

Referenced by switch_core_cert_expand_fingerprint(), and switch_core_cert_verify().

#define MAX_FPSTRLEN   192

Definition at line 148 of file switch_core.h.

#define MESSAGE_STAMP_FFL (   _m)    _m->_file = __FILE__; _m->_func = __SWITCH_FUNC__; _m->_line = __LINE__
#define MESSAGE_STRING_ARG_MAX   10

Definition at line 175 of file switch_core.h.

Referenced by switch_core_session_free_message().

#define switch_cache_db_get_db_handle (   _a,
  _b,
  _c 
)    _switch_cache_db_get_db_handle(_a, _b, _c, __FILE__, __SWITCH_FUNC__, __LINE__)

Definition at line 2532 of file switch_core.h.

#define switch_cache_db_get_db_handle_dsn (   _a,
  _b 
)    _switch_cache_db_get_db_handle_dsn(_a, _b, __FILE__, __SWITCH_FUNC__, __LINE__)
#define switch_cache_db_persistant_execute_trans (   _d,
  _s,
  _r 
)    switch_cache_db_persistant_execute_trans_full(_d, _s, _r, NULL, NULL, NULL, NULL)

Definition at line 2616 of file switch_core.h.

#define switch_core_db_handle (   _a)    _switch_core_db_handle(_a, __FILE__, __SWITCH_FUNC__, __LINE__)
#define SWITCH_MAX_CORE_THREAD_SESSION_OBJS   128

Definition at line 46 of file switch_core.h.

#define SWITCH_MAX_STREAMS   128

Definition at line 47 of file switch_core.h.

#define switch_sql_queue_manager_init (   _q,
  _n,
  _d,
  _m,
  _p1,
  _p2,
  _ip1,
  _ip2 
)    switch_sql_queue_manager_init_name(__FILE__, _q, _n, _d, _m, _p1, _p2, _ip1, _ip2)

Definition at line 2706 of file switch_core.h.

Typedef Documentation

typedef struct dtls_fp_s dtls_fingerprint_t

Definition at line 2479 of file switch_core.h.

typedef int(* switch_core_db_event_callback_func_t)(void *pArg, switch_event_t *event)

Definition at line 2438 of file switch_core.h.

typedef void(* switch_device_state_function_t)(switch_core_session_t *session, switch_channel_callstate_t callstate, switch_device_record_t *drec)

Definition at line 143 of file switch_core.h.

Enumeration Type Documentation

Enumerator
CDF_INUSE 
CDF_PRUNE 

Definition at line 2441 of file switch_core.h.

2441  {
2442  CDF_INUSE = (1 << 0),
2443  CDF_PRUNE = (1 << 1)
2444 } cache_db_flag_t;
cache_db_flag_t
Definition: switch_core.h:2441
Enumerator
DS_OFF 
DS_HANDSHAKE 
DS_SETUP 
DS_READY 
DS_FAIL 
DS_INVALID 

Definition at line 164 of file switch_core.h.

164  {
165  DS_OFF,
166  DS_HANDSHAKE,
167  DS_SETUP,
168  DS_READY,
169  DS_FAIL,
170  DS_INVALID,
171 } dtls_state_t;
dtls_state_t
Definition: switch_core.h:164
Enumerator
DTLS_TYPE_CLIENT 
DTLS_TYPE_SERVER 
DTLS_TYPE_RTP 
DTLS_TYPE_RTCP 

Definition at line 157 of file switch_core.h.

157  {
158  DTLS_TYPE_CLIENT = (1 << 0),
159  DTLS_TYPE_SERVER = (1 << 1),
160  DTLS_TYPE_RTP = (1 << 2),
161  DTLS_TYPE_RTCP = (1 << 3)
162 } dtls_type_t;
dtls_type_t
Definition: switch_core.h:157
Enumerator
SCDB_TYPE_CORE_DB 
SCDB_TYPE_ODBC 
SCDB_TYPE_PGSQL 

Definition at line 2446 of file switch_core.h.

Function Documentation

switch_status_t _switch_cache_db_get_db_handle ( switch_cache_db_handle_t **  dbh,
switch_cache_db_handle_type_t  type,
switch_cache_db_connection_options_t connection_options,
const char *  file,
const char *  func,
int  line 
)

Gets a new cached handle from the pool, potentially creating a new connection. The connection is bound to the thread until it (the thread) terminates unless you dismiss rather than release.

Parameters
[out]dbhThe handle
[in]type- ODBC or SQLLITE
[in]connection_options(userid, password, etc)

Definition at line 384 of file switch_core_sqldb.c.

References add_handle(), CACHE_DB_LEN, switch_cache_db_native_handle_t::core_db_dbh, create_handle(), switch_runtime::db_handle_timeout, get_handle(), switch_cache_db_handle::last_used, switch_runtime::max_db_handles, switch_cache_db_handle::name, switch_cache_db_handle::native_handle, switch_cache_db_native_handle_t::odbc_dbh, switch_cache_db_native_handle_t::pgsql_dbh, runtime, SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_PGSQL, sql_manager, switch_cache_db_type_name(), SWITCH_CHANNEL_ID_LOG, SWITCH_CHANNEL_LOG, switch_core_db_open_file(), switch_epoch_time_now(), SWITCH_LOG_CRIT, SWITCH_LOG_DEBUG10, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, switch_odbc_available(), switch_odbc_handle_connect(), switch_odbc_handle_destroy(), switch_odbc_handle_new(), SWITCH_ODBC_SUCCESS, switch_pgsql_available(), switch_pgsql_handle_connect(), switch_pgsql_handle_destroy(), switch_pgsql_handle_new(), SWITCH_PGSQL_SUCCESS, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_thread_self(), switch_yield, and switch_cache_db_handle::type.

Referenced by _switch_cache_db_get_db_handle_dsn().

388 {
390  char thread_str[CACHE_DB_LEN] = "";
391  char db_str[CACHE_DB_LEN] = "";
392  char db_callsite_str[CACHE_DB_LEN] = "";
393  switch_cache_db_handle_t *new_dbh = NULL;
394  int waiting = 0;
395  uint32_t yield_len = 100000, total_yield = 0;
396 
397  const char *db_name = NULL;
398  const char *odbc_user = NULL;
399  const char *odbc_pass = NULL;
400  const char *db_type = NULL;
401 
402  while(runtime.max_db_handles && sql_manager.total_handles >= runtime.max_db_handles && sql_manager.total_used_handles >= sql_manager.total_handles) {
403  if (!waiting++) {
404  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_WARNING, "Max handles %u exceeded, blocking....\n",
406  }
407 
408  switch_yield(yield_len);
409  total_yield += yield_len;
410 
411  if (runtime.db_handle_timeout && total_yield > runtime.db_handle_timeout) {
412  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "Error connecting\n");
413  *dbh = NULL;
414  return SWITCH_STATUS_FALSE;
415  }
416  }
417 
418  switch (type) {
419  case SCDB_TYPE_PGSQL:
420  {
421  db_name = connection_options->pgsql_options.dsn;
422  odbc_user = NULL;
423  odbc_pass = NULL;
424  db_type = "pgsql";
425  }
426  case SCDB_TYPE_ODBC:
427  {
428  db_name = connection_options->odbc_options.dsn;
429  odbc_user = connection_options->odbc_options.user;
430  odbc_pass = connection_options->odbc_options.pass;
431  db_type = "odbc";
432  }
433  break;
434  case SCDB_TYPE_CORE_DB:
435  {
436  db_name = connection_options->core_db_options.db_path;
437  odbc_user = NULL;
438  odbc_pass = NULL;
439  db_type = "core_db";
440  }
441  break;
442  }
443 
444  if (!db_name) {
445  return SWITCH_STATUS_FALSE;
446  }
447 
448  if (odbc_user || odbc_pass) {
449  snprintf(db_str, sizeof(db_str) - 1, "db=\"%s\";type=\"%s\"user=\"%s\";pass=\"%s\"", db_name, db_type, odbc_user, odbc_pass);
450  } else {
451  snprintf(db_str, sizeof(db_str) - 1, "db=\"%s\",type=\"%s\"", db_name, db_type);
452  }
453  snprintf(db_callsite_str, sizeof(db_callsite_str) - 1, "%s:%d", file, line);
454  snprintf(thread_str, sizeof(thread_str) - 1, "thread=\"%lu\"", (unsigned long) (intptr_t) self);
455 
456  if ((new_dbh = get_handle(db_str, db_callsite_str, thread_str))) {
458  "Reuse Unused Cached DB handle %s [%s]\n", new_dbh->name, switch_cache_db_type_name(new_dbh->type));
459  } else {
460  switch_core_db_t *db = NULL;
461  switch_odbc_handle_t *odbc_dbh = NULL;
462  switch_pgsql_handle_t *pgsql_dbh = NULL;
463 
464  switch (type) {
465  case SCDB_TYPE_PGSQL:
466  {
467  if (!switch_pgsql_available()) {
468  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure! PGSQL NOT AVAILABLE! Can't connect to DSN %s\n", connection_options->pgsql_options.dsn);
469  goto end;
470  }
471 
472  if ((pgsql_dbh = switch_pgsql_handle_new(connection_options->pgsql_options.dsn))) {
474  switch_pgsql_handle_destroy(&pgsql_dbh);
475  }
476  }
477  }
478  break;
479  case SCDB_TYPE_ODBC:
480  {
481 
482  if (!switch_odbc_available()) {
483  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure! ODBC NOT AVAILABLE! Can't connect to DSN %s\n", connection_options->odbc_options.dsn);
484  goto end;
485  }
486 
487  if ((odbc_dbh = switch_odbc_handle_new(connection_options->odbc_options.dsn,
488  connection_options->odbc_options.user, connection_options->odbc_options.pass))) {
490  switch_odbc_handle_destroy(&odbc_dbh);
491  }
492  }
493 
494 
495  }
496  break;
497  case SCDB_TYPE_CORE_DB:
498  {
499  db = switch_core_db_open_file(connection_options->core_db_options.db_path);
500  }
501  break;
502 
503  default:
504  goto end;
505  }
506 
507  if (!db && !odbc_dbh && !pgsql_dbh) {
508  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure to connect to %s %s!\n", switch_cache_db_type_name(type), db_name);
509  goto end;
510  }
511 
512  new_dbh = create_handle(type);
513 
515  "Create Cached DB handle %s [%s] %s:%d\n", new_dbh->name, switch_cache_db_type_name(type), file, line);
516 
517  if (db) {
518  new_dbh->native_handle.core_db_dbh = db;
519  } else if (odbc_dbh) {
520  new_dbh->native_handle.odbc_dbh = odbc_dbh;
521  } else {
522  new_dbh->native_handle.pgsql_dbh = pgsql_dbh;
523  }
524 
525  add_handle(new_dbh, db_str, db_callsite_str, thread_str);
526  }
527 
528  end:
529 
530  if (new_dbh) {
531  new_dbh->last_used = switch_epoch_time_now(NULL);
532  }
533 
534  *dbh = new_dbh;
535 
537 }
switch_cache_db_native_handle_t native_handle
char name[CACHE_DB_LEN]
switch_bool_t switch_pgsql_available(void)
Definition: switch_pgsql.c:819
#define SWITCH_CHANNEL_LOG
struct switch_odbc_handle switch_odbc_handle_t
static switch_cache_db_handle_t * create_handle(switch_cache_db_handle_type_t type)
switch_cache_db_handle_type_t type
switch_cache_db_core_db_options_t core_db_options
Definition: switch_core.h:2473
struct switch_pgsql_handle switch_pgsql_handle_t
void switch_odbc_handle_destroy(switch_odbc_handle_t **handlep)
Definition: switch_odbc.c:671
static const char * switch_cache_db_type_name(switch_cache_db_handle_type_t type)
Definition: switch_core.h:2481
struct switch_runtime runtime
Definition: switch_core.c:64
static void add_handle(switch_cache_db_handle_t *dbh, const char *db_str, const char *db_callsite_str, const char *thread_str)
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
#define CACHE_DB_LEN
Definition: switch_core.h:2440
switch_bool_t switch_odbc_available(void)
Definition: switch_odbc.c:738
uint32_t db_handle_timeout
pthread_t switch_thread_id_t
Definition: switch_apr.h:51
switch_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2454
switch_cache_db_odbc_options_t odbc_options
Definition: switch_core.h:2474
static switch_cache_db_handle_t * get_handle(const char *db_str, const char *user_str, const char *thread_str)
switch_core_db_t * core_db_dbh
Definition: switch_core.h:2453
switch_pgsql_handle_t * pgsql_dbh
Definition: switch_core.h:2455
struct sqlite3 switch_core_db_t
switch_cache_db_pgsql_options_t pgsql_options
Definition: switch_core.h:2475
switch_odbc_status_t switch_odbc_handle_connect(switch_odbc_handle_t *handle)
Definition: switch_odbc.c:336
uint32_t max_db_handles
switch_pgsql_handle_t * switch_pgsql_handle_new(const char *dsn)
Create a new handle for the PGSQL connection.
Definition: switch_pgsql.c:66
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
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_thread_id_t switch_thread_self(void)
Definition: switch_apr.c:79
void switch_pgsql_handle_destroy(switch_pgsql_handle_t **handlep)
Definition: switch_pgsql.c:764
switch_odbc_handle_t * switch_odbc_handle_new(const char *dsn, const char *username, const char *password)
Definition: switch_odbc.c:65
switch_core_db_t * switch_core_db_open_file(const char *filename)
Open a core db (SQLite) file.
switch_pgsql_status_t switch_pgsql_handle_connect(switch_pgsql_handle_t *handle)
Connect to the database specified by the DSN passed to the switch_pgsql_handle_new() call which initi...
Definition: switch_pgsql.c:489
static struct @3 sql_manager
switch_status_t _switch_cache_db_get_db_handle_dsn ( switch_cache_db_handle_t **  dbh,
const char *  dsn,
const char *  file,
const char *  func,
int  line 
)

Definition at line 335 of file switch_core_sqldb.c.

References _switch_cache_db_get_db_handle(), switch_cache_db_connection_options_t::core_db_options, switch_cache_db_core_db_options_t::db_path, switch_cache_db_odbc_options_t::dsn, switch_cache_db_pgsql_options_t::dsn, switch_cache_db_connection_options_t::odbc_options, switch_cache_db_odbc_options_t::pass, switch_cache_db_connection_options_t::pgsql_options, SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_PGSQL, switch_set_string, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_cache_db_odbc_options_t::user.

Referenced by _switch_core_db_handle().

337 {
338  switch_cache_db_connection_options_t connection_options = { {0} };
340  char tmp[256] = "";
341  char *p;
343  int i;
344 
345  if (!strncasecmp(dsn, "pgsql://", 8)) {
346  type = SCDB_TYPE_PGSQL;
347  connection_options.pgsql_options.dsn = (char *)(dsn + 8);
348  } else if (!strncasecmp(dsn, "sqlite://", 9)) {
349  type = SCDB_TYPE_CORE_DB;
350  connection_options.core_db_options.db_path = (char *)(dsn + 9);
351  } else if ((!(i = strncasecmp(dsn, "odbc://", 7))) || strchr(dsn+2, ':')) {
352  type = SCDB_TYPE_ODBC;
353 
354  if (i) {
355  switch_set_string(tmp, dsn);
356  } else {
357  switch_set_string(tmp, dsn+7);
358  }
359 
360  connection_options.odbc_options.dsn = tmp;
361 
362  if ((p = strchr(tmp, ':'))) {
363  *p++ = '\0';
364  connection_options.odbc_options.user = p;
365 
366  if ((p = strchr(connection_options.odbc_options.user, ':'))) {
367  *p++ = '\0';
368  connection_options.odbc_options.pass = p;
369  }
370  }
371  } else {
372  type = SCDB_TYPE_CORE_DB;
373  connection_options.core_db_options.db_path = (char *)dsn;
374  }
375 
376  status = _switch_cache_db_get_db_handle(dbh, type, &connection_options, file, func, line);
377 
378  if (status != SWITCH_STATUS_SUCCESS) *dbh = NULL;
379 
380  return status;
381 }
switch_cache_db_core_db_options_t core_db_options
Definition: switch_core.h:2473
switch_cache_db_handle_type_t
Definition: switch_core.h:2446
switch_cache_db_odbc_options_t odbc_options
Definition: switch_core.h:2474
switch_status_t
Common return values.
switch_cache_db_pgsql_options_t pgsql_options
Definition: switch_core.h:2475
#define switch_set_string(_dst, _src)
Definition: switch_utils.h:665
switch_status_t _switch_cache_db_get_db_handle(switch_cache_db_handle_t **dbh, switch_cache_db_handle_type_t type, switch_cache_db_connection_options_t *connection_options, const char *file, const char *func, int line)
Gets a new cached handle from the pool, potentially creating a new connection. The connection is boun...
switch_status_t _switch_core_db_handle ( switch_cache_db_handle_t **  dbh,
const char *  file,
const char *  func,
int  line 
)

Open the default system database.

Definition at line 184 of file switch_core_sqldb.c.

References _switch_cache_db_get_db_handle_dsn(), switch_runtime::dbname, switch_runtime::odbc_dsn, runtime, sql_manager, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

185 {
186  switch_status_t r;
187  char *dsn;
188 
189  if (!sql_manager.manage) {
190  return SWITCH_STATUS_FALSE;
191  }
192 
193  if (!zstr(runtime.odbc_dsn)) {
194  dsn = runtime.odbc_dsn;
195  } else if (!zstr(runtime.dbname)) {
196  dsn = runtime.dbname;
197  } else {
198  dsn = "core";
199  }
200 
201  if ((r = _switch_cache_db_get_db_handle_dsn(dbh, dsn, file, func, line)) != SWITCH_STATUS_SUCCESS) {
202  *dbh = NULL;
203  }
204 
205  return r;
206 }
struct switch_runtime runtime
Definition: switch_core.c:64
#define zstr(x)
Definition: switch_utils.h:281
switch_status_t _switch_cache_db_get_db_handle_dsn(switch_cache_db_handle_t **dbh, const char *dsn, const char *file, const char *func, int line)
switch_status_t
Common return values.
static struct @3 sql_manager
int switch_cache_db_affected_rows ( switch_cache_db_handle_t dbh)

Get the affected rows of the last performed query.

Parameters
[in]dbhThe handle
[out]thenumber of affected rows

Definition at line 688 of file switch_core_sqldb.c.

References SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_PGSQL, switch_core_db_changes(), switch_odbc_handle_affected_rows(), and switch_pgsql_handle_affected_rows().

689 {
690  switch (dbh->type) {
691  case SCDB_TYPE_CORE_DB:
692  {
694  }
695  break;
696  case SCDB_TYPE_ODBC:
697  {
699  }
700  break;
701  case SCDB_TYPE_PGSQL:
702  {
704  }
705  break;
706  }
707  return 0;
708 }
switch_cache_db_native_handle_t native_handle
switch_cache_db_handle_type_t type
int switch_odbc_handle_affected_rows(switch_odbc_handle_t *handle)
Definition: switch_odbc.c:729
switch_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2454
switch_core_db_t * core_db_dbh
Definition: switch_core.h:2453
switch_pgsql_handle_t * pgsql_dbh
Definition: switch_core.h:2455
int switch_pgsql_handle_affected_rows(switch_pgsql_handle_t *handle)
Definition: switch_pgsql.c:810
int switch_core_db_changes(switch_core_db_t *db)
switch_status_t switch_cache_db_create_schema ( switch_cache_db_handle_t dbh,
char *  sql,
char **  err 
)

Executes the create schema sql.

Parameters
[in]dbhThe handle
[in]sql- sql to run
[out]err- Error if it exists

Definition at line 1271 of file switch_core_sqldb.c.

References runtime, SCF_AUTO_SCHEMAS, switch_assert, switch_cache_db_execute_sql(), SWITCH_STATUS_SUCCESS, and switch_test_flag.

Referenced by switch_core_sqldb_start().

1272 {
1274 
1275  switch_assert(sql != NULL);
1276 
1278  r = switch_cache_db_execute_sql(dbh, sql, err);
1279  }
1280 
1281  return r;
1282 }
struct switch_runtime runtime
Definition: switch_core.c:64
switch_status_t
Common return values.
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
switch_status_t switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err)
Executes the sql.
#define switch_assert(expr)
void switch_cache_db_dismiss_db_handle ( switch_cache_db_handle_t **  dbh)

Returns the handle to the pool, immediately available for other threads to use.

Parameters
[in]Thehandle

Definition at line 329 of file switch_core_sqldb.c.

References switch_cache_db_release_db_handle().

330 {
332 }
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 switch_cache_db_execute_sql ( switch_cache_db_handle_t dbh,
char *  sql,
char **  err 
)

Executes the sql.

Parameters
[in]dbhThe handle
[in]sql- sql to run
[out]err- Error if it exists

Definition at line 666 of file switch_core_sqldb.c.

References io_mutex, switch_cache_db_execute_sql_chunked(), switch_mutex_lock(), switch_mutex_unlock(), and SWITCH_STATUS_FALSE.

Referenced by do_flush(), do_trans(), switch_cache_db_create_schema(), switch_cache_db_persistant_execute_trans_full(), switch_cache_db_test_reactive(), switch_core_recovery_flush(), switch_core_recovery_recover(), switch_core_sqldb_start(), switch_sql_queue_manager_push_confirm(), and switch_user_sql_thread().

667 {
670 
671  if (io_mutex) switch_mutex_lock(io_mutex);
672 
673  switch (dbh->type) {
674  default:
675  {
676  status = switch_cache_db_execute_sql_chunked(dbh, (char *) sql, 32768, err);
677  }
678  break;
679  }
680 
681  if (io_mutex) switch_mutex_unlock(io_mutex);
682 
683  return status;
684 
685 }
switch_mutex_t * io_mutex
switch_cache_db_handle_type_t type
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
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_status_t
Common return values.
switch_mutex_t * io_mutex
static switch_status_t switch_cache_db_execute_sql_chunked(switch_cache_db_handle_t *dbh, char *sql, uint32_t chunk_size, char **err)
char* switch_cache_db_execute_sql2str ( switch_cache_db_handle_t dbh,
char *  sql,
char *  str,
size_t  len,
char **  err 
)

Executes the sql and returns the result as a string.

Parameters
[in]dbhThe handle
[in]sql- sql to run
[out]str- buffer for result
[in]len- length of str buffer
[out]err- Error if it exists

Definition at line 734 of file switch_core_sqldb.c.

References io_mutex, memset(), running, SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_PGSQL, SWITCH_CHANNEL_LOG, switch_cond_next(), switch_copy_string(), SWITCH_CORE_DB_BUSY, switch_core_db_column_count(), switch_core_db_column_text(), switch_core_db_finalize(), switch_core_db_prepare(), SWITCH_CORE_DB_ROW, switch_core_db_step(), SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_odbc_handle_exec_string(), switch_pgsql_handle_exec_string, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

735 {
738 
739  if (io_mutex) switch_mutex_lock(io_mutex);
740 
741  memset(str, 0, len);
742 
743  switch (dbh->type) {
744  case SCDB_TYPE_CORE_DB:
745  {
746  switch_core_db_stmt_t *stmt;
747 
748  if (switch_core_db_prepare(dbh->native_handle.core_db_dbh, sql, -1, &stmt, 0)) {
749  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Statement Error [%s]!\n", sql);
750  goto end;
751  } else {
752  int running = 1;
753  int colcount;
754 
755  while (running < 5000) {
756  int result = switch_core_db_step(stmt);
757  const unsigned char *txt;
758 
759  if (result == SWITCH_CORE_DB_ROW) {
760  if ((colcount = switch_core_db_column_count(stmt)) > 0) {
761  if ((txt = switch_core_db_column_text(stmt, 0))) {
762  switch_copy_string(str, (char *) txt, len);
763  status = SWITCH_STATUS_SUCCESS;
764  } else {
765  goto end;
766  }
767  }
768  break;
769  } else if (result == SWITCH_CORE_DB_BUSY) {
770  running++;
772  continue;
773  }
774  break;
775  }
776 
778  }
779  }
780  break;
781  case SCDB_TYPE_ODBC:
782  {
783  status = switch_odbc_handle_exec_string(dbh->native_handle.odbc_dbh, sql, str, len, err);
784  }
785  break;
786  case SCDB_TYPE_PGSQL:
787  {
788  status = switch_pgsql_handle_exec_string(dbh->native_handle.pgsql_dbh, sql, str, len, err);
789  }
790  break;
791  }
792 
793  end:
794 
795  if (io_mutex) switch_mutex_unlock(io_mutex);
796 
797  return status == SWITCH_STATUS_SUCCESS ? str : NULL;
798 
799 }
switch_cache_db_native_handle_t native_handle
switch_odbc_status_t switch_odbc_handle_exec_string(switch_odbc_handle_t *handle, const char *sql, char *resbuf, size_t len, char **err)
Definition: switch_odbc.c:405
switch_mutex_t * io_mutex
#define SWITCH_CHANNEL_LOG
switch_cache_db_handle_type_t type
#define SWITCH_CORE_DB_BUSY
int switch_core_db_finalize(switch_core_db_stmt_t *pStmt)
int switch_core_db_step(switch_core_db_stmt_t *stmt)
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
#define switch_pgsql_handle_exec_string(handle, sql, resbuf, len, err)
Definition: switch_pgsql.h:121
void switch_cond_next(void)
Definition: switch_time.c:638
switch_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2454
char * switch_copy_string(_Out_z_cap_(dst_size) char *dst, _In_z_ const char *src, _In_ switch_size_t dst_size)
static int32_t running
switch_core_db_t * core_db_dbh
Definition: switch_core.h:2453
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_status_t
Common return values.
switch_pgsql_handle_t * pgsql_dbh
Definition: switch_core.h:2455
struct sqlite3_stmt switch_core_db_stmt_t
#define SWITCH_CORE_DB_ROW
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.
int switch_core_db_column_count(switch_core_db_stmt_t *pStmt)
const unsigned char * switch_core_db_column_text(switch_core_db_stmt_t *stmt, int iCol)
switch_mutex_t * io_mutex
memset(buf, 0, buflen)
int switch_core_db_prepare(switch_core_db_t *db, const char *zSql, int nBytes, switch_core_db_stmt_t **ppStmt, const char **pzTail)
switch_status_t switch_cache_db_execute_sql_callback ( switch_cache_db_handle_t dbh,
const char *  sql,
switch_core_db_callback_func_t  callback,
void *  pdata,
char **  err 
)

Executes the sql and uses callback for row-by-row processing.

Parameters
[in]dbhThe handle
[in]sql- sql to run
[in]callback- function pointer to callback
[in]pdata- data to pass to callback
[out]err- Error if it exists

Definition at line 1161 of file switch_core_sqldb.c.

References io_mutex, SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_PGSQL, SQL_CACHE_TIMEOUT, SWITCH_CHANNEL_LOG, SWITCH_CORE_DB_ABORT, switch_core_db_exec(), switch_core_db_free(), SWITCH_CORE_DB_OK, switch_epoch_time_now(), SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_odbc_handle_callback_exec, switch_pgsql_handle_callback_exec, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by sql_in_thread(), switch_console_complete(), switch_console_expand_alias(), switch_console_list_uuid(), and switch_core_recovery_recover().

1163 {
1165  char *errmsg = NULL;
1167 
1168  if (err) {
1169  *err = NULL;
1170  }
1171 
1172  if (io_mutex) switch_mutex_lock(io_mutex);
1173 
1174 
1175  switch (dbh->type) {
1176  case SCDB_TYPE_PGSQL:
1177  {
1178  status = switch_pgsql_handle_callback_exec(dbh->native_handle.pgsql_dbh, sql, callback, pdata, err);
1179  }
1180  break;
1181  case SCDB_TYPE_ODBC:
1182  {
1183  status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, callback, pdata, err);
1184  }
1185  break;
1186  case SCDB_TYPE_CORE_DB:
1187  {
1188  int ret = switch_core_db_exec(dbh->native_handle.core_db_dbh, sql, callback, pdata, &errmsg);
1189 
1190  if (ret == SWITCH_CORE_DB_OK || ret == SWITCH_CORE_DB_ABORT) {
1191  status = SWITCH_STATUS_SUCCESS;
1192  }
1193 
1194  if (errmsg) {
1195  dbh->last_used = switch_epoch_time_now(NULL) - (SQL_CACHE_TIMEOUT * 2);
1196  if (!strstr(errmsg, "query abort")) {
1197  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
1198  }
1199  switch_core_db_free(errmsg);
1200  }
1201  }
1202  break;
1203  }
1204 
1205  if (io_mutex) switch_mutex_unlock(io_mutex);
1206 
1207  return status;
1208 }
switch_cache_db_native_handle_t native_handle
switch_mutex_t * io_mutex
#define SWITCH_CHANNEL_LOG
switch_cache_db_handle_type_t type
#define SQL_CACHE_TIMEOUT
int switch_core_db_exec(switch_core_db_t *db, const char *sql, switch_core_db_callback_func_t callback, void *data, char **errmsg)
#define SWITCH_CORE_DB_OK
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_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2454
#define switch_odbc_handle_callback_exec(handle,sql,callback, pdata, err)
Execute the sql query and issue a callback for each row returned.
Definition: switch_odbc.h:92
#define switch_pgsql_handle_callback_exec(handle,sql,callback, pdata, err)
Execute the sql query and issue a callback for each row returned.
Definition: switch_pgsql.h:151
switch_core_db_t * core_db_dbh
Definition: switch_core.h:2453
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_status_t
Common return values.
switch_pgsql_handle_t * pgsql_dbh
Definition: switch_core.h:2455
#define SWITCH_CORE_DB_ABORT
void switch_core_db_free(char *z)
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
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_mutex_t * io_mutex
switch_status_t switch_cache_db_execute_sql_callback_err ( switch_cache_db_handle_t dbh,
const char *  sql,
switch_core_db_callback_func_t  callback,
switch_core_db_err_callback_func_t  err_callback,
void *  pdata,
char **  err 
)

Executes the sql and uses callback for row-by-row processing.

Parameters
[in]dbhThe handle
[in]sql- sql to run
[in]callback- function pointer to callback
[in]err_callback- function pointer to callback when error occurs
[in]pdata- data to pass to callback
[out]err- Error if it exists

Definition at line 1210 of file switch_core_sqldb.c.

References io_mutex, helper::pdata, SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_PGSQL, SQL_CACHE_TIMEOUT, SWITCH_CHANNEL_LOG, SWITCH_CORE_DB_ABORT, switch_core_db_exec(), switch_core_db_free(), SWITCH_CORE_DB_OK, switch_epoch_time_now(), SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_odbc_handle_callback_exec, switch_pgsql_handle_callback_exec, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by sql_in_thread().

1213 {
1215  char *errmsg = NULL;
1217 
1218  if (err) {
1219  *err = NULL;
1220  }
1221 
1222  if (io_mutex) switch_mutex_lock(io_mutex);
1223 
1224 
1225  switch (dbh->type) {
1226  case SCDB_TYPE_PGSQL:
1227  {
1228  status = switch_pgsql_handle_callback_exec(dbh->native_handle.pgsql_dbh, sql, callback, pdata, err);
1229  if (err && *err) {
1230  (*err_callback)(pdata, (const char*)*err);
1231  }
1232  }
1233  break;
1234  case SCDB_TYPE_ODBC:
1235  {
1236  status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, callback, pdata, err);
1237  if (err && *err) {
1238  (*err_callback)(pdata, (const char*)*err);
1239  }
1240  }
1241  break;
1242  case SCDB_TYPE_CORE_DB:
1243  {
1244  int ret = switch_core_db_exec(dbh->native_handle.core_db_dbh, sql, callback, pdata, &errmsg);
1245 
1246  if (ret == SWITCH_CORE_DB_OK || ret == SWITCH_CORE_DB_ABORT) {
1247  status = SWITCH_STATUS_SUCCESS;
1248  }
1249 
1250  if (errmsg) {
1251  dbh->last_used = switch_epoch_time_now(NULL) - (SQL_CACHE_TIMEOUT * 2);
1252  if (!strstr(errmsg, "query abort")) {
1253  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
1254  }
1255  }
1256  if ((ret == SWITCH_CORE_DB_ABORT || errmsg) && err_callback) {
1257  (*err_callback)(pdata, errmsg);
1258  }
1259  if (errmsg) {
1260  switch_core_db_free(errmsg);
1261  }
1262  }
1263  break;
1264  }
1265 
1266  if (io_mutex) switch_mutex_unlock(io_mutex);
1267 
1268  return status;
1269 }
switch_cache_db_native_handle_t native_handle
switch_mutex_t * io_mutex
#define SWITCH_CHANNEL_LOG
switch_cache_db_handle_type_t type
#define SQL_CACHE_TIMEOUT
int switch_core_db_exec(switch_core_db_t *db, const char *sql, switch_core_db_callback_func_t callback, void *data, char **errmsg)
#define SWITCH_CORE_DB_OK
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_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2454
#define switch_odbc_handle_callback_exec(handle,sql,callback, pdata, err)
Execute the sql query and issue a callback for each row returned.
Definition: switch_odbc.h:92
#define switch_pgsql_handle_callback_exec(handle,sql,callback, pdata, err)
Execute the sql query and issue a callback for each row returned.
Definition: switch_pgsql.h:151
switch_core_db_t * core_db_dbh
Definition: switch_core.h:2453
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_status_t
Common return values.
switch_pgsql_handle_t * pgsql_dbh
Definition: switch_core.h:2455
#define SWITCH_CORE_DB_ABORT
void switch_core_db_free(char *z)
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
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_mutex_t * io_mutex
switch_status_t switch_cache_db_execute_sql_event_callback ( switch_cache_db_handle_t dbh,
const char *  sql,
switch_core_db_event_callback_func_t  callback,
void *  pdata,
char **  err 
)

Definition at line 1042 of file switch_core_sqldb.c.

References helper::callback, helper_callback(), io_mutex, helper::pdata, SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_PGSQL, SQL_CACHE_TIMEOUT, SWITCH_CHANNEL_LOG, SWITCH_CORE_DB_ABORT, switch_core_db_exec(), switch_core_db_free(), SWITCH_CORE_DB_OK, switch_epoch_time_now(), SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_odbc_handle_callback_exec, switch_pgsql_handle_callback_exec, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by sql_in_thread().

1044 {
1046  char *errmsg = NULL;
1048  struct helper h = {0};
1049 
1050 
1051  if (err) {
1052  *err = NULL;
1053  }
1054 
1055  if (io_mutex) switch_mutex_lock(io_mutex);
1056 
1057  h.callback = callback;
1058  h.pdata = pdata;
1059 
1060  switch (dbh->type) {
1061  case SCDB_TYPE_PGSQL:
1062  {
1064  }
1065  break;
1066  case SCDB_TYPE_ODBC:
1067  {
1069  }
1070  break;
1071  case SCDB_TYPE_CORE_DB:
1072  {
1073  int ret = switch_core_db_exec(dbh->native_handle.core_db_dbh, sql, helper_callback, &h, &errmsg);
1074 
1075  if (ret == SWITCH_CORE_DB_OK || ret == SWITCH_CORE_DB_ABORT) {
1076  status = SWITCH_STATUS_SUCCESS;
1077  }
1078 
1079  if (errmsg) {
1080  dbh->last_used = switch_epoch_time_now(NULL) - (SQL_CACHE_TIMEOUT * 2);
1081  if (!strstr(errmsg, "query abort")) {
1082  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
1083  }
1084  switch_core_db_free(errmsg);
1085  }
1086  }
1087  break;
1088  }
1089 
1090  if (io_mutex) switch_mutex_unlock(io_mutex);
1091 
1092  return status;
1093 }
switch_cache_db_native_handle_t native_handle
switch_mutex_t * io_mutex
#define SWITCH_CHANNEL_LOG
switch_cache_db_handle_type_t type
switch_core_db_event_callback_func_t callback
#define SQL_CACHE_TIMEOUT
int switch_core_db_exec(switch_core_db_t *db, const char *sql, switch_core_db_callback_func_t callback, void *data, char **errmsg)
#define SWITCH_CORE_DB_OK
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_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2454
#define switch_odbc_handle_callback_exec(handle,sql,callback, pdata, err)
Execute the sql query and issue a callback for each row returned.
Definition: switch_odbc.h:92
#define switch_pgsql_handle_callback_exec(handle,sql,callback, pdata, err)
Execute the sql query and issue a callback for each row returned.
Definition: switch_pgsql.h:151
switch_core_db_t * core_db_dbh
Definition: switch_core.h:2453
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_status_t
Common return values.
switch_pgsql_handle_t * pgsql_dbh
Definition: switch_core.h:2455
static int helper_callback(void *pArg, int argc, char **argv, char **columnNames)
#define SWITCH_CORE_DB_ABORT
void switch_core_db_free(char *z)
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
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_mutex_t * io_mutex
void switch_cache_db_flush_handles ( void  )

Definition at line 291 of file switch_core_sqldb.c.

References SQL_CACHE_TIMEOUT, sql_close(), and switch_epoch_time_now().

Referenced by switch_core_session_ctl(), and switch_core_sqldb_stop().

292 {
294 }
#define SQL_CACHE_TIMEOUT
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
static void sql_close(time_t prune)
switch_cache_db_handle_type_t switch_cache_db_get_type ( switch_cache_db_handle_t dbh)

Definition at line 286 of file switch_core_sqldb.c.

Referenced by switch_console_complete(), switch_console_expand_alias(), and switch_console_set_alias().

287 {
288  return dbh->type;
289 }
switch_cache_db_handle_type_t type
int switch_cache_db_load_extension ( switch_cache_db_handle_t dbh,
const char *  extension 
)

load an external extension to db

Parameters
[in]dbhThe handle
[out]thepath to the extension

Definition at line 710 of file switch_core_sqldb.c.

References SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_PGSQL, SWITCH_CHANNEL_LOG, switch_core_db_load_extension(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, and switch_log_printf().

711 {
712  switch (dbh->type) {
713  case SCDB_TYPE_CORE_DB:
714  {
715  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "try to load extension [%s]!\n", extension);
717  }
718  break;
719  case SCDB_TYPE_ODBC:
720  {
721  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "load extension not supported by type ODBC!\n");
722  }
723  break;
724  case SCDB_TYPE_PGSQL:
725  {
726  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "load extension not supported by type PGSQL!\n");
727  }
728  break;
729  }
730  return 0;
731 }
switch_cache_db_native_handle_t native_handle
#define SWITCH_CHANNEL_LOG
switch_cache_db_handle_type_t type
int switch_core_db_load_extension(switch_core_db_t *db, const char *extension)
switch_core_db_t * core_db_dbh
Definition: switch_core.h:2453
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_status_t switch_cache_db_persistant_execute ( switch_cache_db_handle_t dbh,
const char *  sql,
uint32_t  retries 
)

Definition at line 801 of file switch_core_sqldb.c.

References io_mutex, switch_cache_db_execute_sql_real(), SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_safe_free, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_yield.

Referenced by switch_console_set_alias().

802 {
803  char *errmsg = NULL;
805  uint8_t forever = 0;
807 
808  if (!retries) {
809  forever = 1;
810  retries = 1000;
811  }
812 
813  while (retries > 0) {
814 
815  if (io_mutex) switch_mutex_lock(io_mutex);
816  switch_cache_db_execute_sql_real(dbh, sql, &errmsg);
817  if (io_mutex) switch_mutex_unlock(io_mutex);
818 
819 
820  if (errmsg) {
821  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
822  switch_safe_free(errmsg);
823  switch_yield(100000);
824  retries--;
825  if (retries == 0 && forever) {
826  retries = 1000;
827  continue;
828  }
829  } else {
830  status = SWITCH_STATUS_SUCCESS;
831  break;
832  }
833  }
834 
835  return status;
836 }
switch_mutex_t * io_mutex
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_status_t
Common return values.
static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t *dbh, const char *sql, char **err)
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_mutex_t * io_mutex
switch_status_t switch_cache_db_persistant_execute_trans_full ( switch_cache_db_handle_t dbh,
char *  sql,
uint32_t  retries,
const char *  pre_trans_execute,
const char *  post_trans_execute,
const char *  inner_pre_trans_execute,
const char *  inner_post_trans_execute 
)

Definition at line 839 of file switch_core_sqldb.c.

References io_mutex, SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_PGSQL, switch_cache_db_execute_sql(), switch_cache_db_execute_sql_real(), SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_odbc_SQLEndTran(), switch_odbc_SQLSetAutoCommitAttr(), SWITCH_ODBC_SUCCESS, switch_pgsql_finish_results, switch_pgsql_SQLEndTran(), switch_pgsql_SQLSetAutoCommitAttr(), SWITCH_PGSQL_SUCCESS, switch_safe_free, switch_snprintfv(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_yield, and zstr.

845 {
846  char *errmsg = NULL;
848  uint8_t forever = 0;
849  unsigned begin_retries = 100;
850  uint8_t again = 0;
852 
853  if (!retries) {
854  forever = 1;
855  retries = 1000;
856  }
857 
858  if (io_mutex) switch_mutex_lock(io_mutex);
859 
860  if (!zstr(pre_trans_execute)) {
861  switch_cache_db_execute_sql_real(dbh, pre_trans_execute, &errmsg);
862  if (errmsg) {
863  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL PRE TRANS EXEC %s [%s]\n", pre_trans_execute, errmsg);
864  switch_safe_free(errmsg);
865  }
866  }
867 
868  again:
869 
870  while (begin_retries > 0) {
871  again = 0;
872 
873  switch(dbh->type) {
874  case SCDB_TYPE_CORE_DB:
875  {
876  switch_cache_db_execute_sql_real(dbh, "BEGIN EXCLUSIVE", &errmsg);
877  }
878  break;
879  case SCDB_TYPE_ODBC:
880  {
881  switch_odbc_status_t result;
882 
884  char tmp[100];
885  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
886  errmsg = strdup(tmp);
887  }
888  }
889  break;
890  case SCDB_TYPE_PGSQL:
891  {
892  switch_pgsql_status_t result;
893 
895  char tmp[100];
896  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
897  errmsg = strdup(tmp);
898  }
899  }
900  break;
901  }
902 
903  if (errmsg) {
904  begin_retries--;
905  if (strstr(errmsg, "cannot start a transaction within a transaction")) {
906  again = 1;
907  } else {
908  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL Retry [%s]\n", errmsg);
909  }
910  switch_safe_free(errmsg);
911 
912  if (again) {
913  switch(dbh->type) {
914  case SCDB_TYPE_CORE_DB:
915  {
916  switch_cache_db_execute_sql_real(dbh, "COMMIT", NULL);
917  }
918  break;
919  case SCDB_TYPE_ODBC:
920  {
923  }
924  break;
925  case SCDB_TYPE_PGSQL:
926  {
930  }
931  break;
932  }
933 
934  goto again;
935  }
936 
937  switch_yield(100000);
938 
939  if (begin_retries == 0) {
940  goto done;
941  }
942 
943  continue;
944  }
945 
946  break;
947  }
948 
949 
950  if (!zstr(inner_pre_trans_execute)) {
951  switch_cache_db_execute_sql_real(dbh, inner_pre_trans_execute, &errmsg);
952  if (errmsg) {
953  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL PRE TRANS EXEC %s [%s]\n", inner_pre_trans_execute, errmsg);
954  switch_safe_free(errmsg);
955  }
956  }
957 
958  while (retries > 0) {
959 
960  switch_cache_db_execute_sql(dbh, sql, &errmsg);
961 
962  if (errmsg) {
963  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
964  switch_safe_free(errmsg);
965  errmsg = NULL;
966  switch_yield(100000);
967  retries--;
968  if (retries == 0 && forever) {
969  retries = 1000;
970  continue;
971  }
972  } else {
973  status = SWITCH_STATUS_SUCCESS;
974  break;
975  }
976  }
977 
978  if (!zstr(inner_post_trans_execute)) {
979  switch_cache_db_execute_sql_real(dbh, inner_post_trans_execute, &errmsg);
980  if (errmsg) {
981  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL POST TRANS EXEC %s [%s]\n", inner_post_trans_execute, errmsg);
982  switch_safe_free(errmsg);
983  }
984  }
985 
986  done:
987 
988  switch(dbh->type) {
989  case SCDB_TYPE_CORE_DB:
990  {
991  switch_cache_db_execute_sql_real(dbh, "COMMIT", NULL);
992  }
993  break;
994  case SCDB_TYPE_ODBC:
995  {
998  }
999  break;
1000  case SCDB_TYPE_PGSQL:
1001  {
1005  }
1006  break;
1007  }
1008 
1009  if (!zstr(post_trans_execute)) {
1010  switch_cache_db_execute_sql_real(dbh, post_trans_execute, &errmsg);
1011  if (errmsg) {
1012  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL POST TRANS EXEC %s [%s]\n", post_trans_execute, errmsg);
1013  switch_safe_free(errmsg);
1014  }
1015  }
1016 
1017  if (io_mutex) switch_mutex_unlock(io_mutex);
1018 
1019  return status;
1020 }
switch_pgsql_status_t
Definition: switch_pgsql.h:53
switch_cache_db_native_handle_t native_handle
switch_mutex_t * io_mutex
switch_odbc_status_t
Definition: switch_odbc.h:49
#define SWITCH_CHANNEL_LOG
switch_cache_db_handle_type_t type
switch_pgsql_status_t switch_pgsql_SQLEndTran(switch_pgsql_handle_t *handle, switch_bool_t commit)
Definition: switch_pgsql.c:865
switch_pgsql_status_t switch_pgsql_SQLSetAutoCommitAttr(switch_pgsql_handle_t *handle, switch_bool_t on)
Definition: switch_pgsql.c:828
#define zstr(x)
Definition: switch_utils.h:281
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
#define switch_pgsql_finish_results(handle)
Definition: switch_pgsql.h:107
char * switch_snprintfv(char *zBuf, int n, const char *zFormat,...)
switch_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2454
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_status_t
Common return values.
switch_pgsql_handle_t * pgsql_dbh
Definition: switch_core.h:2455
static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t *dbh, const char *sql, char **err)
switch_odbc_status_t switch_odbc_SQLEndTran(switch_odbc_handle_t *handle, switch_bool_t commit)
Definition: switch_odbc.c:760
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_status_t switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err)
Executes the sql.
switch_mutex_t * io_mutex
switch_odbc_status_t switch_odbc_SQLSetAutoCommitAttr(switch_odbc_handle_t *handle, switch_bool_t on)
Definition: switch_odbc.c:747
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 actually terminates.

Parameters
[in]Thehandle

Definition at line 297 of file switch_core_sqldb.c.

References SCDB_TYPE_PGSQL, sql_manager, switch_epoch_time_now(), switch_mutex_lock(), switch_mutex_unlock(), and switch_pgsql_flush().

Referenced by sql_in_thread(), switch_cache_db_dismiss_db_handle(), switch_console_complete(), switch_console_expand_alias(), switch_console_list_uuid(), switch_console_set_alias(), switch_core_recovery_flush(), switch_core_recovery_recover(), switch_core_sqldb_start(), switch_sql_queue_manager_push_confirm(), and switch_user_sql_thread().

298 {
299  if (dbh && *dbh) {
300 
301  switch((*dbh)->type) {
302  case SCDB_TYPE_PGSQL:
303  {
304  switch_pgsql_flush((*dbh)->native_handle.pgsql_dbh);
305  }
306  break;
307  default:
308  break;
309  }
310 
311  switch_mutex_lock(sql_manager.dbh_mutex);
312  (*dbh)->last_used = switch_epoch_time_now(NULL);
313 
314  (*dbh)->io_mutex = NULL;
315 
316  if ((*dbh)->use_count) {
317  if (--(*dbh)->use_count == 0) {
318  (*dbh)->thread_hash = 1;
319  }
320  }
321  switch_mutex_unlock((*dbh)->mutex);
322  sql_manager.total_used_handles--;
323  *dbh = NULL;
324  switch_mutex_unlock(sql_manager.dbh_mutex);
325  }
326 }
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_pgsql_status_t switch_pgsql_flush(switch_pgsql_handle_t *handle)
Definition: switch_pgsql.c:842
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
static struct @3 sql_manager
void switch_cache_db_status ( switch_stream_handle_t stream)

Provides some feedback as to the status of the db connection pool.

Parameters
[in]streamstream for status

Definition at line 3716 of file switch_core_sqldb.c.

References CACHE_DB_LEN, switch_cache_db_handle::creator, dbh, switch_cache_db_handle::last_used, switch_cache_db_handle::last_user, memset(), switch_cache_db_handle::mutex, switch_cache_db_handle::name, switch_cache_db_handle::next, sql_manager, switch_cache_db_type_name(), switch_epoch_time_now(), SWITCH_FALSE, switch_mutex_lock(), switch_mutex_trylock(), switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, SWITCH_TRUE, switch_cache_db_handle::total_used_count, switch_cache_db_handle::type, and switch_cache_db_handle::use_count.

3717 {
3718  /* return some status info suitable for the cli */
3719  switch_cache_db_handle_t *dbh = NULL;
3720  switch_bool_t locked = SWITCH_FALSE;
3721  time_t now = switch_epoch_time_now(NULL);
3722  char cleankey_str[CACHE_DB_LEN];
3723  char *pos1 = NULL;
3724  char *pos2 = NULL;
3725  int count = 0, used = 0;
3726 
3727  switch_mutex_lock(sql_manager.dbh_mutex);
3728 
3729  for (dbh = sql_manager.handle_pool; dbh; dbh = dbh->next) {
3730  char *needles[3];
3731  time_t diff = 0;
3732  int i = 0;
3733 
3734  needles[0] = "pass=\"";
3735  needles[1] = "password=";
3736  needles[2] = "password='";
3737 
3738  diff = now - dbh->last_used;
3739 
3741  switch_mutex_unlock(dbh->mutex);
3742  locked = SWITCH_FALSE;
3743  } else {
3744  locked = SWITCH_TRUE;
3745  }
3746 
3747  /* sanitize password */
3748  memset(cleankey_str, 0, sizeof(cleankey_str));
3749  for (i = 0; i < 3; i++) {
3750  if((pos1 = strstr(dbh->name, needles[i]))) {
3751  pos1 += strlen(needles[i]);
3752 
3753  if (!(pos2 = strstr(pos1, "\""))) {
3754  if (!(pos2 = strstr(pos1, "'"))) {
3755  if (!(pos2 = strstr(pos1, " "))) {
3756  pos2 = pos1 + strlen(pos1);
3757  }
3758  }
3759  }
3760  strncpy(cleankey_str, dbh->name, pos1 - dbh->name);
3761  strcpy(&cleankey_str[pos1 - dbh->name], pos2);
3762  break;
3763  }
3764  }
3765  if (i == 3) {
3766  strncpy(cleankey_str, dbh->name, strlen(dbh->name));
3767  }
3768 
3769  count++;
3770 
3771  if (dbh->use_count) {
3772  used++;
3773  }
3774 
3775  stream->write_function(stream, "%s\n\tType: %s\n\tLast used: %d\n\tTotal used: %ld\n\tFlags: %s, %s(%d)\n"
3776  "\tCreator: %s\n\tLast User: %s\n",
3777  cleankey_str,
3779  diff,
3780  dbh->total_used_count,
3781  locked ? "Locked" : "Unlocked",
3782  dbh->use_count ? "Attached" : "Detached", dbh->use_count, dbh->creator, dbh->last_user);
3783  }
3784 
3785  stream->write_function(stream, "%d total. %d in use.\n", count, used);
3786 
3787  switch_mutex_unlock(sql_manager.dbh_mutex);
3788 }
char name[CACHE_DB_LEN]
switch_status_t switch_mutex_trylock(switch_mutex_t *lock)
Definition: switch_apr.c:295
switch_cache_db_handle_type_t type
switch_bool_t
Definition: switch_types.h:405
static const char * switch_cache_db_type_name(switch_cache_db_handle_type_t type)
Definition: switch_core.h:2481
char creator[CACHE_DB_LEN]
char last_user[CACHE_DB_LEN]
switch_mutex_t * mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
struct switch_cache_db_handle * next
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define CACHE_DB_LEN
Definition: switch_core.h:2440
switch_cache_db_handle_t * dbh
switch_stream_handle_write_function_t write_function
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
memset(buf, 0, buflen)
static struct @3 sql_manager
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.

If auto-clear-sql is disabled, then this function will do nothing and it is assumed that the queries are not needed. If auto-create-schemas is disabled, then just test_sql is executed, but drop_sql and reactive_sql are not.

Otherwise, test_sql gets executed. If that succeeds, then there is nothing to do. Otherwise drop_sql is executed (its result is ignored) and then finally reactive_sql is executed.

Returns
If auto-create-schemas is enabled, SWITCH_TRUE is returned if test_sql succeeds, SWITCH_FALSE otherwise. If reactive_sql is executed successfully SWITCH_TRUE is returned, otherwise SWITCH_FALSE is returned.

Definition at line 1299 of file switch_core_sqldb.c.

References io_mutex, runtime, SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_PGSQL, SCF_AUTO_SCHEMAS, SCF_CLEAR_SQL, switch_assert, switch_cache_db_execute_sql(), SWITCH_CHANNEL_LOG, switch_core_db_exec(), switch_core_db_free(), SWITCH_FALSE, SWITCH_LOG_DEBUG, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_odbc_handle_exec(), SWITCH_ODBC_SUCCESS, switch_pgsql_handle_exec, SWITCH_PGSQL_SUCCESS, SWITCH_STATUS_SUCCESS, switch_test_flag, and SWITCH_TRUE.

Referenced by switch_core_sqldb_start().

1301 {
1304 
1305  switch_assert(test_sql != NULL);
1306  switch_assert(reactive_sql != NULL);
1307 
1309  return SWITCH_TRUE;
1310  }
1311 
1313  switch_status_t status = switch_cache_db_execute_sql(dbh, (char *)test_sql, NULL);
1314 
1315  return (status == SWITCH_STATUS_SUCCESS) ? SWITCH_TRUE : SWITCH_FALSE;
1316  }
1317 
1318  if (io_mutex) switch_mutex_lock(io_mutex);
1319 
1320  switch (dbh->type) {
1321  case SCDB_TYPE_PGSQL:
1322  {
1324  if (drop_sql) {
1325  switch_pgsql_handle_exec(dbh->native_handle.pgsql_dbh, drop_sql, NULL);
1326  }
1327  r = switch_pgsql_handle_exec(dbh->native_handle.pgsql_dbh, reactive_sql, NULL) == SWITCH_PGSQL_SUCCESS;
1328  }
1329  }
1330  break;
1331  case SCDB_TYPE_ODBC:
1332  {
1333  if (switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) {
1334  if (drop_sql) {
1335  switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, drop_sql, NULL, NULL);
1336  }
1337  r = switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, reactive_sql, NULL, NULL) == SWITCH_ODBC_SUCCESS;
1338  }
1339  }
1340  break;
1341  case SCDB_TYPE_CORE_DB:
1342  {
1343  char *errmsg = NULL;
1344  switch_core_db_exec(dbh->native_handle.core_db_dbh, test_sql, NULL, NULL, &errmsg);
1345 
1346  if (errmsg) {
1347  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\nAuto Generating Table!\n", errmsg, test_sql);
1348  switch_core_db_free(errmsg);
1349  errmsg = NULL;
1350  if (drop_sql) {
1351  switch_core_db_exec(dbh->native_handle.core_db_dbh, drop_sql, NULL, NULL, &errmsg);
1352  }
1353  if (errmsg) {
1354  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ignoring SQL ERR [%s]\n[%s]\n", errmsg, drop_sql);
1355  switch_core_db_free(errmsg);
1356  errmsg = NULL;
1357  }
1358  switch_core_db_exec(dbh->native_handle.core_db_dbh, reactive_sql, NULL, NULL, &errmsg);
1359  if (errmsg) {
1360  r = SWITCH_FALSE;
1361  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql);
1362  switch_core_db_free(errmsg);
1363  errmsg = NULL;
1364  } else {
1365  r = SWITCH_TRUE;
1366  }
1367  }
1368  }
1369  break;
1370  }
1371 
1372 
1373  if (io_mutex) switch_mutex_unlock(io_mutex);
1374 
1375  return r;
1376 }
switch_cache_db_native_handle_t native_handle
switch_mutex_t * io_mutex
#define SWITCH_CHANNEL_LOG
switch_cache_db_handle_type_t type
switch_bool_t
Definition: switch_types.h:405
switch_odbc_status_t switch_odbc_handle_exec(switch_odbc_handle_t *handle, const char *sql, switch_odbc_statement_handle_t *rstmt, char **err)
Definition: switch_odbc.c:449
struct switch_runtime runtime
Definition: switch_core.c:64
int switch_core_db_exec(switch_core_db_t *db, const char *sql, switch_core_db_callback_func_t callback, void *data, char **errmsg)
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
#define switch_pgsql_handle_exec(handle, sql, err)
Definition: switch_pgsql.h:117
switch_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2454
switch_core_db_t * core_db_dbh
Definition: switch_core.h:2453
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_status_t
Common return values.
switch_pgsql_handle_t * pgsql_dbh
Definition: switch_core.h:2455
void switch_core_db_free(char *z)
#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.
switch_status_t switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err)
Executes the sql.
#define switch_assert(expr)
switch_mutex_t * io_mutex
static const char* switch_cache_db_type_name ( switch_cache_db_handle_type_t  type)
inlinestatic

Definition at line 2481 of file switch_core.h.

References SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, and SCDB_TYPE_PGSQL.

Referenced by _switch_cache_db_get_db_handle(), and switch_cache_db_status().

2482 {
2483  const char *type_str = "INVALID";
2484 
2485  switch (type) {
2486  case SCDB_TYPE_PGSQL:
2487  {
2488  type_str = "PGSQL";
2489  }
2490  break;
2491  case SCDB_TYPE_ODBC:
2492  {
2493  type_str = "ODBC";
2494  }
2495  break;
2496  case SCDB_TYPE_CORE_DB:
2497  {
2498  type_str = "CORE_DB";
2499  }
2500  break;
2501  }
2502 
2503  return type_str;
2504 }
void switch_close_extra_files ( int *  keep,
int  keep_ttl 
)

Definition at line 3096 of file switch_core.c.

References skip(), and switch_max_file_desc().

Referenced by preprocess_exec(), switch_stream_system_fork(), and switch_system_fork().

3097 {
3098  int open_max = switch_max_file_desc();
3099  int i, j;
3100 
3101  for (i = 3; i < open_max; i++) {
3102  if (keep) {
3103  for (j = 0; j < keep_ttl; j++) {
3104  if (i == keep[j]) {
3105  goto skip;
3106  }
3107  }
3108  }
3109 
3110  close(i);
3111 
3112  skip:
3113 
3114  continue;
3115 
3116  }
3117 }
int switch_max_file_desc(void)
Definition: switch_core.c:3080
static const char * skip(const char *in)
Definition: switch_json.c:270
switch_status_t switch_core_add_registration ( const char *  user,
const char *  realm,
const char *  token,
const char *  url,
uint32_t  expires,
const char *  network_ip,
const char *  network_port,
const char *  network_proto,
const char *  metadata 
)

Add user registration.

Parameters
[in]user
[in]realm
[in]token
[in]url- a freeswitch dial string
[in]expires
[in]network_ip
[in]network_port
[in]network_proto- one of tls, tcp, udp
[in]metadata- generic metadata supplied by module
[out]err- Error if it exists

Definition at line 3244 of file switch_core_sqldb.c.

References switch_runtime::multiple_registrations, runtime, SCF_USE_SQL, db_job::sql, sql_manager, switch_core_get_switchname(), SWITCH_FALSE, switch_mprintf(), switch_sql_queue_manager_push(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_str_nil, switch_test_flag, and zstr.

3247 {
3248  char *sql;
3249 
3250  if (!switch_test_flag((&runtime), SCF_USE_SQL)) {
3251  return SWITCH_STATUS_FALSE;
3252  }
3253 
3255  sql = switch_mprintf("delete from registrations where hostname='%q' and (url='%q' or token='%q')",
3257  } else {
3258  sql = switch_mprintf("delete from registrations where reg_user='%q' and realm='%q' and hostname='%q'",
3259  user, realm, switch_core_get_switchname());
3260  }
3261 
3263 
3264  if ( !zstr(metadata) ) {
3265  sql = switch_mprintf("insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname,metadata) "
3266  "values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q','%q')",
3267  switch_str_nil(user),
3268  switch_str_nil(realm),
3269  switch_str_nil(token),
3270  switch_str_nil(url),
3271  expires,
3272  switch_str_nil(network_ip),
3273  switch_str_nil(network_port),
3274  switch_str_nil(network_proto),
3276  metadata
3277  );
3278  } else {
3279  sql = switch_mprintf("insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname) "
3280  "values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q')",
3281  switch_str_nil(user),
3282  switch_str_nil(realm),
3283  switch_str_nil(token),
3284  switch_str_nil(url),
3285  expires,
3286  switch_str_nil(network_ip),
3287  switch_str_nil(network_port),
3288  switch_str_nil(network_proto),
3290  );
3291  }
3292 
3293 
3295 
3296  return SWITCH_STATUS_SUCCESS;
3297 }
const char * switch_core_get_switchname(void)
Definition: switch_core.c:349
struct switch_runtime runtime
Definition: switch_core.c:64
#define zstr(x)
Definition: switch_utils.h:281
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:903
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
switch_status_t switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
static struct @3 sql_manager
void switch_core_autobind_cpu ( void  )

Definition at line 5330 of file switch_core_media.c.

References core_video_globals_s::cpu_count, next_cpu(), and switch_core_thread_set_cpu_affinity().

Referenced by video_helper_thread().

5331 {
5332  if (video_globals.cpu_count > 1) {
5334  }
5335 }
switch_status_t switch_core_thread_set_cpu_affinity(int cpu)
Definition: switch_core.c:1723
int next_cpu(void)
static core_video_globals_t video_globals
const char* switch_core_banner ( void  )

Definition at line 2342 of file switch_core.c.

Referenced by switch_core_init_and_modload().

2343 {
2344 
2345  return ("\n"
2346  ".=============================================================.\n"
2347  "| _____ ______ _____ _____ ____ _ _ |\n"
2348  "| | ___| __ ___ ___/ ___\\ \\ / /_ _|_ _/ ___| | | | |\n"
2349  "| | |_ | '__/ _ \\/ _ \\___ \\\\ \\ /\\ / / | | | || | | |_| | |\n"
2350  "| | _|| | | __/ __/___) |\\ V V / | | | || |___| _ | |\n"
2351  "| |_| |_| \\___|\\___|____/ \\_/\\_/ |___| |_| \\____|_| |_| |\n"
2352  "| |\n"
2353  ".=============================================================."
2354  "\n"
2355 
2356  "| Anthony Minessale II, Michael Jerris, Brian West, Others |\n"
2357  "| FreeSWITCH (http://www.freeswitch.org) |\n"
2358  "| Paypal Donations Appreciated: paypal@freeswitch.org |\n"
2359  "| Brought to you by ClueCon http://www.cluecon.com/ |\n"
2360  ".=============================================================.\n"
2361  "\n");
2362 }
int switch_core_cert_expand_fingerprint ( dtls_fingerprint_t fp,
const char *  str 
)

Definition at line 152 of file switch_core_cert.c.

References MAX_FPLEN.

Referenced by switch_rtp_add_dtls().

153 {
154  char *tmp = strdup(str);
155  char *p = tmp;
156  int i = 0;
157  char *v;
158 
159  while ((v = strsep(&p, ":")) && (i != (MAX_FPLEN - 1))) {
160  sscanf(v, "%02x", (uint32_t *) &fp->data[i++]);
161  }
162 
163  free(tmp);
164 
165  return i;
166 }
uint8_t data[MAX_FPLEN+1]
Definition: switch_core.h:152
#define MAX_FPLEN
Definition: switch_core.h:147
int switch_core_cert_gen_fingerprint ( const char *  prefix,
dtls_fingerprint_t fp 
)

Definition at line 189 of file switch_core_cert.c.

References switch_directories::certs_dir, SWITCH_CHANNEL_LOG, switch_core_cert_extract_fingerprint(), switch_file_exists(), SWITCH_GLOBAL_dirs, SWITCH_LOG_ERROR, switch_log_printf(), switch_mprintf(), SWITCH_PATH_SEPARATOR, and SWITCH_STATUS_SUCCESS.

Referenced by generate_local_fingerprint().

190 {
191  X509* x509 = NULL;
192  BIO* bio = NULL;
193  int ret = 0;
194  char *rsa;
195 
197 
198  if (switch_file_exists(rsa, NULL) != SWITCH_STATUS_SUCCESS) {
199  free(rsa);
201  }
202 
203  if (!(bio = BIO_new(BIO_s_file()))) {
205  goto end;
206  }
207 
208  if (BIO_read_filename(bio, rsa) != 1) {
210  goto end;
211  }
212 
213  if (!(x509 = PEM_read_bio_X509(bio, NULL, 0, NULL))) {
215  goto end;
216  }
217 
219 
220  ret = 1;
221 
222  end:
223 
224  if (bio) {
225  BIO_free_all(bio);
226  }
227 
228  if (x509) {
229  X509_free(x509);
230  }
231 
232  free(rsa);
233 
234  return ret;
235 }
#define SWITCH_CHANNEL_LOG
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:122
int switch_core_cert_extract_fingerprint(X509 *x509, dtls_fingerprint_t *fp)
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:60
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
Definition: switch_apr.c:496
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_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
int switch_core_cert_verify ( dtls_fingerprint_t fp)

Definition at line 133 of file switch_core_cert.c.

References MAX_FPLEN.

Referenced by dtls_state_setup().

134 {
135  unsigned char fdata[MAX_FPLEN] = { 0 };
136  char *tmp = strdup(fp->str);
137  char *p = tmp;
138  int i = 0;
139  char *v;
140 
141  while ((v = strsep(&p, ":")) && (i != (MAX_FPLEN - 1))) {
142  sscanf(v, "%02x", (uint32_t *) &fdata[i++]);
143  }
144 
145  free(tmp);
146 
147  i = !memcmp(fdata, fp->data, i);
148 
149  return i;
150 }
char str[MAX_FPSTRLEN]
Definition: switch_core.h:154
uint8_t data[MAX_FPLEN+1]
Definition: switch_core.h:152
#define MAX_FPLEN
Definition: switch_core.h:147
switch_cache_db_handle_type_t switch_core_dbtype ( void  )

Definition at line 3129 of file switch_core_sqldb.c.

References SCDB_TYPE_CORE_DB, sql_manager, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_console_set_complete().

3130 {
3132 
3133  switch_mutex_lock(sql_manager.ctl_mutex);
3134  if (sql_manager.qm && sql_manager.qm->event_db) {
3135  type = sql_manager.qm->event_db->type;
3136  }
3137  switch_mutex_unlock(sql_manager.ctl_mutex);
3138 
3139  return type;
3140 }
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_cache_db_handle_type_t
Definition: switch_core.h:2446
static struct @3 sql_manager
uint32_t switch_core_debug_level ( void  )

Definition at line 2522 of file switch_core.c.

References switch_runtime::debug_level.

2523 {
2524  return runtime.debug_level;
2525 }
struct switch_runtime runtime
Definition: switch_core.c:64
uint32_t debug_level
switch_status_t switch_core_del_registration ( const char *  user,
const char *  realm,
const char *  token 
)

Delete user registration.

Parameters
[in]user
[in]realm
[in]token
[out]err- Error if it exists

Definition at line 3299 of file switch_core_sqldb.c.

References switch_runtime::multiple_registrations, runtime, SCF_USE_SQL, db_job::sql, sql_manager, switch_core_get_switchname(), SWITCH_FALSE, switch_mprintf(), switch_sql_queue_manager_push(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_test_flag, and zstr.

3300 {
3301 
3302  char *sql;
3303 
3304  if (!switch_test_flag((&runtime), SCF_USE_SQL)) {
3305  return SWITCH_STATUS_FALSE;
3306  }
3307 
3308  if (!zstr(token) && runtime.multiple_registrations) {
3309  sql = switch_mprintf("delete from registrations where reg_user='%q' and realm='%q' and hostname='%q' and token='%q'", user, realm, switch_core_get_switchname(), token);
3310  } else {
3311  sql = switch_mprintf("delete from registrations where reg_user='%q' and realm='%q' and hostname='%q'", user, realm, switch_core_get_switchname());
3312  }
3313 
3315 
3316 
3317  return SWITCH_STATUS_SUCCESS;
3318 }
const char * switch_core_get_switchname(void)
Definition: switch_core.c:349
struct switch_runtime runtime
Definition: switch_core.c:64
#define zstr(x)
Definition: switch_utils.h:281
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
switch_status_t switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
static struct @3 sql_manager
switch_status_t switch_core_expire_registration ( int  force)

Expire user registrations.

Parameters
[in]forcedelete all registrations
[out]err- Error if it exists

Definition at line 3320 of file switch_core_sqldb.c.

References runtime, SCF_USE_SQL, db_job::sql, sql_manager, switch_core_get_switchname(), switch_epoch_time_now(), SWITCH_FALSE, switch_mprintf(), switch_sql_queue_manager_push(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_test_flag.

Referenced by switch_core_sql_db_thread().

3321 {
3322 
3323  char *sql;
3324  time_t now;
3325 
3326  if (!switch_test_flag((&runtime), SCF_USE_SQL)) {
3327  return SWITCH_STATUS_FALSE;
3328  }
3329 
3330  now = switch_epoch_time_now(NULL);
3331 
3332  if (force) {
3333  sql = switch_mprintf("delete from registrations where hostname='%q'", switch_core_get_switchname());
3334  } else {
3335  sql = switch_mprintf("delete from registrations where expires > 0 and expires <= %ld and hostname='%q'", now, switch_core_get_switchname());
3336  }
3337 
3339 
3340  return SWITCH_STATUS_SUCCESS;
3341 
3342 }
const char * switch_core_get_switchname(void)
Definition: switch_core.c:349
struct switch_runtime runtime
Definition: switch_core.c:64
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:321
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
switch_status_t switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
static struct @3 sql_manager
int switch_core_gen_certs ( const char *  prefix)

Definition at line 240 of file switch_core_cert.c.

References switch_directories::certs_dir, mkcert(), switch_file_exists(), SWITCH_GLOBAL_dirs, switch_is_file_path(), switch_mprintf(), SWITCH_PATH_SEPARATOR, switch_safe_free, SWITCH_STATUS_SUCCESS, and switch_stristr().

Referenced by switch_core_media_init().

241 {
242  //BIO *bio_err;
243  X509 *x509 = NULL;
244  EVP_PKEY *pkey = NULL;
245  char *rsa = NULL, *pvt = NULL;
246  FILE *fp;
247  char *pem = NULL;
248 
249  if (switch_stristr(".pem", prefix)) {
250 
251  if (switch_is_file_path(prefix)) {
252  pem = strdup(prefix);
253  } else {
255  }
256 
257  if (switch_file_exists(pem, NULL) == SWITCH_STATUS_SUCCESS) {
258  goto end;
259  }
260  } else {
261  if (switch_is_file_path(prefix)) {
262  pvt = switch_mprintf("%s.key", prefix);
263  rsa = switch_mprintf("%s.crt", prefix);
264  } else {
267  }
268 
270  goto end;
271  }
272  }
273 
274  CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
275 
276  //bio_err=BIO_new_fp(stderr, BIO_NOCLOSE);
277 
278  mkcert(&x509, &pkey, 1024, 0, 36500);
279 
280  //RSA_print_fp(stdout, pkey->pkey.rsa, 0);
281  //X509_print_fp(stdout, x509);
282 
283  if (pem) {
284  if ((fp = fopen(pem, "w"))) {
285  PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL);
286  PEM_write_X509(fp, x509);
287  fclose(fp);
288  }
289 
290  } else {
291  if (pvt && (fp = fopen(pvt, "w"))) {
292  PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL);
293  fclose(fp);
294  }
295 
296  if (rsa && (fp = fopen(rsa, "w"))) {
297  PEM_write_X509(fp, x509);
298  fclose(fp);
299  }
300  }
301 
302  X509_free(x509);
303  EVP_PKEY_free(pkey);
304 
305 #ifndef OPENSSL_NO_ENGINE
306  ENGINE_cleanup();
307 #endif
308  CRYPTO_cleanup_all_ex_data();
309 
310  //CRYPTO_mem_leaks(bio_err);
311  //BIO_free(bio_err);
312 
313 
314  end:
315 
316  switch_safe_free(pvt);
317  switch_safe_free(rsa);
318  switch_safe_free(pem);
319 
320  return(0);
321 }
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:122
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:60
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
Definition: switch_apr.c:496
static switch_bool_t switch_is_file_path(const char *file)
const char * switch_stristr(const char *instr, const char *str)
static int mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
void switch_core_gen_encoded_silence ( unsigned char *  data,
const switch_codec_implementation_t read_impl,
switch_size_t  len 
)

Definition at line 39 of file switch_core_io.c.

References memset(), and switch_stristr().

Referenced by record_callback(), and switch_core_session_read_frame().

40 {
41  unsigned char g729_filler[] = {
42  114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
43  229, 127, 79, 96, 207, 82, 216, 110, 245, 81,
44  114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
45  229, 127, 79, 96, 207, 82, 216, 110, 245, 81,
46  114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
47  229, 127, 79, 96, 207, 82, 216, 110, 245, 81,
48  114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
49  229, 127, 79, 96, 207, 82, 216, 110, 245, 81,
50  114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
51  229, 127, 79, 96, 207, 82, 216, 110, 245, 81,
52  114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
53  229, 127, 79, 96, 207, 82, 216, 110, 245, 81,
54  114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
55  229, 127, 79, 96, 207, 82, 216, 110, 245, 81
56  };
57 
58 
59  if (read_impl->ianacode == 18 || switch_stristr("g729", read_impl->iananame)) {
60  memcpy(data, g729_filler, len);
61  } else {
62  memset(data, 255, len);
63  }
64 
65 }
const char * switch_stristr(const char *instr, const char *str)
memset(buf, 0, buflen)
uint16_t switch_core_get_rtp_port_range_end_port ( void  )

Get RTP port range end value.

Parameters
[in]void
[out]RTPport range end value

Definition at line 3295 of file switch_core.c.

References switch_rtp_set_end_port().

3296 {
3297  uint16_t end_port = 0;
3298 
3299  /* By default pass rtp port range end value as zero in order to get actual
3300  * RTP port range end value as configured */
3301  end_port = (uint16_t)switch_rtp_set_end_port((switch_port_t)end_port);
3302 
3303  return end_port;
3304 }
switch_port_t switch_rtp_set_end_port(switch_port_t port)
Set/Get RTP end port.
Definition: switch_rtp.c:2401
uint16_t switch_port_t
uint16_t switch_core_get_rtp_port_range_start_port ( void  )

Get RTP port range start value.

Parameters
[in]void
[out]RTPport range start value

Definition at line 3284 of file switch_core.c.

References switch_rtp_set_start_port().

3285 {
3286  uint16_t start_port = 0;
3287 
3288  /* By default pass rtp port range start value as zero in order to get actual
3289  * RTP port range start value as configured */
3290  start_port = (uint16_t)switch_rtp_set_start_port((switch_port_t)start_port);
3291 
3292  return start_port;
3293 }
switch_port_t switch_rtp_set_start_port(switch_port_t port)
Set/Get RTP start port.
Definition: switch_rtp.c:2387
uint16_t switch_port_t
switch_status_t switch_core_get_stacksizes ( switch_size_t cur,
switch_size_t max 
)

Definition at line 3249 of file switch_core.c.

References memset(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

3250 {
3251 #ifdef HAVE_SETRLIMIT
3252  struct rlimit rlp;
3253 
3254  memset(&rlp, 0, sizeof(rlp));
3255  getrlimit(RLIMIT_STACK, &rlp);
3256 
3257  *cur = rlp.rlim_cur;
3258  *max = rlp.rlim_max;
3259 
3260  return SWITCH_STATUS_SUCCESS;
3261 
3262 #else
3263 
3264  return SWITCH_STATUS_FALSE;
3265 
3266 #endif
3267 
3268 
3269 
3270 }
pack cur
memset(buf, 0, buflen)
void switch_core_recovery_flush ( const char *  technology,
const char *  profile_name 
)

Definition at line 2915 of file switch_core_sqldb.c.

References dbh, db_job::sql, switch_cache_db_execute_sql(), switch_cache_db_release_db_handle(), SWITCH_CHANNEL_LOG, switch_core_db_handle, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, switch_mprintf(), switch_safe_free, SWITCH_STATUS_SUCCESS, and zstr.

Referenced by switch_core_session_ctl().

2916 {
2917  char *sql = NULL;
2919 
2921  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
2922  return;
2923  }
2924 
2925  if (zstr(technology)) {
2926 
2927  if (zstr(profile_name)) {
2928  sql = switch_mprintf("delete from recovery");
2929  } else {
2931  }
2932 
2933  } else {
2934  if (zstr(profile_name)) {
2935  sql = switch_mprintf("delete from recovery where technology='%q' ", technology);
2936  } else {
2937  sql = switch_mprintf("delete from recovery where technology='%q' and profile_name='%q'", technology, profile_name);
2938  }
2939  }
2940 
2941  if (sql) {
2942  switch_cache_db_execute_sql(dbh, sql, NULL);
2943  switch_safe_free(sql);
2944  }
2945 
2947 }
#define SWITCH_CHANNEL_LOG
#define zstr(x)
Definition: switch_utils.h:281
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
switch_cache_db_handle_t * dbh
#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 ...
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_status_t switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err)
Executes the sql.
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
int switch_core_recovery_recover ( const char *  technology,
const char *  profile_name 
)

Definition at line 3049 of file switch_core_sqldb.c.

References dbh, recover_callback(), db_job::sql, sql_manager, switch_cache_db_execute_sql(), switch_cache_db_execute_sql_callback(), switch_cache_db_release_db_handle(), SWITCH_CHANNEL_LOG, switch_core_db_handle, switch_core_get_uuid(), SWITCH_LOG_ERROR, switch_log_printf(), switch_mprintf(), switch_safe_free, SWITCH_STATUS_SUCCESS, and zstr.

Referenced by switch_core_session_ctl().

3051 {
3052  char *sql = NULL;
3053  char *errmsg = NULL;
3055  int r = 0;
3056 
3057  if (!sql_manager.manage) {
3058  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DATABASE NOT AVAIALBLE, REVCOVERY NOT POSSIBLE\n");
3059  return 0;
3060  }
3061 
3063  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
3064  return 0;
3065  }
3066 
3067  if (zstr(technology)) {
3068 
3069  if (zstr(profile_name)) {
3070  sql = switch_mprintf("select technology, profile_name, hostname, uuid, metadata "
3071  "from recovery where runtime_uuid!='%q'",
3073  } else {
3074  sql = switch_mprintf("select technology, profile_name, hostname, uuid, metadata "
3075  "from recovery where runtime_uuid!='%q' and profile_name='%q'",
3076  switch_core_get_uuid(), profile_name);
3077  }
3078 
3079  } else {
3080 
3081  if (zstr(profile_name)) {
3082  sql = switch_mprintf("select technology, profile_name, hostname, uuid, metadata "
3083  "from recovery where technology='%q' and runtime_uuid!='%q'",
3084  technology, switch_core_get_uuid());
3085  } else {
3086  sql = switch_mprintf("select technology, profile_name, hostname, uuid, metadata "
3087  "from recovery where technology='%q' and runtime_uuid!='%q' and profile_name='%q'",
3088  technology, switch_core_get_uuid(), profile_name);
3089  }
3090  }
3091 
3092 
3094 
3095  if (errmsg) {
3096  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
3097  switch_safe_free(errmsg);
3098  }
3099 
3100  switch_safe_free(sql);
3101 
3102  if (zstr(technology)) {
3103  if (zstr(profile_name)) {
3104  sql = switch_mprintf("delete from recovery where runtime_uuid!='%q'",
3106  } else {
3107  sql = switch_mprintf("delete from recovery where runtime_uuid!='%q' and profile_name='%q'",
3108  switch_core_get_uuid(), profile_name);
3109  }
3110  } else {
3111  if (zstr(profile_name)) {
3112  sql = switch_mprintf("delete from recovery where runtime_uuid!='%q' and technology='%q' ",
3113  switch_core_get_uuid(), technology);
3114  } else {
3115  sql = switch_mprintf("delete from recovery where runtime_uuid!='%q' and technology='%q' and profile_name='%q'",
3116  switch_core_get_uuid(), technology, profile_name);
3117  }
3118  }
3119 
3120  switch_cache_db_execute_sql(dbh, sql, NULL);
3121  switch_safe_free(sql);
3122 
3124 
3125  return r;
3126 
3127 }
#define SWITCH_CHANNEL_LOG
#define zstr(x)
Definition: switch_utils.h:281
char * switch_core_get_uuid(void)
Retrieve the unique identifier from the core.
Definition: switch_core.c:482
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
switch_cache_db_handle_t * dbh
#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 int recover_callback(void *pArg, int argc, char **argv, char **columnNames)
switch_status_t switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh, const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err)
Executes the sql and uses callback for row-by-row processing.
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_status_t switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err)
Executes the sql.
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
static struct @3 sql_manager
void switch_core_recovery_track ( switch_core_session_t session)

Definition at line 3194 of file switch_core_sqldb.c.

References CF_ANSWERED, CF_RECOVERING, CF_TRACKABLE, CF_TRACKED, CS_SOFT_EXECUTE, db_job::sql, sql_manager, switch_channel_get_state(), switch_channel_get_variable_dup(), switch_channel_set_flag, switch_channel_test_flag(), switch_core_get_switchname(), switch_core_get_uuid(), switch_core_session_get_channel(), switch_core_session_get_uuid(), SWITCH_FALSE, switch_ivr_generate_xml_cdr(), switch_mprintf(), switch_safe_free, switch_sql_queue_manager_push(), SWITCH_STATUS_SUCCESS, switch_str_nil, switch_xml_free(), and switch_xml_toxml_nolock().

Referenced by switch_channel_clear_flag(), switch_channel_perform_mark_answered(), switch_core_media_activate_rtp(), and switch_core_session_perform_receive_message().

3195 {
3196  switch_xml_t cdr = NULL;
3197  char *xml_cdr_text = NULL;
3198  char *sql = NULL;
3200  const char *profile_name;
3201  const char *technology;
3202 
3203  if (!sql_manager.manage) {
3204  return;
3205  }
3206 
3208  return;
3209  }
3210 
3212  return;
3213  }
3214 
3215  profile_name = switch_channel_get_variable_dup(channel, "recovery_profile_name", SWITCH_FALSE, -1);
3216  technology = session->endpoint_interface->interface_name;
3217 
3218  if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
3219  xml_cdr_text = switch_xml_toxml_nolock(cdr, SWITCH_FALSE);
3220  switch_xml_free(cdr);
3221  }
3222 
3223  if (xml_cdr_text) {
3224  if (switch_channel_test_flag(channel, CF_TRACKED)) {
3225  sql = switch_mprintf("update recovery set metadata='%q' where uuid='%q'", xml_cdr_text, switch_core_session_get_uuid(session));
3226  } else {
3227  sql = switch_mprintf("insert into recovery (runtime_uuid, technology, profile_name, hostname, uuid, metadata) "
3228  "values ('%q','%q','%q','%q','%q','%q')",
3229  switch_core_get_uuid(), switch_str_nil(technology),
3230  switch_str_nil(profile_name), switch_core_get_switchname(), switch_core_session_get_uuid(session), xml_cdr_text);
3231  }
3232 
3234 
3235  switch_safe_free(xml_cdr_text);
3237 
3238  }
3239 
3240 }
const char * switch_core_get_switchname(void)
Definition: switch_core.c:349
switch_channel_state_t switch_channel_get_state(switch_channel_t *channel)
Get the current state of a channel in the state engine.
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
A representation of an XML tree.
Definition: switch_xml.h:76
const char * switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup, int idx)
Retrieve a variable from a given channel.
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
char * switch_core_get_uuid(void)
Retrieve the unique identifier from the core.
Definition: switch_core.c:482
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:903
#define switch_channel_set_flag(_c, _f)
char * switch_xml_toxml_nolock(switch_xml_t xml, _In_ switch_bool_t prn_header)
switch_endpoint_interface_t * endpoint_interface
switch_status_t switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
switch_status_t switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t *xml_cdr)
Generate an XML CDR report.
Definition: switch_ivr.c:2713
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
static struct @3 sql_manager
void switch_core_recovery_untrack ( switch_core_session_t session,
switch_bool_t  force 
)

Definition at line 3156 of file switch_core_sqldb.c.

References CF_ANSWERED, CF_RECOVERING, CF_TRACKABLE, CF_TRACKED, CS_SOFT_EXECUTE, db_job::sql, sql_manager, switch_channel_clear_flag(), switch_channel_get_state(), switch_channel_test_flag(), switch_core_get_uuid(), switch_core_session_get_channel(), switch_core_session_get_uuid(), SWITCH_FALSE, switch_mprintf(), and switch_sql_queue_manager_push().

Referenced by switch_core_standard_on_hangup().

3157 {
3158  char *sql = NULL;
3160 
3161  if (!sql_manager.manage) {
3162  return;
3163  }
3164 
3166  return;
3167  }
3168 
3169  if (!switch_channel_test_flag(channel, CF_TRACKABLE)) {
3170  return;
3171  }
3172 
3173  if ((switch_channel_test_flag(channel, CF_RECOVERING))) {
3174  return;
3175  }
3176 
3177  if (switch_channel_test_flag(channel, CF_TRACKED) || force) {
3178 
3179  if (force) {
3180  sql = switch_mprintf("delete from recovery where uuid='%q'", switch_core_session_get_uuid(session));
3181 
3182  } else {
3183  sql = switch_mprintf("delete from recovery where runtime_uuid='%q' and uuid='%q'",
3185  }
3186 
3188 
3190  }
3191 
3192 }
switch_channel_state_t switch_channel_get_state(switch_channel_t *channel)
Get the current state of a channel in the state engine.
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
char * switch_core_get_uuid(void)
Retrieve the unique identifier from the core.
Definition: switch_core.c:482
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
switch_status_t switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
static struct @3 sql_manager
void switch_core_session_debug_pool ( switch_stream_handle_t stream)

Definition at line 2927 of file switch_core_session.c.

References switch_session_manager::busy, switch_session_manager::running, and session_manager.

2928 {
2929  stream->write_function(stream, "Thread pool: running:%d busy:%d popping:%d\n",
2931 }
struct switch_session_manager session_manager
switch_stream_handle_write_function_t write_function
switch_bool_t switch_core_session_in_thread ( switch_core_session_t session)

Definition at line 1614 of file switch_core_session.c.

References SWITCH_FALSE, switch_thread_equal(), switch_thread_self(), and SWITCH_TRUE.

Referenced by switch_channel_perform_answer(), switch_channel_set_direction(), switch_channel_state_change_pending(), switch_ivr_3p_nomedia(), switch_ivr_nomedia(), and switch_ivr_parse_signal_data().

1615 {
1617 }
int switch_thread_equal(switch_thread_id_t tid1, switch_thread_id_t tid2)
Compare two thread ids.
Definition: switch_apr.c:88
switch_thread_id_t switch_thread_self(void)
Definition: switch_apr.c:79
switch_thread_id_t thread_id
switch_status_t switch_core_session_request_video_refresh ( switch_core_session_t session)

Definition at line 10911 of file switch_core_media.c.

References CF_VIDEO, switch_core_session_message::from, switch_media_handle_s::last_video_refresh_req, switch_core_session_message::message_id, switch_assert, switch_channel_test_flag(), switch_core_session_get_channel(), switch_core_session_receive_message, SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ, switch_micro_time_now(), SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and VIDEO_REFRESH_FREQ.

Referenced by do_flush(), dtls_state_ready(), eavesdrop_callback(), jb_frame_inc_line(), jb_next_packet_by_seq(), read_rtp_packet(), switch_channel_perform_video_sync(), switch_channel_set_flag_value(), switch_core_session_execute_application_get_flags(), switch_core_session_read_video_frame(), switch_core_session_send_and_request_video_refresh(), switch_core_session_stop_media(), switch_core_session_video_reinit(), switch_core_session_video_reset(), switch_core_session_wait_for_video_input_params(), switch_ivr_eavesdrop_session(), switch_ivr_record_file(), switch_jb_get_packet(), switch_jb_put_packet(), switch_jb_reset(), switch_rtp_set_video_buffer_size(), and video_helper_thread().

10912 {
10914  switch_media_handle_t *smh = NULL;
10915 
10916  switch_assert(session);
10917 
10918  if (!(smh = session->media_handle)) {
10919  return SWITCH_STATUS_FALSE;
10920  }
10921 
10922  if (switch_channel_test_flag(channel, CF_VIDEO)) {
10923  switch_core_session_message_t msg = { 0 };
10925 
10927  return SWITCH_STATUS_BREAK;
10928  }
10929 
10930  smh->last_video_refresh_req = now;
10931 
10932  msg.from = __FILE__;
10934  switch_core_session_receive_message(session, &msg);
10935  return SWITCH_STATUS_SUCCESS;
10936  }
10937 
10938  return SWITCH_STATUS_FALSE;
10939 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
switch_core_session_message_types_t message_id
Definition: switch_core.h:181
#define VIDEO_REFRESH_FREQ
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
A message object designed to allow unlike technologies to exchange data.
Definition: switch_core.h:177
switch_media_handle_t * media_handle
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
int64_t switch_time_t
Definition: switch_apr.h:188
switch_time_t last_video_refresh_req
#define switch_core_session_receive_message(_session, _message)
Definition: switch_core.h:1217
#define switch_assert(expr)
switch_status_t switch_core_session_send_and_request_video_refresh ( switch_core_session_t session)

Definition at line 10941 of file switch_core_media.c.

References CF_VIDEO, switch_channel_test_flag(), switch_core_media_gen_key_frame, switch_core_session_request_video_refresh(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_session_video_reinit().

10942 {
10943  if (switch_channel_test_flag(session->channel, CF_VIDEO)) {
10946  return SWITCH_STATUS_SUCCESS;
10947  }
10948 
10949  return SWITCH_STATUS_FALSE;
10950 }
#define switch_core_media_gen_key_frame(_session)
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
switch_status_t switch_core_session_request_video_refresh(switch_core_session_t *session)
switch_channel_t * channel
void switch_core_set_signal_handlers ( void  )

Definition at line 2494 of file switch_core.c.

References handle_SIGHUP().

Referenced by switch_core_init_and_modload(), switch_loadable_module_load_file(), and switch_system_fork().

2495 {
2496  /* set signal handlers */
2497  signal(SIGINT, SIG_IGN);
2498 #ifdef SIGPIPE
2499  signal(SIGPIPE, SIG_IGN);
2500 #endif
2501 #ifdef SIGALRM
2502  signal(SIGALRM, SIG_IGN);
2503 #endif
2504 #ifdef SIGQUIT
2505  signal(SIGQUIT, SIG_IGN);
2506 #endif
2507 #ifdef SIGPOLL
2508  signal(SIGPOLL, SIG_IGN);
2509 #endif
2510 #ifdef SIGIO
2511  signal(SIGIO, SIG_IGN);
2512 #endif
2513 #ifdef TRAP_BUS
2514  signal(SIGBUS, handle_SIGBUS);
2515 #endif
2516 #ifdef SIGUSR1
2517  signal(SIGUSR1, handle_SIGHUP);
2518 #endif
2519  signal(SIGHUP, handle_SIGHUP);
2520 }
static void handle_SIGHUP(int sig)
Definition: switch_core.c:2012
void switch_core_sql_exec ( const char *  sql)

Definition at line 3142 of file switch_core_sqldb.c.

References runtime, SCF_USE_SQL, sql_manager, switch_sql_queue_manager_push(), switch_test_flag, and SWITCH_TRUE.

Referenced by switch_console_set_complete().

3143 {
3144  if (!sql_manager.manage) {
3145  return;
3146  }
3147 
3148  if (!switch_test_flag((&runtime), SCF_USE_SQL)) {
3149  return;
3150  }
3151 
3152 
3154 }
struct switch_runtime runtime
Definition: switch_core.c:64
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
switch_status_t switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup)
static struct @3 sql_manager
switch_status_t switch_core_thread_set_cpu_affinity ( int  cpu)

Definition at line 1723 of file switch_core.c.

References SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_autobind_cpu(), and SWITCH_MODULE_RUNTIME_FUNCTION().

1724 {
1726 
1727  if (cpu > -1) {
1728 
1729 #ifdef HAVE_CPU_SET_MACROS
1730  cpu_set_t set;
1731 
1732  CPU_ZERO(&set);
1733  CPU_SET(cpu, &set);
1734 
1735  if (!sched_setaffinity(0, sizeof(set), &set)) {
1736  status = SWITCH_STATUS_SUCCESS;
1737  }
1738 
1739 #else
1740 #if WIN32
1741  if (SetThreadAffinityMask(GetCurrentThread(), (DWORD_PTR) cpu)) {
1742  status = SWITCH_STATUS_SUCCESS;
1743  }
1744 #endif
1745 #endif
1746  }
1747 
1748  return status;
1749 }
switch_status_t
Common return values.
uint32_t switch_default_ptime ( const char *  name,
uint32_t  number 
)

Definition at line 2026 of file switch_core.c.

References switch_runtime::ptimes, and switch_core_hash_find().

Referenced by add_audio_codec(), switch_core_media_negotiate_sdp(), switch_loadable_module_get_codecs(), and switch_loadable_module_get_codecs_sorted().

2027 {
2028  uint32_t *p;
2029 
2030  if ((p = switch_core_hash_find(runtime.ptimes, name))) {
2031  return *p;
2032  }
2033 
2034  return 20;
2035 }
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
struct switch_runtime runtime
Definition: switch_core.c:64
switch_hash_t * ptimes
uint32_t switch_default_rate ( const char *  name,
uint32_t  number 
)

Definition at line 2037 of file switch_core.c.

Referenced by switch_loadable_module_get_codecs_sorted().

2038 {
2039 
2040  if (!strcasecmp(name, "opus")) {
2041  return 48000;
2042  } else if (!strncasecmp(name, "h26", 3)) { // h26x
2043  return 90000;
2044  } else if (!strncasecmp(name, "vp", 2)) { // vp8, vp9
2045  return 90000;
2046  }
2047 
2048  return 8000;
2049 }
pid_t switch_fork ( void  )

Definition at line 3134 of file switch_core.c.

References set_low_priority().

Referenced by daemonize(), preprocess_exec(), switch_stream_system_fork(), and switch_system_fork().

3135 {
3136  int i = fork();
3137 
3138  if (!i) {
3139  set_low_priority();
3140  }
3141 
3142  return i;
3143 }
int32_t set_low_priority(void)
Definition: switch_core.c:932
switch_call_direction_t switch_ice_direction ( switch_core_session_t session)

Definition at line 3165 of file switch_core_media.c.

References CF_3PCC, CF_AVPF, CF_RECOVERING, CF_REINVITE, SWITCH_CALL_DIRECTION_INBOUND, SWITCH_CALL_DIRECTION_OUTBOUND, switch_channel_direction(), and switch_channel_test_flag().

Referenced by check_ice(), and switch_core_media_activate_rtp().

3166 {
3168 
3169  if (switch_channel_test_flag(session->channel, CF_3PCC)) {
3171  }
3172 
3174  && switch_channel_test_flag(session->channel, CF_AVPF)) {
3176  }
3177 
3178  return r;
3179 }
switch_call_direction_t
Definition: switch_types.h:293
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
switch_channel_t * channel
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
int switch_max_file_desc ( void  )

Definition at line 3080 of file switch_core.c.

Referenced by switch_close_extra_files().

3081 {
3082  int max = 0;
3083 
3084 #ifndef WIN32
3085 #if defined(HAVE_GETDTABLESIZE)
3086  max = getdtablesize();
3087 #else
3088  max = sysconf(_SC_OPEN_MAX);
3089 #endif
3090 #endif
3091 
3092  return max;
3093 
3094 }
static void* switch_must_malloc ( size_t  _b)
inlinestatic
static void* switch_must_realloc ( void *  _b,
size_t  _z 
)
inlinestatic
static char* switch_must_strdup ( const char *  _s)
inlinestatic

Definition at line 245 of file switch_core.h.

References switch_assert.

Referenced by preprocess_glob(), switch_xml_locate_user_merged(), switch_xml_parse_str_dynamic(), switch_xml_proc_inst(), and switch_xml_set_attr().

246 {
247  char *s = strdup(_s);
248  switch_assert(s);
249  return s;
250 }
#define switch_assert(expr)
void switch_os_yield ( void  )

Definition at line 141 of file switch_time.c.

Referenced by switch_cond_next(), switch_core_session_read_frame(), switch_event_channel_deliver_thread(), switch_event_dispatch_thread(), SWITCH_MODULE_RUNTIME_FUNCTION(), and timer_next().

142 {
143 #if defined(WIN32)
144  SwitchToThread();
145 #else
146  sched_yield();
147 #endif
148 }
void switch_say_file ( switch_say_file_handle_t sh,
const char *  fmt,
  ... 
)

Definition at line 2780 of file switch_loadable_module.c.

References buf, and switch_vsnprintf().

2781 {
2782  char buf[256] = "";
2783  int ret;
2784  va_list ap;
2785 
2786  va_start(ap, fmt);
2787 
2788  if ((ret = switch_vsnprintf(buf, sizeof(buf), fmt, ap)) > 0) {
2789  if (!sh->cnt++) {
2790  sh->stream.write_function(&sh->stream, "file_string://%s.%s", buf, sh->ext);
2791  } else if (strstr(buf, "://")) {
2792  sh->stream.write_function(&sh->stream, "!%s", buf);
2793  } else {
2794  sh->stream.write_function(&sh->stream, "!%s.%s", buf, sh->ext);
2795  }
2796 
2797  }
2798 
2799  va_end(ap);
2800 }
struct switch_stream_handle stream
switch_byte_t switch_byte_t * buf
switch_stream_handle_write_function_t write_function
int switch_vsnprintf(char *buf, switch_size_t len, const char *format, va_list ap)
Definition: switch_apr.c:194
switch_status_t switch_say_file_handle_create ( switch_say_file_handle_t **  sh,
const char *  ext,
switch_event_t **  var_event 
)

Definition at line 2757 of file switch_loadable_module.c.

References memset(), switch_assert, SWITCH_STANDARD_STREAM, SWITCH_STATUS_SUCCESS, and zstr.

2758 {
2759  switch_assert(sh);
2760 
2761  if (zstr(ext)) {
2762  ext = "wav";
2763  }
2764 
2765  *sh = malloc(sizeof(**sh));
2766  memset(*sh, 0, sizeof(**sh));
2767 
2768  SWITCH_STANDARD_STREAM((*sh)->stream);
2769 
2770  if (var_event) {
2771  (*sh)->param_event = *var_event;
2772  *var_event = NULL;
2773  }
2774 
2775  (*sh)->ext = strdup(ext);
2776 
2777  return SWITCH_STATUS_SUCCESS;
2778 }
#define zstr(x)
Definition: switch_utils.h:281
#define SWITCH_STANDARD_STREAM(s)
#define switch_assert(expr)
memset(buf, 0, buflen)
void switch_say_file_handle_destroy ( switch_say_file_handle_t **  sh)

Definition at line 2743 of file switch_loadable_module.c.

References switch_assert, switch_event_destroy(), and switch_safe_free.

2744 {
2745  switch_assert(sh);
2746 
2747  switch_safe_free((*sh)->stream.data);
2748  switch_safe_free((*sh)->ext);
2749 
2750  if ((*sh)->param_event) {
2751  switch_event_destroy(&(*sh)->param_event);
2752  }
2753  free(*sh);
2754  *sh = NULL;
2755 }
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
void switch_event_destroy(switch_event_t **event)
Destroy an event.
#define switch_assert(expr)
char* switch_say_file_handle_detach_path ( switch_say_file_handle_t sh)

Definition at line 2732 of file switch_loadable_module.c.

References switch_assert.

2733 {
2734  char *path;
2735 
2736  switch_assert(sh);
2737  path = (char *) sh->stream.data;
2738  sh->stream.data = NULL;
2739  return path;
2740 }
struct switch_stream_handle stream
#define switch_assert(expr)
char* switch_say_file_handle_get_path ( switch_say_file_handle_t sh)

Definition at line 2727 of file switch_loadable_module.c.

2728 {
2729  return (char *) sh->stream.data;
2730 }
struct switch_stream_handle stream
char* switch_say_file_handle_get_variable ( switch_say_file_handle_t sh,
const char *  var 
)

Definition at line 2715 of file switch_loadable_module.c.

References switch_event_get_header.

2716 {
2717  char *ret = NULL;
2718 
2719  if (sh->param_event) {
2720  ret = switch_event_get_header(sh->param_event, var);
2721  }
2722 
2723  return ret;
2724 
2725 }
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
switch_status_t switch_sql_queue_manager_destroy ( switch_sql_queue_manager_t **  qmp)

Definition at line 1704 of file switch_core_sqldb.c.

References do_flush(), switch_sql_queue_manager::name, switch_sql_queue_manager::numq, pool, switch_sql_queue_manager::pool, qm, switch_assert, SWITCH_CHANNEL_LOG, switch_core_destroy_memory_pool, SWITCH_LOG_INFO, switch_log_printf(), switch_sql_queue_manager_stop(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_sqldb_stop_thread().

1705 {
1709  uint32_t i;
1710 
1711  switch_assert(qmp);
1712  qm = *qmp;
1713  *qmp = NULL;
1714 
1715  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Destroying SQL queue.\n", qm->name);
1716 
1718 
1719 
1720 
1721  for(i = 0; i < qm->numq; i++) {
1722  do_flush(qm, i, NULL);
1723  }
1724 
1725  pool = qm->pool;
1727 
1728  return status;
1729 }
#define SWITCH_CHANNEL_LOG
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:640
switch_memory_pool_t * pool
switch_status_t switch_sql_queue_manager_stop(switch_sql_queue_manager_t *qm)
switch_sql_queue_manager_t * qm
switch_memory_pool_t * pool
switch_status_t
Common return values.
struct apr_pool_t switch_memory_pool_t
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.
#define switch_assert(expr)
static void do_flush(switch_sql_queue_manager_t *qm, int i, switch_cache_db_handle_t *dbh)
void switch_sql_queue_manager_execute_sql_callback ( switch_sql_queue_manager_t qm,
const char *  sql,
switch_core_db_callback_func_t  callback,
void *  pdata 
)

Definition at line 1553 of file switch_core_sqldb.c.

References new_job(), and switch_thread_pool_launch_thread().

1555 {
1556 
1558  if ((td = new_job(qm, sql, callback, NULL, NULL, NULL, pdata))) {
1560  }
1561 }
static switch_thread_data_t * new_job(switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_callback_func_t callback, switch_core_db_err_callback_func_t err_callback, switch_core_db_event_callback_func_t event_callback, switch_core_db_err_callback_func_t event_err_callback, void *pdata)
switch_status_t switch_thread_pool_launch_thread(switch_thread_data_t **tdp)
void switch_sql_queue_manager_execute_sql_callback_err ( switch_sql_queue_manager_t qm,
const char *  sql,
switch_core_db_callback_func_t  callback,
switch_core_db_err_callback_func_t  err_callback,
void *  pdata 
)

Definition at line 1563 of file switch_core_sqldb.c.

References new_job(), and switch_thread_pool_launch_thread().

1566 {
1567 
1569  if ((td = new_job(qm, sql, callback, err_callback, NULL, NULL, pdata))) {
1571  }
1572 }
static switch_thread_data_t * new_job(switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_callback_func_t callback, switch_core_db_err_callback_func_t err_callback, switch_core_db_event_callback_func_t event_callback, switch_core_db_err_callback_func_t event_err_callback, void *pdata)
switch_status_t switch_thread_pool_launch_thread(switch_thread_data_t **tdp)
void switch_sql_queue_manager_execute_sql_event_callback ( switch_sql_queue_manager_t qm,
const char *  sql,
switch_core_db_event_callback_func_t  callback,
void *  pdata 
)

Definition at line 1574 of file switch_core_sqldb.c.

References new_job(), and switch_thread_pool_launch_thread().

1576 {
1577 
1579  if ((td = new_job(qm, sql, NULL, NULL, callback, NULL, pdata))) {
1581  }
1582 }
static switch_thread_data_t * new_job(switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_callback_func_t callback, switch_core_db_err_callback_func_t err_callback, switch_core_db_event_callback_func_t event_callback, switch_core_db_err_callback_func_t event_err_callback, void *pdata)
switch_status_t switch_thread_pool_launch_thread(switch_thread_data_t **tdp)
void switch_sql_queue_manager_execute_sql_event_callback_err ( switch_sql_queue_manager_t qm,
const char *  sql,
switch_core_db_event_callback_func_t  callback,
switch_core_db_err_callback_func_t  err_callback,
void *  pdata 
)

Definition at line 1584 of file switch_core_sqldb.c.

References new_job(), and switch_thread_pool_launch_thread().

1588 {
1589 
1591  if ((td = new_job(qm, sql, NULL, NULL, callback, err_callback, pdata))) {
1593  }
1594 }
static switch_thread_data_t * new_job(switch_sql_queue_manager_t *qm, const char *sql, switch_core_db_callback_func_t callback, switch_core_db_err_callback_func_t err_callback, switch_core_db_event_callback_func_t event_callback, switch_core_db_err_callback_func_t event_err_callback, void *pdata)
switch_status_t switch_thread_pool_launch_thread(switch_thread_data_t **tdp)
switch_status_t switch_sql_queue_manager_init_name ( const char *  name,
switch_sql_queue_manager_t **  qmp,
uint32_t  numq,
const char *  dsn,
uint32_t  max_trans,
const char *  pre_trans_execute,
const char *  post_trans_execute,
const char *  inner_pre_trans_execute,
const char *  inner_post_trans_execute 
)

Definition at line 1847 of file switch_core_sqldb.c.

References switch_sql_queue_manager::cond, switch_sql_queue_manager::cond2_mutex, switch_sql_queue_manager::cond_mutex, switch_sql_queue_manager::dsn, switch_sql_queue_manager::inner_post_trans_execute, switch_sql_queue_manager::inner_pre_trans_execute, switch_sql_queue_manager::max_trans, switch_sql_queue_manager::mutex, switch_sql_queue_manager::name, switch_sql_queue_manager::numq, pool, switch_sql_queue_manager::pool, switch_sql_queue_manager::post_trans_execute, switch_sql_queue_manager::pre_trans_execute, switch_sql_queue_manager::pre_written, qm, switch_sql_queue_manager::sql_queue, switch_core_alloc, switch_core_new_memory_pool, switch_core_strdup, switch_mutex_init(), SWITCH_MUTEX_NESTED, switch_queue_create(), SWITCH_SQL_QUEUE_LEN, SWITCH_STATUS_SUCCESS, switch_thread_cond_create(), and switch_sql_queue_manager::written.

Referenced by switch_core_sqldb_start_thread().

1854 {
1857  uint32_t i;
1858 
1859  if (!numq) numq = 1;
1860 
1862  qm = switch_core_alloc(pool, sizeof(*qm));
1863 
1864  qm->pool = pool;
1865  qm->numq = numq;
1866  qm->dsn = switch_core_strdup(qm->pool, dsn);
1867  qm->name = switch_core_strdup(qm->pool, name);
1868  qm->max_trans = max_trans;
1869 
1873  switch_thread_cond_create(&qm->cond, qm->pool);
1874 
1875  qm->sql_queue = switch_core_alloc(qm->pool, sizeof(switch_queue_t *) * numq);
1876  qm->written = switch_core_alloc(qm->pool, sizeof(uint32_t) * numq);
1877  qm->pre_written = switch_core_alloc(qm->pool, sizeof(uint32_t) * numq);
1878 
1879  for (i = 0; i < qm->numq; i++) {
1881  }
1882 
1883  if (pre_trans_execute) {
1884  qm->pre_trans_execute = switch_core_strdup(qm->pool, pre_trans_execute);
1885  }
1886  if (post_trans_execute) {
1887  qm->post_trans_execute = switch_core_strdup(qm->pool, post_trans_execute);
1888  }
1889  if (inner_pre_trans_execute) {
1890  qm->inner_pre_trans_execute = switch_core_strdup(qm->pool, inner_pre_trans_execute);
1891  }
1892  if (inner_post_trans_execute) {
1893  qm->inner_post_trans_execute = switch_core_strdup(qm->pool, inner_post_trans_execute);
1894  }
1895 
1896  *qmp = qm;
1897 
1898  return SWITCH_STATUS_SUCCESS;
1899 
1900 }
struct apr_queue_t switch_queue_t
Definition: switch_apr.h:590
#define SWITCH_SQL_QUEUE_LEN
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
Definition: switch_core.h:631
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_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
switch_memory_pool_t * pool
switch_sql_queue_manager_t * qm
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
switch_memory_pool_t * pool
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
switch_thread_cond_t * cond
struct apr_pool_t switch_memory_pool_t
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1109
void switch_sql_queue_manager_pause ( switch_sql_queue_manager_t qm,
switch_bool_t  flush 
)

Definition at line 1626 of file switch_core_sqldb.c.

References do_flush(), switch_mutex_lock(), and switch_mutex_unlock().

1627 {
1628  uint32_t i;
1629 
1630  switch_mutex_lock(qm->mutex);
1631  qm->paused = 1;
1633 
1634  if (flush) {
1635  for(i = 0; i < qm->numq; i++) {
1636  do_flush(qm, i, NULL);
1637  }
1638  }
1639 
1640 }
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
static void do_flush(switch_sql_queue_manager_t *qm, int i, switch_cache_db_handle_t *dbh)
switch_status_t switch_sql_queue_manager_push ( switch_sql_queue_manager_t qm,
const char *  sql,
uint32_t  pos,
switch_bool_t  dup 
)

Definition at line 1731 of file switch_core_sqldb.c.

References qm_wake(), sql_manager, SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypush(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_yield.

Referenced by core_event_handler(), switch_core_add_registration(), switch_core_del_registration(), switch_core_expire_registration(), switch_core_recovery_track(), switch_core_recovery_untrack(), and switch_core_sql_exec().

1732 {
1733  char *sqlptr = NULL;
1734  switch_status_t status;
1735  int x = 0;
1736 
1737  if (sql_manager.paused || qm->thread_running != 1) {
1739  if (!dup) free((char *)sql);
1740  qm_wake(qm);
1741  return SWITCH_STATUS_SUCCESS;
1742  }
1743 
1744  if (qm->thread_running != 1) {
1745  if (!dup) free((char *)sql);
1746  return SWITCH_STATUS_FALSE;
1747  }
1748 
1749  if (pos > qm->numq - 1) {
1750  pos = 0;
1751  }
1752 
1753  sqlptr = dup ? strdup(sql) : (char *)sql;
1754 
1755  do {
1756  switch_mutex_lock(qm->mutex);
1757  status = switch_queue_trypush(qm->sql_queue[pos], sqlptr);
1759  if (status != SWITCH_STATUS_SUCCESS) {
1760  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Delay %d sending sql\n", x);
1761  if (x++) {
1762  switch_yield(1000000 * x);
1763  }
1764  }
1765  } while(status != SWITCH_STATUS_SUCCESS);
1766 
1767  qm_wake(qm);
1768 
1769  return SWITCH_STATUS_SUCCESS;
1770 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_status_t
Common return values.
static int qm_wake(switch_sql_queue_manager_t *qm)
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1155
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.
static struct @3 sql_manager
switch_status_t switch_sql_queue_manager_push_confirm ( switch_sql_queue_manager_t qm,
const char *  sql,
uint32_t  pos,
switch_bool_t  dup 
)

Definition at line 1773 of file switch_core_sqldb.c.

References dbh, qm_wake(), sql_manager, switch_cache_db_execute_sql(), switch_cache_db_get_db_handle_dsn, switch_cache_db_release_db_handle(), SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_push(), switch_sql_queue_manager_size(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_yield.

1774 {
1775 #define EXEC_NOW
1776 #ifdef EXEC_NOW
1778 
1779  if (sql_manager.paused || qm->thread_running != 1) {
1781  if (!dup) free((char *)sql);
1782  qm_wake(qm);
1783  return SWITCH_STATUS_SUCCESS;
1784  }
1785 
1787  switch_cache_db_execute_sql(dbh, (char *)sql, NULL);
1789  }
1790 
1791  if (!dup) free((char *)sql);
1792 
1793 #else
1794 
1795  int size, x = 0, sanity = 0;
1796  uint32_t written, want;
1797 
1798  if (sql_manager.paused) {
1799  if (!dup) free((char *)sql);
1800  qm_wake(qm);
1801  return SWITCH_STATUS_SUCCESS;
1802  }
1803 
1804  if (qm->thread_running != 1) {
1805  if (!dup) free((char *)sql);
1806  return SWITCH_STATUS_FALSE;
1807  }
1808 
1809  if (pos > qm->numq - 1) {
1810  pos = 0;
1811  }
1812 
1813  switch_mutex_lock(qm->mutex);
1814  qm->confirm++;
1815  switch_queue_push(qm->sql_queue[pos], dup ? strdup(sql) : (char *)sql);
1816  written = qm->pre_written[pos];
1817  size = switch_sql_queue_manager_size(qm, pos);
1818  want = written + size;
1820 
1821  qm_wake(qm);
1822 
1823  while((qm->written[pos] < want) || (qm->written[pos] >= written && want < written && qm->written[pos] > want)) {
1824  switch_yield(5000);
1825 
1826  if (++x == 200) {
1827  qm_wake(qm);
1828  x = 0;
1829  if (++sanity == 20) {
1830  break;
1831  }
1832  }
1833  }
1834 
1835  switch_mutex_lock(qm->mutex);
1836  qm->confirm--;
1838 #endif
1839 
1840  return SWITCH_STATUS_SUCCESS;
1841 }
#define SWITCH_CHANNEL_LOG
#define switch_cache_db_get_db_handle_dsn(_a, _b)
Definition: switch_core.h:2536
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
int switch_sql_queue_manager_size(switch_sql_queue_manager_t *qm, uint32_t index)
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_cache_db_handle_t * dbh
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 int qm_wake(switch_sql_queue_manager_t *qm)
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1129
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_status_t switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err)
Executes the sql.
static struct @3 sql_manager
void switch_sql_queue_manager_resume ( switch_sql_queue_manager_t qm)

Definition at line 1616 of file switch_core_sqldb.c.

References qm_wake(), switch_mutex_lock(), and switch_mutex_unlock().

1617 {
1618  switch_mutex_lock(qm->mutex);
1619  qm->paused = 0;
1621 
1622  qm_wake(qm);
1623 
1624 }
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
static int qm_wake(switch_sql_queue_manager_t *qm)
int switch_sql_queue_manager_size ( switch_sql_queue_manager_t qm,
uint32_t  index 
)

Definition at line 1642 of file switch_core_sqldb.c.

References switch_mutex_lock(), switch_mutex_unlock(), and switch_queue_size().

Referenced by switch_sql_queue_manager_push_confirm().

1643 {
1644  int size = 0;
1645 
1646  switch_mutex_lock(qm->mutex);
1647  if (index < qm->numq) {
1648  size = switch_queue_size(qm->sql_queue[index]);
1649  }
1651 
1652  return size;
1653 }
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1114
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_status_t switch_sql_queue_manager_start ( switch_sql_queue_manager_t qm)

Definition at line 1688 of file switch_core_sqldb.c.

References apr_threadattr_t::pool, SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, switch_log_printf(), SWITCH_PRI_NORMAL, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_priority_set(), switch_threadattr_stacksize_set(), and switch_user_sql_thread().

Referenced by switch_core_sqldb_start_thread().

1689 {
1690  switch_threadattr_t *thd_attr;
1691 
1692  if (!qm->thread_running) {
1693  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Starting SQL thread.\n", qm->name);
1694  switch_threadattr_create(&thd_attr, qm->pool);
1697  switch_thread_create(&qm->thread, thd_attr, switch_user_sql_thread, qm, qm->pool);
1698  return SWITCH_STATUS_SUCCESS;
1699  }
1700 
1701  return SWITCH_STATUS_FALSE;
1702 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:660
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:551
switch_memory_pool_t * pool
static void *SWITCH_THREAD_FUNC switch_user_sql_thread(switch_thread_t *thread, void *obj)
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_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_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority)
Definition: switch_apr.c:665
switch_status_t switch_sql_queue_manager_stop ( switch_sql_queue_manager_t qm)

Definition at line 1655 of file switch_core_sqldb.c.

References qm_wake(), SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, switch_log_printf(), switch_queue_interrupt_all(), switch_queue_push(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_thread_join(), and switch_yield.

Referenced by switch_sql_queue_manager_destroy().

1656 {
1658  uint32_t i, sanity = 100;
1659 
1660  if (qm->thread_running == 1) {
1661  qm->thread_running = -1;
1662 
1663  while(--sanity && qm->thread_running == -1) {
1664  for(i = 0; i < qm->numq; i++) {
1665  switch_queue_push(qm->sql_queue[i], NULL);
1667  }
1668  qm_wake(qm);
1669 
1670  if (qm->thread_running == -1) {
1671  switch_yield(100000);
1672  }
1673  }
1674  status = SWITCH_STATUS_SUCCESS;
1675  }
1676 
1677  if (qm->thread) {
1678  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Stopping SQL thread.\n", qm->name);
1679  qm_wake(qm);
1680  switch_thread_join(&status, qm->thread);
1681  qm->thread = NULL;
1682  status = SWITCH_STATUS_SUCCESS;
1683  }
1684 
1685  return status;
1686 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1255
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
switch_status_t
Common return values.
switch_status_t switch_queue_interrupt_all(switch_queue_t *queue)
Definition: switch_apr.c:1145
static int qm_wake(switch_sql_queue_manager_t *qm)
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1129
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.
int switch_stream_system_fork ( const char *  cmd,
switch_stream_handle_t stream 
)

Definition at line 3206 of file switch_core.c.

References switch_close_extra_files(), switch_fork(), switch_system(), and SWITCH_TRUE.

Referenced by preprocess_exec_set(), and switch_stream_system().

3207 {
3208 #ifdef WIN32
3209  return switch_system(cmd, SWITCH_TRUE);
3210 #else
3211  int fds[2], pid = 0;
3212 
3213  if (pipe(fds)) {
3214  goto end;
3215  } else { /* good to go */
3216  pid = switch_fork();
3217 
3218  if (pid < 0) { /* ok maybe not */
3219  close(fds[0]);
3220  close(fds[1]);
3221  goto end;
3222  } else if (pid) { /* parent */
3223  char buf[1024] = "";
3224  int bytes;
3225  close(fds[1]);
3226  while ((bytes = read(fds[0], buf, sizeof(buf))) > 0) {
3227  stream->raw_write_function(stream, (unsigned char *)buf, bytes);
3228  }
3229  close(fds[0]);
3230  waitpid(pid, NULL, 0);
3231  } else { /* child */
3232  switch_close_extra_files(fds, 2);
3233  close(fds[0]);
3234  dup2(fds[1], STDOUT_FILENO);
3235  switch_system(cmd, SWITCH_TRUE);
3236  close(fds[1]);
3237  exit(0);
3238  }
3239  }
3240 
3241  end:
3242 
3243  return 0;
3244 
3245 #endif
3246 
3247 }
switch_stream_handle_raw_write_function_t raw_write_function
void switch_close_extra_files(int *keep, int keep_ttl)
Definition: switch_core.c:3096
int switch_system(const char *cmd, switch_bool_t wait)
Definition: switch_core.c:3194
switch_byte_t switch_byte_t * buf
pid_t switch_fork(void)
Definition: switch_core.c:3134
const char* switch_version_full ( void  )

Definition at line 53 of file switch_version.c.

References switch_version_full_str.

Referenced by main(), send_heartbeat(), and switch_core_init_and_modload().

const char * switch_version_full_str
const char* switch_version_full_human ( void  )

Definition at line 54 of file switch_version.c.

References switch_version_full_human_str.

const char * switch_version_full_human_str
const char* switch_version_major ( void  )

Definition at line 47 of file switch_version.c.

References switch_version_major_str.

const char * switch_version_major_str
const char* switch_version_micro ( void  )

Definition at line 49 of file switch_version.c.

References switch_version_micro_str.

const char * switch_version_micro_str
const char* switch_version_minor ( void  )

Definition at line 48 of file switch_version.c.

References switch_version_minor_str.

const char * switch_version_minor_str
const char* switch_version_revision ( void  )

Definition at line 51 of file switch_version.c.

References switch_version_revision_str.

const char * switch_version_revision_str
const char* switch_version_revision_human ( void  )

Definition at line 52 of file switch_version.c.

References switch_version_revision_human_str.

Referenced by ice_out(), main(), and switch_core_init_and_modload().

const char * switch_version_revision_human_str