RTS API Documentation  1.10.11
Macros | Functions
+ Collaboration diagram for Misc:

Macros

#define switch_check_network_list_ip(_ip_str, _list_name)   switch_check_network_list_ip_token(_ip_str, _list_name, NULL)
 

Functions

FILE * switch_core_data_channel (switch_text_channel_t channel)
 Retrieve a FILE stream of a given text channel name. More...
 
switch_bool_t switch_core_ready (void)
 Determines if the core is ready to take calls. More...
 
switch_bool_t switch_core_running (void)
 
switch_bool_t switch_core_ready_inbound (void)
 Determines if the core is ready to take inbound calls. More...
 
switch_bool_t switch_core_ready_outbound (void)
 Determines if the core is ready to place outbound calls. More...
 
switch_core_flag_t switch_core_flags (void)
 return core flags More...
 
switch_status_t switch_core_management_exec (char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
 Execute a management operation. More...
 
int32_t switch_core_set_process_privileges (void)
 Switch on the privilege awareness for the process and request required privileges. More...
 
int32_t set_normal_priority (void)
 Set the maximum priority the process can obtain. More...
 
int32_t set_auto_priority (void)
 
int32_t set_realtime_priority (void)
 
int32_t set_low_priority (void)
 
int32_t change_user_group (const char *user, const char *group)
 Change user and/or group of the running process. More...
 
void switch_core_runtime_loop (int bg)
 Run endlessly until the system is shutdown. More...
 
switch_status_t switch_core_set_console (const char *console)
 Set the output console to the desired file. More...
 
void switch_core_measure_time (switch_time_t total_ms, switch_core_time_duration_t *duration)
 Breakdown a number of milliseconds into various time spec. More...
 
switch_time_t switch_core_uptime (void)
 Number of microseconds the system has been up. More...
 
int32_t switch_core_session_ctl (switch_session_ctl_t cmd, void *val)
 send a control message to the core More...
 
FILE * switch_core_get_console (void)
 Get the output console. More...
 
switch_thread_tswitch_core_launch_thread (void *(SWITCH_THREAD_FUNC *func)(switch_thread_t *, void *), void *obj, switch_memory_pool_t *pool)
 Launch a thread. More...
 
void switch_core_set_globals (void)
 Initiate Globals. More...
 
uint8_t switch_core_session_compare (switch_core_session_t *a, switch_core_session_t *b)
 Checks if 2 sessions are using the same endpoint module. More...
 
uint8_t switch_core_session_check_interface (switch_core_session_t *session, const switch_endpoint_interface_t *endpoint_interface)
 Checks if a session is using a specific endpoint. More...
 
switch_status_t switch_core_session_set_video_read_callback (switch_core_session_t *session, switch_core_video_thread_callback_func_t func, void *user_data)
 
switch_status_t switch_core_session_video_read_callback (switch_core_session_t *session, switch_frame_t *frame)
 
switch_hash_index_tswitch_core_mime_index (void)
 
const char * switch_core_mime_ext2type (const char *ext)
 
const char * switch_core_mime_type2ext (const char *type)
 
switch_status_t switch_core_mime_add_type (const char *type, const char *ext)
 
switch_loadable_module_interface_tswitch_loadable_module_create_module_interface (switch_memory_pool_t *pool, const char *name)
 
void * switch_loadable_module_create_interface (switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname)
 
switch_time_t switch_micro_time_now (void)
 Get the current epoch time in microseconds. More...
 
switch_time_t switch_mono_micro_time_now (void)
 
void switch_core_memory_reclaim (void)
 
void switch_core_memory_reclaim_events (void)
 
void switch_core_memory_reclaim_logger (void)
 
void switch_core_memory_reclaim_all (void)
 
void switch_core_setrlimits (void)
 
switch_time_t switch_time_ref (void)
 
void switch_time_sync (void)
 
time_t switch_epoch_time_now (time_t *t)
 Get the current epoch time. More...
 
const char * switch_lookup_timezone (const char *tz_name)
 
switch_status_t switch_strftime_tz (const char *tz, const char *format, char *date, size_t len, switch_time_t thetime)
 
switch_status_t switch_time_exp_tz_name (const char *tz, switch_time_exp_t *tm, switch_time_t thetime)
 
void switch_load_network_lists (switch_bool_t reload)
 
switch_bool_t switch_check_network_list_ip_port_token (const char *ip_str, int port, const char *list_name, const char **token)
 
switch_bool_t switch_check_network_list_ip_token (const char *ip_str, const char *list_name, const char **token)
 
void switch_time_set_monotonic (switch_bool_t enable)
 
void switch_time_set_timerfd (int enable)
 
void switch_time_set_nanosleep (switch_bool_t enable)
 
void switch_time_set_matrix (switch_bool_t enable)
 
void switch_time_set_cond_yield (switch_bool_t enable)
 
void switch_time_set_use_system_time (switch_bool_t enable)
 
uint32_t switch_core_min_dtmf_duration (uint32_t duration)
 
uint32_t switch_core_max_dtmf_duration (uint32_t duration)
 
double switch_core_min_idle_cpu (double new_limit)
 
double switch_core_idle_cpu (void)
 
uint32_t switch_core_default_dtmf_duration (uint32_t duration)
 
switch_status_t switch_console_set_complete (const char *string)
 
switch_status_t switch_console_set_alias (const char *string)
 
int switch_system (const char *cmd, switch_bool_t wait)
 
int switch_stream_system (const char *cmd, switch_stream_handle_t *stream)
 
void switch_cond_yield (switch_interval_time_t t)
 
void switch_cond_next (void)
 
switch_status_t switch_core_chat_send_args (const char *dest_proto, const char *proto, const char *from, const char *to, const char *subject, const char *body, const char *type, const char *hint, switch_bool_t blocking)
 
switch_status_t switch_core_chat_send (const char *dest_proto, switch_event_t *message_event)
 
switch_status_t switch_core_chat_deliver (const char *dest_proto, switch_event_t **message_event)
 
switch_status_t switch_ivr_preprocess_session (switch_core_session_t *session, const char *cmds)
 
void switch_core_sqldb_pause (void)
 
void switch_core_sqldb_resume (void)
 

Detailed Description

Macro Definition Documentation

◆ switch_check_network_list_ip

#define switch_check_network_list_ip (   _ip_str,
  _list_name 
)    switch_check_network_list_ip_token(_ip_str, _list_name, NULL)

Definition at line 2519 of file switch_core.h.

Referenced by check_ice(), and switch_core_media_check_nat().

Function Documentation

◆ change_user_group()

int32_t change_user_group ( const char *  user,
const char *  group 
)

Change user and/or group of the running process.

Parameters
username of the user to switch to (or NULL)
groupname of the group to switch to (or NULL)
Returns
0 on success, -1 otherwise

Several possible combinations:

  • user only (group NULL): switch to user and his primary group (and supplementary groups, if supported)
  • user and group: switch to user and specified group (only)
  • group only (user NULL): switch group only

Definition at line 1083 of file switch_core.c.

Referenced by main().

1084 {
1085 #ifndef WIN32
1086  uid_t runas_uid = 0;
1087  gid_t runas_gid = 0;
1088  struct passwd *runas_pw = NULL;
1089 
1090  if (user) {
1091  /*
1092  * Lookup user information in the system's db
1093  */
1094  runas_pw = getpwnam(user);
1095  if (!runas_pw) {
1096  fprintf(stderr, "ERROR: Unknown user \"%s\"\n", user);
1097  return -1;
1098  }
1099  runas_uid = runas_pw->pw_uid;
1100  }
1101 
1102  if (group) {
1103  struct group *gr = NULL;
1104 
1105  /*
1106  * Lookup group information in the system's db
1107  */
1108  gr = getgrnam(group);
1109  if (!gr) {
1110  fprintf(stderr, "ERROR: Unknown group \"%s\"\n", group);
1111  return -1;
1112  }
1113  runas_gid = gr->gr_gid;
1114  }
1115 
1116  if (runas_uid && getuid() == runas_uid && (!runas_gid || runas_gid == getgid())) {
1117  /* already running as the right user and group, nothing to do! */
1118  return 0;
1119  }
1120 
1121  if (runas_uid) {
1122 #ifdef SOLARIS_PRIVILEGES
1123  /* request the privilege to set the UID */
1124  if (priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_PROC_SETID, NULL) < 0) {
1125  fprintf(stderr, "ERROR: Failed to acquire proc_setid privilege (%s)\n", strerror(errno));
1126  return -1;
1127  }
1128 #endif
1129 #ifdef HAVE_SETGROUPS
1130  /*
1131  * Drop all group memberships prior to changing anything
1132  * or else we're going to inherit the parent's list of groups
1133  * (which is not what we want...)
1134  */
1135  if (setgroups(0, NULL) < 0) {
1136  fprintf(stderr, "ERROR: Failed to drop group access list\n");
1137  return -1;
1138  }
1139 #endif
1140  if (runas_gid) {
1141  /*
1142  * A group has been passed, switch to it
1143  * (without loading the user's other groups)
1144  */
1145  if (setgid(runas_gid) < 0) {
1146  fprintf(stderr, "ERROR: Failed to change gid!\n");
1147  return -1;
1148  }
1149  } else {
1150  /*
1151  * No group has been passed, use the user's primary group in this case
1152  */
1153  if (setgid(runas_pw->pw_gid) < 0) {
1154  fprintf(stderr, "ERROR: Failed to change gid!\n");
1155  return -1;
1156  }
1157 #ifdef HAVE_INITGROUPS
1158  /*
1159  * Set all the other groups the user is a member of
1160  * (This can be really useful for fine-grained access control)
1161  */
1162  if (initgroups(runas_pw->pw_name, runas_pw->pw_gid) < 0) {
1163  fprintf(stderr, "ERROR: Failed to set group access list for user\n");
1164  return -1;
1165  }
1166 #endif
1167  }
1168 
1169  /*
1170  * Finally drop all privileges by switching to the new userid
1171  */
1172  if (setuid(runas_uid) < 0) {
1173  fprintf(stderr, "ERROR: Failed to change uid!\n");
1174  return -1;
1175  }
1176 #ifdef HAVE_SYS_PRCTL_H
1177  if (prctl(PR_SET_DUMPABLE, 1) < 0) {
1178  fprintf(stderr, "ERROR: Failed to enable core dumps!\n");
1179  return -1;
1180  }
1181 #endif
1182  }
1183 #endif
1184  return 0;
1185 }

◆ set_auto_priority()

int32_t set_auto_priority ( void  )

Definition at line 1065 of file switch_core.c.

References switch_runtime::cpu_count, and set_realtime_priority().

Referenced by main().

1066 {
1067 #ifndef WIN32
1068  runtime.cpu_count = sysconf (_SC_NPROCESSORS_ONLN);
1069 #else
1070  SYSTEM_INFO sysinfo;
1071  GetSystemInfo( &sysinfo );
1072  runtime.cpu_count = sysinfo.dwNumberOfProcessors;
1073 #endif
1074 
1075  if (!runtime.cpu_count) runtime.cpu_count = 1;
1076 
1077  return set_realtime_priority();
1078 
1079 
1080  // ERROR: code not reachable on Windows Visual Studio Express 2008 return 0;
1081 }
struct switch_runtime runtime
Definition: switch_core.c:86
int32_t set_realtime_priority(void)
Definition: switch_core.c:981

◆ set_low_priority()

int32_t set_low_priority ( void  )

Definition at line 945 of file switch_core.c.

Referenced by main(), and switch_fork().

946 {
947 #ifdef WIN32
948  return SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
949 #else
950 #if defined(USE_SCHED_SETSCHEDULER) && ! defined(SOLARIS_PRIVILEGES)
951  /*
952  * Try to use a normal scheduler
953  */
954  struct sched_param sched = { 0 };
955  sched.sched_priority = 0;
956  if (sched_setscheduler(0, SCHED_OTHER, &sched) < 0) {
957  fprintf(stderr, "ERROR: Failed to set SCHED_OTHER scheduler (%s)\n", strerror(errno));
958  return -1;
959  }
960 #endif
961 
962 #ifdef HAVE_SETPRIORITY
963  /*
964  * setpriority() works on FreeBSD (6.2), nice() doesn't
965  */
966  if (setpriority(PRIO_PROCESS, getpid(), 19) < 0) {
967  fprintf(stderr, "ERROR: Could not set nice level\n");
968  return -1;
969  }
970 #else
971  if (nice(19) != 19) {
972  fprintf(stderr, "ERROR: Could not set nice level\n");
973  return -1;
974  }
975 #endif
976 
977  return 0;
978 #endif
979 }

◆ set_normal_priority()

int32_t set_normal_priority ( void  )

Set the maximum priority the process can obtain.

Returns
0 on success

Definition at line 1060 of file switch_core.c.

Referenced by main().

1061 {
1062  return 0;
1063 }

◆ set_realtime_priority()

int32_t set_realtime_priority ( void  )

Definition at line 981 of file switch_core.c.

References SWITCH_PRI_LOW.

Referenced by main(), and set_auto_priority().

982 {
983 #ifdef WIN32
984  return SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
985 #else
986 #ifdef USE_SCHED_SETSCHEDULER
987  /*
988  * Try to use a round-robin scheduler
989  * with a fallback if that does not work
990  */
991  struct sched_param sched = { 0 };
992  sched.sched_priority = SWITCH_PRI_LOW;
993 #endif
994 
995 #ifdef SOLARIS_PRIVILEGES
996  /* request the privileges to elevate the priority */
997  if (priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_PROC_PRIOCNTL, NULL) < 0) {
998 #ifdef PRIV_PROC_PRIOUP
999  /* fallback to PRIV_PROC_PRIOUP on SmartOS */
1000  fprintf(stderr, "WARN: Failed to acquire proc_priocntl privilege (%s)\n", strerror(errno));
1001  if (priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_PROC_PRIOUP, NULL) < 0) {
1002  fprintf(stderr, "ERROR: Failed to acquire proc_prioup privilege (%s)\n", strerror(errno));
1003  return -1;
1004  }
1005 #else
1006  fprintf(stderr, "ERROR: Failed to acquire proc_priocntl privilege (%s)\n", strerror(errno));
1007  return -1;
1008 #endif
1009  }
1010 
1011  if (sched_setscheduler(0, SCHED_FIFO, &sched) < 0) {
1012  fprintf(stderr, "WARN: Failed to set SCHED_FIFO scheduler (%s)\n", strerror(errno));
1013  } else {
1014  return 0;
1015  }
1016 
1017  if (setpriority(PRIO_PROCESS, 0, -10) < 0) {
1018  fprintf(stderr, "ERROR: Could not set nice level\n");
1019  return -1;
1020  }
1021 
1022  return 0;
1023 #else
1024 
1025 #ifdef USE_SCHED_SETSCHEDULER
1026  if (sched_setscheduler(0, SCHED_FIFO, &sched) < 0) {
1027  fprintf(stderr, "ERROR: Failed to set SCHED_FIFO scheduler (%s)\n", strerror(errno));
1028  sched.sched_priority = 0;
1029  if (sched_setscheduler(0, SCHED_OTHER, &sched) < 0 ) {
1030  fprintf(stderr, "ERROR: Failed to set SCHED_OTHER scheduler (%s)\n", strerror(errno));
1031  return -1;
1032  }
1033  }
1034 #endif
1035 
1036 #ifdef HAVE_SETPRIORITY
1037  /*
1038  * setpriority() works on FreeBSD (6.2), nice() doesn't
1039  */
1040  if (setpriority(PRIO_PROCESS, getpid(), -10) < 0) {
1041  fprintf(stderr, "ERROR: Could not set nice level\n");
1042  return -1;
1043  }
1044 #else
1045  if (nice(-10) != -10) {
1046  fprintf(stderr, "ERROR: Could not set nice level\n");
1047  return -1;
1048  }
1049 #endif
1050 #endif
1051  return 0;
1052 #endif
1053 }

◆ switch_check_network_list_ip_port_token()

switch_bool_t switch_check_network_list_ip_port_token ( const char *  ip_str,
int  port,
const char *  list_name,
const char **  token 
)

Definition at line 1374 of file switch_core.c.

References switch_runtime::global_mutex, switch_ip_list_t::hash, ip, switch_assert, switch_core_hash_find(), SWITCH_FALSE, switch_inet_pton(), switch_mutex_lock(), switch_mutex_unlock(), switch_network_ipv4_mapped_ipv6_addr(), switch_network_list_validate_ip6_port_token(), switch_network_list_validate_ip_port_token(), switch_parse_cidr(), switch_safe_free, switch_separate_string(), switch_test_subnet, switch_testv6_subnet(), and ip_t::v4.

Referenced by switch_check_network_list_ip_token().

