*/
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);
*/
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);
/* 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) {
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");
/* 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) {