switch_core_session.c File Reference

#include "switch.h"
#include "switch_core.h"
#include "private/switch_core_pvt.h"

Include dependency graph for switch_core_session.c:

Go to the source code of this file.

Data Structures

struct  str_node

Defines

#define check_media(session)
#define SWITCH_PREFIX_DIR   "."

Functions

void switch_core_session_set_dmachine (switch_core_session_t *session, switch_ivr_dmachine_t *dmachine, switch_digit_action_target_t target)
switch_ivr_dmachine_tswitch_core_session_get_dmachine (switch_core_session_t *session, switch_digit_action_target_t target)
void switch_core_session_soft_lock (switch_core_session_t *session, uint32_t sec)
void switch_core_session_soft_unlock (switch_core_session_t *session)
switch_status_t switch_core_session_set_codec_slin (switch_core_session_t *session, switch_slin_data_t *data)
switch_core_session_tswitch_core_session_locate (const char *uuid_str)
switch_core_session_tswitch_core_session_force_locate (const char *uuid_str)
switch_status_t switch_core_session_get_partner (switch_core_session_t *session, switch_core_session_t **partner)
 Get the session's partner (the session its bridged to).
void switch_core_session_hupall_matching_var (const char *var_name, const char *var_val, switch_call_cause_t cause)
void switch_core_session_hupall_endpoint (const switch_endpoint_interface_t *endpoint_interface, switch_call_cause_t cause)
 Hangup all sessions that belong to an endpoint.
void switch_core_session_hupall (switch_call_cause_t cause)
switch_status_t switch_core_session_message_send (const char *uuid_str, switch_core_session_message_t *message)
switch_status_t switch_core_session_event_send (const char *uuid_str, switch_event_t **event)
void * switch_core_session_get_private (switch_core_session_t *session)
switch_status_t switch_core_session_set_private (switch_core_session_t *session, void *private_info)
int switch_core_session_add_stream (switch_core_session_t *session, void *private_info)
void * switch_core_session_get_stream (switch_core_session_t *session, int index)
int switch_core_session_get_stream_count (switch_core_session_t *session)
switch_call_cause_t switch_core_session_resurrect_channel (const char *endpoint_name, switch_core_session_t **new_session, switch_memory_pool_t **pool, void *data)
switch_call_cause_t switch_core_session_outgoing_channel (switch_core_session_t *session, switch_event_t *var_event, const char *endpoint_name, switch_caller_profile_t *caller_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
switch_status_t switch_core_session_perform_receive_message (switch_core_session_t *session, switch_core_session_message_t *message, const char *file, const char *func, int line)
switch_status_t switch_core_session_pass_indication (switch_core_session_t *session, switch_core_session_message_types_t indication)
switch_status_t switch_core_session_queue_indication (switch_core_session_t *session, switch_core_session_message_types_t indication)
switch_status_t switch_core_session_queue_message (switch_core_session_t *session, switch_core_session_message_t *message)
void switch_core_session_free_message (switch_core_session_message_t **message)
switch_status_t switch_core_session_dequeue_message (switch_core_session_t *session, switch_core_session_message_t **message)
switch_status_t switch_core_session_flush_message (switch_core_session_t *session)
switch_status_t switch_core_session_queue_signal_data (switch_core_session_t *session, void *signal_data)
switch_status_t switch_core_session_dequeue_signal_data (switch_core_session_t *session, void **signal_data)
switch_status_t switch_core_session_receive_event (switch_core_session_t *session, switch_event_t **event)
switch_status_t switch_core_session_queue_event (switch_core_session_t *session, switch_event_t **event)
uint32_t switch_core_session_messages_waiting (switch_core_session_t *session)
uint32_t switch_core_session_event_count (switch_core_session_t *session)
switch_status_t switch_core_session_dequeue_event (switch_core_session_t *session, switch_event_t **event, switch_bool_t force)
switch_status_t switch_core_session_queue_private_event (switch_core_session_t *session, switch_event_t **event, switch_bool_t priority)
uint32_t switch_core_session_private_event_count (switch_core_session_t *session)
switch_status_t switch_core_session_dequeue_private_event (switch_core_session_t *session, switch_event_t **event)
uint32_t switch_core_session_flush_private_events (switch_core_session_t *session)
 Flush the private event queue of a session.
void switch_core_session_reset (switch_core_session_t *session, switch_bool_t flush_dtmf, switch_bool_t reset_read_codec)
switch_channel_tswitch_core_session_get_channel (switch_core_session_t *session)
switch_status_t switch_core_session_wake_session_thread (switch_core_session_t *session)
void switch_core_session_signal_state_change (switch_core_session_t *session)
unsigned int switch_core_session_running (switch_core_session_t *session)
unsigned int switch_core_session_started (switch_core_session_t *session)
int switch_core_session_sync_clock (void)
void switch_core_session_perform_destroy (switch_core_session_t **session, const char *file, const char *func, int line)
 SWITCH_STANDARD_SCHED_FUNC (sch_heartbeat_callback)
void switch_core_session_unsched_heartbeat (switch_core_session_t *session)
void switch_core_session_sched_heartbeat (switch_core_session_t *session, uint32_t seconds)
void switch_core_session_enable_heartbeat (switch_core_session_t *session, uint32_t seconds)
void switch_core_session_disable_heartbeat (switch_core_session_t *session)
switch_bool_t switch_core_session_in_thread (switch_core_session_t *session)
static void *SWITCH_THREAD_FUNC switch_core_session_thread (switch_thread_t *thread, void *obj)
switch_status_t switch_core_session_thread_launch (switch_core_session_t *session)
void switch_core_session_launch_thread (switch_core_session_t *session, switch_thread_start_t func, void *obj)
switch_status_t switch_core_session_set_uuid (switch_core_session_t *session, const char *use_uuid)
static char * xml_find_var (switch_xml_t vars, const char *name)
static void parse_array (const char *str, uint32_t *array, int32_t array_len)
switch_core_session_tswitch_core_session_request_xml (switch_endpoint_interface_t *endpoint_interface, switch_memory_pool_t **pool, switch_xml_t xml)
switch_core_session_tswitch_core_session_request_uuid (switch_endpoint_interface_t *endpoint_interface, switch_call_direction_t direction, switch_originate_flag_t originate_flags, switch_memory_pool_t **pool, const char *use_uuid)
uint32_t switch_core_session_count (void)
 Provide the total number of sessions.
switch_size_t switch_core_session_get_id (switch_core_session_t *session)
switch_size_t switch_core_session_id (void)
 Provide the current session_id.
switch_core_session_tswitch_core_session_request_by_name (const char *endpoint_name, switch_call_direction_t direction, switch_memory_pool_t **pool)
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.
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.
char * switch_core_session_get_uuid (switch_core_session_t *session)
uint32_t switch_core_session_limit (uint32_t new_limit)
double switch_core_min_idle_cpu (double new_limit)
double switch_core_idle_cpu (void)
uint32_t switch_core_sessions_per_second (uint32_t new_limit)
void switch_core_session_init (switch_memory_pool_t *pool)
void switch_core_session_uninit (void)
switch_app_log_tswitch_core_session_get_app_log (switch_core_session_t *session)
switch_status_t switch_core_session_get_app_flags (const char *app, int32_t *flags)
switch_status_t switch_core_session_execute_application_async (switch_core_session_t *session, const char *app, const char *arg)
switch_status_t switch_core_session_execute_application_get_flags (switch_core_session_t *session, const char *app, const char *arg, int32_t *flags)
switch_status_t switch_core_session_exec (switch_core_session_t *session, const switch_application_interface_t *application_interface, const char *arg)
switch_status_t switch_core_session_execute_exten (switch_core_session_t *session, const char *exten, const char *dialplan, const char *context)
switch_status_t switch_core_session_set_loglevel (switch_core_session_t *session, switch_log_level_t loglevel)
 Sets the log level for a session.
switch_log_level_t switch_core_session_get_loglevel (switch_core_session_t *session)
 Get the log level for a session.

Variables

switch_session_manager session_manager
static const char * message_names []


Define Documentation

#define check_media ( session   ) 

Value:

{                                                                                                                                       \
                if (switch_channel_test_flag(session->channel, CF_BROADCAST_DROP_MEDIA)) { \
                        switch_channel_clear_flag(session->channel, CF_BROADCAST_DROP_MEDIA); \
                        switch_ivr_nomedia(session->uuid_str, SMF_REBRIDGE);            \
                }                                                                                                                               \
        }                                                                                                                                       \

Definition at line 1064 of file switch_core_session.c.

Referenced by switch_core_session_dequeue_private_event(), switch_core_session_flush_private_events(), and switch_core_session_private_event_count().

#define SWITCH_PREFIX_DIR   "."

Definition at line 1978 of file switch_core_session.c.

Referenced by switch_core_set_globals(), and switch_loadable_module_load_file().


Function Documentation

static void parse_array ( const char *  str,
uint32_t *  array,
int32_t  array_len 
) [static]

Definition at line 1551 of file switch_core_session.c.

References str_node::next, and zstr.

Referenced by parse_value(), and switch_core_session_request_xml().

01552 {
01553         char *p, *v, *dup, *next = NULL;
01554 
01555         if (zstr(str)) {
01556                 return;
01557         }
01558 
01559         dup = strdup(str);
01560 
01561         p = dup;
01562         while (p) {
01563                 if ((next = strchr(p, ';'))) {
01564                         *next++ = '\0';
01565                 }
01566 
01567                 if ((v = strchr(p, '='))) {
01568                         *v++ = '\0';
01569                 }
01570 
01571                 if (p && v) {
01572                         int x = 0, y = 0;
01573 
01574                         x = atoi(p);
01575                         y = atoi(v);
01576 
01577                         if (x < array_len) {
01578                                 array[x] = y;
01579                         }
01580                 }
01581 
01582                 p = next;
01583 
01584         }
01585 
01586         free(dup);
01587 }

int switch_core_session_add_stream ( switch_core_session_t session,
void *  private_info 
)

Definition at line 380 of file switch_core_session.c.

00381 {
00382         session->streams[session->stream_count++] = private_info;
00383         return session->stream_count - 1;
00384 }

switch_status_t switch_core_session_dequeue_event ( switch_core_session_t session,
switch_event_t **  event,
switch_bool_t  force 
)

Definition at line 1027 of file switch_core_session.c.

References CF_DIVERT_EVENTS, switch_assert, switch_channel_test_flag(), switch_queue_trypop(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

01028 {
01029         switch_status_t status = SWITCH_STATUS_FALSE;
01030         void *pop;
01031 
01032         switch_assert(session != NULL);
01033 
01034         if (session->event_queue && (force || !switch_channel_test_flag(session->channel, CF_DIVERT_EVENTS))) {
01035                 if ((status = (switch_status_t) switch_queue_trypop(session->event_queue, &pop)) == SWITCH_STATUS_SUCCESS) {
01036                         *event = (switch_event_t *) pop;
01037                 }
01038         }
01039 
01040         return status;
01041 }

switch_status_t switch_core_session_dequeue_message ( switch_core_session_t session,
switch_core_session_message_t **  message 
)

Definition at line 867 of file switch_core_session.c.

References switch_assert, switch_core_session_queue_message(), switch_epoch_time_now(), switch_queue_size(), switch_queue_trypop(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

00868 {
00869         switch_status_t status = SWITCH_STATUS_FALSE;
00870         void *pop;
00871 
00872         switch_assert(session != NULL);
00873 
00874         if (session->message_queue && switch_queue_size(session->message_queue)) {
00875                 if ((status = (switch_status_t) switch_queue_trypop(session->message_queue, &pop)) == SWITCH_STATUS_SUCCESS) {
00876                         *message = (switch_core_session_message_t *) pop;
00877                         if ((*message)->delivery_time && (*message)->delivery_time > switch_epoch_time_now(NULL)) {
00878                                 switch_core_session_queue_message(session, *message);
00879                                 *message = NULL;
00880                                 status = SWITCH_STATUS_FALSE;
00881                         }
00882                 }
00883         }
00884 
00885         return status;
00886 }

switch_status_t switch_core_session_dequeue_private_event ( switch_core_session_t session,
switch_event_t **  event 
)

Definition at line 1095 of file switch_core_session.c.

References CF_EVENT_LOCK, CF_EVENT_LOCK_PRI, check_media, switch_channel_test_flag(), switch_core_session_get_channel(), switch_queue_size(), switch_queue_trypop(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

01096 {
01097         switch_status_t status = SWITCH_STATUS_FALSE;
01098         void *pop;
01099         switch_channel_t *channel = switch_core_session_get_channel(session);
01100         switch_queue_t *queue;
01101 
01102         if (session->private_event_queue) {
01103                 if (switch_queue_size(session->private_event_queue_pri)) {
01104                         queue = session->private_event_queue_pri;
01105 
01106                         if (switch_channel_test_flag(channel, CF_EVENT_LOCK_PRI)) {
01107                                 return SWITCH_STATUS_FALSE;
01108                         }
01109                 } else {
01110                         queue = session->private_event_queue;
01111 
01112                         if (switch_channel_test_flag(channel, CF_EVENT_LOCK)) {
01113                                 return SWITCH_STATUS_FALSE;
01114                         }
01115                 }
01116 
01117                 if ((status = (switch_status_t) switch_queue_trypop(queue, &pop)) == SWITCH_STATUS_SUCCESS) {
01118                         *event = (switch_event_t *) pop;
01119                 } else {
01120                         check_media(session);
01121                 }
01122         }
01123 
01124         return status;
01125 }

uint32_t switch_core_session_event_count ( switch_core_session_t session  ) 

Definition at line 1018 of file switch_core_session.c.

References switch_queue_size().

01019 {
01020         if (session->event_queue) {
01021                 return switch_queue_size(session->event_queue);
01022         }
01023 
01024         return 0;
01025 }

switch_status_t switch_core_session_event_send ( const char *  uuid_str,
switch_event_t **  event 
)

Definition at line 345 of file switch_core_session.c.

References switch_core_session::channel, runtime, switch_runtime::session_hash_mutex, session_manager, switch_session_manager::session_table, switch_channel_up_nosig, switch_core_hash_find(), switch_core_session_queue_event(), switch_core_session_read_lock(), switch_core_session_rwunlock(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

00346 {
00347         switch_core_session_t *session = NULL;
00348         switch_status_t status = SWITCH_STATUS_FALSE;
00349 
00350         switch_mutex_lock(runtime.session_hash_mutex);
00351         if ((session = switch_core_hash_find(session_manager.session_table, uuid_str)) != 0) {
00352                 /* Acquire a read lock on the session or forget it the channel is dead */
00353                 if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
00354                         if (switch_channel_up_nosig(session->channel)) {
00355                                 status = switch_core_session_queue_event(session, event);
00356                         }
00357                         switch_core_session_rwunlock(session);
00358                 }
00359         }
00360         switch_mutex_unlock(runtime.session_hash_mutex);
00361 
00362         return status;
00363 }

switch_status_t switch_core_session_exec ( switch_core_session_t session,
const switch_application_interface_t application_interface,
const char *  arg 
)

Definition at line 2211 of file switch_core_session.c.

References CF_BREAK, switch_core_session_message::from, switch_core_session_message::message_id, switch_app_log::next, switch_core_session_message::string_array_arg, switch_assert, switch_channel_clear_flag(), switch_channel_event_set_data(), switch_channel_expand_variables, switch_channel_get_name(), switch_channel_get_variable, switch_channel_presence, SWITCH_CHANNEL_SESSION_LOG_CLEAN, switch_channel_set_scope_variables(), switch_channel_set_variable, switch_channel_set_variable_var_check(), switch_core_session_alloc, switch_core_session_get_channel(), switch_core_session_receive_message, switch_core_session_strdup, SWITCH_CURRENT_APPLICATION_DATA_VARIABLE, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, SWITCH_CURRENT_APPLICATION_VARIABLE, SWITCH_DISABLE_APP_LOG_VARIABLE, switch_event_add_header_string(), SWITCH_EVENT_CHANNEL_EXECUTE, SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE, switch_event_create, switch_event_create_brackets(), switch_event_fire, SWITCH_FALSE, SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_MESSAGE_INDICATE_APPLICATION_EXEC, SWITCH_MESSAGE_INDICATE_APPLICATION_EXEC_COMPLETE, switch_mprintf(), switch_safe_free, SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, switch_str_nil, switch_time_now(), switch_true(), SWITCH_TRUE, and zstr.

02213 {
02214         switch_app_log_t *log, *lp;
02215         switch_event_t *event;
02216         const char *var;
02217         switch_channel_t *channel = switch_core_session_get_channel(session);
02218         char *expanded = NULL;
02219         const char *app;
02220         switch_core_session_message_t msg = { 0 };
02221         char delim = ',';
02222         int scope = 0;
02223 
02224         switch_assert(application_interface);
02225 
02226         app = application_interface->interface_name;
02227 
02228         if (arg) {
02229                 expanded = switch_channel_expand_variables(session->channel, arg);
02230         }
02231 
02232         if (expanded && *expanded == '%' && (*(expanded+1) == '[' || *(expanded+2) == '[')) {
02233                 char *p, *dup;
02234                 switch_event_t *ovars = NULL;
02235                 
02236                 p = expanded + 1;
02237 
02238                 if (*p != '[') {
02239                         delim = *p;
02240                         p++;
02241                 }
02242 
02243                 dup = strdup(p);
02244                 
02245                 if (expanded != arg) {
02246                         switch_safe_free(expanded);
02247                 }
02248 
02249                 switch_event_create_brackets(dup, '[', ']', delim, &ovars, &expanded, SWITCH_TRUE);
02250                 free(dup);
02251 
02252                 switch_channel_set_scope_variables(session->channel, &ovars);
02253                 scope = 1;
02254         }
02255 
02256         
02257         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG, "EXECUTE %s %s(%s)\n",
02258                                           switch_channel_get_name(session->channel), app, switch_str_nil(expanded));
02259 
02260         if ((var = switch_channel_get_variable(session->channel, "verbose_presence")) && switch_true(var)) {
02261                 char *myarg = NULL;
02262                 if (expanded) {
02263                         myarg = switch_mprintf("%s(%s)", app, expanded);
02264                 } else if (!zstr(arg)) {
02265                         myarg = switch_mprintf("%s(%s)", app, arg);
02266                 } else {
02267                         myarg = switch_mprintf("%s", app);
02268                 }
02269                 if (myarg) {
02270                         switch_channel_presence(session->channel, "unknown", myarg, NULL);
02271                         switch_safe_free(myarg);
02272                 }
02273         }
02274 
02275         if (!(var = switch_channel_get_variable(session->channel, SWITCH_DISABLE_APP_LOG_VARIABLE)) || (!(switch_true(var)))) {
02276                 log = switch_core_session_alloc(session, sizeof(*log));
02277 
02278                 log->app = switch_core_session_strdup(session, application_interface->interface_name);
02279                 if (expanded) {
02280                         log->arg = switch_core_session_strdup(session, expanded);
02281                 }
02282 
02283                 log->stamp = switch_time_now();
02284 
02285                 for (lp = session->app_log; lp && lp->next; lp = lp->next);
02286 
02287                 if (lp) {
02288                         lp->next = log;
02289                 } else {
02290                         session->app_log = log;
02291                 }
02292         }
02293 
02294         switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_VARIABLE, application_interface->interface_name);
02295         switch_channel_set_variable_var_check(channel, SWITCH_CURRENT_APPLICATION_DATA_VARIABLE, expanded, SWITCH_FALSE);
02296         switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, NULL);
02297 
02298         if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
02299                 switch_channel_event_set_data(session->channel, event);
02300                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Application", application_interface->interface_name);
02301                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Application-Data", expanded);
02302                 switch_event_fire(&event);
02303         }
02304 
02305         switch_channel_clear_flag(session->channel, CF_BREAK);
02306 
02307         switch_assert(application_interface->application_function);
02308 
02309         switch_channel_set_variable(session->channel, SWITCH_CURRENT_APPLICATION_VARIABLE, application_interface->interface_name);
02310 
02311         msg.from = __FILE__;
02312         msg.message_id = SWITCH_MESSAGE_INDICATE_APPLICATION_EXEC;
02313         msg.string_array_arg[0] = application_interface->interface_name;
02314         msg.string_array_arg[1] = expanded;
02315         switch_core_session_receive_message(session, &msg);
02316 
02317         application_interface->application_function(session, expanded);
02318 
02319         if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE) == SWITCH_STATUS_SUCCESS) {
02320                 const char *resp = switch_channel_get_variable(session->channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE);
02321                 switch_channel_event_set_data(session->channel, event);
02322                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Application", application_interface->interface_name);
02323                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Application-Data", expanded);
02324                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Application-Response", resp ? resp : "_none_");
02325                 switch_event_fire(&event);
02326         }
02327 
02328         msg.message_id = SWITCH_MESSAGE_INDICATE_APPLICATION_EXEC_COMPLETE;
02329         switch_core_session_receive_message(session, &msg);
02330 
02331         if (expanded != arg) {
02332                 switch_safe_free(expanded);
02333         }
02334 
02335         if (scope) {
02336                 switch_channel_set_scope_variables(session->channel, NULL);
02337         }
02338 
02339         return SWITCH_STATUS_SUCCESS;
02340 }