1375 {
1376  switch_network_list_t *list;
1377  ip_t ip, mask, net;
1378  uint32_t bits;
1379  char *ipv6 = strchr(ip_str,':');
1381  char *ipv4 = NULL;
1382 
1383  if (!list_name) {
1384  return SWITCH_FALSE;
1385  }
1386 
1387  if ((ipv4 = switch_network_ipv4_mapped_ipv6_addr(ip_str))) {
1388  ip_str = ipv4;
1389  ipv6 = NULL;
1390  }
1391 
1393  if (ipv6) {
1394  switch_inet_pton(AF_INET6, ip_str, &ip);
1395  } else {
1396  switch_inet_pton(AF_INET, ip_str, &ip);
1397  ip.v4 = htonl(ip.v4);
1398  }
1399 
1400  if ((list = switch_core_hash_find(IP_LIST.hash, list_name))) {
1401  if (ipv6) {
1402  ok = switch_network_list_validate_ip6_port_token(list, ip, port, token);
1403  } else {
1404  ok = switch_network_list_validate_ip_port_token(list, ip.v4, port, token);
1405  }
1406  } else if (strchr(list_name, '/')) {
1407  if (strchr(list_name, ',')) {
1408  char *list_name_dup = strdup(list_name);
1409  char *argv[100]; /* MAX ACL */
1410  int argc;
1411 
1412  switch_assert(list_name_dup);
1413 
1414  if ((argc = switch_separate_string(list_name_dup, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
1415  int i;
1416  for (i = 0; i < argc; i++) {
1417  switch_parse_cidr(argv[i], &net, &mask, &bits);
1418  if (ipv6) {
1419  if ((ok = switch_testv6_subnet(ip, net, mask))){
1420  break;
1421  }
1422  } else {
1423  if ((ok = switch_test_subnet(ip.v4, net.v4, mask.v4))) {
1424  break;
1425  }
1426  }
1427  }
1428  }
1429  free(list_name_dup);
1430  } else {
1431  switch_parse_cidr(list_name, &net, &mask, &bits);
1432 
1433  if (ipv6) {
1434  ok = switch_testv6_subnet(ip, net, mask);
1435  } else {
1436  ok = switch_test_subnet(ip.v4, net.v4, mask.v4);
1437  }
1438  }
1439  }
1440 
1441  switch_safe_free(ipv4);
1443 
1444  return ok;
1445 }
#define switch_test_subnet(_ip, _net, _mask)
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
switch_bool_t
Definition: switch_types.h:437
int switch_parse_cidr(const char *string, ip_t *ip, ip_t *mask, uint32_t *bitp)
Definition: switch_utils.c:743
switch_bool_t switch_network_list_validate_ip6_port_token(switch_network_list_t *list, ip_t ip, int port, const char **token)
Definition: switch_utils.c:497
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_hash_t * hash
Definition: switch_core.c:1369
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.
switch_bool_t switch_testv6_subnet(ip_t _ip, ip_t _net, ip_t _mask)
Definition: switch_utils.c:483
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
uint32_t v4
Definition: switch_utils.h:278
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
char * switch_network_ipv4_mapped_ipv6_addr(const char *ip_str)
Definition: switch_utils.c:582
static switch_ip_list_t IP_LIST
Definition: switch_core.c:1372
int switch_inet_pton(int af, const char *src, void *dst)
Definition: inet_pton.c:74
switch_mutex_t * global_mutex
char * ip
Definition: switch_msrp.c:60
switch_bool_t switch_network_list_validate_ip_port_token(switch_network_list_t *list, uint32_t ip, int port, const char **token)
Definition: switch_utils.c:546
#define switch_assert(expr)

◆ switch_check_network_list_ip_token()

switch_bool_t switch_check_network_list_ip_token ( const char *  ip_str,
const char *  list_name,
const char **  token 
)

Definition at line 1447 of file switch_core.c.

References switch_check_network_list_ip_port_token().

1448 {
1449  return switch_check_network_list_ip_port_token(ip_str, 0, list_name, token);
1450 }
switch_bool_t switch_check_network_list_ip_port_token(const char *ip_str, int port, const char *list_name, const char **token)
Definition: switch_core.c:1374

◆ switch_cond_next()

void switch_cond_next ( void  )

Definition at line 658 of file switch_time.c.

References do_sleep(), globals, mutex, runtime, switch_mutex_lock(), switch_mutex_unlock(), switch_os_yield(), switch_thread_cond_wait(), switch_runtime::timestamp, and switch_runtime::tipping_point.

Referenced by careful_set(), chat_thread_run(), check_dispatch(), handle_rfc2833(), qm_wake(), rtp_common_read(), sql_close(), switch_cache_db_execute_sql2str(), switch_channel_wait_for_app_flag(), switch_channel_wait_for_flag(), switch_channel_wait_for_state(), switch_channel_wait_for_state_timeout(), switch_console_save_history(), switch_core_file_read_video(), switch_core_memory_init(), switch_core_session_execute_application_get_flags(), switch_core_session_read_frame(), switch_core_session_read_text_frame(), switch_core_session_read_video_frame(), switch_core_session_start_text_thread(), switch_core_session_start_video_thread(), switch_core_session_wake_session_thread(), switch_ivr_collect_digits_callback(), switch_ivr_collect_digits_count(), switch_ivr_multi_threaded_bridge(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_wait_for_answer(), switch_log_init(), switch_log_shutdown(), switch_rtp_set_local_address(), switch_sql_queue_manager_start(), switch_stun_lookup(), switch_thread_pool_wait(), text_bridge_thread(), text_helper_thread(), and video_helper_thread().

659 {
660  if (runtime.tipping_point && globals.timer_count >= runtime.tipping_point) {
661  switch_os_yield();
662  return;
663  }
664 #ifdef DISABLE_1MS_COND
665  do_sleep(1000);
666 #else
667  if (globals.RUNNING != 1 || !runtime.timestamp || globals.use_cond_yield != 1) {
668  do_sleep(1000);
669  return;
670  }
674 #endif
675 }
void switch_os_yield(void)
Definition: switch_time.c:142
static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS+1]
Definition: switch_time.c:138
static struct @9 globals
switch_status_t switch_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex)
Definition: switch_apr.c:378
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_time_t timestamp
uint32_t tipping_point
static void do_sleep(switch_interval_time_t t)
Definition: switch_time.c:151
switch_mutex_t * mutex
Definition: switch_time.c:106

◆ switch_cond_yield()

void switch_cond_yield ( switch_interval_time_t  t)

Definition at line 677 of file switch_time.c.

References do_sleep(), globals, mutex, runtime, switch_mutex_lock(), switch_mutex_unlock(), switch_thread_cond_wait(), and switch_runtime::timestamp.

Referenced by switch_sleep().

678 {
679  switch_time_t want;
680  if (!t)
681  return;
682 
683  if (globals.RUNNING != 1 || !runtime.timestamp || globals.use_cond_yield != 1) {
684  do_sleep(t);
685  return;
686  }
687  want = runtime.timestamp + t;
688  while (globals.RUNNING == 1 && globals.use_cond_yield == 1 && runtime.timestamp < want) {
690  if (runtime.timestamp < want) {
692  }
694  }
695 
696 
697 }
static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS+1]
Definition: switch_time.c:138
static struct @9 globals
switch_status_t switch_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex)
Definition: switch_apr.c:378
struct switch_runtime runtime
Definition: switch_core.c:86
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
int64_t switch_time_t
Definition: switch_apr.h:188
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_time_t timestamp
static void do_sleep(switch_interval_time_t t)
Definition: switch_time.c:151
switch_mutex_t * mutex
Definition: switch_time.c:106

◆ switch_console_set_alias()

switch_status_t switch_console_set_alias ( const char *  string)

Definition at line 1919 of file switch_console.c.

References SCDB_TYPE_CORE_DB, switch_cache_db_get_type(), switch_cache_db_persistant_execute(), switch_cache_db_release_db_handle(), SWITCH_CHANNEL_LOG, switch_core_db_handle, switch_core_get_switchname(), SWITCH_LOG_ERROR, switch_log_printf(), switch_mprintf(), switch_safe_free, switch_separate_string(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

1920 {
1921  char *mydata = NULL, *argv[3] = { 0 };
1922  int argc;
1924 
1925  if (string && (mydata = strdup(string))) {
1926  if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 2) {
1927  switch_cache_db_handle_t *db = NULL;
1928  char *sql = NULL;
1929 
1930  if (argc > 2 && !strcmp(argv[1], argv[2])) {
1931  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Alias and command cannot be the same, this will cause loop!\n");
1932  return SWITCH_STATUS_FALSE;
1933  }
1934 
1937  free(mydata);
1938  return SWITCH_STATUS_FALSE;
1939  }
1940 
1941  if (!strcasecmp(argv[0], "stickyadd") && argc == 3) {
1942  sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_switchname());
1944  switch_safe_free(sql);
1946  sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%q','%q','%q')",
1947  argv[1], argv[2], switch_core_get_switchname());
1948  } else {
1949  sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%w','%w','%w')",
1950  argv[1], argv[2], switch_core_get_switchname());
1951  }
1953  status = SWITCH_STATUS_SUCCESS;
1954  } else if (!strcasecmp(argv[0], "add") && argc == 3) {
1955  sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_switchname());
1957  switch_safe_free(sql);
1959  sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%q','%q','%q')",
1960  argv[1], argv[2], switch_core_get_switchname());
1961  } else {
1962  sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%w','%w','%w')",
1963  argv[1], argv[2], switch_core_get_switchname());
1964  }
1966  status = SWITCH_STATUS_SUCCESS;
1967  } else if (!strcasecmp(argv[0], "del") && argc == 2) {
1968  char *what = argv[1];
1969  if (!strcasecmp(what, "*")) {
1970  sql = switch_mprintf("delete from aliases where hostname='%q'", switch_core_get_switchname());
1972  } else {
1973  sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_switchname());
1975  }
1976  status = SWITCH_STATUS_SUCCESS;
1977  }
1978  switch_safe_free(sql);
1980  }
1981  }
1982 
1983  switch_safe_free(mydata);
1984 
1985  return status;
1986 
1987 }
const char * switch_core_get_switchname(void)
Definition: switch_core.c:361
#define SWITCH_CHANNEL_LOG
void switch_cache_db_release_db_handle(switch_cache_db_handle_t **dbh)
Returns the handle to the pool, handle is NOT available to other threads until the allocating thread ...
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
switch_status_t switch_cache_db_persistant_execute(switch_cache_db_handle_t *dbh, const char *sql, uint32_t retries)
#define switch_core_db_handle(_a)
Definition: switch_core.h:2729
switch_status_t
Common return values.
switch_cache_db_handle_type_t switch_cache_db_get_type(switch_cache_db_handle_t *dbh)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)

◆ switch_console_set_complete()

switch_status_t switch_console_set_complete ( const char *  string)

Definition at line 1835 of file switch_console.c.

References switch_stream_handle::data, SCDB_TYPE_CORE_DB, SCF_USE_SQL, switch_core_dbtype(), switch_core_flags(), switch_core_get_hostname(), switch_core_sql_exec(), switch_safe_free, switch_separate_string(), SWITCH_STANDARD_STREAM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_str_nil, switch_stream_handle::write_function, and zstr.

Referenced by switch_msrp_load_apis_and_applications().

1836 {
1837  char *mydata = NULL, *argv[11] = { 0 };
1838  int argc, x;
1841 
1842  if (!(cflags & SCF_USE_SQL)) {
1843  return SWITCH_STATUS_FALSE;
1844  }
1845 
1846  if (string && (mydata = strdup(string))) {
1847  if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
1848  switch_stream_handle_t mystream = { 0 };
1849  SWITCH_STANDARD_STREAM(mystream);
1850 
1851  if (!strcasecmp(argv[0], "stickyadd")) {
1852  mystream.write_function(&mystream, "insert into complete (sticky, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, hostname) values (1,");
1853  for (x = 0; x < 10; x++) {
1854  if (argv[x + 1] && !strcasecmp(argv[x + 1], "_any_")) {
1855  mystream.write_function(&mystream, "%s", "'', ");
1856  } else {
1858  mystream.write_function(&mystream, "'%q', ", switch_str_nil(argv[x + 1]));
1859  } else {
1860  mystream.write_function(&mystream, "'%w', ", switch_str_nil(argv[x + 1]));
1861  }
1862  }
1863  }
1864  mystream.write_function(&mystream, " '%s')", switch_core_get_hostname());
1865  switch_core_sql_exec(mystream.data);
1866  status = SWITCH_STATUS_SUCCESS;
1867  } else if (!strcasecmp(argv[0], "add")) {
1868  mystream.write_function(&mystream, "insert into complete (sticky, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, hostname) values (0,");
1869  for (x = 0; x < 10; x++) {
1870  if (argv[x + 1] && !strcasecmp(argv[x + 1], "_any_")) {
1871  mystream.write_function(&mystream, "%s", "'', ");
1872  } else {
1874  mystream.write_function(&mystream, "'%q', ", switch_str_nil(argv[x + 1]));
1875  } else {
1876  mystream.write_function(&mystream, "'%w', ", switch_str_nil(argv[x + 1]));
1877  }
1878  }
1879  }
1880  mystream.write_function(&mystream, " '%s')", switch_core_get_hostname());
1881 
1882  switch_core_sql_exec(mystream.data);
1883  status = SWITCH_STATUS_SUCCESS;
1884  } else if (!strcasecmp(argv[0], "del")) {
1885  char *what = argv[1];
1886  if (zstr(what)) {
1887  switch_safe_free(mystream.data);
1888  switch_safe_free(mydata);
1889  return SWITCH_STATUS_FALSE;
1890  } else if (!strcasecmp(what, "*")) {
1891  mystream.write_function(&mystream, "delete from complete where hostname='%q'", switch_core_get_hostname());
1892  switch_core_sql_exec(mystream.data);
1893  } else {
1894  mystream.write_function(&mystream, "delete from complete where ");
1895  for (x = 0; x < argc - 1; x++) {
1897  mystream.write_function(&mystream, "a%d = '%q'%q", x + 1, switch_str_nil(argv[x + 1]), x == argc - 2 ? "" : " and ");
1898  } else {
1899  mystream.write_function(&mystream, "a%d = '%w'%w", x + 1, switch_str_nil(argv[x + 1]), x == argc - 2 ? "" : " and ");
1900  }
1901  }
1902  mystream.write_function(&mystream, " and hostname='%q'", switch_core_get_hostname());
1903  switch_core_sql_exec(mystream.data);
1904  }
1905  status = SWITCH_STATUS_SUCCESS;
1906  }
1907 
1908  switch_safe_free(mystream.data);
1909  }
1910  }
1911 
1912  switch_safe_free(mydata);
1913 
1914  return status;
1915 
1916 }
uint32_t switch_core_flag_t
Definition: switch_types.h:395
#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.
switch_core_flag_t switch_core_flags(void)
return core flags
Definition: switch_core.c:2988
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
#define SWITCH_STANDARD_STREAM(s)
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:993
void switch_core_sql_exec(const char *sql)
switch_stream_handle_write_function_t write_function
switch_status_t
Common return values.
const char * switch_core_get_hostname(void)
Definition: switch_core.c:356
switch_cache_db_handle_type_t switch_core_dbtype(void)

◆ switch_core_chat_deliver()

switch_status_t switch_core_chat_deliver ( const char *  dest_proto,
switch_event_t **  message_event 
)

Definition at line 1090 of file switch_loadable_module.c.

References chat_queue_message(), switch_event_add_header_string(), SWITCH_STACK_BOTTOM, and SWITCH_STATUS_SUCCESS.

1091 {
1092 
1093  if (dest_proto) {
1094  switch_event_add_header_string(*message_event, SWITCH_STACK_BOTTOM, "dest_proto", dest_proto);
1095  }
1096 
1097  chat_queue_message(message_event);
1098 
1099  return SWITCH_STATUS_SUCCESS;
1100 }
static void chat_queue_message(switch_event_t **eventp)
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.

◆ switch_core_chat_send()

switch_status_t switch_core_chat_send ( const char *  dest_proto,
switch_event_t message_event 
)

Definition at line 1075 of file switch_loadable_module.c.

References chat_queue_message(), switch_event_add_header_string(), switch_event_dup(), SWITCH_STACK_BOTTOM, and SWITCH_STATUS_SUCCESS.

Referenced by Event::chat_send().

1076 {
1077  switch_event_t *dup;
1078 
1079  switch_event_dup(&dup, message_event);
1080 
1081  if (dest_proto) {
1082  switch_event_add_header_string(dup, SWITCH_STACK_BOTTOM, "dest_proto", dest_proto);
1083  }
1084 
1085  chat_queue_message(&dup);
1086  return SWITCH_STATUS_SUCCESS;
1087 }
static void chat_queue_message(switch_event_t **eventp)
Representation of an event.
Definition: switch_event.h:80
switch_status_t switch_event_dup(switch_event_t **event, switch_event_t *todup)
Duplicate an event.
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.

