RTS API Documentation  1.10.11
switch_ivr.c
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Anthony Minessale II <anthm@freeswitch.org>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Anthony Minessale II <anthm@freeswitch.org>
27  * Paul D. Tinsley <pdt at jackhammer.org>
28  * Neal Horman <neal at wanlink dot com>
29  * Matt Klein <mklein@nmedia.net>
30  * Michael Jerris <mike@jerris.com>
31  * Ken Rice <krice at suspicious dot org>
32  * Marc Olivier Chouinard <mochouinard@moctel.com>
33  *
34  * switch_ivr.c -- IVR Library
35  *
36  */
37 
38 #include <switch.h>
39 #include <switch_ivr.h>
40 
42 {
43 
45  switch_codec_t codec = { 0 };
46  int16_t peak = 0;
47  int16_t *data;
48  switch_frame_t *read_frame = NULL;
49  uint32_t i;
52  int64_t global_total = 0, global_sum = 0, period_sum = 0;
53  int period_total = 0;
54  int period_avg = 0, global_avg = 0;
55  int avg = 0;
56  int period_len;
57 
58  switch_core_session_get_read_impl(session, &imp);
59 
60  period_len = imp.actual_samples_per_second / imp.samples_per_packet;
61 
62  if (switch_core_codec_init(&codec,
63  "L16",
64  NULL,
65  NULL,
67  imp.microseconds_per_packet / 1000,
71  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
73  return SWITCH_STATUS_FALSE;
74  }
75 
76  while (switch_channel_ready(channel)) {
77  status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
78 
79  if (!SWITCH_READ_ACCEPTABLE(status)) {
80  break;
81  }
82 
83  if (switch_test_flag(read_frame, SFF_CNG) || !read_frame->samples) {
84  continue;
85  }
86 
87 
88  data = (int16_t *) read_frame->data;
89  peak = 0;
90  avg = 0;
91  for (i = 0; i < read_frame->samples; i++) {
92  const int16_t s = (int16_t) abs(data[i]);
93  if (s > peak) {
94  peak = s;
95  }
96  avg += s;
97  }
98 
99  avg /= read_frame->samples;
100 
101  period_sum += peak;
102  global_sum += peak;
103 
104  global_total++;
105  period_total++;
106 
107  period_avg = (int) (period_sum / period_total);
108 
110  "\npacket_avg=%d packet_peak=%d period_avg=%d global_avg=%d\n\n", avg, peak, period_avg, global_avg);
111 
112  if (period_total >= period_len) {
113  global_avg = (int) (global_sum / global_total);
114  period_total = 0;
115  period_sum = 0;
116  }
117 
118  }
119 
120 
122 
123  return SWITCH_STATUS_SUCCESS;
124 
125 }
126 
128 {
131  switch_time_t start = switch_micro_time_now(), now, done = switch_micro_time_now() + (ms * 1000);
132  switch_frame_t *read_frame, cng_frame = { 0 };
133  int32_t left;
134  uint32_t elapsed;
135  char data[2] = "";
136 
137  switch_frame_t write_frame = { 0 };
138  unsigned char *abuf = NULL;
139  switch_codec_implementation_t imp = { 0 };
140  switch_codec_t codec = { 0 };
141  int sval = 0;
142  const char *var;
143 
145 
147 
148  switch_core_session_get_read_impl(session, &imp);
149 
150  /*
151  if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND && !switch_channel_test_flag(channel, CF_PROXY_MODE) &&
152  !switch_channel_media_ready(channel) && !switch_channel_test_flag(channel, CF_SERVICE)) {
153  if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
154  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot establish media.\n");
155  return SWITCH_STATUS_FALSE;
156  }
157  }
158  */
159 
160  if (!switch_channel_media_ready(channel)) {
161 
162  for (elapsed=0; switch_channel_ready(channel) && elapsed<(ms/20); elapsed++) {
163  if (switch_channel_test_flag(channel, CF_BREAK)) {
166  }
167 
168  switch_yield(20 * 1000);
169  }
171  }
172 
174  && (sval = atoi(var))) {
176  }
177 
178  if (ms > 10 && sval) {
179 
180  if (switch_core_codec_init(&codec,
181  "L16",
182  NULL,
183  NULL,
185  imp.microseconds_per_packet / 1000,
186  imp.number_of_channels,
189  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
192  }
193 
194 
195  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n",
197 
198  write_frame.codec = &codec;
200  write_frame.data = abuf;
202  write_frame.datalen = imp.decoded_bytes_per_packet;
203  write_frame.samples = write_frame.datalen / sizeof(int16_t);
204 
205  }
206 
207  if (!write_frame.datalen) {
208  sval = 0;
209  }
210 
211  cng_frame.data = data;
212  cng_frame.datalen = 2;
213  cng_frame.buflen = 2;
214  switch_set_flag((&cng_frame), SFF_CNG);
215 
216  if (sync) {
217  switch_channel_audio_sync(channel);
218  }
219 
220  if (!ms) {
222  }
223 
224  for (;;) {
225  now = switch_micro_time_now();
226  elapsed = (int32_t) ((now - start) / 1000);
227  left = ms - elapsed;
228 
229  if (!switch_channel_ready(channel)) {
230  status = SWITCH_STATUS_FALSE;
231  break;
232  }
233 
234  if (switch_channel_test_flag(channel, CF_BREAK)) {
236  status = SWITCH_STATUS_BREAK;
237  break;
238  }
239 
240  if (now > done || left <= 0) {
241  break;
242  }
243 
244 
246 
247 
248  if (args) {
249  switch_dtmf_t dtmf = {0};
250 
251  /*
252  dtmf handler function you can hook up to be executed when a digit is dialed during playback
253  if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
254  */
255  if (switch_channel_has_dtmf(channel)) {
256  if (!args->input_callback && !args->buf && !args->dmachine) {
257  status = SWITCH_STATUS_BREAK;
258  break;
259  }
260  switch_channel_dequeue_dtmf(channel, &dtmf);
261 
262  if (args->dmachine) {
263  char ds[2] = {dtmf.digit, '\0'};
264  if ((status = switch_ivr_dmachine_feed(args->dmachine, ds, NULL)) != SWITCH_STATUS_SUCCESS) {
265  break;
266  }
267  }
268 
269  if (args->input_callback) {
270  status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen);
271  } else if (args->buf) {
272  *((char *) args->buf) = dtmf.digit;
273  status = SWITCH_STATUS_BREAK;
274  }
275  }
276 
277  if (args->input_callback) {
278  switch_event_t *event = NULL;
279 
281  switch_status_t ostatus = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen);
282  if (ostatus != SWITCH_STATUS_SUCCESS) {
283  status = ostatus;
284  }
285  switch_event_destroy(&event);
286  }
287  }
288 
289  if (status != SWITCH_STATUS_SUCCESS) {
290  break;
291  }
292  }
293 
294  status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
295 
296  if (!SWITCH_READ_ACCEPTABLE(status)) {
297  break;
298  }
299 
300  if (args && args->dmachine) {
301  if ((status = switch_ivr_dmachine_ping(args->dmachine, NULL)) != SWITCH_STATUS_SUCCESS) {
302  break;
303  }
304  }
305 
306  if (read_frame && args && (args->read_frame_callback)) {
307  if ((status = args->read_frame_callback(session, read_frame, args->user_data)) != SWITCH_STATUS_SUCCESS) {
308  break;
309  }
310  }
311 
312  if (sval && write_frame.datalen) {
313  switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, imp.number_of_channels, sval);
314  switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
315  } else {
316  switch_core_session_write_frame(session, &cng_frame, SWITCH_IO_FLAG_NONE, 0);
317  }
318  }
319 
320 
321  end:
322 
324 
326 
327  if (write_frame.codec) {
329  }
330 
331  switch_safe_free(abuf);
332 
333  return status;
334 }
335 
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 }
360 
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 }
370 
372 {
374  switch_unicast_conninfo_t *conninfo;
375  int sanity = 0;
376 
377  if (!switch_channel_test_flag(channel, CF_UNICAST)) {
378  return SWITCH_STATUS_FALSE;
379  }
380 
381  if ((conninfo = switch_channel_get_private(channel, "unicast"))) {
382  switch_status_t st;
383 
384  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Shutting down unicast connection\n");
387  switch_thread_join(&st, conninfo->thread);
388 
389  while (switch_test_flag(conninfo, SUF_THREAD_RUNNING)) {
390  switch_yield(10000);
391  if (++sanity >= 10000) {
392  break;
393  }
394  }
395  if (switch_core_codec_ready(&conninfo->read_codec)) {
397  }
398  switch_socket_close(conninfo->socket);
399  }
401  return SWITCH_STATUS_SUCCESS;
402 }
403 
405  char *local_ip,
406  switch_port_t local_port,
407  char *remote_ip, switch_port_t remote_port, char *transport, char *flags)
408 {
410  switch_unicast_conninfo_t *conninfo = switch_core_session_alloc(session, sizeof(*conninfo));
411  switch_codec_t *read_codec;
412 
413  switch_assert(conninfo != NULL);
414 
415  conninfo->local_ip = switch_core_session_strdup(session, local_ip);
416  conninfo->local_port = local_port;
417 
418  conninfo->remote_ip = switch_core_session_strdup(session, remote_ip);
419  conninfo->remote_port = remote_port;
420  conninfo->session = session;
421 
422  if (!strcasecmp(transport, "udp")) {
423  conninfo->type = AF_INET;
424  conninfo->transport = SOCK_DGRAM;
425  } else if (!strcasecmp(transport, "tcp")) {
426  conninfo->type = AF_INET;
427  conninfo->transport = SOCK_STREAM;
428  } else {
429  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid transport %s\n", transport);
430  goto fail;
431  }
432 
433  if (flags) {
434  if (strstr(flags, "native")) {
435  switch_set_flag(conninfo, SUF_NATIVE);
436  }
437  }
438 
440 
441  read_codec = switch_core_session_get_read_codec(session);
442 
443  if (!switch_test_flag(conninfo, SUF_NATIVE)) {
444  if (switch_core_codec_init(&conninfo->read_codec,
445  "L16",
446  NULL,
447  NULL,
449  read_codec->implementation->microseconds_per_packet / 1000,
453  "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
455  } else {
456  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
458  goto fail;
459  }
460  }
461 
462  conninfo->write_frame.data = conninfo->write_frame_data;
463  conninfo->write_frame.buflen = sizeof(conninfo->write_frame_data);
464  conninfo->write_frame.codec = switch_test_flag(conninfo, SUF_NATIVE) ? read_codec : &conninfo->read_codec;
465 
466  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "connect %s:%d->%s:%d\n",
467  conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port);
468 
469  if (switch_sockaddr_info_get(&conninfo->local_addr,
470  conninfo->local_ip, SWITCH_UNSPEC, conninfo->local_port, 0,
472  goto fail;
473  }
474 
475  if (switch_sockaddr_info_get(&conninfo->remote_addr,
476  conninfo->remote_ip, SWITCH_UNSPEC, conninfo->remote_port, 0,
478  goto fail;
479  }
480 
481  if (switch_socket_create(&conninfo->socket, AF_INET, SOCK_DGRAM, 0, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
482  if (switch_socket_bind(conninfo->socket, conninfo->local_addr) != SWITCH_STATUS_SUCCESS) {
483  goto fail;
484  }
485  } else {
486  goto fail;
487  }
488 
489  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Created unicast connection %s:%d->%s:%d\n",
490  conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port);
491  switch_channel_set_private(channel, "unicast", conninfo);
494  return SWITCH_STATUS_SUCCESS;
495 
496  fail:
497 
498  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Failure creating unicast connection %s:%d->%s:%d\n",
499  conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port);
500  return SWITCH_STATUS_FALSE;
501 }
502 
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 }
795 
797 {
798  switch_event_t *event;
800 
802  status = switch_ivr_parse_event(session, event);
803  event->event_id = SWITCH_EVENT_PRIVATE_COMMAND;
806  switch_event_fire(&event);
807  }
808 
809  return status;
810 
811 }
812 
814 {
817 
818  switch(message->message_id) {
822  }
823  break;
827  }
828  break;
832  }
833  break;
835  switch_core_session_receive_message(session, message);
836  status = SWITCH_STATUS_SUCCESS;
837  break;
838 
839  default:
840  status = SWITCH_STATUS_FALSE;
841  break;
842  }
843 
844  return status;
845 }
846 
848 {
850  int i = 0;
851 
853 
854  while (switch_core_session_dequeue_message(session, &message) == SWITCH_STATUS_SUCCESS) {
855  i++;
856 
857  if (switch_ivr_process_indications(session, message) == SWITCH_STATUS_SUCCESS) {
859  } else {
860  switch_core_session_receive_message(session, message);
861  message = NULL;
862  }
863  }
864 
866 }
867 
868 
870 {
871  void *data;
872  switch_core_session_message_t msg = { 0 };
873  int i = 0;
875 
876  if (only_session_thread && !switch_core_session_in_thread(session)) {
877  return SWITCH_STATUS_FALSE;
878  }
879 
881  return SWITCH_STATUS_FALSE;
882  }
883 
885 
887  msg.from = __FILE__;
888 
890  i++;
891 
892  msg.pointer_arg = data;
894 
895  data = NULL;
896  if (!all)
897  break;
898  }
899 
901 
903 }
904 
907 }
908 
911 }
912 
914 {
915  switch_channel_t *channel;
916  uint32_t stack_count = 0;
917  if ((stack_count = switch_core_session_stack_count(session, 0)) > SWITCH_MAX_STACKS) {
918  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error %s too many stacked extensions [depth=%d]\n",
919  switch_core_session_get_name(session), stack_count);
920  return SWITCH_STATUS_FALSE;
921  }
922 
924 
926 
927  channel = switch_core_session_get_channel(session);
928 
930  if (switch_channel_media_up(channel)) {
932  } else {
933  goto done;
934  }
935  }
936 
938 
939  done:
940  switch_core_session_stack_count(session, -1);
941 
942  return SWITCH_STATUS_SUCCESS;
943 }
944 
945 
947 {
950  switch_frame_t *read_frame = NULL;
951  int stream_id = 0;
952  switch_event_t *event;
953  switch_unicast_conninfo_t *conninfo = NULL;
954  uint32_t rate = 0;
955  uint32_t bpf = 0;
956  const char *to;
957  int timeout = 0;
958  time_t expires = 0;
959  switch_codec_implementation_t read_impl = { 0 };
961  switch_codec_t codec = { 0 };
962  int sval = 0;
963  const char *var;
964  switch_frame_t write_frame = { 0 };
965  unsigned char *abuf = NULL;
966  switch_codec_implementation_t imp = { 0 };
967 
968 
969 
972  }
973 
974  if (switch_channel_test_flag(channel, CF_CONTROLLED)) {
975  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot park channels that are under control already.\n");
976  return SWITCH_STATUS_FALSE;
977  }
978 
979  if (switch_channel_get_state(channel) == CS_RESET) {
980  return SWITCH_STATUS_FALSE;
981  }
982 
984 
985  if ((to = switch_channel_get_variable(channel, "park_timeout"))) {
986  char *cause_str;
987 
988  if ((cause_str = strchr(to, ':'))) {
989  timeout_cause = switch_channel_str2cause(cause_str + 1);
990  }
991 
992  if ((timeout = atoi(to)) >= 0) {
993  expires = switch_epoch_time_now(NULL) + timeout;
994  }
995  switch_channel_set_variable(channel, "park_timeout", NULL);
997  }
998 
1000  switch_channel_set_flag(channel, CF_PARK);
1001 
1003  switch_channel_event_set_data(channel, event);
1004  switch_event_fire(&event);
1005  }
1006 
1008 
1009  if (!rate && switch_channel_media_ready(channel)) {
1010  switch_core_session_get_read_impl(session, &read_impl);
1011  rate = read_impl.actual_samples_per_second;
1012  bpf = read_impl.decoded_bytes_per_packet;
1013 
1014  if (rate && (var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
1015  switch_core_session_get_read_impl(session, &imp);
1016 
1017  if (switch_core_codec_init(&codec,
1018  "L16",
1019  NULL,
1020  NULL,
1022  imp.microseconds_per_packet / 1000,
1023  imp.number_of_channels,
1026  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
1029  }
1030 
1031 
1032  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n",
1034 
1035  write_frame.codec = &codec;
1037  write_frame.data = abuf;
1038  write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
1039  write_frame.datalen = imp.decoded_bytes_per_packet;
1040  write_frame.samples = write_frame.datalen / sizeof(int16_t);
1041  }
1042  }
1043 
1044  if (rate) {
1045  if (switch_channel_test_flag(channel, CF_SERVICE)) {
1046  switch_cond_next();
1047  status = SWITCH_STATUS_SUCCESS;
1048  } else {
1049  status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, stream_id);
1050  }
1051  } else {
1052  switch_yield(20000);
1053 
1055  switch_ivr_parse_event(session, event);
1056  switch_event_destroy(&event);
1057  }
1058 
1059  status = SWITCH_STATUS_SUCCESS;
1060  }
1061 
1062  if (!SWITCH_READ_ACCEPTABLE(status)) {
1063  break;
1064  }
1065 
1066  if (rate && write_frame.data && sval) {
1067  switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, read_impl.number_of_channels, sval);
1068  switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
1069  }
1070 
1071  if (expires && switch_epoch_time_now(NULL) >= expires) {
1072  switch_channel_hangup(channel, timeout_cause);
1073  break;
1074  }
1075 
1076  if (switch_channel_test_flag(channel, CF_UNICAST)) {
1077  if (!switch_channel_media_ready(channel)) {
1080  }
1081  }
1082 
1083  if (!conninfo) {
1084  if (!(conninfo = switch_channel_get_private(channel, "unicast"))) {
1086  }
1087 
1088  if (conninfo) {
1089  unicast_thread_launch(conninfo);
1090  }
1091  }
1092 
1093  if (conninfo) {
1094  switch_size_t len = 0;
1095  uint32_t flags = 0;
1097  uint32_t dlen = sizeof(decoded);
1098  switch_status_t tstatus;
1099  switch_byte_t *sendbuf = NULL;
1100  uint32_t sendlen = 0;
1101 
1102  switch_assert(read_frame);
1103 
1104  if (switch_test_flag(read_frame, SFF_CNG)) {
1105  sendlen = bpf;
1107  memset(decoded, 255, sendlen);
1108  sendbuf = decoded;
1109  tstatus = SWITCH_STATUS_SUCCESS;
1110  } else {
1111  if (switch_test_flag(conninfo, SUF_NATIVE)) {
1112  tstatus = SWITCH_STATUS_NOOP;
1113  } else {
1114  switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
1115  tstatus = switch_core_codec_decode(read_codec,
1116  &conninfo->read_codec,
1117  read_frame->data,
1118  read_frame->datalen, read_impl.actual_samples_per_second, decoded, &dlen, &rate, &flags);
1119  }
1120  switch (tstatus) {
1121  case SWITCH_STATUS_NOOP:
1122  case SWITCH_STATUS_BREAK:
1123  sendbuf = read_frame->data;
1124  sendlen = read_frame->datalen;
1125  tstatus = SWITCH_STATUS_SUCCESS;
1126  break;
1127  case SWITCH_STATUS_SUCCESS:
1128  sendbuf = decoded;
1129  sendlen = dlen;
1130  tstatus = SWITCH_STATUS_SUCCESS;
1131  break;
1132  default:
1135  break;
1136  }
1137  }
1138 
1139  if (tstatus == SWITCH_STATUS_SUCCESS) {
1140  len = sendlen;
1141  if (switch_socket_sendto(conninfo->socket, conninfo->remote_addr, 0, (void *) sendbuf, &len) != SWITCH_STATUS_SUCCESS) {
1143  }
1144  }
1145  }
1146  }
1147 
1148  switch_ivr_parse_all_events(session);
1149 
1150 
1151  if (switch_channel_has_dtmf(channel)) {
1152  switch_dtmf_t dtmf = { 0 };
1153 
1154  if (args && !args->input_callback && !args->buf && !args->dmachine) {
1155  status = SWITCH_STATUS_BREAK;
1156  break;
1157  }
1158 
1159  switch_channel_dequeue_dtmf(channel, &dtmf);
1160 
1161  if (args) {
1162  if (args->dmachine) {
1163  char ds[2] = {dtmf.digit, '\0'};
1164  if ((status = switch_ivr_dmachine_feed(args->dmachine, ds, NULL)) != SWITCH_STATUS_SUCCESS) {
1165  break;
1166  }
1167  }
1168 
1169  if (args->input_callback) {
1170  if ((status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen)) != SWITCH_STATUS_SUCCESS) {
1171  break;
1172  }
1173  }
1174  }
1175  }
1176 
1178  if (args && args->input_callback) {
1179  switch_status_t ostatus;
1180 
1181  if ((ostatus = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen)) != SWITCH_STATUS_SUCCESS) {
1182  status = ostatus;
1183  break;
1184  }
1185  } else {
1186  switch_channel_event_set_data(channel, event);
1187  switch_event_fire(&event);
1188  }
1189  }
1190 
1191  if (args && args->dmachine) {
1192  if ((status = switch_ivr_dmachine_ping(args->dmachine, NULL)) != SWITCH_STATUS_SUCCESS) {
1193  break;
1194  }
1195  }
1196 
1197 
1198  }
1199 
1200  end:
1201 
1203 
1204  if (write_frame.codec) {
1205  switch_core_codec_destroy(&codec);
1206  }
1207 
1208  switch_safe_free(abuf);
1209 
1212 
1214  switch_channel_event_set_data(channel, event);
1215  switch_event_fire(&event);
1216  }
1217 
1218  if (switch_channel_test_flag(channel, CF_UNICAST)) {
1220  }
1221 
1222  return status;
1223 }
1224 
1226  uint32_t abs_timeout)
1227 {
1230  switch_time_t abs_started = 0, digit_started = 0;
1231  uint32_t abs_elapsed = 0, digit_elapsed = 0;
1232 
1233  if (!args) {
1234  return SWITCH_STATUS_GENERR;
1235  }
1236 
1238 
1239  if (abs_timeout) {
1240  abs_started = switch_micro_time_now();
1241  }
1242  if (digit_timeout) {
1243  digit_started = switch_micro_time_now();
1244  }
1245 
1246  while (switch_channel_ready(channel)) {
1247  switch_frame_t *read_frame = NULL;
1248  switch_event_t *event;
1249  switch_dtmf_t dtmf = { 0 };
1250 
1251  if (switch_channel_test_flag(channel, CF_BREAK)) {
1253  status = SWITCH_STATUS_BREAK;
1254  break;
1255  }
1256 
1257  if (abs_timeout) {
1258  abs_elapsed = (uint32_t) ((switch_micro_time_now() - abs_started) / 1000);
1259  if (abs_elapsed >= abs_timeout) {
1260  status = SWITCH_STATUS_TIMEOUT;
1261  break;
1262  }
1263  }
1264  if (digit_timeout) {
1265  digit_elapsed = (uint32_t) ((switch_micro_time_now() - digit_started) / 1000);
1266  if (digit_elapsed >= digit_timeout) {
1267  status = SWITCH_STATUS_TIMEOUT;
1268  break;
1269  }
1270  }
1271 
1272 
1273  switch_ivr_parse_all_events(session);
1274 
1275 
1276  if (switch_channel_has_dtmf(channel)) {
1277  if (!args->input_callback && !args->buf && !args->dmachine) {
1278  status = SWITCH_STATUS_BREAK;
1279  break;
1280  }
1281  switch_channel_dequeue_dtmf(channel, &dtmf);
1282 
1283  if (args->dmachine) {
1284  char ds[2] = {dtmf.digit, '\0'};
1285  if ((status = switch_ivr_dmachine_feed(args->dmachine, ds, NULL)) != SWITCH_STATUS_SUCCESS) {
1286  break;
1287  }
1288  }
1289 
1290  if (args->input_callback) {
1291  status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen);
1292  }
1293 
1294  if (digit_timeout) {
1295  digit_started = switch_micro_time_now();
1296  }
1297  }
1298 
1301  if (args->input_callback) {
1302  ostatus = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen);
1303  }
1304  if (ostatus != SWITCH_STATUS_SUCCESS) {
1305  status = ostatus;
1306  }
1307  switch_event_destroy(&event);
1308  }
1309 
1310  if (status != SWITCH_STATUS_SUCCESS) {
1311  break;
1312  }
1313 
1314  if (switch_channel_test_flag(channel, CF_SERVICE)) {
1315  switch_cond_next();
1316  } else {
1317  status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
1318  }
1319 
1320  if (!SWITCH_READ_ACCEPTABLE(status)) {
1321  break;
1322  }
1323 
1324  if (args && args->dmachine) {
1325  if ((status = switch_ivr_dmachine_ping(args->dmachine, NULL)) != SWITCH_STATUS_SUCCESS) {
1326  break;
1327  }
1328  }
1329 
1330  if (read_frame && args && (args->read_frame_callback)) {
1331  if ((status = args->read_frame_callback(session, read_frame, args->user_data)) != SWITCH_STATUS_SUCCESS) {
1332  break;
1333  }
1334  }
1335  }
1336 
1338 
1339  return status;
1340 }
1341 
1343  char *buf,
1345  switch_size_t maxdigits,
1346  const char *terminators, char *terminator,
1347  uint32_t first_timeout, uint32_t digit_timeout, uint32_t abs_timeout)
1348 {
1349  switch_size_t i = 0, x = strlen(buf);
1352  switch_time_t started = 0, digit_started = 0;
1353  uint32_t abs_elapsed = 0, digit_elapsed = 0;
1354  uint32_t eff_timeout = 0;
1355  switch_frame_t write_frame = { 0 };
1356  unsigned char *abuf = NULL;
1357  switch_codec_implementation_t imp = { 0 };
1358  switch_codec_t codec = { 0 };
1359  int sval = 0;
1360  const char *var;
1361 
1362 
1363  if (x >= buflen || x >= maxdigits) {
1364  return SWITCH_STATUS_FALSE;
1365  }
1366 
1367  if ((var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
1368  switch_core_session_get_read_impl(session, &imp);
1369 
1370  if (switch_core_codec_init(&codec,
1371  "L16",
1372  NULL,
1373  NULL,
1374  imp.samples_per_second,
1375  imp.microseconds_per_packet / 1000,
1376  imp.number_of_channels,
1379  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
1381  return SWITCH_STATUS_FALSE;
1382  }
1383 
1384 
1385  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n",
1387 
1388  write_frame.codec = &codec;
1390  write_frame.data = abuf;
1391  write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
1392  write_frame.datalen = imp.decoded_bytes_per_packet;
1393  write_frame.samples = write_frame.datalen / sizeof(int16_t);
1394  }
1395 
1396  if (terminator != NULL) {
1397  *terminator = '\0';
1398  }
1399 
1400  if (!zstr(terminators)) {
1401  for (i = 0; i < x; i++) {
1402  if (strchr(terminators, buf[i]) && terminator != NULL) {
1403  *terminator = buf[i];
1404  buf[i] = '\0';
1405  switch_safe_free(abuf);
1406  return SWITCH_STATUS_SUCCESS;
1407  }
1408  }
1409  }
1410 
1411  if (abs_timeout) {
1412  started = switch_micro_time_now();
1413  }
1414 
1415  if (digit_timeout && first_timeout) {
1416  eff_timeout = first_timeout;
1417  } else if (digit_timeout && !first_timeout) {
1418  eff_timeout = digit_timeout;
1419  } else if (first_timeout) {
1420  digit_timeout = eff_timeout = first_timeout;
1421  }
1422 
1423 
1424  if (eff_timeout) {
1425  digit_started = switch_micro_time_now();
1426  }
1427 
1428  while (switch_channel_ready(channel)) {
1429  switch_frame_t *read_frame;
1430 
1431  if (abs_timeout) {
1432  abs_elapsed = (uint32_t) ((switch_micro_time_now() - started) / 1000);
1433  if (abs_elapsed >= abs_timeout) {
1434  status = SWITCH_STATUS_TIMEOUT;
1435  break;
1436  }
1437  }
1438 
1439 
1440  switch_ivr_parse_all_events(session);
1441 
1442 
1443 
1444  if (eff_timeout) {
1445  digit_elapsed = (uint32_t) ((switch_micro_time_now() - digit_started) / 1000);
1446 
1447  if (digit_elapsed >= eff_timeout) {
1448  status = SWITCH_STATUS_TIMEOUT;
1449  break;
1450  }
1451  }
1452 
1453  if (switch_channel_has_dtmf(channel)) {
1454  switch_dtmf_t dtmf = { 0 };
1455  switch_size_t y;
1456 
1457  if (eff_timeout) {
1458  eff_timeout = digit_timeout;
1459  digit_started = switch_micro_time_now();
1460  }
1461 
1462  for (y = 0; y <= maxdigits; y++) {
1463  if (switch_channel_dequeue_dtmf(channel, &dtmf) != SWITCH_STATUS_SUCCESS) {
1464  break;
1465  }
1466 
1467  if (!zstr(terminators) && strchr(terminators, dtmf.digit) && terminator != NULL) {
1468  *terminator = dtmf.digit;
1469  switch_safe_free(abuf);
1470  return SWITCH_STATUS_SUCCESS;
1471  }
1472 
1473 
1474  buf[x++] = dtmf.digit;
1475  buf[x] = '\0';
1476 
1477  if (x >= buflen || x >= maxdigits) {
1478  switch_safe_free(abuf);
1479  return SWITCH_STATUS_SUCCESS;
1480  }
1481  }
1482  }
1483 
1484  if (switch_channel_test_flag(channel, CF_SERVICE)) {
1485  switch_cond_next();
1486  } else {
1487  status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
1488  if (!SWITCH_READ_ACCEPTABLE(status)) {
1489  break;
1490  }
1491 
1492  if (write_frame.data) {
1493  switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, imp.number_of_channels, sval);
1494  switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
1495  }
1496 
1497  }
1498  }
1499 
1500  if (write_frame.codec) {
1501  switch_core_codec_destroy(&codec);
1502  }
1503 
1504  switch_safe_free(abuf);
1505 
1506  return status;
1507 }
1508 
1509 
1510 SWITCH_DECLARE(switch_status_t) switch_ivr_send_prompt(switch_core_session_t *session, const char *type, const char *text, const char *regex)
1511 {
1512  switch_core_session_message_t msg = { 0 };
1513 
1515  msg.string_array_arg[0] = type;
1516  msg.string_array_arg[1] = text;
1517  msg.string_array_arg[2] = regex;
1518  msg.from = __FILE__;
1519 
1520  switch_core_session_receive_message(session, &msg);
1521 
1522  return SWITCH_STATUS_SUCCESS;
1523 }
1524 
1526 {
1527  switch_core_session_message_t msg = { 0 };
1529  const char *stream;
1530  const char *other_uuid;
1531  switch_event_t *event;
1532 
1533  if (channel) {
1534  switch_channel_callstate_t callstate;
1535 
1536  callstate = switch_channel_get_callstate(channel);
1537  if (callstate == CCS_HELD) {
1538  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Call is already on hold. No need to hold again.\n");
1539  return SWITCH_STATUS_FALSE;
1540  }
1541  }
1542 
1544  msg.string_arg = message;
1545  msg.from = __FILE__;
1546 
1547  switch_channel_set_flag(channel, CF_HOLD);
1549 
1550  switch_core_session_receive_message(session, &msg);
1551 
1552  if (moh && (stream = switch_channel_get_hold_music(channel))) {
1553  if ((other_uuid = switch_channel_get_partner_uuid(channel))) {
1554  switch_ivr_broadcast(other_uuid, stream, SMF_ECHO_ALEG | SMF_LOOP);
1555  }
1556  }
1557 
1559  switch_channel_event_set_data(channel, event);
1560  switch_event_fire(&event);
1561  }
1562 
1563 
1564  return SWITCH_STATUS_SUCCESS;
1565 }
1566 
1567 SWITCH_DECLARE(switch_status_t) switch_ivr_hold_uuid(const char *uuid, const char *message, switch_bool_t moh)
1568 {
1569  switch_core_session_t *session;
1571 
1572  if ((session = switch_core_session_locate(uuid))) {
1573  status = switch_ivr_hold(session, message, moh);
1575  }
1576 
1577  return status;
1578 }
1579 
1580 SWITCH_DECLARE(switch_status_t) switch_ivr_hold_toggle_uuid(const char *uuid, const char *message, switch_bool_t moh)
1581 {
1582  switch_core_session_t *session;
1583  switch_channel_t *channel;
1584  switch_channel_callstate_t callstate;
1586 
1587  if ((session = switch_core_session_locate(uuid))) {
1588  if ((channel = switch_core_session_get_channel(session))) {
1589  callstate = switch_channel_get_callstate(channel);
1590 
1591  if (callstate == CCS_ACTIVE || callstate == CCS_UNHELD) {
1592  status = switch_ivr_hold(session, message, moh);
1593  } else if (callstate == CCS_HELD) {
1594  status = switch_ivr_unhold(session);
1595  }
1596  }
1598  }
1599 
1600  return status;
1601 }
1602 
1604 {
1605  switch_core_session_message_t msg = { 0 };
1607  const char *other_uuid;
1608  switch_core_session_t *b_session;
1609  switch_event_t *event;
1610 
1611  if (channel) {
1612  switch_channel_callstate_t callstate;
1613 
1614  callstate = switch_channel_get_callstate(channel);
1615  if (callstate != CCS_HELD) {
1616  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Call is not on hold. No need to unhold.\n");
1617  return SWITCH_STATUS_FALSE;
1618  }
1619  }
1620 
1622  msg.from = __FILE__;
1623 
1626 
1627  switch_core_session_receive_message(session, &msg);
1628 
1629 
1630  if ((other_uuid = switch_channel_get_partner_uuid(channel)) && (b_session = switch_core_session_locate(other_uuid))) {
1631  switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
1632  switch_channel_stop_broadcast(b_channel);
1633  switch_channel_wait_for_flag(b_channel, CF_BROADCAST, SWITCH_FALSE, 5000, NULL);
1634  switch_core_session_rwunlock(b_session);
1635  }
1636 
1637 
1639  switch_channel_event_set_data(channel, event);
1640  switch_event_fire(&event);
1641  }
1642 
1643  return SWITCH_STATUS_SUCCESS;
1644 }
1645 
1647 {
1648  switch_core_session_t *session;
1650 
1651  if ((session = switch_core_session_locate(uuid))) {
1652  status = switch_ivr_unhold(session);
1654  }
1655 
1656  return status;
1657 }
1658 
1659 
1660 
1661 
1662 
1664 {
1665  const char *other_uuid = NULL;
1666  switch_channel_t *channel, *other_channel = NULL;
1667  switch_core_session_t *session, *other_session;
1668  switch_core_session_message_t msg = { 0 };
1670  uint8_t swap = 0;
1671  //switch_frame_t *read_frame = NULL;
1672 
1674  msg.from = __FILE__;
1675 
1676  if ((session = switch_core_session_locate(uuid))) {
1677  channel = switch_core_session_get_channel(session);
1678 
1680  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Operation is invalid\n");
1682  return SWITCH_STATUS_INUSE;
1683  }
1684 
1686 
1687  if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
1688  swap = 1;
1689  }
1690 
1691 
1692  status = SWITCH_STATUS_SUCCESS;
1693 
1694  /* If we had early media in bypass mode before, it is no longer relevant */
1695  if (switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
1696  switch_core_session_message_t msg2 = { 0 };
1697 
1699  msg2.from = __FILE__;
1700  switch_core_session_receive_message(session, &msg2);
1701  }
1702 
1703  if ((flags & SMF_REPLYONLY_A)) {
1704  msg.numeric_arg = 1;
1705  }
1706 
1708 
1710  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't re-establsh media on %s\n", switch_channel_get_name(channel));
1713  return SWITCH_STATUS_GENERR;
1714  }
1715 
1716  if ((flags & SMF_REPLYONLY_B)) {
1717  msg.numeric_arg = 1;
1718  } else {
1719  msg.numeric_arg = 0;
1720  }
1721 
1722  if ((flags & SMF_IMMEDIATE)) {
1724  switch_yield(250000);
1725  } else {
1726  switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
1727  switch_channel_wait_for_flag(channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
1728  switch_channel_wait_for_flag(channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL);
1730  //switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
1731  }
1732 
1733  if ((flags & SMF_REBRIDGE)
1735  && (other_session = switch_core_session_locate(other_uuid))) {
1736 
1737  other_channel = switch_core_session_get_channel(other_session);
1738  switch_assert(other_channel != NULL);
1739 
1741  switch_channel_set_variable(other_channel, "rtp_secure_media", "optional");
1742 
1743  switch_core_session_receive_message(other_session, &msg);
1744  switch_channel_wait_for_flag(other_channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
1745  switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
1746  switch_channel_wait_for_flag(other_channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL);
1747  switch_channel_wait_for_flag(other_channel, CF_3P_MEDIA_REQUESTED, SWITCH_FALSE, 10000, NULL);
1748  //switch_core_session_read_frame(other_session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
1749  switch_channel_clear_state_handler(other_channel, NULL);
1750  switch_core_session_rwunlock(other_session);
1751  }
1752  if (other_channel) {
1753  switch_channel_clear_state_handler(channel, NULL);
1754  }
1755 
1758 
1759  if (other_channel) {
1760  if (swap) {
1761  switch_ivr_uuid_bridge(other_uuid, uuid);
1762  } else {
1763  switch_ivr_uuid_bridge(uuid, other_uuid);
1764  }
1765  switch_channel_wait_for_flag(channel, CF_BRIDGED, SWITCH_TRUE, 1000, NULL);
1766  switch_channel_wait_for_flag(other_channel, CF_BRIDGED, SWITCH_TRUE, 1000, NULL);
1767  }
1768  }
1769 
1770  return status;
1771 }
1772 
1774 {
1775  const char *other_uuid = NULL;
1776  switch_channel_t *channel, *other_channel = NULL;
1777  switch_core_session_t *session, *other_session;
1778  switch_core_session_message_t msg = { 0 };
1780  uint8_t swap = 0;
1781  switch_frame_t *read_frame = NULL;
1782 
1784  msg.from = __FILE__;
1785 
1786  if ((session = switch_core_session_locate(uuid))) {
1787  channel = switch_core_session_get_channel(session);
1788 
1789  if (switch_channel_test_flag(channel, CF_MEDIA_TRANS)) {
1791 
1792  return SWITCH_STATUS_INUSE;
1793  }
1794 
1796 
1797  if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
1798  swap = 1;
1799  }
1800 
1801  if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
1803 
1804  status = SWITCH_STATUS_SUCCESS;
1805 
1806  /* If we had early media in bypass mode before, it is no longer relevant */
1807  if (switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
1808  switch_core_session_message_t msg2 = { 0 };
1809 
1811  msg2.from = __FILE__;
1812  switch_core_session_receive_message(session, &msg2);
1813  }
1814 
1815  if ((flags & SMF_REPLYONLY_A)) {
1816  msg.numeric_arg = 1;
1817  }
1818 
1820  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't re-establsh media on %s\n", switch_channel_get_name(channel));
1822 
1823  return SWITCH_STATUS_GENERR;
1824  }
1825 
1826  if ((flags & SMF_REPLYONLY_B)) {
1827  msg.numeric_arg = 1;
1828  } else {
1829  msg.numeric_arg = 0;
1830  }
1831 
1832  if ((flags & SMF_IMMEDIATE)) {
1834  switch_yield(250000);
1835  } else {
1836  switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
1837  switch_channel_wait_for_flag(channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
1838  switch_channel_wait_for_flag(channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL);
1839  res = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
1840  }
1841 
1842  if ((flags & SMF_REBRIDGE)
1844  && (other_session = switch_core_session_locate(other_uuid))) {
1845  other_channel = switch_core_session_get_channel(other_session);
1846  switch_assert(other_channel != NULL);
1847  switch_core_session_receive_message(other_session, &msg);
1848  switch_channel_wait_for_flag(other_channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
1849  switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
1850  switch_channel_wait_for_flag(other_channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL);
1851  res = switch_core_session_read_frame(other_session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
1852  switch_channel_clear_state_handler(other_channel, NULL);
1853  switch_core_session_rwunlock(other_session);
1854  }
1855 
1856  (void)res;
1857 
1858  if (other_channel) {
1859  switch_channel_clear_state_handler(channel, NULL);
1860  }
1861  }
1862 
1865 
1866  if (other_channel) {
1867  if (swap) {
1868  switch_ivr_uuid_bridge(other_uuid, uuid);
1869  } else {
1870  switch_ivr_uuid_bridge(uuid, other_uuid);
1871  }
1872 
1873  switch_channel_wait_for_flag(channel, CF_BRIDGED, SWITCH_TRUE, 1000, NULL);
1874  switch_channel_wait_for_flag(other_channel, CF_BRIDGED, SWITCH_TRUE, 1000, NULL);
1875  }
1876  }
1877 
1878  return status;
1879 }
1880 
1882 {
1883  const char *other_uuid;
1884  switch_channel_t *channel, *other_channel = NULL;
1885  switch_core_session_t *session, *other_session = NULL;
1886  switch_core_session_message_t msg = { 0 };
1888  uint8_t swap = 0;
1889 
1891  msg.from = __FILE__;
1892 
1893  if ((session = switch_core_session_locate(uuid))) {
1894  status = SWITCH_STATUS_SUCCESS;
1895  channel = switch_core_session_get_channel(session);
1896 
1897  if (switch_channel_test_flag(channel, CF_MEDIA_TRANS) || (!(flags & SMF_FORCE) && switch_channel_test_flag(channel, CF_PROXY_MODE))) {
1898  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Operation is invalid\n");
1900  return SWITCH_STATUS_INUSE;
1901  }
1902 
1904 
1905  if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
1906  swap = 1;
1907  }
1908 
1909  if ((flags & SMF_FORCE) || !switch_channel_test_flag(channel, CF_PROXY_MODE)) {
1910  if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) &&
1911  (other_session = switch_core_session_locate(other_uuid))) {
1912  other_channel = switch_core_session_get_channel(other_session);
1913 
1916 
1917  switch_channel_set_flag(other_channel, CF_RESET);
1918  switch_channel_set_flag(other_channel, CF_REDIRECT);
1919 
1922  switch_core_session_receive_message(session, &msg);
1923 
1924  if (!switch_core_session_in_thread(session)) {
1926  }
1927 
1928  switch_channel_set_state(other_channel, CS_PARK);
1929 
1930  if (switch_core_session_in_thread(session)) {
1931  switch_yield(100000);
1932  } else {
1933  switch_channel_wait_for_state(other_channel, channel, CS_PARK);
1934  }
1935 
1936 
1937  if (!switch_core_session_in_thread(session)) {
1938  switch_channel_wait_for_state(channel, NULL, CS_PARK);
1939  }
1940 
1941  switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
1942  switch_channel_wait_for_flag(channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
1944 
1948 
1949 
1950  switch_core_session_receive_message(other_session, &msg);
1951  switch_channel_wait_for_flag(other_channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
1952  switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
1954  }
1955 
1956  if (other_channel) {
1957  if (swap) {
1958  switch_ivr_signal_bridge(other_session, session);
1959  } else {
1960  switch_ivr_signal_bridge(session, other_session);
1961  }
1962 
1963  if (switch_core_session_in_thread(session)) {
1964  switch_yield(100000);
1965  } else {
1966  switch_channel_wait_for_state(other_channel, channel, CS_HIBERNATE);
1967  }
1968 
1969  if (!switch_core_session_in_thread(session)) {
1970  switch_channel_wait_for_state(channel, other_channel, CS_HIBERNATE);
1971  }
1972  switch_core_session_rwunlock(other_session);
1973  }
1974  }
1975 
1978  }
1979 
1980 
1981 
1982  return status;
1983 }
1984 
1985 
1986 
1988 {
1989  const char *other_uuid;
1990  switch_channel_t *channel, *other_channel = NULL;
1991  switch_core_session_t *session, *other_session = NULL;
1992  switch_core_session_message_t msg = { 0 };
1994  uint8_t swap = 0;
1995 
1997  msg.from = __FILE__;
1998 
1999  if ((session = switch_core_session_locate(uuid))) {
2000 
2001  status = SWITCH_STATUS_SUCCESS;
2002  channel = switch_core_session_get_channel(session);
2003 
2004  if (switch_channel_test_flag(channel, CF_SECURE)) {
2007  "Cannot bypass %s due to secure connection.\n", switch_channel_get_name(channel));
2008  return SWITCH_STATUS_FALSE;
2009  }
2010 
2011  if (switch_channel_test_flag(channel, CF_MEDIA_TRANS)) {
2013  return SWITCH_STATUS_INUSE;
2014  }
2015 
2017 
2018  if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
2019  swap = 1;
2020  }
2021 
2024 
2025  if ((flags & SMF_FORCE) || !switch_channel_test_flag(channel, CF_PROXY_MODE)) {
2026  if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) &&
2027  (other_session = switch_core_session_locate(other_uuid))) {
2028  other_channel = switch_core_session_get_channel(other_session);
2029 
2030  switch_channel_set_flag(other_channel, CF_RESET);
2031  switch_channel_set_flag(other_channel, CF_REDIRECT);
2032 
2033  if (!switch_core_session_in_thread(session)) {
2035  }
2036  switch_channel_set_state(other_channel, CS_PARK);
2037  if (switch_core_session_in_thread(session)) {
2038  switch_yield(100000);
2039  } else {
2040  switch_channel_wait_for_state(other_channel, channel, CS_PARK);
2041  }
2042  switch_core_session_receive_message(other_session, &msg);
2043  switch_channel_wait_for_flag(other_channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
2044  //switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
2045  switch_channel_wait_for_flag(other_channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL);
2046  }
2047 
2048  switch_core_session_receive_message(session, &msg);
2049 
2050  if (other_channel) {
2051  if (!switch_core_session_in_thread(session)) {
2052  switch_channel_wait_for_state(channel, NULL, CS_PARK);
2053  switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
2054  switch_channel_wait_for_flag(channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
2055  switch_channel_wait_for_flag(channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL);
2056  }
2057 
2058  if (swap) {
2059  switch_ivr_signal_bridge(other_session, session);
2060  } else {
2061  switch_ivr_signal_bridge(session, other_session);
2062  }
2063 
2064  if (switch_core_session_in_thread(session)) {
2065  switch_yield(100000);
2066  } else {
2067  switch_channel_wait_for_state(other_channel, channel, CS_HIBERNATE);
2068  }
2069 
2070  if (!switch_core_session_in_thread(session)) {
2071  switch_channel_wait_for_state(channel, other_channel, CS_HIBERNATE);
2072  }
2073  switch_core_session_rwunlock(other_session);
2074  }
2075  }
2076 
2079  }
2080 
2081 
2082 
2083  return status;
2084 }
2085 
2086 typedef struct {
2088  const char *uuid;
2092  uint32_t delay;
2093 } media_job_t;
2094 
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 }
2119 
2120 
2121 SWITCH_DECLARE(void) switch_ivr_bg_media(const char *uuid, switch_media_flag_t flags, switch_bool_t on, switch_bool_t is3p, uint32_t delay)
2122 {
2125  media_job_t *job;
2126 
2128  td = switch_core_alloc(pool, sizeof(*td));
2129  job = switch_core_alloc(pool, sizeof(*job));
2130  td->func = media_thread_run;
2131  job->pool = pool;
2132  job->uuid = switch_core_strdup(pool, uuid);
2133  job->flags = flags;
2134  job->on = on;
2135  job->is3p = is3p;
2136  job->delay = delay;
2137  td->obj = job;
2138  td->pool = pool;
2140 
2141 }
2142 
2144 {
2146 
2149  switch_core_session_message_t msg = { 0 };
2150 
2152  msg.from = __FILE__;
2153 
2155  switch_core_session_receive_message(session, &msg);
2156  }
2157 
2158  if (switch_channel_test_flag(channel, CF_HOLD)) {
2159  switch_ivr_unhold(session);
2160  }
2161 }
2162 
2163 SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_t *session, const char *extension, const char *dialplan,
2164  const char *context)
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 }
2317 
2319 {
2322  switch_event_t *var_event;
2323 
2324  const char *val = NULL;
2325  uint8_t prefix = 0;
2326 
2327  if (var && *var == '~') {
2328  var++;
2329  prefix = 1;
2330  }
2331 
2332  if (var && !prefix) {
2333  if ((val = switch_channel_get_variable(chana, var))) {
2334  switch_channel_set_variable(chanb, var, val);
2335  }
2336  } else {
2338 
2339  switch_channel_get_variables(chana, &var_event);
2340 
2341  for (hi = var_event->headers; hi; hi = hi->next) {
2342  char *vvar = hi->name;
2343  char *vval = hi->value;
2344  if (vvar && vval && (!prefix || (var && !strncmp((char *) vvar, var, strlen(var))))) {
2345  switch_channel_set_variable(chanb, (char *) vvar, (char *) vval);
2346  }
2347  }
2348 
2349  switch_event_destroy(&var_event);
2350  }
2351 
2352  return SWITCH_STATUS_SUCCESS;
2353 }
2354 
2355 /******************************************************************************************************/
2356 
2365  unsigned int digit_timeout_ms;
2366 };
2367 
2369  char *digits;
2371 };
2372 
2374 {
2376 
2377  if (parser != NULL) {
2378  int pool_auto_created = 0;
2379 
2380  /* if the caller didn't provide a pool, make one */
2381  if (pool == NULL) {
2383  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "created a memory pool\n");
2384  if (pool != NULL) {
2385  pool_auto_created = 1;
2386  }
2387  }
2388  /* if we have a pool, make a parser object */
2389  if (pool != NULL) {
2391  }
2392  /* if we have parser object, initialize it for the caller */
2393  if (pool && *parser != NULL) {
2394  memset(*parser, 0, sizeof(switch_ivr_digit_stream_parser_t));
2395  (*parser)->pool_auto_created = pool_auto_created;
2396  (*parser)->pool = pool;
2397  (*parser)->digit_timeout_ms = 1000;
2398  switch_core_hash_init(&(*parser)->hash);
2399 
2400  status = SWITCH_STATUS_SUCCESS;
2401  } else {
2402  status = SWITCH_STATUS_MEMERR;
2403  /* if we can't create a parser object,clean up the pool if we created it */
2404  if (pool != NULL && pool_auto_created) {
2406  }
2407  }
2408  }
2409 
2410  return status;
2411 }
2412 
2414 {
2416 
2417  if (parser != NULL) {
2418  if (parser->hash != NULL) {
2419  switch_core_hash_destroy(&parser->hash);
2420  parser->hash = NULL;
2421  }
2422  /* free the memory pool if we created it */
2423  if (parser->pool_auto_created && parser->pool != NULL) {
2424  status = switch_core_destroy_memory_pool(&parser->pool);
2425  }
2426  }
2427 
2428  return status;
2429 }
2430 
2432 {
2434 
2435  /* if we have a parser object memory pool and a stream object pointer that is null */
2436  if (parser && stream && *stream == NULL) {
2437  *stream = (switch_ivr_digit_stream_t *) malloc(sizeof(**stream));
2438  switch_assert(*stream);
2439  memset(*stream, 0, sizeof(**stream));
2440  switch_zmalloc((*stream)->digits, parser->buflen + 1);
2441  status = SWITCH_STATUS_SUCCESS;
2442  }
2443 
2444  return status;
2445 }
2446 
2448 {
2450 
2451  if (*stream) {
2452  switch_safe_free((*stream)->digits);
2453  free(*stream);
2454  *stream = NULL;
2455  status = SWITCH_STATUS_SUCCESS;
2456  }
2457 
2458  return status;
2459 }
2460 
2462 {
2464 
2465  if (parser != NULL && digits != NULL && *digits && parser->hash != NULL) {
2466 
2467  status = switch_core_hash_insert(parser->hash, digits, data);
2468  if (status == SWITCH_STATUS_SUCCESS) {
2469  switch_size_t len = strlen(digits);
2470 
2471  /* if we don't have a terminator, then we have to try and
2472  * figure out when a digit set is completed, therefore we
2473  * keep track of the min and max digit lengths
2474  */
2475 
2476  if (len > parser->buflen) {
2477  parser->buflen = len;
2478  }
2479 
2480  if (parser->terminator == '\0') {
2481  if (len > parser->maxlen) {
2482  parser->maxlen = len;
2483  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "max len %u\n", (uint32_t) parser->maxlen);
2484  }
2485  if (parser->minlen == 0 || len < parser->minlen) {
2486  parser->minlen = len;
2487  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "min len %u\n", (uint32_t) parser->minlen);
2488  }
2489  } else {
2490  /* since we have a terminator, reset min and max */
2491  parser->minlen = 0;
2492  parser->maxlen = 0;
2493  }
2494  }
2495  }
2496  if (status != SWITCH_STATUS_SUCCESS) {
2497  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to add hash for '%s'\n", digits);
2498  }
2499 
2500  return status;
2501 }
2502 
2504 {
2506 
2507  if (parser != NULL && digits != NULL && *digits) {
2509  }
2510 
2511  if (status != SWITCH_STATUS_SUCCESS) {
2512  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to del hash for '%s'\n", digits);
2513  }
2514 
2515  return status;
2516 }
2517 
2519 {
2520  void *result = NULL;
2521  switch_size_t len;
2522 
2523  switch_assert(parser);
2524  switch_assert(stream);
2525  switch_assert(stream->digits);
2526 
2527  len = strlen(stream->digits);
2528 
2529  /* handle new digit arrivals */
2530  if (digit) {
2531  /* if it's not a terminator digit, add it to the collected digits */
2532  if (digit != parser->terminator) {
2533  /* if collected digits length >= the max length of the keys
2534  * in the hash table, then left shift the digit string
2535  */
2536  if (len > 0 && parser->maxlen != 0 && len >= parser->maxlen) {
2537  char *src = stream->digits + 1;
2538  char *dst = stream->digits;
2539 
2540  while (*src) {
2541  *(dst++) = *(src++);
2542  }
2543  *dst = digit;
2544  } else {
2545  *(stream->digits + (len++)) = digit;
2546  *(stream->digits + len) = '\0';
2547  stream->last_digit_time = switch_micro_time_now() / 1000;
2548  }
2549  }
2550  }
2551 
2552  /* don't allow collected digit string testing if there are varying sized keys until timeout */
2553  if (parser->maxlen - parser->minlen > 0 && (switch_micro_time_now() / 1000) - stream->last_digit_time < parser->digit_timeout_ms) {
2554  len = 0;
2555  }
2556  /* if we have digits to test */
2557  if (len) {
2558  result = switch_core_hash_find(parser->hash, stream->digits);
2559  /* if we matched the digit string, or this digit is the terminator
2560  * reset the collected digits for next digit string
2561  */
2562  if (result != NULL || parser->terminator == digit) {
2563  *stream->digits = '\0';
2564  }
2565  }
2566 
2567 
2568  return result;
2569 }
2570 
2572 {
2574  switch_assert(stream);
2575  switch_assert(stream->digits);
2576 
2577  *stream->digits = '\0';
2578  stream->last_digit_time = 0;
2579  status = SWITCH_STATUS_SUCCESS;
2580 
2581  return status;
2582 }
2583 
2585 {
2587 
2588  if (parser != NULL) {
2589  parser->terminator = digit;
2590  /* since we have a terminator, reset min and max */
2591  parser->minlen = 0;
2592  parser->maxlen = 0;
2593  status = SWITCH_STATUS_SUCCESS;
2594  }
2595 
2596  return status;
2597 }
2598 
2600 {
2601  switch_xml_t param;
2602 
2603  if (!(param = switch_xml_add_child_d(xml, "username", off++))) {
2604  return -1;
2605  }
2606  switch_xml_set_txt_d(param, caller_profile->username);
2607 
2608  if (!(param = switch_xml_add_child_d(xml, "dialplan", off++))) {
2609  return -1;
2610  }
2611  switch_xml_set_txt_d(param, caller_profile->dialplan);
2612 
2613  if (!(param = switch_xml_add_child_d(xml, "caller_id_name", off++))) {
2614  return -1;
2615  }
2616  switch_xml_set_txt_d(param, caller_profile->caller_id_name);
2617 
2618  if (!(param = switch_xml_add_child_d(xml, "caller_id_number", off++))) {
2619  return -1;
2620  }
2621  switch_xml_set_txt_d(param, caller_profile->caller_id_number);
2622 
2623  if (!(param = switch_xml_add_child_d(xml, "callee_id_name", off++))) {
2624  return -1;
2625  }
2626  switch_xml_set_txt_d(param, caller_profile->callee_id_name);
2627 
2628  if (!(param = switch_xml_add_child_d(xml, "callee_id_number", off++))) {
2629  return -1;
2630  }
2631  switch_xml_set_txt_d(param, caller_profile->callee_id_number);
2632 
2633  if (!(param = switch_xml_add_child_d(xml, "ani", off++))) {
2634  return -1;
2635  }
2636  switch_xml_set_txt_d(param, caller_profile->ani);
2637 
2638  if (!(param = switch_xml_add_child_d(xml, "aniii", off++))) {
2639  return -1;
2640  }
2641  switch_xml_set_txt_d(param, caller_profile->aniii);
2642 
2643 
2644  if (!(param = switch_xml_add_child_d(xml, "network_addr", off++))) {
2645  return -1;
2646  }
2647  switch_xml_set_txt_d(param, caller_profile->network_addr);
2648 
2649  if (!(param = switch_xml_add_child_d(xml, "rdnis", off++))) {
2650  return -1;
2651  }
2652  switch_xml_set_txt_d(param, caller_profile->rdnis);
2653 
2654  if (!(param = switch_xml_add_child_d(xml, "destination_number", off++))) {
2655  return -1;
2656  }
2657  switch_xml_set_txt_d(param, caller_profile->destination_number);
2658 
2659  if (!(param = switch_xml_add_child_d(xml, "uuid", off++))) {
2660  return -1;
2661  }
2662  switch_xml_set_txt_d(param, caller_profile->uuid);
2663 
2664  if (!(param = switch_xml_add_child_d(xml, "source", off++))) {
2665  return -1;
2666  }
2667  switch_xml_set_txt_d(param, caller_profile->source);
2668 
2669  if (caller_profile->transfer_source) {
2670  if (!(param = switch_xml_add_child_d(xml, "transfer_source", off++))) {
2671  return -1;
2672  }
2673  switch_xml_set_txt_d(param, caller_profile->transfer_source);
2674  }
2675 
2676  if (!(param = switch_xml_add_child_d(xml, "context", off++))) {
2677  return -1;
2678  }
2679  switch_xml_set_txt_d(param, caller_profile->context);
2680 
2681  if (!(param = switch_xml_add_child_d(xml, "chan_name", off++))) {
2682  return -1;
2683  }
2684  switch_xml_set_txt_d(param, caller_profile->chan_name);
2685 
2686 
2687  if (caller_profile->soft) {
2688  profile_node_t *pn;
2689 
2690  for (pn = caller_profile->soft; pn; pn = pn->next) {
2691 
2692  if (!(param = switch_xml_add_child_d(xml, pn->var, off++))) {
2693  return -1;
2694  }
2695  switch_xml_set_txt_d(param, pn->val);
2696  }
2697 
2698  }
2699 
2700 
2701  return off;
2702 }
2703 
2704 
2705 #define add_stat(_x, _i, _s) \
2706  switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_SIZE_T_FMT, _i); \
2707  x_tmp = switch_xml_add_child_d(_x, _s, loff++); \
2708  switch_xml_set_txt_d(x_tmp, var_val)
2709 
2710 #define add_stat_double(_x, _i, _s) \
2711  switch_snprintf(var_val, sizeof(var_val), "%0.2f", _i); \
2712  x_tmp = switch_xml_add_child_d(_x, _s, loff++); \
2713  switch_xml_set_txt_d(x_tmp, var_val)
2714 
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 }
2813 
2814 static int switch_ivr_set_xml_chan_var(switch_xml_t xml, const char *var, const char *val, int off)
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 }
2836 
2837 
2839 {
2840 
2842 
2843  if (!hi)
2844  return off;
2845 
2846  for (; hi; hi = hi->next) {
2847  if (hi->idx) {
2848  int i;
2849 
2850  for (i = 0; i < hi->idx; i++) {
2851  off = switch_ivr_set_xml_chan_var(xml, hi->name, hi->array[i], off);
2852  }
2853  } else {
2854  off = switch_ivr_set_xml_chan_var(xml, hi->name, hi->value, off);
2855  }
2856  }
2858 
2859  return off;
2860 }
2861 
2863 {
2865  switch_caller_profile_t *caller_profile;
2866  switch_xml_t call_stats, variables, cdr, x_main_cp, x_caller_profile, x_caller_extension, x_times, time_tag,
2867  x_application, x_callflow, x_inner_extension, x_apps, x_o, x_channel_data, x_field, xhr, x_hold;
2868  switch_app_log_t *app_log;
2869  char tmp[512], *f;
2870  int cdr_off = 0, cd_off = 0;
2871  switch_hold_record_t *hold_record = switch_channel_get_hold_record(channel), *hr;
2872  const char *text_buffer = NULL;
2873 
2874  if (*xml_cdr) {
2875  cdr = *xml_cdr;
2876  } else {
2877  if (!(cdr = switch_xml_new("cdr"))) {
2878  return SWITCH_STATUS_SUCCESS;
2879  }
2880  }
2881 
2882  switch_xml_set_attr_d(cdr, "core-uuid", switch_core_get_uuid());
2883  switch_xml_set_attr_d(cdr, "switchname", switch_core_get_switchname());
2884 
2885  if (!(x_channel_data = switch_xml_add_child_d(cdr, "channel_data", cdr_off++))) {
2886  goto error;
2887  }
2888 
2889  x_field = switch_xml_add_child_d(x_channel_data, "state", cd_off++);
2891 
2892  x_field = switch_xml_add_child_d(x_channel_data, "direction", cd_off++);
2893  switch_xml_set_txt_d(x_field, switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
2894 
2895 
2896  if ((text_buffer = switch_core_session_get_text_buffer(session))) {
2897  x_field = switch_xml_add_child_d(x_channel_data, "textlog", cd_off++);
2898  switch_xml_set_txt_d(x_field, text_buffer);
2899  }
2900 
2901  x_field = switch_xml_add_child_d(x_channel_data, "state_number", cd_off++);
2902  switch_snprintf(tmp, sizeof(tmp), "%d", switch_channel_get_state(channel));
2903  switch_xml_set_txt_d(x_field, tmp);
2904 
2905  if ((f = switch_channel_get_flag_string(channel))) {
2906  x_field = switch_xml_add_child_d(x_channel_data, "flags", cd_off++);
2907  switch_xml_set_txt_d(x_field, f);
2908  free(f);
2909  }
2910 
2911  if ((f = switch_channel_get_cap_string(channel))) {
2912  x_field = switch_xml_add_child_d(x_channel_data, "caps", cd_off++);
2913  switch_xml_set_txt_d(x_field, f);
2914  free(f);
2915  }
2916 
2917  if (!(call_stats = switch_xml_add_child_d(cdr, "call-stats", cdr_off++))) {
2918  goto error;
2919  }
2920 
2921  switch_ivr_set_xml_call_stats(call_stats, session, 0, SWITCH_MEDIA_TYPE_AUDIO);
2922  switch_ivr_set_xml_call_stats(call_stats, session, 0, SWITCH_MEDIA_TYPE_VIDEO);
2923 
2924 
2925  if (!(variables = switch_xml_add_child_d(cdr, "variables", cdr_off++))) {
2926  goto error;
2927  }
2928 
2929  switch_ivr_set_xml_chan_vars(variables, channel, 0);
2930 
2931 
2932  if ((app_log = switch_core_session_get_app_log(session))) {
2933  int app_off = 0;
2934  switch_app_log_t *ap;
2935 
2936  if (!(x_apps = switch_xml_add_child_d(cdr, "app_log", cdr_off++))) {
2937  goto error;
2938  }
2939  for (ap = app_log; ap; ap = ap->next) {
2940  char tmp[128];
2941 
2942  if (!(x_application = switch_xml_add_child_d(x_apps, "application", app_off++))) {
2943  goto error;
2944  }
2945 
2946  switch_xml_set_attr_d(x_application, "app_name", ap->app);
2947  switch_xml_set_attr_d(x_application, "app_data", ap->arg);
2948 
2949  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, ap->stamp);
2950  switch_xml_set_attr_d_buf(x_application, "app_stamp", tmp);
2951  }
2952  }
2953 
2954  if (hold_record) {
2955  int cf_off = 0;
2956 
2957  if (!(xhr = switch_xml_add_child_d(cdr, "hold-record", cdr_off++))) {
2958  goto error;
2959  }
2960 
2961  for (hr = hold_record; hr; hr = hr->next) {
2962  char *t = tmp;
2963  if (!(x_hold = switch_xml_add_child_d(xhr, "hold", cf_off++))) {
2964  goto error;
2965  }
2966 
2967  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, hr->on);
2968  switch_xml_set_attr_d(x_hold, "on", t);
2969 
2970  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, hr->off);
2971  switch_xml_set_attr_d(x_hold, "off", t);
2972 
2973  if (hr->uuid) {
2974  switch_xml_set_attr_d(x_hold, "bridged-to", hr->uuid);
2975  }
2976 
2977 
2978  }
2979 
2980 
2981  }
2982 
2983 
2984 
2985  caller_profile = switch_channel_get_caller_profile(channel);
2986 
2987  while (caller_profile) {
2988  int cf_off = 0;
2989  int cp_off = 0;
2990 
2991  if (!(x_callflow = switch_xml_add_child_d(cdr, "callflow", cdr_off++))) {
2992  goto error;
2993  }
2994 
2995  if (!zstr(caller_profile->dialplan)) {
2996  switch_xml_set_attr_d(x_callflow, "dialplan", caller_profile->dialplan);
2997  }
2998 
2999  if (!zstr(caller_profile->uuid_str)) {
3000  switch_xml_set_attr_d(x_callflow, "unique-id", caller_profile->uuid_str);
3001  }
3002 
3003  if (!zstr(caller_profile->clone_of)) {
3004  switch_xml_set_attr_d(x_callflow, "clone-of", caller_profile->clone_of);
3005  }
3006 
3007  if (!zstr(caller_profile->profile_index)) {
3008  switch_xml_set_attr_d(x_callflow, "profile_index", caller_profile->profile_index);
3009  }
3010 
3011  if (caller_profile->caller_extension) {
3013  int app_off = 0;
3014 
3015  if (!(x_caller_extension = switch_xml_add_child_d(x_callflow, "extension", cf_off++))) {
3016  goto error;
3017  }
3018 
3019  switch_xml_set_attr_d(x_caller_extension, "name", caller_profile->caller_extension->extension_name);
3020  switch_xml_set_attr_d(x_caller_extension, "number", caller_profile->caller_extension->extension_number);
3021  if (caller_profile->caller_extension->current_application) {
3022  switch_xml_set_attr_d(x_caller_extension, "current_app", caller_profile->caller_extension->current_application->application_name);
3023  }
3024 
3025  for (ap = caller_profile->caller_extension->applications; ap; ap = ap->next) {
3026  if (!(x_application = switch_xml_add_child_d(x_caller_extension, "application", app_off++))) {
3027  goto error;
3028  }
3029  if (ap == caller_profile->caller_extension->current_application) {
3030  switch_xml_set_attr_d(x_application, "last_executed", "true");
3031  }
3032  switch_xml_set_attr_d(x_application, "app_name", ap->application_name);
3033  switch_xml_set_attr_d(x_application, "app_data", ap->application_data);
3034  }
3035 
3036  if (caller_profile->caller_extension->children) {
3037  switch_caller_profile_t *cp = NULL;
3038  int i_off = 0, i_app_off = 0;
3039  for (cp = caller_profile->caller_extension->children; cp; cp = cp->next) {
3040 
3041  if (!cp->caller_extension) {
3042  continue;
3043  }
3044  if (!(x_inner_extension = switch_xml_add_child_d(x_caller_extension, "sub_extensions", app_off++))) {
3045  goto error;
3046  }
3047 
3048  if (!(x_caller_extension = switch_xml_add_child_d(x_inner_extension, "extension", i_off++))) {
3049  goto error;
3050  }
3051  switch_xml_set_attr_d(x_caller_extension, "name", cp->caller_extension->extension_name);
3052  switch_xml_set_attr_d(x_caller_extension, "number", cp->caller_extension->extension_number);
3053  switch_xml_set_attr_d(x_caller_extension, "dialplan", cp->dialplan);
3055  switch_xml_set_attr_d(x_caller_extension, "current_app", cp->caller_extension->current_application->application_name);
3056  }
3057 
3058  for (ap = cp->caller_extension->applications; ap; ap = ap->next) {
3059  if (!(x_application = switch_xml_add_child_d(x_caller_extension, "application", i_app_off++))) {
3060  goto error;
3061  }
3062  if (ap == cp->caller_extension->current_application) {
3063  switch_xml_set_attr_d(x_application, "last_executed", "true");
3064  }
3065  switch_xml_set_attr_d(x_application, "app_name", ap->application_name);
3066  switch_xml_set_attr_d(x_application, "app_data", ap->application_data);
3067  }
3068  }
3069  }
3070  }
3071 
3072  if (!(x_main_cp = switch_xml_add_child_d(x_callflow, "caller_profile", cf_off++))) {
3073  goto error;
3074  }
3075 
3076  cp_off += switch_ivr_set_xml_profile_data(x_main_cp, caller_profile, 0);
3077 
3078  if (caller_profile->origination_caller_profile) {
3079  switch_caller_profile_t *cp = NULL;
3080  int off = 0;
3081  if (!(x_o = switch_xml_add_child_d(x_main_cp, "origination", cp_off++))) {
3082  goto error;
3083  }
3084 
3085  for (cp = caller_profile->origination_caller_profile; cp; cp = cp->next) {
3086  if (!(x_caller_profile = switch_xml_add_child_d(x_o, "origination_caller_profile", off++))) {
3087  goto error;
3088  }
3089  switch_ivr_set_xml_profile_data(x_caller_profile, cp, 0);
3090  }
3091  }
3092 
3093  if (caller_profile->originator_caller_profile) {
3094  switch_caller_profile_t *cp = NULL;
3095  int off = 0;
3096  if (!(x_o = switch_xml_add_child_d(x_main_cp, "originator", cp_off++))) {
3097  goto error;
3098  }
3099 
3100  for (cp = caller_profile->originator_caller_profile; cp; cp = cp->next) {
3101  if (!(x_caller_profile = switch_xml_add_child_d(x_o, "originator_caller_profile", off++))) {
3102  goto error;
3103  }
3104  switch_ivr_set_xml_profile_data(x_caller_profile, cp, 0);
3105  }
3106  }
3107 
3108  if (caller_profile->originatee_caller_profile) {
3109  switch_caller_profile_t *cp = NULL;
3110  int off = 0;
3111  if (!(x_o = switch_xml_add_child_d(x_main_cp, "originatee", cp_off++))) {
3112  goto error;
3113  }
3114  for (cp = caller_profile->originatee_caller_profile; cp; cp = cp->next) {
3115  if (!(x_caller_profile = switch_xml_add_child_d(x_o, "originatee_caller_profile", off++))) {
3116  goto error;
3117  }
3118  switch_ivr_set_xml_profile_data(x_caller_profile, cp, 0);
3119  }
3120  }
3121 
3122  if (caller_profile->times) {
3123  int t_off = 0;
3124  if (!(x_times = switch_xml_add_child_d(x_callflow, "times", cf_off++))) {
3125  goto error;
3126  }
3127  if (!(time_tag = switch_xml_add_child_d(x_times, "created_time", t_off++))) {
3128  goto error;
3129  }
3130  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->created);
3131  switch_xml_set_txt_d(time_tag, tmp);
3132 
3133  if (!(time_tag = switch_xml_add_child_d(x_times, "profile_created_time", t_off++))) {
3134  goto error;
3135  }
3136  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->profile_created);
3137  switch_xml_set_txt_d(time_tag, tmp);
3138 
3139  if (!(time_tag = switch_xml_add_child_d(x_times, "progress_time", t_off++))) {
3140  goto error;
3141  }
3142  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress);
3143  switch_xml_set_txt_d(time_tag, tmp);
3144 
3145 
3146  if (!(time_tag = switch_xml_add_child_d(x_times, "progress_media_time", t_off++))) {
3147  goto error;
3148  }
3149  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress_media);
3150  switch_xml_set_txt_d(time_tag, tmp);
3151 
3152  if (!(time_tag = switch_xml_add_child_d(x_times, "answered_time", t_off++))) {
3153  goto error;
3154  }
3155  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
3156  switch_xml_set_txt_d(time_tag, tmp);
3157 
3158  if (!(time_tag = switch_xml_add_child_d(x_times, "bridged_time", t_off++))) {
3159  goto error;
3160  }
3161  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->bridged);
3162  switch_xml_set_txt_d(time_tag, tmp);
3163 
3164  if (!(time_tag = switch_xml_add_child_d(x_times, "last_hold_time", t_off++))) {
3165  goto error;
3166  }
3167  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->last_hold);
3168  switch_xml_set_txt_d(time_tag, tmp);
3169 
3170  if (!(time_tag = switch_xml_add_child_d(x_times, "hold_accum_time", t_off++))) {
3171  goto error;
3172  }
3173  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hold_accum);
3174  switch_xml_set_txt_d(time_tag, tmp);
3175 
3176  if (!(time_tag = switch_xml_add_child_d(x_times, "hangup_time", t_off++))) {
3177  goto error;
3178  }
3179  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
3180  switch_xml_set_txt_d(time_tag, tmp);
3181 
3182  if (!(time_tag = switch_xml_add_child_d(x_times, "resurrect_time", t_off++))) {
3183  goto error;
3184  }
3185  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->resurrected);
3186  switch_xml_set_txt_d(time_tag, tmp);
3187 
3188  if (!(time_tag = switch_xml_add_child_d(x_times, "transfer_time", t_off++))) {
3189  goto error;
3190  }
3191  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->transferred);
3192  switch_xml_set_txt_d(time_tag, tmp);
3193  }
3194 
3195  caller_profile = caller_profile->next;
3196  }
3197 
3198  *xml_cdr = cdr;
3199 
3200  return SWITCH_STATUS_SUCCESS;
3201 
3202  error:
3203 
3204  if (cdr) {
3205  switch_xml_free(cdr);
3206  }
3207 
3208  return SWITCH_STATUS_FALSE;
3209 }
3210 
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 }
3227 
3228 #define add_jstat(_j, _i, _s) \
3229  switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_SIZE_T_FMT, _i); \
3230  cJSON_AddItemToObject(_j, _s, cJSON_CreateNumber(_i))
3231 
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 }
3303 
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 }
3332 
3333 
3334 
3336 {
3337  cJSON *cdr = cJSON_CreateObject();
3339  switch_caller_profile_t *caller_profile;
3340  cJSON *variables, *j_main_cp, *j_caller_profile, *j_caller_extension, *j_caller_extension_apps, *j_times, *j_application,
3341  *j_callflow, *j_profile, *j_inner_extension, *j_app_log, *j_apps, *j_o, *j_o_profiles, *j_channel_data, *callStats;
3342  switch_app_log_t *app_log;
3343  char tmp[512], *f;
3344 
3345  cJSON_AddItemToObject(cdr, "core-uuid", cJSON_CreateString(switch_core_get_uuid()));
3346  cJSON_AddItemToObject(cdr, "switchname", cJSON_CreateString(switch_core_get_switchname()));
3347  j_channel_data = cJSON_CreateObject();
3348 
3349  cJSON_AddItemToObject(cdr, "channel_data", j_channel_data);
3350 
3351  cJSON_AddItemToObject(j_channel_data, "state", cJSON_CreateString((char *) switch_channel_state_name(switch_channel_get_state(channel))));
3352  cJSON_AddItemToObject(j_channel_data, "direction", cJSON_CreateString(switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound"));
3353 
3354  switch_snprintf(tmp, sizeof(tmp), "%d", switch_channel_get_state(channel));
3355  cJSON_AddItemToObject(j_channel_data, "state_number", cJSON_CreateString((char *) tmp));
3356 
3357  if ((f = switch_channel_get_flag_string(channel))) {
3358  cJSON_AddItemToObject(j_channel_data, "flags", cJSON_CreateString((char *) f));
3359  free(f);
3360  }
3361 
3362  if ((f = switch_channel_get_cap_string(channel))) {
3363  cJSON_AddItemToObject(j_channel_data, "caps", cJSON_CreateString((char *) f));
3364  free(f);
3365  }
3366 
3367  callStats = cJSON_CreateObject();
3368  cJSON_AddItemToObject(cdr, "callStats", callStats);
3371 
3372  variables = cJSON_CreateObject();
3373  cJSON_AddItemToObject(cdr, "variables", variables);
3374  switch_ivr_set_json_chan_vars(variables, channel, urlencode);
3375 
3376 
3377  if ((app_log = switch_core_session_get_app_log(session))) {
3378  switch_app_log_t *ap;
3379 
3380  j_app_log = cJSON_CreateObject();
3381  j_apps = cJSON_CreateArray();
3382 
3383  cJSON_AddItemToObject(cdr, "app_log", j_app_log);
3384  cJSON_AddItemToObject(j_app_log, "applications", j_apps);
3385 
3386  for (ap = app_log; ap; ap = ap->next) {
3387  j_application = cJSON_CreateObject();
3388 
3389  cJSON_AddItemToObject(j_application, "app_name", cJSON_CreateString(ap->app));
3390  cJSON_AddItemToObject(j_application, "app_data", cJSON_CreateString(ap->arg));
3391  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, ap->stamp);
3392  cJSON_AddItemToObject(j_application, "app_stamp", cJSON_CreateString(tmp));
3393 
3394  cJSON_AddItemToArray(j_apps, j_application);
3395  }
3396  }
3397 
3398 
3399  caller_profile = switch_channel_get_caller_profile(channel);
3400 
3401  j_callflow = cJSON_CreateArray();
3402  cJSON_AddItemToObject(cdr, "callflow", j_callflow);
3403 
3404  while (caller_profile) {
3405 
3406  j_profile = cJSON_CreateObject();
3407 
3408  if (!zstr(caller_profile->dialplan)) {
3409  cJSON_AddItemToObject(j_profile, "dialplan", cJSON_CreateString((char *)caller_profile->dialplan));
3410  }
3411 
3412  if (!zstr(caller_profile->profile_index)) {
3413  cJSON_AddItemToObject(j_profile, "profile_index", cJSON_CreateString((char *)caller_profile->profile_index));
3414  }
3415 
3416  if (caller_profile->caller_extension) {
3418 
3419  j_caller_extension = cJSON_CreateObject();
3420  j_caller_extension_apps = cJSON_CreateArray();
3421 
3422  cJSON_AddItemToObject(j_profile, "extension", j_caller_extension);
3423 
3424  cJSON_AddItemToObject(j_caller_extension, "name", cJSON_CreateString(caller_profile->caller_extension->extension_name));
3425  cJSON_AddItemToObject(j_caller_extension, "number", cJSON_CreateString(caller_profile->caller_extension->extension_number));
3426  cJSON_AddItemToObject(j_caller_extension, "applications", j_caller_extension_apps);
3427 
3428  if (caller_profile->caller_extension->current_application) {
3429  cJSON_AddItemToObject(j_caller_extension, "current_app", cJSON_CreateString(caller_profile->caller_extension->current_application->application_name));
3430  }
3431 
3432  for (ap = caller_profile->caller_extension->applications; ap; ap = ap->next) {
3433  j_application = cJSON_CreateObject();
3434 
3435  cJSON_AddItemToArray(j_caller_extension_apps, j_application);
3436 
3437  if (ap == caller_profile->caller_extension->current_application) {
3438  cJSON_AddItemToObject(j_application, "last_executed", cJSON_CreateString("true"));
3439  }
3440  cJSON_AddItemToObject(j_application, "app_name", cJSON_CreateString(ap->application_name));
3441  cJSON_AddItemToObject(j_application, "app_data", cJSON_CreateString(switch_str_nil(ap->application_data)));
3442  }
3443 
3444  if (caller_profile->caller_extension->children) {
3445  switch_caller_profile_t *cp = NULL;
3446  j_inner_extension = cJSON_CreateArray();
3447  cJSON_AddItemToObject(j_caller_extension, "sub_extensions", j_inner_extension);
3448  for (cp = caller_profile->caller_extension->children; cp; cp = cp->next) {
3449 
3450  if (!cp->caller_extension) {
3451  continue;
3452  }
3453 
3454  j_caller_extension = cJSON_CreateObject();
3455  cJSON_AddItemToArray(j_inner_extension, j_caller_extension);
3456 
3457  cJSON_AddItemToObject(j_caller_extension, "name", cJSON_CreateString(cp->caller_extension->extension_name));
3458  cJSON_AddItemToObject(j_caller_extension, "number", cJSON_CreateString(cp->caller_extension->extension_number));
3459 
3460  cJSON_AddItemToObject(j_caller_extension, "dialplan", cJSON_CreateString((char *)cp->dialplan));
3461 
3463  cJSON_AddItemToObject(j_caller_extension, "current_app", cJSON_CreateString(cp->caller_extension->current_application->application_name));
3464  }
3465 
3466  j_caller_extension_apps = cJSON_CreateArray();
3467  cJSON_AddItemToObject(j_caller_extension, "applications", j_caller_extension_apps);
3468  for (ap = cp->caller_extension->applications; ap; ap = ap->next) {
3469  j_application = cJSON_CreateObject();
3470  cJSON_AddItemToArray(j_caller_extension_apps, j_application);
3471 
3472  if (ap == cp->caller_extension->current_application) {
3473  cJSON_AddItemToObject(j_application, "last_executed", cJSON_CreateString("true"));
3474  }
3475  cJSON_AddItemToObject(j_application, "app_name", cJSON_CreateString(ap->application_name));
3476  cJSON_AddItemToObject(j_application, "app_data", cJSON_CreateString(switch_str_nil(ap->application_data)));
3477  }
3478  }
3479  }
3480  }
3481 
3482  j_main_cp = cJSON_CreateObject();
3483  cJSON_AddItemToObject(j_profile, "caller_profile", j_main_cp);
3484 
3485  switch_ivr_set_json_profile_data(j_main_cp, caller_profile);
3486 
3487  if (caller_profile->originator_caller_profile) {
3488  switch_caller_profile_t *cp = NULL;
3489 
3490  j_o = cJSON_CreateObject();
3491  cJSON_AddItemToObject(j_main_cp, "originator", j_o);
3492 
3493  j_o_profiles = cJSON_CreateArray();
3494  cJSON_AddItemToObject(j_o, "originator_caller_profiles", j_o_profiles);
3495 
3496  for (cp = caller_profile->originator_caller_profile; cp; cp = cp->next) {
3497  j_caller_profile = cJSON_CreateObject();
3498  cJSON_AddItemToArray(j_o_profiles, j_caller_profile);
3499 
3500  switch_ivr_set_json_profile_data(j_caller_profile, cp);
3501  }
3502  }
3503 
3504  if (caller_profile->originatee_caller_profile) {
3505  switch_caller_profile_t *cp = NULL;
3506 
3507  j_o = cJSON_CreateObject();
3508  cJSON_AddItemToObject(j_main_cp, "originatee", j_o);
3509 
3510  j_o_profiles = cJSON_CreateArray();
3511  cJSON_AddItemToObject(j_o, "originatee_caller_profiles", j_o_profiles);
3512 
3513  for (cp = caller_profile->originatee_caller_profile; cp; cp = cp->next) {
3514  j_caller_profile = cJSON_CreateObject();
3515  cJSON_AddItemToArray(j_o_profiles, j_caller_profile);
3516 
3517  switch_ivr_set_json_profile_data(j_caller_profile, cp);
3518  }
3519  }
3520 
3521  if (caller_profile->times) {
3522 
3523  j_times = cJSON_CreateObject();
3524  cJSON_AddItemToObject(j_profile, "times", j_times);
3525 
3526  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->created);
3527  cJSON_AddItemToObject(j_times, "created_time", cJSON_CreateString(tmp));
3528 
3529  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->profile_created);
3530  cJSON_AddItemToObject(j_times, "profile_created_time", cJSON_CreateString(tmp));
3531 
3532  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress);
3533  cJSON_AddItemToObject(j_times, "progress_time", cJSON_CreateString(tmp));
3534 
3535  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress_media);
3536  cJSON_AddItemToObject(j_times, "progress_media_time", cJSON_CreateString(tmp));
3537 
3538  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
3539  cJSON_AddItemToObject(j_times, "answered_time", cJSON_CreateString(tmp));
3540 
3541  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->bridged);
3542  cJSON_AddItemToObject(j_times, "bridged_time", cJSON_CreateString(tmp));
3543 
3544  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->last_hold);
3545  cJSON_AddItemToObject(j_times, "last_hold_time", cJSON_CreateString(tmp));
3546 
3547  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hold_accum);
3548  cJSON_AddItemToObject(j_times, "hold_accum_time", cJSON_CreateString(tmp));
3549 
3550  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
3551  cJSON_AddItemToObject(j_times, "hangup_time", cJSON_CreateString(tmp));
3552 
3553  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->resurrected);
3554  cJSON_AddItemToObject(j_times, "resurrect_time", cJSON_CreateString(tmp));
3555 
3556  switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->transferred);
3557  cJSON_AddItemToObject(j_times, "transfer_time", cJSON_CreateString(tmp));
3558 
3559  }
3560  cJSON_AddItemToArray(j_callflow, j_profile);
3561  caller_profile = caller_profile->next;
3562  }
3563 
3564  *json_cdr = cdr;
3565 
3566  return SWITCH_STATUS_SUCCESS;
3567 
3568 }
3569 
3570 
3572 {
3576 
3577 }
3578 
3580 {
3581  switch_jb_t *jb;
3582  int qlen = 0;
3583  switch_frame_t *read_frame, write_frame = { 0 };
3584  switch_status_t status;
3586  uint32_t interval;
3587  uint32_t ts = 0;
3588  uint16_t seq = 0;
3589  switch_codec_implementation_t read_impl = { 0 };
3590  int is_rtp = 0;
3591  int debug = 0;
3592  const char *var;
3593 
3594 
3595  switch_core_session_get_read_impl(session, &read_impl);
3596 
3597  if (delay_ms < 1 || delay_ms > 10000) {
3598  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid delay [%d] must be between 1 and 10000\n", delay_ms);
3599  return;
3600  }
3601 
3602  interval = read_impl.microseconds_per_packet / 1000;
3603 
3604  if (delay_ms < interval * 2) {
3605  delay_ms = interval * 2;
3606  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Minimum possible delay for this codec (%d) has been chosen\n", delay_ms);
3607  }
3608 
3609  qlen = delay_ms / (interval);
3610  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting delay to %dms (%d frames)\n", delay_ms, qlen);
3611 
3612  switch_jb_create(&jb, SJB_AUDIO, qlen, qlen, switch_core_session_get_pool(session));
3613 
3614  if ((var = switch_channel_get_variable(channel, "delay_echo_debug_level"))) {
3615  debug = atoi(var);
3616  }
3617 
3618  if (debug) {
3619  switch_jb_debug_level(jb, debug);
3620  }
3621 
3622  write_frame.codec = switch_core_session_get_read_codec(session);
3623 
3624  while (switch_channel_ready(channel)) {
3625  switch_rtp_packet_t packet = { {0} };
3626  switch_size_t plen = sizeof(packet);
3627 
3628  status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
3629 
3630  if (!SWITCH_READ_ACCEPTABLE(status)) {
3631  break;
3632  }
3633 
3634  if (switch_test_flag(read_frame, SFF_CNG)) {
3635  continue;
3636  }
3637 
3638  if (read_frame->packet) {
3639  is_rtp = 1;
3640  switch_jb_put_packet(jb, (switch_rtp_packet_t *) read_frame->packet, read_frame->packetlen);
3641  } else if (is_rtp) {
3642  continue;
3643  } else {
3644  ts += read_impl.samples_per_packet;
3645  memcpy(packet.body, read_frame->data, read_frame->datalen);
3646  packet.header.ts = htonl(ts);
3647  packet.header.seq = htons(++seq);
3648  packet.header.version = 2;
3649  }
3650 
3651  if (switch_jb_get_packet(jb, (switch_rtp_packet_t *) &packet, &plen) == SWITCH_STATUS_SUCCESS) {
3652  write_frame.data = packet.body;
3653  write_frame.datalen = (uint32_t) plen - 12;
3654  write_frame.buflen = (uint32_t) plen;
3655 
3656  status = switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
3657 
3658  if (!SWITCH_READ_ACCEPTABLE(status)) {
3659  break;
3660  }
3661  }
3662  }
3663 
3664  switch_jb_destroy(&jb);
3665 }
3666 
3668  const char *tosay,
3669  const char *module_name,
3670  const char *say_type,
3671  const char *say_method,
3672  const char *say_gender,
3673  switch_input_args_t *args)
3674 {
3676  switch_channel_t *channel;
3678  const char *save_path = NULL, *chan_lang = NULL, *lang = NULL, *sound_path = NULL;
3679  switch_event_t *hint_data;
3680  switch_xml_t cfg, xml = NULL, language = NULL, macros = NULL, phrases = NULL;
3681  char *p;
3682 
3683  switch_assert(session);
3684  channel = switch_core_session_get_channel(session);
3685  switch_assert(channel);
3686 
3688 
3689 
3690  if (zstr(module_name)) {
3691  module_name = "en";
3692  }
3693 
3694  if (module_name) {
3695  char *p;
3696  p = switch_core_session_strdup(session, module_name);
3697  module_name = p;
3698 
3699  if ((p = strchr(module_name, ':'))) {
3700  *p++ = '\0';
3701  chan_lang = p;
3702  }
3703  }
3704 
3705  if (!chan_lang) {
3706  lang = switch_channel_get_variable(channel, "language");
3707 
3708  if (!lang) {
3709  chan_lang = switch_channel_get_variable(channel, "default_language");
3710  if (!chan_lang) {
3711  chan_lang = module_name;
3712  }
3713  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "No language specified - Using [%s]\n", chan_lang);
3714  } else {
3715  chan_lang = lang;
3716  }
3717  }
3718 
3720  switch_assert(hint_data);
3721 
3722  switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "macro_name", "say_app");
3723  switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "lang", chan_lang);
3724  switch_channel_event_set_data(channel, hint_data);
3725 
3726  if (switch_xml_locate_language(&xml, &cfg, hint_data, &language, &phrases, &macros, chan_lang) != SWITCH_STATUS_SUCCESS) {
3727  goto done;
3728  }
3729 
3730  if ((p = (char *) switch_xml_attr(language, "say-module"))) {
3731  module_name = switch_core_session_strdup(session, p);
3732  } else if ((p = (char *) switch_xml_attr(language, "module"))) {
3733  module_name = switch_core_session_strdup(session, p);
3734  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Deprecated usage of module attribute\n");
3735  } else {
3736  module_name = chan_lang;
3737  }
3738 
3739  if (!(sound_path = (char *) switch_xml_attr(language, "sound-prefix"))) {
3740  if (!(sound_path = (char *) switch_xml_attr(language, "sound-path"))) {
3741  sound_path = (char *) switch_xml_attr(language, "sound_path");
3742  }
3743  }
3744 
3745  if (channel) {
3746  const char *p = switch_channel_get_variable(channel, "sound_prefix_enforced");
3747  if (!switch_true(p)) {
3748  save_path = switch_channel_get_variable(channel, "sound_prefix");
3749  if (sound_path) {
3750  switch_channel_set_variable(channel, "sound_prefix", sound_path);
3751  }
3752  }
3753  }
3754 
3755  if ((si = switch_loadable_module_get_say_interface(module_name))) {
3756  /* should go back and proto all the say mods to const.... */
3757  switch_say_args_t say_args = {0};
3758 
3759  say_args.type = switch_ivr_get_say_type_by_name(say_type);
3760  say_args.method = switch_ivr_get_say_method_by_name(say_method);
3761  say_args.gender = switch_ivr_get_say_gender_by_name(say_gender);
3762 
3763  status = si->say_function(session, (char *) tosay, &say_args, args);
3764  } else {
3765  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid SAY Interface [%s]!\n", module_name);
3766  status = SWITCH_STATUS_FALSE;
3767  }
3768 
3769  done:
3770 
3772 
3773 
3774  if (hint_data) {
3775  switch_event_destroy(&hint_data);
3776  }
3777 
3778  if (save_path) {
3779  switch_channel_set_variable(channel, "sound_prefix", save_path);
3780  }
3781 
3782  if (xml) {
3783  switch_xml_free(xml);
3784  }
3785 
3786  return status;
3787 }
3788 
3790  const char *lang,
3791  const char *ext,
3792  const char *tosay,
3793  const char *module_name,
3794  const char *say_type,
3795  const char *say_method,
3796  const char *say_gender,
3797  char **rstr)
3798 {
3800  switch_channel_t *channel = NULL;
3802  const char *save_path = NULL, *chan_lang = NULL, *sound_path = NULL;
3803  switch_event_t *hint_data;
3804  switch_xml_t cfg, xml = NULL, language = NULL, macros = NULL, phrases = NULL;
3805 
3806  if (session) {
3807  channel = switch_core_session_get_channel(session);
3808 
3809  if (!lang) {
3810  lang = switch_channel_get_variable(channel, "language");
3811 
3812  if (!lang) {
3813  chan_lang = switch_channel_get_variable(channel, "default_language");
3814  if (!chan_lang) {
3815  chan_lang = "en";
3816  }
3817  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "No language specified - Using [%s]\n", chan_lang);
3818  } else {
3819  chan_lang = lang;
3820  }
3821  }
3822  }
3823 
3824  if (!lang) lang = "en";
3825  if (!chan_lang) chan_lang = lang;
3826 
3828  switch_assert(hint_data);
3829 
3830  switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "macro_name", "say_app");
3831  switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "lang", chan_lang);
3832 
3833  if (channel) {
3834  switch_channel_event_set_data(channel, hint_data);
3835  }
3836 
3837  if (switch_xml_locate_language(&xml, &cfg, hint_data, &language, &phrases, &macros, chan_lang) != SWITCH_STATUS_SUCCESS) {
3838  goto done;
3839  }
3840 
3841  if ((module_name = switch_xml_attr(language, "say-module"))) {
3842  } else if ((module_name = switch_xml_attr(language, "module"))) {
3843  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Deprecated usage of module attribute\n");
3844  } else {
3845  module_name = chan_lang;
3846  }
3847 
3848  if (!(sound_path = (char *) switch_xml_attr(language, "sound-prefix"))) {
3849  if (!(sound_path = (char *) switch_xml_attr(language, "sound-path"))) {
3850  sound_path = (char *) switch_xml_attr(language, "sound_path");
3851  }
3852  }
3853 
3854  if (channel) {
3855  const char *p = switch_channel_get_variable(channel, "sound_prefix_enforced");
3856  if (!switch_true(p)) {
3857  save_path = switch_channel_get_variable(channel, "sound_prefix");
3858  if (sound_path) {
3859  switch_channel_set_variable(channel, "sound_prefix", sound_path);
3860  }
3861  }
3862  }
3863 
3864  if ((si = switch_loadable_module_get_say_interface(module_name)) && si->say_string_function) {
3865  /* should go back and proto all the say mods to const.... */
3866  switch_say_args_t say_args = {0};
3867 
3868  say_args.type = switch_ivr_get_say_type_by_name(say_type);
3869  say_args.method = switch_ivr_get_say_method_by_name(say_method);
3870  say_args.gender = switch_ivr_get_say_gender_by_name(say_gender);
3871  say_args.ext = ext;
3872  status = si->say_string_function(session, (char *) tosay, &say_args, rstr);
3873  } else {
3874  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid SAY Interface [%s]!\n", module_name);
3875  status = SWITCH_STATUS_FALSE;
3876  }
3877 
3878  done:
3879 
3880  if (hint_data) {
3881  switch_event_destroy(&hint_data);
3882  }
3883 
3884  if (save_path && channel) {
3885  switch_channel_set_variable(channel, "sound_prefix", save_path);
3886  }
3887 
3888  if (xml) {
3889  switch_xml_free(xml);
3890  }
3891 
3892  return status;
3893 }
3894 
3895 
3896 static const char *get_prefixed_str(char *buffer, size_t buffer_size, const char *prefix, size_t prefix_size, const char *str)
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 }
3920 
3922  const char *user, const char *domain, switch_xml_t x_user)
3923 {
3924  switch_xml_t x_params, x_param;
3925  char *number_alias;
3928 
3929  char *prefix_buffer = NULL;
3930  size_t buffer_size = 0;
3931  size_t prefix_size = 0;
3932 
3933 
3934  status = SWITCH_STATUS_SUCCESS;
3935 
3936  if (!zstr(prefix)) {
3937  prefix_size = strlen(prefix);
3938  buffer_size = 1024 + prefix_size + 1;
3939  prefix_buffer = switch_core_session_alloc(session, buffer_size);
3940  }
3941 
3942  if ((number_alias = (char *) switch_xml_attr(x_user, "number-alias"))) {
3943  switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, "number_alias"), number_alias);
3944  }
3945 
3946  if ((x_params = switch_xml_child(x_user, "variables"))) {
3947  for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
3948  const char *var = switch_xml_attr(x_param, "name");
3949  const char *val = switch_xml_attr(x_param, "value");
3950 
3951  if (var && val) {
3952  switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, var), val);
3953  }
3954  }
3955  }
3956 
3957  if (switch_channel_get_caller_profile(channel) && (x_params = switch_xml_child(x_user, "profile-variables"))) {
3958  for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
3959  const char *var = switch_xml_attr(x_param, "name");
3960  const char *val = switch_xml_attr(x_param, "value");
3961 
3962  if (var && val) {
3963  switch_channel_set_profile_var(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, var), val);
3964  }
3965  }
3966  }
3967 
3968  if (user && domain) {
3969  switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, "user_name"), user);
3970  switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, "domain_name"), domain);
3971  }
3972 
3973  return status;
3974 }
3975 
3977 {
3978  return switch_ivr_set_user_extended(session, data, NULL);
3979 }
3980 
3982 {
3983  switch_xml_t x_user = 0;
3984  char *user, *domain;
3986 
3987  char *prefix;
3988 
3989  if (zstr(data)) {
3990  goto error;
3991  }
3992 
3993  user = switch_core_session_strdup(session, data);
3994 
3995  if ((prefix = strchr(user, ' '))) {
3996  *prefix++ = 0;
3997  }
3998 
3999  if (!(domain = strchr(user, '@'))) {
4000  goto error;
4001  }
4002 
4003  *domain++ = '\0';
4004 
4005  if (switch_xml_locate_user_merged("id", user, domain, NULL, &x_user, params) != SWITCH_STATUS_SUCCESS) {
4006  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", user, domain);
4007  goto done;
4008  }
4009 
4010  status = switch_ivr_set_user_xml(session, prefix, user, domain, x_user);
4011 
4012  goto done;
4013 
4014  error:
4015  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No user@domain specified.\n");
4016 
4017  done:
4018 
4019  if (x_user) {
4020  switch_xml_free(x_user);
4021  }
4022 
4023  return status;
4024 }
4025 
4027 {
4028  switch_bool_t exists = SWITCH_FALSE;
4029  switch_core_session_t *psession = NULL;
4030 
4031  if ((psession = switch_core_session_locate(uuid))) {
4032  switch_core_session_rwunlock(psession);
4033  exists = 1;
4034  }
4035 
4036  return exists;
4037 }
4038 
4040 {
4041  switch_bool_t exists = SWITCH_FALSE;
4042  switch_core_session_t *psession = NULL;
4043 
4044  if ((psession = switch_core_session_force_locate(uuid))) {
4045  switch_core_session_rwunlock(psession);
4046  exists = 1;
4047  }
4048 
4049  return exists;
4050 }
4051 
4053 {
4054  if (zstr(cmd)) {
4055  return SWITCH_STATUS_SUCCESS;
4056  }
4057 
4058  if (fhp) {
4059  if (!switch_test_flag(fhp, SWITCH_FILE_OPEN)) {
4060  return SWITCH_STATUS_FALSE;
4061  }
4062 
4063  if (!strncasecmp(cmd, "speed", 5)) {
4064  char *p;
4065 
4066  if ((p = strchr(cmd, ':'))) {
4067  p++;
4068  if (*p == '+' || *p == '-') {
4069  int step;
4070  if (!(step = atoi(p))) {
4071  step = 1;
4072  }
4073  fhp->speed += step;
4074  } else {
4075  int speed = atoi(p);
4076  fhp->speed = speed;
4077  }
4078  return SWITCH_STATUS_SUCCESS;
4079  }
4080 
4081  return SWITCH_STATUS_FALSE;
4082 
4083  } else if (!strncasecmp(cmd, "volume", 6)) {
4084  char *p;
4085 
4086  if ((p = strchr(cmd, ':'))) {
4087  p++;
4088  if (*p == '+' || *p == '-') {
4089  int step;
4090  if (!(step = atoi(p))) {
4091  step = 1;
4092  }
4093  fhp->vol += step;
4094  } else {
4095  int vol = atoi(p);
4096  fhp->vol = vol;
4097  }
4098  return SWITCH_STATUS_SUCCESS;
4099  }
4100 
4101  if (fhp->vol) {
4103  }
4104 
4105  return SWITCH_STATUS_FALSE;
4106  } else if (!strcasecmp(cmd, "pause")) {
4107  if (switch_test_flag(fhp, SWITCH_FILE_PAUSE)) {
4109  } else {
4111  }
4112 
4114 
4115  return SWITCH_STATUS_SUCCESS;
4116  } else if (!strcasecmp(cmd, "stop")) {
4118  return SWITCH_STATUS_FALSE;
4119  } else if (!strcasecmp(cmd, "truncate")) {
4120  switch_core_file_truncate(fhp, 0);
4121  } else if (!strcasecmp(cmd, "restart")) {
4122  unsigned int pos = 0;
4123  fhp->speed = 0;
4124  switch_core_file_seek(fhp, &pos, 0, SEEK_SET);
4125  return SWITCH_STATUS_SUCCESS;
4126  } else if (!strncasecmp(cmd, "seek", 4)) {
4127  //switch_codec_t *codec;
4128  unsigned int samps = 0;
4129  unsigned int pos = 0;
4130  char *p;
4131  //codec = switch_core_session_get_read_codec(session);
4132 
4133  if ((p = strchr(cmd, ':'))) {
4134  p++;
4135  if (*p == '+' || *p == '-') {
4136  int step;
4137  int32_t target;
4138  if (!(step = atoi(p))) {
4139  step = 1000;
4140  }
4141 
4142  samps = step * (fhp->native_rate / 1000);
4143  target = (int32_t)fhp->offset_pos + samps;
4144 
4145  if (target < 0) {
4146  target = 0;
4147  }
4148 
4149  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "seek to position %d\n", target);
4150  switch_core_file_seek(fhp, &pos, target, SEEK_SET);
4151 
4152  } else {
4153  samps = switch_atoui(p) * (fhp->native_rate / 1000);
4154  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "seek to position %d\n", samps);
4155  switch_core_file_seek(fhp, &pos, samps, SEEK_SET);
4156  }
4157  }
4158 
4159  return SWITCH_STATUS_SUCCESS;
4160  }
4161  }
4162 
4163  if (!strcmp(cmd, "true") || !strcmp(cmd, "undefined")) {
4164  return SWITCH_STATUS_SUCCESS;
4165  }
4166 
4167  return SWITCH_STATUS_FALSE;
4168 
4169 }
4170 
4171 #define START_SAMPLES 32768
4172 
4173 SWITCH_DECLARE(switch_status_t) switch_ivr_insert_file(switch_core_session_t *session, const char *file, const char *insert_file, switch_size_t sample_point)
4174 {
4175  switch_file_handle_t orig_fh = { 0 };
4176  switch_file_handle_t new_fh = { 0 };
4177  switch_codec_implementation_t read_impl = { 0 };
4178  char *tmp_file;
4179  switch_uuid_t uuid;
4180  char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
4181  int16_t *abuf = NULL;
4182  switch_size_t olen = 0;
4183  int asis = 0;
4185  switch_size_t sample_count = 0;
4186  uint32_t pos = 0;
4187  char *ext;
4188 
4189  switch_uuid_get(&uuid);
4190  switch_uuid_format(uuid_str, &uuid);
4191 
4192  if ((ext = strrchr(file, '.'))) {
4193  ext++;
4194  } else {
4195  ext = "wav";
4196  }
4197 
4198  tmp_file = switch_core_session_sprintf(session, "%s%smsg_%s.%s",
4200 
4201  switch_core_session_get_read_impl(session, &read_impl);
4202 
4203  new_fh.channels = read_impl.number_of_channels;
4204  new_fh.native_rate = read_impl.actual_samples_per_second;
4205 
4206 
4207  if (switch_core_file_open(&new_fh,
4208  tmp_file,
4209  new_fh.channels,
4211  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to open file %s\n", tmp_file);
4212  goto end;
4213  }
4214 
4215 
4216  if (switch_core_file_open(&orig_fh,
4217  file,
4218  new_fh.channels,
4220  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to open file %s\n", file);
4221  goto end;
4222  }
4223 
4224 
4225  switch_zmalloc(abuf, START_SAMPLES * sizeof(*abuf));
4226 
4227  if (switch_test_flag((&orig_fh), SWITCH_FILE_NATIVE)) {
4228  asis = 1;
4229  }
4230 
4231  while (switch_channel_ready(channel)) {
4232  olen = START_SAMPLES;
4233 
4234  if (!asis) {
4235  olen /= 2;
4236  }
4237 
4238  if ((sample_count + olen) > sample_point) {
4239  olen = sample_point - sample_count;
4240  }
4241 
4242  if (!olen || switch_core_file_read(&orig_fh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) {
4243  break;
4244  }
4245 
4246  sample_count += olen;
4247 
4248  switch_core_file_write(&new_fh, abuf, &olen);
4249  }
4250 
4251  switch_core_file_close(&orig_fh);
4252 
4253 
4254  if (switch_core_file_open(&orig_fh,
4255  insert_file,
4256  new_fh.channels,
4258  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to open file %s\n", file);
4259  goto end;
4260  }
4261 
4262 
4263  while (switch_channel_ready(channel)) {
4264  olen = START_SAMPLES;
4265 
4266  if (!asis) {
4267  olen /= 2;
4268  }
4269 
4270  if (switch_core_file_read(&orig_fh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) {
4271  break;
4272  }
4273 
4274  sample_count += olen;
4275 
4276  switch_core_file_write(&new_fh, abuf, &olen);
4277  }
4278 
4279  switch_core_file_close(&orig_fh);
4280 
4281  if (switch_core_file_open(&orig_fh,
4282  file,
4283  new_fh.channels,
4285  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to open file %s\n", file);
4286  goto end;
4287  }
4288 
4289  pos = 0;
4290  switch_core_file_seek(&orig_fh, &pos, sample_point, SEEK_SET);
4291 
4292  while (switch_channel_ready(channel)) {
4293  olen = START_SAMPLES;
4294 
4295  if (!asis) {
4296  olen /= 2;
4297  }
4298 
4299  if (switch_core_file_read(&orig_fh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) {
4300  break;
4301  }
4302 
4303  sample_count += olen;
4304 
4305  switch_core_file_write(&new_fh, abuf, &olen);
4306  }
4307 
4308  end:
4309 
4310  if (switch_test_flag((&orig_fh), SWITCH_FILE_OPEN)) {
4311  switch_core_file_close(&orig_fh);
4312  }
4313 
4314  if (switch_test_flag((&new_fh), SWITCH_FILE_OPEN)) {
4315  switch_core_file_close(&new_fh);
4316  }
4317 
4318  switch_file_rename(tmp_file, file, switch_core_session_get_pool(session));
4319  unlink(tmp_file);
4320 
4321  switch_safe_free(abuf);
4322 
4323  return SWITCH_STATUS_SUCCESS;
4324 }
4325 
4326 
4328 {
4330 
4331  if ((status = switch_event_dup_reply(reply, message) != SWITCH_STATUS_SUCCESS)) {
4332  abort();
4333  }
4334 
4335  switch_event_add_header_string(*reply, SWITCH_STACK_BOTTOM, "proto", new_proto);
4336 
4337  return status;
4338 }
4339 
4340 SWITCH_DECLARE(char *) switch_ivr_check_presence_mapping(const char *exten_name, const char *domain_name)
4341 {
4342  char *cf = "presence_map.conf";
4343  switch_xml_t cfg, xml, x_domains, x_domain, x_exten;
4344  char *r = NULL;
4345  switch_event_t *params = NULL;
4346  switch_regex_t *re = NULL;
4347  int proceed = 0, ovector[100];
4348 
4350  switch_assert(params);
4351 
4352  if ( !zstr(domain_name) ) {
4353  switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "domain", domain_name);
4354  }
4355 
4356  if ( !zstr(exten_name) ) {
4357  switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "exten", exten_name);
4358  }
4359 
4360  if (!(xml = switch_xml_open_cfg(cf, &cfg, params))) {
4361  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
4362  goto end;
4363  }
4364 
4365  if (!(x_domains = switch_xml_child(cfg, "domains"))) {
4366  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find any domains!\n");
4367  goto end;
4368  }
4369 
4370  for (x_domain = switch_xml_child(x_domains, "domain"); x_domain; x_domain = x_domain->next) {
4371  const char *dname = switch_xml_attr(x_domain, "name");
4372  if (!dname || (strcasecmp(dname, "*") && strcasecmp(domain_name, dname))) continue;
4373 
4374  for (x_exten = switch_xml_child(x_domain, "exten"); x_exten; x_exten = x_exten->next) {
4375  const char *regex = switch_xml_attr(x_exten, "regex");
4376  const char *proto = switch_xml_attr(x_exten, "proto");
4377 
4378  if (!zstr(regex) && !zstr(proto)) {
4379  proceed = switch_regex_perform(exten_name, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0]));
4381 
4382  if (proceed) {
4383  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Mapping %s@%s to proto %s matching expression [%s]\n",
4384  exten_name, domain_name, proto, regex);
4385  r = strdup(proto);
4386  goto end;
4387  }
4388 
4389  }
4390  }
4391  }
4392 
4393  end:
4394  switch_event_destroy(&params);
4395 
4396  if (xml) {
4397  switch_xml_free(xml);
4398  }
4399 
4400  return r;
4401 
4402 }
4403 
4405 {
4406  switch_core_session_t *session;
4407 
4408  if (zstr(uuid) || !(session = switch_core_session_locate(uuid))) {
4409  return SWITCH_STATUS_FALSE;
4410  } else {
4412  switch_channel_hangup(channel, cause);
4414  return SWITCH_STATUS_SUCCESS;
4415  }
4416 }
4417 
4419 {
4422 
4424  switch_core_session_t *other_session;
4425  const char *uuid = switch_channel_get_variable(channel, "blind_transfer_uuid");
4426 
4428 
4429  if (!zstr(uuid) && (other_session = switch_core_session_locate(uuid))) {
4430  switch_core_session_message_t msg = { 0 };
4432  msg.from = __FILE__;
4433  msg.numeric_arg = success;
4434  switch_core_session_receive_message(other_session, &msg);
4435  switch_core_session_rwunlock(other_session);
4436  status = SWITCH_STATUS_SUCCESS;
4437  }
4438  }
4439 
4440  return status;
4441 
4442 }
4443 
4444 /* For Emacs:
4445  * Local Variables:
4446  * mode:c
4447  * indent-tabs-mode:t
4448  * tab-width:4
4449  * c-basic-offset:4
4450  * End:
4451  * For VIM:
4452  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
4453  */
#define switch_event_prep_for_delivery(_event)
Definition: switch_event.h:243
char * switch_channel_get_cap_string(switch_channel_t *channel)
switch_status_t switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt,...)
switch_xml_t switch_xml_set_attr_d_buf(switch_xml_t xml, const char *name, const char *value)
Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL.
Definition: switch_xml.c:3085
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_status_t switch_ivr_digit_stream_reset(switch_ivr_digit_stream_t *stream)
Reset the collected digit stream to nothing.
Definition: switch_ivr.c:2571
#define SWITCH_SIGNAL_BRIDGE_VARIABLE
Definition: switch_types.h:202
switch_time_t stamp
Definition: switch_core.h:62
const char * uuid
Definition: switch_ivr.c:2088
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
const char * switch_core_get_switchname(void)
Definition: switch_core.c:361
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_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
switch_status_t switch_jb_get_packet(switch_jb_t *jb, switch_rtp_packet_t *packet, switch_size_t *len)
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it&#39;s state machine to end.
#define switch_regex_safe_free(re)
Definition: switch_regex.h:79
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
#define switch_channel_answer(channel)
Answer a channel (initiate/acknowledge a successful connection)
switch_status_t switch_channel_execute_on(switch_channel_t *channel, const char *variable_prefix)
switch_size_t flaws
Definition: switch_types.h:712
int switch_ivr_set_xml_profile_data(switch_xml_t xml, switch_caller_profile_t *caller_profile, int off)
Definition: switch_ivr.c:2599
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core&#39;s master pool.
Definition: switch_core.h:633
void switch_channel_set_flag_recursive(switch_channel_t *channel, switch_channel_flag_t flag)
switch_sockaddr_t * local_addr
Definition: switch_ivr.h:57
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_status_t switch_channel_set_profile_var(switch_channel_t *channel, const char *name, const char *val)
Set a variable on a given channel.
unsigned int switch_atoui(const char *nptr)
switch_socket_t * socket
Definition: switch_ivr.h:52
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
void switch_ivr_bg_media(const char *uuid, switch_media_flag_t flags, switch_bool_t on, switch_bool_t is3p, uint32_t delay)
Definition: switch_ivr.c:2121
switch_status_t switch_ivr_digit_stream_parser_set_terminator(switch_ivr_digit_stream_parser_t *parser, char digit)
Set a digit string terminator.
Definition: switch_ivr.c:2584
switch_status_t switch_ivr_process_fh(switch_core_session_t *session, const char *cmd, switch_file_handle_t *fhp)
Definition: switch_ivr.c:4052
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define switch_core_session_force_locate(uuid_str)
Locate a session based on it&#39;s uuid even if the channel is not ready.
Definition: switch_core.h:941
switch_say_type_t switch_ivr_get_say_type_by_name(const char *name)
An Abstract Representation of a dialplan extension.
switch_say_type_t type
Call Specific Data.
Definition: switch_caller.h:73
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
switch_rtp_numbers_t inbound
Definition: switch_types.h:760
#define SWITCH_THREAD_FUNC
switch_status_t switch_ivr_set_user(switch_core_session_t *session, const char *data)
Definition: switch_ivr.c:3976
switch_rtp_stats_t * switch_core_media_get_stats(switch_core_session_t *session, switch_media_type_t type, switch_memory_pool_t *pool)
void switch_ivr_delay_echo(switch_core_session_t *session, uint32_t delay_ms)
Definition: switch_ivr.c:3579
switch_core_session_message_types_t message_id
Definition: switch_core.h:183
#define SWITCH_CHANNEL_LOG
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.
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
switch_status_t switch_ivr_dmachine_feed(switch_ivr_dmachine_t *dmachine, const char *digits, switch_ivr_dmachine_match_t **match)
switch_status_t switch_ivr_parse_all_signal_data(switch_core_session_t *session)
Definition: switch_ivr.c:905
switch_xml_t switch_xml_set_attr_d(switch_xml_t xml, const char *name, const char *value)
Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL.
Definition: switch_xml.c:3077
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
struct switch_hold_record_s * next
Definition: switch_core.h:78
switch_say_callback_t say_function
const char * switch_xml_attr(_In_opt_ switch_xml_t xml, _In_opt_z_ const char *attr)
returns the value of the requested tag attribute, or NULL if not found
switch_status_t switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa)
Definition: switch_apr.c:742
switch_status_t switch_ivr_process_indications(switch_core_session_t *session, switch_core_session_message_t *message)
Definition: switch_ivr.c:813
const char * switch_channel_get_partner_uuid(switch_channel_t *channel)
#define switch_core_hash_init(_hash)
Definition: switch_core.h:1431
#define switch_channel_set_state(channel, state)
Set the current state of a channel.
switch_status_t switch_channel_set_private(switch_channel_t *channel, const char *key, const void *private_info)
Set private data on channel.
switch_hold_record_t * switch_channel_get_hold_record(switch_channel_t *channel)
#define switch_core_file_open(_fh, _file_path, _channels, _rate, _flags, _pool)
Open a media file using file format modules.
Definition: switch_core.h:1963
#define SWITCH_MAX_STACKS
Definition: switch_types.h:583
#define SWITCH_TRANSFER_SOURCE_VARIABLE
Definition: switch_types.h:145
switch_bool_t switch_ivr_uuid_exists(const char *uuid)
Definition: switch_ivr.c:4026
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.
Definition: switch_ivr.c:127
struct switch_caller_profile * originatee_caller_profile
switch_status_t switch_ivr_session_transfer(switch_core_session_t *session, const char *extension, const char *dialplan, const char *context)
Definition: switch_ivr.c:2163
switch_rtp_hdr_t header
Definition: switch_rtp.h:56
void switch_core_media_set_smode(switch_core_session_t *session, switch_media_type_t type, switch_media_flow_t smode, switch_sdp_type_t sdp_type)
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_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.
Definition: switch_ivr.c:1225
#define SWITCH_RECOMMENDED_BUFFER_SIZE
Definition: switch_types.h:590
void switch_channel_event_set_data(_In_ switch_channel_t *channel, _In_ switch_event_t *event)
Add information about a given channel to an event object.
switch_status_t switch_xml_locate_language(switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_xml_t *language, switch_xml_t *phrases, switch_xml_t *macros, const char *str_language)
Definition: switch_xml.c:3356
cJSON *const to
static int switch_ivr_set_xml_chan_var(switch_xml_t xml, const char *var, const char *val, int off)
Definition: switch_ivr.c:2814
switch_bool_t
Definition: switch_types.h:437
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
static void switch_ivr_set_json_profile_data(cJSON *json, switch_caller_profile_t *caller_profile)
Definition: switch_ivr.c:3211
switch_size_t largest_jb_size
Definition: switch_types.h:692
struct error_period * next
Definition: switch_types.h:677
switch_status_t switch_ivr_digit_stream_destroy(switch_ivr_digit_stream_t **stream)
Destroys a digit stream object.
Definition: switch_ivr.c:2447
switch_status_t switch_xml_locate_user_merged(const char *key, const char *user_name, const char *domain_name, const char *ip, switch_xml_t *user, switch_event_t *params)
Definition: switch_xml.c:2145
switch_status_t switch_ivr_unhold_uuid(const char *uuid)
Signal the session with a protocol specific unhold message.
Definition: switch_ivr.c:1646
const char * network_addr
Definition: switch_caller.h:93
switch_status_t switch_core_file_command(switch_file_handle_t *fh, switch_file_command_t command)
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.
switch_say_gender_t switch_ivr_get_say_gender_by_name(const char *name)
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:683
switch_say_method_t method
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
switch_memory_pool_t * pool
Representation of an event.
Definition: switch_event.h:80
switch_status_t switch_core_file_close(_In_ switch_file_handle_t *fh)
Close an open file handle.
#define fail()
Definition: tone2wav.c:70
#define switch_channel_ready(_channel)
switch_say_string_callback_t say_string_function
#define arg_recursion_check_stop(_args)
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.
Definition: switch_ivr.c:1525
An event Header.
Definition: switch_event.h:65
An Abstract Representation of a dialplan Application.
void switch_core_session_free_message(switch_core_session_message_t **message)
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.
switch_status_t switch_ivr_park(switch_core_session_t *session, switch_input_args_t *args)
Definition: switch_ivr.c:946
void switch_channel_set_caller_profile(switch_channel_t *channel, switch_caller_profile_t *caller_profile)
Set the given channel&#39;s caller profile.
void switch_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t channels, uint32_t divisor)
Generate static noise.
#define switch_channel_media_ready(_channel)
switch_status_t switch_core_file_seek(_In_ switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples, int whence)
Seek a position in a file.
switch_bool_t switch_ivr_uuid_force_exists(const char *uuid)
Definition: switch_ivr.c:4039
switch_status_t switch_ivr_insert_file(switch_core_session_t *session, const char *file, const char *insert_file, switch_size_t sample_point)
Definition: switch_ivr.c:4173
switch_sockaddr_t * remote_addr
Definition: switch_ivr.h:58
switch_status_t switch_core_codec_decode(switch_codec_t *codec, switch_codec_t *other_codec, void *encoded_data, uint32_t encoded_data_len, uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
Decode data using a codec handle.
A representation of an XML tree.
Definition: switch_xml.h:79
switch_memory_pool_t * pool
Definition: switch_core.h:71
switch_status_t switch_core_codec_destroy(switch_codec_t *codec)
Destroy an initalized codec handle.
struct switch_caller_profile * next
const char * string_array_arg[MESSAGE_STRING_ARG_MAX]
Definition: switch_core.h:211
const char * switch_channel_state_name(_In_ switch_channel_state_t state)
Render the name of the provided state enum.
#define START_SAMPLES
Definition: switch_ivr.c:4171
switch_status_t switch_socket_recv(switch_socket_t *sock, char *buf, switch_size_t *len)
Definition: switch_apr.c:805
#define switch_core_session_get_name(_s)
Definition: switch_core.h:265
switch_status_t switch_jb_put_packet(switch_jb_t *jb, switch_rtp_packet_t *packet, switch_size_t len)
switch_status_t switch_core_file_read(_In_ switch_file_handle_t *fh, void *data, switch_size_t *len)
Read media from a file handle.
switch_status_t switch_jb_destroy(switch_jb_t **jbp)
switch_size_t media_bytes
Definition: switch_types.h:683
struct real_pcre switch_regex_t
Definition: switch_regex.h:43
const char * dialplan
Definition: switch_caller.h:77
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
switch_status_t switch_ivr_parse_all_events(switch_core_session_t *session)
Parse all commands from an event.
Definition: switch_ivr.c:913
switch_event_header_t * switch_channel_variable_first(switch_channel_t *channel)
Start iterating over the entries in the channel variable list.
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
switch_size_t dtmf_packet_count
Definition: switch_types.h:689
static switch_thread_t * thread
Definition: switch_log.c:486
char * switch_channel_get_flag_string(switch_channel_t *channel)
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
static const char * get_prefixed_str(char *buffer, size_t buffer_size, const char *prefix, size_t prefix_size, const char *str)
Definition: switch_ivr.c:3896
int switch_ivr_set_xml_call_stats(switch_xml_t xml, switch_core_session_t *session, int off, switch_media_type_t type)
Definition: switch_ivr.c:2715
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.
IVR Library.
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.
uint32_t flaws
Definition: switch_types.h:675
switch_codec_t * codec
Definition: switch_frame.h:56
A message object designed to allow unlike technologies to exchange data.
Definition: switch_core.h:179
uint8_t switch_byte_t
Definition: switch_types.h:256
const char * username
Definition: switch_caller.h:75
#define zstr(x)
Definition: switch_utils.h:314
switch_codec_t * switch_core_session_get_read_codec(_In_ switch_core_session_t *session)
Retrieve the read codec from a given session.
#define SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE
Definition: switch_types.h:131
#define SWITCH_PARK_AFTER_BRIDGE_VARIABLE
Definition: switch_types.h:220
struct switch_caller_application * next
switch_memory_pool_t * pool
Definition: switch_ivr.c:2087
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.
switch_status_t switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
#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.
switch_status_t switch_ivr_parse_next_event(switch_core_session_t *session)
Definition: switch_ivr.c:796
#define SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE
Definition: switch_types.h:219
switch_status_t switch_file_rename(const char *from_path, const char *to_path, switch_memory_pool_t *pool)
Definition: switch_apr.c:447
switch_status_t switch_ivr_blind_transfer_ack(switch_core_session_t *session, switch_bool_t success)
Definition: switch_ivr.c:4418
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
void switch_channel_wait_for_state(switch_channel_t *channel, switch_channel_t *other_channel, switch_channel_state_t want_state)
static void unicast_thread_launch(switch_unicast_conninfo_t *conninfo)
Definition: switch_ivr.c:361
switch_status_t switch_ivr_kill_uuid(const char *uuid, switch_call_cause_t cause)
Definition: switch_ivr.c:4404
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:124
Definition: cJSON.c:68
int64_t switch_time_t
Definition: switch_apr.h:188
const switch_codec_implementation_t * implementation
uint32_t buflen
Definition: switch_frame.h:70
switch_port_t remote_port
Definition: switch_ivr.h:56
switch_xml_t next
Definition: switch_xml.h:91
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...
Definition: switch_ivr.c:1342
switch_rtcp_numbers_t rtcp
Definition: switch_types.h:762
switch_byte_t switch_byte_t * buf
int64_t stop
Definition: switch_types.h:674
if((uint32_t)(unpack->cur - unpack->buf) > unpack->buflen)
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
#define switch_channel_audio_sync(_c)
SWITCH_BEGIN_EXTERN_C switch_status_t switch_jb_create(switch_jb_t **jbp, switch_jb_type_t type, uint32_t min_frame_len, uint32_t max_frame_len, switch_memory_pool_t *pool)
switch_size_t raw_bytes
Definition: switch_types.h:682
uint32_t datalen
Definition: switch_frame.h:68
#define switch_normalize_volume(x)
const char * switch_channel_get_hold_music(switch_channel_t *channel)
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.
Definition: switch_ivr.c:2503
char * switch_core_get_uuid(void)
Retrieve the unique identifier from the core.
Definition: switch_core.c:495
uint32_t packetlen
Definition: switch_frame.h:62
switch_bool_t on
Definition: switch_ivr.c:2090
switch_status_t switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
Definition: switch_apr.c:796
static switch_bool_t switch_is_moh(const char *s)
Definition: switch_utils.h:319
switch_status_t switch_ivr_parse_event(switch_core_session_t *session, switch_event_t *event)
Definition: switch_ivr.c:503
Abstract interface to a say module.
const char * callee_id_number
Definition: switch_caller.h:89
switch_status_t switch_core_session_dequeue_signal_data(switch_core_session_t *session, void **signal_data)
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)
char * switch_event_get_body(switch_event_t *event)
Retrieve the body value from an event.
Definition: switch_event.c:867
uint32_t delay
Definition: switch_ivr.c:2092
intptr_t switch_ssize_t
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
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_THREAD_STACKSIZE
Definition: switch_types.h:584
switch_status_t switch_channel_dequeue_dtmf(_In_ switch_channel_t *channel, _In_ switch_dtmf_t *dtmf)
Retrieve DTMF digits from a given channel.
switch_caller_application_t * applications
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_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.
Definition: switch_ivr.c:2373
#define switch_zmalloc(ptr, len)
switch_codec_t read_codec
Definition: switch_ivr.h:49
const char * caller_id_name
Definition: switch_caller.h:79
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
#define add_stat(_x, _i, _s)
Definition: switch_ivr.c:2705
switch_rtp_numbers_t outbound
Definition: switch_types.h:761
switch_thread_start_t func
Definition: switch_core.h:67
switch_xml_t switch_xml_new(_In_opt_z_ const char *name)
returns a new empty switch_xml structure with the given root tag name
switch_status_t switch_ivr_uuid_bridge(const char *originator_uuid, const char *originatee_uuid)
Bridge two existing sessions.
struct switch_caller_profile * children
#define switch_channel_ring_ready(channel)
Send Ringing message to a channel.
uint32_t switch_core_session_flush_private_events(switch_core_session_t *session)
Flush the private event queue of a session.
switch_input_callback_function_t input_callback
switch_status_t switch_channel_get_variables(switch_channel_t *channel, switch_event_t **event)
switch_status_t switch_ivr_hold_toggle_uuid(const char *uuid, const char *message, switch_bool_t moh)
Toggles channel hold state of session.
Definition: switch_ivr.c:1580
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
switch_status_t switch_core_session_dequeue_private_event(_In_ switch_core_session_t *session, _Out_ switch_event_t **event)
DE-Queue a private event on a given session.
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1379
#define SWITCH_TIME_T_FMT
switch_call_cause_t switch_channel_str2cause(_In_ const char *str)
return a cause code for a given string
switch_time_t last_digit_time
Definition: switch_ivr.c:2370
#define SWITCH_IVR_VERIFY_SILENCE_DIVISOR(divisor)
Definition: switch_ivr.h:68
struct profile_node_s * next
Definition: switch_caller.h:66
struct switch_caller_profile * origination_caller_profile
switch_time_t profile_created
An abstraction of a data frame.
Definition: switch_frame.h:54
uintptr_t switch_size_t
#define arg_recursion_check_start(_args)
#define switch_set_flag_locked(obj, flag)
Set a flag on an arbitrary object while locked.
Definition: switch_utils.h:707
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
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.
Definition: switch_ivr.c:2318
static void *SWITCH_THREAD_FUNC media_thread_run(switch_thread_t *thread, void *obj)
Definition: switch_ivr.c:2095
switch_byte_t switch_byte_t uint32_t buflen
#define switch_core_codec_init(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, _flags, _codec_settings, _pool)
Initialize a codec handle.
Definition: switch_core.h:1693
switch_status_t switch_ivr_send_prompt(switch_core_session_t *session, const char *type, const char *text, const char *regex)
Definition: switch_ivr.c:1510
const char * profile_index
void switch_cond_next(void)
Definition: switch_time.c:658
uint32_t consecutive_flaws
Definition: switch_types.h:676
struct switch_caller_profile * originator_caller_profile
#define SWITCH_STANDARD_STREAM(s)
const char * switch_channel_get_hold_music_partner(switch_channel_t *channel)
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.
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
switch_channel_callstate_t
switch_say_gender_t gender
switch_size_t packet_count
Definition: switch_types.h:684
#define SWITCH_BRIDGE_VARIABLE
Definition: switch_types.h:200
switch_call_cause_t
switch_caller_application_t * current_application
switch_status_t switch_ivr_sound_test(switch_core_session_t *session)
Definition: switch_ivr.c:41
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_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key)
Delete data from a hash based on desired key.
switch_mutex_t * flag_mutex
Definition: switch_ivr.h:59
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.
Definition: switch_ivr.c:2461
switch_thread_t * thread
Definition: switch_ivr.h:64
#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.
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.
Definition: switch_ivr.c:2518
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:82
#define add_stat_double(_x, _i, _s)
Definition: switch_ivr.c:2710
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
switch_size_t jb_packet_count
Definition: switch_types.h:688
switch_read_frame_callback_function_t read_frame_callback
switch_status_t switch_ivr_parse_next_signal_data(switch_core_session_t *session)
Definition: switch_ivr.c:909
switch_status_t switch_channel_set_variable_var_check(switch_channel_t *channel, const char *varname, const char *value, switch_bool_t var_check)
uint32_t switch_channel_test_cap(switch_channel_t *channel, switch_channel_cap_t cap)
switch_size_t skip_packet_count
Definition: switch_types.h:687
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.
Definition: switch_ivr.c:2431
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:993
char * switch_ivr_check_presence_mapping(const char *exten_name, const char *domain_name)
Definition: switch_ivr.c:4340
switch_frame_t write_frame
Definition: switch_ivr.h:50
void switch_jb_debug_level(switch_jb_t *jb, uint8_t level)
void switch_ivr_park_session(switch_core_session_t *session)
Definition: switch_ivr.c:3571
switch_media_flow_t switch_core_session_media_flow(switch_core_session_t *session, switch_media_type_t type)
void switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
Definition: switch_apr.c:1140
#define SWITCH_R_SDP_VARIABLE
Definition: switch_types.h:197
void * packet
Definition: switch_frame.h:60
switch_status_t switch_ivr_3p_nomedia(const char *uuid, switch_media_flag_t flags)
Definition: switch_ivr.c:1881
switch_status_t switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
Definition: switch_apr.c:727
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
#define switch_clear_flag_locked(obj, flag)
Clear a flag on an arbitrary object.
Definition: switch_utils.h:717
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.
Definition: switch_ivr.c:3335
switch_status_t
Common return values.
switch_status_t switch_core_file_write(_In_ switch_file_handle_t *fh, void *data, switch_size_t *len)
Write media to a file handle.
void * switch_channel_get_private(switch_channel_t *channel, const char *key)
Retrieve private from a given channel.
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:287
const cJSON *const target
struct error_period * error_log
Definition: switch_types.h:716
switch_status_t switch_core_session_dequeue_event(_In_ switch_core_session_t *session, _Out_ switch_event_t **event, switch_bool_t force)
DE-Queue an event on a given session.
switch_say_interface_t * switch_loadable_module_get_say_interface(const char *name)
Retrieve the say interface by it&#39;s registered name.
switch_status_t switch_ivr_unhold(switch_core_session_t *session)
Signal the session with a protocol specific unhold message.
Definition: switch_ivr.c:1603
struct switch_event_header * next
Definition: switch_event.h:76
#define SWITCH_SIGNAL_BOND_VARIABLE
Definition: switch_types.h:203
switch_xml_t switch_xml_open_cfg(_In_z_ const char *file_path, _Out_ switch_xml_t *node, _In_opt_ switch_event_t *params)
open a config in the core registry
switch_status_t switch_ivr_create_message_reply(switch_event_t **reply, switch_event_t *message, const char *new_proto)
Definition: switch_ivr.c:4327
void switch_channel_variable_last(switch_channel_t *channel)
Stop iterating over channel variables.
switch_status_t switch_socket_close(switch_socket_t *sock)
Definition: switch_apr.c:737
switch_size_t switch_channel_has_dtmf(_In_ switch_channel_t *channel)
Test for presence of DTMF on a given channel.
#define SWITCH_UNSPEC
Definition: switch_apr.h:1022
switch_status_t switch_event_dup_reply(switch_event_t **event, switch_event_t *todup)
#define switch_core_hash_insert(_h, _k, _d)
Definition: switch_core.h:1479
switch_status_t switch_socket_shutdown(switch_socket_t *sock, switch_shutdown_how_e how)
Definition: switch_apr.c:732
#define switch_core_session_locate(uuid_str)
Locate a session based on it&#39;s uuid.
Definition: switch_core.h:932
char body[SWITCH_RTP_MAX_BUF_LEN+4+sizeof(char *)]
Definition: switch_rtp.h:57
Main Library Header.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
switch_status_t switch_ivr_parse_signal_data(switch_core_session_t *session, switch_bool_t all, switch_bool_t only_session_thread)
Definition: switch_ivr.c:869
switch_size_t flush_packet_count
Definition: switch_types.h:691
#define SWITCH_DECLARE(type)
uint32_t samples
Definition: switch_frame.h:72
#define SWITCH_TEMP_HOLD_MUSIC_VARIABLE
Definition: switch_types.h:194
unsigned int switch_hashfunc_default(const char *key, switch_ssize_t *klen)
Definition: switch_apr.c:143
void switch_uuid_get(switch_uuid_t *uuid)
Definition: switch_apr.c:1152
switch_status_t switch_core_session_dequeue_message(_In_ switch_core_session_t *session, _Out_ switch_core_session_message_t **message)
DE-Queue an message on a given session.
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)
switch_xml_t switch_xml_child(_In_ switch_xml_t xml, _In_z_ const char *name)
returns the first child tag (one level deeper) with the given name or NULL \ if not found ...
switch_status_t switch_core_file_truncate(switch_file_handle_t *fh, int64_t offset)
switch_core_session_t * session
Definition: switch_ivr.h:48
switch_port_t local_port
Definition: switch_ivr.h:54
switch_size_t media_packet_count
Definition: switch_types.h:686
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
switch_app_log_t * switch_core_session_get_app_log(_In_ switch_core_session_t *session)
struct switch_channel_timetable * times
int switch_ivr_set_xml_chan_vars(switch_xml_t xml, switch_channel_t *channel, int off)
Definition: switch_ivr.c:2838
switch_status_t switch_ivr_dmachine_ping(switch_ivr_dmachine_t *dmachine, switch_ivr_dmachine_match_t **match_p)
#define SWITCH_TRANSFER_HISTORY_VARIABLE
Definition: switch_types.h:144
char * buffer
Definition: switch_cJSON.h:153
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
Definition: switch_time.c:322
const char * caller_id_number
Definition: switch_caller.h:81
switch_say_method_t switch_ivr_get_say_method_by_name(const char *name)
#define switch_core_session_alloc(_session, _memory)
Allocate memory from a session&#39;s pool.
Definition: switch_core.h:696
uint32_t switch_media_flag_t
Definition: switch_types.h:509
const char * switch_core_session_get_text_buffer(switch_core_session_t *session)
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
void switch_ivr_check_hold(switch_core_session_t *session)
Definition: switch_ivr.c:2143
void switch_channel_clear_flag_recursive(switch_channel_t *channel, switch_channel_flag_t flag)
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
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.
profile_node_t * soft
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
A table of settings and callbacks that define a paticular implementation of a codec.
int debug
Definition: switch_msrp.c:57
switch_channel_callstate_t switch_channel_get_callstate(switch_channel_t *channel)
struct fspr_pool_t switch_memory_pool_t
switch_media_flag_t flags
Definition: switch_ivr.c:2089
const char *const name
Definition: switch_cJSON.h:250
#define SWITCH_MAX_SESSION_TRANSFERS_VARIABLE
Definition: switch_types.h:231
#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_ivr_deactivate_unicast(switch_core_session_t *session)
Definition: switch_ivr.c:371
void switch_event_destroy(switch_event_t **event)
Destroy an event.
static void switch_ivr_set_json_chan_vars(cJSON *json, switch_channel_t *channel, switch_bool_t urlencode)
Definition: switch_ivr.c:3304
switch_bool_t is3p
Definition: switch_ivr.c:2091
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.
switch_status_t switch_ivr_set_user_extended(switch_core_session_t *session, const char *data, switch_event_t *params)
Definition: switch_ivr.c:3981
switch_status_t switch_ivr_signal_bridge(switch_core_session_t *session, switch_core_session_t *peer_session)
Bridge Signalling from one session to another.
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 ...
switch_status_t switch_ivr_3p_media(const char *uuid, switch_media_flag_t flags)
Definition: switch_ivr.c:1663
#define switch_assert(expr)
struct fspr_thread_t switch_thread_t
Definition: switch_apr.h:941
#define SWITCH_MAX_FORWARDS_VARIABLE
Definition: switch_types.h:226
#define switch_channel_set_variable(_channel, _var, _val)
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)
Definition: switch_ivr.c:3667
switch_status_t switch_sockaddr_info_get(switch_sockaddr_t **sa, const char *hostname, int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:839
switch_status_t switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t *xml_cdr)
Generate an XML CDR report.
Definition: switch_ivr.c:2862
#define switch_channel_pre_answer(channel)
Indicate progress on a channel to attempt early media.
switch_caller_profile_t * switch_channel_get_caller_profile(switch_channel_t *channel)
Retrieve the given channel&#39;s caller profile.
#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_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.
Definition: switch_ivr.c:1567
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
#define SWITCH_READ_ACCEPTABLE(status)
memset(buf, 0, buflen)
#define switch_channel_media_up(_channel)
switch_byte_t write_frame_data[SWITCH_RECOMMENDED_BUFFER_SIZE]
Definition: switch_ivr.h:51
const char * callee_id_name
Definition: switch_caller.h:87
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)
Definition: switch_ivr.c:3789
const char * ext
switch_bool_t switch_core_session_in_thread(switch_core_session_t *session)
void switch_ivr_set_json_call_stats(cJSON *json, switch_core_session_t *session, switch_media_type_t type)
Definition: switch_ivr.c:3232
switch_memory_pool_t * switch_core_session_get_pool(_In_ switch_core_session_t *session)
Retrieve the memory pool from a session.
switch_time_t progress_media
switch_status_t switch_ivr_digit_stream_parser_destroy(switch_ivr_digit_stream_parser_t *parser)
Destroy a digit stream parser object.
Definition: switch_ivr.c:2413
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)
Definition: switch_ivr.c:3921
#define SWITCH_UUID_FORMATTED_LENGTH
Definition: switch_apr.h:545
switch_event_header_t * headers
Definition: switch_event.h:90
switch_memory_pool_t * pool
Definition: switch_ivr.c:2359
switch_ivr_dmachine_t * dmachine
struct switch_app_log * next
Definition: switch_core.h:63
struct switch_caller_extension * caller_extension
static void *SWITCH_THREAD_FUNC unicast_thread_run(switch_thread_t *thread, void *obj)
Definition: switch_ivr.c:336
switch_status_t switch_thread_pool_launch_thread(switch_thread_data_t **tdp)
switch_size_t cng_packet_count
Definition: switch_types.h:690
#define add_jstat(_j, _i, _s)
Definition: switch_ivr.c:3228
switch_status_t switch_ivr_parse_all_messages(switch_core_session_t *session)
Definition: switch_ivr.c:847
switch_memory_pool_t * pool
uint32_t switch_core_session_stack_count(switch_core_session_t *session, int x)
switch_media_type_t