提交 d29c2d74 authored 作者: Brian West's avatar Brian West 提交者: Chris Rienzo

FS-7496 #resolve strip url args after the file extension

上级 b28f7aca
...@@ -844,14 +844,15 @@ static const char *find_extension(const char *url) ...@@ -844,14 +844,15 @@ static const char *find_extension(const char *url)
* @param extension the filename extension * @param extension the filename extension
* @return the cached URL filename. Free when done. * @return the cached URL filename. Free when done.
*/ */
static char *cached_url_filename_create(url_cache_t *cache, const char *extension) static char *cached_url_filename_create(url_cache_t *cache, const char *url)
{ {
char *filename; char *filename;
char *dirname; char *dirname;
char uuid_dir[3] = { 0 }; char uuid_dir[3] = { 0 };
switch_uuid_t uuid; switch_uuid_t uuid;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1] = { 0 }; char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1] = { 0 };
const char *extension = find_extension(url);
/* filename is constructed from UUID and is stored in cache dir (first 2 characters of UUID) */ /* filename is constructed from UUID and is stored in cache dir (first 2 characters of UUID) */
switch_uuid_get(&uuid); switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid); switch_uuid_format(uuid_str, &uuid);
...@@ -861,9 +862,16 @@ static char *cached_url_filename_create(url_cache_t *cache, const char *extensio ...@@ -861,9 +862,16 @@ static char *cached_url_filename_create(url_cache_t *cache, const char *extensio
/* create sub-directory if it doesn't exist */ /* create sub-directory if it doesn't exist */
switch_dir_make_recursive(dirname, SWITCH_DEFAULT_DIR_PERMS, cache->pool); switch_dir_make_recursive(dirname, SWITCH_DEFAULT_DIR_PERMS, cache->pool);
if (!zstr(extension)) { if (!zstr(extension)) {
char *p;
filename = switch_mprintf("%s%s%s.%s", dirname, SWITCH_PATH_SEPARATOR, &uuid_str[2], extension); filename = switch_mprintf("%s%s%s.%s", dirname, SWITCH_PATH_SEPARATOR, &uuid_str[2], extension);
} else { if ((p = strchr(filename, '?'))) {
*p = '\0';
}
if ((p = strchr(filename, '#'))) {
*p = '\0';
}
} else {
filename = switch_mprintf("%s%s%s", dirname, SWITCH_PATH_SEPARATOR, &uuid_str[2]); filename = switch_mprintf("%s%s%s", dirname, SWITCH_PATH_SEPARATOR, &uuid_str[2]);
} }
free(dirname); free(dirname);
...@@ -889,7 +897,7 @@ static cached_url_t *cached_url_create(url_cache_t *cache, const char *url, cons ...@@ -889,7 +897,7 @@ static cached_url_t *cached_url_create(url_cache_t *cache, const char *url, cons
/* intialize cached URL */ /* intialize cached URL */
if (zstr(filename)) { if (zstr(filename)) {
u->filename = cached_url_filename_create(cache, find_extension(url)); u->filename = cached_url_filename_create(cache, url);
} else { } else {
u->filename = strdup(filename); u->filename = strdup(filename);
} }
...@@ -1095,7 +1103,7 @@ SWITCH_STANDARD_API(http_cache_prefetch) ...@@ -1095,7 +1103,7 @@ SWITCH_STANDARD_API(http_cache_prefetch)
#define HTTP_GET_SYNTAX "{param=val}<url>" #define HTTP_GET_SYNTAX "{param=val}<url>"
/** /**
* Get a file from the cache, download if it isn't cached * Get a file from the cache, download if it isn' cached
*/ */
SWITCH_STANDARD_API(http_cache_get) SWITCH_STANDARD_API(http_cache_get)
{ {
...@@ -1564,7 +1572,7 @@ static switch_status_t http_cache_file_open(switch_file_handle_t *handle, const ...@@ -1564,7 +1572,7 @@ static switch_status_t http_cache_file_open(switch_file_handle_t *handle, const
file_flags |= SWITCH_FILE_FLAG_WRITE; file_flags |= SWITCH_FILE_FLAG_WRITE;
context->write_url = switch_core_strdup(handle->memory_pool, path); context->write_url = switch_core_strdup(handle->memory_pool, path);
/* allocate local file in cache */ /* allocate local file in cache */
context->local_path = cached_url_filename_create(&gcache, find_extension(context->write_url)); context->local_path = cached_url_filename_create(&gcache, context->write_url);
} else { } else {
/* READ = HTTP GET */ /* READ = HTTP GET */
file_flags |= SWITCH_FILE_FLAG_READ; file_flags |= SWITCH_FILE_FLAG_READ;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论