From 498b5cb905da25b93a4da8c41ced547dd302c09c Mon Sep 17 00:00:00 2001 From: Eunhae Choi Date: Tue, 27 Dec 2016 17:22:29 +0900 Subject: [PATCH] [0.3.41] remove file:// prefix before checking internal path Change-Id: I7b57664465a379693f2649fc034187a845a60916 --- include/player_private.h | 3 +- packaging/capi-media-player.spec | 2 +- src/player.c | 64 +++++++++++++++++++++----------- src/player_internal.c | 12 ++---- 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/include/player_private.h b/include/player_private.h index ea053f1..590c845 100644 --- a/include/player_private.h +++ b/include/player_private.h @@ -182,7 +182,8 @@ typedef struct _player_cli_s { int client_get_api_timeout(player_cli_s * pc, muse_player_api_e api); int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_info, char **ret_buf, int time_out); -int _player_convert_display_type (player_display_type_e type, player_private_display_type_e *out_type); +int _player_convert_display_type(player_display_type_e type, player_private_display_type_e *out_type); +int _player_get_origin_internal_path(const char* uri, char* origin); #ifdef __cplusplus } diff --git a/packaging/capi-media-player.spec b/packaging/capi-media-player.spec index e6421be..1a5aa29 100644 --- a/packaging/capi-media-player.spec +++ b/packaging/capi-media-player.spec @@ -1,6 +1,6 @@ Name: capi-media-player Summary: A Media Player API -Version: 0.3.40 +Version: 0.3.41 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/player.c b/src/player.c index f13b2f0..be7a808 100644 --- a/src/player.c +++ b/src/player.c @@ -1884,6 +1884,42 @@ int player_unprepare(player_h player) return ret; } +/* 1. covert '/opt/usr/media/xxx' file path to '/opt/usr/home/owner/media/xxx' + * 2. remove 'file://' prefix */ +int _player_get_origin_internal_path(const char* uri, char* origin) +{ + gchar *file_path = NULL; + GError *err = NULL; + + if (strstr(uri, "file://")) { + file_path = g_filename_from_uri(uri, NULL, &err); + + if (!file_path || (err != NULL)) { + LOGE("Invalid URI '%s', err: %s", uri, + (err != NULL) ? err->message : "unknown error"); + + if (err) g_error_free(err); + if (file_path) g_free(file_path); + + return PLAYER_ERROR_INVALID_PARAMETER; + } + LOGD("get file path from uri"); + } + + if (storage_get_origin_internal_path((file_path) ? (file_path) : (uri), MAX_URL_LEN, origin) < 0) { + /* cannot convert path. use the original one. */ + strncpy(origin, (file_path) ? (file_path) : (uri), MAX_URL_LEN-1); + } else { + /* need to use converted path. */ + LOGD("Converted path : %s -> %s", uri, origin); + } + + if (file_path) + g_free(file_path); + + return PLAYER_ERROR_NONE; +} + int player_set_uri(player_h player, const char *uri) { PLAYER_INSTANCE_CHECK(player); @@ -1896,13 +1932,8 @@ int player_set_uri(player_h player, const char *uri) LOGD("ENTER"); - if (storage_get_origin_internal_path(uri, MAX_URL_LEN, path) < 0) { - /* cannot convert path. use the original one. */ - strncpy(path, uri, MAX_URL_LEN-1); - } else { - /* need to use converted path. */ - LOGD("Converted path : %s -> %s", uri, path); - } + if (_player_get_origin_internal_path(uri, path) != PLAYER_ERROR_NONE) + return PLAYER_ERROR_INVALID_PARAMETER; player_msg_send1(api, pc, ret_buf, ret, STRING, path); pc->push_media_stream = FALSE; @@ -3220,14 +3251,8 @@ int player_set_subtitle_path(player_h player, const char *path) LOGD("ENTER"); - if (storage_get_origin_internal_path(path, MAX_URL_LEN, subtitle_path) < 0) { - /* cannot convert path. use the original one. */ - if (path != NULL) - strncpy(subtitle_path, path, MAX_URL_LEN-1); - } else { - /* need to use converted path. */ - LOGD("Converted path : %s -> %s", path, subtitle_path); - } + if (_player_get_origin_internal_path(path, subtitle_path) != PLAYER_ERROR_NONE) + return PLAYER_ERROR_INVALID_PARAMETER; player_msg_send1(api, pc, ret_buf, ret, STRING, subtitle_path); g_free(ret_buf); @@ -3265,13 +3290,8 @@ int player_set_progressive_download_path(player_h player, const char *path) if (!_player_check_network_availability()) return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE; - if (storage_get_origin_internal_path(path, MAX_URL_LEN, dw_path) < 0) { - /* cannot convert path. use the original one. */ - strncpy(dw_path, path, MAX_URL_LEN-1); - } else { - /* need to use converted path. */ - LOGD("Converted path : %s -> %s", path, dw_path); - } + if (_player_get_origin_internal_path(path, dw_path) != PLAYER_ERROR_NONE) + return PLAYER_ERROR_INVALID_PARAMETER; player_msg_send1(api, pc, ret_buf, ret, STRING, dw_path); g_free(ret_buf); diff --git a/src/player_internal.c b/src/player_internal.c index ab84ac1..0b25da9 100644 --- a/src/player_internal.c +++ b/src/player_internal.c @@ -204,9 +204,8 @@ int player_set_ecore_wl_display(player_h player, player_display_type_e type, Eco LOGD("ENTER"); ret = _player_convert_display_type(type, &conv_type); - if (ret != PLAYER_ERROR_NONE) { + if (ret != PLAYER_ERROR_NONE) return ret; - } if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) { LOGE("Display type(%d) is not overlay", conv_type); @@ -274,13 +273,8 @@ int player_set_next_uri(player_h player, const char *uri) LOGD("ENTER"); - if (storage_get_origin_internal_path(uri, MAX_URL_LEN, path) < 0) { - /* cannot convert path. use the original one. */ - strncpy(path, uri, MAX_URL_LEN-1); - } else { - /* need to use converted path. */ - LOGD("Converted path : %s -> %s", uri, path); - } + if (_player_get_origin_internal_path(uri, path) != PLAYER_ERROR_NONE) + return PLAYER_ERROR_INVALID_PARAMETER; player_msg_send1(api, pc, ret_buf, ret, STRING, path); -- 2.34.1