switch_status_t switch_core_session_execute_application_get_flags ( switch_core_session_t session,
const char *  app,
const char *  arg,
int32_t *  flags 
)

Definition at line 2117 of file switch_core_session.c.

References switch_application_interface::application_function, CF_PROXY_MODE, switch_application_interface::flags, SAF_SUPPORT_NOMEDIA, SAF_ZOMBIE_EXEC, SMF_NONE, SWITCH_CALL_DIRECTION_INBOUND, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, switch_channel_direction(), switch_channel_down_nosig, switch_channel_get_name(), switch_channel_hangup, switch_channel_media_ready, switch_channel_media_up, switch_channel_pre_answer, SWITCH_CHANNEL_SESSION_LOG, switch_channel_test_flag(), switch_cond_next(), switch_core_session_exec(), switch_core_session_execute_application_async(), switch_goto_status, switch_ivr_media(), switch_loadable_module_get_application_interface(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_STATUS_FALSE, SWITCH_STATUS_IGNORE, SWITCH_STATUS_SUCCESS, switch_str_nil, switch_test_flag, and UNPROTECT_INTERFACE.

02119 {
02120         switch_application_interface_t *application_interface;
02121         switch_status_t status = SWITCH_STATUS_SUCCESS;
02122 
02123         if (switch_channel_down_nosig(session->channel)) {
02124                 char *p;
02125                 if (!arg && (p = strstr(app, "::"))) {
02126                         *p++ = '0';
02127                         *p++ = '0';
02128                         arg = p;
02129 
02130                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s ASYNC CALL CONVERTED TO INLINE %s(%s)\n", 
02131                                                           switch_channel_get_name(session->channel), app, switch_str_nil(arg));                 
02132                 }
02133                 
02134                 if ((application_interface = switch_loadable_module_get_application_interface(app)) == 0) {
02135                         return SWITCH_STATUS_FALSE;
02136                 }
02137 
02138                 if (switch_test_flag(application_interface, SAF_ZOMBIE_EXEC)) {
02139                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s ZOMBIE EXEC %s(%s)\n", 
02140                                                           switch_channel_get_name(session->channel), app, switch_str_nil(arg));
02141                         goto exec;
02142                 }
02143 
02144                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, 
02145                                                   "%s Channel is hungup and application '%s' does not have the zombie_exec flag.\n",
02146                                                   switch_channel_get_name(session->channel), app);
02147 
02148                 switch_goto_status(SWITCH_STATUS_IGNORE, done);
02149         }
02150 
02151         if (!arg && strstr(app, "::")) {
02152                 return switch_core_session_execute_application_async(session, app, arg);
02153         }
02154 
02155         if ((application_interface = switch_loadable_module_get_application_interface(app)) == 0) {
02156                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid Application %s\n", app);
02157                 switch_channel_hangup(session->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
02158                 switch_goto_status(SWITCH_STATUS_FALSE, done);
02159         }
02160 
02161         if (!application_interface->application_function) {
02162                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No Function for %s\n", app);
02163                 switch_channel_hangup(session->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
02164                 switch_goto_status(SWITCH_STATUS_FALSE, done);
02165         }
02166 
02167         if (flags && application_interface->flags) {
02168                 *flags = application_interface->flags;
02169         }
02170 
02171         if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) && !switch_test_flag(application_interface, SAF_SUPPORT_NOMEDIA)) {
02172                 switch_ivr_media(session->uuid_str, SMF_NONE);
02173                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Application %s Requires media on channel %s!\n",
02174                                                   app, switch_channel_get_name(session->channel));
02175         } else if (!switch_test_flag(application_interface, SAF_SUPPORT_NOMEDIA) && !switch_channel_media_ready(session->channel)) {
02176                 if (switch_channel_direction(session->channel) == SWITCH_CALL_DIRECTION_INBOUND) {
02177                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Application %s Requires media! pre_answering channel %s\n",
02178                                                           app, switch_channel_get_name(session->channel));
02179                         if (switch_channel_pre_answer(session->channel) != SWITCH_STATUS_SUCCESS) {
02180                                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Well, that didn't work very well did it? ...\n");
02181                                 switch_goto_status(SWITCH_STATUS_FALSE, done);
02182                         }
02183                 } else {
02184                         uint32_t ready = 0, sanity = 2000;
02185 
02186                         do {
02187                                 sanity--;
02188                                 ready = switch_channel_media_up(session->channel);
02189                                 switch_cond_next();
02190                         } while(!ready && sanity);
02191 
02192                         if (!ready) {
02193                                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, 
02194                                                                   "Cannot execute app '%s' media required on an outbound channel that does not have media established\n", app);
02195                                 switch_goto_status(SWITCH_STATUS_FALSE, done);
02196                         }
02197                 }
02198         }
02199 
02200  exec:
02201 
02202         switch_core_session_exec(session, application_interface, arg);
02203 
02204   done:
02205 
02206         UNPROTECT_INTERFACE(application_interface);
02207 
02208         return status;
02209 }

