Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

Misc
[Core Library]


Defines

#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.
switch_bool_t switch_core_ready (void)
 Determines if the core is ready to take calls.
switch_core_flag_t switch_core_flags (void)
 return core flags
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.
int32_t set_high_priority (void)
 Set the maximum priority the process can obtain.
int32_t change_user_group (const char *user, const char *group)
 Change user and/or group of the running process.
void switch_core_runtime_loop (int bg)
 Run endlessly until the system is shutdown.
switch_status_t switch_core_set_console (const char *console)
 Set the output console to the desired file.
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.
switch_time_t switch_core_uptime (void)
 Number of microseconds the system has been up.
int32_t switch_core_session_ctl (switch_session_ctl_t cmd, int32_t *val)
 send a control message to the core
FILE * switch_core_get_console (void)
 Get the output console.
void switch_core_launch_thread (void *(*func)(switch_thread_t *, void *), void *obj, switch_memory_pool_t *pool)
 Launch a thread.
void switch_core_set_globals (void)
 Initiate Globals.
uint8_t switch_core_session_compare (switch_core_session_t *a, switch_core_session_t *b)
 indicate if 2 sessions are the same type
uint8_t switch_core_session_check_interface (switch_core_session_t *session, const switch_endpoint_interface_t *endpoint_interface)
switch_hash_index_tswitch_core_mime_index (void)
const char * switch_core_mime_ext2type (const char *ext)
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_timestamp_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)
void switch_time_sync (void)
time_t switch_timestamp (time_t *t)
switch_status_t switch_strftime_tz (const char *tz, const char *format, char *date, size_t len)
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)
uint32_t switch_core_max_dtmf_duration (uint32_t duration)
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)


Define Documentation

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


Function Documentation

int32_t change_user_group const char *  user,
const char *  group
 

Change user and/or group of the running process.

Parameters:
user name of the user to switch to (or NULL)
group name 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
00535 {
00536 #ifndef WIN32
00537         uid_t runas_uid = 0;
00538         gid_t runas_gid = 0;
00539         struct passwd *runas_pw = NULL;
00540 
00541         if (user) {
00542                 /*
00543                  * Lookup user information in the system's db
00544                  */
00545                 runas_pw = getpwnam(user);
00546                 if (!runas_pw) {
00547                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unknown user \"%s\"\n", user);
00548                         return -1;
00549                 }
00550                 runas_uid = runas_pw->pw_uid;
00551         }
00552 
00553         if (group) {
00554                 struct group *gr = NULL;
00555 
00556                 /*
00557                  * Lookup group information in the system's db
00558                  */
00559                 gr = getgrnam(group);
00560                 if (!gr) {
00561                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unknown group \"%s\"\n", group);
00562                         return -1;
00563                 }
00564                 runas_gid = gr->gr_gid;
00565         }
00566 
00567         if (runas_uid && getuid() == runas_uid && (!runas_gid || runas_gid == getgid())) {
00568                 /* already running as the right user and group, nothing to do! */
00569                 return 0;
00570         }
00571 
00572         if (runas_uid) {
00573 #ifdef HAVE_SETGROUPS
00574                 /*
00575                  * Drop all group memberships prior to changing anything
00576                  * or else we're going to inherit the parent's list of groups
00577                  * (which is not what we want...)
00578                  */
00579                 if (setgroups(0, NULL) < 0) {
00580                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to drop group access list\n");
00581                         return -1;
00582                 }
00583 #endif
00584                 if (runas_gid) {
00585                         /*
00586                          * A group has been passed, switch to it
00587                          * (without loading the user's other groups)
00588                          */
00589                         if (setgid(runas_gid) < 0) {
00590                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to change gid!\n");
00591                                 return -1;
00592                         }
00593                 } else {
00594                         /*
00595                          * No group has been passed, use the user's primary group in this case
00596                          */
00597                         if (setgid(runas_pw->pw_gid) < 0) {
00598                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to change gid!\n");
00599                                 return -1;
00600                         }
00601 #ifdef HAVE_INITGROUPS
00602                         /*
00603                          * Set all the other groups the user is a member of
00604                          * (This can be really useful for fine-grained access control)
00605                          */
00606                         if (initgroups(runas_pw->pw_name, runas_pw->pw_gid) < 0) {
00607                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to set group access list for user\n");
00608                                 return -1;
00609                         }
00610 #endif
00611                 }
00612 
00613                 /*
00614                  * Finally drop all privileges by switching to the new userid
00615                  */
00616                 if (setuid(runas_uid) < 0) {
00617                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to change uid!\n");
00618                         return -1;
00619                 }
00620         }
00621 #endif
00622         return 0;
00623 }

