From: Jean-Benoit MARTIN Date: Tue, 26 Aug 2014 14:28:12 +0000 (+0200) Subject: Multiuser feature X-Git-Tag: accepted/tizen/common/20141001.131251^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Faccepted%2Ftizen_3.0.2014.q3_common;p=platform%2Fcore%2Fmultimedia%2Flibmedia-service.git Multiuser feature Use User UID to write or read into database Use Unix socket Fix-Tizen: TC-1482 Change-Id: I302a3cee78003cae500f1c170ea61bf03552e8d4 Signed-off-by: Jean-Benoit MARTIN --- diff --git a/include/media-svc.h b/include/media-svc.h index 8cc969e..ace3366 100755 --- a/include/media-svc.h +++ b/include/media-svc.h @@ -83,7 +83,7 @@ void connect_media_db() * @endcode */ -int media_svc_connect(MediaSvcHandle **handle); +int media_svc_connect(MediaSvcHandle **handle,uid_t uid); /** @@ -183,49 +183,49 @@ void create_media_db_table() * @endcode */ -int media_svc_create_table(MediaSvcHandle *handle); +int media_svc_create_table(MediaSvcHandle *handle, uid_t uid); int media_svc_check_item_exist_by_path(MediaSvcHandle *handle, const char *path); -int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path); +int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, uid_t uid); int media_svc_insert_item_begin(MediaSvcHandle *handle, int with_noti, int data_cnt, int from_pid); -int media_svc_insert_item_end(MediaSvcHandle *handle); +int media_svc_insert_item_end(MediaSvcHandle *handle, uid_t uid); -int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, int is_burst); +int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, int is_burst, uid_t uid); -int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path); +int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, uid_t uid); int media_svc_move_item_begin(MediaSvcHandle *handle, int data_cnt); -int media_svc_move_item_end(MediaSvcHandle *handle); +int media_svc_move_item_end(MediaSvcHandle *handle, uid_t uid); -int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_storage, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path); +int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_storage, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path, uid_t uid); int media_svc_set_item_validity_begin(MediaSvcHandle *handle, int data_cnt); -int media_svc_set_item_validity_end(MediaSvcHandle *handle); +int media_svc_set_item_validity_end(MediaSvcHandle *handle, uid_t uid); -int media_svc_set_item_validity(MediaSvcHandle *handle, const char *path, int validity); +int media_svc_set_item_validity(MediaSvcHandle *handle, const char *path, int validity, uid_t uid); -int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path); +int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path, uid_t uid); -int media_svc_delete_all_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type); +int media_svc_delete_all_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, uid_t uid); -int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type); +int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, uid_t uid); -int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char *folder_path); +int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char *folder_path, uid_t uid); -int media_svc_set_all_storage_items_validity(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, int validity); +int media_svc_set_all_storage_items_validity(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, int validity, uid_t uid); -int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *folder_path, int validity, int recursive); +int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *folder_path, int validity, int recursive, uid_t uid); -int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path); +int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, uid_t uid); -int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const char *dst_path); +int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const char *dst_path, uid_t uid); -int media_svc_request_update_db(const char *db_query); +int media_svc_request_update_db(const char *db_query, uid_t uid); int media_svc_get_storage_type(const char *path, media_svc_storage_type_e *storage_type); diff --git a/packaging/libmedia-service.spec b/packaging/libmedia-service.spec index 646b79e..30dae57 100755 --- a/packaging/libmedia-service.spec +++ b/packaging/libmedia-service.spec @@ -1,6 +1,6 @@ Name: libmedia-service Summary: Media information service library for multimedia applications -Version: 0.2.43 +Version: 0.2.44 Release: 3 Group: System/Libraries License: Apache License, Version 2.0 diff --git a/plugin/media-content-plugin.c b/plugin/media-content-plugin.c index 2436b94..f73ed7b 100755 --- a/plugin/media-content-plugin.c +++ b/plugin/media-content-plugin.c @@ -163,9 +163,9 @@ int check_item(const char *file_path, char ** err_msg) return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int connect(void ** handle, char ** err_msg) +int connect(void ** handle, uid_t uid, char ** err_msg) { - int ret = media_svc_connect(handle); + int ret = media_svc_connect(handle,uid); if(ret < 0) { __set_error_message(ret, err_msg); @@ -239,7 +239,7 @@ int insert_item_begin(void * handle, int item_cnt, int with_noti, int from_pid, return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int insert_item_end(void * handle, char ** err_msg) +int insert_item_end(void * handle, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -248,7 +248,7 @@ int insert_item_end(void * handle, char ** err_msg) return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_insert_item_end(handle); + ret = media_svc_insert_item_end(handle, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -257,7 +257,7 @@ int insert_item_end(void * handle, char ** err_msg) return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int insert_item(void * handle, const char *file_path, int storage_type, char ** err_msg) +int insert_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -276,7 +276,7 @@ int insert_item(void * handle, const char *file_path, int storage_type, char ** return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_insert_item_bulk(handle, storage_type, file_path, FALSE); + ret = media_svc_insert_item_bulk(handle, storage_type, file_path, FALSE, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -285,7 +285,7 @@ int insert_item(void * handle, const char *file_path, int storage_type, char ** return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int insert_item_immediately(void * handle, const char *file_path, int storage_type, char ** err_msg) +int insert_item_immediately(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -304,7 +304,7 @@ int insert_item_immediately(void * handle, const char *file_path, int storage_ty return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_insert_item_immediately(handle, storage_type, file_path); + ret = media_svc_insert_item_immediately(handle, storage_type, file_path, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -313,7 +313,7 @@ int insert_item_immediately(void * handle, const char *file_path, int storage_ty return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int insert_burst_item(void * handle, const char *file_path, int storage_type, char ** err_msg) +int insert_burst_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -332,7 +332,7 @@ int insert_burst_item(void * handle, const char *file_path, int storage_type, ch return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_insert_item_bulk(handle, storage_type, file_path, TRUE); + ret = media_svc_insert_item_bulk(handle, storage_type, file_path, TRUE, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -359,7 +359,7 @@ int move_item_begin(void * handle, int item_cnt, char ** err_msg) return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int move_item_end(void * handle, char ** err_msg) +int move_item_end(void * handle, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -368,7 +368,7 @@ int move_item_end(void * handle, char ** err_msg) return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_move_item_end(handle); + ret = media_svc_move_item_end(handle, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -377,7 +377,7 @@ int move_item_end(void * handle, char ** err_msg) return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int move_item(void * handle, const char *src_path, int src_storage_type, const char *dest_path, int dest_storage_type, char ** err_msg) +int move_item(void * handle, const char *src_path, int src_storage_type, const char *dest_path, int dest_storage_type, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -396,7 +396,7 @@ int move_item(void * handle, const char *src_path, int src_storage_type, const c return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_move_item(handle, src_storage_type, src_path, dest_storage_type, dest_path); + ret = media_svc_move_item(handle, src_storage_type, src_path, dest_storage_type, dest_path, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -405,7 +405,7 @@ int move_item(void * handle, const char *src_path, int src_storage_type, const c return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int set_all_storage_items_validity(void * handle, int storage_type, int validity, char ** err_msg) +int set_all_storage_items_validity(void * handle, int storage_type, int validity, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -419,7 +419,7 @@ int set_all_storage_items_validity(void * handle, int storage_type, int validity return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_set_all_storage_items_validity(handle, storage_type, validity); + ret = media_svc_set_all_storage_items_validity(handle, storage_type, validity, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -428,7 +428,7 @@ int set_all_storage_items_validity(void * handle, int storage_type, int validity return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int set_folder_item_validity(void * handle, const char * folder_path, int validity, int recursive, char ** err_msg) +int set_folder_item_validity(void * handle, const char * folder_path, int validity, int recursive, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -442,7 +442,7 @@ int set_folder_item_validity(void * handle, const char * folder_path, int validi return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_set_folder_items_validity(handle, folder_path, validity, recursive); + ret = media_svc_set_folder_items_validity(handle, folder_path, validity, recursive, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -469,7 +469,7 @@ int set_item_validity_begin(void * handle, int item_cnt, char ** err_msg) return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int set_item_validity_end(void * handle, char ** err_msg) +int set_item_validity_end(void * handle, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -478,7 +478,7 @@ int set_item_validity_end(void * handle, char ** err_msg) return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_set_item_validity_end(handle); + ret = media_svc_set_item_validity_end(handle, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -487,7 +487,7 @@ int set_item_validity_end(void * handle, char ** err_msg) return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int set_item_validity(void * handle, const char *file_path, int storage_type, int validity, char ** err_msg) +int set_item_validity(void * handle, const char *file_path, int storage_type, int validity, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -506,7 +506,7 @@ int set_item_validity(void * handle, const char *file_path, int storage_type, in return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_set_item_validity(handle, file_path, validity); + ret = media_svc_set_item_validity(handle, file_path, validity, uid); if(ret < 0) { __set_error_message(ret, err_msg); @@ -516,7 +516,7 @@ int set_item_validity(void * handle, const char *file_path, int storage_type, in return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int delete_item(void * handle, const char *file_path, int storage_type, char ** err_msg) +int delete_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -537,7 +537,7 @@ int delete_item(void * handle, const char *file_path, int storage_type, char ** ret = media_svc_check_item_exist_by_path(handle, file_path); if(ret == 0) { - ret = media_svc_delete_item_by_path(handle, file_path); + ret = media_svc_delete_item_by_path(handle, file_path, uid); if(ret < 0) { __set_error_message(ret, err_msg); @@ -551,7 +551,7 @@ int delete_item(void * handle, const char *file_path, int storage_type, char ** return MEDIA_SVC_PLUGIN_ERROR; } -int delete_all_items_in_storage(void * handle, int storage_type, char ** err_msg) +int delete_all_items_in_storage(void * handle, int storage_type, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -565,7 +565,7 @@ int delete_all_items_in_storage(void * handle, int storage_type, char ** err_msg return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_delete_all_items_in_storage(handle, storage_type); + ret = media_svc_delete_all_items_in_storage(handle, storage_type, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -574,7 +574,7 @@ int delete_all_items_in_storage(void * handle, int storage_type, char ** err_msg return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int delete_all_invalid_items_in_storage(void * handle, int storage_type, char ** err_msg) +int delete_all_invalid_items_in_storage(void * handle, int storage_type, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -588,7 +588,7 @@ int delete_all_invalid_items_in_storage(void * handle, int storage_type, char ** return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_delete_invalid_items_in_storage(handle, storage_type); + ret = media_svc_delete_invalid_items_in_storage(handle, storage_type, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -597,7 +597,7 @@ int delete_all_invalid_items_in_storage(void * handle, int storage_type, char ** return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int delete_all_invalid_items_in_folder(void * handle, const char *folder_path, char ** err_msg) +int delete_all_invalid_items_in_folder(void * handle, const char *folder_path, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -611,7 +611,7 @@ int delete_all_invalid_items_in_folder(void * handle, const char *folder_path, c return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_delete_invalid_items_in_folder(handle, folder_path); + ret = media_svc_delete_invalid_items_in_folder(handle, folder_path, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -620,7 +620,7 @@ int delete_all_invalid_items_in_folder(void * handle, const char *folder_path, c return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int delete_all_items(void * handle, char ** err_msg) +int delete_all_items(void * handle, uid_t uid ,char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -629,18 +629,18 @@ int delete_all_items(void * handle, char ** err_msg) return MEDIA_SVC_PLUGIN_ERROR; } - ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_INTERNAL, err_msg); + ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_INTERNAL, uid, err_msg); if(ret < 0) return MEDIA_SVC_PLUGIN_ERROR; - ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_EXTERNAL, err_msg); + ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_EXTERNAL, uid, err_msg); if(ret < 0) return MEDIA_SVC_PLUGIN_ERROR; return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int refresh_item(void * handle, const char *file_path, int storage_type, char ** err_msg) +int refresh_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; @@ -659,7 +659,7 @@ int refresh_item(void * handle, const char *file_path, int storage_type, char ** return MEDIA_SVC_PLUGIN_ERROR; } - ret = media_svc_refresh_item(handle, storage_type, file_path); + ret = media_svc_refresh_item(handle, storage_type, file_path, uid); if(ret < 0) { __set_error_message(ret, err_msg); return MEDIA_SVC_PLUGIN_ERROR; @@ -673,11 +673,11 @@ int update_begin(void) return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int update_end(void) +int update_end(uid_t uid) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; - ret = thumbnail_request_extract_all_thumbs(); + ret = thumbnail_request_extract_all_thumbs(uid); if (ret < 0) { return MEDIA_SVC_PLUGIN_ERROR; } diff --git a/src/common/media-svc-album.c b/src/common/media-svc-album.c index 169bea4..fb34d49 100755 --- a/src/common/media-svc-album.c +++ b/src/common/media-svc-album.c @@ -97,13 +97,13 @@ int _media_svc_get_album_art_by_album_id(sqlite3 *handle, int album_id, char **a return MEDIA_INFO_ERROR_NONE; } -int _media_svc_append_album(sqlite3 *handle, const char *album, const char *artist, const char *album_art, int * album_id) +int _media_svc_append_album(sqlite3 *handle, const char *album, const char *artist, const char *album_art, int * album_id, uid_t uid) { int err = -1; char *sql = sqlite3_mprintf("INSERT INTO %s (name, artist, album_art, album_art) values (%Q, %Q, %Q, %Q); ", MEDIA_SVC_DB_TABLE_ALBUM, album, artist, album_art, album_art); - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("failed to insert albums"); diff --git a/src/common/media-svc-db-utils.c b/src/common/media-svc-db-utils.c index 63a0494..5f31896 100755 --- a/src/common/media-svc-db-utils.c +++ b/src/common/media-svc-db-utils.c @@ -96,7 +96,7 @@ int _media_svc_disconnect_db_with_handle(sqlite3 *db_handle) return MEDIA_INFO_ERROR_NONE; } -int _media_svc_create_media_table(sqlite3 *db_handle) +int _media_svc_create_media_table(sqlite3 *db_handle, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; char * sql = NULL; @@ -158,7 +158,7 @@ int _media_svc_create_media_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create db table (%d)", ret); @@ -178,7 +178,7 @@ int _media_svc_create_media_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create db table (%d)", ret); @@ -188,7 +188,7 @@ int _media_svc_create_media_table(sqlite3 *db_handle) return MEDIA_INFO_ERROR_NONE; } -int _media_svc_create_folder_table(sqlite3 *db_handle) +int _media_svc_create_folder_table(sqlite3 *db_handle, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; char * sql = NULL; @@ -207,7 +207,7 @@ int _media_svc_create_folder_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create db table (%d)", ret); @@ -222,7 +222,7 @@ int _media_svc_create_folder_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create trigger (%d)", ret); @@ -232,7 +232,7 @@ int _media_svc_create_folder_table(sqlite3 *db_handle) return MEDIA_INFO_ERROR_NONE; } -int _media_svc_create_playlist_table(sqlite3 *db_handle) +int _media_svc_create_playlist_table(sqlite3 *db_handle, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; char * sql = NULL; @@ -249,7 +249,7 @@ int _media_svc_create_playlist_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create db table (%d)", ret); @@ -267,7 +267,7 @@ int _media_svc_create_playlist_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create db table (%d)", ret); @@ -281,7 +281,7 @@ int _media_svc_create_playlist_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create trigger (%d)", ret); @@ -295,7 +295,7 @@ int _media_svc_create_playlist_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create trigger (%d)", ret); @@ -305,7 +305,7 @@ int _media_svc_create_playlist_table(sqlite3 *db_handle) return MEDIA_INFO_ERROR_NONE; } -int _media_svc_create_album_table(sqlite3 *db_handle) +int _media_svc_create_album_table(sqlite3 *db_handle, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; char * sql = NULL; @@ -323,7 +323,7 @@ int _media_svc_create_album_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create db table (%d)", ret); @@ -338,7 +338,7 @@ int _media_svc_create_album_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create trigger (%d)", ret); @@ -348,7 +348,7 @@ int _media_svc_create_album_table(sqlite3 *db_handle) return MEDIA_INFO_ERROR_NONE; } -int _media_svc_create_tag_table(sqlite3 *db_handle) +int _media_svc_create_tag_table(sqlite3 *db_handle, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; char * sql = NULL; @@ -364,7 +364,7 @@ int _media_svc_create_tag_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create db table (%d)", ret); @@ -382,7 +382,7 @@ int _media_svc_create_tag_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create db table (%d)", ret); @@ -396,7 +396,7 @@ int _media_svc_create_tag_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create trigger (%d)", ret); @@ -410,7 +410,7 @@ int _media_svc_create_tag_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create trigger (%d)", ret); @@ -419,7 +419,7 @@ int _media_svc_create_tag_table(sqlite3 *db_handle) return MEDIA_INFO_ERROR_NONE; } -int _media_svc_create_bookmark_table(sqlite3 *db_handle) +int _media_svc_create_bookmark_table(sqlite3 *db_handle, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; char * sql = NULL; @@ -437,7 +437,7 @@ int _media_svc_create_bookmark_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create db table (%d)", ret); @@ -451,7 +451,7 @@ int _media_svc_create_bookmark_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create trigger (%d)", ret); @@ -461,7 +461,7 @@ int _media_svc_create_bookmark_table(sqlite3 *db_handle) return MEDIA_INFO_ERROR_NONE; } -int _media_svc_create_custom_table(sqlite3 *db_handle) +int _media_svc_create_custom_table(sqlite3 *db_handle, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; char * sql = NULL; @@ -483,7 +483,7 @@ int _media_svc_create_custom_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create db table (%d)", ret); @@ -497,7 +497,7 @@ int _media_svc_create_custom_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create trigger (%d)", ret); @@ -511,7 +511,7 @@ int _media_svc_create_custom_table(sqlite3 *db_handle) media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY); - ret = _media_svc_sql_query(db_handle, sql); + ret = _media_svc_sql_query(db_handle, sql, uid); sqlite3_free(sql); if (ret != SQLITE_OK) { media_svc_error("It failed to create db table (%d)", ret); @@ -521,23 +521,23 @@ int _media_svc_create_custom_table(sqlite3 *db_handle) return MEDIA_INFO_ERROR_NONE; } -int _media_svc_request_update_db(const char *sql_str) +int _media_svc_request_update_db(const char *sql_str, uid_t uid) { int ret = MS_MEDIA_ERR_NONE; - ret = media_db_request_update_db(sql_str); + ret = media_db_request_update_db(sql_str, uid); return ret; } -int _media_svc_sql_query(sqlite3 *db_handle, const char *sql_str) +int _media_svc_sql_query(sqlite3 *db_handle, const char *sql_str, uid_t uid) { int err = -1; media_svc_debug("[SQL query] : %s", sql_str); #if 1 //DB will be updated by Media Server. - err = _media_svc_request_update_db(sql_str); + err = _media_svc_request_update_db(sql_str, uid); return _media_svc_error_convert(err); #else @@ -582,14 +582,14 @@ int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3 return MEDIA_INFO_ERROR_NONE; } -int _media_svc_sql_begin_trans(sqlite3 *handle) +int _media_svc_sql_begin_trans(sqlite3 *handle, uid_t uid) { int err = MEDIA_INFO_ERROR_NONE; media_svc_debug("========_media_svc_sql_begin_trans"); #if 1 //err = _media_svc_request_update_db("BEGIN IMMEDIATE;"); - err = media_db_request_update_db_batch_start("BEGIN IMMEDIATE;"); + err = media_db_request_update_db_batch_start("BEGIN IMMEDIATE;", uid); return _media_svc_error_convert(err); #else @@ -606,13 +606,13 @@ int _media_svc_sql_begin_trans(sqlite3 *handle) #endif } -int _media_svc_sql_end_trans(sqlite3 *handle) +int _media_svc_sql_end_trans(sqlite3 *handle, uid_t uid) { int err = MEDIA_INFO_ERROR_NONE; media_svc_debug("========_media_svc_sql_end_trans"); #if 1 - err = media_db_request_update_db_batch_end("COMMIT;"); + err = media_db_request_update_db_batch_end("COMMIT;", uid); //err = _media_svc_request_update_db("COMMIT;"); return _media_svc_error_convert(err); #else @@ -628,13 +628,13 @@ int _media_svc_sql_end_trans(sqlite3 *handle) #endif } -int _media_svc_sql_rollback_trans(sqlite3 *handle) +int _media_svc_sql_rollback_trans(sqlite3 *handle, uid_t uid) { int err = MEDIA_INFO_ERROR_NONE; media_svc_debug("========_media_svc_sql_rollback_trans"); #if 1 - err = _media_svc_request_update_db("ROLLBACK;"); + err = _media_svc_request_update_db("ROLLBACK;", uid); return _media_svc_error_convert(err); #else char *err_msg = NULL; @@ -649,7 +649,7 @@ int _media_svc_sql_rollback_trans(sqlite3 *handle) #endif } -int _media_svc_sql_query_list(sqlite3 *handle, GList **query_list) +int _media_svc_sql_query_list(sqlite3 *handle, GList **query_list, uid_t uid) { int i = 0; int length = g_list_length(*query_list); @@ -662,7 +662,7 @@ int _media_svc_sql_query_list(sqlite3 *handle, GList **query_list) sql = (char*)g_list_nth_data(*query_list, i); if(sql != NULL) { //err = _media_svc_sql_query(handle, sql); - err = media_db_request_update_db_batch(sql); + err = media_db_request_update_db_batch(sql, uid); //if (err != SQLITE_OK) { // media_svc_error("A query failed in batch"); if (err < MS_MEDIA_ERR_NONE) { diff --git a/src/common/media-svc-media-folder.c b/src/common/media-svc-media-folder.c index 2a1678a..b09506f 100755 --- a/src/common/media-svc-media-folder.c +++ b/src/common/media-svc-media-folder.c @@ -56,13 +56,13 @@ int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *folder_n } int _media_svc_append_folder(sqlite3 *handle, media_svc_storage_type_e storage_type, - const char *folder_id, const char *path_name, const char *folder_name, int modified_date) + const char *folder_id, const char *path_name, const char *folder_name, int modified_date, uid_t uid) { int err = -1; char *sql = sqlite3_mprintf("INSERT INTO %s (folder_uuid, path, name, storage_type, modified_time) values (%Q, %Q, %Q, '%d', '%d'); ", MEDIA_SVC_DB_TABLE_FOLDER, folder_id, path_name, folder_name, storage_type, modified_date); - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("failed to insert folder"); @@ -72,7 +72,7 @@ int _media_svc_append_folder(sqlite3 *handle, media_svc_storage_type_e storage_t return MEDIA_INFO_ERROR_NONE; } -int _media_svc_update_folder_modified_time_by_folder_uuid(sqlite3 *handle, const char *folder_uuid, const char *folder_path, bool stack_query) +int _media_svc_update_folder_modified_time_by_folder_uuid(sqlite3 *handle, const char *folder_uuid, const char *folder_path, bool stack_query, uid_t uid) { int err = -1; int modified_time = 0; @@ -82,7 +82,7 @@ int _media_svc_update_folder_modified_time_by_folder_uuid(sqlite3 *handle, const char *sql = sqlite3_mprintf("UPDATE %s SET modified_time=%d WHERE folder_uuid=%Q;", MEDIA_SVC_DB_TABLE_FOLDER, modified_time, folder_uuid); if(!stack_query) { - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("failed to update folder"); @@ -95,7 +95,7 @@ int _media_svc_update_folder_modified_time_by_folder_uuid(sqlite3 *handle, const return MEDIA_INFO_ERROR_NONE; } -int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *path, media_svc_storage_type_e storage_type, char *folder_id) +int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *path, media_svc_storage_type_e storage_type, char *folder_id, uid_t uid) { char *path_name = NULL; int ret = MEDIA_INFO_ERROR_NONE; @@ -117,7 +117,7 @@ int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *pat folder_name = g_path_get_basename(path_name); folder_modified_date = _media_svc_get_file_time(path_name); - ret = _media_svc_append_folder(handle, storage_type, folder_uuid, path_name, folder_name, folder_modified_date); + ret = _media_svc_append_folder(handle, storage_type, folder_uuid, path_name, folder_name, folder_modified_date, uid); SAFE_FREE(folder_name); _strncpy_safe(folder_id, folder_uuid, MEDIA_SVC_UUID_SIZE+1); } @@ -127,7 +127,7 @@ int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *pat return ret; } -int _media_svc_update_folder_table(sqlite3 *handle) +int _media_svc_update_folder_table(sqlite3 *handle, uid_t uid) { int err = -1; char *sql = NULL; @@ -135,7 +135,7 @@ int _media_svc_update_folder_table(sqlite3 *handle) sql = sqlite3_mprintf("DELETE FROM %s WHERE folder_uuid IN (SELECT folder_uuid FROM %s WHERE folder_uuid NOT IN (SELECT folder_uuid FROM %s))", MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_TABLE_MEDIA); - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("failed to delete folder item"); diff --git a/src/common/media-svc-media.c b/src/common/media-svc-media.c index 12c79f1..7aa7a82 100755 --- a/src/common/media-svc-media.c +++ b/src/common/media-svc-media.c @@ -20,6 +20,8 @@ */ #include +#include +#include #include "media-svc-media.h" #include "media-svc-media-folder.h" #include "media-svc-error.h" @@ -28,6 +30,8 @@ #include "media-svc-db-utils.h" #include "media-svc-noti.h" +#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO + typedef struct{ char thumbnail_path[MEDIA_SVC_PATHNAME_SIZE]; }media_svc_thumbnailpath_s; @@ -164,7 +168,43 @@ int _media_svc_count_record_with_path(sqlite3 *handle, const char *path, int *co return MEDIA_INFO_ERROR_NONE; } -int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, int is_burst, bool stack_query) +char* _media_svc_get_thumb_default_path(uid_t uid) +{ + char *result_psswd = NULL; + struct group *grpinfo = NULL; + if(uid == getuid()) + { + result_psswd = strdup(MEDIA_SVC_THUMB_DEFAULT_PATH); + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + media_svc_error("getgrnam(users) returns NULL !"); + return NULL; + } + } + else + { + struct passwd *userinfo = getpwuid(uid); + if(userinfo == NULL) { + media_svc_error("getpwuid(%d) returns NULL !", uid); + return NULL; + } + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + media_svc_error("getgrnam(users) returns NULL !"); + return NULL; + } + // Compare git_t type and not group name + if (grpinfo->gr_gid != userinfo->pw_gid) { + media_svc_error("UID [%d] does not belong to 'users' group!", uid); + return NULL; + } + asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/thumb_default.png", userinfo->pw_dir); + } + + return result_psswd; +} + +int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid) { media_svc_debug(""); int err = -1; @@ -197,7 +237,7 @@ int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s * int width = 0; int height = 0; - err = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height); + err = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height, uid); if (err < 0) { media_svc_error("thumbnail_request_from_db failed: %d", err); } else { @@ -261,7 +301,7 @@ int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s * burst_id = NULL; if(!stack_query) { - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("failed to insert item"); @@ -276,7 +316,7 @@ int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s * return MEDIA_INFO_ERROR_NONE; } -int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info) +int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid) { int err = -1; @@ -319,7 +359,7 @@ int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s * content_info->path ); - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("failed to update item"); @@ -376,12 +416,12 @@ int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *path, int *me return MEDIA_INFO_ERROR_NONE; } -int _media_svc_delete_item_by_path(sqlite3 *handle, const char *path) +int _media_svc_delete_item_by_path(sqlite3 *handle, const char *path, uid_t uid) { int err = -1; char *sql = sqlite3_mprintf("DELETE FROM %s WHERE validity=1 AND path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path); - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("It failed to delete item (%d)", err); @@ -391,12 +431,12 @@ int _media_svc_delete_item_by_path(sqlite3 *handle, const char *path) return MEDIA_INFO_ERROR_NONE; } -int _media_svc_truncate_table(sqlite3 *handle, media_svc_storage_type_e storage_type) +int _media_svc_truncate_table(sqlite3 *handle, media_svc_storage_type_e storage_type, uid_t uid) { int err = -1; char *sql = sqlite3_mprintf("DELETE FROM %s WHERE storage_type=%d", MEDIA_SVC_DB_TABLE_MEDIA, storage_type); - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("It failed to truncate table (%d)", err); @@ -407,7 +447,7 @@ int _media_svc_truncate_table(sqlite3 *handle, media_svc_storage_type_e storage_ } -int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e storage_type) +int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e storage_type, uid_t uid) { int idx = 0; media_svc_thumbnailpath_s *thumbpath_record = NULL; @@ -438,7 +478,7 @@ int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e st } char *sql = sqlite3_mprintf("DELETE FROM %s WHERE validity = 0 AND storage_type=%d", MEDIA_SVC_DB_TABLE_MEDIA, storage_type); - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("To delete invalid items is failed(%d)", err); @@ -448,7 +488,7 @@ int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e st /*Delete thumbnails*/ for (idx = 0; idx < invalid_count; idx++) { - if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) { + if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) { if (_media_svc_remove_file(thumbpath_record[idx].thumbnail_path) == FALSE) { media_svc_error("fail to remove thumbnail file."); //SAFE_FREE(thumbpath_record); @@ -462,7 +502,7 @@ int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e st return MEDIA_INFO_ERROR_NONE; } -int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *folder_path) +int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *folder_path, uid_t uid) { int idx = 0; media_svc_thumbnailpath_s *thumbpath_record = NULL; @@ -493,7 +533,7 @@ int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *folder_p } char *sql = sqlite3_mprintf("DELETE FROM %s WHERE validity = 0 AND path LIKE '%q/%%'", MEDIA_SVC_DB_TABLE_MEDIA, folder_path); - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("To delete invalid items is failed(%d)", err); @@ -503,7 +543,7 @@ int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *folder_p /*Delete thumbnails*/ for (idx = 0; idx < invalid_count; idx++) { - if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) { + if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) { if (_media_svc_remove_file(thumbpath_record[idx].thumbnail_path) == FALSE) { media_svc_error("fail to remove thumbnail file [%s].", thumbpath_record[idx].thumbnail_path); //SAFE_FREE(thumbpath_record); @@ -518,14 +558,14 @@ int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *folder_p } -int _media_svc_update_item_validity(sqlite3 *handle, const char *path, int validity, bool stack_query) +int _media_svc_update_item_validity(sqlite3 *handle, const char *path, int validity, bool stack_query, uid_t uid) { int err = -1; char *sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE path= '%q'", MEDIA_SVC_DB_TABLE_MEDIA, validity, path); if(!stack_query) { - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("To update item as valid is failed(%d)", err); @@ -538,13 +578,13 @@ int _media_svc_update_item_validity(sqlite3 *handle, const char *path, int valid return MEDIA_INFO_ERROR_NONE; } -int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *path, const char *thumb_path) +int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *path, const char *thumb_path, uid_t uid) { int err = -1; char *sql = sqlite3_mprintf("UPDATE %s SET thumbnail_path=%Q WHERE path= %Q", MEDIA_SVC_DB_TABLE_MEDIA, thumb_path, path); - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("To update thumb path failed(%d)", err); @@ -554,11 +594,11 @@ int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *path, const ch return MEDIA_INFO_ERROR_NONE; } -int _media_svc_update_storage_item_validity(sqlite3 *handle, media_svc_storage_type_e storage_type, int validity) +int _media_svc_update_storage_item_validity(sqlite3 *handle, media_svc_storage_type_e storage_type, int validity, uid_t uid) { int err = -1; char *sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE storage_type=%d", MEDIA_SVC_DB_TABLE_MEDIA, validity, storage_type); - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("To update item as valid is failed(%d)", err); @@ -568,7 +608,7 @@ int _media_svc_update_storage_item_validity(sqlite3 *handle, media_svc_storage_t return MEDIA_INFO_ERROR_NONE; } -int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity) +int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity, uid_t uid) { int err = -1; int ret = MEDIA_INFO_ERROR_NONE; @@ -589,7 +629,7 @@ int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *folder_p /*Update folder item validity*/ sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE folder_uuid='%q'", MEDIA_SVC_DB_TABLE_MEDIA, validity, folder_uuid); - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("To update folder item as valid is failed(%d)", err); @@ -599,13 +639,13 @@ int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *folder_p return MEDIA_INFO_ERROR_NONE; } -int _media_svc_update_recursive_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity) +int _media_svc_update_recursive_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity, uid_t uid) { int err = -1; /*Update folder item validity*/ char *sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE path LIKE '%q/%%'", MEDIA_SVC_DB_TABLE_MEDIA, validity, folder_path); - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("To update recursive folder item validity is failed(%d)", err); @@ -616,7 +656,7 @@ int _media_svc_update_recursive_folder_item_validity(sqlite3 *handle, const char } int _media_svc_update_item_by_path(sqlite3 *handle, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path, - const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query) + const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query, uid_t uid) { /* update path, filename, modified_time, folder_uuid, thumbnail_path, */ /* played_count, last_played_time, last_played_position, favourite, storaget_type*/ @@ -639,7 +679,7 @@ int _media_svc_update_item_by_path(sqlite3 *handle, const char *src_path, media_ } if(!stack_query) { - err = _media_svc_sql_query(handle, sql); + err = _media_svc_sql_query(handle, sql, uid); sqlite3_free(sql); if (err != SQLITE_OK) { media_svc_error("It failed to update metadata (%d)", err); @@ -652,32 +692,32 @@ int _media_svc_update_item_by_path(sqlite3 *handle, const char *src_path, media_ return MEDIA_INFO_ERROR_NONE; } -int _media_svc_list_query_do(sqlite3 *handle, media_svc_query_type_e query_type) +int _media_svc_list_query_do(sqlite3 *handle, media_svc_query_type_e query_type, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; - ret = _media_svc_sql_begin_trans(handle); + ret = _media_svc_sql_begin_trans(handle, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); if (query_type == MEDIA_SVC_QUERY_SET_ITEM_VALIDITY) - ret = _media_svc_sql_query_list(handle, &g_media_svc_item_validity_query_list); + ret = _media_svc_sql_query_list(handle, &g_media_svc_item_validity_query_list,uid); else if (query_type == MEDIA_SVC_QUERY_MOVE_ITEM) - ret = _media_svc_sql_query_list(handle, &g_media_svc_move_item_query_list); + ret = _media_svc_sql_query_list(handle, &g_media_svc_move_item_query_list, uid); else if (query_type == MEDIA_SVC_QUERY_INSERT_ITEM) - ret = _media_svc_sql_query_list(handle, &g_media_svc_insert_item_query_list); + ret = _media_svc_sql_query_list(handle, &g_media_svc_insert_item_query_list, uid); else ret = MEDIA_INFO_ERROR_INVALID_PARAMETER; if (ret != MEDIA_INFO_ERROR_NONE) { media_svc_error("_media_svc_list_query_do failed. start rollback"); - _media_svc_sql_rollback_trans(handle); + _media_svc_sql_rollback_trans(handle,uid); return ret; } - ret = _media_svc_sql_end_trans(handle); + ret = _media_svc_sql_end_trans(handle, uid); if (ret != MEDIA_INFO_ERROR_NONE) { media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback\n"); - _media_svc_sql_rollback_trans(handle); + _media_svc_sql_rollback_trans(handle,uid); return ret; } diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c index 2fb6fe0..dae3ffc 100755 --- a/src/common/media-svc-util.c +++ b/src/common/media-svc-util.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include "uuid.h" #include "media-svc-util.h" #include "media-svc-error.h" @@ -46,6 +48,7 @@ #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/ +#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO typedef enum { MEDIA_SVC_EXTRACTED_FIELD_NONE = 0x00000001, @@ -422,7 +425,139 @@ char *_media_svc_get_title_from_filepath (const char *path) return title; } -int _media_svc_save_image(void *image, int size, char *image_path) +static int _mkdir(const char *dir, mode_t mode) { + char tmp[256]; + char *p = NULL; + size_t len; + + snprintf(tmp, sizeof(tmp),"%s",dir); + len = strlen(tmp); + if(tmp[len - 1] == '/') + tmp[len - 1] = 0; + for(p = tmp + 1; *p; p++) + if(*p == '/') { + *p = 0; + mkdir(tmp, mode); + *p = '/'; + } + return mkdir(tmp, mode); +} + +static char* _media_svc_get_thumb_path(uid_t uid) +{ + char *result_psswd = NULL; + struct group *grpinfo = NULL; + if(uid == getuid()) + { + result_psswd = strdup(MEDIA_SVC_THUMB_PATH_PREFIX); + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + media_svc_error("getgrnam(users) returns NULL !"); + return NULL; + } + } + else + { + struct passwd *userinfo = getpwuid(uid); + if(userinfo == NULL) { + media_svc_error("getpwuid(%d) returns NULL !", uid); + return NULL; + } + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + media_svc_error("getgrnam(users) returns NULL !"); + return NULL; + } + // Compare git_t type and not group name + if (grpinfo->gr_gid != userinfo->pw_gid) { + media_svc_error("UID [%d] does not belong to 'users' group!", uid); + return NULL; + } + asprintf(&result_psswd, "%s/data/file-manager-service/.thumb", userinfo->pw_dir); + } + + _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO); + + return result_psswd; +} + +char* _media_svc_get_thumb_internal_path(uid_t uid) +{ + char *result_psswd = NULL; + struct group *grpinfo = NULL; + if(uid == getuid()) + { + result_psswd = strdup(MEDIA_SVC_THUMB_INTERNAL_PATH); + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + media_svc_error("getgrnam(users) returns NULL !"); + return NULL; + } + } + else + { + struct passwd *userinfo = getpwuid(uid); + if(userinfo == NULL) { + media_svc_error("getpwuid(%d) returns NULL !", uid); + return NULL; + } + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + media_svc_error("getgrnam(users) returns NULL !"); + return NULL; + } + // Compare git_t type and not group name + if (grpinfo->gr_gid != userinfo->pw_gid) { + media_svc_error("UID [%d] does not belong to 'users' group!", uid); + return NULL; + } + asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir); + } + + mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO); + + return result_psswd; +} + +char* _media_svc_get_thumb_external_path(uid_t uid) +{ + char *result_psswd = NULL; + struct group *grpinfo = NULL; + if(uid == getuid()) + { + result_psswd = strdup(MEDIA_SVC_THUMB_EXTERNAL_PATH); + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + media_svc_error("getgrnam(users) returns NULL !"); + return NULL; + } + } + else + { + struct passwd *userinfo = getpwuid(uid); + if(userinfo == NULL) { + media_svc_error("getpwuid(%d) returns NULL !", uid); + return NULL; + } + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + media_svc_error("getgrnam(users) returns NULL !"); + return NULL; + } + // Compare git_t type and not group name + if (grpinfo->gr_gid != userinfo->pw_gid) { + media_svc_error("UID [%d] does not belong to 'users' group!", uid); + return NULL; + } + asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/mmc", userinfo->pw_dir); + } + + _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO); + + return result_psswd; +} + +int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid) { media_svc_debug("start save image, path [%s] image size [%d]", image_path, size); @@ -432,7 +567,7 @@ int _media_svc_save_image(void *image, int size, char *image_path) } struct statfs fs; - if (-1 == statfs(MEDIA_SVC_THUMB_PATH_PREFIX, &fs)) { + if (-1 == statfs(_media_svc_get_thumb_path(uid), &fs)) { media_svc_error("error in statfs"); return MEDIA_INFO_ERROR_INTERNAL; } @@ -466,7 +601,8 @@ int _media_svc_save_image(void *image, int size, char *image_path) return MEDIA_INFO_ERROR_NONE; } -bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format) + +bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid) { char savename[MEDIA_SVC_PATHNAME_SIZE] = {0}; char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0}; @@ -474,7 +610,7 @@ bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char * char hash[255 + 1]; char *thumbfile_ext = NULL; - thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? MEDIA_SVC_THUMB_INTERNAL_PATH : MEDIA_SVC_THUMB_EXTERNAL_PATH; + thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? _media_svc_get_thumb_internal_path(uid) : _media_svc_get_thumb_external_path(uid); memset(file_ext, 0, sizeof(file_ext)); if (!_media_svc_get_file_ext(pathname, file_ext)) { @@ -844,7 +980,7 @@ int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, me return MEDIA_INFO_ERROR_NONE; } -int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, drm_content_info_s *drm_contentInfo) +int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, drm_content_info_s *drm_contentInfo, uid_t uid) { MMHandleType content = 0; MMHandleType tag = 0; @@ -1271,7 +1407,7 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL); if ((mmf_error == MM_ERROR_NONE) && (artwork_mime_size > 0)) { - result = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p); + result = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid); if (result == FALSE) { media_svc_error("Fail to Get Thumbnail Path"); } @@ -1281,7 +1417,7 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s if(strlen(thumb_path) > 0) { - ret = _media_svc_save_image(image, size, thumb_path); + ret = _media_svc_save_image(image, size, thumb_path, uid); if (ret != MEDIA_INFO_ERROR_NONE) { media_svc_error("Fail to Save Thumbnail Image"); } @@ -1298,9 +1434,9 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s if((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) && (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) - ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id); + ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid); else - ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id); + ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid); content_info->album_id = album_id; } diff --git a/src/common/media-svc.c b/src/common/media-svc.c index f211f1c..7419908 100755 --- a/src/common/media-svc.c +++ b/src/common/media-svc.c @@ -43,7 +43,7 @@ static __thread int g_media_svc_insert_item_cur_data_cnt = 0; /* Flag for items to be published by notification */ static __thread int g_insert_with_noti = FALSE; -int media_svc_connect(MediaSvcHandle **handle) +int media_svc_connect(MediaSvcHandle **handle, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; MediaDBHandle *db_handle = NULL; @@ -51,7 +51,7 @@ int media_svc_connect(MediaSvcHandle **handle) media_svc_debug_func(); #if 1 //Use libmedia_utils API - ret = media_db_connect(&db_handle); + ret = media_db_connect(&db_handle,uid); if(ret != MS_MEDIA_ERR_NONE) return _media_svc_error_convert(ret); @@ -87,7 +87,7 @@ int media_svc_disconnect(MediaSvcHandle *handle) #endif } -int media_svc_create_table(MediaSvcHandle *handle) +int media_svc_create_table(MediaSvcHandle *handle, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; sqlite3 * db_handle = (sqlite3 *)handle; @@ -97,32 +97,32 @@ int media_svc_create_table(MediaSvcHandle *handle) media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL"); /*create media table*/ - ret = _media_svc_create_media_table(handle); + ret = _media_svc_create_media_table(handle, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /*create folder table*/ - ret = _media_svc_create_folder_table(handle); + ret = _media_svc_create_folder_table(handle, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /*create playlist table*/ - ret = _media_svc_create_playlist_table(handle); + ret = _media_svc_create_playlist_table(handle, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /* create album table*/ - ret = _media_svc_create_album_table(handle); + ret = _media_svc_create_album_table(handle, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /*create tag table*/ - ret = _media_svc_create_tag_table(handle); + ret = _media_svc_create_tag_table(handle,uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /*create bookmark table*/ - ret = _media_svc_create_bookmark_table(handle); + ret = _media_svc_create_bookmark_table(handle, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); #if 0 /*unify media and custom table*/ /*create custom table*/ - ret = _media_svc_create_custom_table(handle); + ret = _media_svc_create_custom_table(handle, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); #endif @@ -213,7 +213,7 @@ int media_svc_insert_item_begin(MediaSvcHandle *handle, int data_cnt, int with_n return MEDIA_INFO_ERROR_NONE; } -int media_svc_insert_item_end(MediaSvcHandle *handle) +int media_svc_insert_item_end(MediaSvcHandle *handle, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; sqlite3 * db_handle = (sqlite3 *)handle; @@ -224,7 +224,7 @@ int media_svc_insert_item_end(MediaSvcHandle *handle) if (g_media_svc_insert_item_cur_data_cnt > 0) { - ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM); + ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM, uid); if (g_insert_with_noti) { media_svc_debug("sending noti list"); _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt); @@ -240,7 +240,7 @@ int media_svc_insert_item_end(MediaSvcHandle *handle) return ret; } -int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, int is_burst) +int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, int is_burst, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; sqlite3 * db_handle = (sqlite3 *)handle; @@ -269,13 +269,13 @@ int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e } else if(media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) { ret = _media_svc_extract_image_metadata(&content_info, media_type); } else { - ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo); + ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo, uid); } SAFE_FREE(drm_contentInfo); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /*Set or Get folder id*/ - ret = _media_svc_get_and_append_folder_id_by_path(handle, path, storage_type, folder_uuid); + ret = _media_svc_get_and_append_folder_id_by_path(handle, path, storage_type, folder_uuid, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid); @@ -283,7 +283,7 @@ int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e if (g_media_svc_insert_item_data_cnt == 1) { - ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, FALSE); + ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, FALSE, uid); media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info); if (g_insert_with_noti) @@ -291,7 +291,7 @@ int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e } else if(g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) { - ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, TRUE); + ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, TRUE, uid); media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info); if (g_insert_with_noti) @@ -301,13 +301,13 @@ int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e } else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) { - ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, TRUE); + ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, TRUE, uid); media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info); if (g_insert_with_noti) _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt); - ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM); + ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM, uid); media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info); if (g_insert_with_noti) { @@ -333,7 +333,7 @@ int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e return MEDIA_INFO_ERROR_NONE; } -int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path) +int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; sqlite3 * db_handle = (sqlite3 *)handle; @@ -362,12 +362,12 @@ int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_ ret = _media_svc_extract_image_metadata(&content_info, media_type); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); } else { - ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo); + ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); } /*Set or Get folder id*/ - ret = _media_svc_get_and_append_folder_id_by_path(handle, path, storage_type, folder_uuid); + ret = _media_svc_get_and_append_folder_id_by_path(handle, path, storage_type, folder_uuid, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid); @@ -379,7 +379,7 @@ int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_ int width = 0; int height = 0; - ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height); + ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid); if (ret < 0) { media_svc_error("thumbnail_request_from_db failed: %d", ret); } else { @@ -397,7 +397,7 @@ int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_ content_info.media_meta.height = height; } #endif - ret = _media_svc_insert_item_with_data(db_handle, &content_info, FALSE, FALSE); + ret = _media_svc_insert_item_with_data(db_handle, &content_info, FALSE, FALSE, uid); if (ret == MEDIA_INFO_ERROR_NONE) { media_svc_debug("Insertion is successful. Sending noti for this"); @@ -408,7 +408,7 @@ int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_ return ret; } -int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path) +int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; sqlite3 * db_handle = (sqlite3 *)handle; @@ -435,7 +435,7 @@ int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e sto folder_name = g_path_get_basename(path); folder_modified_date = _media_svc_get_file_time(path); - ret = _media_svc_append_folder(handle, storage_type, folder_uuid, path, folder_name, folder_modified_date); + ret = _media_svc_append_folder(handle, storage_type, folder_uuid, path, folder_name, folder_modified_date, uid); SAFE_FREE(folder_name); if (ret < MEDIA_INFO_ERROR_NONE) { @@ -461,7 +461,7 @@ int media_svc_move_item_begin(MediaSvcHandle *handle, int data_cnt) return MEDIA_INFO_ERROR_NONE; } -int media_svc_move_item_end(MediaSvcHandle *handle) +int media_svc_move_item_end(MediaSvcHandle *handle, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; sqlite3 * db_handle = (sqlite3 *)handle; @@ -472,11 +472,11 @@ int media_svc_move_item_end(MediaSvcHandle *handle) if (g_media_svc_move_item_cur_data_cnt > 0) { - ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM); + ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM, uid); } /*clean up old folder path*/ - ret = _media_svc_update_folder_table(handle); + ret = _media_svc_update_folder_table(handle, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); g_media_svc_move_item_data_cnt = 1; @@ -486,7 +486,7 @@ int media_svc_move_item_end(MediaSvcHandle *handle) } int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_storage, const char *src_path, - media_svc_storage_type_e dest_storage, const char *dest_path) + media_svc_storage_type_e dest_storage, const char *dest_path, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; sqlite3 * db_handle = (sqlite3 *)handle; @@ -514,7 +514,7 @@ int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_sto } /*check and update folder*/ - ret = _media_svc_get_and_append_folder_id_by_path(handle, dest_path, dest_storage, folder_uuid); + ret = _media_svc_get_and_append_folder_id_by_path(handle, dest_path, dest_storage, folder_uuid, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /*get filename*/ @@ -533,10 +533,10 @@ int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_sto media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret); /* If old thumb path is default or not */ - if (strncmp(old_thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) == 0) { - strncpy(new_thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(new_thumb_path)); + if (strncmp(old_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) == 0) { + strncpy(new_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(new_thumb_path)); } else { - _media_svc_get_thumbnail_path(dest_storage, new_thumb_path, dest_path, THUMB_EXT); + _media_svc_get_thumbnail_path(dest_storage, new_thumb_path, dest_path, THUMB_EXT, uid); } } @@ -544,9 +544,9 @@ int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_sto /*update item*/ if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) { - ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, FALSE); + ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, FALSE, uid); } else { - ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, FALSE); + ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, FALSE, uid); } SAFE_FREE(file_name); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); @@ -564,27 +564,27 @@ int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_sto /*update folder modified_time*/ folder_path = g_path_get_dirname(dest_path); - ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, FALSE); + ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, FALSE, uid); SAFE_FREE(folder_path); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); - ret = _media_svc_update_folder_table(handle); + ret = _media_svc_update_folder_table(handle, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); } else if (g_media_svc_move_item_cur_data_cnt < (g_media_svc_move_item_data_cnt - 1)) { /*update item*/ if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) { - ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE); + ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE, uid); } else { - ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE); + ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid); } SAFE_FREE(file_name); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /*update folder modified_time*/ folder_path = g_path_get_dirname(dest_path); - ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, TRUE); + ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, TRUE, uid); SAFE_FREE(folder_path); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); @@ -594,21 +594,21 @@ int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_sto /*update item*/ if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) { - ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE); + ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE, uid); } else { - ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE); + ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid); } SAFE_FREE(file_name); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /*update folder modified_time*/ folder_path = g_path_get_dirname(dest_path); - ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, TRUE); + ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, TRUE, uid); SAFE_FREE(folder_path); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /*update db*/ - ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM); + ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); g_media_svc_move_item_cur_data_cnt = 0; @@ -620,7 +620,7 @@ int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_sto /*rename thumbnail file*/ if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) { - if((strlen(old_thumb_path) > 0) && (strncmp(old_thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) { + if((strlen(old_thumb_path) > 0) && (strncmp(old_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) { ret = _media_svc_rename_file(old_thumb_path,new_thumb_path); if (ret < 0) media_svc_error("_media_svc_rename_file failed : %d", ret); @@ -645,7 +645,7 @@ int media_svc_set_item_validity_begin(MediaSvcHandle *handle, int data_cnt) return MEDIA_INFO_ERROR_NONE; } -int media_svc_set_item_validity_end(MediaSvcHandle *handle) +int media_svc_set_item_validity_end(MediaSvcHandle *handle, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; sqlite3 * db_handle = (sqlite3 *)handle; @@ -656,7 +656,7 @@ int media_svc_set_item_validity_end(MediaSvcHandle *handle) if (g_media_svc_item_validity_cur_data_cnt > 0) { - ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY); + ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid); } g_media_svc_item_validity_data_cnt = 1; @@ -665,7 +665,7 @@ int media_svc_set_item_validity_end(MediaSvcHandle *handle) return ret; } -int media_svc_set_item_validity(MediaSvcHandle *handle, const char *path, int validity) +int media_svc_set_item_validity(MediaSvcHandle *handle, const char *path, int validity,uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; sqlite3 * db_handle = (sqlite3 *)handle; @@ -677,21 +677,21 @@ int media_svc_set_item_validity(MediaSvcHandle *handle, const char *path, int va if (g_media_svc_item_validity_data_cnt == 1) { - return _media_svc_update_item_validity(db_handle, path, validity, FALSE); + return _media_svc_update_item_validity(db_handle, path, validity, FALSE, uid); } else if (g_media_svc_item_validity_cur_data_cnt < (g_media_svc_item_validity_data_cnt - 1)) { - ret = _media_svc_update_item_validity(db_handle, path, validity, TRUE); + ret = _media_svc_update_item_validity(db_handle, path, validity, TRUE, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); g_media_svc_item_validity_cur_data_cnt ++; } else if (g_media_svc_item_validity_cur_data_cnt == (g_media_svc_item_validity_data_cnt - 1)) { - ret = _media_svc_update_item_validity(db_handle, path, validity, TRUE); + ret = _media_svc_update_item_validity(db_handle, path, validity, TRUE, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); - ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY); + ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); g_media_svc_item_validity_cur_data_cnt = 0; @@ -705,7 +705,7 @@ int media_svc_set_item_validity(MediaSvcHandle *handle, const char *path, int va return MEDIA_INFO_ERROR_NONE; } -int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path) +int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; sqlite3 * db_handle = (sqlite3 *)handle; @@ -742,7 +742,7 @@ int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path) media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /*Delete item*/ - ret = _media_svc_delete_item_by_path(db_handle, path); + ret = _media_svc_delete_item_by_path(db_handle, path, uid); if (ret != MEDIA_INFO_ERROR_NONE) { media_svc_error("_media_svc_delete_item_by_path failed : %d", ret); _media_svc_destroy_noti_item(noti_item); @@ -756,7 +756,7 @@ int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path) _media_svc_destroy_noti_item(noti_item); /*Delete thumbnail*/ - if ((strlen(thumb_path) > 0) && (strncmp(thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) { + if ((strlen(thumb_path) > 0) && (strncmp(thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) { int thumb_count = 1; /* Get count of media, which contains same thumbnail for music */ if ((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) ||(media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) { @@ -776,7 +776,7 @@ int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path) return MEDIA_INFO_ERROR_NONE; } -int media_svc_delete_all_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type) +int media_svc_delete_all_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; sqlite3 * db_handle = (sqlite3 *)handle; @@ -791,10 +791,10 @@ int media_svc_delete_all_items_in_storage(MediaSvcHandle *handle, media_svc_stor return MEDIA_INFO_ERROR_INVALID_PARAMETER; } - ret = _media_svc_truncate_table(db_handle, storage_type); + ret = _media_svc_truncate_table(db_handle, storage_type, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); - dirpath = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? MEDIA_SVC_THUMB_INTERNAL_PATH : MEDIA_SVC_THUMB_EXTERNAL_PATH; + dirpath = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? _media_svc_get_thumb_internal_path(uid) : _media_svc_get_thumb_external_path(uid); /* remove thumbnails */ ret = _media_svc_remove_all_files_in_dir(dirpath); @@ -803,7 +803,7 @@ int media_svc_delete_all_items_in_storage(MediaSvcHandle *handle, media_svc_stor return MEDIA_INFO_ERROR_NONE; } -int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type) +int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, uid_t uid) { sqlite3 * db_handle = (sqlite3 *)handle; @@ -817,10 +817,10 @@ int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, media_svc_ } /*Delete from DB and remove thumbnail files*/ - return _media_svc_delete_invalid_items(db_handle, storage_type); + return _media_svc_delete_invalid_items(db_handle, storage_type, uid); } -int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char *folder_path) +int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char *folder_path, uid_t uid) { sqlite3 * db_handle = (sqlite3 *)handle; @@ -829,10 +829,10 @@ int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL"); /*Delete from DB and remove thumbnail files*/ - return _media_svc_delete_invalid_folder_items(db_handle, folder_path); + return _media_svc_delete_invalid_folder_items(db_handle, folder_path, uid); } -int media_svc_set_all_storage_items_validity(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, int validity) +int media_svc_set_all_storage_items_validity(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, int validity, uid_t uid) { sqlite3 * db_handle = (sqlite3 *)handle; @@ -843,10 +843,10 @@ int media_svc_set_all_storage_items_validity(MediaSvcHandle *handle, media_svc_s return MEDIA_INFO_ERROR_INVALID_PARAMETER; } - return _media_svc_update_storage_item_validity(db_handle, storage_type, validity); + return _media_svc_update_storage_item_validity(db_handle, storage_type, validity, uid); } -int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *folder_path, int validity, int recursive) +int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *folder_path, int validity, int recursive, uid_t uid) { sqlite3 * db_handle = (sqlite3 *)handle; @@ -854,12 +854,12 @@ int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *fold media_svc_retvm_if(!STRING_VALID(folder_path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "folder_path is NULL"); if(recursive) - return _media_svc_update_recursive_folder_item_validity(db_handle, folder_path, validity); + return _media_svc_update_recursive_folder_item_validity(db_handle, folder_path, validity , uid); else - return _media_svc_update_folder_item_validity(db_handle, folder_path, validity); + return _media_svc_update_folder_item_validity(db_handle, folder_path, validity, uid); } -int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path) +int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; sqlite3 * db_handle = (sqlite3 *)handle; @@ -887,14 +887,14 @@ int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e stor ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); - if (g_file_test(thumb_path, G_FILE_TEST_EXISTS) && (strncmp(thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) { + if (g_file_test(thumb_path, G_FILE_TEST_EXISTS) && (strncmp(thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) { ret = _media_svc_remove_file(thumb_path); if (ret < MEDIA_INFO_ERROR_NONE) { media_svc_error("_media_svc_remove_file failed : %s", thumb_path); } } - ret = _media_svc_update_thumbnail_path(handle, path, NULL); + ret = _media_svc_update_thumbnail_path(handle, path, NULL, uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /* Get notification info */ @@ -913,7 +913,7 @@ int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e stor return ret; } } else { - ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo); + ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo, uid); if (ret != MEDIA_INFO_ERROR_NONE) { _media_svc_destroy_noti_item(noti_item); return ret; @@ -926,7 +926,7 @@ int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e stor int width = 0; int height = 0; - ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height); + ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid); if (ret < 0) { media_svc_error("thumbnail_request_from_db failed: %d", ret); } else { @@ -944,7 +944,7 @@ int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e stor content_info.media_meta.height = height; } #endif - ret = _media_svc_update_item_with_data(db_handle, &content_info); + ret = _media_svc_update_item_with_data(db_handle, &content_info, uid); if (ret == MEDIA_INFO_ERROR_NONE) { media_svc_debug("Update is successful. Sending noti for this"); @@ -959,7 +959,7 @@ int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e stor return ret; } -int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const char *dst_path) +int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const char *dst_path, uid_t uid) { sqlite3 * db_handle = (sqlite3 *)handle; int ret = MEDIA_INFO_ERROR_NONE; @@ -975,7 +975,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const ret = _media_svc_get_noti_info(handle, src_path, MS_MEDIA_ITEM_DIRECTORY, ¬i_item); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); - ret = _media_svc_sql_begin_trans(handle); + ret = _media_svc_sql_begin_trans(handle,uid); media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret); /* Update all folder record's path, which are matched by old parent path */ @@ -989,12 +989,12 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const update_folder_path_sql = sqlite3_mprintf("UPDATE folder SET path = REPLACE( path, '%q', '%q');", src_path_slash, dst_path_slash); //ret = _media_svc_sql_query(handle, update_folder_path_sql); - ret = media_db_request_update_db_batch(update_folder_path_sql); + ret = media_db_request_update_db_batch(update_folder_path_sql, uid); sqlite3_free(update_folder_path_sql); if (ret != SQLITE_OK) { media_svc_error("failed to update folder path"); - _media_svc_sql_rollback_trans(handle); + _media_svc_sql_rollback_trans(handle, uid); return MEDIA_INFO_ERROR_DATABASE_INTERNAL; } @@ -1006,13 +1006,13 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const update_folder_modified_time_sql = sqlite3_mprintf("UPDATE folder SET modified_time = %d where path like '%q';", date, dst_path); - ret = media_db_request_update_db_batch(update_folder_modified_time_sql); + ret = media_db_request_update_db_batch(update_folder_modified_time_sql, uid); //ret = _media_svc_sql_query(handle, update_folder_modified_time_sql); sqlite3_free(update_folder_modified_time_sql); if (ret != SQLITE_OK) { media_svc_error("failed to update folder modified time"); - _media_svc_sql_rollback_trans(handle); + _media_svc_sql_rollback_trans(handle, uid); return MEDIA_INFO_ERROR_DATABASE_INTERNAL; } @@ -1033,7 +1033,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const if (ret != SQLITE_OK) { media_svc_error ("prepare error [%s]", sqlite3_errmsg(handle)); - _media_svc_sql_rollback_trans(handle); + _media_svc_sql_rollback_trans(handle, uid); return MEDIA_INFO_ERROR_DATABASE_INTERNAL; } @@ -1083,7 +1083,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const if (replaced_path == NULL) { media_svc_error("_media_svc_replace_path failed"); SQLITE3_FINALIZE(sql_stmt); - _media_svc_sql_rollback_trans(handle); + _media_svc_sql_rollback_trans(handle, uid); return MEDIA_INFO_ERROR_INTERNAL; } @@ -1092,23 +1092,23 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const if (!no_thumb) { /* If old thumb path is default or not */ - if (strncmp(media_thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) == 0) { - strncpy(media_new_thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(media_new_thumb_path)); + if (strncmp(media_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) == 0) { + strncpy(media_new_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(media_new_thumb_path)); } else { ret = _media_svc_get_store_type_by_path(replaced_path, &storage_type); if (ret < 0) { media_svc_error("_media_svc_get_store_type_by_path failed : %d", ret); SAFE_FREE(replaced_path); - _media_svc_sql_rollback_trans(handle); + _media_svc_sql_rollback_trans(handle,uid); return MEDIA_INFO_ERROR_DATABASE_INTERNAL; } - ret = _media_svc_get_thumbnail_path(storage_type, media_new_thumb_path, replaced_path, THUMB_EXT); + ret = _media_svc_get_thumbnail_path(storage_type, media_new_thumb_path, replaced_path, THUMB_EXT, uid); if (ret < 0) { media_svc_error("_media_svc_get_thumbnail_path failed : %d", ret); SAFE_FREE(replaced_path); SQLITE3_FINALIZE(sql_stmt); - _media_svc_sql_rollback_trans(handle); + _media_svc_sql_rollback_trans(handle,uid); return MEDIA_INFO_ERROR_INTERNAL; } } @@ -1128,7 +1128,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const } } - ret = media_db_request_update_db_batch(update_item_sql); + ret = media_db_request_update_db_batch(update_item_sql,uid); //ret = _media_svc_sql_query(handle, update_item_sql); sqlite3_free(update_item_sql); SAFE_FREE(replaced_path); @@ -1136,14 +1136,14 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const if (ret != SQLITE_OK) { media_svc_error("failed to update item"); SQLITE3_FINALIZE(sql_stmt); - _media_svc_sql_rollback_trans(handle); + _media_svc_sql_rollback_trans(handle,uid); return MEDIA_INFO_ERROR_DATABASE_INTERNAL; } /* Rename thumbnail file of file system */ if ((!no_thumb) && (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) - && (strncmp(media_thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) { + && (strncmp(media_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) { ret = _media_svc_rename_file(media_thumb_path, media_new_thumb_path); if (ret < 0) { media_svc_error("_media_svc_rename_file failed : %d", ret); @@ -1153,10 +1153,10 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const SQLITE3_FINALIZE(sql_stmt); - ret = _media_svc_sql_end_trans(handle); + ret = _media_svc_sql_end_trans(handle, uid); if (ret != MEDIA_INFO_ERROR_NONE) { media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback\n"); - _media_svc_sql_rollback_trans(handle); + _media_svc_sql_rollback_trans(handle,uid); return ret; } @@ -1167,13 +1167,13 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const return MEDIA_INFO_ERROR_NONE; } -int media_svc_request_update_db(const char *db_query) +int media_svc_request_update_db(const char *db_query, uid_t uid) { int ret = MEDIA_INFO_ERROR_NONE; media_svc_retvm_if(!STRING_VALID(db_query), MEDIA_INFO_ERROR_INVALID_PARAMETER, "db_query is NULL"); - ret = _media_svc_request_update_db(db_query); + ret = _media_svc_request_update_db(db_query, uid); return _media_svc_error_convert(ret); } diff --git a/src/include/common/media-svc-album.h b/src/include/common/media-svc-album.h index e7fb882..a36c083 100755 --- a/src/include/common/media-svc-album.h +++ b/src/include/common/media-svc-album.h @@ -23,10 +23,11 @@ #define _MEDIA_SVC_ALBUM_H_ #include +#include int _media_svc_get_album_id(sqlite3 *handle, const char *album, const char *artist, int * album_id); int _media_svc_get_album_art_by_album_id(sqlite3 *handle, int album_id, char **album_art); -int _media_svc_append_album(sqlite3 *handle, const char *album, const char *artist, const char *album_art, int * album_id); +int _media_svc_append_album(sqlite3 *handle, const char *album, const char *artist, const char *album_art, int * album_id, uid_t uid); int _media_svc_get_media_count_with_album_id_by_path(sqlite3 *handle, const char *path, int *count); #endif /*_MEDIA_SVC_ALBUM_H_*/ diff --git a/src/include/common/media-svc-db-utils.h b/src/include/common/media-svc-db-utils.h index 8493a64..e5685b6 100755 --- a/src/include/common/media-svc-db-utils.h +++ b/src/include/common/media-svc-db-utils.h @@ -30,20 +30,20 @@ int _media_svc_connect_db_with_handle(sqlite3 **db_handle); int _media_svc_disconnect_db_with_handle(sqlite3 *db_handle); -int _media_svc_create_media_table(sqlite3 *db_handle); -int _media_svc_create_folder_table(sqlite3 *db_handle); -int _media_svc_create_playlist_table(sqlite3 *db_handle); -int _media_svc_create_album_table(sqlite3 *db_handle); -int _media_svc_create_tag_table(sqlite3 *db_handle); -int _media_svc_create_bookmark_table(sqlite3 *db_handle); -int _media_svc_create_custom_table(sqlite3 *db_handle); -int _media_svc_request_update_db(const char *sql_str); -int _media_svc_sql_query(sqlite3 *db_handle, const char *sql_str); +int _media_svc_create_media_table(sqlite3 *db_handle, uid_t uid); +int _media_svc_create_folder_table(sqlite3 *db_handle, uid_t uid); +int _media_svc_create_playlist_table(sqlite3 *db_handle, uid_t uid); +int _media_svc_create_album_table(sqlite3 *db_handle, uid_t uid); +int _media_svc_create_tag_table(sqlite3 *db_handle, uid_t uid); +int _media_svc_create_bookmark_table(sqlite3 *db_handle, uid_t uid); +int _media_svc_create_custom_table(sqlite3 *db_handle, uid_t uid); +int _media_svc_request_update_db(const char *sql_str, uid_t uid); +int _media_svc_sql_query(sqlite3 *db_handle, const char *sql_str, uid_t uid); int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt** stmt); -int _media_svc_sql_begin_trans(sqlite3 *handle); -int _media_svc_sql_end_trans(sqlite3 *handle); -int _media_svc_sql_rollback_trans(sqlite3 *handle); -int _media_svc_sql_query_list(sqlite3 *handle, GList **query_list); +int _media_svc_sql_begin_trans(sqlite3 *handle, uid_t uid); +int _media_svc_sql_end_trans(sqlite3 *handle, uid_t uid); +int _media_svc_sql_rollback_trans(sqlite3 *handle, uid_t uid); +int _media_svc_sql_query_list(sqlite3 *handle, GList **query_list, uid_t uid); void _media_svc_sql_query_add(GList **query_list, char **query); void _media_svc_sql_query_release(GList **query_list); diff --git a/src/include/common/media-svc-media-folder.h b/src/include/common/media-svc-media-folder.h index 3b9897a..1a17e27 100755 --- a/src/include/common/media-svc-media-folder.h +++ b/src/include/common/media-svc-media-folder.h @@ -27,9 +27,9 @@ #include "media-svc-types.h" int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *folder_name, char *folder_id); -int _media_svc_append_folder(sqlite3 *handle, media_svc_storage_type_e storage_type, const char *folder_id, const char *path_name, const char *folder_name, int modified_date); -int _media_svc_update_folder_modified_time_by_folder_uuid(sqlite3 *handle, const char *folder_uuid, const char *folder_path, bool stack_query); -int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *path, media_svc_storage_type_e storage_type, char *folder_id); -int _media_svc_update_folder_table(sqlite3 *handle); +int _media_svc_append_folder(sqlite3 *handle, media_svc_storage_type_e storage_type, const char *folder_id, const char *path_name, const char *folder_name, int modified_date, uid_t uid); +int _media_svc_update_folder_modified_time_by_folder_uuid(sqlite3 *handle, const char *folder_uuid, const char *folder_path, bool stack_query, uid_t uid); +int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *path, media_svc_storage_type_e storage_type, char *folder_id, uid_t uid); +int _media_svc_update_folder_table(sqlite3 *handle, uid_t uid); #endif /*_MEDIA_SVC_MEDIA_FOLDER_H_*/ diff --git a/src/include/common/media-svc-media.h b/src/include/common/media-svc-media.h index d7e0ba6..b29c503 100755 --- a/src/include/common/media-svc-media.h +++ b/src/include/common/media-svc-media.h @@ -29,25 +29,26 @@ #include "media-svc-noti.h" int _media_svc_count_record_with_path(sqlite3 *handle, const char *path, int *count); -int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, int is_burst, bool stack_query); -int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info); +int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid); +int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid); int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path); int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *path, int *media_type); int _media_svc_get_burst_id(sqlite3 *handle, int *id); -int _media_svc_delete_item_by_path(sqlite3 *handle, const char *path); -int _media_svc_truncate_table(sqlite3 *handle, media_svc_storage_type_e storage_type); -int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e storage_type); -int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *folder_path); -int _media_svc_update_storage_item_validity(sqlite3 *handle, media_svc_storage_type_e storage_type, int validity); -int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity); -int _media_svc_update_recursive_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity); -int _media_svc_update_item_validity(sqlite3 *handle, const char *path, int validity, bool stack_query); -int _media_svc_update_item_by_path(sqlite3 *handle, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path, const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query); -int _media_svc_list_query_do(sqlite3 *handle, media_svc_query_type_e query_type); +int _media_svc_delete_item_by_path(sqlite3 *handle, const char *path, uid_t uid); +int _media_svc_truncate_table(sqlite3 *handle, media_svc_storage_type_e storage_type, uid_t uid); +int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e storage_type, uid_t uid); +int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *folder_path, uid_t uid); +int _media_svc_update_storage_item_validity(sqlite3 *handle, media_svc_storage_type_e storage_type, int validity, uid_t uid); +int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity, uid_t uid); +int _media_svc_update_recursive_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity, uid_t uid); +int _media_svc_update_item_validity(sqlite3 *handle, const char *path, int validity, bool stack_query, uid_t uid); +int _media_svc_update_item_by_path(sqlite3 *handle, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path, const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query, uid_t uid); +int _media_svc_list_query_do(sqlite3 *handle, media_svc_query_type_e query_type, uid_t uid); int _media_svc_get_media_id_by_path(sqlite3 *handle, const char *path, char *media_uuid, int max_length); -int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *path, const char *thumb_path); +int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *path, const char *thumb_path, uid_t uid); int _media_svc_get_noti_info(sqlite3 *handle, const char *path, int update_item, media_svc_noti_item **item); int _media_svc_count_invalid_folder_items(sqlite3 *handle, const char *folder_path, int *count); int _media_svc_get_thumbnail_count(sqlite3 *handle, const char *thumb_path, int *count); +char* _media_svc_get_thumb_default_path(uid_t uid); #endif /*_MEDIA_SVC_MEDIA_H_*/ diff --git a/src/include/common/media-svc-util.h b/src/include/common/media-svc-util.h index 1272641..f05888d 100755 --- a/src/include/common/media-svc-util.h +++ b/src/include/common/media-svc-util.h @@ -54,19 +54,20 @@ int _media_svc_rename_file( const char *old_name, const char *new_name); bool _media_svc_remove_file(const char *path); int _media_svc_remove_all_files_in_dir(const char *dir_path); char *_media_svc_get_title_from_filepath (const char *path); -int _media_svc_save_image(void *image, int size, char *image_path); -bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format); +int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid); +bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid); bool _media_svc_get_file_ext(const char *file_path, char *file_ext); int _media_svc_get_file_time(const char *full_path); int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_storage_type_e storage_type, const char *path, media_svc_media_type_e *media_type, bool refresh, drm_content_info_s **drm_contentInfo); int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, media_svc_media_type_e media_type); -int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, drm_content_info_s *drm_contentInfo); +int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, drm_content_info_s *drm_contentInfo, uid_t uid); int __media_svc_malloc_and_strncpy(char **dst, const char *src); void _media_svc_destroy_content_info(media_svc_content_info_s *content_info); int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type); char *_media_svc_replace_path(char *s, const char *olds, const char *news); - +char* _media_svc_get_thumb_internal_path(uid_t uid); +char* _media_svc_get_thumb_external_path(uid_t uid); int _media_svc_error_convert(int error); /* Define data structures for media type and mime type */