switch_status_t switch_core_session_execute_exten ( switch_core_session_t session,
const char *  exten,
const char *  dialplan,
const char *  context 
)

Definition at line 2342 of file switch_core_session.c.

References switch_caller_application::application_data, switch_caller_application::application_name, switch_caller_profile::caller_extension, switch_caller_extension::children, switch_caller_profile::context, switch_caller_extension::current_application, switch_caller_profile::destination_number, switch_caller_profile::dialplan, switch_dialplan_interface::hunt_function, switch_caller_application::next, switch_caller_profile::next, switch_caller_profile::pool, switch_caller_profile_clone(), switch_channel_get_caller_profile(), switch_channel_get_name(), switch_channel_ready, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_hunt_caller_profile(), switch_core_session_alloc, switch_core_session_execute_application, switch_core_session_get_channel(), switch_core_session_strdup, switch_core_strdup, switch_loadable_module_get_dialplan_interface(), SWITCH_LOG_ERROR, SWITCH_LOG_NOTICE, switch_log_printf(), SWITCH_MAX_STACKS, switch_separate_string(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_str_nil, switch_caller_profile::times, UNPROTECT_INTERFACE, and zstr.

02344 {
02345         char *dp[25];
02346         char *dpstr;
02347         int argc, x, count = 0;
02348         switch_caller_profile_t *profile, *new_profile, *pp = NULL;
02349         switch_channel_t *channel = switch_core_session_get_channel(session);
02350         switch_dialplan_interface_t *dialplan_interface = NULL;
02351         switch_caller_extension_t *extension = NULL;
02352         switch_status_t status = SWITCH_STATUS_SUCCESS;
02353 
02354         if (!(profile = switch_channel_get_caller_profile(channel))) {
02355                 return SWITCH_STATUS_FALSE;
02356         }
02357 
02358         if (session->stack_count > SWITCH_MAX_STACKS) {
02359                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error %s too many stacked extensions\n",
02360                                                   switch_channel_get_name(session->channel));
02361                 return SWITCH_STATUS_FALSE;
02362         }
02363 
02364         session->stack_count++;
02365 
02366         new_profile = switch_caller_profile_clone(session, profile);
02367         new_profile->destination_number = switch_core_strdup(new_profile->pool, exten);
02368         new_profile->times = (switch_channel_timetable_t *) switch_core_session_alloc(session, sizeof(*new_profile->times));
02369         *new_profile->times = *profile->times;
02370 
02371 
02372         if (!zstr(dialplan)) {
02373                 new_profile->dialplan = switch_core_strdup(new_profile->pool, dialplan);
02374         }
02375 
02376         if (!zstr(context)) {
02377                 new_profile->context = switch_core_strdup(new_profile->pool, context);
02378         }
02379 
02380         dpstr = switch_core_session_strdup(session, new_profile->dialplan);
02381 
02382         switch_channel_set_hunt_caller_profile(channel, new_profile);
02383         argc = switch_separate_string(dpstr, ',', dp, (sizeof(dp) / sizeof(dp[0])));
02384         for (x = 0; x < argc; x++) {
02385                 char *dpname = dp[x];
02386                 char *dparg = NULL;
02387 
02388                 if (dpname) {
02389                         if ((dparg = strchr(dpname, ':'))) {
02390                                 *dparg++ = '\0';
02391                         }
02392                 } else {
02393                         continue;
02394                 }
02395 
02396                 if (!(dialplan_interface = switch_loadable_module_get_dialplan_interface(dpname))) {
02397                         continue;
02398                 }
02399 
02400                 count++;
02401 
02402                 extension = dialplan_interface->hunt_function(session, dparg, new_profile);
02403                 UNPROTECT_INTERFACE(dialplan_interface);
02404 
02405                 if (extension) {
02406                         break;
02407                 }
02408         }
02409 
02410         if (!extension) {
02411                 status = SWITCH_STATUS_FALSE;
02412                 goto done;
02413         }
02414 
02415         new_profile->caller_extension = extension;
02416 
02417         if (profile->caller_extension) {
02418                 for (pp = profile->caller_extension->children; pp && pp->next; pp = pp->next);
02419 
02420                 if (pp) {
02421                         pp->next = new_profile;
02422                 } else {
02423                         profile->caller_extension->children = new_profile;
02424                 }
02425         }
02426 
02427         while (switch_channel_ready(channel) && extension->current_application) {
02428                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Execute %s(%s)\n",
02429                                                   extension->current_application->application_name, switch_str_nil(extension->current_application->application_data));
02430 
02431                 if (switch_core_session_execute_application(session,
02432                                                                                                         extension->current_application->application_name,
02433                                                                                                         extension->current_application->application_data) != SWITCH_STATUS_SUCCESS) {
02434                         goto done;
02435                 }
02436 
02437                 extension->current_application = extension->current_application->next;
02438         }
02439 
02440   done:
02441         switch_channel_set_hunt_caller_profile(channel, NULL);
02442 
02443         session->stack_count--;
02444         return status;
02445 }

switch_status_t switch_core_session_flush_message ( switch_core_session_t session  ) 

Definition at line 888 of file switch_core_session.c.

References switch_assert, switch_core_session_free_message(), switch_ivr_process_indications(), switch_queue_trypop(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

00889 {
00890         switch_status_t status = SWITCH_STATUS_FALSE;
00891         void *pop;
00892         switch_core_session_message_t *message;
00893 
00894         switch_assert(session != NULL);
00895 
00896 
00897         if (session->message_queue) {
00898                 while ((status = (switch_status_t) switch_queue_trypop(session->message_queue, &pop)) == SWITCH_STATUS_SUCCESS) {
00899                         message = (switch_core_session_message_t *) pop;
00900                         switch_ivr_process_indications(session, message);
00901                         switch_core_session_free_message(&message);
00902                 }
00903         }
00904 
00905         return SWITCH_STATUS_SUCCESS;
00906 }

switch_core_session_t* switch_core_session_force_locate ( const char *  uuid_str  ) 

Definition at line 145 of file switch_core_session.c.

References runtime, switch_runtime::session_hash_mutex, session_manager, switch_session_manager::session_table, SSF_DESTROYED, switch_channel_get_name(), SWITCH_CHANNEL_ID_LOG, switch_core_hash_find(), switch_core_session_get_uuid(), SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_test_flag, and switch_thread_rwlock_tryrdlock().

00147 {
00148         switch_core_session_t *session = NULL;
00149         switch_status_t status;
00150 
00151         if (uuid_str) {
00152                 switch_mutex_lock(runtime.session_hash_mutex);
00153                 if ((session = switch_core_hash_find(session_manager.session_table, uuid_str))) {
00154                         /* Acquire a read lock on the session */
00155 
00156                         if (switch_test_flag(session, SSF_DESTROYED)) {
00157                                 status = SWITCH_STATUS_FALSE;
00158 #ifdef SWITCH_DEBUG_RWLOCKS
00159                                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, uuid_str, SWITCH_LOG_ERROR, "%s %s Read lock FAIL\n",
00160                                                                   switch_core_session_get_uuid(session), switch_channel_get_name(session->channel));
00161 #endif
00162                         } else {
00163                                 status = (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock);
00164 #ifdef SWITCH_DEBUG_RWLOCKS
00165                                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, uuid_str, SWITCH_LOG_ERROR, "%s %s Read lock ACQUIRED\n",
00166                                                                   switch_core_session_get_uuid(session), switch_channel_get_name(session->channel));
00167 #endif
00168                         }
00169 
00170                         if (status != SWITCH_STATUS_SUCCESS) {
00171                                 /* not available, forget it */
00172                                 session = NULL;
00173                         }
00174                 }
00175                 switch_mutex_unlock(runtime.session_hash_mutex);
00176         }
00177 
00178         /* if its not NULL, now it's up to you to rwunlock this */
00179         return session;
00180 }

switch_app_log_t* switch_core_session_get_app_log ( switch_core_session_t session  ) 

Definition at line 2050 of file switch_core_session.c.

02051 {
02052         return session->app_log;
02053 }

switch_channel_t* switch_core_session_get_channel ( switch_core_session_t session  ) 

Definition at line 1184 of file switch_core_session.c.

References switch_assert.

01185 {
01186         switch_assert(session->channel);
01187         return session->channel;
01188 }

switch_size_t switch_core_session_get_id ( switch_core_session_t session  ) 

Definition at line 1948 of file switch_core_session.c.

01949 {
01950         return session->id;
01951 }

void* switch_core_session_get_private ( switch_core_session_t session  ) 

Definition at line 366 of file switch_core_session.c.

References switch_assert.

00367 {
00368         switch_assert(session != NULL);
00369         return session->private_info;
00370 }

void* switch_core_session_get_stream ( switch_core_session_t session,
int  index 
)

Definition at line 386 of file switch_core_session.c.

00387 {
00388         return session->streams[index];
00389 }

int switch_core_session_get_stream_count ( switch_core_session_t session  ) 

Definition at line 392 of file switch_core_session.c.

00393 {
00394         return session->stream_count;
00395 }

char* switch_core_session_get_uuid ( switch_core_session_t session  ) 

Definition at line 1997 of file switch_core_session.c.

01998 {
01999         return session->uuid_str;
02000 }

void switch_core_session_hupall ( switch_call_cause_t  cause  ) 

Definition at line 286 of file switch_core_session.c.

References switch_core_session::channel, str_node::next, pool, runtime, switch_runtime::session_hash_mutex, session_manager, switch_session_manager::session_table, switch_channel_hangup, switch_core_alloc, switch_core_new_memory_pool, switch_core_session_locate(), switch_core_session_read_lock(), switch_core_session_rwunlock(), switch_core_strdup, switch_hash_first(), switch_hash_next(), switch_hash_this(), switch_mutex_lock(), switch_mutex_unlock(), and SWITCH_STATUS_SUCCESS.

00287 {
00288         switch_hash_index_t *hi;
00289         void *val;
00290         switch_core_session_t *session;
00291         switch_memory_pool_t *pool;
00292         struct str_node *head = NULL, *np;
00293 
00294         switch_core_new_memory_pool(&pool);
00295 
00296 
00297         switch_mutex_lock(runtime.session_hash_mutex);
00298         for (hi = switch_hash_first(NULL, session_manager.session_table); hi; hi = switch_hash_next(hi)) {
00299                 switch_hash_this(hi, NULL, NULL, &val);
00300                 if (val) {
00301                         session = (switch_core_session_t *) val;
00302                         if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
00303                                 np = switch_core_alloc(pool, sizeof(*np));
00304                                 np->str = switch_core_strdup(pool, session->uuid_str);
00305                                 np->next = head;
00306                                 head = np;
00307                                 switch_core_session_rwunlock(session);
00308                         }
00309                 }
00310         }
00311         switch_mutex_unlock(runtime.session_hash_mutex);
00312 
00313         for(np = head; np; np = np->next) { 
00314                 if ((session = switch_core_session_locate(np->str))) {
00315                         switch_channel_hangup(session->channel, cause);
00316                         switch_core_session_rwunlock(session);
00317                 }
00318         }
00319 
00320         switch_core_destroy_memory_pool(&pool);
00321 
00322 }

void switch_core_session_hupall_matching_var ( const char *  var_name,
const char *  var_val,
switch_call_cause_t  cause 
)

Definition at line 203 of file switch_core_session.c.

References switch_core_session::channel, str_node::next, pool, runtime, switch_runtime::session_hash_mutex, session_manager, switch_session_manager::session_table, switch_channel_get_variable, switch_channel_hangup, switch_channel_up_nosig, switch_core_alloc, switch_core_new_memory_pool, switch_core_session_locate(), switch_core_session_read_lock(), switch_core_session_rwunlock(), switch_core_strdup, switch_hash_first(), switch_hash_next(), switch_hash_this(), switch_mutex_lock(), switch_mutex_unlock(), and SWITCH_STATUS_SUCCESS.

