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 3976 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 5407 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().

5408 {
5409  switch_device_node_t *node;
5410 
5411  switch_assert(drec);
5412 
5414  node = switch_core_alloc(drec->pool, sizeof(*node));
5415 
5417  node->parent = drec;
5418  node->callstate = channel->callstate;
5420 
5421  channel->device_node = node;
5422 
5423  if (!drec->uuid_list) {
5424  drec->uuid_list = node;
5425  drec->uuid = node->uuid;
5426  } else {
5427  drec->uuid_tail->next = node;
5428  }
5429 
5430  drec->uuid_tail = node;
5431  drec->refs++;
5432 }
#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 5434 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().

5435 {
5436  switch_device_record_t *drec;
5438 
5439  switch_assert(drecp);
5440 
5442  drec = switch_core_alloc(pool, sizeof(*drec));
5443  drec->pool = pool;
5444  drec->device_id = switch_core_strdup(drec->pool, device_id);
5446 
5447  *drecp = drec;
5448 
5449  return SWITCH_STATUS_SUCCESS;
5450 }
#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 3669 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().

3670 {
3671  char *app;
3672  char *arg = NULL;
3673  char *expanded = NULL;
3674  switch_stream_handle_t stream = { 0 };
3675 
3676  app = switch_core_session_strdup(channel->session, variable);
3677 
3678  if ((arg = strchr(app, ' '))) {
3679  *arg++ = '\0';
3680  }
3681 
3682  if (zstr(arg)) {
3683  expanded = arg;
3684  } else {
3685  expanded = switch_channel_expand_variables(channel, arg);
3686  }
3687 
3688  SWITCH_STANDARD_STREAM(stream);
3689  switch_api_execute(app, expanded, NULL, &stream);
3690  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s process %s: %s(%s)\n%s\n",
3691  channel->name, variable, app, switch_str_nil(expanded), (char *) stream.data);
3692 
3693  if (expanded && expanded != arg) {
3694  free(expanded);
3695  }
3696 
3697  free(stream.data);
3698 }
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 5031 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().

5032 {
5034 
5035 
5036  memset(&drec->stats, 0, sizeof(switch_device_stats_t));
5037 
5038  switch_mutex_lock(drec->mutex);
5039  for(np = drec->uuid_list; np; np = np->next) {
5040  drec->stats.total++;
5042  drec->stats.total_in++;
5043  } else {
5044  drec->stats.total_out++;
5045  }
5046 
5047  if (!np->hup_profile) {
5048  drec->stats.offhook++;
5050  drec->stats.offhook_in++;
5051  } else {
5052  drec->stats.offhook_out++;
5053  }
5054 
5055  if (np->callstate == CCS_HELD) {
5056  drec->stats.held++;
5058  drec->stats.held_in++;
5059  } else {
5060  drec->stats.held_out++;
5061  }
5062  } else if (np->callstate == CCS_UNHELD) {
5063  drec->stats.unheld++;
5065  drec->stats.unheld_in++;
5066  } else {
5067  drec->stats.unheld_out++;
5068  }
5069  } else {
5070  if (np->callstate == CCS_EARLY) {
5071  drec->stats.early++;
5073  drec->stats.early_in++;
5074  } else {
5075  drec->stats.early_out++;
5076  }
5077  } else if (np->callstate == CCS_RINGING) {
5078  drec->stats.ringing++;
5080  drec->stats.ringing_in++;
5081  } else {
5082  drec->stats.ringing_out++;
5083  }
5084  } else if (np->callstate == CCS_RING_WAIT) {
5085  drec->stats.ring_wait++;
5086  } else if (np->callstate == CCS_HANGUP) {
5087  drec->stats.hup++;
5089  drec->stats.hup_in++;
5090  } else {
5091  drec->stats.hup_out++;
5092  }
5093  } else if (np->callstate != CCS_DOWN) {
5094  drec->stats.active++;
5096  drec->stats.active_in++;
5097  } else {
5098  drec->stats.active_out++;
5099  }
5100  }
5101  }
5102  } else {
5103  drec->stats.hup++;
5105  drec->stats.hup_in++;
5106  } else {
5107  drec->stats.hup_out++;
5108  }
5109  }
5110  }
5111  switch_mutex_unlock(drec->mutex);
5112 
5113 }
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 5180 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().

5181 {
5182  switch_hold_record_t *hr, *newhr, *last = NULL;
5183  switch_device_record_t *drec = NULL;
5184  switch_device_node_t *node;
5185 
5186  if (!channel->device_node) {
5187  return;
5188  }
5189 
5190  switch_mutex_lock(globals.device_mutex);
5191  node = channel->device_node;
5192  drec = channel->device_node->parent;
5193 
5194  node->hup_profile = switch_caller_profile_dup(drec->pool, channel->caller_profile);
5195  fetch_device_stats(drec);
5196 
5197  switch_ivr_generate_xml_cdr(channel->session, &node->xml_cdr);
5200  }
5201 
5202  for (hr = channel->hold_record; hr; hr = hr->next) {
5203  newhr = switch_core_alloc(drec->pool, sizeof(*newhr));
5204  newhr->on = hr->on;
5205  newhr->off = hr->off;
5206 
5207  if (hr->uuid) {
5208  newhr->uuid = switch_core_strdup(drec->pool, hr->uuid);
5209  }
5210 
5211  if (!node->hold_record) {
5212  node->hold_record = newhr;
5213  } else if (last) {
5214  last->next = newhr;
5215  }
5216 
5217  last = newhr;
5218  }
5219 
5220  if (!drec->stats.offhook) { /* this is final call */
5221 
5222  switch_core_hash_delete(globals.device_hash, drec->device_id);
5223  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Processing last call from device [%s]\n",
5224  drec->device_id);
5226  } else {
5227  channel->device_node = NULL;
5228  }
5229 
5230  drec->refs--;
5231 
5232  switch_mutex_unlock(globals.device_mutex);
5233 
5234 }
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 3458 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().

3459 {
3460  switch_core_session_message_t msg = { 0 };
3461 
3462  msg.message_id = msg_id;
3463  msg.from = channel->name;
3464  return switch_core_session_perform_receive_message(channel->session, &msg, file, func, line);
3465 }
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 3701 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().

3702 {
3704  switch_event_t *event;
3705  int x = 0;
3706 
3707 
3708  switch_channel_get_variables(channel, &event);
3709 
3710  for (hp = event->headers; hp; hp = hp->next) {
3711  char *var = hp->name;
3712  char *val = hp->value;
3713 
3714  if (!strncasecmp(var, variable_prefix, strlen(variable_prefix))) {
3715  if (hp->idx) {
3716  int i;
3717  for (i = 0; i < hp->idx; i++) {
3718  x++;
3719  do_api_on(channel, hp->array[i]);
3720  }
3721  } else {
3722  x++;
3723  do_api_on(channel, val);
3724  }
3725  }
3726  }
3727 
3728  switch_event_destroy(&event);
3729 
3731 }
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 5499 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.

5500 {
5501  switch_device_state_binding_t *binding = NULL, *ptr = NULL;
5502  assert(function != NULL);
5503 
5504  if (!(binding = (switch_device_state_binding_t *) switch_core_alloc(globals.pool, sizeof(*binding)))) {
5505  return SWITCH_STATUS_MEMERR;
5506  }
5507 
5508  binding->function = function;
5509  binding->user_data = user_data;
5510 
5511  switch_mutex_lock(globals.device_mutex);
5512  for (ptr = globals.device_bindings; ptr && ptr->next; ptr = ptr->next);
5513 
5514  if (ptr) {
5515  ptr->next = binding;
5516  } else {
5517  globals.device_bindings = binding;
5518  }
5519 
5520  switch_mutex_unlock(globals.device_mutex);
5521 
5522  return SWITCH_STATUS_SUCCESS;
5523 }
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 4290 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.

