From e5d140d1e6934fc266d1ddc606ed2d099044e860 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Wed, 8 Aug 2012 13:34:42 -0400 Subject: [PATCH] adding code for reporting DTMF to MGC --- .../mod_media_gateway/media_gateway.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index a9bcd85fe2..ca973e10a9 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -7,6 +7,7 @@ */ #include "mod_media_gateway.h" +#include "media_gateway_stack.h" megaco_profile_t *megaco_profile_locate(const char *name) { @@ -79,6 +80,24 @@ megaco_profile_t* megaco_get_profile_by_suId(SuId suId) return profile; } + +static switch_status_t mg_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + mg_termination_t *term = switch_channel_get_private(channel, "_mg_term_"); + char digit[2] = { dtmf->digit }; + if (!term) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find termination structure for session [%s]\n", + switch_core_session_get_uuid(session)); + return SWITCH_STATUS_SUCCESS; + } + + //switch_status_t mg_send_dtmf_notify(megaco_profile_t* mg_profile, const char* term_name, char* digits, int num_of_collected_digits); + //mg_send_dtmf_notify(term->profile, term->name, digit, 1); + switch_log_printf("NOT Sending notify to MGC for dtmf: %c\n", dtmf->digit); + return SWITCH_STATUS_SUCCESS; +} + /* * Creates a freeswitch channel for the specified termination. * The channel will be parked until future actions are taken @@ -136,6 +155,7 @@ switch_status_t megaco_activate_termination(mg_termination_t *term) } if (zstr(term->uuid)) { + switch_channel_t *channel; if (switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, var_event, 0, NULL) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to instanciate termination [%s]: %s\n", term->name, switch_channel_cause2str(cause)); status = SWITCH_STATUS_FALSE; @@ -144,6 +164,9 @@ switch_status_t megaco_activate_termination(mg_termination_t *term) term->uuid = switch_core_strdup(term->pool, switch_core_session_get_uuid(session)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Termination [%s] successfully instanciated as [%s] [%s]\n", term->name, dialstring, switch_core_session_get_uuid(session)); + channel = switch_core_session_get_channel(session); + switch_channel_set_private(channel, "_mg_term_", term); + switch_core_event_hook_add_recv_dtmf(session, mg_on_dtmf); } switch_set_flag(term, MGT_ACTIVE);