00204 {
00205         switch_hash_index_t *hi;
00206         void *val;
00207         switch_core_session_t *session;
00208         switch_memory_pool_t *pool;
00209         struct str_node *head = NULL, *np;
00210 
00211         switch_core_new_memory_pool(&pool);
00212 
00213         if (!var_val)
00214                 return;
00215 
00216         switch_mutex_lock(runtime.session_hash_mutex);
00217         for (hi = switch_hash_first(NULL, session_manager.session_table); hi; hi = switch_hash_next(hi)) {
00218                 switch_hash_this(hi, NULL, NULL, &val);
00219                 if (val) {
00220                         session = (switch_core_session_t *) val;
00221                         if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
00222                                 np = switch_core_alloc(pool, sizeof(*np));
00223                                 np->str = switch_core_strdup(pool, session->uuid_str);
00224                                 np->next = head;
00225                                 head = np;
00226                                 switch_core_session_rwunlock(session);
00227                         }
00228                 }
00229         }
00230         switch_mutex_unlock(runtime.session_hash_mutex);
00231 
00232         for(np = head; np; np = np->next) {
00233                 if ((session = switch_core_session_locate(np->str))) {
00234                         const char *this_val;
00235                         if (switch_channel_up_nosig(session->channel) &&
00236                                 (this_val = switch_channel_get_variable(session->channel, var_name)) && (!strcmp(this_val, var_val))) {                 
00237                                 switch_channel_hangup(session->channel, cause);
00238                         }
00239                         switch_core_session_rwunlock(session);
00240                 }
00241         }
00242 
00243         switch_core_destroy_memory_pool(&pool);
00244 
00245 }

switch_bool_t switch_core_session_in_thread ( switch_core_session_t session  ) 

Definition at line 1392 of file switch_core_session.c.

References SWITCH_FALSE, switch_thread_equal(), switch_thread_self(), and SWITCH_TRUE.

Referenced by switch_channel_check_signal(), switch_channel_state_change_pending(), and switch_ivr_nomedia().

01393 {
01394         return switch_thread_equal(switch_thread_self(), session->thread_id) ? SWITCH_TRUE : SWITCH_FALSE;
01395 }

void switch_core_session_init ( switch_memory_pool_t pool  ) 

Definition at line 2036 of file switch_core_session.c.

References session_manager, and switch_core_hash_init.

Referenced by switch_core_init().

02037 {
02038         memset(&session_manager, 0, sizeof(session_manager));
02039         session_manager.session_limit = 1000;
02040         session_manager.session_id = 1;
02041         session_manager.memory_pool = pool;
02042         switch_core_hash_init(&session_manager.session_table, session_manager.memory_pool);
02043 }

void switch_core_session_launch_thread ( switch_core_session_t session,
switch_thread_start_t  func,
void *  obj 
)

Definition at line 1488 of file switch_core_session.c.

References apr_threadattr_t::pool, switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_detach_set(), switch_threadattr_stacksize_set(), and thread.

01489 {
01490         switch_thread_t *thread;
01491         switch_threadattr_t *thd_attr = NULL;
01492         switch_threadattr_create(&thd_attr, session->pool);
01493         switch_threadattr_detach_set(thd_attr, 1);
01494 
01495         switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
01496         switch_thread_create(&thread, thd_attr, func, obj, session->pool);
01497 
01498 }

uint32_t switch_core_session_limit ( uint32_t  new_limit  ) 

Definition at line 2003 of file switch_core_session.c.

References switch_session_manager::session_limit, and session_manager.

02004 {
02005         if (new_limit) {
02006                 session_manager.session_limit = new_limit;
02007         }
02008 
02009         return session_manager.session_limit;
02010 }

switch_core_session_t* switch_core_session_locate ( const char *  uuid_str  ) 

Definition at line 111 of file switch_core_session.c.

References runtime, switch_runtime::session_hash_mutex, session_manager, switch_session_manager::session_table, switch_core_hash_find(), switch_core_session_read_lock(), switch_mutex_lock(), switch_mutex_unlock(), and SWITCH_STATUS_SUCCESS.

00113 {
00114         switch_core_session_t *session = NULL;
00115 
00116         if (uuid_str) {
00117                 switch_mutex_lock(runtime.session_hash_mutex);
00118                 if ((session = switch_core_hash_find(session_manager.session_table, uuid_str))) {
00119                         /* Acquire a read lock on the session */
00120 #ifdef SWITCH_DEBUG_RWLOCKS
00121                         if (switch_core_session_perform_read_lock(session, file, func, line) != SWITCH_STATUS_SUCCESS) {
00122 #if EMACS_CC_MODE_IS_BUGGY
00123                         }
00124 #endif
00125 #else
00126                         if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
00127 #endif
00128                                 /* not available, forget it */
00129                                 session = NULL;
00130                         }
00131                 }
00132                 switch_mutex_unlock(runtime.session_hash_mutex);
00133         }
00134 
00135         /* if its not NULL, now it's up to you to rwunlock this */
00136         return session;
00137 }

switch_status_t switch_core_session_message_send ( const char *  uuid_str,
switch_core_session_message_t message 
)

Definition at line 325 of file switch_core_session.c.

References switch_core_session::channel, runtime, switch_runtime::session_hash_mutex, session_manager, switch_session_manager::session_table, switch_channel_up_nosig, switch_core_hash_find(), switch_core_session_read_lock(), switch_core_session_receive_message, switch_core_session_rwunlock(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

00326 {
00327         switch_core_session_t *session = NULL;
00328         switch_status_t status = SWITCH_STATUS_FALSE;
00329 
00330         switch_mutex_lock(runtime.session_hash_mutex);
00331         if ((session = switch_core_hash_find(session_manager.session_table, uuid_str)) != 0) {
00332                 /* Acquire a read lock on the session or forget it the channel is dead */
00333                 if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
00334                         if (switch_channel_up_nosig(session->channel)) {
00335                                 status = switch_core_session_receive_message(session, message);
00336                         }
00337                         switch_core_session_rwunlock(session);
00338                 }
00339         }
00340         switch_mutex_unlock(runtime.session_hash_mutex);
00341 
00342         return status;
00343 }

switch_call_cause_t switch_core_session_outgoing_channel ( switch_core_session_t session,
switch_event_t var_event,
const char *  endpoint_name,
switch_caller_profile_t caller_profile,
switch_core_session_t **  new_session,
switch_memory_pool_t **  pool,
switch_originate_flag_t  flags,
switch_call_cause_t cancel_cause 
)

Definition at line 410 of file switch_core_session.c.

References switch_caller_profile::caller_id_name, switch_caller_profile::caller_id_number, CC_BYPASS_MEDIA, CC_PROXY_MEDIA, CF_PROXY_MEDIA, CF_PROXY_MODE, CF_VIDEO, switch_codec::implementation, switch_endpoint_interface::io_routines, switch_io_event_hook_outgoing_channel::next, switch_io_event_hook_outgoing_channel::outgoing_channel, switch_io_routines::outgoing_channel, SOF_NO_EFFECTIVE_CID_NAME, SOF_NO_EFFECTIVE_CID_NUM, switch_assert, SWITCH_B_SDP_VARIABLE, switch_caller_profile_clone(), SWITCH_CAUSE_CHAN_NOT_IMPLEMENTED, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL, SWITCH_CAUSE_SUCCESS, switch_channel_cause2str(), switch_channel_clear_flag(), switch_channel_event_set_data(), switch_channel_get_caller_profile(), switch_channel_get_name(), switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_set_origination_caller_profile(), switch_channel_set_originator_caller_profile(), switch_channel_set_variable, switch_channel_test_cap(), switch_channel_test_flag(), switch_codec2str, switch_core_codec_ready(), switch_core_session_get_channel(), switch_core_session_get_read_codec(), switch_core_session_get_uuid(), switch_core_session_get_video_read_codec(), switch_core_session_set_uuid(), switch_core_session_sprintf(), switch_core_session_strdup, SWITCH_EVENT_CHANNEL_OUTGOING, switch_event_create, switch_event_del_header, switch_event_fire, switch_event_get_header, switch_loadable_module_get_endpoint_interface(), SWITCH_LOG_CRIT, SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, SWITCH_MAX_FORWARDS_VARIABLE, SWITCH_ORIGINATOR_CODEC_VARIABLE, SWITCH_ORIGINATOR_VARIABLE, SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE, SWITCH_PROCESS_CDR_VARIABLE, SWITCH_R_SDP_VARIABLE, SWITCH_SIGNAL_BOND_VARIABLE, switch_snprintf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, UNPROTECT_INTERFACE, and zstr.

