RTS API Documentation  1.10.11
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_database_interface_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_strndup(_pool, _todup, _len)   switch_core_perform_strndup(_pool, _todup, _len, __FILE__, __SWITCH_FUNC__, __LINE__)
 
#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_hupall_matching_vars(_vs, _c)   switch_core_session_hupall_matching_vars_ans(_vs, _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_insert_alloc(_h, _k, _s)   switch_core_hash_insert_alloc_destructor(_h, _k, _s, NULL)
 
#define switch_core_hash_insert_dup(_h, _k, _d)   switch_core_hash_insert_dup_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)
 
#define switch_core_session_request_video_refresh(_s)   _switch_core_session_request_video_refresh(_s, 0, __FILE__, __SWITCH_FUNC__, __LINE__)
 
#define switch_core_session_force_request_video_refresh(_s)   _switch_core_session_request_video_refresh(_s, 1, __FILE__, __SWITCH_FUNC__, __LINE__)
 

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), CDF_NONEXPIRING = (1 << 2) }
 
enum  switch_cache_db_handle_type_t { SCDB_TYPE_CORE_DB, SCDB_TYPE_ODBC, SCDB_TYPE_DATABASE_INTERFACE }
 

Functions

static void * switch_must_malloc (size_t _b)
 
static void * switch_must_realloc (void *_b, size_t _z)
 
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...
 
void switch_core_media_bug_set_media_params (switch_media_bug_t *bug, switch_mm_t *mm)
 
void switch_core_media_bug_get_media_params (switch_media_bug_t *bug, switch_mm_t *mm)
 
const char * switch_core_media_bug_get_text (switch_media_bug_t *bug)
 
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, switch_bool_t destroy)
 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_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_tswitch_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)
 
void switch_core_pool_stats (switch_stream_handle_t *stream)
 
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_perform_strndup (_In_ switch_memory_pool_t *pool, _In_z_ const char *todup, size_t len, _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)
 
switch_status_t switch_core_session_set_external_id (_In_ switch_core_session_t *session, _In_z_ const char *use_external_id)
 
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)
 
switch_status_t switch_thread_pool_wait (switch_thread_data_t *td, int ms)
 
_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...
 
const char * switch_core_session_get_external_id (_In_ switch_core_session_t *session)
 Retrieve the unique external 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)
 
uint32_t switch_core_session_hupall_matching_vars_ans (_In_ switch_event_t *vars, _In_ switch_call_cause_t cause, switch_hup_type_t type)
 Hangup all sessions which match specific channel variable(s) More...
 
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)
 
uint32_t switch_core_session_stack_count (switch_core_session_t *session, int x)
 
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...
 
const char * switch_core_session_get_text_buffer (switch_core_session_t *session)
 
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_bool_t switch_core_session_transcoding (switch_core_session_t *session_a, switch_core_session_t *session_b, switch_media_type_t type)
 
void switch_core_session_passthru (switch_core_session_t *session, switch_media_type_t type, switch_bool_t on)
 
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_try_reset (switch_core_session_t *session, switch_bool_t flush_dtmf, switch_bool_t reset_read_codec)
 Reset the buffers and resampler on a session, fail if can not lock codec mutexes. 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_pointer (switch_hash_t *hash, const void *data)
 Insert data into a hash with an auto-generated key based on the data pointer. More...
 
switch_status_t switch_core_hash_insert_auto_free (switch_hash_t *hash, const char *key, const void *data)
 Insert data into a hash and set flags so the value is automatically freed on delete. More...
 
switch_status_t switch_core_hash_insert_dup_auto_free (switch_hash_t *hash, const char *key, const char *str)
 Insert strdup(str) into a hash and set flags so the value is automatically freed on delete. 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...
 
void * switch_core_hash_insert_alloc_destructor (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ size_t size, hashtable_destructor_t destructor)
 Allocate memory and insert into a hash. More...
 
switch_status_t switch_core_hash_insert_dup_destructor (_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const char *str, hashtable_destructor_t destructor)
 Insert strdup(str) 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_core_db_tswitch_core_db_open_in_memory (const char *uri)
 Open a core db (SQLite) in-memory. 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_pre_close (_In_ switch_file_handle_t *fh)
 Pre close an open file handle, then can get file size etc., no more wirte to the file. More...
 
switch_status_t switch_core_file_handle_dup (switch_file_handle_t *oldfh, switch_file_handle_t **newfh, switch_memory_pool_t *pool)
 Duplicates a file handle using another pool. 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, const 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_port_token (const char *ip_str, int port, const char *list_name, const char **token)
 
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_ex (switch_cache_db_handle_t **dbh, const char *dsn, switch_bool_t make_module_no_unloadable, const char *file, const char *func, int line)
 
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_bool_t switch_cache_db_test_reactive_ex (switch_cache_db_handle_t *db, const char *test_sql, const char *drop_sql, const char *reactive_sql, const char *row_size_limited_reactive_sql)
 
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_cache_db_database_interface_flush_handles (switch_database_interface_t *database_interface)
 
switch_status_t switch_core_check_core_db_dsn (void)
 Returns error if no suitable database interface found to serve core db dsn. More...
 
switch_status_t switch_database_available (char *dsn)
 Returns error if no suitable database interface found for a dsn. More...
 
void switch_core_set_signal_handlers (void)
 
uint32_t switch_core_debug_level (void)
 
int32_t switch_core_sps (void)
 
int32_t switch_core_sps_last (void)
 
int32_t switch_core_sps_peak (void)
 
int32_t switch_core_sps_peak_fivemin (void)
 
int32_t switch_core_sessions_peak (void)
 
int32_t switch_core_sessions_peak_fivemin (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)
 
uint32_t switch_core_max_audio_channels (uint32_t limit)
 
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)
 
switch_bool_t switch_core_check_dtls_pem (const char *file)
 
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, int force, const char *file, const char *func, int line)
 
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)
 
int switch_spawn (const char *cmd, switch_bool_t wait)
 
int switch_stream_spawn (const char *cmd, switch_bool_t shell, switch_bool_t wait, switch_stream_handle_t *stream)
 
void switch_core_session_debug_pool (switch_stream_handle_t *stream)
 
switch_status_t switch_core_session_override_io_routines (switch_core_session_t *session, switch_io_routines_t *ior)
 
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)
 
switch_status_t switch_core_session_start_text_thread (switch_core_session_t *session)
 
const char * switch_core_get_event_channel_key_separator (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

◆ CACHE_DB_LEN

#define CACHE_DB_LEN   256

Definition at line 2555 of file switch_core.h.

Referenced by _switch_cache_db_get_db_handle(), and switch_cache_db_status().

◆ DTLS_SRTP_FNAME

#define DTLS_SRTP_FNAME   "dtls-srtp"

◆ MAX_FPLEN

#define MAX_FPLEN   64

Definition at line 149 of file switch_core.h.

Referenced by switch_core_cert_expand_fingerprint(), and switch_core_cert_verify().

◆ MAX_FPSTRLEN

#define MAX_FPSTRLEN   192

Definition at line 150 of file switch_core.h.

◆ MESSAGE_STAMP_FFL

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

◆ MESSAGE_STRING_ARG_MAX

#define MESSAGE_STRING_ARG_MAX   10

Definition at line 177 of file switch_core.h.

Referenced by switch_core_session_free_message().

◆ switch_cache_db_get_db_handle

#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 2653 of file switch_core.h.

◆ switch_cache_db_get_db_handle_dsn

#define switch_cache_db_get_db_handle_dsn (   _a,
  _b 
)    _switch_cache_db_get_db_handle_dsn(_a, _b, __FILE__, __SWITCH_FUNC__, __LINE__)

◆ switch_cache_db_persistant_execute_trans

#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 2741 of file switch_core.h.

◆ switch_core_db_handle

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

◆ switch_core_session_force_request_video_refresh

#define switch_core_session_force_request_video_refresh (   _s)    _switch_core_session_request_video_refresh(_s, 1, __FILE__, __SWITCH_FUNC__, __LINE__)

Definition at line 2882 of file switch_core.h.

◆ switch_core_session_request_video_refresh

#define switch_core_session_request_video_refresh (   _s)    _switch_core_session_request_video_refresh(_s, 0, __FILE__, __SWITCH_FUNC__, __LINE__)

◆ SWITCH_MAX_CORE_THREAD_SESSION_OBJS

#define SWITCH_MAX_CORE_THREAD_SESSION_OBJS   128

Definition at line 47 of file switch_core.h.

◆ SWITCH_MAX_STREAMS

#define SWITCH_MAX_STREAMS   128

Definition at line 48 of file switch_core.h.

◆ switch_sql_queue_manager_init

#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 2850 of file switch_core.h.

Typedef Documentation

◆ dtls_fingerprint_t

typedef struct dtls_fp_s dtls_fingerprint_t

◆ switch_cache_db_handle_t

Definition at line 2600 of file switch_core.h.

◆ switch_core_db_event_callback_func_t

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

Definition at line 2553 of file switch_core.h.

◆ switch_device_node_t

◆ switch_device_record_t

◆ switch_device_state_function_t

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 145 of file switch_core.h.

◆ switch_device_stats_t

◆ switch_hold_record_t

◆ switch_thread_data_t

Enumeration Type Documentation

◆ cache_db_flag_t

Enumerator
CDF_INUSE 
CDF_PRUNE 
CDF_NONEXPIRING 

Definition at line 2556 of file switch_core.h.

2556  {
2557  CDF_INUSE = (1 << 0),
2558  CDF_PRUNE = (1 << 1),
2559  CDF_NONEXPIRING = (1 << 2)
2560 } cache_db_flag_t;
cache_db_flag_t
Definition: switch_core.h:2556

◆ dtls_state_t

Enumerator
DS_OFF 
DS_HANDSHAKE 
DS_SETUP 
DS_READY 
DS_FAIL 
DS_INVALID 

Definition at line 166 of file switch_core.h.

166  {
167  DS_OFF,
168  DS_HANDSHAKE,
169  DS_SETUP,
170  DS_READY,
171  DS_FAIL,
172  DS_INVALID,
173 } dtls_state_t;
dtls_state_t
Definition: switch_core.h:166

◆ dtls_type_t

Enumerator
DTLS_TYPE_CLIENT 
DTLS_TYPE_SERVER 
DTLS_TYPE_RTP 
DTLS_TYPE_RTCP 

Definition at line 159 of file switch_core.h.

159  {
160  DTLS_TYPE_CLIENT = (1 << 0),
161  DTLS_TYPE_SERVER = (1 << 1),
162  DTLS_TYPE_RTP = (1 << 2),
163  DTLS_TYPE_RTCP = (1 << 3)
164 } dtls_type_t;
dtls_type_t
Definition: switch_core.h:159

◆ switch_cache_db_handle_type_t

Enumerator
SCDB_TYPE_CORE_DB 
SCDB_TYPE_ODBC 
SCDB_TYPE_DATABASE_INTERFACE 

Definition at line 2562 of file switch_core.h.

Function Documentation

◆ _switch_cache_db_get_db_handle()

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 507 of file switch_core_sqldb.c.

References add_handle(), CACHE_DB_LEN, switch_database_interface_handle::connection_options, switch_cache_db_database_interface_options_t::connection_string, switch_cache_db_native_handle_t::core_db_dbh, switch_cache_db_connection_options_t::core_db_options, create_handle(), switch_cache_db_database_interface_options_t::database_interface, switch_cache_db_native_handle_t::database_interface_dbh, switch_cache_db_connection_options_t::database_interface_options, switch_runtime::db_handle_timeout, switch_cache_db_core_db_options_t::db_path, destroy_handle(), switch_cache_db_odbc_options_t::dsn, get_handle(), switch_coredb_handle::handle, switch_database_interface::handle_new, switch_coredb_handle::in_memory, switch_cache_db_core_db_options_t::in_memory, switch_cache_db_handle::last_used, switch_cache_db_database_interface_options_t::make_module_no_unloadable, switch_runtime::max_db_handles, switch_loadable_module_interface::module_name, switch_cache_db_handle::name, switch_cache_db_handle::native_handle, switch_cache_db_native_handle_t::odbc_dbh, switch_cache_db_connection_options_t::odbc_options, switch_cache_db_database_interface_options_t::original_dsn, switch_database_interface::parent, switch_cache_db_odbc_options_t::pass, switch_cache_db_handle::pool, switch_cache_db_database_interface_options_t::prefix, PROTECT_INTERFACE, runtime, SCDB_TYPE_CORE_DB, SCDB_TYPE_DATABASE_INTERFACE, SCDB_TYPE_ODBC, sql_manager, switch_cache_db_type_name(), SWITCH_CHANNEL_ID_LOG, SWITCH_CHANNEL_LOG, switch_core_alloc, switch_core_db_close(), switch_core_db_open_file(), switch_core_db_open_in_memory(), switch_epoch_time_now(), switch_loadable_module_protect(), 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_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_thread_self(), SWITCH_TRUE, switch_yield, switch_cache_db_handle::type, UNPROTECT_INTERFACE, and switch_cache_db_odbc_options_t::user.

Referenced by _switch_cache_db_get_db_handle_dsn_ex(), and switch_cache_db_type_name().

