]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
use a variable, realm or to host to find gateway when it's not obvious
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 17 Jul 2008 14:32:01 +0000 (14:32 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 17 Jul 2008 14:32:01 +0000 (14:32 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9069 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia_reg.c

index e1c86c74e89d882e238d1a8ae8450e070c4dbddb..47e56ec96870427f79eb9aa83dbc681bb347cb62 100644 (file)
@@ -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);
index 32e3d9c61e5c228b88b64eaa4cd269ea91b2c80f..9bba11a79a254c4375efac81ce0475ad091a7b6e 100644 (file)
@@ -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;