[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)`
This commit is contained in:
parent
b8a9c8be9b
commit
914525b564
|
@ -1954,6 +1954,10 @@ SWITCH_DECLARE(void) switch_core_db_test_reactive(switch_core_db_t *db, char *te
|
||||||
///\ingroup core1
|
///\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,
|
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_ switch_file_handle_t *fh,
|
||||||
_In_opt_z_ const char *file_path,
|
_In_opt_z_ const char *file_path,
|
||||||
|
|
|
@ -62,6 +62,48 @@ static switch_status_t get_file_size(switch_file_handle_t *fh, const char **stri
|
||||||
return status;
|
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_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, const char *func, int line,
|
||||||
switch_file_handle_t *fh,
|
switch_file_handle_t *fh,
|
||||||
const char *file_path,
|
const char *file_path,
|
||||||
|
|
|
@ -989,6 +989,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_stop_displace_session(switch_core_ses
|
||||||
switch_media_bug_t *bug;
|
switch_media_bug_t *bug;
|
||||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
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))) {
|
if ((bug = switch_channel_get_private(channel, file))) {
|
||||||
switch_channel_set_private(channel, file, NULL);
|
switch_channel_set_private(channel, file, NULL);
|
||||||
switch_core_media_bug_remove(session, &bug);
|
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_media_bug_t *bug;
|
||||||
switch_status_t status;
|
switch_status_t status;
|
||||||
time_t to = 0;
|
time_t to = 0;
|
||||||
char *ext;
|
|
||||||
const char *prefix;
|
|
||||||
displace_helper_t *dh;
|
displace_helper_t *dh;
|
||||||
const char *p;
|
const char *p;
|
||||||
switch_bool_t hangup_on_error = SWITCH_FALSE;
|
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;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file = switch_core_absolute_filepath(file, session);
|
||||||
|
|
||||||
if ((bug = switch_channel_get_private(channel, file))) {
|
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");
|
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;
|
return SWITCH_STATUS_FALSE;
|
||||||
|
@ -1039,35 +1040,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_
|
||||||
return SWITCH_STATUS_MEMERR;
|
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.channels = read_impl.number_of_channels;
|
||||||
dh->fh.samplerate = read_impl.actual_samples_per_second;
|
dh->fh.samplerate = read_impl.actual_samples_per_second;
|
||||||
dh->file = switch_core_session_strdup(session, file);
|
dh->file = switch_core_session_strdup(session, file);
|
||||||
|
|
Loading…
Reference in New Issue