Here is the call graph for this function:

int32_t set_high_priority void   ) 
 

Set the maximum priority the process can obtain.

Returns:
0 on success
00474 {
00475 #ifdef WIN32
00476         SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
00477 #else
00478 
00479 #ifdef USE_SETRLIMIT
00480         struct rlimit lim = { RLIM_INFINITY, RLIM_INFINITY };
00481 #endif
00482 
00483 #ifdef USE_SCHED_SETSCHEDULER
00484         /*
00485          * Try to use a round-robin scheduler
00486          * with a fallback if that does not work
00487          */
00488         struct sched_param sched = { 0 };
00489         sched.sched_priority = 1;
00490         if (sched_setscheduler(0, SCHED_RR, &sched)) {
00491                 sched.sched_priority = 0;
00492                 if (sched_setscheduler(0, SCHED_OTHER, &sched)) {
00493                         return -1;
00494                 }
00495         }
00496 #endif
00497 
00498 #ifdef HAVE_SETPRIORITY
00499         /*
00500          * setpriority() works on FreeBSD (6.2), nice() doesn't
00501          */
00502         if (setpriority(PRIO_PROCESS, getpid(), -10) < 0) {
00503                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not set nice level\n");
00504         }
00505 #else
00506         if (nice(-10) != -10) {
00507                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not set nice level\n");
00508         }
00509 #endif
00510 
00511 #ifdef USE_SETRLIMIT
00512         /*
00513          * The amount of memory which can be mlocked is limited for non-root users.
00514          * FS will segfault (= hitting the limit) soon after mlockall has been called
00515          * and we've switched to a different user.
00516          * So let's try to remove the mlock limit here...
00517          */
00518         if (setrlimit(RLIMIT_MEMLOCK, &lim) < 0) {
00519                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to disable memlock limit, application may crash if run as non-root user!\n");
00520         }
00521 #endif
00522 
00523 #ifdef USE_MLOCKALL
00524         /*
00525          * Pin memory pages to RAM to prevent being swapped to disk
00526          */
00527         mlockall(MCL_CURRENT | MCL_FUTURE);
00528 #endif
00529 
00530 #endif
00531         return 0;
00532 }

Here is the call graph for this function:

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

00797 {
00798         switch_network_list_t *list;
00799         uint32_t ip, net, mask, bits;
00800         switch_bool_t ok = SWITCH_FALSE;
00801 
00802         switch_mutex_lock(runtime.global_mutex);
00803         switch_inet_pton(AF_INET, ip_str, &ip);
00804 
00805         ip = htonl(ip);
00806 
00807         if ((list = switch_core_hash_find(IP_LIST.hash, list_name))) {
00808                 ok = switch_network_list_validate_ip_token(list, ip, token);
00809         } else if (strchr(list_name, '/')) {
00810                 switch_parse_cidr(list_name, &net, &mask, &bits);
00811                 ok = switch_test_subnet(ip, net, mask);
00812         }
00813         switch_mutex_unlock(runtime.global_mutex);
00814 
00815         return ok;
00816 }

Here is the call graph for this function:

switch_status_t switch_console_set_alias const char *  string  ) 
 

00797 {
00798         return SWITCH_STATUS_FALSE;
00799 }

switch_status_t switch_console_set_complete const char *  string  ) 
 

00802 {
00803         return SWITCH_STATUS_FALSE;
00804 }

FILE* switch_core_data_channel switch_text_channel_t  channel  ) 
 

Retrieve a FILE stream of a given text channel name.

Parameters:
channel text channel enumeration
Returns:
a FILE stream
00153 {
00154         FILE *handle = stdout;
00155 
00156         switch (channel) {
00157         case SWITCH_CHANNEL_ID_LOG:
00158         case SWITCH_CHANNEL_ID_LOG_CLEAN:
00159                 handle = runtime.console;
00160                 break;
00161         default:
00162                 handle = runtime.console;
00163                 break;
00164         }
00165 
00166         return handle;
00167 }

uint32_t switch_core_default_dtmf_duration uint32_t  duration  ) 
 

00953 {
00954         if (duration) {
00955                 if (duration < SWITCH_DEFAULT_DTMF_DURATION) {
00956                         duration = SWITCH_DEFAULT_DTMF_DURATION;
00957                 }
00958                 runtime.default_dtmf_duration = duration;
00959         }
00960         return runtime.default_dtmf_duration;
00961 }

