Channel Functions
[Core Library]

Collaboration diagram for Channel Functions:

Defines

#define switch_channel_ready(_channel)   switch_channel_test_ready(_channel, SWITCH_TRUE, SWITCH_FALSE)
#define switch_channel_media_ready(_channel)   switch_channel_test_ready(_channel, SWITCH_TRUE, SWITCH_TRUE)
#define switch_channel_media_up(_channel)   (switch_channel_test_flag(_channel, CF_ANSWERED) || switch_channel_test_flag(_channel, CF_EARLY_MEDIA))
#define switch_channel_up(_channel)   (switch_channel_check_signal(_channel, SWITCH_TRUE) || switch_channel_get_state(_channel) < CS_HANGUP)
#define switch_channel_down(_channel)   (switch_channel_check_signal(_channel, SWITCH_TRUE) || switch_channel_get_state(_channel) >= CS_HANGUP)
#define switch_channel_up_nosig(_channel)   (switch_channel_get_state(_channel) < CS_HANGUP)
#define switch_channel_down_nosig(_channel)   (switch_channel_get_state(_channel) >= CS_HANGUP)
#define switch_channel_media_ack(_channel)   (!switch_channel_test_cap(_channel, CC_MEDIA_ACK) || switch_channel_test_flag(_channel, CF_MEDIA_ACK))
#define switch_channel_set_running_state(channel, state)   switch_channel_perform_set_running_state(channel, state, __FILE__, __SWITCH_FUNC__, __LINE__)
#define switch_channel_set_state(channel, state)   switch_channel_perform_set_state(channel, __FILE__, __SWITCH_FUNC__, __LINE__, state)
 Set the current state of a channel.
#define switch_channel_presence(_a, _b, _c, _d)   switch_channel_perform_presence(_a, _b, _c, _d, __FILE__, __SWITCH_FUNC__, __LINE__)
#define switch_channel_set_variable_safe(_channel, _var, _val)   switch_channel_set_variable_var_check(_channel, _var, _val, SWITCH_FALSE)
#define switch_channel_set_variable(_channel, _var, _val)   switch_channel_set_variable_var_check(_channel, _var, _val, SWITCH_TRUE)
#define switch_channel_set_variable_partner(_channel, _var, _val)   switch_channel_set_variable_partner_var_check(_channel, _var, _val, SWITCH_TRUE)
#define switch_channel_export_variable(_channel, _varname, _value, _ev)   switch_channel_export_variable_var_check(_channel, _varname, _value, _ev, SWITCH_TRUE)
#define switch_channel_get_variable(_c, _v)   switch_channel_get_variable_dup(_c, _v, SWITCH_TRUE, -1)
#define switch_channel_set_flag(_c, _f)   switch_channel_set_flag_value(_c, _f, 1)
#define switch_channel_set_cap(_c, _cc)   switch_channel_set_cap_value(_c, _cc, 1)
#define switch_channel_answer(channel)   switch_channel_perform_answer(channel, __FILE__, __SWITCH_FUNC__, __LINE__)
 Answer a channel (initiate/acknowledge a successful connection).
#define switch_channel_mark_answered(channel)   switch_channel_perform_mark_answered(channel, __FILE__, __SWITCH_FUNC__, __LINE__)
 Mark a channel answered with no indication (for outbound calls).
#define switch_channel_mark_pre_answered(channel)   switch_channel_perform_mark_pre_answered(channel, __FILE__, __SWITCH_FUNC__, __LINE__)
 Mark a channel pre_answered (early media) with no indication (for outbound calls).
#define switch_channel_ring_ready(channel)   switch_channel_perform_ring_ready_value(channel, SWITCH_RING_READY_RINGING, __FILE__, __SWITCH_FUNC__, __LINE__)
 Send Ringing message to a channel.
#define switch_channel_ring_ready_value(channel, _rv)   switch_channel_perform_ring_ready_value(channel, _rv, __FILE__, __SWITCH_FUNC__, __LINE__)
#define switch_channel_pre_answer(channel)   switch_channel_perform_pre_answer(channel, __FILE__, __SWITCH_FUNC__, __LINE__)
 Indicate progress on a channel to attempt early media.
#define switch_channel_mark_ring_ready(channel)   switch_channel_perform_mark_ring_ready_value(channel, SWITCH_RING_READY_RINGING, __FILE__, __SWITCH_FUNC__, __LINE__)
 Indicate a channel is ready to provide ringback.
#define switch_channel_mark_ring_ready_value(channel, _rv)   switch_channel_perform_mark_ring_ready_value(channel, _rv, __FILE__, __SWITCH_FUNC__, __LINE__)
#define switch_channel_hangup(channel, hangup_cause)   switch_channel_perform_hangup(channel, __FILE__, __SWITCH_FUNC__, __LINE__, hangup_cause)
 Hangup a channel flagging it's state machine to end.
#define switch_channel_expand_variables(_channel, _in)   switch_channel_expand_variables_check(_channel, _in, NULL, NULL, 0)
#define switch_channel_stop_broadcast(_channel)   for(;;) {if (switch_channel_test_flag(_channel, CF_BROADCAST)) {switch_channel_set_flag(_channel, CF_STOP_BROADCAST); switch_channel_set_flag(_channel, CF_BREAK); } break;}
#define switch_channel_audio_sync(_c)   switch_channel_perform_audio_sync(_c, __FILE__, __SWITCH_FUNC__, __LINE__)
#define switch_channel_set_app_flag(_c, _f)   switch_channel_set_app_flag_key(__FILE__, _c, _f)
#define switch_channel_clear_app_flag(_c, _f)   switch_channel_clear_app_flag_key(__FILE__, _c, _f)
#define switch_channel_test_app_flag(_c, _f)   switch_channel_test_app_flag_key(__FILE__, _c, _f)
#define switch_channel_set_callstate(channel, state)   switch_channel_perform_set_callstate(channel, state, __FILE__, __SWITCH_FUNC__, __LINE__)

Functions

switch_channel_state_t switch_channel_get_state (switch_channel_t *channel)
 Get the current state of a channel in the state engine.
switch_channel_state_t switch_channel_get_running_state (switch_channel_t *channel)
int switch_channel_check_signal (switch_channel_t *channel, switch_bool_t in_thread_only)
int switch_channel_test_ready (switch_channel_t *channel, switch_bool_t check_ready, switch_bool_t check_media)
 Determine if a channel is ready for io.
void switch_channel_wait_for_state (switch_channel_t *channel, switch_channel_t *other_channel, switch_channel_state_t want_state)
void switch_channel_wait_for_state_timeout (switch_channel_t *other_channel, switch_channel_state_t want_state, uint32_t timeout)
switch_status_t switch_channel_wait_for_flag (switch_channel_t *channel, switch_channel_flag_t want_flag, switch_bool_t pres, uint32_t to, switch_channel_t *super_channel)
switch_channel_state_t switch_channel_perform_set_state (switch_channel_t *channel, const char *file, const char *func, int line, switch_channel_state_t state)
switch_channel_state_t switch_channel_perform_set_running_state (switch_channel_t *channel, switch_channel_state_t state, const char *file, const char *func, int line)
switch_call_cause_t switch_channel_str2cause (_In_ const char *str)
 return a cause code for a given string
switch_call_cause_t switch_channel_get_cause (_In_ switch_channel_t *channel)
 return the cause code for a given channel
switch_call_cause_t switch_channel_cause_q850 (switch_call_cause_t cause)
switch_call_cause_t switch_channel_get_cause_q850 (switch_channel_t *channel)
switch_call_cause_tswitch_channel_get_cause_ptr (switch_channel_t *channel)
const char * switch_channel_cause2str (_In_ switch_call_cause_t cause)
 return a cause string for a given cause
switch_channel_timetable_tswitch_channel_get_timetable (_In_ switch_channel_t *channel)
 View the timetable of a channel.
switch_status_t switch_channel_alloc (_In_ switch_channel_t **channel, _In_ switch_call_direction_t direction, _In_ switch_memory_pool_t *pool)
 Allocate a new channel.
switch_status_t switch_channel_init (switch_channel_t *channel, switch_core_session_t *session, switch_channel_state_t state, switch_channel_flag_t flag)
 Connect a newly allocated channel to a session object and setup it's initial state.
void switch_channel_perform_presence (switch_channel_t *channel, const char *rpid, const char *status, const char *id, const char *file, const char *func, int line)
 Fire A presence event for the channel.
void switch_channel_uninit (switch_channel_t *channel)
 Uninitalize a channel.
void switch_channel_set_caller_profile (switch_channel_t *channel, switch_caller_profile_t *caller_profile)
 Set the given channel's caller profile.
switch_caller_profile_tswitch_channel_get_caller_profile (switch_channel_t *channel)
 Retrieve the given channel's caller profile.
void switch_channel_set_originator_caller_profile (switch_channel_t *channel, switch_caller_profile_t *caller_profile)
 Set the given channel's originator caller profile.
void switch_channel_set_hunt_caller_profile (switch_channel_t *channel, switch_caller_profile_t *caller_profile)
switch_caller_profile_tswitch_channel_get_originator_caller_profile (switch_channel_t *channel)
 Retrieve the given channel's originator caller profile.
void switch_channel_set_originatee_caller_profile (switch_channel_t *channel, switch_caller_profile_t *caller_profile)
 Set the given channel's originatee caller profile.
switch_caller_profile_tswitch_channel_get_originatee_caller_profile (switch_channel_t *channel)
 Retrieve the given channel's originatee caller profile.
void switch_channel_set_origination_caller_profile (switch_channel_t *channel, switch_caller_profile_t *caller_profile)
 Set the given channel's origination caller profile.
switch_caller_profile_tswitch_channel_get_origination_caller_profile (switch_channel_t *channel)
 Retrieve the given channel's origination caller profile.
char * switch_channel_get_uuid (switch_channel_t *channel)
 Retrieve the given channel's unique id.
switch_status_t switch_channel_set_profile_var (switch_channel_t *channel, const char *name, const char *val)
 Set a variable on a given channel.
switch_status_t switch_channel_set_variable_var_check (switch_channel_t *channel, const char *varname, const char *value, switch_bool_t var_check)
switch_status_t switch_channel_add_variable_var_check (switch_channel_t *channel, const char *varname, const char *value, switch_bool_t var_check, switch_stack_t stack)
switch_status_t switch_channel_set_variable_printf (switch_channel_t *channel, const char *varname, const char *fmt,...)
switch_status_t switch_channel_set_variable_name_printf (switch_channel_t *channel, const char *val, const char *fmt,...)
switch_status_t switch_channel_set_variable_partner_var_check (switch_channel_t *channel, const char *varname, const char *value, switch_bool_t var_check)
const char * switch_channel_get_variable_partner (switch_channel_t *channel, const char *varname)
const char * switch_channel_get_hold_music (switch_channel_t *channel)
const char * switch_channel_get_hold_music_partner (switch_channel_t *channel)
uint32_t switch_channel_del_variable_prefix (switch_channel_t *channel, const char *prefix)
switch_status_t switch_channel_export_variable_var_check (switch_channel_t *channel, const char *varname, const char *val, const char *export_varname, switch_bool_t var_check)
void switch_channel_process_export (switch_channel_t *channel, switch_channel_t *peer_channel, switch_event_t *var_event, const char *export_varname)
switch_status_t switch_channel_export_variable_printf (switch_channel_t *channel, const char *varname, const char *export_varname, const char *fmt,...)
void switch_channel_set_scope_variables (switch_channel_t *channel, switch_event_t **event)
switch_status_t switch_channel_get_scope_variables (switch_channel_t *channel, switch_event_t **event)
const char * switch_channel_get_variable_dup (switch_channel_t *channel, const char *varname, switch_bool_t dup, int idx)
 Retrieve a variable from a given channel.
switch_status_t switch_channel_get_variables (switch_channel_t *channel, switch_event_t **event)
switch_status_t switch_channel_pass_callee_id (switch_channel_t *channel, switch_channel_t *other_channel)
switch_event_header_tswitch_channel_variable_first (switch_channel_t *channel)
 Start iterating over the entries in the channel variable list.
void switch_channel_variable_last (switch_channel_t *channel)
 Stop iterating over channel variables.
Remarks:
Unlocks the profile mutex initially locked in switch_channel_variable_first.

void switch_channel_restart (switch_channel_t *channel)
switch_status_t switch_channel_caller_extension_masquerade (switch_channel_t *orig_channel, switch_channel_t *new_channel, uint32_t offset)
void switch_channel_set_caller_extension (switch_channel_t *channel, switch_caller_extension_t *caller_extension)
 Assign a caller extension to a given channel.
void switch_channel_flip_cid (switch_channel_t *channel)
void switch_channel_sort_cid (switch_channel_t *channel, switch_bool_t in)
switch_caller_extension_tswitch_channel_get_caller_extension (switch_channel_t *channel)
 Retrieve caller extension from a given channel.
uint32_t switch_channel_test_flag (switch_channel_t *channel, switch_channel_flag_t flag)
 Test for presence of given flag on a given channel.
void switch_channel_set_flag_value (switch_channel_t *channel, switch_channel_flag_t flag, uint32_t value)
 Set given flag(s) on a given channel.
void switch_channel_set_flag_recursive (switch_channel_t *channel, switch_channel_flag_t flag)
void switch_channel_set_cap_value (switch_channel_t *channel, switch_channel_cap_t cap, uint32_t value)
void switch_channel_clear_cap (switch_channel_t *channel, switch_channel_cap_t cap)
uint32_t switch_channel_test_cap (switch_channel_t *channel, switch_channel_cap_t cap)
uint32_t switch_channel_test_cap_partner (switch_channel_t *channel, switch_channel_cap_t cap)
switch_bool_t switch_channel_set_flag_partner (switch_channel_t *channel, switch_channel_flag_t flag)
 Set given flag(s) on a given channel's bridge partner.
switch_bool_t switch_channel_clear_flag_partner (switch_channel_t *channel, switch_channel_flag_t flag)
 Clears given flag(s) on a given channel's bridge partner.
uint32_t switch_channel_test_flag_partner (switch_channel_t *channel, switch_channel_flag_t flag)
void switch_channel_set_state_flag (switch_channel_t *channel, switch_channel_flag_t flag)
 Set given flag(s) on a given channel to be applied on the next state change.
void switch_channel_clear_state_flag (switch_channel_t *channel, switch_channel_flag_t flag)
void switch_channel_clear_flag (switch_channel_t *channel, switch_channel_flag_t flag)
 Clear given flag(s) from a channel.
void switch_channel_clear_flag_recursive (switch_channel_t *channel, switch_channel_flag_t flag)
switch_status_t switch_channel_perform_answer (switch_channel_t *channel, const char *file, const char *func, int line)
switch_status_t switch_channel_perform_mark_answered (switch_channel_t *channel, const char *file, const char *func, int line)
void switch_channel_check_zrtp (switch_channel_t *channel)
switch_status_t switch_channel_perform_ring_ready_value (switch_channel_t *channel, switch_ring_ready_t rv, const char *file, const char *func, int line)
switch_status_t switch_channel_perform_pre_answer (switch_channel_t *channel, const char *file, const char *func, int line)
switch_status_t switch_channel_perform_mark_pre_answered (switch_channel_t *channel, const char *file, const char *func, int line)
switch_status_t switch_channel_perform_mark_ring_ready_value (switch_channel_t *channel, switch_ring_ready_t rv, const char *file, const char *func, int line)
int switch_channel_add_state_handler (switch_channel_t *channel, const switch_state_handler_table_t *state_handler)
 add a state handler table to a given channel
void switch_channel_clear_state_handler (switch_channel_t *channel, const switch_state_handler_table_t *state_handler)
 clear a state handler table from a given channel
const switch_state_handler_table_tswitch_channel_get_state_handler (switch_channel_t *channel, int index)
 Retrieve an state handler tablefrom a given channel at given index level.
switch_status_t switch_channel_set_private (switch_channel_t *channel, const char *key, const void *private_info)
 Set private data on channel.
void * switch_channel_get_private (switch_channel_t *channel, const char *key)
 Retrieve private from a given channel.
void * switch_channel_get_private_partner (switch_channel_t *channel, const char *key)
switch_status_t switch_channel_set_name (switch_channel_t *channel, const char *name)
 Assign a name to a given channel.
char * switch_channel_get_name (switch_channel_t *channel)
 Retrieve the name of a given channel.
switch_channel_state_t switch_channel_perform_hangup (switch_channel_t *channel, const char *file, const char *func, int line, switch_call_cause_t hangup_cause)
switch_size_t switch_channel_has_dtmf (_In_ switch_channel_t *channel)
 Test for presence of DTMF on a given channel.
switch_status_t switch_channel_queue_dtmf (_In_ switch_channel_t *channel, _In_ const switch_dtmf_t *dtmf)
 Queue DTMF on a given channel.
switch_status_t switch_channel_queue_dtmf_string (_In_ switch_channel_t *channel, _In_ const char *dtmf_string)
switch_status_t switch_channel_dequeue_dtmf (_In_ switch_channel_t *channel, _In_ switch_dtmf_t *dtmf)
 Retrieve DTMF digits from a given channel.
void switch_channel_flush_dtmf (_In_ switch_channel_t *channel)
switch_size_t switch_channel_dequeue_dtmf_string (_In_ switch_channel_t *channel, _Out_opt_bytecapcount_(len) char *dtmf_str, _In_ switch_size_t len)
const char * switch_channel_state_name (_In_ switch_channel_state_t state)
 Render the name of the provided state enum.
switch_channel_state_t switch_channel_name_state (_In_ const char *name)
 Render the enum of the provided state name.
void switch_channel_event_set_data (_In_ switch_channel_t *channel, _In_ switch_event_t *event)
 Add information about a given channel to an event object.
void switch_channel_event_set_basic_data (_In_ switch_channel_t *channel, _In_ switch_event_t *event)
void switch_channel_event_set_extended_data (_In_ switch_channel_t *channel, _In_ switch_event_t *event)
char * switch_channel_expand_variables_check (switch_channel_t *channel, const char *in, switch_event_t *var_list, switch_event_t *api_list, uint32_t recur)
 Expand varaibles in a string based on the variables in a paticular channel.
char * switch_channel_build_param_string (_In_ switch_channel_t *channel, _In_opt_ switch_caller_profile_t *caller_profile, _In_opt_ const char *prefix)
switch_status_t switch_channel_set_timestamps (_In_ switch_channel_t *channel)
void switch_channel_perform_audio_sync (switch_channel_t *channel, const char *file, const char *func, int line)
void switch_channel_set_private_flag (switch_channel_t *channel, uint32_t flags)
void switch_channel_clear_private_flag (switch_channel_t *channel, uint32_t flags)
int switch_channel_test_private_flag (switch_channel_t *channel, uint32_t flags)
void switch_channel_set_app_flag_key (const char *app, switch_channel_t *channel, uint32_t flags)
void switch_channel_clear_app_flag_key (const char *app, switch_channel_t *channel, uint32_t flags)
int switch_channel_test_app_flag_key (const char *app, switch_channel_t *channel, uint32_t flags)
void switch_channel_set_bridge_time (switch_channel_t *channel)
void switch_channel_set_hangup_time (switch_channel_t *channel)
switch_call_direction_t switch_channel_direction (switch_channel_t *channel)
switch_core_session_tswitch_channel_get_session (switch_channel_t *channel)
char * switch_channel_get_flag_string (switch_channel_t *channel)
char * switch_channel_get_cap_string (switch_channel_t *channel)
int switch_channel_state_change_pending (switch_channel_t *channel)
void switch_channel_perform_set_callstate (switch_channel_t *channel, switch_channel_callstate_t callstate, const char *file, const char *func, int line)
switch_channel_callstate_t switch_channel_get_callstate (switch_channel_t *channel)
const char * switch_channel_callstate2str (switch_channel_callstate_t callstate)
switch_call_cause_t switch_channel_str2callstate (const char *str)
void switch_channel_mark_hold (switch_channel_t *channel, switch_bool_t on)


Detailed Description

The switch_channel object is a private entity that belongs to a session that contains the call specific information such as the call state, variables, caller profiles and DTMF queue

Define Documentation

#define switch_channel_answer ( channel   )     switch_channel_perform_answer(channel, __FILE__, __SWITCH_FUNC__, __LINE__)

Answer a channel (initiate/acknowledge a successful connection).

Parameters:
channel channel to answer
Returns:
SWITCH_STATUS_SUCCESS if channel was answered successfully

Definition at line 414 of file switch_channel.h.

Referenced by CoreSession::answer(), audio_bridge_thread(), check_channel_status(), fs_channel_answer(), switch_ivr_intercept_session(), switch_ivr_multi_threaded_bridge(), switch_ivr_originate(), switch_ivr_process_indications(), and switch_ivr_record_file().

#define switch_channel_audio_sync ( _c   )     switch_channel_perform_audio_sync(_c, __FILE__, __SWITCH_FUNC__, __LINE__)

Definition at line 607 of file switch_channel.h.

Referenced by check_channel_status(), switch_channel_perform_mark_answered(), switch_ivr_multi_threaded_bridge(), switch_ivr_sleep(), and switch_ivr_speak_text_handle().

#define switch_channel_clear_app_flag ( _c,
_f   )     switch_channel_clear_app_flag_key(__FILE__, _c, _f)

Definition at line 618 of file switch_channel.h.

#define switch_channel_down ( _channel   )     (switch_channel_check_signal(_channel, SWITCH_TRUE) || switch_channel_get_state(_channel) >= CS_HANGUP)

Definition at line 89 of file switch_channel.h.

Referenced by CoreSession::hangupState(), switch_channel_wait_for_flag(), switch_channel_wait_for_state(), switch_core_session_read_video_frame(), switch_core_session_recv_dtmf(), switch_core_session_send_dtmf(), switch_core_session_send_dtmf_string(), switch_core_session_write_frame(), switch_core_session_write_video_frame(), and uuid_bridge_on_soft_execute().

#define switch_channel_down_nosig ( _channel   )     (switch_channel_get_state(_channel) >= CS_HANGUP)

Definition at line 92 of file switch_channel.h.

Referenced by audio_bridge_thread(), check_channel_status(), speech_thread(), switch_channel_event_set_basic_data(), switch_channel_state_change_pending(), switch_channel_wait_for_state(), switch_core_session_execute_application_get_flags(), switch_core_session_perform_receive_message(), switch_core_session_read_lock(), switch_ivr_multi_threaded_bridge(), switch_ivr_signal_bridge(), switch_ivr_uuid_bridge(), and uuid_bridge_on_soft_execute().

#define switch_channel_expand_variables ( _channel,
_in   )     switch_channel_expand_variables_check(_channel, _in, NULL, NULL, 0)

Definition at line 597 of file switch_channel.h.

Referenced by play_and_collect(), record_callback(), switch_core_session_exec(), switch_core_standard_on_routing(), switch_ivr_phrase_macro_event(), and switch_ivr_record_file().

#define switch_channel_export_variable ( _channel,
_varname,
_value,
_ev   )     switch_channel_export_variable_var_check(_channel, _varname, _value, _ev, SWITCH_TRUE)

Definition at line 289 of file switch_channel.h.

Referenced by switch_channel_export_variable_printf().

#define switch_channel_get_variable ( _c,
_v   )     switch_channel_get_variable_dup(_c, _v, SWITCH_TRUE, -1)

Definition at line 303 of file switch_channel.h.

