From 75900accba75de5eba3a03f207165cb9a18587fd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 Jul 2008 14:32:01 +0000 Subject: [PATCH] use a variable, realm or to host to find gateway when it's not obvious git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9069 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/mod_sofia.h | 2 +- src/mod/endpoints/mod_sofia/sofia_reg.c | 48 ++++++++++++++++--------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index e1c86c74e8..47e56ec968 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -600,7 +600,7 @@ sofia_profile_t *sofia_glue_find_profile__(const char *file, const char *func, i #define sofia_glue_find_profile(x) sofia_glue_find_profile__(__FILE__, __SWITCH_FUNC__, __LINE__, x) switch_status_t sofia_reg_add_gateway(char *key, sofia_gateway_t *gateway); -sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, int line, char *key); +sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, int line, const char *key); #define sofia_reg_find_gateway(x) sofia_reg_find_gateway__(__FILE__, __SWITCH_FUNC__, __LINE__, x) void sofia_reg_release_gateway__(const char *file, const char *func, int line, sofia_gateway_t *gateway); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 32e3d9c61e..9bba11a79a 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -965,22 +965,6 @@ void sofia_reg_handle_sip_r_challenge(int status, gw_name = switch_channel_get_variable(channel, "sip_use_gateway"); } - if (!gateway) { - if (gw_name) { - var_gateway = sofia_reg_find_gateway((char *)gw_name); - } - -#if __FINISHED__ - if (!var_gateway) { - // look for it in the params of the contact or req uri etc. - } -#endif - - if (var_gateway) { - gateway = var_gateway; - } - } - if (sip->sip_www_authenticate) { authenticate = sip->sip_www_authenticate; @@ -1000,6 +984,36 @@ void sofia_reg_handle_sip_r_challenge(int status, } } + if (!gateway) { + if (gw_name) { + var_gateway = sofia_reg_find_gateway((char *)gw_name); + } + + + if (!var_gateway && realm) { + char rb[512] = ""; + char *p = (char *) realm; + while((*p == '"')) { + p++; + } + switch_set_string(rb, p); + if ((p = strchr(rb, '"'))) { + *p = '\0'; + } + var_gateway = sofia_reg_find_gateway(rb); + } + + if (!var_gateway && sip && sip->sip_to) { + var_gateway = sofia_reg_find_gateway(sip->sip_to->a_url->url_host); + } + + if (var_gateway) { + gateway = var_gateway; + } + } + + + if (!(scheme && realm)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No scheme and realm!\n"); goto end; @@ -1398,7 +1412,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co } -sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, int line, char *key) +sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, int line, const char *key) { sofia_gateway_t *gateway = NULL;