◆ switch_core_chat_send_args()

switch_status_t switch_core_chat_send_args ( const char *  dest_proto,
const char *  proto,
const char *  from,
const char *  to,
const char *  subject,
const char *  body,
const char *  type,
const char *  hint,
switch_bool_t  blocking 
)

Definition at line 1033 of file switch_loadable_module.c.

References chat_process_event(), chat_queue_message(), switch_event_add_body(), switch_event_add_header_string(), switch_event_create, SWITCH_EVENT_MESSAGE, SWITCH_STACK_BOTTOM, and SWITCH_STATUS_SUCCESS.

1035 {
1036  switch_event_t *message_event;
1037  switch_status_t status;
1038 
1040  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "proto", proto);
1041  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "from", from);
1042  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "to", to);
1043  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "subject", subject);
1044  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "type", type);
1045  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "hint", hint);
1046  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "skip_global_process", "true");
1047  if (blocking) {
1048  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "blocking", "true");
1049  }
1050 
1051  if (body) {
1052  switch_event_add_body(message_event, "%s", body);
1053  }
1054  } else {
1055  abort();
1056  }
1057 
1058  if (dest_proto) {
1059  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "dest_proto", dest_proto);
1060  }
1061 
1062 
1063  if (blocking) {
1064  status = chat_process_event(&message_event);
1065  } else {
1066  chat_queue_message(&message_event);
1067  status = SWITCH_STATUS_SUCCESS;
1068  }
1069 
1070  return status;
1071 
1072 }
static void chat_queue_message(switch_event_t **eventp)
cJSON *const to
Representation of an event.
Definition: switch_event.h:80
switch_status_t switch_event_add_body(switch_event_t *event, const char *fmt,...) PRINTF_FUNCTION(2
Add a body to an event.
static switch_status_t chat_process_event(switch_event_t **eventp)
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.
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

◆ switch_core_data_channel()

FILE* switch_core_data_channel ( switch_text_channel_t  channel)

Retrieve a FILE stream of a given text channel name.

Parameters
channeltext channel enumeration
Returns
a FILE stream

Definition at line 286 of file switch_core.c.

References switch_runtime::console.

Referenced by switch_console_printf(), and switch_log_meta_vprintf().

287 {
288  return runtime.console;
289 }
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_default_dtmf_duration()

uint32_t switch_core_default_dtmf_duration ( uint32_t  duration)

Definition at line 1721 of file switch_core.c.

References switch_runtime::default_dtmf_duration, switch_runtime::max_dtmf_duration, switch_runtime::min_dtmf_duration, SWITCH_MAX_DTMF_DURATION, and SWITCH_MIN_DTMF_DURATION.

Referenced by inband_dtmf_generate_callback(), speech_thread(), switch_channel_dequeue_dtmf(), switch_channel_queue_dtmf(), switch_channel_queue_dtmf_string(), switch_core_session_ctl(), switch_core_session_recv_dtmf(), switch_core_session_send_dtmf(), switch_core_session_send_dtmf_string(), and switch_load_core_config().

1722 {
1723  if (duration) {
1724  if (duration < SWITCH_MIN_DTMF_DURATION) {
1725  duration = SWITCH_MIN_DTMF_DURATION;
1726  }
1727  if (duration > SWITCH_MAX_DTMF_DURATION) {
1728  duration = SWITCH_MAX_DTMF_DURATION;
1729  }
1730  runtime.default_dtmf_duration = duration;
1731 
1732  if (duration < runtime.min_dtmf_duration) {
1733  runtime.min_dtmf_duration = duration;
1734  }
1735 
1736  if (duration > runtime.max_dtmf_duration) {
1737  runtime.max_dtmf_duration = duration;
1738  }
1739 
1740  }
1742 }
uint32_t min_dtmf_duration
struct switch_runtime runtime
Definition: switch_core.c:86
#define SWITCH_MAX_DTMF_DURATION
Definition: switch_types.h:119
uint32_t max_dtmf_duration
#define SWITCH_MIN_DTMF_DURATION
Definition: switch_types.h:118
uint32_t default_dtmf_duration

◆ switch_core_flags()

switch_core_flag_t switch_core_flags ( void  )

return core flags

Returns
core flags

Definition at line 2988 of file switch_core.c.

References switch_runtime::flags.

Referenced by do_shutdown(), switch_console_expand_alias(), and switch_console_set_complete().

2989 {
2990  return runtime.flags;
2991 }
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_get_console()

FILE* switch_core_get_console ( void  )

Get the output console.

Returns
the FILE stream

Definition at line 253 of file switch_core.c.

References switch_runtime::console.

Referenced by switch_console_process(), switch_console_save_history(), and switch_log_init().

254 {
255  return runtime.console;
256 }
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_idle_cpu()

double switch_core_idle_cpu ( void  )

Definition at line 2611 of file switch_core_session.c.

References switch_runtime::profile_time, and runtime.

Referenced by send_heartbeat(), and switch_log_meta_vprintf().

2612 {
2613  return runtime.profile_time;
2614 }
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_launch_thread()

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

◆ switch_core_management_exec()

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.

Parameters
relative_oidthe relative oid of the operation.
actionthe action to perform.
datainput/output string.
datalensize in bytes of data.
Returns
SUCCESS on sucess.

Definition at line 3118 of file switch_core.c.

References switch_management_interface::management_function, switch_loadable_module_get_management_interface(), and SWITCH_STATUS_FALSE.

3119 {
3120  const switch_management_interface_t *ptr;
3122 
3123  if ((ptr = switch_loadable_module_get_management_interface(relative_oid))) {
3124  status = ptr->management_function(relative_oid, action, data, datalen);
3125  }
3126 
3127  return status;
3128 }
switch_management_interface_t * switch_loadable_module_get_management_interface(const char *relative_oid)
Retrieve the management interface by it&#39;s registered name.
Abstract interface to a management module.
switch_status_t
Common return values.
switch_status_t(* management_function)(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)

◆ switch_core_max_dtmf_duration()

uint32_t switch_core_max_dtmf_duration ( uint32_t  duration)

Definition at line 1704 of file switch_core.c.

References switch_runtime::max_dtmf_duration, switch_runtime::min_dtmf_duration, SWITCH_MAX_DTMF_DURATION, and SWITCH_MIN_DTMF_DURATION.

Referenced by inband_dtmf_generate_callback(), switch_channel_dequeue_dtmf(), switch_channel_queue_dtmf(), switch_channel_queue_dtmf_string(), switch_core_session_ctl(), switch_core_session_recv_dtmf(), switch_core_session_send_dtmf(), switch_core_session_send_dtmf_string(), and switch_load_core_config().

1705 {
1706  if (duration) {
1707  if (duration > SWITCH_MAX_DTMF_DURATION) {
1708  duration = SWITCH_MAX_DTMF_DURATION;
1709  }
1710  if (duration < SWITCH_MIN_DTMF_DURATION) {
1711  duration = SWITCH_MIN_DTMF_DURATION;
1712  }
1713  runtime.max_dtmf_duration = duration;
1714  if (duration < runtime.min_dtmf_duration) {
1715  runtime.min_dtmf_duration = duration;
1716  }
1717  }
1718  return runtime.max_dtmf_duration;
1719 }
uint32_t min_dtmf_duration
struct switch_runtime runtime
Definition: switch_core.c:86
#define SWITCH_MAX_DTMF_DURATION
Definition: switch_types.h:119
uint32_t max_dtmf_duration
#define SWITCH_MIN_DTMF_DURATION
Definition: switch_types.h:118

◆ switch_core_measure_time()

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.

Parameters
total_msa number of milliseconds
durationan object to store the results

Definition at line 2535 of file switch_core.c.

References switch_core_time_duration::day, switch_core_time_duration::hr, memset(), switch_core_time_duration::min, switch_core_time_duration::mms, switch_core_time_duration::ms, switch_core_time_duration::sec, and switch_core_time_duration::yr.

Referenced by send_heartbeat().

2536 {
2537  switch_time_t temp = total_ms / 1000;
2538  memset(duration, 0, sizeof(*duration));
2539  duration->mms = (uint32_t) (total_ms % 1000);
2540  duration->ms = (uint32_t) (temp % 1000);
2541  temp = temp / 1000;
2542  duration->sec = (uint32_t) (temp % 60);
2543  temp = temp / 60;
2544  duration->min = (uint32_t) (temp % 60);
2545  temp = temp / 60;
2546  duration->hr = (uint32_t) (temp % 24);
2547  temp = temp / 24;
2548  duration->day = (uint32_t) (temp % 365);
2549  duration->yr = (uint32_t) (temp / 365);
2550 }
int64_t switch_time_t
Definition: switch_apr.h:188
memset(buf, 0, buflen)

◆ switch_core_memory_reclaim()

void switch_core_memory_reclaim ( void  )

Definition at line 554 of file switch_core_memory.c.

References memory_manager, pool, SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_size(), switch_queue_trypop(), and SWITCH_STATUS_SUCCESS.

Referenced by pool_thread(), and switch_core_memory_reclaim_all().

555 {
556 #if !defined(PER_POOL_LOCK) && !defined(INSTANTLY_DESTROY_POOLS)
558  void *pop = NULL;
559  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled memory pool(s)\n",
560  switch_queue_size(memory_manager.pool_recycle_queue) + switch_queue_size(memory_manager.pool_queue));
561 
562  while (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS) {
563  pool = (switch_memory_pool_t *) pop;
564  if (!pool) {
565  break;
566  }
567 #ifdef USE_MEM_LOCK
569 #endif
570  fspr_pool_destroy(pool);
571 #ifdef USE_MEM_LOCK
573 #endif
574  }
575 #endif
576  return;
577 }
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1238
#define SWITCH_CHANNEL_LOG
switch_memory_pool_t * pool
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
static struct @3 memory_manager
switch_status_t switch_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
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
struct fspr_pool_t switch_memory_pool_t

◆ switch_core_memory_reclaim_all()

void switch_core_memory_reclaim_all ( void  )

Definition at line 3130 of file switch_core.c.

References switch_core_memory_reclaim(), switch_core_memory_reclaim_events(), and switch_core_memory_reclaim_logger().

Referenced by switch_core_session_ctl().

3131 {
3135 }
void switch_core_memory_reclaim_logger(void)
Definition: switch_log.c:783
void switch_core_memory_reclaim_events(void)
Definition: switch_event.c:524
void switch_core_memory_reclaim(void)

◆ switch_core_memory_reclaim_events()

void switch_core_memory_reclaim_events ( void  )

Definition at line 524 of file switch_event.c.

References SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(), switch_queue_size(), switch_queue_trypop(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_memory_reclaim_all(), and switch_event_shutdown().

525 {
526 #ifdef SWITCH_EVENT_RECYCLE
527 
528  void *pop;
529  int size;
530  size = switch_queue_size(EVENT_RECYCLE_QUEUE);
531 
532  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled event(s) %d bytes\n", size, (int) sizeof(switch_event_t) * size);
533  size = switch_queue_size(EVENT_HEADER_RECYCLE_QUEUE);
534  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled event header(s) %d bytes\n",
535  size, (int) sizeof(switch_event_header_t) * size);
536 
537  while (switch_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS && pop) {
538  free(pop);
539  }
540  while (switch_queue_trypop(EVENT_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS && pop) {
541  free(pop);
542  }
543 #else
544  return;
545 #endif
546 
547 }
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1238
#define SWITCH_CHANNEL_LOG
Representation of an event.
Definition: switch_event.h:80
An event Header.
Definition: switch_event.h:65
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.

◆ switch_core_memory_reclaim_logger()

void switch_core_memory_reclaim_logger ( void  )

Definition at line 783 of file switch_log.c.

References SWITCH_CHANNEL_SESSION_LOG, SWITCH_LOG_CONSOLE, switch_log_node_free(), switch_log_printf(), switch_queue_size(), switch_queue_trypop(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_memory_reclaim_all(), and switch_log_shutdown().

784 {
785 #ifdef SWITCH_LOG_RECYCLE
786  void *pop;
787  int size = switch_queue_size(LOG_RECYCLE_QUEUE);
788  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CONSOLE, "Returning %d recycled log node(s) %d bytes\n", size,
789  (int) sizeof(switch_log_node_t) * size);
790  while (switch_queue_trypop(LOG_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
791  switch_log_node_free(&pop);
792  }
793 #else
794  return;
795 #endif
796 
797 }
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1238
#define SWITCH_CHANNEL_SESSION_LOG(x)
Log Data.
Definition: switch_log.h:49
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
void switch_log_printf(switch_text_channel_t channel, const char *file, const char *func, int line, const char *userdata, switch_log_level_t level, const char *fmt,...)
Definition: switch_log.c:538
void switch_log_node_free(switch_log_node_t **pnode)
Definition: switch_log.c:300

◆ switch_core_mime_add_type()

switch_status_t switch_core_mime_add_type ( const char *  type,
const char *  ext 
)

Definition at line 1232 of file switch_core.c.

References switch_runtime::mime_type_exts, switch_runtime::mime_types, switch_assert, switch_core_hash_find(), switch_core_hash_insert, switch_core_permanent_strdup, switch_separate_string(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by load_mime_types().

1233 {
1234  char *ptype = NULL;
1235  char *ext_list = NULL;
1236  int argc = 0;
1237  char *argv[20] = { 0 };
1238  int x;
1240 
1241  switch_assert(type);
1242  switch_assert(ext);
1243 
1244  ptype = switch_core_permanent_strdup(type);
1245  ext_list = strdup(ext);
1246 
1247  switch_assert(ext_list);
1248 
1249  /* Map each file extension to this MIME type if not already mapped. Map the MIME type to the first file extension in the list if not already mapped. */
1250  if ((argc = switch_separate_string(ext_list, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
1251  int is_mapped_type = switch_core_hash_find(runtime.mime_type_exts, ptype) != NULL;
1252  for (x = 0; x < argc; x++) {
1253  if (argv[x] && ptype) {
1255  switch_core_hash_insert(runtime.mime_types, argv[x], ptype);
1256  }
1257  if (!is_mapped_type) {
1259  is_mapped_type = 1;
1260  }
1261  }
1262  }
1263 
1264  status = SWITCH_STATUS_SUCCESS;
1265  }
1266 
1267  free(ext_list);
1268 
1269  return status;
1270 }
#define switch_core_permanent_strdup(_todup)
Copy a string using permanent memory allocation.
Definition: switch_core.h:707
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
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.
switch_hash_t * mime_type_exts
switch_hash_t * mime_types
switch_status_t
Common return values.
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1479
#define switch_assert(expr)

◆ switch_core_mime_ext2type()

const char* switch_core_mime_ext2type ( const char *  ext)

Definition at line 1211 of file switch_core.c.

References switch_runtime::mime_types, and switch_core_hash_find().

Referenced by switch_simple_email().

1212 {
1213  if (!ext) {
1214  return NULL;
1215  }
1216  return (const char *) switch_core_hash_find(runtime.mime_types, ext);
1217 }
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 * mime_types

◆ switch_core_mime_index()

switch_hash_index_t* switch_core_mime_index ( void  )

Definition at line 1227 of file switch_core.c.

References switch_runtime::mime_types, and switch_core_hash_first.

1228 {
1230 }
struct switch_runtime runtime
Definition: switch_core.c:86
switch_hash_t * mime_types
#define switch_core_hash_first(_h)
Definition: switch_core.h:1592

◆ switch_core_mime_type2ext()

const char* switch_core_mime_type2ext ( const char *  type)

Definition at line 1219 of file switch_core.c.

References switch_runtime::mime_type_exts, and switch_core_hash_find().

1220 {
1221  if (!mime) {
1222  return NULL;
1223  }
1224  return (const char *) switch_core_hash_find(runtime.mime_type_exts, mime);
1225 }
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 * mime_type_exts

◆ switch_core_min_dtmf_duration()

uint32_t switch_core_min_dtmf_duration ( uint32_t  duration)

Definition at line 1744 of file switch_core.c.

References switch_runtime::max_dtmf_duration, switch_runtime::min_dtmf_duration, SWITCH_MAX_DTMF_DURATION, and SWITCH_MIN_DTMF_DURATION.

Referenced by handle_rfc2833(), switch_channel_dequeue_dtmf(), switch_channel_queue_dtmf(), switch_channel_queue_dtmf_string(), switch_core_session_ctl(), switch_core_session_recv_dtmf(), switch_core_session_send_dtmf(), switch_core_session_send_dtmf_string(), switch_load_core_config(), switch_rtp_queue_rfc2833(), and switch_rtp_queue_rfc2833_in().

1745 {
1746  if (duration) {
1747  if (duration < SWITCH_MIN_DTMF_DURATION) {
1748  duration = SWITCH_MIN_DTMF_DURATION;
1749  }
1750  if (duration > SWITCH_MAX_DTMF_DURATION) {
1751  duration = SWITCH_MAX_DTMF_DURATION;
1752  }
1753 
1754  runtime.min_dtmf_duration = duration;
1755 
1756  if (duration > runtime.max_dtmf_duration) {
1757  runtime.max_dtmf_duration = duration;
1758  }
1759  }
1760  return runtime.min_dtmf_duration;
1761 }
uint32_t min_dtmf_duration
struct switch_runtime runtime
Definition: switch_core.c:86
#define SWITCH_MAX_DTMF_DURATION
Definition: switch_types.h:119
uint32_t max_dtmf_duration
#define SWITCH_MIN_DTMF_DURATION
Definition: switch_types.h:118

◆ switch_core_min_idle_cpu()

double switch_core_min_idle_cpu ( double  new_limit)

Definition at line 2601 of file switch_core_session.c.

References switch_runtime::min_idle_time, and runtime.

Referenced by switch_core_session_ctl(), and switch_load_core_config().

2602 {
2603  if (new_limit >= 0) {
2604  runtime.min_idle_time = new_limit;
2605  }
2606 
2607  return runtime.min_idle_time;
2608 }
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_ready()

switch_bool_t switch_core_ready ( void  )

Determines if the core is ready to take calls.

Returns
SWITCH_TRUE or SWITCH_FALSE

Definition at line 2998 of file switch_core.c.

References SCF_NO_NEW_SESSIONS, SCF_SHUTTING_DOWN, SWITCH_FALSE, switch_test_flag, and SWITCH_TRUE.

Referenced by switch_core_session_ctl(), and switch_core_session_request_uuid().

2999 {
3001 }
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_core_ready_inbound()

switch_bool_t switch_core_ready_inbound ( void  )

Determines if the core is ready to take inbound calls.

Returns
SWITCH_TRUE or SWITCH_FALSE

Definition at line 3003 of file switch_core.c.

References SCF_NO_NEW_INBOUND_SESSIONS, SCF_SHUTTING_DOWN, SWITCH_FALSE, switch_test_flag, and SWITCH_TRUE.

Referenced by switch_core_session_request_uuid().

3004 {
3006 }
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_core_ready_outbound()

switch_bool_t switch_core_ready_outbound ( void  )

Determines if the core is ready to place outbound calls.

Returns
SWITCH_TRUE or SWITCH_FALSE

Definition at line 3008 of file switch_core.c.

References SCF_NO_NEW_OUTBOUND_SESSIONS, SCF_SHUTTING_DOWN, SWITCH_FALSE, switch_test_flag, and SWITCH_TRUE.

Referenced by switch_core_session_request_uuid().

3009 {
3011 }
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_core_running()

switch_bool_t switch_core_running ( void  )

Definition at line 2993 of file switch_core.c.

References switch_runtime::running, SWITCH_FALSE, and SWITCH_TRUE.

Referenced by running().

2994 {
2996 }
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_runtime_loop()

void switch_core_runtime_loop ( int  bg)

Run endlessly until the system is shutdown.

Parameters
bgdivert console to the background

Definition at line 1187 of file switch_core.c.

References FALSE, path, switch_runtime::running, switch_console_loop(), switch_snprintf(), and switch_yield.

Referenced by main().

1188 {
1189 #ifdef WIN32
1190  HANDLE shutdown_event;
1191  char path[256] = "";
1192 #endif
1193  if (bg) {
1194 #ifdef WIN32
1195  switch_snprintf(path, sizeof(path), "Global\\Freeswitch.%d", getpid());
1196  shutdown_event = CreateEvent(NULL, FALSE, FALSE, path);
1197  if (shutdown_event) {
1198  WaitForSingleObject(shutdown_event, INFINITE);
1199  }
1200 #else
1201  while (runtime.running) {
1202  switch_yield(1000000);
1203  }
1204 #endif
1205  } else {
1206  /* wait for console input */
1208  }
1209 }
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
struct switch_runtime runtime
Definition: switch_core.c:86
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
const char *const const char *const path
#define FALSE
void switch_console_loop(void)
A simple comand loop that reads input from the terminal.

◆ switch_core_session_check_interface()

uint8_t switch_core_session_check_interface ( switch_core_session_t session,
const switch_endpoint_interface_t endpoint_interface 
)

Checks if a session is using a specific endpoint.

Parameters
sessionthe session
endpoint_interfaceinterface of the endpoint to check
Returns
TRUE or FALSE

Definition at line 2572 of file switch_core_session.c.

References switch_core_session::endpoint_interface, and switch_assert.

2573 {
2574  switch_assert(session != NULL);
2575  switch_assert(endpoint_interface != NULL);
2576 
2577  return (uint8_t) (session->endpoint_interface == endpoint_interface);
2578 }
switch_endpoint_interface_t * endpoint_interface
#define switch_assert(expr)

◆ switch_core_session_compare()

uint8_t switch_core_session_compare ( switch_core_session_t a,
switch_core_session_t b 
)

Checks if 2 sessions are using the same endpoint module.

Parameters
athe first session
bthe second session
Returns
TRUE or FALSE

Definition at line 2564 of file switch_core_session.c.

References switch_core_session::endpoint_interface, and switch_assert.

2565 {
2566  switch_assert(a != NULL);
2567  switch_assert(b != NULL);
2568 
2569  return (uint8_t) (a->endpoint_interface == b->endpoint_interface);
2570 }
switch_endpoint_interface_t * endpoint_interface
#define switch_assert(expr)

◆ switch_core_session_ctl()

int32_t switch_core_session_ctl ( switch_session_ctl_t  cmd,
void *  val 
)

send a control message to the core

Parameters
cmdthe command
valthe command arguement (if needed)
Returns
0 on success nonzero on error

Definition at line 2651 of file switch_core.c.

References count, switch_runtime::debug_level, handle_SIGHUP(), switch_runtime::hard_log_level, switch_runtime::running, SCF_API_EXPANSION, SCF_DEBUG_SQL, SCF_NO_NEW_INBOUND_SESSIONS, SCF_NO_NEW_OUTBOUND_SESSIONS, SCF_NO_NEW_SESSIONS, SCF_RESTART, SCF_SHUTDOWN_REQUESTED, SCF_SHUTTING_DOWN, SCF_THREADED_SYSTEM_EXEC, SCF_VERBOSE_EVENTS, SCSC_API_EXPANSION, SCSC_CALIBRATE_CLOCK, SCSC_CANCEL_SHUTDOWN, SCSC_CHECK_RUNNING, SCSC_CRASH, SCSC_DEBUG_LEVEL, SCSC_DEBUG_SQL, SCSC_DEFAULT_DTMF_DURATION, SCSC_FLUSH_DB_HANDLES, SCSC_HUPALL, SCSC_LAST_SPS, SCSC_LOGLEVEL, SCSC_MAX_DTMF_DURATION, SCSC_MAX_SESSIONS, SCSC_MDNS_RESOLVE, SCSC_MIN_DTMF_DURATION, SCSC_MIN_IDLE_CPU, SCSC_PAUSE_ALL, SCSC_PAUSE_CHECK, SCSC_PAUSE_INBOUND, SCSC_PAUSE_INBOUND_CHECK, SCSC_PAUSE_OUTBOUND, SCSC_PAUSE_OUTBOUND_CHECK, SCSC_READY_CHECK, SCSC_RECLAIM, SCSC_RECOVER, SCSC_REINCARNATE_NOW, SCSC_SAVE_HISTORY, SCSC_SEND_SIGHUP, SCSC_SESSIONS_PEAK, SCSC_SESSIONS_PEAK_FIVEMIN, SCSC_SHUTDOWN, SCSC_SHUTDOWN_ASAP, SCSC_SHUTDOWN_CAUSE, SCSC_SHUTDOWN_CHECK, SCSC_SHUTDOWN_ELEGANT, SCSC_SHUTDOWN_NOW, SCSC_SPS, SCSC_SPS_PEAK, SCSC_SPS_PEAK_FIVEMIN, SCSC_SQL, SCSC_SYNC_CLOCK, SCSC_SYNC_CLOCK_WHEN_IDLE, SCSC_THREADED_SYSTEM_EXEC, SCSC_VERBOSE_EVENTS, switch_runtime::sessions_peak, switch_runtime::sessions_peak_fivemin, switch_runtime::shutdown_cause, switch_runtime::sps_last, switch_runtime::sps_peak, switch_runtime::sps_peak_fivemin, switch_runtime::sps_total, switch_assert, switch_cache_db_flush_handles(), SWITCH_CAUSE_MANAGER_REQUEST, SWITCH_CHANNEL_LOG, switch_clear_flag, switch_console_save_history(), switch_core_default_dtmf_duration(), switch_core_max_dtmf_duration(), switch_core_media_set_resolveice(), switch_core_memory_reclaim_all(), switch_core_min_dtmf_duration(), switch_core_min_idle_cpu(), switch_core_ready(), switch_core_recovery_flush(), switch_core_recovery_recover(), switch_core_session_count(), switch_core_session_hupall(), switch_core_session_limit(), switch_core_session_sync_clock(), switch_core_sqldb_pause(), switch_core_sqldb_resume(), switch_event_add_header(), switch_event_create, switch_event_fire, SWITCH_EVENT_SHUTDOWN_REQUESTED, SWITCH_LOG_CRIT, SWITCH_LOG_DEBUG, SWITCH_LOG_DISABLE, SWITCH_LOG_INFO, switch_log_printf(), SWITCH_LOG_WARNING, switch_mutex_lock(), switch_mutex_unlock(), switch_safe_free, switch_set_flag, SWITCH_STACK_BOTTOM, SWITCH_STATUS_RESTART, SWITCH_STATUS_SUCCESS, switch_test_flag, switch_time_calibrate_clock(), switch_time_sync(), switch_yield, switch_runtime::throttle_mutex, and zstr.

Referenced by handle_SIGILL(), handle_SIGTERM(), switch_channel_event_set_extended_data(), switch_console_loop(), switch_console_save_history(), and switch_load_core_config().

2652 {
2653  int *intval = (int *) val;
2654  int oldintval = 0, newintval = 0;
2655 
2656  if (intval) {
2657  oldintval = *intval;
2658  }
2659 
2661  return -1;
2662  }
2663 
2664  switch (cmd) {
2665  case SCSC_RECOVER:
2666  {
2667  char *arg = (char *) val;
2668  char *tech = NULL, *prof = NULL;
2669  int r, flush = 0;
2670 
2671  if (!zstr(arg)) {
2672  tech = strdup(arg);
2673  switch_assert(tech);
2674 
2675  if ((prof = strchr(tech, ':'))) {
2676  *prof++ = '\0';
2677  }
2678 
2679  if (!strcasecmp(tech, "flush")) {
2680  flush++;
2681 
2682  if (prof) {
2683  char *tech = prof;
2684  if ((prof = strchr(tech, ':'))) {
2685  *prof++ = '\0';
2686  }
2687  }
2688  }
2689 
2690  }
2691 
2692  if (flush) {
2693  switch_core_recovery_flush(tech, prof);
2694  r = -1;
2695  } else {
2696  r = switch_core_recovery_recover(tech, prof);
2697  }
2698 
2699  switch_safe_free(tech);
2700  return r;
2701 
2702  }
2703  break;
2704  case SCSC_DEBUG_SQL:
2705  {
2708  newintval = 0;
2709  } else {
2711  newintval = 1;
2712  }
2713  }
2714  break;
2715  case SCSC_VERBOSE_EVENTS:
2716  if (intval) {
2717  if (oldintval > -1) {
2718  if (oldintval) {
2720  } else {
2722  }
2723  }
2724  newintval = switch_test_flag((&runtime), SCF_VERBOSE_EVENTS);
2725  }
2726  break;
2727  case SCSC_API_EXPANSION:
2728  if (intval) {
2729  if (oldintval > -1) {
2730  if (oldintval) {
2732  } else {
2734  }
2735  }
2736  newintval = switch_test_flag((&runtime), SCF_API_EXPANSION);
2737  }
2738  break;
2740  if (intval) {
2741  if (oldintval > -1) {
2742  if (oldintval) {
2744  } else {
2746  }
2747  }
2749  }
2750  break;
2751  case SCSC_CALIBRATE_CLOCK:
2753  break;
2754  case SCSC_FLUSH_DB_HANDLES:
2756  break;
2757  case SCSC_SEND_SIGHUP:
2758  handle_SIGHUP(1);
2759  break;
2760  case SCSC_SYNC_CLOCK:
2761  switch_time_sync();
2762  newintval = 0;
2763  break;
2765  newintval = switch_core_session_sync_clock();
2766  break;
2767  case SCSC_SQL:
2768  if (oldintval) {
2770  } else {
2772  }
2773  break;
2774  case SCSC_PAUSE_ALL:
2775  if (oldintval) {
2777  } else {
2779  }
2780  break;
2781  case SCSC_PAUSE_INBOUND:
2782  if (oldintval) {
2784  } else {
2786  }
2787  break;
2788  case SCSC_PAUSE_OUTBOUND:
2789  if (oldintval) {
2791  } else {
2793  }
2794  break;
2795  case SCSC_HUPALL:
2797  break;
2798  case SCSC_CANCEL_SHUTDOWN:
2800  break;
2801  case SCSC_SAVE_HISTORY:
2803  break;
2804  case SCSC_CRASH:
2805  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Declinatio Mortuus Obfirmo!\n");
2807  abort();
2808  break;
2809  case SCSC_SHUTDOWN_NOW:
2811  exit(0);
2812  break;
2813  case SCSC_REINCARNATE_NOW:
2815  exit(SWITCH_STATUS_RESTART);
2816  break;
2817  case SCSC_SHUTDOWN_ELEGANT:
2818  case SCSC_SHUTDOWN_ASAP:
2819  {
2820  int x = 19;
2821  uint32_t count;
2822  switch_event_t *shutdown_requested_event = NULL;
2823  if (switch_event_create(&shutdown_requested_event, SWITCH_EVENT_SHUTDOWN_REQUESTED) == SWITCH_STATUS_SUCCESS) {
2824  switch_event_add_header(shutdown_requested_event, SWITCH_STACK_BOTTOM, "Event-Info", "%s", cmd == SCSC_SHUTDOWN_ASAP ? "ASAP" : "elegant");
2825  switch_event_fire(&shutdown_requested_event);
2826  }
2828  if (cmd == SCSC_SHUTDOWN_ASAP) {
2830  }
2831 
2833  switch_yield(500000);
2834  if (++x == 20) {
2836  "Shutdown in progress, %u session(s) remain.\nShutting down %s\n",
2837  count, cmd == SCSC_SHUTDOWN_ASAP ? "ASAP" : "once there are no active calls.");
2838  x = 0;
2839  }
2840  }
2841 
2844 #ifdef _MSC_VER
2845  win_shutdown();
2846 #endif
2847 
2848  if (oldintval) {
2851  } else {
2853 #ifdef HAVE_SYSTEMD
2854  sd_notifyf(0, "STOPPING=1\n");
2855 #endif
2856 #ifdef _MSC_VER
2857  fclose(stdin);
2858 #endif
2859  }
2860  runtime.running = 0;
2861  } else {
2862  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Shutdown Cancelled\n");
2864  }
2865  }
2866  break;
2867  case SCSC_PAUSE_CHECK:
2869  break;
2872  break;
2875  break;
2876  case SCSC_READY_CHECK:
2877  newintval = switch_core_ready();
2878  break;
2879  case SCSC_SHUTDOWN_CHECK:
2880  newintval = !!switch_test_flag((&runtime), SCF_SHUTDOWN_REQUESTED);
2881  break;
2882  case SCSC_SHUTDOWN:
2883 
2884 #ifdef _MSC_VER
2885  win_shutdown();
2886 #endif
2887 
2888  if (oldintval) {
2891  } else {
2893 #ifdef _MSC_VER
2894  fclose(stdin);
2895 #endif
2896  }
2897  runtime.running = 0;
2898  break;
2899  case SCSC_CHECK_RUNNING:
2900  newintval = runtime.running;
2901  break;
2902  case SCSC_LOGLEVEL:
2903  if (oldintval >= SWITCH_LOG_DISABLE) {
2904  runtime.hard_log_level = oldintval;
2905  }
2906 
2909  }
2910  newintval = runtime.hard_log_level;
2911  break;
2912  case SCSC_DEBUG_LEVEL:
2913  if (oldintval > -1) {
2914  if (oldintval > 10)
2915  oldintval = 10;
2916  runtime.debug_level = oldintval;
2917  }
2918  newintval = runtime.debug_level;
2919  break;
2920  case SCSC_MIN_IDLE_CPU:
2921  {
2922  double *dval = (double *) val;
2923  if (dval) {
2924  *dval = switch_core_min_idle_cpu(*dval);
2925  }
2926  intval = NULL;
2927  }
2928  break;
2929  case SCSC_MAX_SESSIONS:
2930  newintval = switch_core_session_limit(oldintval);
2931  break;
2932  case SCSC_LAST_SPS:
2933  newintval = runtime.sps_last;
2934  break;
2935  case SCSC_SPS_PEAK:
2936  if (oldintval == -1) {
2937  runtime.sps_peak = 0;
2938  }
2939  newintval = runtime.sps_peak;
2940  break;
2941  case SCSC_SPS_PEAK_FIVEMIN:
2942  newintval = runtime.sps_peak_fivemin;
2943  break;
2944  case SCSC_SESSIONS_PEAK:
2945  newintval = runtime.sessions_peak;
2946  break;
2948  newintval = runtime.sessions_peak_fivemin;
2949  break;
2951  newintval = switch_core_max_dtmf_duration(oldintval);
2952  break;
2954  newintval = switch_core_min_dtmf_duration(oldintval);
2955  break;
2957  newintval = switch_core_default_dtmf_duration(oldintval);
2958  break;
2959  case SCSC_SPS:
2961  if (oldintval > 0) {
2962  runtime.sps_total = oldintval;
2963  }
2964  newintval = runtime.sps_total;
2966  break;
2967 
2968  case SCSC_RECLAIM:
2970  newintval = 0;
2971  break;
2972  case SCSC_MDNS_RESOLVE:
2973  switch_core_media_set_resolveice(!!oldintval);
2974  break;
2975  case SCSC_SHUTDOWN_CAUSE:
2976  runtime.shutdown_cause = oldintval;
2977  break;
2978  }
2979 
2980  if (intval) {
2981  *intval = newintval;
2982  }
2983 
2984 
2985  return 0;
2986 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
void switch_time_sync(void)
Definition: switch_time.c:609
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
#define SWITCH_CHANNEL_LOG
int switch_core_session_sync_clock(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
switch_mutex_t * throttle_mutex
switch_call_cause_t shutdown_cause
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
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#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
int32_t sessions_peak_fivemin
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
void switch_core_session_hupall(_In_ switch_call_cause_t cause)
Hangup all sessions.
void switch_core_memory_reclaim_all(void)
Definition: switch_core.c:3130
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
void switch_core_sqldb_resume(void)
uint32_t switch_core_session_count(void)
Provide the total number of sessions.
double switch_core_min_idle_cpu(double new_limit)
static void handle_SIGHUP(int sig)
Definition: switch_core.c:2008
void switch_core_sqldb_pause(void)
void switch_cache_db_flush_handles(void)
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_console_save_history(void)
switch_log_level_t hard_log_level
void switch_time_calibrate_clock(void)
Definition: switch_time.c:208
#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_recovery_flush(const char *technology, const char *profile_name)
#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.
uint32_t debug_level
int count
Definition: switch_cJSON.h:204
#define switch_assert(expr)
int switch_core_recovery_recover(const char *technology, const char *profile_name)
switch_bool_t switch_core_ready(void)
Determines if the core is ready to take calls.
Definition: switch_core.c:2998

◆ switch_core_session_set_video_read_callback()

switch_status_t switch_core_session_set_video_read_callback ( switch_core_session_t session,
switch_core_video_thread_callback_func_t  func,
void *  user_data 
)

Definition at line 15260 of file switch_core_media.c.

References switch_media_handle_s::control_mutex, switch_core_session::media_handle, switch_core_session_start_video_thread(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_core_session::video_read_callback, and switch_core_session::video_read_user_data.

Referenced by eavesdrop_callback().

15262 {
15264  switch_media_handle_t *smh;
15265 
15266  if (!(smh = session->media_handle)) {
15267  return SWITCH_STATUS_FALSE;
15268  }
15269 
15271  if (!func) {
15272  session->video_read_callback = NULL;
15273  session->video_read_user_data = NULL;
15274  } else if (session->video_read_callback) {
15275  status = SWITCH_STATUS_FALSE;
15276  } else {
15277  session->video_read_callback = func;
15278  session->video_read_user_data = user_data;
15279  }
15280 
15283 
15284  return status;
15285 }
switch_status_t switch_core_session_start_video_thread(switch_core_session_t *session)
switch_media_handle_t * media_handle
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 * control_mutex
switch_core_video_thread_callback_func_t video_read_callback
switch_status_t
Common return values.

◆ switch_core_session_video_read_callback()

switch_status_t switch_core_session_video_read_callback ( switch_core_session_t session,
switch_frame_t frame 
)

Definition at line 15287 of file switch_core_media.c.

References switch_media_handle_s::control_mutex, switch_core_session::media_handle, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_CONTINUE, SWITCH_STATUS_FALSE, switch_core_session::video_read_callback, and switch_core_session::video_read_user_data.

Referenced by switch_core_session_read_video_frame().

15288 {
15289  switch_media_handle_t *smh;
15291 
15292  if (!(smh = session->media_handle)) {
15293  return SWITCH_STATUS_FALSE;
15294  }
15295 
15297 
15298  if (session->video_read_callback) {
15299  status = session->video_read_callback(session, frame, session->video_read_user_data);
15300  }
15301 
15303 
15304  return status;
15305 }
switch_media_handle_t * media_handle
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 * control_mutex
switch_core_video_thread_callback_func_t video_read_callback
switch_status_t
Common return values.

◆ switch_core_set_console()

switch_status_t switch_core_set_console ( const char *  console)

Set the output console to the desired file.

Parameters
consolethe file path

Definition at line 243 of file switch_core.c.

References switch_runtime::console, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

244 {
245  if ((runtime.console = fopen(console, "a")) == 0) {
246  fprintf(stderr, "Cannot open output file %s.\n", console);
247  return SWITCH_STATUS_FALSE;
248  }
249 
250  return SWITCH_STATUS_SUCCESS;
251 }
struct switch_runtime runtime
Definition: switch_core.c:86

◆ switch_core_set_globals()

void switch_core_set_globals ( void  )

Initiate Globals.

Definition at line 633 of file switch_core.c.

References switch_directories::base_dir, BUFSIZE, switch_directories::cache_dir, switch_directories::certs_dir, switch_directories::conf_dir, switch_filenames::conf_name, switch_directories::data_dir, switch_directories::db_dir, switch_directories::fonts_dir, switch_directories::grammar_dir, switch_directories::htdocs_dir, switch_directories::images_dir, switch_directories::lib_dir, switch_directories::localstate_dir, switch_directories::log_dir, switch_directories::mod_dir, switch_directories::recordings_dir, switch_directories::run_dir, switch_directories::script_dir, switch_directories::sounds_dir, switch_directories::storage_dir, switch_assert, SWITCH_GLOBAL_dirs, SWITCH_GLOBAL_filenames, SWITCH_PATH_SEPARATOR, SWITCH_PREFIX_DIR, switch_snprintf(), switch_string_replace(), and switch_directories::temp_dir.

Referenced by freeswitch_kill_background(), fs_core_set_globals(), fst_init_core_and_modload(), main(), and switch_core_init().

634 {
635 #define BUFSIZE 1024
636 #ifdef WIN32
637  char lpPathBuffer[BUFSIZE];
638  DWORD dwBufSize = BUFSIZE;
639  char base_dir[1024];
640  char *lastbacklash;
641  char *tmp;
642 
643  GetModuleFileName(NULL, base_dir, BUFSIZE);
644  lastbacklash = strrchr(base_dir, '\\');
645  base_dir[(lastbacklash - base_dir)] = '\0';
646  /* set base_dir as cwd, to be able to use relative paths in scripting languages (e.g. mod_lua) when FS is running as a service or while debugging FS using visual studio */
647  SetCurrentDirectory(base_dir);
648  tmp = switch_string_replace(base_dir, "\\", "/");
649  strcpy(base_dir, tmp);
650  free(tmp);
651 
652 #else
653  char base_dir[1024] = SWITCH_PREFIX_DIR;
654 #endif
655 
656  /* Order of precedence for, eg, rundir:
657  * -run
658  * -base
659  * --with-rundir
660  * --prefix
661  */
662 
663  if (!SWITCH_GLOBAL_dirs.mod_dir && (SWITCH_GLOBAL_dirs.mod_dir = (char *) malloc(BUFSIZE))) {
666  else
667 #ifdef SWITCH_MOD_DIR
668  switch_snprintf(SWITCH_GLOBAL_dirs.mod_dir, BUFSIZE, "%s", SWITCH_MOD_DIR);
669 #else
671 #endif
672  }
673 
674  if (!SWITCH_GLOBAL_dirs.lib_dir && (SWITCH_GLOBAL_dirs.lib_dir = (char *) malloc(BUFSIZE))) {
677  else
678 #ifdef SWITCH_LIB_DIR
679  switch_snprintf(SWITCH_GLOBAL_dirs.lib_dir, BUFSIZE, "%s", SWITCH_LIB_DIR);
680 #else
682 #endif
683  }
684 
685  if (!SWITCH_GLOBAL_dirs.conf_dir && (SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(BUFSIZE))) {
688  else
689 #ifdef SWITCH_CONF_DIR
690  switch_snprintf(SWITCH_GLOBAL_dirs.conf_dir, BUFSIZE, "%s", SWITCH_CONF_DIR);
691 #else
693 #endif
694  }
695 
696  if (!SWITCH_GLOBAL_dirs.log_dir && (SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(BUFSIZE))) {
699  else
700 #ifdef SWITCH_LOG_DIR
701  switch_snprintf(SWITCH_GLOBAL_dirs.log_dir, BUFSIZE, "%s", SWITCH_LOG_DIR);
702 #else
704 #endif
705  }
706 
707  if (!SWITCH_GLOBAL_dirs.run_dir && (SWITCH_GLOBAL_dirs.run_dir = (char *) malloc(BUFSIZE))) {
710  else
711 #ifdef SWITCH_RUN_DIR
712  switch_snprintf(SWITCH_GLOBAL_dirs.run_dir, BUFSIZE, "%s", SWITCH_RUN_DIR);
713 #else
715 #endif
716  }
717 
721  else
722 #ifdef SWITCH_RECORDINGS_DIR
723  switch_snprintf(SWITCH_GLOBAL_dirs.recordings_dir, BUFSIZE, "%s", SWITCH_RECORDINGS_DIR);
724 #else
726 #endif
727  }
728 
729  if (!SWITCH_GLOBAL_dirs.sounds_dir && (SWITCH_GLOBAL_dirs.sounds_dir = (char *) malloc(BUFSIZE))) {
732  else
733 #ifdef SWITCH_SOUNDS_DIR
734  switch_snprintf(SWITCH_GLOBAL_dirs.sounds_dir, BUFSIZE, "%s", SWITCH_SOUNDS_DIR);
735 #else
737 #endif
738  }
739 
743  else
744 #ifdef SWITCH_STORAGE_DIR
745  switch_snprintf(SWITCH_GLOBAL_dirs.storage_dir, BUFSIZE, "%s", SWITCH_STORAGE_DIR);
746 #else
748 #endif
749  }
750 
751  if (!SWITCH_GLOBAL_dirs.cache_dir && (SWITCH_GLOBAL_dirs.cache_dir = (char *) malloc(BUFSIZE))) {
754  else
755 #ifdef SWITCH_CACHE_DIR
756  switch_snprintf(SWITCH_GLOBAL_dirs.cache_dir, BUFSIZE, "%s", SWITCH_CACHE_DIR);
757 #else
759 #endif
760  }
761 
762  if (!SWITCH_GLOBAL_dirs.db_dir && (SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(BUFSIZE))) {
765  else
766 #ifdef SWITCH_DB_DIR
767  switch_snprintf(SWITCH_GLOBAL_dirs.db_dir, BUFSIZE, "%s", SWITCH_DB_DIR);
768 #else
770 #endif
771  }
772 
773  if (!SWITCH_GLOBAL_dirs.script_dir && (SWITCH_GLOBAL_dirs.script_dir = (char *) malloc(BUFSIZE))) {
776  else
777 #ifdef SWITCH_SCRIPT_DIR
778  switch_snprintf(SWITCH_GLOBAL_dirs.script_dir, BUFSIZE, "%s", SWITCH_SCRIPT_DIR);
779 #else
781 #endif
782  }
783 
784  if (!SWITCH_GLOBAL_dirs.htdocs_dir && (SWITCH_GLOBAL_dirs.htdocs_dir = (char *) malloc(BUFSIZE))) {
787  else
788 #ifdef SWITCH_HTDOCS_DIR
789  switch_snprintf(SWITCH_GLOBAL_dirs.htdocs_dir, BUFSIZE, "%s", SWITCH_HTDOCS_DIR);
790 #else
792 #endif
793  }
794 
798  else
799 #ifdef SWITCH_GRAMMAR_DIR
800  switch_snprintf(SWITCH_GLOBAL_dirs.grammar_dir, BUFSIZE, "%s", SWITCH_GRAMMAR_DIR);
801 #else
803 #endif
804  }
805 
806  if (!SWITCH_GLOBAL_dirs.fonts_dir && (SWITCH_GLOBAL_dirs.fonts_dir = (char *) malloc(BUFSIZE))) {
809  else
810 #ifdef SWITCH_FONTS_DIR
811  switch_snprintf(SWITCH_GLOBAL_dirs.fonts_dir, BUFSIZE, "%s", SWITCH_FONTS_DIR);
812 #else
814 #endif
815  }
816 
817  if (!SWITCH_GLOBAL_dirs.images_dir && (SWITCH_GLOBAL_dirs.images_dir = (char *) malloc(BUFSIZE))) {
820  else
821 #ifdef SWITCH_IMAGES_DIR
822  switch_snprintf(SWITCH_GLOBAL_dirs.images_dir, BUFSIZE, "%s", SWITCH_IMAGES_DIR);
823 #else
825 #endif
826  }
827 
828  if (!SWITCH_GLOBAL_dirs.data_dir && (SWITCH_GLOBAL_dirs.data_dir = (char *) malloc(BUFSIZE))) {
831  else
832 #ifdef SWITCH_DATA_DIR
833  switch_snprintf(SWITCH_GLOBAL_dirs.data_dir, BUFSIZE, "%s", SWITCH_DATA_DIR);
834 #else
836 #endif
837  }
838 
842  else
843 #ifdef SWITCH_LOCALSTATE_DIR
844  switch_snprintf(SWITCH_GLOBAL_dirs.localstate_dir, BUFSIZE, "%s", SWITCH_LOCALSTATE_DIR);
845 #else
847 #endif
848  }
849 
850  if (!SWITCH_GLOBAL_dirs.certs_dir && (SWITCH_GLOBAL_dirs.certs_dir = (char *) malloc(BUFSIZE))) {
853  else
854 #ifdef SWITCH_CERTS_DIR
855  switch_snprintf(SWITCH_GLOBAL_dirs.certs_dir, BUFSIZE, "%s", SWITCH_CERTS_DIR);
856 #else
858 #endif
859  }
860 
861  if (!SWITCH_GLOBAL_dirs.temp_dir && (SWITCH_GLOBAL_dirs.temp_dir = (char *) malloc(BUFSIZE))) {
862 #ifdef SWITCH_TEMP_DIR
863  switch_snprintf(SWITCH_GLOBAL_dirs.temp_dir, BUFSIZE, "%s", SWITCH_TEMP_DIR);
864 #else
865 #ifdef WIN32
866  GetTempPath(dwBufSize, lpPathBuffer);
867  lpPathBuffer[strlen(lpPathBuffer)-1] = 0;
868  tmp = switch_string_replace(lpPathBuffer, "\\", "/");
869  strcpy(lpPathBuffer, tmp);
870  free(tmp);
871  switch_snprintf(SWITCH_GLOBAL_dirs.temp_dir, BUFSIZE, "%s", lpPathBuffer);
872 #else
874 #endif
875 #endif
876  }
877 
879  switch_snprintf(SWITCH_GLOBAL_filenames.conf_name, BUFSIZE, "%s", "freeswitch.xml");
880  }
881 
882  /* Do this last because it being empty is part of the above logic */
883  if (!SWITCH_GLOBAL_dirs.base_dir && (SWITCH_GLOBAL_dirs.base_dir = (char *) malloc(BUFSIZE))) {
885  }
886 
905 
907 }
#define BUFSIZE
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
#define SWITCH_PREFIX_DIR
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:124
char * switch_string_replace(const char *string, const char *search, const char *replace)
switch_filenames SWITCH_GLOBAL_filenames
Definition: switch_core.c:83
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:82
#define switch_assert(expr)

