FreeSWITCH API Documentation  1.7.0
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_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_variable_var_check (switch_channel_t *channel, const char *varname, const char *value, switch_bool_t var_check)
 
switch_status_t switch_channel_add_variable_var_check (switch_channel_t *channel, const char *varname, const char *value, switch_bool_t var_check, switch_stack_t stack)
 
switch_status_t switch_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)
 
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_t
switch_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_mark_ring_ready_value (switch_channel_t *channel, switch_ring_ready_t rv, const char *file, const char *func, int line)
 
void switch_channel_check_zrtp (switch_channel_t *channel)
 
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)
 
static void do_execute_on (switch_channel_t *channel, const char *variable)
 
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_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 (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

#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);\
}} \
if((uint32_t)(unpack->cur-unpack->buf) > unpack->buflen)
memset(buf, 0, buflen)

Definition at line 3829 of file switch_channel.c.

Referenced by switch_channel_expand_variables_check().

Typedef Documentation

Enumeration Type Documentation

Enumerator
OCF_HANGUP 

Definition at line 130 of file switch_channel.c.

130  {
131  OCF_HANGUP = (1 << 0)
opaque_channel_flag_t
Enumerator
LP_NEITHER 
LP_ORIGINATOR 
LP_ORIGINATEE 

Definition at line 134 of file switch_channel.c.

Function Documentation

static void add_uuid ( switch_device_record_t drec,
switch_channel_t channel 
)
static

Definition at line 5202 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().

5203 {
5204  switch_device_node_t *node;
5205 
5206  switch_assert(drec);
5207 
5209  node = switch_core_alloc(drec->pool, sizeof(*node));
5210 
5212  node->parent = drec;
5213  node->callstate = channel->callstate;
5215 
5216  channel->device_node = node;
5217 
5218  if (!drec->uuid_list) {
5219  drec->uuid_list = node;
5220  drec->uuid = node->uuid;
5221  } else {
5222  drec->uuid_tail->next = node;
5223  }
5224 
5225  drec->uuid_tail = node;
5226  drec->refs++;
5227 }
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
struct device_uuid_node_s * uuid_tail
Definition: switch_core.h:137
switch_call_direction_t logical_direction
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
switch_call_direction_t direction
Definition: switch_core.h:86
struct device_uuid_node_s * next
Definition: switch_core.h:88
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:83
switch_memory_pool_t * pool
Definition: switch_core.h:139
struct switch_device_record_s * parent
Definition: switch_core.h:87
#define switch_channel_set_flag(_c, _f)
struct device_uuid_node_s * uuid_list
Definition: switch_core.h:136
switch_device_node_t * device_node
switch_channel_callstate_t callstate
#define switch_assert(expr)
switch_core_session_t * session
static void careful_set ( switch_channel_t channel,
switch_channel_state_t state,
switch_channel_state_t  val 
)
inlinestatic

Definition at line 2190 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().

2190  {
2191 
2193  *state = val;
2195  } else {
2197  int x = 0;
2198 
2199  for (x = 0; x < 100; x++) {
2201  *state = val;
2202  switch_mutex_unlock(mutex);
2203  break;
2204  } else {
2205  switch_cond_next();
2206  }
2207  }
2208 
2209  if (x == 100) {
2210  *state = val;
2211  }
2212 
2213  }
2214 }
switch_status_t switch_mutex_trylock(switch_mutex_t *lock)
Definition: switch_apr.c:295
switch_mutex_t * switch_core_session_get_mutex(switch_core_session_t *session)
Signal a session's state machine thread that a state change has occured.
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
void switch_cond_next(void)
Definition: switch_time.c:638
switch_mutex_t * mutex
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_mutex_t * thread_mutex
switch_core_session_t * session
static switch_status_t create_device_record ( switch_device_record_t **  drecp,
const char *  device_id 
)
static

Definition at line 5229 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().

5230 {
5231  switch_device_record_t *drec;
5233 
5234  switch_assert(drecp);
5235 
5237  drec = switch_core_alloc(pool, sizeof(*drec));
5238  drec->pool = pool;
5239  drec->device_id = switch_core_strdup(drec->pool, device_id);
5241 
5242  *drecp = drec;
5243 
5244  return SWITCH_STATUS_SUCCESS;
5245 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
Definition: switch_core.h:631
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
switch_memory_pool_t * pool
switch_mutex_t * mutex
Definition: switch_core.h:138
#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:682
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
switch_memory_pool_t * pool
Definition: switch_core.h:139
struct apr_pool_t switch_memory_pool_t
#define switch_assert(expr)
static void do_api_on ( switch_channel_t channel,
const char *  variable 
)
static

Definition at line 3555 of file switch_channel.c.

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

Referenced by switch_channel_api_on().

3556 {
3557  char *app;
3558  char *arg = NULL;
3559  switch_stream_handle_t stream = { 0 };
3560 
3561  app = switch_core_session_strdup(channel->session, variable);
3562 
3563  if ((arg = strchr(app, ' '))) {
3564  *arg++ = '\0';
3565  }
3566 
3567  SWITCH_STANDARD_STREAM(stream);
3568  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s process %s: %s(%s)\n%s\n",
3569  channel->name, variable, app, switch_str_nil(arg), (char *) stream.data);
3570  switch_api_execute(app, arg, NULL, &stream);
3571  free(stream.data);
3572 }
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 SWITCH_STANDARD_STREAM(s)
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:903
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's pool.
Definition: switch_core.h:717
switch_core_session_t * session
#define SWITCH_CHANNEL_CHANNEL_LOG(x)
static void do_execute_on ( switch_channel_t channel,
const char *  variable 
)
static

Definition at line 3607 of file switch_channel.c.

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

Referenced by switch_channel_execute_on().

3608 {
3609  char *arg = NULL;
3610  char *p;
3611  int bg = 0;
3612  char *app;
3613 
3614  app = switch_core_session_strdup(channel->session, variable);
3615 
3616  for(p = app; p && *p; p++) {
3617  if (*p == ' ' || (*p == ':' && (*(p+1) != ':'))) {
3618  *p++ = '\0';
3619  arg = p;
3620  break;
3621  } else if (*p == ':' && (*(p+1) == ':')) {
3622  bg++;
3623  break;
3624  }
3625  }
3626 
3627  if (!strncasecmp(app, "perl", 4)) {
3628  bg++;
3629  }
3630 
3631  if (bg) {
3633  } else {
3635  }
3636 }
switch_status_t switch_core_session_execute_application_async(switch_core_session_t *session, const char *app, const char *arg)
#define switch_core_session_execute_application(_a, _b, _c)
Execute an application on a session.
Definition: switch_core.h:1103
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
switch_core_session_t * session
static void fetch_device_stats ( switch_device_record_t drec)
static

Definition at line 4826 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().

4827 {
4829 
4830 
4831  memset(&drec->stats, 0, sizeof(switch_device_stats_t));
4832 
4833  switch_mutex_lock(drec->mutex);
4834  for(np = drec->uuid_list; np; np = np->next) {
4835  drec->stats.total++;
4837  drec->stats.total_in++;
4838  } else {
4839  drec->stats.total_out++;
4840  }
4841 
4842  if (!np->hup_profile) {
4843  drec->stats.offhook++;
4845  drec->stats.offhook_in++;
4846  } else {
4847  drec->stats.offhook_out++;
4848  }
4849 
4850  if (np->callstate == CCS_HELD) {
4851  drec->stats.held++;
4853  drec->stats.held_in++;
4854  } else {
4855  drec->stats.held_out++;
4856  }
4857  } else if (np->callstate == CCS_UNHELD) {
4858  drec->stats.unheld++;
4860  drec->stats.unheld_in++;
4861  } else {
4862  drec->stats.unheld_out++;
4863  }
4864  } else {
4865  if (np->callstate == CCS_EARLY) {
4866  drec->stats.early++;
4868  drec->stats.early_in++;
4869  } else {
4870  drec->stats.early_out++;
4871  }
4872  } else if (np->callstate == CCS_RINGING) {
4873  drec->stats.ringing++;
4875  drec->stats.ringing_in++;
4876  } else {
4877  drec->stats.ringing_out++;
4878  }
4879  } else if (np->callstate == CCS_RING_WAIT) {
4880  drec->stats.ring_wait++;
4881  } else if (np->callstate == CCS_HANGUP) {
4882  drec->stats.hup++;
4884  drec->stats.hup_in++;
4885  } else {
4886  drec->stats.hup_out++;
4887  }
4888  } else if (np->callstate != CCS_DOWN) {
4889  drec->stats.active++;
4891  drec->stats.active_in++;
4892  } else {
4893  drec->stats.active_out++;
4894  }
4895  }
4896  }
4897  } else {
4898  drec->stats.hup++;
4900  drec->stats.hup_in++;
4901  } else {
4902  drec->stats.hup_out++;
4903  }
4904  }
4905  }
4906  switch_mutex_unlock(drec->mutex);
4907 
4908 }
switch_device_stats_t stats
Definition: switch_core.h:124
switch_caller_profile_t * hup_profile
Definition: switch_core.h:85
switch_mutex_t * mutex
Definition: switch_core.h:138
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_call_direction_t direction
Definition: switch_core.h:86
struct device_uuid_node_s * next
Definition: switch_core.h:88
switch_channel_callstate_t callstate
Definition: switch_core.h:83
struct device_uuid_node_s * uuid_list
Definition: switch_core.h:136
memset(buf, 0, buflen)
static void process_device_hup ( switch_channel_t channel)
static

Definition at line 4975 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().

4976 {
4977  switch_hold_record_t *hr, *newhr, *last = NULL;
4978  switch_device_record_t *drec = NULL;
4979  switch_device_node_t *node;
4980 
4981  if (!channel->device_node) {
4982  return;
4983  }
4984 
4985  switch_mutex_lock(globals.device_mutex);
4986  node = channel->device_node;
4987  drec = channel->device_node->parent;
4988 
4989  node->hup_profile = switch_caller_profile_dup(drec->pool, channel->caller_profile);
4990  fetch_device_stats(drec);
4991 
4992  switch_ivr_generate_xml_cdr(channel->session, &node->xml_cdr);
4995  }
4996 
4997  for (hr = channel->hold_record; hr; hr = hr->next) {
4998  newhr = switch_core_alloc(drec->pool, sizeof(*newhr));
4999  newhr->on = hr->on;
5000  newhr->off = hr->off;
5001 
5002  if (hr->uuid) {
5003  newhr->uuid = switch_core_strdup(drec->pool, hr->uuid);
5004  }
5005 
5006  if (!node->hold_record) {
5007  node->hold_record = newhr;
5008  } else if (last) {
5009  last->next = newhr;
5010  }
5011 
5012  last = newhr;
5013  }
5014 
5015  if (!drec->stats.offhook) { /* this is final call */
5016 
5017  switch_core_hash_delete(globals.device_hash, drec->device_id);
5018  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Processing last call from device [%s]\n",
5019  drec->device_id);
5021  } else {
5022  channel->device_node = NULL;
5023  }
5024 
5025  drec->refs--;
5026 
5027  switch_mutex_unlock(globals.device_mutex);
5028 
5029 }
switch_xml_t xml_cdr
Definition: switch_core.h:81
struct switch_hold_record_s * next
Definition: switch_core.h:76
switch_device_stats_t stats
Definition: switch_core.h:124
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
switch_caller_profile_t * caller_profile
switch_caller_profile_t * hup_profile
Definition: switch_core.h:85
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:82
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_time_t on
Definition: switch_core.h:73
static struct @0 globals
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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:682
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:139
struct switch_device_record_s * parent
Definition: switch_core.h:87
#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:383
#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:84
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:2713
switch_core_session_t * session
#define SWITCH_CHANNEL_CHANNEL_LOG(x)
switch_time_t off
Definition: switch_core.h:74
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 3296 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_mark_answered(), switch_channel_perform_mark_pre_answered(), and switch_channel_perform_mark_ring_ready_value().

