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

Go to the source code of this file.

Data Structures

struct  media_job_t
 
struct  switch_ivr_digit_stream_parser
 
struct  switch_ivr_digit_stream
 

Macros

#define add_stat(_x, _i, _s)
 
#define add_stat_double(_x, _i, _s)
 
#define add_jstat(_j, _i, _s)
 
#define START_SAMPLES   32768
 

Functions

switch_status_t switch_ivr_sound_test (switch_core_session_t *session)
 
switch_status_t switch_ivr_sleep (switch_core_session_t *session, uint32_t ms, switch_bool_t sync, switch_input_args_t *args)
 Wait for time to pass for a specified number of milliseconds. More...
 
static void *SWITCH_THREAD_FUNC unicast_thread_run (switch_thread_t *thread, void *obj)
 
static void unicast_thread_launch (switch_unicast_conninfo_t *conninfo)
 
switch_status_t switch_ivr_deactivate_unicast (switch_core_session_t *session)
 
switch_status_t switch_ivr_activate_unicast (switch_core_session_t *session, char *local_ip, switch_port_t local_port, char *remote_ip, switch_port_t remote_port, char *transport, char *flags)
 
switch_status_t switch_ivr_parse_event (switch_core_session_t *session, switch_event_t *event)
 
switch_status_t switch_ivr_parse_next_event (switch_core_session_t *session)
 
switch_status_t switch_ivr_process_indications (switch_core_session_t *session, switch_core_session_message_t *message)
 
switch_status_t switch_ivr_parse_all_messages (switch_core_session_t *session)
 
switch_status_t switch_ivr_parse_signal_data (switch_core_session_t *session, switch_bool_t all, switch_bool_t only_session_thread)
 
switch_status_t switch_ivr_parse_all_signal_data (switch_core_session_t *session)
 
switch_status_t switch_ivr_parse_next_signal_data (switch_core_session_t *session)
 
switch_status_t switch_ivr_parse_all_events (switch_core_session_t *session)
 Parse all commands from an event. More...
 
switch_status_t switch_ivr_park (switch_core_session_t *session, switch_input_args_t *args)
 
switch_status_t switch_ivr_collect_digits_callback (switch_core_session_t *session, switch_input_args_t *args, uint32_t digit_timeout, uint32_t abs_timeout)
 Wait for DTMF digits calling a pluggable callback function when digits are collected. More...
 
switch_status_t switch_ivr_collect_digits_count (switch_core_session_t *session, char *buf, switch_size_t buflen, switch_size_t maxdigits, const char *terminators, char *terminator, uint32_t first_timeout, uint32_t digit_timeout, uint32_t abs_timeout)
 Wait for specified number of DTMF digits, untile terminator is received or until the channel hangs up. More...
 
switch_status_t switch_ivr_send_prompt (switch_core_session_t *session, const char *type, const char *text, const char *regex)
 
switch_status_t switch_ivr_hold (switch_core_session_t *session, const char *message, switch_bool_t moh)
 Signal the session with a protocol specific hold message. More...
 
switch_status_t switch_ivr_hold_uuid (const char *uuid, const char *message, switch_bool_t moh)
 Signal the session with a protocol specific hold message. More...
 
switch_status_t switch_ivr_hold_toggle_uuid (const char *uuid, const char *message, switch_bool_t moh)
 Toggles channel hold state of session. More...
 
switch_status_t switch_ivr_unhold (switch_core_session_t *session)
 Signal the session with a protocol specific unhold message. More...
 
switch_status_t switch_ivr_unhold_uuid (const char *uuid)
 Signal the session with a protocol specific unhold message. More...
 
switch_status_t switch_ivr_3p_media (const char *uuid, switch_media_flag_t flags)
 
switch_status_t switch_ivr_media (const char *uuid, switch_media_flag_t flags)
 Signal a session to request direct media access to it's remote end. More...
 
switch_status_t switch_ivr_3p_nomedia (const char *uuid, switch_media_flag_t flags)
 
switch_status_t switch_ivr_nomedia (const char *uuid, switch_media_flag_t flags)
 Signal a session to request indirect media allowing it to exchange media directly with another device. More...
 
static void *SWITCH_THREAD_FUNC media_thread_run (switch_thread_t *thread, void *obj)
 
void switch_ivr_bg_media (const char *uuid, switch_media_flag_t flags, switch_bool_t on, switch_bool_t is3p, uint32_t delay)
 
void switch_ivr_check_hold (switch_core_session_t *session)
 
switch_status_t switch_ivr_session_transfer (switch_core_session_t *session, const char *extension, const char *dialplan, const char *context)
 
switch_status_t switch_ivr_transfer_variable (switch_core_session_t *sessa, switch_core_session_t *sessb, char *var)
 Transfer variables from one session to another. More...
 
switch_status_t switch_ivr_digit_stream_parser_new (switch_memory_pool_t *pool, switch_ivr_digit_stream_parser_t **parser)
 Create a digit stream parser object. More...
 
switch_status_t switch_ivr_digit_stream_parser_destroy (switch_ivr_digit_stream_parser_t *parser)
 Destroy a digit stream parser object. More...
 
switch_status_t switch_ivr_digit_stream_new (switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t **stream)
 Create a new digit stream object. More...
 
switch_status_t switch_ivr_digit_stream_destroy (switch_ivr_digit_stream_t **stream)
 Destroys a digit stream object. More...
 
switch_status_t switch_ivr_digit_stream_parser_set_event (switch_ivr_digit_stream_parser_t *parser, char *digits, void *data)
 Set a digit string to action mapping. More...
 
switch_status_t switch_ivr_digit_stream_parser_del_event (switch_ivr_digit_stream_parser_t *parser, char *digits)
 Delete a string to action mapping. More...
 
void * switch_ivr_digit_stream_parser_feed (switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t *stream, char digit)
 Feed digits collected into the stream for event match testing. More...
 
switch_status_t switch_ivr_digit_stream_reset (switch_ivr_digit_stream_t *stream)
 Reset the collected digit stream to nothing. More...
 
switch_status_t switch_ivr_digit_stream_parser_set_terminator (switch_ivr_digit_stream_parser_t *parser, char digit)
 Set a digit string terminator. More...
 
int switch_ivr_set_xml_profile_data (switch_xml_t xml, switch_caller_profile_t *caller_profile, int off)
 
int switch_ivr_set_xml_call_stats (switch_xml_t xml, switch_core_session_t *session, int off, switch_media_type_t type)
 
static int switch_ivr_set_xml_chan_var (switch_xml_t xml, const char *var, const char *val, int off)
 
int switch_ivr_set_xml_chan_vars (switch_xml_t xml, switch_channel_t *channel, int off)
 
switch_status_t switch_ivr_generate_xml_cdr (switch_core_session_t *session, switch_xml_t *xml_cdr)
 Generate an XML CDR report. More...
 
static void switch_ivr_set_json_profile_data (cJSON *json, switch_caller_profile_t *caller_profile)
 
void switch_ivr_set_json_call_stats (cJSON *json, switch_core_session_t *session, switch_media_type_t type)
 
static void switch_ivr_set_json_chan_vars (cJSON *json, switch_channel_t *channel, switch_bool_t urlencode)
 
switch_status_t switch_ivr_generate_json_cdr (switch_core_session_t *session, cJSON **json_cdr, switch_bool_t urlencode)
 Generate an JSON CDR report. More...
 
void switch_ivr_park_session (switch_core_session_t *session)
 
void switch_ivr_delay_echo (switch_core_session_t *session, uint32_t delay_ms)
 
switch_status_t switch_ivr_say (switch_core_session_t *session, const char *tosay, const char *module_name, const char *say_type, const char *say_method, const char *say_gender, switch_input_args_t *args)
 
switch_status_t switch_ivr_say_string (switch_core_session_t *session, const char *lang, const char *ext, const char *tosay, const char *module_name, const char *say_type, const char *say_method, const char *say_gender, char **rstr)
 
static const char * get_prefixed_str (char *buffer, size_t buffer_size, const char *prefix, size_t prefix_size, const char *str)
 
switch_status_t switch_ivr_set_user_xml (switch_core_session_t *session, const char *prefix, const char *user, const char *domain, switch_xml_t x_user)
 
switch_status_t switch_ivr_set_user (switch_core_session_t *session, const char *data)
 
switch_status_t switch_ivr_set_user_extended (switch_core_session_t *session, const char *data, switch_event_t *params)
 
switch_bool_t switch_ivr_uuid_exists (const char *uuid)
 
