]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
lookup gateway by realm when not found by name
authorAnthony Minessale <anthony.minessale@gmail.com>
Sun, 15 Nov 2009 03:14:06 +0000 (03:14 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Sun, 15 Nov 2009 03:14:06 +0000 (03:14 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15475 d0543943-73ff-0310-b7d9-9358b9ac24b2

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

index 2d71729249f88c187264f4d74139935b06c312aa..bbfc22bd246727d9cf5b4da53e7d55a7c88a5229 100644 (file)
@@ -825,6 +825,9 @@ 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, const char *key);
 #define sofia_reg_find_gateway(x) sofia_reg_find_gateway__(__FILE__, __SWITCH_FUNC__, __LINE__,  x)
 
+sofia_gateway_t *sofia_reg_find_gateway_by_realm__(const char *file, const char *func, int line, const char *key);
+#define sofia_reg_find_gateway_by_realm(x) sofia_reg_find_gateway_by_realm__(__FILE__, __SWITCH_FUNC__, __LINE__,  x)
+
 sofia_gateway_subscription_t *sofia_find_gateway_subscription(sofia_gateway_t *gateway_ptr, const char *event);
 
 void sofia_reg_release_gateway__(const char *file, const char *func, int line, sofia_gateway_t *gateway);
index d12385f7b3b98686db7888458d9c1929a9b5ea01..353410baa81087f7b9f97677e704940829412f6a 100644 (file)
@@ -1510,7 +1510,9 @@ void sofia_reg_handle_sip_r_challenge(int status,
                        if ((p = strchr(rb, '"'))) {
                                *p = '\0';
                        }
-                       var_gateway = sofia_reg_find_gateway(rb);
+                       if (!(var_gateway = sofia_reg_find_gateway(rb))) {
+                               var_gateway = sofia_reg_find_gateway_by_realm(rb);
+                       }
                }
 
                if (!var_gateway && sip && sip->sip_to) {
@@ -2165,6 +2167,48 @@ sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, in
        return gateway;
 }
 
+
+sofia_gateway_t *sofia_reg_find_gateway_by_realm__(const char *file, const char *func, int line, const char *key)
+{
+       sofia_gateway_t *gateway = NULL;
+       switch_hash_index_t *hi;
+       const void *var;
+    void *val;
+
+       switch_mutex_lock(mod_sofia_globals.hash_mutex);
+       for (hi = switch_hash_first(NULL, mod_sofia_globals.gateway_hash); hi; hi = switch_hash_next(hi)) {
+               switch_hash_this(hi, &var, NULL, &val);
+               if ((gateway = (sofia_gateway_t *) val)) {
+                       if (!strcasecmp(gateway->register_realm, key)) {
+                               break;
+                       }
+               } else {
+                       gateway = NULL;
+               }
+       }
+
+       if (gateway) {
+               if (!sofia_test_pflag(gateway->profile, PFLAG_RUNNING) || gateway->deleted) {
+                       gateway = NULL;
+                       goto done;
+               }
+               if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
+                       switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "Profile %s is locked\n", gateway->profile->name);
+                       gateway = NULL;
+               }
+       }
+       if (gateway) {
+#ifdef SOFIA_DEBUG_RWLOCKS
+               switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX GW LOCK %s\n", gateway->profile->name);
+#endif
+       }
+
+  done:
+       switch_mutex_unlock(mod_sofia_globals.hash_mutex);
+       return gateway;
+}
+
+
 void sofia_reg_release_gateway__(const char *file, const char *func, int line, sofia_gateway_t *gateway)
 {
        switch_thread_rwlock_unlock(gateway->profile->rwlock);