4291 {
4292  switch_stream_handle_t stream = { 0 };
4293  switch_size_t encode_len = 1024, new_len = 0;
4294  char *encode_buf = NULL;
4295  const char *prof[13] = { 0 }, *prof_names[13] = {
4296  0};
4297  char *e = NULL;
4299  uint32_t x = 0;
4300 
4301  SWITCH_STANDARD_STREAM(stream);
4302 
4303  if (prefix) {
4304  stream.write_function(&stream, "%s&", prefix);
4305  }
4306 
4307  encode_buf = malloc(encode_len);
4308  switch_assert(encode_buf);
4309 
4310  if (!caller_profile) {
4311  caller_profile = switch_channel_get_caller_profile(channel);
4312  }
4313 
4314  switch_assert(caller_profile != NULL);
4315 
4316  prof[0] = caller_profile->context;
4317  prof[1] = caller_profile->destination_number;
4318  prof[2] = caller_profile->caller_id_name;
4319  prof[3] = caller_profile->caller_id_number;
4320  prof[4] = caller_profile->network_addr;
4321  prof[5] = caller_profile->ani;
4322  prof[6] = caller_profile->aniii;
4323  prof[7] = caller_profile->rdnis;
4324  prof[8] = caller_profile->source;
4325  prof[9] = caller_profile->chan_name;
4326  prof[10] = caller_profile->uuid;
4327  prof[11] = caller_profile->transfer_source;
4328 
4329  prof_names[0] = "context";
4330  prof_names[1] = "destination_number";
4331  prof_names[2] = "caller_id_name";
4332  prof_names[3] = "caller_id_number";
4333  prof_names[4] = "network_addr";
4334  prof_names[5] = "ani";
4335  prof_names[6] = "aniii";
4336  prof_names[7] = "rdnis";
4337  prof_names[8] = "source";
4338  prof_names[9] = "chan_name";
4339  prof_names[10] = "uuid";
4340  prof_names[11] = "transfer_source";
4341 
4342  for (x = 0; prof[x]; x++) {
4343  if (zstr(prof[x])) {
4344  continue;
4345  }
4346  new_len = (strlen(prof[x]) * 3) + 1;
4347  if (encode_len < new_len) {
4348  char *tmp;
4349 
4350  encode_len = new_len;
4351 
4352  if (!(tmp = realloc(encode_buf, encode_len))) {
4353  abort();
4354  }
4355 
4356  encode_buf = tmp;
4357  }
4358  switch_url_encode(prof[x], encode_buf, encode_len);
4359  stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
4360  }
4361 
4362  if (channel->caller_profile->soft) {
4363  profile_node_t *pn;
4364 
4365  for(pn = channel->caller_profile->soft; pn; pn = pn->next) {
4366  char *var = pn->var;
4367  char *val = pn->val;
4368 
4369  new_len = (strlen((char *) var) * 3) + 1;
4370  if (encode_len < new_len) {
4371  char *tmp;
4372 
4373  encode_len = new_len;
4374 
4375  tmp = realloc(encode_buf, encode_len);
4376  switch_assert(tmp);
4377  encode_buf = tmp;
4378  }
4379 
4380  switch_url_encode((char *) val, encode_buf, encode_len);
4381  stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
4382 
4383  }
4384  }
4385 
4386  if ((hi = switch_channel_variable_first(channel))) {
4387  for (; hi; hi = hi->next) {
4388  char *var = hi->name;
4389  char *val = hi->value;
4390 
4391  new_len = (strlen((char *) var) * 3) + 1;
4392  if (encode_len < new_len) {
4393  char *tmp;
4394 
4395  encode_len = new_len;
4396 
4397  tmp = realloc(encode_buf, encode_len);
4398  switch_assert(tmp);
4399  encode_buf = tmp;
4400  }
4401 
4402  switch_url_encode((char *) val, encode_buf, encode_len);
4403  stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
4404 
4405  }
4407  }
4408 
4409  e = (char *) stream.data + (strlen((char *) stream.data) - 1);
4410 
4411  if (e && *e == '&') {
4412  *e = '\0';
4413  }
4414 
4415  switch_safe_free(encode_buf);
4416 
4417  return stream.data;
4418 }
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 5236 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().

