diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index a5ba8fc73b..29da21dd5b 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -240,6 +240,7 @@ SWITCH_DECLARE(switch_status_t) switch_frame_alloc(switch_frame_t **frame, switc SWITCH_DECLARE(switch_status_t) switch_frame_dup(switch_frame_t *orig, switch_frame_t **clone); SWITCH_DECLARE(switch_status_t) switch_frame_free(switch_frame_t **frame); SWITCH_DECLARE(switch_bool_t) switch_is_number(const char *str); +SWITCH_DECLARE(char *) switch_find_parameter(const char *str, const char *param, switch_memory_pool_t *pool); /*! \brief Evaluate the truthfullness of a string expression diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 2a768bcf76..59a9d5734a 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -7404,16 +7404,12 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ } if (sip->sip_from && sip->sip_from->a_url) { - char *tmp; from_user = sip->sip_from->a_url->url_user; from_host = sip->sip_from->a_url->url_host; channel_name = url_set_chanvars(session, sip->sip_from->a_url, sip_from); - if (sip->sip_from->a_url->url_params && (tmp = sofia_glue_find_parameter(sip->sip_from->a_url->url_params, "isup-oli="))) { - aniii = switch_core_session_strdup(session, tmp + 9); - if ((tmp = strchr(aniii, ';'))) { - tmp = '\0'; - } + if (sip->sip_from->a_url->url_params) { + aniii = switch_find_parameter(sip->sip_from->a_url->url_params, "isup-oli", switch_core_session_get_pool(session)); } if (!zstr(from_user)) { @@ -7755,7 +7751,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ if (sip->sip_request->rq_url->url_params) { - gw_param_name = sofia_glue_find_parameter_value(session, sip->sip_request->rq_url->url_params, "gw="); + gw_param_name = switch_find_parameter(sip->sip_request->rq_url->url_params, "gw", switch_core_session_get_pool(session)); } if (strstr(destination_number, "gw+")) { diff --git a/src/switch_utils.c b/src/switch_utils.c index a008830ef6..b160089eed 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -122,6 +122,53 @@ SWITCH_DECLARE(switch_status_t) switch_frame_free(switch_frame_t **frame) return SWITCH_STATUS_SUCCESS; } + +SWITCH_DECLARE(char *) switch_find_parameter(const char *str, const char *param, switch_memory_pool_t *pool) +{ + char *e, *r = NULL, *ptr = NULL, *next = NULL; + size_t len; + + ptr = (char *) str; + + while (ptr) { + len = strlen(param); + e = ptr+len; + next = strchr(ptr, ';'); + + if (!strncasecmp(ptr, param, len) && *e == '=') { + int mlen; + + ptr = ++e; + + if (next) { + e = next; + } else { + e = ptr + strlen(ptr); + } + + mlen = (e - ptr) + 1; + + if (pool) { + r = switch_core_alloc(pool, mlen); + } else { + r = malloc(mlen); + } + + *(r + mlen) = '\0'; + + switch_snprintf(r, mlen, "%s", ptr); + + break; + } + + if (next) { + ptr = next + 1; + } + } + + return r; +} + SWITCH_DECLARE(switch_status_t) switch_network_list_create(switch_network_list_t **list, const char *name, switch_bool_t default_type, switch_memory_pool_t *pool) {