]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Properly handle NULL var_name for switch_play_and_get_digits
authorPeter Wu <peter@lekensteyn.nl>
Fri, 6 May 2016 16:26:07 +0000 (18:26 +0200)
committerPeter Wu <peter@lekensteyn.nl>
Fri, 6 May 2016 16:33:32 +0000 (18:33 +0200)
Do not set "_invalid" in case var_name is empty or unset. While at it,
clear the "foo_invalid" variable before doing anything else when a regex
is passed, this ensures that the variable really reflects the current
run.

Fixes an issue in original FS-7783 feature.

src/switch_ivr_play_say.c

index d856131dd8bb9bce23c0e282e14c0863d60dee08..4a1d6da68c0a5ea6d1ee3bd03a25e2ef9672d103 100644 (file)
@@ -2252,6 +2252,13 @@ SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t
                                                                                                                   const char *transfer_on_failure)
 {
        switch_channel_t *channel = switch_core_session_get_channel(session);
+       char *var_name_invalid = NULL;
+
+       if (!zstr(digits_regex) && !zstr(var_name)) {
+               var_name_invalid = switch_mprintf("%s_invalid", var_name);
+               switch_channel_set_variable(channel, var_name_invalid, NULL);
+               switch_safe_free(var_name_invalid);
+       }
 
        while (switch_channel_ready(channel) && max_tries) {
                switch_status_t status;
@@ -2277,21 +2284,20 @@ SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t
                if (!(status == SWITCH_STATUS_TOO_SMALL && strlen(digit_buffer) == 0)) {
                        if (status == SWITCH_STATUS_SUCCESS) {
                                if (!zstr(digit_buffer)) {
-                                       char *invalid_var = NULL;
                                        if (zstr(digits_regex)) {
                                                return SWITCH_STATUS_SUCCESS;
                                        }
                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "Test Regex [%s][%s]\n", digit_buffer, digits_regex);
 
-                                       invalid_var = switch_mprintf("%s_invalid", var_name);
                                        if (switch_regex_match(digit_buffer, digits_regex) == SWITCH_STATUS_SUCCESS) {
-                                               switch_channel_set_variable(channel, invalid_var, NULL);
-                                               switch_safe_free(invalid_var);
                                                return SWITCH_STATUS_SUCCESS;
                                        } else {
                                                switch_channel_set_variable(channel, var_name, NULL);
-                                               switch_channel_set_variable(channel, invalid_var, digit_buffer);
-                                               switch_safe_free(invalid_var);
+                                               if (!zstr(var_name)) {
+                                                       var_name_invalid = switch_mprintf("%s_invalid", var_name);
+                                                       switch_channel_set_variable(channel, var_name_invalid, digit_buffer);
+                                                       switch_safe_free(var_name_invalid);
+                                               }
                                        }
                                }
                        }