FreeSWITCH API Documentation  1.7.0
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_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

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

Definition at line 2404 of file switch_core.h.

Referenced by check_ice(), and switch_core_media_check_nat().

Function Documentation

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

Referenced by main().

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

Definition at line 1052 of file switch_core.c.

References switch_runtime::cpu_count, and set_realtime_priority().

Referenced by main().

1053 {
1054 #ifndef WIN32
1055  runtime.cpu_count = sysconf (_SC_NPROCESSORS_ONLN);
1056 #else
1057  SYSTEM_INFO sysinfo;
1058  GetSystemInfo( &sysinfo );
1059  runtime.cpu_count = sysinfo.dwNumberOfProcessors;
1060 #endif
1061 
1062  if (!runtime.cpu_count) runtime.cpu_count = 1;
1063 
1064  return set_realtime_priority();
1065 
1066 
1067  // ERROR: code not reachable on Windows Visual Studio Express 2008 return 0;
1068 }
struct switch_runtime runtime
Definition: switch_core.c:64
int32_t set_realtime_priority(void)
Definition: switch_core.c:968
int32_t set_low_priority ( void  )

Definition at line 932 of file switch_core.c.

Referenced by main(), and switch_fork().

933 {
934 #ifdef WIN32
935  return SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
936 #else
937 #if defined(USE_SCHED_SETSCHEDULER) && ! defined(SOLARIS_PRIVILEGES)
938  /*
939  * Try to use a normal scheduler
940  */
941  struct sched_param sched = { 0 };
942  sched.sched_priority = 0;
943  if (sched_setscheduler(0, SCHED_OTHER, &sched) < 0) {
944  fprintf(stderr, "ERROR: Failed to set SCHED_OTHER scheduler (%s)\n", strerror(errno));
945  return -1;
946  }
947 #endif
948 
949 #ifdef HAVE_SETPRIORITY
950  /*
951  * setpriority() works on FreeBSD (6.2), nice() doesn't
952  */
953  if (setpriority(PRIO_PROCESS, getpid(), 19) < 0) {
954  fprintf(stderr, "ERROR: Could not set nice level\n");
955  return -1;
956  }
957 #else
958  if (nice(19) != 19) {
959  fprintf(stderr, "ERROR: Could not set nice level\n");
960  return -1;
961  }
962 #endif
963 
964  return 0;
965 #endif
966 }
int32_t set_normal_priority ( void  )

Set the maximum priority the process can obtain.

Returns
0 on success

Definition at line 1047 of file switch_core.c.

Referenced by main().

1048 {
1049  return 0;
1050 }
int32_t set_realtime_priority ( void  )

Definition at line 968 of file switch_core.c.

References SWITCH_PRI_LOW.

Referenced by main(), and set_auto_priority().

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

Definition at line 1366 of file switch_core.c.

References switch_runtime::global_mutex, switch_ip_list_t::hash, 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_token(), switch_network_list_validate_ip_token(), switch_parse_cidr(), switch_safe_free, switch_separate_string(), switch_test_subnet, switch_testv6_subnet(), and ip_t::v4.

1367 {
1368  switch_network_list_t *list;
1369  ip_t ip, mask, net;
1370  uint32_t bits;
1371  char *ipv6 = strchr(ip_str,':');
1373  char *ipv4 = NULL;
1374 
1375  if ((ipv4 = switch_network_ipv4_mapped_ipv6_addr(ip_str))) {
1376  ip_str = ipv4;
1377  ipv6 = NULL;
1378  }
1379 
1381  if (ipv6) {
1382  switch_inet_pton(AF_INET6, ip_str, &ip);
1383  } else {
1384  switch_inet_pton(AF_INET, ip_str, &ip);
1385  ip.v4 = htonl(ip.v4);
1386  }
1387 
1388  if ((list = switch_core_hash_find(IP_LIST.hash, list_name))) {
1389  if (ipv6) {
1390  ok = switch_network_list_validate_ip6_token(list, ip, token);
1391  } else {
1392  ok = switch_network_list_validate_ip_token(list, ip.v4, token);
1393  }
1394  } else if (strchr(list_name, '/')) {
1395  if (strchr(list_name, ',')) {
1396  char *list_name_dup = strdup(list_name);
1397  char *argv[32];
1398  int argc;
1399 
1400  switch_assert(list_name_dup);
1401 
1402  if ((argc = switch_separate_string(list_name_dup, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
1403  int i;
1404  for (i = 0; i < argc; i++) {
1405  switch_parse_cidr(argv[i], &net, &mask, &bits);
1406  if (ipv6) {
1407  if ((ok = switch_testv6_subnet(ip, net, mask))){
1408  break;
1409  }
1410  } else {
1411  if ((ok = switch_test_subnet(ip.v4, net.v4, mask.v4))) {
1412  break;
1413  }
1414  }
1415  }
1416  }
1417  free(list_name_dup);
1418  } else {
1419  switch_parse_cidr(list_name, &net, &mask, &bits);
1420 
1421  if (ipv6) {
1422  ok = switch_testv6_subnet(ip, net, mask);
1423  } else {
1424  ok = switch_test_subnet(ip.v4, net.v4, mask.v4);
1425  }
1426  }
1427  }
1428 
1429  switch_safe_free(ipv4);
1431 
1432  return ok;
1433 }
#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:405
int switch_parse_cidr(const char *string, ip_t *ip, ip_t *mask, uint32_t *bitp)
Definition: switch_utils.c:607
switch_bool_t switch_network_list_validate_ip6_token(switch_network_list_t *list, ip_t ip, const char **token)
Definition: switch_utils.c:441
struct switch_runtime runtime
Definition: switch_core.c:64
switch_bool_t switch_network_list_validate_ip_token(switch_network_list_t *list, uint32_t ip, const char **token)
Definition: switch_utils.c:468
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_hash_t * hash
Definition: switch_core.c:1361
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:428
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
uint32_t v4
Definition: switch_utils.h:247
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
char * switch_network_ipv4_mapped_ipv6_addr(const char *ip_str)
Definition: switch_utils.c:494
static switch_ip_list_t IP_LIST
Definition: switch_core.c:1364
int switch_inet_pton(int af, const char *src, void *dst)
Definition: inet_pton.c:74
switch_mutex_t * global_mutex
#define switch_assert(expr)
void switch_cond_next ( void  )

Definition at line 638 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_flag(), switch_channel_wait_for_state(), switch_channel_wait_for_state_timeout(), 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_video_frame(), 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_stun_lookup(), and video_helper_thread().

639 {
640  if (runtime.tipping_point && globals.timer_count >= runtime.tipping_point) {
641  switch_os_yield();
642  return;
643  }
644 #ifdef DISABLE_1MS_COND
645  do_sleep(1000);
646 #else
647  if (globals.RUNNING != 1 || !runtime.timestamp || globals.use_cond_yield != 1) {
648  do_sleep(1000);
649  return;
650  }
654 #endif
655 }
void switch_os_yield(void)
Definition: switch_time.c:141
static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS+1]
Definition: switch_time.c:137
switch_status_t switch_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex)
Definition: switch_apr.c:355
struct switch_runtime runtime
Definition: switch_core.c:64
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static struct @7 globals
switch_time_t timestamp
uint32_t tipping_point
static void do_sleep(switch_interval_time_t t)
Definition: switch_time.c:150
switch_mutex_t * mutex
Definition: switch_time.c:105
void switch_cond_yield ( switch_interval_time_t  t)

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

658 {
659  switch_time_t want;
660  if (!t)
661  return;
662 
663  if (globals.RUNNING != 1 || !runtime.timestamp || globals.use_cond_yield != 1) {
664  do_sleep(t);
665  return;
666  }
667  want = runtime.timestamp + t;
668  while (globals.RUNNING == 1 && globals.use_cond_yield == 1 && runtime.timestamp < want) {
670  if (runtime.timestamp < want) {
672  }
674  }
675 
676 
677 }
static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS+1]
Definition: switch_time.c:137
switch_status_t switch_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex)
Definition: switch_apr.c:355
struct switch_runtime runtime
Definition: switch_core.c:64
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
int64_t switch_time_t
Definition: switch_apr.h:188
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static struct @7 globals
switch_time_t timestamp
static void do_sleep(switch_interval_time_t t)
Definition: switch_time.c:150
switch_mutex_t * mutex
Definition: switch_time.c:105
switch_status_t switch_console_set_alias ( const char *  string)

Definition at line 1916 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.

1917 {
1918  char *mydata = NULL, *argv[3] = { 0 };
1919  int argc;
1921 
1922  if (string && (mydata = strdup(string))) {
1923  if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 2) {
1924  switch_cache_db_handle_t *db = NULL;
1925  char *sql = NULL;
1926 
1927  if (argc > 2 && !strcmp(argv[1], argv[2])) {
1928  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Alias and command cannot be the same, this will cause loop!\n");
1929  return SWITCH_STATUS_FALSE;
1930  }
1931 
1934  free(mydata);
1935  return SWITCH_STATUS_FALSE;
1936  }
1937 
1938  if (!strcasecmp(argv[0], "stickyadd") && argc == 3) {
1939  sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_switchname());
1941  switch_safe_free(sql);
1943  sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%q','%q','%q')",
1944  argv[1], argv[2], switch_core_get_switchname());
1945  } else {
1946  sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%w','%w','%w')",
1947  argv[1], argv[2], switch_core_get_switchname());
1948  }
1950  status = SWITCH_STATUS_SUCCESS;
1951  } else if (!strcasecmp(argv[0], "add") && argc == 3) {
1952  sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_switchname());
1954  switch_safe_free(sql);
1956  sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%q','%q','%q')",
1957  argv[1], argv[2], switch_core_get_switchname());
1958  } else {
1959  sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%w','%w','%w')",
1960  argv[1], argv[2], switch_core_get_switchname());
1961  }
1963  status = SWITCH_STATUS_SUCCESS;
1964  } else if (!strcasecmp(argv[0], "del") && argc == 2) {
1965  char *what = argv[1];
1966  if (!strcasecmp(what, "*")) {
1967  sql = switch_mprintf("delete from aliases where hostname='%q'", switch_core_get_switchname());
1969  } else {
1970  sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_switchname());
1972  }
1973  status = SWITCH_STATUS_SUCCESS;
1974  }
1975  switch_safe_free(sql);
1977  }
1978  }
1979 
1980  switch_safe_free(mydata);
1981 
1982  return status;
1983 
1984 }
const char * switch_core_get_switchname(void)
Definition: switch_core.c:349
#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:789
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:2606
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_status_t switch_console_set_complete ( const char *  string)