Referenced by audio_bridge_on_exchange_media(), audio_bridge_thread(), check_channel_status(), fs_channel_get_variable(), fs_switch_channel_get_variable(), fs_switch_ivr_originate(), CoreSession::getVariable(), hanguphook(), inherit_codec(), limit_state_handler(), monitor_callback(), play_and_collect(), record_callback(), rtp_common_read(), sb_on_dtmf(), signal_bridge_on_hangup(), signal_bridge_on_hibernate(), speech_thread(), CoreSession::streamFile(), switch_channel_caller_extension_masquerade(), switch_channel_clear_flag_partner(), switch_channel_event_set_basic_data(), switch_channel_export_variable_var_check(), switch_channel_flip_cid(), switch_channel_get_hold_music(), switch_channel_get_private_partner(), switch_channel_get_variable_partner(), switch_channel_mark_hold(), switch_channel_perform_hangup(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_perform_presence(), switch_channel_process_export(), switch_channel_set_flag_partner(), switch_channel_set_presence_data_vals(), switch_channel_set_variable_partner_var_check(), switch_channel_test_cap_partner(), switch_channel_test_flag_partner(), switch_core_media_bug_add(), switch_core_media_bug_transfer_recordings(), switch_core_session_exec(), switch_core_session_get_partner(), switch_core_session_hangup_state(), switch_core_session_hupall_matching_var(), switch_core_session_outgoing_channel(), switch_core_session_pass_indication(), switch_core_session_perform_receive_message(), switch_core_session_reporting_state(), switch_core_session_thread(), switch_core_session_write_frame(), switch_core_standard_on_execute(), switch_event_add_presence_data_cols(), switch_ivr_bind_dtmf_meta_session(), switch_ivr_blind_transfer_ack(), switch_ivr_broadcast(), switch_ivr_collect_digits_count(), switch_ivr_detect_speech(), switch_ivr_displace_session(), switch_ivr_eavesdrop_session(), switch_ivr_enterprise_originate(), switch_ivr_find_bridged_uuid(), switch_ivr_hold(), switch_ivr_intercept_session(), switch_ivr_media(), switch_ivr_multi_threaded_bridge(), switch_ivr_nomedia(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_parse_event(), switch_ivr_phrase_macro_event(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_record_session(), switch_ivr_say(), switch_ivr_say_string(), switch_ivr_session_transfer(), switch_ivr_sleep(), switch_ivr_soft_hold(), switch_ivr_speak_text(), switch_ivr_speak_text_handle(), switch_ivr_transfer_variable(), switch_ivr_unhold(), switch_ivr_wait_for_answer(), switch_limit_incr(), switch_play_and_get_digits(), switch_process_import(), switch_rtp_add_crypto_key(), switch_rtp_create(), switch_rtp_enable_vad(), switch_rtp_write_frame(), switch_rtp_zerocopy_read_frame(), SWITCH_STANDARD_SCHED_FUNC(), and uuid_bridge_on_soft_execute().

#define switch_channel_hangup ( channel,
hangup_cause   )     switch_channel_perform_hangup(channel, __FILE__, __SWITCH_FUNC__, __LINE__, hangup_cause)

Hangup a channel flagging it's state machine to end.

Parameters:
channel channel to hangup
hangup_cause the appropriate hangup cause
Returns:
the resulting channel state.

Definition at line 536 of file switch_channel.h.

Referenced by abort_call(), audio_bridge_on_exchange_media(), audio_bridge_thread(), check_channel_status(), check_per_channel_timeouts(), cleanup_proxy_mode_a(), collect_thread_run(), CoreSession::destroy(), enterprise_originate_thread(), fs_channel_hangup(), fs_switch_ivr_originate(), CoreSession::hangup(), monitor_callback(), record_callback(), setup_ringback(), signal_bridge_on_hangup(), switch_channel_perform_answer(), switch_channel_perform_pre_answer(), switch_channel_perform_ring_ready_value(), switch_core_session_execute_application_get_flags(), switch_core_session_hupall(), switch_core_session_hupall_endpoint(), switch_core_session_hupall_matching_var(), switch_core_session_read_frame(), switch_core_session_run(), switch_core_session_write_frame(), switch_core_standard_on_execute(), switch_core_standard_on_routing(), switch_ivr_displace_session(), switch_ivr_intercept_session(), switch_ivr_kill_uuid(), switch_ivr_multi_threaded_bridge(), switch_ivr_park(), switch_ivr_parse_event(), switch_ivr_process_indications(), switch_ivr_record_file(), switch_ivr_record_session(), switch_ivr_session_transfer(), switch_ivr_signal_bridge(), switch_ivr_wait_for_answer(), SWITCH_STANDARD_SCHED_FUNC(), and uuid_bridge_on_soft_execute().

#define switch_channel_mark_answered ( channel   )     switch_channel_perform_mark_answered(channel, __FILE__, __SWITCH_FUNC__, __LINE__)

Mark a channel answered with no indication (for outbound calls).

Parameters:
channel channel to mark answered
Returns:
SWITCH_STATUS_SUCCESS if channel was answered successfully

Definition at line 421 of file switch_channel.h.

#define switch_channel_mark_pre_answered ( channel   )     switch_channel_perform_mark_pre_answered(channel, __FILE__, __SWITCH_FUNC__, __LINE__)

Mark a channel pre_answered (early media) with no indication (for outbound calls).

Parameters:
channel channel to mark pre_answered
Returns:
SWITCH_STATUS_SUCCESS if channel was pre_answered successfully

Definition at line 428 of file switch_channel.h.

#define switch_channel_mark_ring_ready ( channel   )     switch_channel_perform_mark_ring_ready_value(channel, SWITCH_RING_READY_RINGING, __FILE__, __SWITCH_FUNC__, __LINE__)

Indicate a channel is ready to provide ringback.

Parameters:
channel channel
Returns:
SWITCH_STATUS_SUCCESS

Definition at line 463 of file switch_channel.h.

#define switch_channel_mark_ring_ready_value ( channel,
_rv   )     switch_channel_perform_mark_ring_ready_value(channel, _rv, __FILE__, __SWITCH_FUNC__, __LINE__)

Definition at line 466 of file switch_channel.h.

#define switch_channel_media_ack ( _channel   )     (!switch_channel_test_cap(_channel, CC_MEDIA_ACK) || switch_channel_test_flag(_channel, CF_MEDIA_ACK))

Definition at line 94 of file switch_channel.h.

Referenced by audio_bridge_thread().

#define switch_channel_media_ready ( _channel   )     switch_channel_test_ready(_channel, SWITCH_TRUE, SWITCH_TRUE)

Definition at line 85 of file switch_channel.h.

Referenced by audio_bridge_thread(), bridge(), check_channel_status(), early_thread_run(), CoreSession::mediaReady(), originate_on_consume_media_transmit(), setup_ringback(), switch_channel_perform_audio_sync(), switch_core_media_bug_add(), switch_core_session_execute_application_get_flags(), switch_core_session_write_frame(), switch_ivr_enterprise_originate(), switch_ivr_multi_threaded_bridge(), switch_ivr_park(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_sleep(), and switch_ivr_wait_for_answer().

#define switch_channel_media_up ( _channel   )     (switch_channel_test_flag(_channel, CF_ANSWERED) || switch_channel_test_flag(_channel, CF_EARLY_MEDIA))

Definition at line 86 of file switch_channel.h.

Referenced by switch_core_session_execute_application_get_flags(), switch_ivr_displace_session(), switch_ivr_eavesdrop_session(), switch_ivr_inband_dtmf_generate_session(), switch_ivr_parse_all_events(), switch_ivr_record_session(), and switch_ivr_uuid_bridge().

#define switch_channel_pre_answer ( channel   )     switch_channel_perform_pre_answer(channel, __FILE__, __SWITCH_FUNC__, __LINE__)

Indicate progress on a channel to attempt early media.

Parameters:
channel channel to pre-answer
Returns:
SWITCH_STATUS_SUCCESS

Definition at line 456 of file switch_channel.h.

Referenced by audio_bridge_thread(), bridge(), fs_channel_pre_answer(), CoreSession::preAnswer(), setup_ringback(), switch_core_media_bug_add(), switch_core_session_execute_application_get_flags(), switch_core_session_send_dtmf_string(), switch_ivr_displace_session(), switch_ivr_eavesdrop_session(), switch_ivr_enterprise_originate(), switch_ivr_gentones(), switch_ivr_inband_dtmf_generate_session(), switch_ivr_inband_dtmf_session(), switch_ivr_park(), switch_ivr_phrase_macro_event(), switch_ivr_play_file(), switch_ivr_process_indications(), switch_ivr_read(), switch_ivr_record_session(), switch_ivr_session_audio(), switch_ivr_session_echo(), switch_ivr_speak_text(), and switch_ivr_speak_text_handle().

#define switch_channel_presence ( _a,
_b,
_c,
_d   )     switch_channel_perform_presence(_a, _b, _c, _d, __FILE__, __SWITCH_FUNC__, __LINE__)

Definition at line 177 of file switch_channel.h.

Referenced by switch_channel_perform_hangup(), switch_channel_perform_mark_answered(), and switch_core_session_exec().

#define switch_channel_ready ( _channel   )     switch_channel_test_ready(_channel, SWITCH_TRUE, SWITCH_FALSE)

Definition at line 84 of file switch_channel.h.

Referenced by audio_bridge_thread(), bridge(), check_channel_status(), collect_thread_run(), enterprise_originate_ringback_thread(), CoreSession::ready(), setup_ringback(), signal_bridge_on_hibernate(), switch_channel_wait_for_flag(), switch_core_session_execute_exten(), switch_core_session_write_frame(), switch_core_standard_on_execute(), switch_ivr_collect_digits_callback(), switch_ivr_collect_digits_count(), switch_ivr_delay_echo(), switch_ivr_eavesdrop_session(), switch_ivr_enterprise_originate(), switch_ivr_gentones(), switch_ivr_insert_file(), switch_ivr_menu_execute(), switch_ivr_multi_threaded_bridge(), switch_ivr_park(), switch_ivr_parse_event(), switch_ivr_play_and_detect_speech(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_session_echo(), switch_ivr_sleep(), switch_ivr_sound_test(), switch_ivr_speak_text_handle(), switch_ivr_wait_for_answer(), switch_ivr_wait_for_silence(), switch_play_and_get_digits(), and uuid_bridge_on_soft_execute().

#define switch_channel_ring_ready ( channel   )     switch_channel_perform_ring_ready_value(channel, SWITCH_RING_READY_RINGING, __FILE__, __SWITCH_FUNC__, __LINE__)

Send Ringing message to a channel.

Parameters:
channel channel to ring
Returns:
SWITCH_STATUS_SUCCESS if successful

Definition at line 438 of file switch_channel.h.

Referenced by check_channel_status(), and switch_ivr_process_indications().

#define switch_channel_ring_ready_value ( channel,
_rv   )     switch_channel_perform_ring_ready_value(channel, _rv, __FILE__, __SWITCH_FUNC__, __LINE__)

Definition at line 439 of file switch_channel.h.

Referenced by check_channel_status().

#define switch_channel_set_app_flag ( _c,
_f   )     switch_channel_set_app_flag_key(__FILE__, _c, _f)

Definition at line 617 of file switch_channel.h.

#define switch_channel_set_callstate ( channel,
state   )     switch_channel_perform_set_callstate(channel, state, __FILE__, __SWITCH_FUNC__, __LINE__)

Definition at line 631 of file switch_channel.h.

Referenced by switch_channel_clear_flag(), switch_channel_perform_hangup(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_set_flag_value(), and switch_core_session_destroy_state().

#define switch_channel_set_cap ( _c,
_cc   )     switch_channel_set_cap_value(_c, _cc, 1)

Definition at line 363 of file switch_channel.h.

#define switch_channel_set_flag ( _c,
_f   )     switch_channel_set_flag_value(_c, _f, 1)

Definition at line 358 of file switch_channel.h.

Referenced by audio_bridge_thread(), check_channel_status(), collect_thread_run(), enterprise_originate_ringback_thread(), signal_bridge_on_hangup(), switch_channel_check_zrtp(), switch_channel_init(), switch_channel_mark_hold(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_set_flag_partner(), switch_channel_set_timestamps(), switch_channel_sort_cid(), switch_channel_transfer_to_extension(), switch_core_media_bug_pause(), switch_core_service_session_av(), switch_core_service_thread(), switch_core_session_execute_application_async(), switch_core_session_outgoing_channel(), switch_core_session_reporting_state(), switch_core_session_request_uuid(), switch_core_session_run(), switch_core_session_set_read_codec(), switch_core_session_set_real_read_codec(), switch_core_standard_on_execute(), switch_ivr_activate_unicast(), switch_ivr_broadcast(), switch_ivr_enterprise_originate(), switch_ivr_hold(), switch_ivr_intercept_session(), switch_ivr_multi_threaded_bridge(), switch_ivr_nomedia(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_park_session(), switch_ivr_parse_all_signal_data(), switch_ivr_parse_event(), switch_ivr_session_transfer(), switch_ivr_signal_bridge(), and switch_ivr_uuid_bridge().

#define switch_channel_set_running_state ( channel,
state   )     switch_channel_perform_set_running_state(channel, state, __FILE__, __SWITCH_FUNC__, __LINE__)

Definition at line 107 of file switch_channel.h.

Referenced by switch_core_session_destroy_state(), and switch_core_session_run().

#define switch_channel_set_state ( channel,
state   )     switch_channel_perform_set_state(channel, __FILE__, __SWITCH_FUNC__, __LINE__, state)

Set the current state of a channel.

Parameters:
channel channel to set state of
state new state
Returns:
current state of channel after application of new state

Definition at line 115 of file switch_channel.h.

Referenced by audio_bridge_on_exchange_media(), audio_bridge_on_routing(), audio_bridge_thread(), CoreSession::CoreSession(), fs_channel_set_state(), CoreSession::originate(), originate_on_routing(), sb_on_dtmf(), signal_bridge_on_hangup(), switch_channel_restart(), switch_channel_transfer_to_extension(), switch_core_session_run(), switch_core_standard_on_execute(), switch_core_standard_on_routing(), switch_ivr_intercept_session(), switch_ivr_multi_threaded_bridge(), switch_ivr_nomedia(), switch_ivr_park_session(), switch_ivr_session_transfer(), switch_ivr_signal_bridge(), switch_ivr_uuid_bridge(), switch_ivr_wait_for_answer(), uuid_bridge_on_hibernate(), uuid_bridge_on_reset(), and uuid_bridge_on_soft_execute().

#define switch_channel_set_variable ( _channel,
_var,
_val   )     switch_channel_set_variable_var_check(_channel, _var, _val, SWITCH_TRUE)

Definition at line 277 of file switch_channel.h.

Referenced by audio_bridge_on_exchange_media(), audio_bridge_thread(), cleanup_proxy_mode_a(), fs_channel_set_variable(), fs_switch_channel_set_variable(), inherit_codec(), limit_state_handler(), monitor_callback(), record_callback(), rtp_common_read(), signal_bridge_on_hangup(), signal_bridge_on_hibernate(), switch_channel_alloc(), switch_channel_caller_extension_masquerade(), switch_channel_check_zrtp(), switch_channel_clear_flag(), switch_channel_clear_flag_recursive(), switch_channel_del_variable_prefix(), switch_channel_export_variable_var_check(), switch_channel_flip_cid(), switch_channel_perform_hangup(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_process_export(), switch_channel_set_flag_recursive(), switch_channel_set_flag_value(), switch_channel_set_name(), switch_channel_set_variable_name_printf(), switch_channel_set_variable_printf(), switch_core_media_bug_transfer_recordings(), switch_core_session_exec(), switch_core_session_hangup_state(), switch_core_session_outgoing_channel(), switch_core_session_perform_receive_message(), switch_core_session_request_uuid(), switch_core_session_request_xml(), switch_core_session_set_read_codec(), switch_core_session_set_real_read_codec(), switch_core_session_set_uuid(), switch_core_session_set_video_read_codec(), switch_core_session_set_video_write_codec(), switch_core_session_set_write_codec(), switch_core_standard_on_execute(), switch_core_standard_on_reset(), switch_core_standard_on_routing(), switch_ivr_menu_execute(), switch_ivr_multi_threaded_bridge(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_phrase_macro_event(), switch_ivr_play_file(), switch_ivr_read(), switch_ivr_record_file(), switch_ivr_record_session(), switch_ivr_say(), switch_ivr_say_string(), switch_ivr_session_transfer(), switch_ivr_set_user(), switch_ivr_signal_bridge(), switch_ivr_transfer_variable(), switch_ivr_uuid_bridge(), switch_limit_incr(), switch_play_and_get_digits(), switch_process_import(), switch_rtp_add_crypto_key(), switch_rtp_create(), transfer_after_bridge(), and uuid_bridge_on_soft_execute().

#define switch_channel_set_variable_partner ( _channel,
_var,
_val   )     switch_channel_set_variable_partner_var_check(_channel, _var, _val, SWITCH_TRUE)

Definition at line 278 of file switch_channel.h.

Referenced by switch_channel_perform_hangup().

#define switch_channel_set_variable_safe ( _channel,
_var,
_val   )     switch_channel_set_variable_var_check(_channel, _var, _val, SWITCH_FALSE)

Definition at line 276 of file switch_channel.h.

#define switch_channel_stop_broadcast ( _channel   )     for(;;) {if (switch_channel_test_flag(_channel, CF_BROADCAST)) {switch_channel_set_flag(_channel, CF_STOP_BROADCAST); switch_channel_set_flag(_channel, CF_BREAK); } break;}

Definition at line 604 of file switch_channel.h.

Referenced by audio_bridge_thread(), switch_core_session_hangup_state(), switch_ivr_multi_threaded_bridge(), switch_ivr_parse_event(), switch_ivr_soft_hold(), switch_ivr_unhold(), and switch_ivr_uuid_bridge().

#define switch_channel_test_app_flag ( _c,
_f   )     switch_channel_test_app_flag_key(__FILE__, _c, _f)

Definition at line 619 of file switch_channel.h.

#define switch_channel_up ( _channel   )     (switch_channel_check_signal(_channel, SWITCH_TRUE) || switch_channel_get_state(_channel) < CS_HANGUP)

Definition at line 88 of file switch_channel.h.

Referenced by CoreSession::bridged(), and CoreSession::destroy().

#define switch_channel_up_nosig ( _channel   )     (switch_channel_get_state(_channel) < CS_HANGUP)

Definition at line 91 of file switch_channel.h.

Referenced by audio_bridge_thread(), check_per_channel_timeouts(), collect_thread_run(), signal_bridge_on_hangup(), speech_thread(), switch_channel_perform_presence(), switch_core_session_event_send(), switch_core_session_hupall_matching_var(), switch_core_session_message_send(), switch_core_session_perform_receive_message(), switch_core_session_receive_event(), switch_ivr_eavesdrop_session(), switch_ivr_signal_bridge(), and switch_ivr_wait_for_answer().


Function Documentation

int switch_channel_add_state_handler ( switch_channel_t channel,
const switch_state_handler_table_t state_handler 
)

add a state handler table to a given channel

Parameters:
channel channel on which to add the state handler table
state_handler table of state handler functions
Returns:
the index number/priority of the table negative value indicates failure

Definition at line 2550 of file switch_channel.c.

References switch_assert, SWITCH_MAX_STATE_HANDLERS, and switch_mutex_lock().

Referenced by switch_ivr_multi_threaded_bridge(), switch_ivr_signal_bridge(), and switch_ivr_uuid_bridge().

02551 {
02552         int x, index;
02553 
02554         switch_assert(channel != NULL);
02555         switch_mutex_lock(channel->state_mutex);
02556         for (x = 0; x < SWITCH_MAX_STATE_HANDLERS; x++) {
02557                 if (channel->state_handlers[x] == state_handler) {
02558                         index = x;
02559                         goto end;
02560                 }
02561         }
02562         index = channel->state_handler_index++;
02563 
02564         if (channel->state_handler_index >= SWITCH_MAX_STATE_HANDLERS) {
02565                 index = -1;
02566                 goto end;
02567         }
02568 
02569         channel->state_handlers[index] = state_handler;
02570 
02571   end:
02572         switch_mutex_unlock(channel->state_mutex);
02573         return index;
02574 }

switch_status_t switch_channel_add_variable_var_check ( switch_channel_t channel,
const char *  varname,
const char *  value,
switch_bool_t  var_check,
switch_stack_t  stack 
)

Definition at line 1226 of file switch_channel.c.

References switch_assert, SWITCH_CHANNEL_CHANNEL_LOG, switch_event_add_header_string(), switch_event_del_header, SWITCH_LOG_CRIT, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_string_var_check_const(), and zstr.

Referenced by switch_ivr_session_transfer(), switch_ivr_uuid_bridge(), and switch_regex_set_var_callback().

01228 {
01229         switch_status_t status = SWITCH_STATUS_FALSE;
01230 
01231         switch_assert(channel != NULL);
01232 
01233         switch_mutex_lock(channel->profile_mutex);
01234         if (channel->variables && !zstr(varname)) {
01235                 if (zstr(value)) {
01236                         switch_event_del_header(channel->variables, varname);
01237                 } else {
01238                         int ok = 1;
01239 
01240                         if (var_check) {
01241                                 ok = !switch_string_var_check_const(value);
01242                         }
01243                         if (ok) {
01244                                 switch_event_add_header_string(channel->variables, stack, varname, value);
01245                         } else {
01246                                 switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_CRIT, "Invalid data (${%s} contains a variable)\n", varname);
01247                         }
01248                 }
01249                 status = SWITCH_STATUS_SUCCESS;
01250         }
01251         switch_mutex_unlock(channel->profile_mutex);
01252 
01253         return status;
01254 }

switch_status_t switch_channel_alloc ( _In_ switch_channel_t **  channel,
_In_ switch_call_direction_t  direction,
_In_ switch_memory_pool_t pool 
)

Allocate a new channel.

Parameters:
channel NULL pointer to allocate channel to
pool memory_pool to use for allocation
Returns:
SWITCH_STATUS_SUCCESS if successful

Referenced by switch_core_session_request_uuid().

char* switch_channel_build_param_string ( _In_ switch_channel_t channel,
_In_opt_ switch_caller_profile_t caller_profile,
_In_opt_ const char *  prefix 
)

switch_status_t switch_channel_caller_extension_masquerade ( switch_channel_t orig_channel,
switch_channel_t new_channel,
uint32_t  offset 
)

Definition at line 2646 of file switch_channel.c.