5237 {
5238  switch_device_record_t *drec = NULL;
5239  switch_device_state_binding_t *ptr = NULL;
5240  switch_event_t *event = NULL;
5241 
5242  if (!channel->device_node) {
5243  return;
5244  }
5245 
5246  drec = channel->device_node->parent;
5247 
5248  switch_mutex_lock(globals.device_mutex);
5249  switch_mutex_lock(drec->mutex);
5250 
5251  fetch_device_stats(drec);
5252 
5253  if (drec->state != SDS_HANGUP) {
5254  if (drec->stats.offhook == 0 || drec->stats.hup == drec->stats.total) {
5255  drec->state = SDS_HANGUP;
5256  } else {
5257  if (drec->stats.active == 0) {
5258  if ((drec->stats.ringing_out + drec->stats.early_out) > 0 || drec->stats.ring_wait > 0) {
5259  drec->state = SDS_RINGING;
5260  } else {
5261  if (drec->stats.held > 0) {
5262  drec->state = SDS_HELD;
5263  } else if (drec->stats.unheld > 0) {
5264  drec->state = SDS_UNHELD;
5265  } else {
5266  drec->state = SDS_DOWN;
5267  }
5268  }
5269  } else if (drec->stats.active == 1) {
5270  drec->state = SDS_ACTIVE;
5271  } else {
5272  drec->state = SDS_ACTIVE_MULTI;
5273  }
5274  }
5275  }
5276 
5277  if ((drec->state == SDS_DOWN && drec->last_state == SDS_DOWN) || (drec->state == SDS_HANGUP && drec->last_state == SDS_HANGUP)) {
5278  switch_mutex_unlock(drec->mutex);
5279  switch_mutex_unlock(globals.device_mutex);
5280  return;
5281  }
5282 
5283  if (!drec->call_start) {
5285  }
5286 
5287  switch(drec->state) {
5288  case SDS_RINGING:
5289  if (!drec->ring_start) {
5291  drec->ring_stop = 0;
5292  }
5293  break;
5294  case SDS_ACTIVE:
5295  case SDS_ACTIVE_MULTI:
5296  if (!drec->active_start) {
5298  drec->active_stop = 0;
5299  }
5300  break;
5301  case SDS_HELD:
5302  if (!drec->hold_start) {
5304  drec->hold_stop = 0;
5305  }
5306  break;
5307  default:
5308  break;
5309  }
5310 
5311  if (callstate != CCS_UNHELD && drec->active_start && drec->state != SDS_ACTIVE && drec->state != SDS_ACTIVE_MULTI) {
5313  }
5314 
5315  if (drec->ring_start && !drec->ring_stop && drec->state != SDS_RINGING) {
5316  drec->ring_stop = switch_micro_time_now();
5317  }
5318 
5319  if (drec->hold_start && !drec->hold_stop && drec->state != SDS_HELD) {
5320  drec->hold_stop = switch_micro_time_now();
5321  }
5322 
5323 
5325  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Device-ID", drec->device_id);
5328  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Device-Call-State", switch_channel_callstate2str(callstate));
5329  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Total-Legs", "%u", drec->stats.total);
5330  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Offhook", "%u", drec->stats.offhook);
5331  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Ringing", "%u", drec->stats.ringing);
5332  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Early", "%u", drec->stats.early);
5333  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Active", "%u", drec->stats.active);
5334  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Held", "%u", drec->stats.held);
5335  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-UnHeld", "%u", drec->stats.unheld);
5336  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Hup", "%u", drec->stats.hup);
5337  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Talk-Time-Start-Uepoch", "%"SWITCH_TIME_T_FMT, drec->active_start);
5338  if (drec->active_stop) {
5339  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Talk-Time-Stop-Uepoch", "%"SWITCH_TIME_T_FMT, drec->active_stop);
5340  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Talk-Time-Milliseconds", "%u", (uint32_t)(drec->active_stop - drec->active_start) / 1000);
5341  }
5342  }
5343 
5345  "%s device: %s\nState: %s Dev State: %s/%s Total:%u Offhook:%u "
5346  "Ringing:%u Early:%u Active:%u Held:%u Unheld:%u Hungup:%u Dur: %u Ringtime: %u Holdtime: %u %s\n",
5347  switch_channel_get_name(channel),
5348  drec->device_id,
5349  switch_channel_callstate2str(callstate),
5352  drec->stats.total,
5353  drec->stats.offhook,
5354  drec->stats.ringing,
5355  drec->stats.early,
5356  drec->stats.active,
5357  drec->stats.held,
5358  drec->stats.unheld,
5359  drec->stats.hup,
5360  drec->active_stop ? (uint32_t)(drec->active_stop - drec->active_start) / 1000 : 0,
5361  drec->ring_stop ? (uint32_t)(drec->ring_stop - drec->ring_start) / 1000 : 0,
5362  drec->hold_stop ? (uint32_t)(drec->hold_stop - drec->hold_start) / 1000 : 0,
5363  switch_channel_test_flag(channel, CF_FINAL_DEVICE_LEG) ? "FINAL LEG" : "");
5364 
5365  for (ptr = globals.device_bindings; ptr; ptr = ptr->next) {
5366  ptr->function(channel->session, callstate, drec);
5367  }
5368 
5369  drec->last_stats = drec->stats;
5370 
5371  if (drec->active_stop) {
5372  drec->active_start = drec->active_stop = 0;
5373  if (drec->state == SDS_ACTIVE || drec->state == SDS_ACTIVE_MULTI) {
5375  }
5376  }
5377 
5378  if (drec->hold_stop) {
5379  drec->hold_start = drec->hold_stop = 0;
5380  if (drec->state == SDS_HELD) {
5382  }
5383  }
5384 
5385  if (drec->ring_stop) {
5386  drec->ring_start = drec->ring_stop = 0;
5387  if (drec->state == SDS_RINGING) {
5389  }
5390  }
5391 
5393 
5394  drec->last_state = drec->state;
5395 
5396  switch_mutex_unlock(drec->mutex);
5397  switch_mutex_unlock(globals.device_mutex);
5398 
5399 
5400  if (event) {
5401  switch_event_fire(&event);
5402  }
5403 
5404 }
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 5115 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().