511 {
513  char thread_str[CACHE_DB_LEN] = "";
514  char db_str[CACHE_DB_LEN] = "";
515  char db_callsite_str[CACHE_DB_LEN] = "";
516  switch_cache_db_handle_t *new_dbh = NULL;
517  int waiting = 0;
518  uint32_t yield_len = 100000, total_yield = 0;
519 
520  const char *db_name = NULL;
521  const char *odbc_user = NULL;
522  const char *odbc_pass = NULL;
523  const char *db_type = NULL;
524 
525  while(runtime.max_db_handles && sql_manager.total_handles >= runtime.max_db_handles && sql_manager.total_used_handles >= sql_manager.total_handles) {
526  if (!waiting++) {
527  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_WARNING, "Max handles %u exceeded, blocking....\n",
529  }
530 
531  switch_yield(yield_len);
532  total_yield += yield_len;
533 
534  if (runtime.db_handle_timeout && total_yield > runtime.db_handle_timeout) {
535  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "Error connecting\n");
536  *dbh = NULL;
537  return SWITCH_STATUS_FALSE;
538  }
539  }
540 
541  switch (type) {
543  {
544  db_name = connection_options->database_interface_options.connection_string;
545  odbc_user = NULL;
546  odbc_pass = NULL;
547  db_type = "database_interface";
548  }
549  break;
550  case SCDB_TYPE_ODBC:
551  {
552  db_name = connection_options->odbc_options.dsn;
553  odbc_user = connection_options->odbc_options.user;
554  odbc_pass = connection_options->odbc_options.pass;
555  db_type = "odbc";
556  }
557  break;
558  case SCDB_TYPE_CORE_DB:
559  {
560  db_name = connection_options->core_db_options.db_path;
561  odbc_user = NULL;
562  odbc_pass = NULL;
563  db_type = "core_db";
564  }
565  break;
566  }
567 
568  if (!db_name) {
569  return SWITCH_STATUS_FALSE;
570  }
571 
572  if (odbc_user || odbc_pass) {
573  snprintf(db_str, sizeof(db_str) - 1, "db=\"%s\";type=\"%s\"user=\"%s\";pass=\"%s\"", db_name, db_type, odbc_user, odbc_pass);
574  } else {
575  snprintf(db_str, sizeof(db_str) - 1, "db=\"%s\",type=\"%s\"", db_name, db_type);
576  }
577  snprintf(db_callsite_str, sizeof(db_callsite_str) - 1, "%s:%d", file, line);
578  snprintf(thread_str, sizeof(thread_str) - 1, "thread=\"%lu\"", (unsigned long) (intptr_t) self);
579 
580  if ((new_dbh = get_handle(db_str, db_callsite_str, thread_str))) {
581  if (type == SCDB_TYPE_DATABASE_INTERFACE) {
583  "Reuse Unused Cached DB handle %s [Database interface prefix: %s]\n", new_dbh->name, connection_options->database_interface_options.prefix);
584  } else {
586  "Reuse Unused Cached DB handle %s [%s]\n", new_dbh->name, switch_cache_db_type_name(new_dbh->type));
587  }
588  } else {
589  switch_core_db_t *db = NULL;
590  switch_odbc_handle_t *odbc_dbh = NULL;
591  switch_database_interface_handle_t *database_interface_dbh = NULL;
592 
593  switch (type) {
595  {
596  switch_database_interface_t *database_interface = connection_options->database_interface_options.database_interface;
597 
598  if (SWITCH_STATUS_SUCCESS != database_interface->handle_new(connection_options->database_interface_options, &database_interface_dbh)) {
599  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure! Can't create new handle! Can't connect to DSN %s\n", connection_options->database_interface_options.original_dsn);
600  goto end;
601  }
602 
603  if (database_interface_dbh) {
604  database_interface_dbh->connection_options = connection_options->database_interface_options;
605 
607  {
608  PROTECT_INTERFACE(database_interface)
609  switch_loadable_module_protect(database_interface->parent->module_name);
610  UNPROTECT_INTERFACE(database_interface)
611  }
612  }
613  }
614  break;
615  case SCDB_TYPE_ODBC:
616  {
617  if (!switch_odbc_available()) {
618  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);
619  goto end;
620  }
621 
622  if ((odbc_dbh = switch_odbc_handle_new(connection_options->odbc_options.dsn,
623  connection_options->odbc_options.user, connection_options->odbc_options.pass))) {
625  switch_odbc_handle_destroy(&odbc_dbh);
626  }
627  }
628  }
629  break;
630  case SCDB_TYPE_CORE_DB:
631  {
632  if (!connection_options->core_db_options.in_memory) {
633  db = switch_core_db_open_file(connection_options->core_db_options.db_path);
634  } else {
635  db = switch_core_db_open_in_memory(connection_options->core_db_options.db_path);
636  }
637  }
638  break;
639 
640  default:
641  goto end;
642  }
643 
644  if (!db && !odbc_dbh && !database_interface_dbh) {
645  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure to connect to %s %s!\n", switch_cache_db_type_name(type), db_name);
646  goto end;
647  }
648 
649  new_dbh = create_handle(type);
650 
652  "Create Cached DB handle %s [%s] %s:%d\n", new_dbh->name, switch_cache_db_type_name(type), file, line);
653 
654  if (database_interface_dbh) {
655  new_dbh->native_handle.database_interface_dbh = database_interface_dbh;
656  } else if (db) {
657  if (!(new_dbh->native_handle.core_db_dbh = switch_core_alloc(new_dbh->pool, sizeof(*new_dbh->native_handle.core_db_dbh)))) {
658  destroy_handle(&new_dbh);
660  goto end;
661  }
662  new_dbh->native_handle.core_db_dbh->handle = db;
663  new_dbh->native_handle.core_db_dbh->in_memory = connection_options->core_db_options.in_memory;
664  } else if (odbc_dbh) {
665  new_dbh->native_handle.odbc_dbh = odbc_dbh;
666  }
667 
668  add_handle(new_dbh, db_str, db_callsite_str, thread_str);
669  }
670 
671  end:
672 
673  if (new_dbh) {
674  new_dbh->last_used = switch_epoch_time_now(NULL);
675  }
676 
677  *dbh = new_dbh;
678 
680 }
switch_cache_db_native_handle_t native_handle
char name[CACHE_DB_LEN]
switch_core_db_t * handle
#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:2594
void switch_odbc_handle_destroy(switch_odbc_handle_t **handlep)
Definition: switch_odbc.c:742
switch_core_db_t * switch_core_db_open_in_memory(const char *uri)
Open a core db (SQLite) in-memory.
static const char * switch_cache_db_type_name(switch_cache_db_handle_type_t type)
Definition: switch_core.h:2602
switch_cache_db_database_interface_options_t connection_options
int switch_core_db_close(switch_core_db_t *db)
switch_memory_pool_t * pool
struct switch_runtime runtime
Definition: switch_core.c:86
switch_status_t switch_loadable_module_protect(const char *mod)
Protect module from beeing unloaded.
switch_coredb_handle_t * core_db_dbh
Definition: switch_core.h:2569
static void add_handle(switch_cache_db_handle_t *dbh, const char *db_str, const char *db_callsite_str, const char *thread_str)
#define UNPROTECT_INTERFACE(_it)
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
#define CACHE_DB_LEN
Definition: switch_core.h:2555
switch_bool_t switch_odbc_available(void)
Definition: switch_odbc.c:809
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:2570
switch_cache_db_odbc_options_t odbc_options
Definition: switch_core.h:2595
switch_database_interface_handle_t * database_interface_dbh
Definition: switch_core.h:2571
static switch_cache_db_handle_t * get_handle(const char *db_str, const char *user_str, const char *thread_str)
struct sqlite3 switch_core_db_t
static struct @4 sql_manager
switch_odbc_status_t switch_odbc_handle_connect(switch_odbc_handle_t *handle)
Definition: switch_odbc.c:343
switch_cache_db_database_interface_options_t database_interface_options
Definition: switch_core.h:2596
uint32_t max_db_handles
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:322
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 PROTECT_INTERFACE(_it)
switch_thread_id_t switch_thread_self(void)
Definition: switch_apr.c:102
switch_bool_t in_memory
switch_odbc_handle_t * switch_odbc_handle_new(const char *dsn, const char *username, const char *password)
Definition: switch_odbc.c:72
switch_database_interface_t * database_interface
Definition: switch_core.h:2589
switch_core_db_t * switch_core_db_open_file(const char *filename)
Open a core db (SQLite) file.
switch_status_t(* handle_new)(switch_cache_db_database_interface_options_t database_interface_options, switch_database_interface_handle_t **dih)
Abstract interface to a database module.
static void destroy_handle(switch_cache_db_handle_t **dbh)
switch_loadable_module_interface_t * parent

◆ _switch_cache_db_get_db_handle_dsn()

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 427 of file switch_core_sqldb.c.

References _switch_cache_db_get_db_handle_dsn_ex(), and SWITCH_FALSE.

429 {
430  return _switch_cache_db_get_db_handle_dsn_ex(dbh, dsn, SWITCH_FALSE, file, func, line);
431 }
switch_status_t _switch_cache_db_get_db_handle_dsn_ex(switch_cache_db_handle_t **dbh, const char *dsn, switch_bool_t make_module_no_unloadable, const char *file, const char *func, int line)

◆ _switch_cache_db_get_db_handle_dsn_ex()

switch_status_t _switch_cache_db_get_db_handle_dsn_ex ( switch_cache_db_handle_t **  dbh,
const char *  dsn,
switch_bool_t  make_module_no_unloadable,
const char *  file,
const char *  func,
int  line 
)

Definition at line 433 of file switch_core_sqldb.c.

References _switch_cache_db_get_db_handle(), switch_cache_db_database_interface_options_t::connection_string, switch_cache_db_connection_options_t::core_db_options, switch_cache_db_database_interface_options_t::database_interface, switch_cache_db_connection_options_t::database_interface_options, switch_cache_db_core_db_options_t::db_path, switch_cache_db_odbc_options_t::dsn, switch_cache_db_core_db_options_t::in_memory, switch_cache_db_database_interface_options_t::make_module_no_unloadable, MIN, switch_cache_db_connection_options_t::odbc_options, switch_cache_db_database_interface_options_t::original_dsn, switch_cache_db_odbc_options_t::pass, switch_cache_db_database_interface_options_t::prefix, SCDB_TYPE_CORE_DB, SCDB_TYPE_DATABASE_INTERFACE, SCDB_TYPE_ODBC, switch_loadable_module_get_database_interface(), switch_set_string, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, SWITCH_TRUE, switch_cache_db_handle::type, UNPROTECT_INTERFACE, and switch_cache_db_odbc_options_t::user.

Referenced by _switch_cache_db_get_db_handle_dsn(), and _switch_core_db_handle().

435 {
436  switch_cache_db_connection_options_t connection_options = { {0} };
438  switch_database_interface_t *database_interface = NULL;
439  char tmp[256] = "";
440  char *p;
442  int i;
443 
444  char *colon_slashes = NULL;
445  if ( NULL != (colon_slashes = strstr(dsn, "://")) )
446  {
447  char prefix[16] = "";
448  strncpy(prefix, dsn, MIN(colon_slashes - dsn, 15));
449 
450  if ((database_interface = switch_loadable_module_get_database_interface(prefix, NULL))) {
452  connection_options.database_interface_options.make_module_no_unloadable = make_module_no_unloadable;
453  connection_options.database_interface_options.database_interface = database_interface;
454  connection_options.database_interface_options.original_dsn = dsn;
455  connection_options.database_interface_options.connection_string = colon_slashes + 3;
456  strcpy(connection_options.database_interface_options.prefix, prefix);
457  UNPROTECT_INTERFACE(database_interface);
458  }
459  }
460 
461  if (!connection_options.database_interface_options.connection_string)
462  {
463  if (!strncasecmp(dsn, "sqlite://", 9)) {
464  type = SCDB_TYPE_CORE_DB;
465  connection_options.core_db_options.db_path = (char *)(dsn + 9);
466  if (!strncasecmp(connection_options.core_db_options.db_path, "memory://", 9)) {
467  connection_options.core_db_options.in_memory = SWITCH_TRUE;
468  connection_options.core_db_options.db_path = (char *)(connection_options.core_db_options.db_path + 9);
469  }
470  }
471  else if ((!(i = strncasecmp(dsn, "odbc://", 7))) || (strchr(dsn + 2, ':') && !colon_slashes)) {
472  type = SCDB_TYPE_ODBC;
473 
474  if (i) {
475  switch_set_string(tmp, dsn);
476  }
477  else {
478  switch_set_string(tmp, dsn + 7);
479  }
480 
481  connection_options.odbc_options.dsn = tmp;
482 
483  if ((p = strchr(tmp, ':'))) {
484  *p++ = '\0';
485  connection_options.odbc_options.user = p;
486 
487  if ((p = strchr(connection_options.odbc_options.user, ':'))) {
488  *p++ = '\0';
489  connection_options.odbc_options.pass = p;
490  }
491  }
492  }
493  else {
494  type = SCDB_TYPE_CORE_DB;
495  connection_options.core_db_options.db_path = (char *)dsn;
496  }
497  }
498 
499  status = _switch_cache_db_get_db_handle(dbh, type, &connection_options, file, func, line);
500 
501  if (status != SWITCH_STATUS_SUCCESS) *dbh = NULL;
502 
503  return status;
504 }
switch_cache_db_core_db_options_t core_db_options
Definition: switch_core.h:2594
#define MIN(a, b)
#define UNPROTECT_INTERFACE(_it)
switch_database_interface_t * switch_loadable_module_get_database_interface(const char *name, const char *modname)
Retrieve the database interface by it&#39;s registered name.
switch_cache_db_handle_type_t
Definition: switch_core.h:2562
switch_cache_db_odbc_options_t odbc_options
Definition: switch_core.h:2595
switch_status_t
Common return values.
switch_cache_db_database_interface_options_t database_interface_options
Definition: switch_core.h:2596
#define switch_set_string(_dst, _src)
Definition: switch_utils.h:734
switch_database_interface_t * database_interface
Definition: switch_core.h:2589
Abstract interface to a database module.
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_core_db_handle()

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 235 of file switch_core_sqldb.c.

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

236 {
237  switch_status_t r;
238  char *dsn;
239 
240  if (!sql_manager.manage) {
241  return SWITCH_STATUS_FALSE;
242  }
243 
244  if (!zstr(runtime.odbc_dsn)) {
245  dsn = runtime.odbc_dsn;
246  } else if (!zstr(runtime.dbname)) {
247  dsn = runtime.dbname;
248  } else {
249  dsn = "core";
250  }
251 
252  if ((r = _switch_cache_db_get_db_handle_dsn_ex(dbh, dsn, SWITCH_TRUE, file, func, line)) != SWITCH_STATUS_SUCCESS) {
253  *dbh = NULL;
254  }
255 
256  return r;
257 }
struct switch_runtime runtime
Definition: switch_core.c:86
#define zstr(x)
Definition: switch_utils.h:314
switch_status_t
Common return values.
switch_status_t _switch_cache_db_get_db_handle_dsn_ex(switch_cache_db_handle_t **dbh, const char *dsn, switch_bool_t make_module_no_unloadable, const char *file, const char *func, int line)
static struct @4 sql_manager

◆ _switch_core_session_request_video_refresh()

switch_status_t _switch_core_session_request_video_refresh ( switch_core_session_t session,
int  force,
const char *  file,
const char *  func,
int  line 
)

Definition at line 14529 of file switch_core_media.c.

References switch_core_session_message::_file, switch_core_session_message::_func, switch_core_session_message::_line, CF_VIDEO, switch_core_session::channel, switch_core_session_message::from, switch_media_handle_s::last_video_refresh_req, switch_core_session::media_handle, switch_core_session_message::message_id, switch_core_session_message::numeric_arg, switch_assert, switch_channel_get_name(), SWITCH_CHANNEL_ID_LOG, switch_channel_media_up, switch_channel_test_flag(), switch_core_session_get_channel(), switch_core_session_get_uuid(), switch_core_session_receive_message, SWITCH_LOG_DEBUG1, switch_log_printf(), SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ, switch_micro_time_now(), SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and VIDEO_REFRESH_FREQ.

14530 {
14532  switch_media_handle_t *smh = NULL;
14533 
14534  switch_assert(session);
14535 
14536  if (!(smh = session->media_handle)) {
14537  return SWITCH_STATUS_FALSE;
14538  }
14539 
14540  if (switch_channel_media_up(channel) && switch_channel_test_flag(channel, CF_VIDEO)) {
14541  switch_core_session_message_t msg = { 0 };
14543 
14544  if (!force && (smh->last_video_refresh_req && (now - smh->last_video_refresh_req) < VIDEO_REFRESH_FREQ)) {
14545  return SWITCH_STATUS_BREAK;
14546  }
14547 
14548  smh->last_video_refresh_req = now;
14549 
14550  if (force) {
14551  msg.numeric_arg = 1;
14552  }
14553 
14554  msg._file = file;
14555  msg._func = func;
14556  msg._line = line;
14558  SWITCH_LOG_DEBUG1, "%s Video refresh requested.\n", switch_channel_get_name(session->channel));
14559  msg.from = __FILE__;
14561  switch_core_session_receive_message(session, &msg);
14562  return SWITCH_STATUS_SUCCESS;
14563  }
14564 
14565  return SWITCH_STATUS_FALSE;
14566 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
switch_core_session_message_types_t message_id
Definition: switch_core.h:183
#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:179
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
switch_channel_t * channel
#define switch_core_session_receive_message(_session, _message)
Definition: switch_core.h:1247
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
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)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
#define switch_channel_media_up(_channel)

◆ switch_cache_db_affected_rows()

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 815 of file switch_core_sqldb.c.

References switch_database_interface::affected_rows, switch_database_interface_handle::connection_options, switch_cache_db_native_handle_t::core_db_dbh, switch_cache_db_database_interface_options_t::database_interface, switch_cache_db_native_handle_t::database_interface_dbh, switch_coredb_handle::handle, switch_cache_db_handle::native_handle, switch_cache_db_native_handle_t::odbc_dbh, SCDB_TYPE_CORE_DB, SCDB_TYPE_DATABASE_INTERFACE, SCDB_TYPE_ODBC, switch_core_db_changes(), switch_odbc_handle_affected_rows(), and switch_cache_db_handle::type.

816 {
817  switch (dbh->type) {
818  case SCDB_TYPE_CORE_DB:
819  {
821  }
822  break;
823  case SCDB_TYPE_ODBC:
824  {
826  }
827  break;
829  {
831  int affected_rows = 0;
832  database_interface->affected_rows(dbh->native_handle.database_interface_dbh, &affected_rows);
833  return affected_rows;
834  }
835  break;
836  }
837  return 0;
838 }
switch_cache_db_native_handle_t native_handle
switch_core_db_t * handle
switch_cache_db_handle_type_t type
int switch_odbc_handle_affected_rows(switch_odbc_handle_t *handle)
Definition: switch_odbc.c:800
switch_cache_db_database_interface_options_t connection_options
switch_coredb_handle_t * core_db_dbh
Definition: switch_core.h:2569
switch_status_t(* affected_rows)(switch_database_interface_handle_t *dih, int *affected_rows)
switch_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2570
switch_database_interface_handle_t * database_interface_dbh
Definition: switch_core.h:2571
int switch_core_db_changes(switch_core_db_t *db)
switch_database_interface_t * database_interface
Definition: switch_core.h:2589
Abstract interface to a database module.

◆ switch_cache_db_create_schema()

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 1394 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().

1395 {
1397 
1398  switch_assert(sql != NULL);
1399 
1401  r = switch_cache_db_execute_sql(dbh, sql, err);
1402  }
1403 
1404  return r;
1405 }
struct switch_runtime runtime
Definition: switch_core.c:86
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:693
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_cache_db_database_interface_flush_handles()

void switch_cache_db_database_interface_flush_handles ( switch_database_interface_t database_interface)

Definition at line 148 of file switch_core_sqldb.c.

References switch_database_interface_handle::connection_options, switch_cache_db_database_interface_options_t::database_interface, switch_cache_db_native_handle_t::database_interface_dbh, del_handle(), destroy_handle(), switch_database_interface::handle_destroy, switch_cache_db_handle::mutex, switch_cache_db_handle::name, switch_cache_db_handle::native_handle, switch_cache_db_handle::next, SCDB_TYPE_DATABASE_INTERFACE, sql_manager, SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, switch_log_printf(), switch_mutex_lock(), switch_mutex_trylock(), switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, and switch_cache_db_handle::type.

Referenced by switch_loadable_module_unprocess().

