]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7760 #resolve
authorkarl anderson <karl@2600hz.com>
Thu, 2 Apr 2015 23:10:53 +0000 (19:10 -0400)
committerLuis Azedo <luis@2600hz.com>
Fri, 3 Jul 2015 18:28:17 +0000 (19:28 +0100)
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
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c

index 95220b15424fac9a614b156692edfbc061b5accb..62fada24855ed2d8958fb14450b3d048b066d19e 100644 (file)
@@ -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;
 
index df52655ab234bf868ea446a3dd5a749f81212544..2bd475fb7ba95c4fff87f71301c4727b36418377 100644 (file)
@@ -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;
index cfc68a2e8b262fc48da5cd8bcd11fb139c92b6e3..202bcf52baf3e08c29984a04f6b9945f2a8a55a9 100644 (file)
@@ -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);