switch_bool_t switch_ivr_uuid_force_exists (const char *uuid)
 
switch_status_t switch_ivr_process_fh (switch_core_session_t *session, const char *cmd, switch_file_handle_t *fhp)
 
switch_status_t switch_ivr_insert_file (switch_core_session_t *session, const char *file, const char *insert_file, switch_size_t sample_point)
 
switch_status_t switch_ivr_create_message_reply (switch_event_t **reply, switch_event_t *message, const char *new_proto)
 
char * switch_ivr_check_presence_mapping (const char *exten_name, const char *domain_name)
 
switch_status_t switch_ivr_kill_uuid (const char *uuid, switch_call_cause_t cause)
 
switch_status_t switch_ivr_blind_transfer_ack (switch_core_session_t *session, switch_bool_t success)
 

Macro Definition Documentation

◆ add_jstat

#define add_jstat (   _j,
  _i,
  _s 
)
Value:
switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_SIZE_T_FMT, _i); \
cJSON_AddItemToObject(_j, _s, cJSON_CreateNumber(_i))
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
#define SWITCH_SIZE_T_FMT

Definition at line 3228 of file switch_ivr.c.

Referenced by switch_ivr_set_json_call_stats().

◆ add_stat

#define add_stat (   _x,
  _i,
  _s 
)
Value:
switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_SIZE_T_FMT, _i); \
x_tmp = switch_xml_add_child_d(_x, _s, loff++); \
switch_xml_set_txt_d(x_tmp, var_val)
switch_xml_t switch_xml_add_child_d(_In_ switch_xml_t xml, _In_z_ const char *name, _In_ switch_size_t off)
wrapper for switch_xml_add_child() that strdup()s name
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
#define SWITCH_SIZE_T_FMT

Definition at line 2705 of file switch_ivr.c.

Referenced by switch_ivr_set_xml_call_stats().

◆ add_stat_double

#define add_stat_double (   _x,
  _i,
  _s 
)
Value:
switch_snprintf(var_val, sizeof(var_val), "%0.2f", _i); \
x_tmp = switch_xml_add_child_d(_x, _s, loff++); \
switch_xml_set_txt_d(x_tmp, var_val)
switch_xml_t switch_xml_add_child_d(_In_ switch_xml_t xml, _In_z_ const char *name, _In_ switch_size_t off)
wrapper for switch_xml_add_child() that strdup()s name
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)

Definition at line 2710 of file switch_ivr.c.

Referenced by switch_ivr_set_xml_call_stats().

◆ START_SAMPLES

#define START_SAMPLES   32768

Definition at line 4171 of file switch_ivr.c.

Referenced by switch_ivr_insert_file().

Function Documentation

◆ get_prefixed_str()

static const char* get_prefixed_str ( char *  buffer,
size_t  buffer_size,
const char *  prefix,
size_t  prefix_size,
const char *  str 
)
static

Definition at line 3896 of file switch_ivr.c.

References buffer.

Referenced by switch_ivr_set_user_xml().

3897 {
3898  size_t str_len;
3899 
3900  if (!buffer) {
3901  /*
3902  if buffer is null then it just returns the str without the prefix appended, otherwise buffer contains the prefix followed by the original string
3903  */
3904 
3905  return str;
3906  }
3907 
3908  str_len = strlen(str);
3909  memcpy(buffer, prefix, prefix_size);
3910 
3911  if (str_len + prefix_size + 1 > buffer_size) {
3912  memcpy(buffer + prefix_size, str, buffer_size - prefix_size - 1);
3913  buffer[buffer_size - 1] = '\0';
3914  } else {
3915  memcpy(buffer + prefix_size, str, str_len + 1);
3916  }
3917 
3918  return buffer;
3919 }
char * buffer
Definition: switch_cJSON.h:153

◆ media_thread_run()

static void* SWITCH_THREAD_FUNC media_thread_run ( switch_thread_t thread,
void *  obj 
)
static

Definition at line 2095 of file switch_ivr.c.

References media_job_t::delay, media_job_t::flags, media_job_t::is3p, media_job_t::on, switch_ivr_3p_media(), switch_ivr_3p_nomedia(), switch_ivr_media(), switch_ivr_nomedia(), switch_yield, and media_job_t::uuid.

Referenced by switch_ivr_bg_media().

2096 {
2097  media_job_t *job = (media_job_t *) obj;
2098 
2099  if (job->delay) {
2100  switch_yield(job->delay * 1000);
2101  }
2102 
2103  if (job->on) {
2104  if (job->is3p) {
2105  switch_ivr_3p_media(job->uuid, job->flags);
2106  } else {
2107  switch_ivr_media(job->uuid, job->flags);
2108  }
2109  } else {
2110  if (job->is3p) {
2111  switch_ivr_3p_nomedia(job->uuid, job->flags);
2112  } else {
2113  switch_ivr_nomedia(job->uuid, job->flags);
2114  }
2115  }
2116 
2117  return NULL;
2118 }
const char * uuid
Definition: switch_ivr.c:2088
switch_status_t switch_ivr_nomedia(const char *uuid, switch_media_flag_t flags)
Signal a session to request indirect media allowing it to exchange media directly with another device...
Definition: switch_ivr.c:1987
switch_status_t switch_ivr_media(const char *uuid, switch_media_flag_t flags)
Signal a session to request direct media access to it&#39;s remote end.
Definition: switch_ivr.c:1773
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
switch_bool_t on
Definition: switch_ivr.c:2090
uint32_t delay
Definition: switch_ivr.c:2092
switch_status_t switch_ivr_3p_nomedia(const char *uuid, switch_media_flag_t flags)
Definition: switch_ivr.c:1881
switch_media_flag_t flags
Definition: switch_ivr.c:2089
switch_bool_t is3p
Definition: switch_ivr.c:2091
switch_status_t switch_ivr_3p_media(const char *uuid, switch_media_flag_t flags)
Definition: switch_ivr.c:1663

◆ switch_ivr_parse_event()

switch_status_t switch_ivr_parse_event ( switch_core_session_t session,
switch_event_t event 
)

Definition at line 503 of file switch_ivr.c.

References CF_BREAK, CF_BRIDGED, CF_BROADCAST, CF_EVENT_LOCK, CF_EVENT_LOCK_PRI, CF_EVENT_PARSE, CF_HOLD_BLEG, CF_STOP_BROADCAST, switch_stream_handle::data, switch_event::headers, switch_event_header::name, switch_event_header::next, SFF_CNG, SMF_ECHO_ALEG, SMF_LOOP, SMF_REBRIDGE, switch_api_execute(), switch_caller_extension_add_application(), switch_caller_extension_new(), SWITCH_CAUSE_NORMAL_CLEARING, switch_channel_audio_sync, switch_channel_clear_flag(), switch_channel_clear_flag_recursive(), switch_channel_get_hold_music(), switch_channel_get_hold_music_partner(), switch_channel_get_name(), switch_channel_get_partner_uuid(), switch_channel_get_variable, switch_channel_hangup, switch_channel_media_ready, switch_channel_ready, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_set_flag_recursive(), switch_channel_set_variable, switch_channel_set_variable_printf(), switch_channel_stop_broadcast, switch_channel_str2cause(), switch_channel_test_flag(), switch_channel_transfer_to_extension(), switch_channel_wait_for_flag(), switch_core_session_execute_application, switch_core_session_flush_private_events(), switch_core_session_get_channel(), switch_core_session_get_uuid(), switch_core_session_kill_channel, switch_core_session_locate, switch_core_session_read_frame(), switch_core_session_rwunlock(), switch_core_session_stack_count(), switch_core_session_strdup, switch_event_get_body(), switch_event_get_header, SWITCH_FALSE, switch_hashfunc_default(), SWITCH_IO_FLAG_NONE, switch_is_moh(), switch_ivr_activate_unicast(), switch_ivr_broadcast(), switch_ivr_nomedia(), SWITCH_LOG_DEBUG, SWITCH_LOG_ERROR, switch_log_printf(), switch_micro_time_now(), switch_mprintf(), SWITCH_READ_ACCEPTABLE, SWITCH_SIG_BREAK, SWITCH_STANDARD_STREAM, SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_str_nil, switch_test_flag, SWITCH_TRUE, switch_true(), switch_event_header::value, and zstr.

Referenced by switch_ivr_park(), and switch_ivr_parse_next_event().