References switch_caller_application::application_data, switch_caller_application::application_name, switch_caller_profile::destination_number, switch_event_header::name, switch_caller_application::next, switch_event_header::next, switch_caller_profile::pool, switch_assert, switch_caller_extension_add_application(), switch_caller_extension_new(), switch_caller_profile_clone(), switch_channel_get_caller_extension(), switch_channel_get_variable, switch_channel_set_caller_extension(), switch_channel_set_caller_profile(), switch_channel_set_variable, switch_core_session_strdup, switch_core_strdup, switch_mutex_lock(), switch_separate_string(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_event_header::value.

02647 {
02648         switch_caller_profile_t *caller_profile;
02649         switch_caller_extension_t *extension = NULL, *orig_extension = NULL;
02650         switch_caller_application_t *ap;
02651         switch_status_t status = SWITCH_STATUS_FALSE;
02652         switch_event_header_t *hi = NULL;
02653         const char *no_copy = switch_channel_get_variable(orig_channel, "attended_transfer_no_copy");
02654         char *dup;
02655         int i, argc = 0;
02656         char *argv[128];
02657 
02658         if (no_copy) {
02659                 dup = switch_core_session_strdup(new_channel->session, no_copy);
02660                 argc = switch_separate_string(dup, ',', argv, (sizeof(argv) / sizeof(argv[0])));
02661         }
02662 
02663 
02664         switch_mutex_lock(orig_channel->profile_mutex);
02665         switch_mutex_lock(new_channel->profile_mutex);
02666 
02667 
02668         caller_profile = switch_caller_profile_clone(new_channel->session, new_channel->caller_profile);
02669         switch_assert(caller_profile);
02670         extension = switch_caller_extension_new(new_channel->session, caller_profile->destination_number, caller_profile->destination_number);
02671         orig_extension = switch_channel_get_caller_extension(orig_channel);
02672 
02673 
02674         if (extension && orig_extension) {
02675                 for (ap = orig_extension->current_application; ap && offset > 0; offset--) {
02676                         ap = ap->next;
02677                 }
02678 
02679                 for (; ap; ap = ap->next) {
02680                         switch_caller_extension_add_application(new_channel->session, extension, ap->application_name, ap->application_data);
02681                 }
02682 
02683                 caller_profile->destination_number = switch_core_strdup(caller_profile->pool, orig_channel->caller_profile->destination_number);
02684                 switch_channel_set_caller_profile(new_channel, caller_profile);
02685                 switch_channel_set_caller_extension(new_channel, extension);
02686 
02687                 for (hi = orig_channel->variables->headers; hi; hi = hi->next) {
02688                         int ok = 1;
02689                         for (i = 0; i < argc; i++) {
02690                                 if (!strcasecmp(argv[i], hi->name)) {
02691                                         ok = 0;
02692                                         break;
02693                                 }
02694                         }
02695 
02696                         if (!ok)
02697                                 continue;
02698 
02699                         switch_channel_set_variable(new_channel, hi->name, hi->value);
02700                 }
02701 
02702                 status = SWITCH_STATUS_SUCCESS;
02703         }
02704 
02705 
02706         switch_mutex_unlock(new_channel->profile_mutex);
02707         switch_mutex_unlock(orig_channel->profile_mutex);
02708 
02709 
02710         return status;
02711 }

const char* switch_channel_callstate2str ( switch_channel_callstate_t  callstate  ) 

Definition at line 249 of file switch_channel.c.

References CALLSTATE_CHART, and switch_callstate_table::name.

Referenced by switch_channel_event_set_basic_data(), and switch_channel_perform_set_callstate().

00250 {
00251         uint8_t x;
00252         const char *str = "UNKNOWN";
00253 
00254         for (x = 0; x < (sizeof(CALLSTATE_CHART) / sizeof(struct switch_cause_table)) - 1; x++) {
00255                 if (CALLSTATE_CHART[x].callstate == callstate) {
00256                         str = CALLSTATE_CHART[x].name;
00257                         break;
00258                 }
00259         }
00260 
00261         return str;
00262 }

const char* switch_channel_cause2str ( _In_ switch_call_cause_t  cause  ) 

return a cause string for a given cause

Parameters:
cause the code to check
Returns:
the string

Referenced by CoreSession::hangupCause(), switch_channel_perform_hangup(), switch_core_session_hangup_state(), switch_core_session_outgoing_channel(), switch_core_session_reporting_state(), switch_core_standard_on_hangup(), switch_core_standard_on_reporting(), and switch_ivr_multi_threaded_bridge().

switch_call_cause_t switch_channel_cause_q850 ( switch_call_cause_t  cause  ) 

Definition at line 300 of file switch_channel.c.

References SWITCH_CAUSE_INTERWORKING, and SWITCH_CAUSE_NORMAL_CLEARING.

Referenced by switch_channel_get_cause_q850().

00301 {
00302         if (cause <= SWITCH_CAUSE_INTERWORKING) {
00303                 return cause;
00304         } else {
00305                 return SWITCH_CAUSE_NORMAL_CLEARING;
00306         }
00307 }

int switch_channel_check_signal ( switch_channel_t channel,
switch_bool_t  in_thread_only 
)

Definition at line 1804 of file switch_channel.c.

References switch_core_session_in_thread(), and switch_ivr_parse_all_signal_data().

Referenced by switch_channel_test_ready(), and switch_channel_wait_for_state_timeout().

01805 {
01806         if (!in_thread_only || switch_core_session_in_thread(channel->session)) {
01807                 switch_ivr_parse_all_signal_data(channel->session);
01808         }
01809 
01810         return 0;
01811 }

void switch_channel_check_zrtp ( switch_channel_t channel  ) 

Definition at line 2955 of file switch_channel.c.

References CF_ZRTP_HASH, CF_ZRTP_PASS, switch_channel_clear_flag(), switch_channel_get_name(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_set_variable, switch_channel_test_flag(), switch_core_session_get_channel(), switch_core_session_get_partner(), switch_core_session_rwunlock(), SWITCH_LOG_INFO, switch_log_printf(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_channel_perform_mark_answered(), and switch_channel_perform_mark_pre_answered().

02956 {
02957 
02958         if (switch_channel_test_flag(channel, CF_ZRTP_HASH) && !switch_channel_test_flag(channel, CF_ZRTP_PASS)) {
02959                 switch_core_session_t *other_session;
02960                 switch_channel_t *other_channel;
02961                 int doit = 1;
02962                 
02963                 if (switch_core_session_get_partner(channel->session, &other_session) == SWITCH_STATUS_SUCCESS) {
02964                         other_channel = switch_core_session_get_channel(other_session);
02965 
02966                         if (switch_channel_test_flag(other_channel, CF_ZRTP_HASH) && !switch_channel_test_flag(other_channel, CF_ZRTP_PASS)) {
02967                                 
02968                                 switch_channel_set_flag(channel, CF_ZRTP_PASS);
02969                                 switch_channel_set_flag(other_channel, CF_ZRTP_PASS);
02970                         
02971                                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(channel->session), SWITCH_LOG_INFO, 
02972                                                                   "%s Activating ZRTP passthru mode.\n", switch_channel_get_name(channel));
02973         
02974                                 switch_channel_set_variable(channel, "zrtp_secure_media", "false");
02975                                 switch_channel_set_variable(other_channel, "zrtp_secure_media", "false");
02976                                 doit = 0;
02977                         }
02978 
02979                         switch_core_session_rwunlock(other_session);
02980                 }
02981 
02982                 if (doit) {
02983                         switch_channel_set_variable(channel, "zrtp_secure_media", "true");
02984                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(channel->session), SWITCH_LOG_INFO, 
02985                                                           "%s ZRTP not negotiated on both sides; disabling ZRTP passthru mode.\n", switch_channel_get_name(channel));
02986 
02987                         switch_channel_clear_flag(channel, CF_ZRTP_PASS);
02988                         switch_channel_clear_flag(channel, CF_ZRTP_HASH);
02989 
02990                         if (switch_core_session_get_partner(channel->session, &other_session) == SWITCH_STATUS_SUCCESS) {
02991                                 other_channel = switch_core_session_get_channel(other_session);  
02992 
02993                                 switch_channel_set_variable(other_channel, "zrtp_secure_media", "true");
02994                                 switch_channel_clear_flag(other_channel, CF_ZRTP_PASS);
02995                                 switch_channel_clear_flag(other_channel, CF_ZRTP_HASH);
02996                                 
02997                                 switch_core_session_rwunlock(other_session);
02998                         }
02999 
03000                 }
03001         }
03002 }

void switch_channel_clear_app_flag_key ( const char *  app,
switch_channel_t channel,
uint32_t  flags 
)

Definition at line 1675 of file switch_channel.c.

References switch_assert, switch_core_hash_find(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_ivr_eavesdrop_update_display().

01676 {
01677         uint32_t *flagp = NULL;
01678         
01679         switch_assert(channel != NULL);
01680         switch_mutex_lock(channel->flag_mutex);
01681         if (channel->app_flag_hash && (flagp = switch_core_hash_find(channel->app_flag_hash, key))) {
01682                 if (!flags) {
01683                         *flagp = 0;
01684                 } else {
01685                         *flagp &= ~flags;
01686                 }
01687         }
01688         switch_mutex_unlock(channel->flag_mutex);
01689 }

void switch_channel_clear_cap ( switch_channel_t channel,
switch_channel_cap_t  cap 
)

Definition at line 1493 of file switch_channel.c.

References switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

01494 {
01495         switch_assert(channel != NULL);
01496         switch_assert(channel->flag_mutex);
01497 
01498         switch_mutex_lock(channel->flag_mutex);
01499         channel->caps[cap] = 0;
01500         switch_mutex_unlock(channel->flag_mutex);
01501 }

void switch_channel_clear_flag ( switch_channel_t channel,
switch_channel_flag_t  flag 
)

Clear given flag(s) from a channel.

Parameters:
channel channel to clear flags from
flag flag to clear

Definition at line 1726 of file switch_channel.c.

References CCS_ACTIVE, CF_ANSWERED, CF_LEG_HOLDING, CF_OUTBOUND, CF_RECOVERED, switch_assert, switch_channel_set_callstate, switch_channel_set_variable, switch_mutex_lock(), switch_mutex_unlock(), and switch_time_now().

Referenced by audio_bridge_on_exchange_media(), audio_bridge_thread(), check_channel_status(), check_per_channel_timeouts(), switch_channel_check_zrtp(), switch_channel_clear_flag_partner(), switch_channel_mark_hold(), switch_channel_perform_hangup(), switch_channel_sort_cid(), switch_core_media_bug_resume(), switch_core_service_thread(), switch_core_session_destroy_state(), switch_core_session_exec(), switch_core_session_outgoing_channel(), switch_core_session_perform_receive_message(), switch_core_session_reset(), switch_core_session_run(), switch_core_standard_on_execute(), switch_core_thread_session_end(), switch_ivr_blind_transfer_ack(), switch_ivr_collect_digits_callback(), switch_ivr_deactivate_unicast(), switch_ivr_enterprise_originate(), switch_ivr_gentones(), switch_ivr_multi_threaded_bridge(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_parse_all_events(), switch_ivr_parse_all_signal_data(), switch_ivr_parse_event(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_session_echo(), switch_ivr_session_transfer(), switch_ivr_signal_bridge(), switch_ivr_sleep(), switch_ivr_speak_text_handle(), switch_ivr_unhold(), switch_ivr_uuid_bridge(), and uuid_bridge_on_reset().

01727 {
01728         int ACTIVE = 0;
01729 
01730         switch_assert(channel != NULL);
01731         switch_assert(channel->flag_mutex);
01732 
01733         switch_mutex_lock(channel->flag_mutex);
01734         if (flag == CF_LEG_HOLDING && channel->flags[flag] && channel->flags[CF_ANSWERED]) {
01735                 ACTIVE = 1;
01736         }
01737         channel->flags[flag] = 0;
01738         switch_mutex_unlock(channel->flag_mutex);
01739 
01740         if (ACTIVE) {
01741                 switch_channel_set_callstate(channel, CCS_ACTIVE);
01742                 switch_mutex_lock(channel->profile_mutex);
01743                 if (channel->caller_profile->times->last_hold) {
01744                         channel->caller_profile->times->hold_accum += (switch_time_now() - channel->caller_profile->times->last_hold);
01745                 }
01746                 switch_mutex_unlock(channel->profile_mutex);
01747         }
01748 
01749         if (flag == CF_OUTBOUND) {
01750                 switch_channel_set_variable(channel, "is_outbound", NULL);
01751         }
01752 
01753         if (flag == CF_RECOVERED) {
01754                 switch_channel_set_variable(channel, "recovered", NULL);
01755         }
01756 }

switch_bool_t switch_channel_clear_flag_partner ( switch_channel_t channel,
switch_channel_flag_t  flag 
)

Clears given flag(s) on a given channel's bridge partner.

Parameters:
channel channel to derive the partner channel to clear flag(s) from
flag the flag to clear
Returns:
true if the flag was cleared

Definition at line 1390 of file switch_channel.c.

References switch_assert, switch_channel_clear_flag(), switch_channel_get_variable, switch_core_session_get_channel(), switch_core_session_locate(), switch_core_session_rwunlock(), SWITCH_FALSE, SWITCH_SIGNAL_BOND_VARIABLE, and SWITCH_TRUE.

01391 {
01392         const char *uuid;
01393 
01394         switch_assert(channel != NULL);
01395 
01396         if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) || (uuid = switch_channel_get_variable(channel, "originate_signal_bond"))) {
01397                 switch_core_session_t *session;
01398                 if ((session = switch_core_session_locate(uuid))) {
01399                         switch_channel_clear_flag(switch_core_session_get_channel(session), flag);
01400                         switch_core_session_rwunlock(session);
01401                         return SWITCH_TRUE;
01402                 }
01403         }
01404 
01405         return SWITCH_FALSE;
01406 }

void switch_channel_clear_flag_recursive ( switch_channel_t channel,
switch_channel_flag_t  flag 
)

Definition at line 1759 of file switch_channel.c.

References CF_OUTBOUND, switch_assert, switch_channel_set_variable, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by hanguphook(), signal_bridge_on_hangup(), switch_ivr_multi_threaded_bridge(), switch_ivr_parse_event(), switch_ivr_uuid_bridge(), and uuid_bridge_on_soft_execute().

01760 {
01761         switch_assert(channel != NULL);
01762         switch_assert(channel->flag_mutex);
01763 
01764         switch_mutex_lock(channel->flag_mutex);
01765         if (channel->flags[flag]) {
01766                 channel->flags[flag]--;
01767         }
01768         switch_mutex_unlock(channel->flag_mutex);
01769 
01770         if (flag == CF_OUTBOUND) {
01771                 switch_channel_set_variable(channel, "is_outbound", NULL);
01772         }
01773 }

void switch_channel_clear_private_flag ( switch_channel_t channel,
uint32_t  flags 
)

Definition at line 1637 of file switch_channel.c.

References switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

01638 {
01639         switch_assert(channel != NULL);
01640         switch_mutex_lock(channel->flag_mutex);
01641         channel->private_flags &= ~flags;
01642         switch_mutex_unlock(channel->flag_mutex);
01643 }

void switch_channel_clear_state_flag ( switch_channel_t channel,
switch_channel_flag_t  flag 
)

Definition at line 1717 of file switch_channel.c.

References switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_ivr_uuid_bridge().

01718 {
01719         switch_assert(channel != NULL);
01720 
01721         switch_mutex_lock(channel->flag_mutex);
01722         channel->state_flags[flag] = 0;
01723         switch_mutex_unlock(channel->flag_mutex);
01724 }

void switch_channel_clear_state_handler ( switch_channel_t channel,
const switch_state_handler_table_t state_handler 
)

clear a state handler table from a given channel

Parameters:
channel channel from which to clear the state handler table
state_handler table of state handler functions

Definition at line 2593 of file switch_channel.c.

References switch_assert, SWITCH_MAX_STATE_HANDLERS, and switch_mutex_lock().

Referenced by audio_bridge_on_exchange_media(), originate_on_consume_media_transmit(), switch_ivr_media(), switch_ivr_session_transfer(), switch_ivr_signal_bridge(), switch_ivr_uuid_bridge(), and uuid_bridge_on_soft_execute().

02594 {
02595         int index, i = channel->state_handler_index;
02596         const switch_state_handler_table_t *new_handlers[SWITCH_MAX_STATE_HANDLERS] = { 0 };
02597 
02598         switch_assert(channel != NULL);
02599 
02600         switch_mutex_lock(channel->state_mutex);
02601         channel->state_handler_index = 0;
02602 
02603         if (state_handler) {
02604                 for (index = 0; index < i; index++) {
02605                         if (channel->state_handlers[index] != state_handler) {
02606                                 new_handlers[channel->state_handler_index++] = channel->state_handlers[index];
02607                         }
02608                 }
02609         } else {
02610                 for (index = 0; index < i; index++) {
02611                         if (channel->state_handlers[index] && switch_test_flag(channel->state_handlers[index], SSH_FLAG_STICKY)) {
02612                                 new_handlers[channel->state_handler_index++] = channel->state_handlers[index];
02613                         }
02614                 }
02615         }
02616 
02617         for (index = 0; index < SWITCH_MAX_STATE_HANDLERS; index++) {
02618                 channel->state_handlers[index] = NULL;
02619         }
02620 
02621         if (channel->state_handler_index > 0) {
02622                 for (index = 0; index < channel->state_handler_index; index++) {
02623                         channel->state_handlers[index] = new_handlers[index];
02624                 }
02625         }
02626 
02627         switch_mutex_unlock(channel->state_mutex);
02628 }

uint32_t switch_channel_del_variable_prefix ( switch_channel_t channel,
const char *  prefix 
)

Definition at line 1142 of file switch_channel.c.

References switch_event::headers, switch_event_header::name, switch_event_header::next, switch_channel_get_variables(), switch_channel_set_variable, switch_event_destroy(), and zstr.

01143 {
01144         switch_event_t *event;
01145         switch_event_header_t *hp;
01146         uint32_t r = 0;
01147 
01148         switch_channel_get_variables(channel, &event);
01149 
01150         if (event) {
01151                 for (hp = event->headers; hp; hp = hp->next) {
01152                         if (zstr(prefix) || !strncasecmp(hp->name, prefix, strlen(prefix))) {
01153                                 switch_channel_set_variable(channel, hp->name, NULL);
01154                         }
01155                 }
01156         }
01157 
01158         switch_event_destroy(&event);
01159 
01160         return r;
01161 }

switch_status_t switch_channel_dequeue_dtmf ( _In_ switch_channel_t channel,
_In_ switch_dtmf_t dtmf 
)

Retrieve DTMF digits from a given channel.

Parameters:
channel channel to retrieve digits from
dtmf digit
Returns:
number of bytes read into the buffer

Referenced by audio_bridge_thread(), switch_channel_dequeue_dtmf_string(), switch_ivr_collect_digits_callback(), switch_ivr_collect_digits_count(), switch_ivr_eavesdrop_session(), switch_ivr_gentones(), switch_ivr_park(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_session_echo(), switch_ivr_sleep(), switch_ivr_speak_text_handle(), and switch_ivr_wait_for_answer().

switch_size_t switch_channel_dequeue_dtmf_string ( _In_ switch_channel_t channel,
_Out_opt_bytecapcount_(len) char *  dtmf_str,
_In_ switch_size_t  len 
)

switch_call_direction_t switch_channel_direction ( switch_channel_t channel  ) 

Definition at line 327 of file switch_channel.c.

Referenced by audio_bridge_thread(), bridge(), send_display(), switch_channel_alloc(), switch_channel_event_set_basic_data(), switch_channel_perform_answer(), switch_channel_perform_pre_answer(), switch_channel_perform_ring_ready_value(), switch_channel_sort_cid(), switch_core_session_execute_application_get_flags(), switch_core_standard_on_routing(), switch_ivr_generate_json_cdr(), switch_ivr_generate_xml_cdr(), switch_ivr_uuid_bridge(), switch_rtp_add_crypto_key(), switch_rtp_create(), and switch_rtp_zerocopy_read_frame().

00328 {
00329         return channel->direction;
00330 }

void switch_channel_event_set_basic_data ( _In_ switch_channel_t channel,
_In_ switch_event_t event 
)

Referenced by switch_channel_event_set_data().

void switch_channel_event_set_data ( _In_ switch_channel_t channel,
_In_ switch_event_t event 
)

Add information about a given channel to an event object.

Parameters:
channel channel to add information about
event event to add information to

Referenced by api_hook(), generate_on_dtmf(), hanguphook(), record_callback(), rtp_common_write(), CoreSession::setEventData(), signal_bridge_on_hangup(), signal_bridge_on_hibernate(), speech_thread(), switch_channel_dequeue_dtmf(), switch_channel_flip_cid(), switch_channel_mark_hold(), switch_channel_perform_hangup(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_perform_mark_ring_ready_value(), switch_channel_perform_presence(), switch_channel_perform_set_callstate(), switch_core_media_bug_add(), switch_core_media_bug_destroy(), switch_core_session_exec(), switch_core_session_outgoing_channel(), switch_core_session_perform_destroy(), switch_core_session_reporting_state(), switch_core_session_run(), switch_core_session_set_read_codec(), switch_core_session_set_real_read_codec(), switch_core_session_set_uuid(), switch_core_session_set_video_read_codec(), switch_core_session_set_video_write_codec(), switch_core_session_set_write_codec(), switch_core_session_thread(), switch_ivr_multi_threaded_bridge(), switch_ivr_park(), switch_ivr_phrase_macro_event(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_say(), switch_ivr_say_string(), switch_ivr_signal_bridge(), SWITCH_STANDARD_SCHED_FUNC(), and uuid_bridge_on_soft_execute().

void switch_channel_event_set_extended_data ( _In_ switch_channel_t channel,
_In_ switch_event_t event 
)

Referenced by switch_channel_event_set_data().

char* switch_channel_expand_variables_check ( switch_channel_t channel,
const char *  in,
switch_event_t var_list,
switch_event_t api_list,
uint32_t  recur 
)

Expand varaibles in a string based on the variables in a paticular channel.

Parameters:
channel channel to expand the variables from
in the original string
Returns:
the original string if no expansion takes place otherwise a new string that must be freed
Note:
it's necessary to test if the return val is the same as the input and free the string if it is not.

Definition at line 3381 of file switch_channel.c.

References switch_stream_handle::data, end_of_p, resize, switch_api_execute(), switch_assert, SWITCH_CHANNEL_CHANNEL_LOG, switch_channel_expand_variables_check(), switch_channel_get_variable_dup(), switch_event_check_permission_list(), SWITCH_LOG_CRIT, switch_log_printf(), switch_safe_free, SWITCH_STANDARD_STREAM, SWITCH_STATUS_SUCCESS, switch_string_has_escaped_data(), switch_string_var_check_const(), SWITCH_TRUE, and zstr.

Referenced by switch_channel_expand_variables_check().

03382 {
03383         char *p, *c = NULL;
03384         char *data, *indup, *endof_indup;
03385         size_t sp = 0, len = 0, olen = 0, vtype = 0, br = 0, cpos, block = 128;
03386         char *cloned_sub_val = NULL, *sub_val = NULL, *expanded_sub_val = NULL;
03387         char *func_val = NULL, *sb = NULL;
03388         int nv = 0;
03389 
03390         if (recur > 100) {
03391                 return (char *) in;
03392         }
03393 
03394         if (zstr(in)) {
03395                 return (char *) in;
03396         }
03397 
03398         nv = switch_string_var_check_const(in) || switch_string_has_escaped_data(in);
03399 
03400         if (!nv) {
03401                 return (char *) in;
03402         }
03403 
03404 
03405         nv = 0;
03406         olen = strlen(in) + 1;
03407         indup = strdup(in);
03408         endof_indup = end_of_p(indup) + 1;
03409 
03410         if ((data = malloc(olen))) {
03411                 memset(data, 0, olen);
03412                 c = data;
03413                 for (p = indup; p && p < endof_indup && *p; p++) {
03414                         vtype = 0;
03415 
03416                         if (*p == '\\') {
03417                                 if (*(p + 1) == '$') {
03418                                         nv = 1;
03419                                         p++;
03420                                 } else if (*(p + 1) == '\'') {
03421                                         p++;
03422                                         continue;
03423                                 } else if (*(p + 1) == '\\') {
03424                                         *c++ = *p++;
03425                                         len++;
03426                                         continue;
03427                                 }
03428                         }
03429 
03430                         if (*p == '$' && !nv) {
03431                                 if (*(p + 1)) {
03432                                         if (*(p + 1) == '{') {
03433                                                 vtype = 1;
03434                                         } else {
03435                                                 nv = 1;
03436                                         }
03437                                 } else {
03438                                         nv = 1;
03439                                 }
03440                         }
03441 
03442                         if (nv) {
03443                                 *c++ = *p;
03444                                 len++;
03445                                 nv = 0;
03446                                 continue;
03447                         }
03448 
03449                         if (vtype) {
03450                                 char *s = p, *e, *vname, *vval = NULL;
03451                                 size_t nlen;
03452 
03453                                 s++;
03454 
03455                                 if (vtype == 1 && *s == '{') {
03456                                         br = 1;
03457                                         s++;
03458                                 }
03459 
03460                                 e = s;
03461                                 vname = s;
03462                                 while (*e) {
03463                                         if (br == 1 && *e == '}') {
03464                                                 br = 0;
03465                                                 *e++ = '\0';
03466                                                 break;
03467                                         }
03468 
03469                                         if (br > 0) {
03470                                                 if (e != s && *e == '{') {
03471                                                         br++;
03472                                                 } else if (br > 1 && *e == '}') {
03473                                                         br--;
03474                                                 }
03475                                         }
03476 
03477                                         e++;
03478                                 }
03479                                 p = e > endof_indup ? endof_indup : e;
03480 
03481                                 vval = NULL;
03482                                 for(sb = vname; sb && *sb; sb++) {
03483                                         if (*sb == ' ') {
03484                                                 vval = sb;
03485                                                 break;
03486                                         } else if (*sb == '(') {
03487                                                 vval = sb;
03488                                                 br = 1;
03489                                                 break;
03490                                         }
03491                                 }
03492 
03493                                 if (vval) {
03494                                         e = vval - 1;
03495                                         *vval++ = '\0';
03496                                         while (*e == ' ') {
03497                                                 *e-- = '\0';
03498                                         }
03499                                         e = vval;
03500 
03501                                         while (e && *e) {
03502                                                 if (*e == '(') {
03503                                                         br++;
03504                                                 } else if (br > 1 && *e == ')') {
03505                                                         br--;
03506                                                 } else if (br == 1 && *e == ')') {
03507                                                         *e = '\0';
03508                                                         break;
03509                                                 }
03510                                                 e++;
03511                                         }
03512 
03513                                         vtype = 2;
03514                                 }
03515 
03516                                 if (vtype == 1) {
03517                                         char *expanded = NULL;
03518                                         int offset = 0;
03519                                         int ooffset = 0;
03520                                         char *ptr;
03521                                         int idx = -1;
03522                                         
03523                                         if ((expanded = switch_channel_expand_variables_check(channel, (char *) vname, var_list, api_list, recur+1)) == vname) {
03524                                                 expanded = NULL;
03525                                         } else {
03526                                                 vname = expanded;
03527                                         }
03528 
03529                                         if ((ptr = strchr(vname, ':'))) {
03530                                                 *ptr++ = '\0';
03531                                                 offset = atoi(ptr);
03532                                                 if ((ptr = strchr(ptr, ':'))) {
03533                                                         ptr++;
03534                                                         ooffset = atoi(ptr);
03535                                                 }
03536                                         }
03537 
03538                                         if ((ptr = strchr(vname, '[')) && strchr(ptr, ']')) {
03539                                                 *ptr++ = '\0';
03540                                                 idx = atoi(ptr);
03541                                         }
03542                                         
03543                                         if ((sub_val = (char *) switch_channel_get_variable_dup(channel, vname, SWITCH_TRUE, idx))) {
03544                                                 if (var_list && !switch_event_check_permission_list(var_list, vname)) {
03545                                                         sub_val = "INVALID";
03546                                                 }
03547 
03548                                                 if ((expanded_sub_val = switch_channel_expand_variables_check(channel, sub_val, var_list, api_list, recur+1)) == sub_val) {
03549                                                         expanded_sub_val = NULL;
03550                                                 } else {
03551                                                         sub_val = expanded_sub_val;
03552                                                 }
03553                                                 
03554                                                 if (offset || ooffset) {
03555                                                         cloned_sub_val = strdup(sub_val);
03556                                                         switch_assert(cloned_sub_val);
03557                                                         sub_val = cloned_sub_val;
03558                                                 }
03559 
03560                                                 if (offset >= 0) {
03561                                                         if ((size_t) offset > strlen(sub_val)) {
03562                                                                 *sub_val = '\0';
03563                                                         } else {
03564                                                                 sub_val += offset;
03565                                                         }
03566                                                 } else if ((size_t) abs(offset) <= strlen(sub_val)) {
03567                                                         sub_val = cloned_sub_val + (strlen(cloned_sub_val) + offset);
03568                                                 }
03569 
03570                                                 if (ooffset > 0 && (size_t) ooffset < strlen(sub_val)) {
03571                                                         if ((ptr = (char *) sub_val + ooffset)) {
03572                                                                 *ptr = '\0';
03573                                                         }
03574                                                 }
03575                                         }
03576 
03577                                         switch_safe_free(expanded);
03578                                 } else {
03579                                         switch_stream_handle_t stream = { 0 };
03580                                         char *expanded = NULL;
03581 
03582                                         SWITCH_STANDARD_STREAM(stream);
03583 
03584                                         if (stream.data) {
03585                                                 char *expanded_vname = NULL;
03586                                                 
03587                                                 if ((expanded_vname = switch_channel_expand_variables_check(channel, (char *) vname, var_list, api_list, recur+1)) == vname) {
03588                                                         expanded_vname = NULL;
03589                                                 } else {
03590                                                         vname = expanded_vname;
03591                                                 }
03592 
03593                                                 if ((expanded = switch_channel_expand_variables_check(channel, vval, var_list, api_list, recur+1)) == vval) {
03594                                                         expanded = NULL;
03595                                                 } else {
03596                                                         vval = expanded;
03597                                                 }
03598 
03599                                                 if (api_list && !switch_event_check_permission_list(api_list, vname)) {
03600                                                         func_val = "INVALID";
03601                                                         sub_val = "INVALID";
03602                                                 } else {
03603                                                         if (switch_api_execute(vname, vval, channel->session, &stream) == SWITCH_STATUS_SUCCESS) {
03604                                                                 func_val = stream.data;
03605                                                                 sub_val = func_val;
03606                                                         } else {
03607                                                                 free(stream.data);
03608                                                         }
03609                                                 }
03610 
03611                                                 switch_safe_free(expanded);
03612                                                 switch_safe_free(expanded_vname);
03613 
03614                                         } else {
03615                                                 switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_CRIT, "Memory Error!\n");
03616                                                 free(data);
03617                                                 free(indup);
03618                                                 return (char *) in;
03619                                         }
03620                                 }
03621                                 if ((nlen = sub_val ? strlen(sub_val) : 0)) {
03622                                         if (len + nlen >= olen) {
03623                                                 resize(nlen);
03624                                         }
03625 
03626                                         len += nlen;
03627                                         strcat(c, sub_val);
03628                                         c += nlen;
03629                                 }
03630 
03631                                 switch_safe_free(func_val);
03632                                 switch_safe_free(cloned_sub_val);
03633                                 switch_safe_free(expanded_sub_val);
03634                                 sub_val = NULL;
03635                                 vname = NULL;
03636                                 vtype = 0;
03637                                 br = 0;
03638                         }
03639                         if (len + 1 >= olen) {
03640                                 resize(1);
03641                         }
03642 
03643                         if (sp) {
03644                                 *c++ = ' ';
03645                                 sp = 0;
03646                                 len++;
03647                         }
03648 
03649                         if (*p == '$') {
03650                                 p--;
03651                         } else {
03652                                 *c++ = *p;
03653                                 len++;
03654                         }
03655                 }
03656         }
03657         free(indup);
03658 
03659         return data;
03660 }

switch_status_t switch_channel_export_variable_printf ( switch_channel_t channel,
const char *  varname,
const char *  export_varname,
const char *  fmt,
  ... 
)

Definition at line 1116 of file switch_channel.c.

References switch_assert, switch_channel_export_variable, SWITCH_STATUS_FALSE, and switch_vasprintf().

01118 {
01119         switch_status_t status = SWITCH_STATUS_FALSE;
01120         char *data = NULL;
01121         va_list ap;
01122         int ret;
01123         
01124         switch_assert(channel != NULL);
01125         
01126         va_start(ap, fmt);
01127         ret = switch_vasprintf(&data, fmt, ap);
01128         va_end(ap);
01129         
01130         if (ret == -1) {
01131                 return SWITCH_STATUS_FALSE;
01132         }
01133         
01134         status = switch_channel_export_variable(channel, varname, export_varname, data);
01135         
01136         free(data);
01137         
01138         return status;
01139 }

switch_status_t switch_channel_export_variable_var_check ( switch_channel_t channel,
const char *  varname,
const char *  val,
const char *  export_varname,
switch_bool_t  var_check 
)

Definition at line 1068 of file switch_channel.c.

References switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_channel_set_variable_var_check(), switch_core_session_strdup, SWITCH_LOG_DEBUG, switch_log_printf(), switch_mprintf(), switch_safe_free, and SWITCH_STATUS_SUCCESS.

01071 {
01072         char *var_name = NULL;
01073         const char *exports;
01074         char *var, *new_exports, *new_exports_d = NULL;
01075         int local = 1;
01076 
01077         exports = switch_channel_get_variable(channel, export_varname);
01078 
01079         var = switch_core_session_strdup(channel->session, varname);
01080 
01081         if (var) {
01082                 if (!strncasecmp(var, "nolocal:", 8)) { /* remove this later ? */
01083                         var_name = var + 8;
01084                         local = 0;
01085                 } else if (!strncasecmp(var, "_nolocal_", 9)) {
01086                         var_name = var + 9;
01087                         local = 0;
01088                 } else {
01089                         var_name = var;
01090                 }
01091         }
01092 
01093         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(channel->session), SWITCH_LOG_DEBUG, "EXPORT (%s) %s[%s]=[%s]\n", 
01094                                           export_varname, local ? "" : "(REMOTE ONLY) ",
01095                                           var_name ? var_name : "", val ? val : "UNDEF");
01096 
01097         
01098         switch_channel_set_variable_var_check(channel, var, val, var_check);
01099 
01100         if (var && val) {
01101                 if (exports) {
01102                         new_exports_d = switch_mprintf("%s,%s", exports, var);
01103                         new_exports = new_exports_d;
01104                 } else {
01105                         new_exports = var;
01106                 }
01107 
01108                 switch_channel_set_variable(channel, export_varname, new_exports);
01109 
01110                 switch_safe_free(new_exports_d);
01111         }
01112 
01113         return SWITCH_STATUS_SUCCESS;
01114 }

void switch_channel_flip_cid ( switch_channel_t channel  ) 

Definition at line 2713 of file switch_channel.c.

References SWITCH_BLANK_STRING, switch_channel_event_set_data(), switch_channel_get_name(), switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_core_strdup, switch_event_add_header_string(), SWITCH_EVENT_CALL_UPDATE, switch_event_create, switch_event_fire, SWITCH_LOG_INFO, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_SIGNAL_BOND_VARIABLE, SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, and switch_str_nil.

Referenced by switch_channel_sort_cid(), and switch_ivr_uuid_bridge().

02714 {
02715         switch_event_t *event;
02716 
02717         switch_mutex_lock(channel->profile_mutex);
02718         if (channel->caller_profile->callee_id_name) {
02719                 switch_channel_set_variable(channel, "pre_transfer_caller_id_name", channel->caller_profile->caller_id_name);
02720                 channel->caller_profile->caller_id_name = switch_core_strdup(channel->caller_profile->pool, channel->caller_profile->callee_id_name);
02721         }
02722         channel->caller_profile->callee_id_name = SWITCH_BLANK_STRING;
02723         
02724         if (channel->caller_profile->callee_id_number) {
02725                 switch_channel_set_variable(channel, "pre_transfer_caller_id_number", channel->caller_profile->caller_id_number);
02726                 channel->caller_profile->caller_id_number = switch_core_strdup(channel->caller_profile->pool, channel->caller_profile->callee_id_number);
02727         }
02728         channel->caller_profile->callee_id_number = SWITCH_BLANK_STRING;
02729         switch_mutex_unlock(channel->profile_mutex);
02730 
02731 
02732         if (switch_event_create(&event, SWITCH_EVENT_CALL_UPDATE) == SWITCH_STATUS_SUCCESS) {
02733                 const char *uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE);
02734                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Direction", "RECV");
02735 
02736                 if (uuid) {
02737                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridged-To", uuid);
02738                 }
02739                 switch_channel_event_set_data(channel, event);
02740                 switch_event_fire(&event);
02741         }
02742 
02743 
02744         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(channel->session), SWITCH_LOG_INFO, "%s Flipping CID from \"%s\" <%s> to \"%s\" <%s>\n", 
02745                                           switch_channel_get_name(channel),
02746                                           switch_str_nil(switch_channel_get_variable(channel, "pre_transfer_caller_id_name")),
02747                                           switch_str_nil(switch_channel_get_variable(channel, "pre_transfer_caller_id_number")),
02748                                           channel->caller_profile->caller_id_name,
02749                                           channel->caller_profile->caller_id_number
02750                                           );
02751 
02752 }

void switch_channel_flush_dtmf ( _In_ switch_channel_t channel  ) 

Referenced by CoreSession::flushDigits(), switch_channel_uninit(), and switch_core_session_reset().

switch_caller_extension_t* switch_channel_get_caller_extension ( switch_channel_t channel  ) 

Retrieve caller extension from a given channel.

Parameters:
channel channel to retrieve extension from
Returns:
the requested extension

Definition at line 2811 of file switch_channel.c.

References switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_channel_caller_extension_masquerade(), switch_core_standard_on_execute(), and switch_core_standard_on_hangup().

02812 {
02813         switch_caller_extension_t *extension = NULL;
02814 
02815         switch_assert(channel != NULL);
02816         switch_mutex_lock(channel->profile_mutex);
02817         if (channel->caller_profile) {
02818                 extension = channel->caller_profile->caller_extension;
02819         }
02820         switch_mutex_unlock(channel->profile_mutex);
02821         return extension;
02822 }

switch_caller_profile_t* switch_channel_get_caller_profile ( switch_channel_t channel  ) 

Retrieve the given channel's caller profile.

Parameters:
channel channel to retrieve the profile from
Returns:
the requested profile

Definition at line 2422 of file switch_channel.c.

References switch_caller_profile::hunt_caller_profile, switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by check_channel_status(), send_display(), switch_channel_build_param_string(), switch_channel_get_variable_dup(), switch_core_session_execute_exten(), switch_core_session_outgoing_channel(), switch_core_session_set_uuid(), switch_core_standard_on_routing(), switch_ivr_eavesdrop_session(), switch_ivr_enterprise_originate(), switch_ivr_generate_json_cdr(), switch_ivr_generate_xml_cdr(), switch_ivr_originate(), switch_ivr_session_transfer(), and switch_ivr_uuid_bridge().

02423 {
02424         switch_caller_profile_t *profile;
02425         switch_assert(channel != NULL);
02426         switch_mutex_lock(channel->profile_mutex);
02427         if ((profile = channel->caller_profile) && profile->hunt_caller_profile) {
02428                 profile = profile->hunt_caller_profile;
02429         }
02430         switch_mutex_unlock(channel->profile_mutex);
02431         return profile;
02432 }

switch_channel_callstate_t switch_channel_get_callstate ( switch_channel_t channel  ) 

Definition at line 243 of file switch_channel.c.

00244 {
00245         return channel->callstate;
00246 }

char* switch_channel_get_cap_string ( switch_channel_t channel  ) 

Definition at line 1553 of file switch_channel.c.

References CC_FLAG_MAX, switch_mutex_lock(), SWITCH_STANDARD_STREAM, and switch_stream_handle::write_function.

Referenced by switch_ivr_generate_json_cdr(), and switch_ivr_generate_xml_cdr().

01554 {
01555         switch_stream_handle_t stream = { 0 };
01556         char *r;
01557         int i = 0;
01558 
01559         SWITCH_STANDARD_STREAM(stream);
01560 
01561         switch_mutex_lock(channel->flag_mutex);
01562         for (i = 0; i < CC_FLAG_MAX; i++) {
01563                 if (channel->caps[i]) {
01564                         stream.write_function(&stream, "%d=%d;", i, channel->caps[i]);
01565                 }
01566         }
01567         switch_mutex_unlock(channel->flag_mutex);
01568 
01569         r = (char *) stream.data;
01570 
01571         if (end_of(r) == ';') {
01572                 end_of(r) = '\0';
01573         }
01574 
01575         return r;
01576 
01577 }

switch_call_cause_t switch_channel_get_cause ( _In_ switch_channel_t channel  ) 

return the cause code for a given channel

Parameters:
channel the channel
Returns:
the code

Referenced by abort_call(), audio_bridge_thread(), check_channel_status(), signal_bridge_on_hangup(), switch_core_session_hangup_state(), switch_core_session_reporting_state(), switch_core_standard_on_hangup(), switch_core_standard_on_reporting(), switch_ivr_multi_threaded_bridge(), switch_ivr_signal_bridge(), and wait_for_cause().

switch_call_cause_t* switch_channel_get_cause_ptr ( switch_channel_t channel  ) 

Definition at line 199 of file switch_channel.c.

00200 {
00201         return &channel->hangup_cause;
00202 }

switch_call_cause_t switch_channel_get_cause_q850 ( switch_channel_t channel  ) 

Definition at line 309 of file switch_channel.c.

References switch_channel_cause_q850().

Referenced by switch_core_session_hangup_state().

00310 {
00311         return switch_channel_cause_q850(channel->hangup_cause);
00312 }

char* switch_channel_get_flag_string ( switch_channel_t channel  ) 

Definition at line 1527 of file switch_channel.c.

References CF_FLAG_MAX, switch_mutex_lock(), SWITCH_STANDARD_STREAM, and switch_stream_handle::write_function.

Referenced by switch_ivr_generate_json_cdr(), and switch_ivr_generate_xml_cdr().

01528 {
01529         switch_stream_handle_t stream = { 0 };
01530         char *r;
01531         int i = 0;
01532 
01533         SWITCH_STANDARD_STREAM(stream);
01534 
01535         switch_mutex_lock(channel->flag_mutex);
01536         for (i = 0; i < CF_FLAG_MAX; i++) {
01537                 if (channel->flags[i]) {
01538                         stream.write_function(&stream, "%d=%d;", i, channel->flags[i]);
01539                 }
01540         }
01541         switch_mutex_unlock(channel->flag_mutex);
01542 
01543         r = (char *) stream.data;
01544 
01545         if (end_of(r) == ';') {
01546                 end_of(r) = '\0';
01547         }
01548 
01549         return r;
01550 
01551 }

const char* switch_channel_get_hold_music ( switch_channel_t channel  ) 

Definition at line 708 of file switch_channel.c.

References switch_channel_get_variable, SWITCH_HOLD_MUSIC_VARIABLE, and SWITCH_TEMP_HOLD_MUSIC_VARIABLE.

Referenced by switch_channel_get_hold_music_partner(), switch_ivr_hold(), switch_ivr_parse_event(), and switch_ivr_soft_hold().

00709 {
00710         const char *var;
00711 
00712         if (!(var = switch_channel_get_variable(channel, SWITCH_TEMP_HOLD_MUSIC_VARIABLE))) {
00713                 var = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE);
00714         }
00715 
00716         return var;
00717 }