149 {
150  switch_cache_db_handle_t *dbh_ptr = NULL;
151 
152  switch_mutex_lock(sql_manager.dbh_mutex);
153 
154 top:
155 
156  for (dbh_ptr = sql_manager.handle_pool; dbh_ptr; dbh_ptr = dbh_ptr->next) {
158  if (dbh_ptr->type != SCDB_TYPE_DATABASE_INTERFACE) {
159  switch_mutex_unlock(dbh_ptr->mutex);
160  continue;
161  }
162 
163  if (dbh_ptr->native_handle.database_interface_dbh->connection_options.database_interface != database_interface) {
164  switch_mutex_unlock(dbh_ptr->mutex);
165  continue;
166  }
167 
168  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "Dropping DB connection %s\n", dbh_ptr->name);
169 
170  database_interface->handle_destroy(&dbh_ptr->native_handle.database_interface_dbh);
171 
172  del_handle(dbh_ptr);
173  switch_mutex_unlock(dbh_ptr->mutex);
174  destroy_handle(&dbh_ptr);
175  goto top;
176  }
177  }
178 
179  switch_mutex_unlock(sql_manager.dbh_mutex);
180 }
switch_cache_db_native_handle_t native_handle
char name[CACHE_DB_LEN]
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_trylock(switch_mutex_t *lock)
Definition: switch_apr.c:318
static void del_handle(switch_cache_db_handle_t *dbh)
switch_cache_db_handle_type_t type
switch_cache_db_database_interface_options_t connection_options
switch_mutex_t * mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
struct switch_cache_db_handle * next
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_database_interface_handle_t * database_interface_dbh
Definition: switch_core.h:2571
switch_status_t(* handle_destroy)(switch_database_interface_handle_t **dih)
static struct @4 sql_manager
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_database_interface_t * database_interface
Definition: switch_core.h:2589
static void destroy_handle(switch_cache_db_handle_t **dbh)

◆ switch_cache_db_dismiss_db_handle()

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 379 of file switch_core_sqldb.c.

References switch_cache_db_release_db_handle().

Referenced by switch_cache_db_type_name().

380 {
382 }
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_cache_db_execute_sql()

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 799 of file switch_core_sqldb.c.

References switch_cache_db_execute_sql_chunked(), SWITCH_STATUS_FALSE, and switch_cache_db_handle::type.

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

800 {
802 
803  switch (dbh->type) {
804  default:
805  {
806  status = switch_cache_db_execute_sql_chunked(dbh, (char *) sql, 32768, err);
807  }
808  break;
809  }
810 
811  return status;
812 }
switch_cache_db_handle_type_t type
switch_status_t
Common return values.
static switch_status_t switch_cache_db_execute_sql_chunked(switch_cache_db_handle_t *dbh, char *sql, uint32_t chunk_size, char **err)

◆ switch_cache_db_execute_sql2str()

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 864 of file switch_core_sqldb.c.

References switch_database_interface_handle::connection_options, switch_cache_db_native_handle_t::core_db_dbh, switch_cache_db_database_interface_options_t::database_interface, switch_cache_db_native_handle_t::database_interface_dbh, switch_database_interface::exec_string, switch_coredb_handle::handle, memset(), switch_cache_db_handle::native_handle, switch_cache_db_native_handle_t::odbc_dbh, running, SCDB_TYPE_CORE_DB, SCDB_TYPE_DATABASE_INTERFACE, SCDB_TYPE_ODBC, 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_odbc_handle_exec_string(), SWITCH_ODBC_SUCCESS, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_cache_db_handle::type.

865 {
867 
868  memset(str, 0, len);
869 
870  switch (dbh->type) {
871  case SCDB_TYPE_CORE_DB:
872  {
873  switch_core_db_stmt_t *stmt;
874 
875  if (switch_core_db_prepare(dbh->native_handle.core_db_dbh->handle, sql, -1, &stmt, 0)) {
876  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Statement Error [%s]!\n", sql);
877  goto end;
878  } else {
879  int running = 1;
880 
881  while (running < 5000) {
882  int result = switch_core_db_step(stmt);
883  const unsigned char *txt;
884 
885  if (result == SWITCH_CORE_DB_ROW) {
886  if (switch_core_db_column_count(stmt) > 0) {
887  if ((txt = switch_core_db_column_text(stmt, 0))) {
888  switch_copy_string(str, (char *) txt, len);
889  status = SWITCH_STATUS_SUCCESS;
890  }
891  }
892  break;
893  } else if (result == SWITCH_CORE_DB_BUSY) {
894  running++;
896  continue;
897  }
898  break;
899  }
900 
902  }
903  }
904  break;
905  case SCDB_TYPE_ODBC:
906  {
908  }
909  break;
911  {
913  status = database_interface->exec_string(dbh->native_handle.database_interface_dbh, sql, str, len, err);
914  }
915  break;
916  }
917 
918  end:
919 
920  return status == SWITCH_STATUS_SUCCESS ? str : NULL;
921 
922 }
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:412
switch_core_db_t * handle
#define SWITCH_CHANNEL_LOG
switch_status_t(* exec_string)(switch_database_interface_handle_t *dih, const char *sql, char *resbuf, size_t len, char **err)
switch_cache_db_handle_type_t type
switch_cache_db_database_interface_options_t connection_options
#define SWITCH_CORE_DB_BUSY
int switch_core_db_finalize(switch_core_db_stmt_t *pStmt)
switch_coredb_handle_t * core_db_dbh
Definition: switch_core.h:2569
int switch_core_db_step(switch_core_db_stmt_t *stmt)
void switch_cond_next(void)
Definition: switch_time.c:658
switch_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2570
char * switch_copy_string(_Out_z_cap_(dst_size) char *dst, _In_z_ const char *src, _In_ switch_size_t dst_size)
switch_database_interface_handle_t * database_interface_dbh
Definition: switch_core.h:2571
static int32_t running
switch_status_t
Common return values.
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_database_interface_t * database_interface
Definition: switch_core.h:2589
Abstract interface to a database module.
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_cache_db_execute_sql_callback()

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 1285 of file switch_core_sqldb.c.

References switch_database_interface_handle::connection_options, switch_cache_db_native_handle_t::core_db_dbh, switch_cache_db_database_interface_options_t::database_interface, switch_cache_db_native_handle_t::database_interface_dbh, database_interface_handle_callback_exec, switch_coredb_handle::handle, switch_cache_db_handle::last_used, switch_cache_db_handle::native_handle, switch_cache_db_native_handle_t::odbc_dbh, SCDB_TYPE_CORE_DB, SCDB_TYPE_DATABASE_INTERFACE, SCDB_TYPE_ODBC, 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_odbc_handle_callback_exec, SWITCH_ODBC_SUCCESS, switch_snprintfv(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_cache_db_handle::type.

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

1287 {
1289  char *errmsg = NULL;
1290 
1291  if (err) {
1292  *err = NULL;
1293  }
1294 
1295  switch (dbh->type) {
1297  {
1299 
1300  if ((status = database_interface_handle_callback_exec(database_interface, dbh->native_handle.database_interface_dbh, sql, callback, pdata, err)) != SWITCH_STATUS_SUCCESS) {
1301  char tmp[100];
1302  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to execute_sql_callback", status);
1303  }
1304  }
1305  break;
1306  case SCDB_TYPE_ODBC:
1307  {
1309  }
1310  break;
1311  case SCDB_TYPE_CORE_DB:
1312  {
1313  int ret = switch_core_db_exec(dbh->native_handle.core_db_dbh->handle, sql, callback, pdata, &errmsg);
1314 
1315  if (ret == SWITCH_CORE_DB_OK || ret == SWITCH_CORE_DB_ABORT) {
1316  status = SWITCH_STATUS_SUCCESS;
1317  }
1318 
1319  if (errmsg) {
1320  dbh->last_used = switch_epoch_time_now(NULL) - (SQL_CACHE_TIMEOUT * 2);
1321  if (!strstr(errmsg, "query abort")) {
1322  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
1323  }
1324  switch_core_db_free(errmsg);
1325  }
1326  }
1327  break;
1328  }
1329 
1330  return status;
1331 }
switch_cache_db_native_handle_t native_handle
switch_core_db_t * handle
#define SWITCH_CHANNEL_LOG
#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:93
switch_cache_db_handle_type_t type
#define SQL_CACHE_TIMEOUT
switch_cache_db_database_interface_options_t connection_options
switch_coredb_handle_t * core_db_dbh
Definition: switch_core.h:2569
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
char * switch_snprintfv(char *zBuf, int n, const char *zFormat,...)
switch_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2570
switch_database_interface_handle_t * database_interface_dbh
Definition: switch_core.h:2571
switch_status_t
Common return values.
#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:322
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_database_interface_t * database_interface
Definition: switch_core.h:2589
#define database_interface_handle_callback_exec(database_interface, dih, sql, callback, pdata, err)
Abstract interface to a database module.

◆ switch_cache_db_execute_sql_callback_err()

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 1333 of file switch_core_sqldb.c.

References switch_database_interface_handle::connection_options, switch_cache_db_native_handle_t::core_db_dbh, switch_cache_db_database_interface_options_t::database_interface, switch_cache_db_native_handle_t::database_interface_dbh, database_interface_handle_callback_exec, switch_coredb_handle::handle, switch_cache_db_handle::last_used, switch_cache_db_handle::native_handle, switch_cache_db_native_handle_t::odbc_dbh, helper::pdata, SCDB_TYPE_CORE_DB, SCDB_TYPE_DATABASE_INTERFACE, SCDB_TYPE_ODBC, 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_odbc_handle_callback_exec, SWITCH_ODBC_SUCCESS, switch_snprintfv(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_cache_db_handle::type.

Referenced by sql_in_thread().

1336 {
1338  char *errmsg = NULL;
1339 
1340  if (err) {
1341  *err = NULL;
1342  }
1343 
1344  switch (dbh->type) {
1346  {
1348 
1349  if ((status = database_interface_handle_callback_exec(database_interface, dbh->native_handle.database_interface_dbh, sql, callback, pdata, err)) != SWITCH_STATUS_SUCCESS) {
1350  char tmp[100];
1351  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to execute_sql_callback_err", status);
1352  }
1353 
1354  if (err && *err) {
1355  (*err_callback)(pdata, (const char*)*err);
1356  }
1357  }
1358  break;
1359  case SCDB_TYPE_ODBC:
1360  {
1362  if (err && *err) {
1363  (*err_callback)(pdata, (const char*)*err);
1364  }
1365  }
1366  break;
1367  case SCDB_TYPE_CORE_DB:
1368  {
1369  int ret = switch_core_db_exec(dbh->native_handle.core_db_dbh->handle, sql, callback, pdata, &errmsg);
1370 
1371  if (ret == SWITCH_CORE_DB_OK || ret == SWITCH_CORE_DB_ABORT) {
1372  status = SWITCH_STATUS_SUCCESS;
1373  }
1374 
1375  if (errmsg) {
1376  dbh->last_used = switch_epoch_time_now(NULL) - (SQL_CACHE_TIMEOUT * 2);
1377  if (!strstr(errmsg, "query abort")) {
1378  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
1379  }
1380  }
1381  if ((ret == SWITCH_CORE_DB_ABORT || errmsg) && err_callback) {
1382  (*err_callback)(pdata, errmsg);
1383  }
1384  if (errmsg) {
1385  switch_core_db_free(errmsg);
1386  }
1387  }
1388  break;
1389  }
1390 
1391  return status;
1392 }
switch_cache_db_native_handle_t native_handle
switch_core_db_t * handle
#define SWITCH_CHANNEL_LOG
#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:93
switch_cache_db_handle_type_t type
#define SQL_CACHE_TIMEOUT
switch_cache_db_database_interface_options_t connection_options
switch_coredb_handle_t * core_db_dbh
Definition: switch_core.h:2569
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
char * switch_snprintfv(char *zBuf, int n, const char *zFormat,...)
switch_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2570
switch_database_interface_handle_t * database_interface_dbh
Definition: switch_core.h:2571
switch_status_t
Common return values.
#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:322
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_database_interface_t * database_interface
Definition: switch_core.h:2589
#define database_interface_handle_callback_exec(database_interface, dih, sql, callback, pdata, err)
Abstract interface to a database module.

◆ switch_cache_db_execute_sql_event_callback()

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 1165 of file switch_core_sqldb.c.

References helper::callback, switch_database_interface_handle::connection_options, switch_cache_db_native_handle_t::core_db_dbh, switch_cache_db_database_interface_options_t::database_interface, switch_cache_db_native_handle_t::database_interface_dbh, database_interface_handle_callback_exec, switch_coredb_handle::handle, helper_callback(), switch_cache_db_handle::last_used, switch_cache_db_handle::native_handle, switch_cache_db_native_handle_t::odbc_dbh, helper::pdata, SCDB_TYPE_CORE_DB, SCDB_TYPE_DATABASE_INTERFACE, SCDB_TYPE_ODBC, 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_odbc_handle_callback_exec, SWITCH_ODBC_SUCCESS, switch_snprintfv(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_cache_db_handle::type.

Referenced by sql_in_thread().

1167 {
1169  char *errmsg = NULL;
1170  struct helper h = {0};
1171 
1172  if (err) {
1173  *err = NULL;
1174  }
1175 
1176  h.callback = callback;
1177  h.pdata = pdata;
1178 
1179  switch (dbh->type) {
1181  {
1183 
1184  if ((status = database_interface_handle_callback_exec(database_interface, dbh->native_handle.database_interface_dbh, sql, helper_callback, &h, err)) != SWITCH_STATUS_SUCCESS) {
1185  char tmp[100];
1186  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to execute_sql_event_callback", status);
1187  }
1188  }
1189  break;
1190  case SCDB_TYPE_ODBC:
1191  {
1193  }
1194  break;
1195  case SCDB_TYPE_CORE_DB:
1196  {
1197  int ret = switch_core_db_exec(dbh->native_handle.core_db_dbh->handle, sql, helper_callback, &h, &errmsg);
1198 
1199  if (ret == SWITCH_CORE_DB_OK || ret == SWITCH_CORE_DB_ABORT) {
1200  status = SWITCH_STATUS_SUCCESS;
1201  }
1202 
1203  if (errmsg) {
1204  dbh->last_used = switch_epoch_time_now(NULL) - (SQL_CACHE_TIMEOUT * 2);
1205  if (!strstr(errmsg, "query abort")) {
1206  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
1207  }
1208  switch_core_db_free(errmsg);
1209  }
1210  }
1211  break;
1212  }
1213 
1214  return status;
1215 }
switch_cache_db_native_handle_t native_handle
switch_core_db_t * handle
#define SWITCH_CHANNEL_LOG
#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:93
switch_cache_db_handle_type_t type
switch_core_db_event_callback_func_t callback
#define SQL_CACHE_TIMEOUT
switch_cache_db_database_interface_options_t connection_options
switch_coredb_handle_t * core_db_dbh
Definition: switch_core.h:2569
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
char * switch_snprintfv(char *zBuf, int n, const char *zFormat,...)
switch_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2570
switch_database_interface_handle_t * database_interface_dbh
Definition: switch_core.h:2571
switch_status_t
Common return values.
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:322
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_database_interface_t * database_interface
Definition: switch_core.h:2589
#define database_interface_handle_callback_exec(database_interface, dih, sql, callback, pdata, err)
Abstract interface to a database module.

◆ switch_cache_db_flush_handles()

void switch_cache_db_flush_handles ( void  )

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

344 {
346 }
#define SQL_CACHE_TIMEOUT
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:322
static void sql_close(time_t prune)

◆ switch_cache_db_get_type()

switch_cache_db_handle_type_t switch_cache_db_get_type ( switch_cache_db_handle_t dbh)

Definition at line 338 of file switch_core_sqldb.c.

References switch_cache_db_handle::type.

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

339 {
340  return dbh->type;
341 }
switch_cache_db_handle_type_t type

◆ switch_cache_db_load_extension()

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 840 of file switch_core_sqldb.c.

References switch_cache_db_native_handle_t::core_db_dbh, switch_coredb_handle::handle, switch_cache_db_handle::native_handle, SCDB_TYPE_CORE_DB, SCDB_TYPE_DATABASE_INTERFACE, SCDB_TYPE_ODBC, SWITCH_CHANNEL_LOG, switch_core_db_load_extension(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), and switch_cache_db_handle::type.

841 {
842  switch (dbh->type) {
843  case SCDB_TYPE_CORE_DB:
844  {
845  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "try to load extension [%s]!\n", extension);
847  }
848  break;
849  case SCDB_TYPE_ODBC:
850  {
851  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "load extension not supported by type ODBC!\n");
852  }
853  break;
855  {
856  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "load extension not supported by type DATABASE_INTERFACE!\n");
857  }
858  break;
859  }
860  return 0;
861 }
switch_cache_db_native_handle_t native_handle
switch_core_db_t * handle
#define SWITCH_CHANNEL_LOG
switch_cache_db_handle_type_t type
switch_coredb_handle_t * core_db_dbh
Definition: switch_core.h:2569
int switch_core_db_load_extension(switch_core_db_t *db, const char *extension)
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_cache_db_persistant_execute()

switch_status_t switch_cache_db_persistant_execute ( switch_cache_db_handle_t dbh,
const char *  sql,
uint32_t  retries 
)

Definition at line 924 of file switch_core_sqldb.c.

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

Referenced by switch_console_set_alias().

925 {
926  char *errmsg = NULL;
928  uint8_t forever = 0;
929 
930  if (!retries) {
931  forever = 1;
932  retries = 1000;
933  }
934 
935  while (retries > 0) {
936 
937  switch_cache_db_execute_sql_real(dbh, sql, &errmsg);
938 
939  if (errmsg) {
940  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
941  switch_safe_free(errmsg);
942  switch_yield(100000);
943  retries--;
944  if (retries == 0 && forever) {
945  retries = 1000;
946  continue;
947  }
948  } else {
949  status = SWITCH_STATUS_SUCCESS;
950  break;
951  }
952  }
953 
954  return status;
955 }
#define SWITCH_CHANNEL_LOG
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
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_cache_db_persistant_execute_trans_full()

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 958 of file switch_core_sqldb.c.

