From 89fd373264fe51e779de26cea83e76bd0c083956 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 12 Sep 2008 14:57:44 +0000 Subject: [PATCH] update git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9536 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/sofia.c | 44 ++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 90dd00f226..47cf0eb016 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -2864,7 +2864,7 @@ 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; - char *glued; + char *param_string = "", *headers = ""; int count = 0, bytes = 0; if (refer_to && refer_to->r_url && refer_to->r_url->url_port) { @@ -2874,27 +2874,39 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t if (switch_strlen_zero(port)) { port = "5060"; } - + channel = switch_core_session_get_channel(a_session); - for (count = 0; refer_to->r_params[count] ; count++) { - bytes += strlen(refer_to->r_params[count]) + 1; - } - bytes++; + if (refer_to->r_params) { + for (count = 0; refer_to->r_params[count] ; count++) { + bytes += strlen(refer_to->r_params[count]) + 1; + } + + if (bytes) { + bytes += 2; + + param_string = switch_core_session_alloc(session, bytes); + *param_string = ';'; + for (count = 0; refer_to->r_params[count] ; count++) { + switch_snprintf(param_string + strlen(param_string), bytes - strlen(param_string), "%s;", refer_to->r_params[count]); + } - glued = switch_core_session_alloc(session, bytes); - for (count = 0; refer_to->r_params[count] ; count++) { - switch_snprintf(glued + strlen(glued), bytes - strlen(glued), "%s;", refer_to->r_params[count]); + if (end_of(param_string) == ';') { + end_of(param_string) = '\0'; + } + } } - - if (end_of(glued) == ';') { - end_of(glued) = '\0'; + + if (refer_to->r_url && refer_to->r_url->url_headers) { + headers = switch_core_session_sprintf(session, "?%s", refer_to->r_url->url_headers); } - - exten = switch_core_session_sprintf(session, "sofia/%s/sip:%s@%s:%s;%s?%s", - profile->name, refer_to->r_url->url_user, - refer_to->r_url->url_host, port, glued, refer_to->r_url->url_headers); + + exten = switch_core_session_sprintf(session, "sofia/%s/sip:%s@%s:%s%s%s", + profile->name, refer_to->r_url->url_user, + refer_to->r_url->url_host, port, param_string, headers); + + switch_core_new_memory_pool(&npool); nightmare_xfer_helper = switch_core_alloc(npool, sizeof(*nightmare_xfer_helper)); nightmare_xfer_helper->exten = switch_core_strdup(npool, exten);