RTS API Documentation  1.10.11
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
switch_channel.c File Reference
#include <switch.h>
#include <switch_channel.h>
#include <pcre.h>
+ Include dependency graph for switch_channel.c:

Go to the source code of this file.

Data Structures

struct  switch_cause_table
 
struct  switch_device_state_binding_s
 
struct  switch_channel
 
struct  switch_callstate_table
 
struct  switch_device_state_table
 

Macros

#define resize(l)
 

Typedefs

typedef struct switch_device_state_binding_s switch_device_state_binding_t
 

Enumerations

enum  opaque_channel_flag_t { OCF_HANGUP = (1 << 0) }
 
enum  switch_originator_type_t { LP_NEITHER, LP_ORIGINATOR, LP_ORIGINATEE }
 

Functions

static void process_device_hup (switch_channel_t *channel)
 
static void switch_channel_check_device_state (switch_channel_t *channel, switch_channel_callstate_t callstate)
 
switch_hold_record_tswitch_channel_get_hold_record (switch_channel_t *channel)
 
const char * switch_channel_cause2str (switch_call_cause_t cause)
 
switch_call_cause_t switch_channel_str2cause (const char *str)
 
switch_call_cause_t switch_channel_get_cause (switch_channel_t *channel)
 
switch_call_cause_tswitch_channel_get_cause_ptr (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)
 
const char * switch_channel_device_state2str (switch_device_state_t device_state)
 
switch_channel_callstate_t switch_channel_str2callstate (const char *str)
 
void switch_channel_perform_audio_sync (switch_channel_t *channel, const char *file, const char *func, int line)
 
void switch_channel_perform_video_sync (switch_channel_t *channel, const char *file, const char *func, int line)
 
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_channel_timetable_tswitch_channel_get_timetable (switch_channel_t *channel)
 
void switch_channel_set_direction (switch_channel_t *channel, switch_call_direction_t direction)
 
switch_call_direction_t switch_channel_direction (switch_channel_t *channel)
 
switch_call_direction_t switch_channel_logical_direction (switch_channel_t *channel)
 
switch_status_t switch_channel_alloc (switch_channel_t **channel, switch_call_direction_t direction, switch_memory_pool_t *pool)
 
switch_status_t switch_channel_dtmf_lock (switch_channel_t *channel)
 
switch_status_t switch_channel_try_dtmf_lock (switch_channel_t *channel)
 
switch_status_t switch_channel_dtmf_unlock (switch_channel_t *channel)
 
switch_size_t switch_channel_has_dtmf (switch_channel_t *channel)
 
switch_status_t switch_channel_queue_dtmf (switch_channel_t *channel, const switch_dtmf_t *dtmf)
 
switch_status_t switch_channel_queue_dtmf_string (switch_channel_t *channel, const char *dtmf_string)
 
switch_status_t switch_channel_dequeue_dtmf (switch_channel_t *channel, switch_dtmf_t *dtmf)
 
switch_size_t switch_channel_dequeue_dtmf_string (switch_channel_t *channel, char *dtmf_str, switch_size_t len)
 
void switch_channel_flush_dtmf (switch_channel_t *channel)
 
void switch_channel_uninit (switch_channel_t *channel)
 Uninitalize a channel. More...
 
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. More...
 
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. More...
 
void switch_channel_mark_hold (switch_channel_t *channel, switch_bool_t on)
 
const char * switch_channel_get_hold_music (switch_channel_t *channel)
 
const char * switch_channel_get_hold_music_partner (switch_channel_t *channel)
 
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. More...
 
const char * switch_channel_get_variable_strdup (switch_channel_t *channel, const char *varname)
 Retrieve a copy of a variable from a given channel. switch_safe_free() call will be required. More...
 
switch_status_t switch_channel_get_variable_buf (switch_channel_t *channel, const char *varname, char *buf, switch_size_t buflen)
 Retrieve a variable from a given channel to a pre-allocated buffer without using a memory pool. More...
 
const char * switch_channel_get_variable_partner (switch_channel_t *channel, const char *varname)
 
void switch_channel_variable_last (switch_channel_t *channel)
 Stop iterating over channel variables. More...
 
switch_event_header_tswitch_channel_variable_first (switch_channel_t *channel)
 Start iterating over the entries in the channel variable list. More...
 
switch_status_t switch_channel_set_private (switch_channel_t *channel, const char *key, const void *private_info)
 Set private data on channel. More...
 
void * switch_channel_get_private (switch_channel_t *channel, const char *key)
 Retrieve private from a given channel. More...
 
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. More...
 
char * switch_channel_get_name (switch_channel_t *channel)
 Retrieve the name of a given channel. More...
 
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. More...
 
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_var_check (switch_channel_t *channel, const char *varname, const char *val, const char *export_varname, switch_bool_t var_check)
 
switch_status_t switch_channel_export_variable_printf (switch_channel_t *channel, const char *varname, const char *export_varname, const char *fmt,...)
 
uint32_t switch_channel_del_variable_prefix (switch_channel_t *channel, const char *prefix)
 
switch_status_t switch_channel_transfer_variable_prefix (switch_channel_t *orig_channel, switch_channel_t *new_channel, const char *prefix)
 
void switch_channel_set_presence_data_vals (switch_channel_t *channel, const char *presence_data_cols)
 Takes presence_data_cols as a parameter or as a channel variable and copies them to channel profile variables. More...
 
switch_status_t switch_channel_set_log_tag (switch_channel_t *channel, const char *tagname, const char *tagvalue)
 
switch_status_t switch_channel_get_log_tags (switch_channel_t *channel, switch_event_t **log_tags)
 
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_set_variable_strip_quotes_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_event_base_add_header (switch_event_t *event, switch_stack_t stack, const char *header_name, char *data)
 
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)
 
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. More...
 
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. More...
 
uint32_t switch_channel_test_flag_partner (switch_channel_t *channel, switch_channel_flag_t flag)
 
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. More...
 
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 *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_status_t switch_channel_wait_for_app_flag (switch_channel_t *channel, uint32_t app_flag, const char *key, switch_bool_t pres, uint32_t to)
 
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)
 
char * switch_channel_get_flag_string (switch_channel_t *channel)
 
char * switch_channel_get_cap_string (switch_channel_t *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. More...
 
void switch_channel_set_flag_recursive (switch_channel_t *channel, switch_channel_flag_t flag)
 
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 *key, switch_channel_t *channel, uint32_t flags)
 
void switch_channel_clear_app_flag_key (const char *key, switch_channel_t *channel, uint32_t flags)
 
int switch_channel_test_app_flag_key (const char *key, switch_channel_t *channel, uint32_t flags)
 
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. More...
 
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. More...
 
void switch_channel_clear_flag_recursive (switch_channel_t *channel, switch_channel_flag_t flag)
 
switch_channel_state_t switch_channel_get_state (switch_channel_t *channel)
 Get the current state of a channel in the state engine. More...
 
switch_channel_state_t switch_channel_get_running_state (switch_channel_t *channel)
 
int switch_channel_state_change_pending (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. More...
 
const char * switch_channel_state_name (switch_channel_state_t state)
 
switch_channel_state_t switch_channel_name_state (const char *name)
 
static void careful_set (switch_channel_t *channel, switch_channel_state_t *state, switch_channel_state_t val)
 
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_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)
 
void switch_channel_state_thread_lock (switch_channel_t *channel)
 
switch_status_t switch_channel_state_thread_trylock (switch_channel_t *channel)
 
void switch_channel_state_thread_unlock (switch_channel_t *channel)
 
void switch_channel_event_set_basic_data (switch_channel_t *channel, switch_event_t *event)
 
void switch_channel_event_set_extended_data (switch_channel_t *channel, switch_event_t *event)
 
void switch_channel_event_set_data (switch_channel_t *channel, switch_event_t *event)
 
void switch_channel_step_caller_profile (switch_channel_t *channel)
 
void switch_channel_set_caller_profile (switch_channel_t *channel, switch_caller_profile_t *caller_profile)
 Set the given channel's caller profile. More...
 
switch_caller_profile_tswitch_channel_get_caller_profile (switch_channel_t *channel)
 Retrieve the given channel's caller profile. More...
 
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. More...
 
void switch_channel_set_hunt_caller_profile (switch_channel_t *channel, switch_caller_profile_t *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. More...
 
switch_caller_profile_tswitch_channel_get_origination_caller_profile (switch_channel_t *channel)
 Retrieve the given channel's origination caller profile. More...
 
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. More...
 
switch_caller_profile_tswitch_channel_get_originator_caller_profile (switch_channel_t *channel)
 Retrieve the given channel's originator caller profile. More...
 
switch_caller_profile_tswitch_channel_get_originatee_caller_profile (switch_channel_t *channel)
 Retrieve the given channel's originatee caller profile. More...
 
char * switch_channel_get_uuid (switch_channel_t *channel)
 Retrieve the given channel's unique id. More...
 
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 More...
 
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. More...
 
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 More...
 
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_invert_cid (switch_channel_t *channel)
 
void switch_channel_flip_cid (switch_channel_t *channel)
 
void switch_channel_sort_cid (switch_channel_t *channel)
 
switch_caller_extension_tswitch_channel_get_queued_extension (switch_channel_t *channel)
 
void switch_channel_transfer_to_extension (switch_channel_t *channel, switch_caller_extension_t *caller_extension)
 
void switch_channel_set_caller_extension (switch_channel_t *channel, switch_caller_extension_t *caller_extension)
 Assign a caller extension to a given channel. More...
 
switch_caller_extension_tswitch_channel_get_caller_extension (switch_channel_t *channel)
 Retrieve caller extension from a given channel. More...
 
void switch_channel_set_bridge_time (switch_channel_t *channel)
 
void switch_channel_set_hangup_time (switch_channel_t *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)
 
static switch_status_t send_ind (switch_channel_t *channel, switch_core_session_message_types_t msg_id, const char *file, const char *func, int line)
 
switch_status_t switch_channel_perform_acknowledge_call (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)
 
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_pre_answer (switch_channel_t *channel, const char *file, const char *func, int line)
 
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)
 
static void do_api_on (switch_channel_t *channel, const char *variable)
 
switch_status_t switch_channel_api_on (switch_channel_t *channel, const char *variable_prefix)
 
switch_status_t switch_channel_execute_on_value (switch_channel_t *channel, const char *variable_value)
 
switch_status_t switch_channel_execute_on (switch_channel_t *channel, const char *variable_prefix)
 
switch_status_t switch_channel_perform_mark_answered (switch_channel_t *channel, const char *file, const char *func, int line)
 
switch_status_t switch_channel_perform_answer (switch_channel_t *channel, const char *file, const char *func, int line)
 
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. More...
 
char * switch_channel_build_param_string (switch_channel_t *channel, switch_caller_profile_t *caller_profile, const char *prefix)
 
switch_status_t switch_channel_pass_callee_id (switch_channel_t *channel, switch_channel_t *other_channel)
 
switch_status_t switch_channel_get_variables (switch_channel_t *channel, switch_event_t **event)
 
switch_status_t switch_channel_get_variables_prefix (switch_channel_t *channel, const char *prefix, switch_event_t **event)
 
switch_core_session_tswitch_channel_get_session (switch_channel_t *channel)
 
switch_status_t switch_channel_set_timestamps (switch_channel_t *channel)
 
const char * switch_channel_get_partner_uuid_copy (switch_channel_t *channel, char *buf, switch_size_t blen)
 
const char * switch_channel_get_partner_uuid (switch_channel_t *channel)
 
void switch_channel_handle_cause (switch_channel_t *channel, switch_call_cause_t cause)
 
void switch_channel_global_init (switch_memory_pool_t *pool)
 
void switch_channel_global_uninit (void)
 
static void fetch_device_stats (switch_device_record_t *drec)
 
void switch_channel_clear_device_record (switch_channel_t *channel)
 
void switch_channel_process_device_hangup (switch_channel_t *channel)
 
static void add_uuid (switch_device_record_t *drec, switch_channel_t *channel)
 
static switch_status_t create_device_record (switch_device_record_t **drecp, const char *device_id)
 
const char * switch_channel_set_device_id (switch_channel_t *channel, const char *device_id)
 
switch_device_record_tswitch_channel_get_device_record (switch_channel_t *channel)
 
void switch_channel_release_device_record (switch_device_record_t **drecp)
 
switch_status_t switch_channel_bind_device_state_handler (switch_device_state_function_t function, void *user_data)
 
switch_status_t switch_channel_unbind_device_state_handler (switch_device_state_function_t function)
 
switch_status_t switch_channel_pass_sdp (switch_channel_t *from_channel, switch_channel_t *to_channel, const char *sdp)
 

Variables

struct {
   switch_memory_pool_t *   pool
 
   switch_hash_t *   device_hash
 
   switch_mutex_t *   device_mutex
 
   switch_device_state_binding_t *   device_bindings
 
globals
 
static struct switch_cause_table CAUSE_CHART []
 
static struct switch_callstate_table CALLSTATE_CHART []
 
static struct switch_device_state_table DEVICE_STATE_CHART []
 
static const char * state_names []
 

Macro Definition Documentation

◆ resize

#define resize (   l)
Value:
{\
char *dp;\
olen += (len + l + block);\
cpos = c - data;\
if ((dp = realloc(data, olen))) {\
data = dp;\
c = data + cpos;\
memset(c, 0, olen - cpos);\
}} \

Definition at line 3977 of file switch_channel.c.

Referenced by switch_channel_expand_variables_check().

Typedef Documentation

◆ switch_device_state_binding_t

Enumeration Type Documentation

◆ opaque_channel_flag_t

Enumerator
OCF_HANGUP 

Definition at line 142 of file switch_channel.c.

142  {
143  OCF_HANGUP = (1 << 0)
opaque_channel_flag_t

◆ switch_originator_type_t

Enumerator
LP_NEITHER 
LP_ORIGINATOR 
LP_ORIGINATEE 

Definition at line 146 of file switch_channel.c.

Function Documentation

◆ add_uuid()

static void add_uuid ( switch_device_record_t drec,
switch_channel_t channel 
)
static

Definition at line 5408 of file switch_channel.c.

References device_uuid_node_s::callstate, switch_channel::callstate, CF_DEVICE_LEG, switch_channel::device_node, device_uuid_node_s::direction, switch_channel::logical_direction, device_uuid_node_s::next, device_uuid_node_s::parent, switch_device_record_s::pool, switch_device_record_s::refs, switch_channel::session, switch_assert, SWITCH_CALL_DIRECTION_INBOUND, SWITCH_CALL_DIRECTION_OUTBOUND, switch_channel_set_flag, switch_core_alloc, switch_core_session_get_uuid(), switch_core_strdup, device_uuid_node_s::uuid, switch_device_record_s::uuid, switch_device_record_s::uuid_list, and switch_device_record_s::uuid_tail.

Referenced by switch_channel_set_device_id().

5409 {
5410  switch_device_node_t *node;
5411 
5412  switch_assert(drec);
5413 
5415  node = switch_core_alloc(drec->pool, sizeof(*node));
5416 
5418  node->parent = drec;
5419  node->callstate = channel->callstate;
5421 
5422  channel->device_node = node;
5423 
5424  if (!drec->uuid_list) {
5425  drec->uuid_list = node;
5426  drec->uuid = node->uuid;
5427  } else {
5428  drec->uuid_tail->next = node;
5429  }
5430 
5431  drec->uuid_tail = node;
5432  drec->refs++;
5433 }
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
struct device_uuid_node_s * uuid_tail
Definition: switch_core.h:139
switch_call_direction_t logical_direction
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
switch_call_direction_t direction
Definition: switch_core.h:88
struct device_uuid_node_s * next
Definition: switch_core.h:90
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
switch_channel_callstate_t callstate
Definition: switch_core.h:85
switch_memory_pool_t * pool
Definition: switch_core.h:141
struct switch_device_record_s * parent
Definition: switch_core.h:89
#define switch_channel_set_flag(_c, _f)
struct device_uuid_node_s * uuid_list
Definition: switch_core.h:138
switch_device_node_t * device_node
switch_channel_callstate_t callstate
#define switch_assert(expr)
switch_core_session_t * session

◆ careful_set()

static void careful_set ( switch_channel_t channel,
switch_channel_state_t state,
switch_channel_state_t  val 
)
inlinestatic

Definition at line 2340 of file switch_channel.c.

References mutex, switch_channel::session, switch_cond_next(), switch_core_session_get_mutex(), switch_mutex_trylock(), switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, and switch_channel::thread_mutex.

Referenced by switch_channel_perform_set_running_state(), and switch_channel_perform_set_state().

2340  {
2341 
2343  *state = val;
2345  } else {
2347  int x = 0;
2348 
2349  for (x = 0; x < 100; x++) {
2351  *state = val;
2352  switch_mutex_unlock(mutex);
2353  break;
2354  } else {
2355  switch_cond_next();
2356  }
2357  }
2358 
2359  if (x == 100) {
2360  *state = val;
2361  }
2362 
2363  }
2364 }
switch_status_t switch_mutex_trylock(switch_mutex_t *lock)
Definition: switch_apr.c:318
switch_mutex_t * switch_core_session_get_mutex(switch_core_session_t *session)
Signal a session&#39;s state machine thread that a state change has occured.
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
void switch_cond_next(void)
Definition: switch_time.c:658
switch_mutex_t * mutex
struct fspr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_mutex_t * thread_mutex
switch_core_session_t * session