00416 {
00417         switch_io_event_hook_outgoing_channel_t *ptr;
00418         switch_status_t status = SWITCH_STATUS_FALSE;
00419         switch_endpoint_interface_t *endpoint_interface;
00420         switch_channel_t *channel = NULL;
00421         switch_caller_profile_t *outgoing_profile = caller_profile;
00422         switch_call_cause_t cause = SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL;
00423         const char *forwardvar;
00424         int forwardval = 70;
00425 
00426         if ((endpoint_interface = switch_loadable_module_get_endpoint_interface(endpoint_name)) == 0) {
00427                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Could not locate channel type %s\n", endpoint_name);
00428                 return SWITCH_CAUSE_CHAN_NOT_IMPLEMENTED;
00429         }
00430 
00431         if (!endpoint_interface->io_routines->outgoing_channel) {
00432                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Could not locate outgoing channel interface for %s\n", endpoint_name);
00433                 return SWITCH_CAUSE_CHAN_NOT_IMPLEMENTED;
00434         }
00435 
00436         if (session) {
00437                 channel = switch_core_session_get_channel(session);
00438 
00439                 switch_assert(channel != NULL);
00440 
00441                 forwardvar = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE);
00442                 if (!zstr(forwardvar)) {
00443                         forwardval = atoi(forwardvar) - 1;
00444                 }
00445                 if (forwardval <= 0) {
00446                         return SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR;
00447                 }
00448 
00449                 if (caller_profile) {
00450                         const char *ecaller_id_name = NULL, *ecaller_id_number = NULL;
00451 
00452                         if (!(flags & SOF_NO_EFFECTIVE_CID_NAME)) {
00453                                 ecaller_id_name = switch_channel_get_variable(channel, "effective_caller_id_name");
00454                         }
00455 
00456                         if (!(flags & SOF_NO_EFFECTIVE_CID_NUM)) {
00457                                 ecaller_id_number = switch_channel_get_variable(channel, "effective_caller_id_number");
00458                         }
00459 
00460                         if (ecaller_id_name || ecaller_id_number) {
00461                                 outgoing_profile = switch_caller_profile_clone(session, caller_profile);
00462 
00463                                 if (ecaller_id_name) {
00464                                         outgoing_profile->caller_id_name = ecaller_id_name;
00465                                 }
00466                                 if (ecaller_id_number) {
00467                                         outgoing_profile->caller_id_number = ecaller_id_number;
00468                                 }
00469                         }
00470                 }
00471                 if (!outgoing_profile) {
00472                         outgoing_profile = switch_channel_get_caller_profile(channel);
00473                 }
00474         }
00475 
00476         if ((cause =
00477                  endpoint_interface->io_routines->outgoing_channel(session, var_event, outgoing_profile, new_session, pool, flags,
00478                                                                                                                    cancel_cause)) != SWITCH_CAUSE_SUCCESS) {
00479                 UNPROTECT_INTERFACE(endpoint_interface);
00480                 return cause;
00481         }
00482 
00483         if (session) {
00484                 for (ptr = session->event_hooks.outgoing_channel; ptr; ptr = ptr->next) {
00485                         if ((status = ptr->outgoing_channel(session, var_event, caller_profile, *new_session, flags)) != SWITCH_STATUS_SUCCESS) {
00486                                 break;
00487                         }
00488                 }
00489         }
00490 
00491         if (!*new_session) {
00492                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT,
00493                                                   "Outgoing method for endpoint: [%s] returned: [%s] but there is no new session!\n", endpoint_name,
00494                                                   switch_channel_cause2str(cause));
00495                 UNPROTECT_INTERFACE(endpoint_interface);
00496                 return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
00497         } else {
00498                 switch_caller_profile_t *profile = NULL, *cloned_profile = NULL;
00499                 switch_event_t *event;
00500                 switch_channel_t *peer_channel = switch_core_session_get_channel(*new_session);
00501                 const char *use_uuid;
00502 
00503                 switch_assert(peer_channel);
00504 
00505                 if ((use_uuid = switch_event_get_header(var_event, "origination_uuid"))) {
00506                         use_uuid = switch_core_session_strdup(*new_session, use_uuid);
00507                         if (switch_core_session_set_uuid(*new_session, use_uuid) == SWITCH_STATUS_SUCCESS) {
00508                                 switch_event_del_header(var_event, "origination_uuid");
00509                                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "%s set UUID=%s\n", switch_channel_get_name(peer_channel),
00510                                                                   use_uuid);
00511                         } else {
00512                                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_CRIT, "%s set UUID=%s FAILED\n",
00513                                                                   switch_channel_get_name(peer_channel), use_uuid);
00514                         }
00515                 }
00516 
00517                 if (channel) {
00518                         const char *val;
00519                         switch_codec_t *vid_read_codec = NULL, *read_codec = switch_core_session_get_read_codec(session);
00520                         const char *ep, *max_forwards = switch_core_session_sprintf(session, "%d", forwardval);
00521 
00522                         switch_channel_set_variable(peer_channel, SWITCH_MAX_FORWARDS_VARIABLE, max_forwards);
00523 
00524                         profile = switch_channel_get_caller_profile(channel);
00525 
00526                         vid_read_codec = switch_core_session_get_video_read_codec(session);
00527 
00528                         if (read_codec && read_codec->implementation && switch_core_codec_ready(read_codec)) {
00529                                 char rc[80] = "", vrc[80] = "", tmp[160] = "";
00530 
00531                                 switch_codec2str(read_codec, rc, sizeof(rc));
00532                                 if (vid_read_codec && vid_read_codec->implementation && switch_core_codec_ready(vid_read_codec)) {
00533                                         vrc[0] = ',';
00534                                         switch_codec2str(vid_read_codec, vrc + 1, sizeof(vrc) - 1);
00535                                         switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE, vrc + 1);
00536                                 }
00537 
00538                                 switch_snprintf(tmp, sizeof(tmp), "%s%s", rc, vrc);
00539                                 switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_CODEC_VARIABLE, tmp);
00540                         } else if ((ep = switch_channel_get_variable(channel, "ep_codec_string"))) {
00541                                 switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_CODEC_VARIABLE, ep);
00542                         }
00543 
00544                         switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VARIABLE, switch_core_session_get_uuid(session));
00545                         switch_channel_set_variable(peer_channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(session));
00546                         // Needed by 3PCC proxy so that aleg can find bleg to pass SDP to, when final ACK arrives.
00547                         switch_channel_set_variable(channel, "originate_signal_bond", switch_core_session_get_uuid(*new_session));
00548 
00549                         if ((val = switch_channel_get_variable(channel, SWITCH_PROCESS_CDR_VARIABLE))) {
00550                                 switch_channel_set_variable(peer_channel, SWITCH_PROCESS_CDR_VARIABLE, val);
00551                         }
00552 
00553                         if ((val = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE))) {
00554                                 switch_channel_set_variable(peer_channel, SWITCH_B_SDP_VARIABLE, val);
00555                         }
00556 
00557                         if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
00558                                 if (switch_channel_test_cap(peer_channel, CC_BYPASS_MEDIA)) {
00559                                         switch_channel_set_flag(peer_channel, CF_PROXY_MODE);
00560                                 } else {
00561                                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
00562                                                                           "%s does not support the proxy feature, disabling.\n", switch_channel_get_name(peer_channel));
00563                                         switch_channel_clear_flag(channel, CF_PROXY_MODE);
00564                                 }
00565                         }
00566 
00567                         if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
00568                                 if (switch_channel_test_cap(peer_channel, CC_PROXY_MEDIA)) {
00569                                         switch_channel_set_flag(peer_channel, CF_PROXY_MEDIA);
00570                                         if (switch_channel_test_flag(channel, CF_VIDEO)) {
00571                                                 switch_channel_set_flag(peer_channel, CF_VIDEO);
00572                                         }
00573                                 } else {
00574                                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
00575                                                                           "%s does not support the proxy feature, disabling.\n", switch_channel_get_name(peer_channel));
00576                                         switch_channel_clear_flag(channel, CF_PROXY_MEDIA);
00577                                 }
00578                         }
00579 
00580                         if (profile) {
00581                                 if ((cloned_profile = switch_caller_profile_clone(*new_session, profile)) != 0) {
00582                                         switch_channel_set_originator_caller_profile(peer_channel, cloned_profile);
00583                                 }
00584                         }
00585 
00586 
00587                         if ((profile = switch_channel_get_caller_profile(peer_channel))) {
00588                                 if ((cloned_profile = switch_caller_profile_clone(session, profile)) != 0) {
00589                                         switch_channel_set_origination_caller_profile(channel, cloned_profile);
00590                                 }
00591                         }
00592 
00593                 }
00594 
00595                 if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_OUTGOING) == SWITCH_STATUS_SUCCESS) {
00596                         switch_channel_event_set_data(peer_channel, event);
00597                         switch_event_fire(&event);
00598                 }
00599         }
00600 
00601         UNPROTECT_INTERFACE(endpoint_interface);
00602         return cause;
00603 }

switch_status_t switch_core_session_pass_indication ( switch_core_session_t session,
switch_core_session_message_types_t  indication 
)

Definition at line 788 of file switch_core_session.c.

References switch_core_session_message::from, switch_core_session_message::message_id, switch_channel_get_variable, switch_core_session_get_channel(), switch_core_session_locate(), switch_core_session_receive_message, switch_core_session_rwunlock(), SWITCH_SIGNAL_BOND_VARIABLE, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

00789 {
00790         switch_core_session_message_t msg = { 0 };
00791         switch_core_session_t *other_session;
00792         const char *uuid;
00793         switch_channel_t *channel = switch_core_session_get_channel(session);
00794         switch_status_t status = SWITCH_STATUS_SUCCESS;
00795 
00796         if (((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) || (uuid = switch_channel_get_variable(channel, "originate_signal_bond"))) && (other_session = switch_core_session_locate(uuid))) {
00797                 msg.message_id = indication;
00798                 msg.from = __FILE__;
00799                 status = switch_core_session_receive_message(other_session, &msg);
00800                 switch_core_session_rwunlock(other_session);
00801         } else {
00802                 status = SWITCH_STATUS_FALSE;
00803         }
00804 
00805         return status;
00806 }

void switch_core_session_perform_destroy ( switch_core_session_t **  session,
const char *  file,
const char *  func,
int  line 
)

Definition at line 1257 of file switch_core_session.c.

References pool, runtime, SCF_SYNC_CLOCK_REQUESTED, switch_session_manager::session_count, switch_runtime::session_hash_mutex, session_manager, switch_session_manager::session_table, switch_buffer_destroy(), switch_channel_event_set_data(), switch_channel_get_name(), switch_channel_get_state(), SWITCH_CHANNEL_ID_LOG, switch_channel_state_name(), switch_channel_uninit(), switch_clear_flag, switch_core_hash_delete(), switch_core_media_bug_remove_all, switch_core_session_destroy_state(), switch_core_session_get_uuid(), switch_core_session_reset(), SWITCH_EVENT_CHANNEL_DESTROY, switch_event_create, switch_event_fire, switch_ivr_clear_speech_cache(), switch_ivr_deactivate_unicast(), switch_ivr_dmachine_destroy(), SWITCH_LOG_NOTICE, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_scheduler_del_task_group(), SWITCH_STATUS_SUCCESS, switch_test_flag, switch_time_sync(), SWITCH_TRUE, and TRUE.

01258 {
01259         switch_memory_pool_t *pool;
01260         switch_event_t *event;
01261         switch_endpoint_interface_t *endpoint_interface = (*session)->endpoint_interface;
01262         int i;
01263 
01264         switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(*session), SWITCH_LOG_NOTICE, "Close Channel %s [%s]\n",
01265                                           switch_channel_get_name((*session)->channel), switch_channel_state_name(switch_channel_get_state((*session)->channel)));
01266 
01267 
01268         switch_core_session_reset(*session, TRUE, SWITCH_TRUE);
01269 
01270         switch_core_media_bug_remove_all(*session);
01271         switch_ivr_deactivate_unicast(*session);
01272 
01273         switch_scheduler_del_task_group((*session)->uuid_str);
01274 
01275         switch_mutex_lock(runtime.session_hash_mutex);
01276         switch_core_hash_delete(session_manager.session_table, (*session)->uuid_str);
01277         if (session_manager.session_count) {
01278                 session_manager.session_count--;
01279                 if (session_manager.session_count == 0) {
01280                         if (switch_test_flag((&runtime), SCF_SYNC_CLOCK_REQUESTED)) {
01281                                 switch_time_sync();
01282                                 switch_clear_flag((&runtime), SCF_SYNC_CLOCK_REQUESTED);
01283                         }
01284                 }
01285         }
01286         switch_mutex_unlock(runtime.session_hash_mutex);
01287 
01288         if ((*session)->plc) {
01289                 plc_free((*session)->plc);
01290                 (*session)->plc = NULL;
01291         }
01292 
01293         if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DESTROY) == SWITCH_STATUS_SUCCESS) {
01294                 switch_channel_event_set_data((*session)->channel, event);
01295                 switch_event_fire(&event);
01296         }
01297 
01298         switch_core_session_destroy_state(*session);
01299 
01300         switch_buffer_destroy(&(*session)->raw_read_buffer);
01301         switch_buffer_destroy(&(*session)->raw_write_buffer);
01302         switch_ivr_clear_speech_cache(*session);
01303         switch_channel_uninit((*session)->channel);
01304 
01305         for (i = 0; i < 2; i++) {
01306                 if ((*session)->dmachine[i]) {
01307                         switch_ivr_dmachine_destroy(&(*session)->dmachine[i]);
01308                 }
01309         }
01310 
01311         pool = (*session)->pool;
01312         //#ifndef NDEBUG
01313         //memset(*session, 0, sizeof(switch_core_session_t));
01314         //#endif
01315         *session = NULL;
01316         switch_core_destroy_memory_pool(&pool);
01317 
01318         UNPROTECT_INTERFACE(endpoint_interface);
01319 }

switch_status_t switch_core_session_perform_receive_message ( switch_core_session_t session,
switch_core_session_message_t message,
const char *  file,
const char *  func,
int  line 
)

Definition at line 647 of file switch_core_session.c.

References CF_CONFIRM_BLIND_TRANSFER, CF_EARLY_MEDIA, switch_core_session_message::from, switch_core_session_message::message_id, switch_io_event_hook_receive_message::next, switch_core_session_message::numeric_arg, switch_io_event_hook_receive_message::receive_message, switch_assert, switch_channel_clear_flag(), switch_channel_down_nosig, switch_channel_get_name(), switch_channel_get_variable, SWITCH_CHANNEL_ID_LOG, switch_channel_set_variable, switch_channel_test_flag(), switch_channel_up_nosig, switch_core_media_bug_flush_all(), switch_core_session_free_message(), switch_core_session_get_uuid(), switch_core_session_kill_channel, switch_core_session_locate(), switch_core_session_read_lock_hangup(), switch_core_session_receive_message, switch_core_session_rwunlock(), switch_core_session_strdup, SWITCH_IGNORE_DISPLAY_UPDATES_VARIABLE, SWITCH_LOG_DEBUG, SWITCH_LOG_DEBUG1, switch_log_printf(), SWITCH_MESSAGE_INDICATE_ANSWER, SWITCH_MESSAGE_INDICATE_BLIND_TRANSFER_RESPONSE, SWITCH_MESSAGE_INDICATE_BRIDGE, SWITCH_MESSAGE_INDICATE_BROADCAST, SWITCH_MESSAGE_INDICATE_CLEAR_PROGRESS, SWITCH_MESSAGE_INDICATE_DEFLECT, SWITCH_MESSAGE_INDICATE_DISPLAY, SWITCH_MESSAGE_INDICATE_HOLD, SWITCH_MESSAGE_INDICATE_MEDIA, SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT, SWITCH_MESSAGE_INDICATE_NOMEDIA, SWITCH_MESSAGE_INDICATE_PROGRESS, SWITCH_MESSAGE_INDICATE_REDIRECT, SWITCH_MESSAGE_INDICATE_RESPOND, SWITCH_MESSAGE_INDICATE_RINGING, SWITCH_MESSAGE_INDICATE_SIGNAL_DATA, SWITCH_MESSAGE_INDICATE_TRANSFER, SWITCH_MESSAGE_INDICATE_UNBRIDGE, SWITCH_MESSAGE_INDICATE_UNHOLD, SWITCH_MESSAGE_INVALID, SWITCH_MESSAGE_REDIRECT_AUDIO, switch_separate_string(), SWITCH_SIG_BREAK, SWITCH_STATUS_SUCCESS, switch_true(), and zstr.