const char* switch_channel_get_hold_music_partner ( switch_channel_t channel  ) 

Definition at line 719 of file switch_channel.c.

References switch_channel_get_hold_music(), switch_core_session_get_channel(), switch_core_session_get_partner(), switch_core_session_rwunlock(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_ivr_parse_event().

00720 {
00721         switch_core_session_t *session;
00722         const char *r = NULL;
00723 
00724         if (switch_core_session_get_partner(channel->session, &session) == SWITCH_STATUS_SUCCESS) {
00725                 r = switch_channel_get_hold_music(switch_core_session_get_channel(session));
00726                 switch_core_session_rwunlock(session);
00727         }
00728 
00729         return r;
00730 }

char* switch_channel_get_name ( switch_channel_t channel  ) 

Retrieve the name of a given channel.

Parameters:
channel channel to get name of
Returns:
the channel's name

Definition at line 932 of file switch_channel.c.

References switch_assert, and zstr.

Referenced by audio_bridge_on_consume_media(), audio_bridge_on_routing(), audio_bridge_thread(), check_channel_status(), collect_thread_run(), CoreSession::destroy(), do_flush(), exec_cb(), inband_dtmf_generate_callback(), inherit_codec(), meta_on_dtmf(), play_and_detect_input_callback(), rtp_common_read(), rtp_common_write(), setup_ringback(), signal_bridge_on_hibernate(), switch_channel_check_zrtp(), switch_channel_dequeue_dtmf(), switch_channel_event_set_basic_data(), switch_channel_flip_cid(), switch_channel_process_export(), switch_channel_queue_dtmf(), switch_channel_queue_dtmf_string(), switch_core_media_bug_add(), switch_core_media_bug_close(), switch_core_media_bug_read(), switch_core_media_bug_remove_all_function(), switch_core_session_enable_heartbeat(), switch_core_session_exec(), switch_core_session_execute_application_get_flags(), switch_core_session_execute_exten(), switch_core_session_force_locate(), switch_core_session_hangup_state(), switch_core_session_outgoing_channel(), switch_core_session_perform_destroy(), switch_core_session_perform_kill_channel(), switch_core_session_perform_receive_message(), switch_core_session_read_frame(), switch_core_session_read_lock(), switch_core_session_read_lock_hangup(), switch_core_session_recv_dtmf(), switch_core_session_run(), switch_core_session_send_dtmf(), switch_core_session_send_dtmf_string(), switch_core_session_set_read_codec(), switch_core_session_set_real_read_codec(), switch_core_session_set_uuid(), switch_core_session_thread(), switch_core_session_write_frame(), switch_core_standard_on_consume_media(), switch_core_standard_on_destroy(), switch_core_standard_on_exchange_media(), switch_core_standard_on_execute(), switch_core_standard_on_hangup(), switch_core_standard_on_hibernate(), switch_core_standard_on_init(), switch_core_standard_on_park(), switch_core_standard_on_reporting(), switch_core_standard_on_reset(), switch_core_standard_on_routing(), switch_core_standard_on_soft_execute(), switch_ivr_media(), switch_ivr_multi_threaded_bridge(), switch_ivr_originate(), switch_ivr_parse_event(), switch_ivr_play_and_detect_speech(), switch_ivr_session_transfer(), switch_ivr_soft_hold(), switch_ivr_uuid_bridge(), uuid_bridge_on_reset(), and uuid_bridge_on_soft_execute().

00933 {
00934         switch_assert(channel != NULL);
00935         return (!zstr(channel->name)) ? channel->name : "N/A";
00936 }

switch_caller_profile_t* switch_channel_get_originatee_caller_profile ( switch_channel_t channel  ) 

Retrieve the given channel's originatee caller profile.

Parameters:
channel channel to retrieve the profile from
Returns:
the requested profile

Definition at line 2529 of file switch_channel.c.

References switch_caller_profile::originatee_caller_profile, switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_channel_set_timestamps(), and switch_core_session_reporting_state().

02530 {
02531         switch_caller_profile_t *profile = NULL;
02532         switch_assert(channel != NULL);
02533 
02534         switch_mutex_lock(channel->profile_mutex);
02535         if (channel->caller_profile) {
02536                 profile = channel->caller_profile->originatee_caller_profile;
02537         }
02538         switch_mutex_unlock(channel->profile_mutex);
02539 
02540         return profile;
02541 }

switch_caller_profile_t* switch_channel_get_origination_caller_profile ( switch_channel_t channel  ) 

Retrieve the given channel's origination caller profile.

Parameters:
channel channel to retrieve the profile from
Returns:
the requested profile

Definition at line 2483 of file switch_channel.c.

References switch_caller_profile::origination_caller_profile, switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

02484 {
02485         switch_caller_profile_t *profile = NULL;
02486         switch_assert(channel != NULL);
02487 
02488         switch_mutex_lock(channel->profile_mutex);
02489         if (channel->caller_profile) {
02490                 profile = channel->caller_profile->origination_caller_profile;
02491         }
02492         switch_mutex_unlock(channel->profile_mutex);
02493 
02494         return profile;
02495 }

switch_caller_profile_t* switch_channel_get_originator_caller_profile ( switch_channel_t channel  ) 

Retrieve the given channel's originator caller profile.

Parameters:
channel channel to retrieve the profile from
Returns:
the requested profile

Definition at line 2514 of file switch_channel.c.

References switch_caller_profile::originator_caller_profile, switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_channel_set_timestamps(), and switch_core_session_reporting_state().

02515 {
02516         switch_caller_profile_t *profile = NULL;
02517         switch_assert(channel != NULL);
02518 
02519         switch_mutex_lock(channel->profile_mutex);
02520         
02521         if (channel->caller_profile) {
02522                 profile = channel->caller_profile->originator_caller_profile;
02523         }
02524         switch_mutex_unlock(channel->profile_mutex);
02525 
02526         return profile;
02527 }

void* switch_channel_get_private ( switch_channel_t channel,
const char *  key 
)

Retrieve private from a given channel.

Parameters:
channel channel to retrieve data from
key unique keyname to retrieve your private data
Returns:
void pointer to channel's private data

Definition at line 884 of file switch_channel.c.

References switch_assert, and switch_core_hash_find_locked().

Referenced by audio_bridge_on_exchange_media(), block_on_dtmf(), dtmf_callback(), generate_on_dtmf(), CoreSession::getPrivate(), hanguphook(), meta_on_dtmf(), monitor_callback(), rtp_common_read(), sb_on_dtmf(), signal_bridge_on_hangup(), speech_on_dtmf(), switch_ivr_bind_dtmf_meta_session(), switch_ivr_block_dtmf_session(), switch_ivr_clear_speech_cache(), switch_ivr_deactivate_unicast(), switch_ivr_detect_speech(), switch_ivr_detect_speech_disable_all_grammars(), switch_ivr_detect_speech_disable_grammar(), switch_ivr_detect_speech_enable_grammar(), switch_ivr_detect_speech_load_grammar(), switch_ivr_detect_speech_start_input_timers(), switch_ivr_detect_speech_unload_grammar(), switch_ivr_displace_session(), switch_ivr_get_file_handle(), switch_ivr_park(), switch_ivr_pause_detect_speech(), switch_ivr_preprocess_session(), switch_ivr_record_session(), switch_ivr_resume_detect_speech(), switch_ivr_session_audio(), switch_ivr_set_param_detect_speech(), switch_ivr_speak_text(), switch_ivr_stop_detect_speech(), switch_ivr_stop_displace_session(), switch_ivr_stop_inband_dtmf_generate_session(), switch_ivr_stop_inband_dtmf_session(), switch_ivr_stop_record_session(), switch_ivr_stop_session_audio(), switch_ivr_stop_tone_detect_session(), switch_ivr_tone_detect_session(), switch_ivr_unbind_dtmf_meta_session(), switch_ivr_unblock_dtmf_session(), switch_rtp_create(), switch_rtp_write_frame(), switch_rtp_zerocopy_read_frame(), and tone_on_dtmf().

00885 {
00886         void *val;
00887         switch_assert(channel != NULL);
00888         val = switch_core_hash_find_locked(channel->private_hash, key, channel->profile_mutex);
00889         return val;
00890 }

void* switch_channel_get_private_partner ( switch_channel_t channel,
const char *  key 
)

Definition at line 892 of file switch_channel.c.

References switch_assert, switch_channel_get_variable, switch_core_hash_find_locked(), switch_core_session_locate(), switch_core_session_rwunlock(), and SWITCH_SIGNAL_BOND_VARIABLE.

00893 {
00894         const char *uuid;
00895         void *val = NULL;
00896 
00897         switch_assert(channel != NULL);
00898 
00899         if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) || (uuid = switch_channel_get_variable(channel, "originate_signal_bond"))) {
00900                 switch_core_session_t *session;
00901                 if ((session = switch_core_session_locate(uuid))) {
00902                         val = switch_core_hash_find_locked(channel->private_hash, key, channel->profile_mutex);
00903                         switch_core_session_rwunlock(session);
00904                 }
00905         }
00906 
00907         return val;
00908 }

switch_channel_state_t switch_channel_get_running_state ( switch_channel_t channel  ) 

Definition at line 1785 of file switch_channel.c.

References switch_assert.

Referenced by switch_core_session_run(), and uuid_bridge_on_soft_execute().

01786 {
01787         switch_channel_state_t state;
01788         switch_assert(channel != NULL);
01789 
01790         state = channel->running_state;
01791 
01792         return state;
01793 }

switch_status_t switch_channel_get_scope_variables ( switch_channel_t channel,
switch_event_t **  event 
)

Definition at line 750 of file switch_channel.c.

References switch_event::headers, switch_event_header::name, switch_event::next, switch_event_header::next, switch_event_add_header_string(), SWITCH_EVENT_CHANNEL_DATA, switch_event_create_plain(), switch_event_get_header, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_event_header::value.