Definition at line 1832 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.

1833 {
1834  char *mydata = NULL, *argv[11] = { 0 };
1835  int argc, x;
1838 
1839  if (!(cflags & SCF_USE_SQL)) {
1840  return SWITCH_STATUS_FALSE;
1841  }
1842 
1843  if (string && (mydata = strdup(string))) {
1844  if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
1845  switch_stream_handle_t mystream = { 0 };
1846  SWITCH_STANDARD_STREAM(mystream);
1847 
1848  if (!strcasecmp(argv[0], "stickyadd")) {
1849  mystream.write_function(&mystream, "insert into complete values (1,");
1850  for (x = 0; x < 10; x++) {
1851  if (argv[x + 1] && !strcasecmp(argv[x + 1], "_any_")) {
1852  mystream.write_function(&mystream, "%s", "'', ");
1853  } else {
1855  mystream.write_function(&mystream, "'%q', ", switch_str_nil(argv[x + 1]));
1856  } else {
1857  mystream.write_function(&mystream, "'%w', ", switch_str_nil(argv[x + 1]));
1858  }
1859  }
1860  }
1861  mystream.write_function(&mystream, " '%s')", switch_core_get_hostname());
1862  switch_core_sql_exec(mystream.data);
1863  status = SWITCH_STATUS_SUCCESS;
1864  } else if (!strcasecmp(argv[0], "add")) {
1865  mystream.write_function(&mystream, "insert into complete values (0,");
1866  for (x = 0; x < 10; x++) {
1867  if (argv[x + 1] && !strcasecmp(argv[x + 1], "_any_")) {
1868  mystream.write_function(&mystream, "%s", "'', ");
1869  } else {
1871  mystream.write_function(&mystream, "'%q', ", switch_str_nil(argv[x + 1]));
1872  } else {
1873  mystream.write_function(&mystream, "'%w', ", switch_str_nil(argv[x + 1]));
1874  }
1875  }
1876  }
1877  mystream.write_function(&mystream, " '%s')", switch_core_get_hostname());
1878 
1879  switch_core_sql_exec(mystream.data);
1880  status = SWITCH_STATUS_SUCCESS;
1881  } else if (!strcasecmp(argv[0], "del")) {
1882  char *what = argv[1];
1883  if (zstr(what)) {
1884  switch_safe_free(mystream.data);
1885  switch_safe_free(mydata);
1886  return SWITCH_STATUS_FALSE;
1887  } else if (!strcasecmp(what, "*")) {
1888  mystream.write_function(&mystream, "delete from complete where hostname='%s'", switch_core_get_hostname());
1889  switch_core_sql_exec(mystream.data);
1890  } else {
1891  mystream.write_function(&mystream, "delete from complete where ");
1892  for (x = 0; x < argc - 1; x++) {
1894  mystream.write_function(&mystream, "a%d = '%q'%q", x + 1, switch_str_nil(argv[x + 1]), x == argc - 2 ? "" : " and ");
1895  } else {
1896  mystream.write_function(&mystream, "a%d = '%w'%w", x + 1, switch_str_nil(argv[x + 1]), x == argc - 2 ? "" : " and ");
1897  }
1898  }
1899  mystream.write_function(&mystream, " and hostname='%s'", switch_core_get_hostname());
1900  switch_core_sql_exec(mystream.data);
1901  }
1902  status = SWITCH_STATUS_SUCCESS;
1903  }
1904 
1905  switch_safe_free(mystream.data);
1906  }
1907  }
1908 
1909  switch_safe_free(mydata);
1910 
1911  return status;
1912 
1913 }
uint32_t switch_core_flag_t
Definition: switch_types.h:376
#define zstr(x)
Definition: switch_utils.h:281
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:2852
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
#define SWITCH_STANDARD_STREAM(s)
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:903
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:344
switch_cache_db_handle_type_t switch_core_dbtype(void)
switch_status_t switch_core_chat_deliver ( const char *  dest_proto,
switch_event_t **  message_event 
)

Definition at line 915 of file switch_loadable_module.c.

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

916 {
917 
918  if (dest_proto) {
919  switch_event_add_header_string(*message_event, SWITCH_STACK_BOTTOM, "dest_proto", dest_proto);
920  }
921 
922  chat_queue_message(message_event);
923 
924  return SWITCH_STATUS_SUCCESS;
925 }
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_status_t switch_core_chat_send ( const char *  dest_proto,
switch_event_t message_event 
)

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

901 {
902  switch_event_t *dup;
903 
904  switch_event_dup(&dup, message_event);
905 
906  if (dest_proto) {
907  switch_event_add_header_string(dup, SWITCH_STACK_BOTTOM, "dest_proto", dest_proto);
908  }
909 
910  chat_queue_message(&dup);
911  return SWITCH_STATUS_SUCCESS;
912 }
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_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 858 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.

860 {
861  switch_event_t *message_event;
862  switch_status_t status;
863 
865  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "proto", proto);
866  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "from", from);
867  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "to", to);
868  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "subject", subject);
869  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "type", type);
870  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "hint", hint);
871  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "skip_global_process", "true");
872  if (blocking) {
873  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "blocking", "true");
874  }
875 
876  if (body) {
877  switch_event_add_body(message_event, "%s", body);
878  }
879  } else {
880  abort();
881  }
882 
883  if (dest_proto) {
884  switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "dest_proto", dest_proto);
885  }
886 
887 
888  if (blocking) {
889  status = chat_process_event(&message_event);
890  } else {
891  chat_queue_message(&message_event);
892  status = SWITCH_STATUS_SUCCESS;
893  }
894 
895  return status;
896 
897 }
static void chat_queue_message(switch_event_t **eventp)
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:383
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 263 of file switch_core.c.

References switch_runtime::console, SWITCH_CHANNEL_ID_LOG, and SWITCH_CHANNEL_ID_LOG_CLEAN.

Referenced by switch_console_printf(), and switch_log_vprintf().

264 {
265  FILE *handle = stdout;
266 
267  switch (channel) {
270  handle = runtime.console;
271  break;
272  default:
273  handle = runtime.console;
274  break;
275  }
276 
277  return handle;
278 }
struct switch_runtime runtime
Definition: switch_core.c:64
uint32_t switch_core_default_dtmf_duration ( uint32_t  duration)

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

1682 {
1683  if (duration) {
1684  if (duration < SWITCH_MIN_DTMF_DURATION) {
1685  duration = SWITCH_MIN_DTMF_DURATION;
1686  }
1687  if (duration > SWITCH_MAX_DTMF_DURATION) {
1688  duration = SWITCH_MAX_DTMF_DURATION;
1689  }
1690  runtime.default_dtmf_duration = duration;
1691 
1692  if (duration < runtime.min_dtmf_duration) {
1693  runtime.min_dtmf_duration = duration;
1694  }
1695 
1696  if (duration > runtime.max_dtmf_duration) {
1697  runtime.max_dtmf_duration = duration;
1698  }
1699 
1700  }
1702 }
uint32_t min_dtmf_duration
struct switch_runtime runtime
Definition: switch_core.c:64
#define SWITCH_MAX_DTMF_DURATION
Definition: switch_types.h:117
uint32_t max_dtmf_duration
#define SWITCH_MIN_DTMF_DURATION
Definition: switch_types.h:116
uint32_t default_dtmf_duration
switch_core_flag_t switch_core_flags ( void  )

return core flags

Returns
core flags

Definition at line 2852 of file switch_core.c.

References switch_runtime::flags.

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

2853 {
2854  return runtime.flags;
2855 }
struct switch_runtime runtime
Definition: switch_core.c:64
FILE* switch_core_get_console ( void  )

Get the output console.

Returns
the FILE stream

Definition at line 230 of file switch_core.c.

References switch_runtime::console.

Referenced by switch_console_process(), and switch_log_init().

231 {
232  return runtime.console;
233 }
struct switch_runtime runtime
Definition: switch_core.c:64
double switch_core_idle_cpu ( void  )

Definition at line 2448 of file switch_core_session.c.

References switch_runtime::profile_time, and runtime.

Referenced by send_heartbeat().

2449 {
2450  return runtime.profile_time;
2451 }
struct switch_runtime runtime
Definition: switch_core.c:64
switch_thread_t* switch_core_launch_thread ( void *  SWITCH_THREAD_FUNC *func)(switch_thread_t *, void *,
void *  obj,
switch_memory_pool_t pool 
)
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 2970 of file switch_core.c.

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

2971 {
2972  const switch_management_interface_t *ptr;
2974 
2975  if ((ptr = switch_loadable_module_get_management_interface(relative_oid))) {
2976  status = ptr->management_function(relative_oid, action, data, datalen);
2977  }
2978 
2979  return status;
2980 }
switch_management_interface_t * switch_loadable_module_get_management_interface(const char *relative_oid)
Retrieve the management interface by it'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)
uint32_t switch_core_max_dtmf_duration ( uint32_t  duration)

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

1665 {
1666  if (duration) {
1667  if (duration > SWITCH_MAX_DTMF_DURATION) {
1668  duration = SWITCH_MAX_DTMF_DURATION;
1669  }
1670  if (duration < SWITCH_MIN_DTMF_DURATION) {
1671  duration = SWITCH_MIN_DTMF_DURATION;
1672  }
1673  runtime.max_dtmf_duration = duration;
1674  if (duration < runtime.min_dtmf_duration) {
1675  runtime.min_dtmf_duration = duration;
1676  }
1677  }
1678  return runtime.max_dtmf_duration;
1679 }
uint32_t min_dtmf_duration
struct switch_runtime runtime
Definition: switch_core.c:64
#define SWITCH_MAX_DTMF_DURATION
Definition: switch_types.h:117
uint32_t max_dtmf_duration
#define SWITCH_MIN_DTMF_DURATION
Definition: switch_types.h:116
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 2450 of file switch_core.c.

References memset().

Referenced by send_heartbeat().