504 {
506  char *cmd = switch_event_get_header(event, "call-command");
507  unsigned long cmd_hash;
508  switch_ssize_t hlen = -1;
509  unsigned long CMD_EXECUTE = switch_hashfunc_default("execute", &hlen);
510  unsigned long CMD_HANGUP = switch_hashfunc_default("hangup", &hlen);
511  unsigned long CMD_NOMEDIA = switch_hashfunc_default("nomedia", &hlen);
512  unsigned long CMD_UNICAST = switch_hashfunc_default("unicast", &hlen);
513  unsigned long CMD_XFEREXT = switch_hashfunc_default("xferext", &hlen);
514  char *lead_frames = switch_event_get_header(event, "lead-frames");
515  char *event_lock = switch_event_get_header(event, "event-lock");
516  char *event_lock_pri = switch_event_get_header(event, "event-lock-pri");
518  int el = 0, elp = 0, reneg_sec = 0;
519  const char *var = NULL;
520 
521  if (zstr(cmd)) {
522  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid Command!\n");
523  return SWITCH_STATUS_FALSE;
524  }
525 
526  cmd_hash = switch_hashfunc_default(cmd, &hlen);
527 
529 
530  if (switch_true(event_lock)) {
532  el = 1;
533  }
534 
535  if (switch_true(event_lock_pri)) {
537  elp = 1;
538  }
539 
540  if (lead_frames && switch_channel_media_ready(channel)) {
541  switch_frame_t *read_frame;
542  int frame_count = atoi(lead_frames);
543  int max_frames = frame_count * 2;
544 
545  while (frame_count > 0 && --max_frames > 0) {
546  status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
547  if (!SWITCH_READ_ACCEPTABLE(status)) {
548  goto done;
549  }
550  if (!switch_test_flag(read_frame, SFF_CNG)) {
551  frame_count--;
552  }
553  }
554  }
555 
556  if (cmd_hash == CMD_EXECUTE) {
557  char *app_name = switch_event_get_header(event, "execute-app-name");
558  char *event_uuid = switch_event_get_header(event, "event-uuid");
559  char *event_uuid_name = switch_event_get_header(event, "event-uuid-name");
560  char *app_arg = switch_event_get_header(event, "execute-app-arg");
561  char *content_type = switch_event_get_header(event, "content-type");
562  char *loop_h = switch_event_get_header(event, "loops");
563  char *hold_bleg = switch_event_get_header(event, "hold-bleg");
564  int loops = 1;
565  int inner = 0;
566 
567  if (zstr(app_arg) && !zstr(content_type) && !strcasecmp(content_type, "text/plain")) {
568  app_arg = switch_event_get_body(event);
569  }
570 
571  if (loop_h) {
572  loops = atoi(loop_h);
573  }
574 
575  if (app_name) {
576  int x;
577  const char *b_uuid = NULL;
578  switch_core_session_t *b_session = NULL;
579 
581 
583  inner++;
584  hold_bleg = NULL;
585  }
586 
587  if (!switch_channel_test_flag(channel, CF_BROADCAST)) {
589  if (inner) {
590  inner--;
591  }
592  }
593 
594  if (hold_bleg && switch_true(hold_bleg)) {
595  if ((b_uuid = switch_channel_get_partner_uuid(channel))) {
596  const char *stream;
597  b_uuid = switch_core_session_strdup(session, b_uuid);
598 
599  if (!(stream = switch_channel_get_hold_music_partner(channel))) {
600  stream = switch_channel_get_hold_music(channel);
601  }
602 
603  if (stream && switch_is_moh(stream)) {
604  if ((b_session = switch_core_session_locate(b_uuid))) {
605  switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
606  switch_status_t st;
608 
609  switch_ivr_broadcast(b_uuid, stream, SMF_ECHO_ALEG | SMF_LOOP);
610  st = switch_channel_wait_for_flag(b_channel, CF_BROADCAST, SWITCH_TRUE, 5000, NULL);
611  if (st != SWITCH_STATUS_SUCCESS &&
612  switch_channel_ready(channel) && switch_channel_ready(b_channel) && !switch_channel_test_flag(b_channel, CF_BROADCAST)) {
614  st = switch_channel_wait_for_flag(b_channel, CF_BROADCAST, SWITCH_TRUE, 5000, NULL);
615 
616  if (st != SWITCH_STATUS_SUCCESS &&
617  switch_channel_ready(channel) && switch_channel_ready(b_channel) && !switch_channel_test_flag(b_channel, CF_BROADCAST)) {
619  }
620  }
621  switch_core_session_rwunlock(b_session);
622  }
623  } else {
624  b_uuid = NULL;
625  }
626  }
627  }
628 
629  for (x = 0; x < loops || loops < 0; x++) {
630  switch_time_t b4, aftr;
631 
632  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Command Execute [depth=%d] %s(%s)\n",
633  switch_channel_get_name(channel), switch_core_session_stack_count(session, 0), app_name, switch_str_nil(app_arg));
634  b4 = switch_micro_time_now();
635 
636  if (event_uuid) {
637  switch_channel_set_variable(channel, "app_uuid", event_uuid);
638  }
639  if (event_uuid_name) {
640  switch_channel_set_variable(channel, "app_uuid_name", event_uuid_name);
641  }
642 
643  switch_channel_set_variable_printf(channel, "current_loop", "%d", x + 1);
644  switch_channel_set_variable_printf(channel, "total_loops", "%d", loops);
645 
646  if (switch_core_session_execute_application(session, app_name, app_arg) != SWITCH_STATUS_SUCCESS) {
648  break;
649  }
650 
651  aftr = switch_micro_time_now();
652  if (!switch_channel_ready(channel) || switch_channel_test_flag(channel, CF_STOP_BROADCAST) || aftr - b4 < 500000) {
653  break;
654  }
655  }
656 
657  switch_channel_set_variable(channel, "current_loop", NULL);
658  switch_channel_set_variable(channel, "total_loops", NULL);
659 
660  if (b_uuid) {
661  if ((b_session = switch_core_session_locate(b_uuid))) {
662  switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
665  switch_channel_wait_for_flag(b_channel, CF_BROADCAST, SWITCH_FALSE, 5000, NULL);
666  switch_core_session_rwunlock(b_session);
667  }
668  }
669 
670  if (!inner) {
672  }
673 
677  }
678 
679  switch_channel_audio_sync(channel);
680 
681  if ((var = switch_channel_get_variable(channel, "media_reneg_after_broadcast"))) {
682  reneg_sec = atoi(var);
683  if (reneg_sec < 0) reneg_sec = 0;
684 
685  if (!reneg_sec && switch_true(var)) {
686  reneg_sec = -1;
687  }
688  }
689 
690  if (reneg_sec) {
691  switch_stream_handle_t stream = { 0 };
692  char *api, *api_arg;
693 
694  SWITCH_STANDARD_STREAM(stream);
695  if (reneg_sec > 0) {
696  api = "sched_api";
697  api_arg = switch_mprintf("+%d %s uuid_media_reneg %s", reneg_sec, switch_core_session_get_uuid(session), switch_core_session_get_uuid(session));
698  } else {
699  api = "uuid_media_reneg";
700  api_arg = strdup(switch_core_session_get_uuid(session));
701  }
702  switch_api_execute(api, api_arg, NULL, &stream);
703  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "sending command sched_api %s [%s]\n", api, (char *)stream.data);
704  free(stream.data);
705  free(api_arg);
706  }
707 
708  }
709  } else if (cmd_hash == CMD_UNICAST) {
710  char *local_ip = switch_event_get_header(event, "local-ip");
711  char *local_port = switch_event_get_header(event, "local-port");
712  char *remote_ip = switch_event_get_header(event, "remote-ip");
713  char *remote_port = switch_event_get_header(event, "remote-port");
714  char *transport = switch_event_get_header(event, "transport");
715  char *flags = switch_event_get_header(event, "flags");
716 
717  if (zstr(local_ip)) {
718  local_ip = "127.0.0.1";
719  }
720  if (zstr(remote_ip)) {
721  remote_ip = "127.0.0.1";
722  }
723  if (zstr(local_port)) {
724  local_port = "8025";
725  }
726  if (zstr(remote_port)) {
727  remote_port = "8026";
728  }
729  if (zstr(transport)) {
730  transport = "udp";
731  }
732 
733  switch_ivr_activate_unicast(session, local_ip, (switch_port_t) atoi(local_port), remote_ip, (switch_port_t) atoi(remote_port), transport, flags);
734 
735  } else if (cmd_hash == CMD_XFEREXT) {
737  switch_caller_extension_t *extension = NULL;
738 
739 
740  if ((extension = switch_caller_extension_new(session, "xferext", "xferext")) == 0) {
741  abort();
742  }
743 
744  for (hp = event->headers; hp; hp = hp->next) {
745  char *app;
746  char *data;
747 
748  if (!strcasecmp(hp->name, "application")) {
749  app = strdup(hp->value);
750  if (app) {
751  data = strchr(app, ' ');
752 
753  if (data) {
754  *data++ = '\0';
755  }
756 
757  switch_caller_extension_add_application(session, extension, app, data);
758  free(app);
759  }
760  }
761  }
762 
763  switch_channel_transfer_to_extension(channel, extension);
764 
765  } else if (cmd_hash == CMD_HANGUP) {
766  char *cause_name = switch_event_get_header(event, "hangup-cause");
768 
769  if (cause_name) {
770  cause = switch_channel_str2cause(cause_name);
771  }
772 
773  switch_channel_hangup(channel, cause);
774  } else if (cmd_hash == CMD_NOMEDIA) {
775  char *uuid = switch_event_get_header(event, "nomedia-uuid");
777  }
778 
779  status = SWITCH_STATUS_SUCCESS;
780 
781  done:
782 
784 
785  if (el) {
787  }
788 
789  if (elp) {
791  }
792 
793  return switch_channel_test_flag(channel, CF_BREAK) ? SWITCH_STATUS_BREAK : status;
794 }
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it&#39;s state machine to end.
void switch_channel_set_flag_recursive(switch_channel_t *channel, switch_channel_flag_t flag)
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
#define SWITCH_CHANNEL_SESSION_LOG(x)
An Abstract Representation of a dialplan extension.
const char * switch_channel_get_partner_uuid(switch_channel_t *channel)
switch_status_t switch_ivr_nomedia(const char *uuid, switch_media_flag_t flags)
Signal a session to request indirect media allowing it to exchange media directly with another device...
Definition: switch_ivr.c:1987
#define switch_channel_stop_broadcast(_channel)
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.
switch_status_t switch_ivr_broadcast(const char *uuid, const char *path, switch_media_flag_t flags)
Signal the session to broadcast audio.
#define switch_channel_ready(_channel)
An event Header.
Definition: switch_event.h:65
#define switch_channel_media_ready(_channel)
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
switch_status_t switch_core_session_read_frame(_In_ switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
Read a frame from a session.
#define zstr(x)
Definition: switch_utils.h:314
#define switch_core_session_execute_application(_a, _b, _c)
Execute an application on a session.
Definition: switch_core.h:1129
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
int64_t switch_time_t
Definition: switch_apr.h:188
#define switch_channel_audio_sync(_c)
const char * switch_channel_get_hold_music(switch_channel_t *channel)
static switch_bool_t switch_is_moh(const char *s)
Definition: switch_utils.h:319
char * switch_event_get_body(switch_event_t *event)
Retrieve the body value from an event.
Definition: switch_event.c:867
intptr_t switch_ssize_t
#define switch_channel_get_variable(_c, _v)
uint32_t switch_core_session_flush_private_events(switch_core_session_t *session)
Flush the private event queue of a session.
switch_call_cause_t switch_channel_str2cause(_In_ const char *str)
return a cause code for a given string
An abstraction of a data frame.
Definition: switch_frame.h:54
void switch_caller_extension_add_application(_In_ switch_core_session_t *session, _In_ switch_caller_extension_t *caller_extension, _In_z_ const char *application_name, _In_z_ const char *extra_data)
Add an application (instruction) to the given extension.
uint16_t switch_port_t
#define SWITCH_STANDARD_STREAM(s)
const char * switch_channel_get_hold_music_partner(switch_channel_t *channel)
hashtable_flag_t flags
switch_call_cause_t
switch_caller_extension_t * switch_caller_extension_new(_In_ switch_core_session_t *session, _In_z_ const char *extension_name, _In_z_ const char *extension_number)
Create a new extension with desired parameters.
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:993
switch_status_t switch_ivr_activate_unicast(switch_core_session_t *session, char *local_ip, switch_port_t local_port, char *remote_ip, switch_port_t remote_port, char *transport, char *flags)
Definition: switch_ivr.c:404
switch_status_t
Common return values.
struct switch_event_header * next
Definition: switch_event.h:76
#define switch_core_session_locate(uuid_str)
Locate a session based on it&#39;s uuid.
Definition: switch_core.h:932
unsigned int switch_hashfunc_default(const char *key, switch_ssize_t *klen)
Definition: switch_apr.c:143
void switch_channel_transfer_to_extension(switch_channel_t *channel, switch_caller_extension_t *caller_extension)
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
#define switch_channel_set_flag(_c, _f)
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
void switch_channel_clear_flag_recursive(switch_channel_t *channel, switch_channel_flag_t flag)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session&#39;s pool.
Definition: switch_core.h:719
switch_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_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
#define switch_channel_set_variable(_channel, _var, _val)
#define switch_core_session_kill_channel(session, sig)
Send a signal to a channel.
Definition: switch_core.h:1393
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
#define SWITCH_READ_ACCEPTABLE(status)
switch_event_header_t * headers
Definition: switch_event.h:90
uint32_t switch_core_session_stack_count(switch_core_session_t *session, int x)

◆ switch_ivr_session_transfer()

switch_status_t switch_ivr_session_transfer ( switch_core_session_t session,
const char *  extension,
const char *  dialplan,
const char *  context 
)

Definition at line 2163 of file switch_ivr.c.

References CF_ORIGINATING, CF_REUSE_CALLER_PROFILE, CF_TRANSFER, switch_caller_profile::context, CS_ROUTING, switch_caller_profile::destination_number, switch_caller_profile::dialplan, switch_core_session_message::from, switch_core_session_message::message_id, switch_caller_profile::pool, switch_caller_profile::rdnis, SMF_NONE, SWITCH_BRIDGE_VARIABLE, switch_caller_profile_clone(), SWITCH_CAUSE_BLIND_TRANSFER, SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR, switch_channel_add_variable_var_check(), switch_channel_audio_sync, switch_channel_clear_flag(), switch_channel_clear_state_handler(), switch_channel_execute_on(), switch_channel_get_caller_profile(), switch_channel_get_name(), switch_channel_get_variable, switch_channel_hangup, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_caller_profile(), switch_channel_set_flag, switch_channel_set_state, switch_channel_set_variable, switch_channel_set_variable_var_check(), switch_channel_test_flag(), switch_core_session_get_channel(), switch_core_session_locate, switch_core_session_receive_message, switch_core_session_reset(), switch_core_session_rwunlock(), switch_core_session_sprintf(), switch_core_sprintf(), switch_core_strdup, switch_epoch_time_now(), SWITCH_FALSE, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, switch_ivr_check_hold(), switch_ivr_media(), SWITCH_LOG_NOTICE, switch_log_printf(), SWITCH_MAX_FORWARDS_VARIABLE, SWITCH_MAX_SESSION_TRANSFERS_VARIABLE, SWITCH_MESSAGE_INDICATE_TRANSFER, SWITCH_SIGNAL_BOND_VARIABLE, SWITCH_SIGNAL_BRIDGE_VARIABLE, SWITCH_STACK_PUSH, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, SWITCH_TEMP_HOLD_MUSIC_VARIABLE, SWITCH_TRANSFER_HISTORY_VARIABLE, SWITCH_TRANSFER_SOURCE_VARIABLE, SWITCH_TRUE, switch_caller_profile::transfer_source, switch_caller_profile::uuid_str, and zstr.

2165 {
2167  switch_caller_profile_t *profile, *new_profile;
2168  switch_core_session_message_t msg = { 0 };
2169  switch_core_session_t *other_session;
2170  switch_channel_t *other_channel = NULL;
2171  const char *uuid = NULL;
2172  const char *max_forwards;
2173  const char *forwardvar_name = SWITCH_MAX_SESSION_TRANSFERS_VARIABLE; /* max_session_transfers has first priority for setting maximum */
2174  const char *forwardvar = switch_channel_get_variable(channel, forwardvar_name);
2175  int forwardval = 70;
2176  const char *use_dialplan = dialplan, *use_context = context;
2177 
2178  if (zstr(forwardvar)) {
2179  forwardvar_name = SWITCH_MAX_FORWARDS_VARIABLE; /* fall back to max_forwards variable for setting maximum */
2180  forwardvar = switch_channel_get_variable(channel, forwardvar_name);
2181  }
2182  if (!zstr(forwardvar)) {
2183  forwardval = atoi(forwardvar) - 1;
2184  }
2185  if (forwardval <= 0) {
2187  return SWITCH_STATUS_FALSE;
2188  }
2189 
2190  switch_ivr_check_hold(session);
2191 
2192 
2193  max_forwards = switch_core_session_sprintf(session, "%d", forwardval);
2194  switch_channel_set_variable(channel, forwardvar_name, max_forwards);
2195 
2198 
2199  /* clear all state handlers */
2200  switch_channel_clear_state_handler(channel, NULL);
2201 
2202  /* reset temp hold music */
2204 
2205  switch_channel_execute_on(channel, "execute_on_blind_transfer");
2206 
2207  if ((profile = switch_channel_get_caller_profile(channel))) {
2208  const char *var;
2209 
2210  if (zstr(dialplan) && (var = switch_channel_get_variable(channel, "force_transfer_dialplan"))) {
2211  use_dialplan = var;
2212  }
2213 
2214  if (zstr(context) && (var = switch_channel_get_variable(channel, "force_transfer_context"))) {
2215  use_context = var;
2216  }
2217 
2218  if (zstr(use_dialplan)) {
2219  use_dialplan = profile->dialplan;
2220  if (!zstr(use_dialplan) && !strcasecmp(use_dialplan, "inline")) {
2221  use_dialplan = NULL;
2222  }
2223  }
2224 
2225  if (zstr(use_context)) {
2226  use_context = profile->context;
2227  }
2228 
2229  if (zstr(use_dialplan)) {
2230  use_dialplan = "XML";
2231  }
2232 
2233  if (zstr(use_context)) {
2234  use_context = "default";
2235  }
2236 
2237  if (zstr(extension)) {
2238  extension = "service";
2239  }
2240 
2241 
2243  new_profile = switch_channel_get_caller_profile(channel);
2244  } else {
2245  new_profile = switch_caller_profile_clone(session, profile);
2246  }
2247 
2248  new_profile->dialplan = switch_core_strdup(new_profile->pool, use_dialplan);
2249  new_profile->context = switch_core_strdup(new_profile->pool, use_context);
2250  new_profile->destination_number = switch_core_strdup(new_profile->pool, extension);
2251  new_profile->rdnis = switch_core_strdup(new_profile->pool, profile->destination_number);
2252 
2254 
2255  /* Set CF_TRANSFER flag before hanging up bleg to avoid race condition */
2257 
2258  /* If HANGUP_AFTER_BRIDGE is set to 'true', SWITCH_SIGNAL_BRIDGE_VARIABLE
2259  * will not have a value, so we need to check SWITCH_BRIDGE_VARIABLE */
2260 
2262 
2263  if (!uuid) {
2265  }
2266 
2267  if (uuid && (other_session = switch_core_session_locate(uuid))) {
2268  other_channel = switch_core_session_get_channel(other_session);
2270  switch_core_session_rwunlock(other_session);
2271  }
2272 
2274  && (other_session = switch_core_session_locate(uuid))) {
2275  other_channel = switch_core_session_get_channel(other_session);
2276 
2279 
2282 
2283  /* If we are transferring the CALLER out of the bridge, we do not want to hang up on them */
2285 
2287  switch_ivr_media(uuid, SMF_NONE);
2288 
2289  switch_core_session_rwunlock(other_session);
2290  }
2291 
2293  switch_channel_set_caller_profile(channel, new_profile);
2294  }
2295 
2297  switch_channel_audio_sync(channel);
2298 
2300  msg.from = __FILE__;
2301  switch_core_session_receive_message(session, &msg);
2302 
2303  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Transfer %s to %s[%s@%s]\n", switch_channel_get_name(channel), use_dialplan,
2304  extension, use_context);
2305 
2306 
2307  new_profile->transfer_source = switch_core_sprintf(new_profile->pool, "%ld:%s:bl_xfer:%s/%s/%s",
2308  (long) switch_epoch_time_now(NULL), new_profile->uuid_str,
2309  extension, use_context, use_dialplan);
2312  return SWITCH_STATUS_SUCCESS;
2313  }
2314 
2315  return SWITCH_STATUS_FALSE;
2316 }
#define SWITCH_SIGNAL_BRIDGE_VARIABLE
Definition: switch_types.h:202
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it&#39;s state machine to end.
switch_status_t switch_channel_execute_on(switch_channel_t *channel, const char *variable_prefix)
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 ...
#define SWITCH_CHANNEL_SESSION_LOG(x)
Call Specific Data.
Definition: switch_caller.h:73
switch_core_session_message_types_t message_id
Definition: switch_core.h:183
void switch_core_session_reset(_In_ switch_core_session_t *session, switch_bool_t flush_dtmf, switch_bool_t reset_read_codec)
Reset the buffers and resampler on a session.
#define switch_channel_set_state(channel, state)
Set the current state of a channel.
#define SWITCH_TRANSFER_SOURCE_VARIABLE
Definition: switch_types.h:145
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_caller_profile_t * switch_caller_profile_clone(_In_ switch_core_session_t *session, _In_ switch_caller_profile_t *tocopy)
Clone an existing caller profile object.
void switch_channel_set_caller_profile(switch_channel_t *channel, switch_caller_profile_t *caller_profile)
Set the given channel&#39;s caller profile.
const char * dialplan
Definition: switch_caller.h:77
switch_status_t switch_ivr_media(const char *uuid, switch_media_flag_t flags)
Signal a session to request direct media access to it&#39;s remote end.
Definition: switch_ivr.c:1773
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.
A message object designed to allow unlike technologies to exchange data.
Definition: switch_core.h:179
#define zstr(x)
Definition: switch_utils.h:314
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
#define SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE
Definition: switch_types.h:219
#define switch_channel_audio_sync(_c)
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)
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
#define switch_channel_get_variable(_c, _v)
#define SWITCH_BRIDGE_VARIABLE
Definition: switch_types.h:200
#define switch_core_session_receive_message(_session, _message)
Definition: switch_core.h:1247
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
switch_status_t switch_channel_set_variable_var_check(switch_channel_t *channel, const char *varname, const char *value, switch_bool_t var_check)
#define SWITCH_SIGNAL_BOND_VARIABLE
Definition: switch_types.h:203
#define switch_core_session_locate(uuid_str)
Locate a session based on it&#39;s uuid.
Definition: switch_core.h:932
#define SWITCH_TEMP_HOLD_MUSIC_VARIABLE
Definition: switch_types.h:194
#define switch_channel_set_flag(_c, _f)
#define SWITCH_TRANSFER_HISTORY_VARIABLE
Definition: switch_types.h:144
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:322
void switch_ivr_check_hold(switch_core_session_t *session)
Definition: switch_ivr.c:2143
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_MAX_SESSION_TRANSFERS_VARIABLE
Definition: switch_types.h:231
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
char * switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the pool ...
#define SWITCH_MAX_FORWARDS_VARIABLE
Definition: switch_types.h:226
#define switch_channel_set_variable(_channel, _var, _val)
switch_caller_profile_t * switch_channel_get_caller_profile(switch_channel_t *channel)
Retrieve the given channel&#39;s caller profile.
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_memory_pool_t * pool

◆ switch_ivr_set_json_call_stats()

void switch_ivr_set_json_call_stats ( cJSON json,
switch_core_session_t session,
switch_media_type_t  type 
)

Definition at line 3232 of file switch_ivr.c.

References add_jstat, switch_rtp_numbers_t::burstrate, switch_rtp_numbers_t::cng_packet_count, error_period::consecutive_flaws, switch_rtp_numbers_t::dtmf_packet_count, switch_rtp_numbers_t::error_log, error_period::flaws, switch_rtp_numbers_t::flaws, switch_rtp_numbers_t::flush_packet_count, switch_rtp_stats_t::inbound, switch_rtp_numbers_t::jb_packet_count, switch_rtp_numbers_t::largest_jb_size, switch_rtp_numbers_t::lossrate, switch_rtp_numbers_t::max_variance, switch_rtp_numbers_t::mean_interval, switch_rtp_numbers_t::media_bytes, switch_rtp_numbers_t::media_packet_count, switch_rtp_numbers_t::min_variance, switch_rtp_numbers_t::mos, name, error_period::next, switch_rtcp_numbers_t::octet_count, switch_rtp_stats_t::outbound, switch_rtp_numbers_t::packet_count, switch_rtcp_numbers_t::packet_count, switch_rtp_numbers_t::R, switch_rtp_numbers_t::raw_bytes, switch_rtp_stats_t::rtcp, switch_rtp_numbers_t::skip_packet_count, error_period::start, switch_rtp_numbers_t::std_deviation, error_period::stop, switch_core_media_get_stats(), SWITCH_MEDIA_TYPE_VIDEO, and switch_rtp_numbers_t::variance.