References switch_database_interface::commit, switch_database_interface_handle::connection_options, switch_cache_db_database_interface_options_t::database_interface, switch_cache_db_native_handle_t::database_interface_dbh, switch_cache_db_handle::native_handle, switch_cache_db_native_handle_t::odbc_dbh, SCDB_TYPE_CORE_DB, SCDB_TYPE_DATABASE_INTERFACE, SCDB_TYPE_ODBC, switch_database_interface::sql_set_auto_commit_attr, 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_odbc_SQLEndTran(), switch_odbc_SQLSetAutoCommitAttr(), SWITCH_ODBC_SUCCESS, switch_safe_free, switch_snprintfv(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_yield, switch_cache_db_handle::type, and zstr.

964 {
965  char *errmsg = NULL;
967  uint8_t forever = 0;
968  unsigned begin_retries = 100;
969  uint8_t again = 0;
970 
971  if (!retries) {
972  forever = 1;
973  retries = 1000;
974  }
975 
976  if (!zstr(pre_trans_execute)) {
977  switch_cache_db_execute_sql_real(dbh, pre_trans_execute, &errmsg);
978  if (errmsg) {
979  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL PRE TRANS EXEC %s [%s]\n", pre_trans_execute, errmsg);
980  switch_safe_free(errmsg);
981  }
982  }
983 
984  again:
985 
986  while (begin_retries > 0) {
987  again = 0;
988 
989  switch(dbh->type) {
990  case SCDB_TYPE_CORE_DB:
991  {
992  switch_cache_db_execute_sql_real(dbh, "BEGIN EXCLUSIVE", &errmsg);
993  }
994  break;
995  case SCDB_TYPE_ODBC:
996  {
997  switch_odbc_status_t result;
998 
1000  char tmp[100];
1001  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
1002  errmsg = strdup(tmp);
1003  }
1004  }
1005  break;
1007  {
1009  switch_status_t result;
1010 
1011  if ((result = database_interface->sql_set_auto_commit_attr(dbh->native_handle.database_interface_dbh, 0)) != SWITCH_STATUS_SUCCESS) {
1012  char tmp[100];
1013  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
1014  errmsg = strdup(tmp);
1015  }
1016  }
1017  break;
1018  }
1019 
1020  if (errmsg) {
1021  begin_retries--;
1022  if (strstr(errmsg, "cannot start a transaction within a transaction")) {
1023  again = 1;
1024  } else {
1025  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL Retry [%s]\n", errmsg);
1026  }
1027  switch_safe_free(errmsg);
1028 
1029  if (again) {
1030  switch(dbh->type) {
1031  case SCDB_TYPE_CORE_DB:
1032  {
1033  switch_cache_db_execute_sql_real(dbh, "COMMIT", NULL);
1034  }
1035  break;
1036  case SCDB_TYPE_ODBC:
1037  {
1040  }
1041  break;
1043  {
1045  switch_status_t result;
1046 
1047  if ((result = database_interface->commit(dbh->native_handle.database_interface_dbh)) != SWITCH_STATUS_SUCCESS) {
1048  char tmp[100];
1049  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to commit transaction", result);
1050  }
1051  }
1052  break;
1053  }
1054 
1055  goto again;
1056  }
1057 
1058  switch_yield(100000);
1059 
1060  if (begin_retries == 0) {
1061  goto done;
1062  }
1063 
1064  continue;
1065  }
1066 
1067  break;
1068  }
1069 
1070 
1071  if (!zstr(inner_pre_trans_execute)) {
1072  switch_cache_db_execute_sql_real(dbh, inner_pre_trans_execute, &errmsg);
1073  if (errmsg) {
1074  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL PRE TRANS EXEC %s [%s]\n", inner_pre_trans_execute, errmsg);
1075  switch_safe_free(errmsg);
1076  }
1077  }
1078 
1079  while (retries > 0) {
1080 
1081  switch_cache_db_execute_sql(dbh, sql, &errmsg);
1082 
1083  if (errmsg) {
1084  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
1085  switch_safe_free(errmsg);
1086  errmsg = NULL;
1087  switch_yield(100000);
1088  retries--;
1089  if (retries == 0 && forever) {
1090  retries = 1000;
1091  continue;
1092  }
1093  } else {
1094  status = SWITCH_STATUS_SUCCESS;
1095  break;
1096  }
1097  }
1098 
1099  if (!zstr(inner_post_trans_execute)) {
1100  switch_cache_db_execute_sql_real(dbh, inner_post_trans_execute, &errmsg);
1101  if (errmsg) {
1102  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL POST TRANS EXEC %s [%s]\n", inner_post_trans_execute, errmsg);
1103  switch_safe_free(errmsg);
1104  }
1105  }
1106 
1107  done:
1108 
1109  switch(dbh->type) {
1110  case SCDB_TYPE_CORE_DB:
1111  {
1112  switch_cache_db_execute_sql_real(dbh, "COMMIT", NULL);
1113  }
1114  break;
1115  case SCDB_TYPE_ODBC:
1116  {
1119  }
1120  break;
1122  {
1124  switch_status_t result;
1125 
1126  if ((result = database_interface->commit(dbh->native_handle.database_interface_dbh)) != SWITCH_STATUS_SUCCESS) {
1127  char tmp[100];
1128  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to commit transaction", result);
1129  }
1130  }
1131  break;
1132  }
1133 
1134  if (!zstr(post_trans_execute)) {
1135  switch_cache_db_execute_sql_real(dbh, post_trans_execute, &errmsg);
1136  if (errmsg) {
1137  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL POST TRANS EXEC %s [%s]\n", post_trans_execute, errmsg);
1138  switch_safe_free(errmsg);
1139  }
1140  }
1141 
1142  return status;
1143 }
switch_cache_db_native_handle_t native_handle
switch_odbc_status_t
Definition: switch_odbc.h:49
#define SWITCH_CHANNEL_LOG
switch_status_t(* commit)(switch_database_interface_handle_t *dih)
switch_cache_db_handle_type_t type
switch_status_t(* sql_set_auto_commit_attr)(switch_database_interface_handle_t *dih, switch_bool_t on)
switch_cache_db_database_interface_options_t connection_options
#define zstr(x)
Definition: switch_utils.h:314
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
char * switch_snprintfv(char *zBuf, int n, const char *zFormat,...)
switch_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2570
switch_database_interface_handle_t * database_interface_dbh
Definition: switch_core.h:2571
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)
switch_odbc_status_t switch_odbc_SQLEndTran(switch_odbc_handle_t *handle, switch_bool_t commit)
Definition: switch_odbc.c:835
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_database_interface_t * database_interface
Definition: switch_core.h:2589
Abstract interface to a database module.
switch_odbc_status_t switch_odbc_SQLSetAutoCommitAttr(switch_odbc_handle_t *handle, switch_bool_t on)
Definition: switch_odbc.c:818

◆ switch_cache_db_release_db_handle()

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 349 of file switch_core_sqldb.c.

References switch_database_interface::flush, SCDB_TYPE_DATABASE_INTERFACE, sql_manager, switch_epoch_time_now(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by sql_in_thread(), switch_cache_db_dismiss_db_handle(), switch_cache_db_type_name(), 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().

350 {
351  if (dbh && *dbh) {
352 
353  switch((*dbh)->type) {
355  {
356  switch_database_interface_t *database_interface = (*dbh)->native_handle.database_interface_dbh->connection_options.database_interface;
357  database_interface->flush((*dbh)->native_handle.database_interface_dbh);
358  }
359  break;
360  default:
361  break;
362  }
363 
364  (*dbh)->last_used = switch_epoch_time_now(NULL);
365  if ((*dbh)->use_count) {
366  --(*dbh)->use_count;
367  }
368 
369  switch_mutex_unlock((*dbh)->mutex);
370  *dbh = NULL;
371 
372  switch_mutex_lock(sql_manager.dbh_mutex);
373  sql_manager.total_used_handles--;
374  switch_mutex_unlock(sql_manager.dbh_mutex);
375  }
376 }
switch_status_t(* flush)(switch_database_interface_handle_t *dih)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static struct @4 sql_manager
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:322
Abstract interface to a database module.

◆ switch_cache_db_status()

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 3935 of file switch_core_sqldb.c.

References CACHE_DB_LEN, CDF_NONEXPIRING, count, 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_test_flag, SWITCH_TRUE, switch_cache_db_handle::total_used_count, switch_cache_db_handle::type, switch_cache_db_handle::use_count, and switch_stream_handle::write_function.

3936 {
3937  /* return some status info suitable for the cli */
3938  switch_cache_db_handle_t *dbh = NULL;
3939  switch_bool_t locked = SWITCH_FALSE;
3940  time_t now = switch_epoch_time_now(NULL);
3941  char cleankey_str[CACHE_DB_LEN];
3942  char *pos1 = NULL;
3943  char *pos2 = NULL;
3944  int count = 0, used = 0;
3945 
3946  switch_mutex_lock(sql_manager.dbh_mutex);
3947 
3948  for (dbh = sql_manager.handle_pool; dbh; dbh = dbh->next) {
3949  char *needles[3];
3950  time_t diff = 0;
3951  int i = 0;
3952 
3953  needles[0] = "pass=\"";
3954  needles[1] = "password=";
3955  needles[2] = "password='";
3956 
3957  diff = now - dbh->last_used;
3958 
3960  switch_mutex_unlock(dbh->mutex);
3961  locked = SWITCH_FALSE;
3962  } else {
3963  locked = SWITCH_TRUE;
3964  }
3965 
3966  /* sanitize password */
3967  memset(cleankey_str, 0, sizeof(cleankey_str));
3968  for (i = 0; i < 3; i++) {
3969  if((pos1 = strstr(dbh->name, needles[i]))) {
3970  pos1 += strlen(needles[i]);
3971 
3972  if (!(pos2 = strstr(pos1, "\""))) {
3973  if (!(pos2 = strstr(pos1, "'"))) {
3974  if (!(pos2 = strstr(pos1, " "))) {
3975  pos2 = pos1 + strlen(pos1);
3976  }
3977  }
3978  }
3979  strncpy(cleankey_str, dbh->name, pos1 - dbh->name);
3980  strcpy(&cleankey_str[pos1 - dbh->name], pos2);
3981  break;
3982  }
3983  }
3984  if (i == 3) {
3985  snprintf(cleankey_str, sizeof(cleankey_str), "%s", dbh->name);
3986  }
3987 
3988  count++;
3989 
3990  if (dbh->use_count) {
3991  used++;
3992  }
3993 
3994  stream->write_function(stream, "%s\n\tType: %s\n\tLast used: %d\n\tTotal used: %ld\n\tFlags: %s, %s(%d)%s\n"
3995  "\tCreator: %s\n\tLast User: %s\n",
3996  cleankey_str,
3998  diff,
3999  dbh->total_used_count,
4000  locked ? "Locked" : "Unlocked",
4001  dbh->use_count ? "Attached" : "Detached", dbh->use_count, switch_test_flag(dbh, CDF_NONEXPIRING) ? ", Non-expiring" : "", dbh->creator, dbh->last_user);
4002  }
4003 
4004  stream->write_function(stream, "%d total. %d in use.\n", count, used);
4005 
4006  switch_mutex_unlock(sql_manager.dbh_mutex);
4007 }
char name[CACHE_DB_LEN]
switch_status_t switch_mutex_trylock(switch_mutex_t *lock)
Definition: switch_apr.c:318
switch_cache_db_handle_type_t type
switch_bool_t
Definition: switch_types.h:437
static const char * switch_cache_db_type_name(switch_cache_db_handle_type_t type)
Definition: switch_core.h:2602
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:313
struct switch_cache_db_handle * next
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
#define CACHE_DB_LEN
Definition: switch_core.h:2555
switch_cache_db_handle_t * dbh
switch_stream_handle_write_function_t write_function
static struct @4 sql_manager
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:322
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
int count
Definition: switch_cJSON.h:204
memset(buf, 0, buflen)

◆ switch_cache_db_test_reactive()

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 1422 of file switch_core_sqldb.c.

References switch_cache_db_test_reactive_ex().

Referenced by switch_core_sqldb_start().

1424 {
1425  return switch_cache_db_test_reactive_ex(dbh, test_sql, drop_sql, reactive_sql, NULL);
1426 }
switch_bool_t switch_cache_db_test_reactive_ex(switch_cache_db_handle_t *dbh, const char *test_sql, const char *drop_sql, const char *reactive_sql, const char *row_size_limited_reactive_sql)

◆ switch_cache_db_test_reactive_ex()

switch_bool_t switch_cache_db_test_reactive_ex ( switch_cache_db_handle_t db,
const char *  test_sql,
const char *  drop_sql,
const char *  reactive_sql,
const char *  row_size_limited_reactive_sql 
)

Definition at line 1428 of file switch_core_sqldb.c.

References switch_database_interface_handle::connection_options, switch_cache_db_native_handle_t::core_db_dbh, switch_cache_db_database_interface_options_t::database_interface, switch_cache_db_native_handle_t::database_interface_dbh, database_interface_handle_exec, switch_coredb_handle::handle, switch_cache_db_handle::native_handle, switch_cache_db_native_handle_t::odbc_dbh, runtime, SCDB_TYPE_CORE_DB, SCDB_TYPE_DATABASE_INTERFACE, SCDB_TYPE_ODBC, 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_DATABASE_FLAG_ROW_SIZE_LIMIT, SWITCH_FALSE, SWITCH_LOG_DEBUG, switch_log_printf(), switch_odbc_handle_exec(), SWITCH_ODBC_SUCCESS, switch_snprintfv(), SWITCH_STATUS_SUCCESS, switch_test_flag, SWITCH_TRUE, and switch_cache_db_handle::type.

Referenced by switch_cache_db_test_reactive(), and switch_core_sqldb_start().

1430 {
1432 
1433  switch_assert(test_sql != NULL);
1434  switch_assert(reactive_sql != NULL);
1435 
1437  return SWITCH_TRUE;
1438  }
1439 
1441  switch_status_t status = switch_cache_db_execute_sql(dbh, (char *)test_sql, NULL);
1442 
1443  return (status == SWITCH_STATUS_SUCCESS) ? SWITCH_TRUE : SWITCH_FALSE;
1444  }
1445 
1446  switch (dbh->type) {
1448  {
1450  switch_status_t result;
1451 
1452  if ((result = database_interface_handle_exec(database_interface, dbh->native_handle.database_interface_dbh, test_sql, NULL)) != SWITCH_STATUS_SUCCESS) {
1453  char tmp[100];
1454  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to test_reactive with test_sql", result);
1455 
1456  if (drop_sql) {
1457  if ((result = database_interface_handle_exec(database_interface, dbh->native_handle.database_interface_dbh, drop_sql, NULL)) != SWITCH_STATUS_SUCCESS) {
1458  char tmp[100];
1459  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to test_reactive with drop_sql", result);
1460  }
1461  }
1462 
1463  if ((result = database_interface_handle_exec(database_interface, dbh->native_handle.database_interface_dbh, reactive_sql, NULL)) != SWITCH_STATUS_SUCCESS) {
1464  char tmp[100];
1465  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to test_reactive with reactive_sql", result);
1466 
1467  if (row_size_limited_reactive_sql && switch_test_flag(database_interface, SWITCH_DATABASE_FLAG_ROW_SIZE_LIMIT)) {
1468  if ((result = database_interface_handle_exec(database_interface, dbh->native_handle.database_interface_dbh, row_size_limited_reactive_sql, NULL)) != SWITCH_STATUS_SUCCESS) {
1469  switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to test_reactive with row_size_limited_reactive_sql", result);
1470  }
1471  }
1472  }
1473 
1474  r = (result == SWITCH_STATUS_SUCCESS);
1475  }
1476  }
1477  break;
1478  case SCDB_TYPE_ODBC:
1479  {
1480  if (switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) {
1481  if (drop_sql) {
1482  switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, drop_sql, NULL, NULL);
1483  }
1484  r = switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, reactive_sql, NULL, NULL) == SWITCH_ODBC_SUCCESS;
1485  }
1486  }
1487  break;
1488  case SCDB_TYPE_CORE_DB:
1489  {
1490  char *errmsg = NULL;
1491  switch_core_db_exec(dbh->native_handle.core_db_dbh->handle, test_sql, NULL, NULL, &errmsg);
1492 
1493  if (errmsg) {
1494  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\nAuto Generating Table!\n", errmsg, test_sql);
1495  switch_core_db_free(errmsg);
1496  errmsg = NULL;
1497  if (drop_sql) {
1498  switch_core_db_exec(dbh->native_handle.core_db_dbh->handle, drop_sql, NULL, NULL, &errmsg);
1499  }
1500  if (errmsg) {
1501  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ignoring SQL ERR [%s]\n[%s]\n", errmsg, drop_sql);
1502  switch_core_db_free(errmsg);
1503  errmsg = NULL;
1504  }
1505  switch_core_db_exec(dbh->native_handle.core_db_dbh->handle, reactive_sql, NULL, NULL, &errmsg);
1506  if (errmsg) {
1507  r = SWITCH_FALSE;
1508  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql);
1509  switch_core_db_free(errmsg);
1510  errmsg = NULL;
1511  } else {
1512  r = SWITCH_TRUE;
1513  }
1514  }
1515  }
1516  break;
1517  }
1518 
1519  return r;
1520 }
switch_cache_db_native_handle_t native_handle
switch_core_db_t * handle
#define SWITCH_CHANNEL_LOG
switch_cache_db_handle_type_t type
switch_bool_t
Definition: switch_types.h:437
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:456
switch_cache_db_database_interface_options_t connection_options
struct switch_runtime runtime
Definition: switch_core.c:86
switch_coredb_handle_t * core_db_dbh
Definition: switch_core.h:2569
int switch_core_db_exec(switch_core_db_t *db, const char *sql, switch_core_db_callback_func_t callback, void *data, char **errmsg)
char * switch_snprintfv(char *zBuf, int n, const char *zFormat,...)
switch_odbc_handle_t * odbc_dbh
Definition: switch_core.h:2570
switch_database_interface_handle_t * database_interface_dbh
Definition: switch_core.h:2571
switch_cache_db_handle_t * dbh
switch_status_t
Common return values.
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:693
#define database_interface_handle_exec(database_interface, dih, sql, 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_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_database_interface_t * database_interface
Definition: switch_core.h:2589
Abstract interface to a database module.