switch_core_flag_t switch_core_flags void   ) 
 

return core flags

Returns:
core flags
01398 {
01399         return runtime.flags;
01400 }

FILE* switch_core_get_console void   ) 
 

Get the output console.

Returns:
the FILE stream
00148 {
00149         return runtime.console;
00150 }

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

Launch a thread.

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_oid the relative oid of the operation.
action the action to perform.
data input/output string.
datalen size in bytes of data.
Returns:
SUCCESS on sucess.
01466 {
01467         const switch_management_interface_t *ptr;
01468         switch_status_t status = SWITCH_STATUS_FALSE;
01469 
01470         if ((ptr = switch_loadable_module_get_management_interface(relative_oid))) {
01471                 status = ptr->management_function(relative_oid, action, data, datalen);
01472         }
01473 
01474         return status;
01475 }

Here is the call graph for this function:

uint32_t switch_core_max_dtmf_duration uint32_t  duration  ) 
 

00942 {
00943         if (duration) {
00944                 if (duration > SWITCH_MAX_DTMF_DURATION) {
00945                         duration = SWITCH_MAX_DTMF_DURATION;
00946                 }
00947                 runtime.max_dtmf_duration = duration;
00948         }
00949         return runtime.max_dtmf_duration;
00950 }

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_ms a number of milliseconds
duration an object to store the results
01270 {
01271         switch_time_t temp = total_ms / 1000;
01272         memset(duration, 0, sizeof(*duration));
01273         duration->mms = (uint32_t) (total_ms % 1000);
01274         duration->ms = (uint32_t) (temp % 1000);
01275         temp = temp / 1000;
01276         duration->sec = (uint32_t) (temp % 60);
01277         temp = temp / 60;
01278         duration->min = (uint32_t) (temp % 60);
01279         temp = temp / 60;
01280         duration->hr = (uint32_t) (temp % 24);
01281         temp = temp / 24;
01282         duration->day = (uint32_t) (temp % 365);
01283         duration->yr = (uint32_t) (temp / 365);
01284 }

void switch_core_memory_reclaim void   ) 
 

00356 {
00357         switch_memory_pool_t *pool;
00358         void *pop = NULL;
00359         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled memory pool(s)\n",
00360                                           switch_queue_size(memory_manager.pool_recycle_queue) + switch_queue_size(memory_manager.pool_queue));
00361 
00362         while (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS) {
00363                 pool = (switch_memory_pool_t *) pop;
00364                 if (!pool) {
00365                         break;
00366                 }
00367                 apr_pool_destroy(pool);
00368         }
00369 }

Here is the call graph for this function:

void switch_core_memory_reclaim_all void   ) 
 

Here is the call graph for this function:

void switch_core_memory_reclaim_events void   ) 
 

00407 {
00408         void *pop;
00409         int size;
00410         size = switch_queue_size(EVENT_RECYCLE_QUEUE);
00411 
00412         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled event(s) %d bytes\n", size, (int) sizeof(switch_event_t) * size);
00413         size = switch_queue_size(EVENT_HEADER_RECYCLE_QUEUE);
00414         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled event header(s) %d bytes\n",
00415                                           size, (int) sizeof(switch_event_header_t) * size);
00416 
00417         while (switch_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
00418                 free(pop);
00419         }
00420         while (switch_queue_trypop(EVENT_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
00421                 free(pop);
00422         }
00423 }

Here is the call graph for this function:

void switch_core_memory_reclaim_logger void   ) 
 

00424 {
00425         void *pop;
00426         int size = switch_queue_size(LOG_RECYCLE_QUEUE);
00427         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled log node(s) %d bytes\n", size,
00428                                           (int) sizeof(switch_log_node_t) * size);
00429         while (switch_queue_trypop(LOG_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
00430                 free(pop);
00431         }
00432 }

Here is the call graph for this function:

switch_status_t switch_core_mime_add_type const char *  type,
const char *  ext
 

