From 914525b564fa095fe570311da391b096cb2ebe84 Mon Sep 17 00:00:00 2001 From: Aron Podrigal Date: Mon, 26 Apr 2021 10:07:10 -0500 Subject: [PATCH] [core] fix switch_ivr_stop_displace_session when using relative file - Added new function `SWITCH_DECLARE(const char *) switch_core_absolute_filepath(const char *file, switch_core_session_t *session)` --- src/include/switch_core.h | 4 ++++ src/switch_core_file.c | 42 +++++++++++++++++++++++++++++++++++++++ src/switch_ivr_async.c | 34 +++---------------------------- 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index ff04fa0954..9052871f4c 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -1954,6 +1954,10 @@ SWITCH_DECLARE(void) switch_core_db_test_reactive(switch_core_db_t *db, char *te ///\ingroup core1 ///\{ + +SWITCH_DECLARE(const char *) switch_core_absolute_filepath(_In_ const char *file, _In_ switch_core_session_t *session); + + SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, const char *func, int line, _In_ switch_file_handle_t *fh, _In_opt_z_ const char *file_path, diff --git a/src/switch_core_file.c b/src/switch_core_file.c index 84e6acb3c0..a09bea08f4 100644 --- a/src/switch_core_file.c +++ b/src/switch_core_file.c @@ -62,6 +62,48 @@ static switch_status_t get_file_size(switch_file_handle_t *fh, const char **stri return status; } + +SWITCH_DECLARE(const char *) switch_core_absolute_filepath(const char *file, switch_core_session_t *session) +{ + const char *prefix = NULL; + char *ext; + switch_channel_t *channel = switch_core_session_get_channel(session); + + if (!strstr(file, SWITCH_URL_SEPARATOR)) { + if (!switch_is_file_path(file)) { + char *tfile = NULL; + char *e; + + if (*file == '[') { + tfile = switch_core_session_strdup(session, file); + if ((e = switch_find_end_paren(tfile, '[', ']'))) { + *e = '\0'; + file = e + 1; + } else { + tfile = NULL; + } + } + + if (!(prefix = switch_channel_get_variable(channel, "sound_prefix"))) { + prefix = SWITCH_GLOBAL_dirs.base_dir; + } + + file = switch_core_session_sprintf(session, "%s%s%s%s%s", switch_str_nil(tfile), tfile ? "]" : "", prefix, SWITCH_PATH_SEPARATOR, file); + } + if ((ext = strrchr(file, '.'))) { + ext++; + } else { + switch_codec_implementation_t read_impl = { 0 }; + switch_core_session_get_read_impl(session, &read_impl); + ext = read_impl.iananame; + file = switch_core_session_sprintf(session, "%s.%s", file, ext); + } + } + + return file; +} + + SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, const char *func, int line, switch_file_handle_t *fh, const char *file_path, diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 4075f0adce..894fc1b8f8 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -989,6 +989,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_stop_displace_session(switch_core_ses switch_media_bug_t *bug; switch_channel_t *channel = switch_core_session_get_channel(session); + file = switch_core_absolute_filepath(file, session); if ((bug = switch_channel_get_private(channel, file))) { switch_channel_set_private(channel, file, NULL); switch_core_media_bug_remove(session, &bug); @@ -1004,8 +1005,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_ switch_media_bug_t *bug; switch_status_t status; time_t to = 0; - char *ext; - const char *prefix; displace_helper_t *dh; const char *p; switch_bool_t hangup_on_error = SWITCH_FALSE; @@ -1030,6 +1029,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_ return SWITCH_STATUS_FALSE; } + file = switch_core_absolute_filepath(file, session); + if ((bug = switch_channel_get_private(channel, file))) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Only 1 of the same file per channel please!\n"); return SWITCH_STATUS_FALSE; @@ -1039,35 +1040,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_ return SWITCH_STATUS_MEMERR; } - if (!(prefix = switch_channel_get_variable(channel, "sound_prefix"))) { - prefix = SWITCH_GLOBAL_dirs.base_dir; - } - - if (!strstr(file, SWITCH_URL_SEPARATOR)) { - if (!switch_is_file_path(file)) { - char *tfile = NULL; - char *e; - - if (*file == '[') { - tfile = switch_core_session_strdup(session, file); - if ((e = switch_find_end_paren(tfile, '[', ']'))) { - *e = '\0'; - file = e + 1; - } else { - tfile = NULL; - } - } - - file = switch_core_session_sprintf(session, "%s%s%s%s%s", switch_str_nil(tfile), tfile ? "]" : "", prefix, SWITCH_PATH_SEPARATOR, file); - } - if ((ext = strrchr(file, '.'))) { - ext++; - } else { - ext = read_impl.iananame; - file = switch_core_session_sprintf(session, "%s.%s", file, ext); - } - } - dh->fh.channels = read_impl.number_of_channels; dh->fh.samplerate = read_impl.actual_samples_per_second; dh->file = switch_core_session_strdup(session, file);