00751 {
00752         switch_status_t status = SWITCH_STATUS_FALSE;
00753         switch_event_t *new_event;
00754 
00755         switch_mutex_lock(channel->profile_mutex);
00756         if (channel->scope_variables) {
00757                 switch_event_t *ep;
00758                 switch_event_header_t *hp;
00759 
00760                 switch_event_create_plain(&new_event, SWITCH_EVENT_CHANNEL_DATA);
00761                 status = SWITCH_STATUS_SUCCESS;
00762                 *event = new_event;
00763 
00764                 for (ep = channel->scope_variables; ep; ep = ep->next) {
00765                         for (hp = ep->headers; hp; hp = hp->next) {
00766                                 if (!switch_event_get_header(new_event, hp->value)) {
00767                                         switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, hp->name, hp->value);
00768                                 }
00769                         }
00770                 }
00771         }
00772         switch_mutex_unlock(channel->profile_mutex);
00773 
00774         return status;
00775 }

switch_core_session_t* switch_channel_get_session ( switch_channel_t channel  ) 

Definition at line 3827 of file switch_channel.c.

References switch_assert.

03828 {
03829         switch_assert(channel);
03830         return channel->session;
03831 }

switch_channel_state_t switch_channel_get_state ( switch_channel_t channel  ) 

Get the current state of a channel in the state engine.

Parameters:
channel channel to retrieve state from
Returns:
current state of channel

Definition at line 1775 of file switch_channel.c.

References switch_assert.

Referenced by audio_bridge_on_exchange_media(), audio_bridge_thread(), check_channel_status(), check_per_channel_timeouts(), fs_channel_set_state(), CoreSession::getState(), hanguphook(), limit_state_handler(), originate_on_consume_media_transmit(), originate_on_routing(), CoreSession::setHangupHook(), signal_bridge_on_hibernate(), switch_core_session_hangup_state(), switch_core_session_perform_destroy(), switch_core_session_read_frame(), switch_core_session_read_lock_hangup(), switch_core_session_reporting_state(), switch_core_session_run(), switch_core_standard_on_execute(), switch_ivr_generate_json_cdr(), switch_ivr_generate_xml_cdr(), switch_ivr_multi_threaded_bridge(), switch_ivr_park(), switch_ivr_uuid_bridge(), switch_ivr_wait_for_answer(), and uuid_bridge_on_soft_execute().

01776 {
01777         switch_channel_state_t state;
01778         switch_assert(channel != NULL);
01779 
01780         state = channel->state;
01781 
01782         return state;
01783 }

const switch_state_handler_table_t* switch_channel_get_state_handler ( switch_channel_t channel,
int  index 
)

Retrieve an state handler tablefrom a given channel at given index level.

Parameters:
channel channel from which to retrieve the state handler table
index the index of the state handler table (start from 0)
Returns:
given channel's state handler table at given index or NULL if requested index does not exist.

Definition at line 2576 of file switch_channel.c.

References switch_assert, SWITCH_MAX_STATE_HANDLERS, switch_mutex_lock(), and switch_mutex_unlock().

02577 {
02578         const switch_state_handler_table_t *h = NULL;
02579 
02580         switch_assert(channel != NULL);
02581 
02582         if (index >= SWITCH_MAX_STATE_HANDLERS || index > channel->state_handler_index) {
02583                 return NULL;
02584         }
02585 
02586         switch_mutex_lock(channel->state_mutex);
02587         h = channel->state_handlers[index];
02588         switch_mutex_unlock(channel->state_mutex);
02589 
02590         return h;
02591 }

switch_channel_timetable_t* switch_channel_get_timetable ( _In_ switch_channel_t channel  ) 

View the timetable of a channel.

Parameters:
channel channel to retrieve timetable from
Returns:
a pointer to the channel's timetable (created, answered, etc..)

char* switch_channel_get_uuid ( switch_channel_t channel  ) 

Retrieve the given channel's unique id.

Parameters:
channel channel to retrieve the unique id from
Returns:
the unique id

Definition at line 2543 of file switch_channel.c.

References switch_assert, and switch_core_session_get_uuid().

Referenced by switch_channel_perform_hangup(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_perform_mark_ring_ready_value(), switch_channel_perform_ring_ready_value(), switch_channel_perform_set_callstate(), switch_channel_perform_set_state(), and switch_rtp_add_crypto_key().

02544 {
02545         switch_assert(channel != NULL);
02546         switch_assert(channel->session != NULL);
02547         return switch_core_session_get_uuid(channel->session);
02548 }

const char* switch_channel_get_variable_dup ( switch_channel_t channel,
const char *  varname,
switch_bool_t  dup,
int  idx 
)

Retrieve a variable from a given channel.

Parameters:
channel channel to retrieve variable from
varname the name of the variable
Returns:
the value of the requested variable

Definition at line 777 of file switch_channel.c.

References switch_event::next, switch_caller_profile::originatee_caller_profile, switch_caller_profile::originator_caller_profile, switch_assert, switch_caller_get_field_by_name(), switch_channel_get_caller_profile(), switch_core_get_variable_pdup(), switch_core_session_get_pool(), switch_core_session_strdup, switch_event_get_header_idx(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_channel_expand_variables_check(), and switch_channel_set_presence_data_vals().

00778 {
00779         const char *v = NULL, *r = NULL, *vdup = NULL;
00780         switch_assert(channel != NULL);
00781 
00782         switch_mutex_lock(channel->profile_mutex);
00783 
00784         if (channel->scope_variables) {
00785                 switch_event_t *ep;
00786 
00787                 for (ep = channel->scope_variables; ep; ep = ep->next) {
00788                         if ((v = switch_event_get_header_idx(ep, varname, idx))) {
00789                                 break;
00790                         }
00791                 }
00792         }
00793 
00794         if (!v && (!channel->variables || !(v = switch_event_get_header_idx(channel->variables, varname, idx)))) {
00795                 switch_caller_profile_t *cp = switch_channel_get_caller_profile(channel);
00796 
00797                 if (cp) {
00798                         if (!strncmp(varname, "aleg_", 5)) {
00799                                 cp = cp->originator_caller_profile;
00800                                 varname += 5;
00801                         } else if (!strncmp(varname, "bleg_", 5)) {
00802                                 cp = cp->originatee_caller_profile;
00803                                 varname += 5;
00804                         }
00805                 }
00806 
00807                 if (!cp || !(v = switch_caller_get_field_by_name(cp, varname))) {
00808                         if ((vdup = switch_core_get_variable_pdup(varname, switch_core_session_get_pool(channel->session)))) {
00809                                 v = vdup;
00810                         }
00811                 }
00812         }
00813 
00814         if (dup && v != vdup) {
00815                 if (v) {
00816                         r = switch_core_session_strdup(channel->session, v);
00817                 }
00818         } else {
00819                 r = v;
00820         }
00821 
00822         switch_mutex_unlock(channel->profile_mutex);
00823 
00824         return r;
00825 }

const char* switch_channel_get_variable_partner ( switch_channel_t channel,
const char *  varname 
)

Definition at line 827 of file switch_channel.c.

References switch_assert, switch_channel_get_variable, switch_core_session_get_channel(), switch_core_session_locate(), switch_core_session_rwunlock(), switch_core_session_strdup, SWITCH_SIGNAL_BOND_VARIABLE, and zstr.

00828 {
00829         const char *uuid;
00830         const char *val = NULL, *r = NULL;
00831         switch_assert(channel != NULL);
00832 
00833         if (!zstr(varname)) {
00834                 if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) || (uuid = switch_channel_get_variable(channel, "originate_signal_bond"))) {
00835                         switch_core_session_t *session;
00836                         if ((session = switch_core_session_locate(uuid))) {
00837                                 switch_channel_t *tchannel = switch_core_session_get_channel(session);
00838                                 val = switch_channel_get_variable(tchannel, varname);
00839                                 switch_core_session_rwunlock(session);
00840                         }
00841                 }
00842         }
00843 
00844         if (val)
00845                 r = switch_core_session_strdup(channel->session, val);
00846 
00847         return r;
00848 }

switch_status_t switch_channel_get_variables ( switch_channel_t channel,
switch_event_t **  event 
)

Definition at line 3818 of file switch_channel.c.

References switch_event_dup(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by api_hook(), switch_channel_api_on(), switch_channel_del_variable_prefix(), switch_channel_execute_on(), and switch_ivr_transfer_variable().

03819 {
03820         switch_status_t status;
03821         switch_mutex_lock(channel->profile_mutex);
03822         status = switch_event_dup(event, channel->variables);
03823         switch_mutex_unlock(channel->profile_mutex);
03824         return status;
03825 }

switch_size_t switch_channel_has_dtmf ( _In_ switch_channel_t channel  ) 

Test for presence of DTMF on a given channel.

Parameters:
channel channel to test
Returns:
number of digits in the queue

Referenced by audio_bridge_thread(), switch_core_session_reset(), switch_ivr_collect_digits_callback(), switch_ivr_collect_digits_count(), switch_ivr_eavesdrop_session(), switch_ivr_gentones(), switch_ivr_park(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_session_echo(), switch_ivr_sleep(), switch_ivr_speak_text_handle(), and switch_ivr_wait_for_answer().

switch_status_t switch_channel_init ( switch_channel_t channel,
switch_core_session_t session,
switch_channel_state_t  state,
switch_channel_flag_t  flag 
)

Connect a newly allocated channel to a session object and setup it's initial state.

Parameters:
channel the channel to initilize
session the session to connect the channel to
state the initial state of the channel
flags the initial channel flags

Definition at line 590 of file switch_channel.c.

References CS_NONE, switch_assert, switch_channel_set_flag, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_session_request_uuid().

00592 {
00593         switch_assert(channel != NULL);
00594         channel->state = state;
00595         switch_channel_set_flag(channel, flag);
00596         channel->session = session;
00597         channel->running_state = CS_NONE;
00598         return SWITCH_STATUS_SUCCESS;
00599 }

void switch_channel_mark_hold ( switch_channel_t channel,
switch_bool_t  on 
)

Definition at line 675 of file switch_channel.c.

References CF_LEG_HOLDING, switch_channel_clear_flag(), switch_channel_event_set_data(), switch_channel_get_variable, switch_channel_set_flag, switch_channel_test_flag(), switch_core_media_bug_transfer_recordings(), switch_core_session_get_partner(), switch_core_session_rwunlock(), SWITCH_EVENT_CHANNEL_HOLD, SWITCH_EVENT_CHANNEL_UNHOLD, switch_event_create, switch_event_fire, SWITCH_STATUS_SUCCESS, and switch_true().

Referenced by switch_ivr_intercept_session().

00676 {
00677         switch_event_t *event;
00678 
00679         if (!!on == !!switch_channel_test_flag(channel, CF_LEG_HOLDING)) {
00680                 goto end;
00681         }
00682         
00683         if (on) {
00684                 switch_channel_set_flag(channel, CF_LEG_HOLDING);
00685         } else {
00686                 switch_channel_clear_flag(channel, CF_LEG_HOLDING);
00687         }
00688 
00689         if (switch_event_create(&event, on ? SWITCH_EVENT_CHANNEL_HOLD : SWITCH_EVENT_CHANNEL_UNHOLD) == SWITCH_STATUS_SUCCESS) {
00690                 switch_channel_event_set_data(channel, event);
00691                 switch_event_fire(&event);
00692         }
00693 
00694  end:
00695 
00696         if (on) {
00697                 if (switch_true(switch_channel_get_variable(channel, "flip_record_on_hold"))) {
00698                         switch_core_session_t *other_session;
00699                         if (switch_core_session_get_partner(channel->session, &other_session) == SWITCH_STATUS_SUCCESS) {
00700                                 switch_core_media_bug_transfer_recordings(channel->session, other_session);
00701                                 switch_core_session_rwunlock(other_session);
00702                         }
00703                 }
00704         }
00705 
00706 }

switch_channel_state_t switch_channel_name_state ( _In_ const char *  name  ) 

Render the enum of the provided state name.

Parameters:
name the name of the state
Returns:
the enum value (numeric)

Referenced by fs_channel_set_state().

switch_status_t switch_channel_pass_callee_id ( switch_channel_t channel,
switch_channel_t other_channel 
)

Definition at line 3792 of file switch_channel.c.

References switch_assert, switch_core_strdup, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

Referenced by audio_bridge_thread(), check_channel_status(), and switch_ivr_multi_threaded_bridge().

03793 {
03794         int x = 0;
03795 
03796         switch_assert(channel);
03797         switch_assert(other_channel);
03798 
03799         switch_mutex_lock(channel->profile_mutex);
03800         switch_mutex_lock(other_channel->profile_mutex);
03801 
03802         if (!zstr(channel->caller_profile->callee_id_name)) {
03803                 other_channel->caller_profile->callee_id_name = switch_core_strdup(other_channel->caller_profile->pool, channel->caller_profile->callee_id_name);
03804                 x++;
03805         }
03806 
03807         if (!zstr(channel->caller_profile->callee_id_number)) {
03808                 other_channel->caller_profile->callee_id_number = switch_core_strdup(other_channel->caller_profile->pool, channel->caller_profile->callee_id_number);
03809                 x++;
03810         }
03811 
03812         switch_mutex_unlock(other_channel->profile_mutex);
03813         switch_mutex_unlock(channel->profile_mutex);
03814 
03815         return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
03816 }

switch_status_t switch_channel_perform_answer ( switch_channel_t channel,
const char *  file,
const char *  func,
int  line 
)

Definition at line 3337 of file switch_channel.c.

References CF_ANSWERED, CS_HANGUP, switch_core_session_message::from, switch_core_session_message::message_id, switch_assert, SWITCH_CALL_DIRECTION_OUTBOUND, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION, switch_channel_direction(), switch_channel_hangup, switch_channel_perform_mark_answered(), switch_channel_test_flag(), switch_core_session_perform_receive_message(), SWITCH_MESSAGE_INDICATE_ANSWER, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

03338 {
03339         switch_core_session_message_t msg = { 0 };
03340         switch_status_t status = SWITCH_STATUS_SUCCESS;
03341 
03342         switch_assert(channel != NULL);
03343 
03344         if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
03345                 return SWITCH_STATUS_SUCCESS;
03346         }
03347 
03348         if (channel->hangup_cause || channel->state >= CS_HANGUP) {
03349                 return SWITCH_STATUS_FALSE;
03350         }
03351 
03352         if (switch_channel_test_flag(channel, CF_ANSWERED)) {
03353                 return SWITCH_STATUS_SUCCESS;
03354         }
03355         
03356 
03357         msg.message_id = SWITCH_MESSAGE_INDICATE_ANSWER;
03358         msg.from = channel->name;
03359         status = switch_core_session_perform_receive_message(channel->session, &msg, file, func, line);
03360 
03361 
03362         if (status == SWITCH_STATUS_SUCCESS) {
03363                 switch_channel_perform_mark_answered(channel, file, func, line);
03364         } else {
03365                 switch_channel_hangup(channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
03366         }
03367 
03368         return status;
03369 }

void switch_channel_perform_audio_sync ( switch_channel_t channel,
const char *  file,
const char *  func,
int  line 
)

Definition at line 285 of file switch_channel.c.

References switch_core_session_message::_file, switch_core_session_message::_func, switch_core_session_message::_line, switch_core_session_message::from, switch_core_session_message::message_id, switch_channel_media_ready, switch_core_session_receive_message, and SWITCH_MESSAGE_INDICATE_AUDIO_SYNC.

00286 {
00287         if (switch_channel_media_ready(channel)) {
00288                 switch_core_session_message_t msg = { 0 };
00289                 msg.message_id = SWITCH_MESSAGE_INDICATE_AUDIO_SYNC;
00290                 msg.from = channel->name;
00291                 msg._file = file;
00292                 msg._func = func;
00293                 msg._line = line;
00294                 switch_core_session_receive_message(channel->session, &msg);
00295         }
00296 }

switch_channel_state_t switch_channel_perform_hangup ( switch_channel_t channel,
const char *  file,
const char *  func,
int  line,
switch_call_cause_t  hangup_cause 
)

Definition at line 2845 of file switch_channel.c.

References CCS_HANGUP, CF_BLOCK_STATE, CS_HANGUP, OCF_HANGUP, switch_assert, SWITCH_CAUSE_LOSE_RACE, switch_channel_cause2str(), switch_channel_clear_flag(), switch_channel_event_set_data(), switch_channel_get_uuid(), switch_channel_get_variable, SWITCH_CHANNEL_ID_LOG, switch_channel_presence, switch_channel_set_callstate, switch_channel_set_variable, switch_channel_set_variable_partner, switch_core_session_hangup_state(), switch_core_session_kill_channel, switch_core_session_running(), switch_core_session_signal_state_change(), switch_core_session_started(), switch_core_session_thread_launch(), switch_event_add_header_string(), SWITCH_EVENT_CHANNEL_HANGUP, switch_event_create, switch_event_fire, SWITCH_FALSE, SWITCH_LOG_NOTICE, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE, SWITCH_SIG_KILL, SWITCH_STACK_BOTTOM, and SWITCH_STATUS_SUCCESS.

02847 {
02848         int ok = 0;
02849 
02850         switch_assert(channel != NULL);
02851 
02852         /* one per customer */
02853         switch_mutex_lock(channel->state_mutex);
02854         if (!(channel->opaque_flags & OCF_HANGUP)) {
02855                 channel->opaque_flags |= OCF_HANGUP;
02856                 ok = 1;
02857         }
02858         switch_mutex_unlock(channel->state_mutex);
02859 
02860         if (!ok) {
02861                 return channel->state;
02862         }
02863 
02864         switch_channel_clear_flag(channel, CF_BLOCK_STATE);
02865 
02866         if (channel->state < CS_HANGUP) {
02867                 switch_channel_state_t last_state;
02868                 switch_event_t *event;
02869                 const char *var;
02870 
02871                 switch_mutex_lock(channel->state_mutex);
02872                 last_state = channel->state;
02873                 channel->state = CS_HANGUP;
02874                 switch_mutex_unlock(channel->state_mutex);
02875 
02876 
02877                 if (hangup_cause == SWITCH_CAUSE_LOSE_RACE) {
02878                         switch_channel_presence(channel, "unknown", "cancelled", NULL);
02879                         switch_channel_set_variable(channel, "presence_call_info", NULL);
02880                 }
02881 
02882                 switch_channel_set_callstate(channel, CCS_HANGUP);
02883                 channel->hangup_cause = hangup_cause;
02884                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Hangup %s [%s] [%s]\n",
02885                                                   channel->name, state_names[last_state], switch_channel_cause2str(channel->hangup_cause));
02886 
02887 
02888                 switch_channel_set_variable_partner(channel, "last_bridge_hangup_cause", switch_channel_cause2str(hangup_cause));
02889 
02890                 if ((var = switch_channel_get_variable(channel, SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE))) {
02891                         switch_channel_set_variable_partner(channel, "last_bridge_" SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE, var);
02892                 }
02893 
02894 
02895                 if (!switch_core_session_running(channel->session) && !switch_core_session_started(channel->session)) {
02896                         switch_core_session_thread_launch(channel->session);
02897                 }
02898 
02899                 if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_HANGUP) == SWITCH_STATUS_SUCCESS) {
02900                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Hangup-Cause", switch_channel_cause2str(hangup_cause));
02901                         switch_channel_event_set_data(channel, event);
02902                         switch_event_fire(&event);
02903                 }
02904 
02905                 switch_core_session_kill_channel(channel->session, SWITCH_SIG_KILL);
02906                 switch_core_session_signal_state_change(channel->session);
02907                 switch_core_session_hangup_state(channel->session, SWITCH_FALSE);
02908         }
02909 
02910         return channel->state;
02911 }

switch_status_t switch_channel_perform_mark_answered ( switch_channel_t channel,
const char *  file,
const char *  func,
int  line 
)

Definition at line 3253 of file switch_channel.c.

References CCS_ACTIVE, CF_ANSWERED, CF_EARLY_MEDIA, CF_PASSTHRU_PTIME_MISMATCH, CS_HANGUP, switch_assert, switch_channel_api_on(), SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE, SWITCH_CHANNEL_API_ON_MEDIA_VARIABLE, switch_channel_audio_sync, switch_channel_check_zrtp(), switch_channel_event_set_data(), switch_channel_execute_on(), SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE, switch_channel_get_uuid(), switch_channel_get_variable, SWITCH_CHANNEL_ID_LOG, switch_channel_presence, switch_channel_set_callstate, switch_channel_set_flag, switch_channel_set_variable, switch_channel_test_flag(), switch_core_session_enable_heartbeat(), switch_core_session_kill_channel, switch_core_session_locate(), switch_core_session_rwunlock(), SWITCH_ENABLE_HEARTBEAT_EVENTS_VARIABLE, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, SWITCH_EVENT_CHANNEL_ANSWER, switch_event_create, switch_event_fire, switch_is_number(), SWITCH_LOG_NOTICE, switch_log_printf(), switch_micro_time_now(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_ORIGINATOR_VARIABLE, SWITCH_PASSTHRU_PTIME_MISMATCH_VARIABLE, SWITCH_SIG_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_true().

Referenced by switch_channel_perform_answer().

03254 {
03255         switch_event_t *event;
03256         const char *uuid;
03257         switch_core_session_t *other_session;
03258         const char *var;
03259 
03260         switch_assert(channel != NULL);
03261 
03262         if (channel->hangup_cause || channel->state >= CS_HANGUP) {
03263                 return SWITCH_STATUS_FALSE;
03264         }
03265 
03266         if (switch_channel_test_flag(channel, CF_ANSWERED)) {
03267                 return SWITCH_STATUS_SUCCESS;
03268         }
03269 
03270         if (channel->caller_profile && channel->caller_profile->times) {
03271                 switch_mutex_lock(channel->profile_mutex);
03272                 channel->caller_profile->times->answered = switch_micro_time_now();
03273                 switch_mutex_unlock(channel->profile_mutex);
03274         }
03275 
03276         switch_channel_check_zrtp(channel);
03277         switch_channel_set_flag(channel, CF_ANSWERED);
03278         switch_channel_set_callstate(channel, CCS_ACTIVE);
03279 
03280         if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) {
03281                 switch_channel_event_set_data(channel, event);
03282                 switch_event_fire(&event);
03283         }
03284 
03285         /* if we're the child of another channel and the other channel is in a blocking read they will never realize we have answered so send 
03286            a SWITCH_SIG_BREAK to interrupt any blocking reads on that channel
03287          */
03288         if ((uuid = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_VARIABLE))
03289                 && (other_session = switch_core_session_locate(uuid))) {
03290                 switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK);
03291                 switch_core_session_rwunlock(other_session);
03292         }
03293 
03294         if ((var = switch_channel_get_variable(channel, SWITCH_PASSTHRU_PTIME_MISMATCH_VARIABLE))) {
03295                 switch_channel_set_flag(channel, CF_PASSTHRU_PTIME_MISMATCH);
03296         }
03297 
03298         if ((var = switch_channel_get_variable(channel, SWITCH_ENABLE_HEARTBEAT_EVENTS_VARIABLE))) {
03299                 uint32_t seconds = 60;
03300                 int tmp;
03301 
03302                 if (switch_is_number(var)) {
03303                         tmp = atoi(var);
03304                         if (tmp > 0) {
03305                                 seconds = tmp;
03306                         }
03307                 } else if (!switch_true(var)) {
03308                         seconds = 0;
03309                 }
03310 
03311                 if (seconds) {
03312                         switch_core_session_enable_heartbeat(channel->session, seconds);
03313                 }
03314         }
03315 
03316         switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ANSWER");
03317         switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Channel [%s] has been answered\n",
03318                                           channel->name);
03319 
03320 
03321         switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE);
03322 
03323         if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
03324                 switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE);
03325                 switch_channel_api_on(channel, SWITCH_CHANNEL_API_ON_MEDIA_VARIABLE);
03326         }
03327 
03328         switch_channel_api_on(channel, SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE);
03329 
03330         switch_channel_presence(channel, "unknown", "answered", NULL);
03331 
03332         switch_channel_audio_sync(channel);
03333 
03334         return SWITCH_STATUS_SUCCESS;
03335 }

switch_status_t switch_channel_perform_mark_pre_answered ( switch_channel_t channel,
const char *  file,
const char *  func,
int  line 
)

Definition at line 3007 of file switch_channel.c.