◆ create_device_record()

static switch_status_t create_device_record ( switch_device_record_t **  drecp,
const char *  device_id 
)
static

Definition at line 5435 of file switch_channel.c.

References switch_device_record_s::device_id, switch_device_record_s::mutex, pool, switch_device_record_s::pool, switch_assert, switch_core_alloc, switch_core_new_memory_pool, switch_core_strdup, switch_mutex_init(), SWITCH_MUTEX_NESTED, and SWITCH_STATUS_SUCCESS.

Referenced by switch_channel_set_device_id().

5436 {
5437  switch_device_record_t *drec;
5439 
5440  switch_assert(drecp);
5441 
5443  drec = switch_core_alloc(pool, sizeof(*drec));
5444  drec->pool = pool;
5445  drec->device_id = switch_core_strdup(drec->pool, device_id);
5447 
5448  *drecp = drec;
5449 
5450  return SWITCH_STATUS_SUCCESS;
5451 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core&#39;s master pool.
Definition: switch_core.h:633
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_memory_pool_t * pool
switch_mutex_t * mutex
Definition: switch_core.h:140
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
switch_memory_pool_t * pool
Definition: switch_core.h:141
struct fspr_pool_t switch_memory_pool_t
#define switch_assert(expr)

◆ do_api_on()

static void do_api_on ( switch_channel_t channel,
const char *  variable 
)
static

Definition at line 3670 of file switch_channel.c.

References switch_stream_handle::data, switch_channel::name, switch_channel::session, switch_api_execute(), SWITCH_CHANNEL_CHANNEL_LOG, switch_channel_expand_variables, switch_core_session_strdup, SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_STANDARD_STREAM, switch_str_nil, and zstr.

Referenced by switch_channel_api_on().

3671 {
3672  char *app;
3673  char *arg = NULL;
3674  char *expanded = NULL;
3675  switch_stream_handle_t stream = { 0 };
3676 
3677  app = switch_core_session_strdup(channel->session, variable);
3678 
3679  if ((arg = strchr(app, ' '))) {
3680  *arg++ = '\0';
3681  }
3682 
3683  if (zstr(arg)) {
3684  expanded = arg;
3685  } else {
3686  expanded = switch_channel_expand_variables(channel, arg);
3687  }
3688 
3689  SWITCH_STANDARD_STREAM(stream);
3690  switch_api_execute(app, expanded, NULL, &stream);
3691  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s process %s: %s(%s)\n%s\n",
3692  channel->name, variable, app, switch_str_nil(expanded), (char *) stream.data);
3693 
3694  if (expanded && expanded != arg) {
3695  free(expanded);
3696  }
3697 
3698  free(stream.data);
3699 }
switch_status_t switch_api_execute(const char *cmd, const char *arg, switch_core_session_t *session, switch_stream_handle_t *stream)
Execute a registered API command.
#define zstr(x)
Definition: switch_utils.h:314
#define SWITCH_STANDARD_STREAM(s)
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:993
#define switch_channel_expand_variables(_channel, _in)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session&#39;s pool.
Definition: switch_core.h:719
switch_core_session_t * session
#define SWITCH_CHANNEL_CHANNEL_LOG(x)

◆ fetch_device_stats()

static void fetch_device_stats ( switch_device_record_t drec)
static

Definition at line 5032 of file switch_channel.c.

References switch_device_stats_s::active, switch_device_stats_s::active_in, switch_device_stats_s::active_out, device_uuid_node_s::callstate, CCS_DOWN, CCS_EARLY, CCS_HANGUP, CCS_HELD, CCS_RING_WAIT, CCS_RINGING, CCS_UNHELD, device_uuid_node_s::direction, switch_device_stats_s::early, switch_device_stats_s::early_in, switch_device_stats_s::early_out, switch_device_stats_s::held, switch_device_stats_s::held_in, switch_device_stats_s::held_out, switch_device_stats_s::hup, switch_device_stats_s::hup_in, switch_device_stats_s::hup_out, device_uuid_node_s::hup_profile, memset(), switch_device_record_s::mutex, device_uuid_node_s::next, switch_device_stats_s::offhook, switch_device_stats_s::offhook_in, switch_device_stats_s::offhook_out, switch_device_stats_s::ring_wait, switch_device_stats_s::ringing, switch_device_stats_s::ringing_in, switch_device_stats_s::ringing_out, switch_device_record_s::stats, SWITCH_CALL_DIRECTION_INBOUND, switch_mutex_lock(), switch_mutex_unlock(), switch_device_stats_s::total, switch_device_stats_s::total_in, switch_device_stats_s::total_out, switch_device_stats_s::unheld, switch_device_stats_s::unheld_in, switch_device_stats_s::unheld_out, and switch_device_record_s::uuid_list.

Referenced by process_device_hup(), and switch_channel_check_device_state().

5033 {
5035 
5036 
5037  memset(&drec->stats, 0, sizeof(switch_device_stats_t));
5038 
5039  switch_mutex_lock(drec->mutex);
5040  for(np = drec->uuid_list; np; np = np->next) {
5041  drec->stats.total++;
5043  drec->stats.total_in++;
5044  } else {
5045  drec->stats.total_out++;
5046  }
5047 
5048  if (!np->hup_profile) {
5049  drec->stats.offhook++;
5051  drec->stats.offhook_in++;
5052  } else {
5053  drec->stats.offhook_out++;
5054  }
5055 
5056  if (np->callstate == CCS_HELD) {
5057  drec->stats.held++;
5059  drec->stats.held_in++;
5060  } else {
5061  drec->stats.held_out++;
5062  }
5063  } else if (np->callstate == CCS_UNHELD) {
5064  drec->stats.unheld++;
5066  drec->stats.unheld_in++;
5067  } else {
5068  drec->stats.unheld_out++;
5069  }
5070  } else {
5071  if (np->callstate == CCS_EARLY) {
5072  drec->stats.early++;
5074  drec->stats.early_in++;
5075  } else {
5076  drec->stats.early_out++;
5077  }
5078  } else if (np->callstate == CCS_RINGING) {
5079  drec->stats.ringing++;
5081  drec->stats.ringing_in++;
5082  } else {
5083  drec->stats.ringing_out++;
5084  }
5085  } else if (np->callstate == CCS_RING_WAIT) {
5086  drec->stats.ring_wait++;
5087  } else if (np->callstate == CCS_HANGUP) {
5088  drec->stats.hup++;
5090  drec->stats.hup_in++;
5091  } else {
5092  drec->stats.hup_out++;
5093  }
5094  } else if (np->callstate != CCS_DOWN) {
5095  drec->stats.active++;
5097  drec->stats.active_in++;
5098  } else {
5099  drec->stats.active_out++;
5100  }
5101  }
5102  }
5103  } else {
5104  drec->stats.hup++;
5106  drec->stats.hup_in++;
5107  } else {
5108  drec->stats.hup_out++;
5109  }
5110  }
5111  }
5112  switch_mutex_unlock(drec->mutex);
5113 
5114 }
switch_device_stats_t stats
Definition: switch_core.h:126
switch_caller_profile_t * hup_profile
Definition: switch_core.h:87
switch_mutex_t * mutex
Definition: switch_core.h:140
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_call_direction_t direction
Definition: switch_core.h:88
struct device_uuid_node_s * next
Definition: switch_core.h:90
switch_channel_callstate_t callstate
Definition: switch_core.h:85
struct device_uuid_node_s * uuid_list
Definition: switch_core.h:138
memset(buf, 0, buflen)

◆ process_device_hup()

static void process_device_hup ( switch_channel_t channel)
static

Definition at line 5181 of file switch_channel.c.

References switch_channel::caller_profile, CF_FINAL_DEVICE_LEG, switch_device_record_s::device_id, switch_channel::device_node, device_uuid_node_s::event, fetch_device_stats(), globals, device_uuid_node_s::hold_record, switch_channel::hold_record, device_uuid_node_s::hup_profile, switch_hold_record_s::next, switch_hold_record_s::off, switch_device_stats_s::offhook, switch_hold_record_s::on, device_uuid_node_s::parent, switch_device_record_s::pool, switch_device_record_s::refs, switch_channel::session, switch_device_record_s::stats, switch_caller_profile_dup(), SWITCH_CHANNEL_CHANNEL_LOG, switch_channel_event_set_extended_data(), switch_channel_set_flag, switch_core_alloc, switch_core_hash_delete(), switch_core_strdup, SWITCH_EVENT_CALL_DETAIL, switch_event_create, switch_ivr_generate_xml_cdr(), SWITCH_LOG_DEBUG, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, switch_hold_record_s::uuid, and device_uuid_node_s::xml_cdr.

Referenced by switch_channel_process_device_hangup().

5182 {
5183  switch_hold_record_t *hr, *newhr, *last = NULL;
5184  switch_device_record_t *drec = NULL;
5185  switch_device_node_t *node;
5186 
5187  if (!channel->device_node) {
5188  return;
5189  }
5190 
5191  switch_mutex_lock(globals.device_mutex);
5192  node = channel->device_node;
5193  drec = channel->device_node->parent;
5194 
5195  node->hup_profile = switch_caller_profile_dup(drec->pool, channel->caller_profile);
5196  fetch_device_stats(drec);
5197 
5198  switch_ivr_generate_xml_cdr(channel->session, &node->xml_cdr);
5201  }
5202 
5203  for (hr = channel->hold_record; hr; hr = hr->next) {
5204  newhr = switch_core_alloc(drec->pool, sizeof(*newhr));
5205  newhr->on = hr->on;
5206  newhr->off = hr->off;
5207 
5208  if (hr->uuid) {
5209  newhr->uuid = switch_core_strdup(drec->pool, hr->uuid);
5210  }
5211 
5212  if (!node->hold_record) {
5213  node->hold_record = newhr;
5214  } else if (last) {
5215  last->next = newhr;
5216  }
5217 
5218  last = newhr;
5219  }
5220 
5221  if (!drec->stats.offhook) { /* this is final call */
5222 
5223  switch_core_hash_delete(globals.device_hash, drec->device_id);
5224  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Processing last call from device [%s]\n",
5225  drec->device_id);
5227  } else {
5228  channel->device_node = NULL;
5229  }
5230 
5231  drec->refs--;
5232 
5233  switch_mutex_unlock(globals.device_mutex);
5234 
5235 }
switch_xml_t xml_cdr
Definition: switch_core.h:83
struct switch_hold_record_s * next
Definition: switch_core.h:78
switch_device_stats_t stats
Definition: switch_core.h:126
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_caller_profile_t * caller_profile
switch_caller_profile_t * hup_profile
Definition: switch_core.h:87
switch_hold_record_t * hold_record
void switch_channel_event_set_extended_data(switch_channel_t *channel, switch_event_t *event)
switch_event_t * event
Definition: switch_core.h:84
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_time_t on
Definition: switch_core.h:75
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static void fetch_device_stats(switch_device_record_t *drec)
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
static struct @1 globals
void * switch_core_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key)
Delete data from a hash based on desired key.
switch_memory_pool_t * pool
Definition: switch_core.h:141
struct switch_device_record_s * parent
Definition: switch_core.h:89
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
#define switch_channel_set_flag(_c, _f)
switch_caller_profile_t * switch_caller_profile_dup(_In_ switch_memory_pool_t *pool, _In_ switch_caller_profile_t *tocopy)
Duplicate an existing caller profile object.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_device_node_t * device_node
switch_hold_record_t * hold_record
Definition: switch_core.h:86
switch_status_t switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t *xml_cdr)
Generate an XML CDR report.
Definition: switch_ivr.c:2862
switch_core_session_t * session
#define SWITCH_CHANNEL_CHANNEL_LOG(x)
switch_time_t off
Definition: switch_core.h:76

◆ send_ind()

static switch_status_t send_ind ( switch_channel_t channel,
switch_core_session_message_types_t  msg_id,
const char *  file,
const char *  func,
int  line 
)
static

Definition at line 3459 of file switch_channel.c.

References switch_core_session_message::from, switch_core_session_message::message_id, switch_channel::name, switch_channel::session, and switch_core_session_perform_receive_message().

Referenced by switch_channel_perform_acknowledge_call(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), and switch_channel_perform_mark_ring_ready_value().

3460 {
3461  switch_core_session_message_t msg = { 0 };
3462 
3463  msg.message_id = msg_id;
3464  msg.from = channel->name;
3465  return switch_core_session_perform_receive_message(channel->session, &msg, file, func, line);
3466 }
switch_core_session_message_types_t message_id
Definition: switch_core.h:183
switch_status_t switch_core_session_perform_receive_message(_In_ switch_core_session_t *session, _In_ switch_core_session_message_t *message, const char *file, const char *func, int line)
Receive a message on a given session.
A message object designed to allow unlike technologies to exchange data.
Definition: switch_core.h:179
switch_core_session_t * session

◆ switch_channel_alloc()

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

Definition at line 450 of file switch_channel.c.

References switch_assert, SWITCH_CALL_DIRECTION_OUTBOUND, SWITCH_CAUSE_NONE, switch_channel_direction(), switch_channel_set_variable, switch_core_alloc, switch_core_hash_init, SWITCH_DTMF_LOG_LEN, SWITCH_EVENT_CHANNEL_DATA, switch_event_create_plain(), switch_mutex_init(), SWITCH_MUTEX_NESTED, switch_queue_create(), SWITCH_STATUS_MEMERR, and SWITCH_STATUS_SUCCESS.