2451 {
2452  switch_time_t temp = total_ms / 1000;
2453  memset(duration, 0, sizeof(*duration));
2454  duration->mms = (uint32_t) (total_ms % 1000);
2455  duration->ms = (uint32_t) (temp % 1000);
2456  temp = temp / 1000;
2457  duration->sec = (uint32_t) (temp % 60);
2458  temp = temp / 60;
2459  duration->min = (uint32_t) (temp % 60);
2460  temp = temp / 60;
2461  duration->hr = (uint32_t) (temp % 24);
2462  temp = temp / 24;
2463  duration->day = (uint32_t) (temp % 365);
2464  duration->yr = (uint32_t) (temp / 365);
2465 }
int64_t switch_time_t
Definition: switch_apr.h:188
memset(buf, 0, buflen)
void switch_core_memory_reclaim ( void  )

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

480 {
481 #if !defined(PER_POOL_LOCK) && !defined(INSTANTLY_DESTROY_POOLS)
483  void *pop = NULL;
484  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled memory pool(s)\n",
485  switch_queue_size(memory_manager.pool_recycle_queue) + switch_queue_size(memory_manager.pool_queue));
486 
487  while (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS) {
488  pool = (switch_memory_pool_t *) pop;
489  if (!pool) {
490  break;
491  }
492 #ifdef USE_MEM_LOCK
494 #endif
495  apr_pool_destroy(pool);
496 #ifdef USE_MEM_LOCK
498 #endif
499  }
500 #endif
501  return;
502 }
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1114
#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:1140
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static struct @2 memory_manager
struct apr_pool_t switch_memory_pool_t
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
void switch_core_memory_reclaim_all ( void  )

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

2983 {
2987 }
void switch_core_memory_reclaim_logger(void)
Definition: switch_log.c:544
void switch_core_memory_reclaim_events(void)
Definition: switch_event.c:499
void switch_core_memory_reclaim(void)
void switch_core_memory_reclaim_events ( void  )

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

500 {
501 #ifdef SWITCH_EVENT_RECYCLE
502 
503  void *pop;
504  int size;
505  size = switch_queue_size(EVENT_RECYCLE_QUEUE);
506 
507  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled event(s) %d bytes\n", size, (int) sizeof(switch_event_t) * size);
508  size = switch_queue_size(EVENT_HEADER_RECYCLE_QUEUE);
509  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled event header(s) %d bytes\n",
510  size, (int) sizeof(switch_event_header_t) * size);
511 
512  while (switch_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS && pop) {
513  free(pop);
514  }
515  while (switch_queue_trypop(EVENT_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS && pop) {
516  free(pop);
517  }
518 #else
519  return;
520 #endif
521 
522 }
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1114
#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:1140
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
void switch_core_memory_reclaim_logger ( void  )

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

545 {
546 #ifdef SWITCH_LOG_RECYCLE
547  void *pop;
548  int size = switch_queue_size(LOG_RECYCLE_QUEUE);
549  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CONSOLE, "Returning %d recycled log node(s) %d bytes\n", size,
550  (int) sizeof(switch_log_node_t) * size);
551  while (switch_queue_trypop(LOG_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
552  switch_log_node_free(&pop);
553  }
554 #else
555  return;
556 #endif
557 
558 }
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1114
#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:1140
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:321
void switch_log_node_free(switch_log_node_t **pnode)
Definition: switch_log.c:125
switch_status_t switch_core_mime_add_type ( const char *  type,
const char *  ext 
)

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