00666 {
00667         const char *check;
00668         switch_status_t status = SWITCH_STATUS_FALSE;
00669 
00670         switch_assert(type);
00671         switch_assert(ext);
00672 
00673         check = (const char *) switch_core_hash_find(runtime.mime_types, ext);
00674 
00675         if (!check) {
00676                 char *ptype = switch_core_permanent_strdup(type);
00677                 char *ext_list = strdup(ext);
00678                 int argc = 0;
00679                 char *argv[20] = { 0 };
00680                 int x;
00681 
00682                 switch_assert(ext_list);
00683 
00684                 if ((argc = switch_separate_string(ext_list, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
00685 
00686                         for (x = 0; x < argc; x++) {
00687                                 if (argv[x] && ptype) {
00688                                         switch_core_hash_insert(runtime.mime_types, argv[x], ptype);
00689                                 }
00690                         }
00691 
00692                         status = SWITCH_STATUS_SUCCESS;
00693                 }
00694 
00695                 free(ext_list);
00696         }
00697 
00698         return status;
00699 }

Here is the call graph for this function:

const char* switch_core_mime_ext2type const char *  ext  ) 
 

00652 {
00653         if (!ext) {
00654                 return NULL;
00655         }
00656         return (const char *) switch_core_hash_find(runtime.mime_types, ext);
00657 }

Here is the call graph for this function:

switch_hash_index_t* switch_core_mime_index void   ) 
 

00661 {
00662         return switch_hash_first(NULL, runtime.mime_types);
00663 }

Here is the call graph for this function:

switch_bool_t switch_core_ready void   ) 
 

Determines if the core is ready to take calls.

Returns:
SWITCH_TRUE or SWITCH_FALSE
01403 {
01404         return (switch_test_flag((&runtime), SCF_SHUTTING_DOWN) || switch_test_flag((&runtime), SCF_NO_NEW_SESSIONS)) ? SWITCH_FALSE : SWITCH_TRUE;
01405 }

void switch_core_runtime_loop int  bg  ) 
 

Run endlessly until the system is shutdown.

Parameters:
bg divert console to the background
00626 {
00627 #ifdef WIN32
00628         HANDLE shutdown_event;
00629         char path[256] = "";
00630 #endif
00631         if (bg) {
00632                 bg = 0;
00633 #ifdef WIN32
00634                 switch_snprintf(path, sizeof(path), "Global\\Freeswitch.%d", getpid());
00635                 shutdown_event = CreateEvent(NULL, FALSE, FALSE, path);
00636                 if (shutdown_event) {
00637                         WaitForSingleObject(shutdown_event, INFINITE);
00638                 }
00639 #else
00640                 runtime.running = 1;
00641                 while (runtime.running) {
00642                         switch_yield(1000000);
00643                 }
00644 #endif
00645         } else {
00646                 /* wait for console input */
00647                 switch_console_loop();
00648         }
00649 }

Here is the call graph for this function:

uint8_t switch_core_session_check_interface switch_core_session_t session,
const switch_endpoint_interface_t endpoint_interface
 

01003 {
01004         switch_assert(session != NULL);
01005         switch_assert(endpoint_interface != NULL);
01006 
01007         return (uint8_t) (session->endpoint_interface == endpoint_interface);
01008 }

uint8_t switch_core_session_compare switch_core_session_t a,
switch_core_session_t b
 

indicate if 2 sessions are the same type

Parameters:
a the first session
b the second session
Returns:
TRUE or FALSE
00995 {
00996         switch_assert(a != NULL);
00997         switch_assert(b != NULL);
00998 
00999         return (uint8_t) (a->endpoint_interface == b->endpoint_interface);
01000 }

int32_t switch_core_session_ctl switch_session_ctl_t  cmd,
int32_t *  val
 

send a control message to the core