451 {
452  switch_assert(pool != NULL);
453 
454  if (((*channel) = switch_core_alloc(pool, sizeof(switch_channel_t))) == 0) {
455  return SWITCH_STATUS_MEMERR;
456  }
457 
458  switch_event_create_plain(&(*channel)->variables, SWITCH_EVENT_CHANNEL_DATA);
459 
460  switch_core_hash_init(&(*channel)->private_hash);
461  switch_queue_create(&(*channel)->dtmf_queue, SWITCH_DTMF_LOG_LEN, pool);
462  switch_queue_create(&(*channel)->dtmf_log_queue, SWITCH_DTMF_LOG_LEN, pool);
463 
464  switch_mutex_init(&(*channel)->dtmf_mutex, SWITCH_MUTEX_NESTED, pool);
465  switch_mutex_init(&(*channel)->flag_mutex, SWITCH_MUTEX_NESTED, pool);
466  switch_mutex_init(&(*channel)->state_mutex, SWITCH_MUTEX_NESTED, pool);
467  switch_mutex_init(&(*channel)->thread_mutex, SWITCH_MUTEX_NESTED, pool);
468  switch_mutex_init(&(*channel)->profile_mutex, SWITCH_MUTEX_NESTED, pool);
469  (*channel)->hangup_cause = SWITCH_CAUSE_NONE;
470  (*channel)->name = "";
471  (*channel)->direction = (*channel)->logical_direction = direction;
472  switch_channel_set_variable(*channel, "direction", switch_channel_direction(*channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
473 
474  return SWITCH_STATUS_SUCCESS;
475 }
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1431
switch_memory_pool_t * pool
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
static switch_status_t switch_event_create_plain(switch_event_t **event, switch_event_types_t event_id)
Definition: switch_event.h:386
#define SWITCH_DTMF_LOG_LEN
Definition: switch_types.h:237
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1233
#define switch_assert(expr)
#define switch_channel_set_variable(_channel, _var, _val)

◆ switch_channel_api_on()

switch_status_t switch_channel_api_on ( switch_channel_t channel,
const char *  variable_prefix 
)

Definition at line 3702 of file switch_channel.c.

References switch_event_header::array, do_api_on(), switch_event::headers, switch_event_header::idx, switch_event_header::name, switch_event_header::next, switch_channel_get_variables(), switch_event_destroy(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_event_header::value.

Referenced by audio_bridge_on_exchange_media(), audio_bridge_thread(), check_channel_status(), record_callback(), send_record_stop_event(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_perform_mark_ring_ready_value(), switch_core_media_process_udptl(), switch_ivr_originate(), switch_ivr_record_file_event(), and tone_on_dtmf().

3703 {
3705  switch_event_t *event;
3706  int x = 0;
3707 
3708 
3709  switch_channel_get_variables(channel, &event);
3710 
3711  for (hp = event->headers; hp; hp = hp->next) {
3712  char *var = hp->name;
3713  char *val = hp->value;
3714 
3715  if (!strncasecmp(var, variable_prefix, strlen(variable_prefix))) {
3716  if (hp->idx) {
3717  int i;
3718  for (i = 0; i < hp->idx; i++) {
3719  x++;
3720  do_api_on(channel, hp->array[i]);
3721  }
3722  } else {
3723  x++;
3724  do_api_on(channel, val);
3725  }
3726  }
3727  }
3728 
3729  switch_event_destroy(&event);
3730 
3732 }
Representation of an event.
Definition: switch_event.h:80
An event Header.
Definition: switch_event.h:65
static void do_api_on(switch_channel_t *channel, const char *variable)
switch_status_t switch_channel_get_variables(switch_channel_t *channel, switch_event_t **event)
struct switch_event_header * next
Definition: switch_event.h:76
void switch_event_destroy(switch_event_t **event)
Destroy an event.
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_channel_bind_device_state_handler()

switch_status_t switch_channel_bind_device_state_handler ( switch_device_state_function_t  function,
void *  user_data 
)

Definition at line 5500 of file switch_channel.c.

References switch_device_state_binding_s::function, globals, switch_core_alloc, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_MEMERR, SWITCH_STATUS_SUCCESS, and switch_device_state_binding_s::user_data.

5501 {
5502  switch_device_state_binding_t *binding = NULL, *ptr = NULL;
5503  assert(function != NULL);
5504 
5505  if (!(binding = (switch_device_state_binding_t *) switch_core_alloc(globals.pool, sizeof(*binding)))) {
5506  return SWITCH_STATUS_MEMERR;
5507  }
5508 
5509  binding->function = function;
5510  binding->user_data = user_data;
5511 
5512  switch_mutex_lock(globals.device_mutex);
5513  for (ptr = globals.device_bindings; ptr && ptr->next; ptr = ptr->next);
5514 
5515  if (ptr) {
5516  ptr->next = binding;
5517  } else {
5518  globals.device_bindings = binding;
5519  }
5520 
5521  switch_mutex_unlock(globals.device_mutex);
5522 
5523  return SWITCH_STATUS_SUCCESS;
5524 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_device_state_function_t function
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
static struct @1 globals

◆ switch_channel_build_param_string()

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

Definition at line 4291 of file switch_channel.c.

References switch_caller_profile::ani, switch_caller_profile::aniii, switch_caller_profile::caller_id_name, switch_caller_profile::caller_id_number, switch_channel::caller_profile, switch_caller_profile::chan_name, switch_caller_profile::context, switch_stream_handle::data, switch_caller_profile::destination_number, switch_event_header::name, switch_caller_profile::network_addr, profile_node_s::next, switch_event_header::next, switch_caller_profile::rdnis, switch_caller_profile::soft, switch_caller_profile::source, switch_assert, switch_channel_get_caller_profile(), switch_channel_variable_first(), switch_channel_variable_last(), switch_safe_free, SWITCH_STANDARD_STREAM, switch_url_encode(), switch_caller_profile::transfer_source, switch_caller_profile::uuid, profile_node_s::val, switch_event_header::value, profile_node_s::var, switch_stream_handle::write_function, and zstr.

4292 {
4293  switch_stream_handle_t stream = { 0 };
4294  switch_size_t encode_len = 1024, new_len = 0;
4295  char *encode_buf = NULL;
4296  const char *prof[13] = { 0 }, *prof_names[13] = {
4297  0};
4298  char *e = NULL;
4300  uint32_t x = 0;
4301 
4302  SWITCH_STANDARD_STREAM(stream);
4303 
4304  if (prefix) {
4305  stream.write_function(&stream, "%s&", prefix);
4306  }
4307 
4308  encode_buf = malloc(encode_len);
4309  switch_assert(encode_buf);
4310 
4311  if (!caller_profile) {
4312  caller_profile = switch_channel_get_caller_profile(channel);
4313  }
4314 
4315  switch_assert(caller_profile != NULL);
4316 
4317  prof[0] = caller_profile->context;
4318  prof[1] = caller_profile->destination_number;
4319  prof[2] = caller_profile->caller_id_name;
4320  prof[3] = caller_profile->caller_id_number;
4321  prof[4] = caller_profile->network_addr;
4322  prof[5] = caller_profile->ani;
4323  prof[6] = caller_profile->aniii;
4324  prof[7] = caller_profile->rdnis;
4325  prof[8] = caller_profile->source;
4326  prof[9] = caller_profile->chan_name;
4327  prof[10] = caller_profile->uuid;
4328  prof[11] = caller_profile->transfer_source;
4329 
4330  prof_names[0] = "context";
4331  prof_names[1] = "destination_number";
4332  prof_names[2] = "caller_id_name";
4333  prof_names[3] = "caller_id_number";
4334  prof_names[4] = "network_addr";
4335  prof_names[5] = "ani";
4336  prof_names[6] = "aniii";
4337  prof_names[7] = "rdnis";
4338  prof_names[8] = "source";
4339  prof_names[9] = "chan_name";
4340  prof_names[10] = "uuid";
4341  prof_names[11] = "transfer_source";
4342 
4343  for (x = 0; prof[x]; x++) {
4344  if (zstr(prof[x])) {
4345  continue;
4346  }
4347  new_len = (strlen(prof[x]) * 3) + 1;
4348  if (encode_len < new_len) {
4349  char *tmp;
4350 
4351  encode_len = new_len;
4352 
4353  if (!(tmp = realloc(encode_buf, encode_len))) {
4354  abort();
4355  }
4356 
4357  encode_buf = tmp;
4358  }
4359  switch_url_encode(prof[x], encode_buf, encode_len);
4360  stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
4361  }
4362 
4363  if (channel->caller_profile->soft) {
4364  profile_node_t *pn;
4365 
4366  for(pn = channel->caller_profile->soft; pn; pn = pn->next) {
4367  char *var = pn->var;
4368  char *val = pn->val;
4369 
4370  new_len = (strlen((char *) var) * 3) + 1;
4371  if (encode_len < new_len) {
4372  char *tmp;
4373 
4374  encode_len = new_len;
4375 
4376  tmp = realloc(encode_buf, encode_len);
4377  switch_assert(tmp);
4378  encode_buf = tmp;
4379  }
4380 
4381  switch_url_encode((char *) val, encode_buf, encode_len);
4382  stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
4383 
4384  }
4385  }
4386 
4387  if ((hi = switch_channel_variable_first(channel))) {
4388  for (; hi; hi = hi->next) {
4389  char *var = hi->name;
4390  char *val = hi->value;
4391 
4392  new_len = (strlen((char *) var) * 3) + 1;
4393  if (encode_len < new_len) {
4394  char *tmp;
4395 
4396  encode_len = new_len;
4397 
4398  tmp = realloc(encode_buf, encode_len);
4399  switch_assert(tmp);
4400  encode_buf = tmp;
4401  }
4402 
4403  switch_url_encode((char *) val, encode_buf, encode_len);
4404  stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
4405 
4406  }
4408  }
4409 
4410  e = (char *) stream.data + (strlen((char *) stream.data) - 1);
4411 
4412  if (e && *e == '&') {
4413  *e = '\0';
4414  }
4415 
4416  switch_safe_free(encode_buf);
4417 
4418  return stream.data;
4419 }
const char * network_addr
Definition: switch_caller.h:93
switch_caller_profile_t * caller_profile
An event Header.
Definition: switch_event.h:65
char * switch_url_encode(const char *url, char *buf, size_t len)
switch_event_header_t * switch_channel_variable_first(switch_channel_t *channel)
Start iterating over the entries in the channel variable list.
#define zstr(x)
Definition: switch_utils.h:314
const char * caller_id_name
Definition: switch_caller.h:79
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
struct profile_node_s * next
Definition: switch_caller.h:66
uintptr_t switch_size_t
#define SWITCH_STANDARD_STREAM(s)
switch_stream_handle_write_function_t write_function
struct switch_event_header * next
Definition: switch_event.h:76
void switch_channel_variable_last(switch_channel_t *channel)
Stop iterating over channel variables.
const char * caller_id_number
Definition: switch_caller.h:81
profile_node_t * soft
#define switch_assert(expr)
switch_caller_profile_t * switch_channel_get_caller_profile(switch_channel_t *channel)
Retrieve the given channel&#39;s caller profile.

◆ switch_channel_cause2str()

const char* switch_channel_cause2str ( switch_call_cause_t  cause)

Definition at line 202 of file switch_channel.c.

References CAUSE_CHART, and switch_cause_table::name.

Referenced by switch_channel_event_set_basic_data(), switch_channel_handle_cause(), and switch_channel_perform_hangup().

203 {
204  uint8_t x;
205  const char *str = "UNKNOWN";
206 
207  for (x = 0; x < (sizeof(CAUSE_CHART) / sizeof(struct switch_cause_table)) - 1; x++) {
208  if (CAUSE_CHART[x].cause == cause) {
209  str = CAUSE_CHART[x].name;
210  break;
211  }
212  }
213 
214  return str;
215 }
const char * name
static struct switch_cause_table CAUSE_CHART[]

◆ switch_channel_check_device_state()

static void switch_channel_check_device_state ( switch_channel_t channel,
switch_channel_callstate_t  callstate 
)
static

Definition at line 5237 of file switch_channel.c.

References switch_device_stats_s::active, switch_device_record_s::active_start, switch_device_record_s::active_stop, switch_device_record_s::call_start, CCS_UNHELD, CF_FINAL_DEVICE_LEG, switch_device_record_s::device_id, switch_channel::device_node, switch_device_stats_s::early, switch_device_stats_s::early_out, fetch_device_stats(), switch_device_state_binding_s::function, globals, switch_device_stats_s::held, switch_device_record_s::hold_start, switch_device_record_s::hold_stop, switch_device_stats_s::hup, switch_device_record_s::last_call_time, switch_device_record_s::last_state, switch_device_record_s::last_stats, switch_device_record_s::mutex, switch_device_state_binding_s::next, switch_device_stats_s::offhook, device_uuid_node_s::parent, switch_device_record_s::ring_start, switch_device_record_s::ring_stop, switch_device_stats_s::ring_wait, switch_device_stats_s::ringing, switch_device_stats_s::ringing_out, SDS_ACTIVE, SDS_ACTIVE_MULTI, SDS_DOWN, SDS_HANGUP, SDS_HELD, SDS_RINGING, SDS_UNHELD, switch_channel::session, switch_device_record_s::state, switch_device_record_s::stats, switch_channel_callstate2str(), SWITCH_CHANNEL_CHANNEL_LOG, switch_channel_device_state2str(), switch_channel_get_name(), switch_channel_test_flag(), switch_event_add_header(), switch_event_add_header_string(), switch_event_create, SWITCH_EVENT_DEVICE_STATE, switch_event_fire, SWITCH_LOG_DEBUG1, switch_log_printf(), switch_micro_time_now(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, SWITCH_TIME_T_FMT, switch_device_stats_s::total, and switch_device_stats_s::unheld.

Referenced by switch_channel_perform_set_callstate(), switch_channel_process_device_hangup(), and switch_channel_set_device_id().

5238 {
5239  switch_device_record_t *drec = NULL;
5240  switch_device_state_binding_t *ptr = NULL;
5241  switch_event_t *event = NULL;
5242 
5243  if (!channel->device_node) {
5244  return;
5245  }
5246 
5247  drec = channel->device_node->parent;
5248 
5249  switch_mutex_lock(globals.device_mutex);
5250  switch_mutex_lock(drec->mutex);
5251 
5252  fetch_device_stats(drec);
5253 
5254  if (drec->state != SDS_HANGUP) {
5255  if (drec->stats.offhook == 0 || drec->stats.hup == drec->stats.total) {
5256  drec->state = SDS_HANGUP;
5257  } else {
5258  if (drec->stats.active == 0) {
5259  if ((drec->stats.ringing_out + drec->stats.early_out) > 0 || drec->stats.ring_wait > 0) {
5260  drec->state = SDS_RINGING;
5261  } else {
5262  if (drec->stats.held > 0) {
5263  drec->state = SDS_HELD;
5264  } else if (drec->stats.unheld > 0) {
5265  drec->state = SDS_UNHELD;
5266  } else {
5267  drec->state = SDS_DOWN;
5268  }
5269  }
5270  } else if (drec->stats.active == 1) {
5271  drec->state = SDS_ACTIVE;
5272  } else {
5273  drec->state = SDS_ACTIVE_MULTI;
5274  }
5275  }
5276  }
5277 
5278  if ((drec->state == SDS_DOWN && drec->last_state == SDS_DOWN) || (drec->state == SDS_HANGUP && drec->last_state == SDS_HANGUP)) {
5279  switch_mutex_unlock(drec->mutex);
5280  switch_mutex_unlock(globals.device_mutex);
5281  return;
5282  }
5283 
5284  if (!drec->call_start) {
5286  }
5287 
5288  switch(drec->state) {
5289  case SDS_RINGING:
5290  if (!drec->ring_start) {
5292  drec->ring_stop = 0;
5293  }
5294  break;
5295  case SDS_ACTIVE:
5296  case SDS_ACTIVE_MULTI:
5297  if (!drec->active_start) {
5299  drec->active_stop = 0;
5300  }
5301  break;
5302  case SDS_HELD:
5303  if (!drec->hold_start) {
5305  drec->hold_stop = 0;
5306  }
5307  break;
5308  default:
5309  break;
5310  }
5311 
5312  if (callstate != CCS_UNHELD && drec->active_start && drec->state != SDS_ACTIVE && drec->state != SDS_ACTIVE_MULTI) {
5314  }
5315 
5316  if (drec->ring_start && !drec->ring_stop && drec->state != SDS_RINGING) {
5317  drec->ring_stop = switch_micro_time_now();
5318  }
5319 
5320  if (drec->hold_start && !drec->hold_stop && drec->state != SDS_HELD) {
5321  drec->hold_stop = switch_micro_time_now();
5322  }
5323 
5324 
5326  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Device-ID", drec->device_id);
5329  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Device-Call-State", switch_channel_callstate2str(callstate));
5330  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Total-Legs", "%u", drec->stats.total);
5331  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Offhook", "%u", drec->stats.offhook);
5332  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Ringing", "%u", drec->stats.ringing);
5333  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Early", "%u", drec->stats.early);
5334  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Active", "%u", drec->stats.active);
5335  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Held", "%u", drec->stats.held);
5336  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-UnHeld", "%u", drec->stats.unheld);
5337  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Hup", "%u", drec->stats.hup);
5338  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Talk-Time-Start-Uepoch", "%"SWITCH_TIME_T_FMT, drec->active_start);
5339  if (drec->active_stop) {
5340  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Talk-Time-Stop-Uepoch", "%"SWITCH_TIME_T_FMT, drec->active_stop);
5341  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Talk-Time-Milliseconds", "%u", (uint32_t)(drec->active_stop - drec->active_start) / 1000);
5342  }
5343  }
5344 
5346  "%s device: %s\nState: %s Dev State: %s/%s Total:%u Offhook:%u "
5347  "Ringing:%u Early:%u Active:%u Held:%u Unheld:%u Hungup:%u Dur: %u Ringtime: %u Holdtime: %u %s\n",
5348  switch_channel_get_name(channel),
5349  drec->device_id,
5350  switch_channel_callstate2str(callstate),
5353  drec->stats.total,
5354  drec->stats.offhook,
5355  drec->stats.ringing,
5356  drec->stats.early,
5357  drec->stats.active,
5358  drec->stats.held,
5359  drec->stats.unheld,
5360  drec->stats.hup,
5361  drec->active_stop ? (uint32_t)(drec->active_stop - drec->active_start) / 1000 : 0,
5362  drec->ring_stop ? (uint32_t)(drec->ring_stop - drec->ring_start) / 1000 : 0,
5363  drec->hold_stop ? (uint32_t)(drec->hold_stop - drec->hold_start) / 1000 : 0,
5364  switch_channel_test_flag(channel, CF_FINAL_DEVICE_LEG) ? "FINAL LEG" : "");
5365 
5366  for (ptr = globals.device_bindings; ptr; ptr = ptr->next) {
5367  ptr->function(channel->session, callstate, drec);
5368  }
5369 
5370  drec->last_stats = drec->stats;
5371 
5372  if (drec->active_stop) {
5373  drec->active_start = drec->active_stop = 0;
5374  if (drec->state == SDS_ACTIVE || drec->state == SDS_ACTIVE_MULTI) {
5376  }
5377  }
5378 
5379  if (drec->hold_stop) {
5380  drec->hold_start = drec->hold_stop = 0;
5381  if (drec->state == SDS_HELD) {
5383  }
5384  }
5385 
5386  if (drec->ring_stop) {
5387  drec->ring_start = drec->ring_stop = 0;
5388  if (drec->state == SDS_RINGING) {
5390  }
5391  }
5392 
5394 
5395  drec->last_state = drec->state;
5396 
5397  switch_mutex_unlock(drec->mutex);
5398  switch_mutex_unlock(globals.device_mutex);
5399 
5400 
5401  if (event) {
5402  switch_event_fire(&event);
5403  }
5404 
5405 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
switch_device_state_t state
Definition: switch_core.h:128
switch_device_state_t last_state
Definition: switch_core.h:129
switch_device_stats_t stats
Definition: switch_core.h:126
const char * switch_channel_callstate2str(switch_channel_callstate_t callstate)
switch_time_t active_stop
Definition: switch_core.h:131
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
switch_time_t active_start
Definition: switch_core.h:130
switch_mutex_t * mutex
Definition: switch_core.h:140
const char * switch_channel_device_state2str(switch_device_state_t device_state)
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.
switch_time_t ring_stop
Definition: switch_core.h:134
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_device_state_function_t function
switch_time_t hold_start
Definition: switch_core.h:135
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static void fetch_device_stats(switch_device_record_t *drec)
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
switch_time_t ring_start
Definition: switch_core.h:133
#define SWITCH_TIME_T_FMT
static struct @1 globals
switch_time_t call_start
Definition: switch_core.h:137
struct switch_device_record_s * parent
Definition: switch_core.h:89
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_device_node_t * device_node
switch_device_stats_t last_stats
Definition: switch_core.h:127
switch_time_t last_call_time
Definition: switch_core.h:132
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_core_session_t * session
#define SWITCH_CHANNEL_CHANNEL_LOG(x)
struct switch_device_state_binding_s * next
switch_time_t hold_stop
Definition: switch_core.h:136

◆ switch_channel_clear_device_record()

void switch_channel_clear_device_record ( switch_channel_t channel)

Definition at line 5116 of file switch_channel.c.

References CF_FINAL_DEVICE_LEG, switch_device_record_s::device_id, switch_channel::device_node, device_uuid_node_s::event, globals, device_uuid_node_s::hup_profile, switch_device_record_s::mutex, device_uuid_node_s::next, device_uuid_node_s::parent, pool, switch_device_record_s::pool, switch_device_record_s::refs, switch_caller_profile_event_set_data(), SWITCH_CHANNEL_CHANNEL_LOG, switch_channel_test_flag(), switch_core_destroy_memory_pool, switch_event_add_header_string(), SWITCH_EVENT_CALL_DETAIL, switch_event_create, switch_event_destroy(), switch_event_fire, SWITCH_LOG_DEBUG, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_snprintf(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, switch_xml_free(), switch_yield, switch_device_record_s::uuid, switch_device_record_s::uuid_list, and device_uuid_node_s::xml_cdr.

Referenced by switch_core_session_destroy_state().

5117 {
5119  int sanity = 100;
5121  switch_event_t *event;
5122 
5123  if (!channel->device_node || !switch_channel_test_flag(channel, CF_FINAL_DEVICE_LEG)) {
5124  return;
5125  }
5126 
5127  while(--sanity && channel->device_node->parent->refs) {
5128  switch_yield(100000);
5129  }
5130 
5131  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Destroying device cdr %s on device [%s]\n",
5132  channel->device_node->parent->uuid,
5133  channel->device_node->parent->device_id);
5134 
5136  int x = 0;
5137  char prefix[80] = "";
5138 
5139  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Type", "device");
5141 
5143  for(np = channel->device_node->parent->uuid_list; np; np = np->next) {
5144  switch_snprintf(prefix, sizeof(prefix), "Call-%d", ++x);
5146  }
5148 
5149  switch_event_fire(&event);
5150  }
5151 
5153  for(np = channel->device_node->parent->uuid_list; np; np = np->next) {
5154  if (np->xml_cdr) {
5155  switch_xml_free(np->xml_cdr);
5156  }
5157  if (np->event) {
5159  }
5160  }
5162 
5163  pool = channel->device_node->parent->pool;
5164 
5165  switch_mutex_lock(globals.device_mutex);
5167 
5168  switch_mutex_unlock(globals.device_mutex);
5169 
5170 
5171 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
switch_xml_t xml_cdr
Definition: switch_core.h:83
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
switch_memory_pool_t * pool
Representation of an event.
Definition: switch_event.h:80
switch_caller_profile_t * hup_profile
Definition: switch_core.h:87
switch_mutex_t * mutex
Definition: switch_core.h:140
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
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.
switch_event_t * event
Definition: switch_core.h:84
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
void switch_caller_profile_event_set_data(_In_ switch_caller_profile_t *caller_profile, _In_opt_z_ const char *prefix, _In_ switch_event_t *event)
Add headers to an existing event in regards to a specific profile.
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
static struct @1 globals
struct device_uuid_node_s * next
Definition: switch_core.h:90
switch_memory_pool_t * pool
Definition: switch_core.h:141
struct switch_device_record_s * parent
Definition: switch_core.h:89
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
struct device_uuid_node_s * uuid_list
Definition: switch_core.h:138
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_device_node_t * device_node
struct fspr_pool_t switch_memory_pool_t
void switch_event_destroy(switch_event_t **event)
Destroy an event.
#define SWITCH_CHANNEL_CHANNEL_LOG(x)

◆ switch_channel_dequeue_dtmf()

switch_status_t switch_channel_dequeue_dtmf ( switch_channel_t channel,
switch_dtmf_t dtmf 
)

Definition at line 640 of file switch_channel.c.

References CF_DIVERT_EVENTS, switch_dtmf_t::digit, DTMF_FLAG_SENSITIVE, switch_channel::dtmf_log_queue, switch_channel::dtmf_mutex, switch_channel::dtmf_queue, switch_dtmf_t::duration, switch_channel::session, switch_dtmf_t::source, SWITCH_CHANNEL_CHANNEL_LOG, switch_channel_event_set_data(), switch_channel_get_name(), switch_channel_test_flag(), switch_core_default_dtmf_duration(), switch_core_max_dtmf_duration(), switch_core_min_dtmf_duration(), switch_core_session_queue_event(), SWITCH_DTMF_APP, SWITCH_DTMF_ENDPOINT, SWITCH_DTMF_INBAND_AUDIO, SWITCH_DTMF_RTP, SWITCH_DTMF_UNKNOWN, switch_event_add_header(), switch_event_create, SWITCH_EVENT_DTMF, switch_event_fire, switch_log_printf(), SWITCH_LOG_WARNING, switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypop(), switch_queue_trypush(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_test_flag.

Referenced by switch_channel_dequeue_dtmf_string().

641 {
642  switch_event_t *event;
643  void *pop;
644  switch_dtmf_t *dt;
646  int sensitive = 0;
647 
648  switch_mutex_lock(channel->dtmf_mutex);
649 
650  if (switch_queue_trypop(channel->dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
651  dt = (switch_dtmf_t *) pop;
652  *dtmf = *dt;
653  sensitive = switch_test_flag(dtmf, DTMF_FLAG_SENSITIVE);
654 
655  if (!sensitive && switch_queue_trypush(channel->dtmf_log_queue, dt) != SWITCH_STATUS_SUCCESS) {
656  free(dt);
657  }
658 
659  dt = NULL;
660 
661  if (dtmf->duration > switch_core_max_dtmf_duration(0)) {
662  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_WARNING, "%s EXCESSIVE DTMF DIGIT [%c] LEN [%d]\n",
663  switch_channel_get_name(channel), sensitive ? 'S' : dtmf->digit, dtmf->duration);
665  } else if (dtmf->duration < switch_core_min_dtmf_duration(0)) {
666  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_WARNING, "%s SHORT DTMF DIGIT [%c] LEN [%d]\n",
667  switch_channel_get_name(channel), sensitive ? 'S' : dtmf->digit, dtmf->duration);
669  } else if (!dtmf->duration) {
671  }
672 
673  status = SWITCH_STATUS_SUCCESS;
674  }
676 
677  if (!sensitive && status == SWITCH_STATUS_SUCCESS && switch_event_create(&event, SWITCH_EVENT_DTMF) == SWITCH_STATUS_SUCCESS) {
678  const char *dtmf_source_str = NULL;
679  switch_channel_event_set_data(channel, event);
680  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "DTMF-Digit", "%c", dtmf->digit);
681  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "DTMF-Duration", "%u", dtmf->duration);
682  switch(dtmf->source) {
683  case SWITCH_DTMF_INBAND_AUDIO: /* From audio */
684  dtmf_source_str = "INBAND_AUDIO";
685  break;
686  case SWITCH_DTMF_RTP: /* From RTP as a telephone event */
687  dtmf_source_str = "RTP";
688  break;
689  case SWITCH_DTMF_ENDPOINT: /* From endpoint signaling */
690  dtmf_source_str = "ENDPOINT";
691  break;
692  case SWITCH_DTMF_APP: /* Injected by application */
693  dtmf_source_str = "APP";
694  break;
695  case SWITCH_DTMF_UNKNOWN: /* Unknown source */
696  default:
697  dtmf_source_str = "UNKNOWN";
698  break;
699  }
700  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "DTMF-Source", "%s", dtmf_source_str);
702  switch_core_session_queue_event(channel->session, &event);
703  } else {
704  switch_event_fire(&event);
705  }
706  }
707 
708  return status;
709 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
switch_queue_t * dtmf_log_queue
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
uint32_t duration
Definition: switch_types.h:302
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.
uint32_t switch_core_max_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1704
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1744
void switch_channel_event_set_data(switch_channel_t *channel, switch_event_t *event)
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_queue_t * dtmf_queue
switch_status_t switch_core_session_queue_event(_In_ switch_core_session_t *session, _Inout_ switch_event_t **event)
Queue an event on a given session.
uint32_t switch_core_default_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1721
switch_status_t
Common return values.
switch_mutex_t * dtmf_mutex
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1279
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
switch_dtmf_source_t source
Definition: switch_types.h:304
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_core_session_t * session
#define SWITCH_CHANNEL_CHANNEL_LOG(x)

◆ switch_channel_dequeue_dtmf_string()

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

Definition at line 711 of file switch_channel.c.

References switch_dtmf_t::digit, memset(), switch_channel_dequeue_dtmf(), and SWITCH_STATUS_SUCCESS.

712 {
713  switch_size_t x = 0;
714  switch_dtmf_t dtmf = { 0 };
715 
716  memset(dtmf_str, 0, len);
717 
718  while (x < len - 1 && switch_channel_dequeue_dtmf(channel, &dtmf) == SWITCH_STATUS_SUCCESS) {
719  dtmf_str[x++] = dtmf.digit;
720  }
721 
722  return x;
723 
724 }
switch_status_t switch_channel_dequeue_dtmf(switch_channel_t *channel, switch_dtmf_t *dtmf)
uintptr_t switch_size_t
memset(buf, 0, buflen)

◆ switch_channel_device_state2str()

const char* switch_channel_device_state2str ( switch_device_state_t  device_state)

Definition at line 330 of file switch_channel.c.

References DEVICE_STATE_CHART, and switch_device_state_table::name.

Referenced by switch_channel_check_device_state().

331 {
332  uint8_t x;
333  const char *str = "UNKNOWN";
334 
335  for (x = 0; x < (sizeof(DEVICE_STATE_CHART) / sizeof(struct switch_cause_table)) - 1; x++) {
336  if (DEVICE_STATE_CHART[x].device_state == device_state) {
337  str = DEVICE_STATE_CHART[x].name;
338  break;
339  }
340  }
341 
342  return str;
343 }
static struct switch_device_state_table DEVICE_STATE_CHART[]

◆ switch_channel_event_set_basic_data()

void switch_channel_event_set_basic_data ( switch_channel_t channel,
switch_event_t event 
)

Definition at line 2657 of file switch_channel.c.

References switch_codec_implementation::actual_samples_per_second, switch_codec_implementation::bits_per_second, switch_channel::caller_profile, switch_channel::callstate, CF_ANSWERED, CF_DIALPLAN, CF_EARLY_MEDIA, switch_channel::direction, switch_channel::hangup_cause, switch_codec_implementation::iananame, switch_channel::last_profile_type, LP_ORIGINATEE, LP_ORIGINATOR, switch_caller_profile::originatee_caller_profile, switch_caller_profile::originator_caller_profile, switch_channel::profile_mutex, switch_channel::running_state, switch_channel::session, switch_channel::state, SWITCH_CALL_DIRECTION_INBOUND, SWITCH_CALL_DIRECTION_OUTBOUND, switch_caller_profile_event_set_data(), switch_channel_callstate2str(), switch_channel_cause2str(), switch_channel_direction(), switch_channel_down_nosig, switch_channel_get_name(), switch_channel_get_variable_dup(), switch_channel_state_name(), switch_channel_test_flag(), switch_core_session_get_external_id(), switch_core_session_get_read_impl(), switch_core_session_get_uuid(), switch_core_session_get_write_impl(), switch_event_add_header(), switch_event_add_header_string(), switch_event_add_presence_data_cols(), SWITCH_FALSE, switch_mutex_lock(), switch_mutex_unlock(), switch_snprintf(), and SWITCH_STACK_BOTTOM.

Referenced by switch_channel_event_set_data().

2658 {
2659  switch_caller_profile_t *caller_profile, *originator_caller_profile = NULL, *originatee_caller_profile = NULL;
2660  switch_codec_implementation_t impl = { 0 };
2661  char state_num[25];
2662  const char *v;
2663 
2664  switch_mutex_lock(channel->profile_mutex);
2665 
2666  if ((caller_profile = channel->caller_profile)) {
2667  originator_caller_profile = caller_profile->originator_caller_profile;
2668  originatee_caller_profile = caller_profile->originatee_caller_profile;
2669  }
2670 
2673  switch_snprintf(state_num, sizeof(state_num), "%d", channel->state);
2674  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-State-Number", state_num);
2678 
2679  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Call-Direction",
2680  channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
2681  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Call-Direction",
2682  channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
2683 
2684  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-HIT-Dialplan",
2686  switch_channel_test_flag(channel, CF_DIALPLAN) ? "true" : "false");
2687 
2688 
2689  if ((v = switch_channel_get_variable_dup(channel, "presence_id", SWITCH_FALSE, -1))) {
2690  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Presence-ID", v);
2691  }
2692 
2693  if ((v = switch_channel_get_variable_dup(channel, "presence_data", SWITCH_FALSE, -1))) {
2694  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Presence-Data", v);
2695  }
2696 
2697 
2698  if ((v = switch_channel_get_variable_dup(channel, "presence_data_cols", SWITCH_FALSE, -1))) {
2699  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Data-Cols", v);
2700  switch_event_add_presence_data_cols(channel, event, "PD-");
2701  }
2702 
2703  if ((v = switch_channel_get_variable_dup(channel, "call_uuid", SWITCH_FALSE, -1))) {
2704  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-UUID", v);
2705  } else {
2707  }
2708 
2709  if (switch_channel_down_nosig(channel)) {
2710  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "hangup");
2711  } else if (switch_channel_test_flag(channel, CF_ANSWERED)) {
2712  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "answered");
2713  } else if (switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
2714  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "early");
2715  } else {
2716  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "ringing");
2717  }
2718 
2719  if (channel->hangup_cause) {
2721  }
2722 
2723 
2724  switch_core_session_get_read_impl(channel->session, &impl);
2725 
2726  if (impl.iananame) {
2727  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Name", impl.iananame);
2728  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Rate", "%u", impl.actual_samples_per_second);
2729  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Bit-Rate", "%d", impl.bits_per_second);
2730  }
2731 
2733 
2734  if (impl.iananame) {
2735  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Name", impl.iananame);
2736  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Rate", "%u", impl.actual_samples_per_second);
2737  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Bit-Rate", "%d", impl.bits_per_second);
2738  }
2739 
2740  /* Index Caller's Profile */
2741  if (caller_profile) {
2742  switch_caller_profile_event_set_data(caller_profile, "Caller", event);
2743  }
2744 
2745  /* Index Originator/ee's Profile */
2746  if (originator_caller_profile && channel->last_profile_type == LP_ORIGINATOR) {
2747  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Other-Type", "originator");
2748  switch_caller_profile_event_set_data(originator_caller_profile, "Other-Leg", event);
2749  } else if (originatee_caller_profile && channel->last_profile_type == LP_ORIGINATEE) { /* Index Originatee's Profile */
2750  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Other-Type", "originatee");
2751  switch_caller_profile_event_set_data(originatee_caller_profile, "Other-Leg", event);
2752  }
2753 
2754 
2756 }
Call Specific Data.
Definition: switch_caller.h:73
struct switch_caller_profile * originatee_caller_profile
void switch_event_add_presence_data_cols(switch_channel_t *channel, switch_event_t *event, const char *prefix)
const char * switch_channel_callstate2str(switch_channel_callstate_t callstate)
switch_caller_profile_t * caller_profile
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
const char * switch_core_session_get_external_id(_In_ switch_core_session_t *session)
Retrieve the unique external identifier from a session.
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.
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
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.
switch_mutex_t * profile_mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
void switch_caller_profile_event_set_data(_In_ switch_caller_profile_t *caller_profile, _In_opt_z_ const char *prefix, _In_ switch_event_t *event)
Add headers to an existing event in regards to a specific profile.
switch_channel_state_t running_state
const char * switch_channel_state_name(switch_channel_state_t state)
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
switch_originator_type_t last_profile_type
#define switch_channel_down_nosig(_channel)
switch_status_t switch_core_session_get_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
struct switch_caller_profile * originator_caller_profile
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
switch_call_direction_t direction
switch_channel_state_t state
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
A table of settings and callbacks that define a paticular implementation of a codec.
switch_channel_callstate_t callstate
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_core_session_t * session
switch_call_cause_t hangup_cause
const char * switch_channel_cause2str(switch_call_cause_t cause)