1221 {
1222  char *ptype = NULL;
1223  char *ext_list = NULL;
1224  int argc = 0;
1225  char *argv[20] = { 0 };
1226  int x;
1228 
1229  switch_assert(type);
1230  switch_assert(ext);
1231 
1232  ptype = switch_core_permanent_strdup(type);
1233  ext_list = strdup(ext);
1234 
1235  switch_assert(ext_list);
1236 
1237  /* 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. */
1238  if ((argc = switch_separate_string(ext_list, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
1239  int is_mapped_type = switch_core_hash_find(runtime.mime_type_exts, ptype) != NULL;
1240  for (x = 0; x < argc; x++) {
1241  if (argv[x] && ptype) {
1243  switch_core_hash_insert(runtime.mime_types, argv[x], ptype);
1244  }
1245  if (!is_mapped_type) {
1247  is_mapped_type = 1;
1248  }
1249  }
1250  }
1251 
1252  status = SWITCH_STATUS_SUCCESS;
1253  }
1254 
1255  free(ext_list);
1256 
1257  return status;
1258 }
#define switch_core_permanent_strdup(_todup)
Copy a string using permanent memory allocation.
Definition: switch_core.h:705
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
struct switch_runtime runtime
Definition: switch_core.c:64
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:1410
#define switch_assert(expr)
const char* switch_core_mime_ext2type ( const char *  ext)

Definition at line 1199 of file switch_core.c.

References switch_runtime::mime_types, and switch_core_hash_find().

Referenced by switch_simple_email().

1200 {
1201  if (!ext) {
1202  return NULL;
1203  }
1204  return (const char *) switch_core_hash_find(runtime.mime_types, ext);
1205 }
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
struct switch_runtime runtime
Definition: switch_core.c:64
switch_hash_t * mime_types
switch_hash_index_t* switch_core_mime_index ( void  )

Definition at line 1215 of file switch_core.c.

References switch_runtime::mime_types, and switch_core_hash_first.

1216 {
1218 }
struct switch_runtime runtime
Definition: switch_core.c:64
switch_hash_t * mime_types
#define switch_core_hash_first(_h)
Definition: switch_core.h:1501
const char* switch_core_mime_type2ext ( const char *  type)

Definition at line 1207 of file switch_core.c.

References switch_runtime::mime_type_exts, and switch_core_hash_find().

1208 {
1209  if (!mime) {
1210  return NULL;
1211  }
1212  return (const char *) switch_core_hash_find(runtime.mime_type_exts, mime);
1213 }
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
struct switch_runtime runtime
Definition: switch_core.c:64
switch_hash_t * mime_type_exts
uint32_t switch_core_min_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 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().

1705 {
1706  if (duration) {
1707  if (duration < SWITCH_MIN_DTMF_DURATION) {
1708  duration = SWITCH_MIN_DTMF_DURATION;
1709  }
1710  if (duration > SWITCH_MAX_DTMF_DURATION) {
1711  duration = SWITCH_MAX_DTMF_DURATION;
1712  }
1713 
1714  runtime.min_dtmf_duration = duration;
1715 
1716  if (duration > runtime.max_dtmf_duration) {
1717  runtime.max_dtmf_duration = duration;
1718  }
1719  }
1720  return runtime.min_dtmf_duration;
1721 }
uint32_t min_dtmf_duration
struct switch_runtime runtime
Definition: switch_core.c:64
#define SWITCH_MAX_DTMF_DURATION
Definition: switch_types.h:117
uint32_t max_dtmf_duration
#define SWITCH_MIN_DTMF_DURATION
Definition: switch_types.h:116
double switch_core_min_idle_cpu ( double  new_limit)

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

2439 {
2440  if (new_limit >= 0) {
2441  runtime.min_idle_time = new_limit;
2442  }
2443 
2444  return runtime.min_idle_time;
2445 }
struct switch_runtime runtime
Definition: switch_core.c:64
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 2862 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().

2863 {
2865 }
struct switch_runtime runtime
Definition: switch_core.c:64
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
switch_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 2867 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().

2868 {
2870 }
struct switch_runtime runtime
Definition: switch_core.c:64
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
switch_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 2872 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().

2873 {
2875 }
struct switch_runtime runtime
Definition: switch_core.c:64
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
switch_bool_t switch_core_running ( void  )

Definition at line 2857 of file switch_core.c.

References switch_runtime::running, SWITCH_FALSE, and SWITCH_TRUE.

Referenced by running().

2858 {
2860 }
struct switch_runtime runtime
Definition: switch_core.c:64
void switch_core_runtime_loop ( int  bg)

Run endlessly until the system is shutdown.

Parameters
bgdivert console to the background

Definition at line 1174 of file switch_core.c.

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

Referenced by main().

1175 {
1176 #ifdef WIN32
1177  HANDLE shutdown_event;
1178  char path[256] = "";
1179 #endif
1180  if (bg) {
1181 #ifdef WIN32
1182  switch_snprintf(path, sizeof(path), "Global\\Freeswitch.%d", getpid());
1183  shutdown_event = CreateEvent(NULL, FALSE, FALSE, path);
1184  if (shutdown_event) {
1185  WaitForSingleObject(shutdown_event, INFINITE);
1186  }
1187 #else
1188  runtime.running = 1;
1189  while (runtime.running) {
1190  switch_yield(1000000);
1191  }
1192 #endif
1193  } else {
1194  /* wait for console input */
1196  }
1197 }
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:64
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
#define FALSE
void switch_console_loop(void)
A simple comand loop that reads input from the terminal.
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 2414 of file switch_core_session.c.

References switch_assert.

2415 {
2416  switch_assert(session != NULL);
2417  switch_assert(endpoint_interface != NULL);
2418 
2419  return (uint8_t) (session->endpoint_interface == endpoint_interface);
2420 }
switch_endpoint_interface_t * endpoint_interface
#define switch_assert(expr)
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 2406 of file switch_core_session.c.

References switch_assert.

2407 {
2408  switch_assert(a != NULL);
2409  switch_assert(b != NULL);
2410 
2411  return (uint8_t) (a->endpoint_interface == b->endpoint_interface);
2412 }
switch_endpoint_interface_t * endpoint_interface
#define switch_assert(expr)
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 2528 of file switch_core.c.

References 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_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_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::sps_last, switch_runtime::sps_peak, switch_runtime::sps_peak_fivemin, switch_runtime::sps_total, 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_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_LOG_CRIT, SWITCH_LOG_DEBUG, SWITCH_LOG_INFO, switch_log_printf(), SWITCH_LOG_WARNING, switch_mutex_lock(), switch_mutex_unlock(), switch_safe_free, switch_set_flag, SWITCH_STATUS_RESTART, switch_test_flag, switch_time_calibrate_clock(), switch_time_sync(), switch_yield, switch_runtime::throttle_mutex, and zstr.

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

2529 {
2530  int *intval = (int *) val;
2531  int oldintval = 0, newintval = 0;
2532 
2533  if (intval) {
2534  oldintval = *intval;
2535  }
2536 
2538  return -1;
2539  }
2540 
2541  switch (cmd) {
2542  case SCSC_RECOVER:
2543  {
2544  char *arg = (char *) val;
2545  char *tech = NULL, *prof = NULL;
2546  int r, flush = 0;
2547 
2548  if (!zstr(arg)) {
2549  tech = strdup(arg);
2550 
2551  if ((prof = strchr(tech, ':'))) {
2552  *prof++ = '\0';
2553  }
2554 
2555  if (!strcasecmp(tech, "flush")) {
2556  flush++;
2557  tech = NULL;
2558 
2559  if (prof) {
2560  tech = prof;
2561  if ((prof = strchr(tech, ':'))) {
2562  *prof++ = '\0';
2563  }
2564  }
2565  }
2566 
2567  }
2568 
2569  if (flush) {
2570  switch_core_recovery_flush(tech, prof);
2571  r = -1;
2572  } else {
2573  r = switch_core_recovery_recover(tech, prof);
2574  }
2575 
2576  switch_safe_free(tech);
2577  return r;
2578 
2579  }
2580  break;
2581  case SCSC_DEBUG_SQL:
2582  {
2585  newintval = 0;
2586  } else {
2588  newintval = 1;
2589  }
2590  }
2591  break;
2592  case SCSC_VERBOSE_EVENTS:
2593  if (intval) {
2594  if (oldintval > -1) {
2595  if (oldintval) {
2597  } else {
2599  }
2600  }
2601  newintval = switch_test_flag((&runtime), SCF_VERBOSE_EVENTS);
2602  }
2603  break;
2604  case SCSC_API_EXPANSION:
2605  if (intval) {
2606  if (oldintval > -1) {
2607  if (oldintval) {
2609  } else {
2611  }
2612  }
2613  newintval = switch_test_flag((&runtime), SCF_API_EXPANSION);
2614  }
2615  break;
2617  if (intval) {
2618  if (oldintval > -1) {
2619  if (oldintval) {
2621  } else {
2623  }
2624  }
2626  }
2627  break;
2628  case SCSC_CALIBRATE_CLOCK:
2630  break;
2631  case SCSC_FLUSH_DB_HANDLES:
2633  break;
2634  case SCSC_SEND_SIGHUP:
2635  handle_SIGHUP(1);
2636  break;
2637  case SCSC_SYNC_CLOCK:
2638  switch_time_sync();
2639  newintval = 0;
2640  break;
2642  newintval = switch_core_session_sync_clock();
2643  break;
2644  case SCSC_SQL:
2645  if (oldintval) {
2647  } else {
2649  }
2650  break;
2651  case SCSC_PAUSE_ALL:
2652  if (oldintval) {
2654  } else {
2656  }
2657  break;
2658  case SCSC_PAUSE_INBOUND:
2659  if (oldintval) {
2661  } else {
2663  }
2664  break;
2665  case SCSC_PAUSE_OUTBOUND:
2666  if (oldintval) {
2668  } else {
2670  }
2671  break;
2672  case SCSC_HUPALL:
2674  break;
2675  case SCSC_CANCEL_SHUTDOWN:
2677  break;
2678  case SCSC_SAVE_HISTORY:
2680  break;
2681  case SCSC_CRASH:
2682  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Declinatio Mortuus Obfirmo!\n");
2684  abort();
2685  break;
2686  case SCSC_SHUTDOWN_NOW:
2688  exit(0);
2689  break;
2690  case SCSC_REINCARNATE_NOW:
2692  exit(SWITCH_STATUS_RESTART);
2693  break;
2694  case SCSC_SHUTDOWN_ELEGANT:
2695  case SCSC_SHUTDOWN_ASAP:
2696  {
2697  int x = 19;
2698  uint32_t count;
2699 
2701  if (cmd == SCSC_SHUTDOWN_ASAP) {
2703  }
2704 
2706  switch_yield(500000);
2707  if (++x == 20) {
2709  "Shutdown in progress, %u session(s) remain.\nShutting down %s\n",
2710  count, cmd == SCSC_SHUTDOWN_ASAP ? "ASAP" : "once there are no active calls.");
2711  x = 0;
2712  }
2713  }
2714 
2717 #ifdef _MSC_VER
2718  win_shutdown();
2719 #endif
2720 
2721  if (oldintval) {
2724  } else {
2726 #ifdef _MSC_VER
2727  fclose(stdin);
2728 #endif
2729  }
2730  runtime.running = 0;
2731  } else {
2732  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Shutdown Cancelled\n");
2734  }
2735  }
2736  break;
2737  case SCSC_PAUSE_CHECK:
2739  break;
2742  break;
2745  break;
2746  case SCSC_READY_CHECK:
2747  newintval = switch_core_ready();
2748  break;
2749  case SCSC_SHUTDOWN_CHECK:
2750  newintval = !!switch_test_flag((&runtime), SCF_SHUTDOWN_REQUESTED);
2751  break;
2752  case SCSC_SHUTDOWN:
2753 
2754 #ifdef _MSC_VER
2755  win_shutdown();
2756 #endif
2757 
2758  if (oldintval) {
2761  } else {
2763 #ifdef _MSC_VER
2764  fclose(stdin);
2765 #endif
2766  }
2767  runtime.running = 0;
2768  break;
2769  case SCSC_CHECK_RUNNING:
2770  newintval = runtime.running;
2771  break;
2772  case SCSC_LOGLEVEL:
2773  if (oldintval > -1) {
2774  runtime.hard_log_level = oldintval;
2775  }
2776 
2779  }
2780  newintval = runtime.hard_log_level;
2781  break;
2782  case SCSC_DEBUG_LEVEL:
2783  if (oldintval > -1) {
2784  if (oldintval > 10)
2785  newintval = 10;
2786  runtime.debug_level = oldintval;
2787  }
2788  newintval = runtime.debug_level;
2789  break;
2790  case SCSC_MIN_IDLE_CPU:
2791  {
2792  double *dval = (double *) val;
2793  if (dval) {
2794  *dval = switch_core_min_idle_cpu(*dval);
2795  }
2796  intval = NULL;
2797  }
2798  break;
2799  case SCSC_MAX_SESSIONS:
2800  newintval = switch_core_session_limit(oldintval);
2801  break;
2802  case SCSC_LAST_SPS:
2803  newintval = runtime.sps_last;
2804  break;
2805  case SCSC_SPS_PEAK:
2806  if (oldintval == -1) {
2807  runtime.sps_peak = 0;
2808  }
2809  newintval = runtime.sps_peak;
2810  break;
2811  case SCSC_SPS_PEAK_FIVEMIN:
2812  newintval = runtime.sps_peak_fivemin;
2813  break;
2814  case SCSC_SESSIONS_PEAK:
2815  newintval = runtime.sessions_peak;
2816  break;
2818  newintval = runtime.sessions_peak_fivemin;
2819  break;
2821  newintval = switch_core_max_dtmf_duration(oldintval);
2822  break;
2824  newintval = switch_core_min_dtmf_duration(oldintval);
2825  break;
2827  newintval = switch_core_default_dtmf_duration(oldintval);
2828  break;
2829  case SCSC_SPS:
2831  if (oldintval > 0) {
2832  runtime.sps_total = oldintval;
2833  }
2834  newintval = runtime.sps_total;
2836  break;
2837 
2838  case SCSC_RECLAIM:
2840  newintval = 0;
2841  break;
2842  }
2843 
2844  if (intval) {
2845  *intval = newintval;
2846  }
2847 
2848 
2849  return 0;
2850 }
void switch_time_sync(void)
Definition: switch_time.c:589
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
#define SWITCH_CHANNEL_LOG
int switch_core_session_sync_clock(void)
switch_mutex_t * throttle_mutex
struct switch_runtime runtime
Definition: switch_core.c:64
#define zstr(x)
Definition: switch_utils.h:281
uint32_t switch_core_max_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1664
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:655
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1704
int32_t sessions_peak_fivemin
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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:2982
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
void switch_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:2012
void switch_core_sqldb_pause(void)
void switch_cache_db_flush_handles(void)
uint32_t switch_core_default_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1681
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:207
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:624
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
uint32_t debug_level
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:2862
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 11511 of file switch_core_media.c.