Parameters:
cmd the command
val the command arguement (if needed)
Returns:
0 on success nonzero on error
01292 {
01293         if (switch_test_flag((&runtime), SCF_SHUTTING_DOWN)) {
01294                 return -1;
01295         }
01296 
01297         switch (cmd) {
01298         case SCSC_SYNC_CLOCK:
01299                 switch_time_sync();
01300                 *val = 0;
01301                 break;
01302         case SCSC_PAUSE_INBOUND:
01303                 if (*val) {
01304                         switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
01305                 } else {
01306                         switch_clear_flag((&runtime), SCF_NO_NEW_SESSIONS);
01307                 }
01308                 break;
01309         case SCSC_HUPALL:
01310                 switch_core_session_hupall(SWITCH_CAUSE_MANAGER_REQUEST);
01311                 break;
01312         case SCSC_CANCEL_SHUTDOWN:
01313                 switch_clear_flag((&runtime), SCF_SHUTDOWN_REQUESTED);
01314                 break;
01315         case SCSC_SHUTDOWN_ELEGANT:
01316                 {
01317                         int x = 19;
01318                         
01319                         switch_set_flag((&runtime), SCF_SHUTDOWN_REQUESTED);
01320                         switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
01321 
01322                         while(runtime.running && switch_test_flag((&runtime), SCF_SHUTDOWN_REQUESTED) && switch_core_session_count()) {
01323                                 switch_yield(500000);
01324                                 if (++x == 20) {
01325                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Shutdown in progress.....\n");
01326                                         x = 0;
01327                                 }
01328                         }
01329                         
01330                         if (switch_test_flag((&runtime), SCF_SHUTDOWN_REQUESTED)) {
01331                                 if (*val) {
01332                                         switch_set_flag((&runtime), SCF_RESTART);
01333                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Restarting\n");
01334                                 } else {
01335                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Shutting down\n");
01336                                 }
01337                                 runtime.running = 0;
01338                         } else {
01339                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Shutdown Cancelled\n");
01340                                 switch_clear_flag((&runtime), SCF_NO_NEW_SESSIONS);
01341                         }
01342                 }
01343                 break;
01344         case SCSC_SHUTDOWN:
01345                 if (*val) {
01346                         switch_set_flag((&runtime), SCF_RESTART);
01347                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Restarting\n");
01348                 } else {
01349                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Shutting down\n");
01350                 }
01351                 runtime.running = 0;
01352                 break;
01353         case SCSC_CHECK_RUNNING:
01354                 *val = runtime.running;
01355                 break;
01356         case SCSC_LOGLEVEL:
01357                 if (*val > -1) {
01358                         runtime.hard_log_level = *val;
01359                 }
01360 
01361                 if (runtime.hard_log_level > SWITCH_LOG_DEBUG) {
01362                         runtime.hard_log_level = SWITCH_LOG_DEBUG;
01363                 }
01364                 *val = runtime.hard_log_level;
01365                 break;
01366         case SCSC_MAX_SESSIONS:
01367                 *val = switch_core_session_limit(*val);
01368                 break;
01369         case SCSC_LAST_SPS:
01370                 *val = runtime.sps_last;
01371                 break;
01372         case SCSC_MAX_DTMF_DURATION:
01373                 *val = switch_core_max_dtmf_duration(*val);
01374                 break;
01375         case SCSC_DEFAULT_DTMF_DURATION:
01376                 *val = switch_core_default_dtmf_duration(*val);
01377                 break;
01378         case SCSC_SPS:
01379                 switch_mutex_lock(runtime.throttle_mutex);
01380                 if (*val > 0) {
01381                         runtime.sps_total = *val;
01382                 }
01383                 *val = runtime.sps_total;
01384                 switch_mutex_unlock(runtime.throttle_mutex);
01385                 break;
01386 
01387         case SCSC_RECLAIM:
01388                 switch_core_memory_reclaim_all();
01389                 *val = 0;
01390                 break;
01391         }
01392 
01393 
01394         return 0;
01395 }

Here is the call graph for this function:

switch_status_t switch_core_set_console const char *  console  ) 
 

Set the output console to the desired file.

Parameters:
console the file path
00138 {
00139         if ((runtime.console = fopen(console, "a")) == 0) {
00140                 fprintf(stderr, "Cannot open output file %s.\n", console);
00141                 return SWITCH_STATUS_FALSE;
00142         }
00143 
00144         return SWITCH_STATUS_SUCCESS;
00145 }

void switch_core_set_globals void   ) 
 

Initiate Globals.

