lookup gateway by realm when not found by name

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15475 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2009-11-15 03:14:06 +00:00
parent f05737e3ba
commit b60abded11
2 changed files with 48 additions and 1 deletions

View 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);

View 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);