References switch_media_handle_s::control_mutex, switch_core_session_start_video_thread(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by eavesdrop_callback().

11513 {
11515  switch_media_handle_t *smh;
11516 
11517  if (!(smh = session->media_handle)) {
11518  return SWITCH_STATUS_FALSE;
11519  }
11520 
11522  if (!func) {
11523  session->video_read_callback = NULL;
11524  session->video_read_user_data = NULL;
11525  } else if (session->video_read_callback) {
11526  status = SWITCH_STATUS_FALSE;
11527  } else {
11528  session->video_read_callback = func;
11529  session->video_read_user_data = user_data;
11530  }
11531 
11534 
11535  return status;
11536 }
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:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * control_mutex
switch_core_video_thread_callback_func_t video_read_callback
switch_status_t
Common return values.
switch_status_t switch_core_session_video_read_callback ( switch_core_session_t session,
switch_frame_t frame 
)

Definition at line 11538 of file switch_core_media.c.

References switch_media_handle_s::control_mutex, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_CONTINUE, and SWITCH_STATUS_FALSE.

Referenced by switch_core_session_read_video_frame().

11539 {
11540  switch_media_handle_t *smh;
11542 
11543  if (!(smh = session->media_handle)) {
11544  return SWITCH_STATUS_FALSE;
11545  }
11546 
11548 
11549  if (session->video_read_callback) {
11550  status = session->video_read_callback(session, frame, session->video_read_user_data);
11551  }
11552 
11554 
11555  return status;
11556 }
switch_media_handle_t * media_handle
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * control_mutex
switch_core_video_thread_callback_func_t video_read_callback
switch_status_t
Common return values.
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 220 of file switch_core.c.

References switch_runtime::console, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

221 {
222  if ((runtime.console = fopen(console, "a")) == 0) {
223  fprintf(stderr, "Cannot open output file %s.\n", console);
224  return SWITCH_STATUS_FALSE;
225  }
226 
227  return SWITCH_STATUS_SUCCESS;
228 }
struct switch_runtime runtime
Definition: switch_core.c:64
void switch_core_set_globals ( void  )

Initiate Globals.

Definition at line 620 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_CACHE_DIR, SWITCH_CERTS_DIR, SWITCH_CONF_DIR, SWITCH_DATA_DIR, SWITCH_DB_DIR, SWITCH_FONTS_DIR, SWITCH_GLOBAL_dirs, SWITCH_GLOBAL_filenames, SWITCH_GRAMMAR_DIR, SWITCH_HTDOCS_DIR, SWITCH_IMAGES_DIR, SWITCH_LOCALSTATE_DIR, SWITCH_LOG_DIR, SWITCH_MOD_DIR, SWITCH_PATH_SEPARATOR, SWITCH_PREFIX_DIR, SWITCH_RECORDINGS_DIR, SWITCH_RUN_DIR, SWITCH_SCRIPT_DIR, switch_snprintf(), SWITCH_SOUNDS_DIR, SWITCH_STORAGE_DIR, switch_string_replace(), and switch_directories::temp_dir.

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

621 {
622 #define BUFSIZE 1024
623 #ifdef WIN32
624  char lpPathBuffer[BUFSIZE];
625  DWORD dwBufSize = BUFSIZE;
626  char base_dir[1024];
627  char *lastbacklash;
628  char *tmp;
629 
630  GetModuleFileName(NULL, base_dir, BUFSIZE);
631  lastbacklash = strrchr(base_dir, '\\');
632  base_dir[(lastbacklash - base_dir)] = '\0';
633  /* 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 */
634  SetCurrentDirectory(base_dir);
635  tmp = switch_string_replace(base_dir, "\\", "/");
636  strcpy(base_dir, tmp);
637  free(tmp);
638 
639 #else
640  char base_dir[1024] = SWITCH_PREFIX_DIR;
641 #endif
642 
643  /* Order of precedence for, eg, rundir:
644  * -run
645  * -base
646  * --with-rundir
647  * --prefix
648  */
649 
650  if (!SWITCH_GLOBAL_dirs.mod_dir && (SWITCH_GLOBAL_dirs.mod_dir = (char *) malloc(BUFSIZE))) {
653  else
654 #ifdef SWITCH_MOD_DIR
656 #else
658 #endif
659  }
660 
661  if (!SWITCH_GLOBAL_dirs.lib_dir && (SWITCH_GLOBAL_dirs.lib_dir = (char *) malloc(BUFSIZE))) {
664  else
665 #ifdef SWITCH_LIB_DIR
666  switch_snprintf(SWITCH_GLOBAL_dirs.lib_dir, BUFSIZE, "%s", SWITCH_LIB_DIR);
667 #else
669 #endif
670  }
671 
672  if (!SWITCH_GLOBAL_dirs.conf_dir && (SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(BUFSIZE))) {
675  else
676 #ifdef SWITCH_CONF_DIR
678 #else
680 #endif
681  }
682 
683  if (!SWITCH_GLOBAL_dirs.log_dir && (SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(BUFSIZE))) {
686  else
687 #ifdef SWITCH_LOG_DIR
689 #else
691 #endif
692  }
693 
694  if (!SWITCH_GLOBAL_dirs.run_dir && (SWITCH_GLOBAL_dirs.run_dir = (char *) malloc(BUFSIZE))) {
697  else
698 #ifdef SWITCH_RUN_DIR
700 #else
702 #endif
703  }
704 
708  else
709 #ifdef SWITCH_RECORDINGS_DIR
711 #else
713 #endif
714  }
715 
716  if (!SWITCH_GLOBAL_dirs.sounds_dir && (SWITCH_GLOBAL_dirs.sounds_dir = (char *) malloc(BUFSIZE))) {
719  else
720 #ifdef SWITCH_SOUNDS_DIR
722 #else
724 #endif
725  }
726 
730  else
731 #ifdef SWITCH_STORAGE_DIR
733 #else
735 #endif
736  }
737 
738  if (!SWITCH_GLOBAL_dirs.cache_dir && (SWITCH_GLOBAL_dirs.cache_dir = (char *) malloc(BUFSIZE))) {
741  else
742 #ifdef SWITCH_CACHE_DIR
744 #else
746 #endif
747  }
748 
749  if (!SWITCH_GLOBAL_dirs.db_dir && (SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(BUFSIZE))) {
752  else
753 #ifdef SWITCH_DB_DIR
755 #else
757 #endif
758  }
759 
760  if (!SWITCH_GLOBAL_dirs.script_dir && (SWITCH_GLOBAL_dirs.script_dir = (char *) malloc(BUFSIZE))) {
763  else
764 #ifdef SWITCH_SCRIPT_DIR
766 #else
768 #endif
769  }
770 
771  if (!SWITCH_GLOBAL_dirs.htdocs_dir && (SWITCH_GLOBAL_dirs.htdocs_dir = (char *) malloc(BUFSIZE))) {
774  else
775 #ifdef SWITCH_HTDOCS_DIR
777 #else
779 #endif
780  }
781 
785  else
786 #ifdef SWITCH_GRAMMAR_DIR
788 #else
790 #endif
791  }
792 
793  if (!SWITCH_GLOBAL_dirs.fonts_dir && (SWITCH_GLOBAL_dirs.fonts_dir = (char *) malloc(BUFSIZE))) {
796  else
797 #ifdef SWITCH_FONTS_DIR
799 #else
801 #endif
802  }
803 
804  if (!SWITCH_GLOBAL_dirs.images_dir && (SWITCH_GLOBAL_dirs.images_dir = (char *) malloc(BUFSIZE))) {
807  else
808 #ifdef SWITCH_IMAGES_DIR
810 #else
812 #endif
813  }
814 
815  if (!SWITCH_GLOBAL_dirs.data_dir && (SWITCH_GLOBAL_dirs.data_dir = (char *) malloc(BUFSIZE))) {
818  else
819 #ifdef SWITCH_DATA_DIR
821 #else
823 #endif
824  }
825 
829  else
830 #ifdef SWITCH_LOCALSTATE_DIR
832 #else
834 #endif
835  }
836 
837  if (!SWITCH_GLOBAL_dirs.certs_dir && (SWITCH_GLOBAL_dirs.certs_dir = (char *) malloc(BUFSIZE))) {
840  else
841 #ifdef SWITCH_CERTS_DIR
843 #else
845 #endif
846  }
847 
848  if (!SWITCH_GLOBAL_dirs.temp_dir && (SWITCH_GLOBAL_dirs.temp_dir = (char *) malloc(BUFSIZE))) {
849 #ifdef SWITCH_TEMP_DIR
850  switch_snprintf(SWITCH_GLOBAL_dirs.temp_dir, BUFSIZE, "%s", SWITCH_TEMP_DIR);
851 #else
852 #ifdef WIN32
853  GetTempPath(dwBufSize, lpPathBuffer);
854  lpPathBuffer[strlen(lpPathBuffer)-1] = 0;
855  tmp = switch_string_replace(lpPathBuffer, "\\", "/");
856  strcpy(lpPathBuffer, tmp);
857  free(tmp);
858  switch_snprintf(SWITCH_GLOBAL_dirs.temp_dir, BUFSIZE, "%s", lpPathBuffer);
859 #else
861 #endif
862 #endif
863  }
864 
866  switch_snprintf(SWITCH_GLOBAL_filenames.conf_name, BUFSIZE, "%s", "freeswitch.xml");
867  }
868 
869  /* Do this last because it being empty is part of the above logic */
870  if (!SWITCH_GLOBAL_dirs.base_dir && (SWITCH_GLOBAL_dirs.base_dir = (char *) malloc(BUFSIZE))) {
872  }
873 
892 
894 }
#define SWITCH_IMAGES_DIR
#define SWITCH_RECORDINGS_DIR
#define SWITCH_CONF_DIR
#define SWITCH_CACHE_DIR
#define SWITCH_MOD_DIR
#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_HTDOCS_DIR
#define SWITCH_PREFIX_DIR
#define SWITCH_STORAGE_DIR
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:122
#define SWITCH_LOG_DIR
#define SWITCH_RUN_DIR
#define SWITCH_DB_DIR
#define SWITCH_SOUNDS_DIR
char * switch_string_replace(const char *string, const char *search, const char *replace)
#define SWITCH_GRAMMAR_DIR
#define SWITCH_SCRIPT_DIR
#define SWITCH_LOCALSTATE_DIR
switch_filenames SWITCH_GLOBAL_filenames
Definition: switch_core.c:61
#define SWITCH_FONTS_DIR
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:60
#define switch_assert(expr)
#define SWITCH_DATA_DIR
#define SWITCH_CERTS_DIR
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 897 of file switch_core.c.

Referenced by main().

898 {
899 #ifdef SOLARIS_PRIVILEGES
900  priv_set_t *basicset;
901 
902  /* make the process privilege-aware */
903  setpflags(PRIV_AWARE, 1);
904 
905  /* reset the privileges to basic */
906  basicset = priv_str_to_set("basic", ",", NULL);
907  if (setppriv(PRIV_SET, PRIV_EFFECTIVE, basicset) != 0) {
908  fprintf(stderr, "ERROR: Failed to acquire basic privileges (%s)\n", strerror(errno));
909  }
910 
911  /* we need high-resolution clock, and this requires a non-basic privilege */
912  if (priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_PROC_CLOCK_HIGHRES, NULL) < 0) {
913  fprintf(stderr, "ERROR: Failed to acquire proc_clock_highres privilege (%s)\n", strerror(errno));
914  return -1;
915  }
916 
917  /* need this for setrlimit */
918  if (priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_SYS_RESOURCE, NULL) < 0) {
919  fprintf(stderr, "ERROR: Failed to acquire sys_resource privilege (%s)\n", strerror(errno));
920  return -1;
921  }
922 
923  /* we need to read directories belonging to other uid */
924  if (priv_set(PRIV_ON, PRIV_EFFECTIVE, PRIV_FILE_DAC_SEARCH, NULL) < 0) {
925  fprintf(stderr, "ERROR: Failed to acquire file_dac_search privilege (%s)\n", strerror(errno));
926  return -1;
927  }
928 #endif
929  return 0;
930 }
void switch_core_setrlimits ( void  )

Definition at line 1314 of file switch_core.c.

References memset(), SWITCH_SYSTEM_THREAD_STACKSIZE, and SWITCH_THREAD_STACKSIZE.

Referenced by main().

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

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

3636 {
3637  if (sql_manager.paused) {
3638  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL is already paused.\n");
3639  }
3640  sql_manager.paused = 1;
3641 }
#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.
static struct @3 sql_manager
void switch_core_sqldb_resume ( void  )

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

3644 {
3645  if (!sql_manager.paused) {
3646  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL is already running.\n");
3647  }
3648  sql_manager.paused = 0;
3649 }
#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.
static struct @3 sql_manager
switch_time_t switch_core_uptime ( void  )

Number of microseconds the system has been up.