00367 {
00368 #define BUFSIZE 1024
00369 #ifdef WIN32
00370         char lpPathBuffer[BUFSIZE];
00371         DWORD dwBufSize = BUFSIZE;
00372         char base_dir[1024];
00373         char *lastbacklash;
00374         GetModuleFileName(NULL, base_dir, BUFSIZE);
00375         lastbacklash = strrchr(base_dir, '\\');
00376         base_dir[(lastbacklash - base_dir)] = '\0';
00377 #else
00378         char base_dir[1024] = SWITCH_PREFIX_DIR;
00379 #endif
00380 
00381         if (!SWITCH_GLOBAL_dirs.base_dir && (SWITCH_GLOBAL_dirs.base_dir = (char *) malloc(BUFSIZE))) {
00382                 switch_snprintf(SWITCH_GLOBAL_dirs.base_dir, BUFSIZE, "%s", base_dir);
00383         }
00384 
00385         if (!SWITCH_GLOBAL_dirs.mod_dir && (SWITCH_GLOBAL_dirs.mod_dir = (char *) malloc(BUFSIZE))) {
00386 #ifdef SWITCH_MOD_DIR
00387                 switch_snprintf(SWITCH_GLOBAL_dirs.mod_dir, BUFSIZE, "%s", SWITCH_MOD_DIR);
00388 #else
00389                 switch_snprintf(SWITCH_GLOBAL_dirs.mod_dir, BUFSIZE, "%s%smod", base_dir, SWITCH_PATH_SEPARATOR);
00390 #endif
00391         }
00392 
00393         if (!SWITCH_GLOBAL_dirs.conf_dir && (SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(BUFSIZE))) {
00394 #ifdef SWITCH_CONF_DIR
00395                 switch_snprintf(SWITCH_GLOBAL_dirs.conf_dir, BUFSIZE, "%s", SWITCH_CONF_DIR);
00396 #else
00397                 switch_snprintf(SWITCH_GLOBAL_dirs.conf_dir, BUFSIZE, "%s%sconf", base_dir, SWITCH_PATH_SEPARATOR);
00398 #endif
00399         }
00400 
00401         if (!SWITCH_GLOBAL_dirs.log_dir && (SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(BUFSIZE))) {
00402 #ifdef SWITCH_LOG_DIR
00403                 switch_snprintf(SWITCH_GLOBAL_dirs.log_dir, BUFSIZE, "%s", SWITCH_LOG_DIR);
00404 #else
00405                 switch_snprintf(SWITCH_GLOBAL_dirs.log_dir, BUFSIZE, "%s%slog", base_dir, SWITCH_PATH_SEPARATOR);
00406 #endif
00407         }
00408 
00409         if (!SWITCH_GLOBAL_dirs.storage_dir && (SWITCH_GLOBAL_dirs.storage_dir = (char *) malloc(BUFSIZE))) {
00410 #ifdef SWITCH_STORAGE_DIR
00411                 switch_snprintf(SWITCH_GLOBAL_dirs.storage_dir, BUFSIZE, "%s", SWITCH_STORAGE_DIR);
00412 #else
00413                 switch_snprintf(SWITCH_GLOBAL_dirs.storage_dir, BUFSIZE, "%s%sstorage", base_dir, SWITCH_PATH_SEPARATOR);
00414 #endif
00415         }
00416 
00417         if (!SWITCH_GLOBAL_dirs.db_dir && (SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(BUFSIZE))) {
00418 #ifdef SWITCH_DB_DIR
00419                 switch_snprintf(SWITCH_GLOBAL_dirs.db_dir, BUFSIZE, "%s", SWITCH_DB_DIR);
00420 #else
00421                 switch_snprintf(SWITCH_GLOBAL_dirs.db_dir, BUFSIZE, "%s%sdb", base_dir, SWITCH_PATH_SEPARATOR);
00422 #endif
00423         }
00424 
00425         if (!SWITCH_GLOBAL_dirs.script_dir && (SWITCH_GLOBAL_dirs.script_dir = (char *) malloc(BUFSIZE))) {
00426 #ifdef SWITCH_SCRIPT_DIR
00427                 switch_snprintf(SWITCH_GLOBAL_dirs.script_dir, BUFSIZE, "%s", SWITCH_SCRIPT_DIR);
00428 #else
00429                 switch_snprintf(SWITCH_GLOBAL_dirs.script_dir, BUFSIZE, "%s%sscripts", base_dir, SWITCH_PATH_SEPARATOR);
00430 #endif
00431         }
00432 
00433         if (!SWITCH_GLOBAL_dirs.htdocs_dir && (SWITCH_GLOBAL_dirs.htdocs_dir = (char *) malloc(BUFSIZE))) {
00434 #ifdef SWITCH_HTDOCS_DIR
00435                 switch_snprintf(SWITCH_GLOBAL_dirs.htdocs_dir, BUFSIZE, "%s", SWITCH_HTDOCS_DIR);
00436 #else
00437                 switch_snprintf(SWITCH_GLOBAL_dirs.htdocs_dir, BUFSIZE, "%s%shtdocs", base_dir, SWITCH_PATH_SEPARATOR);
00438 #endif
00439         }
00440 
00441         if (!SWITCH_GLOBAL_dirs.grammar_dir && (SWITCH_GLOBAL_dirs.grammar_dir = (char *) malloc(BUFSIZE))) {
00442 #ifdef SWITCH_GRAMMAR_DIR
00443                 switch_snprintf(SWITCH_GLOBAL_dirs.grammar_dir, BUFSIZE, "%s", SWITCH_GRAMMAR_DIR);
00444 #else
00445                 switch_snprintf(SWITCH_GLOBAL_dirs.grammar_dir, BUFSIZE, "%s%sgrammar", base_dir, SWITCH_PATH_SEPARATOR);
00446 #endif
00447         }
00448 
00449         if (!SWITCH_GLOBAL_dirs.temp_dir && (SWITCH_GLOBAL_dirs.temp_dir = (char *) malloc(BUFSIZE))) {
00450 #ifdef SWITCH_TEMP_DIR
00451                 switch_snprintf(SWITCH_GLOBAL_dirs.temp_dir, BUFSIZE, "%s", SWITCH_TEMP_DIR);
00452 #else
00453 #ifdef WIN32
00454                 GetTempPath(dwBufSize, lpPathBuffer);
00455                 switch_snprintf(SWITCH_GLOBAL_dirs.temp_dir, BUFSIZE, "%s", lpPathBuffer);
00456 #else
00457                 switch_snprintf(SWITCH_GLOBAL_dirs.temp_dir, BUFSIZE, "%s", "/tmp/");
00458 #endif
00459 #endif
00460         }
00461 
00462         switch_assert(SWITCH_GLOBAL_dirs.base_dir);
00463         switch_assert(SWITCH_GLOBAL_dirs.mod_dir);
00464         switch_assert(SWITCH_GLOBAL_dirs.conf_dir);
00465         switch_assert(SWITCH_GLOBAL_dirs.log_dir);
00466         switch_assert(SWITCH_GLOBAL_dirs.db_dir);
00467         switch_assert(SWITCH_GLOBAL_dirs.script_dir);
00468         switch_assert(SWITCH_GLOBAL_dirs.htdocs_dir);
00469         switch_assert(SWITCH_GLOBAL_dirs.grammar_dir);
00470         switch_assert(SWITCH_GLOBAL_dirs.temp_dir);
00471 }