◆ switch_core_set_process_privileges()

int32_t switch_core_set_process_privileges ( void  )

Switch on the privilege awareness for the process and request required privileges.

Returns
0 on success

Definition at line 910 of file switch_core.c.

Referenced by main().

911 {
912 #ifdef SOLARIS_PRIVILEGES
913  priv_set_t *basicset;
914 
915  /* make the process privilege-aware */
916  setpflags(PRIV_AWARE, 1);
917 
918  /* reset the privileges to basic */
919  basicset = priv_str_to_set("basic", ",", NULL);
920  if (setppriv(PRIV_SET, PRIV_EFFECTIVE, basicset) != 0) {
921  fprintf(stderr, "ERROR: Failed to acquire basic privileges (%s)\n", strerror(errno));
922  }
923 
924  /* we need high-resolution clock, and this requires a non-basic privilege */
925  if (priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_PROC_CLOCK_HIGHRES, NULL) < 0) {
926  fprintf(stderr, "ERROR: Failed to acquire proc_clock_highres privilege (%s)\n", strerror(errno));
927  return -1;
928  }
929 
930  /* need this for setrlimit */
931  if (priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_SYS_RESOURCE, NULL) < 0) {
932  fprintf(stderr, "ERROR: Failed to acquire sys_resource privilege (%s)\n", strerror(errno));
933  return -1;
934  }
935 
936  /* we need to read directories belonging to other uid */
937  if (priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_FILE_DAC_SEARCH, NULL) < 0) {
938  fprintf(stderr, "ERROR: Failed to acquire file_dac_search privilege (%s)\n", strerror(errno));
939  return -1;
940  }
941 #endif
942  return 0;
943 }