5116 {
5118  int sanity = 100;
5120  switch_event_t *event;
5121 
5122  if (!channel->device_node || !switch_channel_test_flag(channel, CF_FINAL_DEVICE_LEG)) {
5123  return;
5124  }
5125 
5126  while(--sanity && channel->device_node->parent->refs) {
5127  switch_yield(100000);
5128  }
5129 
5130  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Destroying device cdr %s on device [%s]\n",
5131  channel->device_node->parent->uuid,
5132  channel->device_node->parent->device_id);
5133 
5135  int x = 0;
5136  char prefix[80] = "";
5137 
5138  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Type", "device");
5140 
5142  for(np = channel->device_node->parent->uuid_list; np; np = np->next) {
5143  switch_snprintf(prefix, sizeof(prefix), "Call-%d", ++x);
5145  }
5147 
5148  switch_event_fire(&event);
5149  }
5150 
5152  for(np = channel->device_node->parent->uuid_list; np; np = np->next) {
5153  if (np->xml_cdr) {
5154  switch_xml_free(np->xml_cdr);
5155  }
5156  if (np->event) {
5158  }
5159  }
5161 
5162  pool = channel->device_node->parent->pool;
5163 
5164  switch_mutex_lock(globals.device_mutex);
5166 
5167  switch_mutex_unlock(globals.device_mutex);
5168 
5169 
5170 }
#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:298
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:300
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 3779 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().

3780 {
3782  switch_event_t *event, *cevent;
3783  int x = 0;
3784 
3785  switch_core_get_variables(&event);
3786  switch_channel_get_variables(channel, &cevent);
3787  switch_event_merge(event, cevent);
3788 
3789  for (hp = event->headers; hp; hp = hp->next) {
3790  char *var = hp->name;
3791  char *val = hp->value;
3792 
3793  if (!strncasecmp(var, variable_prefix, strlen(variable_prefix))) {
3794  if (hp->idx) {
3795  int i;
3796  for (i = 0; i < hp->idx; i++) {
3797  x++;
3798  switch_channel_execute_on_value(channel, hp->array[i]);
3799  }
3800  } else {
3801  x++;
3802  switch_channel_execute_on_value(channel, val);
3803  }
3804  }
3805  }
3806 
3807  switch_event_destroy(&event);
3808  switch_event_destroy(&cevent);
3809 
3811 }
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 3733 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().

3734 {
3735  switch_status_t status;
3736  char *arg = NULL;
3737  char *p;
3738  int bg = 0;
3739  char *app;
3740  char *expanded = NULL;
3741 
3742  app = switch_core_session_strdup(channel->session, variable_value);
3743 
3744  for(p = app; p && *p; p++) {
3745  if (*p == ' ' || (*p == ':' && (*(p+1) != ':'))) {
3746  *p++ = '\0';
3747  arg = p;
3748  break;
3749  } else if (*p == ':' && (*(p+1) == ':')) {
3750  bg++;
3751  break;
3752  }
3753  }
3754 
3755  switch_assert(app != NULL);
3756  if (!strncasecmp(app, "perl", 4)) {
3757  bg++;
3758  }
3759 
3760  if (zstr(arg)) {
3761  expanded = arg;
3762  } else {
3763  expanded = switch_channel_expand_variables(channel, arg);
3764  }
3765 
3766  if (bg) {
3767  status = switch_core_session_execute_application_async(channel->session, app, arg);
3768  } else {
3769  status = switch_core_session_execute_application(channel->session, app, arg);
3770  }
3771 
3772  if (expanded && expanded != arg) {
3773  free(expanded);
3774  }
3775 
3776  return status;
3777 }
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 5481 of file switch_channel.c.

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