3297 {
3298  switch_core_session_message_t msg = { 0 };
3299 
3300  msg.message_id = msg_id;
3301  msg.from = channel->name;
3302  return switch_core_session_perform_receive_message(channel->session, &msg, file, func, line);
3303 }
switch_core_session_message_types_t message_id
Definition: switch_core.h:181
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:177
switch_core_session_t * session
switch_status_t switch_channel_alloc ( switch_channel_t **  channel,
switch_call_direction_t  direction,
switch_memory_pool_t pool 
)

Definition at line 437 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.

438 {
439  switch_assert(pool != NULL);
440 
441  if (((*channel) = switch_core_alloc(pool, sizeof(switch_channel_t))) == 0) {
442  return SWITCH_STATUS_MEMERR;
443  }
444 
445  switch_event_create_plain(&(*channel)->variables, SWITCH_EVENT_CHANNEL_DATA);
446 
447  switch_core_hash_init(&(*channel)->private_hash);
448  switch_queue_create(&(*channel)->dtmf_queue, SWITCH_DTMF_LOG_LEN, pool);
449  switch_queue_create(&(*channel)->dtmf_log_queue, SWITCH_DTMF_LOG_LEN, pool);
450 
451  switch_mutex_init(&(*channel)->dtmf_mutex, SWITCH_MUTEX_NESTED, pool);
452  switch_mutex_init(&(*channel)->flag_mutex, SWITCH_MUTEX_NESTED, pool);
453  switch_mutex_init(&(*channel)->state_mutex, SWITCH_MUTEX_NESTED, pool);
454  switch_mutex_init(&(*channel)->thread_mutex, SWITCH_MUTEX_NESTED, pool);
455  switch_mutex_init(&(*channel)->profile_mutex, SWITCH_MUTEX_NESTED, pool);
456  (*channel)->hangup_cause = SWITCH_CAUSE_NONE;
457  (*channel)->name = "";
458  (*channel)->direction = (*channel)->logical_direction = direction;
459  switch_channel_set_variable(*channel, "direction", switch_channel_direction(*channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
460 
461  return SWITCH_STATUS_SUCCESS;
462 }
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1390
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:682
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
static switch_status_t switch_event_create_plain(switch_event_t **event, switch_event_types_t event_id)
Definition: switch_event.h:385
#define SWITCH_DTMF_LOG_LEN
Definition: switch_types.h:230
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:1109
#define switch_assert(expr)
#define switch_channel_set_variable(_channel, _var, _val)
switch_status_t switch_channel_api_on ( switch_channel_t channel,
const char *  variable_prefix 
)

Definition at line 3575 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_thread(), check_channel_status(), 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(), and tone_on_dtmf().

3576 {
3578  switch_event_t *event;
3579  int x = 0;
3580 
3581 
3582  switch_channel_get_variables(channel, &event);
3583 
3584  for (hp = event->headers; hp; hp = hp->next) {
3585  char *var = hp->name;
3586  char *val = hp->value;
3587 
3588  if (!strncasecmp(var, variable_prefix, strlen(variable_prefix))) {
3589  if (hp->idx) {
3590  int i;
3591  for (i = 0; i < hp->idx; i++) {
3592  x++;
3593  do_api_on(channel, hp->array[i]);
3594  }
3595  } else {
3596  x++;
3597  do_api_on(channel, val);
3598  }
3599  }
3600  }
3601 
3602  switch_event_destroy(&event);
3603 
3605 }
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_status_t switch_channel_bind_device_state_handler ( switch_device_state_function_t  function,
void *  user_data 
)

Definition at line 5294 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.

5295 {
5296  switch_device_state_binding_t *binding = NULL, *ptr = NULL;
5297  assert(function != NULL);
5298 
5299  if (!(binding = (switch_device_state_binding_t *) switch_core_alloc(globals.pool, sizeof(*binding)))) {
5300  return SWITCH_STATUS_MEMERR;
5301  }
5302 
5303  binding->function = function;
5304  binding->user_data = user_data;
5305 
5306  switch_mutex_lock(globals.device_mutex);
5307  for (ptr = globals.device_bindings; ptr && ptr->next; ptr = ptr->next);
5308 
5309  if (ptr) {
5310  ptr->next = binding;
5311  } else {
5312  globals.device_bindings = binding;
5313  }
5314 
5315  switch_mutex_unlock(globals.device_mutex);
5316 
5317  return SWITCH_STATUS_SUCCESS;
5318 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
static struct @0 globals
switch_device_state_function_t function
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
char* switch_channel_build_param_string ( switch_channel_t channel,
switch_caller_profile_t caller_profile,
const char *  prefix 
)

Definition at line 4129 of file switch_channel.c.

References switch_stream_handle::data, switch_event_header::name, profile_node_s::next, switch_event_header::next, switch_assert, switch_channel_get_caller_profile(), switch_channel_variable_first(), switch_channel_variable_last(), switch_safe_free, SWITCH_STANDARD_STREAM, switch_url_encode(), profile_node_s::val, switch_event_header::value, profile_node_s::var, switch_stream_handle::write_function, and zstr.

4130 {
4131  switch_stream_handle_t stream = { 0 };
4132  switch_size_t encode_len = 1024, new_len = 0;
4133  char *encode_buf = NULL;
4134  const char *prof[13] = { 0 }, *prof_names[13] = {
4135  0};
4136  char *e = NULL;
4138  uint32_t x = 0;
4139 
4140  SWITCH_STANDARD_STREAM(stream);
4141 
4142  if (prefix) {
4143  stream.write_function(&stream, "%s&", prefix);
4144  }
4145 
4146  encode_buf = malloc(encode_len);
4147  switch_assert(encode_buf);
4148 
4149  if (!caller_profile) {
4150  caller_profile = switch_channel_get_caller_profile(channel);
4151  }
4152 
4153  switch_assert(caller_profile != NULL);
4154 
4155  prof[0] = caller_profile->context;
4156  prof[1] = caller_profile->destination_number;
4157  prof[2] = caller_profile->caller_id_name;
4158  prof[3] = caller_profile->caller_id_number;
4159  prof[4] = caller_profile->network_addr;
4160  prof[5] = caller_profile->ani;
4161  prof[6] = caller_profile->aniii;
4162  prof[7] = caller_profile->rdnis;
4163  prof[8] = caller_profile->source;
4164  prof[9] = caller_profile->chan_name;
4165  prof[10] = caller_profile->uuid;
4166  prof[11] = caller_profile->transfer_source;
4167 
4168  prof_names[0] = "context";
4169  prof_names[1] = "destination_number";
4170  prof_names[2] = "caller_id_name";
4171  prof_names[3] = "caller_id_number";
4172  prof_names[4] = "network_addr";
4173  prof_names[5] = "ani";
4174  prof_names[6] = "aniii";
4175  prof_names[7] = "rdnis";
4176  prof_names[8] = "source";
4177  prof_names[9] = "chan_name";
4178  prof_names[10] = "uuid";
4179  prof_names[11] = "transfer_source";
4180 
4181  for (x = 0; prof[x]; x++) {
4182  if (zstr(prof[x])) {
4183  continue;
4184  }
4185  new_len = (strlen(prof[x]) * 3) + 1;
4186  if (encode_len < new_len) {
4187  char *tmp;
4188 
4189  encode_len = new_len;
4190 
4191  if (!(tmp = realloc(encode_buf, encode_len))) {
4192  abort();
4193  }
4194 
4195  encode_buf = tmp;
4196  }
4197  switch_url_encode(prof[x], encode_buf, encode_len);
4198  stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
4199  }
4200 
4201  if (channel->caller_profile->soft) {
4202  profile_node_t *pn;
4203 
4204  for(pn = channel->caller_profile->soft; pn; pn = pn->next) {
4205  char *var = pn->var;
4206  char *val = pn->val;
4207 
4208  new_len = (strlen((char *) var) * 3) + 1;
4209  if (encode_len < new_len) {
4210  char *tmp;
4211 
4212  encode_len = new_len;
4213 
4214  tmp = realloc(encode_buf, encode_len);
4215  switch_assert(tmp);
4216  encode_buf = tmp;
4217  }
4218 
4219  switch_url_encode((char *) val, encode_buf, encode_len);
4220  stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
4221 
4222  }
4223  }
4224 
4225  if ((hi = switch_channel_variable_first(channel))) {
4226  for (; hi; hi = hi->next) {
4227  char *var = hi->name;
4228  char *val = hi->value;
4229 
4230  new_len = (strlen((char *) var) * 3) + 1;
4231  if (encode_len < new_len) {
4232  char *tmp;
4233 
4234  encode_len = new_len;
4235 
4236  tmp = realloc(encode_buf, encode_len);
4237  switch_assert(tmp);
4238  encode_buf = tmp;
4239  }
4240 
4241  switch_url_encode((char *) val, encode_buf, encode_len);
4242  stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
4243 
4244  }
4246  }
4247 
4248  e = (char *) stream.data + (strlen((char *) stream.data) - 1);
4249 
4250  if (e && *e == '&') {
4251  *e = '\0';
4252  }
4253 
4254  switch_safe_free(encode_buf);
4255 
4256  return stream.data;
4257 }
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:281
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:789
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's caller profile.
const char* switch_channel_cause2str ( switch_call_cause_t  cause)

Definition at line 189 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().

190 {
191  uint8_t x;
192  const char *str = "UNKNOWN";
193 
194  for (x = 0; x < (sizeof(CAUSE_CHART) / sizeof(struct switch_cause_table)) - 1; x++) {
195  if (CAUSE_CHART[x].cause == cause) {
196  str = CAUSE_CHART[x].name;
197  break;
198  }
199  }
200 
201  return str;
202 }
const char * name
static struct switch_cause_table CAUSE_CHART[]
static void switch_channel_check_device_state ( switch_channel_t channel,
switch_channel_callstate_t  callstate 
)
static

Definition at line 5031 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().

5032 {
5033  switch_device_record_t *drec = NULL;
5034  switch_device_state_binding_t *ptr = NULL;
5035  switch_event_t *event = NULL;
5036 
5037  if (!channel->device_node) {
5038  return;
5039  }
5040 
5041  drec = channel->device_node->parent;
5042 
5043  switch_mutex_lock(globals.device_mutex);
5044  switch_mutex_lock(drec->mutex);
5045 
5046  fetch_device_stats(drec);
5047 
5048  if (drec->state != SDS_HANGUP) {
5049  if (drec->stats.offhook == 0 || drec->stats.hup == drec->stats.total) {
5050  drec->state = SDS_HANGUP;
5051  } else {
5052  if (drec->stats.active == 0) {
5053  if ((drec->stats.ringing_out + drec->stats.early_out) > 0 || drec->stats.ring_wait > 0) {
5054  drec->state = SDS_RINGING;
5055  } else {
5056  if (drec->stats.held > 0) {
5057  drec->state = SDS_HELD;
5058  } else if (drec->stats.unheld > 0) {
5059  drec->state = SDS_UNHELD;
5060  } else {
5061  drec->state = SDS_DOWN;
5062  }
5063  }
5064  } else if (drec->stats.active == 1) {
5065  drec->state = SDS_ACTIVE;
5066  } else {
5067  drec->state = SDS_ACTIVE_MULTI;
5068  }
5069  }
5070  }
5071 
5072  if ((drec->state == SDS_DOWN && drec->last_state == SDS_DOWN) || (drec->state == SDS_HANGUP && drec->last_state == SDS_HANGUP)) {
5073  switch_mutex_unlock(drec->mutex);
5074  switch_mutex_unlock(globals.device_mutex);
5075  return;
5076  }
5077 
5078  if (!drec->call_start) {
5080  }
5081 
5082  switch(drec->state) {
5083  case SDS_RINGING:
5084  if (!drec->ring_start) {
5086  drec->ring_stop = 0;
5087  }
5088  break;
5089  case SDS_ACTIVE:
5090  case SDS_ACTIVE_MULTI:
5091  if (!drec->active_start) {
5093  drec->active_stop = 0;
5094  }
5095  break;
5096  case SDS_HELD:
5097  if (!drec->hold_start) {
5099  drec->hold_stop = 0;
5100  }
5101  break;
5102  default:
5103  break;
5104  }
5105 
5106  if (callstate != CCS_UNHELD && drec->active_start && drec->state != SDS_ACTIVE && drec->state != SDS_ACTIVE_MULTI) {
5108  }
5109 
5110  if (drec->ring_start && !drec->ring_stop && drec->state != SDS_RINGING) {
5111  drec->ring_stop = switch_micro_time_now();
5112  }
5113 
5114  if (drec->hold_start && !drec->hold_stop && drec->state != SDS_HELD) {
5115  drec->hold_stop = switch_micro_time_now();
5116  }
5117 
5118 
5120  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Device-ID", drec->device_id);
5123  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Device-Call-State", switch_channel_callstate2str(callstate));
5124  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Total-Legs", "%u", drec->stats.total);
5125  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Offhook", "%u", drec->stats.offhook);
5126  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Ringing", "%u", drec->stats.ringing);
5127  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Early", "%u", drec->stats.early);
5128  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Active", "%u", drec->stats.active);
5129  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Held", "%u", drec->stats.held);
5130  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-UnHeld", "%u", drec->stats.unheld);
5131  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Legs-Hup", "%u", drec->stats.hup);
5132  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Talk-Time-Start-Uepoch", "%"SWITCH_TIME_T_FMT, drec->active_start);
5133  if (drec->active_stop) {
5134  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Talk-Time-Stop-Uepoch", "%"SWITCH_TIME_T_FMT, drec->active_stop);
5135  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Device-Talk-Time-Milliseconds", "%u", (uint32_t)(drec->active_stop - drec->active_start) / 1000);
5136  }
5137  }
5138 
5140  "%s device: %s\nState: %s Dev State: %s/%s Total:%u Offhook:%u "
5141  "Ringing:%u Early:%u Active:%u Held:%u Unheld:%u Hungup:%u Dur: %u Ringtime: %u Holdtime: %u %s\n",
5142  switch_channel_get_name(channel),
5143  drec->device_id,
5144  switch_channel_callstate2str(callstate),
5147  drec->stats.total,
5148  drec->stats.offhook,
5149  drec->stats.ringing,
5150  drec->stats.early,
5151  drec->stats.active,
5152  drec->stats.held,
5153  drec->stats.unheld,
5154  drec->stats.hup,
5155  drec->active_stop ? (uint32_t)(drec->active_stop - drec->active_start) / 1000 : 0,
5156  drec->ring_stop ? (uint32_t)(drec->ring_stop - drec->ring_start) / 1000 : 0,
5157  drec->hold_stop ? (uint32_t)(drec->hold_stop - drec->hold_start) / 1000 : 0,
5158  switch_channel_test_flag(channel, CF_FINAL_DEVICE_LEG) ? "FINAL LEG" : "");
5159 
5160  for (ptr = globals.device_bindings; ptr; ptr = ptr->next) {
5161  ptr->function(channel->session, callstate, drec);
5162  }
5163 
5164  drec->last_stats = drec->stats;
5165 
5166  if (drec->active_stop) {
5167  drec->active_start = drec->active_stop = 0;
5168  if (drec->state == SDS_ACTIVE || drec->state == SDS_ACTIVE_MULTI) {
5170  }
5171  }
5172 
5173  if (drec->hold_stop) {
5174  drec->hold_start = drec->hold_stop = 0;
5175  if (drec->state == SDS_HELD) {
5177  }
5178  }
5179 
5180  if (drec->ring_stop) {
5181  drec->ring_start = drec->ring_stop = 0;
5182  if (drec->state == SDS_RINGING) {
5184  }
5185  }
5186 
5188 
5189  drec->last_state = drec->state;
5190 
5191  switch_mutex_unlock(drec->mutex);
5192  switch_mutex_unlock(globals.device_mutex);
5193 
5194 
5195  if (event) {
5196  switch_event_fire(&event);
5197  }
5198 
5199 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
switch_device_state_t state
Definition: switch_core.h:126
switch_device_state_t last_state
Definition: switch_core.h:127
switch_device_stats_t stats
Definition: switch_core.h:124
const char * switch_channel_callstate2str(switch_channel_callstate_t callstate)
switch_time_t active_stop
Definition: switch_core.h:129
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:128
switch_mutex_t * mutex
Definition: switch_core.h:138
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:132
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
static struct @0 globals
switch_device_state_function_t function
switch_time_t hold_start
Definition: switch_core.h:133
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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:131
#define SWITCH_TIME_T_FMT
switch_time_t call_start
Definition: switch_core.h:135
struct switch_device_record_s * parent
Definition: switch_core.h:87
#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:383
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:125
switch_time_t last_call_time
Definition: switch_core.h:130
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:134
void switch_channel_clear_device_record ( switch_channel_t channel)

Definition at line 4910 of file switch_channel.c.

References CF_FINAL_DEVICE_LEG, device_uuid_node_s::event, globals, device_uuid_node_s::hup_profile, device_uuid_node_s::next, device_uuid_node_s::parent, pool, 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_list, and device_uuid_node_s::xml_cdr.

Referenced by switch_core_session_destroy_state().

4911 {
4913  int sanity = 100;
4915  switch_event_t *event;
4916 
4917  if (!channel->device_node || !switch_channel_test_flag(channel, CF_FINAL_DEVICE_LEG)) {
4918  return;
4919  }
4920 
4921  while(--sanity && channel->device_node->parent->refs) {
4922  switch_yield(100000);
4923  }
4924 
4925  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Destroying device cdr %s on device [%s]\n",
4926  channel->device_node->parent->uuid,
4927  channel->device_node->parent->device_id);
4928 
4930  int x = 0;
4931  char prefix[80] = "";
4932 
4933  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Type", "device");
4935 
4937  for(np = channel->device_node->parent->uuid_list; np; np = np->next) {
4938  switch_snprintf(prefix, sizeof(prefix), "Call-%d", ++x);
4940  }
4942 
4943  switch_event_fire(&event);
4944  }
4945 
4947  for(np = channel->device_node->parent->uuid_list; np; np = np->next) {
4948  if (np->xml_cdr) {
4949  switch_xml_free(np->xml_cdr);
4950  }
4951  if (np->event) {
4953  }
4954  }
4956 
4957  pool = channel->device_node->parent->pool;
4958 
4959  switch_mutex_lock(globals.device_mutex);
4961 
4962  switch_mutex_unlock(globals.device_mutex);
4963 
4964 
4965 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
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:81
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:640
switch_memory_pool_t * pool
Representation of an event.
Definition: switch_event.h:80
switch_caller_profile_t * hup_profile
Definition: switch_core.h:85
switch_mutex_t * mutex
Definition: switch_core.h:138
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:82
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
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.
static struct @0 globals
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:908
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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 device_uuid_node_s * next
Definition: switch_core.h:88
switch_memory_pool_t * pool
Definition: switch_core.h:139
struct switch_device_record_s * parent
Definition: switch_core.h:87
#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:383
struct device_uuid_node_s * uuid_list
Definition: switch_core.h:136
struct apr_pool_t switch_memory_pool_t
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
void switch_event_destroy(switch_event_t **event)
Destroy an event.
#define SWITCH_CHANNEL_CHANNEL_LOG(x)
switch_status_t switch_channel_dequeue_dtmf ( switch_channel_t channel,
switch_dtmf_t dtmf 
)

Definition at line 623 of file switch_channel.c.

References CF_DIVERT_EVENTS, DTMF_FLAG_SENSITIVE, 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().

624 {
625  switch_event_t *event;
626  void *pop;
627  switch_dtmf_t *dt;
629  int sensitive = 0;
630 
631  switch_mutex_lock(channel->dtmf_mutex);
632 
633  if (switch_queue_trypop(channel->dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
634  dt = (switch_dtmf_t *) pop;
635  *dtmf = *dt;
636  sensitive = switch_test_flag(dtmf, DTMF_FLAG_SENSITIVE);
637 
638  if (!sensitive && switch_queue_trypush(channel->dtmf_log_queue, dt) != SWITCH_STATUS_SUCCESS) {
639  free(dt);
640  }
641 
642  dt = NULL;
643 
644  if (dtmf->duration > switch_core_max_dtmf_duration(0)) {
645  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_WARNING, "%s EXCESSIVE DTMF DIGIT [%c] LEN [%d]\n",
646  switch_channel_get_name(channel), sensitive ? 'S' : dtmf->digit, dtmf->duration);
648  } else if (dtmf->duration < switch_core_min_dtmf_duration(0)) {
649  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_WARNING, "%s SHORT DTMF DIGIT [%c] LEN [%d]\n",
650  switch_channel_get_name(channel), sensitive ? 'S' : dtmf->digit, dtmf->duration);
652  } else if (!dtmf->duration) {
654  }
655 
656  status = SWITCH_STATUS_SUCCESS;
657  }
659 
660  if (!sensitive && status == SWITCH_STATUS_SUCCESS && switch_event_create(&event, SWITCH_EVENT_DTMF) == SWITCH_STATUS_SUCCESS) {
661  const char *dtmf_source_str = NULL;
662  switch_channel_event_set_data(channel, event);
663  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "DTMF-Digit", "%c", dtmf->digit);
664  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "DTMF-Duration", "%u", dtmf->duration);
665  switch(dtmf->source) {
666  case SWITCH_DTMF_INBAND_AUDIO: /* From audio */
667  dtmf_source_str = "INBAND_AUDIO";
668  break;
669  case SWITCH_DTMF_RTP: /* From RTP as a telephone event */
670  dtmf_source_str = "RTP";
671  break;
672  case SWITCH_DTMF_ENDPOINT: /* From endpoint signaling */
673  dtmf_source_str = "ENDPOINT";
674  break;
675  case SWITCH_DTMF_APP: /* Injected by application */
676  dtmf_source_str = "APP";
677  break;
678  case SWITCH_DTMF_UNKNOWN: /* Unknown source */
679  default:
680  dtmf_source_str = "UNKNOWN";
681  break;
682  }
683  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "DTMF-Source", "%s", dtmf_source_str);
685  switch_core_session_queue_event(channel->session, &event);
686  } else {
687  switch_event_fire(&event);
688  }
689  }
690 
691  return status;
692 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
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:1140
uint32_t duration
Definition: switch_types.h:288
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:1664
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1704
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:285
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:1681
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:383
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1155
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
switch_dtmf_source_t source
Definition: switch_types.h:290
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_size_t switch_channel_dequeue_dtmf_string ( switch_channel_t channel,
char *  dtmf_str,
switch_size_t  len 
)

