RTS API Documentation  1.10.11
Data Structures | Macros | Functions | Variables
switch_core.c File Reference
#include <switch.h>
#include <switch_ssl.h>
#include <switch_stun.h>
#include <switch_nat.h>
#include "private/switch_apr_pvt.h"
#include "private/switch_core_pvt.h"
#include <switch_curl.h>
#include <switch_msrp.h>
#include <switch_private.h>
#include <errno.h>
#include <sqlite3.h>
#include <xswitch.h>
#include "cc.h"
+ Include dependency graph for switch_core.c:

Go to the source code of this file.

Data Structures

struct  switch_ip_list_t
 
struct  system_thread_handle
 

Macros

#define BUFSIZE   1024
 

Functions

static void switch_load_core_config (const char *file)
 
static void send_heartbeat (void)
 
static void check_ip (void)
 
 SWITCH_STANDARD_SCHED_FUNC (heartbeat_callback)
 
 SWITCH_STANDARD_SCHED_FUNC (check_ip_callback)
 
switch_status_t switch_core_set_console (const char *console)
 Set the output console to the desired file. More...
 
FILE * switch_core_get_console (void)
 Get the output console. More...
 
void switch_core_screen_size (int *x, int *y)
 
FILE * switch_core_data_channel (switch_text_channel_t channel)
 Retrieve a FILE stream of a given text channel name. More...
 
void switch_core_remove_state_handler (const switch_state_handler_table_t *state_handler)
 
int switch_core_add_state_handler (const switch_state_handler_table_t *state_handler)
 
const switch_state_handler_table_tswitch_core_get_state_handler (int index)
 
void switch_core_dump_variables (switch_stream_handle_t *stream)
 
const char * switch_core_get_hostname (void)
 
const char * switch_core_get_switchname (void)
 
char * switch_core_get_domain (switch_bool_t dup)
 
switch_status_t switch_core_get_variables (switch_event_t **event)
 
char * switch_core_get_variable (const char *varname)
 
char * switch_core_get_variable_dup (const char *varname)
 
char * switch_core_get_variable_pdup (const char *varname, switch_memory_pool_t *pool)
 
static void switch_core_unset_variables (void)
 
void switch_core_set_variable (const char *varname, const char *value)
 
switch_bool_t switch_core_set_var_conditional (const char *varname, const char *value, const char *val2)
 
char * switch_core_get_uuid (void)
 Retrieve the unique identifier from the core. More...
 
static void *SWITCH_THREAD_FUNC switch_core_service_thread (switch_thread_t *thread, void *obj)
 
void switch_core_thread_session_end (switch_core_session_t *session)
 
void switch_core_service_session_av (switch_core_session_t *session, switch_bool_t audio, switch_bool_t video)
 
switch_thread_tswitch_core_launch_thread (switch_thread_start_t func, void *obj, switch_memory_pool_t *pool)
 
void switch_core_set_globals (void)
 Initiate Globals. 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_low_priority (void)
 
int32_t set_realtime_priority (void)
 
uint32_t switch_core_cpu_count (void)
 
int32_t set_normal_priority (void)
 Set the maximum priority the process can obtain. More...
 
int32_t set_auto_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...
 
const char * switch_core_mime_ext2type (const char *ext)
 
const char * switch_core_mime_type2ext (const char *mime)
 
switch_hash_index_tswitch_core_mime_index (void)
 
switch_status_t switch_core_mime_add_type (const char *type, const char *ext)
 
static void load_mime_types (void)
 
void switch_core_setrlimits (void)
 
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_load_network_lists (switch_bool_t reload)
 
uint32_t switch_core_max_dtmf_duration (uint32_t duration)
 
uint32_t switch_core_default_dtmf_duration (uint32_t duration)
 
uint32_t switch_core_min_dtmf_duration (uint32_t duration)
 
switch_status_t switch_core_thread_set_cpu_affinity (int cpu)
 
int switch_core_test_flag (int flag)
 
switch_status_t switch_core_init (switch_core_flag_t flags, switch_bool_t console, const char **err)
 
static void handle_SIGHUP (int sig)
 
uint32_t switch_default_ptime (const char *name, uint32_t number)
 
uint32_t switch_default_rate (const char *name, uint32_t number)
 
const char * switch_core_banner (void)
 
switch_status_t switch_core_sqldb_init (const char **err)
 
switch_status_t switch_core_init_and_modload (switch_core_flag_t flags, switch_bool_t console, const char **err)
 
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...
 
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)
 
uint32_t switch_core_max_audio_channels (uint32_t limit)
 
int32_t switch_core_session_ctl (switch_session_ctl_t cmd, void *val)
 send a control message to the core More...
 
switch_core_flag_t switch_core_flags (void)
 return core flags More...
 
switch_bool_t switch_core_running (void)
 
switch_bool_t switch_core_ready (void)
 Determines if the core is ready to take calls. More...
 
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...
 
void switch_core_sqldb_destroy (void)
 
switch_status_t switch_core_destroy (void)
 Destroy the core. 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...
 
void switch_core_memory_reclaim_all (void)
 
static void *SWITCH_THREAD_FUNC system_thread (switch_thread_t *thread, void *obj)
 
static int switch_system_thread (const char *cmd, switch_bool_t wait)
 
int switch_max_file_desc (void)
 
void switch_close_extra_files (int *keep, int keep_ttl)
 
pid_t switch_fork (void)
 
static int switch_system_fork (const char *cmd, switch_bool_t wait)
 
int switch_system (const char *cmd, switch_bool_t wait)
 
int switch_stream_system_fork (const char *cmd, switch_stream_handle_t *stream)
 
int switch_stream_spawn (const char *cmd, switch_bool_t shell, switch_bool_t wait, switch_stream_handle_t *stream)
 
int switch_spawn (const char *cmd, switch_bool_t wait)
 
switch_status_t switch_core_get_stacksizes (switch_size_t *cur, switch_size_t *max)
 
int switch_stream_system (const char *cmd, switch_stream_handle_t *stream)
 
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...
 
const char * switch_core_get_event_channel_key_separator (void)
 

Variables

switch_directories SWITCH_GLOBAL_dirs = { 0 }
 
switch_filenames SWITCH_GLOBAL_filenames = { 0 }
 
struct switch_runtime runtime = { 0 }
 
static char main_ip4 [256] = ""
 
static char main_ip6 [256] = ""
 
static switch_ip_list_t IP_LIST = { 0 }
 
static uint32_t d_30 = 30
 

Macro Definition Documentation

◆ BUFSIZE

#define BUFSIZE   1024

Referenced by switch_core_set_globals().

Function Documentation

◆ check_ip()

static void check_ip ( void  )
static

Definition at line 132 of file switch_core.c.

References switch_runtime::hostname, main_ip4, main_ip6, switch_core_get_variable(), switch_core_set_variable(), switch_event_add_header(), switch_event_add_header_string(), switch_event_create, switch_event_fire, SWITCH_EVENT_TRAP, switch_find_local_ip(), switch_set_string, SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, and zstr.

Referenced by SWITCH_STANDARD_SCHED_FUNC().

133 {
134  char guess_ip4[256] = "";
135  char guess_ip6[256] = "";
136  char old_ip4[256] = "";
137  char old_ip6[256] = "";
138  int ok4 = 1, ok6 = 1;
139  int mask = 0;
140  switch_status_t check6, check4;
141  switch_event_t *event;
142  char *hostname = switch_core_get_variable("hostname");
143 
144  gethostname(runtime.hostname, sizeof(runtime.hostname));
145 
146  if (zstr(hostname)) {
148  } else if (strcmp(hostname, runtime.hostname)) {
150  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "condition", "hostname-change");
151  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "old-hostname", hostname);
153  switch_event_fire(&event);
154  }
155 
157  }
158 
159  check4 = switch_find_local_ip(guess_ip4, sizeof(guess_ip4), &mask, AF_INET);
160  check6 = switch_find_local_ip(guess_ip6, sizeof(guess_ip6), NULL, AF_INET6);
161 
162  if (check6 != SWITCH_STATUS_SUCCESS && (zstr(main_ip6) || !strcasecmp(main_ip6, "::1"))) {
163  check6 = SWITCH_STATUS_SUCCESS;
164  }
165 
166  if (check4 != SWITCH_STATUS_SUCCESS) {
167  ok4 = 2;
168  } else if (!*main_ip4) {
169  switch_set_string(main_ip4, guess_ip4);
170  } else {
171  if (!(ok4 = !strcmp(main_ip4, guess_ip4))) {
172  struct in_addr in;
173 
174  in.s_addr = mask;
175  switch_set_string(old_ip4, main_ip4);
176  switch_set_string(main_ip4, guess_ip4);
177  switch_core_set_variable("local_ip_v4", guess_ip4);
178  switch_core_set_variable("local_mask_v4", inet_ntoa(in));
179  }
180  }
181 
182  if (check6 != SWITCH_STATUS_SUCCESS) {
183  ok6 = 2;
184  } else if (!*main_ip6) {
185  switch_set_string(main_ip6, guess_ip6);
186  } else {
187  if (!(ok6 = !strcmp(main_ip6, guess_ip6))) {
188  switch_set_string(old_ip6, main_ip6);
189  switch_set_string(main_ip6, guess_ip6);
190  switch_core_set_variable("local_ip_v6", guess_ip6);
191  }
192  }
193 
194  if (!ok4 || !ok6) {
196  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "condition", "network-address-change");
197  if (!ok4) {
198  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-previous-v4", old_ip4);
199  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-change-v4", main_ip4);
200  }
201  if (!ok6) {
202  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-previous-v6", old_ip6);
203  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-change-v6", main_ip6);
204  }
205  switch_event_fire(&event);
206  }
207  }
208 
209  if (ok4 == 2 || ok6 == 2) {
211  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "condition", "network-outage");
212 
213  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-status-v4", ok4 == 2 ? "disconnected" : "active");
214  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-v4", main_ip4);
215 
216  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-status-v6", ok6 == 2 ? "disconnected" : "active");
217  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-v6", main_ip6);
218 
219  switch_event_fire(&event);
220  }
221  }
222 
223 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
char hostname[256]
struct switch_runtime runtime
Definition: switch_core.c:86
#define zstr(x)
Definition: switch_utils.h:314
switch_byte_t in
static char main_ip6[256]
Definition: switch_core.c:130
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
void switch_core_set_variable(const char *varname, const char *value)
Definition: switch_core.c:442
static char main_ip4[256]
Definition: switch_core.c:129
switch_status_t
Common return values.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
#define switch_set_string(_dst, _src)
Definition: switch_utils.h:734
char * switch_core_get_variable(const char *varname)
Definition: switch_core.c:395
switch_status_t switch_find_local_ip(_Out_opt_bytecapcount_(len) char *buf, _In_ int len, _In_opt_ int *mask, _In_ int family)
find local ip of the box