Here is the call graph for this function:

void switch_core_setrlimits void   ) 
 

00752 {
00753 #ifdef HAVE_SETRLIMIT
00754         struct rlimit rlp;
00755 
00756         /* 
00757            Setting the stack size on FreeBSD results in an instant crash.
00758 
00759            If anyone knows how to fix this,
00760            feel free to submit a patch to http://jira.freeswitch.org 
00761          */
00762 
00763 #ifndef __FreeBSD__
00764         memset(&rlp, 0, sizeof(rlp));
00765         rlp.rlim_cur = SWITCH_THREAD_STACKSIZE;
00766         rlp.rlim_max = SWITCH_SYSTEM_THREAD_STACKSIZE;
00767         setrlimit(RLIMIT_STACK, &rlp);
00768 #endif
00769 
00770         memset(&rlp, 0, sizeof(rlp));
00771         rlp.rlim_cur = 999999;
00772         rlp.rlim_max = 999999;
00773         setrlimit(RLIMIT_NOFILE, &rlp);
00774 
00775         memset(&rlp, 0, sizeof(rlp));
00776         rlp.rlim_cur = RLIM_INFINITY;
00777         rlp.rlim_max = RLIM_INFINITY;
00778 
00779         setrlimit(RLIMIT_CPU, &rlp);
00780         setrlimit(RLIMIT_DATA, &rlp);
00781         setrlimit(RLIMIT_FSIZE, &rlp);
00782 #ifndef __OpenBSD__
00783         setrlimit(RLIMIT_AS, &rlp);
00784 #endif
00785 #endif
00786         return;
00787 }

switch_time_t switch_core_uptime void   ) 
 

Number of microseconds the system has been up.

Returns:
a number of microseconds
01287 {
01288         return switch_timestamp_now() - runtime.initiated;
01289 }

Here is the call graph for this function:

void switch_load_network_lists switch_bool_t  reload  ) 
 

