[Freeswitch-svn] [commit] r6481 - in freeswitch/trunk/src/mod: endpoints/mod_sofia event_handlers/mod_event_socket

Freeswitch SVN anthm at freeswitch.org
Mon Dec 3 19:21:33 EST 2007


Author: anthm
Date: Mon Dec  3 19:21:32 2007
New Revision: 6481

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
   freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c

Log:
fix SFSIP-37

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	Mon Dec  3 19:21:32 2007
@@ -428,8 +428,9 @@
 auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, 
 								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[]);
+									  char const *phrase,
+									  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[]);

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	Mon Dec  3 19:21:32 2007
@@ -95,18 +95,26 @@
 	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 ((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);
-			if (!tech_pvt->call_id && sip && sip->sip_call_id && sip->sip_call_id->i_id) {
-				tech_pvt->call_id = switch_core_session_strdup(session, sip->sip_call_id->i_id);
-				switch_channel_set_variable(channel, "sip_call_id", tech_pvt->call_id);
+	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);
+				if (!tech_pvt->call_id && sip && sip->sip_call_id && sip->sip_call_id->i_id) {
+					tech_pvt->call_id = switch_core_session_strdup(session, sip->sip_call_id->i_id);
+					switch_channel_set_variable(channel, "sip_call_id", tech_pvt->call_id);
+				}
+			} else {
+				/* too late */
+				return;
 			}
-		} else {
-			/* too late */
-			return;
 		}
 	}
 	
@@ -143,7 +151,7 @@
 	}
 
 	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 @@
 
   done:
 
+	if (gateway) {
+		sofia_reg_release_gateway(gateway);
+	}
+
 	if (session) {
 		switch_core_session_rwunlock(session);
 
@@ -686,18 +698,10 @@
 			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);
 			}
 		}
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	Mon Dec  3 19:21:32 2007
@@ -660,13 +660,12 @@
 }
 
 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[])
+									  char const *phrase,
+									  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,68 +704,9 @@
 		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) {
-				goto cancel;
-			}
-
-		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
-			goto cancel;
-		}
+	if (!gateway) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Matching gateway found\n");
+		goto cancel;
 	}
 
 	snprintf(authentication, sizeof(authentication), "%s:%s:%s:%s", scheme, realm, gateway->register_username, gateway->register_password);
@@ -779,16 +719,11 @@
 	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);

Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	(original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	Mon Dec  3 19:21:32 2007
@@ -352,10 +352,16 @@
 	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 @@
 			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;
 		}



More information about the Freeswitch-svn mailing list