2006-01-26 13:00:27 -05:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
2009-02-04 16:20:54 -05:00
|
|
|
* Copyright (C) 2005/2006, Anthony Minessale II <anthm@freeswitch.org>
|
2006-01-26 13:00:27 -05:00
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2009-02-04 16:20:54 -05:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2006-01-26 13:00:27 -05:00
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
2009-02-04 16:20:54 -05:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2006-10-28 00:40:59 -04:00
|
|
|
* Paul D. Tinsley <pdt at jackhammer.org>
|
2006-11-13 11:29:16 -05:00
|
|
|
* Neal Horman <neal at wanlink dot com>
|
2006-11-29 15:07:13 -05:00
|
|
|
* Matt Klein <mklein@nmedia.net>
|
2007-02-02 23:09:43 -05:00
|
|
|
* Michael Jerris <mike@jerris.com>
|
2008-01-16 17:13:36 -05:00
|
|
|
* Ken Rice <krice at suspicious dot org>
|
2006-01-26 13:00:27 -05:00
|
|
|
*
|
2006-12-04 00:41:03 -05:00
|
|
|
* switch_ivr.c -- IVR Library
|
2006-01-26 13:00:27 -05:00
|
|
|
*
|
|
|
|
*/
|
2008-01-27 12:36:53 -05:00
|
|
|
|
2006-01-26 13:00:27 -05:00
|
|
|
#include <switch.h>
|
|
|
|
#include <switch_ivr.h>
|
2007-10-04 11:09:44 -04:00
|
|
|
#include "stfu.h"
|
2006-10-25 00:28:49 -04:00
|
|
|
|
2008-12-09 19:48:24 -05:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_bool_t sync, switch_input_args_t *args)
|
2006-07-13 09:20:20 -04:00
|
|
|
{
|
2008-01-28 02:26:10 -05:00
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
2006-07-13 09:20:20 -04:00
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
2009-01-25 16:23:07 -05:00
|
|
|
switch_time_t start = switch_micro_time_now(), now, done = switch_micro_time_now() + (ms * 1000);
|
2008-10-03 14:14:11 -04:00
|
|
|
switch_frame_t *read_frame, cng_frame = { 0 };
|
2006-07-13 09:20:20 -04:00
|
|
|
int32_t left, elapsed;
|
2008-10-03 14:14:11 -04:00
|
|
|
char data[2] = "";
|
|
|
|
|
2008-12-08 19:32:51 -05:00
|
|
|
switch_frame_t write_frame = { 0 };
|
|
|
|
unsigned char *abuf = NULL;
|
|
|
|
switch_codec_implementation_t imp = {0};
|
|
|
|
switch_codec_t codec = { 0 };
|
|
|
|
int sval = 0;
|
|
|
|
const char *var;
|
2009-01-06 17:39:48 -05:00
|
|
|
|
2009-02-03 15:33:24 -05:00
|
|
|
/*
|
2009-01-19 11:00:11 -05:00
|
|
|
if (!switch_channel_test_flag(channel, CF_OUTBOUND) && !switch_channel_test_flag(channel, CF_PROXY_MODE) &&
|
|
|
|
!switch_channel_media_ready(channel) && !switch_channel_test_flag(channel, CF_SERVICE)) {
|
2009-01-06 17:39:48 -05:00
|
|
|
if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot establish media.\n");
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2009-02-03 15:33:24 -05:00
|
|
|
*/
|
2009-01-06 17:39:48 -05:00
|
|
|
|
2009-01-19 11:00:11 -05:00
|
|
|
if (!switch_channel_media_ready(channel)) {
|
|
|
|
switch_yield(ms * 1000);
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ms > 100 && (var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
|
2008-12-08 19:32:51 -05:00
|
|
|
switch_core_session_get_read_impl(session, &imp);
|
2009-01-06 16:07:58 -05:00
|
|
|
|
2008-12-08 19:32:51 -05:00
|
|
|
if (switch_core_codec_init(&codec,
|
|
|
|
"L16",
|
|
|
|
NULL,
|
|
|
|
imp.samples_per_second,
|
|
|
|
imp.microseconds_per_packet / 1000,
|
|
|
|
imp.number_of_channels,
|
|
|
|
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
|
|
|
|
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
|
|
|
|
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n",
|
|
|
|
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
|
|
|
|
|
|
|
|
write_frame.codec = &codec;
|
|
|
|
switch_zmalloc(abuf, SWITCH_RECOMMENDED_BUFFER_SIZE);
|
|
|
|
write_frame.data = abuf;
|
|
|
|
write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
|
|
|
|
write_frame.datalen = imp.decoded_bytes_per_packet;
|
|
|
|
write_frame.samples = write_frame.datalen / sizeof(int16_t);
|
2008-12-09 19:48:24 -05:00
|
|
|
|
2008-12-08 19:32:51 -05:00
|
|
|
}
|
|
|
|
|
2009-01-06 18:26:49 -05:00
|
|
|
if (!write_frame.datalen) {
|
|
|
|
sval = 0;
|
|
|
|
}
|
|
|
|
|
2008-10-03 14:14:11 -04:00
|
|
|
cng_frame.data = data;
|
|
|
|
cng_frame.datalen = 2;
|
|
|
|
cng_frame.buflen = 2;
|
2008-11-26 13:56:37 -05:00
|
|
|
switch_set_flag((&cng_frame), SFF_CNG);
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2009-01-19 11:00:11 -05:00
|
|
|
if (sync) {
|
2008-12-01 11:21:27 -05:00
|
|
|
switch_channel_audio_sync(channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ms) {
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2008-11-26 23:02:57 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
for (;;) {
|
2009-01-25 16:23:07 -05:00
|
|
|
now = switch_micro_time_now();
|
2007-03-29 18:31:56 -04:00
|
|
|
elapsed = (int32_t) ((now - start) / 1000);
|
2006-07-13 09:20:20 -04:00
|
|
|
left = ms - elapsed;
|
|
|
|
|
|
|
|
if (!switch_channel_ready(channel)) {
|
|
|
|
status = SWITCH_STATUS_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2008-07-08 15:26:44 -04:00
|
|
|
|
|
|
|
if (switch_channel_test_flag(channel, CF_BREAK)) {
|
|
|
|
switch_channel_clear_flag(channel, CF_BREAK);
|
|
|
|
status = SWITCH_STATUS_BREAK;
|
|
|
|
break;
|
|
|
|
}
|
2006-07-13 09:20:20 -04:00
|
|
|
|
|
|
|
if (now > done || left <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
2008-07-08 13:27:02 -04:00
|
|
|
|
2008-07-08 19:13:02 -04:00
|
|
|
if (switch_core_session_private_event_count(session)) {
|
|
|
|
switch_ivr_parse_all_events(session);
|
|
|
|
}
|
|
|
|
|
2008-07-08 13:27:02 -04:00
|
|
|
if (args && (args->input_callback || args->buf || args->buflen)) {
|
|
|
|
switch_dtmf_t dtmf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
dtmf handler function you can hook up to be executed when a digit is dialed during playback
|
|
|
|
if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
|
|
|
|
*/
|
|
|
|
if (switch_channel_has_dtmf(channel)) {
|
|
|
|
if (!args->input_callback && !args->buf) {
|
|
|
|
status = SWITCH_STATUS_BREAK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch_channel_dequeue_dtmf(channel, &dtmf);
|
|
|
|
if (args->input_callback) {
|
|
|
|
status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen);
|
|
|
|
} else {
|
|
|
|
switch_copy_string((char *) args->buf, (void *) &dtmf, args->buflen);
|
|
|
|
status = SWITCH_STATUS_BREAK;
|
|
|
|
}
|
|
|
|
}
|
2008-07-08 19:13:02 -04:00
|
|
|
|
2008-07-08 13:27:02 -04:00
|
|
|
if (args->input_callback) {
|
|
|
|
switch_event_t *event = NULL;
|
|
|
|
|
|
|
|
if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
status = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen);
|
|
|
|
switch_event_destroy(&event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != SWITCH_STATUS_SUCCESS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-07-13 09:20:20 -04:00
|
|
|
|
2009-01-06 17:39:48 -05:00
|
|
|
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
|
|
|
|
|
|
|
|
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
|
|
|
break;
|
2006-07-13 09:20:20 -04:00
|
|
|
}
|
2008-10-03 14:14:11 -04:00
|
|
|
|
2009-01-06 18:26:49 -05:00
|
|
|
if (sval && write_frame.datalen) {
|
2008-12-08 19:32:51 -05:00
|
|
|
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, sval);
|
|
|
|
switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
|
|
|
|
} else {
|
|
|
|
switch_core_session_write_frame(session, &cng_frame, SWITCH_IO_FLAG_NONE, 0);
|
|
|
|
}
|
|
|
|
}
|
2009-01-06 17:39:48 -05:00
|
|
|
|
2008-12-08 19:32:51 -05:00
|
|
|
if (write_frame.codec) {
|
|
|
|
switch_core_codec_destroy(&codec);
|
2006-07-13 09:20:20 -04:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2008-12-08 19:32:51 -05:00
|
|
|
switch_safe_free(abuf);
|
|
|
|
|
2006-07-13 09:20:20 -04:00
|
|
|
return status;
|
|
|
|
}
|
2006-01-26 13:00:27 -05:00
|
|
|
|
2007-04-09 14:38:47 -04:00
|
|
|
static void *SWITCH_THREAD_FUNC unicast_thread_run(switch_thread_t *thread, void *obj)
|
|
|
|
{
|
|
|
|
switch_unicast_conninfo_t *conninfo = (switch_unicast_conninfo_t *) obj;
|
2007-04-10 17:18:33 -04:00
|
|
|
switch_size_t len;
|
2007-04-09 14:38:47 -04:00
|
|
|
switch_channel_t *channel;
|
|
|
|
|
|
|
|
if (!conninfo) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel = switch_core_session_get_channel(conninfo->session);
|
2008-05-27 00:30:03 -04:00
|
|
|
|
|
|
|
while (switch_test_flag(conninfo, SUF_READY) && switch_test_flag(conninfo, SUF_THREAD_RUNNING)) {
|
2007-04-09 14:38:47 -04:00
|
|
|
len = conninfo->write_frame.buflen;
|
|
|
|
if (switch_socket_recv(conninfo->socket, conninfo->write_frame.data, &len) != SWITCH_STATUS_SUCCESS || len == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
conninfo->write_frame.datalen = (uint32_t) len;
|
2007-04-09 14:38:47 -04:00
|
|
|
conninfo->write_frame.samples = conninfo->write_frame.datalen / 2;
|
2008-05-08 15:19:47 -04:00
|
|
|
switch_core_session_write_frame(conninfo->session, &conninfo->write_frame, SWITCH_IO_FLAG_NONE, conninfo->stream_id);
|
2007-04-09 14:38:47 -04:00
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-04-09 14:38:47 -04:00
|
|
|
switch_clear_flag_locked(conninfo, SUF_READY);
|
|
|
|
switch_clear_flag_locked(conninfo, SUF_THREAD_RUNNING);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unicast_thread_launch(switch_unicast_conninfo_t *conninfo)
|
|
|
|
{
|
|
|
|
switch_thread_t *thread;
|
|
|
|
switch_threadattr_t *thd_attr = NULL;
|
|
|
|
|
|
|
|
switch_threadattr_create(&thd_attr, switch_core_session_get_pool(conninfo->session));
|
|
|
|
switch_threadattr_detach_set(thd_attr, 1);
|
|
|
|
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
|
|
|
|
switch_set_flag_locked(conninfo, SUF_THREAD_RUNNING);
|
|
|
|
switch_thread_create(&thread, thd_attr, unicast_thread_run, conninfo, switch_core_session_get_pool(conninfo->session));
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_deactivate_unicast(switch_core_session_t *session)
|
|
|
|
{
|
2008-01-28 02:26:10 -05:00
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
2007-04-09 14:38:47 -04:00
|
|
|
switch_unicast_conninfo_t *conninfo;
|
|
|
|
int sanity = 0;
|
|
|
|
|
2007-12-10 23:21:54 -05:00
|
|
|
if (!switch_channel_test_flag(channel, CF_UNICAST)) {
|
2008-05-27 00:30:03 -04:00
|
|
|
return SWITCH_STATUS_FALSE;
|
2007-12-10 23:21:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((conninfo = switch_channel_get_private(channel, "unicast"))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Shutting down unicast connection\n");
|
|
|
|
switch_clear_flag_locked(conninfo, SUF_READY);
|
|
|
|
switch_socket_shutdown(conninfo->socket, SWITCH_SHUTDOWN_READWRITE);
|
2008-05-27 00:30:03 -04:00
|
|
|
while (switch_test_flag(conninfo, SUF_THREAD_RUNNING)) {
|
2007-12-10 23:21:54 -05:00
|
|
|
switch_yield(10000);
|
|
|
|
if (++sanity >= 10000) {
|
|
|
|
break;
|
2007-04-13 12:24:02 -04:00
|
|
|
}
|
2007-04-09 14:38:47 -04:00
|
|
|
}
|
2007-12-10 23:21:54 -05:00
|
|
|
if (conninfo->read_codec.implementation) {
|
|
|
|
switch_core_codec_destroy(&conninfo->read_codec);
|
|
|
|
}
|
|
|
|
switch_socket_close(conninfo->socket);
|
2007-04-09 14:38:47 -04:00
|
|
|
}
|
2007-12-10 23:21:54 -05:00
|
|
|
switch_channel_clear_flag(channel, CF_UNICAST);
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2007-04-09 14:38:47 -04:00
|
|
|
}
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_t *session,
|
2007-04-09 14:38:47 -04:00
|
|
|
char *local_ip,
|
2007-04-10 13:34:53 -04:00
|
|
|
switch_port_t local_port,
|
2008-05-27 00:30:03 -04:00
|
|
|
char *remote_ip, switch_port_t remote_port, char *transport, char *flags)
|
2007-04-09 14:38:47 -04:00
|
|
|
{
|
2008-01-28 02:26:10 -05:00
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
|
|
|
switch_unicast_conninfo_t *conninfo = switch_core_session_alloc(session, sizeof(*conninfo));
|
2007-04-09 14:38:47 -04:00
|
|
|
switch_codec_t *read_codec;
|
|
|
|
|
2007-12-11 14:23:57 -05:00
|
|
|
switch_assert(conninfo != NULL);
|
2007-04-09 14:38:47 -04:00
|
|
|
|
|
|
|
conninfo->local_ip = switch_core_session_strdup(session, local_ip);
|
|
|
|
conninfo->local_port = local_port;
|
|
|
|
|
|
|
|
conninfo->remote_ip = switch_core_session_strdup(session, remote_ip);
|
|
|
|
conninfo->remote_port = remote_port;
|
|
|
|
conninfo->session = session;
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-04-09 14:38:47 -04:00
|
|
|
if (!strcasecmp(transport, "udp")) {
|
|
|
|
conninfo->type = AF_INET;
|
|
|
|
conninfo->transport = SOCK_DGRAM;
|
|
|
|
} else if (!strcasecmp(transport, "tcp")) {
|
|
|
|
conninfo->type = AF_INET;
|
|
|
|
conninfo->transport = SOCK_STREAM;
|
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid transport %s\n", transport);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2007-04-13 12:24:02 -04:00
|
|
|
if (flags) {
|
|
|
|
if (strstr(flags, "native")) {
|
|
|
|
switch_set_flag(conninfo, SUF_NATIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-09 14:38:47 -04:00
|
|
|
switch_mutex_init(&conninfo->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-04-09 14:38:47 -04:00
|
|
|
read_codec = switch_core_session_get_read_codec(session);
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-04-13 12:24:02 -04:00
|
|
|
if (!switch_test_flag(conninfo, SUF_NATIVE)) {
|
|
|
|
if (switch_core_codec_init(&conninfo->read_codec,
|
|
|
|
"L16",
|
|
|
|
NULL,
|
2007-10-19 11:31:02 -04:00
|
|
|
read_codec->implementation->actual_samples_per_second,
|
2008-10-20 13:48:42 -04:00
|
|
|
read_codec->implementation->microseconds_per_packet / 1000,
|
2007-04-13 12:24:02 -04:00
|
|
|
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
|
|
|
|
NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
|
|
|
"Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
|
2008-10-20 13:48:42 -04:00
|
|
|
read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_packet / 1000);
|
2007-04-13 12:24:02 -04:00
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
|
2008-10-20 13:48:42 -04:00
|
|
|
read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_packet / 1000);
|
2007-04-13 12:24:02 -04:00
|
|
|
goto fail;
|
|
|
|
}
|
2007-04-09 14:38:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
conninfo->write_frame.data = conninfo->write_frame_data;
|
|
|
|
conninfo->write_frame.buflen = sizeof(conninfo->write_frame_data);
|
2007-04-13 12:24:02 -04:00
|
|
|
conninfo->write_frame.codec = switch_test_flag(conninfo, SUF_NATIVE) ? read_codec : &conninfo->read_codec;
|
2007-04-09 14:38:47 -04:00
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "connect %s:%d->%s:%d\n",
|
|
|
|
conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port);
|
|
|
|
|
|
|
|
if (switch_sockaddr_info_get(&conninfo->local_addr,
|
2008-05-27 00:30:03 -04:00
|
|
|
conninfo->local_ip, SWITCH_UNSPEC, conninfo->local_port, 0,
|
2007-04-09 14:38:47 -04:00
|
|
|
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
|
|
|
if (switch_sockaddr_info_get(&conninfo->remote_addr,
|
2007-04-09 14:38:47 -04:00
|
|
|
conninfo->remote_ip, SWITCH_UNSPEC, conninfo->remote_port, 0,
|
|
|
|
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-04-09 14:38:47 -04:00
|
|
|
if (switch_socket_create(&conninfo->socket, AF_INET, SOCK_DGRAM, 0, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
if (switch_socket_bind(conninfo->socket, conninfo->local_addr) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Created unicast connection %s:%d->%s:%d\n",
|
|
|
|
conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port);
|
|
|
|
switch_channel_set_private(channel, "unicast", conninfo);
|
|
|
|
switch_channel_set_flag(channel, CF_UNICAST);
|
|
|
|
switch_set_flag_locked(conninfo, SUF_READY);
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
fail:
|
2007-04-09 14:38:47 -04:00
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure creating unicast connection %s:%d->%s:%d\n",
|
|
|
|
conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port);
|
2008-05-27 00:30:03 -04:00
|
|
|
return SWITCH_STATUS_FALSE;
|
2007-04-09 14:38:47 -04:00
|
|
|
}
|
|
|
|
|
2007-01-06 12:06:18 -05:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *session, switch_event_t *event)
|
2006-09-06 23:58:01 -04:00
|
|
|
{
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
|
|
|
char *cmd = switch_event_get_header(event, "call-command");
|
|
|
|
unsigned long cmd_hash;
|
2007-09-28 21:06:08 -04:00
|
|
|
switch_ssize_t hlen = -1;
|
2007-03-09 15:44:13 -05:00
|
|
|
unsigned long CMD_EXECUTE = switch_hashfunc_default("execute", &hlen);
|
|
|
|
unsigned long CMD_HANGUP = switch_hashfunc_default("hangup", &hlen);
|
|
|
|
unsigned long CMD_NOMEDIA = switch_hashfunc_default("nomedia", &hlen);
|
2007-04-09 14:38:47 -04:00
|
|
|
unsigned long CMD_UNICAST = switch_hashfunc_default("unicast", &hlen);
|
2007-05-09 15:44:15 -04:00
|
|
|
char *lead_frames = switch_event_get_header(event, "lead-frames");
|
2007-06-25 17:25:33 -04:00
|
|
|
char *event_lock = switch_event_get_header(event, "event-lock");
|
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
|
|
|
|
2007-01-06 12:06:18 -05:00
|
|
|
if (switch_strlen_zero(cmd)) {
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Command!\n");
|
2007-05-14 16:38:18 -04:00
|
|
|
return SWITCH_STATUS_FALSE;
|
2007-03-29 18:31:56 -04:00
|
|
|
}
|
2007-01-06 12:06:18 -05:00
|
|
|
|
2007-03-09 15:44:13 -05:00
|
|
|
cmd_hash = switch_hashfunc_default(cmd, &hlen);
|
2006-09-06 23:58:01 -04:00
|
|
|
|
2006-10-31 16:38:06 -05:00
|
|
|
switch_channel_set_flag(channel, CF_EVENT_PARSE);
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2007-06-25 17:25:33 -04:00
|
|
|
if (switch_true(event_lock)) {
|
|
|
|
switch_channel_set_flag(channel, CF_EVENT_LOCK);
|
|
|
|
}
|
|
|
|
|
2007-05-09 15:44:15 -04:00
|
|
|
if (lead_frames) {
|
|
|
|
switch_frame_t *read_frame;
|
|
|
|
int frame_count = atoi(lead_frames);
|
2008-05-19 10:30:39 -04:00
|
|
|
int max_frames = frame_count * 2;
|
2008-05-27 00:30:03 -04:00
|
|
|
|
|
|
|
while (frame_count > 0 && --max_frames > 0) {
|
2008-05-08 15:19:47 -04:00
|
|
|
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
|
2007-05-09 15:44:15 -04:00
|
|
|
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
2007-06-25 17:25:33 -04:00
|
|
|
goto done;
|
2007-05-09 15:44:15 -04:00
|
|
|
}
|
|
|
|
if (!switch_test_flag(read_frame, SFF_CNG)) {
|
|
|
|
frame_count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
|
|
|
|
if (cmd_hash == CMD_EXECUTE) {
|
2008-11-13 12:40:25 -05:00
|
|
|
switch_application_interface_t *application_interface;
|
2007-03-29 18:31:56 -04:00
|
|
|
char *app_name = switch_event_get_header(event, "execute-app-name");
|
|
|
|
char *app_arg = switch_event_get_header(event, "execute-app-arg");
|
2007-03-30 18:13:19 -04:00
|
|
|
char *loop_h = switch_event_get_header(event, "loops");
|
2008-03-11 20:11:33 -04:00
|
|
|
char *hold_bleg = switch_event_get_header(event, "hold-bleg");
|
2007-04-09 14:38:47 -04:00
|
|
|
int loops = 1;
|
2007-06-25 17:25:33 -04:00
|
|
|
|
2007-03-30 18:13:19 -04:00
|
|
|
if (loop_h) {
|
|
|
|
loops = atoi(loop_h);
|
|
|
|
}
|
2007-11-02 14:34:26 -04:00
|
|
|
|
2007-06-25 17:25:33 -04:00
|
|
|
if (app_name) {
|
2007-03-29 18:31:56 -04:00
|
|
|
if ((application_interface = switch_loadable_module_get_application_interface(app_name))) {
|
|
|
|
if (application_interface->application_function) {
|
2007-03-30 18:13:19 -04:00
|
|
|
int x;
|
2008-03-11 20:11:33 -04:00
|
|
|
const char *b_uuid = NULL;
|
|
|
|
switch_core_session_t *b_session = NULL;
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2008-01-05 12:32:13 -05:00
|
|
|
switch_channel_clear_flag(channel, CF_STOP_BROADCAST);
|
2007-03-30 18:13:19 -04:00
|
|
|
switch_channel_set_flag(channel, CF_BROADCAST);
|
2008-03-11 20:11:33 -04:00
|
|
|
if (hold_bleg && switch_true(hold_bleg)) {
|
|
|
|
if ((b_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
|
|
|
|
const char *stream;
|
2008-03-12 21:08:42 -04:00
|
|
|
b_uuid = switch_core_session_strdup(session, b_uuid);
|
2008-03-11 20:11:33 -04:00
|
|
|
|
|
|
|
if (!(stream = switch_channel_get_variable_partner(channel, SWITCH_HOLD_MUSIC_VARIABLE))) {
|
|
|
|
stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE);
|
|
|
|
}
|
2008-03-11 20:30:52 -04:00
|
|
|
|
2008-05-15 10:49:11 -04:00
|
|
|
if (stream && switch_is_moh(stream)) {
|
2008-03-12 12:40:01 -04:00
|
|
|
if ((b_session = switch_core_session_locate(b_uuid))) {
|
|
|
|
switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
|
|
|
|
switch_ivr_broadcast(b_uuid, stream, SMF_ECHO_ALEG | SMF_LOOP);
|
2008-09-09 12:31:53 -04:00
|
|
|
switch_channel_wait_for_flag(b_channel, CF_BROADCAST, SWITCH_TRUE, 5000, NULL);
|
2008-03-12 12:40:01 -04:00
|
|
|
switch_core_session_rwunlock(b_session);
|
|
|
|
}
|
2008-03-11 20:11:33 -04:00
|
|
|
} else {
|
|
|
|
b_uuid = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-30 18:13:19 -04:00
|
|
|
for (x = 0; x < loops || loops < 0; x++) {
|
2008-05-15 10:49:11 -04:00
|
|
|
switch_time_t b4, aftr;
|
2008-05-27 00:30:03 -04:00
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Command Execute %s(%s)\n",
|
2009-01-15 17:11:27 -05:00
|
|
|
switch_channel_get_name(channel), app_name, switch_str_nil(app_arg));
|
2009-01-25 16:23:07 -05:00
|
|
|
b4 = switch_micro_time_now();
|
2007-04-20 21:03:58 -04:00
|
|
|
switch_core_session_exec(session, application_interface, app_arg);
|
2009-01-25 16:23:07 -05:00
|
|
|
aftr = switch_micro_time_now();
|
2008-05-15 10:49:11 -04:00
|
|
|
if (!switch_channel_ready(channel) || switch_channel_test_flag(channel, CF_STOP_BROADCAST) || aftr - b4 < 500000) {
|
2007-03-30 18:13:19 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-03-12 21:08:42 -04:00
|
|
|
|
2008-03-11 20:11:33 -04:00
|
|
|
if (b_uuid) {
|
|
|
|
if ((b_session = switch_core_session_locate(b_uuid))) {
|
|
|
|
switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
|
|
|
|
switch_channel_stop_broadcast(b_channel);
|
2008-09-09 12:31:53 -04:00
|
|
|
switch_channel_wait_for_flag(b_channel, CF_BROADCAST, SWITCH_FALSE, 5000, NULL);
|
2008-03-11 20:11:33 -04:00
|
|
|
switch_core_session_rwunlock(b_session);
|
|
|
|
}
|
|
|
|
}
|
2008-03-12 21:08:42 -04:00
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
switch_channel_clear_flag(channel, CF_BROADCAST);
|
2007-03-29 18:31:56 -04:00
|
|
|
}
|
2008-11-12 14:28:05 -05:00
|
|
|
UNPROTECT_INTERFACE(application_interface);
|
2007-03-29 18:31:56 -04:00
|
|
|
}
|
|
|
|
}
|
2007-04-09 14:38:47 -04:00
|
|
|
} else if (cmd_hash == CMD_UNICAST) {
|
2007-10-31 17:44:49 -04:00
|
|
|
char *local_ip = switch_event_get_header(event, "local-ip");
|
|
|
|
char *local_port = switch_event_get_header(event, "local-port");
|
|
|
|
char *remote_ip = switch_event_get_header(event, "remote-ip");
|
|
|
|
char *remote_port = switch_event_get_header(event, "remote-port");
|
2007-04-09 14:38:47 -04:00
|
|
|
char *transport = switch_event_get_header(event, "transport");
|
2007-04-13 12:24:02 -04:00
|
|
|
char *flags = switch_event_get_header(event, "flags");
|
2007-04-09 14:38:47 -04:00
|
|
|
|
|
|
|
if (switch_strlen_zero(local_ip)) {
|
|
|
|
local_ip = "127.0.0.1";
|
|
|
|
}
|
|
|
|
if (switch_strlen_zero(remote_ip)) {
|
|
|
|
remote_ip = "127.0.0.1";
|
|
|
|
}
|
|
|
|
if (switch_strlen_zero(local_port)) {
|
|
|
|
local_port = "8025";
|
|
|
|
}
|
|
|
|
if (switch_strlen_zero(remote_port)) {
|
|
|
|
remote_port = "8026";
|
|
|
|
}
|
|
|
|
if (switch_strlen_zero(transport)) {
|
|
|
|
transport = "udp";
|
|
|
|
}
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
switch_ivr_activate_unicast(session, local_ip, (switch_port_t) atoi(local_port), remote_ip, (switch_port_t) atoi(remote_port), transport, flags);
|
2007-04-09 14:38:47 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
} else if (cmd_hash == CMD_HANGUP) {
|
|
|
|
char *cause_name = switch_event_get_header(event, "hangup-cause");
|
|
|
|
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
|
|
|
|
|
|
|
|
if (cause_name) {
|
|
|
|
cause = switch_channel_str2cause(cause_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_channel_hangup(channel, cause);
|
|
|
|
} else if (cmd_hash == CMD_NOMEDIA) {
|
|
|
|
char *uuid = switch_event_get_header(event, "nomedia-uuid");
|
|
|
|
switch_ivr_nomedia(uuid, SMF_REBRIDGE);
|
|
|
|
}
|
|
|
|
|
2007-06-25 17:25:33 -04:00
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
2007-05-14 16:38:18 -04:00
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
done:
|
2006-10-31 16:38:06 -05:00
|
|
|
switch_channel_clear_flag(channel, CF_EVENT_PARSE);
|
2007-06-25 17:25:33 -04:00
|
|
|
switch_channel_clear_flag(channel, CF_EVENT_LOCK);
|
|
|
|
|
|
|
|
return status;
|
2006-09-06 23:58:01 -04:00
|
|
|
}
|
|
|
|
|
2008-03-24 20:24:23 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_parse_next_event(switch_core_session_t *session)
|
2007-05-14 19:50:38 -04:00
|
|
|
{
|
|
|
|
switch_event_t *event;
|
|
|
|
|
2008-03-24 20:24:23 -04:00
|
|
|
if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) {
|
2007-05-14 19:50:38 -04:00
|
|
|
switch_ivr_parse_event(session, event);
|
|
|
|
switch_event_fire(&event);
|
2008-03-24 20:24:23 -04:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2007-05-14 19:50:38 -04:00
|
|
|
}
|
|
|
|
|
2008-03-24 20:24:23 -04:00
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_events(switch_core_session_t *session)
|
|
|
|
{
|
|
|
|
|
|
|
|
while (switch_ivr_parse_next_event(session) == SWITCH_STATUS_SUCCESS);
|
2008-12-17 16:50:34 -05:00
|
|
|
switch_ivr_sleep(session, 0, SWITCH_TRUE, NULL);
|
|
|
|
|
2007-05-14 19:50:38 -04:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-16 16:32:49 -05:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session, switch_input_args_t *args)
|
2006-09-06 23:58:01 -04:00
|
|
|
{
|
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
2008-01-28 02:26:10 -05:00
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
2007-04-09 14:38:47 -04:00
|
|
|
switch_frame_t *read_frame;
|
2006-11-30 16:28:32 -05:00
|
|
|
int stream_id = 0;
|
2006-09-06 23:58:01 -04:00
|
|
|
switch_event_t *event;
|
2007-04-09 14:38:47 -04:00
|
|
|
switch_unicast_conninfo_t *conninfo = NULL;
|
2008-07-08 19:30:17 -04:00
|
|
|
switch_codec_t *read_codec;
|
2008-05-23 22:39:23 -04:00
|
|
|
uint32_t rate;
|
|
|
|
uint32_t bpf;
|
2008-11-13 18:25:38 -05:00
|
|
|
const char *to;
|
|
|
|
int timeout = 0;
|
|
|
|
time_t expires = 0;
|
2007-05-14 19:50:38 -04:00
|
|
|
|
2008-04-14 10:05:22 -04:00
|
|
|
if (switch_channel_test_flag(channel, CF_CONTROLLED)) {
|
2008-07-08 19:30:17 -04:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot park channels that are under control already.\n");
|
2008-04-14 10:05:22 -04:00
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-07-08 19:30:17 -04:00
|
|
|
if (!switch_channel_test_flag(channel, CF_ANSWERED)) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Careful, Channel is unanswered. Pre-answering...\n");
|
|
|
|
if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot establish media.\n");
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-19 15:58:01 -04:00
|
|
|
if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-07-08 19:30:17 -04:00
|
|
|
read_codec = switch_core_session_get_read_codec(session);
|
|
|
|
|
2008-05-23 22:39:23 -04:00
|
|
|
if (!read_codec || !read_codec->implementation) {
|
2008-05-23 23:26:57 -04:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot park channels that have no read codec.\n");
|
2008-05-23 22:39:23 -04:00
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rate = read_codec->implementation->actual_samples_per_second;
|
2008-10-20 13:48:42 -04:00
|
|
|
bpf = read_codec->implementation->decoded_bytes_per_packet;
|
2008-05-23 22:39:23 -04:00
|
|
|
|
2008-11-13 18:25:38 -05:00
|
|
|
if ((to = switch_channel_get_variable(channel, "park_timeout"))) {
|
|
|
|
if ((timeout = atoi(to)) < 0) {
|
|
|
|
timeout = 0;
|
|
|
|
} else {
|
2009-01-25 16:23:07 -05:00
|
|
|
expires = switch_epoch_time_now(NULL) + timeout;
|
2008-11-13 18:25:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-31 19:19:30 -04:00
|
|
|
switch_channel_set_flag(channel, CF_CONTROLLED);
|
2006-09-06 23:58:01 -04:00
|
|
|
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_PARK) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_channel_event_set_data(channel, event);
|
|
|
|
switch_event_fire(&event);
|
|
|
|
}
|
|
|
|
|
2008-05-23 22:39:23 -04:00
|
|
|
while (read_codec && switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_CONTROLLED)) {
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2008-05-08 15:19:47 -04:00
|
|
|
if ((status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, stream_id)) == SWITCH_STATUS_SUCCESS) {
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
|
|
|
break;
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2009-01-25 16:23:07 -05:00
|
|
|
if (expires && switch_epoch_time_now(NULL) >= expires) {
|
2008-11-13 18:25:38 -05:00
|
|
|
switch_channel_hangup(channel, SWITCH_CAUSE_RECOVERY_ON_TIMER_EXPIRE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-04-09 14:38:47 -04:00
|
|
|
if (switch_channel_test_flag(channel, CF_UNICAST)) {
|
|
|
|
if (!conninfo) {
|
|
|
|
if (!(conninfo = switch_channel_get_private(channel, "unicast"))) {
|
|
|
|
switch_channel_clear_flag(channel, CF_UNICAST);
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-04-09 14:38:47 -04:00
|
|
|
if (conninfo) {
|
|
|
|
unicast_thread_launch(conninfo);
|
|
|
|
}
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-04-09 14:38:47 -04:00
|
|
|
if (conninfo) {
|
2007-04-13 12:24:02 -04:00
|
|
|
switch_size_t len = 0;
|
2007-04-09 14:38:47 -04:00
|
|
|
uint32_t flags = 0;
|
|
|
|
switch_byte_t decoded[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
|
|
|
uint32_t dlen = sizeof(decoded);
|
2007-12-18 12:50:39 -05:00
|
|
|
switch_status_t tstatus;
|
2007-04-09 14:38:47 -04:00
|
|
|
switch_byte_t *sendbuf = NULL;
|
|
|
|
uint32_t sendlen = 0;
|
|
|
|
|
|
|
|
if (switch_test_flag(read_frame, SFF_CNG)) {
|
2008-05-23 22:39:23 -04:00
|
|
|
sendlen = bpf;
|
2008-05-21 18:26:30 -04:00
|
|
|
switch_assert(sendlen <= SWITCH_RECOMMENDED_BUFFER_SIZE);
|
2007-04-09 14:38:47 -04:00
|
|
|
memset(decoded, 255, sendlen);
|
|
|
|
sendbuf = decoded;
|
2007-12-18 13:31:38 -05:00
|
|
|
tstatus = SWITCH_STATUS_SUCCESS;
|
2007-04-09 14:38:47 -04:00
|
|
|
} else {
|
2007-04-13 12:24:02 -04:00
|
|
|
if (switch_test_flag(conninfo, SUF_NATIVE)) {
|
2007-12-18 12:50:39 -05:00
|
|
|
tstatus = SWITCH_STATUS_NOOP;
|
2007-04-13 12:24:02 -04:00
|
|
|
} else {
|
2008-05-27 00:30:03 -04:00
|
|
|
tstatus = switch_core_codec_decode(read_codec,
|
|
|
|
&conninfo->read_codec,
|
|
|
|
read_frame->data,
|
|
|
|
read_frame->datalen,
|
|
|
|
read_codec->implementation->actual_samples_per_second, decoded, &dlen, &rate, &flags);
|
2007-04-13 12:24:02 -04:00
|
|
|
}
|
2007-12-18 12:50:39 -05:00
|
|
|
switch (tstatus) {
|
2007-04-09 14:38:47 -04:00
|
|
|
case SWITCH_STATUS_NOOP:
|
|
|
|
case SWITCH_STATUS_BREAK:
|
|
|
|
sendbuf = read_frame->data;
|
|
|
|
sendlen = read_frame->datalen;
|
2007-12-18 12:50:39 -05:00
|
|
|
tstatus = SWITCH_STATUS_SUCCESS;
|
2007-04-09 14:38:47 -04:00
|
|
|
break;
|
|
|
|
case SWITCH_STATUS_SUCCESS:
|
|
|
|
sendbuf = decoded;
|
|
|
|
sendlen = dlen;
|
2007-12-18 12:50:39 -05:00
|
|
|
tstatus = SWITCH_STATUS_SUCCESS;
|
2007-04-09 14:38:47 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Codec Error\n");
|
|
|
|
switch_ivr_deactivate_unicast(session);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-18 12:50:39 -05:00
|
|
|
if (tstatus == SWITCH_STATUS_SUCCESS) {
|
2007-04-09 14:38:47 -04:00
|
|
|
len = sendlen;
|
2008-05-27 00:30:03 -04:00
|
|
|
if (switch_socket_sendto(conninfo->socket, conninfo->remote_addr, 0, (void *) sendbuf, &len) != SWITCH_STATUS_SUCCESS) {
|
2007-04-09 14:38:47 -04:00
|
|
|
switch_ivr_deactivate_unicast(session);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-05-14 19:50:38 -04:00
|
|
|
if (switch_core_session_private_event_count(session)) {
|
|
|
|
switch_ivr_parse_all_events(session);
|
2007-03-29 18:31:56 -04:00
|
|
|
}
|
2007-01-06 12:06:18 -05:00
|
|
|
|
|
|
|
if (switch_channel_has_dtmf(channel)) {
|
2008-05-27 00:30:03 -04:00
|
|
|
switch_dtmf_t dtmf = { 0 };
|
2007-12-21 19:32:20 -05:00
|
|
|
switch_channel_dequeue_dtmf(channel, &dtmf);
|
2007-02-16 16:32:49 -05:00
|
|
|
if (args && args->input_callback) {
|
2007-12-21 19:32:20 -05:00
|
|
|
if ((status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen)) != SWITCH_STATUS_SUCCESS) {
|
2007-02-16 16:32:49 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
}
|
2007-01-06 12:06:18 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) {
|
2007-02-16 16:32:49 -05:00
|
|
|
if (args && args->input_callback) {
|
2007-03-29 20:13:31 -04:00
|
|
|
if ((status = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen)) != SWITCH_STATUS_SUCCESS) {
|
2007-02-16 16:32:49 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch_channel_event_set_data(channel, event);
|
|
|
|
switch_event_fire(&event);
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:58:01 -04:00
|
|
|
}
|
2008-05-23 22:39:23 -04:00
|
|
|
|
2006-09-06 23:58:01 -04:00
|
|
|
switch_channel_clear_flag(channel, CF_CONTROLLED);
|
|
|
|
|
|
|
|
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNPARK) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_channel_event_set_data(channel, event);
|
|
|
|
switch_event_fire(&event);
|
|
|
|
}
|
|
|
|
|
2007-04-09 14:38:47 -04:00
|
|
|
if (switch_channel_test_flag(channel, CF_UNICAST)) {
|
|
|
|
switch_ivr_deactivate_unicast(session);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:58:01 -04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2007-03-29 20:13:31 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t timeout)
|
2006-01-27 16:33:45 -05:00
|
|
|
{
|
2008-01-28 02:26:10 -05:00
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
2006-04-29 19:43:28 -04:00
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
2006-11-09 00:39:04 -05:00
|
|
|
switch_time_t started = 0;
|
2006-11-11 19:38:31 -05:00
|
|
|
uint32_t elapsed;
|
2006-11-09 00:39:04 -05:00
|
|
|
|
2008-05-16 13:55:12 -04:00
|
|
|
if (!args || !args->input_callback) {
|
2006-01-27 16:33:45 -05:00
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
2006-11-09 00:39:04 -05:00
|
|
|
if (timeout) {
|
2009-01-25 16:23:07 -05:00
|
|
|
started = switch_micro_time_now();
|
2006-11-09 00:39:04 -05:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
while (switch_channel_ready(channel)) {
|
2008-04-04 17:43:20 -04:00
|
|
|
switch_frame_t *read_frame = NULL;
|
2006-07-12 14:39:19 -04:00
|
|
|
switch_event_t *event;
|
2008-05-27 00:30:03 -04:00
|
|
|
switch_dtmf_t dtmf = { 0 };
|
2006-01-27 16:33:45 -05:00
|
|
|
|
2008-04-03 17:27:16 -04:00
|
|
|
if (switch_channel_test_flag(channel, CF_BREAK)) {
|
|
|
|
switch_channel_clear_flag(channel, CF_BREAK);
|
|
|
|
status = SWITCH_STATUS_BREAK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-11-09 00:39:04 -05:00
|
|
|
if (timeout) {
|
2009-01-25 16:23:07 -05:00
|
|
|
elapsed = (uint32_t) ((switch_micro_time_now() - started) / 1000);
|
2006-11-09 00:39:04 -05:00
|
|
|
if (elapsed >= timeout) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-09-06 23:58:01 -04:00
|
|
|
|
2007-05-14 19:50:38 -04:00
|
|
|
if (switch_core_session_private_event_count(session)) {
|
2008-05-27 00:30:03 -04:00
|
|
|
switch_ivr_parse_all_events(session);
|
|
|
|
}
|
2006-09-06 23:58:01 -04:00
|
|
|
|
2006-01-27 16:33:45 -05:00
|
|
|
if (switch_channel_has_dtmf(channel)) {
|
2007-12-21 19:32:20 -05:00
|
|
|
switch_channel_dequeue_dtmf(channel, &dtmf);
|
2008-05-27 00:30:03 -04:00
|
|
|
status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen);
|
2006-07-12 14:39:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) {
|
2007-03-29 18:31:56 -04:00
|
|
|
status = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen);
|
2006-07-12 14:39:19 -04:00
|
|
|
switch_event_destroy(&event);
|
2006-01-27 16:33:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status != SWITCH_STATUS_SUCCESS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-06-09 18:59:13 -04:00
|
|
|
if (switch_channel_test_flag(channel, CF_SERVICE)) {
|
2008-11-14 18:31:21 -05:00
|
|
|
switch_cond_next();
|
2006-06-09 18:59:13 -04:00
|
|
|
} else {
|
2008-05-08 15:19:47 -04:00
|
|
|
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
|
2006-06-09 18:59:13 -04:00
|
|
|
}
|
2006-04-28 15:46:57 -04:00
|
|
|
|
|
|
|
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
2006-01-27 16:33:45 -05:00
|
|
|
break;
|
|
|
|
}
|
2008-04-04 17:18:16 -04:00
|
|
|
|
2008-04-04 17:43:20 -04:00
|
|
|
if (read_frame && args && (args->read_frame_callback)) {
|
2008-04-04 17:18:16 -04:00
|
|
|
if (args->read_frame_callback(session, read_frame, args->user_data) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-01-27 16:33:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2006-04-29 19:43:28 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session,
|
2006-06-09 18:59:13 -04:00
|
|
|
char *buf,
|
2007-10-12 16:14:41 -04:00
|
|
|
switch_size_t buflen,
|
2008-05-27 00:30:03 -04:00
|
|
|
switch_size_t maxdigits,
|
|
|
|
const char *terminators, char *terminator,
|
|
|
|
uint32_t first_timeout, uint32_t digit_timeout, uint32_t abs_timeout)
|
2006-01-27 16:33:45 -05:00
|
|
|
{
|
2007-10-12 16:14:41 -04:00
|
|
|
switch_size_t i = 0, x = strlen(buf);
|
2008-01-28 02:26:10 -05:00
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
2006-12-04 00:41:03 -05:00
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
2008-01-07 11:49:46 -05:00
|
|
|
switch_time_t started = 0, digit_started = 0;
|
|
|
|
uint32_t abs_elapsed = 0, digit_elapsed = 0;
|
|
|
|
uint32_t eff_timeout = 0;
|
2008-12-08 19:32:51 -05:00
|
|
|
switch_frame_t write_frame = { 0 };
|
|
|
|
unsigned char *abuf = NULL;
|
|
|
|
switch_codec_implementation_t imp = {0};
|
|
|
|
switch_codec_t codec = { 0 };
|
|
|
|
int sval = 0;
|
|
|
|
const char *var;
|
|
|
|
|
|
|
|
if ((var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
|
|
|
|
switch_core_session_get_read_impl(session, &imp);
|
|
|
|
|
|
|
|
if (switch_core_codec_init(&codec,
|
|
|
|
"L16",
|
|
|
|
NULL,
|
|
|
|
imp.samples_per_second,
|
|
|
|
imp.microseconds_per_packet / 1000,
|
|
|
|
imp.number_of_channels,
|
|
|
|
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
|
|
|
|
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
|
|
|
|
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n",
|
|
|
|
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
|
|
|
|
|
|
|
|
write_frame.codec = &codec;
|
|
|
|
switch_zmalloc(abuf, SWITCH_RECOMMENDED_BUFFER_SIZE);
|
|
|
|
write_frame.data = abuf;
|
|
|
|
write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
|
|
|
|
write_frame.datalen = imp.decoded_bytes_per_packet;
|
|
|
|
write_frame.samples = write_frame.datalen / sizeof(int16_t);
|
|
|
|
}
|
2006-02-28 19:58:32 -05:00
|
|
|
|
2008-12-08 19:32:51 -05:00
|
|
|
if (terminator != NULL) {
|
2006-12-04 00:41:03 -05:00
|
|
|
*terminator = '\0';
|
2008-12-08 19:32:51 -05:00
|
|
|
}
|
2006-01-30 11:11:21 -05:00
|
|
|
|
2006-12-04 00:41:03 -05:00
|
|
|
if (!switch_strlen_zero(terminators)) {
|
2007-03-29 18:31:56 -04:00
|
|
|
for (i = 0; i < x; i++) {
|
2006-12-04 00:41:03 -05:00
|
|
|
if (strchr(terminators, buf[i]) && terminator != NULL) {
|
2006-02-28 19:58:32 -05:00
|
|
|
*terminator = buf[i];
|
2008-03-12 12:40:01 -04:00
|
|
|
buf[i] = '\0';
|
2006-02-28 19:58:32 -05:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2006-01-30 11:11:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-07 11:49:46 -05:00
|
|
|
if (abs_timeout) {
|
2009-01-25 16:23:07 -05:00
|
|
|
started = switch_micro_time_now();
|
2008-01-07 11:49:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (digit_timeout && first_timeout) {
|
|
|
|
eff_timeout = first_timeout;
|
|
|
|
} else if (digit_timeout && !first_timeout) {
|
|
|
|
first_timeout = eff_timeout = digit_timeout;
|
|
|
|
} else if (first_timeout) {
|
|
|
|
digit_timeout = eff_timeout = first_timeout;
|
2006-02-28 19:58:32 -05:00
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2008-01-07 11:49:46 -05:00
|
|
|
|
|
|
|
if (eff_timeout) {
|
2009-01-25 16:23:07 -05:00
|
|
|
digit_started = switch_micro_time_now();
|
2008-01-07 11:49:46 -05:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
while (switch_channel_ready(channel)) {
|
2006-04-29 02:05:03 -04:00
|
|
|
switch_frame_t *read_frame;
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2008-01-07 11:49:46 -05:00
|
|
|
if (abs_timeout) {
|
2009-01-25 16:23:07 -05:00
|
|
|
abs_elapsed = (uint32_t) ((switch_micro_time_now() - started) / 1000);
|
2008-01-07 11:49:46 -05:00
|
|
|
if (abs_elapsed >= abs_timeout) {
|
2006-02-28 19:58:32 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
if (switch_core_session_private_event_count(session)) {
|
|
|
|
switch_ivr_parse_all_events(session);
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2008-01-07 11:49:46 -05:00
|
|
|
|
|
|
|
if (eff_timeout) {
|
2009-01-25 16:23:07 -05:00
|
|
|
digit_elapsed = (uint32_t) ((switch_micro_time_now() - digit_started) / 1000);
|
2008-01-07 11:49:46 -05:00
|
|
|
if (digit_elapsed >= eff_timeout) {
|
2008-08-05 17:50:48 -04:00
|
|
|
status = SWITCH_STATUS_TIMEOUT;
|
2008-01-07 11:49:46 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-27 16:33:45 -05:00
|
|
|
if (switch_channel_has_dtmf(channel)) {
|
2008-05-27 00:30:03 -04:00
|
|
|
switch_dtmf_t dtmf = { 0 };
|
2007-12-21 19:51:26 -05:00
|
|
|
switch_size_t y;
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2008-01-07 11:49:46 -05:00
|
|
|
if (eff_timeout) {
|
|
|
|
eff_timeout = digit_timeout;
|
2009-01-25 16:23:07 -05:00
|
|
|
digit_started = switch_micro_time_now();
|
2008-01-07 11:49:46 -05:00
|
|
|
}
|
|
|
|
|
2008-03-04 13:55:16 -05:00
|
|
|
for (y = 0; y <= maxdigits; y++) {
|
2007-12-21 19:32:20 -05:00
|
|
|
if (switch_channel_dequeue_dtmf(channel, &dtmf) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
break;
|
|
|
|
}
|
2006-01-27 16:33:45 -05:00
|
|
|
|
2007-12-21 19:32:20 -05:00
|
|
|
if (!switch_strlen_zero(terminators) && strchr(terminators, dtmf.digit) && terminator != NULL) {
|
|
|
|
*terminator = dtmf.digit;
|
2006-01-27 16:33:45 -05:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
|
|
|
|
2007-12-21 19:32:20 -05:00
|
|
|
buf[x++] = dtmf.digit;
|
2006-01-27 16:33:45 -05:00
|
|
|
buf[x] = '\0';
|
|
|
|
if (x >= buflen || x >= maxdigits) {
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-06-09 18:59:13 -04:00
|
|
|
|
|
|
|
if (switch_channel_test_flag(channel, CF_SERVICE)) {
|
2008-11-14 18:31:21 -05:00
|
|
|
switch_cond_next();
|
2006-06-09 18:59:13 -04:00
|
|
|
} else {
|
2008-05-08 15:19:47 -04:00
|
|
|
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
|
2006-04-28 15:46:57 -04:00
|
|
|
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
2006-02-28 19:58:32 -05:00
|
|
|
break;
|
|
|
|
}
|
2008-12-08 19:32:51 -05:00
|
|
|
|
|
|
|
if (write_frame.data) {
|
|
|
|
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, sval);
|
|
|
|
switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
|
|
|
|
}
|
|
|
|
|
2006-01-27 16:33:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-08 19:32:51 -05:00
|
|
|
if (write_frame.codec) {
|
|
|
|
switch_core_codec_destroy(&codec);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_safe_free(abuf);
|
|
|
|
|
2006-01-27 16:33:45 -05:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-05-01 12:41:46 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session, const char *message, switch_bool_t moh)
|
2006-01-26 20:46:14 -05:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_core_session_message_t msg = { 0 };
|
2008-01-28 02:26:10 -05:00
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
2008-03-10 12:19:55 -04:00
|
|
|
const char *stream;
|
|
|
|
const char *other_uuid;
|
2006-03-01 17:55:28 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
msg.message_id = SWITCH_MESSAGE_INDICATE_HOLD;
|
2008-03-10 23:45:16 -04:00
|
|
|
msg.string_arg = message;
|
2007-03-29 18:31:56 -04:00
|
|
|
msg.from = __FILE__;
|
2006-01-26 20:46:14 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_channel_set_flag(channel, CF_HOLD);
|
|
|
|
switch_channel_set_flag(channel, CF_SUSPEND);
|
|
|
|
|
|
|
|
switch_core_session_receive_message(session, &msg);
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2008-05-01 12:41:46 -04:00
|
|
|
if (moh && (stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) {
|
2008-03-10 12:19:55 -04:00
|
|
|
if ((other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
|
|
|
|
switch_ivr_broadcast(other_uuid, stream, SMF_ECHO_ALEG | SMF_LOOP);
|
|
|
|
}
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2008-03-10 12:19:55 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2006-01-26 20:46:14 -05:00
|
|
|
|
2008-05-01 12:41:46 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_hold_uuid(const char *uuid, const char *message, switch_bool_t moh)
|
2007-03-29 18:31:56 -04:00
|
|
|
{
|
|
|
|
switch_core_session_t *session;
|
2006-01-26 20:46:14 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if ((session = switch_core_session_locate(uuid))) {
|
2008-05-01 12:41:46 -04:00
|
|
|
switch_ivr_hold(session, message, moh);
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_core_session_rwunlock(session);
|
2006-01-26 20:46:14 -05:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2006-01-26 20:46:14 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_unhold(switch_core_session_t *session)
|
|
|
|
{
|
|
|
|
switch_core_session_message_t msg = { 0 };
|
2008-01-28 02:26:10 -05:00
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
2008-03-10 12:19:55 -04:00
|
|
|
const char *other_uuid;
|
|
|
|
switch_core_session_t *b_session;
|
2006-07-25 18:37:52 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
msg.message_id = SWITCH_MESSAGE_INDICATE_UNHOLD;
|
|
|
|
msg.from = __FILE__;
|
2006-07-25 18:37:52 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_channel_clear_flag(channel, CF_HOLD);
|
|
|
|
switch_channel_clear_flag(channel, CF_SUSPEND);
|
2006-07-25 18:37:52 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_core_session_receive_message(session, &msg);
|
2006-07-25 18:37:52 -04:00
|
|
|
|
2008-03-10 12:19:55 -04:00
|
|
|
|
|
|
|
if ((other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (b_session = switch_core_session_locate(other_uuid))) {
|
|
|
|
switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
|
|
|
|
switch_channel_stop_broadcast(b_channel);
|
2008-09-09 12:31:53 -04:00
|
|
|
switch_channel_wait_for_flag(b_channel, CF_BROADCAST, SWITCH_FALSE, 5000, NULL);
|
2008-03-10 12:19:55 -04:00
|
|
|
switch_core_session_rwunlock(b_session);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2006-11-29 12:10:40 -05:00
|
|
|
|
2007-11-01 07:28:26 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_unhold_uuid(const char *uuid)
|
2007-03-29 18:31:56 -04:00
|
|
|
{
|
|
|
|
switch_core_session_t *session;
|
2006-01-26 20:46:14 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if ((session = switch_core_session_locate(uuid))) {
|
|
|
|
switch_ivr_unhold(session);
|
|
|
|
switch_core_session_rwunlock(session);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2006-09-06 23:58:01 -04:00
|
|
|
|
2007-11-01 07:28:26 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_flag_t flags)
|
2007-03-29 18:31:56 -04:00
|
|
|
{
|
2007-11-01 07:28:26 -04:00
|
|
|
const char *other_uuid = NULL;
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_channel_t *channel, *other_channel = NULL;
|
|
|
|
switch_core_session_t *session, *other_session;
|
|
|
|
switch_core_session_message_t msg = { 0 };
|
|
|
|
switch_status_t status = SWITCH_STATUS_GENERR;
|
|
|
|
uint8_t swap = 0;
|
2008-03-24 16:58:44 -04:00
|
|
|
switch_frame_t *read_frame = NULL;
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
msg.message_id = SWITCH_MESSAGE_INDICATE_MEDIA;
|
|
|
|
msg.from = __FILE__;
|
2006-01-26 20:46:14 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if ((session = switch_core_session_locate(uuid))) {
|
|
|
|
channel = switch_core_session_get_channel(session);
|
2008-01-28 02:26:10 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_ORIGINATOR)) {
|
|
|
|
swap = 1;
|
|
|
|
}
|
2006-07-12 14:39:19 -04:00
|
|
|
|
2008-02-21 12:48:41 -05:00
|
|
|
if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
|
2007-03-29 18:31:56 -04:00
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
switch_core_session_receive_message(session, &msg);
|
2008-09-19 16:59:23 -04:00
|
|
|
|
|
|
|
if ((flags & SMF_IMMEDIATE)) {
|
|
|
|
switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 250, NULL);
|
|
|
|
switch_yield(250000);
|
|
|
|
} else {
|
2008-09-19 15:58:01 -04:00
|
|
|
switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
|
|
|
|
switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if ((flags & SMF_REBRIDGE)
|
|
|
|
&& (other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE))
|
|
|
|
&& (other_session = switch_core_session_locate(other_uuid))) {
|
|
|
|
other_channel = switch_core_session_get_channel(other_session);
|
2007-12-11 14:23:57 -05:00
|
|
|
switch_assert(other_channel != NULL);
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_core_session_receive_message(other_session, &msg);
|
2008-09-09 12:31:53 -04:00
|
|
|
switch_channel_wait_for_flag(other_channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
|
2008-05-08 15:19:47 -04:00
|
|
|
switch_core_session_read_frame(other_session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_channel_clear_state_handler(other_channel, NULL);
|
|
|
|
switch_core_session_rwunlock(other_session);
|
|
|
|
}
|
|
|
|
if (other_channel) {
|
|
|
|
switch_channel_clear_state_handler(channel, NULL);
|
2006-01-26 20:46:14 -05:00
|
|
|
}
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_core_session_rwunlock(session);
|
|
|
|
|
|
|
|
if (other_channel) {
|
|
|
|
if (swap) {
|
|
|
|
switch_ivr_uuid_bridge(other_uuid, uuid);
|
2006-12-22 16:10:20 -05:00
|
|
|
} else {
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_ivr_uuid_bridge(uuid, other_uuid);
|
2007-03-10 22:07:58 -05:00
|
|
|
}
|
2008-09-09 12:31:53 -04:00
|
|
|
switch_channel_wait_for_flag(channel, CF_BRIDGED, SWITCH_TRUE, 1000, NULL);
|
|
|
|
switch_channel_wait_for_flag(other_channel, CF_BRIDGED, SWITCH_TRUE, 1000, NULL);
|
2006-02-28 23:47:34 -05:00
|
|
|
}
|
2006-01-26 20:46:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
2006-01-26 13:00:27 -05:00
|
|
|
|
2007-11-01 07:28:26 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(const char *uuid, switch_media_flag_t flags)
|
2006-09-08 23:39:28 -04:00
|
|
|
{
|
2007-11-01 07:28:26 -04:00
|
|
|
const char *other_uuid;
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_channel_t *channel, *other_channel = NULL;
|
|
|
|
switch_core_session_t *session, *other_session = NULL;
|
|
|
|
switch_core_session_message_t msg = { 0 };
|
|
|
|
switch_status_t status = SWITCH_STATUS_GENERR;
|
|
|
|
uint8_t swap = 0;
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
msg.message_id = SWITCH_MESSAGE_INDICATE_NOMEDIA;
|
|
|
|
msg.from = __FILE__;
|
|
|
|
|
|
|
|
if ((session = switch_core_session_locate(uuid))) {
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
|
|
|
|
if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_ORIGINATOR)) {
|
|
|
|
swap = 1;
|
|
|
|
}
|
|
|
|
|
2008-02-21 12:48:41 -05:00
|
|
|
if ((flags & SMF_FORCE) || !switch_channel_test_flag(channel, CF_PROXY_MODE)) {
|
2007-05-16 13:35:00 -04:00
|
|
|
switch_core_session_receive_message(session, &msg);
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) &&
|
|
|
|
(other_session = switch_core_session_locate(other_uuid))) {
|
|
|
|
other_channel = switch_core_session_get_channel(other_session);
|
2007-05-14 16:38:18 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_core_session_receive_message(other_session, &msg);
|
|
|
|
switch_channel_clear_state_handler(other_channel, NULL);
|
|
|
|
}
|
2007-05-14 19:50:38 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (other_channel) {
|
|
|
|
switch_channel_clear_state_handler(channel, NULL);
|
|
|
|
if (swap) {
|
|
|
|
switch_ivr_signal_bridge(other_session, session);
|
|
|
|
} else {
|
|
|
|
switch_ivr_signal_bridge(session, other_session);
|
|
|
|
}
|
2008-09-09 12:31:53 -04:00
|
|
|
switch_channel_wait_for_flag(channel, CF_BRIDGED, SWITCH_TRUE, 1000, NULL);
|
|
|
|
switch_channel_wait_for_flag(other_channel, CF_BRIDGED, SWITCH_TRUE, 1000, NULL);
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_core_session_rwunlock(other_session);
|
2006-09-08 23:39:28 -04:00
|
|
|
}
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_core_session_rwunlock(session);
|
2006-09-08 23:39:28 -04:00
|
|
|
}
|
2007-03-20 16:37:52 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
return status;
|
2006-09-08 23:39:28 -04:00
|
|
|
}
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_t *session, const char *extension, const char *dialplan,
|
|
|
|
const char *context)
|
2006-09-08 23:39:28 -04:00
|
|
|
{
|
2008-01-28 02:26:10 -05:00
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_caller_profile_t *profile, *new_profile;
|
|
|
|
switch_core_session_message_t msg = { 0 };
|
|
|
|
switch_core_session_t *other_session;
|
|
|
|
switch_channel_t *other_channel = NULL;
|
2007-11-01 07:28:26 -04:00
|
|
|
const char *uuid = NULL;
|
2008-04-14 11:55:37 -04:00
|
|
|
const char *max_forwards;
|
|
|
|
const char *forwardvar = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE);
|
|
|
|
int forwardval = 70;
|
|
|
|
|
|
|
|
if (!switch_strlen_zero(forwardvar)) {
|
2008-05-27 00:30:03 -04:00
|
|
|
forwardval = atoi(forwardvar) - 1;
|
2008-04-14 11:55:37 -04:00
|
|
|
}
|
|
|
|
if (forwardval <= 0) {
|
|
|
|
switch_channel_hangup(channel, SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR);
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
max_forwards = switch_core_session_sprintf(session, "%d", forwardval);
|
|
|
|
switch_channel_set_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE, max_forwards);
|
2006-09-08 23:39:28 -04:00
|
|
|
|
2009-01-09 15:34:01 -05:00
|
|
|
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
|
2008-01-04 20:03:08 -05:00
|
|
|
switch_channel_clear_flag(channel, CF_ORIGINATING);
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
/* clear all state handlers */
|
|
|
|
switch_channel_clear_state_handler(channel, NULL);
|
2006-09-08 23:39:28 -04:00
|
|
|
|
2007-12-05 17:35:37 -05:00
|
|
|
if ((profile = switch_channel_get_caller_profile(channel))) {
|
2008-11-19 15:42:28 -05:00
|
|
|
const char *var;
|
|
|
|
|
2007-12-05 17:35:37 -05:00
|
|
|
if (switch_strlen_zero(dialplan)) {
|
|
|
|
dialplan = profile->dialplan;
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-12-05 17:35:37 -05:00
|
|
|
if (switch_strlen_zero(context)) {
|
|
|
|
context = profile->context;
|
|
|
|
}
|
2007-09-28 21:06:08 -04:00
|
|
|
|
2007-12-05 17:35:37 -05:00
|
|
|
if (switch_strlen_zero(dialplan)) {
|
|
|
|
dialplan = "XML";
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-12-05 17:35:37 -05:00
|
|
|
if (switch_strlen_zero(context)) {
|
|
|
|
context = "default";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_strlen_zero(extension)) {
|
|
|
|
extension = "service";
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2008-11-19 15:42:28 -05:00
|
|
|
if ((var = switch_channel_get_variable(channel, "force_transfer_dialplan"))) {
|
|
|
|
dialplan = var;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((var = switch_channel_get_variable(channel, "force_transfer_context"))) {
|
|
|
|
context = var;
|
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
new_profile = switch_caller_profile_clone(session, profile);
|
2007-06-12 17:00:26 -04:00
|
|
|
|
2008-01-16 17:13:36 -05:00
|
|
|
new_profile->dialplan = switch_core_strdup(new_profile->pool, dialplan);
|
|
|
|
new_profile->context = switch_core_strdup(new_profile->pool, context);
|
|
|
|
new_profile->destination_number = switch_core_strdup(new_profile->pool, extension);
|
|
|
|
new_profile->rdnis = switch_core_strdup(new_profile->pool, profile->destination_number);
|
2006-09-08 23:39:28 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_channel_set_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE, NULL);
|
2007-09-21 14:49:14 -04:00
|
|
|
|
|
|
|
/* If HANGUP_AFTER_BRIDGE is set to 'true', SWITCH_SIGNAL_BRIDGE_VARIABLE
|
|
|
|
* will not have a value, so we need to check SWITCH_BRIDGE_VARIABLE */
|
|
|
|
|
|
|
|
uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE);
|
2007-09-28 21:06:08 -04:00
|
|
|
|
2008-02-15 18:16:01 -05:00
|
|
|
if (!uuid) {
|
2007-09-21 14:49:14 -04:00
|
|
|
uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE);
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-09-21 14:49:14 -04:00
|
|
|
if (uuid && (other_session = switch_core_session_locate(uuid))) {
|
2007-10-01 10:57:15 -04:00
|
|
|
other_channel = switch_core_session_get_channel(other_session);
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BOND_VARIABLE, NULL);
|
|
|
|
switch_core_session_rwunlock(other_session);
|
|
|
|
}
|
2006-09-08 23:39:28 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE))
|
|
|
|
&& (other_session = switch_core_session_locate(uuid))) {
|
|
|
|
other_channel = switch_core_session_get_channel(other_session);
|
2006-09-08 23:39:28 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_channel_set_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
|
|
|
|
switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, NULL);
|
|
|
|
switch_channel_set_variable(other_channel, SWITCH_BRIDGE_VARIABLE, NULL);
|
2007-09-21 14:49:14 -04:00
|
|
|
|
|
|
|
/* If we are transferring the CALLER out of the bridge, we do not want to hang up on them */
|
|
|
|
switch_channel_set_variable(channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "false");
|
2006-09-08 23:39:28 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_channel_hangup(other_channel, SWITCH_CAUSE_BLIND_TRANSFER);
|
|
|
|
switch_ivr_media(uuid, SMF_NONE);
|
2006-09-08 23:39:28 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_core_session_rwunlock(other_session);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_channel_set_caller_profile(channel, new_profile);
|
|
|
|
switch_channel_set_flag(channel, CF_TRANSFER);
|
2007-06-25 17:25:33 -04:00
|
|
|
|
2008-05-05 11:30:55 -04:00
|
|
|
switch_channel_set_state(channel, CS_ROUTING);
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
msg.message_id = SWITCH_MESSAGE_INDICATE_TRANSFER;
|
|
|
|
msg.from = __FILE__;
|
|
|
|
switch_core_session_receive_message(session, &msg);
|
2006-09-08 23:39:28 -04:00
|
|
|
|
2007-03-29 20:15:25 -04:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Transfer %s to %s[%s@%s]\n", switch_channel_get_name(channel), dialplan, extension,
|
|
|
|
context);
|
2007-03-29 18:31:56 -04:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2006-09-08 23:39:28 -04:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
return SWITCH_STATUS_FALSE;
|
2006-09-08 23:39:28 -04:00
|
|
|
}
|
|
|
|
|
2007-03-29 20:13:31 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_transfer_variable(switch_core_session_t *sessa, switch_core_session_t *sessb, char *var)
|
2006-10-05 10:24:25 -04:00
|
|
|
{
|
|
|
|
switch_channel_t *chana = switch_core_session_get_channel(sessa);
|
|
|
|
switch_channel_t *chanb = switch_core_session_get_channel(sessb);
|
2007-11-01 07:28:26 -04:00
|
|
|
const char *val = NULL;
|
2007-02-12 20:22:17 -05:00
|
|
|
uint8_t prefix = 0;
|
2006-10-05 10:24:25 -04:00
|
|
|
|
2007-02-12 20:22:17 -05:00
|
|
|
if (var && *var == '~') {
|
|
|
|
var++;
|
|
|
|
prefix = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var && !prefix) {
|
2006-10-05 10:24:25 -04:00
|
|
|
if ((val = switch_channel_get_variable(chana, var))) {
|
|
|
|
switch_channel_set_variable(chanb, var, val);
|
|
|
|
}
|
|
|
|
} else {
|
2007-09-28 21:06:08 -04:00
|
|
|
switch_event_header_t *hi;
|
2007-09-24 15:34:25 -04:00
|
|
|
if ((hi = switch_channel_variable_first(chana))) {
|
2007-09-28 21:06:08 -04:00
|
|
|
for (; hi; hi = hi->next) {
|
|
|
|
char *vvar = hi->name;
|
|
|
|
char *vval = hi->value;
|
2007-04-28 17:48:03 -04:00
|
|
|
if (vvar && vval && (!prefix || (var && !strncmp((char *) vvar, var, strlen(var))))) {
|
|
|
|
switch_channel_set_variable(chanb, (char *) vvar, (char *) vval);
|
|
|
|
}
|
2006-10-05 10:24:25 -04:00
|
|
|
}
|
2007-04-28 17:48:03 -04:00
|
|
|
switch_channel_variable_last(chana);
|
2006-10-05 10:24:25 -04:00
|
|
|
}
|
|
|
|
}
|
2006-04-28 15:46:57 -04:00
|
|
|
|
2006-10-05 10:24:25 -04:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2006-11-11 19:32:18 -05:00
|
|
|
|
2006-12-04 00:41:03 -05:00
|
|
|
/******************************************************************************************************/
|
|
|
|
|
2006-11-13 11:29:16 -05:00
|
|
|
struct switch_ivr_digit_stream_parser {
|
|
|
|
int pool_auto_created;
|
|
|
|
switch_memory_pool_t *pool;
|
|
|
|
switch_hash_t *hash;
|
|
|
|
switch_size_t maxlen;
|
2006-12-04 00:41:03 -05:00
|
|
|
switch_size_t minlen;
|
2006-12-10 17:22:28 -05:00
|
|
|
char terminator;
|
2006-12-04 00:41:03 -05:00
|
|
|
unsigned int digit_timeout_ms;
|
2006-12-10 17:22:28 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct switch_ivr_digit_stream {
|
|
|
|
char *digits;
|
2006-12-04 00:41:03 -05:00
|
|
|
switch_time_t last_digit_time;
|
2006-11-13 11:29:16 -05:00
|
|
|
};
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_new(switch_memory_pool_t *pool, switch_ivr_digit_stream_parser_t **parser)
|
2007-03-29 18:31:56 -04:00
|
|
|
{
|
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
2006-11-13 11:29:16 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (parser != NULL) {
|
2006-11-13 11:29:16 -05:00
|
|
|
int pool_auto_created = 0;
|
|
|
|
|
2008-09-02 06:39:39 -04:00
|
|
|
/* if the caller didn't provide a pool, make one */
|
2006-11-13 11:29:16 -05:00
|
|
|
if (pool == NULL) {
|
|
|
|
switch_core_new_memory_pool(&pool);
|
2006-12-04 00:41:03 -05:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "created a memory pool\n");
|
2006-11-13 11:29:16 -05:00
|
|
|
if (pool != NULL) {
|
|
|
|
pool_auto_created = 1;
|
|
|
|
}
|
|
|
|
}
|
2008-09-02 06:39:39 -04:00
|
|
|
/* if we have a pool, make a parser object */
|
2006-11-13 11:29:16 -05:00
|
|
|
if (pool != NULL) {
|
2007-03-29 20:13:31 -04:00
|
|
|
*parser = (switch_ivr_digit_stream_parser_t *) switch_core_alloc(pool, sizeof(switch_ivr_digit_stream_parser_t));
|
2006-11-13 11:29:16 -05:00
|
|
|
}
|
2008-09-02 06:39:39 -04:00
|
|
|
/* if we have parser object, initialize it for the caller */
|
2008-01-28 03:47:55 -05:00
|
|
|
if (pool && *parser != NULL) {
|
2007-03-29 18:31:56 -04:00
|
|
|
memset(*parser, 0, sizeof(switch_ivr_digit_stream_parser_t));
|
2006-11-13 11:29:16 -05:00
|
|
|
(*parser)->pool_auto_created = pool_auto_created;
|
|
|
|
(*parser)->pool = pool;
|
2006-12-04 00:41:03 -05:00
|
|
|
(*parser)->digit_timeout_ms = 1000;
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_core_hash_init(&(*parser)->hash, (*parser)->pool);
|
2006-11-13 11:29:16 -05:00
|
|
|
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
} else {
|
|
|
|
status = SWITCH_STATUS_MEMERR;
|
2008-09-02 06:39:39 -04:00
|
|
|
/* if we can't create a parser object,clean up the pool if we created it */
|
2006-11-13 11:29:16 -05:00
|
|
|
if (pool != NULL && pool_auto_created) {
|
|
|
|
switch_core_destroy_memory_pool(&pool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
return status;
|
2006-11-11 19:32:18 -05:00
|
|
|
}
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_destroy(switch_ivr_digit_stream_parser_t *parser)
|
2006-11-11 19:32:18 -05:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
|
|
|
|
|
|
|
if (parser != NULL) {
|
|
|
|
if (parser->hash != NULL) {
|
2007-09-28 21:06:08 -04:00
|
|
|
switch_core_hash_destroy(&parser->hash);
|
2007-03-29 18:31:56 -04:00
|
|
|
parser->hash = NULL;
|
|
|
|
}
|
2008-09-02 06:39:39 -04:00
|
|
|
/* free the memory pool if we created it */
|
2007-03-29 18:31:56 -04:00
|
|
|
if (parser->pool_auto_created && parser->pool != NULL) {
|
|
|
|
status = switch_core_destroy_memory_pool(&parser->pool);
|
2006-11-12 15:34:04 -05:00
|
|
|
}
|
2006-11-11 19:32:18 -05:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
return status;
|
2006-11-11 19:32:18 -05:00
|
|
|
}
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_new(switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t **stream)
|
2006-11-11 19:32:18 -05:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
|
|
|
|
2008-10-06 19:05:55 -04:00
|
|
|
/* if we have a parser object memory pool and a stream object pointer that is null */
|
2007-03-29 18:31:56 -04:00
|
|
|
if (parser != NULL && parser->pool && stream != NULL && *stream == NULL) {
|
|
|
|
*stream = (switch_ivr_digit_stream_t *) switch_core_alloc(parser->pool, sizeof(switch_ivr_digit_stream_t));
|
|
|
|
if (*stream != NULL) {
|
|
|
|
memset(*stream, 0, sizeof(switch_ivr_digit_stream_t));
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
2006-12-04 00:41:03 -05:00
|
|
|
}
|
2006-11-11 19:32:18 -05:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
return status;
|
2006-11-11 19:32:18 -05:00
|
|
|
}
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_destroy(switch_ivr_digit_stream_t *stream)
|
2006-11-11 19:32:18 -05:00
|
|
|
{
|
2006-12-04 00:41:03 -05:00
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
2006-11-11 19:32:18 -05:00
|
|
|
|
2007-12-17 18:19:10 -05:00
|
|
|
if (stream && stream->digits != NULL) {
|
2007-03-29 18:31:56 -04:00
|
|
|
free(stream->digits);
|
|
|
|
stream->digits = NULL;
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
2006-11-11 19:32:18 -05:00
|
|
|
}
|
|
|
|
|
2006-12-04 00:41:03 -05:00
|
|
|
return status;
|
2006-11-11 19:32:18 -05:00
|
|
|
}
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_ivr_digit_stream_parser_t *parser, char *digits, void *data)
|
2006-11-12 15:34:04 -05:00
|
|
|
{
|
2006-12-04 00:41:03 -05:00
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
2007-02-13 12:15:42 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (parser != NULL && digits != NULL && *digits && parser->hash != NULL) {
|
2006-11-12 15:34:04 -05:00
|
|
|
|
2007-09-28 21:06:08 -04:00
|
|
|
status = switch_core_hash_insert(parser->hash, digits, data);
|
2007-03-29 18:31:56 -04:00
|
|
|
if (status == SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_size_t len = strlen(digits);
|
2006-11-12 15:34:04 -05:00
|
|
|
|
2008-09-02 06:39:39 -04:00
|
|
|
/* if we don't have a terminator, then we have to try and
|
|
|
|
* figure out when a digit set is completed, therefore we
|
|
|
|
* keep track of the min and max digit lengths
|
|
|
|
*/
|
2007-03-29 18:31:56 -04:00
|
|
|
if (parser->terminator == '\0') {
|
|
|
|
if (len > parser->maxlen) {
|
|
|
|
parser->maxlen = len;
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "max len %u\n", (uint32_t) parser->maxlen);
|
2007-02-15 16:59:59 -05:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
if (parser->minlen == 0 || len < parser->minlen) {
|
|
|
|
parser->minlen = len;
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "min len %u\n", (uint32_t) parser->minlen);
|
2007-02-15 16:59:59 -05:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
} else {
|
2008-09-02 06:39:39 -04:00
|
|
|
/* since we have a terminator, reset min and max */
|
2007-03-29 18:31:56 -04:00
|
|
|
parser->minlen = 0;
|
|
|
|
parser->maxlen = 0;
|
2007-02-13 12:15:42 -05:00
|
|
|
}
|
2006-11-12 15:34:04 -05:00
|
|
|
}
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
if (status != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to add hash for '%s'\n", digits);
|
|
|
|
}
|
2006-11-12 15:34:04 -05:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_ivr_digit_stream_parser_t *parser, char *digits)
|
2006-11-11 19:32:18 -05:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
2006-11-11 19:32:18 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (parser != NULL && digits != NULL && *digits) {
|
|
|
|
status = switch_core_hash_delete(parser->hash, digits);
|
2006-12-04 00:41:03 -05:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (status != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to del hash for '%s'\n", digits);
|
2006-11-11 19:32:18 -05:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
return status;
|
|
|
|
}
|
2006-11-11 19:32:18 -05:00
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(void *) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t *stream, char digit)
|
2007-03-29 18:31:56 -04:00
|
|
|
{
|
|
|
|
void *result = NULL;
|
2006-11-11 19:32:18 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (parser != NULL && stream != NULL) {
|
|
|
|
switch_size_t len = (stream->digits != NULL ? strlen(stream->digits) : 0);
|
2006-12-23 11:40:37 -05:00
|
|
|
|
2008-09-02 06:39:39 -04:00
|
|
|
/* handle new digit arrivals */
|
2007-03-29 18:31:56 -04:00
|
|
|
if (digit != '\0') {
|
2006-11-11 19:32:18 -05:00
|
|
|
|
2008-09-02 06:39:39 -04:00
|
|
|
/* if it's not a terminator digit, add it to the collected digits */
|
2007-03-29 18:31:56 -04:00
|
|
|
if (digit != parser->terminator) {
|
2008-09-02 06:39:39 -04:00
|
|
|
/* if collected digits length >= the max length of the keys
|
|
|
|
* in the hash table, then left shift the digit string
|
|
|
|
*/
|
2007-03-29 18:31:56 -04:00
|
|
|
if (len > 0 && parser->maxlen != 0 && len >= parser->maxlen) {
|
|
|
|
char *src = stream->digits + 1;
|
|
|
|
char *dst = stream->digits;
|
2006-11-11 19:32:18 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
while (*src) {
|
|
|
|
*(dst++) = *(src++);
|
|
|
|
}
|
|
|
|
*dst = digit;
|
|
|
|
} else {
|
2007-12-18 12:33:29 -05:00
|
|
|
char *tmp = realloc(stream->digits, len + 2);
|
|
|
|
switch_assert(tmp);
|
|
|
|
stream->digits = tmp;
|
2007-03-29 18:31:56 -04:00
|
|
|
*(stream->digits + (len++)) = digit;
|
|
|
|
*(stream->digits + len) = '\0';
|
2009-01-25 16:23:07 -05:00
|
|
|
stream->last_digit_time = switch_micro_time_now() / 1000;
|
2006-11-11 19:32:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-02 06:39:39 -04:00
|
|
|
/* don't allow collected digit string testing if there are varying sized keys until timeout */
|
2009-01-25 16:23:07 -05:00
|
|
|
if (parser->maxlen - parser->minlen > 0 && (switch_micro_time_now() / 1000) - stream->last_digit_time < parser->digit_timeout_ms) {
|
2007-03-29 18:31:56 -04:00
|
|
|
len = 0;
|
|
|
|
}
|
2008-09-02 06:39:39 -04:00
|
|
|
/* if we have digits to test */
|
2007-03-29 18:31:56 -04:00
|
|
|
if (len) {
|
|
|
|
result = switch_core_hash_find(parser->hash, stream->digits);
|
2008-09-02 06:39:39 -04:00
|
|
|
/* if we matched the digit string, or this digit is the terminator
|
|
|
|
* reset the collected digits for next digit string
|
|
|
|
*/
|
2007-03-29 18:31:56 -04:00
|
|
|
if (result != NULL || parser->terminator == digit) {
|
|
|
|
free(stream->digits);
|
|
|
|
stream->digits = NULL;
|
2007-02-13 12:15:42 -05:00
|
|
|
}
|
2006-11-11 19:32:18 -05:00
|
|
|
}
|
2006-12-04 00:41:03 -05:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
return result;
|
2006-11-11 19:32:18 -05:00
|
|
|
}
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_reset(switch_ivr_digit_stream_t *stream)
|
2006-12-04 00:41:03 -05:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
2006-12-04 00:41:03 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (stream != NULL && stream->digits != NULL) {
|
|
|
|
free(stream->digits);
|
|
|
|
stream->digits = NULL;
|
|
|
|
stream->last_digit_time = 0;
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
2006-12-04 00:41:03 -05:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
return status;
|
2006-12-04 00:41:03 -05:00
|
|
|
}
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_terminator(switch_ivr_digit_stream_parser_t *parser, char digit)
|
2006-12-04 00:41:03 -05:00
|
|
|
{
|
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (parser != NULL) {
|
|
|
|
parser->terminator = digit;
|
2008-09-02 06:39:39 -04:00
|
|
|
/* since we have a terminator, reset min and max */
|
2007-03-29 18:31:56 -04:00
|
|
|
parser->minlen = 0;
|
|
|
|
parser->maxlen = 0;
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
2006-12-04 00:41:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2007-10-02 15:58:06 -04:00
|
|
|
SWITCH_DECLARE(int) switch_ivr_set_xml_profile_data(switch_xml_t xml, switch_caller_profile_t *caller_profile, int off)
|
2006-11-13 11:29:16 -05:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_xml_t param;
|
2006-12-04 00:41:03 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "username", off++))) {
|
|
|
|
return -1;
|
2006-12-04 00:41:03 -05:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_xml_set_txt(param, caller_profile->username);
|
2006-12-04 00:41:03 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "dialplan", off++))) {
|
|
|
|
return -1;
|
2006-12-04 00:41:03 -05:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_xml_set_txt(param, caller_profile->dialplan);
|
2006-12-04 00:41:03 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "caller_id_name", off++))) {
|
|
|
|
return -1;
|
2006-12-04 00:41:03 -05:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_xml_set_txt(param, caller_profile->caller_id_name);
|
2006-12-04 00:41:03 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "ani", off++))) {
|
|
|
|
return -1;
|
2006-11-13 11:29:16 -05:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_xml_set_txt(param, caller_profile->ani);
|
2006-11-13 11:29:16 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "aniii", off++))) {
|
|
|
|
return -1;
|
2006-11-13 11:29:16 -05:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_xml_set_txt(param, caller_profile->aniii);
|
2006-11-13 11:29:16 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "caller_id_number", off++))) {
|
|
|
|
return -1;
|
2007-02-09 17:55:48 -05:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_xml_set_txt(param, caller_profile->caller_id_number);
|
2007-02-09 17:55:48 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "network_addr", off++))) {
|
|
|
|
return -1;
|
2007-02-09 17:55:48 -05:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_xml_set_txt(param, caller_profile->network_addr);
|
2007-02-09 17:55:48 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "rdnis", off++))) {
|
|
|
|
return -1;
|
2006-12-20 16:25:14 -05:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_xml_set_txt(param, caller_profile->rdnis);
|
2006-12-20 16:25:14 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "destination_number", off++))) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
switch_xml_set_txt(param, caller_profile->destination_number);
|
2007-02-14 10:19:01 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "uuid", off++))) {
|
2007-02-14 10:19:01 -05:00
|
|
|
return -1;
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_xml_set_txt(param, caller_profile->uuid);
|
2007-02-14 10:19:01 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "source", off++))) {
|
2007-02-14 10:19:01 -05:00
|
|
|
return -1;
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_xml_set_txt(param, caller_profile->source);
|
2007-02-14 10:19:01 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "context", off++))) {
|
2007-02-14 10:19:01 -05:00
|
|
|
return -1;
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_xml_set_txt(param, caller_profile->context);
|
2007-02-14 10:19:01 -05:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if (!(param = switch_xml_add_child_d(xml, "chan_name", off++))) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
switch_xml_set_txt(param, caller_profile->chan_name);
|
2007-02-14 10:19:01 -05:00
|
|
|
|
2007-10-02 12:38:15 -04:00
|
|
|
return off;
|
2007-02-14 10:19:01 -05:00
|
|
|
}
|
|
|
|
|
2007-10-02 15:58:06 -04:00
|
|
|
SWITCH_DECLARE(int) switch_ivr_set_xml_chan_vars(switch_xml_t xml, switch_channel_t *channel, int off)
|
|
|
|
{
|
|
|
|
switch_xml_t variable;
|
2007-12-10 23:21:54 -05:00
|
|
|
switch_event_header_t *hi = switch_channel_variable_first(channel);
|
2007-10-02 15:58:06 -04:00
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
if (!hi)
|
|
|
|
return off;
|
2007-12-10 23:21:54 -05:00
|
|
|
|
|
|
|
for (; hi; hi = hi->next) {
|
2008-01-08 11:20:00 -05:00
|
|
|
if (!switch_strlen_zero(hi->name) && !switch_strlen_zero(hi->value) && ((variable = switch_xml_add_child_d(xml, hi->name, off++)))) {
|
2007-12-10 23:21:54 -05:00
|
|
|
char *data;
|
|
|
|
switch_size_t dlen = strlen(hi->value) * 3;
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-12-10 23:21:54 -05:00
|
|
|
if ((data = malloc(dlen))) {
|
|
|
|
memset(data, 0, dlen);
|
|
|
|
switch_url_encode(hi->value, data, dlen);
|
|
|
|
switch_xml_set_txt_d(variable, data);
|
|
|
|
free(data);
|
2007-10-02 15:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-10 23:21:54 -05:00
|
|
|
switch_channel_variable_last(channel);
|
2007-10-02 15:58:06 -04:00
|
|
|
|
|
|
|
return off;
|
|
|
|
}
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t *xml_cdr)
|
2007-02-14 10:19:01 -05:00
|
|
|
{
|
2008-01-28 02:26:10 -05:00
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
2007-02-14 10:19:01 -05:00
|
|
|
switch_caller_profile_t *caller_profile;
|
2008-05-27 00:30:03 -04:00
|
|
|
switch_xml_t variables, cdr, x_main_cp, x_caller_profile, x_caller_extension, x_times, time_tag,
|
2007-10-02 12:38:15 -04:00
|
|
|
x_application, x_callflow, x_inner_extension, x_apps, x_o;
|
2007-04-20 21:03:58 -04:00
|
|
|
switch_app_log_t *app_log;
|
2007-02-14 10:19:01 -05:00
|
|
|
char tmp[512];
|
|
|
|
int cdr_off = 0, v_off = 0;
|
|
|
|
|
|
|
|
if (!(cdr = switch_xml_new("cdr"))) {
|
2007-03-29 18:31:56 -04:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2007-02-14 10:19:01 -05:00
|
|
|
|
|
|
|
if (!(variables = switch_xml_add_child_d(cdr, "variables", cdr_off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2007-04-20 21:03:58 -04:00
|
|
|
if ((app_log = switch_core_session_get_app_log(session))) {
|
|
|
|
int app_off = 0;
|
|
|
|
switch_app_log_t *ap;
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-04-20 21:03:58 -04:00
|
|
|
if (!(x_apps = switch_xml_add_child_d(cdr, "app_log", cdr_off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
for (ap = app_log; ap; ap = ap->next) {
|
2007-04-20 21:03:58 -04:00
|
|
|
|
|
|
|
if (!(x_application = switch_xml_add_child_d(x_apps, "application", app_off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-04-20 21:03:58 -04:00
|
|
|
switch_xml_set_attr_d(x_application, "app_name", ap->app);
|
|
|
|
switch_xml_set_attr_d(x_application, "app_data", ap->arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-02 15:58:06 -04:00
|
|
|
switch_ivr_set_xml_chan_vars(variables, channel, v_off);
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-02-14 10:19:01 -05:00
|
|
|
caller_profile = switch_channel_get_caller_profile(channel);
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2007-02-14 10:19:01 -05:00
|
|
|
while (caller_profile) {
|
|
|
|
int cf_off = 0;
|
2007-10-02 12:38:15 -04:00
|
|
|
int cp_off = 0;
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2007-02-14 10:19:01 -05:00
|
|
|
if (!(x_callflow = switch_xml_add_child_d(cdr, "callflow", cdr_off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
2008-02-26 18:29:58 -05:00
|
|
|
|
|
|
|
if (!switch_strlen_zero(caller_profile->dialplan)) {
|
|
|
|
switch_xml_set_attr_d(x_callflow, "dialplan", caller_profile->dialplan);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!switch_strlen_zero(caller_profile->profile_index)) {
|
|
|
|
switch_xml_set_attr_d(x_callflow, "profile_index", caller_profile->profile_index);
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2007-02-14 10:19:01 -05:00
|
|
|
if (caller_profile->caller_extension) {
|
|
|
|
switch_caller_application_t *ap;
|
2007-02-15 14:58:25 -05:00
|
|
|
int app_off = 0;
|
|
|
|
|
2007-02-14 10:19:01 -05:00
|
|
|
if (!(x_caller_extension = switch_xml_add_child_d(x_callflow, "extension", cf_off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-02-14 10:19:01 -05:00
|
|
|
switch_xml_set_attr_d(x_caller_extension, "name", caller_profile->caller_extension->extension_name);
|
|
|
|
switch_xml_set_attr_d(x_caller_extension, "number", caller_profile->caller_extension->extension_number);
|
|
|
|
if (caller_profile->caller_extension->current_application) {
|
2007-03-29 20:13:31 -04:00
|
|
|
switch_xml_set_attr_d(x_caller_extension, "current_app", caller_profile->caller_extension->current_application->application_name);
|
2007-02-14 10:19:01 -05:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
for (ap = caller_profile->caller_extension->applications; ap; ap = ap->next) {
|
2007-02-15 14:58:25 -05:00
|
|
|
if (!(x_application = switch_xml_add_child_d(x_caller_extension, "application", app_off++))) {
|
2007-02-14 10:19:01 -05:00
|
|
|
goto error;
|
|
|
|
}
|
2007-02-15 15:02:52 -05:00
|
|
|
if (ap == caller_profile->caller_extension->current_application) {
|
|
|
|
switch_xml_set_attr_d(x_application, "last_executed", "true");
|
|
|
|
}
|
2007-02-14 10:19:01 -05:00
|
|
|
switch_xml_set_attr_d(x_application, "app_name", ap->application_name);
|
|
|
|
switch_xml_set_attr_d(x_application, "app_data", ap->application_data);
|
|
|
|
}
|
2007-04-20 21:03:58 -04:00
|
|
|
|
|
|
|
if (caller_profile->caller_extension->children) {
|
|
|
|
switch_caller_profile_t *cp = NULL;
|
|
|
|
int i_off = 0;
|
|
|
|
for (cp = caller_profile->caller_extension->children; cp; cp = cp->next) {
|
2007-12-17 18:19:10 -05:00
|
|
|
app_off = 0;
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-04-20 21:03:58 -04:00
|
|
|
if (!cp->caller_extension) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!(x_inner_extension = switch_xml_add_child_d(x_caller_extension, "sub_extensions", i_off++))) {
|
|
|
|
goto error;
|
2008-05-27 00:30:03 -04:00
|
|
|
}
|
2007-04-20 21:03:58 -04:00
|
|
|
|
|
|
|
if (!(x_caller_extension = switch_xml_add_child_d(x_inner_extension, "extension", cf_off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
switch_xml_set_attr_d(x_caller_extension, "name", cp->caller_extension->extension_name);
|
|
|
|
switch_xml_set_attr_d(x_caller_extension, "number", cp->caller_extension->extension_number);
|
|
|
|
switch_xml_set_attr_d(x_caller_extension, "dialplan", cp->dialplan);
|
|
|
|
if (cp->caller_extension->current_application) {
|
|
|
|
switch_xml_set_attr_d(x_caller_extension, "current_app", cp->caller_extension->current_application->application_name);
|
|
|
|
}
|
2008-05-27 00:30:03 -04:00
|
|
|
|
2007-04-20 21:03:58 -04:00
|
|
|
for (ap = cp->caller_extension->applications; ap; ap = ap->next) {
|
|
|
|
if (!(x_application = switch_xml_add_child_d(x_caller_extension, "application", app_off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (ap == cp->caller_extension->current_application) {
|
|
|
|
switch_xml_set_attr_d(x_application, "last_executed", "true");
|
|
|
|
}
|
|
|
|
switch_xml_set_attr_d(x_application, "app_name", ap->application_name);
|
|
|
|
switch_xml_set_attr_d(x_application, "app_data", ap->application_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-14 10:19:01 -05:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2007-10-02 12:38:15 -04:00
|
|
|
if (!(x_main_cp = switch_xml_add_child_d(x_callflow, "caller_profile", cf_off++))) {
|
2007-02-14 10:19:01 -05:00
|
|
|
goto error;
|
|
|
|
}
|
2007-10-02 12:38:15 -04:00
|
|
|
|
2007-10-02 15:58:06 -04:00
|
|
|
cp_off += switch_ivr_set_xml_profile_data(x_main_cp, caller_profile, 0);
|
2007-02-14 10:19:01 -05:00
|
|
|
|
|
|
|
if (caller_profile->originator_caller_profile) {
|
2007-10-02 12:38:15 -04:00
|
|
|
switch_caller_profile_t *cp = NULL;
|
|
|
|
int off = 0;
|
|
|
|
if (!(x_o = switch_xml_add_child_d(x_main_cp, "originator", cp_off++))) {
|
2007-02-14 10:19:01 -05:00
|
|
|
goto error;
|
|
|
|
}
|
2007-10-02 12:38:15 -04:00
|
|
|
|
|
|
|
for (cp = caller_profile->originator_caller_profile; cp; cp = cp->next) {
|
|
|
|
if (!(x_caller_profile = switch_xml_add_child_d(x_o, "originator_caller_profile", off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
2007-10-02 15:58:06 -04:00
|
|
|
switch_ivr_set_xml_profile_data(x_caller_profile, cp, 0);
|
2007-10-02 12:38:15 -04:00
|
|
|
}
|
2007-02-14 10:19:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (caller_profile->originatee_caller_profile) {
|
2007-10-02 12:38:15 -04:00
|
|
|
switch_caller_profile_t *cp = NULL;
|
|
|
|
int off = 0;
|
|
|
|
if (!(x_o = switch_xml_add_child_d(x_main_cp, "originatee", cp_off++))) {
|
2007-02-14 10:19:01 -05:00
|
|
|
goto error;
|
|
|
|
}
|
2007-10-02 12:38:15 -04:00
|
|
|
for (cp = caller_profile->originatee_caller_profile; cp; cp = cp->next) {
|
|
|
|
if (!(x_caller_profile = switch_xml_add_child_d(x_o, "originatee_caller_profile", off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
2008-10-30 11:18:07 -04:00
|
|
|
switch_ivr_set_xml_profile_data(x_caller_profile, cp, 0);
|
2007-10-02 12:38:15 -04:00
|
|
|
}
|
2007-02-14 10:19:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (caller_profile->times) {
|
2007-02-15 14:20:14 -05:00
|
|
|
int t_off = 0;
|
|
|
|
if (!(x_times = switch_xml_add_child_d(x_callflow, "times", cf_off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!(time_tag = switch_xml_add_child_d(x_times, "created_time", t_off++))) {
|
2007-02-14 10:19:01 -05:00
|
|
|
goto error;
|
|
|
|
}
|
2007-12-12 16:53:32 -05:00
|
|
|
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->created);
|
2007-02-15 14:20:14 -05:00
|
|
|
switch_xml_set_txt_d(time_tag, tmp);
|
2007-02-14 10:19:01 -05:00
|
|
|
|
2007-12-20 12:27:11 -05:00
|
|
|
if (!(time_tag = switch_xml_add_child_d(x_times, "profile_created_time", t_off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->profile_created);
|
|
|
|
switch_xml_set_txt_d(time_tag, tmp);
|
|
|
|
|
2008-05-23 21:43:12 -04:00
|
|
|
if (!(time_tag = switch_xml_add_child_d(x_times, "progress_time", t_off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress);
|
|
|
|
switch_xml_set_txt_d(time_tag, tmp);
|
|
|
|
|
|
|
|
|
|
|
|
if (!(time_tag = switch_xml_add_child_d(x_times, "progress_media_time", t_off++))) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress_media);
|
|
|
|
switch_xml_set_txt_d(time_tag, tmp);
|
|
|
|
|
2007-02-15 14:20:14 -05:00
|
|
|
if (!(time_tag = switch_xml_add_child_d(x_times, "answered_time", t_off++))) {
|
2007-02-14 10:19:01 -05:00
|
|
|
goto error;
|
|
|
|
}
|
2007-12-12 16:53:32 -05:00
|
|
|
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
|
2007-02-15 14:20:14 -05:00
|
|
|
switch_xml_set_txt_d(time_tag, tmp);
|
2007-02-14 10:19:01 -05:00
|
|
|
|
2007-02-15 14:20:14 -05:00
|
|
|
if (!(time_tag = switch_xml_add_child_d(x_times, "hangup_time", t_off++))) {
|
2007-02-14 10:19:01 -05:00
|
|
|
goto error;
|
|
|
|
}
|
2007-12-12 16:53:32 -05:00
|
|
|
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
|
2007-02-15 14:20:14 -05:00
|
|
|
switch_xml_set_txt_d(time_tag, tmp);
|
2007-02-14 10:19:01 -05:00
|
|
|
|
2007-02-15 14:20:14 -05:00
|
|
|
if (!(time_tag = switch_xml_add_child_d(x_times, "transfer_time", t_off++))) {
|
2007-02-14 10:19:01 -05:00
|
|
|
goto error;
|
|
|
|
}
|
2007-12-12 16:53:32 -05:00
|
|
|
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->transferred);
|
2007-02-15 14:20:14 -05:00
|
|
|
switch_xml_set_txt_d(time_tag, tmp);
|
2007-02-14 10:19:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
caller_profile = caller_profile->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
*xml_cdr = cdr;
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
error:
|
2007-02-14 10:19:01 -05:00
|
|
|
|
|
|
|
if (cdr) {
|
|
|
|
switch_xml_free(cdr);
|
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2007-02-14 10:19:01 -05:00
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-12-13 17:17:20 -05:00
|
|
|
SWITCH_DECLARE(void) switch_ivr_park_session(switch_core_session_t *session)
|
|
|
|
{
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
|
|
|
switch_channel_set_state(channel, CS_PARK);
|
2008-10-27 13:14:55 -04:00
|
|
|
switch_channel_set_flag(channel, CF_TRANSFER);
|
|
|
|
|
2007-12-13 17:17:20 -05:00
|
|
|
}
|
|
|
|
|
2007-10-04 11:09:44 -04:00
|
|
|
SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint32_t delay_ms)
|
|
|
|
{
|
|
|
|
stfu_instance_t *jb;
|
|
|
|
int qlen = 0;
|
|
|
|
switch_codec_t *read_codec;
|
|
|
|
stfu_frame_t *jb_frame;
|
|
|
|
switch_frame_t *read_frame, write_frame = { 0 };
|
|
|
|
switch_status_t status;
|
2008-01-28 02:26:10 -05:00
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
2007-10-04 11:09:44 -04:00
|
|
|
uint32_t interval, samples;
|
|
|
|
uint32_t ts = 0;
|
|
|
|
|
2007-10-04 20:05:41 -04:00
|
|
|
if (delay_ms < 1 || delay_ms > 10000) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid delay [%d] must be between 1 and 10000\n", delay_ms);
|
2007-10-04 11:09:44 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
read_codec = switch_core_session_get_read_codec(session);
|
2008-10-20 13:48:42 -04:00
|
|
|
interval = read_codec->implementation->microseconds_per_packet / 1000;
|
|
|
|
samples = switch_samples_per_packet(read_codec->implementation->samples_per_second, interval);
|
2007-10-04 11:09:44 -04:00
|
|
|
|
|
|
|
qlen = delay_ms / (interval);
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setting delay to %dms (%d frames)\n", delay_ms, qlen);
|
|
|
|
jb = stfu_n_init(qlen);
|
|
|
|
|
|
|
|
write_frame.codec = read_codec;
|
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
while (switch_channel_ready(channel)) {
|
2008-05-08 15:19:47 -04:00
|
|
|
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
|
2007-10-04 11:09:44 -04:00
|
|
|
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
stfu_n_eat(jb, ts, read_frame->data, read_frame->datalen);
|
|
|
|
ts += interval;
|
|
|
|
|
|
|
|
if ((jb_frame = stfu_n_read_a_frame(jb))) {
|
|
|
|
write_frame.data = jb_frame->data;
|
2008-05-27 00:30:03 -04:00
|
|
|
write_frame.datalen = (uint32_t) jb_frame->dlen;
|
2008-05-08 15:19:47 -04:00
|
|
|
status = switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
|
2007-10-04 11:09:44 -04:00
|
|
|
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stfu_n_destroy(&jb);
|
|
|
|
}
|
2007-02-14 10:19:01 -05:00
|
|
|
|
2008-05-27 00:30:03 -04:00
|
|
|
SWITCH_DECLARE(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, switch_input_args_t *args)
|
2008-05-09 18:16:08 -04:00
|
|
|
{
|
|
|
|
switch_say_interface_t *si;
|
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
if ((si = switch_loadable_module_get_say_interface(module_name))) {
|
2008-09-02 06:39:39 -04:00
|
|
|
/* should go back and proto all the say mods to const.... */
|
2008-05-27 00:30:03 -04:00
|
|
|
status = si->say_function(session, (char *) tosay, switch_ivr_get_say_type_by_name(say_type), switch_ivr_get_say_method_by_name(say_method), args);
|
2008-05-09 18:16:08 -04:00
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid SAY Interface [%s]!\n", module_name);
|
|
|
|
status = SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
2007-02-14 10:19:01 -05:00
|
|
|
|
2008-05-24 13:28:04 -04:00
|
|
|
|
2008-07-16 13:44:54 -04:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_ivr_set_user(switch_core_session_t *session, const char *data)
|
|
|
|
{
|
2008-12-23 12:36:50 -05:00
|
|
|
switch_xml_t x_domain, xml = NULL, x_user, x_param, x_params, x_group = NULL;
|
2008-07-16 13:44:54 -04:00
|
|
|
char *user, *mailbox, *domain;
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
|
|
|
|
|
|
|
if (switch_strlen_zero(data)) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
user = switch_core_session_strdup(session, data);
|
|
|
|
|
|
|
|
if (!(domain = strchr(user, '@'))) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
*domain++ = '\0';
|
|
|
|
|
2008-12-23 12:36:50 -05:00
|
|
|
if (switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, &x_group, NULL) != SWITCH_STATUS_SUCCESS) {
|
2008-07-16 13:44:54 -04:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", user, domain);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
if ((mailbox = (char *) switch_xml_attr(x_user, "mailbox"))) {
|
|
|
|
switch_channel_set_variable(channel, "mailbox", mailbox);
|
|
|
|
}
|
|
|
|
|
2008-09-02 12:38:45 -04:00
|
|
|
if ((x_params = switch_xml_child(x_domain, "variables"))) {
|
|
|
|
for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
|
2008-12-23 12:36:50 -05:00
|
|
|
const char *var = switch_xml_attr(x_param, "name");
|
|
|
|
const char *val = switch_xml_attr(x_param, "value");
|
|
|
|
|
|
|
|
if (var && val) {
|
|
|
|
switch_channel_set_variable(channel, var, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x_group && (x_params = switch_xml_child(x_group, "variables"))) {
|
|
|
|
for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
|
2008-09-02 12:38:45 -04:00
|
|
|
const char *var = switch_xml_attr(x_param, "name");
|
|
|
|
const char *val = switch_xml_attr(x_param, "value");
|
|
|
|
|
|
|
|
if (var && val) {
|
|
|
|
switch_channel_set_variable(channel, var, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-16 13:44:54 -04:00
|
|
|
if ((x_params = switch_xml_child(x_user, "variables"))) {
|
|
|
|
for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
|
|
|
|
const char *var = switch_xml_attr(x_param, "name");
|
|
|
|
const char *val = switch_xml_attr(x_param, "value");
|
|
|
|
|
|
|
|
if (var && val) {
|
|
|
|
switch_channel_set_variable(channel, var, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_channel_set_variable(channel, "user_name", user);
|
|
|
|
switch_channel_set_variable(channel, "domain_name", domain);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
error:
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No user@domain specified.\n");
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (xml) {
|
|
|
|
switch_xml_free(xml);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2006-11-27 17:30:48 -05:00
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2008-02-03 17:14:57 -05:00
|
|
|
* indent-tabs-mode:t
|
2006-11-27 17:30:48 -05:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
2008-07-03 15:12:26 -04:00
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
2006-11-27 17:30:48 -05:00
|
|
|
*/
|