◆ handle_SIGHUP()

static void handle_SIGHUP ( int  sig)
static

Definition at line 2008 of file switch_core.c.

References switch_event_add_header(), switch_event_create, switch_event_fire, SWITCH_EVENT_TRAP, SWITCH_STACK_BOTTOM, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_session_ctl(), and switch_core_set_signal_handlers().

2009 {
2010  if (sig) {
2011  switch_event_t *event;
2012 
2014  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Trapped-Signal", "HUP");
2015  switch_event_fire(&event);
2016  }
2017  }
2018  return;
2019 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384

◆ load_mime_types()

static void load_mime_types ( void  )
static

Definition at line 1272 of file switch_core.c.

References switch_directories::conf_dir, switch_assert, switch_core_mime_add_type(), switch_fp_read_dline(), SWITCH_GLOBAL_dirs, switch_mprintf(), and switch_safe_free.

Referenced by switch_core_init().

1273 {
1274  char *cf = "mime.types";
1275  FILE *fd = NULL;
1276  char *line_buf = NULL;
1277  switch_size_t llen = 0;
1278  char *mime_path = NULL;
1279 
1280  mime_path = switch_mprintf("%s/%s", SWITCH_GLOBAL_dirs.conf_dir, cf);
1281  switch_assert(mime_path);
1282 
1283  fd = fopen(mime_path, "rb");
1284 
1285  if (fd == NULL) {
1286  goto end;
1287  }
1288 
1289  while ((switch_fp_read_dline(fd, &line_buf, &llen))) {
1290  char *p;
1291  char *type = line_buf;
1292 
1293  if (*line_buf == '#') {
1294  continue;
1295  }
1296 
1297  if ((p = strchr(line_buf, '\r')) || (p = strchr(line_buf, '\n'))) {
1298  *p = '\0';
1299  }
1300 
1301  if ((p = strchr(type, '\t')) || (p = strchr(type, ' '))) {
1302  *p++ = '\0';
1303 
1304  while (*p == ' ' || *p == '\t') {
1305  p++;
1306  }
1307 
1308  switch_core_mime_add_type(type, p);
1309  }
1310 
1311  }
1312 
1313  switch_safe_free(line_buf);
1314  fclose(fd);
1315 
1316  end:
1317 
1318  switch_safe_free(mime_path);
1319 
1320 }
switch_status_t switch_core_mime_add_type(const char *type, const char *ext)
Definition: switch_core.c:1232
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
uintptr_t switch_size_t
switch_size_t switch_fp_read_dline(FILE *fd, char **buf, switch_size_t *len)
Definition: switch_utils.c:892
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:82
#define switch_assert(expr)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)

◆ send_heartbeat()

static void send_heartbeat ( void  )
static

Definition at line 89 of file switch_core.c.

References switch_core_time_duration::day, switch_core_time_duration::hr, switch_core_time_duration::min, switch_core_time_duration::mms, switch_core_time_duration::ms, switch_core_time_duration::sec, switch_runtime::sessions_peak, switch_runtime::sessions_peak_fivemin, switch_runtime::sps, switch_runtime::sps_last, switch_runtime::sps_peak, switch_runtime::sps_peak_fivemin, switch_core_idle_cpu(), switch_core_measure_time(), switch_core_session_count(), switch_core_session_id(), switch_core_session_limit(), switch_core_uptime(), switch_event_add_header(), switch_event_create, switch_event_fire, SWITCH_EVENT_HEARTBEAT, SWITCH_SIZE_T_FMT, SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, SWITCH_TIME_T_FMT, switch_version_full(), and switch_core_time_duration::yr.

Referenced by SWITCH_STANDARD_SCHED_FUNC().

90 {
91  switch_event_t *event;
93 
95 
97  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Info", "System Ready");
99  "%u year%s, "
100  "%u day%s, "
101  "%u hour%s, "
102  "%u minute%s, "
103  "%u second%s, "
104  "%u millisecond%s, "
105  "%u microsecond%s",
106  duration.yr, duration.yr == 1 ? "" : "s",
107  duration.day, duration.day == 1 ? "" : "s",
108  duration.hr, duration.hr == 1 ? "" : "s",
109  duration.min, duration.min == 1 ? "" : "s",
110  duration.sec, duration.sec == 1 ? "" : "s",
111  duration.ms, duration.ms == 1 ? "" : "s", duration.mms, duration.mms == 1 ? "" : "s");
112 
113  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FreeSWITCH-Version", "%s", switch_version_full());
117  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Per-Sec", "%u", runtime.sps);
118  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Per-Sec-Last", "%u", runtime.sps_last);
119  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Per-Sec-Max", "%u", runtime.sps_peak);
120  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Per-Sec-FiveMin", "%u", runtime.sps_peak_fivemin);
121  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Since-Startup", "%" SWITCH_SIZE_T_FMT, switch_core_session_id() - 1);
122  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Peak-Max", "%u", runtime.sessions_peak);
123  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Session-Peak-FiveMin", "%u", runtime.sessions_peak_fivemin);
125  switch_event_fire(&event);
126  }
127 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
switch_time_t switch_core_uptime(void)
Number of microseconds the system has been up.
Definition: switch_core.c:2552
const char * switch_version_full(void)
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
struct switch_runtime runtime
Definition: switch_core.c:86
switch_size_t switch_core_session_id(void)
Provide the current session_id.
double switch_core_idle_cpu(void)
int32_t sessions_peak_fivemin
#define SWITCH_TIME_T_FMT
uint32_t switch_core_session_count(void)
Provide the total number of sessions.
uint32_t switch_core_session_limit(_In_ uint32_t new_limit)
Set/Get Session Limit.
#define SWITCH_SIZE_T_FMT
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
int32_t sps_peak_fivemin
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.
Definition: switch_core.c:2535

◆ 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_state_handler()

int switch_core_add_state_handler ( const switch_state_handler_table_t state_handler)

Definition at line 317 of file switch_core.c.

References switch_runtime::global_mutex, index, switch_runtime::state_handler_index, switch_runtime::state_handlers, SWITCH_MAX_STATE_HANDLERS, switch_mutex_lock(), and switch_mutex_unlock().

318 {
319  int index;
320 
323 
324  if (index > (SWITCH_MAX_STATE_HANDLERS - 1)) {
325  index = -1;
326  } else {
327  runtime.state_handlers[index] = state_handler;
329  }
330 
332  return index;
333 }
const switch_state_handler_table_t * state_handlers[SWITCH_MAX_STATE_HANDLERS]
#define SWITCH_MAX_STATE_HANDLERS
Definition: switch_types.h:592
struct switch_runtime runtime
Definition: switch_core.c:86
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_mutex_t * global_mutex

◆ 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_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_dump_variables()

void switch_core_dump_variables ( switch_stream_handle_t stream)

Definition at line 345 of file switch_core.c.

References switch_runtime::global_mutex, switch_runtime::global_vars, switch_event::headers, switch_event_header::name, switch_event_header::next, switch_mutex_lock(), switch_mutex_unlock(), switch_event_header::value, and switch_stream_handle::write_function.

346 {
348 
350  for (hi = runtime.global_vars->headers; hi; hi = hi->next) {
351  stream->write_function(stream, "%s=%s\n", hi->name, hi->value);
352  }
354 }
An event Header.
Definition: switch_event.h:65
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:86
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_mutex_t * global_mutex
switch_stream_handle_write_function_t write_function
struct switch_event_header * next
Definition: switch_event.h:76
switch_event_header_t * headers
Definition: switch_event.h:90

◆ 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_get_state_handler()

const switch_state_handler_table_t* switch_core_get_state_handler ( int  index)

Definition at line 335 of file switch_core.c.

References index, switch_runtime::state_handler_index, switch_runtime::state_handlers, and SWITCH_MAX_STATE_HANDLERS.

336 {
337 
339  return NULL;
340  }
341 
342  return runtime.state_handlers[index];
343 }
const switch_state_handler_table_t * state_handlers[SWITCH_MAX_STATE_HANDLERS]
#define SWITCH_MAX_STATE_HANDLERS
Definition: switch_types.h:592
struct switch_runtime runtime
Definition: switch_core.c:86
int index
Definition: switch_cJSON.h:160

◆ switch_core_get_variable()

char* switch_core_get_variable ( const char *  varname)

Definition at line 395 of file switch_core.c.

References switch_runtime::global_var_rwlock, switch_runtime::global_vars, switch_event_get_header, switch_thread_rwlock_rdlock(), and switch_thread_rwlock_unlock().

Referenced by check_ip(), switch_core_get_domain(), switch_stream_spawn(), switch_stream_system(), and switch_system().