Returns
a number of microseconds

Definition at line 2467 of file switch_core.c.

References switch_runtime::initiated, and switch_mono_micro_time_now().

Referenced by send_heartbeat().

2468 {
2470 }
switch_time_t initiated
struct switch_runtime runtime
Definition: switch_core.c:64
switch_time_t switch_mono_micro_time_now(void)
Definition: switch_time.c:315
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 321 of file switch_time.c.

References switch_micro_time_now().

Referenced by _switch_cache_db_get_db_handle(), audio_bridge_thread(), 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_bug_transfer_recordings(), 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(), switch_ivr_record_session(), switch_ivr_session_transfer(), switch_ivr_uuid_bridge(), switch_nat_late_init(), switch_rtp_create(), switch_rtp_enable_vad(), switch_rtp_init(), switch_scheduler_add_task(), switch_scheduler_execute(), switch_simple_email(), SWITCH_STANDARD_SCHED_FUNC(), task_thread_loop(), and video_bug_thread().

322 {
323  time_t now = switch_micro_time_now() / APR_USEC_PER_SEC;
324  if (t) {
325  *t = now;
326  }
327  return now;
328 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
switch_status_t switch_ivr_preprocess_session ( switch_core_session_t session,
const char *  cmds 
)

Definition at line 2835 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(), pp_cb_t::write_ec, pp_cb_t::write_mutex, and pp_cb_t::write_st.

2836 {
2838  switch_media_bug_t *bug;
2839  switch_status_t status;
2840  time_t to = 0;
2842  switch_codec_implementation_t read_impl = { 0 };
2843  pp_cb_t *cb;
2844  int update = 0;
2845  int argc;
2846  char *mydata = NULL, *argv[5];
2847  int i = 0;
2848 
2849  switch_core_session_get_read_impl(session, &read_impl);
2850 
2851  if ((cb = switch_channel_get_private(channel, "_preprocess"))) {
2852  update = 1;
2853  } else {
2854  cb = switch_core_session_alloc(session, sizeof(*cb));
2855  }
2856 
2857 
2858  if (update) {
2859  if (!strcasecmp(cmds, "stop")) {
2860  cb->done = 1;
2861  return SWITCH_STATUS_SUCCESS;
2862  }
2863  }
2864 
2865  mydata = strdup(cmds);
2866  argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
2867 
2868  for (i = 0; i < argc; i++) {
2869  char *var = argv[i];
2870  char *val = NULL;
2871  char rw;
2872  int tr;
2873  int err = 1;
2874  SpeexPreprocessState *st = NULL;
2875  SpeexEchoState *ec = NULL;
2876  switch_mutex_t *mutex = NULL;
2877  int r = 0;
2878 
2879  if (var) {
2880  if ((val = strchr(var, '='))) {
2881  *val++ = '\0';
2882 
2883  rw = *var++;
2884  while (*var == '.' || *var == '_') {
2885  var++;
2886  }
2887 
2888  if (rw == 'r') {
2889  if (!cb->read_st) {
2890  cb->read_st = speex_preprocess_state_init(read_impl.samples_per_packet, read_impl.samples_per_second);
2891  flags |= SMBF_READ_REPLACE;
2892  }
2893  st = cb->read_st;
2894  ec = cb->read_ec;
2895  mutex = cb->read_mutex;
2896  } else if (rw == 'w') {
2897  if (!cb->write_st) {
2898  cb->write_st = speex_preprocess_state_init(read_impl.samples_per_packet, read_impl.samples_per_second);
2899  flags |= SMBF_WRITE_REPLACE;
2900  }
2901  st = cb->write_st;
2902  ec = cb->write_ec;
2903  mutex = cb->write_mutex;
2904  }
2905 
2906  if (mutex)
2907  switch_mutex_lock(mutex);
2908 
2909  if (st) {
2910  err = 0;
2911  tr = switch_true(val);
2912  if (!strcasecmp(var, "agc")) {
2913  int l = read_impl.samples_per_second;
2914  int tmp = atoi(val);
2915 
2916  if (!tr) {
2917  l = tmp;
2918  }
2919 
2920  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting AGC on %c to %d\n", rw, tr);
2921  speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC, &tr);
2922  speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_LEVEL, &l);
2923 
2924  } else if (!strcasecmp(var, "noise_suppress")) {
2925  int db = atoi(val);
2926  if (db < 0) {
2927  r = speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &db);
2928  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting NOISE_SUPPRESS on %c to %d [%d]\n", rw, db,
2929  r);
2930  } else {
2931  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Syntax error noise_suppress should be in -db\n");
2932  }
2933  } else if (!strcasecmp(var, "echo_cancel")) {
2934  int tail = 1024;
2935  int tmp = atoi(val);
2936 
2937  if (!tr && tmp > 0) {
2938  tail = tmp;
2939  } else if (!tr) {
2940  if (ec) {
2941  if (rw == 'r') {
2942  speex_echo_state_destroy(cb->read_ec);
2943  cb->read_ec = NULL;
2944  } else {
2945  speex_echo_state_destroy(cb->write_ec);
2946  cb->write_ec = NULL;
2947  }
2948  }
2949 
2950  ec = NULL;
2951  }
2952 
2953  if (!ec) {
2954  if (rw == 'r') {
2955  ec = cb->read_ec = speex_echo_state_init(read_impl.samples_per_packet, tail);
2956  speex_echo_ctl(ec, SPEEX_ECHO_SET_SAMPLING_RATE, &read_impl.samples_per_second);
2957  flags |= SMBF_WRITE_REPLACE;
2958  } else {
2959  ec = cb->write_ec = speex_echo_state_init(read_impl.samples_per_packet, tail);
2960  speex_echo_ctl(ec, SPEEX_ECHO_SET_SAMPLING_RATE, &read_impl.samples_per_second);
2961  flags |= SMBF_READ_REPLACE;
2962  }
2963  speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_ECHO_STATE, ec);
2964  }
2965 
2966 
2967  } else if (!strcasecmp(var, "echo_suppress")) {
2968  int db = atoi(val);
2969  if (db < 0) {
2970  speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_ECHO_SUPPRESS, &db);
2971  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting ECHO_SUPPRESS on %c to %d [%d]\n", rw, db,
2972  r);
2973  } else {
2974  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Syntax error echo_suppress should be in -db\n");
2975  }
2976  } else {
2977  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Warning unknown parameter [%s] \n", var);
2978  }
2979  }
2980  }
2981 
2982  if (mutex)
2983  switch_mutex_unlock(mutex);
2984 
2985  if (err) {
2986  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Syntax error parsing preprocessor commands\n");
2987  }
2988 
2989  } else {
2990  break;
2991  }
2992  }
2993 
2994 
2995  switch_safe_free(mydata);
2996 
2997  if (update) {
2998  return SWITCH_STATUS_SUCCESS;
2999  }
3000 
3001 
3002  if ((status = switch_core_media_bug_add(session, "preprocess", NULL,
3003  preprocess_callback, cb, to, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
3004  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error adding media bug.\n");
3005  if (cb->read_st) {
3006  speex_preprocess_state_destroy(cb->read_st);
3007  }
3008 
3009  if (cb->write_st) {
3010  speex_preprocess_state_destroy(cb->write_st);
3011  }
3012 
3013  if (cb->read_ec) {
3014  speex_echo_state_destroy(cb->read_ec);
3015  }
3016 
3017  if (cb->write_ec) {
3018  speex_echo_state_destroy(cb->write_ec);
3019  }
3020 
3021  return status;
3022  }
3023 
3024  switch_channel_set_private(channel, "_preprocess", cb);
3025 
3026  return SWITCH_STATUS_SUCCESS;
3027 }
switch_mutex_t * read_mutex
#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
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.
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
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:285
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
static switch_bool_t preprocess_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
switch_mutex_t * mutex
struct apr_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's pool.
Definition: switch_core.h:694
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
void switch_load_network_lists ( switch_bool_t  reload)

Definition at line 1436 of file switch_core.c.

References switch_runtime::global_mutex, switch_ip_list_t::hash, memset(), switch_xml::next, switch_ip_list_t::pool, 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_token(), switch_network_list_add_host_mask(), switch_network_list_create(), 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().

1437 {
1438  switch_xml_t xml = NULL, x_lists = NULL, x_list = NULL, x_node = NULL, cfg = NULL;
1439  switch_network_list_t *rfc_list, *list;
1440  char guess_ip[16] = "";
1441  int mask = 0;
1442  char guess_mask[16] = "";
1443  char *tmp_name;
1444  struct in_addr in;
1445 
1446  switch_find_local_ip(guess_ip, sizeof(guess_ip), &mask, AF_INET);
1447  in.s_addr = mask;
1448  switch_set_string(guess_mask, inet_ntoa(in));
1449 
1451 
1452  if (IP_LIST.hash) {
1454  }
1455 
1456  if (IP_LIST.pool) {
1458  }
1459 
1460  memset(&IP_LIST, 0, sizeof(IP_LIST));
1463 
1464 
1465  tmp_name = "rfc6598.auto";
1466  switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool);
1467  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
1468  switch_network_list_add_cidr(rfc_list, "100.64.0.0/10", SWITCH_TRUE);
1469  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1470 
1471  tmp_name = "rfc1918.auto";
1472  switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool);
1473  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
1474  switch_network_list_add_cidr(rfc_list, "10.0.0.0/8", SWITCH_TRUE);
1475  switch_network_list_add_cidr(rfc_list, "172.16.0.0/12", SWITCH_TRUE);
1476  switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_TRUE);
1477  switch_network_list_add_cidr(rfc_list, "fe80::/10", SWITCH_TRUE);
1478  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1479 
1480  tmp_name = "wan.auto";
1481  switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
1482  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (allow)\n", tmp_name);
1483  switch_network_list_add_cidr(rfc_list, "0.0.0.0/8", SWITCH_FALSE);
1484  switch_network_list_add_cidr(rfc_list, "10.0.0.0/8", SWITCH_FALSE);
1485  switch_network_list_add_cidr(rfc_list, "172.16.0.0/12", SWITCH_FALSE);
1486  switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_FALSE);
1487  switch_network_list_add_cidr(rfc_list, "169.254.0.0/16", SWITCH_FALSE);
1488  switch_network_list_add_cidr(rfc_list, "fe80::/10", SWITCH_FALSE);
1489  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1490 
1491  tmp_name = "wan_v6.auto";
1492  switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
1493  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (allow)\n", tmp_name);
1494  switch_network_list_add_cidr(rfc_list, "0.0.0.0/0", SWITCH_FALSE);
1495  switch_network_list_add_cidr(rfc_list, "fe80::/10", SWITCH_FALSE);
1496  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1497 
1498 
1499  tmp_name = "wan_v4.auto";
1500  switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
1501  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (allow)\n", tmp_name);
1502  switch_network_list_add_cidr(rfc_list, "0.0.0.0/8", SWITCH_FALSE);
1503  switch_network_list_add_cidr(rfc_list, "10.0.0.0/8", SWITCH_FALSE);
1504  switch_network_list_add_cidr(rfc_list, "172.16.0.0/12", SWITCH_FALSE);
1505  switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_FALSE);
1506  switch_network_list_add_cidr(rfc_list, "169.254.0.0/16", SWITCH_FALSE);
1507  switch_network_list_add_cidr(rfc_list, "::/0", SWITCH_FALSE);
1508  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1509 
1510 
1511  tmp_name = "any_v6.auto";
1512  switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
1513  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (allow)\n", tmp_name);
1514  switch_network_list_add_cidr(rfc_list, "0.0.0.0/0", SWITCH_FALSE);
1515  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1516 
1517 
1518  tmp_name = "any_v4.auto";
1519  switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
1520  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (allow)\n", tmp_name);
1521  switch_network_list_add_cidr(rfc_list, "::/0", SWITCH_FALSE);
1522  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1523 
1524 
1525  tmp_name = "nat.auto";
1526  switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool);
1527  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
1528  if (switch_network_list_add_host_mask(rfc_list, guess_ip, guess_mask, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
1529  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding %s/%s (deny) to list %s\n", guess_ip, guess_mask, tmp_name);
1530  }
1531  switch_network_list_add_cidr(rfc_list, "10.0.0.0/8", SWITCH_TRUE);
1532  switch_network_list_add_cidr(rfc_list, "172.16.0.0/12", SWITCH_TRUE);
1533  switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_TRUE);
1534  switch_network_list_add_cidr(rfc_list, "100.64.0.0/10", SWITCH_TRUE);
1535  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1536 
1537  tmp_name = "loopback.auto";
1538  switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool);
1539  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
1540  switch_network_list_add_cidr(rfc_list, "127.0.0.0/8", SWITCH_TRUE);
1541  switch_network_list_add_cidr(rfc_list, "::1/128", SWITCH_TRUE);
1542  switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
1543 
1544  tmp_name = "localnet.auto";
1546  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
1547 
1548  if (switch_network_list_add_host_mask(list, guess_ip, guess_mask, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
1549  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding %s/%s (allow) to list %s\n", guess_ip, guess_mask, tmp_name);
1550  }
1551  switch_core_hash_insert(IP_LIST.hash, tmp_name, list);
1552 
1553 
1554  if ((xml = switch_xml_open_cfg("acl.conf", &cfg, NULL))) {
1555  if ((x_lists = switch_xml_child(cfg, "network-lists"))) {
1556  for (x_list = switch_xml_child(x_lists, "list"); x_list; x_list = x_list->next) {
1557  const char *name = switch_xml_attr(x_list, "name");
1558  const char *dft = switch_xml_attr(x_list, "default");
1559  switch_bool_t default_type = SWITCH_TRUE;
1560 
1561  if (zstr(name)) {
1562  continue;
1563  }
1564 
1565  if (dft) {
1566  default_type = switch_true(dft);
1567  }
1568 
1569  if (switch_network_list_create(&list, name, default_type, IP_LIST.pool) != SWITCH_STATUS_SUCCESS) {
1570  abort();
1571  }
1572 
1573  if (reload) {
1574  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (%s)\n", name, default_type ? "allow" : "deny");
1575  } else {
1576  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Created ip list %s default (%s)\n", name, default_type ? "allow" : "deny");
1577  }
1578 
1579 
1580  for (x_node = switch_xml_child(x_list, "node"); x_node; x_node = x_node->next) {
1581  const char *cidr = NULL, *host = NULL, *mask = NULL, *domain = NULL;
1582  switch_bool_t ok = default_type;
1583  const char *type = switch_xml_attr(x_node, "type");
1584 
1585  if (type) {
1586  ok = switch_true(type);
1587  }
1588 
1589  cidr = switch_xml_attr(x_node, "cidr");
1590  host = switch_xml_attr(x_node, "host");
1591  mask = switch_xml_attr(x_node, "mask");
1592  domain = switch_xml_attr(x_node, "domain");
1593 
1594  if (domain) {
1595  switch_event_t *my_params = NULL;
1596  switch_xml_t x_domain, xml_root;
1597  switch_xml_t gt, gts, ut, uts;
1598 
1600  switch_assert(my_params);
1601  switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "domain", domain);
1602  switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "purpose", "network-list");
1603 
1604  if (switch_xml_locate_domain(domain, my_params, &xml_root, &x_domain) != SWITCH_STATUS_SUCCESS) {
1605  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate domain %s\n", domain);
1606  switch_event_destroy(&my_params);
1607  continue;
1608  }
1609 
1610  switch_event_destroy(&my_params);
1611 
1612  if ((ut = switch_xml_child(x_domain, "users"))) {
1613  x_domain = ut;
1614  }
1615 
1616  for (ut = switch_xml_child(x_domain, "user"); ut; ut = ut->next) {
1617  const char *user_cidr = switch_xml_attr(ut, "cidr");
1618  const char *id = switch_xml_attr(ut, "id");
1619 
1620  if (id && user_cidr) {
1621  char *token = switch_mprintf("%s@%s", id, domain);
1622  switch_assert(token);
1623  switch_network_list_add_cidr_token(list, user_cidr, ok, token);
1624  free(token);
1625  }
1626  }
1627 
1628  for (gts = switch_xml_child(x_domain, "groups"); gts; gts = gts->next) {
1629  for (gt = switch_xml_child(gts, "group"); gt; gt = gt->next) {
1630  for (uts = switch_xml_child(gt, "users"); uts; uts = uts->next) {
1631  for (ut = switch_xml_child(uts, "user"); ut; ut = ut->next) {
1632  const char *user_cidr = switch_xml_attr(ut, "cidr");
1633  const char *id = switch_xml_attr(ut, "id");
1634 
1635  if (id && user_cidr) {
1636  char *token = switch_mprintf("%s@%s", id, domain);
1637  switch_assert(token);
1638  switch_network_list_add_cidr_token(list, user_cidr, ok, token);
1639  free(token);
1640  }
1641  }
1642  }
1643  }
1644  }
1645 
1646  switch_xml_free(xml_root);
1647  } else if (cidr) {
1648  switch_network_list_add_cidr(list, cidr, ok);
1649  } else if (host && mask) {
1650  switch_network_list_add_host_mask(list, host, mask, ok);
1651  }
1652 
1653  switch_core_hash_insert(IP_LIST.hash, name, list);
1654  }
1655  }
1656  }
1657 
1658  switch_xml_free(xml);
1659  }
1660 
1662 }
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's master pool.
Definition: switch_core.h:631
switch_memory_pool_t * pool
Definition: switch_core.c:1360
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:1390
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:404
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:552
switch_bool_t
Definition: switch_types.h:405
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:640
Representation of an event.
Definition: switch_event.h:80
#define switch_network_list_add_cidr(_list, _cidr_str, _ok)
A representation of an XML tree.
Definition: switch_xml.h:76
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
struct switch_runtime runtime
Definition: switch_core.c:64
#define zstr(x)
Definition: switch_utils.h:281
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_hash_t * hash
Definition: switch_core.c:1361
switch_xml_t next
Definition: switch_xml.h:88
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:579
switch_byte_t in
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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:1364
switch_mutex_t * global_mutex
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:1410
#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:383
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:665
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
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)
void* switch_loadable_module_create_interface ( switch_loadable_module_interface_t mod,
switch_module_interface_name_t  iname 
)

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

