From b2b9555d347b11e84a86b3de1c2de5f8f8d8437e Mon Sep 17 00:00:00 2001 From: karl anderson Date: Thu, 2 Apr 2015 19:10:53 -0400 Subject: [PATCH] FS-7760 #resolve added xml fetch for channels to externally support nightmare transfer depends on channel-xml-fetch-on-nightmare-transfer profile param (default is disabled) --- src/include/switch_types.h | 4 +-- src/mod/endpoints/mod_sofia/mod_sofia.h | 2 ++ src/mod/endpoints/mod_sofia/sofia.c | 44 ++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 95220b1542..62fada2485 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -588,9 +588,9 @@ typedef enum { SWITCH_XML_SECTION_DIALPLAN = (1 << 2), SWITCH_XML_SECTION_LANGUAGES = (1 << 3), SWITCH_XML_SECTION_CHATPLAN = (1 << 4), - + SWITCH_XML_SECTION_CHANNELS = (1 << 5), /* Nothing after this line */ - SWITCH_XML_SECTION_MAX = (1 << 4) + SWITCH_XML_SECTION_MAX = (1 << 5) } switch_xml_section_enum_t; typedef uint32_t switch_xml_section_t; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index df52655ab2..2bd475fb7b 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -283,6 +283,8 @@ typedef enum { PFLAG_ENABLE_CHAT, PFLAG_AUTH_SUBSCRIPTIONS, PFLAG_PROXY_REFER, + PFLAG_CHANNEL_XML_FETCH_ON_NIGHTMARE_TRANSFER, + /* No new flags below this line */ PFLAG_MAX } PFLAGS; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index cfc68a2e8b..202bcf52ba 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -4188,6 +4188,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER); //sofia_set_pflag(profile, PFLAG_PRESENCE_ON_FIRST_REGISTER); + sofia_clear_pflag(profile, PFLAG_CHANNEL_XML_FETCH_ON_NIGHTMARE_TRANSFER); profile->shutdown_type = "false"; profile->local_network = "localnet.auto"; sofia_set_flag(profile, TFLAG_ENABLE_SOA); @@ -5444,6 +5445,12 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) } else { profile->paid_type = PAID_DEFAULT; } + } else if (!strcasecmp(var, "channel-xml-fetch-on-nightmare-transfer")) { + if(switch_true(val)) { + sofia_set_pflag(profile, PFLAG_CHANNEL_XML_FETCH_ON_NIGHTMARE_TRANSFER); + } else { + sofia_clear_pflag(profile, PFLAG_CHANNEL_XML_FETCH_ON_NIGHTMARE_TRANSFER); + } } } @@ -8208,6 +8215,23 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t if ((a_session = switch_core_session_locate(br_a))) { const char *port = NULL; const char *rep_h = NULL; + switch_xml_t xml_root = NULL, xml_channel = NULL; + switch_event_t *xml_params = NULL; + const char *xml_url = NULL; + switch_xml_t params = NULL, param = NULL; + + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "REFER from %s replaces %s (%s@%s) with %s on another server\n" + ,switch_core_session_get_uuid(session), rep, exten, (char *) refer_to->r_url->url_host, br_a); + + switch_event_create(&xml_params, SWITCH_EVENT_REQUEST_PARAMS); + switch_assert(xml_params); + switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "purpose", "nightmare_xfer"); + switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "profile", profile->name); + switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "refer-to-user", refer_to->r_url->url_user); + switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "refer-to-host", refer_to->r_url->url_host); + switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "refer-to-params", refer_to->r_url->url_params ? refer_to->r_url->url_params : ""); + switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "refer-to-headers", refer_to->r_url->url_headers ? refer_to->r_url->url_headers : ""); if (refer_to && refer_to->r_url->url_port) { port = refer_to->r_url->url_port; @@ -8215,9 +8239,20 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t channel = switch_core_session_get_channel(a_session); - exten = switch_core_session_sprintf(session, "sofia/%s/sip:%s@%s%s%s", - profile->name, refer_to->r_url->url_user, - refer_to->r_url->url_host, port ? ":" : "", port ? port : ""); + if (sofia_test_flag(profile, PFLAG_CHANNEL_XML_FETCH_ON_NIGHTMARE_TRANSFER) + && switch_xml_locate("channels", "channel", "uuid", replaces->rp_call_id, &xml_root, &xml_channel, xml_params, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS + && (params = switch_xml_child(xml_channel, "params")) + && (param = switch_xml_find_child(params, "param", "name", "sip-url")) + && (xml_url = switch_xml_attr(param, "value")) + && !zstr(xml_url)) { + exten = switch_core_session_sprintf(session, "sofia/%s/%s", profile->name, xml_url); + } else { + exten = switch_core_session_sprintf(session, "sofia/%s/sip:%s@%s%s%s", + profile->name, refer_to->r_url->url_user, + refer_to->r_url->url_host, port ? ":" : "", port ? port : ""); + } + switch_xml_free(xml_root); + switch_event_destroy(&xml_params); switch_core_new_memory_pool(&npool); nightmare_xfer_helper = switch_core_alloc(npool, sizeof(*nightmare_xfer_helper)); @@ -8234,11 +8269,12 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t "{sip_invite_params=%s}%s", refer_to->r_url->url_params, exten); } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "INVITE RURI '%s'\n", nightmare_xfer_helper->exten_with_params); } else { nightmare_xfer_helper->exten_with_params = nightmare_xfer_helper->exten; } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Nightmare transfer to '%s'\n", nightmare_xfer_helper->exten_with_params); + nightmare_xfer_helper->event = switch_core_strdup(npool, etmp); nightmare_xfer_helper->reply_uuid = switch_core_strdup(npool, switch_core_session_get_uuid(session)); nightmare_xfer_helper->bridge_to_uuid = switch_core_strdup(npool, br_a);