00650 {
00651         switch_io_event_hook_receive_message_t *ptr;
00652         switch_status_t status = SWITCH_STATUS_SUCCESS;
00653 
00654         switch_assert(session != NULL);
00655 
00656         if ((status = switch_core_session_read_lock_hangup(session)) != SWITCH_STATUS_SUCCESS) {
00657                 return status;
00658         }
00659         
00660         if (!message->_file) {
00661                 message->_file = file;
00662         }
00663 
00664         if (!message->_func) {
00665                 message->_func = func;
00666         }
00667 
00668         if (!message->_line) {
00669                 message->_line = line;
00670         }
00671 
00672         if (message->message_id > SWITCH_MESSAGE_INVALID-1) {
00673                 message->message_id = SWITCH_MESSAGE_INVALID-1;
00674         }
00675 
00676         switch_log_printf(SWITCH_CHANNEL_ID_LOG, message->_file, message->_func, message->_line,
00677                                           switch_core_session_get_uuid(session), SWITCH_LOG_DEBUG1, "%s receive message [%s]\n",
00678                                           switch_channel_get_name(session->channel), message_names[message->message_id]);
00679 
00680 
00681         if (message->message_id == SWITCH_MESSAGE_INDICATE_CLEAR_PROGRESS) {
00682                 switch_channel_clear_flag(session->channel, CF_EARLY_MEDIA);
00683         }
00684 
00685         if (message->message_id == SWITCH_MESSAGE_INDICATE_DISPLAY) {
00686                 char *arg = NULL;
00687 
00688                 if (zstr(message->string_array_arg[0]) && !zstr(message->string_arg)) {
00689                         arg = switch_core_session_strdup(session, message->string_arg);
00690                         switch_separate_string(arg, '|', (char **)message->string_array_arg, 2);                        
00691                 }
00692 
00693                 if (!zstr(message->string_array_arg[0])) {
00694                         switch_channel_set_variable(session->channel, "last_sent_callee_id_name", message->string_array_arg[0]);
00695                 }
00696 
00697                 if (!zstr(message->string_array_arg[1])) {
00698                         switch_channel_set_variable(session->channel, "last_sent_callee_id_number", message->string_array_arg[1]);
00699                 }
00700                 
00701 
00702                 if (switch_true(switch_channel_get_variable(session->channel, SWITCH_IGNORE_DISPLAY_UPDATES_VARIABLE))) {
00703                         switch_log_printf(SWITCH_CHANNEL_ID_LOG, message->_file, message->_func, message->_line,
00704                                                           switch_core_session_get_uuid(session), SWITCH_LOG_DEBUG1, "Ignoring display update.\n");
00705                         status = SWITCH_STATUS_SUCCESS;
00706                         goto end;
00707                 }
00708 
00709         }
00710 
00711         if (switch_channel_down_nosig(session->channel) && message->message_id != SWITCH_MESSAGE_INDICATE_SIGNAL_DATA) {
00712                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, message->_file, message->_func, message->_line,
00713                                                   switch_core_session_get_uuid(session), SWITCH_LOG_DEBUG, "%s skip receive message [%s] (channel is hungup already)\n",
00714                                                   switch_channel_get_name(session->channel), message_names[message->message_id]);
00715         
00716         } else if (session->endpoint_interface->io_routines->receive_message) {
00717                 status = session->endpoint_interface->io_routines->receive_message(session, message);
00718         }
00719 
00720         if (status == SWITCH_STATUS_SUCCESS) {
00721                 for (ptr = session->event_hooks.receive_message; ptr; ptr = ptr->next) {
00722                         if ((status = ptr->receive_message(session, message)) != SWITCH_STATUS_SUCCESS) {
00723                                 break;
00724                         }
00725                 }
00726 
00727 
00728                 if (message->message_id == SWITCH_MESSAGE_INDICATE_BRIDGE &&
00729                         switch_channel_test_flag(session->channel, CF_CONFIRM_BLIND_TRANSFER)) {
00730                         switch_core_session_t *other_session;
00731                         const char *uuid = switch_channel_get_variable(session->channel, "blind_transfer_uuid");
00732 
00733                         switch_channel_clear_flag(session->channel, CF_CONFIRM_BLIND_TRANSFER);
00734 
00735                         if (!zstr(uuid) && (other_session = switch_core_session_locate(uuid))) {
00736                                 switch_core_session_message_t msg = { 0 };                      
00737                                 msg.message_id = SWITCH_MESSAGE_INDICATE_BLIND_TRANSFER_RESPONSE;
00738                                 msg.from = __FILE__;
00739                                 msg.numeric_arg = 1;
00740                                 switch_core_session_receive_message(other_session, &msg);
00741                                 switch_core_session_rwunlock(other_session);
00742                         }
00743                 }
00744         }
00745 
00746 
00747         message->_file = NULL;
00748         message->_func = NULL;
00749         message->_line = 0;
00750 
00751         if (switch_channel_up_nosig(session->channel)) {
00752                 if (message->message_id == SWITCH_MESSAGE_INDICATE_BRIDGE || message->message_id == SWITCH_MESSAGE_INDICATE_UNBRIDGE) {
00753                         switch_core_media_bug_flush_all(session);
00754                 }
00755 
00756                 switch (message->message_id) {
00757                 case SWITCH_MESSAGE_REDIRECT_AUDIO:
00758                 case SWITCH_MESSAGE_INDICATE_ANSWER:
00759                 case SWITCH_MESSAGE_INDICATE_PROGRESS:
00760                 case SWITCH_MESSAGE_INDICATE_BRIDGE:
00761                 case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
00762                 case SWITCH_MESSAGE_INDICATE_TRANSFER:
00763                 case SWITCH_MESSAGE_INDICATE_RINGING:
00764                 case SWITCH_MESSAGE_INDICATE_MEDIA:
00765                 case SWITCH_MESSAGE_INDICATE_NOMEDIA:
00766                 case SWITCH_MESSAGE_INDICATE_HOLD:
00767                 case SWITCH_MESSAGE_INDICATE_UNHOLD:
00768                 case SWITCH_MESSAGE_INDICATE_REDIRECT:
00769                 case SWITCH_MESSAGE_INDICATE_RESPOND:
00770                 case SWITCH_MESSAGE_INDICATE_BROADCAST:
00771                 case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT:
00772                 case SWITCH_MESSAGE_INDICATE_DEFLECT:
00773                         switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
00774                         break;
00775                 default:
00776                         break;
00777                 }
00778         }
00779 
00780   end:
00781 
00782         switch_core_session_free_message(&message);
00783         switch_core_session_rwunlock(session);
00784 
00785         return status;
00786 }

uint32_t switch_core_session_private_event_count ( switch_core_session_t session  ) 

Definition at line 1072 of file switch_core_session.c.

References CF_EVENT_LOCK, CF_EVENT_LOCK_PRI, check_media, switch_channel_test_flag(), switch_core_session_get_channel(), and switch_queue_size().

01073 {
01074         switch_channel_t *channel = switch_core_session_get_channel(session);
01075         uint32_t count = 0;
01076 
01077         if (session->private_event_queue) {
01078 
01079                 if (!switch_channel_test_flag(channel, CF_EVENT_LOCK)) {
01080                         count = switch_queue_size(session->private_event_queue);
01081                 }
01082 
01083                 if (!switch_channel_test_flag(channel, CF_EVENT_LOCK_PRI)) {
01084                         count += switch_queue_size(session->private_event_queue_pri);
01085                 }
01086 
01087                 if (count == 0) {
01088                         check_media(session);
01089                 }
01090         }
01091 
01092         return count;
01093 }

switch_status_t switch_core_session_queue_event ( switch_core_session_t session,
switch_event_t **  event 
)

Definition at line 983 of file switch_core_session.c.

References CF_PROXY_MODE, CF_THREAD_SLEEPING, switch_assert, switch_channel_test_flag(), switch_core_session_wake_session_thread(), switch_queue_trypush(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

00984 {
00985         switch_status_t status = SWITCH_STATUS_FALSE;
00986 
00987         switch_assert(session != NULL);
00988 
00989         if (session->event_queue) {
00990                 if (switch_queue_trypush(session->event_queue, *event) == SWITCH_STATUS_SUCCESS) {
00991                         *event = NULL;
00992                         status = SWITCH_STATUS_SUCCESS;
00993 
00994                         if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || switch_channel_test_flag(session->channel, CF_THREAD_SLEEPING)) {
00995                                 switch_core_session_wake_session_thread(session);
00996                         }
00997                 }
00998         }
00999 
01000         return status;
01001 }

switch_status_t switch_core_session_queue_indication ( switch_core_session_t session,
switch_core_session_message_types_t  indication 
)

Definition at line 808 of file switch_core_session.c.

References SCSMF_DYNAMIC, switch_core_session_queue_message(), switch_set_flag, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

00809 {
00810         switch_core_session_message_t *msg;
00811 
00812         if ((msg = malloc(sizeof(*msg)))) {
00813                 memset(msg, 0, sizeof(*msg));
00814                 msg->message_id = indication;
00815                 msg->from = __FILE__;
00816                 switch_set_flag(msg, SCSMF_DYNAMIC);
00817                 switch_core_session_queue_message(session, msg);
00818                 return SWITCH_STATUS_SUCCESS;
00819         }
00820 
00821         return SWITCH_STATUS_FALSE;
00822 }

switch_status_t switch_core_session_queue_message ( switch_core_session_t session,
switch_core_session_message_t message 
)

Definition at line 824 of file switch_core_session.c.

References CF_PROXY_MODE, CF_THREAD_SLEEPING, switch_assert, switch_channel_test_flag(), switch_core_session_kill_channel, switch_core_session_wake_session_thread(), switch_queue_trypush(), SWITCH_SIG_BREAK, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

00825 {
00826         switch_status_t status = SWITCH_STATUS_FALSE;
00827 
00828         switch_assert(session != NULL);
00829 
00830         if (session->message_queue) {
00831                 if (switch_queue_trypush(session->message_queue, message) == SWITCH_STATUS_SUCCESS) {
00832                         status = SWITCH_STATUS_SUCCESS;
00833                 }
00834 
00835                 switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
00836 
00837                 if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || switch_channel_test_flag(session->channel, CF_THREAD_SLEEPING)) {
00838                         switch_core_session_wake_session_thread(session);
00839                 }
00840         }
00841 
00842         return status;
00843 }

switch_status_t switch_core_session_queue_private_event ( switch_core_session_t session,
switch_event_t **  event,
switch_bool_t  priority 
)

Definition at line 1043 of file switch_core_session.c.

References switch_assert, switch_core_session_kill_channel, SWITCH_EVENT_PRIVATE_COMMAND, switch_queue_trypush(), SWITCH_SIG_BREAK, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

01044 {
01045         switch_status_t status = SWITCH_STATUS_FALSE;
01046         switch_queue_t *queue;
01047 
01048         switch_assert(session != NULL);
01049 
01050         if (session->private_event_queue) {
01051                 queue = priority ? session->private_event_queue_pri : session->private_event_queue;
01052 
01053                 (*event)->event_id = SWITCH_EVENT_PRIVATE_COMMAND;
01054                 if (switch_queue_trypush(queue, *event) == SWITCH_STATUS_SUCCESS) {
01055                         *event = NULL;
01056                         switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
01057                         status = SWITCH_STATUS_SUCCESS;
01058                 }
01059         }
01060 
01061         return status;
01062 }

switch_status_t switch_core_session_receive_event ( switch_core_session_t session,
switch_event_t **  event 
)

Definition at line 945 of file switch_core_session.c.

References switch_io_event_hook_receive_event::next, switch_io_event_hook_receive_event::receive_event, switch_assert, switch_channel_up_nosig, switch_core_session_kill_channel, switch_core_session_read_lock(), switch_core_session_rwunlock(), switch_event_destroy(), SWITCH_SIG_BREAK, SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

00946 {
00947         switch_io_event_hook_receive_event_t *ptr;
00948         switch_status_t status = SWITCH_STATUS_FALSE;
00949 
00950         switch_assert(session != NULL);
00951 
00952         /* Acquire a read lock on the session or forget it the channel is dead */
00953         if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
00954                 if (switch_channel_up_nosig(session->channel)) {
00955                         if (session->endpoint_interface->io_routines->receive_event) {
00956                                 status = session->endpoint_interface->io_routines->receive_event(session, *event);
00957                         }
00958 
00959                         if (status == SWITCH_STATUS_SUCCESS) {
00960                                 for (ptr = session->event_hooks.receive_event; ptr; ptr = ptr->next) {
00961                                         if ((status = ptr->receive_event(session, *event)) != SWITCH_STATUS_SUCCESS) {
00962                                                 break;
00963                                         }
00964                                 }
00965                         }
00966 
00967                         if (status == SWITCH_STATUS_BREAK) {
00968                                 status = SWITCH_STATUS_SUCCESS;
00969                         }
00970 
00971                         if (status == SWITCH_STATUS_SUCCESS) {
00972                                 switch_event_destroy(event);
00973                         }
00974                 }
00975                 switch_core_session_rwunlock(session);
00976         }
00977 
00978         switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
00979 
00980         return status;
00981 }