Definition at line 694 of file switch_channel.c.

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

695 {
696  switch_size_t x = 0;
697  switch_dtmf_t dtmf = { 0 };
698 
699  memset(dtmf_str, 0, len);
700 
701  while (x < len - 1 && switch_channel_dequeue_dtmf(channel, &dtmf) == SWITCH_STATUS_SUCCESS) {
702  dtmf_str[x++] = dtmf.digit;
703  }
704 
705  return x;
706 
707 }
switch_status_t switch_channel_dequeue_dtmf(switch_channel_t *channel, switch_dtmf_t *dtmf)
uintptr_t switch_size_t
memset(buf, 0, buflen)
const char* switch_channel_device_state2str ( switch_device_state_t  device_state)

Definition at line 317 of file switch_channel.c.

References DEVICE_STATE_CHART, and switch_device_state_table::name.

Referenced by switch_channel_check_device_state().

318 {
319  uint8_t x;
320  const char *str = "UNKNOWN";
321 
322  for (x = 0; x < (sizeof(DEVICE_STATE_CHART) / sizeof(struct switch_cause_table)) - 1; x++) {
323  if (DEVICE_STATE_CHART[x].device_state == device_state) {
324  str = DEVICE_STATE_CHART[x].name;
325  break;
326  }
327  }
328 
329  return str;
330 }
static struct switch_device_state_table DEVICE_STATE_CHART[]
void switch_channel_event_set_basic_data ( switch_channel_t channel,
switch_event_t event 
)