396 {
397  char *val;
399  val = (char *) switch_event_get_header(runtime.global_vars, varname);
401  return val;
402 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:86
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:250
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172

◆ switch_core_get_variable_dup()

char* switch_core_get_variable_dup ( const char *  varname)

Definition at line 404 of file switch_core.c.

References switch_runtime::global_var_rwlock, switch_runtime::global_vars, switch_event_get_header, switch_thread_rwlock_rdlock(), and switch_thread_rwlock_unlock().

Referenced by switch_core_init_and_modload().

405 {
406  char *val = NULL, *v;
407 
408  if (varname) {
410  if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
411  val = strdup(v);
412  }
414  }
415 
416  return val;
417 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:86
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:250
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172

◆ switch_core_get_variable_pdup()

char* switch_core_get_variable_pdup ( const char *  varname,
switch_memory_pool_t pool 
)

Definition at line 419 of file switch_core.c.

References switch_runtime::global_var_rwlock, switch_runtime::global_vars, switch_core_strdup, switch_event_get_header, switch_thread_rwlock_rdlock(), and switch_thread_rwlock_unlock().

420 {
421  char *val = NULL, *v;
422 
423  if (varname) {
425  if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
426  val = switch_core_strdup(pool, v);
427  }
429  }
430 
431  return val;
432 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
#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_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:86
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:250
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172

◆ switch_core_init()

switch_status_t switch_core_init ( switch_core_flag_t  flags,
switch_bool_t  console,
const char **  err 
)

Definition at line 1798 of file switch_core.c.

References switch_directories::base_dir, switch_frame::buflen, switch_directories::cache_dir, switch_directories::certs_dir, switch_runtime::colorize_console, switch_directories::conf_dir, switch_runtime::console, switch_runtime::cpu_count, switch_frame::data, switch_directories::data_dir, switch_frame::datalen, switch_directories::db_dir, switch_runtime::db_handle_timeout, switch_runtime::dbname, DBTYPE_DEFAULT, switch_runtime::default_dtmf_duration, switch_runtime::dummy_cng_frame, switch_runtime::dummy_data, switch_runtime::event_heartbeat_interval, switch_runtime::flags, switch_directories::fonts_dir, switch_runtime::global_mutex, switch_runtime::global_var_rwlock, switch_runtime::global_vars, switch_directories::grammar_dir, switch_runtime::hard_log_level, switch_runtime::hostname, switch_directories::htdocs_dir, switch_directories::images_dir, switch_runtime::initiated, load_mime_types(), switch_directories::localstate_dir, switch_directories::log_dir, switch_runtime::mailer_app, switch_runtime::mailer_app_args, switch_runtime::max_db_handles, switch_runtime::max_dtmf_duration, switch_runtime::memory_pool, memset(), switch_runtime::microseconds_per_tick, switch_runtime::mime_type_exts, switch_runtime::mime_types, switch_runtime::min_dtmf_duration, switch_directories::mod_dir, switch_runtime::odbc_dbtype, switch_runtime::ptimes, switch_directories::recordings_dir, switch_directories::run_dir, switch_runtime::runlevel, switch_runtime::running, SCF_API_EXPANSION, SCF_AUTO_SCHEMAS, SCF_CLEAR_SQL, SCF_LOG_DISABLE, SCF_MINIMAL, SCF_NO_NEW_SESSIONS, SCF_SESSION_THREAD_POOL, SCF_THREADED_SYSTEM_EXEC, SCF_USE_AUTO_NAT, SCF_USE_NAT_MAPPING, switch_directories::script_dir, switch_runtime::session_hash_mutex, SFF_CNG, switch_runtime::shutdown_cause, switch_directories::sounds_dir, switch_runtime::sps_total, SSHF_NO_DEL, SSHF_NONE, SSHF_OWN_THREAD, switch_directories::storage_dir, switch_assert, SWITCH_CAUSE_SYSTEM_SHUTDOWN, switch_channel_global_init(), SWITCH_CHANNEL_LOG, switch_console_init(), switch_core_hash_init_case(), switch_core_media_init(), switch_core_memory_init(), switch_core_session_init(), switch_core_set_globals(), switch_core_set_variable(), switch_core_state_machine_init(), switch_curl_init(), SWITCH_DEFAULT_DIR_PERMS, SWITCH_DEFAULT_DTMF_DURATION, switch_dir_make_recursive(), switch_epoch_time_now(), SWITCH_EVENT_CHANNEL_DATA, switch_event_create_plain(), switch_event_init(), SWITCH_FALSE, switch_find_local_ip(), SWITCH_GLOBAL_dirs, switch_load_core_config(), SWITCH_LOG_DEBUG, SWITCH_LOG_DEBUG1, SWITCH_LOG_DISABLE, switch_log_init(), switch_log_printf(), SWITCH_MAX_DTMF_DURATION, SWITCH_MIN_DTMF_DURATION, switch_mono_micro_time_now(), switch_mutex_init(), SWITCH_MUTEX_NESTED, switch_nat_init(), switch_nat_late_init(), switch_rtp_init(), switch_scheduler_add_task(), switch_scheduler_task_thread_start(), switch_set_flag, switch_ssl_init_ssl_locks(), SWITCH_STATUS_MEMERR, SWITCH_STATUS_SUCCESS, switch_test_flag, switch_thread_rwlock_create(), switch_uuid_format(), switch_uuid_get(), switch_xml_init(), switch_directories::temp_dir, switch_runtime::throttle_mutex, switch_runtime::timer_affinity, switch_runtime::tipping_point, switch_runtime::uuid_mutex, and switch_runtime::uuid_str.

Referenced by switch_core_init_and_modload().

1799 {
1800  switch_uuid_t uuid;
1801  char guess_ip[256];
1802  int mask = 0;
1803  struct in_addr in;
1804 
1805 
1806  if (runtime.runlevel > 0) {
1807  /* one per customer */
1808  return SWITCH_STATUS_SUCCESS;
1809  }
1810 
1811  memset(&runtime, 0, sizeof(runtime));
1812  gethostname(runtime.hostname, sizeof(runtime.hostname));
1813 
1815  runtime.max_db_handles = 50;
1816  runtime.db_handle_timeout = 5000000;
1818 
1819  runtime.runlevel++;
1823  runtime.dbname = "core";
1829 #ifdef WIN32
1831 #endif
1833  if (flags & SCF_LOG_DISABLE) {
1835  flags &= ~SCF_LOG_DISABLE;
1836  } else {
1838  }
1839  runtime.mailer_app = "sendmail";
1840  runtime.mailer_app_args = "-t";
1845  runtime.dbname = NULL;
1846 #ifndef WIN32
1847  runtime.cpu_count = sysconf (_SC_NPROCESSORS_ONLN);
1848 #else
1849  {
1850  SYSTEM_INFO sysinfo;
1851  GetSystemInfo( &sysinfo );
1852  runtime.cpu_count = sysinfo.dwNumberOfProcessors;
1853  }
1854 #endif
1855 
1856  if (!runtime.cpu_count) runtime.cpu_count = 1;
1857 
1858  if (sqlite3_initialize() != SQLITE_OK) {
1859  *err = "FATAL ERROR! Could not initialize SQLite\n";
1860  return SWITCH_STATUS_MEMERR;
1861  }
1862 
1863  /* INIT APR and Create the pool context */
1864  if (fspr_initialize() != SWITCH_STATUS_SUCCESS) {
1865  *err = "FATAL ERROR! Could not initialize APR\n";
1866  return SWITCH_STATUS_MEMERR;
1867  }
1868 
1870  *err = "FATAL ERROR! Could not allocate memory pool\n";
1871  return SWITCH_STATUS_MEMERR;
1872  }
1874 
1890 
1892 
1894 
1897 
1905  load_mime_types();
1906  runtime.flags |= flags;
1907  runtime.sps_total = 30;
1908 
1909  *err = NULL;
1910 
1911  if (console) {
1912  runtime.console = stdout;
1913  }
1914 
1915  SSL_library_init();
1917  OpenSSL_add_all_algorithms();
1918  switch_curl_init();
1919 
1921  switch_find_local_ip(guess_ip, sizeof(guess_ip), &mask, AF_INET);
1922  switch_core_set_variable("local_ip_v4", guess_ip);
1923  in.s_addr = mask;
1924  switch_core_set_variable("local_mask_v4", inet_ntoa(in));
1925 
1926 
1927  switch_find_local_ip(guess_ip, sizeof(guess_ip), NULL, AF_INET6);
1928  switch_core_set_variable("local_ip_v6", guess_ip);
1952 
1954  /* allow missing configuration if MINIMAL */
1955  if (!(flags & SCF_MINIMAL)) {
1956  fspr_terminate();
1957  return SWITCH_STATUS_MEMERR;
1958  }
1959  }
1960 
1963  }
1964 
1966 
1967  runtime.tipping_point = 0;
1968  runtime.timer_affinity = -1;
1970 
1971  if (flags & SCF_MINIMAL) return SWITCH_STATUS_SUCCESS;
1972 
1973  switch_load_core_config("switch.conf");
1974 
1976 
1979 
1981 
1983 
1984  runtime.running = 1;
1986 
1987  switch_scheduler_add_task(switch_epoch_time_now(NULL), heartbeat_callback, "heartbeat", "core", 0, NULL, SSHF_NONE | SSHF_NO_DEL);
1988 
1989  switch_scheduler_add_task(switch_epoch_time_now(NULL), check_ip_callback, "check_ip", "core", 0, NULL, SSHF_NONE | SSHF_NO_DEL | SSHF_OWN_THREAD);
1990 
1991  switch_uuid_get(&uuid);
1994 
1995 
1996  return SWITCH_STATUS_SUCCESS;
1997 }
switch_memory_pool_t * switch_core_memory_init(void)
uint32_t min_dtmf_duration
switch_frame_t dummy_cng_frame
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
switch_time_t initiated
void switch_ssl_init_ssl_locks(void)
int32_t timer_affinity
void switch_scheduler_task_thread_start(void)
Start the scheduler system.
void switch_core_set_globals(void)
Initiate Globals.
Definition: switch_core.c:633
void switch_core_session_init(switch_memory_pool_t *pool)
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
char hostname[256]
switch_mutex_t * throttle_mutex
#define SWITCH_DEFAULT_DTMF_DURATION
Definition: switch_types.h:116
switch_call_cause_t shutdown_cause
static void switch_load_core_config(const char *file)
Definition: switch_core.c:2049
uint32_t microseconds_per_tick
struct switch_runtime runtime
Definition: switch_core.c:86
uint32_t switch_scheduler_add_task(time_t task_runtime, switch_scheduler_func_t func, const char *desc, const char *group, uint32_t cmd_id, void *cmd_arg, switch_scheduler_flag_t flags)
Schedule a task in the future.
void switch_rtp_init(switch_memory_pool_t *pool)
Initilize the RTP System.
Definition: switch_rtp.c:1522
switch_status_t switch_event_init(switch_memory_pool_t *pool)
Start the eventing system.
Definition: switch_event.c:692
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
switch_hash_t * ptimes
void switch_channel_global_init(switch_memory_pool_t *pool)
switch_dbtype_t odbc_dbtype
void switch_nat_init(switch_memory_pool_t *pool, switch_bool_t mapping)
Initilize the NAT Traversal System.
Definition: switch_nat.c:399
uint32_t buflen
Definition: switch_frame.h:70
switch_bool_t colorize_console
uint32_t datalen
Definition: switch_frame.h:68
switch_byte_t in
#define SWITCH_MAX_DTMF_DURATION
Definition: switch_types.h:119
static void load_mime_types(void)
Definition: switch_core.c:1272
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
switch_status_t switch_console_init(switch_memory_pool_t *pool)
switch_hash_t * mime_type_exts
uint32_t event_heartbeat_interval
void switch_core_set_variable(const char *varname, const char *value)
Definition: switch_core.c:442
uint32_t db_handle_timeout
switch_mutex_t * session_hash_mutex
void switch_nat_late_init(void)
Initilize the rest of the NAT Traversal System.
Definition: switch_nat.c:708
static switch_status_t switch_event_create_plain(switch_event_t **event, switch_event_types_t event_id)
Definition: switch_event.h:386
switch_mutex_t * global_mutex
switch_hash_t * mime_types
#define SWITCH_DEFAULT_DIR_PERMS
Definition: switch_types.h:120
uint32_t max_dtmf_duration
void switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
Definition: switch_apr.c:1140
#define SWITCH_MIN_DTMF_DURATION
Definition: switch_types.h:118
switch_status_t switch_dir_make_recursive(const char *path, switch_fileperms_t perm, switch_memory_pool_t *pool)
Definition: switch_apr.c:551
switch_status_t switch_core_hash_init_case(_Out_ switch_hash_t **hash, switch_bool_t case_sensitive)
Initialize a hash table.
switch_log_level_t hard_log_level
uint32_t default_dtmf_duration
uint32_t tipping_point
void switch_uuid_get(switch_uuid_t *uuid)
Definition: switch_apr.c:1152
uint32_t max_db_handles
switch_time_t switch_mono_micro_time_now(void)
Definition: switch_time.c:316
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:82
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:322
switch_mutex_t * uuid_mutex
switch_status_t switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock, switch_memory_pool_t *pool)
Definition: switch_apr.c:235
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
switch_memory_pool_t * memory_pool
switch_status_t switch_log_init(_In_ switch_memory_pool_t *pool, _In_ switch_bool_t colorize)
Initilize the logging engine.
switch_status_t switch_find_local_ip(_Out_opt_bytecapcount_(len) char *buf, _In_ int len, _In_opt_ int *mask, _In_ int family)
find local ip of the box
void switch_core_media_init(void)
void switch_curl_init(void)
Definition: switch_curl.c:51
#define switch_assert(expr)
void switch_core_state_machine_init(switch_memory_pool_t *pool)
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1]
memset(buf, 0, buflen)
switch_status_t switch_xml_init(_In_ switch_memory_pool_t *pool, _Out_ const char **err)
initilize the core XML backend

