fix SFSIP-37
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6481 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
0f1d4b9a70
commit
1bbb57a82c
|
@ -429,7 +429,8 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
|
|||
const char *regstr, char *np, size_t nplen, char *ip, switch_event_t **v_event, long exptime);
|
||||
void sofia_reg_handle_sip_r_challenge(int status,
|
||||
char const *phrase,
|
||||
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[]);
|
||||
nua_t *nua, sofia_profile_t *profile,
|
||||
nua_handle_t *nh, switch_core_session_t *session, sofia_gateway_t *gateway, sip_t const *sip, tagi_t tags[]);
|
||||
void sofia_reg_handle_sip_r_register(int status,
|
||||
char const *phrase,
|
||||
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
|
||||
|
|
|
@ -95,8 +95,15 @@ void sofia_event_callback(nua_event_t event,
|
|||
auth_res_t auth_res = AUTH_FORBIDDEN;
|
||||
switch_core_session_t *session = NULL;
|
||||
switch_channel_t *channel = NULL;
|
||||
sofia_gateway_t *gateway = NULL;
|
||||
|
||||
if (sofia_private && !switch_strlen_zero(sofia_private->uuid)) {
|
||||
if (sofia_private) {
|
||||
if ((gateway = sofia_private->gateway)) {
|
||||
if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is locked\n", gateway->profile->name);
|
||||
return;
|
||||
}
|
||||
} else if (!switch_strlen_zero(sofia_private->uuid)) {
|
||||
if ((session = switch_core_session_locate(sofia_private->uuid))) {
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
channel = switch_core_session_get_channel(tech_pvt->session);
|
||||
|
@ -109,6 +116,7 @@ void sofia_event_callback(nua_event_t event,
|
|||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (status != 100 && status != 200) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "event [%s] status [%d][%s] session: %s\n",
|
||||
|
@ -143,7 +151,7 @@ void sofia_event_callback(nua_event_t event,
|
|||
}
|
||||
|
||||
if (sip && (status == 401 || status == 407)) {
|
||||
sofia_reg_handle_sip_r_challenge(status, phrase, nua, profile, nh, session, sip, tags);
|
||||
sofia_reg_handle_sip_r_challenge(status, phrase, nua, profile, nh, session, gateway, sip, tags);
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
@ -251,6 +259,10 @@ void sofia_event_callback(nua_event_t event,
|
|||
|
||||
done:
|
||||
|
||||
if (gateway) {
|
||||
sofia_reg_release_gateway(gateway);
|
||||
}
|
||||
|
||||
if (session) {
|
||||
switch_core_session_rwunlock(session);
|
||||
|
||||
|
@ -686,18 +698,10 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
|
|||
if ((gp = sofia_reg_find_gateway(gateway->name))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate gateway '%s'\n", gateway->name);
|
||||
sofia_reg_release_gateway(gp);
|
||||
} else if ((gp=sofia_reg_find_gateway(gateway->register_from))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate uri '%s'\n", gateway->register_from);
|
||||
sofia_reg_release_gateway(gp);
|
||||
} else if ((gp=sofia_reg_find_gateway(gateway->register_contact))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate contact '%s'\n", gateway->register_contact);
|
||||
sofia_reg_release_gateway(gp);
|
||||
} else {
|
||||
gateway->next = profile->gateways;
|
||||
profile->gateways = gateway;
|
||||
sofia_reg_add_gateway(gateway->name, gateway);
|
||||
sofia_reg_add_gateway(gateway->register_from, gateway);
|
||||
sofia_reg_add_gateway(gateway->register_contact, gateway);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -661,12 +661,11 @@ void sofia_reg_handle_sip_r_register(int status,
|
|||
|
||||
void sofia_reg_handle_sip_r_challenge(int status,
|
||||
char const *phrase,
|
||||
nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[])
|
||||
nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh,
|
||||
switch_core_session_t *session, sofia_gateway_t *gateway, sip_t const *sip, tagi_t tags[])
|
||||
{
|
||||
sofia_gateway_t *gateway = NULL;
|
||||
sip_www_authenticate_t const *authenticate = NULL;
|
||||
char const *realm = NULL;
|
||||
char *p = NULL, *duprealm = NULL, *qrealm = NULL;
|
||||
char const *scheme = NULL;
|
||||
int indexnum;
|
||||
char *cur;
|
||||
|
@ -705,70 +704,11 @@ void sofia_reg_handle_sip_r_challenge(int status,
|
|||
return;
|
||||
}
|
||||
|
||||
if (profile) {
|
||||
sofia_gateway_t *gateway_ptr = NULL;
|
||||
|
||||
if ((duprealm = strdup(realm))) {
|
||||
qrealm = duprealm;
|
||||
|
||||
while (*qrealm && *qrealm == '"') {
|
||||
qrealm++;
|
||||
}
|
||||
|
||||
if ((p = strchr(qrealm, '"'))) {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
if (sip->sip_from) {
|
||||
char *from_key = switch_mprintf("sip:%s@%s",
|
||||
(char *) sip->sip_from->a_url->url_user,
|
||||
(char *) sip->sip_from->a_url->url_host);
|
||||
|
||||
if (!(gateway = sofia_reg_find_gateway(from_key))) {
|
||||
gateway = sofia_reg_find_gateway(qrealm);
|
||||
}
|
||||
|
||||
switch_safe_free(from_key);
|
||||
}
|
||||
|
||||
if (!gateway) {
|
||||
switch_mutex_lock(mod_sofia_globals.hash_mutex);
|
||||
for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
|
||||
if (scheme && qrealm && !strcasecmp(gateway_ptr->register_scheme, scheme)
|
||||
&& !strcasecmp(gateway_ptr->register_realm, qrealm)) {
|
||||
gateway = gateway_ptr;
|
||||
|
||||
if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
|
||||
#ifdef SOFIA_DEBUG_RWLOCKS
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is locked\n", gateway->profile->name);
|
||||
#endif
|
||||
gateway = NULL;
|
||||
}
|
||||
#ifdef SOFIA_DEBUG_RWLOCKS
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX GW LOCK %s\n", gateway->profile->name);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
|
||||
}
|
||||
|
||||
if (!gateway) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Match for Scheme [%s] Realm [%s]\n", scheme, qrealm);
|
||||
}
|
||||
|
||||
switch_safe_free(duprealm);
|
||||
|
||||
if (!gateway) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Matching gateway found\n");
|
||||
goto cancel;
|
||||
}
|
||||
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
|
||||
goto cancel;
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(authentication, sizeof(authentication), "%s:%s:%s:%s", scheme, realm, gateway->register_username, gateway->register_password);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Authenticating '%s' with '%s'.\n", profile->username, authentication);
|
||||
|
@ -779,16 +719,11 @@ void sofia_reg_handle_sip_r_challenge(int status,
|
|||
tl_gets(tags, NUTAG_CALLSTATE_REF(ss_state), SIPTAG_WWW_AUTHENTICATE_REF(authenticate), TAG_END());
|
||||
|
||||
nua_authenticate(nh, SIPTAG_EXPIRES_STR(gateway->expires_str), NUTAG_AUTH(authentication), TAG_END());
|
||||
if (gateway) {
|
||||
sofia_reg_release_gateway(gateway);
|
||||
gateway = NULL;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
cancel:
|
||||
if (gateway) {
|
||||
sofia_reg_release_gateway(gateway);
|
||||
}
|
||||
|
||||
if (session) {
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
switch_channel_hangup(channel, SWITCH_CAUSE_MANDATORY_IE_MISSING);
|
||||
|
|
|
@ -352,10 +352,16 @@ static switch_status_t read_packet(listener_t * listener, switch_event_t **event
|
|||
char *ptr;
|
||||
uint8_t crcount = 0;
|
||||
uint32_t max_len = sizeof(mbuf);
|
||||
switch_channel_t *channel = NULL;
|
||||
*event = NULL;
|
||||
start = time(NULL);
|
||||
ptr = mbuf;
|
||||
|
||||
|
||||
if (listener->session) {
|
||||
channel = switch_core_session_get_channel(listener->session);
|
||||
}
|
||||
|
||||
while (listener->sock && !prefs.done) {
|
||||
uint8_t do_sleep = 1;
|
||||
mlen = 1;
|
||||
|
@ -365,7 +371,7 @@ static switch_status_t read_packet(listener_t * listener, switch_event_t **event
|
|||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
if (listener->session && !switch_channel_ready(switch_core_session_get_channel(listener->session))) {
|
||||
if (channel && !switch_channel_ready(channel)) {
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue