From ebe4720b16c16fdcde3f4cd3b489b2d3f1f48513 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Tue, 13 Mar 2018 15:44:06 +0900 Subject: [PATCH] Add function to trim the path Change-Id: I6fa4bb11965eb86ae0b0ddf48e6c9ea363fcb23a Signed-off-by: Minje Ahn --- include/media_util_private.h | 1 + include_product/media_util_private.h | 1 + src/media_content.c | 7 ++----- src/media_util_private.c | 34 +++++++++++++++++++++++++++++----- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/include/media_util_private.h b/include/media_util_private.h index 89b95eb..5db2d36 100755 --- a/include/media_util_private.h +++ b/include/media_util_private.h @@ -31,6 +31,7 @@ extern "C" { */ bool _media_util_check_support_media_type(const char *path); int _media_util_check_file_exist(const char *path); +void _media_util_trim_path(const char *input_path, char **output_path); int _media_util_check_ignore_file(const char *path, bool *ignore); int _media_util_check_ignore_dir(const char *dir_path, bool *ignore); int _media_content_replace_path_in_condition(const char *condition, char *replace_condition, bool replace); diff --git a/include_product/media_util_private.h b/include_product/media_util_private.h index 0abd2fe..1b638fd 100755 --- a/include_product/media_util_private.h +++ b/include_product/media_util_private.h @@ -31,6 +31,7 @@ extern "C" { */ bool _media_util_check_support_media_type(const char *path); int _media_util_check_file_exist(const char *path); +void _media_util_trim_path(const char *input_path, char **output_path); int _media_util_check_ignore_file(const char *path, bool *ignore); int _media_util_check_ignore_dir(const char *dir_path, bool *ignore); int _media_content_replace_path_in_condition(const char *condition, char *replace_condition, bool replace); diff --git a/src/media_content.c b/src/media_content.c index 0e708e6..3f88054 100755 --- a/src/media_content.c +++ b/src/media_content.c @@ -1478,11 +1478,8 @@ static int __media_content_check_dir(const char *path) /* Check symbolic link directory */ real = realpath(path, NULL); - /* remove if suffix is '/' */ - if (g_str_has_suffix(path, "/")) - origin = g_strndup(path, strlen(path) - 1); - else - origin = g_strdup(path); + /* Get trimmed path */ + _media_util_trim_path(path, &origin); #ifdef _USE_TVPD_MODE if (g_strcmp0(real, origin) != 0) { diff --git a/src/media_util_private.c b/src/media_util_private.c index d963500..77ca1af 100755 --- a/src/media_util_private.c +++ b/src/media_util_private.c @@ -76,6 +76,33 @@ int _media_util_check_file_exist(const char *path) return MEDIA_CONTENT_ERROR_NONE; } +void _media_util_trim_path(const char *input_path, char **output_path) +{ + char buf[4096] = {0,}; + char tmp[4096] = {0,}; + char *pos = NULL; + + memset(buf, 0, sizeof(buf)); + if (!SAFE_STRLCPY(buf, input_path, sizeof(buf))) + media_content_sec_debug("Truncation occurred[%d]", strlen(input_path)); + + while ((pos = strstr(buf, "//")) != NULL) { + memset(tmp, 0, sizeof(tmp)); + if (!SAFE_STRLCPY(tmp, buf, pos - buf + 1)) + media_content_sec_debug("Truncation occurred"); + SAFE_STRLCAT(tmp, pos + 1, sizeof(tmp)); + + memset(buf, 0, sizeof(buf)); + if (!SAFE_STRLCPY(buf, tmp, sizeof(buf))) + media_content_sec_debug("Truncation occurred[%d]", strlen(tmp)); + } + + if (g_str_has_suffix(buf, "/")) + *output_path = g_strndup(buf, strlen(buf) - 1); + else + *output_path = g_strdup(buf); +} + int _media_util_check_ignore_file(const char *path, bool *ignore) { media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path"); @@ -112,11 +139,8 @@ int _media_util_check_ignore_file(const char *path, bool *ignore) /* Check symbolic directory */ tmp_path = realpath(path, NULL); - /* remove if suffix is '/' */ - if (g_str_has_suffix(path, "/")) - org_path = g_strndup(path, strlen(path) - 1); - else - org_path = g_strdup(path); + /* Get trimmed path */ + _media_util_trim_path(path, &org_path); #ifdef _USE_TVPD_MODE if (g_strcmp0(tmp_path, org_path) != 0) { -- 2.7.4