◆ switch_core_init_and_modload()

switch_status_t switch_core_init_and_modload ( switch_core_flag_t  flags,
switch_bool_t  console,
const char **  err 
)

Definition at line 2443 of file switch_core.c.

References cc, cc_s, switch_stream_handle::data, switch_runtime::events_use_dispatch, switch_runtime::runlevel, SCF_NO_NEW_SESSIONS, SCF_USE_SQL, SWITCH_CHANNEL_LOG, switch_clear_flag, switch_console_execute(), switch_core_banner(), switch_core_get_variable_dup(), switch_core_init(), switch_core_screen_size(), switch_core_session_limit(), switch_core_sessions_per_second(), switch_core_set_signal_handlers(), switch_event_add_header(), switch_event_create, switch_event_fire, SWITCH_EVENT_STARTUP, SWITCH_FALSE, switch_load_core_config(), switch_load_network_lists(), switch_loadable_module_init(), SWITCH_LOG_CONSOLE, SWITCH_LOG_INFO, switch_log_printf(), switch_msrp_init(), SWITCH_SEQ_BBLUE, SWITCH_SEQ_DEFAULT_COLOR, SWITCH_SEQ_FYELLOW, SWITCH_STACK_BOTTOM, SWITCH_STANDARD_STREAM, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_test_flag, SWITCH_TRUE, switch_version_full(), and switch_version_revision_human().

2444 {
2445  switch_event_t *event;
2446  char *cmd;
2447  int x = 0;
2448  const char *use = NULL;
2449 #include "cc.h"
2450 
2451 
2452  if (switch_core_init(flags, console, err) != SWITCH_STATUS_SUCCESS) {
2453  return SWITCH_STATUS_GENERR;
2454  }
2455 
2456  if (runtime.runlevel > 1) {
2457  /* one per customer */
2458  return SWITCH_STATUS_SUCCESS;
2459  }
2460 
2461  runtime.runlevel++;
2463 
2466 
2467  switch_msrp_init();
2468 
2469  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Bringing up environment.\n");
2472  *err = "Cannot load modules";
2474  return SWITCH_STATUS_GENERR;
2475  }
2476 
2478 
2479  switch_load_core_config("post_load_switch.conf");
2480 
2482 
2484  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Info", "System Ready");
2485  switch_event_fire(&event);
2486  }
2487 
2488  switch_core_screen_size(&x, NULL);
2489 
2490  use = (x > 100) ? cc : cc_s;
2491 
2492 #ifdef WIN32
2494 #else
2500 
2501 #endif
2502 
2503 
2505  "\nFreeSWITCH Version %s (%s)\n\nFreeSWITCH Started\nMax Sessions [%u]\nSession Rate [%d]\nSQL [%s]\n",
2508  switch_core_sessions_per_second(0), switch_test_flag((&runtime), SCF_USE_SQL) ? "Enabled" : "Disabled");
2509 
2510 
2511  if (x < 160) {
2512  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\n[This app Best viewed at 160x60 or more..]\n");
2513  }
2514 
2516 
2517  if ((cmd = switch_core_get_variable_dup("api_on_startup"))) {
2518  switch_stream_handle_t stream = { 0 };
2519  SWITCH_STANDARD_STREAM(stream);
2520  switch_console_execute(cmd, 0, &stream);
2521  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Startup command [%s] executed. Output:\n%s\n", cmd, (char *)stream.data);
2522  free(stream.data);
2523  free(cmd);
2524  }
2525 
2526 #ifdef HAVE_SYSTEMD
2527  sd_notifyf(0, "READY=1\n"
2528  "MAINPID=%lu\n", (unsigned long) getpid());
2529 #endif
2530 
2531  return SWITCH_STATUS_SUCCESS;
2532 
2533 }
void switch_core_set_signal_handlers(void)
Definition: switch_core.c:2579
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
#define SWITCH_CHANNEL_LOG
uint32_t switch_core_sessions_per_second(_In_ uint32_t new_limit)
Set/Get Session Rate Limit.
const char * switch_version_full(void)
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
const char * cc
Definition: cc.h:2
const char * cc_s
Definition: cc.h:3
static void switch_load_core_config(const char *file)
Definition: switch_core.c:2049
struct switch_runtime runtime
Definition: switch_core.c:86
#define SWITCH_SEQ_FYELLOW
Definition: switch_types.h:95
switch_status_t switch_msrp_init(void)
Definition: switch_msrp.c:294
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:724
#define SWITCH_STANDARD_STREAM(s)
uint32_t switch_core_session_limit(_In_ uint32_t new_limit)
Set/Get Session Limit.
#define SWITCH_SEQ_DEFAULT_COLOR
Definition: switch_types.h:70
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
const char * switch_core_banner(void)
Definition: switch_core.c:2406
switch_status_t switch_core_init(switch_core_flag_t flags, switch_bool_t console, const char **err)
Definition: switch_core.c:1798
#define SWITCH_SEQ_BBLUE
Definition: switch_types.h:104
switch_status_t switch_loadable_module_init(switch_bool_t autoload)
Initilize the module backend and load all the modules.
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_console_execute(char *xcmd, int rec, switch_stream_handle_t *istream)
void switch_load_network_lists(switch_bool_t reload)
Definition: switch_core.c:1452
char * switch_core_get_variable_dup(const char *varname)
Definition: switch_core.c:404
const char * switch_version_revision_human(void)
void switch_core_screen_size(int *x, int *y)
Definition: switch_core.c:261

◆ switch_core_launch_thread()

switch_thread_t* switch_core_launch_thread ( switch_thread_start_t  func,
void *  obj,
switch_memory_pool_t pool 
)

Definition at line 601 of file switch_core.c.

