[Freeswitch-svn] [commit] r6735 - freeswitch/trunk/src/mod/endpoints/mod_sofia

Freeswitch SVN mikej at freeswitch.org
Wed Dec 12 23:01:30 EST 2007


Author: mikej
Date: Wed Dec 12 23:01:29 2007
New Revision: 6735

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c

Log:
cleanup, null checks. etc.

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Wed Dec 12 23:01:29 2007
@@ -554,6 +554,10 @@
 		}
 	}
 
+	if (!tech_pvt->read_codec.implementation) {
+		return SWITCH_STATUS_GENERR;
+	}
+
 	if (switch_test_flag(tech_pvt, TFLAG_HUP)) {
 		return SWITCH_STATUS_FALSE;
 	}
@@ -1371,7 +1375,7 @@
 		goto done;
 	}
 
-	if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
+	if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) || !argv[0]) {
 		stream->write_function(stream, "%s", usage_string);
 		goto done;
 	}

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	Wed Dec 12 23:01:29 2007
@@ -345,7 +345,7 @@
 	uint32_t ireg_loops = 0;
 	uint32_t gateway_loops = 0;
 	switch_event_t *s_event;
-	int tport_log = 0;
+	int tportlog = 0;
 	
 	switch_mutex_lock(mod_sofia_globals.mutex);
 	mod_sofia_globals.threads++;
@@ -363,13 +363,13 @@
 	}
 
 	if (switch_test_flag(profile, TFLAG_TPORT_LOG)) {
-		tport_log = 1;
+		tportlog = 1;
 	}
 
 	profile->nua = nua_create(profile->s_root,	/* Event loop */
 							  sofia_event_callback,	/* Callback for processing events */
 							  profile,	/* Additional data to pass to callback */
-							  NUTAG_URL(profile->bindurl), NTATAG_UDP_MTU(65536), TAG_IF(tport_log,TPTAG_LOG(1)), TAG_END());	/* Last tag should always finish the sequence */
+							  NUTAG_URL(profile->bindurl), NTATAG_UDP_MTU(65536), TAG_IF(tportlog,TPTAG_LOG(1)), TAG_END());	/* Last tag should always finish the sequence */
 
 	if (!profile->nua) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Creating SIP UA for profile: %s\n", profile->name);
