From 768fbb68d4f1efe09f8700894571ca560d54c98d Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Wed, 26 May 2021 09:38:04 +0800 Subject: [PATCH] normalize_path support file resource start with file:// --- src/common_define.h | 7 +++++++ src/http_func.c | 4 ++-- src/shared_func.c | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/common_define.h b/src/common_define.h index 88f1c56..bd374e9 100644 --- a/src/common_define.h +++ b/src/common_define.h @@ -107,6 +107,13 @@ extern int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind); #define IP_ADDRESS_SIZE 16 #define INFINITE_FILE_SIZE (256 * 1024LL * 1024 * 1024 * 1024 * 1024LL) +#define FILE_RESOURCE_TAG_STR "file://" +#define FILE_RESOURCE_TAG_LEN (sizeof(FILE_RESOURCE_TAG_STR) - 1) + +#define IS_FILE_RESOURCE(filename) \ + (strncasecmp(filename, FILE_RESOURCE_TAG_STR, \ + FILE_RESOURCE_TAG_LEN) == 0) + #ifndef byte #define byte signed char #endif diff --git a/src/http_func.c b/src/http_func.c index 8969c3b..7afb1a2 100644 --- a/src/http_func.c +++ b/src/http_func.c @@ -60,6 +60,7 @@ int get_url_content_ex(const char *url, const int url_len, char *pPort; char *pSpace; + *error_info = '\0'; *http_status = 0; if (*content == NULL) { @@ -254,9 +255,8 @@ int get_url_content_ex(const char *url, const int url_len, *http_status = atoi(pSpace + 1); *content_len -= pContent - *content; - memcpy(*content, pContent, *content_len); + memmove(*content, pContent, *content_len); *(*content + *content_len) = '\0'; - *error_info = '\0'; } while (0); close(sock); diff --git a/src/shared_func.c b/src/shared_func.c index 832fa8e..a96f04a 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -2996,6 +2996,13 @@ int normalize_path(const char *from, const char *filename, const char *last; int len; + if (IS_FILE_RESOURCE(from)) { + from = from + FILE_RESOURCE_TAG_LEN; + } + if (IS_FILE_RESOURCE(filename)) { + filename = filename + FILE_RESOURCE_TAG_LEN; + } + if (*filename == '/') { return snprintf(full_filename, size, "%s", filename); } @@ -3099,6 +3106,11 @@ int normalize_path_ex(const char *from, const char *filename, return normalize_path(from, filename, full_filename, size); } + if (IS_FILE_RESOURCE(filename)) { + return snprintf(full_filename, size, "%s", + filename + FILE_RESOURCE_TAG_LEN); + } + if (!is_url_from) { return snprintf(full_filename, size, "%s", filename); }