References switch_core_thread_session::objs, pool, switch_core_thread_session::pool, SWITCH_CHANNEL_LOG, switch_core_alloc, switch_core_new_memory_pool, SWITCH_LOG_CRIT, switch_log_printf(), SWITCH_PRI_REALTIME, SWITCH_STATUS_SUCCESS, switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_priority_set(), switch_threadattr_stacksize_set(), and thread.

602 {
603  switch_thread_t *thread = NULL;
604  switch_threadattr_t *thd_attr = NULL;
606  int mypool;
607 
608  mypool = pool ? 0 : 1;
609 
611  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate memory pool\n");
612  return NULL;
613  }
614 
615  switch_threadattr_create(&thd_attr, pool);
616 
617  if ((ts = switch_core_alloc(pool, sizeof(*ts))) == 0) {
618  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate memory\n");
619  } else {
620  if (mypool) {
621  ts->pool = pool;
622  }
623  ts->objs[0] = obj;
624  ts->objs[1] = thread;
627  switch_thread_create(&thread, thd_attr, func, ts, pool);
628  }
629 
630  return thread;
631 }
#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
#define SWITCH_CHANNEL_LOG
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 switch_thread_t * thread
Definition: switch_log.c:486
switch_memory_pool_t * pool
Definition: switch_core.h:225
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:584
void * objs[SWITCH_MAX_CORE_THREAD_SESSION_OBJS]
Definition: switch_core.h:222
A generic object to pass as a thread&#39;s session object to allow mutiple arguements and a pool...
Definition: switch_core.h:216
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_thread_t switch_thread_t
Definition: switch_apr.h:941
switch_status_t switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority)
Definition: switch_apr.c:688

◆ 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_remove_state_handler()

void switch_core_remove_state_handler ( const switch_state_handler_table_t state_handler)

Definition at line 292 of file switch_core.c.

References cur, switch_runtime::global_mutex, index, switch_runtime::state_handler_index, switch_runtime::state_handlers, SWITCH_MAX_STATE_HANDLERS, switch_mutex_lock(), and switch_mutex_unlock().

293 {
294  int index, tmp_index = 0;
296 
298 
299  for (index = 0; index < runtime.state_handler_index; index++) {
301  runtime.state_handlers[index] = NULL;
302  if (cur == state_handler) {
303  continue;
304  }
305  tmp[tmp_index++] = cur;
306  }
307 
309 
310  for (index = 0; index < tmp_index; index++) {
312  }
314 }
const switch_state_handler_table_t * state_handlers[SWITCH_MAX_STATE_HANDLERS]
pack cur
#define SWITCH_MAX_STATE_HANDLERS
Definition: switch_types.h:592
struct switch_runtime runtime
Definition: switch_core.c:86
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_mutex_t * global_mutex

◆ switch_core_service_session_av()

void switch_core_service_session_av ( switch_core_session_t session,
switch_bool_t  audio,
switch_bool_t  video 
)

Definition at line 573 of file switch_core.c.

References CF_SERVICE_AUDIO, CF_SERVICE_VIDEO, switch_assert, switch_channel_set_flag, switch_core_service_thread(), switch_core_session_get_channel(), and switch_core_session_launch_thread().

574 {
575  switch_channel_t *channel;
576  switch_assert(session);
577 
578  channel = switch_core_session_get_channel(session);
579  switch_assert(channel);
580 
581  if (audio) switch_channel_set_flag(channel, CF_SERVICE_AUDIO);
582  if (video) switch_channel_set_flag(channel, CF_SERVICE_VIDEO);
583 
584  switch_core_session_launch_thread(session, (void *(*)(switch_thread_t *,void *))switch_core_service_thread, session);
585 }
_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.
static void *SWITCH_THREAD_FUNC switch_core_service_thread(switch_thread_t *thread, void *obj)
Definition: switch_core.c:501
#define switch_channel_set_flag(_c, _f)
#define switch_assert(expr)
struct fspr_thread_t switch_thread_t
Definition: switch_apr.h:941
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.

◆ switch_core_service_thread()

static void* SWITCH_THREAD_FUNC switch_core_service_thread ( switch_thread_t thread,
void *  obj 
)
static

Definition at line 501 of file switch_core.c.

References CF_SERVICE, CF_SERVICE_AUDIO, CF_SERVICE_VIDEO, CF_VIDEO, switch_core_session::frame_read_mutex, switch_channel_clear_flag(), switch_channel_set_flag, switch_channel_test_flag(), switch_core_session_get_channel(), switch_core_session_read_frame(), switch_core_session_read_lock(), switch_core_session_read_video_frame(), switch_core_session_rwunlock(), SWITCH_IO_FLAG_NONE, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_BREAK, SWITCH_STATUS_SUCCESS, and SWITCH_STATUS_TIMEOUT.

Referenced by switch_core_service_session_av().

502 {
503  switch_core_session_t *session = obj;
504  switch_channel_t *channel;
505  switch_frame_t *read_frame = NULL;
506 
507 // switch_assert(thread != NULL);
508 // switch_assert(session != NULL);
509 
511  return NULL;
512  }
513 
515 
516  channel = switch_core_session_get_channel(session);
517 
519  while (switch_channel_test_flag(channel, CF_SERVICE)) {
520 
522  switch (switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0)) {
525  case SWITCH_STATUS_BREAK:
526  break;
527  default:
529  break;
530  }
531  }
532 
534  switch (switch_core_session_read_video_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0)) {
537  case SWITCH_STATUS_BREAK:
538  break;
539  default:
541  break;
542  }
543  }
544  }
545 
547 
550 
552 
553  return NULL;
554 }
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.
switch_status_t switch_core_session_read_lock(_In_ switch_core_session_t *session)
Acquire a read lock on the session.
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
switch_status_t switch_core_session_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.
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
_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.
switch_mutex_t * frame_read_mutex
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
An abstraction of a data frame.
Definition: switch_frame.h:54
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
#define switch_channel_set_flag(_c, _f)
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.

◆ 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_set_var_conditional()

switch_bool_t switch_core_set_var_conditional ( const char *  varname,
const char *  value,
const char *  val2 
)

Definition at line 464 of file switch_core.c.

References switch_runtime::global_var_rwlock, switch_runtime::global_vars, switch_event_add_header_string_nodup(), switch_event_del_header, switch_event_get_header, SWITCH_FALSE, SWITCH_STACK_BOTTOM, switch_string_var_check(), switch_thread_rwlock_unlock(), switch_thread_rwlock_wrlock(), SWITCH_TRUE, and zstr.