References caller_profile, CCS_EARLY, CF_ANSWERED, CF_EARLY_MEDIA, CF_PASSTHRU_PTIME_MISMATCH, switch_channel_timetable::progress_media, switch_channel_api_on(), SWITCH_CHANNEL_API_ON_MEDIA_VARIABLE, SWITCH_CHANNEL_API_ON_PRE_ANSWER_VARIABLE, switch_channel_check_zrtp(), switch_channel_event_set_data(), switch_channel_execute_on(), SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE, SWITCH_CHANNEL_EXECUTE_ON_PRE_ANSWER_VARIABLE, switch_channel_get_uuid(), switch_channel_get_variable, SWITCH_CHANNEL_ID_LOG, switch_channel_set_callstate, switch_channel_set_flag, switch_channel_set_variable, switch_channel_test_flag(), switch_core_session_get_channel(), switch_core_session_kill_channel, switch_core_session_locate(), switch_core_session_rwunlock(), SWITCH_ENDPOINT_DISPOSITION_VARIABLE, SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA, switch_event_create, switch_event_fire, SWITCH_LOG_NOTICE, switch_log_printf(), switch_micro_time_now(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_ORIGINATOR_VARIABLE, SWITCH_PASSTHRU_PTIME_MISMATCH_VARIABLE, SWITCH_SIG_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_caller_profile::times.

Referenced by switch_channel_perform_pre_answer().

03008 {
03009         switch_event_t *event;
03010         const char *var = NULL;
03011 
03012         if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED)) {
03013                 const char *uuid;
03014                 switch_core_session_t *other_session;
03015 
03016                 switch_channel_check_zrtp(channel);
03017                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Pre-Answer %s!\n", channel->name);
03018                 switch_channel_set_flag(channel, CF_EARLY_MEDIA);
03019                 switch_channel_set_callstate(channel, CCS_EARLY);
03020                 switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "EARLY MEDIA");
03021 
03022                 if (channel->caller_profile && channel->caller_profile->times) {
03023                         switch_mutex_lock(channel->profile_mutex);
03024                         channel->caller_profile->times->progress_media = switch_micro_time_now();
03025                         if (channel->caller_profile->originator_caller_profile) {
03026                                 switch_core_session_t *osession;
03027                                 if ((osession = switch_core_session_locate(channel->caller_profile->originator_caller_profile->uuid))) {
03028                                         switch_channel_t *other_channel;
03029                                         other_channel = switch_core_session_get_channel(osession);
03030                                         if (other_channel->caller_profile) {
03031                                                 other_channel->caller_profile->times->progress_media = channel->caller_profile->times->progress_media;
03032                                         }
03033                                         switch_core_session_rwunlock(osession);
03034                                 }
03035                                 channel->caller_profile->originator_caller_profile->times->progress_media = channel->caller_profile->times->progress_media;
03036                         }
03037                         switch_mutex_unlock(channel->profile_mutex);
03038                 }
03039 
03040                 if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA) == SWITCH_STATUS_SUCCESS) {
03041                         switch_channel_event_set_data(channel, event);
03042                         switch_event_fire(&event);
03043                 }
03044 
03045                 switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_PRE_ANSWER_VARIABLE);
03046                 switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE);
03047 
03048                 switch_channel_api_on(channel, SWITCH_CHANNEL_API_ON_PRE_ANSWER_VARIABLE);
03049                 switch_channel_api_on(channel, SWITCH_CHANNEL_API_ON_MEDIA_VARIABLE);
03050 
03051                 if ((var = switch_channel_get_variable(channel, SWITCH_PASSTHRU_PTIME_MISMATCH_VARIABLE))) {
03052                         switch_channel_set_flag(channel, CF_PASSTHRU_PTIME_MISMATCH);
03053                 }
03054 
03055 
03056                 /* if we're the child of another channel and the other channel is in a blocking read they will never realize we have answered so send 
03057                    a SWITCH_SIG_BREAK to interrupt any blocking reads on that channel
03058                  */
03059                 if ((uuid = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_VARIABLE))
03060                         && (other_session = switch_core_session_locate(uuid))) {
03061                         switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK);
03062                         switch_core_session_rwunlock(other_session);
03063                 }
03064 
03065                 return SWITCH_STATUS_SUCCESS;
03066         }
03067 
03068         return SWITCH_STATUS_FALSE;
03069 }

switch_status_t switch_channel_perform_mark_ring_ready_value ( switch_channel_t channel,
switch_ring_ready_t  rv,
const char *  file,
const char *  func,
int  line 
)

Definition at line 2913 of file switch_channel.c.

References caller_profile, CF_ANSWERED, CF_EARLY_MEDIA, CF_RING_READY, switch_channel_timetable::progress, switch_channel_api_on(), SWITCH_CHANNEL_API_ON_RING_VARIABLE, switch_channel_event_set_data(), switch_channel_execute_on(), SWITCH_CHANNEL_EXECUTE_ON_RING_VARIABLE, switch_channel_get_uuid(), SWITCH_CHANNEL_ID_LOG, switch_channel_set_flag_value(), switch_channel_test_flag(), switch_core_session_get_channel(), switch_core_session_locate(), switch_core_session_rwunlock(), SWITCH_EVENT_CHANNEL_PROGRESS, switch_event_create, switch_event_fire, SWITCH_LOG_NOTICE, switch_log_printf(), switch_micro_time_now(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_caller_profile::times.

Referenced by switch_channel_perform_ring_ready_value().

02916 {
02917         switch_event_t *event;
02918 
02919         if (!switch_channel_test_flag(channel, CF_RING_READY) && 
02920                 !switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED)) {
02921                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Ring-Ready %s!\n", channel->name);
02922                 switch_channel_set_flag_value(channel, CF_RING_READY, rv);
02923                 if (channel->caller_profile && channel->caller_profile->times) {
02924                         switch_mutex_lock(channel->profile_mutex);
02925                         channel->caller_profile->times->progress = switch_micro_time_now();
02926                         if (channel->caller_profile->originator_caller_profile) {
02927                                 switch_core_session_t *other_session;
02928                                 if ((other_session = switch_core_session_locate(channel->caller_profile->originator_caller_profile->uuid))) {
02929                                         switch_channel_t *other_channel;
02930                                         other_channel = switch_core_session_get_channel(other_session);
02931                                         if (other_channel->caller_profile) {
02932                                                 other_channel->caller_profile->times->progress = channel->caller_profile->times->progress;
02933                                         }
02934                                         switch_core_session_rwunlock(other_session);
02935                                 }
02936                                 channel->caller_profile->originator_caller_profile->times->progress = channel->caller_profile->times->progress;
02937                         }
02938                         switch_mutex_unlock(channel->profile_mutex);
02939                 }
02940 
02941                 if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_PROGRESS) == SWITCH_STATUS_SUCCESS) {
02942                         switch_channel_event_set_data(channel, event);
02943                         switch_event_fire(&event);
02944                 }
02945 
02946                 switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_RING_VARIABLE);
02947                 switch_channel_api_on(channel, SWITCH_CHANNEL_API_ON_RING_VARIABLE);
02948 
02949                 return SWITCH_STATUS_SUCCESS;
02950         }
02951 
02952         return SWITCH_STATUS_FALSE;
02953 }

switch_status_t switch_channel_perform_pre_answer ( switch_channel_t channel,
const char *  file,
const char *  func,
int  line 
)

Definition at line 3071 of file switch_channel.c.

References CF_ANSWERED, CF_EARLY_MEDIA, CS_HANGUP, switch_core_session_message::from, switch_core_session_message::message_id, switch_assert, SWITCH_CALL_DIRECTION_INBOUND, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION, switch_channel_direction(), switch_channel_hangup, switch_channel_perform_mark_pre_answered(), switch_channel_test_flag(), switch_core_session_perform_receive_message(), SWITCH_MESSAGE_INDICATE_PROGRESS, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

03072 {
03073         switch_core_session_message_t msg = { 0 };
03074         switch_status_t status = SWITCH_STATUS_SUCCESS;
03075 
03076         switch_assert(channel != NULL);
03077 
03078         if (channel->hangup_cause || channel->state >= CS_HANGUP) {
03079                 return SWITCH_STATUS_FALSE;
03080         }
03081 
03082         if (switch_channel_test_flag(channel, CF_ANSWERED)) {
03083                 return SWITCH_STATUS_SUCCESS;
03084         }
03085 
03086         if (switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
03087                 return SWITCH_STATUS_SUCCESS;
03088         }
03089 
03090         if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) {
03091                 msg.message_id = SWITCH_MESSAGE_INDICATE_PROGRESS;
03092                 msg.from = channel->name;
03093                 status = switch_core_session_perform_receive_message(channel->session, &msg, file, func, line);
03094         }
03095 
03096         if (status == SWITCH_STATUS_SUCCESS) {
03097                 switch_channel_perform_mark_pre_answered(channel, file, func, line);
03098         } else {
03099                 switch_channel_hangup(channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
03100         }
03101 
03102         return status;
03103 }

void switch_channel_perform_presence ( switch_channel_t channel,
const char *  rpid,
const char *  status,
const char *  id,
const char *  file,
const char *  func,
int  line 
)

Fire A presence event for the channel.

Parameters:
channel the channel to initilize
rpid the rpid if for the icon to use
status the status message
id presence id

Definition at line 601 of file switch_channel.c.

References CF_ANSWERED, SWITCH_CALL_DIRECTION_OUTBOUND, switch_channel_event_set_data(), switch_channel_get_variable, switch_channel_test_flag(), switch_channel_up_nosig, switch_event_add_header(), switch_event_add_header_string(), switch_event_create, switch_event_fire, SWITCH_EVENT_PRESENCE_IN, SWITCH_EVENT_PRESENCE_OUT, SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, and switch_true().

00603 {
00604         switch_event_t *event;
00605         switch_event_types_t type = SWITCH_EVENT_PRESENCE_IN;
00606         const char *call_info = NULL;
00607         char *call_info_state = "active";
00608 
00609         if (!status) {
00610                 type = SWITCH_EVENT_PRESENCE_OUT;
00611         }
00612 
00613         if (!id) {
00614                 id = switch_channel_get_variable(channel, "presence_id");
00615         }
00616 
00617         if (!id) {
00618                 return;
00619         }
00620 
00621         call_info = switch_channel_get_variable(channel, "presence_call_info");
00622 
00623         if (switch_event_create(&event, type) == SWITCH_STATUS_SUCCESS) {
00624                 switch_channel_event_set_data(channel, event);
00625                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", "any");
00626                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", __FILE__);
00627                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", id);
00628                 if (type == SWITCH_EVENT_PRESENCE_IN) {
00629                         if (!rpid) {
00630                                 rpid = "unknown";
00631                         }
00632                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
00633                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", status);
00634                 }
00635                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
00636                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
00637 
00638 
00639                 if (!switch_channel_up_nosig(channel)) {
00640                         call_info_state = "idle";
00641                 } else if (!strcasecmp(status, "hold-private")) {
00642                         call_info_state = "held-private";
00643                 } else if (!strcasecmp(status, "hold")) {
00644                         call_info_state = "held";
00645                 } else if (!switch_channel_test_flag(channel, CF_ANSWERED)) {
00646                         if (channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND) {
00647                                 call_info_state = "progressing";
00648                         } else {
00649                                 call_info_state = "alerting";
00650                         }
00651                 }
00652                 
00653                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "presence-call-info-state", call_info_state);
00654                 
00655                 if (call_info) {
00656                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "presence-call-info", call_info);
00657                 }
00658 
00659                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "presence-call-direction",
00660                                                                            channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
00661 
00662                 switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", channel->event_count++);
00663                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Calling-File", file);
00664                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Calling-Function", func);
00665                 switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Presence-Calling-Line", "%d", line);
00666 
00667                 if (switch_true(switch_channel_get_variable(channel, "presence_privacy"))) {
00668                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Privacy", "true");
00669                 }
00670 
00671                 switch_event_fire(&event);
00672         }
00673 }

switch_status_t switch_channel_perform_ring_ready_value ( switch_channel_t channel,
switch_ring_ready_t  rv,
const char *  file,
const char *  func,
int  line 
)

Definition at line 3105 of file switch_channel.c.

References CF_ANSWERED, CF_EARLY_MEDIA, CS_HANGUP, switch_core_session_message::from, switch_core_session_message::message_id, switch_core_session_message::numeric_arg, switch_assert, SWITCH_CALL_DIRECTION_INBOUND, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION, switch_channel_direction(), switch_channel_get_uuid(), switch_channel_hangup, SWITCH_CHANNEL_ID_LOG, switch_channel_perform_mark_ring_ready_value(), switch_channel_test_flag(), switch_core_session_perform_receive_message(), SWITCH_LOG_NOTICE, switch_log_printf(), SWITCH_MESSAGE_INDICATE_RINGING, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

03107 {
03108         switch_core_session_message_t msg = { 0 };
03109         switch_status_t status = SWITCH_STATUS_SUCCESS;
03110 
03111         switch_assert(channel != NULL);
03112 
03113         if (channel->hangup_cause || channel->state >= CS_HANGUP) {
03114                 return SWITCH_STATUS_FALSE;
03115         }
03116 
03117         if (switch_channel_test_flag(channel, CF_ANSWERED)) {
03118                 return SWITCH_STATUS_SUCCESS;
03119         }
03120 
03121         if (switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
03122                 return SWITCH_STATUS_SUCCESS;
03123         }
03124 
03125         if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) {
03126                 msg.message_id = SWITCH_MESSAGE_INDICATE_RINGING;
03127                 msg.from = channel->name;
03128                 msg.numeric_arg = rv;
03129                 status = switch_core_session_perform_receive_message(channel->session, &msg, file, func, line);
03130         }
03131 
03132         if (status == SWITCH_STATUS_SUCCESS) {
03133                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Ring Ready %s!\n", channel->name);
03134                 switch_channel_perform_mark_ring_ready_value(channel, rv, file, func, line);
03135         } else {
03136                 switch_channel_hangup(channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
03137         }
03138 
03139         return status;
03140 }

void switch_channel_perform_set_callstate ( switch_channel_t channel,
switch_channel_callstate_t  callstate,
const char *  file,
const char *  func,
int  line 
)

Definition at line 221 of file switch_channel.c.

References switch_channel_callstate2str(), switch_channel_event_set_data(), switch_channel_get_uuid(), SWITCH_CHANNEL_ID_LOG, switch_event_add_header(), switch_event_add_header_string(), SWITCH_EVENT_CHANNEL_CALLSTATE, switch_event_create, switch_event_fire, SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_STACK_BOTTOM, and SWITCH_STATUS_SUCCESS.

00223 {
00224         switch_event_t *event;
00225         switch_channel_callstate_t o_callstate = channel->callstate;
00226 
00227         if (o_callstate == callstate) return;
00228         
00229         channel->callstate = callstate;
00230         
00231         switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_DEBUG,
00232                                           "(%s) Callstate Change %s -> %s\n", channel->name, 
00233                                           switch_channel_callstate2str(o_callstate), switch_channel_callstate2str(callstate));
00234         
00235         if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_CALLSTATE) == SWITCH_STATUS_SUCCESS) {
00236                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Original-Channel-Call-State", switch_channel_callstate2str(o_callstate));
00237                 switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Call-State-Number", "%d", callstate);
00238                 switch_channel_event_set_data(channel, event);
00239                 switch_event_fire(&event);
00240         }
00241 }

switch_channel_state_t switch_channel_perform_set_running_state ( switch_channel_t channel,
switch_channel_state_t  state,
const char *  file,
const char *  func,
int  line 
)

Definition at line 1883 of file switch_channel.c.

References CF_FLAG_MAX, and switch_mutex_lock().

01885 {
01886         int x;
01887 
01888         switch_mutex_lock(channel->flag_mutex);
01889         if (channel->state_flags[0]) {
01890                 for (x = 1; x < CF_FLAG_MAX; x++) {
01891                         if (channel->state_flags[x]) {
01892                                 channel->flags[x] = 1;
01893                                 channel->state_flags[x] = 0;
01894                         }
01895                 }
01896                 channel->state_flags[0] = 0;
01897         }
01898         switch_mutex_unlock(channel->flag_mutex);
01899 
01900         switch_channel_clear_flag(channel, CF_TAGGED);
01901         
01902 
01903         switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_DEBUG, "(%s) Running State Change %s\n",
01904                                           channel->name, state_names[state]);
01905 
01906         switch_mutex_lock(channel->state_mutex);
01907 
01908         channel->running_state = state;
01909 
01910         if (state == CS_ROUTING || state == CS_HANGUP) {
01911                 switch_channel_presence(channel, "unknown", (const char *) state_names[state], NULL);
01912         }
01913 
01914         if (state <= CS_DESTROY) {
01915                 switch_event_t *event;
01916 
01917                 if (state < CS_HANGUP) {
01918                         if (state == CS_ROUTING) {
01919                                 switch_channel_set_callstate(channel, CCS_RINGING);
01920                         } else if (switch_channel_test_flag(channel, CF_ANSWERED)) {
01921                                 switch_channel_set_callstate(channel, CCS_ACTIVE);
01922                         } else if (switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
01923                                 switch_channel_set_callstate(channel, CCS_EARLY);
01924                         }
01925                 }
01926 
01927                 if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_STATE) == SWITCH_STATUS_SUCCESS) {
01928                         if (state == CS_ROUTING) {
01929                                 switch_channel_event_set_data(channel, event);
01930                         } else {
01931                                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-State", switch_channel_state_name(state));
01932                                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-State", switch_channel_callstate2str(channel->callstate));
01933                                 switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State-Number", "%d", state);
01934                                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Name", channel->name);
01935                                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(channel->session));
01936                                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Call-Direction",
01937                                                                                            channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
01938                                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Call-Direction",
01939                                                                                            channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
01940 
01941                                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-HIT-Dialplan", 
01942                                                                                            switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND ||
01943                                                                                            switch_channel_test_flag(channel, CF_DIALPLAN) ? "true" : "false");
01944                                 
01945                                 if (switch_channel_down_nosig(channel)) {
01946                                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "hangup");
01947                                 } else if (switch_channel_test_flag(channel, CF_ANSWERED)) {
01948                                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "answered");
01949                                 } else if (switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
01950                                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "early");
01951                                 } else {
01952                                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "ringing");
01953                                 }
01954                         }
01955                         switch_event_fire(&event);
01956                 }
01957         }
01958 
01959         switch_mutex_unlock(channel->state_mutex);
01960 
01961         return (switch_channel_state_t) SWITCH_STATUS_SUCCESS;
01962 }

switch_channel_state_t switch_channel_perform_set_state ( switch_channel_t channel,
const char *  file,
const char *  func,
int  line,
switch_channel_state_t  state 
)

Definition at line 1964 of file switch_channel.c.

References CS_CONSUME_MEDIA, CS_DESTROY, CS_EXCHANGE_MEDIA, CS_EXECUTE, CS_HANGUP, CS_HIBERNATE, CS_INIT, CS_NEW, CS_PARK, CS_REPORTING, CS_RESET, CS_ROUTING, CS_SOFT_EXECUTE, switch_assert, SWITCH_CAUSE_NORMAL_CLEARING, switch_channel_get_uuid(), SWITCH_CHANNEL_ID_LOG, switch_core_session_signal_state_change(), SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_LOG_WARNING, switch_mutex_lock(), and switch_mutex_unlock().

01966 {
01967         switch_channel_state_t last_state;
01968         int ok = 0;
01969 
01970         switch_assert(channel != NULL);
01971         switch_assert(state <= CS_DESTROY);
01972         switch_mutex_lock(channel->state_mutex);
01973 
01974         last_state = channel->state;
01975         switch_assert(last_state <= CS_DESTROY);
01976 
01977         if (last_state == state) {
01978                 goto done;
01979         }
01980 
01981         if (last_state >= CS_HANGUP && state < last_state) {
01982                 goto done;
01983         }
01984 
01985         /* STUB for more dev
01986            case CS_INIT:
01987            switch(state) {
01988 
01989            case CS_NEW:
01990            case CS_INIT:
01991            case CS_EXCHANGE_MEDIA:
01992            case CS_SOFT_EXECUTE:
01993            case CS_ROUTING:
01994            case CS_EXECUTE:
01995            case CS_HANGUP:
01996            case CS_DESTROY:
01997 
01998            default:
01999            break;
02000            }
02001            break;
02002          */
02003 
02004         switch (last_state) {
02005         case CS_NEW:
02006         case CS_RESET:
02007                 switch (state) {
02008                 default:
02009                         ok++;
02010                         break;
02011                 }
02012                 break;
02013 
02014         case CS_INIT:
02015                 switch (state) {
02016                 case CS_EXCHANGE_MEDIA:
02017                 case CS_SOFT_EXECUTE:
02018                 case CS_ROUTING:
02019                 case CS_EXECUTE:
02020                 case CS_PARK:
02021                 case CS_CONSUME_MEDIA:
02022                 case CS_HIBERNATE:
02023                 case CS_RESET:
02024                         ok++;
02025                 default:
02026                         break;
02027                 }
02028                 break;
02029 
02030         case CS_EXCHANGE_MEDIA:
02031                 switch (state) {
02032                 case CS_SOFT_EXECUTE:
02033                 case CS_ROUTING:
02034                 case CS_EXECUTE:
02035                 case CS_PARK:
02036                 case CS_CONSUME_MEDIA:
02037                 case CS_HIBERNATE:
02038                 case CS_RESET:
02039                         ok++;
02040                 default:
02041                         break;
02042                 }
02043                 break;
02044 
02045         case CS_SOFT_EXECUTE:
02046                 switch (state) {
02047                 case CS_EXCHANGE_MEDIA:
02048                 case CS_ROUTING:
02049                 case CS_EXECUTE:
02050                 case CS_PARK:
02051                 case CS_CONSUME_MEDIA:
02052                 case CS_HIBERNATE:
02053                 case CS_RESET:
02054                         ok++;
02055                 default:
02056                         break;
02057                 }
02058                 break;
02059 
02060         case CS_PARK:
02061                 switch (state) {
02062                 case CS_EXCHANGE_MEDIA:
02063                 case CS_ROUTING:
02064                 case CS_EXECUTE:
02065                 case CS_SOFT_EXECUTE:
02066                 case CS_HIBERNATE:
02067                 case CS_RESET:
02068                 case CS_CONSUME_MEDIA:
02069                         ok++;
02070                 default:
02071                         break;
02072                 }
02073                 break;
02074 
02075         case CS_CONSUME_MEDIA:
02076                 switch (state) {
02077                 case CS_EXCHANGE_MEDIA:
02078                 case CS_ROUTING:
02079                 case CS_EXECUTE:
02080                 case CS_SOFT_EXECUTE:
02081                 case CS_HIBERNATE:
02082                 case CS_RESET:
02083                 case CS_PARK:
02084                         ok++;
02085                 default:
02086                         break;
02087                 }
02088                 break;
02089         case CS_HIBERNATE:
02090                 switch (state) {
02091                 case CS_EXCHANGE_MEDIA:
02092                 case CS_INIT:
02093                 case CS_ROUTING:
02094                 case CS_EXECUTE:
02095                 case CS_SOFT_EXECUTE:
02096                 case CS_PARK:
02097                 case CS_CONSUME_MEDIA:
02098                 case CS_RESET:
02099                         ok++;
02100                 default:
02101                         break;
02102                 }
02103                 break;
02104 
02105         case CS_ROUTING:
02106                 switch (state) {
02107                 case CS_EXCHANGE_MEDIA:
02108                 case CS_EXECUTE:
02109                 case CS_SOFT_EXECUTE:
02110                 case CS_PARK:
02111                 case CS_CONSUME_MEDIA:
02112                 case CS_HIBERNATE:
02113                 case CS_RESET:
02114                         ok++;
02115                 default:
02116                         break;
02117                 }
02118                 break;
02119 
02120         case CS_EXECUTE:
02121                 switch (state) {
02122                 case CS_EXCHANGE_MEDIA:
02123                 case CS_SOFT_EXECUTE:
02124                 case CS_ROUTING:
02125                 case CS_PARK:
02126                 case CS_CONSUME_MEDIA:
02127                 case CS_HIBERNATE:
02128                 case CS_RESET:
02129                         ok++;
02130                 default:
02131                         break;
02132                 }
02133                 break;
02134 
02135         case CS_HANGUP:
02136                 switch (state) {
02137                 case CS_REPORTING:
02138                 case CS_DESTROY:
02139                         ok++;
02140                 default:
02141                         break;
02142                 }
02143                 break;
02144 
02145         case CS_REPORTING:
02146                 switch (state) {
02147                 case CS_DESTROY:
02148                         ok++;
02149                 default:
02150                         break;
02151                 }
02152                 break;
02153 
02154         default:
02155                 break;
02156 
02157         }
02158 
02159         if (ok) {
02160                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_DEBUG, "(%s) State Change %s -> %s\n",
02161                                                   channel->name, state_names[last_state], state_names[state]);
02162 
02163                 channel->state = state;
02164 
02165                 if (state == CS_HANGUP && !channel->hangup_cause) {
02166                         channel->hangup_cause = SWITCH_CAUSE_NORMAL_CLEARING;
02167                 }
02168 
02169                 if (state <= CS_DESTROY) {
02170                         switch_core_session_signal_state_change(channel->session);
02171                 }
02172         } else {
02173                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_WARNING,
02174                                                   "(%s) Invalid State Change %s -> %s\n", channel->name, state_names[last_state], state_names[state]);
02175                 /* we won't tolerate an invalid state change so we can make sure we are as robust as a nice cup of dark coffee! */
02176                 /* not cool lets crash this bad boy and figure out wtf is going on */
02177                 switch_assert(channel->state >= CS_HANGUP);
02178         }
02179   done:
02180 
02181         switch_mutex_unlock(channel->state_mutex);
02182         return channel->state;
02183 }