◆ switch_core_setrlimits()

void switch_core_setrlimits ( void  )

Definition at line 1322 of file switch_core.c.

References memset(), SWITCH_SYSTEM_THREAD_STACKSIZE, and SWITCH_THREAD_STACKSIZE.

Referenced by main().

1323 {
1324 #ifdef HAVE_SETRLIMIT
1325  struct rlimit rlp;
1326 
1327  /*
1328  Setting the stack size on FreeBSD results in an instant crash.
1329 
1330  If anyone knows how to fix this,
1331  feel free to submit a patch to https://github.com/signalwire/freeswitch
1332  */
1333 
1334 #ifndef __FreeBSD__
1335  memset(&rlp, 0, sizeof(rlp));
1336  rlp.rlim_cur = SWITCH_THREAD_STACKSIZE;
1337  rlp.rlim_max = SWITCH_SYSTEM_THREAD_STACKSIZE;
1338  setrlimit(RLIMIT_STACK, &rlp);
1339 #endif
1340 
1341  memset(&rlp, 0, sizeof(rlp));
1342  rlp.rlim_cur = 999999;
1343  rlp.rlim_max = 999999;
1344  setrlimit(RLIMIT_NOFILE, &rlp);
1345 
1346  memset(&rlp, 0, sizeof(rlp));
1347  rlp.rlim_cur = RLIM_INFINITY;
1348  rlp.rlim_max = RLIM_INFINITY;
1349 
1350  setrlimit(RLIMIT_CPU, &rlp);
1351  setrlimit(RLIMIT_DATA, &rlp);
1352  setrlimit(RLIMIT_FSIZE, &rlp);
1353 #ifdef RLIMIT_NPROC
1354  setrlimit(RLIMIT_NPROC, &rlp);
1355 #endif
1356 #ifdef RLIMIT_RTPRIO
1357  setrlimit(RLIMIT_RTPRIO, &rlp);
1358 #endif
1359 
1360 #if !defined(__OpenBSD__) && !defined(__NetBSD__)
1361  setrlimit(RLIMIT_AS, &rlp);
1362 #endif
1363 #endif
1364  return;
1365 }
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:584
#define SWITCH_SYSTEM_THREAD_STACKSIZE
Definition: switch_types.h:585
memset(buf, 0, buflen)

◆ switch_core_sqldb_pause()

void switch_core_sqldb_pause ( void  )

Definition at line 3854 of file switch_core_sqldb.c.

References sql_manager, SWITCH_CHANNEL_LOG, switch_log_printf(), and SWITCH_LOG_WARNING.

Referenced by switch_core_session_ctl().

3855 {
3856  if (sql_manager.paused) {
3857  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL is already paused.\n");
3858  }
3859  sql_manager.paused = 1;
3860 }
#define SWITCH_CHANNEL_LOG
static struct @4 sql_manager
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.

◆ switch_core_sqldb_resume()

void switch_core_sqldb_resume ( void  )

Definition at line 3862 of file switch_core_sqldb.c.

References sql_manager, SWITCH_CHANNEL_LOG, switch_log_printf(), and SWITCH_LOG_WARNING.

Referenced by switch_core_session_ctl().

3863 {
3864  if (!sql_manager.paused) {
3865  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL is already running.\n");
3866  }
3867  sql_manager.paused = 0;
3868 }
#define SWITCH_CHANNEL_LOG
static struct @4 sql_manager
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.

◆ switch_core_uptime()

switch_time_t switch_core_uptime ( void  )

Number of microseconds the system has been up.

Returns
a number of microseconds

Definition at line 2552 of file switch_core.c.

References FALSE, switch_runtime::initiated, path, and switch_mono_micro_time_now().

Referenced by send_heartbeat().

2553 {
2555 }
switch_time_t initiated
struct switch_runtime runtime
Definition: switch_core.c:86
switch_time_t switch_mono_micro_time_now(void)
Definition: switch_time.c:316

◆ switch_epoch_time_now()

time_t switch_epoch_time_now ( time_t *  t)

Get the current epoch time.

Parameters
[out](optional)The current epoch time
Returns
The current epoch time

Definition at line 322 of file switch_time.c.

References switch_micro_time_now().