◆ switch_cache_db_type_name()

static const char* switch_cache_db_type_name ( switch_cache_db_handle_type_t  type)
inlinestatic

Definition at line 2602 of file switch_core.h.

References _switch_cache_db_get_db_handle(), dbh, SCDB_TYPE_CORE_DB, SCDB_TYPE_DATABASE_INTERFACE, SCDB_TYPE_ODBC, switch_cache_db_dismiss_db_handle(), switch_cache_db_get_type(), switch_cache_db_release_db_handle(), SWITCH_DECLARE, and switch_cache_db_handle::type.

Referenced by _switch_cache_db_get_db_handle(), and switch_cache_db_status().

2603 {
2604  const char *type_str = "INVALID";
2605 
2606  switch (type) {
2608  {
2609  type_str = "DATABASE_INTERFACE";
2610  }
2611  break;
2612  case SCDB_TYPE_ODBC:
2613  {
2614  type_str = "ODBC";
2615  }
2616  break;
2617  case SCDB_TYPE_CORE_DB:
2618  {
2619  type_str = "CORE_DB";
2620  }
2621  break;
2622  }
2623 
2624  return type_str;
2625 }

◆ switch_close_extra_files()

void switch_close_extra_files ( int *  keep,
int  keep_ttl 
)

Definition at line 3244 of file switch_core.c.

References system_thread_handle::cmd, SWITCH_DECLARE, switch_fork(), switch_max_file_desc(), switch_system_fork(), and switch_system_thread().

Referenced by preprocess_exec(), and switch_system_fork().

3245 {
3246  int open_max = switch_max_file_desc();
3247  int i, j;
3248 
3249  for (i = 3; i < open_max; i++) {
3250  if (keep) {
3251  for (j = 0; j < keep_ttl; j++) {
3252  if (i == keep[j]) {
3253  goto skip;
3254  }
3255  }
3256  }
3257 
3258  close(i);
3259 
3260  skip:
3261 
3262  continue;
3263 
3264  }
3265 }
int switch_max_file_desc(void)
Definition: switch_core.c:3228

◆ switch_core_add_registration()

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 3465 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.

3468 {
3469  char *sql;
3470 
3471  if (!switch_test_flag((&runtime), SCF_USE_SQL)) {
3472  return SWITCH_STATUS_FALSE;
3473  }
3474 
3476  sql = switch_mprintf("delete from registrations where hostname='%q' and (url='%q' or token='%q')",
3478  } else {
3479  sql = switch_mprintf("delete from registrations where reg_user='%q' and realm='%q' and hostname='%q'",
3480  user, realm, switch_core_get_switchname());
3481  }
3482 
3484 
3485  if ( !zstr(metadata) ) {
3486  sql = switch_mprintf("insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname,metadata) "
3487  "values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q','%q')",
3488  switch_str_nil(user),
3489  switch_str_nil(realm),
3490  switch_str_nil(token),
3491  switch_str_nil(url),
3492  expires,
3493  switch_str_nil(network_ip),
3494  switch_str_nil(network_port),
3495  switch_str_nil(network_proto),
3497  metadata
3498  );
3499  } else {
3500  sql = switch_mprintf("insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname) "
3501  "values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q')",
3502  switch_str_nil(user),
3503  switch_str_nil(realm),
3504  switch_str_nil(token),
3505  switch_str_nil(url),
3506  expires,
3507  switch_str_nil(network_ip),
3508  switch_str_nil(network_port),
3509  switch_str_nil(network_proto),
3511  );
3512  }
3513 
3514 
3516 
3517  return SWITCH_STATUS_SUCCESS;
3518 }
const char * switch_core_get_switchname(void)
Definition: switch_core.c:361
struct switch_runtime runtime
Definition: switch_core.c:86
#define zstr(x)
Definition: switch_utils.h:314
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:993
static struct @4 sql_manager
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
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,...)

◆ switch_core_autobind_cpu()

void switch_core_autobind_cpu ( void  )

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

7099 {
7100  if (video_globals.cpu_count > 1) {
7102  }
7103 }
switch_status_t switch_core_thread_set_cpu_affinity(int cpu)
Definition: switch_core.c:1763
int next_cpu(void)
static core_video_globals_t video_globals

◆ switch_core_banner()

const char* switch_core_banner ( void  )

Definition at line 2406 of file switch_core.c.

Referenced by switch_core_init_and_modload().

2407 {
2408 
2409  return ("\n"
2410  ".=============================================================.\n"
2411  "| _____ ______ _____ _____ ____ _ _ |\n"
2412  "| | ___| __ ___ ___/ ___\\ \\ / /_ _|_ _/ ___| | | | |\n"
2413  "| | |_ | '__/ _ \\/ _ \\___ \\\\ \\ /\\ / / | | | || | | |_| | |\n"
2414  "| | _|| | | __/ __/___) |\\ V V / | | | || |___| _ | |\n"
2415  "| |_| |_| \\___|\\___|____/ \\_/\\_/ |___| |_| \\____|_| |_| |\n"
2416  "| |\n"
2417  ".=============================================================."
2418  "\n"
2419 
2420  "| Anthony Minessale II, Michael Jerris, Brian West, Others |\n"
2421  "| FreeSWITCH (http://www.freeswitch.org) |\n"
2422  "| Paypal Donations Appreciated: paypal@freeswitch.org |\n"
2423  "| Brought to you by ClueCon http://www.cluecon.com/ |\n"
2424  ".=============================================================.\n"
2425  "\n");
2426 }

◆ switch_core_cert_expand_fingerprint()

int switch_core_cert_expand_fingerprint ( dtls_fingerprint_t fp,
const char *  str 
)

Definition at line 162 of file switch_core_cert.c.

References dtls_fp_s::data, and MAX_FPLEN.

Referenced by switch_rtp_add_dtls().

163 {
164  char *tmp = strdup(str);
165  char *p = tmp;
166  int i = 0;
167  char *v;
168 
169  while ((v = strsep(&p, ":")) && (i != (MAX_FPLEN - 1))) {
170  sscanf(v, "%02x", (uint32_t *) &fp->data[i++]);
171  }
172 
173  free(tmp);
174 
175  return i;
176 }
uint8_t data[MAX_FPLEN+1]
Definition: switch_core.h:154
#define MAX_FPLEN
Definition: switch_core.h:149

◆ switch_core_cert_gen_fingerprint()

int switch_core_cert_gen_fingerprint ( const char *  prefix,
dtls_fingerprint_t fp 
)

Definition at line 199 of file switch_core_cert.c.

References switch_directories::certs_dir, mkcert(), 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().

200 {
201  X509* x509 = NULL;
202  BIO* bio = NULL;
203  int ret = 0;
204  char *rsa;
205 
207 
208  if (switch_file_exists(rsa, NULL) != SWITCH_STATUS_SUCCESS) {
209  free(rsa);
211  }
212 
213  if (!(bio = BIO_new(BIO_s_file()))) {
215  goto end;
216  }
217 
218  if (BIO_read_filename(bio, rsa) != 1) {
220  goto end;
221  }
222 
223  if (!(x509 = PEM_read_bio_X509(bio, NULL, 0, NULL))) {
225  goto end;
226  }
227 
229 
230  ret = 1;
231 
232  end:
233 
234  if (bio) {
235  BIO_free_all(bio);
236  }
237 
238  if (x509) {
239  X509_free(x509);
240  }
241 
242  free(rsa);
243 
244  return ret;
245 }
#define SWITCH_CHANNEL_LOG
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:124
int switch_core_cert_extract_fingerprint(X509 *x509, dtls_fingerprint_t *fp)
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:82
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
Definition: switch_apr.c:519
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,...)

◆ switch_core_cert_verify()

int switch_core_cert_verify ( dtls_fingerprint_t fp)

Definition at line 143 of file switch_core_cert.c.

References dtls_fp_s::data, MAX_FPLEN, and dtls_fp_s::str.

Referenced by do_dtls(), and dtls_state_setup().

144 {
145  unsigned char fdata[MAX_FPLEN] = { 0 };
146  char *tmp = strdup(fp->str);
147  char *p = tmp;
148  int i = 0;
149  char *v;
150 
151  while ((v = strsep(&p, ":")) && (i != (MAX_FPLEN - 1))) {
152  sscanf(v, "%02x", (uint32_t *) &fdata[i++]);
153  }
154 
155  free(tmp);
156 
157  i = !memcmp(fdata, fp->data, i);
158 
159  return i;
160 }
char str[MAX_FPSTRLEN]
Definition: switch_core.h:156
uint8_t data[MAX_FPLEN+1]
Definition: switch_core.h:154
#define MAX_FPLEN
Definition: switch_core.h:149

◆ switch_core_check_core_db_dsn()

switch_status_t switch_core_check_core_db_dsn ( void  )

Returns error if no suitable database interface found to serve core db dsn.

Definition at line 422 of file switch_core_sqldb.c.

References switch_runtime::odbc_dsn, runtime, and switch_database_available().

Referenced by switch_core_sqldb_init().

423 {
425 }
switch_status_t switch_database_available(char *dsn)
Returns error if no suitable database interface found for a dsn.
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_check_dtls_pem()

switch_bool_t switch_core_check_dtls_pem ( const char *  file)

Definition at line 338 of file switch_core_cert.c.

References switch_directories::certs_dir, SWITCH_CHANNEL_LOG, SWITCH_FALSE, switch_file_exists(), SWITCH_GLOBAL_dirs, switch_is_file_path(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, switch_mprintf(), SWITCH_PATH_SEPARATOR, switch_safe_free, SWITCH_STATUS_SUCCESS, and SWITCH_TRUE.

Referenced by switch_core_media_init().

339 {
340  char *pem = NULL, *old_pem = NULL;
341  FILE *fp = NULL;
342  EVP_PKEY *pkey = NULL;
343  int bits = 0;
344 
345  if (switch_is_file_path(file)) {
346  pem = strdup(file);
347  } else {
349  }
350 
351  if (switch_file_exists(pem, NULL) != SWITCH_STATUS_SUCCESS) {
352  switch_safe_free(pem);
353 
354  return SWITCH_FALSE;
355  }
356 
357  fp = fopen(pem, "r");
358  if (!fp) {
359  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open %s: %s\n", pem, strerror(errno));
360  goto rename_pem;
361  }
362 
363  pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL);
364  fclose(fp);
365 
366  if (!pkey) {
367  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot read key %s: %s\n", pem, ERR_error_string(ERR_get_error(), NULL));
368  goto rename_pem;
369  }
370 
371  bits = EVP_PKEY_bits(pkey);
372  EVP_PKEY_free(pkey);
373 
374  if (bits < 4096) {
375  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s cryptographic length is too short (%d), it will be regenerated\n", pem, bits);
376  goto rename_pem;
377  }
378 
379  switch_safe_free(pem);
380 
381  return SWITCH_TRUE;
382 
383 rename_pem:
384 
385  old_pem = switch_mprintf("%s.old", pem);
386 
387  if (rename(pem, old_pem) != -1) {
388  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Renamed %s to %s\n", pem, old_pem);
389  } else {
390  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not rename %s: %s\n", pem, strerror(errno));
391  }
392 
393  switch_safe_free(old_pem);
394  switch_safe_free(pem);
395 
396  return SWITCH_FALSE;
397 }
#define SWITCH_CHANNEL_LOG
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:124
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:82
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
Definition: switch_apr.c:519
static switch_bool_t switch_is_file_path(const char *file)
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,...)

◆ switch_core_dbtype()

switch_cache_db_handle_type_t switch_core_dbtype ( void  )

Definition at line 3350 of file switch_core_sqldb.c.

References SCDB_TYPE_CORE_DB, sql_manager, switch_mutex_lock(), switch_mutex_unlock(), and switch_cache_db_handle::type.

Referenced by switch_console_set_complete().

3351 {
3353 
3354  switch_mutex_lock(sql_manager.ctl_mutex);
3355  if (sql_manager.qm && sql_manager.qm->event_db) {
3356  type = sql_manager.qm->event_db->type;
3357  }
3358  switch_mutex_unlock(sql_manager.ctl_mutex);
3359 
3360  return type;
3361 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_cache_db_handle_type_t
Definition: switch_core.h:2562
static struct @4 sql_manager

◆ switch_core_debug_level()

uint32_t switch_core_debug_level ( void  )

Definition at line 2607 of file switch_core.c.

References switch_runtime::debug_level.

2608 {
2609  return runtime.debug_level;
2610 }
struct switch_runtime runtime
Definition: switch_core.c:86
uint32_t debug_level

◆ switch_core_del_registration()

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 3520 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.

3521 {
3522 
3523  char *sql;
3524 
3525  if (!switch_test_flag((&runtime), SCF_USE_SQL)) {
3526  return SWITCH_STATUS_FALSE;
3527  }
3528 
3529  if (!zstr(token) && runtime.multiple_registrations) {
3530  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);
3531  } else {
3532  sql = switch_mprintf("delete from registrations where reg_user='%q' and realm='%q' and hostname='%q'", user, realm, switch_core_get_switchname());
3533  }
3534 
3536 
3537 
3538  return SWITCH_STATUS_SUCCESS;
3539 }
const char * switch_core_get_switchname(void)
Definition: switch_core.c:361
struct switch_runtime runtime
Definition: switch_core.c:86
#define zstr(x)
Definition: switch_utils.h:314
static struct @4 sql_manager
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
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,...)

◆ switch_core_expire_registration()

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 3541 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().

3542 {
3543 
3544  char *sql;
3545  time_t now;
3546 
3547  if (!switch_test_flag((&runtime), SCF_USE_SQL)) {
3548  return SWITCH_STATUS_FALSE;
3549  }
3550 
3551  now = switch_epoch_time_now(NULL);
3552 
3553  if (force) {
3554  sql = switch_mprintf("delete from registrations where hostname='%q'", switch_core_get_switchname());
3555  } else {
3556  sql = switch_mprintf("delete from registrations where expires > 0 and expires <= %ld and hostname='%q'", now, switch_core_get_switchname());
3557  }
3558 
3560 
3561  return SWITCH_STATUS_SUCCESS;
3562 
3563 }
const char * switch_core_get_switchname(void)
Definition: switch_core.c:361
struct switch_runtime runtime
Definition: switch_core.c:86
static struct @4 sql_manager
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:322
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
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,...)

◆ switch_core_gen_certs()

int switch_core_gen_certs ( const char *  prefix)

Definition at line 250 of file switch_core_cert.c.

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

Referenced by load_config(), and switch_core_media_init().

251 {
252  //BIO *bio_err;
253  X509 *x509 = NULL;
254  EVP_PKEY *pkey = NULL;
255  char *rsa = NULL, *pvt = NULL;
256  FILE *fp;
257  char *pem = NULL;
258 
259  if (switch_stristr(".pem", prefix)) {
260 
261  if (switch_is_file_path(prefix)) {
262  pem = strdup(prefix);
263  } else {
265  }
266 
267  if (switch_file_exists(pem, NULL) == SWITCH_STATUS_SUCCESS) {
268  goto end;
269  }
270  } else {
271  if (switch_is_file_path(prefix)) {
272  pvt = switch_mprintf("%s.key", prefix);
273  rsa = switch_mprintf("%s.crt", prefix);
274  } else {
277  }
278 
280  goto end;
281  }
282  }
283 
284 #ifdef CRYPTO_MEM_CHECK_ON
285  CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
286 #endif
287 
288  //bio_err=BIO_new_fp(stderr, BIO_NOCLOSE);
289 
290  if (!mkcert(&x509, &pkey, 4096, 0, 36500)) {
291  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Certificate generation failed\n");
292  goto end;
293  }
294 
295  //RSA_print_fp(stdout, pkey->pkey.rsa, 0);
296  //X509_print_fp(stdout, x509);
297 
298  if (pem) {
299  if ((fp = fopen(pem, "w"))) {
300  PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL);
301  PEM_write_X509(fp, x509);
302  fclose(fp);
303  }
304 
305  } else {
306  if (pvt && (fp = fopen(pvt, "w"))) {
307  PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL);
308  fclose(fp);
309  }
310 
311  if (rsa && (fp = fopen(rsa, "w"))) {
312  PEM_write_X509(fp, x509);
313  fclose(fp);
314  }
315  }
316 
317  X509_free(x509);
318  EVP_PKEY_free(pkey);
319 
320 #ifndef OPENSSL_NO_ENGINE
321  ENGINE_cleanup();
322 #endif
323  CRYPTO_cleanup_all_ex_data();
324 
325  //CRYPTO_mem_leaks(bio_err);
326  //BIO_free(bio_err);
327 
328 
329  end:
330 
331  switch_safe_free(pvt);
332  switch_safe_free(rsa);
333  switch_safe_free(pem);
334 
335  return(0);
336 }
#define SWITCH_CHANNEL_LOG
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:124
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:82
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
Definition: switch_apr.c:519
static switch_bool_t switch_is_file_path(const char *file)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
const char * switch_stristr(const char *instr, const char *str)
static int mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)

