]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
some more protection from passing around and printing null values, we are now initial...
authorMichael Jerris <mike@jerris.com>
Mon, 12 Feb 2007 18:13:14 +0000 (18:13 +0000)
committerMichael Jerris <mike@jerris.com>
Mon, 12 Feb 2007 18:13:14 +0000 (18:13 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4203 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_utils.h
src/mod/endpoints/mod_portaudio/mod_portaudio.c
src/switch_caller.c
src/switch_ivr.c

index a67a3ceb72d38d086b0f5c38986197903938e0e8..0a4fa622773be92efe0155d2c1a789c3e7499777 100644 (file)
@@ -199,6 +199,13 @@ switch_mutex_unlock(obj->flag_mutex);
 */
 #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
 */
index 6d31a63c6da2307e462dffeeaa73c10f1fc552b7..c87e728bb2341fa0cefb35dcafcabb48daac9a53 100644 (file)
@@ -849,7 +849,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
 
                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);
index 4a5062618d74593dbcc607144ad93f0cf93cf9fe..ec96741c3137d55b42c6b3c0d08922ff4cc5f8eb 100644 (file)
@@ -53,17 +53,17 @@ SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_new(switch_memor
                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 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_
        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);
        }
index b3d745b3d3ab1a117133ba5244f796cc8214834e..3c764278d9c97dae049ce14c16cc9f092522f0ed 100644 (file)
@@ -3642,13 +3642,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_
                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;