◆ switch_channel_event_set_data()

void switch_channel_event_set_data ( switch_channel_t channel,
switch_event_t event 
)

Definition at line 2843 of file switch_channel.c.

References switch_channel::profile_mutex, switch_channel_event_set_basic_data(), switch_channel_event_set_extended_data(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by 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(), and switch_channel_perform_set_running_state().

2844 {
2845  switch_mutex_lock(channel->profile_mutex);
2846  switch_channel_event_set_basic_data(channel, event);
2849 }
void switch_channel_event_set_basic_data(switch_channel_t *channel, switch_event_t *event)
void switch_channel_event_set_extended_data(switch_channel_t *channel, switch_event_t *event)
switch_mutex_t * profile_mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308

◆ switch_channel_event_set_extended_data()

void switch_channel_event_set_extended_data ( switch_channel_t channel,
switch_event_t event 
)

Definition at line 2758 of file switch_channel.c.

References buf, CF_VERBOSE_EVENTS, switch_event::event_id, switch_event::headers, switch_event_header::name, switch_event_header::next, switch_event::next, switch_channel::profile_mutex, switch_channel::scope_variables, SCSC_VERBOSE_EVENTS, switch_assert, switch_channel_test_flag(), switch_core_session_ctl(), switch_event_add_header_string(), SWITCH_EVENT_API, SWITCH_EVENT_CALL_UPDATE, SWITCH_EVENT_CHANNEL_ANSWER, SWITCH_EVENT_CHANNEL_BRIDGE, SWITCH_EVENT_CHANNEL_CREATE, SWITCH_EVENT_CHANNEL_DATA, SWITCH_EVENT_CHANNEL_DESTROY, SWITCH_EVENT_CHANNEL_EXECUTE, SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE, SWITCH_EVENT_CHANNEL_HANGUP, SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE, SWITCH_EVENT_CHANNEL_HOLD, SWITCH_EVENT_CHANNEL_ORIGINATE, SWITCH_EVENT_CHANNEL_PARK, SWITCH_EVENT_CHANNEL_PROGRESS, SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA, SWITCH_EVENT_CHANNEL_UNBRIDGE, SWITCH_EVENT_CHANNEL_UNHOLD, SWITCH_EVENT_CHANNEL_UNPARK, SWITCH_EVENT_CHANNEL_UUID, SWITCH_EVENT_CUSTOM, switch_event_get_header, SWITCH_EVENT_MEDIA_BUG_START, SWITCH_EVENT_MEDIA_BUG_STOP, SWITCH_EVENT_PLAYBACK_START, SWITCH_EVENT_PLAYBACK_STOP, SWITCH_EVENT_RECORD_START, SWITCH_EVENT_RECORD_STOP, SWITCH_EVENT_REQUEST_PARAMS, SWITCH_EVENT_SESSION_HEARTBEAT, SWITCH_EVENT_TEXT, switch_mutex_lock(), switch_mutex_unlock(), switch_snprintf(), SWITCH_STACK_BOTTOM, switch_event_header::value, and switch_channel::variables.

Referenced by process_device_hup(), and switch_channel_event_set_data().

2759 {
2761  int global_verbose_events = -1;
2762 
2763  switch_mutex_lock(channel->profile_mutex);
2764 
2765  switch_core_session_ctl(SCSC_VERBOSE_EVENTS, &global_verbose_events);
2766 
2767  if (global_verbose_events ||
2769  switch_event_get_header(event, "presence-data-cols") ||
2772  event->event_id == SWITCH_EVENT_CHANNEL_UUID ||
2774  event->event_id == SWITCH_EVENT_CHANNEL_PARK ||
2783  event->event_id == SWITCH_EVENT_CHANNEL_DATA ||
2788  event->event_id == SWITCH_EVENT_API ||
2789  event->event_id == SWITCH_EVENT_RECORD_START ||
2790  event->event_id == SWITCH_EVENT_RECORD_STOP ||
2793  event->event_id == SWITCH_EVENT_CALL_UPDATE ||
2796  event->event_id == SWITCH_EVENT_CHANNEL_HOLD ||
2798  event->event_id == SWITCH_EVENT_TEXT ||
2799  event->event_id == SWITCH_EVENT_CUSTOM) {
2800 
2801  /* Index Variables */
2802 
2803  if (channel->scope_variables) {
2804  switch_event_t *ep;
2805 
2806  for (ep = channel->scope_variables; ep; ep = ep->next) {
2807  for (hi = ep->headers; hi; hi = hi->next) {
2808  char buf[1024];
2809  char *vvar = NULL, *vval = NULL;
2810 
2811  vvar = (char *) hi->name;
2812  vval = (char *) hi->value;
2813 
2814  switch_assert(vvar && vval);
2815  switch_snprintf(buf, sizeof(buf), "scope_variable_%s", vvar);
2816 
2817  if (!switch_event_get_header(event, buf)) {
2819  }
2820  }
2821  }
2822  }
2823 
2824  if (channel->variables) {
2825  for (hi = channel->variables->headers; hi; hi = hi->next) {
2826  char buf[1024];
2827  char *vvar = NULL, *vval = NULL;
2828 
2829  vvar = (char *) hi->name;
2830  vval = (char *) hi->value;
2831 
2832  switch_assert(vvar && vval);
2833  switch_snprintf(buf, sizeof(buf), "variable_%s", vvar);
2835  }
2836  }
2837  }
2838 
2840 }
switch_event_types_t event_id
Definition: switch_event.h:82
switch_event_t * variables
Representation of an event.
Definition: switch_event.h:80
An event Header.
Definition: switch_event.h:65
struct switch_event * next
Definition: switch_event.h:101
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
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.
switch_mutex_t * profile_mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_event_t * scope_variables
switch_byte_t switch_byte_t * buf
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
struct switch_event_header * next
Definition: switch_event.h:76
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
int32_t switch_core_session_ctl(switch_session_ctl_t cmd, void *val)
send a control message to the core
Definition: switch_core.c:2651
#define switch_assert(expr)
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_channel_execute_on()

switch_status_t switch_channel_execute_on ( switch_channel_t channel,
const char *  variable_prefix 
)

Definition at line 3780 of file switch_channel.c.

References switch_event_header::array, switch_event::headers, switch_event_header::idx, switch_event_header::name, switch_event_header::next, switch_channel_execute_on_value(), switch_channel_get_variables(), switch_core_get_variables(), switch_event_destroy(), switch_event_merge(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_event_header::value.

Referenced by audio_bridge_on_exchange_media(), audio_bridge_thread(), check_channel_status(), check_timeout(), record_callback(), record_helper_post_process(), send_record_stop_event(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_perform_mark_ring_ready_value(), switch_core_media_activate_rtp(), switch_core_media_negotiate_sdp(), switch_core_media_process_t38_passthru(), switch_core_media_process_udptl(), switch_core_media_read_frame(), switch_core_media_set_codec(), switch_ivr_originate(), switch_ivr_record_file_event(), switch_ivr_session_transfer(), tone_detect_callback(), and tone_on_dtmf().

3781 {
3783  switch_event_t *event, *cevent;
3784  int x = 0;
3785 
3786  switch_core_get_variables(&event);
3787  switch_channel_get_variables(channel, &cevent);
3788  switch_event_merge(event, cevent);
3789 
3790  for (hp = event->headers; hp; hp = hp->next) {
3791  char *var = hp->name;
3792  char *val = hp->value;
3793 
3794  if (!strncasecmp(var, variable_prefix, strlen(variable_prefix))) {
3795  if (hp->idx) {
3796  int i;
3797  for (i = 0; i < hp->idx; i++) {
3798  x++;
3799  switch_channel_execute_on_value(channel, hp->array[i]);
3800  }
3801  } else {
3802  x++;
3803  switch_channel_execute_on_value(channel, val);
3804  }
3805  }
3806  }
3807 
3808  switch_event_destroy(&event);
3809  switch_event_destroy(&cevent);
3810 
3812 }
Representation of an event.
Definition: switch_event.h:80
An event Header.
Definition: switch_event.h:65
switch_status_t switch_core_get_variables(switch_event_t **event)
Definition: switch_core.c:386
void switch_event_merge(switch_event_t *event, switch_event_t *tomerge)
switch_status_t switch_channel_get_variables(switch_channel_t *channel, switch_event_t **event)
struct switch_event_header * next
Definition: switch_event.h:76
void switch_event_destroy(switch_event_t **event)
Destroy an event.
switch_status_t switch_channel_execute_on_value(switch_channel_t *channel, const char *variable_value)
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_channel_execute_on_value()

switch_status_t switch_channel_execute_on_value ( switch_channel_t channel,
const char *  variable_value 
)

Definition at line 3734 of file switch_channel.c.

References switch_channel::session, switch_assert, switch_channel_expand_variables, switch_core_session_execute_application, switch_core_session_execute_application_async(), switch_core_session_strdup, and zstr.

Referenced by record_callback(), record_helper_post_process(), send_record_stop_event(), switch_channel_execute_on(), and switch_ivr_record_file_event().

3735 {
3736  switch_status_t status;
3737  char *arg = NULL;
3738  char *p;
3739  int bg = 0;
3740  char *app;
3741  char *expanded = NULL;
3742 
3743  app = switch_core_session_strdup(channel->session, variable_value);
3744 
3745  for(p = app; p && *p; p++) {
3746  if (*p == ' ' || (*p == ':' && (*(p+1) != ':'))) {
3747  *p++ = '\0';
3748  arg = p;
3749  break;
3750  } else if (*p == ':' && (*(p+1) == ':')) {
3751  bg++;
3752  break;
3753  }
3754  }
3755 
3756  switch_assert(app != NULL);
3757  if (!strncasecmp(app, "perl", 4)) {
3758  bg++;
3759  }
3760 
3761  if (zstr(arg)) {
3762  expanded = arg;
3763  } else {
3764  expanded = switch_channel_expand_variables(channel, arg);
3765  }
3766 
3767  if (bg) {
3768  status = switch_core_session_execute_application_async(channel->session, app, arg);
3769  } else {
3770  status = switch_core_session_execute_application(channel->session, app, arg);
3771  }
3772 
3773  if (expanded && expanded != arg) {
3774  free(expanded);
3775  }
3776 
3777  return status;
3778 }
switch_status_t switch_core_session_execute_application_async(switch_core_session_t *session, const char *app, const char *arg)
#define zstr(x)
Definition: switch_utils.h:314
#define switch_core_session_execute_application(_a, _b, _c)
Execute an application on a session.
Definition: switch_core.h:1129
#define switch_channel_expand_variables(_channel, _in)
switch_status_t
Common return values.
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session&#39;s pool.
Definition: switch_core.h:719
#define switch_assert(expr)
switch_core_session_t * session

◆ switch_channel_flush_dtmf()

void switch_channel_flush_dtmf ( switch_channel_t channel)

Definition at line 726 of file switch_channel.c.

References CS_HANGUP, switch_channel::dtmf_log_queue, switch_channel::dtmf_mutex, switch_channel::dtmf_queue, switch_channel::state, switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypop(), switch_queue_trypush(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_channel_uninit().

727 {
728  void *pop;
729 
730  switch_mutex_lock(channel->dtmf_mutex);
731  while (switch_queue_trypop(channel->dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
732  switch_dtmf_t *dt = (switch_dtmf_t *) pop;
733  if (channel->state >= CS_HANGUP || switch_queue_trypush(channel->dtmf_log_queue, dt) != SWITCH_STATUS_SUCCESS) {
734  free(dt);
735  }
736  }
738 }
switch_queue_t * dtmf_log_queue
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_queue_t * dtmf_queue
switch_mutex_t * dtmf_mutex
switch_channel_state_t state
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1279

◆ switch_channel_get_cause()

switch_call_cause_t switch_channel_get_cause ( switch_channel_t channel)

Definition at line 238 of file switch_channel.c.

References switch_channel::hangup_cause.

239 {
240  return channel->hangup_cause;
241 }
switch_call_cause_t hangup_cause

◆ switch_channel_get_device_record()

switch_device_record_t* switch_channel_get_device_record ( switch_channel_t channel)

Definition at line 5482 of file switch_channel.c.

References switch_channel::device_node, switch_device_record_s::mutex, device_uuid_node_s::parent, and switch_mutex_lock().

5483 {
5484  if (channel->device_node) {
5486  return channel->device_node->parent;
5487  }
5488 
5489  return NULL;
5490 }
switch_mutex_t * mutex
Definition: switch_core.h:140
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
struct switch_device_record_s * parent
Definition: switch_core.h:89
switch_device_node_t * device_node

◆ switch_channel_get_hold_record()

switch_hold_record_t* switch_channel_get_hold_record ( switch_channel_t channel)

Definition at line 197 of file switch_channel.c.

References switch_channel::hold_record.

Referenced by switch_ivr_generate_xml_cdr().

198 {
199  return channel->hold_record;
200 }
switch_hold_record_t * hold_record

◆ switch_channel_get_partner_uuid()

const char* switch_channel_get_partner_uuid ( switch_channel_t channel)

◆ switch_channel_get_partner_uuid_copy()

const char* switch_channel_get_partner_uuid_copy ( switch_channel_t channel,
char *  buf,
switch_size_t  blen 
)

Definition at line 4846 of file switch_channel.c.

References switch_channel::profile_mutex, switch_channel_get_variable_dup(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE, SWITCH_SIGNAL_BOND_VARIABLE, and SWITCH_TRUE.

Referenced by switch_core_session_perform_get_partner().

4847 {
4848  const char *uuid = NULL;
4849 
4850  switch_mutex_lock(channel->profile_mutex);
4853  }
4854 
4855  if (uuid) {
4856  strncpy(buf, uuid, blen);
4857  uuid = (const char *) buf;
4858  }
4860 
4861  return uuid;
4862 }
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.
#define SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE
Definition: switch_types.h:204
switch_mutex_t * profile_mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_byte_t switch_byte_t * buf
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
#define SWITCH_SIGNAL_BOND_VARIABLE
Definition: switch_types.h:203

◆ switch_channel_get_queued_extension()

switch_caller_extension_t* switch_channel_get_queued_extension ( switch_channel_t channel)

Definition at line 3312 of file switch_channel.c.

References switch_channel::profile_mutex, switch_channel::queued_extension, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_standard_on_routing().

3313 {
3314  switch_caller_extension_t *caller_extension;
3315 
3316  switch_mutex_lock(channel->profile_mutex);
3317  caller_extension = channel->queued_extension;
3318  channel->queued_extension = NULL;
3320 
3321  return caller_extension;
3322 }
An Abstract Representation of a dialplan extension.
switch_mutex_t * profile_mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_caller_extension_t * queued_extension
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308

◆ switch_channel_get_timetable()

switch_channel_timetable_t* switch_channel_get_timetable ( switch_channel_t channel)

Definition at line 419 of file switch_channel.c.

References switch_channel::caller_profile, switch_channel::profile_mutex, switch_mutex_lock(), switch_mutex_unlock(), and switch_caller_profile::times.

420 {
421  switch_channel_timetable_t *times = NULL;
422 
423  if (channel->caller_profile) {
425  times = channel->caller_profile->times;
427  }
428 
429  return times;
430 }
switch_caller_profile_t * caller_profile
switch_mutex_t * profile_mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
struct switch_channel_timetable * times

◆ switch_channel_global_init()

void switch_channel_global_init ( switch_memory_pool_t pool)

Definition at line 5017 of file switch_channel.c.

References globals, memset(), pool, switch_core_hash_init, switch_mutex_init(), and SWITCH_MUTEX_NESTED.

Referenced by switch_core_init().

5018 {
5019  memset(&globals, 0, sizeof(globals));
5020  globals.pool = pool;
5021 
5023  switch_core_hash_init(&globals.device_hash);
5024 }
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1431
switch_memory_pool_t * pool
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
static struct @1 globals
memset(buf, 0, buflen)

◆ switch_channel_global_uninit()

void switch_channel_global_uninit ( void  )

Definition at line 5026 of file switch_channel.c.

References globals, and switch_core_hash_destroy().

Referenced by switch_core_destroy().

5027 {
5028  switch_core_hash_destroy(&globals.device_hash);
5029 }
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
static struct @1 globals

◆ switch_channel_handle_cause()

void switch_channel_handle_cause ( switch_channel_t channel,
switch_call_cause_t  cause 
)

Definition at line 4876 of file switch_channel.c.

References CF_CONFIRM_BLIND_TRANSFER, CF_TRANSFER, CS_ROUTING, switch_channel::session, SWITCH_CAUSE_ATTENDED_TRANSFER, SWITCH_CAUSE_NO_ANSWER, SWITCH_CAUSE_NO_USER_RESPONSE, SWITCH_CAUSE_ORIGINATOR_CANCEL, switch_channel_cause2str(), switch_channel_get_state(), switch_channel_get_variable, switch_channel_hangup, SWITCH_CHANNEL_SESSION_LOG, switch_channel_test_flag(), switch_channel_up_nosig, switch_core_session_strdup, switch_ivr_session_transfer(), SWITCH_LOG_DEBUG, switch_log_printf(), switch_separate_string(), switch_snprintf(), switch_split, and switch_true().

Referenced by signal_bridge_on_hangup(), switch_ivr_enterprise_orig_and_bridge(), switch_ivr_enterprise_originate(), switch_ivr_multi_threaded_bridge(), and switch_ivr_orig_and_bridge().

4877 {
4878  switch_core_session_t *session = channel->session;
4879  const char *transfer_on_fail = NULL;
4880  char *tof_data = NULL;
4881  char *tof_array[4] = { 0 };
4882  //int tof_arrayc = 0;
4883 
4884  if (!switch_channel_up_nosig(channel)) {
4885  return;
4886  }
4887 
4888  transfer_on_fail = switch_channel_get_variable(channel, "transfer_on_fail");
4889  tof_data = switch_core_session_strdup(session, transfer_on_fail);
4890  switch_split(tof_data, ' ', tof_array);
4891  transfer_on_fail = tof_array[0];
4892 
4893  /*
4894  if the variable continue_on_fail is set it can be:
4895  'true' to continue on all failures.
4896  'false' to not continue.
4897  A list of codes either names or numbers eg "user_busy,normal_temporary_failure,603"
4898  failure_causes acts as the opposite version
4899  EXCEPTION... ATTENDED_TRANSFER never is a reason to continue.......
4900  */
4901  if (cause != SWITCH_CAUSE_ATTENDED_TRANSFER) {
4902  const char *continue_on_fail = NULL, *failure_causes = NULL;
4903 
4904  continue_on_fail = switch_channel_get_variable(channel, "continue_on_fail");
4905  failure_causes = switch_channel_get_variable(channel, "failure_causes");
4906 
4907  if (continue_on_fail || failure_causes) {
4908  const char *cause_str;
4909  char cause_num[35] = "";
4910 
4911  cause_str = switch_channel_cause2str(cause);
4912  switch_snprintf(cause_num, sizeof(cause_num), "%u", cause);
4913 
4914  if (failure_causes) {
4915  char *lbuf = switch_core_session_strdup(session, failure_causes);
4916  char *argv[256] = { 0 };
4917  int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
4918  int i, x = 0;
4919 
4920  for (i = 0; i < argc; i++) {
4921  if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
4922  x++;
4923  break;
4924  }
4925  }
4926  if (!x) {
4928  "Failure causes [%s]: Cause: %s\n", failure_causes, cause_str);
4929  return;
4930  }
4931  }
4932 
4933  if (continue_on_fail) {
4934  if (switch_true(continue_on_fail)) {
4935  return;
4936  } else {
4937  char *lbuf = switch_core_session_strdup(session, continue_on_fail);
4938  char *argv[256] = { 0 };
4939  int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
4940  int i;
4941 
4942  for (i = 0; i < argc; i++) {
4943  if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
4945  "Continue on fail [%s]: Cause: %s\n", continue_on_fail, cause_str);
4946  return;
4947  }
4948  }
4949  }
4950  }
4951  } else {
4952  /* no answer is *always* a reason to continue */
4954  return;
4955  }
4956  }
4957 
4958  if (transfer_on_fail || failure_causes) {
4959  const char *cause_str;
4960  char cause_num[35] = "";
4961 
4962  cause_str = switch_channel_cause2str(cause);
4963  switch_snprintf(cause_num, sizeof(cause_num), "%u", cause);
4964 
4965  if ((tof_array[1] == NULL ) || (!strcasecmp(tof_array[1], "auto_cause"))){
4966  tof_array[1] = (char *) cause_str;
4967  }
4968 
4969  if (failure_causes) {
4970  char *lbuf = switch_core_session_strdup(session, failure_causes);
4971  char *argv[256] = { 0 };
4972  int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
4973  int i, x = 0;
4974 
4975  for (i = 0; i < argc; i++) {
4976  if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
4977  x++;
4978  break;
4979  }
4980  }
4981  if (!x) {
4983  "Failure causes [%s]: Cause: %s\n", failure_causes, cause_str);
4984 
4985  switch_ivr_session_transfer(session, tof_array[1], tof_array[2], tof_array[3]);
4986  }
4987  }
4988 
4989  if (transfer_on_fail) {
4990  if (switch_true(transfer_on_fail)) {
4991  return;
4992  } else {
4993  char *lbuf = switch_core_session_strdup(session, transfer_on_fail);
4994  char *argv[256] = { 0 };
4995  int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
4996  int i;
4997 
4998  for (i = 0; i < argc; i++) {
4999  if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
5001  "Transfer on fail [%s]: Cause: %s\n", transfer_on_fail, cause_str);
5002  switch_ivr_session_transfer(session, tof_array[1], tof_array[2], tof_array[3]);
5003  }
5004  }
5005  }
5006  }
5007  }
5008  }
5009 
5010 
5012  switch_channel_get_state(channel) != CS_ROUTING) {
5013  switch_channel_hangup(channel, cause);
5014  }
5015 }
switch_channel_state_t switch_channel_get_state(switch_channel_t *channel)
Get the current state of a channel in the state engine.
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it&#39;s state machine to end.
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define switch_split(_data, _delim, _array)
Definition: switch_utils.h:375
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
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.
switch_status_t switch_ivr_session_transfer(_In_ switch_core_session_t *session, const char *extension, const char *dialplan, const char *context)
Transfer an existing session to another location.
unsigned int switch_separate_string(_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen)
Separate a string into an array based on a character delimiter.
#define switch_channel_get_variable(_c, _v)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
#define switch_channel_up_nosig(_channel)
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session&#39;s pool.
Definition: switch_core.h:719
switch_core_session_t * session
const char * switch_channel_cause2str(switch_call_cause_t cause)

