From efca0c8087d98c5d1e05a2b3df31e494d6597219 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 12 Jun 2007 21:00:26 +0000 Subject: [PATCH] hack up the core with a butcher knife git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5314 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_core.h | 10 +- src/include/switch_core_event_hook.h | 181 +++++++------- .../mod_event_socket/mod_event_socket.c | 5 - src/switch_channel.c | 9 +- src/switch_core_event_hook.c | 232 ++---------------- src/switch_core_io.c | 39 ++- src/switch_ivr.c | 8 + src/switch_ivr_bridge.c | 26 +- 8 files changed, 168 insertions(+), 342 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 97586a2d06..79d9e3c067 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -789,7 +789,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_waitfor_write(switch_core_se \param dtmf string to send to the session \return SWITCH_STATUS_SUCCESS if the dtmf was written */ -SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_session_t *session, char *dtmf); +SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_session_t *session, const char *dtmf); + +/*! + \brief RECV DTMF on a session + \param session session to recv DTMF from + \param dtmf string to recv from the session + \return SWITCH_STATUS_SUCCESS if the dtmf is ok to queue +*/ +SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(switch_core_session_t *session, const char *dtmf); ///\} diff --git a/src/include/switch_core_event_hook.h b/src/include/switch_core_event_hook.h index 8ed8c0ac7b..8f48d87df7 100644 --- a/src/include/switch_core_event_hook.h +++ b/src/include/switch_core_event_hook.h @@ -32,7 +32,8 @@ #define SWITCH_EVENT_HOOKS_H #include -SWITCH_BEGIN_EXTERN_C typedef struct switch_io_event_hooks switch_io_event_hooks_t; +SWITCH_BEGIN_EXTERN_C +typedef struct switch_io_event_hooks switch_io_event_hooks_t; typedef struct switch_io_event_hook_outgoing_channel switch_io_event_hook_outgoing_channel_t; typedef struct switch_io_event_hook_receive_message switch_io_event_hook_receive_message_t; @@ -45,9 +46,8 @@ typedef struct switch_io_event_hook_kill_channel switch_io_event_hook_kill_chann typedef struct switch_io_event_hook_waitfor_read switch_io_event_hook_waitfor_read_t; typedef struct switch_io_event_hook_waitfor_write switch_io_event_hook_waitfor_write_t; typedef struct switch_io_event_hook_send_dtmf switch_io_event_hook_send_dtmf_t; +typedef struct switch_io_event_hook_recv_dtmf switch_io_event_hook_recv_dtmf_t; typedef struct switch_io_event_hook_state_change switch_io_event_hook_state_change_t; - - typedef switch_status_t (*switch_outgoing_channel_hook_t) (switch_core_session_t *, switch_caller_profile_t *, switch_core_session_t *); typedef switch_status_t (*switch_receive_message_hook_t) (switch_core_session_t *, switch_core_session_message_t *); typedef switch_status_t (*switch_receive_event_hook_t) (switch_core_session_t *, switch_event_t *); @@ -58,24 +58,24 @@ typedef switch_status_t (*switch_video_write_frame_hook_t) (switch_core_session_ typedef switch_status_t (*switch_kill_channel_hook_t) (switch_core_session_t *, int); typedef switch_status_t (*switch_waitfor_read_hook_t) (switch_core_session_t *, int, int); typedef switch_status_t (*switch_waitfor_write_hook_t) (switch_core_session_t *, int, int); -typedef switch_status_t (*switch_send_dtmf_hook_t) (switch_core_session_t *, char *); +typedef switch_status_t (*switch_send_dtmf_hook_t) (switch_core_session_t *, const char *); +typedef switch_status_t (*switch_recv_dtmf_hook_t) (switch_core_session_t *, const char *); typedef switch_status_t (*switch_state_change_hook_t) (switch_core_session_t *); -/*! \brief Node in which to store custom outgoing channel callback hooks */ +/*! \brief Node in which to store custom receive message callback hooks */ struct switch_io_event_hook_outgoing_channel { - /*! the outgoing channel callback hook */ switch_outgoing_channel_hook_t outgoing_channel; struct switch_io_event_hook_outgoing_channel *next; }; /*! \brief Node in which to store custom receive message callback hooks */ struct switch_io_event_hook_receive_message { - /*! the message callback hook */ switch_receive_message_hook_t receive_message; struct switch_io_event_hook_receive_message *next; }; + /*! \brief Node in which to store custom receive message callback hooks */ struct switch_io_event_hook_receive_event { /*! the event callback hook */ @@ -139,9 +139,16 @@ struct switch_io_event_hook_send_dtmf { struct switch_io_event_hook_send_dtmf *next; }; +/*! \brief Node in which to store custom recv dtmf channel callback hooks */ +struct switch_io_event_hook_recv_dtmf { + /*! the recv dtmf channel callback hook */ + switch_recv_dtmf_hook_t recv_dtmf; + struct switch_io_event_hook_recv_dtmf *next; +}; + /*! \brief Node in which to store state change callback hooks */ struct switch_io_event_hook_state_change { - /*! the send dtmf channel callback hook */ + /*! the state change channel callback hook */ switch_state_change_hook_t state_change; struct switch_io_event_hook_state_change *next; }; @@ -170,106 +177,82 @@ struct switch_io_event_hooks { switch_io_event_hook_waitfor_write_t *waitfor_write; /*! a list of send dtmf hooks */ switch_io_event_hook_send_dtmf_t *send_dtmf; + /*! a list of recv dtmf hooks */ + switch_io_event_hook_recv_dtmf_t *recv_dtmf; /*! a list of state change hooks */ switch_io_event_hook_state_change_t *state_change; }; extern switch_io_event_hooks_t switch_core_session_get_event_hooks(switch_core_session_t *session); +#define NEW_HOOK_DECL_ADD_P(_NAME) SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_##_NAME \ + (switch_core_session_t *session, switch_##_NAME##_hook_t _NAME) + +#define NEW_HOOK_DECL_REM_P(_NAME) SWITCH_DECLARE(switch_status_t) switch_core_event_hook_remove_##_NAME \ + (switch_core_session_t *session, switch_##_NAME##_hook_t _NAME) + +#define NEW_HOOK_DECL(_NAME) NEW_HOOK_DECL_ADD_P(_NAME) \ + { \ + switch_io_event_hook_##_NAME##_t *hook, *ptr; \ + assert(_NAME != NULL); \ + if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { \ + hook->_NAME = _NAME ; \ + if (! session->event_hooks._NAME ) { \ + session->event_hooks._NAME = hook; \ + } else { \ + for (ptr = session->event_hooks._NAME; ptr && ptr->next; ptr = ptr->next); \ + ptr->next = hook; \ + } \ + return SWITCH_STATUS_SUCCESS; \ + } \ + return SWITCH_STATUS_MEMERR; \ + } \ + NEW_HOOK_DECL_REM_P(_NAME) \ + { \ + switch_io_event_hook_##_NAME##_t *ptr, *last = NULL; \ + assert(_NAME != NULL); \ + for (ptr = session->event_hooks._NAME; ptr; ptr = ptr->next) { \ + if (ptr->_NAME == _NAME) { \ + if (last) { \ + last->next = ptr->next; \ + } else { \ + session->event_hooks._NAME = ptr->next; \ + } \ + return SWITCH_STATUS_SUCCESS; \ + } \ + last = ptr; \ + } \ + return SWITCH_STATUS_FALSE; \ + } -///\defgroup shooks Session Hook Callbacks -///\ingroup core1 -///\{ +NEW_HOOK_DECL_ADD_P(outgoing_channel); +NEW_HOOK_DECL_ADD_P(receive_message); +NEW_HOOK_DECL_ADD_P(receive_event); +NEW_HOOK_DECL_ADD_P(state_change); +NEW_HOOK_DECL_ADD_P(read_frame); +NEW_HOOK_DECL_ADD_P(write_frame); +NEW_HOOK_DECL_ADD_P(video_read_frame); +NEW_HOOK_DECL_ADD_P(video_write_frame); +NEW_HOOK_DECL_ADD_P(kill_channel); +NEW_HOOK_DECL_ADD_P(waitfor_read); +NEW_HOOK_DECL_ADD_P(waitfor_write); +NEW_HOOK_DECL_ADD_P(send_dtmf); +NEW_HOOK_DECL_ADD_P(recv_dtmf); -/*! - \brief Add an event hook to be executed when a session requests an outgoing extension - \param session session to bind hook to - \param outgoing_channel hook to bind - \return SWITCH_STATUS_SUCCESS on suceess -*/ -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_outgoing_channel(switch_core_session_t *session, - switch_outgoing_channel_hook_t outgoing_channel); - -/*! - \brief Add an event hook to be executed when a session sends a message - \param session session to bind hook to - \param receive_message hook to bind - \return SWITCH_STATUS_SUCCESS on suceess -*/ -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_receive_message(switch_core_session_t *session, switch_receive_message_hook_t receive_message); - -/*! - \brief Add an event hook to be executed when a session reads a frame - \param session session to bind hook to - \param read_frame hook to bind - \return SWITCH_STATUS_SUCCESS on suceess -*/ -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_read_frame(switch_core_session_t *session, switch_read_frame_hook_t read_frame); - -/*! - \brief Add an event hook to be executed when a session reads a frame - \param session session to bind hook to - \param video_read_frame hook to bind - \return SWITCH_STATUS_SUCCESS on suceess -*/ -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_video_read_frame(switch_core_session_t *session, switch_read_frame_hook_t video_read_frame); - -/*! - \brief Add an event hook to be executed when a session writes a frame - \param session session to bind hook to - \param write_frame hook to bind - \return SWITCH_STATUS_SUCCESS on suceess -*/ -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_write_frame(switch_core_session_t *session, switch_write_frame_hook_t write_frame); - -/*! - \brief Add an event hook to be executed when a session writes a video frame - \param session session to bind hook to - \param video_write_frame hook to bind - \return SWITCH_STATUS_SUCCESS on suceess -*/ -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_video_write_frame(switch_core_session_t *session, switch_video_write_frame_hook_t video_write_frame); - -/*! - \brief Add an event hook to be executed when a session kills a channel - \param session session to bind hook to - \param kill_channel hook to bind - \return SWITCH_STATUS_SUCCESS on suceess -*/ -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_kill_channel(switch_core_session_t *session, switch_kill_channel_hook_t kill_channel); - -/*! - \brief Add an event hook to be executed when a session waits for a read event - \param session session to bind hook to - \param waitfor_read hook to bind - \return SWITCH_STATUS_SUCCESS on suceess -*/ -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_waitfor_read(switch_core_session_t *session, switch_waitfor_read_hook_t waitfor_read); - -/*! - \brief Add an event hook to be executed when a session waits for a write event - \param session session to bind hook to - \param waitfor_write hook to bind - \return SWITCH_STATUS_SUCCESS on suceess -*/ -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_waitfor_write(switch_core_session_t *session, switch_waitfor_write_hook_t waitfor_write); - -/*! - \brief Add an event hook to be executed when a session sends dtmf - \param session session to bind hook to - \param send_dtmf hook to bind - \return SWITCH_STATUS_SUCCESS on suceess -*/ -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_send_dtmf(switch_core_session_t *session, switch_send_dtmf_hook_t send_dtmf); - -/*! - \brief Add an event hook to be executed when a session receives a state change signal - \param session session to bind hook to - \param state_change hook to bind - \return SWITCH_STATUS_SUCCESS on suceess -*/ -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_state_change(switch_core_session_t *session, switch_state_change_hook_t state_change); +NEW_HOOK_DECL_REM_P(outgoing_channel); +NEW_HOOK_DECL_REM_P(receive_message); +NEW_HOOK_DECL_REM_P(receive_event); +NEW_HOOK_DECL_REM_P(state_change); +NEW_HOOK_DECL_REM_P(read_frame); +NEW_HOOK_DECL_REM_P(write_frame); +NEW_HOOK_DECL_REM_P(video_read_frame); +NEW_HOOK_DECL_REM_P(video_write_frame); +NEW_HOOK_DECL_REM_P(kill_channel); +NEW_HOOK_DECL_REM_P(waitfor_read); +NEW_HOOK_DECL_REM_P(waitfor_write); +NEW_HOOK_DECL_REM_P(send_dtmf); +NEW_HOOK_DECL_REM_P(recv_dtmf); ///\} SWITCH_END_EXTERN_C diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c index fdeae10aa3..8149ec62f4 100644 --- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c +++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c @@ -136,11 +136,6 @@ static void event_handler(switch_event_t *event) if (event->event_id != SWITCH_EVENT_CUSTOM || (event->subclass && switch_core_hash_find(l->event_hash, event->subclass->name))) { send = 1; } - } else { - int x; - for(x = 0; x <= SWITCH_EVENT_ALL; x++) { - printf("%d ", l->event_list[x]); - } } if (send && switch_test_flag(l, LFLAG_MYEVENTS)) { diff --git a/src/switch_channel.c b/src/switch_channel.c index e4b41f263f..36ff1b1cf6 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -208,7 +208,11 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *chan assert(channel != NULL); - switch_mutex_lock(channel->dtmf_mutex); + switch_mutex_lock(channel->dtmf_mutex); + + if ((status = switch_core_session_recv_dtmf(channel->session, dtmf) != SWITCH_STATUS_SUCCESS)) { + goto done; + } inuse = switch_buffer_inuse(channel->dtmf_buffer); len = strlen(dtmf); @@ -227,6 +231,9 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *chan p++; } status = switch_buffer_write(channel->dtmf_buffer, dtmf, wr) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_MEMERR; + + done: + switch_mutex_unlock(channel->dtmf_mutex); return status; diff --git a/src/switch_core_event_hook.c b/src/switch_core_event_hook.c index 60feeab3a8..c7fa8ba7ce 100644 --- a/src/switch_core_event_hook.c +++ b/src/switch_core_event_hook.c @@ -31,222 +31,18 @@ #include "switch.h" #include "private/switch_core_pvt.h" -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_outgoing(switch_core_session_t *session, switch_outgoing_channel_hook_t outgoing_channel) -{ - switch_io_event_hook_outgoing_channel_t *hook, *ptr; + - assert(outgoing_channel != NULL); - if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { - hook->outgoing_channel = outgoing_channel; - if (!session->event_hooks.outgoing_channel) { - session->event_hooks.outgoing_channel = hook; - } else { - for (ptr = session->event_hooks.outgoing_channel; ptr && ptr->next; ptr = ptr->next); - ptr->next = hook; - - } - - return SWITCH_STATUS_SUCCESS; - } - - return SWITCH_STATUS_MEMERR; -} - -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_state_change(switch_core_session_t *session, switch_state_change_hook_t state_change) -{ - switch_io_event_hook_state_change_t *hook, *ptr; - - assert(state_change != NULL); - if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { - hook->state_change = state_change; - if (!session->event_hooks.state_change) { - session->event_hooks.state_change = hook; - } else { - for (ptr = session->event_hooks.state_change; ptr && ptr->next; ptr = ptr->next); - ptr->next = hook; - - } - - return SWITCH_STATUS_SUCCESS; - } - - return SWITCH_STATUS_MEMERR; - -} - -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_read_frame(switch_core_session_t *session, switch_read_frame_hook_t read_frame) -{ - switch_io_event_hook_read_frame_t *hook, *ptr; - - assert(read_frame != NULL); - if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { - hook->read_frame = read_frame; - if (!session->event_hooks.read_frame) { - session->event_hooks.read_frame = hook; - } else { - for (ptr = session->event_hooks.read_frame; ptr && ptr->next; ptr = ptr->next); - ptr->next = hook; - - } - - return SWITCH_STATUS_SUCCESS; - } - - return SWITCH_STATUS_MEMERR; - -} - -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_write_frame(switch_core_session_t *session, switch_write_frame_hook_t write_frame) -{ - switch_io_event_hook_write_frame_t *hook, *ptr; - - assert(write_frame != NULL); - if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { - hook->write_frame = write_frame; - if (!session->event_hooks.write_frame) { - session->event_hooks.write_frame = hook; - } else { - for (ptr = session->event_hooks.write_frame; ptr && ptr->next; ptr = ptr->next); - ptr->next = hook; - - } - - return SWITCH_STATUS_SUCCESS; - } - - return SWITCH_STATUS_MEMERR; - -} - -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_video_read_frame(switch_core_session_t *session, switch_video_read_frame_hook_t video_read_frame) -{ - switch_io_event_hook_video_read_frame_t *hook, *ptr; - - assert(video_read_frame != NULL); - if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { - hook->video_read_frame = video_read_frame; - if (!session->event_hooks.video_read_frame) { - session->event_hooks.video_read_frame = hook; - } else { - for (ptr = session->event_hooks.video_read_frame; ptr && ptr->next; ptr = ptr->next); - ptr->next = hook; - - } - - return SWITCH_STATUS_SUCCESS; - } - - return SWITCH_STATUS_MEMERR; - -} - -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_video_write_frame(switch_core_session_t *session, switch_video_write_frame_hook_t video_write_frame) -{ - switch_io_event_hook_video_write_frame_t *hook, *ptr; - - assert(video_write_frame != NULL); - if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { - hook->video_write_frame = video_write_frame; - if (!session->event_hooks.video_write_frame) { - session->event_hooks.video_write_frame = hook; - } else { - for (ptr = session->event_hooks.video_write_frame; ptr && ptr->next; ptr = ptr->next); - ptr->next = hook; - - } - - return SWITCH_STATUS_SUCCESS; - } - - return SWITCH_STATUS_MEMERR; - -} - -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_kill_channel(switch_core_session_t *session, switch_kill_channel_hook_t kill_channel) -{ - switch_io_event_hook_kill_channel_t *hook, *ptr; - - assert(kill_channel != NULL); - if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { - hook->kill_channel = kill_channel; - if (!session->event_hooks.kill_channel) { - session->event_hooks.kill_channel = hook; - } else { - for (ptr = session->event_hooks.kill_channel; ptr && ptr->next; ptr = ptr->next); - ptr->next = hook; - - } - - return SWITCH_STATUS_SUCCESS; - } - - return SWITCH_STATUS_MEMERR; - -} - -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_waitfor_read(switch_core_session_t *session, switch_waitfor_read_hook_t waitfor_read) -{ - switch_io_event_hook_waitfor_read_t *hook, *ptr; - - assert(waitfor_read != NULL); - if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { - hook->waitfor_read = waitfor_read; - if (!session->event_hooks.waitfor_read) { - session->event_hooks.waitfor_read = hook; - } else { - for (ptr = session->event_hooks.waitfor_read; ptr && ptr->next; ptr = ptr->next); - ptr->next = hook; - - } - - return SWITCH_STATUS_SUCCESS; - } - - return SWITCH_STATUS_MEMERR; - -} - -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_waitfor_write(switch_core_session_t *session, switch_waitfor_write_hook_t waitfor_write) -{ - switch_io_event_hook_waitfor_write_t *hook, *ptr; - - assert(waitfor_write != NULL); - if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { - hook->waitfor_write = waitfor_write; - if (!session->event_hooks.waitfor_write) { - session->event_hooks.waitfor_write = hook; - } else { - for (ptr = session->event_hooks.waitfor_write; ptr && ptr->next; ptr = ptr->next); - ptr->next = hook; - - } - - return SWITCH_STATUS_SUCCESS; - } - - return SWITCH_STATUS_MEMERR; - -} - - -SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_send_dtmf(switch_core_session_t *session, switch_send_dtmf_hook_t send_dtmf) -{ - switch_io_event_hook_send_dtmf_t *hook, *ptr; - - assert(send_dtmf != NULL); - if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { - hook->send_dtmf = send_dtmf; - if (!session->event_hooks.send_dtmf) { - session->event_hooks.send_dtmf = hook; - } else { - for (ptr = session->event_hooks.send_dtmf; ptr && ptr->next; ptr = ptr->next); - ptr->next = hook; - - } - - return SWITCH_STATUS_SUCCESS; - } - - return SWITCH_STATUS_MEMERR; - -} +NEW_HOOK_DECL(outgoing_channel) +NEW_HOOK_DECL(receive_message) +NEW_HOOK_DECL(receive_event) +NEW_HOOK_DECL(state_change) +NEW_HOOK_DECL(read_frame) +NEW_HOOK_DECL(write_frame) +NEW_HOOK_DECL(video_read_frame) +NEW_HOOK_DECL(video_write_frame) +NEW_HOOK_DECL(kill_channel) +NEW_HOOK_DECL(waitfor_read) +NEW_HOOK_DECL(waitfor_write) +NEW_HOOK_DECL(send_dtmf) +NEW_HOOK_DECL(recv_dtmf) diff --git a/src/switch_core_io.c b/src/switch_core_io.c index a8fa5155f4..2462087bbc 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -464,7 +464,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess session->write_resampler->from_len = write_frame->datalen / 2; switch_short_to_float(data, session->write_resampler->from, session->write_resampler->from_len); - + session->write_resampler->to_len = (uint32_t) switch_resample_process(session->write_resampler, session->write_resampler->from, @@ -497,7 +497,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess } else if (switch_test_flag(bp, SMBF_WRITE_REPLACE)) { do_bugs = 0; if (bp->callback) { - bp->replace_frame_in = frame; + bp->replace_frame_in = write_frame; bp->replace_frame_out = NULL; if ((ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_WRITE_REPLACE)) == SWITCH_TRUE) { write_frame = bp->replace_frame_out; @@ -790,14 +790,34 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_waitfor_write(switch_core_se } -SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_session_t *session, char *dtmf) +SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(switch_core_session_t *session, const char *dtmf) +{ + switch_io_event_hook_recv_dtmf_t *ptr; + switch_status_t status; + + for (ptr = session->event_hooks.recv_dtmf; ptr; ptr = ptr->next) { + if ((status = ptr->recv_dtmf(session, dtmf)) != SWITCH_STATUS_SUCCESS) { + return status; + } + } + return SWITCH_STATUS_SUCCESS; +} + +SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_session_t *session, const char *dtmf) { switch_io_event_hook_send_dtmf_t *ptr; switch_status_t status = SWITCH_STATUS_FALSE; - + + + for (ptr = session->event_hooks.send_dtmf; ptr; ptr = ptr->next) { + if ((status = ptr->send_dtmf(session, dtmf)) != SWITCH_STATUS_SUCCESS) { + return SWITCH_STATUS_SUCCESS; + } + } + if (session->endpoint_interface->io_routines->send_dtmf) { if (strchr(dtmf, 'w') || strchr(dtmf, 'W')) { - char *d; + const char *d; for (d = dtmf; d && *d; d++) { char digit[2] = { 0 }; @@ -815,16 +835,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio } } } else { - status = session->endpoint_interface->io_routines->send_dtmf(session, dtmf); + status = session->endpoint_interface->io_routines->send_dtmf(session, (char *)dtmf); } - if (status == SWITCH_STATUS_SUCCESS) { - for (ptr = session->event_hooks.send_dtmf; ptr; ptr = ptr->next) { - if ((status = ptr->send_dtmf(session, dtmf)) != SWITCH_STATUS_SUCCESS) { - break; - } - } - } } return status; diff --git a/src/switch_ivr.c b/src/switch_ivr.c index f96fe4fdcf..1409f4dad6 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -871,6 +871,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_ context = new_profile->context; } + if (switch_strlen_zero(context)) { + context = "default"; + } + + if (switch_strlen_zero(dialplan)) { + context = "XML"; + } + switch_channel_set_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE, NULL); if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index 9e2904df11..4b8272d969 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -120,7 +120,6 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj) char dtmf[128]; switch_channel_dequeue_dtmf(chan_a, dtmf, sizeof(dtmf)); switch_core_session_send_dtmf(session_b, dtmf); - if (input_callback) { if (input_callback(session_a, dtmf, SWITCH_INPUT_TYPE_DTMF, user_data, 0) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s ended call via DTMF\n", switch_channel_get_name(chan_a)); @@ -526,13 +525,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses switch_copy_string(b_leg->b_uuid, switch_core_session_get_uuid(session), sizeof(b_leg->b_uuid)); b_leg->stream_id = stream_id; b_leg->input_callback = input_callback; - b_leg->session_data = session_data; + b_leg->session_data = peer_session_data; a_leg->session = session; switch_copy_string(a_leg->b_uuid, switch_core_session_get_uuid(peer_session), sizeof(a_leg->b_uuid)); - b_leg->stream_id = stream_id; - b_leg->input_callback = input_callback; - b_leg->session_data = peer_session_data; + a_leg->stream_id = stream_id; + a_leg->input_callback = input_callback; + a_leg->session_data = session_data; switch_channel_add_state_handler(peer_channel, &audio_bridge_peer_state_handlers); @@ -543,6 +542,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) { switch_event_t *event; switch_core_session_message_t msg = { 0 }; + const switch_application_interface_t *application_interface; + char *app, *data; switch_channel_set_state(peer_channel, CS_HOLD); @@ -555,6 +556,21 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses switch_channel_set_variable(caller_channel, SWITCH_BRIDGE_VARIABLE, switch_core_session_get_uuid(peer_session)); switch_channel_set_variable(peer_channel, SWITCH_BRIDGE_VARIABLE, switch_core_session_get_uuid(session)); + if ((app = switch_channel_get_variable(caller_channel, "bridge_pre_execute_aleg_app"))) { + data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_aleg_data"); + if ((application_interface = switch_loadable_module_get_application_interface(app))) { + switch_core_session_exec(session, application_interface, data); + } + } + + if ((app = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_app"))) { + data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_data"); + if ((application_interface = switch_loadable_module_get_application_interface(app))) { + switch_core_session_exec(peer_session, application_interface, data); + } + } + + msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE; msg.from = __FILE__; msg.string_arg = switch_core_session_strdup(peer_session, switch_core_session_get_uuid(session));