Referenced by switch_ivr_generate_json_cdr().

3233 {
3234  const char *name = (type == SWITCH_MEDIA_TYPE_VIDEO) ? "video" : "audio";
3235  cJSON *j_stat, *j_in, *j_out;
3236  switch_rtp_stats_t *stats = switch_core_media_get_stats(session, type, NULL);
3237  char var_val[35] = "";
3238 
3239  if (!stats) return;
3240 
3241  j_stat = cJSON_CreateObject();
3242  j_in = cJSON_CreateObject();
3243  j_out = cJSON_CreateObject();
3244 
3245  cJSON_AddItemToObject(json, name, j_stat);
3246  cJSON_AddItemToObject(j_stat, "inbound", j_in);
3247  cJSON_AddItemToObject(j_stat, "outbound", j_out);
3248 
3249  stats->inbound.std_deviation = sqrt(stats->inbound.variance);
3250 
3251  add_jstat(j_in, stats->inbound.raw_bytes, "raw_bytes");
3252  add_jstat(j_in, stats->inbound.media_bytes, "media_bytes");
3253  add_jstat(j_in, stats->inbound.packet_count, "packet_count");
3254  add_jstat(j_in, stats->inbound.media_packet_count, "media_packet_count");
3255  add_jstat(j_in, stats->inbound.skip_packet_count, "skip_packet_count");
3256  add_jstat(j_in, stats->inbound.jb_packet_count, "jitter_packet_count");
3257  add_jstat(j_in, stats->inbound.dtmf_packet_count, "dtmf_packet_count");
3258  add_jstat(j_in, stats->inbound.cng_packet_count, "cng_packet_count");
3259  add_jstat(j_in, stats->inbound.flush_packet_count, "flush_packet_count");
3260  add_jstat(j_in, stats->inbound.largest_jb_size, "largest_jb_size");
3261  add_jstat(j_in, stats->inbound.min_variance, "jitter_min_variance");
3262  add_jstat(j_in, stats->inbound.max_variance, "jitter_max_variance");
3263  add_jstat(j_in, stats->inbound.lossrate, "jitter_loss_rate");
3264  add_jstat(j_in, stats->inbound.burstrate, "jitter_burst_rate");
3265  add_jstat(j_in, stats->inbound.mean_interval, "mean_interval");
3266  add_jstat(j_in, stats->inbound.flaws, "flaw_total");
3267  add_jstat(j_in, stats->inbound.R, "quality_percentage");
3268  add_jstat(j_in, stats->inbound.mos, "mos");
3269 
3270 
3271  if (stats->inbound.error_log) {
3272  cJSON *j_err_log, *j_err;
3274 
3275  j_err_log = cJSON_CreateArray();
3276  cJSON_AddItemToObject(j_in, "errorLog", j_err_log);
3277 
3278  for(ep = stats->inbound.error_log; ep; ep = ep->next) {
3279 
3280  if (!(ep->start && ep->stop)) continue;
3281 
3282  j_err = cJSON_CreateObject();
3283 
3284  cJSON_AddItemToObject(j_err, "start", cJSON_CreateNumber(ep->start));
3285  cJSON_AddItemToObject(j_err, "stop", cJSON_CreateNumber(ep->stop));
3286  cJSON_AddItemToObject(j_err, "flaws", cJSON_CreateNumber(ep->flaws));
3287  cJSON_AddItemToObject(j_err, "consecutiveFlaws", cJSON_CreateNumber(ep->consecutive_flaws));
3288  cJSON_AddItemToObject(j_err, "durationMS", cJSON_CreateNumber((ep->stop - ep->start) / 1000));
3289  cJSON_AddItemToArray(j_err_log, j_err);
3290  }
3291  }
3292 
3293  add_jstat(j_out, stats->outbound.raw_bytes, "raw_bytes");
3294  add_jstat(j_out, stats->outbound.media_bytes, "media_bytes");
3295  add_jstat(j_out, stats->outbound.packet_count, "packet_count");
3296  add_jstat(j_out, stats->outbound.media_packet_count, "media_packet_count");
3297  add_jstat(j_out, stats->outbound.skip_packet_count, "skip_packet_count");
3298  add_jstat(j_out, stats->outbound.dtmf_packet_count, "dtmf_packet_count");
3299  add_jstat(j_out, stats->outbound.cng_packet_count, "cng_packet_count");
3300  add_jstat(j_out, stats->rtcp.packet_count, "rtcp_packet_count");
3301  add_jstat(j_out, stats->rtcp.octet_count, "rtcp_octet_count");
3302 }
switch_size_t flaws
Definition: switch_types.h:712
switch_rtp_numbers_t inbound
Definition: switch_types.h:760
switch_rtp_stats_t * switch_core_media_get_stats(switch_core_session_t *session, switch_media_type_t type, switch_memory_pool_t *pool)
switch_size_t largest_jb_size
Definition: switch_types.h:692
struct error_period * next
Definition: switch_types.h:677
switch_size_t media_bytes
Definition: switch_types.h:683
switch_size_t dtmf_packet_count
Definition: switch_types.h:689
uint32_t flaws
Definition: switch_types.h:675
switch_rtcp_numbers_t rtcp
Definition: switch_types.h:762
int64_t stop
Definition: switch_types.h:674
switch_size_t raw_bytes
Definition: switch_types.h:682
switch_rtp_numbers_t outbound
Definition: switch_types.h:761
uint32_t consecutive_flaws
Definition: switch_types.h:676
int64_t start
Definition: switch_types.h:673
switch_size_t packet_count
Definition: switch_types.h:684
switch_size_t jb_packet_count
Definition: switch_types.h:688
switch_size_t skip_packet_count
Definition: switch_types.h:687
struct error_period * error_log
Definition: switch_types.h:716
switch_size_t flush_packet_count
Definition: switch_types.h:691
switch_size_t media_packet_count
Definition: switch_types.h:686
const char *const name
Definition: switch_cJSON.h:250
switch_size_t cng_packet_count
Definition: switch_types.h:690
#define add_jstat(_j, _i, _s)
Definition: switch_ivr.c:3228