◆ switch_core_gen_encoded_silence()

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 switch_codec_implementation::ianacode, switch_codec_implementation::iananame, 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)

◆ switch_core_get_event_channel_key_separator()

const char* switch_core_get_event_channel_key_separator ( void  )

Definition at line 3592 of file switch_core.c.

References switch_runtime::event_channel_key_separator.

Referenced by ecd_deliver().

3593 {
3595 }
struct switch_runtime runtime
Definition: switch_core.c:86
char * event_channel_key_separator

◆ switch_core_get_rtp_port_range_end_port()

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 3581 of file switch_core.c.

References switch_rtp_set_end_port().

3582 {
3583  uint16_t end_port = 0;
3584 
3585  /* By default pass rtp port range end value as zero in order to get actual
3586  * RTP port range end value as configured */
3587  end_port = (uint16_t)switch_rtp_set_end_port((switch_port_t)end_port);
3588 
3589  return end_port;
3590 }
switch_port_t switch_rtp_set_end_port(switch_port_t port)
Set/Get RTP end port.
Definition: switch_rtp.c:2596
uint16_t switch_port_t

◆ switch_core_get_rtp_port_range_start_port()

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 3570 of file switch_core.c.

References switch_rtp_set_start_port().

3571 {
3572  uint16_t start_port = 0;
3573 
3574  /* By default pass rtp port range start value as zero in order to get actual
3575  * RTP port range start value as configured */
3576  start_port = (uint16_t)switch_rtp_set_start_port((switch_port_t)start_port);
3577 
3578  return start_port;
3579 }
switch_port_t switch_rtp_set_start_port(switch_port_t port)
Set/Get RTP start port.
Definition: switch_rtp.c:2582
uint16_t switch_port_t

◆ switch_core_get_stacksizes()

switch_status_t switch_core_get_stacksizes ( switch_size_t cur,
switch_size_t max 
)

Definition at line 3512 of file switch_core.c.

References memset(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

3513 {
3514 #ifdef HAVE_SETRLIMIT
3515  struct rlimit rlp;
3516 
3517  memset(&rlp, 0, sizeof(rlp));
3518  getrlimit(RLIMIT_STACK, &rlp);
3519 
3520  *cur = rlp.rlim_cur;
3521  *max = rlp.rlim_max;
3522 
3523  return SWITCH_STATUS_SUCCESS;
3524 
3525 #else
3526 
3527  return SWITCH_STATUS_FALSE;
3528 
3529 #endif
3530 
3531 
3532 
3533 }
pack cur
memset(buf, 0, buflen)

◆ switch_core_max_audio_channels()

uint32_t switch_core_max_audio_channels ( uint32_t  limit)

Definition at line 2642 of file switch_core.c.

References switch_runtime::max_audio_channels.

Referenced by switch_core_media_negotiate_sdp(), switch_core_perform_file_open(), and switch_load_core_config().

2643 {
2644  if (limit) {
2645  runtime.max_audio_channels = limit;
2646  }
2647 
2648  return runtime.max_audio_channels;
2649 }
uint32_t max_audio_channels
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_recovery_flush()

void switch_core_recovery_flush ( const char *  technology,
const char *  profile_name 
)

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

3134 {
3135  char *sql = NULL;
3137 
3139  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
3140  return;
3141  }
3142 
3143  if (zstr(technology)) {
3144 
3145  if (zstr(profile_name)) {
3146  sql = switch_mprintf("delete from recovery");
3147  } else {
3149  }
3150 
3151  } else {
3152  if (zstr(profile_name)) {
3153  sql = switch_mprintf("delete from recovery where technology='%q' ", technology);
3154  } else {
3155  sql = switch_mprintf("delete from recovery where technology='%q' and profile_name='%q'", technology, profile_name);
3156  }
3157  }
3158 
3159  if (sql) {
3160  switch_cache_db_execute_sql(dbh, sql, NULL);
3161  switch_safe_free(sql);
3162  }
3163 
3165 }
#define SWITCH_CHANNEL_LOG
#define zstr(x)
Definition: switch_utils.h:314
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
switch_cache_db_handle_t * dbh
#define switch_core_db_handle(_a)
Definition: switch_core.h:2729
void switch_cache_db_release_db_handle(switch_cache_db_handle_t **dbh)
Returns the handle to the pool, handle is NOT available to other threads until the allocating thread ...
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,...)

◆ switch_core_recovery_recover()

int switch_core_recovery_recover ( const char *  technology,
const char *  profile_name 
)

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

3272 {
3273  char *sql = NULL;
3274  char *errmsg = NULL;
3276  int r = 0;
3277 
3278  if (!sql_manager.manage) {
3279  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DATABASE NOT AVAIALBLE, REVCOVERY NOT POSSIBLE\n");
3280  return 0;
3281  }
3282 
3284  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
3285  return 0;
3286  }
3287 
3288  if (zstr(technology)) {
3289 
3290  if (zstr(profile_name)) {
3291  sql = switch_mprintf("select technology, profile_name, hostname, uuid, metadata "
3292  "from recovery where runtime_uuid!='%q'",
3294  } else {
3295  sql = switch_mprintf("select technology, profile_name, hostname, uuid, metadata "
3296  "from recovery where runtime_uuid!='%q' and profile_name='%q'",
3297  switch_core_get_uuid(), profile_name);
3298  }
3299 
3300  } else {
3301 
3302  if (zstr(profile_name)) {
3303  sql = switch_mprintf("select technology, profile_name, hostname, uuid, metadata "
3304  "from recovery where technology='%q' and runtime_uuid!='%q'",
3305  technology, switch_core_get_uuid());
3306  } else {
3307  sql = switch_mprintf("select technology, profile_name, hostname, uuid, metadata "
3308  "from recovery where technology='%q' and runtime_uuid!='%q' and profile_name='%q'",
3309  technology, switch_core_get_uuid(), profile_name);
3310  }
3311  }
3312 
3313 
3315 
3316  if (errmsg) {
3317  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
3318  switch_safe_free(errmsg);
3319  }
3320 
3321  switch_safe_free(sql);
3322 
3323  if (zstr(technology)) {
3324  if (zstr(profile_name)) {
3325  sql = switch_mprintf("delete from recovery where runtime_uuid!='%q'",
3327  } else {
3328  sql = switch_mprintf("delete from recovery where runtime_uuid!='%q' and profile_name='%q'",
3329  switch_core_get_uuid(), profile_name);
3330  }
3331  } else {
3332  if (zstr(profile_name)) {
3333  sql = switch_mprintf("delete from recovery where runtime_uuid!='%q' and technology='%q' ",
3334  switch_core_get_uuid(), technology);
3335  } else {
3336  sql = switch_mprintf("delete from recovery where runtime_uuid!='%q' and technology='%q' and profile_name='%q'",
3337  switch_core_get_uuid(), technology, profile_name);
3338  }
3339  }
3340 
3341  switch_cache_db_execute_sql(dbh, sql, NULL);
3342  switch_safe_free(sql);
3343 
3345 
3346  return r;
3347 
3348 }
#define SWITCH_CHANNEL_LOG
#define zstr(x)
Definition: switch_utils.h:314
char * switch_core_get_uuid(void)
Retrieve the unique identifier from the core.
Definition: switch_core.c:495
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
switch_cache_db_handle_t * dbh
#define switch_core_db_handle(_a)
Definition: switch_core.h:2729
void switch_cache_db_release_db_handle(switch_cache_db_handle_t **dbh)
Returns the handle to the pool, handle is NOT available to other threads until the allocating thread ...
static struct @4 sql_manager
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,...)

◆ switch_core_recovery_track()

void switch_core_recovery_track ( switch_core_session_t session)

Definition at line 3415 of file switch_core_sqldb.c.

References CF_ANSWERED, CF_RECOVERING, CF_TRACKABLE, CF_TRACKED, CS_SOFT_EXECUTE, switch_core_session::endpoint_interface, switch_endpoint_interface::interface_name, 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().

3416 {
3417  switch_xml_t cdr = NULL;
3418  char *xml_cdr_text = NULL;
3419  char *sql = NULL;
3421  const char *profile_name;
3422  const char *technology;
3423 
3424  if (!sql_manager.manage) {
3425  return;
3426  }
3427 
3429  return;
3430  }
3431 
3433  return;
3434  }
3435 
3436  profile_name = switch_channel_get_variable_dup(channel, "recovery_profile_name", SWITCH_FALSE, -1);
3437  technology = session->endpoint_interface->interface_name;
3438 
3439  if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
3440  xml_cdr_text = switch_xml_toxml_nolock(cdr, SWITCH_FALSE);
3441  switch_xml_free(cdr);
3442  }
3443 
3444  if (xml_cdr_text) {
3445  if (switch_channel_test_flag(channel, CF_TRACKED)) {
3446  sql = switch_mprintf("update recovery set metadata='%q' where uuid='%q'", xml_cdr_text, switch_core_session_get_uuid(session));
3447  } else {
3448  sql = switch_mprintf("insert into recovery (runtime_uuid, technology, profile_name, hostname, uuid, metadata) "
3449  "values ('%q','%q','%q','%q','%q','%q')",
3450  switch_core_get_uuid(), switch_str_nil(technology),
3451  switch_str_nil(profile_name), switch_core_get_switchname(), switch_core_session_get_uuid(session), xml_cdr_text);
3452  }
3453 
3455 
3456  switch_safe_free(xml_cdr_text);
3458 
3459  }
3460 
3461 }
const char * switch_core_get_switchname(void)
Definition: switch_core.c:361
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:79
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:495
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
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:993
#define switch_xml_toxml_nolock(xml, prn_header)
Definition: switch_xml.h:225
static struct @4 sql_manager
#define switch_channel_set_flag(_c, _f)
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:2862
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)

◆ switch_core_recovery_untrack()

void switch_core_recovery_untrack ( switch_core_session_t session,
switch_bool_t  force 
)

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

3378 {
3379  char *sql = NULL;
3381 
3382  if (!sql_manager.manage) {
3383  return;
3384  }
3385 
3387  return;
3388  }
3389 
3390  if (!switch_channel_test_flag(channel, CF_TRACKABLE)) {
3391  return;
3392  }
3393 
3394  if ((switch_channel_test_flag(channel, CF_RECOVERING))) {
3395  return;
3396  }
3397 
3398  if (switch_channel_test_flag(channel, CF_TRACKED) || force) {
3399 
3400  if (force) {
3401  sql = switch_mprintf("delete from recovery where uuid='%q'", switch_core_session_get_uuid(session));
3402 
3403  } else {
3404  sql = switch_mprintf("delete from recovery where runtime_uuid='%q' and uuid='%q'",
3406  }
3407 
3409 
3411  }
3412 
3413 }
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:495
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
static struct @4 sql_manager
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,...)

◆ switch_core_session_debug_pool()

void switch_core_session_debug_pool ( switch_stream_handle_t stream)

Definition at line 3122 of file switch_core_session.c.

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

3123 {
3124  stream->write_function(stream, "Thread pool: running:%d busy:%d popping:%d\n",
3126 }
struct switch_session_manager session_manager
switch_stream_handle_write_function_t write_function

◆ switch_core_session_in_thread()

switch_bool_t switch_core_session_in_thread ( switch_core_session_t session)

Definition at line 1712 of file switch_core_session.c.

References SWITCH_FALSE, switch_thread_equal(), switch_thread_self(), SWITCH_TRUE, and switch_core_session::thread_id.

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().

1713 {
1715 }
int switch_thread_equal(switch_thread_id_t tid1, switch_thread_id_t tid2)
Compare two thread ids.
Definition: switch_apr.c:111
switch_thread_id_t switch_thread_self(void)
Definition: switch_apr.c:102
switch_thread_id_t thread_id

◆ switch_core_session_override_io_routines()

switch_status_t switch_core_session_override_io_routines ( switch_core_session_t session,
switch_io_routines_t ior 
)

Definition at line 3142 of file switch_core_session.c.

References CC_IO_OVERRIDE, switch_core_session::channel, switch_core_session::endpoint_interface, switch_core_session::io_override, switch_channel_test_cap(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

3143 {
3145  session->io_override = ior;
3146  return SWITCH_STATUS_SUCCESS;
3147  }
3148 
3149  return SWITCH_STATUS_FALSE;
3150 }
switch_channel_t * channel
switch_io_routines_t * io_override
uint32_t switch_channel_test_cap(switch_channel_t *channel, switch_channel_cap_t cap)
switch_endpoint_interface_t * endpoint_interface

◆ switch_core_session_send_and_request_video_refresh()

switch_status_t switch_core_session_send_and_request_video_refresh ( switch_core_session_t session)

Definition at line 14568 of file switch_core_media.c.

References CF_VIDEO, switch_core_session::channel, 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().

14569 {
14570  if (switch_channel_test_flag(session->channel, CF_VIDEO)) {
14573  return SWITCH_STATUS_SUCCESS;
14574  }
14575 
14576  return SWITCH_STATUS_FALSE;
14577 }
#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_channel_t * channel
#define switch_core_session_request_video_refresh(_s)
Definition: switch_core.h:2881

◆ switch_core_session_start_text_thread()

switch_status_t switch_core_session_start_text_thread ( switch_core_session_t session)

Definition at line 7396 of file switch_core_media.c.

References CF_HAS_TEXT, switch_core_session::channel, media_helper::cond, media_helper::cond_mutex, switch_media_handle_s::control_mutex, switch_rtp_engine_s::cur_payload_map, switch_media_handle_s::engines, switch_core_session::media_handle, switch_rtp_engine_s::media_thread, switch_rtp_engine_s::mh, core_video_globals_s::pool, payload_map_s::pt, media_helper::ready, switch_rtp_engine_s::rtp_session, media_helper::session, SWITCH_CHANNEL_SESSION_LOG, switch_channel_test_flag(), switch_cond_next(), switch_core_session_get_name, switch_core_session_get_pool(), SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_MEDIA_TYPE_TEXT, switch_mutex_init(), switch_mutex_lock(), SWITCH_MUTEX_NESTED, switch_mutex_unlock(), switch_rtp_set_default_payload(), SWITCH_STATUS_FALSE, SWITCH_STATUS_NOTIMPL, SWITCH_STATUS_SUCCESS, switch_thread_cond_create(), switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_stacksize_set(), and text_helper_thread().

Referenced by switch_core_media_activate_rtp(), switch_core_media_gen_local_sdp(), switch_core_media_negotiate_sdp(), switch_core_media_start_engine_function(), and switch_core_session_set_text_read_callback().

7397 {
7398  switch_threadattr_t *thd_attr = NULL;
7400  switch_rtp_engine_t *t_engine = NULL;
7401  switch_media_handle_t *smh;
7402 
7403  if (!switch_channel_test_flag(session->channel, CF_HAS_TEXT)) {
7404  return SWITCH_STATUS_NOTIMPL;
7405  }
7406 
7407  if (!(smh = session->media_handle)) {
7408  return SWITCH_STATUS_FALSE;
7409  }
7410 
7411  t_engine = &smh->engines[SWITCH_MEDIA_TYPE_TEXT];
7412 
7414 
7415  if (t_engine->media_thread) {
7417  return SWITCH_STATUS_FALSE;
7418  }
7419 
7420  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Starting Text thread\n", switch_core_session_get_name(session));
7421 
7422  if (t_engine->rtp_session) {
7424  }
7425 
7426  t_engine->mh.session = session;
7427  switch_threadattr_create(&thd_attr, pool);
7429 
7430  switch_thread_cond_create(&t_engine->mh.cond, pool);
7432  //switch_mutex_init(&t_engine->mh.file_read_mutex, SWITCH_MUTEX_NESTED, pool);
7433  //switch_mutex_init(&t_engine->mh.file_write_mutex, SWITCH_MUTEX_NESTED, pool);
7434  //switch_mutex_init(&smh->read_mutex[SWITCH_MEDIA_TYPE_TEXT], SWITCH_MUTEX_NESTED, pool);
7435  //switch_mutex_init(&smh->write_mutex[SWITCH_MEDIA_TYPE_TEXT], SWITCH_MUTEX_NESTED, pool);
7436 
7437  t_engine->mh.ready = 0;
7438 
7439  if (switch_thread_create(&t_engine->media_thread, thd_attr, text_helper_thread, &t_engine->mh,
7441  while(!t_engine->mh.ready) {
7442  switch_cond_next();
7443  }
7444  }
7445 
7447  return SWITCH_STATUS_SUCCESS;
7448 }
switch_status_t switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool)
Definition: switch_apr.c:373
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_core_session_t * session
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:683
switch_memory_pool_t * pool
static void *SWITCH_THREAD_FUNC text_helper_thread(switch_thread_t *thread, void *obj)
switch_thread_cond_t * cond
#define switch_core_session_get_name(_s)
Definition: switch_core.h:265
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_media_handle_t * media_handle
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
switch_channel_t * channel
switch_rtp_t * rtp_session
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:584
payload_map_t * cur_payload_map
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
switch_payload_t pt
void switch_cond_next(void)
Definition: switch_time.c:658
switch_mutex_t * control_mutex
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL]
void switch_rtp_set_default_payload(switch_rtp_t *rtp_session, switch_payload_t payload)
Set the default payload number for a given RTP session.
Definition: switch_rtp.c:5335
switch_thread_t * media_thread
switch_mutex_t * cond_mutex
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:665
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:698
struct fspr_pool_t switch_memory_pool_t
struct media_helper mh
switch_memory_pool_t * switch_core_session_get_pool(_In_ switch_core_session_t *session)
Retrieve the memory pool from a session.

