Author: anthm Date: Thu Jul 17 10:32:01 2008 New Revision: 9069 Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Log: use a variable, realm or to host to find gateway when it's not obvious Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Thu Jul 17 10:32:01 2008 @@ -600,7 +600,7 @@ #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); Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Thu Jul 17 10:32:01 2008 @@ -965,22 +965,6 @@ 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 @@ } } + 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 @@ } -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;