diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 4fec5c3269..fae029bc61 100755 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -4419,7 +4419,7 @@ struct file_string_context { typedef struct file_string_context file_string_context_t; -static int next_file(switch_file_handle_t *handle) +static switch_status_t next_file(switch_file_handle_t *handle) { file_string_context_t *context = handle->private_info; char *file; @@ -4434,7 +4434,7 @@ static int next_file(switch_file_handle_t *handle) } if (context->index >= context->argc) { - return 0; + return SWITCH_STATUS_FALSE; } @@ -4450,8 +4450,23 @@ static int next_file(switch_file_handle_t *handle) file = switch_core_sprintf(handle->memory_pool, "%s%s%s", prefix, SWITCH_PATH_SEPARATOR, context->argv[context->index]); } - if (switch_core_file_open(&context->fh, - file, handle->channels, handle->samplerate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) { + if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) { + char *path = switch_core_strdup(handle->memory_pool, file); + char *p; + + if ((p = strrchr(path, *SWITCH_PATH_SEPARATOR))) { + *p = '\0'; + if (switch_dir_make_recursive(path, SWITCH_DEFAULT_DIR_PERMS, handle->memory_pool) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", path); + return SWITCH_STATUS_FALSE; + } + + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error finding the folder path section in '%s'\n", path); + } + + } + if (switch_core_file_open(&context->fh, file, handle->channels, handle->samplerate, handle->flags, NULL) != SWITCH_STATUS_SUCCESS) { goto top; } @@ -4477,7 +4492,7 @@ static int next_file(switch_file_handle_t *handle) } } - return 1; + return SWITCH_STATUS_SUCCESS; } @@ -4503,11 +4518,6 @@ static switch_status_t file_string_file_open(switch_file_handle_t *handle, const file_string_context_t *context; char *file_dup; - if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This format does not support writing!\n"); - return SWITCH_STATUS_FALSE; - } - context = switch_core_alloc(handle->memory_pool, sizeof(*context)); file_dup = switch_core_strdup(handle->memory_pool, path); @@ -4516,7 +4526,7 @@ static switch_status_t file_string_file_open(switch_file_handle_t *handle, const handle->private_info = context; - return next_file(handle) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; + return next_file(handle); } static switch_status_t file_string_file_close(switch_file_handle_t *handle) @@ -4549,16 +4559,35 @@ static switch_status_t file_string_file_read(switch_file_handle_t *handle, void } if (status != SWITCH_STATUS_SUCCESS) { - if (!next_file(handle)) { - return SWITCH_STATUS_FALSE; + if ((status = next_file(handle)) != SWITCH_STATUS_SUCCESS) { + return status; } *len = llen; status = switch_core_file_read(&context->fh, data, len); } - return SWITCH_STATUS_SUCCESS; + return status; } +static switch_status_t file_string_file_write(switch_file_handle_t *handle, void *data, size_t *len) +{ + file_string_context_t *context = handle->private_info; + switch_status_t status; + size_t llen = *len; + + status = switch_core_file_write(&context->fh, data, len); + + if (status != SWITCH_STATUS_SUCCESS) { + if ((status = next_file(handle)) != SWITCH_STATUS_SUCCESS) { + return status; + } + *len = llen; + status = switch_core_file_write(&context->fh, data, len); + } + return status; +} + + /* Registration */ static char *file_string_supported_formats[SWITCH_MAX_CODECS] = { 0 }; @@ -4979,6 +5008,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load) file_interface->file_open = file_string_file_open; file_interface->file_close = file_string_file_close; file_interface->file_read = file_string_file_read; + file_interface->file_write = file_string_file_write; file_interface->file_seek = file_string_file_seek; diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 314b41a5ed..a9ebc4b352 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -1825,7 +1825,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t file_path = switch_core_session_strdup(session, file); } - if (file_path) { + if (file_path && !strstr(file_path, SWITCH_URL_SEPARATOR)) { char *p; char *path = switch_core_session_strdup(session, file_path);