465 {
466  char *val;
467 
468  if (varname) {
470  val = (char *) switch_event_get_header(runtime.global_vars, varname);
471 
472  if (val) {
473  if (!val2 || strcmp(val, val2) != 0) {
475  return SWITCH_FALSE;
476  }
478  } else if (!zstr(val2)) {
480  return SWITCH_FALSE;
481  }
482 
483  if (value) {
484  char *v = strdup(value);
487  } else {
489  }
491  }
492  return SWITCH_TRUE;
493 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
switch_status_t switch_event_add_header_string_nodup(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
#define switch_event_del_header(_e, _h)
Definition: switch_event.h:212
const char *const const char *const const cJSON *const value
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:86
#define zstr(x)
Definition: switch_utils.h:314
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
static switch_bool_t switch_string_var_check(char *s, switch_bool_t disable)
Definition: switch_utils.h:763
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172

◆ switch_core_set_variable()

void switch_core_set_variable ( const char *  varname,
const char *  value 
)

Definition at line 442 of file switch_core.c.

References switch_runtime::global_var_rwlock, switch_runtime::global_vars, switch_event_add_header_string(), switch_event_del_header, switch_event_get_header, SWITCH_STACK_BOTTOM, switch_string_var_check(), switch_thread_rwlock_unlock(), switch_thread_rwlock_wrlock(), and SWITCH_TRUE.

Referenced by check_ip(), switch_core_init(), and switch_load_core_config().

443 {
444  char *val;
445 
446  if (varname) {
448  val = (char *) switch_event_get_header(runtime.global_vars, varname);
449  if (val) {
451  }
452  if (value) {
453  char *v = strdup(value);
456  free(v);
457  } else {
459  }
461  }
462 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
#define switch_event_del_header(_e, _h)
Definition: switch_event.h:212
const char *const const char *const const cJSON *const value
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:86
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
static switch_bool_t switch_string_var_check(char *s, switch_bool_t disable)
Definition: switch_utils.h:763
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172

◆ 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_sqldb_destroy()

void switch_core_sqldb_destroy ( void  )

Definition at line 3013 of file switch_core.c.

References SCF_USE_SQL, switch_core_sqldb_stop(), and switch_test_flag.

Referenced by switch_loadable_module_shutdown().

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

◆ switch_core_sqldb_init()

switch_status_t switch_core_sqldb_init ( const char **  err)

Definition at line 2428 of file switch_core.c.

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

Referenced by switch_loadable_module_init().

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

◆ switch_core_thread_session_end()

void switch_core_thread_session_end ( switch_core_session_t session)

Definition at line 557 of file switch_core.c.

References CF_SERVICE, CF_SERVICE_AUDIO, CF_SERVICE_VIDEO, switch_assert, switch_channel_clear_flag(), switch_core_session_get_channel(), switch_core_session_kill_channel, and SWITCH_SIG_BREAK.

558 {
559  switch_channel_t *channel;
560  switch_assert(session);
561 
562  channel = switch_core_session_get_channel(session);
563  switch_assert(channel);
564 
568 
570 
571 }
_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.
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
#define switch_assert(expr)
#define switch_core_session_kill_channel(session, sig)
Send a signal to a channel.
Definition: switch_core.h:1393

◆ 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_core_unset_variables()

static void switch_core_unset_variables ( void  )
static

Definition at line 434 of file switch_core.c.

References switch_runtime::global_var_rwlock, switch_runtime::global_vars, SWITCH_EVENT_CHANNEL_DATA, switch_event_create_plain(), switch_event_destroy(), switch_thread_rwlock_unlock(), and switch_thread_rwlock_wrlock().

Referenced by switch_core_destroy().

435 {
440 }
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
switch_thread_rwlock_t * global_var_rwlock
switch_event_t * global_vars
struct switch_runtime runtime
Definition: switch_core.c:86
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
static switch_status_t switch_event_create_plain(switch_event_t **event, switch_event_types_t event_id)
Definition: switch_event.h:386
void switch_event_destroy(switch_event_t **event)
Destroy an event.

◆ 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_load_core_config()

static void switch_load_core_config ( const char *  file)
static

Definition at line 2049 of file switch_core.c.

References switch_runtime::colorize_console, switch_runtime::core_db_inner_post_trans_execute, switch_runtime::core_db_inner_pre_trans_execute, switch_runtime::core_db_post_trans_execute, switch_runtime::core_db_pre_trans_execute, switch_runtime::cpu_count, switch_runtime::cpu_idle_smoothing_depth, d_30, switch_runtime::db_handle_timeout, switch_runtime::dbname, DBTYPE_DEFAULT, DBTYPE_MSSQL, switch_runtime::event_channel_key_separator, switch_runtime::event_heartbeat_interval, switch_runtime::events_use_dispatch, switch_runtime::mailer_app, switch_runtime::mailer_app_args, switch_runtime::max_db_handles, switch_runtime::memory_pool, memset(), switch_runtime::microseconds_per_tick, switch_runtime::multiple_registrations, switch_xml::next, switch_runtime::odbc_dbtype, switch_runtime::odbc_dsn, switch_runtime::port_alloc_flags, switch_runtime::ptimes, SCF_API_EXPANSION, SCF_AUTO_SCHEMAS, SCF_CLEAR_SQL, SCF_CORE_NON_SQLITE_DB_REQ, SCF_CPF_SOFT_LOOKUP, SCF_CPF_SOFT_PREFIX, SCF_DIALPLAN_TIMESTAMPS, SCF_EARLY_HANGUP, SCF_EVENT_CHANNEL_ENABLE_HIERARCHY_DELIVERY, SCF_EVENT_CHANNEL_HIERARCHY_DELIVERY_ONCE, SCF_EVENT_CHANNEL_LOG_UNDELIVERABLE_JSON, SCF_SESSION_THREAD_POOL, SCF_THREADED_SYSTEM_EXEC, SCF_VERBOSE_EVENTS, SCSC_DEBUG_LEVEL, SCSC_LOGLEVEL, SPF_ROBUST_UDP, switch_atoul(), SWITCH_CHANNEL_LOG, switch_clear_flag, switch_core_alloc, switch_core_default_dtmf_duration(), switch_core_hash_insert, switch_core_max_audio_channels(), switch_core_max_dtmf_duration(), switch_core_media_set_resolveice(), switch_core_min_dtmf_duration(), switch_core_min_idle_cpu(), switch_core_session_ctl(), switch_core_session_limit(), switch_core_sessions_per_second(), switch_core_set_variable(), switch_core_strdup, switch_event_launch_dispatch_threads(), SWITCH_LOG_CRIT, SWITCH_LOG_ERROR, SWITCH_LOG_INVALID, SWITCH_LOG_NOTICE, switch_log_printf(), switch_log_str2level(), SWITCH_LOG_WARNING, switch_odbc_skip_autocommit_flip(), switch_rtp_set_end_port(), switch_rtp_set_start_port(), switch_set_flag, switch_time_set_cond_yield(), switch_time_set_matrix(), switch_time_set_monotonic(), switch_time_set_nanosleep(), switch_time_set_timerfd(), switch_time_set_use_system_time(), SWITCH_TRUE, switch_true(), switch_xml_attr_soft(), switch_xml_child(), switch_xml_free(), switch_xml_open_cfg(), switch_runtime::switchname, switch_runtime::timer_affinity, switch_runtime::tipping_point, and zstr.

Referenced by switch_core_init(), and switch_core_init_and_modload().

2050 {
2051  switch_xml_t xml = NULL, cfg = NULL;
2052 
2056 
2057 
2058  if ((xml = switch_xml_open_cfg(file, &cfg, NULL))) {
2059  switch_xml_t settings, param;
2060 
2061  if ((settings = switch_xml_child(cfg, "default-ptimes"))) {
2062  for (param = switch_xml_child(settings, "codec"); param; param = param->next) {
2063  const char *var = switch_xml_attr_soft(param, "name");
2064  const char *val = switch_xml_attr_soft(param, "ptime");
2065 
2066  if (!zstr(var) && !zstr(val)) {
2067  uint32_t *p;
2068  uint32_t v = switch_atoul(val);
2069 
2070  if (!strcasecmp(var, "G723") || !strcasecmp(var, "iLBC")) {
2071  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error adding %s, defaults cannot be changed\n", var);
2072  continue;
2073  }
2074 
2075  if (v == 0) {
2076  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error adding %s, invalid ptime\n", var);
2077  continue;
2078  }
2079 
2080  p = switch_core_alloc(runtime.memory_pool, sizeof(*p));
2081  *p = v;
2083  }
2084 
2085  }
2086  }
2087 
2088  if ((settings = switch_xml_child(cfg, "settings"))) {
2089  for (param = switch_xml_child(settings, "param"); param; param = param->next) {
2090  const char *var = switch_xml_attr_soft(param, "name");
2091  const char *val = switch_xml_attr_soft(param, "value");
2092 
2093  if (!strcasecmp(var, "loglevel")) {
2094  int level;
2095  if (*val > 47 && *val < 58) {
2096  level = atoi(val);
2097  } else {
2098  level = switch_log_str2level(val);
2099  }
2100 
2101  if (level != SWITCH_LOG_INVALID) {
2103  }
2104 #ifdef HAVE_SETRLIMIT
2105  } else if (!strcasecmp(var, "dump-cores") && switch_true(val)) {
2106  struct rlimit rlp;
2107  memset(&rlp, 0, sizeof(rlp));
2108  rlp.rlim_cur = RLIM_INFINITY;
2109  rlp.rlim_max = RLIM_INFINITY;
2110  setrlimit(RLIMIT_CORE, &rlp);
2111 #endif
2112  } else if (!strcasecmp(var, "debug-level")) {
2113  int tmp = atoi(val);
2114  if (tmp > -1 && tmp < 11) {
2116  }
2117  } else if (!strcasecmp(var, "max-db-handles")) {
2118  long tmp = atol(val);
2119 
2120  if (tmp > 4 && tmp < 5001) {
2121  runtime.max_db_handles = (uint32_t) tmp;
2122  } else {
2123  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "max-db-handles must be between 5 and 5000\n");
2124  }
2125  } else if (!strcasecmp(var, "odbc-skip-autocommit-flip")) {
2126  if (switch_true(val)) {
2128  }
2129  } else if (!strcasecmp(var, "db-handle-timeout")) {
2130  long tmp = atol(val);
2131 
2132  if (tmp > 0 && tmp < 5001) {
2133  runtime.db_handle_timeout = (uint32_t) tmp * 1000000;
2134  } else {
2135  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "db-handle-timeout must be between 1 and 5000\n");
2136  }
2137 
2138  } else if (!strcasecmp(var, "event-heartbeat-interval")) {
2139  long tmp = atol(val);
2140 
2141  if (tmp > 0) {
2142  runtime.event_heartbeat_interval = (uint32_t) tmp;
2143  } else {
2144  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "heartbeat-interval must be a greater than 0\n");
2145  }
2146 
2147  } else if (!strcasecmp(var, "multiple-registrations")) {
2149  } else if (!strcasecmp(var, "auto-create-schemas")) {
2150  if (switch_true(val)) {
2152  } else {
2154  }
2155  } else if (!strcasecmp(var, "session-thread-pool")) {
2156  if (switch_true(val)) {
2158  } else {
2160  }
2161  } else if (!strcasecmp(var, "auto-clear-sql")) {
2162  if (switch_true(val)) {
2164  } else {
2166  }
2167  } else if (!strcasecmp(var, "api-expansion")) {
2168  if (switch_true(val)) {
2170  } else {
2172  }
2173  } else if (!strcasecmp(var, "enable-early-hangup") && switch_true(val)) {
2175  } else if (!strcasecmp(var, "colorize-console") && switch_true(val)) {
2177  } else if (!strcasecmp(var, "core-db-pre-trans-execute") && !zstr(val)) {
2179  } else if (!strcasecmp(var, "core-db-post-trans-execute") && !zstr(val)) {
2181  } else if (!strcasecmp(var, "core-db-inner-pre-trans-execute") && !zstr(val)) {
2183  } else if (!strcasecmp(var, "core-db-inner-post-trans-execute") && !zstr(val)) {
2185  } else if (!strcasecmp(var, "dialplan-timestamps")) {
2186  if (switch_true(val)) {
2188  } else {
2190  }
2191  } else if (!strcasecmp(var, "mailer-app") && !zstr(val)) {
2193  } else if (!strcasecmp(var, "mailer-app-args") && val) {
2195  } else if (!strcasecmp(var, "sessions-per-second") && !zstr(val)) {
2197  } else if (!strcasecmp(var, "max-dtmf-duration") && !zstr(val)) {
2198  int tmp = atoi(val);
2199  if (tmp > 0) {
2200  switch_core_max_dtmf_duration((uint32_t) tmp);
2201  }
2202  } else if (!strcasecmp(var, "min-dtmf-duration") && !zstr(val)) {
2203  int tmp = atoi(val);
2204  if (tmp > 0) {
2205  switch_core_min_dtmf_duration((uint32_t) tmp);
2206  }
2207  } else if (!strcasecmp(var, "default-dtmf-duration") && !zstr(val)) {
2208  int tmp = atoi(val);
2209  if (tmp > 0) {
2210  switch_core_default_dtmf_duration((uint32_t) tmp);
2211  }
2212  } else if (!strcasecmp(var, "enable-use-system-time")) {
2214  } else if (!strcasecmp(var, "enable-monotonic-timing")) {
2216  } else if (!strcasecmp(var, "enable-softtimer-timerfd")) {
2217  int ival = 0;
2218  if (val) {
2219  if (switch_true(val)) {
2220  ival = 2;
2221  } else {
2222  if (strcasecmp(val, "broadcast")) {
2223  ival = 1;
2224  } else if (strcasecmp(val, "fd-per-timer")) {
2225  ival = 2;
2226  }
2227  }
2228  }
2230  } else if (!strcasecmp(var, "enable-clock-nanosleep")) {
2232  } else if (!strcasecmp(var, "enable-cond-yield")) {
2234  } else if (!strcasecmp(var, "enable-timer-matrix")) {
2236  } else if (!strcasecmp(var, "max-sessions") && !zstr(val)) {
2237  switch_core_session_limit(atoi(val));
2238  } else if (!strcasecmp(var, "verbose-channel-events") && !zstr(val)) {
2239  int v = switch_true(val);
2240  if (v) {
2242  } else {
2244  }
2245  } else if (!strcasecmp(var, "threaded-system-exec") && !zstr(val)) {
2246 #ifdef WIN32
2247  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "threaded-system-exec is not implemented on this platform\n");
2248 #else
2249  int v = switch_true(val);
2250  if (v) {
2252  } else {
2254  }
2255 #endif
2256  } else if (!strcasecmp(var, "spawn-instead-of-system") && !zstr(val)) {
2257 #ifdef WIN32
2258  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "spawn-instead-of-system is not implemented on this platform\n");
2259 #else
2260  int v = switch_true(val);
2261  if (v) {
2262  switch_core_set_variable("spawn_instead_of_system", "true");
2263  } else {
2264  switch_core_set_variable("spawn_instead_of_system", "false");
2265  }
2266 #endif
2267  } else if (!strcasecmp(var, "exclude-error-log-from-xml-cdr") && !zstr(val)) {
2268  int v = switch_true(val);
2269  if (v) {
2270  switch_core_set_variable("exclude_error_log_from_xml_cdr", "true");
2271  } else {
2272  switch_core_set_variable("exclude_error_log_from_xml_cdr", "false");
2273  }
2274  } else if (!strcasecmp(var, "min-idle-cpu") && !zstr(val)) {
2275  switch_core_min_idle_cpu(atof(val));
2276  } else if (!strcasecmp(var, "tipping-point") && !zstr(val)) {
2277  runtime.tipping_point = atoi(val);
2278  } else if (!strcasecmp(var, "cpu-idle-smoothing-depth") && !zstr(val)) {
2279  runtime.cpu_idle_smoothing_depth = atoi(val);
2280  } else if (!strcasecmp(var, "events-use-dispatch") && !zstr(val)) {
2282  } else if (!strcasecmp(var, "initial-event-threads") && !zstr(val)) {
2283  int tmp;
2284 
2288  "Implicitly setting events-use-dispatch based on usage of this initial-event-threads parameter.\n");
2289  }
2290 
2291  tmp = atoi(val);
2292 
2293  if (tmp > runtime.cpu_count / 2) {
2294  tmp = runtime.cpu_count / 2;
2295  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "This value cannot be higher than %d so setting it to that value\n",
2296  runtime.cpu_count / 2);
2297  }
2298 
2299  if (tmp < 1) {
2300  tmp = 1;
2301  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "This value cannot be lower than 1 so setting it to that level\n");
2302  }
2303 
2305 
2306  } else if (!strcasecmp(var, "1ms-timer") && switch_true(val)) {
2308  } else if (!strcasecmp(var, "timer-affinity") && !zstr(val)) {
2309  if (!strcasecmp(val, "disabled")) {
2310  runtime.timer_affinity = -1;
2311  } else {
2312  runtime.timer_affinity = atoi(val);
2313  }
2314  } else if (!strcasecmp(var, "ice-resolve-candidate")) {
2316  } else if (!strcasecmp(var, "rtp-start-port") && !zstr(val)) {
2318  } else if (!strcasecmp(var, "rtp-end-port") && !zstr(val)) {
2320  } else if (!strcasecmp(var, "rtp-port-usage-robustness") && switch_true(val)) {
2322  } else if (!strcasecmp(var, "core-db-name") && !zstr(val)) {
2324  } else if (!strcasecmp(var, "core-db-dsn") && !zstr(val)) {
2326  } else if (!strcasecmp(var, "core-non-sqlite-db-required") && !zstr(val)) {
2328  } else if (!strcasecmp(var, "core-dbtype") && !zstr(val)) {
2329  if (!strcasecmp(val, "MSSQL")) {
2331  } else {
2333  }
2334  } else if (!strcasecmp(var, "switchname") && !zstr(val)) {
2337  } else if (!strcasecmp(var, "rtp-retain-crypto-keys")) {
2338  if (switch_true(val)) {
2340  "rtp-retain-crypto-keys enabled. Could be used to decrypt secure media.\n");
2341  }
2342  switch_core_set_variable("rtp_retain_crypto_keys", val);
2343  } else if (!strcasecmp(var, "caller-profile-soft-variables-uses-prefix") && !zstr(val)) {
2344  int v = switch_true(val);
2345  if (v) {
2347  } else {
2349  }
2350  } else if (!strcasecmp(var, "caller-profile-soft-lookup-values") && !zstr(val)) {
2351  int v = switch_true(val);
2352  if (v) {
2354  } else {
2356  }
2357  } else if (!strcasecmp(var, "event-channel-key-separator") && !zstr(val)) {
2359  } else if (!strcasecmp(var, "event-channel-enable-hierarchy-deliver") && !zstr(val)) {
2360  int v = switch_true(val);
2361  if (v) {
2363  } else {
2365  }
2366  } else if (!strcasecmp(var, "event-channel-hierarchy-deliver-once") && !zstr(val)) {
2367  int v = switch_true(val);
2368  if (v) {
2370  } else {
2372  }
2373  } else if (!strcasecmp(var, "event-channel-log-undeliverable-json") && !zstr(val)) {
2374  int v = switch_true(val);
2375  if (v) {
2377  } else {
2379  }
2380  } else if (!strcasecmp(var, "max-audio-channels") && !zstr(val)) {
2381  switch_core_max_audio_channels(atoi(val));
2382  }
2383  }
2384  }
2385 
2386  if (runtime.event_channel_key_separator == NULL) {
2388  }
2389 
2390  if ((settings = switch_xml_child(cfg, "variables"))) {
2391  for (param = switch_xml_child(settings, "variable"); param; param = param->next) {
2392  const char *var = switch_xml_attr_soft(param, "name");
2393  const char *val = switch_xml_attr_soft(param, "value");
2394  if (var && val) {
2395  switch_core_set_variable(var, val);
2396  }
2397  }
2398  }
2399 
2400  switch_xml_free(xml);
2401  }
2402 
2403 
2404 }
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
char * core_db_inner_post_trans_execute
const char * switch_xml_attr_soft(_In_ switch_xml_t xml, _In_z_ const char *attr)
returns the value of the requested tag attribute, or "" if not found
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
#define SWITCH_CHANNEL_LOG
uint32_t switch_core_sessions_per_second(_In_ uint32_t new_limit)
Set/Get Session Rate Limit.
void switch_time_set_nanosleep(switch_bool_t enable)
Definition: switch_time.c:366
int32_t timer_affinity
char * core_db_post_trans_execute
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
void switch_event_launch_dispatch_threads(uint32_t max)
Definition: switch_event.c:653
A representation of an XML tree.
Definition: switch_xml.h:79
void switch_time_set_timerfd(int enable)
Definition: switch_time.c:348
switch_port_t switch_rtp_set_start_port(switch_port_t port)
Set/Get RTP start port.
Definition: switch_rtp.c:2582
uint32_t microseconds_per_tick
struct switch_runtime runtime
Definition: switch_core.c:86
#define zstr(x)
Definition: switch_utils.h:314
uint32_t switch_core_max_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1704
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:724
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1744
switch_hash_t * ptimes
switch_dbtype_t odbc_dbtype
switch_xml_t next
Definition: switch_xml.h:91
char * event_channel_key_separator
switch_bool_t colorize_console
void switch_time_set_matrix(switch_bool_t enable)
Definition: switch_time.c:360
switch_log_level_t switch_log_str2level(_In_z_ const char *str)
Return the level number of the specified log level name.
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
static uint32_t d_30
Definition: switch_core.c:2047
switch_port_t switch_rtp_set_end_port(switch_port_t port)
Set/Get RTP end port.
Definition: switch_rtp.c:2596
uint32_t switch_core_max_audio_channels(uint32_t limit)
Definition: switch_core.c:2642
unsigned long switch_atoul(const char *nptr)
uint32_t event_heartbeat_interval
void switch_core_set_variable(const char *varname, const char *value)
Definition: switch_core.c:442
uint32_t db_handle_timeout
uint16_t switch_port_t
double switch_core_min_idle_cpu(double new_limit)
void switch_core_media_set_resolveice(switch_bool_t resolve_ice)
uint32_t switch_core_default_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1721
uint32_t switch_core_session_limit(_In_ uint32_t new_limit)
Set/Get Session Limit.
void switch_time_set_monotonic(switch_bool_t enable)
Definition: switch_time.c:331
switch_xml_t switch_xml_open_cfg(_In_z_ const char *file_path, _Out_ switch_xml_t *node, _In_opt_ switch_event_t *params)
open a config in the core registry
void switch_odbc_skip_autocommit_flip(void)
Definition: switch_odbc.c:67
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1479
uint32_t tipping_point
uint32_t max_db_handles
switch_xml_t switch_xml_child(_In_ switch_xml_t xml, _In_z_ const char *name)
returns the first child tag (one level deeper) with the given name or NULL \ if not found ...
void switch_time_set_use_system_time(switch_bool_t enable)
Definition: switch_time.c:342
char * core_db_pre_trans_execute
uint32_t port_alloc_flags
void switch_time_set_cond_yield(switch_bool_t enable)
Definition: switch_time.c:373
switch_memory_pool_t * memory_pool
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.
uint32_t cpu_idle_smoothing_depth
int32_t switch_core_session_ctl(switch_session_ctl_t cmd, void *val)
send a control message to the core
Definition: switch_core.c:2651
char * core_db_inner_pre_trans_execute
memset(buf, 0, buflen)