switch_core_session_t* switch_core_session_request_by_name ( const char *  endpoint_name,
switch_call_direction_t  direction,
switch_memory_pool_t **  pool 
)

Definition at line 1959 of file switch_core_session.c.

References SOF_NONE, SWITCH_CHANNEL_LOG, switch_core_session_request, switch_loadable_module_get_endpoint_interface(), SWITCH_LOG_ERROR, switch_log_printf(), and UNPROTECT_INTERFACE.

01961 {
01962         switch_endpoint_interface_t *endpoint_interface;
01963         switch_core_session_t *session;
01964 
01965         if ((endpoint_interface = switch_loadable_module_get_endpoint_interface(endpoint_name)) == 0) {
01966                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not locate channel type %s\n", endpoint_name);
01967                 return NULL;
01968         }
01969 
01970         session = switch_core_session_request(endpoint_interface, direction, SOF_NONE, pool);
01971 
01972         UNPROTECT_INTERFACE(endpoint_interface);
01973 
01974         return session;
01975 }

switch_core_session_t* switch_core_session_request_uuid ( switch_endpoint_interface_t endpoint_interface,
switch_call_direction_t  direction,
switch_originate_flag_t  originate_flags,
switch_memory_pool_t **  pool,
const char *  use_uuid 
)

Definition at line 1811 of file switch_core_session.c.

References CF_OUTBOUND, CS_NEW, switch_runtime::min_idle_time, switch_runtime::profile_time, PROTECT_INTERFACE, runtime, switch_session_manager::session_count, switch_runtime::session_hash_mutex, switch_session_manager::session_id, switch_session_manager::session_limit, session_manager, switch_session_manager::session_table, SOF_NO_LIMITS, switch_runtime::sps, SWITCH_CALL_DIRECTION_INBOUND, SWITCH_CALL_DIRECTION_OUTBOUND, switch_channel_alloc(), switch_channel_init(), SWITCH_CHANNEL_LOG, switch_channel_set_flag, switch_channel_set_variable, switch_channel_set_variable_printf(), switch_core_alloc, switch_core_hash_find(), switch_core_hash_insert(), switch_core_memory_pool_set_data(), switch_core_new_memory_pool, switch_core_ready(), switch_core_ready_inbound(), switch_core_ready_outbound(), SWITCH_EVENT_QUEUE_LEN, SWITCH_LOG_CRIT, switch_log_printf(), SWITCH_MESSAGE_QUEUE_LEN, switch_mutex_init(), switch_mutex_lock(), SWITCH_MUTEX_NESTED, switch_mutex_unlock(), switch_queue_create(), switch_set_string, SWITCH_STATUS_SUCCESS, switch_thread_cond_create(), switch_thread_rwlock_create(), switch_uuid_format(), switch_uuid_get(), switch_runtime::throttle_mutex, and UNPROTECT_INTERFACE.

01816 {
01817         switch_memory_pool_t *usepool;
01818         switch_core_session_t *session;
01819         switch_uuid_t uuid;
01820         uint32_t count = 0;
01821         int32_t sps = 0;
01822 
01823 
01824         if (use_uuid && switch_core_hash_find(session_manager.session_table, use_uuid)) {
01825                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Duplicate UUID!\n");
01826                 return NULL;
01827         }
01828 
01829         if (direction == SWITCH_CALL_DIRECTION_INBOUND && !switch_core_ready_inbound()) {
01830                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The system cannot create any inbound sessions at this time.\n");
01831                 return NULL;
01832         }
01833 
01834         if (direction == SWITCH_CALL_DIRECTION_OUTBOUND && !switch_core_ready_outbound()) {
01835                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The system cannot create any outbound sessions at this time.\n");
01836                 return NULL;
01837         }
01838 
01839         if (!switch_core_ready() || endpoint_interface == NULL) {
01840                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The system cannot create any sessions at this time.\n");
01841                 return NULL;
01842         }
01843 
01844         if (runtime.min_idle_time > 0 && runtime.profile_time < runtime.min_idle_time) {
01845                 return NULL;
01846         }
01847 
01848         PROTECT_INTERFACE(endpoint_interface);
01849 
01850         if (!(originate_flags & SOF_NO_LIMITS)) {
01851                 switch_mutex_lock(runtime.throttle_mutex);
01852                 count = session_manager.session_count;
01853                 sps = --runtime.sps;
01854                 switch_mutex_unlock(runtime.throttle_mutex);
01855                 
01856                 if (sps <= 0) {
01857                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Throttle Error! %d\n", session_manager.session_count);
01858                         UNPROTECT_INTERFACE(endpoint_interface);
01859                         return NULL;
01860                 }
01861 
01862                 if ((count + 1) > session_manager.session_limit) {
01863                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Over Session Limit! %d\n", session_manager.session_limit);
01864                         UNPROTECT_INTERFACE(endpoint_interface);
01865                         return NULL;
01866                 }
01867         }
01868 
01869 
01870         if (pool && *pool) {
01871                 usepool = *pool;
01872                 *pool = NULL;
01873         } else {
01874                 switch_core_new_memory_pool(&usepool);
01875         }
01876 
01877         session = switch_core_alloc(usepool, sizeof(*session));
01878         session->pool = usepool;
01879 
01880         switch_core_memory_pool_set_data(session->pool, "__session", session);
01881 
01882         if (switch_channel_alloc(&session->channel, direction, session->pool) != SWITCH_STATUS_SUCCESS) {
01883                 abort();
01884         }
01885 
01886         switch_channel_init(session->channel, session, CS_NEW, 0);
01887 
01888         if (direction == SWITCH_CALL_DIRECTION_OUTBOUND) {
01889                 switch_channel_set_flag(session->channel, CF_OUTBOUND);
01890         }
01891 
01892         /* The session *IS* the pool you may not alter it because you have no idea how
01893            its all private it will be passed to the thread run function */
01894 
01895         if (use_uuid) {
01896                 switch_set_string(session->uuid_str, use_uuid);
01897         } else {
01898                 switch_uuid_get(&uuid);
01899                 switch_uuid_format(session->uuid_str, &uuid);
01900         }
01901 
01902         switch_channel_set_variable(session->channel, "uuid", session->uuid_str);
01903         switch_channel_set_variable(session->channel, "call_uuid", session->uuid_str);
01904 
01905         session->endpoint_interface = endpoint_interface;
01906         session->raw_write_frame.data = session->raw_write_buf;
01907         session->raw_write_frame.buflen = sizeof(session->raw_write_buf);
01908         session->raw_read_frame.data = session->raw_read_buf;
01909         session->raw_read_frame.buflen = sizeof(session->raw_read_buf);
01910 
01911 
01912         session->enc_write_frame.data = session->enc_write_buf;
01913         session->enc_write_frame.buflen = sizeof(session->enc_write_buf);
01914         session->enc_read_frame.data = session->enc_read_buf;
01915         session->enc_read_frame.buflen = sizeof(session->enc_read_buf);
01916 
01917         switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool);
01918         switch_mutex_init(&session->resample_mutex, SWITCH_MUTEX_NESTED, session->pool);
01919         switch_mutex_init(&session->codec_read_mutex, SWITCH_MUTEX_NESTED, session->pool);
01920         switch_mutex_init(&session->codec_write_mutex, SWITCH_MUTEX_NESTED, session->pool);
01921         switch_mutex_init(&session->frame_read_mutex, SWITCH_MUTEX_NESTED, session->pool);
01922         switch_thread_rwlock_create(&session->bug_rwlock, session->pool);
01923         switch_thread_cond_create(&session->cond, session->pool);
01924         switch_thread_rwlock_create(&session->rwlock, session->pool);
01925         switch_thread_rwlock_create(&session->io_rwlock, session->pool);
01926         switch_queue_create(&session->message_queue, SWITCH_MESSAGE_QUEUE_LEN, session->pool);
01927         switch_queue_create(&session->signal_data_queue, SWITCH_MESSAGE_QUEUE_LEN, session->pool);
01928         switch_queue_create(&session->event_queue, SWITCH_EVENT_QUEUE_LEN, session->pool);
01929         switch_queue_create(&session->private_event_queue, SWITCH_EVENT_QUEUE_LEN, session->pool);
01930         switch_queue_create(&session->private_event_queue_pri, SWITCH_EVENT_QUEUE_LEN, session->pool);
01931 
01932         switch_mutex_lock(runtime.session_hash_mutex);
01933         switch_core_hash_insert(session_manager.session_table, session->uuid_str, session);
01934         session->id = session_manager.session_id++;
01935         session_manager.session_count++;
01936         switch_mutex_unlock(runtime.session_hash_mutex);
01937 
01938         switch_channel_set_variable_printf(session->channel, "session_id", "%u", session->id);
01939 
01940         return session;
01941 }

void switch_core_session_reset ( switch_core_session_t session,
switch_bool_t  flush_dtmf,
switch_bool_t  reset_read_codec 
)

Definition at line 1146 of file switch_core_session.c.

References CF_BREAK, SSF_WARN_TRANSCODE, switch_buffer_destroy(), switch_channel_clear_flag(), switch_channel_flush_dtmf(), switch_channel_has_dtmf(), switch_clear_flag, switch_core_session_flush_message(), switch_core_session_get_channel(), switch_core_session_set_read_codec(), switch_ivr_deactivate_unicast(), switch_mutex_lock(), switch_mutex_unlock(), and switch_resample_destroy().

01147 {
01148         switch_channel_t *channel = switch_core_session_get_channel(session);
01149         switch_size_t has;
01150 
01151         if (reset_read_codec) {
01152                 switch_core_session_set_read_codec(session, NULL);
01153         }
01154 
01155         /* clear resamplers */
01156         switch_mutex_lock(session->resample_mutex);
01157         switch_resample_destroy(&session->read_resampler);
01158         switch_resample_destroy(&session->write_resampler);
01159         switch_mutex_unlock(session->resample_mutex);
01160         /* clear indications */
01161         switch_core_session_flush_message(session);
01162 
01163         /* wipe these, they will be recreated if need be */
01164         switch_mutex_lock(session->codec_write_mutex);
01165         switch_buffer_destroy(&session->raw_write_buffer);
01166         switch_mutex_unlock(session->codec_write_mutex);
01167 
01168         switch_mutex_lock(session->codec_read_mutex);
01169         switch_buffer_destroy(&session->raw_read_buffer);
01170         switch_mutex_unlock(session->codec_read_mutex);
01171 
01172         if (flush_dtmf) {
01173                 while ((has = switch_channel_has_dtmf(channel))) {
01174                         switch_channel_flush_dtmf(channel);
01175                 }
01176         }
01177 
01178         switch_clear_flag(session, SSF_WARN_TRANSCODE);
01179         switch_ivr_deactivate_unicast(session);
01180         switch_channel_clear_flag(channel, CF_BREAK);
01181 }

switch_call_cause_t switch_core_session_resurrect_channel ( const char *  endpoint_name,
switch_core_session_t **  new_session,
switch_memory_pool_t **  pool,
void *  data 
)

Definition at line 397 of file switch_core_session.c.

References switch_endpoint_interface::io_routines, switch_io_routines::resurrect_session, SWITCH_CAUSE_CHAN_NOT_IMPLEMENTED, SWITCH_CHANNEL_LOG, switch_loadable_module_get_endpoint_interface(), SWITCH_LOG_ERROR, and switch_log_printf().

00399 {
00400         const switch_endpoint_interface_t *endpoint_interface;
00401 
00402         if ((endpoint_interface = switch_loadable_module_get_endpoint_interface(endpoint_name)) == 0) {
00403                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not locate channel type %s\n", endpoint_name);
00404                 return SWITCH_CAUSE_CHAN_NOT_IMPLEMENTED;
00405         }
00406 
00407         return endpoint_interface->io_routines->resurrect_session(new_session, pool, data);
00408 }

unsigned int switch_core_session_running ( switch_core_session_t session  ) 

Definition at line 1227 of file switch_core_session.c.

References SSF_THREAD_RUNNING, and switch_test_flag.

01228 {
01229         return switch_test_flag(session, SSF_THREAD_RUNNING) ? 1 : 0;
01230 }

switch_status_t switch_core_session_set_private ( switch_core_session_t session,
void *  private_info 
)

Definition at line 373 of file switch_core_session.c.

References switch_assert, and SWITCH_STATUS_SUCCESS.

00374 {
00375         switch_assert(session != NULL);
00376         session->private_info = private_info;
00377         return SWITCH_STATUS_SUCCESS;
00378 }

switch_status_t switch_core_session_set_uuid ( switch_core_session_t session,
const char *  use_uuid 
)

Definition at line 1500 of file switch_core_session.c.