5482 {
5483  if (channel->device_node) {
5485  return channel->device_node->parent;
5486  }
5487 
5488  return NULL;
5489 }
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 4845 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().

4846 {
4847  const char *uuid = NULL;
4848 
4849  switch_mutex_lock(channel->profile_mutex);
4852  }
4853 
4854  if (uuid) {
4855  strncpy(buf, uuid, blen);
4856  uuid = (const char *) buf;
4857  }
4859 
4860  return uuid;
4861 }
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 3311 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().

3312 {
3313  switch_caller_extension_t *caller_extension;
3314 
3315  switch_mutex_lock(channel->profile_mutex);
3316  caller_extension = channel->queued_extension;
3317  channel->queued_extension = NULL;
3319 
3320  return caller_extension;
3321 }
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 5016 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().

5017 {
5018  memset(&globals, 0, sizeof(globals));
5019  globals.pool = pool;
5020 
5022  switch_core_hash_init(&globals.device_hash);
5023 }
#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 5025 of file switch_channel.c.

References globals, and switch_core_hash_destroy().

Referenced by switch_core_destroy().

5026 {
5027  switch_core_hash_destroy(&globals.device_hash);
5028 }
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 4875 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().

4876 {
4877  switch_core_session_t *session = channel->session;
4878  const char *transfer_on_fail = NULL;
4879  char *tof_data = NULL;
4880  char *tof_array[4] = { 0 };
4881  //int tof_arrayc = 0;
4882 
4883  if (!switch_channel_up_nosig(channel)) {
4884  return;
4885  }
4886 
4887  transfer_on_fail = switch_channel_get_variable(channel, "transfer_on_fail");
4888  tof_data = switch_core_session_strdup(session, transfer_on_fail);
4889  switch_split(tof_data, ' ', tof_array);
4890  transfer_on_fail = tof_array[0];
4891 
4892  /*
4893  if the variable continue_on_fail is set it can be:
4894  'true' to continue on all failures.
4895  'false' to not continue.
4896  A list of codes either names or numbers eg "user_busy,normal_temporary_failure,603"
4897  failure_causes acts as the opposite version
4898  EXCEPTION... ATTENDED_TRANSFER never is a reason to continue.......
4899  */
4900  if (cause != SWITCH_CAUSE_ATTENDED_TRANSFER) {
4901  const char *continue_on_fail = NULL, *failure_causes = NULL;
4902 
4903  continue_on_fail = switch_channel_get_variable(channel, "continue_on_fail");
4904  failure_causes = switch_channel_get_variable(channel, "failure_causes");
4905 
4906  if (continue_on_fail || failure_causes) {
4907  const char *cause_str;
4908  char cause_num[35] = "";
4909 
4910  cause_str = switch_channel_cause2str(cause);
4911  switch_snprintf(cause_num, sizeof(cause_num), "%u", cause);
4912 
4913  if (failure_causes) {
4914  char *lbuf = switch_core_session_strdup(session, failure_causes);
4915  char *argv[256] = { 0 };
4916  int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
4917  int i, x = 0;
4918 
4919  for (i = 0; i < argc; i++) {
4920  if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
4921  x++;
4922  break;
4923  }
4924  }
4925  if (!x) {
4927  "Failure causes [%s]: Cause: %s\n", failure_causes, cause_str);
4928  return;
4929  }
4930  }
4931 
4932  if (continue_on_fail) {
4933  if (switch_true(continue_on_fail)) {
4934  return;
4935  } else {
4936  char *lbuf = switch_core_session_strdup(session, continue_on_fail);
4937  char *argv[256] = { 0 };
4938  int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
4939  int i;
4940 
4941  for (i = 0; i < argc; i++) {
4942  if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
4944  "Continue on fail [%s]: Cause: %s\n", continue_on_fail, cause_str);
4945  return;
4946  }
4947  }
4948  }
4949  }
4950  } else {
4951  /* no answer is *always* a reason to continue */
4953  return;
4954  }
4955  }
4956 
4957  if (transfer_on_fail || failure_causes) {
4958  const char *cause_str;
4959  char cause_num[35] = "";
4960 
4961  cause_str = switch_channel_cause2str(cause);
4962  switch_snprintf(cause_num, sizeof(cause_num), "%u", cause);
4963 
4964  if ((tof_array[1] == NULL ) || (!strcasecmp(tof_array[1], "auto_cause"))){
4965  tof_array[1] = (char *) cause_str;
4966  }
4967 
4968  if (failure_causes) {
4969  char *lbuf = switch_core_session_strdup(session, failure_causes);
4970  char *argv[256] = { 0 };
4971  int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
4972  int i, x = 0;
4973 
4974  for (i = 0; i < argc; i++) {
4975  if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
4976  x++;
4977  break;
4978  }
4979  }
4980  if (!x) {
4982  "Failure causes [%s]: Cause: %s\n", failure_causes, cause_str);
4983 
4984  switch_ivr_session_transfer(session, tof_array[1], tof_array[2], tof_array[3]);
4985  }
4986  }
4987 
4988  if (transfer_on_fail) {
4989  if (switch_true(transfer_on_fail)) {
4990  return;
4991  } else {
4992  char *lbuf = switch_core_session_strdup(session, transfer_on_fail);
4993  char *argv[256] = { 0 };
4994  int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
4995  int i;
4996 
4997  for (i = 0; i < argc; i++) {
4998  if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
5000  "Transfer on fail [%s]: Cause: %s\n", transfer_on_fail, cause_str);
5001  switch_ivr_session_transfer(session, tof_array[1], tof_array[2], tof_array[3]);
5002  }
5003  }
5004  }
5005  }
5006  }
5007  }
5008 
5009 
5011  switch_channel_get_state(channel) != CS_ROUTING) {
5012  switch_channel_hangup(channel, cause);
5013  }
5014 }
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 5550 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().

