Revision
15475
Author
anthm
Date
2009-11-14 21:14:06 -0600 (Sat, 14 Nov 2009)

Log Message

lookup gateway by realm when not found by name

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (15474 => 15475)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	2009-11-15 02:16:10 UTC (rev 15474)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	2009-11-15 03:14:06 UTC (rev 15475)
@@ -825,6 +825,9 @@
 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);

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (15474 => 15475)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	2009-11-15 02:16:10 UTC (rev 15474)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	2009-11-15 03:14:06 UTC (rev 15475)
@@ -1510,7 +1510,9 @@
 			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 @@
 	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);