00820 {
00821         switch_xml_t xml = NULL, x_lists = NULL, x_list = NULL, x_node = NULL, cfg = NULL;
00822         switch_network_list_t *list;
00823 
00824 
00825         switch_mutex_lock(runtime.global_mutex);
00826 
00827         if (IP_LIST.hash) {
00828                 switch_core_hash_destroy(&IP_LIST.hash);
00829         }
00830 
00831         if (IP_LIST.pool) {
00832                 switch_core_destroy_memory_pool(&IP_LIST.pool);
00833         }
00834 
00835         memset(&IP_LIST, 0, sizeof(IP_LIST));
00836         switch_core_new_memory_pool(&IP_LIST.pool);
00837         switch_core_hash_init(&IP_LIST.hash, IP_LIST.pool);
00838 
00839         if ((xml = switch_xml_open_cfg("acl.conf", &cfg, NULL))) {
00840                 if ((x_lists = switch_xml_child(cfg, "network-lists"))) {
00841                         for (x_list = switch_xml_child(x_lists, "list"); x_list; x_list = x_list->next) {
00842                                 const char *name = switch_xml_attr(x_list, "name");
00843                                 const char *dft = switch_xml_attr(x_list, "default");
00844                                 switch_bool_t default_type = SWITCH_TRUE;
00845 
00846                                 if (switch_strlen_zero(name)) {
00847                                         continue;
00848                                 }
00849 
00850                                 if (dft) {
00851                                         default_type = switch_true(dft);
00852                                 }
00853 
00854                                 if (switch_network_list_create(&list, default_type, IP_LIST.pool) != SWITCH_STATUS_SUCCESS) {
00855                                         abort();
00856                                 }
00857 
00858                                 if (reload) {
00859                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (%s)\n", name, default_type ? "allow" : "deny");
00860                                 } else {
00861                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Created ip list %s default (%s)\n", name, default_type ? "allow" : "deny");
00862                                 }
00863 
00864 
00865                                 for (x_node = switch_xml_child(x_list, "node"); x_node; x_node = x_node->next) {
00866                                         const char *cidr = NULL, *host = NULL, *mask = NULL, *domain = NULL;
00867                                         switch_bool_t ok = default_type;
00868                                         const char *type = switch_xml_attr(x_node, "type");
00869 
00870                                         if (type) {
00871                                                 ok = switch_true(type);
00872                                         }
00873 
00874                                         cidr = switch_xml_attr(x_node, "cidr");
00875                                         host = switch_xml_attr(x_node, "host");
00876                                         mask = switch_xml_attr(x_node, "mask");
00877                                         domain = switch_xml_attr(x_node, "domain");
00878 
00879                                         if (domain) {
00880                                                 switch_event_t *my_params = NULL;
00881                                                 switch_xml_t x_domain, xml_root;
00882                                                 switch_xml_t ut;
00883 
00884                                                 switch_event_create(&my_params, SWITCH_EVENT_GENERAL);
00885                                                 switch_assert(my_params);
00886                                                 switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "domain", domain);
00887                                                 switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "purpose", "network-list");
00888                                                 
00889                                                 if (switch_xml_locate_domain(domain, my_params, &xml_root, &x_domain) != SWITCH_STATUS_SUCCESS) {
00890                                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate domain %s\n", domain);
00891                                                         switch_event_destroy(&my_params);
00892                                                         continue;
00893                                                 }
00894                                                 
00895                                                 switch_event_destroy(&my_params);
00896 
00897                                                 for (ut = switch_xml_child(x_domain, "user"); ut; ut = ut->next) {
00898                                                         const char *user_cidr = switch_xml_attr(ut, "cidr");
00899                                                         const char *id = switch_xml_attr(ut, "id");
00900 
00901                                                         if (id && user_cidr) {
00902                                                                 char *token = switch_mprintf("%s@%s", id, domain);
00903                                                                 switch_assert(token);
00904                                                                 
00905                                                                 if (switch_network_list_add_cidr_token(list, user_cidr, ok, token) == SWITCH_STATUS_SUCCESS) {
00906                                                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding %s (%s) [%s] to list %s\n", 
00907                                                                                                           user_cidr, ok ? "allow" : "deny", switch_str_nil(token), name);
00908                                                                 } else {
00909                                                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Adding %s (%s) [%s] to list %s\n",
00910                                                                                                           user_cidr, ok ? "allow" : "deny", switch_str_nil(token), name);
00911                                                                 }
00912                                                                 free(token);
00913                                                         }
00914                                                 }
00915                                                 switch_xml_free(xml_root);
00916                                         } else if (cidr) {
00917                                                 if (switch_network_list_add_cidr(list, cidr, ok) == SWITCH_STATUS_SUCCESS) {
00918                                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding %s (%s) to list %s\n", cidr, ok ? "allow" : "deny", name);
00919                                                 } else {
00920                                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
00921                                                                                           "Error Adding %s (%s) to list %s\n", cidr, ok ? "allow" : "deny", name);
00922                                                 }
00923                                         } else if (host && mask) {
00924                                                 if (switch_network_list_add_host_mask(list, host, mask, ok) == SWITCH_STATUS_SUCCESS) {
00925                                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
00926                                                                                           "Adding %s/%s (%s) to list %s\n", host, mask, ok ? "allow" : "deny", name);
00927                                                 }
00928                                         } 
00929 
00930                                         switch_core_hash_insert(IP_LIST.hash, name, list);
00931                                 }
00932                         }
00933                 }
00934 
00935                 switch_xml_free(xml);
00936         }
00937 
00938