Referenced by _switch_cache_db_get_db_handle(), audio_bridge_thread(), check_channel_status(), check_per_channel_timeouts(), core_event_handler(), meta_on_dtmf(), perform_write(), rtp_common_write(), switch_cache_db_execute_sql_callback(), switch_cache_db_execute_sql_callback_err(), switch_cache_db_execute_sql_event_callback(), switch_cache_db_execute_sql_event_callback_err(), switch_cache_db_flush_handles(), switch_cache_db_release_db_handle(), switch_cache_db_status(), switch_core_expire_registration(), switch_core_init(), switch_core_media_bug_patch_video(), switch_core_media_gen_local_sdp(), switch_core_media_get_video_fps(), switch_core_media_patch_sdp(), switch_core_media_read_frame(), switch_core_media_set_udptl_image_sdp(), switch_core_session_dequeue_message(), switch_core_session_read_frame(), switch_core_session_read_video_frame(), switch_core_session_sched_heartbeat(), switch_core_session_write_frame(), switch_core_session_write_video_frame(), switch_core_sql_db_thread(), switch_ivr_displace_session(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_record_file_event(), switch_ivr_record_session_event(), switch_ivr_session_transfer(), switch_ivr_uuid_bridge(), switch_nat_late_init(), switch_rtp_create(), switch_rtp_enable_vad(), switch_scheduler_add_task_ex(), switch_scheduler_execute(), switch_simple_email(), SWITCH_STANDARD_SCHED_FUNC(), task_thread_loop(), and video_bug_thread().

323 {
324  time_t now = switch_micro_time_now() / APR_USEC_PER_SEC;
325  if (t) {
326  *t = now;
327  }
328  return now;
329 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311

◆ switch_ivr_preprocess_session()

switch_status_t switch_ivr_preprocess_session ( switch_core_session_t session,
const char *  cmds 
)

Definition at line 3461 of file switch_ivr_async.c.

References pp_cb_t::done, mutex, preprocess_callback(), pp_cb_t::read_ec, pp_cb_t::read_mutex, pp_cb_t::read_st, switch_codec_implementation::samples_per_packet, switch_codec_implementation::samples_per_second, SMBF_NO_PAUSE, SMBF_READ_REPLACE, SMBF_WRITE_REPLACE, switch_channel_get_private(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_private(), switch_core_media_bug_add(), switch_core_session_alloc, switch_core_session_get_channel(), switch_core_session_get_read_impl(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, switch_mutex_lock(), switch_mutex_unlock(), switch_safe_free, switch_separate_string(), SWITCH_STATUS_SUCCESS, switch_true(), to, pp_cb_t::write_ec, pp_cb_t::write_mutex, and pp_cb_t::write_st.

3462 {
3464  switch_media_bug_t *bug;
3465  switch_status_t status;
3466  time_t to = 0;
3468  switch_codec_implementation_t read_impl = { 0 };
3469  pp_cb_t *cb;
3470  int update = 0;
3471  int argc;
3472  char *mydata = NULL, *argv[5];
3473  int i = 0;
3474 
3475  switch_core_session_get_read_impl(session, &read_impl);
3476 
3477  if ((cb = switch_channel_get_private(channel, "_preprocess"))) {
3478  update = 1;
3479  } else {
3480  cb = switch_core_session_alloc(session, sizeof(*cb));
3481  }
3482 
3483 
3484  if (update) {
3485  if (!strcasecmp(cmds, "stop")) {
3486  cb->done = 1;
3487  return SWITCH_STATUS_SUCCESS;
3488  }
3489  }
3490 
3491  mydata = strdup(cmds);
3492  argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
3493 
3494  for (i = 0; i < argc; i++) {
3495  char *var = argv[i];
3496  char *val = NULL;
3497  char rw;
3498  int tr;
3499  int err = 1;
3500  SpeexPreprocessState *st = NULL;
3501  SpeexEchoState *ec = NULL;
3502  switch_mutex_t *mutex = NULL;
3503  int r = 0;
3504 
3505  if (var) {
3506  if ((val = strchr(var, '='))) {
3507  *val++ = '\0';
3508 
3509  rw = *var++;
3510  while (*var == '.' || *var == '_') {
3511  var++;
3512  }
3513 
3514  if (rw == 'r') {
3515  if (!cb->read_st) {
3516  cb->read_st = speex_preprocess_state_init(read_impl.samples_per_packet, read_impl.samples_per_second);
3517  flags |= SMBF_READ_REPLACE;
3518  }
3519  st = cb->read_st;
3520  ec = cb->read_ec;
3521  mutex = cb->read_mutex;
3522  } else if (rw == 'w') {
3523  if (!cb->write_st) {
3524  cb->write_st = speex_preprocess_state_init(read_impl.samples_per_packet, read_impl.samples_per_second);
3525  flags |= SMBF_WRITE_REPLACE;
3526  }
3527  st = cb->write_st;
3528  ec = cb->write_ec;
3529  mutex = cb->write_mutex;
3530  }
3531 
3532  if (mutex)
3533  switch_mutex_lock(mutex);
3534 
3535  if (st) {
3536  err = 0;
3537  tr = switch_true(val);
3538  if (!strcasecmp(var, "agc")) {
3539  int l = read_impl.samples_per_second;
3540  int tmp = atoi(val);
3541 
3542  if (!tr) {
3543  l = tmp;
3544  }
3545 
3546  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting AGC on %c to %d\n", rw, tr);
3547  speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC, &tr);
3548  speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_LEVEL, &l);
3549 
3550  } else if (!strcasecmp(var, "noise_suppress")) {
3551  int db = atoi(val);
3552  if (db < 0) {
3553  r = speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &db);
3554  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting NOISE_SUPPRESS on %c to %d [%d]\n", rw, db,
3555  r);
3556  } else {
3557  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Syntax error noise_suppress should be in -db\n");
3558  }
3559  } else if (!strcasecmp(var, "echo_cancel")) {
3560  int tail = 1024;
3561  int tmp = atoi(val);
3562 
3563  if (!tr && tmp > 0) {
3564  tail = tmp;
3565  } else if (!tr) {
3566  if (ec) {
3567  if (rw == 'r') {
3568  speex_echo_state_destroy(cb->read_ec);
3569  cb->read_ec = NULL;
3570  } else {
3571  speex_echo_state_destroy(cb->write_ec);
3572  cb->write_ec = NULL;
3573  }
3574  }
3575 
3576  ec = NULL;
3577  }
3578 
3579  if (!ec) {
3580  if (rw == 'r') {
3581  ec = cb->read_ec = speex_echo_state_init(read_impl.samples_per_packet, tail);
3582  speex_echo_ctl(ec, SPEEX_ECHO_SET_SAMPLING_RATE, &read_impl.samples_per_second);
3583  flags |= SMBF_WRITE_REPLACE;
3584  } else {
3585  ec = cb->write_ec = speex_echo_state_init(read_impl.samples_per_packet, tail);
3586  speex_echo_ctl(ec, SPEEX_ECHO_SET_SAMPLING_RATE, &read_impl.samples_per_second);
3587  flags |= SMBF_READ_REPLACE;
3588  }
3589  speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_ECHO_STATE, ec);
3590  }
3591 
3592 
3593  } else if (!strcasecmp(var, "echo_suppress")) {
3594  int db = atoi(val);
3595  if (db < 0) {
3596  speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_ECHO_SUPPRESS, &db);
3597  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting ECHO_SUPPRESS on %c to %d [%d]\n", rw, db,
3598  r);
3599  } else {
3600  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Syntax error echo_suppress should be in -db\n");
3601  }
3602  } else {
3603  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Warning unknown parameter [%s] \n", var);
3604  }
3605  }
3606  }
3607 
3608  if (mutex)
3609  switch_mutex_unlock(mutex);
3610 
3611  if (err) {
3612  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Syntax error parsing preprocessor commands\n");
3613  }
3614 
3615  } else {
3616  break;
3617  }
3618  }
3619 
3620 
3621  switch_safe_free(mydata);
3622 
3623  if (update) {
3624  return SWITCH_STATUS_SUCCESS;
3625  }
3626 
3627 
3628  if ((status = switch_core_media_bug_add(session, "preprocess", NULL,
3629  preprocess_callback, cb, to, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
3630  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error adding media bug.\n");
3631  if (cb->read_st) {
3632  speex_preprocess_state_destroy(cb->read_st);
3633  }
3634 
3635  if (cb->write_st) {
3636  speex_preprocess_state_destroy(cb->write_st);
3637  }
3638 
3639  if (cb->read_ec) {
3640  speex_echo_state_destroy(cb->read_ec);
3641  }
3642 
3643  if (cb->write_ec) {
3644  speex_echo_state_destroy(cb->write_ec);
3645  }
3646 
3647  return status;
3648  }
3649 
3650  switch_channel_set_private(channel, "_preprocess", cb);
3651 
3652  return SWITCH_STATUS_SUCCESS;
3653 }
switch_mutex_t * read_mutex
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
#define SWITCH_CHANNEL_SESSION_LOG(x)
SpeexEchoState * write_ec
switch_status_t switch_channel_set_private(switch_channel_t *channel, const char *key, const void *private_info)
Set private data on channel.
SpeexPreprocessState * write_st
cJSON *const to
switch_status_t switch_core_media_bug_add(_In_ switch_core_session_t *session, _In_ const char *function, _In_ const char *target, _In_ switch_media_bug_callback_t callback, _In_opt_ void *user_data, _In_ time_t stop_time, _In_ switch_media_bug_flag_t flags, _Out_ switch_media_bug_t **new_bug)
Add a media bug to the session.
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
_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.
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.
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
static switch_bool_t preprocess_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
switch_mutex_t * mutex
struct fspr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_status_t
Common return values.
void * switch_channel_get_private(switch_channel_t *channel, const char *key)
Retrieve private from a given channel.
SpeexPreprocessState * read_st
switch_mutex_t * write_mutex
#define switch_core_session_alloc(_session, _memory)
Allocate memory from a session&#39;s pool.
Definition: switch_core.h:696
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.
A table of settings and callbacks that define a paticular implementation of a codec.
uint32_t switch_media_bug_flag_t
SpeexEchoState * read_ec

◆ switch_load_network_lists()

void switch_load_network_lists ( switch_bool_t  reload)

Definition at line 1452 of file switch_core.c.

References switch_runtime::global_mutex, switch_ip_list_t::hash, MAX_NETWORK_PORTS, switch_network_port_range::max_port, memset(), switch_network_port_range::min_port, name, switch_xml::next, switch_ip_list_t::pool, switch_network_port_range::port, switch_network_port_range::ports, switch_assert, SWITCH_CHANNEL_LOG, switch_core_destroy_memory_pool, switch_core_hash_destroy(), switch_core_hash_init, switch_core_hash_insert, switch_core_new_memory_pool, switch_event_add_header_string(), switch_event_create, switch_event_destroy(), SWITCH_EVENT_GENERAL, SWITCH_FALSE, switch_find_local_ip(), SWITCH_LOG_CONSOLE, SWITCH_LOG_NOTICE, switch_log_printf(), SWITCH_LOG_WARNING, switch_mprintf(), switch_mutex_lock(), switch_mutex_unlock(), switch_network_list_add_cidr, switch_network_list_add_cidr_port_token(), switch_network_list_add_cidr_token(), switch_network_list_add_host_mask(), switch_network_list_add_host_port_mask(), switch_network_list_create(), switch_separate_string(), switch_set_string, SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, SWITCH_TRUE, switch_true(), switch_xml_attr(), switch_xml_child(), switch_xml_free(), switch_xml_locate_domain(), switch_xml_open_cfg(), and zstr.

Referenced by switch_core_init_and_modload().

1453 {
1454  switch_xml_t xml = NULL, x_lists = NULL, x_list = NULL, x_node = NULL, cfg = NULL;
1455  switch_network_list_t *rfc_list, *list;
1456  char guess_ip[16] = "";
1457  int mask = 0;
1458  char guess_mask[16] = "";
1459  char *tmp_name;
1460  struct in_addr in;
1461 
1462  switch_find_local_ip(guess_ip, sizeof(guess_ip), &mask, AF_INET);
1463  in.s_addr = mask;
1464  switch_set_string(guess_mask, inet_ntoa(in));
1465 
1467 
1468  if (IP_LIST.hash) {
1470  }
1471 
1472  if (IP_LIST.pool) {
1474  }
1475 
1476  memset(&IP_LIST, 0, sizeof(IP_LIST));
1479 
1480 
1481  tmp_name = "rfc6598.auto";
1482  switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool);
1483  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
1484  switch_network_list_add_cidr(rfc_list, "100.64.0.0/10", SWITCH_TRUE);
1485  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1486 
1487  tmp_name = "rfc1918.auto";
1488  switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool);
1489  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
1490  switch_network_list_add_cidr(rfc_list, "10.0.0.0/8", SWITCH_TRUE);
1491  switch_network_list_add_cidr(rfc_list, "172.16.0.0/12", SWITCH_TRUE);
1492  switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_TRUE);
1493  switch_network_list_add_cidr(rfc_list, "fe80::/10", SWITCH_TRUE);
1494  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1495 
1496  tmp_name = "wan.auto";
1497  switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
1498  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (allow)\n", tmp_name);
1499  switch_network_list_add_cidr(rfc_list, "0.0.0.0/8", SWITCH_FALSE);
1500  switch_network_list_add_cidr(rfc_list, "10.0.0.0/8", SWITCH_FALSE);
1501  switch_network_list_add_cidr(rfc_list, "172.16.0.0/12", SWITCH_FALSE);
1502  switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_FALSE);
1503  switch_network_list_add_cidr(rfc_list, "169.254.0.0/16", SWITCH_FALSE);
1504  switch_network_list_add_cidr(rfc_list, "100.64.0.0/10", SWITCH_FALSE);
1505  switch_network_list_add_cidr(rfc_list, "fe80::/10", SWITCH_FALSE);
1506  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1507 
1508  tmp_name = "wan_v6.auto";
1509  switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
1510  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (allow)\n", tmp_name);
1511  switch_network_list_add_cidr(rfc_list, "0.0.0.0/0", SWITCH_FALSE);
1512  switch_network_list_add_cidr(rfc_list, "fe80::/10", SWITCH_FALSE);
1513  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1514 
1515 
1516  tmp_name = "wan_v4.auto";
1517  switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
1518  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (allow)\n", tmp_name);
1519  switch_network_list_add_cidr(rfc_list, "0.0.0.0/8", SWITCH_FALSE);
1520  switch_network_list_add_cidr(rfc_list, "10.0.0.0/8", SWITCH_FALSE);
1521  switch_network_list_add_cidr(rfc_list, "172.16.0.0/12", SWITCH_FALSE);
1522  switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_FALSE);
1523  switch_network_list_add_cidr(rfc_list, "169.254.0.0/16", SWITCH_FALSE);
1524  switch_network_list_add_cidr(rfc_list, "100.64.0.0/10", SWITCH_FALSE);
1525  switch_network_list_add_cidr(rfc_list, "::/0", SWITCH_FALSE);
1526  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1527 
1528 
1529  tmp_name = "any_v6.auto";
1530  switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
1531  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (allow)\n", tmp_name);
1532  switch_network_list_add_cidr(rfc_list, "0.0.0.0/0", SWITCH_FALSE);
1533  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1534 
1535 
1536  tmp_name = "any_v4.auto";
1537  switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
1538  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (allow)\n", tmp_name);
1539  switch_network_list_add_cidr(rfc_list, "::/0", SWITCH_FALSE);
1540  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1541 
1542 
1543  tmp_name = "nat.auto";
1544  switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool);
1545  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
1546  if (switch_network_list_add_host_mask(rfc_list, guess_ip, guess_mask, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
1547  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding %s/%s (deny) to list %s\n", guess_ip, guess_mask, tmp_name);
1548  }
1549  switch_network_list_add_cidr(rfc_list, "10.0.0.0/8", SWITCH_TRUE);
1550  switch_network_list_add_cidr(rfc_list, "172.16.0.0/12", SWITCH_TRUE);
1551  switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_TRUE);
1552  switch_network_list_add_cidr(rfc_list, "100.64.0.0/10", SWITCH_TRUE);
1553  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1554 
1555  tmp_name = "loopback.auto";
1556  switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool);
1557  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
1558  switch_network_list_add_cidr(rfc_list, "127.0.0.0/8", SWITCH_TRUE);
1559  switch_network_list_add_cidr(rfc_list, "::1/128", SWITCH_TRUE);
1560  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1561 
1562  tmp_name = "localnet.auto";
1564  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
1565 
1566  if (switch_network_list_add_host_mask(list, guess_ip, guess_mask, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
1567  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding %s/%s (allow) to list %s\n", guess_ip, guess_mask, tmp_name);
1568  }
1569  switch_core_hash_insert(IP_LIST.hash, tmp_name, list);
1570 
1571 
1572  if ((xml = switch_xml_open_cfg("acl.conf", &cfg, NULL))) {
1573  if ((x_lists = switch_xml_child(cfg, "network-lists"))) {
1574  for (x_list = switch_xml_child(x_lists, "list"); x_list; x_list = x_list->next) {
1575  const char *name = switch_xml_attr(x_list, "name");
1576  const char *dft = switch_xml_attr(x_list, "default");
1577  switch_bool_t default_type = SWITCH_TRUE;
1578 
1579  if (zstr(name)) {
1580  continue;
1581  }
1582 
1583  if (dft) {
1584  default_type = switch_true(dft);
1585  }
1586 
1587  if (switch_network_list_create(&list, name, default_type, IP_LIST.pool) != SWITCH_STATUS_SUCCESS) {
1588  abort();
1589  }
1590 
1591  if (reload) {
1592  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (%s)\n", name, default_type ? "allow" : "deny");
1593  } else {
1594  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Created ip list %s default (%s)\n", name, default_type ? "allow" : "deny");
1595  }
1596 
1597 
1598  for (x_node = switch_xml_child(x_list, "node"); x_node; x_node = x_node->next) {
1599  const char *cidr = NULL, *host = NULL, *mask = NULL, *domain = NULL, *port = NULL;
1600  switch_bool_t ok = default_type;
1601  const char *type = switch_xml_attr(x_node, "type");
1602  switch_network_port_range_t port_range;
1603  char *argv[MAX_NETWORK_PORTS] = { 0 };
1604  int argc = 0, i;
1605 
1606  if (type) {
1607  ok = switch_true(type);
1608  }
1609 
1610  cidr = switch_xml_attr(x_node, "cidr");
1611  host = switch_xml_attr(x_node, "host");
1612  mask = switch_xml_attr(x_node, "mask");
1613  domain = switch_xml_attr(x_node, "domain");
1614 
1615  memset(&port_range, 0, sizeof(switch_network_port_range_t));
1616 
1617  if( (port = switch_xml_attr(x_node, "port")) != NULL) {
1618  port_range.port = atoi(port);
1619  }
1620 
1621  if( (port = switch_xml_attr(x_node, "ports")) != NULL) {
1622  argc = switch_separate_string((char*)port, ',', argv, (sizeof(argv) / sizeof(argv[0])));
1623  for(i=0; i < argc; i++) {
1624  port_range.ports[i] = atoi(argv[i]);
1625  }
1626  }
1627  if( (port = switch_xml_attr(x_node, "port-min")) != NULL) {
1628  port_range.min_port = atoi(port);
1629  }
1630  if( (port = switch_xml_attr(x_node, "port-max")) != NULL) {
1631  port_range.max_port = atoi(port);
1632  }
1633 
1634  if (domain) {
1635  switch_event_t *my_params = NULL;
1636  switch_xml_t x_domain, xml_root;
1637  switch_xml_t gt, gts, ut, uts;
1638 
1640  switch_assert(my_params);
1641  switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "domain", domain);
1642  switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "purpose", "network-list");
1643 
1644  if (switch_xml_locate_domain(domain, my_params, &xml_root, &x_domain) != SWITCH_STATUS_SUCCESS) {
1645  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate domain %s\n", domain);
1646  switch_event_destroy(&my_params);
1647  continue;
1648  }
1649 
1650  switch_event_destroy(&my_params);
1651 
1652  if ((ut = switch_xml_child(x_domain, "users"))) {
1653  x_domain = ut;
1654  }
1655 
1656  for (ut = switch_xml_child(x_domain, "user"); ut; ut = ut->next) {
1657  const char *user_cidr = switch_xml_attr(ut, "cidr");
1658  const char *id = switch_xml_attr(ut, "id");
1659 
1660  if (id && user_cidr) {
1661  char *token = switch_mprintf("%s@%s", id, domain);
1662  switch_assert(token);
1663  switch_network_list_add_cidr_token(list, user_cidr, ok, token);
1664  free(token);
1665  }
1666  }
1667 
1668  for (gts = switch_xml_child(x_domain, "groups"); gts; gts = gts->next) {
1669  for (gt = switch_xml_child(gts, "group"); gt; gt = gt->next) {
1670  for (uts = switch_xml_child(gt, "users"); uts; uts = uts->next) {
1671  for (ut = switch_xml_child(uts, "user"); ut; ut = ut->next) {
1672  const char *user_cidr = switch_xml_attr(ut, "cidr");
1673  const char *id = switch_xml_attr(ut, "id");
1674 
1675  if (id && user_cidr) {
1676  char *token = switch_mprintf("%s@%s", id, domain);
1677  switch_assert(token);
1678  switch_network_list_add_cidr_port_token(list, user_cidr, ok, token, &port_range);
1679  free(token);
1680  }
1681  }
1682  }
1683  }
1684  }
1685 
1686  switch_xml_free(xml_root);
1687  } else if (cidr) {
1688  switch_network_list_add_cidr_port_token(list, cidr, ok, NULL, &port_range);
1689  } else if (host && mask) {
1690  switch_network_list_add_host_port_mask(list, host, mask, ok, &port_range);
1691  }
1692  }
1693 
1694  switch_core_hash_insert(IP_LIST.hash, name, list);
1695  }
1696  }
1697 
1698  switch_xml_free(xml);
1699  }
1700 
1702 }
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
#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_memory_pool_t * pool
Definition: switch_core.c:1368
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
switch_status_t switch_xml_locate_domain(_In_z_ const char *domain_name, _In_opt_ switch_event_t *params, _Out_ switch_xml_t *root, _Out_ switch_xml_t *domain)
#define SWITCH_CHANNEL_LOG
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
const char * switch_xml_attr(_In_opt_ switch_xml_t xml, _In_opt_z_ const char *attr)
returns the value of the requested tag attribute, or NULL if not found
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1431
switch_status_t switch_network_list_create(switch_network_list_t **list, const char *name, switch_bool_t default_type, switch_memory_pool_t *pool)
Definition: switch_utils.c:459
switch_status_t switch_network_list_add_cidr_token(switch_network_list_t *list, const char *cidr_str, switch_bool_t ok, const char *token)
Definition: switch_utils.c:702
switch_bool_t
Definition: switch_types.h:437
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
Representation of an event.
Definition: switch_event.h:80
switch_status_t switch_network_list_add_host_port_mask(switch_network_list_t *list, const char *host, const char *mask_str, switch_bool_t ok, switch_network_port_range_p port)
Definition: switch_utils.c:707
#define switch_network_list_add_cidr(_list, _cidr_str, _ok)
A representation of an XML tree.
Definition: switch_xml.h:79
struct switch_runtime runtime
Definition: switch_core.c:86
#define zstr(x)
Definition: switch_utils.h:314
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_hash_t * hash
Definition: switch_core.c:1369
switch_xml_t next
Definition: switch_xml.h:91
switch_status_t switch_network_list_add_host_mask(switch_network_list_t *list, const char *host, const char *mask_str, switch_bool_t ok)
Definition: switch_utils.c:737
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.
switch_byte_t in
int ports[MAX_NETWORK_PORTS]
Definition: switch_utils.h:53
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
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.
static switch_ip_list_t IP_LIST
Definition: switch_core.c:1372
#define MAX_NETWORK_PORTS
Definition: switch_utils.h:49
switch_mutex_t * global_mutex
switch_status_t switch_network_list_add_cidr_port_token(switch_network_list_t *list, const char *cidr_str, switch_bool_t ok, const char *token, switch_network_port_range_p port)
Definition: switch_utils.c:675
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
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1479
#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
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 ...
#define switch_set_string(_dst, _src)
Definition: switch_utils.h:734
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_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
const char *const name
Definition: switch_cJSON.h:250
void switch_event_destroy(switch_event_t **event)
Destroy an event.
#define switch_assert(expr)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
memset(buf, 0, buflen)

◆ switch_loadable_module_create_interface()

void* switch_loadable_module_create_interface ( switch_loadable_module_interface_t mod,
switch_module_interface_name_t  iname 
)

Definition at line 3063 of file switch_loadable_module.c.

References ALLOC_INTERFACE, SWITCH_API_INTERFACE, SWITCH_APPLICATION_INTERFACE, SWITCH_ASR_INTERFACE, SWITCH_CHANNEL_LOG, SWITCH_CHAT_APPLICATION_INTERFACE, SWITCH_CHAT_INTERFACE, SWITCH_CODEC_INTERFACE, SWITCH_DATABASE_INTERFACE, SWITCH_DIALPLAN_INTERFACE, SWITCH_DIRECTORY_INTERFACE, SWITCH_ENDPOINT_INTERFACE, SWITCH_FILE_INTERFACE, SWITCH_JSON_API_INTERFACE, SWITCH_LIMIT_INTERFACE, switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_MANAGEMENT_INTERFACE, SWITCH_SAY_INTERFACE, SWITCH_SPEECH_INTERFACE, and SWITCH_TIMER_INTERFACE.

Referenced by SWITCH_MODULE_LOAD_FUNCTION().

3064 {
3065 
3066  switch (iname) {
3068  ALLOC_INTERFACE(endpoint)
3069 
3071  ALLOC_INTERFACE(timer)
3072 
3074  ALLOC_INTERFACE(dialplan)
3075 
3077  ALLOC_INTERFACE(codec)
3078 
3080  ALLOC_INTERFACE(application)
3081 
3083  ALLOC_INTERFACE(chat_application)
3084 
3085  case SWITCH_API_INTERFACE:
3086  ALLOC_INTERFACE(api)
3087 
3089  ALLOC_INTERFACE(json_api)
3090 
3091  case SWITCH_FILE_INTERFACE:
3092  ALLOC_INTERFACE(file)
3093 
3095  ALLOC_INTERFACE(speech)
3096 
3098  ALLOC_INTERFACE(directory)
3099 
3100  case SWITCH_CHAT_INTERFACE:
3101  ALLOC_INTERFACE(chat)
3102 
3103  case SWITCH_SAY_INTERFACE:
3104  ALLOC_INTERFACE(say)
3105 
3106  case SWITCH_ASR_INTERFACE:
3107  ALLOC_INTERFACE(asr)
3108 
3110  ALLOC_INTERFACE(management)
3111 
3113  ALLOC_INTERFACE(limit)
3114 
3116  ALLOC_INTERFACE(database)
3117 
3118  default:
3119  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Module Type!\n");
3120  return NULL;
3121  }
3122 }
#define ALLOC_INTERFACE(_TYPE_)
#define SWITCH_CHANNEL_LOG
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_loadable_module_create_module_interface()

switch_loadable_module_interface_t* switch_loadable_module_create_module_interface ( switch_memory_pool_t pool,
const char *  name 
)

Definition at line 3033 of file switch_loadable_module.c.

References switch_loadable_module_interface::module_name, switch_loadable_module_interface::pool, pool, switch_loadable_module_interface::rwlock, switch_assert, switch_core_alloc, switch_core_strdup, and switch_thread_rwlock_create().