Definition at line 2507 of file switch_channel.c.

References switch_codec_implementation::actual_samples_per_second, switch_codec_implementation::bits_per_second, CF_ANSWERED, CF_DIALPLAN, CF_EARLY_MEDIA, switch_codec_implementation::iananame, LP_ORIGINATEE, LP_ORIGINATOR, switch_caller_profile::originatee_caller_profile, switch_caller_profile::originator_caller_profile, 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_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().

2508 {
2509  switch_caller_profile_t *caller_profile, *originator_caller_profile = NULL, *originatee_caller_profile = NULL;
2510  switch_codec_implementation_t impl = { 0 };
2511  char state_num[25];
2512  const char *v;
2513 
2514  switch_mutex_lock(channel->profile_mutex);
2515 
2516  if ((caller_profile = channel->caller_profile)) {
2517  originator_caller_profile = caller_profile->originator_caller_profile;
2518  originatee_caller_profile = caller_profile->originatee_caller_profile;
2519  }
2520 
2523  switch_snprintf(state_num, sizeof(state_num), "%d", channel->state);
2524  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-State-Number", state_num);
2527 
2528  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Call-Direction",
2529  channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
2530  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Call-Direction",
2531  channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
2532 
2533  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-HIT-Dialplan",
2535  switch_channel_test_flag(channel, CF_DIALPLAN) ? "true" : "false");
2536 
2537 
2538  if ((v = switch_channel_get_variable_dup(channel, "presence_id", SWITCH_FALSE, -1))) {
2539  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Presence-ID", v);
2540  }
2541 
2542  if ((v = switch_channel_get_variable_dup(channel, "presence_data", SWITCH_FALSE, -1))) {
2543  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Presence-Data", v);
2544  }
2545 
2546 
2547  if ((v = switch_channel_get_variable_dup(channel, "presence_data_cols", SWITCH_FALSE, -1))) {
2548  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Data-Cols", v);
2549  switch_event_add_presence_data_cols(channel, event, "PD-");
2550  }
2551 
2552  if ((v = switch_channel_get_variable_dup(channel, "call_uuid", SWITCH_FALSE, -1))) {
2553  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-UUID", v);
2554  } else {
2556  }
2557 
2558  if (switch_channel_down_nosig(channel)) {
2559  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "hangup");
2560  } else if (switch_channel_test_flag(channel, CF_ANSWERED)) {
2561  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "answered");
2562  } else if (switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
2563  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "early");
2564  } else {
2565  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "ringing");
2566  }
2567 
2568  if (channel->hangup_cause) {
2570  }
2571 
2572 
2573  switch_core_session_get_read_impl(channel->session, &impl);
2574 
2575  if (impl.iananame) {
2576  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Name", impl.iananame);
2577  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Rate", "%u", impl.actual_samples_per_second);
2578  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Bit-Rate", "%d", impl.bits_per_second);
2579  }
2580 
2582 
2583  if (impl.iananame) {
2584  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Name", impl.iananame);
2585  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Rate", "%u", impl.actual_samples_per_second);
2586  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Bit-Rate", "%d", impl.bits_per_second);
2587  }
2588 
2589  /* Index Caller's Profile */
2590  if (caller_profile) {
2591  switch_caller_profile_event_set_data(caller_profile, "Caller", event);
2592  }
2593 
2594  /* Index Originator/ee's Profile */
2595  if (originator_caller_profile && channel->last_profile_type == LP_ORIGINATOR) {
2596  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Other-Type", "originator");
2597  switch_caller_profile_event_set_data(originator_caller_profile, "Other-Leg", event);
2598  } else if (originatee_caller_profile && channel->last_profile_type == LP_ORIGINATEE) { /* Index Originatee's Profile */
2599  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Other-Type", "originatee");
2600  switch_caller_profile_event_set_data(originatee_caller_profile, "Other-Leg", event);
2601  }
2602 
2603 
2605 }
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_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:290
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:285
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)
void switch_channel_event_set_data ( switch_channel_t channel,
switch_event_t event 
)

Definition at line 2689 of file switch_channel.c.

References 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().

2690 {
2691  switch_mutex_lock(channel->profile_mutex);
2692  switch_channel_event_set_basic_data(channel, event);
2695 }
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:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
void switch_channel_event_set_extended_data ( switch_channel_t channel,
switch_event_t event 
)

Definition at line 2607 of file switch_channel.c.

References buf, CF_VERBOSE_EVENTS, ep, switch_event::headers, switch_event_header::name, switch_event_header::next, switch_event::next, 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_ORIGINATE, SWITCH_EVENT_CHANNEL_PARK, SWITCH_EVENT_CHANNEL_PROGRESS, SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA, SWITCH_EVENT_CHANNEL_UNBRIDGE, 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_mutex_lock(), switch_mutex_unlock(), switch_snprintf(), SWITCH_STACK_BOTTOM, and switch_event_header::value.

Referenced by process_device_hup(), and switch_channel_event_set_data().

2608 {
2610  int global_verbose_events = -1;
2611 
2612  switch_mutex_lock(channel->profile_mutex);
2613 
2614  switch_core_session_ctl(SCSC_VERBOSE_EVENTS, &global_verbose_events);
2615 
2616  if (global_verbose_events ||
2618  switch_event_get_header(event, "presence-data-cols") ||
2621  event->event_id == SWITCH_EVENT_CHANNEL_UUID ||
2623  event->event_id == SWITCH_EVENT_CHANNEL_PARK ||
2632  event->event_id == SWITCH_EVENT_CHANNEL_DATA ||
2637  event->event_id == SWITCH_EVENT_API ||
2638  event->event_id == SWITCH_EVENT_RECORD_START ||
2639  event->event_id == SWITCH_EVENT_RECORD_STOP ||
2642  event->event_id == SWITCH_EVENT_CALL_UPDATE ||
2645  event->event_id == SWITCH_EVENT_CUSTOM) {
2646 
2647  /* Index Variables */
2648 
2649  if (channel->scope_variables) {
2650  switch_event_t *ep;
2651 
2652  for (ep = channel->scope_variables; ep; ep = ep->next) {
2653  for (hi = ep->headers; hi; hi = hi->next) {
2654  char buf[1024];
2655  char *vvar = NULL, *vval = NULL;
2656 
2657  vvar = (char *) hi->name;
2658  vval = (char *) hi->value;
2659 
2660  switch_assert(vvar && vval);
2661  switch_snprintf(buf, sizeof(buf), "scope_variable_%s", vvar);
2662 
2663  if (!switch_event_get_header(event, buf)) {
2665  }
2666  }
2667  }
2668  }
2669 
2670  if (channel->variables) {
2671  for (hi = channel->variables->headers; hi; hi = hi->next) {
2672  char buf[1024];
2673  char *vvar = NULL, *vval = NULL;
2674 
2675  vvar = (char *) hi->name;
2676  vval = (char *) hi->value;
2677 
2678  switch_assert(vvar && vval);
2679  switch_snprintf(buf, sizeof(buf), "variable_%s", vvar);
2681  }
2682  }
2683  }
2684 
2686 }
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:290
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:285
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 const char * ep
Definition: switch_json.c:36
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:2528
#define switch_assert(expr)
switch_event_header_t * headers
Definition: switch_event.h:90
switch_status_t switch_channel_execute_on ( switch_channel_t channel,
const char *  variable_prefix 
)

Definition at line 3638 of file switch_channel.c.

References switch_event_header::array, do_execute_on(), switch_event::headers, switch_event_header::idx, switch_event_header::name, switch_event_header::next, 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_thread(), check_channel_status(), record_callback(), switch_channel_perform_mark_answered(), switch_channel_perform_mark_pre_answered(), switch_channel_perform_mark_ring_ready_value(), switch_core_media_process_udptl(), switch_core_media_read_frame(), switch_ivr_originate(), switch_ivr_session_transfer(), tone_detect_callback(), and tone_on_dtmf().