◆ 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_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_STANDARD_SCHED_FUNC() [1/2]

SWITCH_STANDARD_SCHED_FUNC ( heartbeat_callback  )

Definition at line 225 of file switch_core.c.

References switch_runtime::event_heartbeat_interval, send_heartbeat(), and switch_epoch_time_now().

226 {
227  send_heartbeat();
228 
229  /* reschedule this task */
231 }
struct switch_runtime runtime
Definition: switch_core.c:86
uint32_t event_heartbeat_interval
static void send_heartbeat(void)
Definition: switch_core.c:89
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:322

◆ SWITCH_STANDARD_SCHED_FUNC() [2/2]

SWITCH_STANDARD_SCHED_FUNC ( check_ip_callback  )

Definition at line 234 of file switch_core.c.

References check_ip(), and switch_epoch_time_now().

235 {
236  check_ip();
237 
238  /* reschedule this task */
239  task->runtime = switch_epoch_time_now(NULL) + 60;
240 }
static void check_ip(void)
Definition: switch_core.c:132
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:322

◆ 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_system_fork()

static int switch_system_fork ( const char *  cmd,
switch_bool_t  wait 
)
static

Definition at line 3295 of file switch_core.c.

References memset(), SWITCH_CHANNEL_LOG, switch_close_extra_files(), switch_core_set_signal_handlers(), switch_fork(), SWITCH_LOG_ERROR, and switch_log_printf().