void switch_channel_process_export ( switch_channel_t channel,
switch_channel_t peer_channel,
switch_event_t var_event,
const char *  export_varname 
)

Definition at line 1011 of file switch_channel.c.

References switch_channel_get_name(), switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_core_session_strdup, switch_event_add_header_string(), switch_event_del_header, SWITCH_LOG_DEBUG, switch_log_printf(), switch_separate_string(), SWITCH_STACK_BOTTOM, and zstr.

Referenced by check_bridge_export(), switch_ivr_enterprise_originate(), and switch_ivr_originate().

01013 {
01014 
01015         const char *export_vars = switch_channel_get_variable(channel, export_varname);
01016         char *cptmp = switch_core_session_strdup(channel->session, export_vars);
01017         int argc;
01018         char *argv[256];
01019 
01020         if (zstr(export_vars)) return;
01021 
01022 
01023         if (var_event) {
01024                 switch_event_del_header(var_event, export_varname);
01025                 switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, export_varname, export_vars);
01026         }
01027         
01028         if (peer_channel) {
01029                 switch_channel_set_variable(peer_channel, export_varname, export_vars);
01030         }
01031 
01032         if ((argc = switch_separate_string(cptmp, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
01033                 int x;
01034                 
01035                 for (x = 0; x < argc; x++) {
01036                         const char *vval;
01037                         if ((vval = switch_channel_get_variable(channel, argv[x]))) {
01038                                 char *vvar = argv[x];
01039                                 if (!strncasecmp(vvar, "nolocal:", 8)) { /* remove this later ? */
01040                                         vvar += 8;
01041                                 } else if (!strncasecmp(vvar, "_nolocal_", 9)) {
01042                                         vvar += 9;
01043                                 }
01044                                 if (var_event) {
01045                                         switch_event_del_header(var_event, vvar);
01046                                         switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, vvar, vval);
01047                                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(channel->session), SWITCH_LOG_DEBUG, 
01048                                                                           "%s EXPORTING[%s] [%s]=[%s] to event\n", 
01049                                                                           switch_channel_get_name(channel), 
01050                                                                           export_varname,
01051                                                                           vvar, vval);
01052                                 }
01053                                 if (peer_channel) {
01054                                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(channel->session), SWITCH_LOG_DEBUG, 
01055                                                                           "%s EXPORTING[%s] [%s]=[%s] to %s\n", 
01056                                                                           switch_channel_get_name(channel), 
01057                                                                           export_varname,
01058                                                                           vvar, vval, switch_channel_get_name(peer_channel));
01059                                         switch_channel_set_variable(peer_channel, vvar, vval);
01060                                 }
01061                         }
01062                 }
01063         }
01064 
01065 
01066 }

switch_status_t switch_channel_queue_dtmf ( _In_ switch_channel_t channel,
_In_ const switch_dtmf_t dtmf 
)

Queue DTMF on a given channel.

Parameters:
channel channel to queue DTMF to
dtmf digit
Returns:
SWITCH_STATUS_SUCCESS if successful

Referenced by inband_dtmf_callback(), speech_thread(), and switch_channel_queue_dtmf_string().

switch_status_t switch_channel_queue_dtmf_string ( _In_ switch_channel_t channel,
_In_ const char *  dtmf_string 
)

void switch_channel_restart ( switch_channel_t channel  ) 

Definition at line 2630 of file switch_channel.c.

References CS_EXECUTE, CS_RESET, switch_channel_set_state, and switch_channel_wait_for_state_timeout().

02631 {
02632         switch_channel_set_state(channel, CS_RESET);
02633         switch_channel_wait_for_state_timeout(channel, CS_RESET, 5000);
02634         switch_channel_set_state(channel, CS_EXECUTE);
02635 }

void switch_channel_set_app_flag_key ( const char *  app,
switch_channel_t channel,
uint32_t  flags 
)

Definition at line 1651 of file switch_channel.c.

References switch_assert, switch_core_hash_find(), switch_core_hash_init, switch_core_hash_insert(), switch_core_session_alloc, switch_core_session_get_pool(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_ivr_eavesdrop_update_display().

01652 {
01653         uint32_t *flagp = NULL;
01654         switch_byte_t new = 0;
01655 
01656         switch_assert(channel != NULL);
01657         switch_mutex_lock(channel->flag_mutex);
01658 
01659         if (!channel->app_flag_hash) {
01660                 switch_core_hash_init(&channel->app_flag_hash, switch_core_session_get_pool(channel->session));
01661                 new++;
01662         }
01663         
01664         if (new || !(flagp = switch_core_hash_find(channel->app_flag_hash, key))) {
01665                 flagp = switch_core_session_alloc(channel->session, sizeof(uint32_t));
01666                 switch_core_hash_insert(channel->app_flag_hash, key, flagp);
01667         }
01668 
01669         switch_assert(flagp);
01670         *flagp |= flags;
01671 
01672         switch_mutex_unlock(channel->flag_mutex);
01673 }

void switch_channel_set_bridge_time ( switch_channel_t channel  ) 

Definition at line 2825 of file switch_channel.c.

References switch_micro_time_now(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by audio_bridge_thread(), and switch_ivr_signal_bridge().

02826 {
02827         switch_mutex_lock(channel->profile_mutex);
02828         if (channel->caller_profile && channel->caller_profile->times) {
02829                 channel->caller_profile->times->bridged = switch_micro_time_now();
02830         }
02831         switch_mutex_unlock(channel->profile_mutex);
02832 }

void switch_channel_set_caller_extension ( switch_channel_t channel,
switch_caller_extension_t caller_extension 
)

Assign a caller extension to a given channel.

Parameters:
channel channel to assign extension to
caller_extension extension to assign

Definition at line 2798 of file switch_channel.c.

References switch_assert, switch_channel_sort_cid(), switch_mutex_lock(), switch_mutex_unlock(), and SWITCH_TRUE.

Referenced by audio_bridge_thread(), switch_channel_caller_extension_masquerade(), and switch_core_standard_on_routing().

02799 {
02800         switch_assert(channel != NULL);
02801 
02802         switch_channel_sort_cid(channel, SWITCH_TRUE);
02803         
02804         switch_mutex_lock(channel->profile_mutex);
02805         caller_extension->next = channel->caller_profile->caller_extension;
02806         channel->caller_profile->caller_extension = caller_extension;
02807         switch_mutex_unlock(channel->profile_mutex);
02808 }

void switch_channel_set_caller_profile ( switch_channel_t channel,
switch_caller_profile_t caller_profile 
)

Set the given channel's caller profile.

Parameters:
channel channel to assign the profile to
caller_profile the profile to assign

Definition at line 2372 of file switch_channel.c.

References switch_assert, switch_caller_extension_clone(), switch_core_session_alloc, switch_core_session_get_uuid(), switch_core_session_strdup, switch_core_sprintf(), switch_micro_time_now(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_channel_caller_extension_masquerade(), and switch_ivr_session_transfer().

02373 {
02374         char *uuid = NULL;
02375         switch_assert(channel != NULL);
02376         switch_assert(channel->session != NULL);
02377         switch_mutex_lock(channel->profile_mutex);
02378         switch_assert(caller_profile != NULL);
02379 
02380         caller_profile->direction = channel->direction;
02381         uuid = switch_core_session_get_uuid(channel->session);
02382 
02383         if (!caller_profile->uuid || strcasecmp(caller_profile->uuid, uuid)) {
02384                 caller_profile->uuid = switch_core_session_strdup(channel->session, uuid);
02385         }
02386 
02387         if (!caller_profile->chan_name || strcasecmp(caller_profile->chan_name, channel->name)) {
02388                 caller_profile->chan_name = switch_core_session_strdup(channel->session, channel->name);
02389         }
02390 
02391         if (!caller_profile->context) {
02392                 caller_profile->context = switch_core_session_strdup(channel->session, "default");
02393         }
02394 
02395         if (!caller_profile->times) {
02396                 caller_profile->times = (switch_channel_timetable_t *) switch_core_session_alloc(channel->session, sizeof(*caller_profile->times));
02397                 caller_profile->times->profile_created = switch_micro_time_now();
02398         }
02399 
02400         if (channel->caller_profile && channel->caller_profile->times) {
02401                 channel->caller_profile->times->transferred = caller_profile->times->profile_created;
02402                 caller_profile->times->answered = channel->caller_profile->times->answered;
02403                 caller_profile->times->progress = channel->caller_profile->times->progress;
02404                 caller_profile->times->progress_media = channel->caller_profile->times->progress_media;
02405                 caller_profile->times->created = channel->caller_profile->times->created;
02406                 caller_profile->times->hungup = channel->caller_profile->times->hungup;
02407                 if (channel->caller_profile->caller_extension) {
02408                         switch_caller_extension_clone(&caller_profile->caller_extension, channel->caller_profile->caller_extension, caller_profile->pool);
02409                 }
02410         } else {
02411                 caller_profile->times->created = switch_micro_time_now();
02412         }
02413 
02414 
02415         caller_profile->next = channel->caller_profile;
02416         channel->caller_profile = caller_profile;
02417         caller_profile->profile_index = switch_core_sprintf(caller_profile->pool, "%d", ++channel->profile_index);
02418 
02419         switch_mutex_unlock(channel->profile_mutex);
02420 }

void switch_channel_set_cap_value ( switch_channel_t channel,
switch_channel_cap_t  cap,
uint32_t  value 
)

Definition at line 1483 of file switch_channel.c.

References switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_session_request_xml().

01484 {
01485         switch_assert(channel);
01486         switch_assert(channel->flag_mutex);
01487 
01488         switch_mutex_lock(channel->flag_mutex);
01489         channel->caps[cap] = value;
01490         switch_mutex_unlock(channel->flag_mutex);
01491 }

switch_bool_t switch_channel_set_flag_partner ( switch_channel_t channel,
switch_channel_flag_t  flag 
)

Set given flag(s) on a given channel's bridge partner.

Parameters:
channel channel to derive the partner channel to set flag on
flag to set
Returns:
true if the flag was set

Definition at line 1354 of file switch_channel.c.

References switch_assert, switch_channel_get_variable, switch_channel_set_flag, switch_core_session_get_channel(), switch_core_session_locate(), switch_core_session_rwunlock(), SWITCH_FALSE, SWITCH_SIGNAL_BOND_VARIABLE, and SWITCH_TRUE.

01355 {
01356         const char *uuid;
01357 
01358         switch_assert(channel != NULL);
01359 
01360         if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) || (uuid = switch_channel_get_variable(channel, "originate_signal_bond"))) {
01361                 switch_core_session_t *session;
01362                 if ((session = switch_core_session_locate(uuid))) {
01363                         switch_channel_set_flag(switch_core_session_get_channel(session), flag);
01364                         switch_core_session_rwunlock(session);
01365                         return SWITCH_TRUE;
01366                 }
01367         }
01368 
01369         return SWITCH_FALSE;
01370 }

void switch_channel_set_flag_recursive ( switch_channel_t channel,
switch_channel_flag_t  flag 
)

Definition at line 1610 of file switch_channel.c.

References CF_OUTBOUND, CF_RECOVERED, switch_assert, switch_channel_set_variable, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_ivr_multi_threaded_bridge(), switch_ivr_parse_event(), and switch_ivr_signal_bridge().

01611 {
01612         switch_assert(channel);
01613         switch_assert(channel->flag_mutex);
01614 
01615         switch_mutex_lock(channel->flag_mutex);
01616         channel->flags[flag]++;
01617         switch_mutex_unlock(channel->flag_mutex);
01618 
01619         if (flag == CF_OUTBOUND) {
01620                 switch_channel_set_variable(channel, "is_outbound", "true");
01621         }
01622 
01623         if (flag == CF_RECOVERED) {
01624                 switch_channel_set_variable(channel, "recovered", "true");
01625         }
01626 }

void switch_channel_set_flag_value ( switch_channel_t channel,
switch_channel_flag_t  flag,
uint32_t  value 
)

Set given flag(s) on a given channel.

Parameters:
channel channel on which to set flag
flag or'd list of flags to set

Definition at line 1579 of file switch_channel.c.

References CCS_HELD, CF_ANSWERED, CF_LEG_HOLDING, CF_OUTBOUND, CF_RECOVERED, switch_assert, switch_channel_set_callstate, switch_channel_set_variable, switch_mutex_lock(), switch_mutex_unlock(), and switch_time_now().

Referenced by switch_channel_perform_mark_ring_ready_value(), and switch_core_session_request_xml().

01580 {
01581         int HELD = 0;
01582         
01583         switch_assert(channel);
01584         switch_assert(channel->flag_mutex);
01585 
01586         switch_mutex_lock(channel->flag_mutex);
01587         if (flag == CF_LEG_HOLDING && !channel->flags[flag] && channel->flags[CF_ANSWERED]) {
01588                 HELD = 1;
01589         }
01590         channel->flags[flag] = value;
01591         switch_mutex_unlock(channel->flag_mutex);
01592 
01593         if (HELD) {
01594                 switch_channel_set_callstate(channel, CCS_HELD);
01595                 switch_mutex_lock(channel->profile_mutex);
01596                 channel->caller_profile->times->last_hold = switch_time_now();
01597                 switch_mutex_unlock(channel->profile_mutex);
01598         }
01599 
01600         if (flag == CF_OUTBOUND) {
01601                 switch_channel_set_variable(channel, "is_outbound", "true");
01602         }
01603 
01604         if (flag == CF_RECOVERED) {
01605                 switch_channel_set_variable(channel, "recovered", "true");
01606         }
01607 
01608 }

void switch_channel_set_hangup_time ( switch_channel_t channel  ) 

Definition at line 2835 of file switch_channel.c.

References switch_micro_time_now(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_session_hangup_state().

02836 {
02837         if (channel->caller_profile && channel->caller_profile->times && !channel->caller_profile->times->hungup) {
02838                 switch_mutex_lock(channel->profile_mutex);
02839                 channel->caller_profile->times->hungup = switch_micro_time_now();
02840                 switch_mutex_unlock(channel->profile_mutex);
02841         }
02842 }

void switch_channel_set_hunt_caller_profile ( switch_channel_t channel,
switch_caller_profile_t caller_profile 
)

Definition at line 2453 of file switch_channel.c.

References switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_session_execute_exten().

02454 {
02455         switch_assert(channel != NULL);
02456         switch_assert(channel->caller_profile != NULL);
02457 
02458         switch_mutex_lock(channel->profile_mutex);
02459 
02460         channel->caller_profile->hunt_caller_profile = NULL;
02461         if (channel->caller_profile && caller_profile) {
02462                 caller_profile->direction = channel->direction;
02463                 channel->caller_profile->hunt_caller_profile = caller_profile;
02464         }
02465         switch_mutex_unlock(channel->profile_mutex);
02466 }

switch_status_t switch_channel_set_name ( switch_channel_t channel,
const char *  name 
)

Assign a name to a given channel.

Parameters:
channel channel to assign name to
name name to assign
Returns:
SWITCH_STATUS_SUCCESS if name was assigned

Definition at line 910 of file switch_channel.c.

References switch_assert, SWITCH_CHANNEL_CHANNEL_LOG, SWITCH_CHANNEL_NAME_VARIABLE, switch_channel_set_variable, switch_core_session_get_uuid(), switch_core_session_strdup, SWITCH_LOG_NOTICE, switch_log_printf(), SWITCH_STATUS_SUCCESS, and zstr.

Referenced by switch_core_session_request_xml().

00911 {
00912         const char *old = NULL;
00913 
00914         switch_assert(channel != NULL);
00915         if (!zstr(channel->name)) {
00916                 old = channel->name;
00917         }
00918         channel->name = NULL;
00919         if (name) {
00920                 char *uuid = switch_core_session_get_uuid(channel->session);
00921                 channel->name = switch_core_session_strdup(channel->session, name);
00922                 switch_channel_set_variable(channel, SWITCH_CHANNEL_NAME_VARIABLE, name);
00923                 if (old) {
00924                         switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_NOTICE, "Rename Channel %s->%s [%s]\n", old, name, uuid);
00925                 } else {
00926                         switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_NOTICE, "New Channel %s [%s]\n", name, uuid);
00927                 }
00928         }
00929         return SWITCH_STATUS_SUCCESS;
00930 }

void switch_channel_set_originatee_caller_profile ( switch_channel_t channel,
switch_caller_profile_t caller_profile 
)

Set the given channel's originatee caller profile.

Parameters:
channel channel to assign the profile to
caller_profile the profile to assign

Definition at line 2498 of file switch_channel.c.

References LP_ORIGINATEE, switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_ivr_uuid_bridge().

02499 {
02500         switch_assert(channel != NULL);
02501         switch_assert(channel->caller_profile != NULL);
02502 
02503         switch_mutex_lock(channel->profile_mutex);
02504 
02505         if (channel->caller_profile) {
02506                 caller_profile->next = channel->caller_profile->originatee_caller_profile;
02507                 channel->caller_profile->originatee_caller_profile = caller_profile;
02508                 channel->last_profile_type = LP_ORIGINATEE;
02509         }
02510         switch_assert(channel->caller_profile->originatee_caller_profile->next != channel->caller_profile->originatee_caller_profile);
02511         switch_mutex_unlock(channel->profile_mutex);
02512 }

void switch_channel_set_origination_caller_profile ( switch_channel_t channel,
switch_caller_profile_t caller_profile 
)

Set the given channel's origination caller profile.

Parameters:
channel channel to assign the profile to
caller_profile the profile to assign

Definition at line 2468 of file switch_channel.c.

References switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_session_outgoing_channel().

02469 {
02470         switch_assert(channel != NULL);
02471         switch_assert(channel->caller_profile != NULL);
02472 
02473         switch_mutex_lock(channel->profile_mutex);
02474 
02475         if (channel->caller_profile) {
02476                 caller_profile->next = channel->caller_profile->origination_caller_profile;
02477                 channel->caller_profile->origination_caller_profile = caller_profile;
02478         }
02479         switch_assert(channel->caller_profile->origination_caller_profile->next != channel->caller_profile->origination_caller_profile);
02480         switch_mutex_unlock(channel->profile_mutex);
02481 }

void switch_channel_set_originator_caller_profile ( switch_channel_t channel,
switch_caller_profile_t caller_profile 
)

Set the given channel's originator caller profile.

Parameters:
channel channel to assign the profile to
caller_profile the profile to assign

Definition at line 2434 of file switch_channel.c.

References LP_ORIGINATOR, switch_assert, switch_core_alloc, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_session_outgoing_channel(), and switch_ivr_uuid_bridge().

02435 {
02436         switch_assert(channel != NULL);
02437         switch_assert(channel->caller_profile != NULL);
02438         switch_mutex_lock(channel->profile_mutex);
02439 
02440         if (!caller_profile->times) {
02441                 caller_profile->times = (switch_channel_timetable_t *) switch_core_alloc(caller_profile->pool, sizeof(*caller_profile->times));
02442         }
02443 
02444         if (channel->caller_profile) {
02445                 caller_profile->next = channel->caller_profile->originator_caller_profile;
02446                 channel->caller_profile->originator_caller_profile = caller_profile;
02447                 channel->last_profile_type = LP_ORIGINATOR;
02448         }
02449         switch_assert(channel->caller_profile->originator_caller_profile->next != channel->caller_profile->originator_caller_profile);
02450         switch_mutex_unlock(channel->profile_mutex);
02451 }

switch_status_t switch_channel_set_private ( switch_channel_t channel,
const char *  key,
const void *  private_info 
)

Set private data on channel.

Parameters:
channel channel on which to set data
key unique keyname to associate your private data to
private_info void pointer to private data
Returns:
SWITCH_STATUS_SUCCESS if data was set
Remarks:
set NULL to delete your private data

Definition at line 877 of file switch_channel.c.

References switch_assert, switch_core_hash_insert_locked(), and SWITCH_STATUS_SUCCESS.

Referenced by audio_bridge_on_exchange_media(), check_channel_status(), CoreSession::destroy(), monitor_callback(), preprocess_callback(), read_displace_callback(), record_callback(), session_audio_callback(), CoreSession::setDTMFCallback(), CoreSession::setHangupHook(), CoreSession::setPrivate(), signal_bridge_on_hangup(), signal_bridge_on_hibernate(), switch_ivr_activate_unicast(), switch_ivr_bind_dtmf_meta_session(), switch_ivr_block_dtmf_session(), switch_ivr_clear_speech_cache(), switch_ivr_detect_speech(), switch_ivr_displace_session(), switch_ivr_inband_dtmf_generate_session(), switch_ivr_inband_dtmf_session(), switch_ivr_multi_threaded_bridge(), switch_ivr_play_file(), switch_ivr_record_session(), switch_ivr_session_audio(), switch_ivr_speak_text(), switch_ivr_stop_detect_speech(), switch_ivr_stop_displace_session(), switch_ivr_stop_inband_dtmf_generate_session(), switch_ivr_stop_inband_dtmf_session(), switch_ivr_stop_session_audio(), switch_ivr_stop_tone_detect_session(), switch_ivr_unbind_dtmf_meta_session(), switch_ivr_unblock_dtmf_session(), switch_rtp_create(), and write_displace_callback().

00878 {
00879         switch_assert(channel != NULL);
00880         switch_core_hash_insert_locked(channel->private_hash, key, private_info, channel->profile_mutex);
00881         return SWITCH_STATUS_SUCCESS;
00882 }

void switch_channel_set_private_flag ( switch_channel_t channel,
uint32_t  flags 
)

Definition at line 1629 of file switch_channel.c.

References switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

01630 {
01631         switch_assert(channel != NULL);
01632         switch_mutex_lock(channel->flag_mutex);
01633         channel->private_flags |= flags;
01634         switch_mutex_unlock(channel->flag_mutex);
01635 }

switch_status_t switch_channel_set_profile_var ( switch_channel_t channel,
const char *  name,
const char *  val 
)

Set a variable on a given channel.

Parameters:
channel channel to set variable on
varname the name of the variable
value the value of the variable
Returns:
SWITCH_STATUS_SUCCESS if successful

Definition at line 938 of file switch_channel.c.

References SWITCH_BLANK_STRING, switch_core_alloc, switch_core_strdup, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, and zstr.

Referenced by switch_channel_set_presence_data_vals().

00939 {
00940         char *v;
00941         switch_status_t status = SWITCH_STATUS_SUCCESS;
00942 
00943         switch_mutex_lock(channel->profile_mutex);
00944 
00945         if (!zstr(val)) {
00946                 v = switch_core_strdup(channel->caller_profile->pool, val);
00947         } else {
00948                 v = SWITCH_BLANK_STRING;
00949         }
00950 
00951         if (!strcasecmp(name, "dialplan")) {
00952                 channel->caller_profile->dialplan = v;
00953         } else if (!strcasecmp(name, "username")) {
00954                 channel->caller_profile->username = v;
00955         } else if (!strcasecmp(name, "caller_id_name")) {
00956                 channel->caller_profile->caller_id_name = v;
00957         } else if (!strcasecmp(name, "caller_id_number")) {
00958                 channel->caller_profile->caller_id_number = v;
00959         } else if (!strcasecmp(name, "callee_id_name")) {
00960                 channel->caller_profile->callee_id_name = v;
00961         } else if (!strcasecmp(name, "callee_id_number")) {
00962                 channel->caller_profile->callee_id_number = v;
00963         } else if (val && !strcasecmp(name, "caller_ton")) {
00964                 channel->caller_profile->caller_ton = (uint8_t) atoi(v);
00965         } else if (val && !strcasecmp(name, "caller_numplan")) {
00966                 channel->caller_profile->caller_numplan = (uint8_t) atoi(v);
00967         } else if (val && !strcasecmp(name, "destination_number_ton")) {
00968                 channel->caller_profile->destination_number_ton = (uint8_t) atoi(v);
00969         } else if (val && !strcasecmp(name, "destination_number_numplan")) {
00970                 channel->caller_profile->destination_number_numplan = (uint8_t) atoi(v);
00971         } else if (!strcasecmp(name, "ani")) {
00972                 channel->caller_profile->ani = v;
00973         } else if (!strcasecmp(name, "aniii")) {
00974                 channel->caller_profile->aniii = v;
00975         } else if (!strcasecmp(name, "network_addr")) {
00976                 channel->caller_profile->network_addr = v;
00977         } else if (!strcasecmp(name, "rdnis")) {
00978                 channel->caller_profile->rdnis = v;
00979         } else if (!strcasecmp(name, "destination_number")) {
00980                 channel->caller_profile->destination_number = v;
00981         } else if (!strcasecmp(name, "uuid")) {
00982                 channel->caller_profile->uuid = v;
00983         } else if (!strcasecmp(name, "source")) {
00984                 channel->caller_profile->source = v;
00985         } else if (!strcasecmp(name, "context")) {
00986                 channel->caller_profile->context = v;
00987         } else if (!strcasecmp(name, "chan_name")) {
00988                 channel->caller_profile->chan_name = v;
00989         } else {
00990                 profile_node_t *pn, *n = switch_core_alloc(channel->caller_profile->pool, sizeof(*n));
00991                 
00992                 n->var = switch_core_strdup(channel->caller_profile->pool, name);
00993                 n->val = v;
00994 
00995                 if (!channel->caller_profile->soft) {
00996                         channel->caller_profile->soft = n;
00997                 } else {
00998                         for(pn = channel->caller_profile->soft; pn && pn->next; pn = pn->next);
00999                         
01000                         if (pn) {
01001                                 pn->next = n;
01002                         }
01003                 }
01004         }
01005         switch_mutex_unlock(channel->profile_mutex);
01006 
01007         return status;
01008 }