3639 {
3641  switch_event_t *event, *cevent;
3642  int x = 0;
3643 
3644  switch_core_get_variables(&event);
3645  switch_channel_get_variables(channel, &cevent);
3646  switch_event_merge(event, cevent);
3647 
3648  for (hp = event->headers; hp; hp = hp->next) {
3649  char *var = hp->name;
3650  char *val = hp->value;
3651 
3652  if (!strncasecmp(var, variable_prefix, strlen(variable_prefix))) {
3653  if (hp->idx) {
3654  int i;
3655  for (i = 0; i < hp->idx; i++) {
3656  x++;
3657  do_execute_on(channel, hp->array[i]);
3658  }
3659  } else {
3660  x++;
3661  do_execute_on(channel, val);
3662  }
3663  }
3664  }
3665 
3666  switch_event_destroy(&event);
3667  switch_event_destroy(&cevent);
3668 
3670 }
Representation of an event.
Definition: switch_event.h:80
An event Header.
Definition: switch_event.h:65
static void do_execute_on(switch_channel_t *channel, const char *variable)
switch_status_t switch_core_get_variables(switch_event_t **event)
Definition: switch_core.c:374
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_event_header_t * headers
Definition: switch_event.h:90
void switch_channel_flush_dtmf ( switch_channel_t channel)

Definition at line 709 of file switch_channel.c.

References CS_HANGUP, switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypop(), switch_queue_trypush(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_channel_uninit().

710 {
711  void *pop;
712 
713  switch_mutex_lock(channel->dtmf_mutex);
714  while (switch_queue_trypop(channel->dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
715  switch_dtmf_t *dt = (switch_dtmf_t *) pop;
716  if (channel->state >= CS_HANGUP || switch_queue_trypush(channel->dtmf_log_queue, dt) != SWITCH_STATUS_SUCCESS) {
717  free(dt);
718  }
719  }
721 }
switch_queue_t * dtmf_log_queue
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1140
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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:1155
switch_call_cause_t switch_channel_get_cause ( switch_channel_t channel)

Definition at line 225 of file switch_channel.c.

226 {
227  return channel->hangup_cause;
228 }
switch_call_cause_t hangup_cause
switch_device_record_t* switch_channel_get_device_record ( switch_channel_t channel)

Definition at line 5276 of file switch_channel.c.

References switch_mutex_lock().

5277 {
5278  if (channel->device_node) {
5280  return channel->device_node->parent;
5281  }
5282 
5283  return NULL;
5284 }
switch_mutex_t * mutex
Definition: switch_core.h:138
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
struct switch_device_record_s * parent
Definition: switch_core.h:87
switch_device_node_t * device_node
switch_hold_record_t* switch_channel_get_hold_record ( switch_channel_t channel)

Definition at line 184 of file switch_channel.c.

Referenced by switch_ivr_generate_xml_cdr().

185 {
186  return channel->hold_record;
187 }
switch_hold_record_t * hold_record
const char* switch_channel_get_partner_uuid ( switch_channel_t channel)

Definition at line 4659 of file switch_channel.c.

References switch_channel_get_variable, SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE, and SWITCH_SIGNAL_BOND_VARIABLE.

Referenced by recover_callback(), rtp_common_read(), switch_channel_clear_flag_partner(), switch_channel_flip_cid(), switch_channel_get_private_partner(), switch_channel_get_variable_partner(), switch_channel_set_flag_partner(), switch_channel_set_flag_value(), switch_channel_set_variable_partner_var_check(), switch_channel_test_cap_partner(), switch_channel_test_flag_partner(), switch_core_media_gen_local_sdp(), switch_core_media_receive_message(), switch_core_session_pass_indication(), switch_core_session_perform_get_partner(), switch_core_session_read_frame(), switch_core_session_write_frame(), switch_core_standard_on_reset(), switch_ivr_broadcast(), switch_ivr_find_bridged_uuid(), switch_ivr_hold(), switch_ivr_intercept_session(), switch_ivr_parse_event(), switch_ivr_soft_hold(), switch_ivr_unhold(), switch_rtp_write_frame(), and switch_rtp_zerocopy_read_frame().

4660 {
4661  const char *uuid = NULL;
4662 
4663  if (!(uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
4665  }
4666 
4667  return uuid;
4668 }
#define SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE
Definition: switch_types.h:203
#define switch_channel_get_variable(_c, _v)
#define SWITCH_SIGNAL_BOND_VARIABLE
Definition: switch_types.h:202
switch_caller_extension_t* switch_channel_get_queued_extension ( switch_channel_t channel)

Definition at line 3149 of file switch_channel.c.

References switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_core_standard_on_routing().

3150 {
3151  switch_caller_extension_t *caller_extension;
3152 
3153  switch_mutex_lock(channel->profile_mutex);
3154  caller_extension = channel->queued_extension;
3155  channel->queued_extension = NULL;
3157 
3158  return caller_extension;
3159 }
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:290
switch_caller_extension_t * queued_extension
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_channel_timetable_t* switch_channel_get_timetable ( switch_channel_t channel)

Definition at line 406 of file switch_channel.c.

References switch_mutex_lock(), and switch_mutex_unlock().

407 {
408  switch_channel_timetable_t *times = NULL;
409 
410  if (channel->caller_profile) {
412  times = channel->caller_profile->times;
414  }
415 
416  return times;
417 }
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:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
struct switch_channel_timetable * times
void switch_channel_global_init ( switch_memory_pool_t pool)

Definition at line 4811 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().

4812 {
4813  memset(&globals, 0, sizeof(globals));
4814  globals.pool = pool;
4815 
4817  switch_core_hash_init(&globals.device_hash);
4818 }
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1390
switch_memory_pool_t * pool
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
static struct @0 globals
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
memset(buf, 0, buflen)
void switch_channel_global_uninit ( void  )

Definition at line 4820 of file switch_channel.c.

References globals, and switch_core_hash_destroy().

Referenced by switch_core_destroy().

4821 {
4822  switch_core_hash_destroy(&globals.device_hash);
4823 }
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
static struct @0 globals
void switch_channel_handle_cause ( switch_channel_t channel,
switch_call_cause_t  cause 
)

Definition at line 4670 of file switch_channel.c.

References CF_CONFIRM_BLIND_TRANSFER, CF_TRANSFER, CS_ROUTING, 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_originate(), and switch_ivr_multi_threaded_bridge().

4671 {
4672  switch_core_session_t *session = channel->session;
4673  const char *transfer_on_fail = NULL;
4674  char *tof_data = NULL;
4675  char *tof_array[4] = { 0 };
4676  //int tof_arrayc = 0;
4677 
4678  if (!switch_channel_up_nosig(channel)) {
4679  return;
4680  }
4681 
4682  transfer_on_fail = switch_channel_get_variable(channel, "transfer_on_fail");
4683  tof_data = switch_core_session_strdup(session, transfer_on_fail);
4684  switch_split(tof_data, ' ', tof_array);
4685  transfer_on_fail = tof_array[0];
4686 
4687  /*
4688  if the variable continue_on_fail is set it can be:
4689  'true' to continue on all failures.
4690  'false' to not continue.
4691  A list of codes either names or numbers eg "user_busy,normal_temporary_failure,603"
4692  failure_causes acts as the opposite version
4693  EXCEPTION... ATTENDED_TRANSFER never is a reason to continue.......
4694  */
4695  if (cause != SWITCH_CAUSE_ATTENDED_TRANSFER) {
4696  const char *continue_on_fail = NULL, *failure_causes = NULL;
4697 
4698  continue_on_fail = switch_channel_get_variable(channel, "continue_on_fail");
4699  failure_causes = switch_channel_get_variable(channel, "failure_causes");
4700 
4701  if (continue_on_fail || failure_causes) {
4702  const char *cause_str;
4703  char cause_num[35] = "";
4704 
4705  cause_str = switch_channel_cause2str(cause);
4706  switch_snprintf(cause_num, sizeof(cause_num), "%u", cause);
4707 
4708  if (failure_causes) {
4709  char *lbuf = switch_core_session_strdup(session, failure_causes);
4710  char *argv[256] = { 0 };
4711  int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
4712  int i, x = 0;
4713 
4714  for (i = 0; i < argc; i++) {
4715  if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
4716  x++;
4717  break;
4718  }
4719  }
4720  if (!x) {
4722  "Failure causes [%s]: Cause: %s\n", failure_causes, cause_str);
4723  return;
4724  }
4725  }
4726 
4727  if (continue_on_fail) {
4728  if (switch_true(continue_on_fail)) {
4729  return;
4730  } else {
4731  char *lbuf = switch_core_session_strdup(session, continue_on_fail);
4732  char *argv[256] = { 0 };
4733  int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
4734  int i;
4735 
4736  for (i = 0; i < argc; i++) {
4737  if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
4739  "Continue on fail [%s]: Cause: %s\n", continue_on_fail, cause_str);
4740  return;
4741  }
4742  }
4743  }
4744  }
4745  } else {
4746  /* no answer is *always* a reason to continue */
4748  return;
4749  }
4750  }
4751 
4752  if (transfer_on_fail || failure_causes) {
4753  const char *cause_str;
4754  char cause_num[35] = "";
4755 
4756  cause_str = switch_channel_cause2str(cause);
4757  switch_snprintf(cause_num, sizeof(cause_num), "%u", cause);
4758 
4759  if ((tof_array[1] == NULL ) || (!strcasecmp(tof_array[1], "auto_cause"))){
4760  tof_array[1] = (char *) cause_str;
4761  }
4762 
4763  if (failure_causes) {
4764  char *lbuf = switch_core_session_strdup(session, failure_causes);
4765  char *argv[256] = { 0 };
4766  int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
4767  int i, x = 0;
4768 
4769  for (i = 0; i < argc; i++) {
4770  if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
4771  x++;
4772  break;
4773  }
4774  }
4775  if (!x) {
4777  "Failure causes [%s]: Cause: %s\n", failure_causes, cause_str);
4778 
4779  switch_ivr_session_transfer(session, tof_array[1], tof_array[2], tof_array[3]);
4780  }
4781  }
4782 
4783  if (transfer_on_fail) {
4784  if (switch_true(transfer_on_fail)) {
4785  return;
4786  } else {
4787  char *lbuf = switch_core_session_strdup(session, transfer_on_fail);
4788  char *argv[256] = { 0 };
4789  int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
4790  int i;
4791 
4792  for (i = 0; i < argc; i++) {
4793  if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
4795  "Transfer on fail [%s]: Cause: %s\n", transfer_on_fail, cause_str);
4796  switch_ivr_session_transfer(session, tof_array[1], tof_array[2], tof_array[3]);
4797  }
4798  }
4799  }
4800  }
4801  }
4802  }
4803 
4804 
4806  switch_channel_get_state(channel) != CS_ROUTING) {
4807  switch_channel_hangup(channel, cause);
4808  }
4809 }
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's state machine to end.
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define switch_split(_data, _delim, _array)
Definition: switch_utils.h:342
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
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's pool.
Definition: switch_core.h:717
switch_core_session_t * session
const char * switch_channel_cause2str(switch_call_cause_t cause)
switch_size_t switch_channel_has_dtmf ( switch_channel_t channel)