Referenced by switch_close_extra_files(), and switch_system().

3296 {
3297  int pid;
3298  char *dcmd = strdup(cmd);
3299 #if defined(HAVE_SETRLIMIT) && !defined(__FreeBSD__)
3300  struct rlimit rlim;
3301  struct rlimit rlim_save;
3302 #endif
3303 
3305 
3306  pid = switch_fork();
3307 
3308  if (pid) {
3309  if (wait) {
3310  waitpid(pid, NULL, 0);
3311  }
3312  free(dcmd);
3313  } else {
3314  switch_close_extra_files(NULL, 0);
3315 
3316 #if defined(HAVE_SETRLIMIT) && !defined(__FreeBSD__)
3317  memset(&rlim, 0, sizeof(rlim));
3318  getrlimit(RLIMIT_STACK, &rlim);
3319 
3320  memset(&rlim_save, 0, sizeof(rlim_save));
3321  getrlimit(RLIMIT_STACK, &rlim_save);
3322 
3323  rlim.rlim_cur = rlim.rlim_max;
3324  if (setrlimit(RLIMIT_STACK, &rlim) < 0) {
3325  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Setting stack size failed! (%s)\n", strerror(errno));
3326  }
3327 #endif
3328 
3329  if (system(dcmd) == -1) {
3330  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to execute because of a command error : %s\n", dcmd);
3331  }
3332  free(dcmd);
3333  exit(0);
3334  }
3335 
3336  return 0;
3337 }
void switch_core_set_signal_handlers(void)
Definition: switch_core.c:2579
#define SWITCH_CHANNEL_LOG
void switch_close_extra_files(int *keep, int keep_ttl)
Definition: switch_core.c:3244
pid_t switch_fork(void)
Definition: switch_core.c:3282
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_system_thread()

static int switch_system_thread ( const char *  cmd,
switch_bool_t  wait 
)
static

Definition at line 3189 of file switch_core.c.

References system_thread_handle::cmd, system_thread_handle::cond, system_thread_handle::mutex, pool, system_thread_handle::pool, system_thread_handle::ret, SWITCH_CHANNEL_LOG, switch_core_alloc, switch_core_destroy_memory_pool, switch_core_new_memory_pool, switch_core_strdup, SWITCH_LOG_CRIT, switch_log_printf(), switch_mutex_init(), switch_mutex_lock(), SWITCH_MUTEX_NESTED, switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, SWITCH_SYSTEM_THREAD_STACKSIZE, switch_thread_cond_create(), switch_thread_cond_wait(), switch_thread_create(), switch_threadattr_create(), switch_threadattr_detach_set(), switch_threadattr_stacksize_set(), system_thread(), and thread.

Referenced by switch_close_extra_files(), and switch_system().

3190 {
3192  switch_threadattr_t *thd_attr;
3193  int ret = 0;
3194  struct system_thread_handle *sth;
3196 
3199  return 1;
3200  }
3201 
3202  if (!(sth = switch_core_alloc(pool, sizeof(struct system_thread_handle)))) {
3204  return 1;
3205  }
3206 
3207  sth->pool = pool;
3208  sth->cmd = switch_core_strdup(pool, cmd);
3209 
3210  switch_thread_cond_create(&sth->cond, sth->pool);
3212  switch_mutex_lock(sth->mutex);
3213 
3214  switch_threadattr_create(&thd_attr, sth->pool);
3216  switch_threadattr_detach_set(thd_attr, 1);
3217  switch_thread_create(&thread, thd_attr, system_thread, sth, sth->pool);
3218 
3219  if (wait) {
3220  switch_thread_cond_wait(sth->cond, sth->mutex);
3221  ret = sth->ret;
3222  }
3223  switch_mutex_unlock(sth->mutex);
3224 
3225  return ret;
3226 }
#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_CHANNEL_LOG
switch_mutex_t * mutex
Definition: switch_core.c:3141
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:683
#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_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex)
Definition: switch_apr.c:378
static switch_thread_t * thread
Definition: switch_log.c:486
switch_thread_cond_t * cond
Definition: switch_core.c:3140
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_status_t switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on)
Definition: switch_apr.c:678
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
#define SWITCH_SYSTEM_THREAD_STACKSIZE
Definition: switch_types.h:585
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
static void *SWITCH_THREAD_FUNC system_thread(switch_thread_t *thread, void *obj)
Definition: switch_core.c:3147
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 fspr_thread_t switch_thread_t
Definition: switch_apr.h:941
switch_memory_pool_t * pool
Definition: switch_core.c:3142

◆ system_thread()

static void* SWITCH_THREAD_FUNC system_thread ( switch_thread_t thread,
void *  obj 
)
static

Definition at line 3147 of file switch_core.c.

References system_thread_handle::cmd, system_thread_handle::cond, system_thread_handle::fds, memset(), system_thread_handle::mutex, system_thread_handle::pool, system_thread_handle::ret, SWITCH_CHANNEL_LOG, switch_core_destroy_memory_pool, SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), and switch_thread_cond_signal().

Referenced by switch_system_thread().

3148 {
3149  struct system_thread_handle *sth = (struct system_thread_handle *) obj;
3150 
3151 #if defined(HAVE_SETRLIMIT) && !defined(__FreeBSD__)
3152  struct rlimit rlim;
3153  struct rlimit rlim_save;
3154 
3155  memset(&rlim, 0, sizeof(rlim));
3156  getrlimit(RLIMIT_STACK, &rlim);
3157 
3158  memset(&rlim_save, 0, sizeof(rlim_save));
3159  getrlimit(RLIMIT_STACK, &rlim_save);
3160 
3161  rlim.rlim_cur = rlim.rlim_max;
3162  if (setrlimit(RLIMIT_STACK, &rlim) < 0) {
3163  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Setting stack size failed! (%s)\n", strerror(errno));
3164  }
3165 #endif
3166 
3167  if (sth->fds) {
3168  dup2(sth->fds[1], STDOUT_FILENO);
3169  }
3170 
3171  sth->ret = system(sth->cmd);
3172 
3173 #if defined(HAVE_SETRLIMIT) && !defined(__FreeBSD__)
3174  if (setrlimit(RLIMIT_STACK, &rlim_save) < 0) {
3175  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Setting stack size failed! (%s)\n", strerror(errno));
3176  }
3177 #endif
3178 
3179  switch_mutex_lock(sth->mutex);
3181  switch_mutex_unlock(sth->mutex);
3182 
3184 
3185  return NULL;
3186 }
#define SWITCH_CHANNEL_LOG
switch_mutex_t * mutex
Definition: switch_core.c:3141
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
switch_thread_cond_t * cond
Definition: switch_core.c:3140
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_status_t switch_thread_cond_signal(switch_thread_cond_t *cond)
Definition: switch_apr.c:394
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_memory_pool_t * pool
Definition: switch_core.c:3142

Variable Documentation

◆ d_30

uint32_t d_30 = 30
static

Definition at line 2047 of file switch_core.c.

Referenced by switch_load_core_config().

◆ IP_LIST

switch_ip_list_t IP_LIST = { 0 }
static

Definition at line 1372 of file switch_core.c.

◆ main_ip4

char main_ip4[256] = ""
static

Definition at line 129 of file switch_core.c.

Referenced by check_ip().

◆ main_ip6

char main_ip6[256] = ""
static

Definition at line 130 of file switch_core.c.

Referenced by check_ip().

◆ runtime

struct switch_runtime runtime = { 0 }

Definition at line 86 of file switch_core.c.

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

◆ SWITCH_GLOBAL_dirs

switch_directories SWITCH_GLOBAL_dirs = { 0 }

◆ SWITCH_GLOBAL_filenames

switch_filenames SWITCH_GLOBAL_filenames = { 0 }