◆ switch_ivr_set_json_chan_vars()

static void switch_ivr_set_json_chan_vars ( cJSON json,
switch_channel_t channel,
switch_bool_t  urlencode 
)
static

Definition at line 3304 of file switch_ivr.c.

References memset(), switch_event_header::name, switch_event_header::next, switch_channel_variable_first(), switch_channel_variable_last(), switch_safe_free, switch_url_encode(), switch_event_header::value, and zstr.

Referenced by switch_ivr_generate_json_cdr().

3305 {
3307 
3308  if (!hi)
3309  return;
3310 
3311  for (; hi; hi = hi->next) {
3312  if (!zstr(hi->name) && !zstr(hi->value)) {
3313  char *data = hi->value;
3314  if (urlencode) {
3315  switch_size_t dlen = strlen(hi->value) * 3;
3316 
3317  if ((data = malloc(dlen))) {
3318  memset(data, 0, dlen);
3319  switch_url_encode(hi->value, data, dlen);
3320  }
3321  }
3322 
3323  cJSON_AddItemToObject(json, hi->name, cJSON_CreateString(data));
3324 
3325  if (data != hi->value) {
3326  switch_safe_free(data);
3327  }
3328  }
3329  }
3331 }
An event Header.
Definition: switch_event.h:65
char * switch_url_encode(const char *url, char *buf, size_t len)
switch_event_header_t * switch_channel_variable_first(switch_channel_t *channel)
Start iterating over the entries in the channel variable list.
#define zstr(x)
Definition: switch_utils.h:314
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
uintptr_t switch_size_t
struct switch_event_header * next
Definition: switch_event.h:76
void switch_channel_variable_last(switch_channel_t *channel)
Stop iterating over channel variables.
memset(buf, 0, buflen)

◆ switch_ivr_set_json_profile_data()

static void switch_ivr_set_json_profile_data ( cJSON json,
switch_caller_profile_t caller_profile 
)
static

Definition at line 3211 of file switch_ivr.c.