◆ switch_core_sessions_peak()

int32_t switch_core_sessions_peak ( void  )

Definition at line 2632 of file switch_core.c.

References switch_runtime::sessions_peak.

2633 {
2634  return runtime.sessions_peak;
2635 }
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_sessions_peak_fivemin()

int32_t switch_core_sessions_peak_fivemin ( void  )

Definition at line 2637 of file switch_core.c.

References switch_runtime::sessions_peak_fivemin.

2638 {
2640 }
struct switch_runtime runtime
Definition: switch_core.c:86
int32_t sessions_peak_fivemin

◆ switch_core_set_signal_handlers()

void switch_core_set_signal_handlers ( void  )

Definition at line 2579 of file switch_core.c.

References handle_SIGHUP().

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

2580 {
2581  /* set signal handlers */
2582  signal(SIGINT, SIG_IGN);
2583 #ifdef SIGPIPE
2584  signal(SIGPIPE, SIG_IGN);
2585 #endif
2586 #ifdef SIGALRM
2587  signal(SIGALRM, SIG_IGN);
2588 #endif
2589 #ifdef SIGQUIT
2590  signal(SIGQUIT, SIG_IGN);
2591 #endif
2592 #ifdef SIGPOLL
2593  signal(SIGPOLL, SIG_IGN);
2594 #endif
2595 #ifdef SIGIO
2596  signal(SIGIO, SIG_IGN);
2597 #endif
2598 #ifdef TRAP_BUS
2599  signal(SIGBUS, handle_SIGBUS);
2600 #endif
2601 #ifdef SIGUSR1
2602  signal(SIGUSR1, handle_SIGHUP);
2603 #endif
2604  signal(SIGHUP, handle_SIGHUP);
2605 }
static void handle_SIGHUP(int sig)
Definition: switch_core.c:2008

◆ switch_core_sps()

int32_t switch_core_sps ( void  )

Definition at line 2612 of file switch_core.c.

References switch_runtime::sps.

2613 {
2614  return runtime.sps;
2615 }
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_sps_last()

int32_t switch_core_sps_last ( void  )

Definition at line 2617 of file switch_core.c.

References switch_runtime::sps_last.

2618 {
2619  return runtime.sps_last;
2620 }
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_sps_peak()

int32_t switch_core_sps_peak ( void  )

Definition at line 2622 of file switch_core.c.

References switch_runtime::sps_peak.

2623 {
2624  return runtime.sps_peak;
2625 }
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_sps_peak_fivemin()

int32_t switch_core_sps_peak_fivemin ( void  )

Definition at line 2627 of file switch_core.c.

References switch_runtime::sps_peak_fivemin.

2628 {
2629  return runtime.sps_peak_fivemin;
2630 }
struct switch_runtime runtime
Definition: switch_core.c:86
int32_t sps_peak_fivemin

◆ switch_core_sql_exec()

void switch_core_sql_exec ( const char *  sql)

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

3364 {
3365  if (!sql_manager.manage) {
3366  return;
3367  }
3368 
3369  if (!switch_test_flag((&runtime), SCF_USE_SQL)) {
3370  return;
3371  }
3372 
3373 
3375 }
struct switch_runtime runtime
Definition: switch_core.c:86
static struct @4 sql_manager
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
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_core_thread_set_cpu_affinity()

switch_status_t switch_core_thread_set_cpu_affinity ( int  cpu)

Definition at line 1763 of file switch_core.c.

References SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_autobind_cpu(), and SWITCH_MODULE_RUNTIME_FUNCTION().

1764 {
1766 
1767  if (cpu > -1) {
1768 
1769 #ifdef HAVE_CPU_SET_MACROS
1770  cpu_set_t set;
1771 
1772  CPU_ZERO(&set);
1773  CPU_SET(cpu, &set);
1774 
1775  if (!sched_setaffinity(0, sizeof(set), &set)) {
1776  status = SWITCH_STATUS_SUCCESS;
1777  }
1778 
1779 #else
1780 #if WIN32
1781  if (SetThreadAffinityMask(GetCurrentThread(), (DWORD_PTR) cpu)) {
1782  status = SWITCH_STATUS_SUCCESS;
1783  }
1784 #endif
1785 #endif
1786  }
1787 
1788  return status;
1789 }
switch_status_t
Common return values.

◆ switch_database_available()

switch_status_t switch_database_available ( char *  dsn)

Returns error if no suitable database interface found for a dsn.

Definition at line 388 of file switch_core_sqldb.c.

References MIN, switch_loadable_module_get_database_interface(), switch_odbc_available(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and UNPROTECT_INTERFACE.

Referenced by switch_core_check_core_db_dsn().

389 {
391  switch_database_interface_t *database_interface;
392 
393  if (!dsn) {
394  status = SWITCH_STATUS_SUCCESS;
395  }
396  else {
397  char *colon_slashes = NULL;
398  if (NULL != (colon_slashes = strstr(dsn, "://")))
399  {
400  char prefix[16] = "";
401  strncpy(prefix, dsn, MIN(colon_slashes - dsn, 15));
402 
403  if (!strncasecmp(prefix, "odbc", 4)) {
405  }
406  else if (!strncasecmp(prefix, "sqlite", 6)) {
407  status = SWITCH_STATUS_SUCCESS;
408  }
409  else if ((database_interface = switch_loadable_module_get_database_interface(prefix, NULL))) {
410  status = SWITCH_STATUS_SUCCESS;
411  UNPROTECT_INTERFACE(database_interface);
412  }
413  }
414  else if (strchr(dsn + 2, ':')) {
415  status = SWITCH_STATUS_SUCCESS;
416  }
417  }
418 
419  return status;
420 }
#define MIN(a, b)
#define UNPROTECT_INTERFACE(_it)
switch_database_interface_t * switch_loadable_module_get_database_interface(const char *name, const char *modname)
Retrieve the database interface by it&#39;s registered name.
switch_bool_t switch_odbc_available(void)
Definition: switch_odbc.c:809
switch_status_t
Common return values.
Abstract interface to a database module.

◆ switch_default_ptime()

uint32_t switch_default_ptime ( const char *  name,
uint32_t  number 
)

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

2023 {
2024  uint32_t *p;
2025 
2026  if ((p = switch_core_hash_find(runtime.ptimes, name))) {
2027  return *p;
2028  }
2029 
2030  return 20;
2031 }
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:86
switch_hash_t * ptimes
const char *const name
Definition: switch_cJSON.h:250

◆ switch_default_rate()

uint32_t switch_default_rate ( const char *  name,
uint32_t  number 
)

Definition at line 2033 of file switch_core.c.

Referenced by switch_loadable_module_get_codecs_sorted().

2034 {
2035 
2036  if (!strcasecmp(name, "opus")) {
2037  return 48000;
2038  } else if (!strncasecmp(name, "h26", 3)) { // h26x
2039  return 90000;
2040  } else if (!strncasecmp(name, "vp", 2)) { // vp8, vp9
2041  return 90000;
2042  }
2043 
2044  return 8000;
2045 }
const char *const name
Definition: switch_cJSON.h:250

◆ switch_fork()

pid_t switch_fork ( void  )

Definition at line 3282 of file switch_core.c.

References set_low_priority().

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

3283 {
3284  int i = fork();
3285 
3286  if (!i) {
3287  set_low_priority();
3288  }
3289 
3290  return i;
3291 }
int32_t set_low_priority(void)
Definition: switch_core.c:945

◆ switch_max_file_desc()

int switch_max_file_desc ( void  )

Definition at line 3228 of file switch_core.c.

Referenced by switch_close_extra_files().

3229 {
3230  int max = 0;
3231 
3232 #ifndef WIN32
3233 #if defined(HAVE_GETDTABLESIZE)
3234  max = getdtablesize();
3235 #else
3236  max = sysconf(_SC_OPEN_MAX);
3237 #endif
3238 #endif
3239 
3240  return max;
3241 
3242 }

◆ switch_must_malloc()

static void* switch_must_malloc ( size_t  _b)
inlinestatic

◆ switch_must_realloc()

static void* switch_must_realloc ( void *  _b,
size_t  _z 
)
inlinestatic

◆ switch_os_yield()

void switch_os_yield ( void  )

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

143 {
144 #if defined(WIN32)
145  SwitchToThread();
146 #else
147  sched_yield();
148 #endif
149 }

◆ switch_say_file()

void switch_say_file ( switch_say_file_handle_t sh,
const char *  fmt,
  ... 
)

Definition at line 3196 of file switch_loadable_module.c.

References buf, switch_say_file_handle::cnt, switch_say_file_handle::ext, switch_say_file_handle::stream, switch_vsnprintf(), and switch_stream_handle::write_function.

3197 {
3198  char buf[256] = "";
3199  va_list ap;
3200 
3201  va_start(ap, fmt);
3202 
3203  if (switch_vsnprintf(buf, sizeof(buf), fmt, ap) > 0) {
3204  if (!sh->cnt++) {
3205  sh->stream.write_function(&sh->stream, "file_string://%s.%s", buf, sh->ext);
3206  } else if (strstr(buf, "://")) {
3207  sh->stream.write_function(&sh->stream, "!%s", buf);
3208  } else {
3209  sh->stream.write_function(&sh->stream, "!%s.%s", buf, sh->ext);
3210  }
3211  }
3212 
3213  va_end(ap);
3214 }
struct switch_stream_handle stream
int cJSON_bool fmt
Definition: switch_cJSON.h:150
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:217

◆ switch_say_file_handle_create()

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 3173 of file switch_loadable_module.c.

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

3174 {
3175  switch_assert(sh);
3176 
3177  if (zstr(ext)) {
3178  ext = "wav";
3179  }
3180 
3181  *sh = malloc(sizeof(**sh));
3182  memset(*sh, 0, sizeof(**sh));
3183 
3184  SWITCH_STANDARD_STREAM((*sh)->stream);
3185 
3186  if (var_event) {
3187  (*sh)->param_event = *var_event;
3188  *var_event = NULL;
3189  }
3190 
3191  (*sh)->ext = strdup(ext);
3192 
3193  return SWITCH_STATUS_SUCCESS;
3194 }
#define zstr(x)
Definition: switch_utils.h:314
#define SWITCH_STANDARD_STREAM(s)
#define switch_assert(expr)
memset(buf, 0, buflen)

◆ switch_say_file_handle_destroy()

void switch_say_file_handle_destroy ( switch_say_file_handle_t **  sh)

Definition at line 3159 of file switch_loadable_module.c.

References switch_assert, switch_event_destroy(), and switch_safe_free.

3160 {
3161  switch_assert(sh);
3162 
3163  switch_safe_free((*sh)->stream.data);
3164  switch_safe_free((*sh)->ext);
3165 
3166  if ((*sh)->param_event) {
3167  switch_event_destroy(&(*sh)->param_event);
3168  }
3169  free(*sh);
3170  *sh = NULL;
3171 }
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
void switch_event_destroy(switch_event_t **event)
Destroy an event.
#define switch_assert(expr)

◆ switch_say_file_handle_detach_path()

char* switch_say_file_handle_detach_path ( switch_say_file_handle_t sh)

Definition at line 3148 of file switch_loadable_module.c.

References switch_stream_handle::data, path, switch_say_file_handle::stream, and switch_assert.

3149 {
3150  char *path;
3151 
3152  switch_assert(sh);
3153  path = (char *) sh->stream.data;
3154  sh->stream.data = NULL;
3155  return path;
3156 }
struct switch_stream_handle stream
const char *const const char *const path
#define switch_assert(expr)

◆ switch_say_file_handle_get_path()

char* switch_say_file_handle_get_path ( switch_say_file_handle_t sh)

Definition at line 3143 of file switch_loadable_module.c.

References switch_stream_handle::data, and switch_say_file_handle::stream.

3144 {
3145  return (char *) sh->stream.data;
3146 }
struct switch_stream_handle stream

◆ switch_say_file_handle_get_variable()

char* switch_say_file_handle_get_variable ( switch_say_file_handle_t sh,
const char *  var 
)

Definition at line 3131 of file switch_loadable_module.c.

References switch_say_file_handle::param_event, and switch_event_get_header.

3132 {
3133  char *ret = NULL;
3134 
3135  if (sh->param_event) {
3136  ret = switch_event_get_header(sh->param_event, var);
3137  }
3138 
3139  return ret;
3140 
3141 }
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172

◆ switch_spawn()

int switch_spawn ( const char *  cmd,
switch_bool_t  wait 
)

Definition at line 3507 of file switch_core.c.

References SWITCH_FALSE, and switch_stream_spawn().

3508 {
3509  return switch_stream_spawn(cmd, SWITCH_FALSE, wait, NULL);
3510 }
int switch_stream_spawn(const char *cmd, switch_bool_t shell, switch_bool_t wait, switch_stream_handle_t *stream)
Definition: switch_core.c:3372

◆ switch_sql_queue_manager_destroy()

switch_status_t switch_sql_queue_manager_destroy ( switch_sql_queue_manager_t **  qmp)

Definition at line 1858 of file switch_core_sqldb.c.

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

Referenced by switch_core_sqldb_stop_thread().

1859 {
1863  uint32_t i;
1864 
1865  switch_assert(qmp);
1866  qm = *qmp;
1867  if (!qm) {
1868  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No SQL queue to destroy.\n");
1869  return SWITCH_STATUS_NOOP;
1870  }
1871 
1872  *qmp = NULL;
1873 
1874  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Destroying SQL queue.\n", qm->name);
1875 
1877 
1878 
1879 
1880  for(i = 0; i < qm->numq; i++) {
1881  do_flush(qm, i, NULL);
1882  }
1883 
1884  pool = qm->pool;
1886 
1887  return status;
1888 }
#define SWITCH_CHANNEL_LOG
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
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.
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.
struct fspr_pool_t switch_memory_pool_t
#define switch_assert(expr)
static void do_flush(switch_sql_queue_manager_t *qm, int i, switch_cache_db_handle_t *dbh)

◆ switch_sql_queue_manager_execute_sql_callback()

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 1700 of file switch_core_sqldb.c.

References new_job(), and switch_thread_pool_launch_thread().

1702 {
1703 
1705  if ((td = new_job(qm, sql, callback, NULL, NULL, NULL, pdata))) {
1707  }
1708 }
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_sql_queue_manager_execute_sql_callback_err()

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 1710 of file switch_core_sqldb.c.

References new_job(), and switch_thread_pool_launch_thread().

1713 {
1714 
1716  if ((td = new_job(qm, sql, callback, err_callback, NULL, NULL, pdata))) {
1718  }
1719 }
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_sql_queue_manager_execute_sql_event_callback()

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 1721 of file switch_core_sqldb.c.

References new_job(), and switch_thread_pool_launch_thread().

1723 {
1724 
1726  if ((td = new_job(qm, sql, NULL, NULL, callback, NULL, pdata))) {
1728  }
1729 }
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_sql_queue_manager_execute_sql_event_callback_err()

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 1731 of file switch_core_sqldb.c.

References new_job(), and switch_thread_pool_launch_thread().

1735 {
1736 
1738  if ((td = new_job(qm, sql, NULL, NULL, callback, err_callback, pdata))) {
1740  }
1741 }
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_sql_queue_manager_init_name()

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 2006 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, switch_cache_db_handle::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().

2013 {
2016  uint32_t i;
2017 
2018  if (!numq) numq = 1;
2019 
2021  qm = switch_core_alloc(pool, sizeof(*qm));
2022 
2023  qm->pool = pool;
2024  qm->numq = numq;
2025  qm->dsn = switch_core_strdup(qm->pool, dsn);
2026  qm->name = switch_core_strdup(qm->pool, name);
2027  qm->max_trans = max_trans;
2028 
2032  switch_thread_cond_create(&qm->cond, qm->pool);
2033 
2034  qm->sql_queue = switch_core_alloc(qm->pool, sizeof(switch_queue_t *) * numq);
2035  qm->written = switch_core_alloc(qm->pool, sizeof(uint32_t) * numq);
2036  qm->pre_written = switch_core_alloc(qm->pool, sizeof(uint32_t) * numq);
2037 
2038  for (i = 0; i < qm->numq; i++) {
2040  }
2041 
2042  if (pre_trans_execute) {
2043  qm->pre_trans_execute = switch_core_strdup(qm->pool, pre_trans_execute);
2044  }
2045  if (post_trans_execute) {
2046  qm->post_trans_execute = switch_core_strdup(qm->pool, post_trans_execute);
2047  }
2048  if (inner_pre_trans_execute) {
2049  qm->inner_pre_trans_execute = switch_core_strdup(qm->pool, inner_pre_trans_execute);
2050  }
2051  if (inner_post_trans_execute) {
2052  qm->inner_post_trans_execute = switch_core_strdup(qm->pool, inner_post_trans_execute);
2053  }
2054 
2055  *qmp = qm;
2056 
2057  return SWITCH_STATUS_SUCCESS;
2058 
2059 }
#define SWITCH_SQL_QUEUE_LEN
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core&#39;s master pool.
Definition: switch_core.h:633
switch_status_t switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool)
Definition: switch_apr.c:373
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
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:684
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:293
switch_thread_cond_t * cond
struct fspr_pool_t switch_memory_pool_t
const char *const name
Definition: switch_cJSON.h:250
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1233