2651 {
2652 
2653  switch (iname) {
2655  ALLOC_INTERFACE(endpoint)
2656 
2658  ALLOC_INTERFACE(timer)
2659 
2661  ALLOC_INTERFACE(dialplan)
2662 
2664  ALLOC_INTERFACE(codec)
2665 
2667  ALLOC_INTERFACE(application)
2668 
2670  ALLOC_INTERFACE(chat_application)
2671 
2672  case SWITCH_API_INTERFACE:
2673  ALLOC_INTERFACE(api)
2674 
2676  ALLOC_INTERFACE(json_api)
2677 
2678  case SWITCH_FILE_INTERFACE:
2679  ALLOC_INTERFACE(file)
2680 
2682  ALLOC_INTERFACE(speech)
2683 
2685  ALLOC_INTERFACE(directory)
2686 
2687  case SWITCH_CHAT_INTERFACE:
2688  ALLOC_INTERFACE(chat)
2689 
2690  case SWITCH_SAY_INTERFACE:
2691  ALLOC_INTERFACE(say)
2692 
2693  case SWITCH_ASR_INTERFACE:
2694  ALLOC_INTERFACE(asr)
2695 
2697  ALLOC_INTERFACE(management)
2698 
2700  ALLOC_INTERFACE(limit)
2701 
2702  default:
2703  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Module Type!\n");
2704  return NULL;
2705  }
2706 }
#define ALLOC_INTERFACE(_TYPE_)
#define SWITCH_CHANNEL_LOG
return
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_interface_t* switch_loadable_module_create_module_interface ( switch_memory_pool_t pool,
const char *  name 
)

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

2621 {
2623 
2625  switch_assert(mod != NULL);
2626 
2627  mod->pool = pool;
2628 
2629  mod->module_name = switch_core_strdup(mod->pool, name);
2631  return mod;
2632 }
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
switch_memory_pool_t * pool
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
switch_status_t switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock, switch_memory_pool_t *pool)
Definition: switch_apr.c:212
#define switch_assert(expr)
The abstraction of a loadable module.
const char* switch_lookup_timezone ( const char *  tz_name)

Definition at line 1361 of file switch_time.c.

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

Referenced by switch_strftime_tz(), and switch_time_exp_tz_name().