Definition at line 479 of file switch_channel.c.

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

480 {
481  switch_size_t has;
482 
483  switch_mutex_lock(channel->dtmf_mutex);
484  has = switch_queue_size(channel->dtmf_queue);
486 
487  return has;
488 }
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1114
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_queue_t * dtmf_queue
uintptr_t switch_size_t
switch_mutex_t * dtmf_mutex
switch_channel_state_t switch_channel_name_state ( const char *  name)

Definition at line 2178 of file switch_channel.c.

References CS_DESTROY.

2179 {
2180  uint32_t x = 0;
2181  for (x = 0; state_names[x]; x++) {
2182  if (!strcasecmp(state_names[x], name)) {
2183  return (switch_channel_state_t) x;
2184  }
2185  }
2186 
2187  return CS_DESTROY;
2188 }
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 ...
switch_status_t switch_channel_pass_sdp ( switch_channel_t from_channel,
switch_channel_t to_channel,
const char *  sdp 
)

Definition at line 5345 of file switch_channel.c.

References 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().

5346 {
5348  char *use_sdp = (char *) sdp;
5349  char *patched_sdp = NULL;
5350 
5352  const char *var;
5353 
5354  if ((var = switch_channel_get_variable(from_channel, "bypass_media_sdp_filter"))) {
5355  if ((patched_sdp = switch_core_media_process_sdp_filter(use_sdp, var, from_channel->session))) {
5356  use_sdp = patched_sdp;
5357  }
5358  }
5359 
5360  switch_channel_set_variable(to_channel, SWITCH_B_SDP_VARIABLE, use_sdp);
5361  }
5362 
5363  switch_safe_free(patched_sdp);
5364 
5365  return status;
5366 }
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:789
switch_status_t
Common return values.
#define SWITCH_B_SDP_VARIABLE
Definition: switch_types.h:198
#define switch_channel_set_variable(_channel, _var, _val)
switch_core_session_t * session
void switch_channel_process_device_hangup ( switch_channel_t channel)

Definition at line 4967 of file switch_channel.c.

References process_device_hup(), and switch_channel_check_device_state().

Referenced by switch_core_session_hangup_state().

4968 {
4969 
4970  switch_channel_check_device_state(channel, channel->callstate);
4971  process_device_hup(channel);
4972 
4973 }
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_status_t switch_channel_queue_dtmf ( switch_channel_t channel,
const switch_dtmf_t dtmf 
)

Definition at line 490 of file switch_channel.c.

References switch_dtmf_t::digit, DTMF_FLAG_SENSITIVE, switch_dtmf_t::duration, is_dtmf, 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().

491 {
492  switch_status_t status;
493  void *pop;
494  switch_dtmf_t new_dtmf = { 0 };
496 
497  switch_assert(dtmf);
498 
499  switch_mutex_lock(channel->dtmf_mutex);
500  new_dtmf = *dtmf;
501 
502  if (sensitive) {
503  switch_set_flag((&new_dtmf), DTMF_FLAG_SENSITIVE);
504  }
505 
506  if ((status = switch_core_session_recv_dtmf(channel->session, dtmf) != SWITCH_STATUS_SUCCESS)) {
507  goto done;
508  }
509 
510  if (is_dtmf(new_dtmf.digit)) {
511  switch_dtmf_t *dt;
512  int x = 0;
513 
514  if (!sensitive) {
515  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_INFO, "RECV DTMF %c:%d\n", new_dtmf.digit, new_dtmf.duration);
516  }
517 
518  if (new_dtmf.digit != 'w' && new_dtmf.digit != 'W') {
519  if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
520  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s EXCESSIVE DTMF DIGIT LEN [%d]\n",
521  switch_channel_get_name(channel), new_dtmf.duration);
523  } else if (new_dtmf.duration < switch_core_min_dtmf_duration(0)) {
524  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s SHORT DTMF DIGIT LEN [%d]\n",
525  switch_channel_get_name(channel), new_dtmf.duration);
527  }
528  }
529 
530  if (!new_dtmf.duration) {
532  }
533 
534 
535  switch_zmalloc(dt, sizeof(*dt));
536  *dt = new_dtmf;
537 
538 
539  while (switch_queue_trypush(channel->dtmf_queue, dt) != SWITCH_STATUS_SUCCESS) {
540  if (switch_queue_trypop(channel->dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
541  free(pop);
542  }
543  if (++x > 100) {
544  status = SWITCH_STATUS_FALSE;
545  free(dt);
546  goto done;
547  }
548  }
549  }
550 
551  status = SWITCH_STATUS_SUCCESS;
552 
553  done:
554 
556 
558 
559  return status;
560 }
#define SWITCH_SENSITIVE_DTMF_VARIABLE
Definition: switch_types.h:144
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
switch_bool_t
Definition: switch_types.h:405
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1140
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:288
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
uint32_t switch_core_max_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1664
#define is_dtmf(key)
determine if a character is a valid DTMF key
Definition: switch_utils.h:614
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1704
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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:1681
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:1155
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_status_t switch_channel_queue_dtmf_string ( switch_channel_t channel,
const char *  dtmf_string 
)

Definition at line 562 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_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_SUCCESS, and zstr.

563 {
564  char *p;
566  int sent = 0, dur;
567  char *string;
568  int i, argc;
569  char *argv[256];
570 
571  if (zstr(dtmf_string)) {
572  return SWITCH_STATUS_FALSE;
573  }
574 
575 
577 
578  if (*dtmf_string == '~') {
579  dtmf_string++;
580  dtmf.flags = 0;
581  }
582 
583  string = switch_core_session_strdup(channel->session, dtmf_string);
584  argc = switch_separate_string(string, '+', argv, (sizeof(argv) / sizeof(argv[0])));
585 
586  for (i = 0; i < argc; i++) {
589  if ((p = strchr(argv[i], '@'))) {
590  *p++ = '\0';
591  if ((dur = atoi(p)) > (int)switch_core_min_dtmf_duration(0) / 8) {
592  dtmf.duration = dur * 8;
593  }
594  }
595 
596  for (p = argv[i]; p && *p; p++) {
597  if (is_dtmf(*p)) {
598  dtmf.digit = *p;
599 
600  if (dtmf.duration > switch_core_max_dtmf_duration(0)) {
601  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_WARNING, "EXCESSIVE DTMF DIGIT LEN %c %d\n", dtmf.digit, dtmf.duration);
603  } else if (dtmf.duration < switch_core_min_dtmf_duration(0)) {
604  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_WARNING, "SHORT DTMF DIGIT LEN %c %d\n", dtmf.digit, dtmf.duration);
606  } else if (!dtmf.duration) {
608  }
609 
610  if (switch_channel_queue_dtmf(channel, &dtmf) == SWITCH_STATUS_SUCCESS) {
611  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s Queue dtmf\ndigit=%c ms=%u samples=%u\n",
612  switch_channel_get_name(channel), dtmf.digit, dur, dtmf.duration);
613  sent++;
614  }
615  }
616  }
617 
618  }
619 
621 }
switch_status_t switch_channel_queue_dtmf(switch_channel_t *channel, const switch_dtmf_t *dtmf)
uint32_t duration
Definition: switch_types.h:288
#define zstr(x)
Definition: switch_utils.h:281
uint32_t switch_core_max_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1664
#define is_dtmf(key)
determine if a character is a valid DTMF key
Definition: switch_utils.h:614
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1704
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.
uint32_t switch_core_default_dtmf_duration(uint32_t duration)
Definition: switch_core.c:1681
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's pool.
Definition: switch_core.h:717
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)
void switch_channel_release_device_record ( switch_device_record_t **  drecp)

Definition at line 5286 of file switch_channel.c.

References switch_mutex_unlock().