@@ -1046,8 +1046,8 @@
 				}
 
 				if (profile->bind_params) {
-					char *url = profile->bindurl;
-					profile->bindurl = switch_core_sprintf(profile->pool, "%s;%s", url, profile->bind_params);
+					char *bindurl = profile->bindurl;
+					profile->bindurl = switch_core_sprintf(profile->pool, "%s;%s", bindurl, profile->bind_params);
 				}
 				
 			}

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	Wed Dec 12 23:01:29 2007
@@ -867,6 +867,7 @@
 
 switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
 {
+	int ms;
 
 	if (tech_pvt->read_codec.implementation) {
 		if (!force) {
@@ -901,32 +902,38 @@
 							   NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
 		return SWITCH_STATUS_FALSE;
-	} else {
-		if (switch_core_codec_init(&tech_pvt->write_codec,
-								   tech_pvt->iananame,
-								   tech_pvt->rm_fmtp,
-								   tech_pvt->rm_rate,
-								   tech_pvt->codec_ms,
-								   1,
-								   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags,
-								   NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
-			return SWITCH_STATUS_FALSE;
-		} else {
-			int ms;
-			tech_pvt->read_frame.rate = tech_pvt->rm_rate;
-			ms = tech_pvt->write_codec.implementation->microseconds_per_frame / 1000;
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set Codec %s %s/%ld %d ms %d samples\n",
-							  switch_channel_get_name(tech_pvt->channel), tech_pvt->iananame, tech_pvt->rm_rate, tech_pvt->codec_ms,
-							  tech_pvt->read_codec.implementation->samples_per_frame
-							  );
-			tech_pvt->read_frame.codec = &tech_pvt->read_codec;
-			
-			switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
-			switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
-			tech_pvt->fmtp_out = switch_core_session_strdup(tech_pvt->session, tech_pvt->write_codec.fmtp_out);
-		}
+	} 
+
+	if (switch_core_codec_init(&tech_pvt->write_codec,
+							   tech_pvt->iananame,
+							   tech_pvt->rm_fmtp,
+							   tech_pvt->rm_rate,
+							   tech_pvt->codec_ms,
+							   1,
+							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags,
+							   NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
+		return SWITCH_STATUS_FALSE;
+	} 
+
+	tech_pvt->read_frame.rate = tech_pvt->rm_rate;
+	ms = tech_pvt->write_codec.implementation->microseconds_per_frame / 1000;
+
+	if (!tech_pvt->read_codec.implementation) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
+		return SWITCH_STATUS_FALSE;
 	}
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set Codec %s %s/%ld %d ms %d samples\n",
+					  switch_channel_get_name(tech_pvt->channel), tech_pvt->iananame, tech_pvt->rm_rate, tech_pvt->codec_ms,
+					  tech_pvt->read_codec.implementation->samples_per_frame
+					  );
+	tech_pvt->read_frame.codec = &tech_pvt->read_codec;
+	
+	switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
+	switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
+	tech_pvt->fmtp_out = switch_core_session_strdup(tech_pvt->session, tech_pvt->write_codec.fmtp_out);
+
 	return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c	Wed Dec 12 23:01:29 2007
@@ -341,23 +341,23 @@
 	case SWITCH_EVENT_PRESENCE_PROBE:
 		if (proto) {
 			char *to = switch_event_get_header(event, "to");
-			char *user, *euser, *host, *p;
+			char *probe_user, *probe_euser, *probe_host, *p;
 
-			if (!to || !(user = strdup(to))) {
+			if (!to || !(probe_user = strdup(to))) {
 				return;
 			}
 
-			if ((host = strchr(user, '@'))) {
-				*host++ = '\0';
+			if ((probe_host = strchr(probe_user, '@'))) {
+				*probe_host++ = '\0';
 			}
-			euser = user;
-			if ((p = strchr(euser, '+'))) {
-				euser = (p + 1);
+			probe_euser = probe_user;
+			if ((p = strchr(probe_euser, '+'))) {
+				probe_euser = (p + 1);
 			}
 
-			if (euser && host &&
+			if (probe_euser && probe_host &&
 				(sql = switch_mprintf("select sip_user,sip_host,status,rpid,'' from sip_registrations where sip_user='%q' and sip_host='%q'",
-									  euser, host)) && (profile = sofia_glue_find_profile(host))) {
+									  probe_euser, probe_host)) && (profile = sofia_glue_find_profile(probe_host))) {
 				
 				sofia_glue_execute_sql_callback(profile,
 												SWITCH_FALSE,
@@ -725,17 +725,17 @@
 			from_host = "n/a";
 		}
 
-		if (strstr(to_user, "ext+") || strstr(to_user, "user+")) {
-			char proto[80];
+		if (to_user && (strstr(to_user, "ext+") || strstr(to_user, "user+"))) {
+			char protocol[80];
 			char *p;
 
-			switch_copy_string(proto, to_user, sizeof(proto));
-			if ((p = strchr(proto, '+'))) {
+			switch_copy_string(protocol, to_user, sizeof(protocol));
+			if ((p = strchr(protocol, '+'))) {
 				*p = '\0';
 			}
 			
 			if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
-				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", proto);
+				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", protocol);
 				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "login", "%s", profile->name);
 				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host);
 				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "rpid", "active");
@@ -754,7 +754,7 @@
 			}
 		}
 
-		if (strchr(to_user, '+')) {
+		if (to_user && strchr(to_user, '+')) {
 			char *h;
 			if ((proto = (d_user = strdup(to_user)))) {
 				if ((my_to_user = strchr(d_user, '+'))) {

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	Wed Dec 12 23:01:29 2007
@@ -89,9 +89,8 @@
 											  NUTAG_CALLSTATE_REF(ss_state), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END()))) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "registering %s\n", gateway_ptr->name);
 
-				if (!(gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private)))) {
-					abort();
-				}
+				gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private));
+				switch_assert(gateway_ptr->sofia_private);
 				memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
 
 				gateway_ptr->sofia_private->gateway = gateway_ptr;
@@ -881,9 +880,6 @@
 	}
 
 	if (!a1_hash) {
-		su_md5_t ctx;
-		char *input;
-
 		input = switch_mprintf("%s:%s:%s", username, realm, passwd);
 		su_md5_init(&ctx);
 		su_md5_strupdate(&ctx, input);



More information about the Freeswitch-svn mailing list