1362 {
1363  char *value = NULL;
1364 
1365  if (zstr(tz_name) || !TIMEZONES_LIST.hash) {
1366  return NULL;
1367  }
1368 
1369  if ((value = switch_core_hash_find(TIMEZONES_LIST.hash, tz_name)) == NULL) {
1370  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timezone '%s' not found!\n", tz_name);
1371  }
1372 
1373  return value;
1374 }
#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.
static switch_timezones_list_t TIMEZONES_LIST
Definition: switch_time.c:1358
#define zstr(x)
Definition: switch_utils.h:281
switch_hash_t * hash
Definition: switch_time.c:1355
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_time_t switch_micro_time_now ( void  )

Get the current epoch time in microseconds.

Returns
the current epoch time in microseconds

Definition at line 310 of file switch_time.c.

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

Referenced by check_jitter(), check_rtcp_and_ice(), API::getTime(), handle_ice(), ice_out(), read_rtp_packet(), record_callback(), 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_console_printf(), switch_core_media_codec_control(), switch_core_port_allocator_request_port(), switch_core_session_request_video_refresh(), 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_parse_event(), switch_ivr_sleep(), switch_ivr_tone_detect_session(), switch_ivr_wait_for_answer(), switch_log_vprintf(), switch_pgsql_next_result_timed(), switch_rtp_activate_ice(), switch_rtp_create(), 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_init(), and tone_detect_set_total_time().

311 {
312  return (globals.RUNNING == 1 && runtime.timestamp) ? runtime.timestamp : switch_time_now();
313 }
struct switch_runtime runtime
Definition: switch_core.c:64
static struct @7 globals
switch_time_t timestamp
switch_time_t switch_time_now(void)
Definition: switch_apr.c:302
switch_time_t switch_mono_micro_time_now ( void  )

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

316 {
317  return time_now(-1);
318 }
static switch_time_t time_now(int64_t offset)
Definition: switch_time.c:520
int switch_stream_system ( const char *  cmd,
switch_stream_handle_t stream 
)

Definition at line 3273 of file switch_core.c.

References switch_stream_system_fork(), switch_system(), and SWITCH_TRUE.

3274 {
3275 #ifdef WIN32
3276  stream->write_function(stream, "Capturing output not supported.\n");
3277  return switch_system(cmd, SWITCH_TRUE);
3278 #else
3279  return switch_stream_system_fork(cmd, stream);
3280 #endif
3281 
3282 }
int switch_system(const char *cmd, switch_bool_t wait)
Definition: switch_core.c:3194
switch_stream_handle_write_function_t write_function
int switch_stream_system_fork(const char *cmd, switch_stream_handle_t *stream)
Definition: switch_core.c:3206
switch_status_t switch_strftime_tz ( const char *  tz,
const char *  format,
char *  date,
size_t  len,
switch_time_t  thetime 
)

Definition at line 1458 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.

1459 {
1460  time_t timep;
1461 
1462  const char *tz_name = tz;
1463  const char *tzdef;
1464 
1465  switch_size_t retsize;
1466 
1467  struct tm tm = { 0 };
1468  switch_time_exp_t stm;
1469 
1470  if (!thetime) {
1471  thetime = switch_micro_time_now();
1472  }
1473 
1474  timep = (thetime) / (int64_t) (1000000);
1475 
1476  if (!zstr(tz_name)) {
1477  tzdef = switch_lookup_timezone(tz_name);
1478  } else {
1479  /* We set the default timezone to GMT. */
1480  tz_name = "GMT";
1481  tzdef = "GMT";
1482  }
1483 
1484  if (tzdef) { /* The lookup of the zone may fail. */
1485  tztime(&timep, tzdef, &tm);
1486  tm2switchtime(&tm, &stm);
1487  switch_strftime_nocheck(date, &retsize, len, zstr(format) ? "%Y-%m-%d %T" : format, &stm);
1488  if (!zstr_buf(date)) {
1489  return SWITCH_STATUS_SUCCESS;
1490  }
1491  }
1492  return SWITCH_STATUS_FALSE;
1493 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
static void tm2switchtime(struct tm *tm, switch_time_exp_t *xt)
Definition: switch_time.c:1324
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:179
#define zstr(x)
Definition: switch_utils.h:281
uintptr_t switch_size_t
#define zstr_buf(s)
Definition: switch_utils.h:285
static void tztime(const time_t *const timep, const char *tzstring, struct tm *const tmp)
Definition: switch_time.c:2431
const char * switch_lookup_timezone(const char *tz_name)
Definition: switch_time.c:1361
int switch_system ( const char *  cmd,
switch_bool_t  wait 
)

Definition at line 3194 of file switch_core.c.

References SCF_THREADED_SYSTEM_EXEC, switch_system_fork(), switch_system_thread(), and switch_test_flag.

Referenced by preprocess_exec(), switch_simple_email(), switch_stream_system(), and switch_stream_system_fork().

3195 {
3196  int (*sys_p)(const char *cmd, switch_bool_t wait);
3197 
3199 
3200  return sys_p(cmd, wait);
3201 
3202 }
switch_bool_t
Definition: switch_types.h:405
struct switch_runtime runtime
Definition: switch_core.c:64
static int switch_system_thread(const char *cmd, switch_bool_t wait)
Definition: switch_core.c:3041
static int switch_system_fork(const char *cmd, switch_bool_t wait)
Definition: switch_core.c:3147
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
switch_status_t switch_time_exp_tz_name ( const char *  tz,
switch_time_exp_t tm,
switch_time_t  thetime 
)

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

1428 {
1429  struct tm xtm = { 0 };
1430  const char *tz_name = tz;
1431  const char *tzdef;
1432  time_t timep;
1433 
1434  if (!thetime) {
1435  thetime = switch_micro_time_now();
1436  }
1437 
1438  timep = (thetime) / (int64_t) (1000000);
1439 
1440  if (!zstr(tz_name)) {
1441  tzdef = switch_lookup_timezone(tz_name);
1442  } else {
1443  /* We set the default timezone to GMT. */
1444  tz_name = "GMT";
1445  tzdef = "GMT";
1446  }
1447 
1448  if (tzdef) { /* The lookup of the zone may fail. */
1449  tztime(&timep, tzdef, &xtm);
1450  tm2switchtime(&xtm, tm);
1451  return SWITCH_STATUS_SUCCESS;
1452  }
1453 
1454  return SWITCH_STATUS_FALSE;
1455 
1456 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
static void tm2switchtime(struct tm *tm, switch_time_exp_t *xt)
Definition: switch_time.c:1324
#define zstr(x)
Definition: switch_utils.h:281
static void tztime(const time_t *const timep, const char *tzstring, struct tm *const tmp)
Definition: switch_time.c:2431
const char * switch_lookup_timezone(const char *tz_name)
Definition: switch_time.c:1361
switch_time_t switch_time_ref ( void  )

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

577 {
578  if (SYSTEM_TIME) {
579  /* Return system time reference */
580  return time_now(0);
581  } else {
582  /* Return monotonic time reference (when available) */
584  }
585 }
static switch_time_t time_now(int64_t offset)
Definition: switch_time.c:520
switch_time_t switch_mono_micro_time_now(void)
Definition: switch_time.c:315
static int SYSTEM_TIME
Definition: switch_time.c:67
void switch_time_set_cond_yield ( switch_bool_t  enable)

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

373 {
374  COND = enable ? 1 : 0;
375  if (COND) {
376  MATRIX = 1;
377  }
379 }
void switch_time_sync(void)
Definition: switch_time.c:589
static int COND
Definition: switch_time.c:86
static int MATRIX
Definition: switch_time.c:88
void switch_time_set_matrix ( switch_bool_t  enable)

Definition at line 359 of file switch_time.c.

References MATRIX, and switch_time_sync().

Referenced by switch_load_core_config().

360 {
361  MATRIX = enable ? 1 : 0;
363 }
void switch_time_sync(void)
Definition: switch_time.c:589
static int MATRIX
Definition: switch_time.c:88
void switch_time_set_monotonic ( switch_bool_t  enable)

Definition at line 330 of file switch_time.c.

References MONO, and switch_time_sync().

Referenced by switch_load_core_config().

331 {
332 #if (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) || defined(WIN32)
333  MONO = enable ? 1 : 0;
335 #else
336  MONO = 0;
337 #endif
338 }
void switch_time_sync(void)
Definition: switch_time.c:589
static int MONO
Definition: switch_time.c:63
void switch_time_set_nanosleep ( switch_bool_t  enable)

Definition at line 365 of file switch_time.c.

References NANO.

Referenced by switch_load_core_config(), and SWITCH_MODULE_LOAD_FUNCTION().

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

Definition at line 347 of file switch_time.c.

References switch_time_sync(), and TFD.

Referenced by switch_load_core_config().

348 {
349 #if defined(HAVE_TIMERFD_CREATE)
350  TFD = enable;
352 
353 #else
354  TFD = 0;
355 #endif
356 }
void switch_time_sync(void)
Definition: switch_time.c:589
static int TFD
Definition: switch_time.c:80
void switch_time_set_use_system_time ( switch_bool_t  enable)

Definition at line 341 of file switch_time.c.

References SYSTEM_TIME.

Referenced by switch_load_core_config().

342 {
343  SYSTEM_TIME = enable;
344 }
static int SYSTEM_TIME
Definition: switch_time.c:67
void switch_time_sync ( void  )

Definition at line 589 of file switch_time.c.

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

590 {
591  runtime.time_sync++; /* Indicate that we are syncing time right now */
592 
594 
595  if (SYSTEM_TIME) {
597  runtime.offset = 0;
598  } else {
599  runtime.offset = runtime.reference - switch_mono_micro_time_now(); /* Get the offset between system time and the monotonic clock (when available) */
601  }
602 
603  if (runtime.reference - last_time > 1000000 || last_time == 0) {
604  if (SYSTEM_TIME) {
605  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Clock is already configured to always report system time.\n");
606  } else {
607  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Clock synchronized to system time.\n");
608  }
609  }
611 
612  runtime.time_sync++; /* Indicate that we are finished syncing time */
613 }
#define SWITCH_CHANNEL_LOG
static switch_time_t time_now(int64_t offset)
Definition: switch_time.c:520
struct switch_runtime runtime
Definition: switch_core.c:64
switch_time_t switch_mono_micro_time_now(void)
Definition: switch_time.c:315
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:587
static int SYSTEM_TIME
Definition: switch_time.c:67
switch_time_t switch_time_now(void)
Definition: switch_apr.c:302
switch_time_t reference