References switch_core_session_message::from, switch_core_session_message::message_id, switch_caller_profile::pool, runtime, switch_runtime::session_hash_mutex, session_manager, switch_session_manager::session_table, switch_core_session_message::string_array_arg, switch_assert, switch_channel_event_set_data(), switch_channel_get_caller_profile(), switch_channel_get_name(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_core_hash_delete(), switch_core_hash_find(), switch_core_hash_insert(), switch_core_session_receive_message, switch_core_strdup, switch_event_add_header_string(), SWITCH_EVENT_CHANNEL_UUID, switch_event_create, switch_event_fire, SWITCH_LOG_CRIT, switch_log_printf(), SWITCH_MESSAGE_INDICATE_UUID_CHANGE, switch_mutex_lock(), switch_mutex_unlock(), switch_set_string, SWITCH_STACK_BOTTOM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_caller_profile::uuid.

01501 {
01502         switch_event_t *event;
01503         switch_core_session_message_t msg = { 0 };
01504         switch_caller_profile_t *profile;
01505 
01506         switch_assert(use_uuid);
01507 
01508         switch_mutex_lock(runtime.session_hash_mutex);
01509         if (switch_core_hash_find(session_manager.session_table, use_uuid)) {
01510                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Duplicate UUID!\n");
01511                 switch_mutex_unlock(runtime.session_hash_mutex);
01512                 return SWITCH_STATUS_FALSE;
01513         }
01514 
01515         msg.message_id = SWITCH_MESSAGE_INDICATE_UUID_CHANGE;
01516         msg.from = switch_channel_get_name(session->channel);
01517         msg.string_array_arg[0] = session->uuid_str;
01518         msg.string_array_arg[1] = use_uuid;
01519         switch_core_session_receive_message(session, &msg);
01520 
01521         if ((profile = switch_channel_get_caller_profile(session->channel))) {
01522                 profile->uuid = switch_core_strdup(profile->pool, use_uuid);
01523         }
01524 
01525         switch_channel_set_variable(session->channel, "uuid", use_uuid);
01526         switch_channel_set_variable(session->channel, "call_uuid", use_uuid);
01527 
01528         switch_event_create(&event, SWITCH_EVENT_CHANNEL_UUID);
01529         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Old-Unique-ID", session->uuid_str);
01530         switch_core_hash_delete(session_manager.session_table, session->uuid_str);
01531         switch_set_string(session->uuid_str, use_uuid);
01532         switch_core_hash_insert(session_manager.session_table, session->uuid_str, session);
01533         switch_mutex_unlock(runtime.session_hash_mutex);
01534         switch_channel_event_set_data(session->channel, event);
01535         switch_event_fire(&event);
01536 
01537 
01538         return SWITCH_STATUS_SUCCESS;
01539 }

void switch_core_session_signal_state_change ( switch_core_session_t session  ) 

Definition at line 1206 of file switch_core_session.c.

References switch_io_event_hook_state_change::next, switch_io_event_hook_state_change::state_change, switch_core_session_kill_channel, switch_core_session_wake_session_thread(), SWITCH_SIG_BREAK, and SWITCH_STATUS_SUCCESS.

01207 {
01208         switch_status_t status = SWITCH_STATUS_SUCCESS;
01209         switch_io_event_hook_state_change_t *ptr;
01210 
01211         switch_core_session_wake_session_thread(session);
01212 
01213         if (session->endpoint_interface->io_routines->state_change) {
01214                 status = session->endpoint_interface->io_routines->state_change(session);
01215         }
01216 
01217         if (status == SWITCH_STATUS_SUCCESS) {
01218                 for (ptr = session->event_hooks.state_change; ptr; ptr = ptr->next) {
01219                         if ((status = ptr->state_change(session)) != SWITCH_STATUS_SUCCESS) {
01220                                 break;
01221                         }
01222                 }
01223         }
01224         switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
01225 }

unsigned int switch_core_session_started ( switch_core_session_t session  ) 

Definition at line 1232 of file switch_core_session.c.

References SSF_THREAD_STARTED, and switch_test_flag.

01233 {
01234         return switch_test_flag(session, SSF_THREAD_STARTED) ? 1 : 0;
01235 }

static void* SWITCH_THREAD_FUNC switch_core_session_thread ( switch_thread_t thread,
void *  obj 
) [static]

Definition at line 1397 of file switch_core_session.c.

References switch_core_session::channel, switch_core_session::id, switch_core_session::soft_lock, SSF_DESTROYED, switch_assert, switch_channel_event_set_data(), switch_channel_get_name(), switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_core_media_bug_remove_all, switch_core_memory_pool_tag(), switch_core_session_destroy, switch_core_session_get_pool(), switch_core_session_run(), switch_core_session_rwunlock(), switch_core_session_strdup, switch_core_session_write_lock(), switch_event_create, switch_event_destroy(), SWITCH_EVENT_GENERAL, switch_event_serialize(), SWITCH_FALSE, SWITCH_LOG_DEBUG, SWITCH_LOG_NOTICE, switch_log_printf(), switch_set_flag, SWITCH_SIZE_T_FMT, SWITCH_STATUS_SUCCESS, switch_thread_self(), switch_true(), switch_yield, switch_core_session::thread, and switch_core_session::thread_id.

Referenced by switch_core_session_thread_launch().

01398 {
01399         switch_core_session_t *session = obj;
01400         switch_event_t *event;
01401         char *event_str = NULL;
01402         const char *val;
01403 
01404         session->thread = thread;
01405         session->thread_id = switch_thread_self();
01406 
01407         switch_core_session_run(session);
01408         switch_core_media_bug_remove_all(session);
01409 
01410         if (session->soft_lock) {
01411                 uint32_t loops = session->soft_lock * 10;
01412 
01413                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Session %" SWITCH_SIZE_T_FMT " (%s) Soft-Locked, "
01414                                                   "Waiting %u for external entities\n",
01415                                                   session->id, switch_channel_get_name(session->channel), session->soft_lock);
01416 
01417                 while(--loops > 0) {
01418                         if (!session->soft_lock) break;
01419                         switch_yield(100000);
01420                 }
01421 
01422         }
01423 
01424         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Session %" SWITCH_SIZE_T_FMT " (%s) Locked, Waiting on external entities\n",
01425                                           session->id, switch_channel_get_name(session->channel));
01426         switch_core_session_write_lock(session);
01427         switch_set_flag(session, SSF_DESTROYED);
01428 
01429         if ((val = switch_channel_get_variable(session->channel, "memory_debug")) && switch_true(val)) {
01430                 if (switch_event_create(&event, SWITCH_EVENT_GENERAL) == SWITCH_STATUS_SUCCESS) {
01431                         switch_channel_event_set_data(session->channel, event);
01432                         switch_event_serialize(event, &event_str, SWITCH_FALSE);
01433                         switch_assert(event_str);
01434                         switch_core_memory_pool_tag(switch_core_session_get_pool(session), switch_core_session_strdup(session, event_str));
01435                         free(event_str);
01436                         switch_event_destroy(&event);
01437                 }
01438         }
01439 
01440         switch_core_session_rwunlock(session);
01441 
01442         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Session %" SWITCH_SIZE_T_FMT " (%s) Ended\n",
01443                                           session->id, switch_channel_get_name(session->channel));
01444         switch_core_session_destroy(&session);
01445         return NULL;
01446 }

switch_status_t switch_core_session_thread_launch ( switch_core_session_t session  ) 

Definition at line 1448 of file switch_core_session.c.

References apr_threadattr_t::pool, SSF_THREAD_RUNNING, SSF_THREAD_STARTED, SWITCH_CHANNEL_SESSION_LOG, switch_clear_flag, switch_core_session_thread(), SWITCH_LOG_CRIT, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_set_flag, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_test_flag, switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_detach_set(), switch_threadattr_stacksize_set(), and thread.

01449 {
01450         switch_status_t status = SWITCH_STATUS_FALSE;
01451         switch_thread_t *thread;
01452         switch_threadattr_t *thd_attr;;
01453 
01454         switch_threadattr_create(&thd_attr, session->pool);
01455         switch_threadattr_detach_set(thd_attr, 1);
01456 
01457         if (switch_test_flag(session, SSF_THREAD_RUNNING) || switch_test_flag(session, SSF_THREAD_STARTED)) {
01458                 goto end;
01459         }
01460 
01461         switch_mutex_lock(session->mutex);
01462 
01463         if (switch_test_flag(session, SSF_THREAD_RUNNING)) {
01464                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Cannot double-launch thread!\n");
01465         } else if (switch_test_flag(session, SSF_THREAD_STARTED)) {
01466                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Cannot launch thread again after it has already been run!\n");
01467         } else {
01468                 switch_set_flag(session, SSF_THREAD_RUNNING);
01469                 switch_set_flag(session, SSF_THREAD_STARTED);
01470                 switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
01471                 if (switch_thread_create(&thread, thd_attr, switch_core_session_thread, session, session->pool) == SWITCH_STATUS_SUCCESS) {
01472                         switch_set_flag(session, SSF_THREAD_STARTED);
01473                         status = SWITCH_STATUS_SUCCESS;
01474                 } else {
01475                         switch_clear_flag(session, SSF_THREAD_RUNNING);
01476                         switch_clear_flag(session, SSF_THREAD_STARTED); 
01477                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Cannot create thread!\n");
01478                 }
01479         }
01480 
01481         switch_mutex_unlock(session->mutex);
01482 
01483  end:
01484 
01485         return status;
01486 }

void switch_core_session_uninit ( void   ) 

Definition at line 2045 of file switch_core_session.c.

References session_manager, switch_session_manager::session_table, and switch_core_hash_destroy().

switch_status_t switch_core_session_wake_session_thread ( switch_core_session_t session  ) 

Definition at line 1190 of file switch_core_session.c.

References switch_mutex_trylock(), switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, and switch_thread_cond_signal().

01191 {
01192         switch_status_t status;
01193 
01194         /* If trylock fails the signal is already awake so we needn't bother */
01195 
01196         status = switch_mutex_trylock(session->mutex);
01197 
01198         if (status == SWITCH_STATUS_SUCCESS) {
01199                 switch_thread_cond_signal(session->cond);
01200                 switch_mutex_unlock(session->mutex);
01201         }
01202 
01203         return status;
01204 }

uint32_t switch_core_sessions_per_second ( uint32_t  new_limit  ) 

Definition at line 2027 of file switch_core_session.c.

References runtime, and switch_runtime::sps_total.

02028 {
02029         if (new_limit) {
02030                 runtime.sps_total = new_limit;
02031         }
02032 
02033         return runtime.sps_total;
02034 }

SWITCH_STANDARD_SCHED_FUNC ( sch_heartbeat_callback   ) 

Definition at line 1323 of file switch_core_session.c.

References switch_core_session::channel, switch_channel_event_set_data(), switch_core_session_locate(), switch_core_session_rwunlock(), switch_epoch_time_now(), switch_event_create, switch_event_fire, SWITCH_EVENT_SESSION_HEARTBEAT, and switch_core_session::track_duration.

01324 {
01325         switch_event_t *event;
01326         switch_core_session_t *session;
01327         char *uuid = task->cmd_arg;
01328 
01329         if ((session = switch_core_session_locate(uuid))) {
01330                 switch_event_create(&event, SWITCH_EVENT_SESSION_HEARTBEAT);
01331                 switch_channel_event_set_data(session->channel, event);
01332                 switch_event_fire(&event);
01333 
01334                 /* reschedule this task */
01335                 task->runtime = switch_epoch_time_now(NULL) + session->track_duration;
01336 
01337                 switch_core_session_rwunlock(session);
01338         }
01339 }

static char* xml_find_var ( switch_xml_t  vars,
const char *  name 
) [static]

Definition at line 1541 of file switch_core_session.c.

References switch_xml_child(), and switch_xml::txt.

Referenced by switch_core_session_request_xml().

01542 {
01543         switch_xml_t var;
01544         if ((var = switch_xml_child(vars, name)) && var->txt) {
01545                 return var->txt;
01546         }
01547 
01548         return NULL;
01549 }


Variable Documentation

const char* message_names[] [static]

Definition at line 605 of file switch_core_session.c.

struct switch_session_manager session_manager

Definition at line 40 of file switch_core_session.c.

Referenced by switch_core_session_count(), switch_core_session_event_send(), switch_core_session_force_locate(), switch_core_session_hupall(), switch_core_session_hupall_endpoint(), switch_core_session_hupall_matching_var(), switch_core_session_id(), switch_core_session_init(), switch_core_session_limit(), switch_core_session_locate(), switch_core_session_message_send(), switch_core_session_perform_destroy(), switch_core_session_request_uuid(), switch_core_session_set_uuid(), switch_core_session_sync_clock(), and switch_core_session_uninit().


Generated on Sun May 20 04:00:09 2012 for FreeSWITCH API Documentation by  doxygen 1.4.7