5551 {
5553  char *use_sdp = (char *) sdp;
5554  char *patched_sdp = NULL;
5555 
5557  const char *var;
5558 
5559  if ((var = switch_channel_get_variable(from_channel, "bypass_media_sdp_filter"))) {
5560  if ((patched_sdp = switch_core_media_process_sdp_filter(use_sdp, var, from_channel->session))) {
5561  use_sdp = patched_sdp;
5562  }
5563  }
5564 
5565  switch_channel_set_variable(to_channel, SWITCH_B_SDP_VARIABLE, use_sdp);
5566  }
5567 
5568  switch_safe_free(patched_sdp);
5569 
5570  return status;
5571 }
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 5172 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().

5173 {
5174 
5175  switch_channel_check_device_state(channel, channel->callstate);
5176  process_device_hup(channel);
5177 
5178 }
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:437
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:298
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:298
#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 5491 of file switch_channel.c.

References switch_mutex_unlock().

5492 {
5493  if (drecp && *drecp) {
5494  switch_mutex_unlock((*drecp)->mutex);
5495  *drecp = NULL;
5496  }
5497 }
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 5453 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().

5454 {
5455  switch_device_record_t *drec;
5456 
5457  if (channel->device_node) {
5458  return NULL;
5459  }
5460 
5461  channel->device_id = switch_core_session_strdup(channel->session, device_id);
5462 
5463  switch_mutex_lock(globals.device_mutex);
5464 
5465  if (!(drec = switch_core_hash_find(globals.device_hash, channel->device_id))) {
5466  create_device_record(&drec, channel->device_id);
5467  switch_core_hash_insert(globals.device_hash, drec->device_id, drec);
5468  }
5469 
5470  add_uuid(drec, channel);
5471 
5472  switch_mutex_unlock(globals.device_mutex);
5473 
5474  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Setting DEVICE ID to [%s]\n", device_id);
5475 
5476  switch_channel_check_device_state(channel, channel->callstate);
5477 
5478  return device_id;
5479 }
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 4488 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.

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

3324 {
3325  switch_mutex_lock(channel->profile_mutex);
3326  channel->queued_extension = caller_extension;
3328 
3331 }
#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 5525 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.

5526 {
5527  switch_device_state_binding_t *ptr, *last = NULL;
5529 
5530  switch_mutex_lock(globals.device_mutex);
5531  for (ptr = globals.device_bindings; ptr; ptr = ptr->next) {
5532  if (ptr->function == function) {
5533  status = SWITCH_STATUS_SUCCESS;
5534 
5535  if (last) {
5536  last->next = ptr->next;
5537  } else {
5538  globals.device_bindings = ptr->next;
5539  last = NULL;
5540  continue;
5541  }
5542  }
5543  last = ptr;
5544  }
5545  switch_mutex_unlock(globals.device_mutex);
5546 
5547  return status;
5548 }
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().