[Freeswitch-svn] [commit] r4203 - in freeswitch/trunk/src: . include mod/endpoints/mod_portaudio

Freeswitch SVN mikej at freeswitch.org
Mon Feb 12 13:13:14 EST 2007


Author: mikej
Date: Mon Feb 12 13:13:14 2007
New Revision: 4203

Modified:
   freeswitch/trunk/src/include/switch_utils.h
   freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c
   freeswitch/trunk/src/switch_caller.c
   freeswitch/trunk/src/switch_ivr.c

Log:
some more protection from passing around and printing null values, we are now initializing null's passed to switch_caller_profile_new as blank strings in the caller profile, if your using any caller profile values in if's, please use !switch_strlen_zero() in your check.

Modified: freeswitch/trunk/src/include/switch_utils.h
==============================================================================
--- freeswitch/trunk/src/include/switch_utils.h	(original)
+++ freeswitch/trunk/src/include/switch_utils.h	Mon Feb 12 13:13:14 2007
@@ -200,6 +200,13 @@
 #define switch_strlen_zero(s) (!s || *s == '\0')
 
 /*!
+  \brief Make a null string a blank string instead
+  \param s the string to test
+  \return the original string or blank string.
+*/
+#define switch_str_nil(s) (s ? s : "")
+
+/*!
   \brief Wait a desired number of microseconds and yield the CPU
 */
 #if defined(HAVE_USLEEP)

Modified: freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c	Mon Feb 12 13:13:14 2007
@@ -849,7 +849,7 @@
 
 		if (outbound_profile) {
 			char name[128];
-            char *id = outbound_profile->caller_id_number ? outbound_profile->caller_id_number : "na";
+            char *id = !switch_strlen_zero(outbound_profile->caller_id_number) ? outbound_profile->caller_id_number : "na";
 			snprintf(name, sizeof(name), "PortAudio/%s", id);
 					 
 			switch_channel_set_name(channel, name);

Modified: freeswitch/trunk/src/switch_caller.c
==============================================================================
--- freeswitch/trunk/src/switch_caller.c	(original)
+++ freeswitch/trunk/src/switch_caller.c	Mon Feb 12 13:13:14 2007
@@ -53,17 +53,17 @@
 		if (!context) {
 			context = "default";
 		}
-		profile->username = switch_core_strdup(pool, username);
-		profile->dialplan = switch_core_strdup(pool, dialplan);
-		profile->caller_id_name = switch_core_strdup(pool, caller_id_name);
-		profile->caller_id_number = switch_core_strdup(pool, caller_id_number);
-		profile->network_addr = switch_core_strdup(pool, network_addr);
-		profile->ani = switch_core_strdup(pool, ani);
-		profile->aniii = switch_core_strdup(pool, aniii);
-		profile->rdnis = switch_core_strdup(pool, rdnis);
-		profile->source = switch_core_strdup(pool, source);
-		profile->context = switch_core_strdup(pool, context);
-		profile->destination_number = switch_core_strdup(pool, destination_number);
+		profile->username = switch_core_strdup(pool, switch_str_nil(username));
+		profile->dialplan = switch_core_strdup(pool, switch_str_nil(dialplan));
+		profile->caller_id_name = switch_core_strdup(pool, switch_str_nil(caller_id_name));
+		profile->caller_id_number = switch_core_strdup(pool, switch_str_nil(caller_id_number));
+		profile->network_addr = switch_core_strdup(pool, switch_str_nil(network_addr));
+		profile->ani = switch_core_strdup(pool, switch_str_nil(ani));
+		profile->aniii = switch_core_strdup(pool, switch_str_nil(aniii));
+		profile->rdnis = switch_core_strdup(pool, switch_str_nil(rdnis));
+		profile->source = switch_core_strdup(pool, switch_str_nil(source));
+		profile->context = switch_core_strdup(pool, switch_str_nil(context));
+		profile->destination_number = switch_core_strdup(pool, switch_str_nil(destination_number));
 		switch_set_flag(profile, SWITCH_CPF_SCREEN);
 	}
 
@@ -145,55 +145,55 @@
 	char header_name[1024];
 
 
-	if (caller_profile->username) {
+	if (!switch_strlen_zero(caller_profile->username)) {
 		snprintf(header_name, sizeof(header_name), "%s-Username", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->username);
 	}
-	if (caller_profile->dialplan) {
+	if (!switch_strlen_zero(caller_profile->dialplan)) {
 		snprintf(header_name, sizeof(header_name), "%s-Dialplan", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->dialplan);
 	}
-	if (caller_profile->caller_id_name) {
+	if (!switch_strlen_zero(caller_profile->caller_id_name)) {
 		snprintf(header_name, sizeof(header_name), "%s-Caller-ID-Name", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->caller_id_name);
 	}
-	if (caller_profile->caller_id_number) {
+	if (!switch_strlen_zero(caller_profile->caller_id_number)) {
 		snprintf(header_name, sizeof(header_name), "%s-Caller-ID-Number", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->caller_id_number);
 	}
-	if (caller_profile->network_addr) {
+	if (!switch_strlen_zero(caller_profile->network_addr)) {
 		snprintf(header_name, sizeof(header_name), "%s-Network-Addr", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->network_addr);
 	}
-	if (caller_profile->ani) {
+	if (!switch_strlen_zero(caller_profile->ani)) {
 		snprintf(header_name, sizeof(header_name), "%s-ANI", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->ani);
 	}
-	if (caller_profile->aniii) {
+	if (!switch_strlen_zero(caller_profile->aniii)) {
 		snprintf(header_name, sizeof(header_name), "%s-ANI-II", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->aniii);
 	}
-	if (caller_profile->destination_number) {
+	if (!switch_strlen_zero(caller_profile->destination_number)) {
 		snprintf(header_name, sizeof(header_name), "%s-Destination-Number", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->destination_number);
 	}
-	if (caller_profile->uuid) {
+	if (!switch_strlen_zero(caller_profile->uuid)) {
 		snprintf(header_name, sizeof(header_name), "%s-Unique-ID", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->uuid);
 	}
-	if (caller_profile->source) {
+	if (!switch_strlen_zero(caller_profile->source)) {
 		snprintf(header_name, sizeof(header_name), "%s-Source", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->source);
 	}
-	if (caller_profile->context) {
+	if (!switch_strlen_zero(caller_profile->context)) {
 		snprintf(header_name, sizeof(header_name), "%s-Context", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->context);
 	}
-	if (caller_profile->rdnis) {
+	if (!switch_strlen_zero(caller_profile->rdnis)) {
 		snprintf(header_name, sizeof(header_name), "%s-RDNIS", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->rdnis);
 	}
-	if (caller_profile->chan_name) {
+	if (!switch_strlen_zero(caller_profile->chan_name)) {
 		snprintf(header_name, sizeof(header_name), "%s-Channel-Name", prefix);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->chan_name);
 	}

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Mon Feb 12 13:13:14 2007
@@ -3642,13 +3642,13 @@
 		new_profile = switch_caller_profile_clone(session, profile);
 		new_profile->destination_number = switch_core_session_strdup(session, extension);
 
-		if (dialplan) {
+		if (!switch_strlen_zero(dialplan)) {
 			new_profile->dialplan = switch_core_session_strdup(session, dialplan);
 		} else {
 			dialplan = new_profile->dialplan;
 		}
 
-		if (context) {
+		if (!switch_strlen_zero(context)) {
 			new_profile->context = switch_core_session_strdup(session, context);
 		} else {
 			context = new_profile->context;



More information about the Freeswitch-svn mailing list