Referenced by SWITCH_MODULE_LOAD_FUNCTION().

3034 {
3036 
3038  switch_assert(mod != NULL);
3039 
3040  mod->pool = pool;
3041 
3042  mod->module_name = switch_core_strdup(mod->pool, name);
3044  return mod;
3045 }
#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
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
switch_status_t switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock, switch_memory_pool_t *pool)
Definition: switch_apr.c:235
const char *const name
Definition: switch_cJSON.h:250
#define switch_assert(expr)
The abstraction of a loadable module.

◆ switch_lookup_timezone()

const char* switch_lookup_timezone ( const char *  tz_name)

Definition at line 1379 of file switch_time.c.

References switch_timezones_list_t::hash, SWITCH_CHANNEL_LOG, switch_core_hash_find(), SWITCH_LOG_ERROR, switch_log_printf(), value, and zstr.

Referenced by switch_strftime_tz(), and switch_time_exp_tz_name().

1380 {
1381  char *value = NULL;
1382 
1383  if (zstr(tz_name) || !TIMEZONES_LIST.hash) {
1384  return NULL;
1385  }
1386 
1387  if ((value = switch_core_hash_find(TIMEZONES_LIST.hash, tz_name)) == NULL) {
1388  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timezone '%s' not found!\n", tz_name);
1389  }
1390 
1391  return value;
1392 }
#define SWITCH_CHANNEL_LOG
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
const char *const const char *const const cJSON *const value
static switch_timezones_list_t TIMEZONES_LIST
Definition: switch_time.c:1376
#define zstr(x)
Definition: switch_utils.h:314
switch_hash_t * hash
Definition: switch_time.c:1373
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_micro_time_now()

switch_time_t switch_micro_time_now ( void  )

Get the current epoch time in microseconds.

Returns
the current epoch time in microseconds

Definition at line 311 of file switch_time.c.

References globals, runtime, switch_time_now(), and switch_runtime::timestamp.

Referenced by _switch_core_session_request_video_refresh(), calc_elapsed(), calc_local_lsr_now(), check_jitter(), check_rtcp_and_ice(), check_timeout(), do_flush(), API::getTime(), handle_ice(), ice_out(), process_rtcp_report(), read_rtp_packet(), record_callback(), rtcp_generate_sender_info(), rtp_common_write(), switch_channel_check_device_state(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_perform_mark_ring_ready_value(), switch_channel_set_bridge_time(), switch_channel_set_caller_profile(), switch_channel_set_hangup_time(), switch_collect_input_callback(), switch_console_printf(), switch_core_port_allocator_request_port(), switch_core_session_read_text_frame(), switch_core_session_write_video_frame(), switch_epoch_time_now(), switch_event_prep_for_delivery_detailed(), switch_generate_sln_silence(), switch_ivr_collect_digits_callback(), switch_ivr_collect_digits_count(), switch_ivr_digit_stream_parser_feed(), switch_ivr_originate(), switch_ivr_parse_event(), switch_ivr_play_and_collect_input(), switch_ivr_sleep(), switch_ivr_tone_detect_session(), switch_ivr_wait_for_answer(), switch_log_meta_vprintf(), switch_rtp_activate_ice(), switch_rtp_create(), switch_rtp_enable_vad(), switch_rtp_reset_media_timer(), switch_rtp_sync_stats(), switch_str_time(), switch_strftime_tz(), switch_stun_lookup(), switch_time_exp_tz_name(), switch_xml_locate_user_cache(), switch_xml_locate_user_merged(), switch_xml_std_datetime_check(), timer_generic_sync(), timer_init(), and tone_detect_set_total_time().

312 {
313  return (globals.RUNNING == 1 && runtime.timestamp) ? runtime.timestamp : switch_time_now();
314 }
static struct @9 globals
struct switch_runtime runtime
Definition: switch_core.c:86
switch_time_t timestamp
switch_time_t switch_time_now(void)
Definition: switch_apr.c:325

◆ switch_mono_micro_time_now()

switch_time_t switch_mono_micro_time_now ( void  )

Definition at line 316 of file switch_time.c.

References time_now().

Referenced by switch_core_init(), switch_core_uptime(), SWITCH_MODULE_LOAD_FUNCTION(), SWITCH_MODULE_RUNTIME_FUNCTION(), switch_time_ref(), and switch_time_sync().

317 {
318  return time_now(-1);
319 }
static switch_time_t time_now(int64_t offset)
Definition: switch_time.c:540

◆ switch_stream_system()

int switch_stream_system ( const char *  cmd,
switch_stream_handle_t stream 
)

Definition at line 3536 of file switch_core.c.

References buffer, switch_stream_handle::raw_write_function, switch_core_get_variable(), SWITCH_FALSE, switch_stream_spawn(), SWITCH_TRUE, and switch_true().

Referenced by preprocess_exec_set(), and switch_stream_system_fork().

3537 {
3538 #ifdef __linux__
3539  switch_bool_t spawn_instead_of_system = switch_true(switch_core_get_variable("spawn_instead_of_system"));
3540 #else
3541  switch_bool_t spawn_instead_of_system = SWITCH_FALSE;
3542 #endif
3543 
3544  if (spawn_instead_of_system){
3545  return switch_stream_spawn(cmd, SWITCH_TRUE, SWITCH_TRUE, stream);
3546  } else {
3547  char buffer[128];
3548  size_t bytes;
3549  FILE* pipe = popen(cmd, "r");
3550  if (!pipe) return 1;
3551 
3552  while (!feof(pipe)) {
3553  while ((bytes = fread(buffer, 1, 128, pipe)) > 0) {
3554  if (stream != NULL) {
3555  stream->raw_write_function(stream, (unsigned char *)buffer, bytes);
3556  }
3557  }
3558  }
3559 
3560  if (ferror(pipe)) {
3561  pclose(pipe);
3562  return 1;
3563  }
3564 
3565  pclose(pipe);
3566  return 0;
3567  }
3568 }
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
switch_stream_handle_raw_write_function_t raw_write_function
switch_bool_t
Definition: switch_types.h:437
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
char * buffer
Definition: switch_cJSON.h:153
char * switch_core_get_variable(const char *varname)
Definition: switch_core.c:395

◆ switch_strftime_tz()

switch_status_t switch_strftime_tz ( const char *  tz,
const char *  format,
char *  date,
size_t  len,
switch_time_t  thetime 
)

Definition at line 1475 of file switch_time.c.

References switch_lookup_timezone(), switch_micro_time_now(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_strftime_nocheck(), tm2switchtime(), tztime(), zstr, and zstr_buf.

1476 {
1477  time_t timep;
1478 
1479  const char *tz_name = tz;
1480  const char *tzdef;
1481 
1482  switch_size_t retsize;
1483 
1484  struct tm tm = { 0 };
1485  switch_time_exp_t stm;
1486 
1487  if (!thetime) {
1488  thetime = switch_micro_time_now();
1489  }
1490 
1491  timep = (thetime) / (int64_t) (1000000);
1492 
1493  if (!zstr(tz_name)) {
1494  tzdef = switch_lookup_timezone(tz_name);
1495  } else {
1496  /* We set the default timezone to GMT. */
1497  tzdef = "GMT";
1498  }
1499 
1500  if (tzdef) { /* The lookup of the zone may fail. */
1501  tztime(&timep, tzdef, &tm);
1502  tm2switchtime(&tm, &stm);
1503  switch_strftime_nocheck(date, &retsize, len, zstr(format) ? "%Y-%m-%d %T" : format, &stm);
1504  if (!zstr_buf(date)) {
1505  return SWITCH_STATUS_SUCCESS;
1506  }
1507  }
1508  return SWITCH_STATUS_FALSE;
1509 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
static void tm2switchtime(struct tm *tm, switch_time_exp_t *xt)
Definition: switch_time.c:1342
char const int const cJSON_bool format
Definition: switch_cJSON.h:153
switch_status_t switch_strftime_nocheck(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
Definition: switch_apr.c:202
#define zstr(x)
Definition: switch_utils.h:314
uintptr_t switch_size_t
#define zstr_buf(s)
Definition: switch_utils.h:318
static void tztime(const time_t *const timep, const char *tzstring, struct tm *const tmp)
Definition: switch_time.c:2446
const char * switch_lookup_timezone(const char *tz_name)
Definition: switch_time.c:1379

◆ switch_system()

int switch_system ( const char *  cmd,
switch_bool_t  wait 
)

Definition at line 3342 of file switch_core.c.

References SCF_THREADED_SYSTEM_EXEC, switch_core_get_variable(), SWITCH_FALSE, switch_stream_spawn(), switch_system_fork(), switch_system_thread(), switch_test_flag, SWITCH_TRUE, and switch_true().

Referenced by preprocess_exec(), and switch_simple_email().

3343 {
3344  int retval = 0;
3345 #ifdef __linux__
3346  switch_bool_t spawn_instead_of_system = switch_true(switch_core_get_variable("spawn_instead_of_system"));
3347 #else
3348  switch_bool_t spawn_instead_of_system = SWITCH_FALSE;
3349 #endif
3350 
3351  if (spawn_instead_of_system) {
3352  retval = switch_stream_spawn(cmd, SWITCH_TRUE, wait, NULL);
3354  retval = switch_system_thread(cmd, wait);
3355  } else {
3356  retval = switch_system_fork(cmd, wait);
3357  }
3358  return retval;
3359 }
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
switch_bool_t
Definition: switch_types.h:437
struct switch_runtime runtime
Definition: switch_core.c:86
static int switch_system_thread(const char *cmd, switch_bool_t wait)
Definition: switch_core.c:3189
static int switch_system_fork(const char *cmd, switch_bool_t wait)
Definition: switch_core.c:3295
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
char * switch_core_get_variable(const char *varname)
Definition: switch_core.c:395
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693

◆ switch_time_exp_tz_name()

switch_status_t switch_time_exp_tz_name ( const char *  tz,
switch_time_exp_t tm,
switch_time_t  thetime 
)

Definition at line 1445 of file switch_time.c.

References switch_lookup_timezone(), switch_micro_time_now(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, tm2switchtime(), tztime(), and zstr.

Referenced by switch_xml_std_datetime_check().

1446 {
1447  struct tm xtm = { 0 };
1448  const char *tz_name = tz;
1449  const char *tzdef;
1450  time_t timep;
1451 
1452  if (!thetime) {
1453  thetime = switch_micro_time_now();
1454  }
1455 
1456  timep = (thetime) / (int64_t) (1000000);
1457 
1458  if (!zstr(tz_name)) {
1459  tzdef = switch_lookup_timezone(tz_name);
1460  } else {
1461  /* We set the default timezone to GMT. */
1462  tzdef = "GMT";
1463  }
1464 
1465  if (tzdef) { /* The lookup of the zone may fail. */
1466  tztime(&timep, tzdef, &xtm);
1467  tm2switchtime(&xtm, tm);
1468  return SWITCH_STATUS_SUCCESS;
1469  }
1470 
1471  return SWITCH_STATUS_FALSE;
1472 
1473 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
static void tm2switchtime(struct tm *tm, switch_time_exp_t *xt)
Definition: switch_time.c:1342
#define zstr(x)
Definition: switch_utils.h:314
static void tztime(const time_t *const timep, const char *tzstring, struct tm *const tmp)
Definition: switch_time.c:2446
const char * switch_lookup_timezone(const char *tz_name)
Definition: switch_time.c:1379

◆ switch_time_ref()

switch_time_t switch_time_ref ( void  )

Definition at line 596 of file switch_time.c.

References switch_mono_micro_time_now(), SYSTEM_TIME, and time_now().

Referenced by average_time(), and SWITCH_MODULE_RUNTIME_FUNCTION().

597 {
598  if (SYSTEM_TIME) {
599  /* Return system time reference */
600  return time_now(0);
601  } else {
602  /* Return monotonic time reference (when available) */
604  }
605 }
static switch_time_t time_now(int64_t offset)
Definition: switch_time.c:540
switch_time_t switch_mono_micro_time_now(void)
Definition: switch_time.c:316
static int SYSTEM_TIME
Definition: switch_time.c:68

◆ switch_time_set_cond_yield()

void switch_time_set_cond_yield ( switch_bool_t  enable)

Definition at line 373 of file switch_time.c.

References COND, MATRIX, and switch_time_sync().

Referenced by switch_load_core_config(), SWITCH_MODULE_LOAD_FUNCTION(), and switch_time_calibrate_clock().

374 {
375  COND = enable ? 1 : 0;
376  if (COND) {
377  MATRIX = 1;
378  }
380 }
void switch_time_sync(void)
Definition: switch_time.c:609
static int COND
Definition: switch_time.c:87
static int MATRIX
Definition: switch_time.c:89

◆ switch_time_set_matrix()

void switch_time_set_matrix ( switch_bool_t  enable)

Definition at line 360 of file switch_time.c.

References MATRIX, and switch_time_sync().

Referenced by switch_load_core_config().

361 {
362  MATRIX = enable ? 1 : 0;
364 }
void switch_time_sync(void)
Definition: switch_time.c:609
static int MATRIX
Definition: switch_time.c:89

◆ switch_time_set_monotonic()

void switch_time_set_monotonic ( switch_bool_t  enable)

Definition at line 331 of file switch_time.c.

References MONO, and switch_time_sync().

Referenced by switch_load_core_config().

332 {
333 #if (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) || defined(WIN32)
334  MONO = enable ? 1 : 0;
336 #else
337  MONO = 0;
338 #endif
339 }
void switch_time_sync(void)
Definition: switch_time.c:609
static int MONO
Definition: switch_time.c:64

◆ switch_time_set_nanosleep()

void switch_time_set_nanosleep ( switch_bool_t  enable)

Definition at line 366 of file switch_time.c.

References NANO.

Referenced by switch_load_core_config(), and SWITCH_MODULE_LOAD_FUNCTION().

367 {
368 #if defined(HAVE_CLOCK_NANOSLEEP)
369  NANO = enable ? 1 : 0;
370 #endif
371 }
static int NANO
Definition: switch_time.c:82

◆ switch_time_set_timerfd()

void switch_time_set_timerfd ( int  enable)

Definition at line 348 of file switch_time.c.

References switch_time_sync(), and TFD.

Referenced by switch_load_core_config().

349 {
350 #if defined(HAVE_TIMERFD_CREATE)
351  TFD = enable;
353 
354 #else
355  TFD = 0;
356 #endif
357 }
void switch_time_sync(void)
Definition: switch_time.c:609
static int TFD
Definition: switch_time.c:81

◆ switch_time_set_use_system_time()

void switch_time_set_use_system_time ( switch_bool_t  enable)

Definition at line 342 of file switch_time.c.

References SYSTEM_TIME.

Referenced by switch_load_core_config().

343 {
344  SYSTEM_TIME = enable;
345 }
static int SYSTEM_TIME
Definition: switch_time.c:68

◆ switch_time_sync()

void switch_time_sync ( void  )

Definition at line 609 of file switch_time.c.

References last_time, switch_runtime::offset, switch_runtime::reference, runtime, SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, switch_log_printf(), switch_mono_micro_time_now(), switch_time_now(), SYSTEM_TIME, time_now(), and switch_runtime::time_sync.

Referenced by switch_core_session_ctl(), switch_core_session_perform_destroy(), switch_core_session_sync_clock(), SWITCH_MODULE_RUNTIME_FUNCTION(), switch_time_set_cond_yield(), switch_time_set_matrix(), switch_time_set_monotonic(), switch_time_set_timerfd(), and timer_init().

610 {
611  runtime.time_sync++; /* Indicate that we are syncing time right now */
612 
614 
615  if (SYSTEM_TIME) {
617  runtime.offset = 0;
618  } else {
619  runtime.offset = runtime.reference - switch_mono_micro_time_now(); /* Get the offset between system time and the monotonic clock (when available) */
621  }
622 
623  if (runtime.reference - last_time > 1000000 || last_time == 0) {
624  if (SYSTEM_TIME) {
625  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Clock is already configured to always report system time.\n");
626  } else {
627  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Clock synchronized to system time.\n");
628  }
629  }
631 
632  runtime.time_sync++; /* Indicate that we are finished syncing time */
633 }
#define SWITCH_CHANNEL_LOG
static switch_time_t time_now(int64_t offset)
Definition: switch_time.c:540
struct switch_runtime runtime
Definition: switch_core.c:86
switch_time_t switch_mono_micro_time_now(void)
Definition: switch_time.c:316
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
static switch_time_t last_time
Definition: switch_time.c:607
static int SYSTEM_TIME
Definition: switch_time.c:68
switch_time_t switch_time_now(void)
Definition: switch_apr.c:325
switch_time_t reference