◆ switch_channel_has_dtmf()

switch_size_t switch_channel_has_dtmf ( switch_channel_t channel)

Definition at line 492 of file switch_channel.c.

References switch_channel::dtmf_mutex, switch_channel::dtmf_queue, switch_mutex_lock(), switch_mutex_unlock(), and switch_queue_size().

493 {
494  switch_size_t has;
495 
496  switch_mutex_lock(channel->dtmf_mutex);
497  has = switch_queue_size(channel->dtmf_queue);
499 
500  return has;
501 }
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1238
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_queue_t * dtmf_queue
uintptr_t switch_size_t
switch_mutex_t * dtmf_mutex

◆ switch_channel_name_state()

switch_channel_state_t switch_channel_name_state ( const char *  name)

Definition at line 2328 of file switch_channel.c.

References CS_DESTROY, and state_names.

2329 {
2330  uint32_t x = 0;
2331  for (x = 0; state_names[x]; x++) {
2332  if (!strcasecmp(state_names[x], name)) {
2333  return (switch_channel_state_t) x;
2334  }
2335  }
2336 
2337  return CS_DESTROY;
2338 }
static const char * state_names[]
switch_channel_state_t
Channel States (these are the defaults, CS_SOFT_EXECUTE, CS_EXCHANGE_MEDIA, and CS_CONSUME_MEDIA are ...
const char *const name
Definition: switch_cJSON.h:250

◆ switch_channel_pass_sdp()

switch_status_t switch_channel_pass_sdp ( switch_channel_t from_channel,
switch_channel_t to_channel,
const char *  sdp 
)

Definition at line 5551 of file switch_channel.c.

References switch_channel::session, SWITCH_B_SDP_VARIABLE, switch_channel_get_variable, switch_channel_set_variable, switch_core_media_process_sdp_filter(), switch_safe_free, and SWITCH_STATUS_FALSE.

Referenced by switch_core_session_outgoing_channel().

5552 {
5554  char *use_sdp = (char *) sdp;
5555  char *patched_sdp = NULL;
5556 
5558  const char *var;
5559 
5560  if ((var = switch_channel_get_variable(from_channel, "bypass_media_sdp_filter"))) {
5561  if ((patched_sdp = switch_core_media_process_sdp_filter(use_sdp, var, from_channel->session))) {
5562  use_sdp = patched_sdp;
5563  }
5564  }
5565 
5566  switch_channel_set_variable(to_channel, SWITCH_B_SDP_VARIABLE, use_sdp);
5567  }
5568 
5569  switch_safe_free(patched_sdp);
5570 
5571  return status;
5572 }
char * switch_core_media_process_sdp_filter(const char *sdp, const char *cmd_buf, switch_core_session_t *session)
#define switch_channel_get_variable(_c, _v)
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
switch_status_t
Common return values.
#define SWITCH_B_SDP_VARIABLE
Definition: switch_types.h:199
#define switch_channel_set_variable(_channel, _var, _val)
switch_core_session_t * session