5287 {
5288  if (drecp && *drecp) {
5289  switch_mutex_unlock((*drecp)->mutex);
5290  *drecp = NULL;
5291  }
5292 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
const char* switch_channel_set_device_id ( switch_channel_t channel,
const char *  device_id 
)

Definition at line 5248 of file switch_channel.c.

References add_uuid(), create_device_record(), switch_device_record_s::device_id, globals, 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().

5249 {
5250  switch_device_record_t *drec;
5251 
5252  if (channel->device_node) {
5253  return NULL;
5254  }
5255 
5256  channel->device_id = switch_core_session_strdup(channel->session, device_id);
5257 
5258  switch_mutex_lock(globals.device_mutex);
5259 
5260  if (!(drec = switch_core_hash_find(globals.device_hash, channel->device_id))) {
5261  create_device_record(&drec, channel->device_id);
5262  switch_core_hash_insert(globals.device_hash, drec->device_id, drec);
5263  }
5264 
5265  add_uuid(drec, channel);
5266 
5267  switch_mutex_unlock(globals.device_mutex);
5268 
5269  switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Setting DEVICE ID to [%s]\n", device_id);
5270 
5271  switch_channel_check_device_state(channel, channel->callstate);
5272 
5273  return device_id;
5274 }
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:290
static struct @0 globals
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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:1410
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's pool.
Definition: switch_core.h:717
switch_channel_callstate_t callstate
switch_core_session_t * session
#define SWITCH_CHANNEL_CHANNEL_LOG(x)
switch_status_t switch_channel_set_timestamps ( switch_channel_t channel)

Definition at line 4304 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, CF_TIMESTAMP_SET, switch_channel_timetable::created, switch_stream_handle::data, switch_dtmf_t::digit, end_of, switch_channel_timetable::hold_accum, 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_timetable::progress, switch_channel_timetable::progress_media, switch_channel_timetable::resurrected, 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_stream_handle::write_function, and zstr.

4305 {
4307  const char *cid_buf = NULL;
4308  switch_caller_profile_t *caller_profile;
4309  switch_app_log_t *app_log, *ap;
4310  char *last_app = NULL, *last_arg = NULL;
4311  char start[80] = "", resurrect[80] = "", answer[80] = "", hold[80],
4312  bridge[80] = "", progress[80] = "", progress_media[80] = "", end[80] = "", tmp[80] = "",
4313  profile_start[80] = "";
4314  int32_t duration = 0, legbillsec = 0, billsec = 0, mduration = 0, billmsec = 0, legbillmsec = 0, progressmsec = 0, progress_mediamsec = 0;
4315  int32_t answersec = 0, answermsec = 0, waitsec = 0, waitmsec = 0;
4316  switch_time_t answerusec = 0;
4317  switch_time_t uduration = 0, legbillusec = 0, billusec = 0, progresssec = 0, progressusec = 0, progress_mediasec = 0, progress_mediausec = 0, waitusec = 0;
4318  time_t tt_created = 0, tt_answered = 0, tt_resurrected = 0, tt_bridged, tt_last_hold, tt_hold_accum,
4319  tt_progress = 0, tt_progress_media = 0, tt_hungup = 0, mtt_created = 0, mtt_answered = 0, mtt_bridged = 0,
4320  mtt_hungup = 0, tt_prof_created, mtt_progress = 0, mtt_progress_media = 0;
4321  void *pop;
4322  char dtstr[SWITCH_DTMF_LOG_LEN + 1] = "";
4323  int x = 0;
4324 
4325  switch_mutex_lock(channel->profile_mutex);
4326 
4329  return SWITCH_STATUS_FALSE;
4330  }
4331 
4332  if (!(caller_profile = channel->caller_profile) || !channel->variables) {
4334  return SWITCH_STATUS_FALSE;
4335  }
4336 
4338 
4339  if ((app_log = switch_core_session_get_app_log(channel->session))) {
4340  for (ap = app_log; ap && ap->next; ap = ap->next);
4341  last_app = ap->app;
4342  last_arg = ap->arg;
4343  }
4344 
4345  if (!zstr(caller_profile->caller_id_name)) {
4346  cid_buf = switch_core_session_sprintf(channel->session, "\"%s\" <%s>", caller_profile->caller_id_name,
4347  switch_str_nil(caller_profile->caller_id_number));
4348  } else {
4349  cid_buf = caller_profile->caller_id_number;
4350  }
4351 
4353  switch_dtmf_t *dt = (switch_dtmf_t *) pop;
4354 
4355  if (dt) {
4356  dtstr[x++] = dt->digit;
4357  free(dt);
4358  dt = NULL;
4359  }
4360  }
4361 
4362  if (x) {
4363  const char *var = switch_channel_get_variable(channel, "digits_dialed_filter");
4364  char *digit_string = dtstr;
4365  char *X = NULL;
4366  switch_regex_t *re = NULL;
4367  char *substituted = NULL;
4368 
4369  if (!zstr(var)) {
4370  int proceed = 0;
4371  int ovector[30];
4372 
4373  if ((proceed = switch_regex_perform(dtstr, var, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
4374  int len = (strlen(dtstr) + strlen(var) + 10) * proceed;
4375  int i = 0;
4376  const char *replace = NULL;
4377 
4378  X = malloc(len);
4379 
4380  for (i = 0; i < proceed; i++) {
4381  if (pcre_get_substring(dtstr, ovector, proceed, i, &replace) > 0) {
4382  switch_size_t plen = strlen(replace);
4383  memset(X, 'X', plen);
4384  *(X+plen) = '\0';
4385 
4386  switch_safe_free(substituted);
4387  substituted = switch_string_replace(substituted ? substituted : dtstr, replace, X);
4388 
4389  pcre_free_substring(replace);
4390  }
4391  }
4392 
4393  if (!zstr(substituted)) {
4394  digit_string = substituted;
4395  }
4396  }
4397  }
4398 
4399  switch_channel_set_variable(channel, "digits_dialed", digit_string);
4401  switch_safe_free(substituted);
4402  switch_safe_free(X);
4403  } else {
4404  switch_channel_set_variable(channel, "digits_dialed", "none");
4405  }
4406 
4407  if (caller_profile->times) {
4408  switch_time_exp_t tm;
4409  switch_size_t retsize;
4410  const char *fmt = "%Y-%m-%d %T";
4411 
4412  switch_time_exp_lt(&tm, caller_profile->times->created);
4413  switch_strftime_nocheck(start, &retsize, sizeof(start), fmt, &tm);
4414  switch_channel_set_variable(channel, "start_stamp", start);
4415 
4416  switch_time_exp_lt(&tm, caller_profile->times->profile_created);
4417  switch_strftime_nocheck(profile_start, &retsize, sizeof(profile_start), fmt, &tm);
4418  switch_channel_set_variable(channel, "profile_start_stamp", profile_start);
4419 
4420  if (caller_profile->times->answered) {
4421  switch_time_exp_lt(&tm, caller_profile->times->answered);
4422  switch_strftime_nocheck(answer, &retsize, sizeof(answer), fmt, &tm);
4423  switch_channel_set_variable(channel, "answer_stamp", answer);
4424  }
4425 
4426  if (caller_profile->times->bridged) {
4427  switch_time_exp_lt(&tm, caller_profile->times->bridged);
4428  switch_strftime_nocheck(bridge, &retsize, sizeof(bridge), fmt, &tm);
4429  switch_channel_set_variable(channel, "bridge_stamp", bridge);
4430  }
4431 
4432  if (caller_profile->times->last_hold) {
4433  switch_time_exp_lt(&tm, caller_profile->times->last_hold);
4434  switch_strftime_nocheck(hold, &retsize, sizeof(hold), fmt, &tm);
4435  switch_channel_set_variable(channel, "hold_stamp", hold);
4436  }
4437 
4438  if (caller_profile->times->resurrected) {
4439  switch_time_exp_lt(&tm, caller_profile->times->resurrected);
4440  switch_strftime_nocheck(resurrect, &retsize, sizeof(resurrect), fmt, &tm);
4441  switch_channel_set_variable(channel, "resurrect_stamp", resurrect);
4442  }
4443 
4444  if (caller_profile->times->progress) {
4445  switch_time_exp_lt(&tm, caller_profile->times->progress);
4446  switch_strftime_nocheck(progress, &retsize, sizeof(progress), fmt, &tm);
4447  switch_channel_set_variable(channel, "progress_stamp", progress);
4448  }
4449 
4450  if (caller_profile->times->progress_media) {
4451  switch_time_exp_lt(&tm, caller_profile->times->progress_media);
4452  switch_strftime_nocheck(progress_media, &retsize, sizeof(progress_media), fmt, &tm);
4453  switch_channel_set_variable(channel, "progress_media_stamp", progress_media);
4454  }
4455 
4456  if (channel->hold_record) {
4458  switch_stream_handle_t stream = { 0 };
4459 
4460  SWITCH_STANDARD_STREAM(stream);
4461 
4462  stream.write_function(&stream, "{", SWITCH_VA_NONE);
4463 
4464  for (hr = channel->hold_record; hr; hr = hr->next) {
4465  stream.write_function(&stream, "{%"SWITCH_TIME_T_FMT",%"SWITCH_TIME_T_FMT"},", hr->on, hr->off);
4466  }
4467  end_of((char *)stream.data) = '}';
4468 
4469  switch_channel_set_variable(channel, "hold_events", (char *)stream.data);
4470  free(stream.data);
4471  }
4472 
4473  switch_time_exp_lt(&tm, caller_profile->times->hungup);
4474  switch_strftime_nocheck(end, &retsize, sizeof(end), fmt, &tm);
4475  switch_channel_set_variable(channel, "end_stamp", end);
4476 
4477  tt_created = (time_t) (caller_profile->times->created / 1000000);
4478  mtt_created = (time_t) (caller_profile->times->created / 1000);
4479  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_created);
4480  switch_channel_set_variable(channel, "start_epoch", tmp);
4481  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->created);
4482  switch_channel_set_variable(channel, "start_uepoch", tmp);
4483 
4484  tt_prof_created = (time_t) (caller_profile->times->profile_created / 1000000);
4485  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_prof_created);
4486  switch_channel_set_variable(channel, "profile_start_epoch", tmp);
4487  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->profile_created);
4488  switch_channel_set_variable(channel, "profile_start_uepoch", tmp);
4489 
4490  tt_answered = (time_t) (caller_profile->times->answered / 1000000);
4491  mtt_answered = (time_t) (caller_profile->times->answered / 1000);
4492  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_answered);
4493  switch_channel_set_variable(channel, "answer_epoch", tmp);
4494  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
4495  switch_channel_set_variable(channel, "answer_uepoch", tmp);
4496 
4497  tt_bridged = (time_t) (caller_profile->times->bridged / 1000000);
4498  mtt_bridged = (time_t) (caller_profile->times->bridged / 1000);
4499  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_bridged);
4500  switch_channel_set_variable(channel, "bridge_epoch", tmp);
4501  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->bridged);
4502  switch_channel_set_variable(channel, "bridge_uepoch", tmp);
4503 
4504  tt_last_hold = (time_t) (caller_profile->times->last_hold / 1000000);
4505  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_last_hold);
4506  switch_channel_set_variable(channel, "last_hold_epoch", tmp);
4507  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->last_hold);
4508  switch_channel_set_variable(channel, "last_hold_uepoch", tmp);
4509 
4510  tt_hold_accum = (time_t) (caller_profile->times->hold_accum / 1000000);
4511  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_hold_accum);
4512  switch_channel_set_variable(channel, "hold_accum_seconds", tmp);
4513  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hold_accum);
4514  switch_channel_set_variable(channel, "hold_accum_usec", tmp);
4515  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hold_accum / 1000);
4516  switch_channel_set_variable(channel, "hold_accum_ms", tmp);
4517 
4518  tt_resurrected = (time_t) (caller_profile->times->resurrected / 1000000);
4519  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_resurrected);
4520  switch_channel_set_variable(channel, "resurrect_epoch", tmp);
4521  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->resurrected);
4522  switch_channel_set_variable(channel, "resurrect_uepoch", tmp);
4523 
4524  tt_progress = (time_t) (caller_profile->times->progress / 1000000);
4525  mtt_progress = (time_t) (caller_profile->times->progress / 1000);
4526  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_progress);
4527  switch_channel_set_variable(channel, "progress_epoch", tmp);
4528  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress);
4529  switch_channel_set_variable(channel, "progress_uepoch", tmp);
4530 
4531  tt_progress_media = (time_t) (caller_profile->times->progress_media / 1000000);
4532  mtt_progress_media = (time_t) (caller_profile->times->progress_media / 1000);
4533  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_progress_media);
4534  switch_channel_set_variable(channel, "progress_media_epoch", tmp);
4535  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress_media);
4536  switch_channel_set_variable(channel, "progress_media_uepoch", tmp);
4537 
4538  tt_hungup = (time_t) (caller_profile->times->hungup / 1000000);
4539  mtt_hungup = (time_t) (caller_profile->times->hungup / 1000);
4540  switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_hungup);
4541  switch_channel_set_variable(channel, "end_epoch", tmp);
4542  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
4543  switch_channel_set_variable(channel, "end_uepoch", tmp);
4544 
4545  duration = (int32_t) (tt_hungup - tt_created);
4546  mduration = (int32_t) (mtt_hungup - mtt_created);
4547  uduration = caller_profile->times->hungup - caller_profile->times->created;
4548 
4549  if (caller_profile->times->bridged > caller_profile->times->created) {
4550  waitsec = (int32_t) (tt_bridged - tt_created);
4551  waitmsec = (int32_t) (mtt_bridged - mtt_created);
4552  waitusec = caller_profile->times->bridged - caller_profile->times->created;
4553  } else {
4554  waitsec = 0;
4555  waitmsec = 0;
4556  waitusec = 0;
4557  }
4558 
4559  if (caller_profile->times->answered) {
4560  billsec = (int32_t) (tt_hungup - tt_answered);
4561  billmsec = (int32_t) (mtt_hungup - mtt_answered);
4562  billusec = caller_profile->times->hungup - caller_profile->times->answered;
4563 
4564  legbillsec = (int32_t) (tt_hungup - tt_created);
4565  legbillmsec = (int32_t) (mtt_hungup - mtt_created);
4566  legbillusec = caller_profile->times->hungup - caller_profile->times->created;
4567 
4568  answersec = (int32_t) (tt_answered - tt_created);
4569  answermsec = (int32_t) (mtt_answered - mtt_created);
4570  answerusec = caller_profile->times->answered - caller_profile->times->created;
4571  }
4572 
4573  if (caller_profile->times->progress) {
4574  progresssec = (int32_t) (tt_progress - tt_created);
4575  progressmsec = (int32_t) (mtt_progress - mtt_created);
4576  progressusec = caller_profile->times->progress - caller_profile->times->created;
4577  }
4578 
4579  if (caller_profile->times->progress_media) {
4580  progress_mediasec = (int32_t) (tt_progress_media - tt_created);
4581  progress_mediamsec = (int32_t) (mtt_progress_media - mtt_created);
4582  progress_mediausec = caller_profile->times->progress_media - caller_profile->times->created;
4583  }
4584 
4585  }
4586 
4587  switch_channel_set_variable(channel, "last_app", last_app);
4588  switch_channel_set_variable(channel, "last_arg", last_arg);
4589  switch_channel_set_variable(channel, "caller_id", cid_buf);
4590 
4591  switch_snprintf(tmp, sizeof(tmp), "%d", duration);
4592  switch_channel_set_variable(channel, "duration", tmp);
4593 
4594  switch_snprintf(tmp, sizeof(tmp), "%d", billsec);
4595  switch_channel_set_variable(channel, "billsec", tmp);
4596 
4597  switch_snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, progresssec);
4598  switch_channel_set_variable(channel, "progresssec", tmp);
4599 
4600  switch_snprintf(tmp, sizeof(tmp), "%d", answersec);
4601  switch_channel_set_variable(channel, "answersec", tmp);
4602 
4603  switch_snprintf(tmp, sizeof(tmp), "%d", waitsec);
4604  switch_channel_set_variable(channel, "waitsec", tmp);
4605 
4606  switch_snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, progress_mediasec);
4607  switch_channel_set_variable(channel, "progress_mediasec", tmp);
4608 
4609  switch_snprintf(tmp, sizeof(tmp), "%d", legbillsec);
4610  switch_channel_set_variable(channel, "flow_billsec", tmp);
4611 
4612  switch_snprintf(tmp, sizeof(tmp), "%d", mduration);
4613  switch_channel_set_variable(channel, "mduration", tmp);
4614 
4615  switch_snprintf(tmp, sizeof(tmp), "%d", billmsec);
4616  switch_channel_set_variable(channel, "billmsec", tmp);
4617 
4618  switch_snprintf(tmp, sizeof(tmp), "%d", progressmsec);
4619  switch_channel_set_variable(channel, "progressmsec", tmp);
4620 
4621  switch_snprintf(tmp, sizeof(tmp), "%d", answermsec);
4622  switch_channel_set_variable(channel, "answermsec", tmp);
4623 
4624  switch_snprintf(tmp, sizeof(tmp), "%d", waitmsec);
4625  switch_channel_set_variable(channel, "waitmsec", tmp);
4626 
4627  switch_snprintf(tmp, sizeof(tmp), "%d", progress_mediamsec);
4628  switch_channel_set_variable(channel, "progress_mediamsec", tmp);
4629 
4630  switch_snprintf(tmp, sizeof(tmp), "%d", legbillmsec);
4631  switch_channel_set_variable(channel, "flow_billmsec", tmp);
4632 
4633  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, uduration);
4634  switch_channel_set_variable(channel, "uduration", tmp);
4635 
4636  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, billusec);
4637  switch_channel_set_variable(channel, "billusec", tmp);
4638 
4639  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, progressusec);
4640  switch_channel_set_variable(channel, "progressusec", tmp);
4641 
4642  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, answerusec);
4643  switch_channel_set_variable(channel, "answerusec", tmp);
4644 
4645  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, waitusec);
4646  switch_channel_set_variable(channel, "waitusec", tmp);
4647 
4648  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, progress_mediausec);
4649  switch_channel_set_variable(channel, "progress_mediausec", tmp);
4650 
4651  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, legbillusec);
4652  switch_channel_set_variable(channel, "flow_billusec", tmp);
4653 
4655 
4656  return status;
4657 }
#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:76
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:1140
switch_status_t switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
Definition: switch_apr.c:323
#define end_of(_s)
Definition: switch_utils.h:616
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:179
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:281
switch_mutex_t * profile_mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
int64_t switch_time_t
Definition: switch_apr.h:188
switch_time_t on
Definition: switch_core.h:73
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#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:789
#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:903
switch_stream_handle_write_function_t write_function
#define SWITCH_DTMF_LOG_LEN
Definition: switch_types.h:230
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:74
switch_time_t progress_media
struct switch_app_log * next
Definition: switch_core.h:62
const char* switch_channel_state_name ( switch_channel_state_t  state)