References switch_caller_profile::ani, switch_caller_profile::aniii, switch_caller_profile::caller_id_name, switch_caller_profile::caller_id_number, switch_caller_profile::chan_name, switch_caller_profile::context, switch_caller_profile::destination_number, switch_caller_profile::dialplan, switch_caller_profile::network_addr, switch_caller_profile::rdnis, switch_caller_profile::source, switch_caller_profile::username, and switch_caller_profile::uuid.

Referenced by switch_ivr_generate_json_cdr().

3212 {
3213  cJSON_AddItemToObject(json, "username", cJSON_CreateString((char *)caller_profile->username));
3214  cJSON_AddItemToObject(json, "dialplan", cJSON_CreateString((char *)caller_profile->dialplan));
3215  cJSON_AddItemToObject(json, "caller_id_name", cJSON_CreateString((char *)caller_profile->caller_id_name));
3216  cJSON_AddItemToObject(json, "ani", cJSON_CreateString((char *)caller_profile->ani));
3217  cJSON_AddItemToObject(json, "aniii", cJSON_CreateString((char *)caller_profile->aniii));
3218  cJSON_AddItemToObject(json, "caller_id_number", cJSON_CreateString((char *)caller_profile->caller_id_number));
3219  cJSON_AddItemToObject(json, "network_addr", cJSON_CreateString((char *)caller_profile->network_addr));
3220  cJSON_AddItemToObject(json, "rdnis", cJSON_CreateString((char *)caller_profile->rdnis));
3221  cJSON_AddItemToObject(json, "destination_number", cJSON_CreateString(caller_profile->destination_number));
3222  cJSON_AddItemToObject(json, "uuid", cJSON_CreateString(caller_profile->uuid));
3223  cJSON_AddItemToObject(json, "source", cJSON_CreateString((char *)caller_profile->source));
3224  cJSON_AddItemToObject(json, "context", cJSON_CreateString((char *)caller_profile->context));
3225  cJSON_AddItemToObject(json, "chan_name", cJSON_CreateString(caller_profile->chan_name));
3226 }
const char * network_addr
Definition: switch_caller.h:93
const char * dialplan
Definition: switch_caller.h:77
const char * username
Definition: switch_caller.h:75
const char * caller_id_name
Definition: switch_caller.h:79
const char * caller_id_number
Definition: switch_caller.h:81

◆ switch_ivr_set_xml_call_stats()

int switch_ivr_set_xml_call_stats ( switch_xml_t  xml,
switch_core_session_t session,
int  off,
switch_media_type_t  type 
)

Definition at line 2715 of file switch_ivr.c.

References add_stat, add_stat_double, switch_rtp_numbers_t::burstrate, switch_rtp_numbers_t::cng_packet_count, error_period::consecutive_flaws, switch_rtp_numbers_t::dtmf_packet_count, switch_rtp_numbers_t::error_log, error_period::flaws, switch_rtp_numbers_t::flaws, switch_rtp_numbers_t::flush_packet_count, switch_rtp_stats_t::inbound, switch_rtp_numbers_t::jb_packet_count, switch_rtp_numbers_t::largest_jb_size, switch_rtp_numbers_t::lossrate, switch_rtp_numbers_t::max_variance, switch_rtp_numbers_t::mean_interval, switch_rtp_numbers_t::media_bytes, switch_rtp_numbers_t::media_packet_count, switch_rtp_numbers_t::min_variance, switch_rtp_numbers_t::mos, name, error_period::next, switch_rtcp_numbers_t::octet_count, switch_rtp_stats_t::outbound, switch_rtp_numbers_t::packet_count, switch_rtcp_numbers_t::packet_count, switch_rtp_numbers_t::R, switch_rtp_numbers_t::raw_bytes, switch_rtp_stats_t::rtcp, switch_rtp_numbers_t::skip_packet_count, error_period::start, switch_rtp_numbers_t::std_deviation, error_period::stop, switch_core_get_variable(), switch_core_media_get_stats(), SWITCH_MEDIA_TYPE_VIDEO, switch_snprintf(), SWITCH_TIME_T_FMT, switch_true(), switch_xml_add_child_d(), switch_xml_set_txt_d(), and switch_rtp_numbers_t::variance.

Referenced by switch_ivr_generate_xml_cdr().

2716 {
2717  const char *name = (type == SWITCH_MEDIA_TYPE_VIDEO) ? "video" : "audio";
2718  switch_xml_t x_stat, x_in, x_out, x_tmp = NULL;
2719  int xoff = 0;
2720  int loff = 0;
2721  switch_rtp_stats_t *stats = switch_core_media_get_stats(session, type, NULL);
2722  char var_val[35] = "";
2723  switch_bool_t exclude_error_log_from_xml_cdr = switch_true(switch_core_get_variable("exclude_error_log_from_xml_cdr"));
2724 
2725  if (!stats) return off;
2726 
2727  if (!(x_stat = switch_xml_add_child_d(xml, name, off++))) {
2728  abort();
2729  }
2730 
2731  if (!(x_in = switch_xml_add_child_d(x_stat, "inbound", xoff++))) {
2732  abort();
2733  }
2734 
2735  if (!(x_out = switch_xml_add_child_d(x_stat, "outbound", xoff++))) {
2736  abort();
2737  }
2738 
2739  stats->inbound.std_deviation = sqrt(stats->inbound.variance);
2740 
2741  add_stat(x_in, stats->inbound.raw_bytes, "raw_bytes");
2742  add_stat(x_in, stats->inbound.media_bytes, "media_bytes");
2743  add_stat(x_in, stats->inbound.packet_count, "packet_count");
2744  add_stat(x_in, stats->inbound.media_packet_count, "media_packet_count");
2745  add_stat(x_in, stats->inbound.skip_packet_count, "skip_packet_count");
2746  add_stat(x_in, stats->inbound.jb_packet_count, "jitter_packet_count");
2747  add_stat(x_in, stats->inbound.dtmf_packet_count, "dtmf_packet_count");
2748  add_stat(x_in, stats->inbound.cng_packet_count, "cng_packet_count");
2749  add_stat(x_in, stats->inbound.flush_packet_count, "flush_packet_count");
2750  add_stat(x_in, stats->inbound.largest_jb_size, "largest_jb_size");
2751  add_stat_double(x_in, stats->inbound.min_variance, "jitter_min_variance");
2752  add_stat_double(x_in, stats->inbound.max_variance, "jitter_max_variance");
2753  add_stat_double(x_in, stats->inbound.lossrate, "jitter_loss_rate");
2754  add_stat_double(x_in, stats->inbound.burstrate, "jitter_burst_rate");
2755  add_stat_double(x_in, stats->inbound.mean_interval, "mean_interval");
2756  add_stat(x_in, stats->inbound.flaws, "flaw_total");
2757  add_stat_double(x_in, stats->inbound.R, "quality_percentage");
2758  add_stat_double(x_in, stats->inbound.mos, "mos");
2759 
2760 
2761  if (stats->inbound.error_log && !exclude_error_log_from_xml_cdr) {
2762  switch_xml_t x_err_log, x_err;
2764  int eoff = 0;
2765 
2766  if (!(x_err_log = switch_xml_add_child_d(x_stat, "error-log", xoff++))) {
2767  abort();
2768  }
2769 
2770  for(ep = stats->inbound.error_log; ep; ep = ep->next) {
2771 
2772  if (!(ep->start && ep->stop)) continue;
2773 
2774  if (!(x_err = switch_xml_add_child_d(x_err_log, "error-period", eoff++))) {
2775  abort();
2776  }
2777 
2778  switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_TIME_T_FMT, ep->start);
2779  x_tmp = switch_xml_add_child_d(x_err, "start", 0);
2780  switch_xml_set_txt_d(x_tmp, var_val);
2781 
2782  switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_TIME_T_FMT, ep->stop);
2783  x_tmp = switch_xml_add_child_d(x_err, "stop", 1);
2784  switch_xml_set_txt_d(x_tmp, var_val);
2785 
2786  switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_TIME_T_FMT, ep->flaws);
2787  x_tmp = switch_xml_add_child_d(x_err, "flaws", 2);
2788  switch_xml_set_txt_d(x_tmp, var_val);
2789 
2790  switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_TIME_T_FMT, ep->consecutive_flaws);
2791  x_tmp = switch_xml_add_child_d(x_err, "consecutive-flaws", 3);
2792  switch_xml_set_txt_d(x_tmp, var_val);
2793 
2794  switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_TIME_T_FMT, (ep->stop - ep->start) / 1000);
2795  x_tmp = switch_xml_add_child_d(x_err, "duration-msec", 4);
2796  switch_xml_set_txt_d(x_tmp, var_val);
2797  }
2798  }
2799 
2800  loff=0;
2801  add_stat(x_out, stats->outbound.raw_bytes, "raw_bytes");
2802  add_stat(x_out, stats->outbound.media_bytes, "media_bytes");
2803  add_stat(x_out, stats->outbound.packet_count, "packet_count");
2804  add_stat(x_out, stats->outbound.media_packet_count, "media_packet_count");
2805  add_stat(x_out, stats->outbound.skip_packet_count, "skip_packet_count");
2806  add_stat(x_out, stats->outbound.dtmf_packet_count, "dtmf_packet_count");
2807  add_stat(x_out, stats->outbound.cng_packet_count, "cng_packet_count");
2808  add_stat(x_out, stats->rtcp.packet_count, "rtcp_packet_count");
2809  add_stat(x_out, stats->rtcp.octet_count, "rtcp_octet_count");
2810 
2811  return off;
2812 }
switch_xml_t switch_xml_add_child_d(_In_ switch_xml_t xml, _In_z_ const char *name, _In_ switch_size_t off)
wrapper for switch_xml_add_child() that strdup()s name
switch_size_t flaws
Definition: switch_types.h:712
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
switch_rtp_numbers_t inbound
Definition: switch_types.h:760
switch_rtp_stats_t * switch_core_media_get_stats(switch_core_session_t *session, switch_media_type_t type, switch_memory_pool_t *pool)
switch_bool_t
Definition: switch_types.h:437
switch_size_t largest_jb_size
Definition: switch_types.h:692
struct error_period * next
Definition: switch_types.h:677
A representation of an XML tree.
Definition: switch_xml.h:79
switch_size_t media_bytes
Definition: switch_types.h:683
switch_xml_t switch_xml_set_txt_d(switch_xml_t xml, const char *txt)
wrapper for switch_xml_set_txt() that strdup()s txt \ sets the character content for the given tag an...
Definition: switch_xml.c:3005
switch_size_t dtmf_packet_count
Definition: switch_types.h:689
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
uint32_t flaws
Definition: switch_types.h:675
switch_rtcp_numbers_t rtcp
Definition: switch_types.h:762
int64_t stop
Definition: switch_types.h:674
switch_size_t raw_bytes
Definition: switch_types.h:682
#define add_stat(_x, _i, _s)
Definition: switch_ivr.c:2705
switch_rtp_numbers_t outbound
Definition: switch_types.h:761
#define SWITCH_TIME_T_FMT
uint32_t consecutive_flaws
Definition: switch_types.h:676
int64_t start
Definition: switch_types.h:673
char * switch_core_get_variable(_In_z_ const char *varname)
Retrieve a global variable from the core.
switch_size_t packet_count
Definition: switch_types.h:684
#define add_stat_double(_x, _i, _s)
Definition: switch_ivr.c:2710
switch_size_t jb_packet_count
Definition: switch_types.h:688
switch_size_t skip_packet_count
Definition: switch_types.h:687
struct error_period * error_log
Definition: switch_types.h:716
switch_size_t flush_packet_count
Definition: switch_types.h:691
switch_size_t media_packet_count
Definition: switch_types.h:686
const char *const name
Definition: switch_cJSON.h:250
switch_size_t cng_packet_count
Definition: switch_types.h:690

