From 10e9022f44ccf8391c124085ff8a64be103a4be3 Mon Sep 17 00:00:00 2001 From: Eunhae Choi Date: Tue, 27 Dec 2016 18:37:31 +0900 Subject: [PATCH] [v0.3.39] remove file:// prefix before checking internal path Change-Id: I5fa2f59fbb6cfa95f2aabf3c70a7f5717c45100d --- include/player_private.h | 3 ++- src/player.c | 64 +++++++++++++++++++++++++++++++----------------- src/player_internal.c | 12 +++------ 3 files changed, 47 insertions(+), 32 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/src/player.c b/src/player.c index 701176c..f2fe531 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; @@ -3257,14 +3288,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); @@ -3302,13 +3327,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.7.4