Definition at line 2172 of file switch_channel.c.

Referenced by switch_channel_event_set_basic_data().

2173 {
2174  return state_names[state];
2175 }
static const char * state_names[]
void switch_channel_state_thread_lock ( switch_channel_t channel)

Definition at line 2490 of file switch_channel.c.

References switch_mutex_lock().

Referenced by switch_core_session_run().

2491 {
2492  switch_mutex_lock(channel->thread_mutex);
2493 }
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * thread_mutex
switch_status_t switch_channel_state_thread_trylock ( switch_channel_t channel)

Definition at line 2496 of file switch_channel.c.

References switch_mutex_trylock().

Referenced by switch_core_session_wake_session_thread().

2497 {
2498  return switch_mutex_trylock(channel->thread_mutex);
2499 }
switch_status_t switch_mutex_trylock(switch_mutex_t *lock)
Definition: switch_apr.c:295
switch_mutex_t * thread_mutex
void switch_channel_state_thread_unlock ( switch_channel_t channel)

Definition at line 2502 of file switch_channel.c.

References switch_mutex_unlock().

Referenced by switch_core_session_run(), and switch_core_session_wake_session_thread().

2503 {
2505 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_mutex_t * thread_mutex
switch_call_cause_t switch_channel_str2cause ( const char *  str)

Definition at line 204 of file switch_channel.c.

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

205 {
206  uint8_t x;
208 
209  if (!zstr(str)) {
210  if (*str > 47 && *str < 58) {
211  cause = atoi(str);
212  } else {
213  for (x = 0; x < (sizeof(CAUSE_CHART) / sizeof(struct switch_cause_table)) - 1 && CAUSE_CHART[x].name; x++) {
214  if (!strcasecmp(CAUSE_CHART[x].name, str)) {
215  cause = CAUSE_CHART[x].cause;
216  break;
217  }
218  }
219  }
220  }
221 
222  return cause;
223 }
#define zstr(x)
Definition: switch_utils.h:281
static struct switch_cause_table CAUSE_CHART[]
switch_call_cause_t
switch_call_cause_t cause
void switch_channel_transfer_to_extension ( switch_channel_t channel,
switch_caller_extension_t caller_extension 
)

Definition at line 3161 of file switch_channel.c.

References CF_TRANSFER, CS_ROUTING, switch_channel_set_flag, switch_channel_set_state, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by switch_ivr_parse_event().

3162 {
3163  switch_mutex_lock(channel->profile_mutex);
3164  channel->queued_extension = caller_extension;
3166 
3169 }
#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:290
switch_caller_extension_t * queued_extension
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define switch_channel_set_flag(_c, _f)
switch_status_t switch_channel_unbind_device_state_handler ( switch_device_state_function_t  function)

Definition at line 5320 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.

5321 {
5322  switch_device_state_binding_t *ptr, *last = NULL;
5324 
5325  switch_mutex_lock(globals.device_mutex);
5326  for (ptr = globals.device_bindings; ptr; ptr = ptr->next) {
5327  if (ptr->function == function) {
5328  status = SWITCH_STATUS_SUCCESS;
5329 
5330  if (last) {
5331  last->next = ptr->next;
5332  } else {
5333  globals.device_bindings = ptr->next;
5334  last = NULL;
5335  continue;
5336  }
5337  }
5338  last = ptr;
5339  }
5340  switch_mutex_unlock(globals.device_mutex);
5341 
5342  return status;
5343 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
static struct @0 globals
switch_device_state_function_t function
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_status_t
Common return values.
struct switch_device_state_binding_s * next
switch_status_t switch_event_base_add_header ( switch_event_t event,
switch_stack_t  stack,
const char *  header_name,
char *  data 
)

Variable Documentation

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 241 of file switch_channel.c.

Referenced by switch_channel_callstate2str(), and switch_channel_str2callstate().

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

Definition at line 53 of file switch_channel.c.

switch_hash_t* device_hash

Definition at line 51 of file switch_channel.c.

switch_mutex_t* device_mutex

Definition at line 52 of file switch_channel.c.

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 258 of file switch_channel.c.

Referenced by switch_channel_device_state2str().

struct { ... } globals

Definition at line 50 of file switch_channel.c.

Referenced by check_queue(), EventConsumer::cleanup(), create_device_record(), create_handle(), destroy_thread(), main(), new_job(), record_callback(), sql_in_thread(), switch_caller_profile_clone(), switch_caller_profile_dup(), switch_caller_profile_new(), switch_channel_clear_device_record(), switch_channel_global_init(), switch_core_asr_open(), switch_core_codec_destroy(), switch_core_codec_init_with_bitrate(), switch_core_directory_open(), switch_core_launch_thread(), switch_core_media_bug_add(), switch_core_media_ext_address_lookup(), switch_core_memory_reclaim(), switch_core_perform_file_open(), switch_core_port_allocator_destroy(), switch_core_port_allocator_new(), switch_core_session_findall_matching_var(), switch_core_session_hupall(), switch_core_session_hupall_endpoint(), switch_core_session_hupall_matching_var_ans(), switch_core_session_init(), switch_core_session_perform_destroy(), switch_core_session_request_uuid(), switch_core_session_start_video_thread(), switch_core_session_thread_pool_worker(), switch_core_speech_open(), switch_core_sqldb_start(), switch_core_timer_init(), 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_digit_stream_parser_new(), switch_ivr_dmachine_create(), switch_ivr_dmachine_destroy(), switch_ivr_enterprise_originate(), switch_ivr_menu_init(), switch_ivr_menu_stack_free(), switch_ivr_menu_stack_xml_init(), switch_ivr_play_file(), switch_ivr_speak_text(), switch_jb_create(), switch_live_array_create(), switch_live_array_destroy(), switch_log_init(), SWITCH_MODULE_LOAD_FUNCTION(), switch_nat_init(), switch_network_list_create(), switch_rtp_create(), switch_sockaddr_create(), switch_sql_queue_manager_destroy(), switch_sql_queue_manager_init_name(), switch_system_thread(), switch_xml_free_in_thread(), switch_xml_init(), task_own_thread(), and test_port().

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 2154 of file switch_channel.c.