void switch_channel_set_scope_variables ( switch_channel_t channel,
switch_event_t **  event 
)

Definition at line 732 of file switch_channel.c.

References switch_event_destroy(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_session_exec().

00733 {
00734         switch_mutex_lock(channel->profile_mutex);
00735 
00736         if (event && *event) { /* push */
00737                 (*event)->next = channel->scope_variables;
00738                 channel->scope_variables = *event;
00739                 *event = NULL;
00740         } else if (channel->scope_variables) { /* pop */
00741                 switch_event_t *top_event = channel->scope_variables;
00742                 channel->scope_variables = channel->scope_variables->next;
00743                 switch_event_destroy(&top_event);
00744         }
00745 
00746         switch_mutex_unlock(channel->profile_mutex);
00747         
00748 }

void switch_channel_set_state_flag ( switch_channel_t channel,
switch_channel_flag_t  flag 
)

Set given flag(s) on a given channel to be applied on the next state change.

Parameters:
channel channel on which to set flag(s)
flag flag to set

Definition at line 1707 of file switch_channel.c.

References switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_ivr_intercept_session(), switch_ivr_signal_bridge(), and switch_ivr_uuid_bridge().

01708 {
01709         switch_assert(channel != NULL);
01710 
01711         switch_mutex_lock(channel->flag_mutex);
01712         channel->state_flags[0] = 1;
01713         channel->state_flags[flag] = 1;
01714         switch_mutex_unlock(channel->flag_mutex);
01715 }

switch_status_t switch_channel_set_timestamps ( _In_ switch_channel_t channel  ) 

Referenced by switch_core_session_hangup_state().

switch_status_t switch_channel_set_variable_name_printf ( switch_channel_t channel,
const char *  val,
const char *  fmt,
  ... 
)

Definition at line 1290 of file switch_channel.c.

References switch_assert, switch_channel_set_variable, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_MEMERR, and switch_vasprintf().

Referenced by switch_ivr_multi_threaded_bridge().

01291 {
01292         int ret = 0;
01293         char *varname;
01294         va_list ap;
01295         switch_status_t status = SWITCH_STATUS_FALSE;
01296 
01297         switch_assert(channel != NULL);
01298 
01299         switch_mutex_lock(channel->profile_mutex);
01300 
01301         va_start(ap, fmt);
01302         ret = switch_vasprintf(&varname, fmt, ap);
01303         va_end(ap);
01304 
01305         if (ret == -1) {
01306                 switch_mutex_unlock(channel->profile_mutex);
01307                 return SWITCH_STATUS_MEMERR;
01308         }
01309 
01310         status = switch_channel_set_variable(channel, varname, val);
01311 
01312         free(varname);
01313 
01314         switch_mutex_unlock(channel->profile_mutex);
01315 
01316         return status;
01317 }

switch_status_t switch_channel_set_variable_partner_var_check ( switch_channel_t channel,
const char *  varname,
const char *  value,
switch_bool_t  var_check 
)

Definition at line 1320 of file switch_channel.c.

References switch_assert, switch_channel_get_variable, switch_channel_set_variable_var_check(), switch_core_session_get_channel(), switch_core_session_locate(), switch_core_session_rwunlock(), SWITCH_SIGNAL_BOND_VARIABLE, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

01322 {
01323         const char *uuid;
01324         switch_assert(channel != NULL);
01325 
01326         if (!zstr(varname)) {
01327                 if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) || (uuid = switch_channel_get_variable(channel, "originate_signal_bond"))) {
01328                         switch_core_session_t *session;
01329                         if ((session = switch_core_session_locate(uuid))) {
01330                                 switch_channel_t *tchannel = switch_core_session_get_channel(session);
01331                                 switch_channel_set_variable_var_check(tchannel, varname, value, var_check);
01332                                 switch_core_session_rwunlock(session);
01333                         }
01334                         return SWITCH_STATUS_SUCCESS;
01335                 }
01336         }
01337 
01338         return SWITCH_STATUS_FALSE;
01339 }

switch_status_t switch_channel_set_variable_printf ( switch_channel_t channel,
const char *  varname,
const char *  fmt,
  ... 
)

Definition at line 1259 of file switch_channel.c.

References switch_assert, switch_channel_set_variable, switch_event_del_header, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_MEMERR, switch_vasprintf(), and zstr.

Referenced by switch_core_session_hangup_state(), switch_core_session_request_uuid(), switch_ivr_play_file(), switch_ivr_record_file(), and switch_limit_incr().

01260 {
01261         int ret = 0;
01262         char *data;
01263         va_list ap;
01264         switch_status_t status = SWITCH_STATUS_FALSE;
01265 
01266         switch_assert(channel != NULL);
01267 
01268         switch_mutex_lock(channel->profile_mutex);
01269         if (channel->variables && !zstr(varname)) {
01270                 switch_event_del_header(channel->variables, varname);
01271 
01272                 va_start(ap, fmt);
01273                 ret = switch_vasprintf(&data, fmt, ap);
01274                 va_end(ap);
01275 
01276                 if (ret == -1) {
01277                         switch_mutex_unlock(channel->profile_mutex);
01278                         return SWITCH_STATUS_MEMERR;
01279                 }
01280 
01281                 status = switch_channel_set_variable(channel, varname, data);
01282                 free(data);
01283         }
01284         switch_mutex_unlock(channel->profile_mutex);
01285 
01286         return status;
01287 }

switch_status_t switch_channel_set_variable_var_check ( switch_channel_t channel,
const char *  varname,
const char *  value,
switch_bool_t  var_check 
)

Definition at line 1195 of file switch_channel.c.

References switch_assert, SWITCH_CHANNEL_CHANNEL_LOG, switch_event_add_header_string(), switch_event_del_header, SWITCH_LOG_CRIT, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_string_var_check_const(), and zstr.

Referenced by CoreSession::setVariable(), switch_channel_export_variable_var_check(), switch_channel_set_variable_partner_var_check(), and switch_core_session_exec().

01197 {
01198         switch_status_t status = SWITCH_STATUS_FALSE;
01199 
01200         switch_assert(channel != NULL);
01201 
01202         switch_mutex_lock(channel->profile_mutex);
01203         if (channel->variables && !zstr(varname)) {
01204                 if (zstr(value)) {
01205                         switch_event_del_header(channel->variables, varname);
01206                 } else {
01207                         int ok = 1;
01208 
01209                         if (var_check) {
01210                                 ok = !switch_string_var_check_const(value);
01211                         }
01212                         if (ok) {
01213                                 switch_event_add_header_string(channel->variables, SWITCH_STACK_BOTTOM, varname, value);
01214                         } else {
01215                                 switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_CRIT, "Invalid data (${%s} contains a variable)\n", varname);
01216                         }
01217                 }
01218                 status = SWITCH_STATUS_SUCCESS;
01219         }
01220         switch_mutex_unlock(channel->profile_mutex);
01221 
01222         return status;
01223 }

void switch_channel_sort_cid ( switch_channel_t channel,
switch_bool_t  in 
)

Definition at line 2754 of file switch_channel.c.

References CF_DIALPLAN, SWITCH_BLANK_STRING, SWITCH_CALL_DIRECTION_OUTBOUND, switch_channel_clear_flag(), switch_channel_direction(), switch_channel_flip_cid(), switch_channel_set_flag, switch_channel_test_flag(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_channel_set_caller_extension().

02755 {
02756 
02757         if (in) {
02758                 if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND && !switch_channel_test_flag(channel, CF_DIALPLAN)) {
02759                         switch_channel_set_flag(channel, CF_DIALPLAN);
02760                         switch_channel_flip_cid(channel);
02761                 }
02762 
02763                 return;
02764         }
02765 
02766         if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND && switch_channel_test_flag(channel, CF_DIALPLAN)) {
02767                 switch_channel_clear_flag(channel, CF_DIALPLAN);
02768                 switch_mutex_lock(channel->profile_mutex);
02769                 channel->caller_profile->callee_id_name = SWITCH_BLANK_STRING;
02770                 channel->caller_profile->callee_id_number = SWITCH_BLANK_STRING;
02771                 switch_mutex_unlock(channel->profile_mutex);
02772         }
02773         
02774 }

int switch_channel_state_change_pending ( switch_channel_t channel  ) 

Definition at line 1795 of file switch_channel.c.

References switch_channel_down_nosig, and switch_core_session_in_thread().

Referenced by switch_channel_test_ready(), and switch_ivr_eavesdrop_session().

01796 {
01797         if (switch_channel_down_nosig(channel) || !switch_core_session_in_thread(channel->session)) {
01798                 return 0;
01799         }
01800 
01801         return channel->running_state != channel->state;
01802 }

const char* switch_channel_state_name ( _In_ switch_channel_state_t  state  ) 

Render the name of the provided state enum.

Parameters:
state state to get name of
Returns:
the string representation of the state

Referenced by CoreSession::getState(), switch_channel_event_set_basic_data(), switch_core_session_perform_destroy(), switch_ivr_generate_json_cdr(), and switch_ivr_generate_xml_cdr().

switch_call_cause_t switch_channel_str2callstate ( const char *  str  ) 

Definition at line 265 of file switch_channel.c.

References switch_callstate_table::callstate, CALLSTATE_CHART, switch_callstate_table::name, and SWITCH_CAUSE_NONE.

00266 {
00267         uint8_t x;
00268         switch_channel_callstate_t callstate = (switch_channel_callstate_t) SWITCH_CAUSE_NONE;
00269 
00270         if (*str > 47 && *str < 58) {
00271                 callstate = atoi(str);
00272         } else {
00273                 for (x = 0; x < (sizeof(CALLSTATE_CHART) / sizeof(struct switch_callstate_table)) - 1 && CALLSTATE_CHART[x].name; x++) {
00274                         if (!strcasecmp(CALLSTATE_CHART[x].name, str)) {
00275                                 callstate = CALLSTATE_CHART[x].callstate;
00276                                 break;
00277                         }
00278                 }
00279         }
00280         return (switch_call_cause_t) callstate;
00281 }

switch_call_cause_t switch_channel_str2cause ( _In_ const char *  str  ) 

return a cause code for a given string

Parameters:
str the string to check
Returns:
the code

Referenced by fs_channel_hangup(), CoreSession::hangup(), monitor_callback(), switch_ivr_park(), and switch_ivr_parse_event().

int switch_channel_test_app_flag_key ( const char *  app,
switch_channel_t channel,
uint32_t  flags 
)

Definition at line 1691 of file switch_channel.c.

References switch_assert, switch_core_hash_find(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_ivr_eavesdrop_update_display().

01692 {
01693         int r = 0;
01694         uint32_t *flagp = NULL;
01695         switch_assert(channel != NULL);
01696 
01697         switch_mutex_lock(channel->flag_mutex);
01698         if (channel->app_flag_hash && (flagp = switch_core_hash_find(channel->app_flag_hash, key))) {
01699                 r = (*flagp & flags);
01700         }
01701         switch_mutex_unlock(channel->flag_mutex);
01702         
01703 
01704         return r;
01705 }

uint32_t switch_channel_test_cap ( switch_channel_t channel,
switch_channel_cap_t  cap 
)

Definition at line 1503 of file switch_channel.c.

References switch_assert.

Referenced by switch_channel_test_cap_partner(), switch_core_session_outgoing_channel(), and switch_core_session_send_dtmf().

01504 {
01505         switch_assert(channel != NULL);
01506         return channel->caps[cap] ? 1 : 0;
01507 }

uint32_t switch_channel_test_cap_partner ( switch_channel_t channel,
switch_channel_cap_t  cap 
)

Definition at line 1509 of file switch_channel.c.

References switch_assert, switch_channel_get_variable, switch_channel_test_cap(), switch_core_session_get_channel(), switch_core_session_locate(), switch_core_session_rwunlock(), and SWITCH_SIGNAL_BOND_VARIABLE.

01510 {
01511         const char *uuid;
01512         int r = 0;
01513 
01514         switch_assert(channel != NULL);
01515 
01516         if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) || (uuid = switch_channel_get_variable(channel, "originate_signal_bond"))) {
01517                 switch_core_session_t *session;
01518                 if ((session = switch_core_session_locate(uuid))) {
01519                         r = switch_channel_test_cap(switch_core_session_get_channel(session), cap);
01520                         switch_core_session_rwunlock(session);
01521                 }
01522         }
01523 
01524         return r;
01525 }

uint32_t switch_channel_test_flag ( switch_channel_t channel,
switch_channel_flag_t  flag 
)

Test for presence of given flag on a given channel.

Parameters:
channel channel to test
flag to test
Returns:
TRUE if flags were present

Definition at line 1341 of file switch_channel.c.

References switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by CoreSession::answered(), audio_bridge_on_exchange_media(), audio_bridge_thread(), block_on_dtmf(), CoreSession::bridged(), check_channel_status(), check_per_channel_timeouts(), cleanup_proxy_mode_a(), cleanup_proxy_mode_b(), CoreSession::destroy(), early_thread_run(), generate_on_dtmf(), hanguphook(), meta_on_dtmf(), originate_on_consume_media_transmit(), sb_on_dtmf(), send_display(), setup_ringback(), signal_bridge_on_hangup(), signal_bridge_on_hibernate(), switch_channel_check_zrtp(), switch_channel_dequeue_dtmf(), switch_channel_event_set_basic_data(), switch_channel_event_set_extended_data(), switch_channel_mark_hold(), switch_channel_perform_answer(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_perform_mark_ring_ready_value(), switch_channel_perform_pre_answer(), switch_channel_perform_presence(), switch_channel_perform_ring_ready_value(), switch_channel_set_timestamps(), switch_channel_sort_cid(), switch_channel_test_flag_partner(), switch_channel_test_ready(), switch_channel_wait_for_flag(), switch_core_service_thread(), switch_core_session_dequeue_event(), switch_core_session_dequeue_private_event(), switch_core_session_enable_heartbeat(), switch_core_session_execute_application_async(), switch_core_session_execute_application_get_flags(), switch_core_session_hangup_state(), switch_core_session_outgoing_channel(), switch_core_session_perform_receive_message(), switch_core_session_private_event_count(), switch_core_session_queue_event(), switch_core_session_queue_message(), switch_core_session_queue_signal_data(), switch_core_session_read_frame(), switch_core_session_read_lock(), switch_core_session_recv_dtmf(), switch_core_session_reporting_state(), switch_core_session_run(), switch_core_session_send_dtmf(), switch_core_session_write_frame(), switch_core_standard_on_execute(), switch_core_standard_on_hangup(), switch_core_standard_on_routing(), switch_ivr_blind_transfer_ack(), switch_ivr_broadcast(), switch_ivr_collect_digits_callback(), switch_ivr_collect_digits_count(), switch_ivr_deactivate_unicast(), switch_ivr_enterprise_originate(), switch_ivr_gentones(), switch_ivr_intercept_session(), switch_ivr_media(), switch_ivr_multi_threaded_bridge(), switch_ivr_nomedia(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_parse_all_events(), switch_ivr_parse_all_signal_data(), switch_ivr_parse_event(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_session_echo(), switch_ivr_signal_bridge(), switch_ivr_sleep(), switch_ivr_soft_hold(), switch_ivr_speak_text_handle(), switch_ivr_uuid_bridge(), switch_ivr_wait_for_answer(), uuid_bridge_on_reset(), and uuid_bridge_on_soft_execute().

01342 {
01343         uint32_t r = 0;
01344 
01345         switch_assert(channel != NULL);
01346 
01347         switch_mutex_lock(channel->flag_mutex);
01348         r = channel->flags[flag];
01349         switch_mutex_unlock(channel->flag_mutex);
01350 
01351         return r;
01352 }

uint32_t switch_channel_test_flag_partner ( switch_channel_t channel,
switch_channel_flag_t  flag 
)

Definition at line 1372 of file switch_channel.c.

References switch_assert, switch_channel_get_variable, switch_channel_test_flag(), switch_core_session_get_channel(), switch_core_session_locate(), switch_core_session_rwunlock(), and SWITCH_SIGNAL_BOND_VARIABLE.

01373 {
01374         const char *uuid;
01375         int r = 0;
01376 
01377         switch_assert(channel != NULL);
01378 
01379         if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) || (uuid = switch_channel_get_variable(channel, "originate_signal_bond"))) {
01380                 switch_core_session_t *session;
01381                 if ((session = switch_core_session_locate(uuid))) {
01382                         r = switch_channel_test_flag(switch_core_session_get_channel(session), flag);
01383                         switch_core_session_rwunlock(session);
01384                 }
01385         }
01386 
01387         return r;
01388 }

int switch_channel_test_private_flag ( switch_channel_t channel,
uint32_t  flags 
)

Definition at line 1645 of file switch_channel.c.

References switch_assert.

01646 {
01647         switch_assert(channel != NULL);
01648         return (channel->private_flags & flags);
01649 }

int switch_channel_test_ready ( switch_channel_t channel,
switch_bool_t  check_ready,
switch_bool_t  check_media 
)

Determine if a channel is ready for io.

Parameters:
channel channel to test
Returns:
true if the channel is ready

Definition at line 1813 of file switch_channel.c.

References CF_ANSWERED, CF_EARLY_MEDIA, CF_NOT_READY, CF_PROXY_MODE, CF_TRANSFER, CS_HANGUP, CS_RESET, CS_ROUTING, switch_assert, switch_channel_check_signal(), switch_channel_state_change_pending(), switch_channel_test_flag(), switch_core_session_get_read_codec(), switch_core_session_get_write_codec(), and SWITCH_TRUE.

01814 {
01815         int ret = 0;
01816 
01817         switch_assert(channel != NULL);
01818 
01819         switch_channel_check_signal(channel, SWITCH_TRUE);
01820 
01821         if (check_media) {
01822                 ret = ((switch_channel_test_flag(channel, CF_ANSWERED) ||
01823                                 switch_channel_test_flag(channel, CF_EARLY_MEDIA)) && !switch_channel_test_flag(channel, CF_PROXY_MODE) &&
01824                            switch_core_session_get_read_codec(channel->session) && switch_core_session_get_write_codec(channel->session));
01825                            
01826 
01827                 if (!ret)
01828                         return ret;
01829         }
01830 
01831         if (!check_ready)
01832                 return ret;
01833 
01834         ret = 0;
01835 
01836         if (!channel->hangup_cause && channel->state > CS_ROUTING && channel->state < CS_HANGUP && channel->state != CS_RESET &&
01837                 !switch_channel_test_flag(channel, CF_TRANSFER) && !switch_channel_test_flag(channel, CF_NOT_READY) && 
01838                 !switch_channel_state_change_pending(channel)) {
01839                 ret++;
01840         }
01841 
01842 
01843 
01844         return ret;
01845 }

void switch_channel_uninit ( switch_channel_t channel  ) 

Uninitalize a channel.

Parameters:
channel the channel to uninit

Definition at line 571 of file switch_channel.c.

References switch_channel_flush_dtmf(), switch_core_hash_destroy(), switch_event_destroy(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypop(), switch_safe_free, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_session_perform_destroy().

00572 {
00573         void *pop;
00574         switch_channel_flush_dtmf(channel);
00575         while (switch_queue_trypop(channel->dtmf_log_queue, &pop) == SWITCH_STATUS_SUCCESS) {
00576                 switch_safe_free(pop);
00577         }
00578         switch_core_hash_destroy(&channel->private_hash);
00579         if (channel->app_flag_hash) {
00580                 switch_core_hash_destroy(&channel->app_flag_hash);
00581         }
00582         switch_mutex_lock(channel->profile_mutex);
00583         switch_event_destroy(&channel->variables);
00584         switch_event_destroy(&channel->api_list);
00585         switch_event_destroy(&channel->var_list);
00586         switch_event_destroy(&channel->app_list);
00587         switch_mutex_unlock(channel->profile_mutex);
00588 }

switch_event_header_t* switch_channel_variable_first ( switch_channel_t channel  ) 

Start iterating over the entries in the channel variable list.

Parameters:
channel the channel to iterate the variables for
Remarks:
This function locks the profile mutex, use switch_channel_variable_last to unlock

Definition at line 862 of file switch_channel.c.

References switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_channel_build_param_string(), switch_ivr_originate(), switch_ivr_set_json_chan_vars(), and switch_ivr_set_xml_chan_vars().

00863 {
00864         switch_event_header_t *hi = NULL;
00865 
00866         switch_assert(channel != NULL);
00867         switch_mutex_lock(channel->profile_mutex);
00868         if (channel->variables && (hi = channel->variables->headers)) {
00869                 channel->vi = 1;
00870         } else {
00871                 switch_mutex_unlock(channel->profile_mutex);
00872         }
00873 
00874         return hi;
00875 }

void switch_channel_variable_last ( switch_channel_t channel  ) 

Stop iterating over channel variables.

Remarks:
Unlocks the profile mutex initially locked in switch_channel_variable_first.

Definition at line 851 of file switch_channel.c.

References switch_assert, and switch_mutex_unlock().

Referenced by switch_channel_build_param_string().

00852 {
00853         switch_assert(channel != NULL);
00854         if (!channel->vi) {
00855                 return;
00856         }
00857         channel->vi = 0;
00858         switch_mutex_unlock(channel->profile_mutex);
00859 
00860 }

switch_status_t switch_channel_wait_for_flag ( switch_channel_t channel,
switch_channel_flag_t  want_flag,
switch_bool_t  pres,
uint32_t  to,
switch_channel_t super_channel 
)

Definition at line 1444 of file switch_channel.c.

References switch_channel_down, switch_channel_ready, switch_channel_test_flag(), switch_cond_next(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and SWITCH_STATUS_TIMEOUT.

Referenced by audio_bridge_thread(), switch_core_session_run(), switch_ivr_media(), switch_ivr_multi_threaded_bridge(), switch_ivr_nomedia(), switch_ivr_parse_event(), and switch_ivr_unhold().

01447 {
01448 
01449         if (to) {
01450                 to++;
01451         }
01452 
01453         for (;;) {
01454                 if (pres) {
01455                         if (switch_channel_test_flag(channel, want_flag)) {
01456                                 break;
01457                         }
01458                 } else {
01459                         if (!switch_channel_test_flag(channel, want_flag)) {
01460                                 break;
01461                         }
01462                 }
01463 
01464                 switch_cond_next();
01465 
01466                 if (super_channel && !switch_channel_ready(super_channel)) {
01467                         return SWITCH_STATUS_FALSE;
01468                 }
01469 
01470                 if (switch_channel_down(channel)) {
01471                         return SWITCH_STATUS_FALSE;
01472                 }
01473 
01474                 if (to && !--to) {
01475                         return SWITCH_STATUS_TIMEOUT;
01476                 }
01477         }
01478 
01479         return SWITCH_STATUS_SUCCESS;
01480 }

void switch_channel_wait_for_state ( switch_channel_t channel,
switch_channel_t other_channel,
switch_channel_state_t  want_state 
)

Definition at line 1408 of file switch_channel.c.

References CS_HANGUP, switch_assert, switch_channel_down, switch_channel_down_nosig, and switch_yield.

Referenced by CoreSession::CoreSession(), switch_ivr_multi_threaded_bridge(), and switch_ivr_nomedia().

01409 {
01410 
01411         switch_assert(channel);
01412         
01413         for (;;) {
01414                 if ((channel->state < CS_HANGUP && channel->state == channel->running_state && channel->running_state == want_state) ||
01415                         (other_channel && switch_channel_down_nosig(other_channel)) || switch_channel_down(channel)) {
01416                         break;
01417                 }
01418                 switch_yield(20000);
01419         }
01420 }

void switch_channel_wait_for_state_timeout ( switch_channel_t other_channel,
switch_channel_state_t  want_state,
uint32_t  timeout 
)

Definition at line 1423 of file switch_channel.c.

References CS_HANGUP, switch_channel_check_signal(), switch_cond_next(), and SWITCH_TRUE.

Referenced by switch_channel_restart().

01424 {
01425 
01426         uint32_t count = 0;
01427 
01428         for (;;) {
01429 
01430                 if ((channel->state == channel->running_state && channel->running_state == want_state) || channel->state >= CS_HANGUP) {
01431                         break;
01432                 }
01433 
01434                 switch_channel_check_signal(channel, SWITCH_TRUE);
01435 
01436                 switch_cond_next();
01437 
01438                 if (++count >= timeout) {
01439                         break;
01440                 }
01441         }
01442 }


Generated on Wed May 16 04:00:18 2012 for FreeSWITCH API Documentation by  doxygen 1.4.7