From 0a000613e203e3ef1053e1ab563be16622802873 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 15:13:04 -0400 Subject: [PATCH 1/3] fix warnings --- src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c | 2 +- src/mod/endpoints/mod_media_gateway/media_gateway_xml.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c index 6a6ef5c4d9..4307a8e91b 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c @@ -143,7 +143,7 @@ switch_status_t mg_is_ito_pkg_req(megaco_profile_t* mg_profile, MgMgcoCommand *c (reqEvtPar->u.other.val.u.eq.type.val == MGT_VALTYPE_UINT32)) { switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO," Received Inactivity timer value [%d]\n", - reqEvtPar->u.other.val.u.eq.u.decInt.val); + (int)reqEvtPar->u.other.val.u.eq.u.decInt.val); mg_profile->inact_tmr = reqEvtPar->u.other.val.u.eq.u.decInt.val/MG_INACTIVITY_TMR_RESOLUTION; diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c b/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c index b52d4da0f1..0d6390a173 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c @@ -123,7 +123,7 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload) const char *prefix = switch_xml_attr(mg_term, "termination-id-prefix"); //const char *sztermination_id_base = switch_xml_attr(mg_term, "termination-id-base"); //const char *tech = switch_xml_attr(mg_term, "tech"); - const char *channel_prefix = switch_xml_attr(mg_term, "channel-prefix"); + //const char *channel_prefix = switch_xml_attr(mg_term, "channel-prefix"); const char *channel_map = switch_xml_attr(mg_term, "channel-map"); const char *szspan_id = switch_xml_attr(mg_term, "span-id"); const int span_id = !zstr(szspan_id) ? atoi(szspan_id) : 0; From 3519ebc981eff76d7ab506f407558e93992e59b1 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 27 Jul 2012 10:59:37 -0400 Subject: [PATCH 2/3] add megaco_prepare_termination --- .../mod_media_gateway/media_gateway.c | 42 +++++++++++++++++++ .../mod_media_gateway/mod_media_gateway.h | 1 + 2 files changed, 43 insertions(+) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index e47055236a..ee5abe7d2f 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -155,6 +155,48 @@ done: return SWITCH_STATUS_SUCCESS; } + +/* + * Originate a channel so the target technology gets to run initialization code + */ +switch_status_t megaco_prepare_termination(mg_termination_t *term) +{ + switch_event_t *var_event = NULL; + switch_core_session_t *session = NULL; + switch_status_t status = SWITCH_STATUS_SUCCESS; + char dialstring[100]; + switch_call_cause_t cause; + switch_channel_t *channel; + switch_event_create(&var_event, SWITCH_EVENT_CLONE); + + if (term->type == MG_TERM_RTP) { + } else if (term->type == MG_TERM_TDM) { + switch_snprintf(dialstring, sizeof dialstring, "tdm/%s", term->name); + + switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "ftdm_start_only", "true"); + switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, kSPAN_NAME, term->u.tdm.span_name); + switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, kCHAN_ID, "%d", term->u.tdm.channel); + } + + /* Set common variables on the channel */ + switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, SWITCH_PARK_AFTER_BRIDGE_VARIABLE, "true"); + if (switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, var_event, 0, NULL) != SWITCH_STATUS_SUCCESS) { + status = SWITCH_STATUS_FALSE; + goto done; + } + channel = switch_core_session_get_channel(session); + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + +done: + if (session) { + switch_core_session_rwunlock(session); + } + switch_event_destroy(&var_event); + + return SWITCH_STATUS_SUCCESS; +} + + mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const char *prefix) { mg_termination_type_t termtype; diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h index af53052fbb..4ffeaaa4e0 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h @@ -235,6 +235,7 @@ void megaco_release_context(mg_context_t *ctx); switch_status_t megaco_context_sub_termination(mg_context_t *ctx, mg_termination_t *term); switch_status_t megaco_context_sub_all_termination(mg_context_t *ctx); switch_status_t megaco_activate_termination(mg_termination_t *term); +switch_status_t megaco_prepare_termination(mg_termination_t *term); mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const char *prefix); mg_termination_t *megaco_find_termination(megaco_profile_t *profile, const char *name); From a668b9ddf65c8f58f6d4cc734e6aa7095d4bb05f Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 27 Jul 2012 11:06:23 -0400 Subject: [PATCH 3/3] automatically fail new tdm channel if ftdm_start_only is true --- libs/freetdm/mod_freetdm/tdm.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index efdf4dce3e..b2d37d47ed 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -112,7 +112,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi ftdm_codec_t codec; uint32_t interval; ftdm_status_t fstatus; - + const char *ftdm_start_only = switch_event_get_header(var_event, "ftdm_start_only"); ctdm_private_t *tech_pvt = NULL; if (zstr(szchanid) || zstr(span_name)) { @@ -129,6 +129,15 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi goto fail; } + if ((fstatus = ftdm_span_start(span)) != FTDM_SUCCESS && fstatus != FTDM_EINVAL) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't start span %s.\n", span_name); + goto fail; + } + + if (!zstr(ftdm_start_only) && switch_true(ftdm_start_only)) { + goto fail; + } + if (!(*new_session = switch_core_session_request(ctdm.endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, 0, pool))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't request session.\n"); @@ -137,11 +146,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi channel = switch_core_session_get_channel(*new_session); - if ((fstatus = ftdm_span_start(span)) != FTDM_SUCCESS && fstatus != FTDM_EINVAL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't start span %s.\n", span_name); - goto fail; - } - if (ftdm_channel_open(span_id, chan_id, &chan) != FTDM_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't open span or channel.\n"); goto fail;