From 69d643b53f5c72a33728a73b9fbf0b0ecc41b7e6 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 6 May 2016 18:26:07 +0200 Subject: [PATCH] Properly handle NULL var_name for switch_play_and_get_digits 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 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index d856131dd8..4a1d6da68c 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -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); + } } } }