◆ switch_channel_process_device_hangup()

void switch_channel_process_device_hangup ( switch_channel_t channel)

Definition at line 5173 of file switch_channel.c.

References switch_channel::callstate, process_device_hup(), and switch_channel_check_device_state().

Referenced by switch_core_session_hangup_state().

5174 {
5175 
5176  switch_channel_check_device_state(channel, channel->callstate);
5177  process_device_hup(channel);
5178 
5179 }
static void process_device_hup(switch_channel_t *channel)
static void switch_channel_check_device_state(switch_channel_t *channel, switch_channel_callstate_t callstate)
switch_channel_callstate_t callstate

◆ switch_channel_queue_dtmf()

switch_status_t switch_channel_queue_dtmf ( switch_channel_t channel,
const switch_dtmf_t dtmf 
)

Definition at line 503 of file switch_channel.c.

References switch_dtmf_t::digit, DTMF_FLAG_SENSITIVE, switch_channel::dtmf_mutex, switch_channel::dtmf_queue, switch_dtmf_t::duration, is_dtmf, switch_channel::session, switch_assert, SWITCH_CHANNEL_CHANNEL_LOG, switch_channel_get_name(), switch_channel_get_variable_dup(), switch_core_default_dtmf_duration(), switch_core_max_dtmf_duration(), switch_core_media_break(), switch_core_min_dtmf_duration(), switch_core_session_recv_dtmf(), SWITCH_FALSE, SWITCH_LOG_DEBUG, SWITCH_LOG_INFO, switch_log_printf(), SWITCH_MEDIA_TYPE_AUDIO, switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypop(), switch_queue_trypush(), SWITCH_SENSITIVE_DTMF_VARIABLE, switch_set_flag, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_true(), and switch_zmalloc.

Referenced by switch_channel_queue_dtmf_string().

504 {
505  switch_status_t status;
506  void *pop;
507  switch_dtmf_t new_dtmf = { 0 };
509 
510  switch_assert(dtmf);
511 
512  switch_mutex_lock(channel->dtmf_mutex);
513  new_dtmf = *dtmf;
514 
515  if (sensitive) {
516  switch_set_flag((&new_dtmf), DTMF_FLAG_SENSITIVE);
517  }
518 
519  if ((status = switch_core_session_recv_dtmf(channel->session, dtmf) != SWITCH_STATUS_SUCCESS)) {
520  goto done;
521  }
522 
523  if (is_dtmf(new_dtmf.digit)) {
524  switch_dtmf_t *dt;
525  int x = 0;
526 
527  if (!sensitive) {
528  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_INFO, "RECV DTMF %c:%d\n", new_dtmf.digit, new_dtmf.duration);
529  }
530 
531  if (new_dtmf.digit != 'w' && new_dtmf.digit != 'W') {
532  if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
533  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s EXCESSIVE DTMF DIGIT LEN [%d]\n",
534  switch_channel_get_name(channel), new_dtmf.duration);
536  } else if (new_dtmf.duration < switch_core_min_dtmf_duration(0)) {
537  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s SHORT DTMF DIGIT LEN [%d]\n",
538  switch_channel_get_name(channel), new_dtmf.duration);
540  }
541  }
542 
543  if (!new_dtmf.duration) {
545  }
546 
547 
548  switch_zmalloc(dt, sizeof(*dt));
549  *dt = new_dtmf;
550 
551 
552  while (switch_queue_trypush(channel->dtmf_queue, dt) != SWITCH_STATUS_SUCCESS) {
553  if (switch_queue_trypop(channel->dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
554  free(pop);
555  }
556  if (++x > 100) {
557  status = SWITCH_STATUS_FALSE;
558  free(dt);
559  goto done;
560  }
561  }
562  }
563 
564  status = SWITCH_STATUS_SUCCESS;
565 
566  done:
567 
569 
571 
572  return status;
573 }
#define SWITCH_SENSITIVE_DTMF_VARIABLE
Definition: switch_types.h:146
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
switch_bool_t
Definition: switch_types.h:441
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
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.
uint32_t duration
Definition: switch_types.h:302
uint32_t switch_core_max_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1704
#define is_dtmf(key)
determine if a character is a valid DTMF key
Definition: switch_utils.h:683
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1744
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_queue_t * dtmf_queue
#define switch_zmalloc(ptr, len)
void switch_core_media_break(switch_core_session_t *session, switch_media_type_t type)
switch_status_t switch_core_session_recv_dtmf(_In_ switch_core_session_t *session, const switch_dtmf_t *dtmf)
RECV DTMF on a session.
uint32_t switch_core_default_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1721
switch_status_t
Common return values.
switch_mutex_t * dtmf_mutex
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1279
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
#define switch_assert(expr)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_core_session_t * session
#define SWITCH_CHANNEL_CHANNEL_LOG(x)

◆ switch_channel_queue_dtmf_string()

switch_status_t switch_channel_queue_dtmf_string ( switch_channel_t channel,
const char *  dtmf_string 
)

Definition at line 575 of file switch_channel.c.

References switch_dtmf_t::digit, DTMF_FLAG_SKIP_PROCESS, switch_dtmf_t::duration, switch_dtmf_t::flags, is_dtmf, switch_channel::session, string, SWITCH_CHANNEL_CHANNEL_LOG, switch_channel_get_name(), switch_channel_queue_dtmf(), switch_core_default_dtmf_duration(), switch_core_max_dtmf_duration(), switch_core_min_dtmf_duration(), switch_core_session_strdup, SWITCH_DTMF_APP, SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_LOG_WARNING, switch_separate_string(), SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, and zstr.

576 {
577  char *p;
579  int sent = 0, dur, bad_input = 0;
580  char *string;
581  int i, argc;
582  char *argv[256];
583 
584  if (zstr(dtmf_string)) {
585  return SWITCH_STATUS_GENERR;
586  }
587 
588 
590 
591  if (*dtmf_string == '~') {
592  dtmf_string++;
593  dtmf.flags = 0;
594  }
595 
596  string = switch_core_session_strdup(channel->session, dtmf_string);
597  argc = switch_separate_string(string, '+', argv, (sizeof(argv) / sizeof(argv[0])));
598 
599  for (i = 0; i < argc; i++) {
602  if ((p = strchr(argv[i], '@'))) {
603  *p++ = '\0';
604  if ((dur = atoi(p)) > (int)switch_core_min_dtmf_duration(0) / 8) {
605  dtmf.duration = dur * 8;
606  }
607  }
608 
609  for (p = argv[i]; p && *p; p++) {
610  if (is_dtmf(*p)) {
611  dtmf.digit = *p;
612 
613  if (dtmf.duration > switch_core_max_dtmf_duration(0)) {
614  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_WARNING, "EXCESSIVE DTMF DIGIT LEN %c %d\n", dtmf.digit, dtmf.duration);
616  } else if (dtmf.duration < switch_core_min_dtmf_duration(0)) {
617  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_WARNING, "SHORT DTMF DIGIT LEN %c %d\n", dtmf.digit, dtmf.duration);
619  } else if (!dtmf.duration) {
621  }
622 
623  if (switch_channel_queue_dtmf(channel, &dtmf) == SWITCH_STATUS_SUCCESS) {
624  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s Queue dtmf\ndigit=%c ms=%u samples=%u\n",
625  switch_channel_get_name(channel), dtmf.digit, dur, dtmf.duration);
626  sent++;
627  }
628  } else {
629  bad_input++;
630  }
631  }
632 
633  }
634  if (sent) {
635  return SWITCH_STATUS_SUCCESS;
636  }
637  return bad_input ? SWITCH_STATUS_GENERR : SWITCH_STATUS_FALSE;
638 }
switch_status_t switch_channel_queue_dtmf(switch_channel_t *channel, const switch_dtmf_t *dtmf)
uint32_t duration
Definition: switch_types.h:302
#define zstr(x)
Definition: switch_utils.h:314
uint32_t switch_core_max_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1704
#define is_dtmf(key)
determine if a character is a valid DTMF key
Definition: switch_utils.h:683
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1744
unsigned int switch_separate_string(_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen)
Separate a string into an array based on a character delimiter.
const char *const string
Definition: switch_cJSON.h:162
uint32_t switch_core_default_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1721
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session&#39;s pool.
Definition: switch_core.h:719
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_core_session_t * session
#define SWITCH_CHANNEL_CHANNEL_LOG(x)

