Skip to content

Commit

Permalink
[core] fix switch_ivr_stop_displace_session when using relative file
Browse files Browse the repository at this point in the history
- Added new function `SWITCH_DECLARE(const char *) switch_core_absolute_filepath(const char *file, switch_core_session_t *session)`
  • Loading branch information
ar45 committed Apr 26, 2021
1 parent b7316ba commit df9b129
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 31 deletions.
4 changes: 4 additions & 0 deletions src/include/switch_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,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,
Expand Down
42 changes: 42 additions & 0 deletions src/switch_core_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 2 additions & 31 deletions src/switch_ivr_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,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);
Expand All @@ -1001,8 +1002,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;
Expand Down Expand Up @@ -1036,35 +1035,7 @@ 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);
}
}

file = switch_core_absolute_filepath(file, session);
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);
Expand Down

0 comments on commit df9b129

Please sign in to comment.