◆ switch_sql_queue_manager_pause()

void switch_sql_queue_manager_pause ( switch_sql_queue_manager_t qm,
switch_bool_t  flush 
)

Definition at line 1773 of file switch_core_sqldb.c.

References do_flush(), switch_sql_queue_manager::mutex, switch_sql_queue_manager::numq, switch_sql_queue_manager::paused, switch_mutex_lock(), and switch_mutex_unlock().

1774 {
1775  uint32_t i;
1776 
1777  switch_mutex_lock(qm->mutex);
1778  qm->paused = 1;
1780 
1781  if (flush) {
1782  for(i = 0; i < qm->numq; i++) {
1783  do_flush(qm, i, NULL);
1784  }
1785  }
1786 
1787 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static void do_flush(switch_sql_queue_manager_t *qm, int i, switch_cache_db_handle_t *dbh)

◆ switch_sql_queue_manager_push()

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 1890 of file switch_core_sqldb.c.

References switch_sql_queue_manager::mutex, switch_sql_queue_manager::numq, qm_wake(), sql_manager, switch_sql_queue_manager::sql_queue, SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypush(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_yield, and switch_sql_queue_manager::thread_running.

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().

1891 {
1892  char *sqlptr = NULL;
1893  switch_status_t status;
1894  int x = 0;
1895 
1896  if (sql_manager.paused || qm->thread_running != 1) {
1898  if (!dup) free((char *)sql);
1899  qm_wake(qm);
1900  return SWITCH_STATUS_SUCCESS;
1901  }
1902 
1903  if (qm->thread_running != 1) {
1904  if (!dup) free((char *)sql);
1905  return SWITCH_STATUS_FALSE;
1906  }
1907 
1908  if (pos > qm->numq - 1) {
1909  pos = 0;
1910  }
1911 
1912  sqlptr = dup ? strdup(sql) : (char *)sql;
1913 
1914  do {
1915  switch_mutex_lock(qm->mutex);
1916  status = switch_queue_trypush(qm->sql_queue[pos], sqlptr);
1918  if (status != SWITCH_STATUS_SUCCESS) {
1919  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Delay %d sending sql\n", x);
1920  if (x++) {
1921  switch_yield(1000000 * x);
1922  }
1923  }
1924  } while(status != SWITCH_STATUS_SUCCESS);
1925 
1926  qm_wake(qm);
1927 
1928  return SWITCH_STATUS_SUCCESS;
1929 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_status_t
Common return values.
static struct @4 sql_manager
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:1279
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_sql_queue_manager_push_confirm()

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 1932 of file switch_core_sqldb.c.

References switch_sql_queue_manager::confirm, dbh, switch_sql_queue_manager::dsn, switch_sql_queue_manager::mutex, switch_sql_queue_manager::numq, switch_sql_queue_manager::pre_written, qm_wake(), sql_manager, switch_sql_queue_manager::sql_queue, 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, switch_yield, switch_sql_queue_manager::thread_running, and switch_sql_queue_manager::written.

1933 {
1934 #define EXEC_NOW
1935 #ifdef EXEC_NOW
1937 
1938  if (sql_manager.paused || qm->thread_running != 1) {
1940  if (!dup) free((char *)sql);
1941  qm_wake(qm);
1942  return SWITCH_STATUS_SUCCESS;
1943  }
1944 
1946  switch_cache_db_execute_sql(dbh, (char *)sql, NULL);
1948  }
1949 
1950  if (!dup) free((char *)sql);
1951 
1952 #else
1953 
1954  int size, x = 0, sanity = 0;
1955  uint32_t written, want;
1956 
1957  if (sql_manager.paused) {
1958  if (!dup) free((char *)sql);
1959  qm_wake(qm);
1960  return SWITCH_STATUS_SUCCESS;
1961  }
1962 
1963  if (qm->thread_running != 1) {
1964  if (!dup) free((char *)sql);
1965  return SWITCH_STATUS_FALSE;
1966  }
1967 
1968  if (pos > qm->numq - 1) {
1969  pos = 0;
1970  }
1971 
1972  switch_mutex_lock(qm->mutex);
1973  qm->confirm++;
1974  switch_queue_push(qm->sql_queue[pos], dup ? strdup(sql) : (char *)sql);
1975  written = qm->pre_written[pos];
1976  size = switch_sql_queue_manager_size(qm, pos);
1977  want = written + size;
1979 
1980  qm_wake(qm);
1981 
1982  while((qm->written[pos] < want) || (qm->written[pos] >= written && want < written && qm->written[pos] > want)) {
1983  switch_yield(5000);
1984 
1985  if (++x == 200) {
1986  qm_wake(qm);
1987  x = 0;
1988  if (++sanity == 20) {
1989  break;
1990  }
1991  }
1992  }
1993 
1994  switch_mutex_lock(qm->mutex);
1995  qm->confirm--;
1997 #endif
1998 
1999  return SWITCH_STATUS_SUCCESS;
2000 }
#define SWITCH_CHANNEL_LOG
#define switch_cache_db_get_db_handle_dsn(_a, _b)
Definition: switch_core.h:2659
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
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:998
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
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 struct @4 sql_manager
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:1253
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_sql_queue_manager_resume()

void switch_sql_queue_manager_resume ( switch_sql_queue_manager_t qm)

Definition at line 1763 of file switch_core_sqldb.c.

References switch_sql_queue_manager::mutex, switch_sql_queue_manager::paused, qm_wake(), switch_mutex_lock(), and switch_mutex_unlock().

1764 {
1765  switch_mutex_lock(qm->mutex);
1766  qm->paused = 0;
1768 
1769  qm_wake(qm);
1770 
1771 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static int qm_wake(switch_sql_queue_manager_t *qm)

◆ switch_sql_queue_manager_size()

int switch_sql_queue_manager_size ( switch_sql_queue_manager_t qm,
uint32_t  index 
)

Definition at line 1789 of file switch_core_sqldb.c.

References switch_sql_queue_manager::mutex, switch_sql_queue_manager::sql_queue, switch_mutex_lock(), switch_mutex_unlock(), and switch_queue_size().

Referenced by switch_sql_queue_manager_push_confirm().

1790 {
1791  int size = 0;
1792 
1793  switch_mutex_lock(qm->mutex);
1794  if (index < qm->numq) {
1795  size = switch_queue_size(qm->sql_queue[index]);
1796  }
1798 
1799  return size;
1800 }
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1238
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
int index
Definition: switch_cJSON.h:160

◆ switch_sql_queue_manager_start()

switch_status_t switch_sql_queue_manager_start ( switch_sql_queue_manager_t qm)

Definition at line 1835 of file switch_core_sqldb.c.

References switch_sql_queue_manager::event_db, switch_sql_queue_manager::name, switch_sql_queue_manager::pool, SWITCH_CHANNEL_LOG, switch_cond_next(), 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(), switch_user_sql_thread(), switch_sql_queue_manager::thread, switch_sql_queue_manager::thread_initiated, and switch_sql_queue_manager::thread_running.

Referenced by switch_core_sqldb_start_thread().

1836 {
1837  switch_threadattr_t *thd_attr;
1838 
1839  if (!qm->thread_running) {
1840  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Starting SQL thread.\n", qm->name);
1841  switch_threadattr_create(&thd_attr, qm->pool);
1845  while (!qm->thread_initiated) {
1846  switch_cond_next();
1847  }
1848 
1849  if (qm->event_db) {
1850  return SWITCH_STATUS_SUCCESS;
1851  }
1852  }
1853  }
1854 
1855  return SWITCH_STATUS_FALSE;
1856 }
#define SWITCH_CHANNEL_LOG
switch_cache_db_handle_t * event_db
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:683
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:584
switch_memory_pool_t * pool
static void *SWITCH_THREAD_FUNC switch_user_sql_thread(switch_thread_t *thread, void *obj)
void switch_cond_next(void)
Definition: switch_time.c:658
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:665
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:698
switch_status_t switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority)
Definition: switch_apr.c:688

◆ switch_sql_queue_manager_stop()

switch_status_t switch_sql_queue_manager_stop ( switch_sql_queue_manager_t qm)

Definition at line 1802 of file switch_core_sqldb.c.

References switch_sql_queue_manager::name, switch_sql_queue_manager::numq, qm_wake(), switch_sql_queue_manager::sql_queue, 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(), switch_yield, switch_sql_queue_manager::thread, and switch_sql_queue_manager::thread_running.

Referenced by switch_sql_queue_manager_destroy().

1803 {
1805  uint32_t i, sanity = 100;
1806 
1807  if (qm->thread_running == 1) {
1808  qm->thread_running = -1;
1809 
1810  while(--sanity && qm->thread_running == -1) {
1811  for(i = 0; i < qm->numq; i++) {
1812  switch_queue_push(qm->sql_queue[i], NULL);
1814  }
1815  qm_wake(qm);
1816 
1817  if (qm->thread_running == -1) {
1818  switch_yield(100000);
1819  }
1820  }
1821  status = SWITCH_STATUS_SUCCESS;
1822  }
1823 
1824  if (qm->thread) {
1825  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Stopping SQL thread.\n", qm->name);
1826  qm_wake(qm);
1827  switch_thread_join(&status, qm->thread);
1828  qm->thread = NULL;
1829  status = SWITCH_STATUS_SUCCESS;
1830  }
1831 
1832  return status;
1833 }
#define SWITCH_CHANNEL_LOG
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1379
switch_status_t
Common return values.
switch_status_t switch_queue_interrupt_all(switch_queue_t *queue)
Definition: switch_apr.c:1269
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:1253
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_stream_spawn()

int switch_stream_spawn ( const char *  cmd,
switch_bool_t  shell,
switch_bool_t  wait,
switch_stream_handle_t stream 
)

Definition at line 3372 of file switch_core.c.

References buffer, memset(), switch_stream_handle::raw_write_function, SWITCH_CHANNEL_LOG, switch_core_get_variable(), SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, switch_safe_free, switch_separate_string(), and zstr.

Referenced by switch_spawn(), switch_stream_system(), and switch_system().

3373 {
3374 #ifndef __linux__
3375  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "posix_spawn is unsupported on current platform\n");
3376  return 1;
3377 #else
3378  int status = 0;
3379  char buffer[1024];
3380  pid_t pid;
3381  char *pdata = NULL, *argv[64];
3382  posix_spawn_file_actions_t action;
3383  posix_spawnattr_t *attr;
3384  int cout_pipe[2];
3385  int cerr_pipe[2];
3386  struct pollfd pfds[2] = { {0} };
3387 
3388  if (zstr(cmd)) {
3389  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to execute switch_spawn_stream because of empty command\n");
3390  return 1;
3391  }
3392 
3393  if (shell) {
3394  argv[0] = switch_core_get_variable("spawn_system_shell");
3395  argv[1] = "-c";
3396  argv[2] = (char *)cmd;
3397  argv[3] = NULL;
3398  if (zstr(argv[0])) {
3399  argv[0] = "/bin/sh";
3400  }
3401  } else {
3402  if (!(pdata = strdup(cmd))) {
3403  return 1;
3404  }
3405  if (!switch_separate_string(pdata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) {
3406  free(pdata);
3407  return 1;
3408  }
3409  }
3410 
3411  if (!(attr = malloc(sizeof(posix_spawnattr_t)))) {
3412  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to execute switch_spawn_stream because of a memory error: %s\n", cmd);
3413  switch_safe_free(pdata);
3414  return 1;
3415  }
3416 
3417  if (stream) {
3418  if (pipe(cout_pipe)) {
3419  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to execute switch_spawn_stream because of a pipe error: %s\n", cmd);
3420  free(attr);
3421  switch_safe_free(pdata);
3422  return 1;
3423  }
3424 
3425  if (pipe(cerr_pipe)) {
3426  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to execute switch_spawn_stream because of a pipe error: %s\n", cmd);
3427  close(cout_pipe[0]);
3428  close(cout_pipe[1]);
3429  free(attr);
3430  switch_safe_free(pdata);
3431  return 1;
3432  }
3433  }
3434 
3435  memset(attr, 0, sizeof(posix_spawnattr_t));
3436  posix_spawnattr_init(attr);
3437  posix_spawnattr_setflags(attr, POSIX_SPAWN_USEVFORK);
3438 
3439  posix_spawn_file_actions_init(&action);
3440 
3441  if (stream) {
3442  posix_spawn_file_actions_addclose(&action, cout_pipe[0]);
3443  posix_spawn_file_actions_addclose(&action, cerr_pipe[0]);
3444  posix_spawn_file_actions_adddup2(&action, cout_pipe[1], 1);
3445  posix_spawn_file_actions_adddup2(&action, cerr_pipe[1], 2);
3446 
3447  posix_spawn_file_actions_addclose(&action, cout_pipe[1]);
3448  posix_spawn_file_actions_addclose(&action, cerr_pipe[1]);
3449  }
3450 
3451  if (posix_spawnp(&pid, argv[0], &action, attr, argv, environ) != 0) {
3452  status = 1;
3453  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to execute posix_spawnp: %s\n", cmd);
3454  if (stream) {
3455  close(cout_pipe[0]), close(cerr_pipe[0]);
3456  close(cout_pipe[1]), close(cerr_pipe[1]);
3457  }
3458  } else {
3459  if (stream) {
3460  close(cout_pipe[1]), close(cerr_pipe[1]); /* close child-side of pipes */
3461 
3462  pfds[0] = (struct pollfd) {
3463  .fd = cout_pipe[0],
3464  .events = POLLIN,
3465  .revents = 0
3466  };
3467 
3468  pfds[1] = (struct pollfd) {
3469  .fd = cerr_pipe[0],
3470  .events = POLLIN,
3471  .revents = 0
3472  };
3473 
3474  while (poll(pfds, 2, /*timeout*/-1) > 0) {
3475  if (pfds[0].revents & POLLIN) {
3476  int bytes_read = read(cout_pipe[0], buffer, sizeof(buffer));
3477  stream->raw_write_function(stream, (unsigned char *)buffer, bytes_read);
3478  } else if (pfds[1].revents & POLLIN) {
3479  int bytes_read = read(cerr_pipe[0], buffer, sizeof(buffer));
3480  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "STDERR of cmd (%s): %.*s\n", cmd, bytes_read, buffer);
3481  } else {
3482  break; /* nothing left to read */
3483  }
3484  }
3485 
3486  close(cout_pipe[0]), close(cerr_pipe[0]);
3487  }
3488 
3489  if (wait) {
3490  if (waitpid(pid, &status, 0) != pid) {
3491  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "waitpid failed: %s\n", cmd);
3492  } else if (status != 0) {
3493  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Exit status (%d): %s\n", status, cmd);
3494  }
3495  }
3496  }
3497 
3498  posix_spawnattr_destroy(attr);
3499  free(attr);
3500  posix_spawn_file_actions_destroy(&action);
3501  switch_safe_free(pdata);
3502 
3503  return status;
3504 #endif
3505 }
#define SWITCH_CHANNEL_LOG
switch_stream_handle_raw_write_function_t raw_write_function
#define zstr(x)
Definition: switch_utils.h:314
unsigned int switch_separate_string(_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen)
Separate a string into an array based on a character delimiter.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
char * buffer
Definition: switch_cJSON.h:153
char * switch_core_get_variable(const char *varname)
Definition: switch_core.c:395
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.
memset(buf, 0, buflen)

◆ switch_stream_system_fork()

int switch_stream_system_fork ( const char *  cmd,
switch_stream_handle_t stream 
)

Definition at line 3363 of file switch_core.c.

References switch_stream_system().

3364 {
3365  return switch_stream_system(cmd, stream);
3366 }
int switch_stream_system(const char *cmd, switch_stream_handle_t *stream)
Definition: switch_core.c:3536

◆ switch_version_full()

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

◆ switch_version_full_human()

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

◆ switch_version_major()

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

◆ switch_version_micro()

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

◆ switch_version_minor()

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

◆ switch_version_revision()

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

◆ switch_version_revision_human()

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