◆ switch_channel_release_device_record()

void switch_channel_release_device_record ( switch_device_record_t **  drecp)

Definition at line 5492 of file switch_channel.c.

References switch_mutex_unlock().

5493 {
5494  if (drecp && *drecp) {
5495  switch_mutex_unlock((*drecp)->mutex);
5496  *drecp = NULL;
5497  }
5498 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313

◆ switch_channel_set_device_id()

const char* switch_channel_set_device_id ( switch_channel_t channel,
const char *  device_id 
)

Definition at line 5454 of file switch_channel.c.

References add_uuid(), switch_channel::callstate, create_device_record(), switch_device_record_s::device_id, switch_channel::device_id, switch_channel::device_node, globals, switch_channel::session, SWITCH_CHANNEL_CHANNEL_LOG, switch_channel_check_device_state(), switch_core_hash_find(), switch_core_hash_insert, switch_core_session_strdup, SWITCH_LOG_DEBUG, switch_log_printf(), switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_channel_set_profile_var().

5455 {
5456  switch_device_record_t *drec;
5457 
5458  if (channel->device_node) {
5459  return NULL;
5460  }
5461 
5462  channel->device_id = switch_core_session_strdup(channel->session, device_id);
5463 
5464  switch_mutex_lock(globals.device_mutex);
5465 
5466  if (!(drec = switch_core_hash_find(globals.device_hash, channel->device_id))) {
5467  create_device_record(&drec, channel->device_id);
5468  switch_core_hash_insert(globals.device_hash, drec->device_id, drec);
5469  }
5470 
5471  add_uuid(drec, channel);
5472 
5473  switch_mutex_unlock(globals.device_mutex);
5474 
5475  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Setting DEVICE ID to [%s]\n", device_id);
5476 
5477  switch_channel_check_device_state(channel, channel->callstate);
5478 
5479  return device_id;
5480 }
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static struct @1 globals
static void switch_channel_check_device_state(switch_channel_t *channel, switch_channel_callstate_t callstate)
static void add_uuid(switch_device_record_t *drec, switch_channel_t *channel)
static switch_status_t create_device_record(switch_device_record_t **drecp, const char *device_id)
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1479
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_device_node_t * device_node
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session&#39;s pool.
Definition: switch_core.h:719
switch_channel_callstate_t callstate
switch_core_session_t * session
#define SWITCH_CHANNEL_CHANNEL_LOG(x)

◆ switch_channel_set_timestamps()

switch_status_t switch_channel_set_timestamps ( switch_channel_t channel)

Definition at line 4489 of file switch_channel.c.

References switch_channel_timetable::answered, switch_app_log::app, switch_app_log::arg, bridge(), switch_channel_timetable::bridged, switch_caller_profile::caller_id_name, switch_caller_profile::caller_id_number, switch_channel::caller_profile, CF_TIMESTAMP_SET, switch_channel_timetable::created, switch_stream_handle::data, switch_dtmf_t::digit, switch_channel::dtmf_log_queue, end_of, fmt, switch_channel_timetable::hold_accum, switch_channel::hold_record, switch_channel_timetable::hungup, switch_channel_timetable::last_hold, memset(), switch_app_log::next, switch_hold_record_s::next, switch_hold_record_s::off, switch_hold_record_s::on, switch_channel_timetable::profile_created, switch_channel::profile_mutex, switch_channel_timetable::progress, switch_channel_timetable::progress_media, switch_channel_timetable::resurrected, switch_channel::session, switch_channel_get_variable, switch_channel_set_flag, switch_channel_set_variable, switch_channel_test_flag(), switch_core_session_get_app_log(), switch_core_session_sprintf(), SWITCH_DTMF_LOG_LEN, switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypop(), switch_regex_perform(), switch_regex_safe_free, switch_safe_free, switch_snprintf(), SWITCH_STANDARD_STREAM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_str_nil, switch_strftime_nocheck(), switch_string_replace(), switch_time_exp_lt(), SWITCH_TIME_T_FMT, SWITCH_VA_NONE, TIME_T_FMT, switch_caller_profile::times, switch_channel::variables, switch_stream_handle::write_function, and zstr.

4490 {
4492  const char *cid_buf = NULL;
4493  switch_caller_profile_t *caller_profile;
4494  switch_app_log_t *app_log, *ap;
4495  char *last_app = NULL, *last_arg = NULL;
4496  char start[80] = "", resurrect[80] = "", answer[80] = "", hold[80],
4497  bridge[80] = "", progress[80] = "", progress_media[80] = "", end[80] = "", tmp[80] = "",
4498  profile_start[80] = "";
4499  int32_t duration = 0, legbillsec = 0, billsec = 0, mduration = 0, billmsec = 0, legbillmsec = 0, progressmsec = 0, progress_mediamsec = 0;
4500  int32_t answersec = 0, answermsec = 0, waitsec = 0, waitmsec = 0;
4501  switch_time_t answerusec = 0;
4502  switch_time_t uduration = 0, legbillusec = 0, billusec = 0, progresssec = 0, progressusec = 0, progress_mediasec = 0, progress_mediausec = 0, waitusec = 0;
4503  time_t tt_created = 0, tt_answered = 0, tt_resurrected = 0, tt_bridged, tt_last_hold, tt_hold_accum,
4504  tt_progress = 0, tt_progress_media = 0, tt_hungup = 0, mtt_created = 0, mtt_answered = 0, mtt_bridged = 0,
4505  mtt_hungup = 0, tt_prof_created, mtt_progress = 0, mtt_progress_media = 0;
4506  void *pop;
4507  char dtstr[SWITCH_DTMF_LOG_LEN + 1] = "";
4508  int x = 0;
4509 
4510  switch_mutex_lock(channel->profile_mutex);
4511 
4514  return SWITCH_STATUS_FALSE;
4515  }
4516 
4517  if (!(caller_profile = channel->caller_profile) || !channel->variables) {
4519  return SWITCH_STATUS_FALSE;
4520  }
4521 
4523 
4524  if ((app_log = switch_core_session_get_app_log(channel->session))) {
4525  for (ap = app_log; ap && ap->next; ap = ap->next);
4526  last_app = ap->app;
4527  last_arg = ap->arg;
4528  }
4529 
4530  if (!zstr(caller_profile->caller_id_name)) {
4531  cid_buf = switch_core_session_sprintf(channel->session, "\"%s\" <%s>", caller_profile->caller_id_name,
4532  switch_str_nil(caller_profile->caller_id_number));
4533  } else {
4534  cid_buf = caller_profile->caller_id_number;
4535  }
4536 
4538  switch_dtmf_t *dt = (switch_dtmf_t *) pop;
4539 
4540  if (dt) {
4541  dtstr[x++] = dt->digit;
4542  free(dt);
4543  dt = NULL;
4544  }
4545  }
4546 
4547  if (x) {
4548  const char *var = switch_channel_get_variable(channel, "digits_dialed_filter");
4549  char *digit_string = dtstr;
4550  char *X = NULL;
4551  switch_regex_t *re = NULL;
4552  char *substituted = NULL;
4553 
4554  if (!zstr(var)) {
4555  int proceed = 0;
4556  int ovector[30];
4557 
4558  if ((proceed = switch_regex_perform(dtstr, var, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
4559  int len = (strlen(dtstr) + strlen(var) + 10) * proceed;
4560  int i = 0;
4561  const char *replace = NULL;
4562 
4563  X = malloc(len);
4564 
4565  for (i = 0; i < proceed; i++) {
4566  if (pcre_get_substring(dtstr, ovector, proceed, i, &replace) >= 0) {
4567  if (replace) {
4568  switch_size_t plen = strlen(replace);
4569  memset(X, 'X', plen);
4570  *(X+plen) = '\0';
4571 
4572  switch_safe_free(substituted);
4573  substituted = switch_string_replace(substituted ? substituted : dtstr, replace, X);
4574 
4575  pcre_free_substring(replace);
4576  }
4577  }
4578  }
4579 
4580  if (!zstr(substituted)) {
4581  digit_string = substituted;
4582  }
4583  }
4584  }
4585 
4586  switch_channel_set_variable(channel, "digits_dialed", digit_string);
4588  switch_safe_free(substituted);
4589  switch_safe_free(X);
4590  } else {
4591  switch_channel_set_variable(channel, "digits_dialed", "none");
4592  }
4593 
4594  if (caller_profile->times) {
4595  switch_time_exp_t tm;
4596  switch_size_t retsize;
4597  const char *fmt = "%Y-%m-%d %T";
4598 
4599  switch_time_exp_lt(&tm, caller_profile->times->created);
4600  switch_strftime_nocheck(start, &retsize, sizeof(start), fmt, &tm);
4601  switch_channel_set_variable(channel, "start_stamp", start);
4602 
4603  switch_time_exp_lt(&tm, caller_profile->times->profile_created);
4604  switch_strftime_nocheck(profile_start, &retsize, sizeof(profile_start), fmt, &tm);
4605  switch_channel_set_variable(channel, "profile_start_stamp", profile_start);
4606 
4607  if (caller_profile->times->answered) {
4608  switch_time_exp_lt(&tm, caller_profile->times->answered);
4609  switch_strftime_nocheck(answer, &retsize, sizeof(answer), fmt, &tm);
4610  switch_channel_set_variable(channel, "answer_stamp", answer);
4611  }
4612 
4613  if (caller_profile->times->bridged) {
4614  switch_time_exp_lt(&tm, caller_profile->times->bridged);
4615  switch_strftime_nocheck(bridge, &retsize, sizeof(bridge), fmt, &tm);
4616  switch_channel_set_variable(channel, "bridge_stamp", bridge);
4617  }
4618 
4619  if (caller_profile->times->last_hold) {
4620  switch_time_exp_lt(&tm, caller_profile->times->last_hold);
4621  switch_strftime_nocheck(hold, &retsize, sizeof(hold), fmt, &tm);
4622  switch_channel_set_variable(channel, "hold_stamp", hold);
4623  }
4624 
4625  if (caller_profile->times->resurrected) {
4626  switch_time_exp_lt(&tm, caller_profile->times->resurrected);
4627  switch_strftime_nocheck(resurrect, &retsize, sizeof(resurrect), fmt, &tm);
4628  switch_channel_set_variable(channel, "resurrect_stamp", resurrect);
4629  }
4630 
4631  if (caller_profile->times->progress) {
4632  switch_time_exp_lt(&tm, caller_profile->times->progress);
4633  switch_strftime_nocheck(progress, &retsize, sizeof(progress), fmt, &tm);
4634  switch_channel_set_variable(channel, "progress_stamp", progress);
4635  }
4636 
4637  if (caller_profile->times->progress_media) {
4638  switch_time_exp_lt(&tm, caller_profile->times->progress_media);
4639  switch_strftime_nocheck(progress_media, &retsize, sizeof(progress_media), fmt, &tm);
4640  switch_channel_set_variable(channel, "progress_media_stamp", progress_media);
4641  }
4642 
4643  if (channel->hold_record) {
4645  switch_stream_handle_t stream = { 0 };
4646 
4647  SWITCH_STANDARD_STREAM(stream);
4648 
4649  stream.write_function(&stream, "{", SWITCH_VA_NONE);
4650 
4651  for (hr = channel->hold_record; hr; hr = hr->next) {
4652  stream.write_function(&stream, "{%"SWITCH_TIME_T_FMT",%"SWITCH_TIME_T_FMT"},", hr->on, hr->off);
4653  }
4654  end_of((char *)stream.data) = '}';
4655 
4656  switch_channel_set_variable(channel, "hold_events", (char *)stream.data);
4657  free(stream.data);
4658  }
4659 
4660  switch_time_exp_lt(&tm, caller_profile->times->hungup);
4661  switch_strftime_nocheck(end, &retsize, sizeof(end), fmt, &tm);
4662  switch_channel_set_variable(channel, "end_stamp", end);
4663 
4664  tt_created = (time_t) (caller_profile->times->created / 1000000);
4665  mtt_created = (time_t) (caller_profile->times->created / 1000);
4666  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_created);
4667  switch_channel_set_variable(channel, "start_epoch", tmp);
4668  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->created);
4669  switch_channel_set_variable(channel, "start_uepoch", tmp);
4670 
4671  tt_prof_created = (time_t) (caller_profile->times->profile_created / 1000000);
4672  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_prof_created);
4673  switch_channel_set_variable(channel, "profile_start_epoch", tmp);
4674  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->profile_created);
4675  switch_channel_set_variable(channel, "profile_start_uepoch", tmp);
4676 
4677  tt_answered = (time_t) (caller_profile->times->answered / 1000000);
4678  mtt_answered = (time_t) (caller_profile->times->answered / 1000);
4679  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_answered);
4680  switch_channel_set_variable(channel, "answer_epoch", tmp);
4681  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
4682  switch_channel_set_variable(channel, "answer_uepoch", tmp);
4683 
4684  tt_bridged = (time_t) (caller_profile->times->bridged / 1000000);
4685  mtt_bridged = (time_t) (caller_profile->times->bridged / 1000);
4686  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_bridged);
4687  switch_channel_set_variable(channel, "bridge_epoch", tmp);
4688  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->bridged);
4689  switch_channel_set_variable(channel, "bridge_uepoch", tmp);
4690 
4691  tt_last_hold = (time_t) (caller_profile->times->last_hold / 1000000);
4692  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_last_hold);
4693  switch_channel_set_variable(channel, "last_hold_epoch", tmp);
4694  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->last_hold);
4695  switch_channel_set_variable(channel, "last_hold_uepoch", tmp);
4696 
4697  tt_hold_accum = (time_t) (caller_profile->times->hold_accum / 1000000);
4698  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_hold_accum);
4699  switch_channel_set_variable(channel, "hold_accum_seconds", tmp);
4700  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hold_accum);
4701  switch_channel_set_variable(channel, "hold_accum_usec", tmp);
4702  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hold_accum / 1000);
4703  switch_channel_set_variable(channel, "hold_accum_ms", tmp);
4704 
4705  tt_resurrected = (time_t) (caller_profile->times->resurrected / 1000000);
4706  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_resurrected);
4707  switch_channel_set_variable(channel, "resurrect_epoch", tmp);
4708  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->resurrected);
4709  switch_channel_set_variable(channel, "resurrect_uepoch", tmp);
4710 
4711  tt_progress = (time_t) (caller_profile->times->progress / 1000000);
4712  mtt_progress = (time_t) (caller_profile->times->progress / 1000);
4713  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_progress);
4714  switch_channel_set_variable(channel, "progress_epoch", tmp);
4715  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress);
4716  switch_channel_set_variable(channel, "progress_uepoch", tmp);
4717 
4718  tt_progress_media = (time_t) (caller_profile->times->progress_media / 1000000);
4719  mtt_progress_media = (time_t) (caller_profile->times->progress_media / 1000);
4720  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_progress_media);
4721  switch_channel_set_variable(channel, "progress_media_epoch", tmp);
4722  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress_media);
4723  switch_channel_set_variable(channel, "progress_media_uepoch", tmp);
4724 
4725  tt_hungup = (time_t) (caller_profile->times->hungup / 1000000);
4726  mtt_hungup = (time_t) (caller_profile->times->hungup / 1000);
4727  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_hungup);
4728  switch_channel_set_variable(channel, "end_epoch", tmp);
4729  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
4730  switch_channel_set_variable(channel, "end_uepoch", tmp);
4731 
4732  duration = (int32_t) (tt_hungup - tt_created);
4733  mduration = (int32_t) (mtt_hungup - mtt_created);
4734  uduration = caller_profile->times->hungup - caller_profile->times->created;
4735 
4736  if (caller_profile->times->bridged > caller_profile->times->created) {
4737  waitsec = (int32_t) (tt_bridged - tt_created);
4738  waitmsec = (int32_t) (mtt_bridged - mtt_created);
4739  waitusec = caller_profile->times->bridged - caller_profile->times->created;
4740  } else {
4741  waitsec = 0;
4742  waitmsec = 0;
4743  waitusec = 0;
4744  }
4745 
4746  if (caller_profile->times->answered) {
4747  billsec = (int32_t) (tt_hungup - tt_answered);
4748  billmsec = (int32_t) (mtt_hungup - mtt_answered);
4749  billusec = caller_profile->times->hungup - caller_profile->times->answered;
4750 
4751  legbillsec = (int32_t) (tt_hungup - tt_created);
4752  legbillmsec = (int32_t) (mtt_hungup - mtt_created);
4753  legbillusec = caller_profile->times->hungup - caller_profile->times->created;
4754 
4755  answersec = (int32_t) (tt_answered - tt_created);
4756  answermsec = (int32_t) (mtt_answered - mtt_created);
4757  answerusec = caller_profile->times->answered - caller_profile->times->created;
4758  }
4759 
4760  if (caller_profile->times->progress) {
4761  progresssec = (int32_t) (tt_progress - tt_created);
4762  progressmsec = (int32_t) (mtt_progress - mtt_created);
4763  progressusec = caller_profile->times->progress - caller_profile->times->created;
4764  }
4765 
4766  if (caller_profile->times->progress_media) {
4767  progress_mediasec = (int32_t) (tt_progress_media - tt_created);
4768  progress_mediamsec = (int32_t) (mtt_progress_media - mtt_created);
4769  progress_mediausec = caller_profile->times->progress_media - caller_profile->times->created;
4770  }
4771 
4772  }
4773 
4774  switch_channel_set_variable(channel, "last_app", last_app);
4775  switch_channel_set_variable(channel, "last_arg", last_arg);
4776  switch_channel_set_variable(channel, "caller_id", cid_buf);
4777 
4778  switch_snprintf(tmp, sizeof(tmp), "%d", duration);
4779  switch_channel_set_variable(channel, "duration", tmp);
4780 
4781  switch_snprintf(tmp, sizeof(tmp), "%d", billsec);
4782  switch_channel_set_variable(channel, "billsec", tmp);
4783 
4784  switch_snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, progresssec);
4785  switch_channel_set_variable(channel, "progresssec", tmp);
4786 
4787  switch_snprintf(tmp, sizeof(tmp), "%d", answersec);
4788  switch_channel_set_variable(channel, "answersec", tmp);
4789 
4790  switch_snprintf(tmp, sizeof(tmp), "%d", waitsec);
4791  switch_channel_set_variable(channel, "waitsec", tmp);
4792 
4793  switch_snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, progress_mediasec);
4794  switch_channel_set_variable(channel, "progress_mediasec", tmp);
4795 
4796  switch_snprintf(tmp, sizeof(tmp), "%d", legbillsec);
4797  switch_channel_set_variable(channel, "flow_billsec", tmp);
4798 
4799  switch_snprintf(tmp, sizeof(tmp), "%d", mduration);
4800  switch_channel_set_variable(channel, "mduration", tmp);
4801 
4802  switch_snprintf(tmp, sizeof(tmp), "%d", billmsec);
4803  switch_channel_set_variable(channel, "billmsec", tmp);
4804 
4805  switch_snprintf(tmp, sizeof(tmp), "%d", progressmsec);
4806  switch_channel_set_variable(channel, "progressmsec", tmp);
4807 
4808  switch_snprintf(tmp, sizeof(tmp), "%d", answermsec);
4809  switch_channel_set_variable(channel, "answermsec", tmp);
4810 
4811  switch_snprintf(tmp, sizeof(tmp), "%d", waitmsec);
4812  switch_channel_set_variable(channel, "waitmsec", tmp);
4813 
4814  switch_snprintf(tmp, sizeof(tmp), "%d", progress_mediamsec);
4815  switch_channel_set_variable(channel, "progress_mediamsec", tmp);
4816 
4817  switch_snprintf(tmp, sizeof(tmp), "%d", legbillmsec);
4818  switch_channel_set_variable(channel, "flow_billmsec", tmp);
4819 
4820  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, uduration);
4821  switch_channel_set_variable(channel, "uduration", tmp);
4822 
4823  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, billusec);
4824  switch_channel_set_variable(channel, "billusec", tmp);
4825 
4826  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, progressusec);
4827  switch_channel_set_variable(channel, "progressusec", tmp);
4828 
4829  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, answerusec);
4830  switch_channel_set_variable(channel, "answerusec", tmp);
4831 
4832  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, waitusec);
4833  switch_channel_set_variable(channel, "waitusec", tmp);
4834 
4835  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, progress_mediausec);
4836  switch_channel_set_variable(channel, "progress_mediausec", tmp);
4837 
4838  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, legbillusec);
4839  switch_channel_set_variable(channel, "flow_billusec", tmp);
4840 
4842 
4843  return status;
4844 }
#define switch_regex_safe_free(re)
Definition: switch_regex.h:79
char * switch_core_session_sprintf(_In_ switch_core_session_t *session, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the session ...
switch_event_t * variables
Call Specific Data.
Definition: switch_caller.h:73
struct switch_hold_record_s * next
Definition: switch_core.h:78
switch_queue_t * dtmf_log_queue
switch_caller_profile_t * caller_profile
switch_hold_record_t * hold_record
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
switch_status_t switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
Definition: switch_apr.c:346
#define end_of(_s)
Definition: switch_utils.h:685
struct real_pcre switch_regex_t
Definition: switch_regex.h:43
switch_status_t switch_strftime_nocheck(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
Definition: switch_apr.c:202
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
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.
#define zstr(x)
Definition: switch_utils.h:314
int cJSON_bool fmt
Definition: switch_cJSON.h:150
switch_mutex_t * profile_mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
int64_t switch_time_t
Definition: switch_apr.h:188
switch_time_t on
Definition: switch_core.h:75
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
#define switch_channel_get_variable(_c, _v)
const char * caller_id_name
Definition: switch_caller.h:79
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
#define SWITCH_TIME_T_FMT
switch_time_t profile_created
uintptr_t switch_size_t
void bridge(CoreSession &session_a, CoreSession &session_b)
bridge the audio of session_b into session_a
#define TIME_T_FMT
#define SWITCH_STANDARD_STREAM(s)
int switch_regex_perform(const char *field, const char *expression, switch_regex_t **new_re, int *ovector, uint32_t olen)
Definition: switch_regex.c:55
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:993
switch_stream_handle_write_function_t write_function
#define SWITCH_DTMF_LOG_LEN
Definition: switch_types.h:237
switch_status_t
Common return values.
char * switch_string_replace(const char *string, const char *search, const char *replace)
#define switch_channel_set_flag(_c, _f)
switch_app_log_t * switch_core_session_get_app_log(_In_ switch_core_session_t *session)
struct switch_channel_timetable * times
const char * caller_id_number
Definition: switch_caller.h:81
#define SWITCH_VA_NONE
#define switch_channel_set_variable(_channel, _var, _val)
switch_core_session_t * session
memset(buf, 0, buflen)
switch_time_t off
Definition: switch_core.h:76
switch_time_t progress_media
struct switch_app_log * next
Definition: switch_core.h:63

◆ switch_channel_state_name()

const char* switch_channel_state_name ( switch_channel_state_t  state)

Definition at line 2322 of file switch_channel.c.

References state_names.

Referenced by switch_channel_event_set_basic_data().

2323 {
2324  return state_names[state];
2325 }
static const char * state_names[]

◆ switch_channel_state_thread_lock()

void switch_channel_state_thread_lock ( switch_channel_t channel)

Definition at line 2640 of file switch_channel.c.

References switch_mutex_lock(), and switch_channel::thread_mutex.

Referenced by switch_core_session_run().

2641 {
2642  switch_mutex_lock(channel->thread_mutex);
2643 }
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_mutex_t * thread_mutex

◆ switch_channel_state_thread_trylock()

switch_status_t switch_channel_state_thread_trylock ( switch_channel_t channel)

Definition at line 2646 of file switch_channel.c.

References switch_mutex_trylock(), and switch_channel::thread_mutex.

Referenced by switch_core_session_wake_session_thread().

2647 {
2648  return switch_mutex_trylock(channel->thread_mutex);
2649 }
switch_status_t switch_mutex_trylock(switch_mutex_t *lock)
Definition: switch_apr.c:318
switch_mutex_t * thread_mutex

◆ switch_channel_state_thread_unlock()

void switch_channel_state_thread_unlock ( switch_channel_t channel)

Definition at line 2652 of file switch_channel.c.

References switch_mutex_unlock(), and switch_channel::thread_mutex.

Referenced by switch_core_session_run(), and switch_core_session_wake_session_thread().

2653 {
2655 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_mutex_t * thread_mutex

◆ switch_channel_str2cause()

switch_call_cause_t switch_channel_str2cause ( const char *  str)

Definition at line 217 of file switch_channel.c.

References switch_cause_table::cause, CAUSE_CHART, switch_cause_table::name, SWITCH_CAUSE_NORMAL_CLEARING, and zstr.

218 {
219  uint8_t x;
221 
222  if (!zstr(str)) {
223  if (*str > 47 && *str < 58) {
224  cause = atoi(str);
225  } else {
226  for (x = 0; x < (sizeof(CAUSE_CHART) / sizeof(struct switch_cause_table)) - 1 && CAUSE_CHART[x].name; x++) {
227  if (!strcasecmp(CAUSE_CHART[x].name, str)) {
228  cause = CAUSE_CHART[x].cause;
229  break;
230  }
231  }
232  }
233  }
234 
235  return cause;
236 }
#define zstr(x)
Definition: switch_utils.h:314
static struct switch_cause_table CAUSE_CHART[]
switch_call_cause_t
switch_call_cause_t cause
const char *const name
Definition: switch_cJSON.h:250

◆ switch_channel_transfer_to_extension()

void switch_channel_transfer_to_extension ( switch_channel_t channel,
switch_caller_extension_t caller_extension 
)

Definition at line 3324 of file switch_channel.c.

References CF_TRANSFER, CS_ROUTING, switch_channel::profile_mutex, switch_channel::queued_extension, switch_channel_set_flag, switch_channel_set_state, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_ivr_parse_event().

3325 {
3326  switch_mutex_lock(channel->profile_mutex);
3327  channel->queued_extension = caller_extension;
3329 
3332 }
#define switch_channel_set_state(channel, state)
Set the current state of a channel.
switch_mutex_t * profile_mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_caller_extension_t * queued_extension
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
#define switch_channel_set_flag(_c, _f)

◆ switch_channel_unbind_device_state_handler()

switch_status_t switch_channel_unbind_device_state_handler ( switch_device_state_function_t  function)

Definition at line 5526 of file switch_channel.c.

References switch_device_state_binding_s::function, globals, switch_device_state_binding_s::next, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

5527 {
5528  switch_device_state_binding_t *ptr, *last = NULL;
5530 
5531  switch_mutex_lock(globals.device_mutex);
5532  for (ptr = globals.device_bindings; ptr; ptr = ptr->next) {
5533  if (ptr->function == function) {
5534  status = SWITCH_STATUS_SUCCESS;
5535 
5536  if (last) {
5537  last->next = ptr->next;
5538  } else {
5539  globals.device_bindings = ptr->next;
5540  last = NULL;
5541  continue;
5542  }
5543  }
5544  last = ptr;
5545  }
5546  switch_mutex_unlock(globals.device_mutex);
5547 
5548  return status;
5549 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_device_state_function_t function
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static struct @1 globals
switch_status_t
Common return values.
struct switch_device_state_binding_s * next

◆ switch_event_base_add_header()

switch_status_t switch_event_base_add_header ( switch_event_t event,
switch_stack_t  stack,
const char *  header_name,
char *  data 
)

Variable Documentation

◆ CALLSTATE_CHART

struct switch_callstate_table CALLSTATE_CHART[]
static
Initial value:
= {
{"DOWN", CCS_DOWN},
{"DIALING", CCS_DIALING},
{"RINGING", CCS_RINGING},
{"EARLY", CCS_EARLY},
{"ACTIVE", CCS_ACTIVE},
{"HELD", CCS_HELD},
{"RING_WAIT", CCS_RING_WAIT},
{"HANGUP", CCS_HANGUP},
{"UNHELD", CCS_UNHELD},
{NULL, 0}
}

Definition at line 254 of file switch_channel.c.

Referenced by switch_channel_callstate2str(), and switch_channel_str2callstate().

◆ CAUSE_CHART

struct switch_cause_table CAUSE_CHART[]
static

Definition at line 56 of file switch_channel.c.

Referenced by switch_channel_cause2str(), and switch_channel_str2cause().

◆ device_bindings

Definition at line 53 of file switch_channel.c.

◆ device_hash

switch_hash_t* device_hash

Definition at line 51 of file switch_channel.c.

◆ device_mutex

switch_mutex_t* device_mutex

Definition at line 52 of file switch_channel.c.

◆ DEVICE_STATE_CHART

struct switch_device_state_table DEVICE_STATE_CHART[]
static
Initial value:
= {
{"DOWN", SDS_DOWN},
{"RINGING", SDS_RINGING},
{"ACTIVE", SDS_ACTIVE},
{"ACTIVE_MULTI", SDS_ACTIVE_MULTI},
{"HELD", SDS_HELD},
{"UNHELD", SDS_UNHELD},
{"HANGUP", SDS_HANGUP},
{NULL, 0}
}

Definition at line 271 of file switch_channel.c.

Referenced by switch_channel_device_state2str().

◆ globals

struct { ... } globals

◆ pool

Definition at line 50 of file switch_channel.c.

Referenced by check_queue(), create_device_record(), destroy_thread(), dtls_bio_filter_free(), dtls_bio_filter_new(), main(), preprocess_stun_set(), record_helper_create(), record_helper_destroy(), switch_caller_profile_clone(), switch_caller_profile_dup(), switch_caller_profile_new(), switch_channel_clear_device_record(), switch_channel_global_init(), switch_console_save_history(), switch_core_asr_open(), switch_core_codec_destroy(), switch_core_codec_init_with_bitrate(), switch_core_directory_open(), switch_core_file_handle_dup(), switch_core_launch_thread(), switch_core_media_bug_add(), switch_core_memory_reclaim(), switch_core_perform_destroy_memory_pool(), switch_core_perform_file_open(), switch_core_session_findall_matching_var(), switch_core_session_hupall(), switch_core_session_hupall_endpoint(), switch_core_session_hupall_matching_vars_ans(), switch_core_session_init(), switch_core_session_perform_destroy(), switch_core_session_request_uuid(), switch_core_session_thread_pool_worker(), switch_core_speech_open(), switch_core_timer_init(), switch_dial_handle_create(), switch_dial_handle_destroy(), switch_dial_handle_list_create(), switch_dial_handle_list_destroy(), switch_event_init(), switch_event_launch_dispatch_threads(), switch_frame_buffer_create(), switch_frame_buffer_destroy(), switch_img_txt_handle_create(), switch_img_txt_handle_destroy(), switch_ivr_bg_media(), switch_ivr_broadcast_in_thread(), switch_ivr_dmachine_create(), switch_ivr_dmachine_destroy(), switch_ivr_enterprise_originate(), switch_ivr_play_file(), switch_ivr_speak_text(), switch_jb_create(), switch_known_bitrate(), switch_live_array_create(), switch_live_array_destroy(), switch_log_init(), switch_media_type2str(), SWITCH_MODULE_LOAD_FUNCTION(), switch_nat_init(), switch_needs_url_encode(), switch_network_list_create(), switch_pool_clear(), switch_rtp_create(), switch_sockaddr_create(), switch_sockaddr_new(), switch_system_thread(), switch_xml_free_in_thread(), switch_xml_init(), switch_xml_locate_language(), and xswitch_http_request().

◆ state_names

const char* state_names[]
static
Initial value:
= {
"CS_NEW",
"CS_INIT",
"CS_ROUTING",
"CS_SOFT_EXECUTE",
"CS_EXECUTE",
"CS_EXCHANGE_MEDIA",
"CS_PARK",
"CS_CONSUME_MEDIA",
"CS_HIBERNATE",
"CS_RESET",
"CS_HANGUP",
"CS_REPORTING",
"CS_DESTROY",
"CS_NONE",
NULL
}

Definition at line 2304 of file switch_channel.c.

Referenced by switch_channel_name_state(), switch_channel_perform_hangup(), switch_channel_perform_set_running_state(), switch_channel_perform_set_state(), and switch_channel_state_name().