◆ switch_ivr_set_xml_chan_var()

static int switch_ivr_set_xml_chan_var ( switch_xml_t  xml,
const char *  var,
const char *  val,
int  off 
)
static

Definition at line 2814 of file switch_ivr.c.

References memset(), switch_url_encode(), switch_xml_add_child_d(), switch_xml_set_txt_d(), and zstr.

Referenced by switch_ivr_set_xml_chan_vars().

2815 {
2816  char *data;
2817  switch_size_t dlen;
2818  switch_xml_t variable;
2819 
2820  if (!val) val = "";
2821 
2822  dlen = strlen(val) * 3 + 1;
2823 
2824  if (!zstr(var) && ((variable = switch_xml_add_child_d(xml, var, off++)))) {
2825  if ((data = malloc(dlen))) {
2826  memset(data, 0, dlen);
2827  switch_url_encode(val, data, dlen);
2828  switch_xml_set_txt_d(variable, data);
2829  free(data);
2830  } else abort();
2831  }
2832 
2833  return off;
2834 
2835 }
switch_xml_t switch_xml_add_child_d(_In_ switch_xml_t xml, _In_z_ const char *name, _In_ switch_size_t off)
wrapper for switch_xml_add_child() that strdup()s name
A representation of an XML tree.
Definition: switch_xml.h:79
char * switch_url_encode(const char *url, char *buf, size_t len)
switch_xml_t switch_xml_set_txt_d(switch_xml_t xml, const char *txt)
wrapper for switch_xml_set_txt() that strdup()s txt \ sets the character content for the given tag an...
Definition: switch_xml.c:3005
#define zstr(x)
Definition: switch_utils.h:314
uintptr_t switch_size_t
memset(buf, 0, buflen)

◆ unicast_thread_launch()

static void unicast_thread_launch ( switch_unicast_conninfo_t conninfo)
static

Definition at line 361 of file switch_ivr.c.

References switch_unicast_conninfo::session, SUF_THREAD_RUNNING, switch_core_session_get_pool(), switch_set_flag_locked, switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_stacksize_set(), switch_unicast_conninfo::thread, and unicast_thread_run().

Referenced by switch_ivr_park().

362 {
363  switch_threadattr_t *thd_attr = NULL;
364 
368  switch_thread_create(&conninfo->thread, thd_attr, unicast_thread_run, conninfo, switch_core_session_get_pool(conninfo->session));
369 }
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:683
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:584
#define switch_set_flag_locked(obj, flag)
Set a flag on an arbitrary object while locked.
Definition: switch_utils.h:707
switch_thread_t * thread
Definition: switch_ivr.h:64
switch_core_session_t * session
Definition: switch_ivr.h:48
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:665
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:698
switch_memory_pool_t * switch_core_session_get_pool(_In_ switch_core_session_t *session)
Retrieve the memory pool from a session.
static void *SWITCH_THREAD_FUNC unicast_thread_run(switch_thread_t *thread, void *obj)
Definition: switch_ivr.c:336

◆ unicast_thread_run()

static void* SWITCH_THREAD_FUNC unicast_thread_run ( switch_thread_t thread,
void *  obj 
)
static

Definition at line 336 of file switch_ivr.c.

References switch_frame::buflen, switch_frame::data, switch_frame::datalen, switch_frame::samples, switch_unicast_conninfo::session, switch_unicast_conninfo::socket, switch_unicast_conninfo::stream_id, SUF_READY, SUF_THREAD_RUNNING, switch_clear_flag_locked, switch_core_session_write_frame(), SWITCH_IO_FLAG_NONE, switch_socket_recv(), SWITCH_STATUS_SUCCESS, switch_test_flag, and switch_unicast_conninfo::write_frame.

Referenced by unicast_thread_launch().

337 {
339  switch_size_t len;
340 
341  if (!conninfo) {
342  return NULL;
343  }
344 
345  while (switch_test_flag(conninfo, SUF_READY) && switch_test_flag(conninfo, SUF_THREAD_RUNNING)) {
346  len = conninfo->write_frame.buflen;
347  if (switch_socket_recv(conninfo->socket, conninfo->write_frame.data, &len) != SWITCH_STATUS_SUCCESS || len == 0) {
348  break;
349  }
350  conninfo->write_frame.datalen = (uint32_t) len;
351  conninfo->write_frame.samples = conninfo->write_frame.datalen / 2;
353  }
354 
357 
358  return NULL;
359 }
switch_socket_t * socket
Definition: switch_ivr.h:52
switch_status_t switch_socket_recv(switch_socket_t *sock, char *buf, switch_size_t *len)
Definition: switch_apr.c:805
switch_status_t switch_core_session_write_frame(_In_ switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
Write a frame to a session.
uint32_t buflen
Definition: switch_frame.h:70
uint32_t datalen
Definition: switch_frame.h:68
uintptr_t switch_size_t
switch_frame_t write_frame
Definition: switch_ivr.h:50
#define switch_clear_flag_locked(obj, flag)
Clear a flag on an arbitrary object.
Definition: switch_utils.h:717
uint32_t samples
Definition: switch_frame.h:72
switch_core_session_t * session
Definition: switch_ivr.h:48
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693