From: Minje Ahn Date: Mon, 15 Jun 2015 06:30:14 +0000 (+0900) Subject: Add new API(image meta/storage/playlist). X-Git-Tag: accepted/tizen/mobile/20150617.044509~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F04%2F41404%2F1;p=platform%2Fcore%2Fapi%2Fmedia-content.git Add new API(image meta/storage/playlist). Change-Id: I95772997bfffe026d9d1177080e01cfdbddb5213 Signed-off-by: Minje Ahn --- diff --git a/include/media_info_private.h b/include/media_info_private.h index d9fd53a..3d2b706 100755 --- a/include/media_info_private.h +++ b/include/media_info_private.h @@ -161,6 +161,7 @@ typedef enum { MEDIA_GROUP_BOOKMARK, MEDIA_GROUP_TAG_BY_MEDIA_ID, MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID, + MEDIA_GROUP_STORAGE, } group_list_e; typedef enum { @@ -170,6 +171,7 @@ typedef enum { typedef struct _filter_s { + char *storage_id; char *condition; char *order_keyword; media_content_order_e order_type; @@ -185,7 +187,9 @@ typedef struct char *path; char *name; time_t modified_time; - media_content_storage_e storage_type; + int storage_type; + char *storage_uuid; + int folder_order; }media_folder_s; typedef struct @@ -310,6 +314,7 @@ typedef struct int played_count; time_t played_time; int played_position; + char *storage_uuid; int sync_status; image_meta_s *image_meta; video_meta_s *video_meta; @@ -479,6 +484,7 @@ typedef struct _media_content_cb_data { #define DB_FIELD_FOLDER_MODIFIED_TIME "modified_time" #define DB_FIELD_FOLDER_STORAGE_TYPE "storage_type" #define DB_FIELD_FOLDER_NAME_PINYIN "name_pinyin" +#define DB_FIELD_FOLDER_ORDER "folder_order" /* DB field for playlist */ #define DB_FIELD_PLAYLIST_ID "playlist_id" @@ -507,48 +513,29 @@ typedef struct _media_content_cb_data { #define QUERY_KEYWORD_LIMIT "limit" #define QUERY_KEYWORD_DESC "DESC" #define QUERY_KEYWORD_SPACE " " +#define QUERY_KEYWORD_OPEN_BRACKET "(" #define QUERY_KEYWORD_BRACKET ")" -#define UPDATE_SQL "UPDATE %s SET %s WHERE %s" /* DB TABLE JOIN */ -#define SELECT_EMPTY_PLAYLIST "SELECT playlist_id, name FROM "DB_TABLE_PLAYLIST" WHERE playlist_id NOT IN (select playlist_id from "DB_TABLE_PLAYLIST_MAP")" -#define SELECT_EMPTY_TAG "SELECT tag_id, name FROM "DB_TABLE_TAG" WHERE tag_id NOT IN (SELECT tag_id FROM "DB_TABLE_TAG_MAP")" -#define FOLDER_MEDIA_JOIN "("DB_TABLE_FOLDER" AS f INNER JOIN "DB_TABLE_MEDIA" AS m ON f.folder_uuid=m.folder_uuid) WHERE m.validity=1" -#define PLAYLISTMAP_MEDIA_JOIN "("DB_TABLE_PLAYLIST_MAP" AS pm INNER JOIN "DB_TABLE_MEDIA" AS m \ - ON (pm.media_uuid = m.media_uuid)) WHERE m.validity=1" -#define SELECT_PLAYLIST_FROM_PLAYLIST_PLAYLISTMAP_MEDIA_JOIN "SELECT DISTINCT p.playlist_id, p.name FROM "DB_TABLE_PLAYLIST" AS p INNER JOIN "DB_TABLE_PLAYLIST_MAP" AS pm INNER JOIN "DB_TABLE_MEDIA" AS m \ - ON (p.playlist_id=pm.playlist_id AND pm.media_uuid = m.media_uuid) WHERE m.validity=1" -#define SELECT_TAG_FROM_TAG_TAGMAP_MEDIA_JOIN "SELECT DISTINCT t.tag_id, t.name FROM "DB_TABLE_TAG" AS t INNER JOIN "DB_TABLE_MEDIA" AS m INNER JOIN "DB_TABLE_TAG_MAP" AS tm \ - ON (tm.media_uuid = m.media_uuid and tm.tag_id=t.tag_id) WHERE m.validity=1" -#define BOOKMARK_MEDIA_JOIN "("DB_TABLE_BOOKMARK" AS b INNER JOIN "DB_TABLE_MEDIA" AS m \ +#define FOLDER_MEDIA_JOIN "("DB_TABLE_FOLDER" AS f INNER JOIN '%s' AS m ON f.folder_uuid=m.folder_uuid) WHERE m.validity=1 " +#define BOOKMARK_MEDIA_JOIN "("DB_TABLE_BOOKMARK" AS b INNER JOIN '%s' AS m \ ON (b.media_uuid = m.media_uuid)) WHERE m.validity=1" -#define ALBUM_MEDIA_JOIN "("DB_TABLE_ALBUM" AS a INNER JOIN "DB_TABLE_MEDIA" AS m \ +#define ALBUM_MEDIA_JOIN "("DB_TABLE_ALBUM" AS a INNER JOIN '%s' AS m \ ON (a.album_id = m.album_id)) WHERE m.validity=1" /* Get Group List */ #define SELECT_ALBUM_LIST "SELECT DISTINCT a.album_id, a.name, a.artist, a.album_art FROM "ALBUM_MEDIA_JOIN -#define SELECT_ARTIST_LIST "SELECT DISTINCT artist FROM "DB_TABLE_MEDIA" WHERE validity=1" -#define SELECT_GENRE_LIST "SELECT DISTINCT genre FROM "DB_TABLE_MEDIA" WHERE validity=1" -#define SELECT_COMPOSER_LIST "SELECT DISTINCT composer FROM "DB_TABLE_MEDIA" WHERE validity=1 " -#define SELECT_YEAR_LIST "SELECT DISTINCT year FROM "DB_TABLE_MEDIA" WHERE validity=1 " -#define SELECT_MEDIA_GROUP_LIST "SELECT DISTINCT %s FROM "DB_TABLE_MEDIA" WHERE validity=1 " - -#define SELECT_FOLDER_LIST "SELECT DISTINCT f.folder_uuid, f.path, f.name, f.storage_type, f.modified_time FROM "FOLDER_MEDIA_JOIN -//#define SELECT_TAG_LIST SELECT_EMPTY_TAG" UNION "SELECT_TAG_FROM_TAG_TAGMAP_MEDIA_JOIN -//#define SELECT_PLAYLIST_LIST SELECT_EMPTY_PLAYLIST" UNION "SELECT_PLAYLIST_FROM_PLAYLIST_PLAYLISTMAP_MEDIA_JOIN +#define SELECT_MEDIA_GROUP_LIST "SELECT DISTINCT %s FROM '%s' WHERE validity=1 " + +#define SELECT_FOLDER_LIST "SELECT DISTINCT f.folder_uuid, f.path, f.name, f.storage_type, f.modified_time, f.storage_uuid, f.folder_order FROM "FOLDER_MEDIA_JOIN +#define SELECT_FOLDER_LIST_BY_STORAGE_ID SELECT_FOLDER_LIST"AND f.storage_uuid='%s' " #define SELECT_TAG_LIST "SELECT DISTINCT tag_id, name FROM "DB_VIEW_TAG" WHERE 1 " -#define SELECT_PLAYLIST_LIST "SELECT DISTINCT playlist_id, name, thumbnail_path FROM "DB_VIEW_PLAYLIST" WHERE 1 " -#define SELECT_BOOKMARK_LIST "SELECT DISTINCT b.bookmark_id, b.media_uuid, b.marked_time, b.thumbnail_path FROM "BOOKMARK_MEDIA_JOIN +#define SELECT_PLAYLIST_LIST "SELECT DISTINCT playlist_id, name, p_thumbnail_path FROM "DB_VIEW_PLAYLIST" WHERE 1 " /* Get Group Count */ #define SELECT_ALBUM_COUNT "SELECT COUNT(DISTINCT a.album_id) FROM "ALBUM_MEDIA_JOIN -#define SELECT_ARTIST_COUNT "SELECT COUNT(DISTINCT artist) FROM "DB_TABLE_MEDIA" WHERE validity=1" -#define SELECT_GENRE_COUNT "SELECT COUNT(DISTINCT genre) FROM "DB_TABLE_MEDIA" WHERE validity=1" -#define SELECT_COMPOSER_COUNT "SELECT COUNT(DISTINCT composer) FROM "DB_TABLE_MEDIA" WHERE validity=1" -#define SELECT_YEAR_COUNT "SELECT COUNT(DISTINCT year) FROM "DB_TABLE_MEDIA" WHERE validity=1" #define SELECT_FOLDER_COUNT "SELECT COUNT(DISTINCT f.folder_uuid) FROM "FOLDER_MEDIA_JOIN -//#define SELECT_TAG_COUNT "SELECT COUNT(*) FROM ("SELECT_TAG_LIST -//#define SELECT_PLAYLIST_COUNT "SELECT COUNT(*) FROM ("SELECT_PLAYLIST_LIST +#define SELECT_FOLDER_COUNT_BY_STORAGE_ID SELECT_FOLDER_COUNT"AND f.storage_uuid='%s' " #define SELECT_TAG_COUNT "SELECT COUNT(DISTINCT tag_id) FROM "DB_VIEW_TAG" WHERE 1 " #define SELECT_PLAYLIST_COUNT "SELECT COUNT(DISTINCT playlist_id) FROM "DB_VIEW_PLAYLIST" WHERE 1 " #define SELECT_BOOKMARK_COUNT "SELECT COUNT(DISTINCT b.bookmark_id) FROM "BOOKMARK_MEDIA_JOIN @@ -557,19 +544,14 @@ typedef struct _media_content_cb_data { /* Get Media Count of Group */ #define SELECT_MEDIA_COUNT_FROM_MEDIA "SELECT COUNT(*) FROM ("SELECT_MEDIA_ITEM //to apply limit condition. "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1" -#define SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 " -#define SELECT_MEDIA_COUNT_FROM_ALBUM "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND album_id='%d'" -#define SELECT_MEDIA_COUNT_FROM_ARTIST "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND artist='%q'" -#define SELECT_MEDIA_COUNT_FROM_GENRE "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND genre='%q'" -#define SELECT_MEDIA_COUNT_FROM_COMPOSER "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND composer='%q'" -#define SELECT_MEDIA_COUNT_FROM_YEAR "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND year='%q'" +#define SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE "SELECT COUNT(*) FROM '%s' WHERE validity=1 " +#define SELECT_MEDIA_COUNT_FROM_ALBUM "SELECT COUNT(*) FROM '%s' WHERE validity=1 AND album_id='%d'" #define SELECT_MEDIA_COUNT_FROM_GROUP "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP //to apply limit condition. #define SELECT_MEDIA_COUNT_FROM_GROUP_NULL "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_NULL //to apply limit condition. -#define SELECT_MEDIA_COUNT_FROM_FOLDER "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND folder_uuid='%q'" -//#define SELECT_MEDIA_COUNT_FROM_TAG "SELECT COUNT(*) FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d AND media_uuid IN (SELECT media_uuid FROM "DB_TABLE_MEDIA" WHERE validity=1" -//#define SELECT_MEDIA_COUNT_FROM_PLAYLIST "SELECT COUNT(*) FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d AND media_uuid IN (SELECT media_uuid FROM "DB_TABLE_MEDIA" WHERE validity=1" +#define SELECT_MEDIA_COUNT_FROM_FOLDER "SELECT COUNT(*) FROM '%s' WHERE validity=1 AND folder_uuid='%q'" +#define SELECT_MEDIA_COUNT_FROM_STORAGE "SELECT COUNT(*) FROM '%s' WHERE validity=1 AND storage_uuid='%q'" #define SELECT_MEDIA_COUNT_FROM_TAG "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE (tag_id=%d AND media_count>0) " -#define SELECT_MEDIA_COUNT_FROM_PLAYLIST "SELECT COUNT(*) FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) " +#define SELECT_MEDIA_COUNT_FROM_PLAYLIST "SELECT COUNT(*) FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) " /* Get Group Info by Group ID*/ #define SELECT_ALBUM_FROM_ALBUM "SELECT * FROM "DB_TABLE_ALBUM" WHERE album_id=%d" @@ -583,66 +565,62 @@ typedef struct _media_content_cb_data { #define INSERT_TAG_TO_TAG "INSERT INTO "DB_TABLE_TAG" (name) VALUES (%Q)" #define REMOVE_TAG_ITEM_FROM_TAG_MAP "DELETE FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d AND media_uuid='%q'" #define UPDATE_TAG_NAME_FROM_TAG "UPDATE "DB_TABLE_TAG" SET name='%q' WHERE tag_id=%d" -//#define SELECT_TAG_COUNT_BY_MEDIA_ID "SELECT COUNT(*) FROM "DB_TABLE_TAG" WHERE tag_id IN (SELECT tag_id FROM "DB_TABLE_TAG_MAP" WHERE media_uuid = '%q')" -//#define SELECT_TAG_LIST_BY_MEDIA_ID "SELECT * FROM "DB_TABLE_TAG" WHERE tag_id IN (SELECT tag_id FROM "DB_TABLE_TAG_MAP" WHERE media_uuid = '%s')" -#define SELECT_TAG_COUNT_BY_MEDIA_ID "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE media_uuid = '%q'" +#define SELECT_TAG_COUNT_BY_MEDIA_ID "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE media_uuid = '%s'" #define SELECT_TAG_LIST_BY_MEDIA_ID "SELECT tag_id, name FROM "DB_VIEW_TAG" WHERE media_uuid = '%s'" /* Get Media list of Group */ #define MEDIA_INFO_ITEM "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description, \ - rating, favourite, author, provider, content_name, category, location_tag, age_rating, keyword, is_drm, storage_type, longitude, latitude, altitude, exposure_time, fnumber, iso, model, width, height, datetaken, orientation, title, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, bitpersample, duration, played_count, last_played_time, last_played_position, samplerate, channel, burst_id, timeline, weather, sync_status" + rating, favourite, author, provider, content_name, category, location_tag, age_rating, keyword, is_drm, storage_type, longitude, latitude, altitude, exposure_time, fnumber, iso, model, width, height, datetaken, orientation, title, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, bitpersample, duration, played_count, last_played_time, last_played_position, samplerate, channel, burst_id, timeline, weather, sync_status, storage_uuid" + +/*Folder info*/ +#define UPDATE_FOLDER_ORDER "UPDATE "DB_TABLE_FOLDER" SET folder_order=%d WHERE folder_uuid=%Q" /* Playlist Info */ #define INSERT_PLAYLIST_TO_PLAYLIST "INSERT INTO "DB_TABLE_PLAYLIST" (name) VALUES (%Q)" #define UPDATE_PLAYLIST_NAME_FROM_PLAYLIST "UPDATE "DB_TABLE_PLAYLIST" SET name='%q' WHERE playlist_id=%d" -#define UPDATE_PLAYLIST_THUMBNAIL_FROM_PLAYLIST "UPDATE "DB_TABLE_PLAYLIST" SET thumbnail_path='%q' WHERE playlist_id=%d" +#define UPDATE_PLAYLIST_THUMBNAIL_FROM_PLAYLIST "UPDATE "DB_TABLE_PLAYLIST" SET thumbnail_path='%q' WHERE playlist_id=%d" #define SELECT_PLAYLIST_ID_FROM_PLAYLIST "SELECT playlist_id FROM "DB_TABLE_PLAYLIST" WHERE name='%q'" -//#define SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_MAP "SELECT pm._id, pm.media_uuid FROM "PLAYLISTMAP_MEDIA_JOIN" AND pm.playlist_id=%d" -#define SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_VIEW "SELECT pm_id, media_uuid FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d " - -//#define SELECT_PLAY_ORDER_FROM_PLAYLIST_MAP "SELECT play_order FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d and _id=%d" +#define SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_VIEW "SELECT pm_id, media_uuid FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) " +#define SELECT_PLAYLIST_ITEM_ALL_FROM_PLAYLIST_VIEW "SELECT "MEDIA_INFO_ITEM", pm_id FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) " #define SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW "SELECT play_order FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d and pm_id=%d" -//#define SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_MAP "SELECT MAX(play_order) FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d" #define SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_VIEW "SELECT MAX(play_order) FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d" #define REMOVE_PLAYLIST_ITEM_FROM_PLAYLIST_MAP "DELETE FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d AND _id=%d" #define UPDATE_PLAYLIST_ORDER_FROM_PLAYLIST_MAP "UPDATE "DB_TABLE_PLAYLIST_MAP" SET play_order=%d WHERE playlist_id=%d AND _id=%d" /* Bookmark */ -#define INSERT_BOOKMARK_TO_BOOKMARK "INSERT INTO "DB_TABLE_BOOKMARK" (media_uuid, marked_time, thumbnail_path) VALUES ('%q', '%d', %Q)" -#define SELECT_BOOKMARK_COUNT_BY_MEDIA_ID "SELECT COUNT(*) FROM "DB_TABLE_BOOKMARK" WHERE media_uuid='%q'" -#define SELECT_BOOKMARK_LIST_BY_MEDIA_ID "SELECT * FROM "DB_TABLE_BOOKMARK" WHERE media_uuid='%q'" -#define SELECT_BOOKMARK_LIST_BY_MEDIA_ID_USUAL "SELECT * FROM "DB_TABLE_BOOKMARK" WHERE media_uuid='%s'" - -/* Get Meta */ -#define MEDIA_AV_META "media_uuid, title, album, artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, duration, played_count, last_played_time, last_played_position" -#define MEDIA_IMAGE_META "media_uuid, width, height, datetaken, orientation" -#define SELECT_IMAGE_FROM_MEDIA "SELECT "MEDIA_IMAGE_META" FROM "DB_TABLE_MEDIA" WHERE media_uuid='%s'" -#define SELECT_AUDIO_FROM_MEDIA "SELECT "MEDIA_AV_META", samplerate, channel FROM "DB_TABLE_MEDIA" WHERE media_uuid='%s'" -#define SELECT_VIDEO_FROM_MEDIA "SELECT "MEDIA_AV_META", width, height FROM "DB_TABLE_MEDIA" WHERE media_uuid='%s'" +#define INSERT_BOOKMARK_TO_BOOKMARK "INSERT INTO "DB_TABLE_BOOKMARK" (media_uuid, marked_time, thumbnail_path) VALUES ('%q', '%d', %Q)" +#define SELECT_BOOKMARK_COUNT_BY_MEDIA_ID "SELECT COUNT(*) FROM "BOOKMARK_MEDIA_JOIN" AND b.media_uuid='%s'" +#define SELECT_BOOKMARK_LIST_BY_MEDIA_ID "SELECT b.bookmark_id, b.media_uuid, b.marked_time, b.thumbnail_path FROM "BOOKMARK_MEDIA_JOIN" AND b.media_uuid='%s'" /* Update Meta*/ -#define UPDATE_AV_META_FROM_MEDIA "UPDATE "DB_TABLE_MEDIA" SET played_count=%d, last_played_time=%d, last_played_position=%d WHERE media_uuid='%q'" -#define UPDATE_IMAGE_META_FROM_MEDIA "UPDATE "DB_TABLE_MEDIA" SET orientation=%d, weather=%Q WHERE media_uuid='%q'" - -#define SELECT_MEDIA_ITEM "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1" -#define SELECT_MEDIA_FROM_MEDIA "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND media_uuid='%s'" -#define SELECT_MEDIA_BY_PATH "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND path='%q'" -#define SELECT_MEDIA_FROM_ALBUM "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND album_id=%d" -#define SELECT_MEDIA_FROM_GROUP "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND %s='%q'" -#define SELECT_MEDIA_FROM_GROUP_NULL "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND %s IS NULL" -#define SELECT_MEDIA_FROM_FOLDER "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND folder_uuid='%q'" -#define SELECT_MEDIA_FROM_TAG "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE media_uuid IN (SELECT media_uuid FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d) AND validity=1" -#define SELECT_MEDIA_FROM_PLAYLIST "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE media_uuid IN (SELECT media_uuid FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d) AND validity=1" -#define SELECT_MEDIA_PATH_BY_ID "SELECT path FROM "DB_TABLE_MEDIA" WHERE media_uuid='%q'" +#define UPDATE_AV_META_FROM_MEDIA "UPDATE '%s' SET played_count=%d, last_played_time=%d, last_played_position=%d WHERE media_uuid='%q'" +#define UPDATE_IMAGE_META_FROM_MEDIA "UPDATE '%s' SET orientation=%d, weather=%Q WHERE media_uuid='%q'" + +#define SELECT_MEDIA_ITEM "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1" +#define SELECT_MEDIA_FROM_MEDIA "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND media_uuid='%s'" +#define SELECT_MEDIA_BY_PATH "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND path='%q'" +#define SELECT_MEDIA_FROM_ALBUM "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND album_id=%d" +#define SELECT_MEDIA_FROM_GROUP "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND %s='%q'" +#define SELECT_MEDIA_FROM_GROUP_NULL "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND %s IS NULL" +#define SELECT_MEDIA_FROM_FOLDER "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND folder_uuid='%s'" +#define SELECT_MEDIA_FROM_STORAGE "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND storage_uuid='%s'" +#define SELECT_MEDIA_FROM_TAG "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE media_uuid IN (SELECT media_uuid FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d) AND validity=1" +#define SELECT_MEDIA_FROM_PLAYLIST "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE media_uuid IN (SELECT media_uuid FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d) AND validity=1" +#define SELECT_MEDIA_PATH_BY_ID "SELECT path FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q'" +#define SELECT_MEDIA_STORAGE_ID_BY_ID "SELECT storage_uuid FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q'" /* Delete */ -#define DELETE_MEDIA_FROM_MEDIA "DELETE FROM "DB_TABLE_MEDIA" WHERE media_uuid='%q'" -#define DELETE_MEDIA_FROM_MEDIA_BATCH "DELETE FROM "DB_TABLE_MEDIA" WHERE %s" -#define DELETE_FOLDER_FROM_FOLDER "DELETE FROM "DB_TABLE_FOLDER" WHERE folder_uuid='%q'" -#define DELETE_PLAYLIST_FROM_PLAYLIST "DELETE FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d" -#define DELETE_TAG_FROM_TAG "DELETE FROM "DB_TABLE_TAG" WHERE tag_id=%d" -#define DELETE_BOOKMARK_FROM_BOOKMARK "DELETE FROM "DB_TABLE_BOOKMARK" WHERE bookmark_id=%d" +#define DELETE_MEDIA_FROM_MEDIA_BATCH "DELETE FROM '%s' WHERE %s" +#define DELETE_PLAYLIST_FROM_PLAYLIST "DELETE FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d" +#define DELETE_TAG_FROM_TAG "DELETE FROM "DB_TABLE_TAG" WHERE tag_id=%d" +#define DELETE_BOOKMARK_FROM_BOOKMARK "DELETE FROM "DB_TABLE_BOOKMARK" WHERE bookmark_id=%d" + +/* Storage*/ +#define SELECT_STORAGE_COUNT "SELECT COUNT(*) FROM "DB_TABLE_STORAGE" WHERE validity=1" +#define SELECT_STORAGE_LIST "SELECT * FROM "DB_TABLE_STORAGE" WHERE validity=1" +#define SELECT_STORAGE_INFO_FROM_STORAGE "SELECT * FROM "DB_TABLE_STORAGE" WHERE validity=1 AND storage_uuid='%s'" +#define DEFAULT_MEDIA_STORAGE_ID "media" int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condition_query, char *option_query); int _content_error_capi(int type, int cotent_error); @@ -650,6 +628,7 @@ int _content_query_sql(char *query_str); MediaSvcHandle* _content_get_db_handle(void); attribute_h _content_get_attirbute_handle(void); attribute_h _content_get_alias_attirbute_handle(void); +int _media_info_get_media_info_from_db(const char *path, const char *storage_id, media_info_h media); void _media_info_item_get_detail(sqlite3_stmt *stmt, media_info_h media); int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count); int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count); @@ -664,8 +643,10 @@ int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_li int _media_db_get_group_item_count(const char *group_name, filter_h filter, group_list_e group_type, int *item_count); int _media_db_get_group_item_by_id(int group_id, filter_h filter, media_info_cb callback, void *user_data, group_list_e group_type); int _media_db_get_group_item(const char *group_name, filter_h filter, media_info_cb callback, void *user_data, group_list_e group_type); -int _media_db_get_media_group_item_count(const char *group_name, media_group_e group, filter_h filter, int *item_count); -int _media_db_get_media_group_item(const char *group_name, media_group_e group, filter_h filter, media_info_cb callback, void *user_data); +int _media_db_get_media_group_item_count(const char *group_name, filter_h filter, media_group_e group, int *item_count); +int _media_db_get_media_group_item(const char *group_name, filter_h filter, media_group_e group, media_info_cb callback, void *user_data); +int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data); +int _media_db_get_storage_id_by_media_id(const char *media_id, char *storage_id); /** * @internal diff --git a/include/media_util_private.h b/include/media_util_private.h index 2b68c32..dc388d0 100755 --- a/include/media_util_private.h +++ b/include/media_util_private.h @@ -31,8 +31,8 @@ extern "C" { */ int _media_util_check_file(const char *path); + int _media_util_check_ignore_dir(const char *dir_path, bool *ignore); -int _media_util_get_store_type_by_path(const char *path, int *storage_type); #ifdef __cplusplus diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec index 0eee6cf..275f851 100755 --- a/packaging/capi-content-media-content.spec +++ b/packaging/capi-content-media-content.spec @@ -1,6 +1,6 @@ Name: capi-content-media-content Summary: A Media content library in SLP C API -Version: 0.2.62 +Version: 0.2.63 Release: 0 Group: Multimedia/API License: Apache-2.0 @@ -42,6 +42,7 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %postun -p /sbin/ldconfig + %files %manifest %{name}.manifest %license LICENSE.APLv2.0 diff --git a/src/media_audio.c b/src/media_audio.c index baf0291..ec607ef 100755 --- a/src/media_audio.c +++ b/src/media_audio.c @@ -736,7 +736,13 @@ int audio_meta_update_to_db(audio_meta_h audio) if(_audio != NULL && STRING_VALID(_audio->media_id)) { - sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, _audio->played_count, _audio->played_time, _audio->played_position, _audio->media_id); + char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,}; + memset(storage_id, 0x00, sizeof(storage_id)); + + ret = _media_db_get_storage_id_by_media_id(_audio->media_id, storage_id); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, storage_id, _audio->played_count, _audio->played_time, _audio->played_position, _audio->media_id); ret = _content_query_sql(sql); sqlite3_free(sql); } diff --git a/src/media_bookmark.c b/src/media_bookmark.c index 311922a..466e6e3 100755 --- a/src/media_bookmark.c +++ b/src/media_bookmark.c @@ -62,8 +62,6 @@ int media_bookmark_get_bookmark_count_from_db(filter_h filter, int *bookmark_cou { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if (bookmark_count == NULL) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); diff --git a/src/media_content.c b/src/media_content.c index 1ec1ab5..b5539f1 100755 --- a/src/media_content.c +++ b/src/media_content.c @@ -15,15 +15,24 @@ */ +#include #include -#include +#include + +#include +#include +#include +#include +#include +#include +#include static attribute_h g_attr_handle = NULL; static attribute_h g_alias_attr_handle = NULL; static MediaSvcHandle *db_handle = NULL; static int ref_count = 0; -static GMutex *db_mutex = NULL; +static GMutex db_mutex; static __thread media_noti_cb_s *g_noti_info = NULL; @@ -486,6 +495,9 @@ static int __media_content_create_alias_attr_handle(void) ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_NAME_PINYIN, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_NAME_PINYIN); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_ORDER, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_ORDER); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + /* Playlist*/ ret = _media_filter_attribute_add(g_alias_attr_handle, PLAYLIST_NAME, DB_TABLE_ALIAS_PLAYLIST"."DB_FIELD_PLAYLIST_NAME); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -512,6 +524,8 @@ static int __media_content_create_attribute_handle(void) media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); ret = __media_content_create_alias_attr_handle(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + _media_filter_attribute_destory(g_attr_handle); return ret; } @@ -571,24 +585,32 @@ int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condit //query = sqlite3_mprintf("%s %s %s", select_query, condition_query, option_query); len = snprintf(query, sizeof(query), "%s %s %s", select_query, condition_query, option_query); - if (len > 0) { + if (len > 0 && len < MAX_QUERY_SIZE) { query[len] = '\0'; + } else if (len >= MAX_QUERY_SIZE) { + query[MAX_QUERY_SIZE -1] = '\0'; } else { media_content_error("snprintf failed"); return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } - media_content_info("Query : [%s]", query); + media_content_sec_debug("Query : [%s]", query); err = sqlite3_prepare_v2((sqlite3*)db_handle, query, strlen(query), stmt, NULL); if(err != SQLITE_OK) { media_content_error("DB_FAILED(0x%08x) fail to sqlite3_prepare(), %s", MEDIA_CONTENT_ERROR_DB_FAILED, sqlite3_errmsg((sqlite3*)db_handle)); - if (err == SQLITE_BUSY) + if (err == SQLITE_BUSY) { + media_content_error(" BUSY ERROR"); return MEDIA_CONTENT_ERROR_DB_BUSY; - else + } else if (err == SQLITE_PERM) { + media_content_error("PERMISSION EROR"); + return MEDIA_CONTENT_ERROR_PERMISSION_DENIED; + } else { + media_content_error("OTHER ERROR"); return MEDIA_CONTENT_ERROR_DB_FAILED; + } } } else @@ -657,32 +679,44 @@ int media_content_connect(void) { int ret = MEDIA_CONTENT_ERROR_NONE; - if (!db_mutex) - db_mutex = g_mutex_new(); - - if (db_mutex != NULL) { - g_mutex_lock(db_mutex); - - media_content_debug("ref count : %d", ref_count); + if (g_mutex_trylock(&db_mutex)) { + media_content_info("ref count : %d", ref_count); if(ref_count == 0) { if(db_handle == NULL) { - ret = media_svc_connect(&db_handle,tzplatform_getuid(TZ_USER_NAME)); - } - - ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret); - - if(ret == MEDIA_CONTENT_ERROR_NONE) { ret = __media_content_create_attribute_handle(); + if(ret == MEDIA_CONTENT_ERROR_NONE) { + ret = media_svc_connect(&db_handle,tzplatform_getuid(TZ_USER_NAME)); + ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret); + if(ret == MEDIA_CONTENT_ERROR_NONE) { + ref_count++; + //__media_content_create_collate(); + } else { + __media_content_destroy_attribute_handle(); + } + } else { + media_content_error("Internal DB Connection Error"); + } + } else { + media_content_error("Wrong DB Connection status"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; + } + } else { + if(db_handle != NULL) { + ref_count++; + } else { + media_content_error("Wrong DB Handle status"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; } } - ref_count++; - g_mutex_unlock(db_mutex); + media_content_info("ref count changed to: %d", ref_count); + g_mutex_unlock(&db_mutex); } else { media_content_error("mutex is NULL"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; } return ret; @@ -692,18 +726,21 @@ int media_content_disconnect(void) { int ret = MEDIA_CONTENT_ERROR_NONE; - if (db_mutex != NULL) { - g_mutex_lock(db_mutex); - + if (g_mutex_trylock(&db_mutex)) { media_content_debug("ref count : %d", ref_count); if(ref_count > 0) { - ref_count--; + if(db_handle != NULL) { + ref_count--; + } else { + media_content_error("Wrong DB Handle status"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; + } } else { media_content_error("DB_FAILED(0x%08x) database is not connected", MEDIA_CONTENT_ERROR_DB_FAILED); - g_mutex_unlock(db_mutex); + g_mutex_unlock(&db_mutex); return MEDIA_CONTENT_ERROR_DB_FAILED; } @@ -716,78 +753,101 @@ int media_content_disconnect(void) if(ret == MEDIA_CONTENT_ERROR_NONE) { ret = __media_content_destroy_attribute_handle(); db_handle = NULL; + } else { + media_content_error("database disconnect fail"); + ref_count++; } + } else { + media_content_error("Wrong DB Handle status"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; } - g_mutex_unlock(db_mutex); - g_mutex_free(db_mutex); - db_mutex = NULL; + g_mutex_unlock(&db_mutex); + + media_content_info("ref count changed to: %d", ref_count); return ret; } - g_mutex_unlock(db_mutex); + g_mutex_unlock(&db_mutex); } else { media_content_error("mutex is NULL"); + ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION; } + media_content_info("ref count changed to: %d", ref_count); + return ret; } int media_content_scan_file(const char *path) { int ret = MEDIA_CONTENT_ERROR_NONE; + bool ignore_dir = FALSE; + char *folder_path = NULL; + int check_file = MEDIA_CONTENT_ERROR_NONE; if (!STRING_VALID(path)) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } - media_content_debug("Path : %s", path); + media_content_sec_debug("Path : %s", path); + + check_file = _media_util_check_file(path); + if (check_file == MEDIA_CONTENT_ERROR_NONE) { + /* This means this path has to be inserted or refreshed */ + folder_path = g_path_get_dirname(path); + ret = _media_util_check_ignore_dir(folder_path, &ignore_dir); + SAFE_FREE(folder_path); + + if(ignore_dir) { + media_content_error("Invalid folder path"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } - if (g_file_test(path, G_FILE_TEST_EXISTS)) { - if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { - /* This means this path has to be inserted or refreshed */ - media_content_debug("This path exists in file system."); + media_svc_storage_type_e storage_type; - media_svc_storage_type_e storage_type; + ret = media_svc_get_storage_type(path, &storage_type); + if(ret != MS_MEDIA_ERR_NONE) { + media_content_sec_error("media_svc_get_storage_type failed : %d (%s)", ret, path); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } - ret = media_svc_get_storage_type(path, &storage_type); - if (ret < 0) { - media_content_error("media_svc_get_storage_type failed : %d (%s)", ret, path); + ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), path); + if (ret == MS_MEDIA_ERR_NONE) { + /* Refresh */ + ret = media_svc_refresh_item(_content_get_db_handle(), storage_type, "media", path,tzplatform_getuid(TZ_USER_NAME)); + if(ret != MS_MEDIA_ERR_NONE) { + media_content_error("media_svc_refresh_item failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), path); - if (ret == MS_MEDIA_ERR_NONE) { - /* Refresh */ - ret = media_svc_refresh_item(_content_get_db_handle(), storage_type, path, tzplatform_getuid(TZ_USER_NAME)); - if (ret < 0) { - media_content_error("media_svc_refresh_item failed : %d", ret); - return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) { + /* Insert */ + ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_type, path,tzplatform_getuid(TZ_USER_NAME)); + if(ret != MS_MEDIA_ERR_NONE) { + if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) { + media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path); + ret = MEDIA_CONTENT_ERROR_NONE; + } else { + media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path); } - } else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) { - /* Insert */ - ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_type, path, tzplatform_getuid(TZ_USER_NAME)); - if (ret < 0) { - media_content_error("media_svc_insert_item_immediately failed : %d", ret); - return _content_error_capi(MEDIA_CONTENT_TYPE, ret); - } - } else { - media_content_error("media_svc_check_item_exist_by_path failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - } else if (g_file_test(path, G_FILE_TEST_IS_DIR)) { - /* Dierectory is not accpted in this function */ - media_content_error("This path is directory"); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } else { + media_content_error("media_svc_check_item_exist_by_path failed : %d", ret); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } + } else if (check_file == MEDIA_CONTENT_ERROR_PERMISSION_DENIED) { + media_content_error("You have no permission for this file %d", ret); + return MEDIA_CONTENT_ERROR_PERMISSION_DENIED; } else { /* This means this path has to be deleted */ media_content_debug("This path doesn't exists in file system... So now start to delete it from DB"); - ret = media_svc_delete_item_by_path(_content_get_db_handle(), path, tzplatform_getuid(TZ_USER_NAME)); - if (ret < 0) { + ret = media_svc_delete_item_by_path(_content_get_db_handle(), "media", path, tzplatform_getuid(TZ_USER_NAME)); + if(ret != MS_MEDIA_ERR_NONE) { media_content_error("media_svc_delete_item_by_path failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } @@ -819,7 +879,8 @@ static int __media_content_check_dir(const char *path) dp = opendir(path); if (dp == NULL) { - media_content_error("error [%s, %s]", path, strerror(errno)); + media_content_sec_error("path [%s]", path); + media_content_stderror("open dir fail"); if (errno == EACCES || errno == EPERM) { return MEDIA_CONTENT_ERROR_PERMISSION_DENIED; } else { @@ -832,6 +893,7 @@ static int __media_content_check_dir(const char *path) return MEDIA_CONTENT_ERROR_NONE; } + int media_content_scan_folder(const char *path, bool is_recursive, media_scan_completed_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -852,10 +914,11 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co if (ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED) { return ret; } + media_content_scan_cb_data *cb_data = NULL; cb_data = (media_content_scan_cb_data *)malloc(sizeof(media_content_scan_cb_data)); if (cb_data == NULL) { - media_content_error("malloc failed"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; } @@ -863,7 +926,19 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co cb_data->user_data = user_data; ret = media_directory_scanning_async(path, is_recursive, _media_content_scan_cb, cb_data, tzplatform_getuid(TZ_USER_NAME)); - if (ret < 0) { + if(ret != MS_MEDIA_ERR_NONE) { + media_content_error("media_directory_scanning_async failed : %d", ret); + } + + return _content_error_capi(MEDIA_REGISTER_TYPE, ret); +} + +int media_content_cancel_scan_folder(const char *path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + //ret = media_directory_scanning_cancel(path); + if(ret != MS_MEDIA_ERR_NONE) { media_content_error("media_directory_scanning_async failed : %d", ret); } @@ -897,6 +972,16 @@ int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *u { int ret = MEDIA_CONTENT_ERROR_NONE; + if (callback == NULL) { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if (g_noti_info != NULL) { + media_content_error("Noti callback is alreay set"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + g_noti_info = (media_noti_cb_s*)calloc(1, sizeof(media_noti_cb_s)); if (g_noti_info == NULL) { media_content_error("Failed to create noti info"); @@ -911,7 +996,7 @@ int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *u return _content_error_capi(MEDIA_REGISTER_TYPE, ret); } -int media_content_unset_db_updated_cb() +int media_content_unset_db_updated_cb(void) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -920,4 +1005,3 @@ int media_content_unset_db_updated_cb() return _content_error_capi(MEDIA_REGISTER_TYPE, ret); } - diff --git a/src/media_db.c b/src/media_db.c index abf4919..7ce4e92 100755 --- a/src/media_db.c +++ b/src/media_db.c @@ -19,6 +19,7 @@ #include static char * __media_db_get_group_name(media_group_e group); +static int __media_db_make_query(filter_h filter, attribute_h attr, char *select_query, int select_query_size, char **condition_query, char **option_query); static char * __media_db_get_group_name(media_group_e group) { @@ -89,22 +90,60 @@ static char * __media_db_get_group_name(media_group_e group) return NULL; } +static int __media_db_make_query(filter_h filter, attribute_h attr, char *select_query, int select_query_size, char **condition_query, char **option_query) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_s *_filter = NULL; + + if(filter != NULL) + { + _filter = (filter_s*)filter; + + if(STRING_VALID(_filter->condition)) + { + /*bracket should be added to condition. If application use "OR" condition, F/W restriction condition like "validity=1" is disregared + ex) select path from media where validity=1 and media_type=3 or media_type=1;*/ + char bracket_added_condition[MAX_QUERY_SIZE] = {0, }; + memset(bracket_added_condition, 0x00, sizeof(bracket_added_condition)); + + SAFE_STRLCAT(bracket_added_condition, QUERY_KEYWORD_OPEN_BRACKET, MAX_QUERY_SIZE); + SAFE_STRLCAT(bracket_added_condition, _filter->condition, MAX_QUERY_SIZE); + SAFE_STRLCAT(bracket_added_condition, QUERY_KEYWORD_BRACKET, MAX_QUERY_SIZE); + { + ret = _media_filter_attribute_generate(attr, bracket_added_condition, _filter->condition_collate_type, condition_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + } + } + + ret = _media_filter_attribute_option_generate(attr, filter, option_query); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + SAFE_FREE(*condition_query); + return ret; + } + + if(STRING_VALID(*condition_query)) + { + SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, select_query_size); + SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, select_query_size); + } + } + + return ret; +} + int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; - char select_query[DEFAULT_QUERY_SIZE]; + char select_query[MAX_QUERY_SIZE] = {0, }; char *condition_query = NULL; char *option_query = NULL; - attribute_h attr; - - media_content_debug_func(); - - memset(select_query, 0x00, sizeof(select_query)); + attribute_h attr = NULL; + filter_s *_filter = (filter_s*)filter; attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); switch(group_type) { case MEDIA_GROUP_NONE: @@ -117,26 +156,28 @@ int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *gro break; case MEDIA_GROUP_ALBUM: attr = _content_get_alias_attirbute_handle(); - //snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT); - if(!SAFE_STRLCPY(select_query, SELECT_ALBUM_COUNT, sizeof(select_query))) - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_ALBUM_COUNT, DB_TABLE_MEDIA_VIEW); break; case MEDIA_GROUP_FOLDER: attr = _content_get_alias_attirbute_handle(); - //snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT); if(!SAFE_STRLCPY(select_query, SELECT_FOLDER_COUNT, sizeof(select_query))) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } + + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT_BY_STORAGE_ID, _filter->storage_id, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT, DB_TABLE_MEDIA_VIEW); + break; case MEDIA_GROUP_PLAYLIST: - //attr = _content_get_alias_attirbute_handle(); - //snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_COUNT); if(!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_COUNT, sizeof(select_query))) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -144,8 +185,6 @@ int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *gro } break; case MEDIA_GROUP_TAG: - //attr = _content_get_alias_attirbute_handle(); - //snprintf(select_query, sizeof(select_query), SELECT_TAG_COUNT); if(!SAFE_STRLCPY(select_query, SELECT_TAG_COUNT, sizeof(select_query))) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -154,8 +193,15 @@ int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *gro break; case MEDIA_GROUP_BOOKMARK: attr = _content_get_alias_attirbute_handle(); - //snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT); - if(!SAFE_STRLCPY(select_query, SELECT_BOOKMARK_COUNT, sizeof(select_query))) + + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT, DB_TABLE_MEDIA_VIEW); + + break; + case MEDIA_GROUP_STORAGE: + if(!SAFE_STRLCPY(select_query, SELECT_STORAGE_COUNT, sizeof(select_query))) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; @@ -163,29 +209,8 @@ int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *gro break; } - if(filter != NULL) - { - _filter = (filter_s*)filter; - - if(STRING_VALID(_filter->condition)) - { - ret = _media_filter_attribute_generate(attr, _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - } - - ret = _media_filter_attribute_option_generate(attr, filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - SAFE_FREE(condition_query); - return ret; - } - - if(STRING_VALID(condition_query)) - { - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); - } - } + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); @@ -195,64 +220,44 @@ int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *gro while(sqlite3_step(stmt) == SQLITE_ROW) { *group_count = (int)sqlite3_column_int(stmt, 0); - media_content_debug("group count : [%d]", *group_count); } SQLITE3_FINALIZE(stmt); + return ret; } int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; - char select_query[DEFAULT_QUERY_SIZE]; + char select_query[MAX_QUERY_SIZE] = {0, }; char *condition_query = NULL; char *option_query = NULL; + attribute_h attr = NULL; + filter_s *_filter = (filter_s*)filter; - media_content_debug_func(); - + attr = _content_get_attirbute_handle(); memset(select_query, 0x00, sizeof(select_query)); - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group)); - - if(filter != NULL) - { - _filter = (filter_s*)filter; - - if(STRING_VALID(_filter->condition)) - { - ret = _media_filter_attribute_generate(_content_get_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - } - - ret = _media_filter_attribute_option_generate(_content_get_attirbute_handle(), filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - SAFE_FREE(condition_query); - return ret; - } - - if(STRING_VALID(condition_query)) - { - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); - } - - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - if(STRING_VALID(condition_query)) - SAFE_STRLCAT(select_query, condition_query, sizeof(select_query)); - if(STRING_VALID(option_query)) - SAFE_STRLCAT(select_query, option_query, sizeof(select_query)); + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group), DB_TABLE_MEDIA_VIEW); - SAFE_FREE(condition_query); - SAFE_FREE(option_query); - } + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); + if(STRING_VALID(condition_query)) + SAFE_STRLCAT(select_query, condition_query, sizeof(select_query)); + if(STRING_VALID(option_query)) + SAFE_STRLCAT(select_query, option_query, sizeof(select_query)); SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query)); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); SAFE_FREE(option_query); @@ -261,51 +266,34 @@ int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *g while(sqlite3_step(stmt) == SQLITE_ROW) { *group_count = (int)sqlite3_column_int(stmt, 0); - media_content_debug("group count : [%d]", *group_count); } SQLITE3_FINALIZE(stmt); + return ret; } int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; - char select_query[DEFAULT_QUERY_SIZE]; + char select_query[MAX_QUERY_SIZE] = {0, }; char *condition_query = NULL; char *option_query = NULL; char *name = NULL; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; + attribute_h attr = NULL; + filter_s *_filter = (filter_s*)filter; + attr = _content_get_attirbute_handle(); memset(select_query, 0x00, sizeof(select_query)); - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group)); - - if(filter != NULL) - { - _filter = (filter_s*)filter; - - if(_filter->condition) - { - ret = _media_filter_attribute_generate(_content_get_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - } - - ret = _media_filter_attribute_option_generate(_content_get_attirbute_handle(), filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - SAFE_FREE(condition_query); - return ret; - } + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group), DB_TABLE_MEDIA_VIEW); - if(STRING_VALID(condition_query)) - { - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); - } - } + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); @@ -317,7 +305,6 @@ int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_ if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) { name = strdup((const char *)sqlite3_column_text(stmt, 0)); - media_content_debug("group name : [%s]", name); } if(callback(name, user_data) == false) @@ -330,51 +317,30 @@ int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_ } SQLITE3_FINALIZE(stmt); + return ret; } int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; - char select_query[DEFAULT_QUERY_SIZE]; + char select_query[MAX_QUERY_SIZE] = {0, }; char *condition_query = NULL; char *option_query = NULL; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; + attribute_h attr = NULL; + filter_s *_filter = (filter_s*)filter; + attr = _content_get_alias_attirbute_handle(); memset(select_query, 0x00, sizeof(select_query)); - //snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST); - if(!SAFE_STRLCPY(select_query, SELECT_ALBUM_LIST, sizeof(select_query))) - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - if(filter != NULL) - { - _filter = (filter_s*)filter; - - if(_filter->condition) - { - ret = _media_filter_attribute_generate(_content_get_alias_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - } - - ret = _media_filter_attribute_option_generate(_content_get_alias_attirbute_handle(), filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - SAFE_FREE(condition_query); - return ret; - } + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_ALBUM_LIST, DB_TABLE_MEDIA_VIEW); - if(STRING_VALID(condition_query)) - { - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); - } - } + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); @@ -413,54 +379,33 @@ int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_dat } SQLITE3_FINALIZE(stmt); + return ret; } int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; - char select_query[DEFAULT_QUERY_SIZE]; + char select_query[MAX_QUERY_SIZE] = {0, }; char *condition_query = NULL; char *option_query = NULL; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; - + attribute_h attr = NULL; + filter_s *_filter = (filter_s*)filter; + attr = _content_get_alias_attirbute_handle(); memset(select_query, 0x00, sizeof(select_query)); - //snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST); - if(!SAFE_STRLCPY(select_query, SELECT_FOLDER_LIST, sizeof(select_query))) - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - if(filter != NULL) - { - _filter = (filter_s*)filter; - - if(_filter->condition) - { - ret = _media_filter_attribute_generate(_content_get_alias_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - } - - ret = _media_filter_attribute_option_generate(_content_get_alias_attirbute_handle(), filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - SAFE_FREE(condition_query); - return ret; - } + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST_BY_STORAGE_ID, _filter->storage_id, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_FOLDER_LIST, DB_TABLE_MEDIA_VIEW); - if(STRING_VALID(condition_query)) - { - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); - } - } + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + SAFE_FREE(condition_query); SAFE_FREE(option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -485,9 +430,14 @@ int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_d if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) _folder->name = strdup((const char *)sqlite3_column_text(stmt, 2)); - _folder->storage_type = (int)sqlite3_column_int(stmt,3); + _folder->storage_type = (int)sqlite3_column_int(stmt, 3); - _folder->modified_time = (int)sqlite3_column_int(stmt,4); + _folder->modified_time = (int)sqlite3_column_int(stmt, 4); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 5))) + _folder->storage_uuid = strdup((const char *)sqlite3_column_text(stmt, 5)); + + _folder->folder_order = (int)sqlite3_column_int(stmt, 6); if(callback((media_folder_h)_folder, user_data) == false) { @@ -499,54 +449,30 @@ int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_d } SQLITE3_FINALIZE(stmt); + return ret; } int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; - char select_query[DEFAULT_QUERY_SIZE]; + char select_query[MAX_QUERY_SIZE] = {0, }; char *condition_query = NULL; char *option_query = NULL; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; + attribute_h attr = NULL; + attr = _content_get_attirbute_handle(); memset(select_query, 0x00, sizeof(select_query)); - //snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_LIST); if(!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_LIST, sizeof(select_query))) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } - - if(filter != NULL) - { - _filter = (filter_s*)filter; - - if(_filter->condition) - { - //ret = _media_filter_attribute_generate(_content_get_alias_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - ret = _media_filter_attribute_generate(_content_get_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - } - - //ret = _media_filter_attribute_option_generate(_content_get_alias_attirbute_handle(), filter, &option_query); - ret = _media_filter_attribute_option_generate(_content_get_attirbute_handle(), filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - SAFE_FREE(condition_query); - return ret; - } - - if(STRING_VALID(condition_query)) - { - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); - } - } + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); @@ -581,48 +507,27 @@ int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *us } SQLITE3_FINALIZE(stmt); + return ret; } int _media_db_get_playlist_item(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; - char select_query[DEFAULT_QUERY_SIZE]; + char select_query[MAX_QUERY_SIZE] = {0, }; char *condition_query = NULL; char *option_query = NULL; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; + attribute_h attr = NULL; + attr = _content_get_attirbute_handle(); memset(select_query, 0x00, sizeof(select_query)); - snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_VIEW, playlist_id); - - if(filter != NULL) - { - _filter = (filter_s*)filter; - - if(_filter->condition) - { - //ret = _media_filter_attribute_generate(_content_get_alias_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - ret = _media_filter_attribute_generate(_content_get_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - } - - //ret = _media_filter_attribute_option_generate(_content_get_alias_attirbute_handle(), filter, &option_query); - ret = _media_filter_attribute_option_generate(_content_get_attirbute_handle(), filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - SAFE_FREE(condition_query); - return ret; - } + //snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_VIEW, playlist_id); + snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_ITEM_ALL_FROM_PLAYLIST_VIEW, playlist_id); - if(STRING_VALID(condition_query)) - { - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); - } - } + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); @@ -632,48 +537,47 @@ int _media_db_get_playlist_item(int playlist_id, filter_h filter, playlist_membe while(sqlite3_step(stmt) == SQLITE_ROW) { int playlist_member_id = 0; - char media_uuid[MEDIA_CONTENT_UUID_SIZE+1]; - media_info_h media = NULL; - memset(media_uuid, 0x00, sizeof(media_uuid)); + playlist_member_id = (int)sqlite3_column_int(stmt, MEDIA_INFO_ITEM_MAX); //MEDIA_INFO_ITEM_MAX is pm_id - playlist_member_id = (int)sqlite3_column_int(stmt, 0); + media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s)); - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) - strncpy(media_uuid, (const char *)sqlite3_column_text(stmt, 1), MEDIA_CONTENT_UUID_SIZE); + if(_media == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } - ret = media_info_get_media_from_db(media_uuid, &media); + _media_info_item_get_detail(stmt, (media_info_h)_media); - if(callback(playlist_member_id, media, user_data) == false) + if(callback(playlist_member_id, (media_info_h)_media, user_data) == false) { - media_info_destroy(media); + media_info_destroy((media_info_h)_media); break; } - media_info_destroy(media); + media_info_destroy((media_info_h)_media); + } SQLITE3_FINALIZE(stmt); + return ret; } -//same as _media_db_get_playlist int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; - char select_query[DEFAULT_QUERY_SIZE]; + char select_query[MAX_QUERY_SIZE] = {0, }; char *condition_query = NULL; char *option_query = NULL; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; - attribute_h attr; + attribute_h attr = NULL; + attr = _content_get_attirbute_handle(); memset(select_query, 0x00, sizeof(select_query)); if(!STRING_VALID(media_id)) { - //attr = _content_get_alias_attirbute_handle(); - attr = _content_get_attirbute_handle(); - //snprintf(select_query, sizeof(select_query), SELECT_TAG_LIST); if(!SAFE_STRLCPY(select_query, SELECT_TAG_LIST, sizeof(select_query))) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -682,35 +586,13 @@ int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callba } else { - attr = _content_get_attirbute_handle(); snprintf(select_query, sizeof(select_query), SELECT_TAG_LIST_BY_MEDIA_ID, media_id); } - if(filter != NULL) - { - _filter = (filter_s*)filter; + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - if(_filter->condition) - { - ret = _media_filter_attribute_generate(attr, _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - } - - ret = _media_filter_attribute_option_generate(attr, filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - SAFE_FREE(condition_query); - return ret; - } - - if(STRING_VALID(condition_query)) - { - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); - } - } - - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); + SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); @@ -742,61 +624,31 @@ int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callba } SQLITE3_FINALIZE(stmt); + return ret; } int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; - char select_query[DEFAULT_QUERY_SIZE]; + char select_query[MAX_QUERY_SIZE] = {0, }; char *condition_query = NULL; char *option_query = NULL; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; - attribute_h attr; + attribute_h attr = NULL; + filter_s *_filter = (filter_s*)filter; + + attr = _content_get_attirbute_handle(); memset(select_query, 0x00, sizeof(select_query)); - if(!STRING_VALID(media_id)) - { - attr = _content_get_alias_attirbute_handle(); - //snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST); - if(!SAFE_STRLCPY(select_query, SELECT_BOOKMARK_LIST, sizeof(select_query))) - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - } + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_MEDIA_ID, _filter->storage_id, media_id); else - { - attr = _content_get_attirbute_handle(); - snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_MEDIA_ID_USUAL, media_id); - } - - if(filter != NULL) - { - _filter = (filter_s*)filter; - - if(_filter->condition) - { - ret = _media_filter_attribute_generate(attr, _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - } - - ret = _media_filter_attribute_option_generate(attr, filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - SAFE_FREE(condition_query); - return ret; - } + snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_MEDIA_ID, DB_TABLE_MEDIA_VIEW, media_id); - if(STRING_VALID(condition_query)) - { - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); - } - } + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); @@ -834,6 +686,7 @@ int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark } SQLITE3_FINALIZE(stmt); + return ret; } @@ -841,32 +694,29 @@ int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; - char select_query[DEFAULT_QUERY_SIZE]; + char select_query[MAX_QUERY_SIZE] = {0, }; char *condition_query = NULL; char *option_query = NULL; attribute_h attr = NULL; + filter_s *_filter = (filter_s*)filter; - media_content_debug_func(); - + attr = _content_get_attirbute_handle(); memset(select_query, 0x00, sizeof(select_query)); if(group_type == MEDIA_GROUP_ALBUM) { - attr = _content_get_attirbute_handle(); - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, group_id); + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, _filter->storage_id, group_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, DB_TABLE_MEDIA_VIEW, group_id); } else if(group_type == MEDIA_GROUP_PLAYLIST) { - //attr = _content_get_alias_attirbute_handle(); - attr = _content_get_attirbute_handle(); snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_PLAYLIST, group_id); } else if(group_type == MEDIA_GROUP_TAG) { - attr = _content_get_attirbute_handle(); snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_TAG, group_id); } else @@ -875,45 +725,8 @@ int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_li return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } - if(filter != NULL) - { - _filter = (filter_s*)filter; - - if(_filter->condition) - { - ret = _media_filter_attribute_generate(attr, _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - } - - ret = _media_filter_attribute_option_generate(attr, filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - SAFE_FREE(condition_query); - return ret; - } - - if(STRING_VALID(condition_query)) - { - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); - } - } -/* - if((group_type == MEDIA_GROUP_PLAYLIST) || (group_type == MEDIA_GROUP_TAG)) - { - strncat(select_query, QUERY_KEYWORD_SPACE, strlen(QUERY_KEYWORD_SPACE)); - - if(STRING_VALID(condition_query)) - strncat(select_query, condition_query, strlen(condition_query)); - if(STRING_VALID(option_query)) - strncat(select_query, option_query, strlen(option_query)); - - strncat(select_query, QUERY_KEYWORD_BRACKET, strlen(QUERY_KEYWORD_BRACKET)); - - SAFE_FREE(condition_query); - SAFE_FREE(option_query); - } -*/ + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); @@ -923,55 +736,70 @@ int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_li while(sqlite3_step(stmt) == SQLITE_ROW) { *item_count = (int)sqlite3_column_int(stmt, 0); - media_content_debug("group item count : [%d]", *item_count); } SQLITE3_FINALIZE(stmt); + return ret; } int _media_db_get_group_item_count(const char *group_name, filter_h filter, group_list_e group_type, int *item_count) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; - char complete_select_query[DEFAULT_QUERY_SIZE]; - char *select_query = NULL; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *tmp_query = NULL; char *condition_query = NULL; char *option_query = NULL; bool is_simple = FALSE; + attribute_h attr = NULL; + filter_s *_filter = (filter_s*)filter; - media_content_debug_func(); + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); if(group_type == MEDIA_GROUP_NONE) { - /* There are 2 ways to get count for media table for performance + /* There are 2 ways to get count for media table for performance If user wants to set offset and count, use SQL SELECT_MEDIA_COUNT_FROM_MEDIA. If user wants to get count without setting count, SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE */ - _filter = (filter_s *)filter; - if (_filter) { - if ((_filter->offset < 0) && (_filter->count < 0)) { - select_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE); + if (_filter && ((_filter->offset < 0) && (_filter->count < 0))) { + if(STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, DB_TABLE_MEDIA_VIEW); is_simple = TRUE; - } else { - select_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_MEDIA); - } } else { - select_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_MEDIA); + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_MEDIA, DB_TABLE_MEDIA_VIEW); } } else if(group_type == MEDIA_GROUP_FOLDER) { - select_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, group_name); + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, _filter->storage_id, group_name); + else + tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, DB_TABLE_MEDIA_VIEW, group_name); + + SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); } else if(group_type == MEDIA_GROUP_TAG_BY_MEDIA_ID) { - select_query = sqlite3_mprintf(SELECT_TAG_COUNT_BY_MEDIA_ID, group_name); + snprintf(select_query, sizeof(select_query), SELECT_TAG_COUNT_BY_MEDIA_ID, group_name); } else if(group_type == MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID) { - select_query = sqlite3_mprintf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, group_name); + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + tmp_query = sqlite3_mprintf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, _filter->storage_id, group_name); + else + tmp_query = sqlite3_mprintf(SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, DB_TABLE_MEDIA_VIEW, group_name); + + SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); + } + else if(group_type == MEDIA_GROUP_STORAGE) + { + tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_STORAGE, group_name, group_name); + + SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); } else { @@ -979,57 +807,32 @@ int _media_db_get_group_item_count(const char *group_name, filter_h filter, grou return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } - if(filter != NULL) + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + if(ret != MEDIA_CONTENT_ERROR_NONE) { - _filter = (filter_s*)filter; - - if(_filter->condition) - { - ret = _media_filter_attribute_generate(_content_get_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - sqlite3_free(select_query); - return ret; - } - } - - ret = _media_filter_attribute_option_generate(_content_get_attirbute_handle(), filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - sqlite3_free(select_query); - SAFE_FREE(condition_query); - return ret; - } - - if(STRING_VALID(condition_query)) - { - snprintf(complete_select_query, sizeof(complete_select_query), "%s %s", select_query, QUERY_KEYWORD_AND); - } - else - { - snprintf(complete_select_query, sizeof(complete_select_query), "%s", select_query); - } - } else { - snprintf(complete_select_query, sizeof(complete_select_query), "%s", select_query); + if(tmp_query != NULL) + sqlite3_free(tmp_query); + return ret; } if(group_type == MEDIA_GROUP_NONE) { - SAFE_STRLCAT(complete_select_query, QUERY_KEYWORD_SPACE, sizeof(complete_select_query)); + SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); if(STRING_VALID(condition_query)) - SAFE_STRLCAT(complete_select_query, condition_query, sizeof(complete_select_query)); + SAFE_STRLCAT(select_query, condition_query, sizeof(select_query)); if(STRING_VALID(option_query)) - SAFE_STRLCAT(complete_select_query, option_query, sizeof(complete_select_query)); + SAFE_STRLCAT(select_query, option_query, sizeof(select_query)); if (!is_simple) - SAFE_STRLCAT(complete_select_query, QUERY_KEYWORD_BRACKET, sizeof(complete_select_query)); + SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query)); SAFE_FREE(condition_query); SAFE_FREE(option_query); } - ret = _content_query_prepare(&stmt, complete_select_query, condition_query, option_query); - sqlite3_free(select_query); + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + if(tmp_query != NULL) + sqlite3_free(tmp_query); SAFE_FREE(condition_query); SAFE_FREE(option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -1037,36 +840,46 @@ int _media_db_get_group_item_count(const char *group_name, filter_h filter, grou while(sqlite3_step(stmt) == SQLITE_ROW) { *item_count = (int)sqlite3_column_int(stmt, 0); - media_content_debug("group item count : [%d]", *item_count); } SQLITE3_FINALIZE(stmt); + return ret; } int _media_db_get_group_item_by_id(int group_id, filter_h filter, media_info_cb callback, void *user_data, group_list_e group_type) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; - char select_query[DEFAULT_QUERY_SIZE]; + char select_query[MAX_QUERY_SIZE] = {0, }; char *condition_query = NULL; char *option_query = NULL; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; + attribute_h attr = NULL; + filter_s *_filter = (filter_s*)filter; + attr = _content_get_attirbute_handle(); memset(select_query, 0x00, sizeof(select_query)); if(group_type == MEDIA_GROUP_ALBUM) { - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM, group_id); + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM, _filter->storage_id, group_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM, DB_TABLE_MEDIA_VIEW, group_id); } else if(group_type == MEDIA_GROUP_PLAYLIST) { - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_PLAYLIST, group_id); + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_PLAYLIST, _filter->storage_id, group_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_PLAYLIST, DB_TABLE_MEDIA_VIEW, group_id); } else if(group_type == MEDIA_GROUP_TAG) { - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_TAG, group_id); + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_TAG, _filter->storage_id, group_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_TAG, DB_TABLE_MEDIA_VIEW, group_id); } else { @@ -1074,29 +887,8 @@ int _media_db_get_group_item_by_id(int group_id, filter_h filter, media_info_cb return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } - if(filter != NULL) - { - _filter = (filter_s*)filter; - - if(_filter->condition) - { - ret = _media_filter_attribute_generate(_content_get_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - } - - ret = _media_filter_attribute_option_generate(_content_get_attirbute_handle(), filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - SAFE_FREE(condition_query); - return ret; - } - - if(STRING_VALID(condition_query)) - { - SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); - SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, sizeof(select_query)); - } - } + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); @@ -1125,31 +917,40 @@ int _media_db_get_group_item_by_id(int group_id, filter_h filter, media_info_cb } SQLITE3_FINALIZE(stmt); + return ret; } int _media_db_get_group_item(const char *group_name, filter_h filter, media_info_cb callback, void *user_data, group_list_e group_type) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; - char complete_select_query[DEFAULT_QUERY_SIZE]; - char *select_query = NULL; + char select_query[MAX_QUERY_SIZE] = {0, }; char *condition_query = NULL; char *option_query = NULL; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; + attribute_h attr = NULL; + filter_s *_filter = (filter_s*)filter; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); if(group_type == MEDIA_GROUP_NONE) { - select_query = sqlite3_mprintf(SELECT_MEDIA_ITEM); + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_ITEM, _filter->storage_id); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_ITEM, DB_TABLE_MEDIA_VIEW); } else if(group_type == MEDIA_GROUP_FOLDER) { - select_query = sqlite3_mprintf(SELECT_MEDIA_FROM_FOLDER, group_name); + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_FOLDER, _filter->storage_id, group_name); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_FOLDER, DB_TABLE_MEDIA_VIEW, group_name); } - else if(group_type == MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID) + else if(group_type == MEDIA_GROUP_STORAGE) { - select_query = sqlite3_mprintf(SELECT_BOOKMARK_LIST_BY_MEDIA_ID, group_name); + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_STORAGE, group_name, group_name); } else { @@ -1157,42 +958,10 @@ int _media_db_get_group_item(const char *group_name, filter_h filter, media_info return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } - if(filter != NULL) - { - _filter = (filter_s*)filter; - - if(_filter->condition) - { - ret = _media_filter_attribute_generate(_content_get_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - sqlite3_free(select_query); - return ret; - } - } - - ret = _media_filter_attribute_option_generate(_content_get_attirbute_handle(), filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - sqlite3_free(select_query); - SAFE_FREE(condition_query); - return ret; - } - - if(STRING_VALID(condition_query)) - { - snprintf(complete_select_query, sizeof(complete_select_query), "%s %s", select_query, QUERY_KEYWORD_AND); - } - else - { - snprintf(complete_select_query, sizeof(complete_select_query), "%s", select_query); - } - } else { - snprintf(complete_select_query, sizeof(complete_select_query), "%s", select_query); - } + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - ret = _content_query_prepare(&stmt, complete_select_query, condition_query, option_query); - sqlite3_free(select_query); + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); SAFE_FREE(option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -1219,74 +988,66 @@ int _media_db_get_group_item(const char *group_name, filter_h filter, media_info } SQLITE3_FINALIZE(stmt); + return ret; } -int _media_db_get_media_group_item_count(const char *group_name, media_group_e group, filter_h filter, int *item_count) +int _media_db_get_media_group_item_count(const char *group_name, filter_h filter, media_group_e group, int *item_count) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; - char complete_select_query[DEFAULT_QUERY_SIZE]; - char *select_query = NULL; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *tmp_query = NULL; char *condition_query = NULL; char *option_query = NULL; + attribute_h attr = NULL; + filter_s *_filter = (filter_s*)filter; - media_content_debug_func(); + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); if(group_name != NULL) - select_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, __media_db_get_group_name(group), group_name); - else - select_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP_NULL, __media_db_get_group_name(group)); - - if(filter != NULL) { - _filter = (filter_s*)filter; - - if(_filter->condition) - { - ret = _media_filter_attribute_generate(_content_get_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - sqlite3_free(select_query); - return ret; - } - } - - ret = _media_filter_attribute_option_generate(_content_get_attirbute_handle(), filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - sqlite3_free(select_query); - SAFE_FREE(condition_query); - return ret; - } - - if(STRING_VALID(condition_query)) + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) { - snprintf(complete_select_query, sizeof(complete_select_query), "%s %s", select_query, QUERY_KEYWORD_AND); + tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name); + SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); } else { - snprintf(complete_select_query, sizeof(complete_select_query), "%s", select_query); + tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group), group_name); + SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); } - } else { - snprintf(complete_select_query, sizeof(complete_select_query), "%s", select_query); + } + else + { + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group)); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group)); } - SAFE_STRLCAT(complete_select_query, QUERY_KEYWORD_SPACE, sizeof(complete_select_query)); + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + if(tmp_query != NULL) + sqlite3_free(tmp_query); + return ret; + } + + SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); if(STRING_VALID(condition_query)) - SAFE_STRLCAT(complete_select_query, condition_query, sizeof(complete_select_query)); + SAFE_STRLCAT(select_query, condition_query, sizeof(select_query)); if(STRING_VALID(option_query)) - SAFE_STRLCAT(complete_select_query, option_query, sizeof(complete_select_query)); - - SAFE_STRLCAT(complete_select_query, QUERY_KEYWORD_BRACKET, sizeof(complete_select_query)); + SAFE_STRLCAT(select_query, option_query, sizeof(select_query)); + SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query)); SAFE_FREE(condition_query); SAFE_FREE(option_query); - ret = _content_query_prepare(&stmt, complete_select_query, condition_query, option_query); - sqlite3_free(select_query); + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + if(tmp_query != NULL) + sqlite3_free(tmp_query); SAFE_FREE(condition_query); SAFE_FREE(option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -1294,92 +1055,172 @@ int _media_db_get_media_group_item_count(const char *group_name, media_group_e g while(sqlite3_step(stmt) == SQLITE_ROW) { *item_count = (int)sqlite3_column_int(stmt, 0); - media_content_debug("group item count : [%d]", *item_count); } SQLITE3_FINALIZE(stmt); + return ret; } -int _media_db_get_media_group_item(const char *group_name, media_group_e group, filter_h filter, media_info_cb callback, void *user_data) +int _media_db_get_media_group_item(const char *group_name, filter_h filter, media_group_e group, media_info_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; - char complete_select_query[DEFAULT_QUERY_SIZE]; - char *select_query = NULL; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *tmp_query = NULL; char *condition_query = NULL; char *option_query = NULL; sqlite3_stmt *stmt = NULL; - filter_s *_filter = NULL; + attribute_h attr = NULL; + filter_s *_filter = (filter_s*)filter; - media_content_debug_func(); + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); if(group_name != NULL) - select_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP, __media_db_get_group_name(group), group_name); + { + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + tmp_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP, _filter->storage_id, __media_db_get_group_name(group), group_name); + else + tmp_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group), group_name); + + SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); + } else - select_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP_NULL, __media_db_get_group_name(group)); + { + if((_filter != NULL) && STRING_VALID(_filter->storage_id)) + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, _filter->storage_id, __media_db_get_group_name(group)); + else + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, DB_TABLE_MEDIA_VIEW, __media_db_get_group_name(group)); + } - if(filter != NULL) + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + if(ret != MEDIA_CONTENT_ERROR_NONE) { - _filter = (filter_s*)filter; + if(tmp_query != NULL) + sqlite3_free(tmp_query); + return ret; + } - if(_filter->condition) - { - ret = _media_filter_attribute_generate(_content_get_attirbute_handle(), _filter->condition, _filter->condition_collate_type, &condition_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { - sqlite3_free(select_query); - return ret; - } - } + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + if(tmp_query != NULL) + sqlite3_free(tmp_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - ret = _media_filter_attribute_option_generate(_content_get_attirbute_handle(), filter, &option_query); - if(ret != MEDIA_CONTENT_ERROR_NONE) + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s)); + if(item == NULL) { - sqlite3_free(select_query); - SAFE_FREE(condition_query); - return ret; + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; } - if(STRING_VALID(condition_query)) - { - snprintf(complete_select_query, sizeof(complete_select_query), "%s %s", select_query, QUERY_KEYWORD_AND); - } - else + _media_info_item_get_detail(stmt, (media_info_h)item); + + if(callback((media_info_h)item, user_data) == false) { - snprintf(complete_select_query, sizeof(complete_select_query), "%s", select_query); + media_info_destroy((media_info_h)item); + break; } - } else { - snprintf(complete_select_query, sizeof(complete_select_query), "%s", select_query); + + media_info_destroy((media_info_h)item); } - ret = _content_query_prepare(&stmt, complete_select_query, condition_query, option_query); - sqlite3_free(select_query); + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[DEFAULT_QUERY_SIZE]; + char *condition_query = NULL; + char *option_query = NULL; + sqlite3_stmt *stmt = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + if(!SAFE_STRLCPY(select_query, SELECT_STORAGE_LIST, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); SAFE_FREE(condition_query); SAFE_FREE(option_query); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); while(sqlite3_step(stmt) == SQLITE_ROW) { - media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s)); - if(item == NULL) + media_storage_s *_storage = (media_storage_s*)calloc(1, sizeof(media_storage_s)); + + if(_storage == NULL) { media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); SQLITE3_FINALIZE(stmt); return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; } - _media_info_item_get_detail(stmt, (media_info_h)item); + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) + _storage->storage_id = strdup((const char *)sqlite3_column_text(stmt, 0)); - if(callback((media_info_h)item, user_data) == false) + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + _storage->storage_name = strdup((const char *)sqlite3_column_text(stmt, 1)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) + _storage->storage_path = strdup((const char *)sqlite3_column_text(stmt, 2)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3))) + _storage->storage_account = strdup((const char *)sqlite3_column_text(stmt, 3)); + + _storage->storage_type = (int)sqlite3_column_int(stmt, 4); + + if(callback((media_storage_h)_storage, user_data) == false) { - media_info_destroy((media_info_h)item); + media_storage_destroy((media_storage_h) _storage); break; } - media_info_destroy((media_info_h)item); + media_storage_destroy((media_storage_h) _storage); } SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_storage_id_by_media_id(const char *media_id, char *storage_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char *select_query = NULL; + + select_query = sqlite3_mprintf(SELECT_MEDIA_STORAGE_ID_BY_ID, media_id); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + sqlite3_free(select_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + if(sqlite3_step(stmt) == SQLITE_ROW) + { + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) + strncpy(storage_id, (const char *)sqlite3_column_text(stmt, 0), MEDIA_CONTENT_UUID_SIZE); + } else { + media_content_error("There's no media!!"); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + SQLITE3_FINALIZE(stmt); + return ret; } diff --git a/src/media_filter.c b/src/media_filter.c index 5305c54..4bcaa30 100755 --- a/src/media_filter.c +++ b/src/media_filter.c @@ -15,9 +15,7 @@ */ -#include #include -#include static char *media_token[] = { @@ -54,6 +52,37 @@ static char *__media_filter_replace_attr(attribute_h attr, char *name); static int __tokenize_operator(token_t *token, const char *str, int op_type); static int __tokenize(GList **token_list, const char *str); +static bool __is_pinyin_needed(void) +{ + char *lang = NULL; + char *china = "zh_CN"; + char *hongkong = "zh_HK"; + int ret = FALSE; +#if 0 + /*Check CSC first*/ + bool pinyin_support = FALSE; + media_svc_check_pinyin_support(&pinyin_support); + if(pinyin_support) + { + /*Check Language Setting*/ + lang = vconf_get_str(VCONFKEY_LANGSET); + if (lang == NULL) + { + media_content_error("Fail to get string of language set"); + return ret; + } + if((strncmp(china, lang, strlen(china)) == 0) || + (strncmp(hongkong, lang, strlen(hongkong)) == 0)) + { + ret = TRUE; + } + + SAFE_FREE(lang); + } +#endif + return ret; +} + static char *__get_order_str(media_content_order_e order_enum) { switch(order_enum) { @@ -73,6 +102,11 @@ static char *__get_collate_str(media_content_collation_e collate_type) return "NOCASE"; case MEDIA_CONTENT_COLLATE_RTRIM: return "RTRIM"; + case MEDIA_CONTENT_COLLATE_LOCALIZED: + if(__is_pinyin_needed()) + return "NOCASE"; + else + return "localized"; default: return " "; } } @@ -126,7 +160,7 @@ static int __tokenize_operator(token_t *token, const char *str, int op_type) token->str = (char*)calloc(token_size+1, sizeof(char)); if(token->str == NULL) { - media_content_error("OUT_OF_MEMORY"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return -1; } @@ -152,7 +186,7 @@ static int __tokenize_string(token_t *token, const char *str, int size) token->str = (char*)calloc(size+1, sizeof(char)); if(token->str == NULL) { - media_content_error("OUT_OF_MEMORY"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return -1; } token->type = UNKNOWN_TYPE; @@ -192,10 +226,21 @@ static int __tokenize_attribute(GList **token_list, const char *str) continue; } token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } token->type = UNKNOWN_TYPE; token->str = (char*)calloc(idx+1, sizeof(char)); + if(token->str == NULL) + { + SAFE_FREE(token); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } strncpy(token->str, tmp, idx); - media_content_debug("type : [%d] str : [%s]", token->type, token->str); + //media_content_debug("type : [%d] str : [%s]", token->type, token->str); *token_list = g_list_append(*token_list, token); tmp = tmp +idx + strlen(media_token[0]); idx = -1; @@ -207,14 +252,14 @@ static int __tokenize_attribute(GList **token_list, const char *str) token_t *token = (token_t*)calloc(1, sizeof(token_t)); if(token == NULL) { - media_content_error("OUT_OF_MEMORY"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return -1; } ret = __tokenize_string(token, tmp, idx); if (ret < 0) { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } else @@ -236,7 +281,7 @@ static int __tokenize_attribute(GList **token_list, const char *str) else { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } } @@ -247,7 +292,7 @@ static int __tokenize_attribute(GList **token_list, const char *str) token_t *token = (token_t*)calloc(1, sizeof(token_t)); if(token == NULL) { - media_content_error("OUT_OF_MEMORY"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return -1; } @@ -255,7 +300,7 @@ static int __tokenize_attribute(GList **token_list, const char *str) if (ret < 0) { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } @@ -266,7 +311,7 @@ static int __tokenize_attribute(GList **token_list, const char *str) else { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } } @@ -300,8 +345,19 @@ static int __tokenize(GList **token_list, const char *str) } token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } token->type = UNKNOWN_TYPE; token->str = (char*)calloc(idx+1, sizeof(char)); + if(token->str == NULL) + { + SAFE_FREE(token); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } strncpy(token->str, tmp, idx); //media_content_debug("type : [%d] str : [%s]", token->type, token->str); *token_list = g_list_append(*token_list, token); @@ -322,10 +378,21 @@ static int __tokenize(GList **token_list, const char *str) if(tmp[j] == media_token[1][0]) { token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } token->str = (char*) calloc(j+1+1, sizeof(char)); + if(token->str == NULL) + { + SAFE_FREE(token); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } token->type = STRING_TYPE; strncpy(token->str, tmp, j+1); - media_content_debug("type : [%d] str : [%s], j : %d", token->type, token->str, j); + //media_content_debug("type : [%d] str : [%s], j : %d", token->type, token->str, j); *token_list = g_list_append(*token_list, token); tmp = tmp + strlen(token->str); idx = -1; @@ -337,10 +404,21 @@ static int __tokenize(GList **token_list, const char *str) if(!flag && *tmp != '\0' && tmp[j]=='\0') { token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } token->str = (char*) calloc(j+1,sizeof(char)); + if(token->str == NULL) + { + SAFE_FREE(token); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } token->type = UNKNOWN_TYPE; strncpy(token->str, tmp,j); - media_content_debug("type : [%d] str : [%s]", token->type, token->str); + //media_content_debug("type : [%d] str : [%s]", token->type, token->str); *token_list = g_list_append(*token_list, token); tmp = tmp +strlen(token->str); idx = -1; @@ -360,7 +438,18 @@ static int __tokenize(GList **token_list, const char *str) if(tmp[j] == media_token[2][0]) { token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } token->str = (char*) calloc(j+1+1, sizeof(char)); + if(token->str == NULL) + { + SAFE_FREE(token); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } token->type = STRING_TYPE; strncpy(token->str, tmp, j+1); //media_content_debug("type : [%d] str : [%s]", token->type, token->str); @@ -375,10 +464,21 @@ static int __tokenize(GList **token_list, const char *str) if(!flag && *tmp != '\0' && tmp[j]=='\0') { token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } token->str = (char*) calloc(j+1,sizeof(char)); + if(token->str == NULL) + { + SAFE_FREE(token); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } token->type = UNKNOWN_TYPE; strncpy(token->str, tmp,j); - media_content_debug("type : [%d] str : [%s]", token->type, token->str); + //media_content_debug("type : [%d] str : [%s]", token->type, token->str); *token_list = g_list_append(*token_list, token); tmp = tmp + strlen(token->str); idx = -1; @@ -391,14 +491,14 @@ static int __tokenize(GList **token_list, const char *str) token_t *token = (token_t*)calloc(1, sizeof(token_t)); if(token == NULL) { - media_content_error("OUT_OF_MEMORY"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return -1; } ret = __tokenize_string(token, tmp, idx); if (ret < 0) { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } else @@ -419,7 +519,7 @@ static int __tokenize(GList **token_list, const char *str) else { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } @@ -431,7 +531,7 @@ static int __tokenize(GList **token_list, const char *str) token_t *token = (token_t*)calloc(1, sizeof(token_t)); if(token == NULL) { - media_content_error("OUT_OF_MEMORY"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return -1; } @@ -439,7 +539,7 @@ static int __tokenize(GList **token_list, const char *str) if (ret < 0) { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } else @@ -460,7 +560,7 @@ static int __tokenize(GList **token_list, const char *str) else { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } @@ -472,7 +572,7 @@ static int __tokenize(GList **token_list, const char *str) token_t *token = (token_t*)calloc(1, sizeof(token_t)); if(token == NULL) { - media_content_error("OUT_OF_MEMORY"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return -1; } @@ -480,7 +580,7 @@ static int __tokenize(GList **token_list, const char *str) if (ret < 0) { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } else @@ -501,7 +601,7 @@ static int __tokenize(GList **token_list, const char *str) else { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } @@ -513,7 +613,7 @@ static int __tokenize(GList **token_list, const char *str) token_t *token = (token_t*)calloc(1, sizeof(token_t)); if(token == NULL) { - media_content_error("OUT_OF_MEMORY"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return -1; } @@ -521,7 +621,7 @@ static int __tokenize(GList **token_list, const char *str) if (ret < 0) { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } else @@ -542,7 +642,7 @@ static int __tokenize(GList **token_list, const char *str) else { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } @@ -554,7 +654,7 @@ static int __tokenize(GList **token_list, const char *str) token_t *token = (token_t*)calloc(1, sizeof(token_t)); if(token == NULL) { - media_content_error("OUT_OF_MEMORY"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return -1; } @@ -562,7 +662,7 @@ static int __tokenize(GList **token_list, const char *str) if (ret < 0) { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } else @@ -583,7 +683,7 @@ static int __tokenize(GList **token_list, const char *str) else { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } @@ -595,7 +695,7 @@ static int __tokenize(GList **token_list, const char *str) token_t *token = (token_t*)calloc(1, sizeof(token_t)); if(token == NULL) { - media_content_error("OUT_OF_MEMORY"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return -1; } @@ -603,7 +703,7 @@ static int __tokenize(GList **token_list, const char *str) if (ret < 0) { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } else @@ -624,7 +724,7 @@ static int __tokenize(GList **token_list, const char *str) else { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } @@ -636,7 +736,7 @@ static int __tokenize(GList **token_list, const char *str) token_t *token = (token_t*)calloc(1, sizeof(token_t)); if(token == NULL) { - media_content_error("OUT_OF_MEMORY"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return -1; } @@ -644,7 +744,7 @@ static int __tokenize(GList **token_list, const char *str) if (ret < 0) { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } else @@ -665,7 +765,7 @@ static int __tokenize(GList **token_list, const char *str) else { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } @@ -677,7 +777,7 @@ static int __tokenize(GList **token_list, const char *str) token_t *token = (token_t*)calloc(1, sizeof(token_t)); if(token == NULL) { - media_content_error("OUT_OF_MEMORY"); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return -1; } @@ -685,7 +785,7 @@ static int __tokenize(GList **token_list, const char *str) if (ret < 0) { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } @@ -696,7 +796,7 @@ static int __tokenize(GList **token_list, const char *str) else { SAFE_FREE(token); - media_content_error("tokenize error occued"); + media_content_error("tokenize error occured"); return -1; } } @@ -856,14 +956,14 @@ int _media_filter_attribute_generate(attribute_h attr, char *condition, media_co } } - if(collate_type == MEDIA_CONTENT_COLLATE_NOCASE || collate_type == MEDIA_CONTENT_COLLATE_RTRIM) { + if(collate_type == MEDIA_CONTENT_COLLATE_NOCASE || collate_type == MEDIA_CONTENT_COLLATE_RTRIM ||collate_type == MEDIA_CONTENT_COLLATE_LOCALIZED) { SAFE_STRLCAT(*generated_condition, "COLLATE ", size); SAFE_STRLCAT(*generated_condition, __get_collate_str(collate_type), size); SAFE_STRLCAT(*generated_condition, SPACE, size); } - media_content_debug("statement : %s(%d) (total:%d)", *generated_condition, strlen(*generated_condition), total_str_size); - media_content_debug("Condition : %s", *generated_condition); + //media_content_debug("statement : %s(%d) (total:%d)", *generated_condition, strlen(*generated_condition), total_str_size); + media_content_sec_debug("Condition : %s", *generated_condition); //if(*generated_condition != NULL) // res = 1; @@ -889,8 +989,6 @@ int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, c int size = 0; //bool order_by = true; - media_content_debug_func(); - if(filter == NULL) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -916,7 +1014,6 @@ int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, c token_t *token; char *attr_str; - media_content_debug("Tokenize for [%s]", _filter->order_keyword); if(__tokenize_attribute(&token_list, _filter->order_keyword) < 0) { media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -933,8 +1030,14 @@ int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, c if(STRING_VALID(replace_str)) { attr_str = (char*)calloc(strlen(replace_str) + COLLATE_STR_SIZE + 1, sizeof(char)); + if(attr_str == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SAFE_FREE(replace_str); + continue; + } - if(_filter->order_collate_type == MEDIA_CONTENT_COLLATE_NOCASE || _filter->order_collate_type == MEDIA_CONTENT_COLLATE_RTRIM) { + if(_filter->order_collate_type == MEDIA_CONTENT_COLLATE_NOCASE || _filter->order_collate_type == MEDIA_CONTENT_COLLATE_RTRIM ||_filter->order_collate_type == MEDIA_CONTENT_COLLATE_LOCALIZED) { snprintf(attr_str, strlen(replace_str) + COLLATE_STR_SIZE + 1, "%s COLLATE %s %s", replace_str, __get_collate_str(_filter->order_collate_type), __get_order_str(_filter->order_type)); } else { snprintf(attr_str, strlen(replace_str) + COLLATE_STR_SIZE + 1, "%s %s", replace_str, __get_order_str(_filter->order_type)); @@ -951,7 +1054,7 @@ int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, c } total_str_size += strlen(token->str) + 1; - media_content_debug("[%d][type:%d]:%s", idx, token->type, token->str); + //media_content_debug("[%d][type:%d]:%s", idx, token->type, token->str); } //make the statment @@ -965,7 +1068,7 @@ int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, c if((token != NULL) && STRING_VALID(token->str)) { - media_content_debug("[%d] %s", idx, token->str); + //media_content_debug("[%d] %s", idx, token->str); SAFE_STRLCAT(generated_condition, token->str, size); SAFE_STRLCAT(generated_condition, SPACE, size); @@ -1019,6 +1122,7 @@ int media_filter_create(filter_h *filter) } else { + _filter->storage_id = NULL; _filter->condition = NULL; _filter->order_keyword = NULL; _filter->order_type = -1; @@ -1040,6 +1144,7 @@ int media_filter_destroy(filter_h filter) if(_filter) { + SAFE_FREE(_filter->storage_id); SAFE_FREE(_filter->condition); SAFE_FREE(_filter->order_keyword); SAFE_FREE(_filter); @@ -1080,7 +1185,7 @@ int media_filter_set_condition(filter_h filter, const char *condition, media_con filter_s *_filter = (filter_s*)filter; if((_filter != NULL) && STRING_VALID(condition) - && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_RTRIM))) + && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_LOCALIZED))) { if(STRING_VALID(_filter->condition)) { @@ -1094,7 +1199,7 @@ int media_filter_set_condition(filter_h filter, const char *condition, media_con return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; } - media_content_debug("Condition string : %s", _filter->condition); + media_content_sec_debug("Condition string : %s", _filter->condition); _filter->condition_collate_type = collate_type; } @@ -1114,7 +1219,7 @@ int media_filter_set_order(filter_h filter, media_content_order_e order_type, co if((_filter != NULL) && STRING_VALID(order_keyword) && ((order_type == MEDIA_CONTENT_ORDER_ASC) ||(order_type == MEDIA_CONTENT_ORDER_DESC)) - && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_RTRIM))) + && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_LOCALIZED))) { SAFE_FREE(_filter->order_keyword); @@ -1145,6 +1250,36 @@ int media_filter_set_order(filter_h filter, media_content_order_e order_type, co return ret; } +int media_filter_set_storage(filter_h filter, const char *storage_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_s *_filter = (filter_s*)filter; + + if((_filter != NULL) && STRING_VALID(storage_id)) + { + if(STRING_VALID(_filter->storage_id)) + { + SAFE_FREE(_filter->storage_id); + } + + _filter->storage_id = strdup(storage_id); + if(_filter->storage_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + media_content_sec_debug("storage_id : %s", _filter->storage_id); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + int media_filter_get_offset(filter_h filter, int *offset, int *count) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -1228,3 +1363,33 @@ int media_filter_get_order(filter_h filter, media_content_order_e* order_type, c return ret; } + +int media_filter_get_storage(filter_h filter, char **storage_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_s *_filter = (filter_s*)filter; + + if(_filter) + { + if(STRING_VALID(_filter->storage_id)) + { + *storage_id = strdup(_filter->storage_id); + if(*storage_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *storage_id = NULL; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} diff --git a/src/media_folder.c b/src/media_folder.c index bb1cda5..1cac252 100755 --- a/src/media_folder.c +++ b/src/media_folder.c @@ -15,7 +15,6 @@ */ -#include #include #include @@ -49,8 +48,6 @@ int media_folder_get_folder_count_from_db(filter_h filter, int *folder_count) { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(!folder_count) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -66,8 +63,6 @@ int media_folder_foreach_folder_from_db(filter_h filter, media_folder_cb callbac { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(callback == NULL) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -83,8 +78,6 @@ int media_folder_get_media_count_from_db(const char *folder_id, filter_h filter, { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(STRING_VALID(folder_id) && media_count) { ret = _media_db_get_group_item_count(folder_id, filter, MEDIA_GROUP_FOLDER, media_count); @@ -102,8 +95,6 @@ int media_folder_foreach_media_from_db(const char *folder_id, filter_h filter, m { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if((callback != NULL) && STRING_VALID(folder_id)) { ret = _media_db_get_group_item(folder_id, filter, callback, user_data, MEDIA_GROUP_FOLDER); @@ -126,6 +117,7 @@ int media_folder_destroy(media_folder_h folder) SAFE_FREE(_folder->path); SAFE_FREE(_folder->name); SAFE_FREE(_folder->folder_id); + SAFE_FREE(_folder->storage_uuid); SAFE_FREE(_folder); ret = MEDIA_CONTENT_ERROR_NONE; } @@ -186,6 +178,17 @@ int media_folder_clone(media_folder_h *dst, media_folder_h src) } } + if(STRING_VALID(_src->storage_uuid)) + { + _dst->storage_uuid = strdup(_src->storage_uuid); + if(_dst->storage_uuid == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_folder_destroy((media_folder_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + *dst = (media_folder_h)_dst; ret = MEDIA_CONTENT_ERROR_NONE; @@ -329,10 +332,59 @@ int media_folder_get_storage_type(media_folder_h folder, media_content_storage_e return ret; } +int media_folder_get_storage_id(media_folder_h folder, char **storage_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_folder_s *_folder = (media_folder_s*)folder; + if(_folder) + { + if(STRING_VALID(_folder->storage_uuid)) + { + *storage_id = strdup(_folder->storage_uuid); + if(*storage_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *storage_id = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_folder_get_order(media_folder_h folder, int *order) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_folder_s *_folder = (media_folder_s*)folder; + if(_folder) + { + *order = _folder->folder_order; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + + int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folder) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; sqlite3_stmt *stmt = NULL; char select_query[DEFAULT_QUERY_SIZE]; @@ -360,6 +412,8 @@ int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folde return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; } + media_content_error("folder handle %x", _folder); + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) _folder->folder_id = strdup((const char *)sqlite3_column_text(stmt, 0)); @@ -373,21 +427,30 @@ int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folde } SQLITE3_FINALIZE(stmt); + return ret; } int media_folder_update_to_db(media_folder_h folder) { int ret = MEDIA_CONTENT_ERROR_NONE; - int len = 0; media_folder_s *_folder = (media_folder_s*)folder; - - char sql[MAX_QUERY_SIZE]; - memset(sql, '\0', sizeof(sql)); char *set_sql = NULL; - char *where_sql = NULL; + char *sql = NULL; - if((_folder != NULL) && STRING_VALID(_folder->folder_id) && g_src_path) + if((_folder == NULL) || (_folder->folder_id == NULL)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + /* Update folder order */ + sql = sqlite3_mprintf(UPDATE_FOLDER_ORDER, _folder->folder_order, _folder->folder_id); + + ret = _content_query_sql(sql); + sqlite3_free(sql); + + if(STRING_VALID(_folder->folder_id) && g_src_path) { /* Set modified time */ time_t date; @@ -397,34 +460,28 @@ int media_folder_update_to_db(media_folder_h folder) set_sql = __media_folder_get_update_folder_sql((media_folder_h)_folder); if(set_sql == NULL) { + SAFE_FREE(g_src_path); media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; } - where_sql = sqlite3_mprintf("folder_uuid='%q'", _folder->folder_id); - - len = snprintf(sql, sizeof(sql), UPDATE_SQL, DB_TABLE_FOLDER, set_sql, where_sql); - if (len > 0) { - sql[len] = '\0'; - } else { - media_content_error("snprintf failed"); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE folder_uuid=%Q", DB_TABLE_FOLDER, set_sql, _folder->folder_id); ret = _content_query_sql(sql); sqlite3_free(set_sql); - sqlite3_free(where_sql); + sqlite3_free(sql); + if (ret != MEDIA_CONTENT_ERROR_NONE) + { + SAFE_FREE(g_src_path); + return ret; + } + + ret = media_svc_rename_folder(_content_get_db_handle(), _folder->storage_uuid, g_src_path, _folder->path, tzplatform_getuid(TZ_USER_NAME)); + SAFE_FREE(g_src_path); - /* Do folder rename operation using libmedia-service */ - ret = media_svc_rename_folder(_content_get_db_handle(), g_src_path, _folder->path, tzplatform_getuid(TZ_USER_NAME)); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - else - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } return ret; } @@ -441,9 +498,9 @@ int media_folder_set_name(media_folder_h folder, const char *name) char new_folder_path[MAX_QUERY_SIZE] = {0,}; folder_path = g_path_get_dirname(_folder->path); - media_content_debug("Existed Folder Path : %s", _folder->path); + media_content_sec_debug("Existed Folder Path : %s", _folder->path); snprintf(new_folder_path, sizeof(new_folder_path), "%s/%s", folder_path, name); - media_content_debug("New Path : %s", new_folder_path); + media_content_sec_debug("New Path : %s", new_folder_path); SAFE_FREE(g_src_path); g_src_path = strdup(_folder->path); @@ -475,3 +532,21 @@ int media_folder_set_name(media_folder_h folder, const char *name) return ret; } + +int media_folder_set_order(media_folder_h folder, int order) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_folder_s *_folder = (media_folder_s*)folder; + + if(_folder != NULL && order >= 0) + { + _folder->folder_order = order; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} diff --git a/src/media_group.c b/src/media_group.c index 572f9c8..cc98ff2 100755 --- a/src/media_group.c +++ b/src/media_group.c @@ -24,8 +24,6 @@ int media_album_get_album_count_from_db(filter_h filter, int *album_count) { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(album_count != NULL) { ret = _media_db_get_group_count(filter, MEDIA_GROUP_ALBUM, album_count); @@ -43,8 +41,6 @@ int media_album_foreach_album_from_db(filter_h filter, media_album_cb callback, { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(callback == NULL) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -60,8 +56,6 @@ int media_album_get_media_count_from_db(int album_id, filter_h filter, int *medi { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if((album_id > 0) && (media_count != NULL)) { ret = _media_db_get_group_item_count_by_id(album_id, filter, MEDIA_GROUP_ALBUM, media_count); @@ -79,8 +73,6 @@ int media_album_foreach_media_from_db(int album_id, filter_h filter, media_info_ { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if((album_id > 0) && (callback != NULL)) { ret = _media_db_get_group_item_by_id(album_id, filter, callback, user_data, MEDIA_GROUP_ALBUM); @@ -100,8 +92,6 @@ int media_album_get_album_from_db(int album_id, media_album_h *album) sqlite3_stmt *stmt = NULL; char select_query[DEFAULT_QUERY_SIZE]; - media_content_debug_func(); - if(album_id < 0) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -118,6 +108,12 @@ int media_album_get_album_from_db(int album_id, media_album_h *album) while(sqlite3_step(stmt) == SQLITE_ROW) { media_album_s *_album = (media_album_s*)calloc(1, sizeof(media_album_s)); + if(_album == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } _album->album_id = (int)sqlite3_column_int(stmt, 0); @@ -130,10 +126,7 @@ int media_album_get_album_from_db(int album_id, media_album_h *album) *album = (media_album_h)_album; } - if(stmt != NULL) - { - sqlite3_finalize(stmt); - } + SQLITE3_FINALIZE(stmt); return ret; } @@ -343,9 +336,7 @@ int media_group_get_group_count_from_db(filter_h filter, media_group_e group, in { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - - if((group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group > MEDIA_CONTENT_GROUP_KEYWORD) || (group_count == NULL)) + if((group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_CONTENT_GROUP_MAX) || (group_count == NULL)) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; @@ -362,9 +353,7 @@ int media_group_foreach_group_from_db(filter_h filter, media_group_e group, medi { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - - if((callback == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group > MEDIA_CONTENT_GROUP_KEYWORD)) + if((callback == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_CONTENT_GROUP_MAX)) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; @@ -381,16 +370,14 @@ int media_group_get_media_count_from_db(const char *group_name, media_group_e gr { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - - if((media_count == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group > MEDIA_CONTENT_GROUP_KEYWORD)) + if((media_count == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_CONTENT_GROUP_MAX)) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } else { - ret = _media_db_get_media_group_item_count(group_name, group, filter, media_count); + ret = _media_db_get_media_group_item_count(group_name, filter, group, media_count); } return ret; @@ -400,16 +387,14 @@ int media_group_foreach_media_from_db(const char *group_name, media_group_e grou { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - - if((callback == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group > MEDIA_CONTENT_GROUP_KEYWORD)) + if((callback == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_CONTENT_GROUP_MAX)) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } else { - ret = _media_db_get_media_group_item(group_name, group, filter, callback, user_data); + ret = _media_db_get_media_group_item(group_name, filter, group, callback, user_data); } return ret; diff --git a/src/media_image.c b/src/media_image.c index abb4190..a8ad9c5 100755 --- a/src/media_image.c +++ b/src/media_image.c @@ -15,10 +15,7 @@ */ -#include -#include #include -#include int image_meta_destroy(image_meta_h image) @@ -465,7 +462,13 @@ int image_meta_update_to_db(image_meta_h image) if(_image != NULL && STRING_VALID(_image->media_id)) { - sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->weather, _image->media_id); + char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,}; + memset(storage_id, 0x00, sizeof(storage_id)); + + ret = _media_db_get_storage_id_by_media_id(_image->media_id, storage_id); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, storage_id, _image->orientation, _image->weather, _image->media_id); ret = _content_query_sql(sql); sqlite3_free(sql); } diff --git a/src/media_info.c b/src/media_info.c index 5bbdee0..b74256f 100755 --- a/src/media_info.c +++ b/src/media_info.c @@ -14,64 +14,19 @@ * limitations under the License. */ -#include #include -#include #include #include #include -#include -#include -static int __media_info_get_media_info_from_db(char *path, media_info_h media); static void __media_info_insert_completed_cb(media_request_result_s *result, void *user_data); static void __media_info_thumbnail_completed_cb(int error, const char *path, void *user_data); static bool __media_info_delete_batch_cb(media_info_h media, void *user_data); static int __media_info_insert_batch(media_batch_insert_e insert_type, const char **path_array, unsigned int array_length, media_insert_completed_cb completed_cb, void *user_data); -static int __media_info_get_media_info_from_db(char *path, media_info_h media) -{ - int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; - sqlite3_stmt *stmt = NULL; - char *select_query = NULL; - media_info_s *_media = (media_info_s*)media; - - if(_media == NULL) - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - select_query = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, path); - - ret = _content_query_prepare(&stmt, select_query, NULL, NULL); - sqlite3_free(select_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - - if(sqlite3_step(stmt) == SQLITE_ROW) - { - _media_info_item_get_detail(stmt, (media_info_h)_media); - media_content_debug("New Media ID: %s", _media->media_id); - } else { - media_content_debug("There's no media!!"); - } -/* - while(sqlite3_step(stmt) == SQLITE_ROW) - { - _media_info_item_get_detail(stmt, (media_info_h)_media); - media_content_debug("New Media ID: %s", _media->media_id); - } -*/ - SQLITE3_FINALIZE(stmt); - - return ret; -} - static int __media_info_get_media_path_by_id_from_db(const char *media_id, char **path) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; sqlite3_stmt *stmt = NULL; char *select_query = NULL; @@ -92,12 +47,13 @@ static int __media_info_get_media_path_by_id_from_db(const char *media_id, char if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) *path = strdup((const char *)sqlite3_column_text(stmt, 0)); } else { - media_content_debug("There's no media with this ID : %s", media_id); + media_content_error("There's no media with this ID : %s", media_id); *path = NULL; - ret = MEDIA_CONTENT_ERROR_DB_FAILED; + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } SQLITE3_FINALIZE(stmt); + return ret; } @@ -116,7 +72,7 @@ static void __media_info_insert_completed_cb(media_request_result_s *result, voi if (STRING_VALID(_cb_data->insert_list_path)) { if (unlink(_cb_data->insert_list_path) < 0) { - media_content_error("failed to delete : %s", strerror(errno)); + media_content_stderror("failed to delete"); } SAFE_FREE(_cb_data->insert_list_path); } @@ -156,39 +112,139 @@ static void __media_info_thumbnail_completed_cb(int error, const char *path, voi static bool __media_info_delete_batch_cb(media_info_h media, void *user_data) { + int err = MEDIA_CONTENT_ERROR_NONE; char *thumb_path = NULL; media_content_type_e media_type = 0; + GArray *thumb_list = (GArray *)user_data; if(media == NULL) { - media_content_debug("NO Item \n"); + media_content_debug("NO Item"); return true; } - media_info_get_media_type(media, &media_type); - media_content_debug("media_type : [%d] \n", media_type); + err = media_info_get_media_type(media, &media_type); + if (err == MEDIA_CONTENT_ERROR_NONE) { + media_content_debug("media_type : [%d]", media_type); - media_info_get_thumbnail_path(media, &thumb_path); - if (STRING_VALID(thumb_path)) { - if (strncmp(MEDIA_CONTENT_THUMB_DEFAULT_PATH, thumb_path, strlen(MEDIA_CONTENT_THUMB_DEFAULT_PATH)) != 0) { - media_content_debug("Deleting thumbnail : [%s] \n", thumb_path); - if (unlink(thumb_path) < 0) { - media_content_error("failed to delete : %s", strerror(errno)); + media_info_get_thumbnail_path(media, &thumb_path); + if (STRING_VALID(thumb_path)) { + if (strncmp(MEDIA_CONTENT_THUMB_DEFAULT_PATH, thumb_path, strlen(MEDIA_CONTENT_THUMB_DEFAULT_PATH)) != 0) { + g_array_append_val(thumb_list, thumb_path); } } - - SAFE_FREE(thumb_path); + } else { + media_content_error("media_info_get_media_type failed"); } return true; } +static int __media_info_insert_batch(media_batch_insert_e insert_type, const char **path_array, + unsigned int array_length, + media_insert_completed_cb completed_cb, + void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + FILE *fp = NULL; + char list_path[255] = {0,}; + int idx = 0; + int nwrites = 0; + + for (idx = 0; idx < BATCH_REQUEST_MAX; idx++) { + snprintf(list_path, sizeof(list_path), "%s/request-%ld-%d", MEDIA_CONTENT_INSERT_FILES_PATH, media_content_gettid(), idx); + + if (g_file_test(list_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { + memset(list_path, 0x00, sizeof(list_path)); + continue; + } else { + media_content_debug("The request file list path : %s", list_path); + break; + } + } + + if (idx == BATCH_REQUEST_MAX) { + media_content_error("Too many batch request for one thread"); + return MEDIA_CONTENT_ERROR_DB_BUSY; + } + + fp = fopen(list_path, "w"); + if (fp == NULL) { + media_content_error("failed to open file : [%s]", list_path); + media_content_stderror("failed to open file"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + for (idx = 0; idx < array_length; idx++) { + if (STRING_VALID(path_array[idx])) { + int size = strlen(path_array[idx]); + + ret = _media_util_check_file(path_array[idx]); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + fclose(fp); + if (unlink(list_path) < 0) { + media_content_stderror("failed to delete"); + } + return ret; + } + + nwrites = fwrite(path_array[idx], 1, size, fp); + if (nwrites != size) { + media_content_stderror("failed to write"); + fclose(fp); + if (unlink(list_path) < 0) { + media_content_stderror("failed to delete"); + } + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + nwrites = fwrite("\n", 1, 1, fp); + if (nwrites != 1) { + media_content_stderror("failed to write"); + fclose(fp); + if (unlink(list_path) < 0) { + media_content_stderror("failed to delete"); + } + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + } else { + media_content_error("path[%d] is invalid string", idx); + } + } + + fclose(fp); + + media_insert_cb_s *_cb_data = (media_insert_cb_s *)calloc(1, sizeof(media_insert_cb_s)); + if(_cb_data == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _cb_data->insert_completed_cb = completed_cb; + _cb_data->user_data = user_data; + _cb_data->insert_list_path = strdup(list_path); + + if(insert_type == MEDIA_BATCH_INSERT_NORMAL) + ret = media_files_register(list_path, __media_info_insert_completed_cb, _cb_data, tzplatform_getuid(TZ_USER_NAME)); + else if(insert_type == MEDIA_BATCH_INSERT_BURSTSHOT) + ret = media_burstshot_register(list_path, __media_info_insert_completed_cb, _cb_data, tzplatform_getuid(TZ_USER_NAME)); + else + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + + if (ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_files_register failed : %d", ret); + if (unlink(list_path) < 0) { + media_content_stderror("failed to delete"); + } + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + + return ret; +} void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media) { -//#define MEDIA_INFO_ITEM "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description, -// rating, favourite, author, provider, content_name, category, location_tag, age_rating, keyword, is_drm, storage_type, longitude, latitude, altitude, width, height, datetaken, orientation, title, album, artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, duration, played_count, last_played_time, last_played_position, samplerate, channel" - media_info_s *_media = (media_info_s*)media; if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_UUID))) @@ -264,6 +320,8 @@ void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media) _media->sync_status = (int)sqlite3_column_int(stmt, MEDIA_INFO_SYNC_STATUS); + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_STORAGE_UUID))) + _media->storage_uuid = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_STORAGE_UUID)); if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) { _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s)); @@ -389,12 +447,45 @@ void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media) _media->audio_meta->samplerate = sqlite3_column_int(stmt, MEDIA_INFO_SAMPLERATE); _media->audio_meta->channel = sqlite3_column_int(stmt, MEDIA_INFO_CHANNEL); } + } +} + +int _media_info_get_media_info_from_db(const char *path, const char *storage_id, media_info_h media) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char *select_query = NULL; + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + select_query = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, storage_id, path); + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + sqlite3_free(select_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + if(sqlite3_step(stmt) == SQLITE_ROW) + { + _media_info_item_get_detail(stmt, (media_info_h)_media); + } else { + media_content_error("There's no media!!"); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } + + SQLITE3_FINALIZE(stmt); + + return ret; } -int media_info_insert_to_db (const char *path, media_info_h *info) +int media_info_insert_to_db(const char *path, media_info_h *info) { + bool ignore_dir = FALSE; + char *folder_path = NULL; int ret = MEDIA_CONTENT_ERROR_NONE; if(!STRING_VALID(path)) @@ -409,159 +500,62 @@ int media_info_insert_to_db (const char *path, media_info_h *info) return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } -#if 0 - media_content_debug("Register: %s", path); - ret = media_file_register(path); - if(ret != MS_MEDIA_ERR_NONE) - { - media_content_error("media_file_register failed"); - return _content_error_capi(MEDIA_REGISTER_TYPE, ret); + ret = _media_util_check_file(path); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + return ret; } -#else - char *_path = strdup(path); - if (_path == NULL) { - media_content_error("strdup failed : %s", path); - return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + folder_path = g_path_get_dirname(path); + ret = _media_util_check_ignore_dir(folder_path, &ignore_dir); + SAFE_FREE(folder_path); + + if(ignore_dir) { + media_content_error("Invalid folder path"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } - ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), _path); + ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), path); if (ret == MS_MEDIA_ERR_DB_NO_RECORD) { - media_content_debug("media_svc_check_item_exist_by_path : no record : %s", _path); + media_content_sec_debug("media_svc_check_item_exist_by_path : no record : %s", path); - media_svc_storage_type_e storage_type; + media_svc_storage_type_e storage_type = 0; - ret = media_svc_get_storage_type(_path, &storage_type); - if (ret < 0) { - media_content_error("media_svc_get_storage_type failed : %d (%s)", ret, _path); - SAFE_FREE(_path); + ret = media_svc_get_storage_type(path, &storage_type); + if(ret != MS_MEDIA_ERR_NONE) { + media_content_sec_error("media_svc_get_storage_type failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - media_content_debug("media_svc_insert_item_immediately: %s", _path); - ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_type, _path, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_type, path, tzplatform_getuid(TZ_USER_NAME)); + + if(ret != MS_MEDIA_ERR_NONE) { + if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) { + media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path); + ret = MEDIA_CONTENT_ERROR_NONE; + } else { + media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path); + } - if (ret < 0) { - media_content_error("media_svc_insert_item_immediately failed : %d (%s)", ret, _path); - SAFE_FREE(_path); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } } else if (ret != MS_MEDIA_ERR_NONE) { - media_content_error("media_svc_check_item_exist_by_path failed : %d (%s)", ret, _path); - SAFE_FREE(_path); + media_content_sec_error("media_svc_check_item_exist_by_path failed : %d (%s)", ret, path); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } -#endif media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s)); if(_media == NULL) { media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - SAFE_FREE(_path); - return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; - } - - _media->file_path = _path; - if(_media->file_path == NULL) - { - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - SAFE_FREE(_media); return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; } - ret = __media_info_get_media_info_from_db(_media->file_path, (media_info_h)_media); + ret = _media_info_get_media_info_from_db(path, DEFAULT_MEDIA_STORAGE_ID, (media_info_h)_media); *info = (media_info_h)_media; return ret; } -static int __media_info_insert_batch(media_batch_insert_e insert_type, const char **path_array, - unsigned int array_length, - media_insert_completed_cb completed_cb, - void *user_data) -{ - int ret = MEDIA_CONTENT_ERROR_NONE; - FILE *fp = NULL; - char list_path[255] = {0,}; - int idx = 0; - int nwrites = 0; - - for (idx = 0; idx < BATCH_REQUEST_MAX; idx++) { - snprintf(list_path, sizeof(list_path), "%s/request-%ld-%d", MEDIA_CONTENT_INSERT_FILES_PATH, media_content_gettid(), idx); - - if (g_file_test(list_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { - memset(list_path, 0x00, sizeof(list_path)); - continue; - } else { - media_content_debug("The request file list path : %s", list_path); - break; - } - } - - if (idx == BATCH_REQUEST_MAX) { - media_content_error("Too many batch request for one thread"); - return MEDIA_CONTENT_ERROR_DB_BUSY; - } - - fp = fopen(list_path, "w"); - if (fp == NULL) { - media_content_error("failed to open file : %s [%s]", list_path, strerror(errno)); - return MEDIA_CONTENT_ERROR_INVALID_OPERATION; - } - - for (idx = 0; idx < array_length; idx++) { - if (STRING_VALID(path_array[idx])) { - int size = strlen(path_array[idx]); - - nwrites = fwrite(path_array[idx], 1, size, fp); - if (nwrites != size) { - media_content_error("failed to write thumbnail : %s", strerror(errno)); - fclose(fp); - if (unlink(list_path) < 0) { - media_content_error("failed to delete : %s", strerror(errno)); - } - return MEDIA_CONTENT_ERROR_INVALID_OPERATION; - } - - nwrites = fwrite("\n", 1, 1, fp); - if (nwrites != 1) { - media_content_error("failed to write thumbnail : %s", strerror(errno)); - fclose(fp); - if (unlink(list_path) < 0) { - media_content_error("failed to delete : %s", strerror(errno)); - } - return MEDIA_CONTENT_ERROR_INVALID_OPERATION; - } - } else { - media_content_error("path[%d] is invalid string", idx); - } - } - - fclose(fp); - - media_insert_cb_s *_cb_data = (media_insert_cb_s *)calloc(1, sizeof(media_insert_cb_s)); - _cb_data->insert_completed_cb = completed_cb; - _cb_data->user_data = user_data; - _cb_data->insert_list_path = strdup(list_path); - - if(insert_type == MEDIA_BATCH_INSERT_NORMAL) - ret = media_files_register(list_path, __media_info_insert_completed_cb, _cb_data, tzplatform_getuid(TZ_USER_NAME)); - else if(insert_type == MEDIA_BATCH_INSERT_BURSTSHOT) - ret = media_burstshot_register(list_path, __media_info_insert_completed_cb, _cb_data, tzplatform_getuid(TZ_USER_NAME)); - else - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - - if (ret != MEDIA_CONTENT_ERROR_NONE) { - media_content_error("media_files_register failed : %d", ret); - if (unlink(list_path) < 0) { - media_content_error("failed to delete : %s", strerror(errno)); - } - return _content_error_capi(MEDIA_CONTENT_TYPE, ret); - } - - return ret; -} - int media_info_insert_batch_to_db( const char **path_array, unsigned int array_length, @@ -603,6 +597,8 @@ int media_info_insert_burst_shot_to_db(const char **path_array, unsigned int arr int media_info_delete_from_db(const char *media_id) { int ret = MEDIA_CONTENT_ERROR_NONE; + char *path = NULL; + char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,}; if(!STRING_VALID(media_id)) { @@ -610,30 +606,69 @@ int media_info_delete_from_db(const char *media_id) return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } -#if 0 - char *query_string = NULL; - query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA, media_id); - - ret = _content_query_sql(query_string); - - sqlite3_free(query_string); - - return ret; -#else - char *path = NULL; + memset(storage_id, 0x00, sizeof(storage_id)); ret = __media_info_get_media_path_by_id_from_db(media_id, &path); - if (ret < MEDIA_CONTENT_ERROR_NONE) { + if(ret != MEDIA_CONTENT_ERROR_NONE) { media_content_error("__media_info_get_media_path_by_id_from_db failed : %d", ret); SAFE_FREE(path); return ret; } - ret = media_svc_delete_item_by_path(_content_get_db_handle(), path, tzplatform_getuid(TZ_USER_NAME)); + ret = _media_db_get_storage_id_by_media_id(media_id, storage_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("_media_db_get_storage_id_by_media_id failed : %d", ret); + SAFE_FREE(path); + return ret; + } + + ret = media_svc_delete_item_by_path(_content_get_db_handle(), storage_id, path, tzplatform_getuid(TZ_USER_NAME)); SAFE_FREE(path); - return _content_error_capi(ret,MEDIA_CONTENT_TYPE); -#endif + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); +} + +static int __media_info_delete_thumb_from_list(GArray *thumb_list) +{ + int i = 0; + int list_len = 0; + char *thumb_path = NULL; + + if (thumb_list != NULL) { + + list_len = thumb_list->len; + + for (i = 0; i < list_len; i ++) { + thumb_path = g_array_index(thumb_list, char*, i); + media_content_debug("thumb path [%s]", thumb_path); + if (unlink(thumb_path) < 0) { + media_content_stderror("failed to delete"); + } + } + } + return MEDIA_CONTENT_ERROR_NONE; +} + +static int __media_info_release_thumb_list(GArray *thumb_list) +{ + int i = 0; + int list_len = 0; + char *thumb_path = NULL; + + if (thumb_list != NULL) { + + list_len = thumb_list->len; + + for (i = 0; i < list_len; i ++) { + thumb_path = g_array_index(thumb_list, char*, 0); + g_array_remove_index(thumb_list,0); + SAFE_FREE(thumb_path); + } + + g_array_free(thumb_list, FALSE); + } + + return MEDIA_CONTENT_ERROR_NONE; } int media_info_delete_batch_from_db(filter_h filter) @@ -644,6 +679,7 @@ int media_info_delete_batch_from_db(filter_h filter) filter_s *_filter = NULL; attribute_h attr; char *condition_query = NULL; + GArray *thumb_list = NULL; if(filter == NULL) { @@ -651,8 +687,10 @@ int media_info_delete_batch_from_db(filter_h filter) return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } + thumb_list = g_array_new(FALSE, FALSE, sizeof(char*)); + /* Delete thumbnail of each item */ - ret = _media_db_get_group_item(NULL, filter, __media_info_delete_batch_cb, NULL, MEDIA_GROUP_NONE); + ret = _media_db_get_group_item(NULL, filter, __media_info_delete_batch_cb, thumb_list, MEDIA_GROUP_NONE); _filter = (filter_s*)filter; attr = _content_get_attirbute_handle(); @@ -660,16 +698,26 @@ int media_info_delete_batch_from_db(filter_h filter) if(_filter->condition) { ret = _media_filter_attribute_generate(attr, _filter->condition, _filter->condition_collate_type, &condition_query); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + __media_info_release_thumb_list(thumb_list); + return ret; + } } if(STRING_VALID(condition_query)) { - query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA_BATCH, condition_query); + if (_filter->storage_id == NULL) { + /*FIX ME*/ + query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA_BATCH, "media", condition_query); + } else { + query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA_BATCH, _filter->storage_id, condition_query); + } } else { SAFE_FREE(condition_query); + __media_info_release_thumb_list(thumb_list); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } @@ -679,8 +727,11 @@ int media_info_delete_batch_from_db(filter_h filter) In this case, send noti for internal storage and external storage */ media_content_debug("Batch deletion is successfull. Send notification for this"); - media_db_update_send(getpid(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_CONTENT_PATH_PHONE, NULL, -1, NULL); - media_db_update_send(getpid(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_CONTENT_PATH_MMC, NULL, -1, NULL); + media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_CONTENT_PATH_PHONE, -1, NULL, NULL); + media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_CONTENT_PATH_MMC, -1, NULL, NULL); + + __media_info_delete_thumb_from_list(thumb_list); + __media_info_release_thumb_list(thumb_list); } SAFE_FREE(condition_query); @@ -711,6 +762,7 @@ int media_info_destroy(media_info_h media) SAFE_FREE(_media->keyword); SAFE_FREE(_media->title); SAFE_FREE(_media->weather); + SAFE_FREE(_media->storage_uuid); if(_media->image_meta) { SAFE_FREE(_media->image_meta->media_id); @@ -722,7 +774,9 @@ int media_info_destroy(media_info_h media) SAFE_FREE(_media->image_meta->weather); SAFE_FREE(_media->image_meta); - } else if(_media->video_meta) { + } + + if(_media->video_meta) { SAFE_FREE(_media->video_meta->media_id); SAFE_FREE(_media->video_meta->title); SAFE_FREE(_media->video_meta->album); @@ -736,7 +790,9 @@ int media_info_destroy(media_info_h media) SAFE_FREE(_media->video_meta->track_num); SAFE_FREE(_media->video_meta); - } else if(_media->audio_meta) { + } + + if(_media->audio_meta) { SAFE_FREE(_media->audio_meta->media_id); SAFE_FREE(_media->audio_meta->title); SAFE_FREE(_media->audio_meta->album); @@ -934,6 +990,17 @@ int media_info_clone(media_info_h *dst, media_info_h src) } } + if(STRING_VALID(_src->storage_uuid)) + { + _dst->storage_uuid = strdup(_src->storage_uuid); + if(_dst->storage_uuid == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + _dst->media_type = _src->media_type; _dst->size = _src->size; _dst->added_time = _src->added_time; @@ -1081,6 +1148,16 @@ int media_info_clone(media_info_h *dst, media_info_h src) return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; } } + if(STRING_VALID(_src->video_meta->album_artist)) + { + _dst->video_meta->album_artist = strdup(_src->video_meta->album_artist); + if(_dst->video_meta->album_artist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } if(STRING_VALID(_src->video_meta->genre)) { _dst->video_meta->genre = strdup(_src->video_meta->genre); @@ -1199,6 +1276,16 @@ int media_info_clone(media_info_h *dst, media_info_h src) return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; } } + if(STRING_VALID(_src->audio_meta->album_artist)) + { + _dst->audio_meta->album_artist = strdup(_src->audio_meta->album_artist); + if(_dst->audio_meta->album_artist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } if(STRING_VALID(_src->audio_meta->genre)) { _dst->audio_meta->genre = strdup(_src->audio_meta->genre); @@ -1287,8 +1374,6 @@ int media_info_get_media_count_from_db(filter_h filter, int *media_count) { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(media_count == NULL) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -1306,8 +1391,6 @@ int media_info_foreach_media_from_db(filter_h filter, media_info_cb callback, vo { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(callback == NULL) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -1323,8 +1406,6 @@ int media_info_get_tag_count_from_db(const char *media_id, filter_h filter, int { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(STRING_VALID(media_id) && tag_count) { ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_TAG_BY_MEDIA_ID, tag_count); @@ -1342,8 +1423,6 @@ int media_info_foreach_tag_from_db(const char *media_id, filter_h filter, media_ { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if((callback != NULL) && STRING_VALID(media_id)) { ret = _media_db_get_tag(media_id, filter, callback, user_data); @@ -1361,8 +1440,6 @@ int media_info_get_bookmark_count_from_db(const char *media_id, filter_h filter, { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(STRING_VALID(media_id) && bookmark_count) { ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID, bookmark_count); @@ -1380,8 +1457,6 @@ int media_info_foreach_bookmark_from_db (const char *media_id, filter_h filter, { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if((callback != NULL) && STRING_VALID(media_id)) { ret = _media_db_get_bookmark(media_id, filter, callback, user_data); @@ -1511,6 +1586,9 @@ int media_info_get_video(media_info_h media, video_meta_h *video) if(STRING_VALID(_media->video_meta->artist)) { _video->artist = strdup(_media->video_meta->artist); } + if(STRING_VALID(_media->video_meta->album_artist)) { + _video->album_artist = strdup(_media->video_meta->album_artist); + } if(STRING_VALID(_media->video_meta->genre)) { _video->genre = strdup(_media->video_meta->genre); } @@ -1588,6 +1666,9 @@ int media_info_get_audio(media_info_h media, audio_meta_h *audio) if(STRING_VALID(_media->audio_meta->artist)) { _audio->artist = strdup(_media->audio_meta->artist); } + if(STRING_VALID(_media->audio_meta->album_artist)) { + _audio->album_artist = strdup(_media->audio_meta->album_artist); + } if(STRING_VALID(_media->audio_meta->genre)) { _audio->genre = strdup(_media->audio_meta->genre); } @@ -2273,6 +2354,37 @@ int media_info_get_keyword(media_info_h media, char **keyword) return ret; } +int media_info_get_storage_id(media_info_h media, char **storage_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && storage_id) + { + if(STRING_VALID(_media->storage_uuid)) + { + *storage_id = strdup(_media->storage_uuid); + if(*storage_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *storage_id = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + int media_info_is_drm(media_info_h media, bool *is_drm) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -2392,8 +2504,8 @@ int media_info_set_played_time(media_info_h media) int media_info_get_media_from_db(const char *media_id, media_info_h *media) { int ret = MEDIA_CONTENT_ERROR_NONE; - int ret_view = MEDIA_CONTENT_ERROR_NONE; char select_query[DEFAULT_QUERY_SIZE]; + char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,}; sqlite3_stmt *stmt = NULL; if(!STRING_VALID(media_id) || (media == NULL)) @@ -2403,14 +2515,24 @@ int media_info_get_media_from_db(const char *media_id, media_info_h *media) } memset(select_query, 0x00, sizeof(select_query)); + memset(storage_id, 0x00, sizeof(storage_id)); + + ret = _media_db_get_storage_id_by_media_id(media_id, storage_id); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_MEDIA, storage_id, media_id); - snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_MEDIA, media_id); ret = _content_query_prepare(&stmt, select_query, NULL, NULL); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + media_info_s *_media = NULL; + while(sqlite3_step(stmt) == SQLITE_ROW) { - media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s)); + if(_media) + media_info_destroy((media_info_h)_media); + + _media = (media_info_s*)calloc(1, sizeof(media_info_s)); if(_media == NULL) { @@ -2425,6 +2547,7 @@ int media_info_get_media_from_db(const char *media_id, media_info_h *media) } SQLITE3_FINALIZE(stmt); + return ret; } @@ -2860,11 +2983,9 @@ int media_info_set_keyword(media_info_h media, const char *keyword) int media_info_update_to_db(media_info_h media) { int ret = MEDIA_CONTENT_ERROR_NONE; - int len = 0; media_info_s *_media = (media_info_s*)media; char *set_sql = NULL; - char sql[MAX_QUERY_SIZE]; - memset(sql, '\0', sizeof(sql)); + char *sql = NULL; if(_media != NULL && STRING_VALID(_media->media_id)) { @@ -2912,13 +3033,16 @@ int media_info_update_to_db(media_info_h media) set_sql = sqlite3_mprintf("file_name=%Q, added_time=%d, description=%Q, longitude=%f, latitude=%f, altitude=%f, \ played_count=%d, last_played_time=%d, last_played_position=%d, \ rating=%d, favourite=%d, author=%Q, provider=%Q, content_name=%Q, category=%Q, location_tag=%Q, age_rating=%Q, keyword=%Q, weather=%Q, sync_status=%d, \ - file_name_pinyin=%Q, description_pinyin=%Q, author_pinyin=%Q, provider_pinyin=%Q, content_name_pinyin=%Q, category_pinyin=%Q, location_tag_pinyin=%Q, age_rating_pinyin=%Q, keyword_pinyin=%Q", + file_name_pinyin=%Q, description_pinyin=%Q, author_pinyin=%Q, provider_pinyin=%Q, content_name_pinyin=%Q, category_pinyin=%Q, location_tag_pinyin=%Q, age_rating_pinyin=%Q, keyword_pinyin=%Q, title=%Q", _media->display_name, _media->added_time, _media->description, _media->longitude, _media->latitude, _media->altitude, _media->played_count, _media->played_time, _media->played_position, _media->rating, _media->favourite, _media->author, _media->provider, _media->content_name, _media->category, _media->location_tag, _media->age_rating, _media->keyword, _media->weather, _media->sync_status, - file_name_pinyin, description_pinyin, author_pinyin, provider_pinyin, content_name_pinyin, category_pinyin, location_tag_pinyin, age_rating_pinyin, keyword_pinyin); + file_name_pinyin, description_pinyin, author_pinyin, provider_pinyin, content_name_pinyin, category_pinyin, location_tag_pinyin, age_rating_pinyin, keyword_pinyin, _media->title); + + sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id); - len = snprintf(sql, sizeof(sql), "UPDATE %s SET %s WHERE media_uuid='%s'", DB_TABLE_MEDIA, set_sql, _media->media_id); + ret = _content_query_sql(sql); sqlite3_free(set_sql); + sqlite3_free(sql); SAFE_FREE(description_pinyin); SAFE_FREE(author_pinyin); @@ -2929,22 +3053,45 @@ int media_info_update_to_db(media_info_h media) SAFE_FREE(age_rating_pinyin); SAFE_FREE(keyword_pinyin); - if (len > 0) { - sql[len] = '\0'; - } else { - media_content_error("snprintf failed"); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + if(_media->storage_type == MEDIA_CONTENT_STORAGE_CLOUD) + { + set_sql = NULL; + sql = NULL; + + if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) + { + set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d, width=%d, height=%d", \ + _media->title, _media->video_meta->album, _media->video_meta->artist, _media->video_meta->genre, _media->video_meta->duration, _media->video_meta->width, _media->video_meta->height); + } + else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) + { + set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d", \ + _media->title, _media->audio_meta->album, _media->audio_meta->artist, _media->audio_meta->genre, _media->audio_meta->duration); + } + else if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) + { + set_sql = sqlite3_mprintf("title=%Q, width=%d, height=%d", _media->title, _media->image_meta->width, _media->image_meta->height); + } + else + { + set_sql = sqlite3_mprintf("title=%Q", _media->title); + } + sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id); + + ret = _content_query_sql(sql); + + sqlite3_free(set_sql); + sqlite3_free(sql); + } - ret = _content_query_sql(sql); if (ret == MEDIA_CONTENT_ERROR_NONE) { /* Send notification for this update */ media_content_debug("Update is successfull. Send notification for this"); if (_media->file_path && _media->mime_type) { - media_db_update_send(getpid(), MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, _media->file_path, _media->media_id, _media->media_type, _media->mime_type); + media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, _media->file_path, _media->media_type, _media->media_id, _media->mime_type); } else { - media_content_error("Can't media_db_update_send : path or mime type is NULL"); + media_content_error("Can't Send Noti : path or mime type is NULL"); } } } @@ -2984,6 +3131,13 @@ int media_info_refresh_metadata_to_db(const char *media_id) return ret; } + if(storage_type == MEDIA_CONTENT_STORAGE_CLOUD) + { + media_info_destroy(media); + media_content_error("Can't refresh cloud content!!"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + ret = media_info_get_file_path(media, &file_path); if(ret != MEDIA_CONTENT_ERROR_NONE) { @@ -2991,7 +3145,18 @@ int media_info_refresh_metadata_to_db(const char *media_id) return ret; } - ret = media_svc_refresh_item(_content_get_db_handle(), storage_type, file_path, tzplatform_getuid(TZ_USER_NAME)); + ret = _media_util_check_file(file_path); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SAFE_FREE(file_path); + media_info_destroy(media); + return ret; + } + + ret = media_svc_refresh_item(_content_get_db_handle(), storage_type, "media", file_path, tzplatform_getuid(TZ_USER_NAME)); + if (ret != MS_MEDIA_ERR_NONE) + { + ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } SAFE_FREE(file_path); media_info_destroy(media); @@ -3003,8 +3168,8 @@ int media_info_move_to_db(media_info_h media, const char* dst_path) { int ret = MEDIA_CONTENT_ERROR_NONE; - int src_storage_type = 0; - int dst_storage_type = 0; + media_svc_storage_type_e src_storage_type = 0; + media_svc_storage_type_e dst_storage_type = 0; if(media == NULL || !STRING_VALID(dst_path)) { @@ -3014,10 +3179,24 @@ int media_info_move_to_db(media_info_h media, const char* dst_path) media_info_s *_media = (media_info_s*)media; - ret = _media_util_get_store_type_by_path(_media->file_path, &src_storage_type); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - ret = _media_util_get_store_type_by_path(dst_path, &dst_storage_type); - media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + ret = _media_util_check_file(dst_path); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + return ret; + } + + ret = media_svc_get_storage_type(_media->file_path, &src_storage_type); + if(ret != MS_MEDIA_ERR_NONE) + { + media_content_sec_error("media_svc_get_storage_type failed : %d", ret); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + + ret = media_svc_get_storage_type(dst_path, &dst_storage_type); + if(ret != MS_MEDIA_ERR_NONE) + { + media_content_sec_error("media_svc_get_storage_type failed : %d", ret); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } ret = media_svc_move_item(_content_get_db_handle(), src_storage_type, _media->file_path, dst_storage_type, dst_path, tzplatform_getuid(TZ_USER_NAME)); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); @@ -3031,6 +3210,12 @@ int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb if(_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) { media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s*)calloc(1, sizeof(media_thumbnail_cb_s)); + if(_thumb_cb == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + _thumb_cb->handle = _media; _thumb_cb->user_data = user_data; _thumb_cb->thumbnail_completed_cb = callback; @@ -3065,3 +3250,696 @@ int media_info_cancel_thumbnail(media_info_h media) return ret; } + +static int __media_info_map_data_usr_to_svc(media_info_s *media, media_svc_content_info_s **service_content, media_content_storage_e storage_type) +{ + if(media == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + media_svc_content_info_s *svc_content_info = calloc(1, sizeof(media_svc_content_info_s)); + if(svc_content_info == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + svc_content_info->path = g_strdup(media->file_path); + svc_content_info->media_type = media->media_type; + svc_content_info->mime_type = g_strdup(media->mime_type); + svc_content_info->size = media->size; + svc_content_info->storage_type = storage_type; + svc_content_info->storage_uuid = g_strdup(media->storage_uuid); + + svc_content_info->added_time = media->added_time; + svc_content_info->modified_time = media->modified_time; + svc_content_info->thumbnail_path = g_strdup(media->thumbnail_path); + svc_content_info->is_drm = media->is_drm; + + svc_content_info->media_meta.title = g_strdup(media->title); + svc_content_info->media_meta.rating = media->rating; + svc_content_info->media_meta.description = g_strdup(media->description); + svc_content_info->media_meta.longitude = media->longitude; + svc_content_info->media_meta.latitude = media->latitude; + svc_content_info->media_meta.altitude = media->altitude; + svc_content_info->media_meta.weather = g_strdup(media->weather); + + switch(media->media_type) + { + case MEDIA_CONTENT_TYPE_IMAGE: + svc_content_info->media_meta.width = media->image_meta->width; + svc_content_info->media_meta.height = media->image_meta->height; + svc_content_info->media_meta.datetaken = g_strdup(media->image_meta->date_taken); + svc_content_info->media_meta.orientation = media->image_meta->orientation; + break; + case MEDIA_CONTENT_TYPE_VIDEO: + svc_content_info->media_meta.album = g_strdup(media->audio_meta->album); + svc_content_info->media_meta.artist = g_strdup(media->audio_meta->artist); + svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist); + svc_content_info->media_meta.genre = g_strdup(media->audio_meta->genre); + svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer); + svc_content_info->media_meta.year = g_strdup(media->audio_meta->year); + svc_content_info->media_meta.recorded_date = g_strdup(media->audio_meta->recorded_date); + svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright); + svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num); + svc_content_info->media_meta.bitrate = media->audio_meta->bitrate; + svc_content_info->media_meta.duration = media->audio_meta->duration; + svc_content_info->media_meta.width = media->image_meta->width; + svc_content_info->media_meta.height = media->image_meta->height; + break; + case MEDIA_CONTENT_TYPE_SOUND: + case MEDIA_CONTENT_TYPE_MUSIC: + svc_content_info->media_meta.album = g_strdup(media->audio_meta->album); + svc_content_info->media_meta.artist = g_strdup(media->audio_meta->artist); + svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist); + svc_content_info->media_meta.genre = g_strdup(media->audio_meta->genre); + svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer); + svc_content_info->media_meta.year = g_strdup(media->audio_meta->year); + svc_content_info->media_meta.recorded_date = g_strdup(media->audio_meta->recorded_date); + svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright); + svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num); + svc_content_info->media_meta.bitrate = media->audio_meta->bitrate; + svc_content_info->media_meta.duration = media->audio_meta->duration; + svc_content_info->media_meta.channel = media->audio_meta->channel; + svc_content_info->media_meta.samplerate = media->audio_meta->samplerate; + break; + case MEDIA_CONTENT_TYPE_OTHERS: + default: + break; + } + + *service_content = svc_content_info; + return MEDIA_CONTENT_ERROR_NONE; +} + +static int __media_info_set_str_data(media_info_h media, media_info_item_e data_type, const char *str_data) +{ + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + switch(data_type) + { + case MEDIA_INFO_PATH: + SAFE_FREE(_media->file_path); + if(STRING_VALID(str_data)) + { + _media->file_path = strdup(str_data); + + if(_media->file_path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->file_path = NULL; + } + break; + case MEDIA_INFO_MIME_TYPE: + SAFE_FREE(_media->mime_type); + if(STRING_VALID(str_data)) + { + _media->mime_type = strdup(str_data); + + if(_media->mime_type == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->mime_type = NULL; + } + break; + case MEDIA_INFO_THUMBNAIL_PATH: + SAFE_FREE(_media->thumbnail_path); + if(STRING_VALID(str_data)) + { + _media->thumbnail_path = strdup(str_data); + + if(_media->thumbnail_path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->thumbnail_path = NULL; + } + break; + case MEDIA_INFO_TITLE: + SAFE_FREE(_media->title); + if(STRING_VALID(str_data)) + { + _media->title = strdup(str_data); + + if(_media->title == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->title = NULL; + } + break; + case MEDIA_INFO_STORAGE_UUID: + SAFE_FREE(_media->storage_uuid); + if(STRING_VALID(str_data)) + { + _media->storage_uuid = strdup(str_data); + + if(_media->storage_uuid == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->storage_uuid = NULL; + } + break; + case MEDIA_INFO_ALBUM: + if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) + { + SAFE_FREE(_media->video_meta->album); + if(STRING_VALID(str_data)) + { + _media->video_meta->album = strdup(str_data); + + if(_media->video_meta->album == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->video_meta->album = NULL; + } + } + else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) + { + SAFE_FREE(_media->audio_meta->album); + if(STRING_VALID(str_data)) + { + _media->audio_meta->album = strdup(str_data); + + if(_media->audio_meta->album == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->audio_meta->album = NULL; + } + } + else + { + media_content_error("Invalid media type"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + case MEDIA_INFO_ARTIST: + if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) + { + SAFE_FREE(_media->video_meta->artist); + if(STRING_VALID(str_data)) + { + _media->video_meta->artist = strdup(str_data); + + if(_media->video_meta->artist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->video_meta->artist = NULL; + } + } + else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) + { + SAFE_FREE(_media->audio_meta->artist); + if(STRING_VALID(str_data)) + { + _media->audio_meta->artist = strdup(str_data); + + if(_media->audio_meta->artist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->audio_meta->artist = NULL; + } + } + else + { + media_content_error("Invalid media type"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + case MEDIA_INFO_GENRE: + if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) + { + SAFE_FREE(_media->video_meta->genre); + if(STRING_VALID(str_data)) + { + _media->video_meta->genre = strdup(str_data); + + if(_media->video_meta->genre == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->video_meta->genre = NULL; + } + } + else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) + { + SAFE_FREE(_media->audio_meta->genre); + if(STRING_VALID(str_data)) + { + _media->audio_meta->genre = strdup(str_data); + + if(_media->audio_meta->genre == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->audio_meta->genre = NULL; + } + } + else + { + media_content_error("Invalid media type"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + case MEDIA_INFO_RECORDED_DATE: + if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) + { + SAFE_FREE(_media->video_meta->recorded_date); + if(STRING_VALID(str_data)) + { + _media->video_meta->recorded_date = strdup(str_data); + + if(_media->video_meta->recorded_date == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->video_meta->recorded_date = NULL; + } + } + else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) + { + SAFE_FREE(_media->audio_meta->recorded_date); + if(STRING_VALID(str_data)) + { + _media->audio_meta->recorded_date = strdup(str_data); + + if(_media->audio_meta->recorded_date == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->audio_meta->recorded_date = NULL; + } + } + else + { + media_content_error("Invalid media type"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + default: + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return MEDIA_CONTENT_ERROR_NONE; +} + +int media_info_insert_to_db_with_data(media_info_h media, media_info_h *info) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if (!STRING_VALID(_media->file_path)) + { + media_content_error("invalid media path"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if (!STRING_VALID(_media->mime_type)) + { + media_content_error("invalid mime_type"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if (!STRING_VALID(_media->storage_uuid)) + { + media_content_error("invalid storage_uuid"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if (!STRING_VALID(_media->title)) + { + media_content_error("invalid title"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(_media->storage_type < 0) + { + media_content_error("invalid storage_type"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if ((_media->media_type < MEDIA_CONTENT_TYPE_IMAGE) || (_media->media_type > MEDIA_CONTENT_TYPE_OTHERS)) + { + media_content_error("invalid media type [%d]", _media->media_type); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if (_media->size <= 0) + { + media_content_error("invalid size [%d]", _media->size); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if (_media->modified_time <= 0) + { + media_content_error("invalid modified_time [%d]", _media->modified_time); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + media_content_sec_debug("storage[%d], path[%s], media_type[%d]", _media->storage_type, _media->file_path, _media->media_type); + + media_svc_content_info_s *svc_content_info = NULL; + + ret = __media_info_map_data_usr_to_svc(_media, &svc_content_info, MEDIA_CONTENT_STORAGE_CLOUD); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(svc_content_info == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } +#if 0 + ret = media_svc_insert_item_immediately_with_data(_content_get_db_handle(), svc_content_info); + if(ret != MS_MEDIA_ERR_NONE) { + media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, _media->file_path); + media_svc_destroy_content_info(svc_content_info); + SAFE_FREE(svc_content_info); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + /*free the svc_content_info*/ + media_svc_destroy_content_info(svc_content_info); + SAFE_FREE(svc_content_info); +#endif + if(info != NULL) + { + media_info_s *_get_media = (media_info_s*)calloc(1, sizeof(media_info_s)); + if(_get_media == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + ret = _media_info_get_media_info_from_db(_media->file_path, _media->storage_uuid, (media_info_h)_get_media); + + *info = (media_info_h)_get_media; + } + + return ret; +} + +int media_info_create_handle(media_info_h *media) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + media_info_s *_media = (media_info_s*)calloc(1,sizeof(media_info_s)); + if(_media == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s)); + if(_media->audio_meta == NULL) + { + SAFE_FREE(_media); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s)); + if(_media->video_meta == NULL) + { + SAFE_FREE(_media->audio_meta); + SAFE_FREE(_media); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s)); + if(_media->image_meta == NULL) + { + SAFE_FREE(_media->audio_meta); + SAFE_FREE(_media->video_meta); + SAFE_FREE(_media); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _media->storage_type = -1; + _media->media_type = -1; + _media->modified_time = -1; + _media->size = -1; + + *media = (media_info_h)_media; + + return ret; +} + +int media_info_set_path(media_info_h media, const char *path) +{ + return __media_info_set_str_data(media, MEDIA_INFO_PATH, path); +} + +int media_info_set_mime_type(media_info_h media, const char *mime_type) +{ + return __media_info_set_str_data(media, MEDIA_INFO_MIME_TYPE, mime_type); +} + +int media_info_set_title(media_info_h media, const char *title) +{ + return __media_info_set_str_data(media, MEDIA_INFO_TITLE, title); +} + +int media_info_set_album(media_info_h media, const char *album) +{ + return __media_info_set_str_data(media, MEDIA_INFO_ALBUM, album); +} + +int media_info_set_artist(media_info_h media, const char *artist) +{ + return __media_info_set_str_data(media, MEDIA_INFO_ARTIST, artist); +} + +int media_info_set_genre(media_info_h media, const char *genre) +{ + return __media_info_set_str_data(media, MEDIA_INFO_GENRE, genre); +} + +int media_info_set_recorded_date(media_info_h media, const char *recorded_date) +{ + return __media_info_set_str_data(media, MEDIA_INFO_RECORDED_DATE, recorded_date); +} + +int media_info_set_thumbnail_path(media_info_h media, const char *thumbnail_path) +{ + return __media_info_set_str_data(media, MEDIA_INFO_THUMBNAIL_PATH, thumbnail_path); +} + +int media_info_set_storage_id(media_info_h media, const char *storage_id) +{ + return __media_info_set_str_data(media, MEDIA_INFO_STORAGE_UUID, storage_id); +} + +int media_info_set_size(media_info_h media, unsigned long long size) +{ + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + _media->size = size; + + return MEDIA_CONTENT_ERROR_NONE; +} + +int media_info_set_modified_time(media_info_h media, time_t modified_time) +{ + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + _media->modified_time = modified_time; + + return MEDIA_CONTENT_ERROR_NONE; +} + +int media_info_set_media_type(media_info_h media, media_content_type_e type) +{ + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + _media->media_type = type; + + return MEDIA_CONTENT_ERROR_NONE; +} + +int media_info_set_duration(media_info_h media, int duration) +{ + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) + _media->video_meta->duration = duration; + else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) + _media->audio_meta->duration = duration; + else + { + media_content_error("Invalid media type"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return MEDIA_CONTENT_ERROR_NONE; +} + +int media_info_set_width(media_info_h media, int width) +{ + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) + _media->video_meta->width = width; + else if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) + _media->image_meta->width = width; + else + { + media_content_error("Invalid media type"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return MEDIA_CONTENT_ERROR_NONE; +} + +int media_info_set_height(media_info_h media, int height) +{ + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) + _media->video_meta->height = height; + else if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) + _media->image_meta->height = height; + else + { + media_content_error("Invalid media type"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return MEDIA_CONTENT_ERROR_NONE; +} + +int media_info_set_storage_type(media_info_h media, media_content_storage_e storage_type) +{ + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + _media->storage_type = storage_type; + + return MEDIA_CONTENT_ERROR_NONE; +} diff --git a/src/media_playlist.c b/src/media_playlist.c index 408dc2f..b249ce9 100755 --- a/src/media_playlist.c +++ b/src/media_playlist.c @@ -20,6 +20,9 @@ #include #include +#define PLAYLIST_ARRAY_SIZE 20 +#define PLAYLIST_ARRAY_EXPAND 10 +#define MAX_TMP_STR 2048 static __thread GList *g_playlist_item_list = NULL; @@ -31,6 +34,11 @@ static int __media_playlist_remove_item_from_playlist(int playlist_id, int playl static int __media_playlist_update_playlist_name(int playlist_id, const char *playlist_name); static int __media_playlist_update_thumbnail_path(int playlist_id, const char *path); static int __media_playlist_update_play_order(int playlist_id, int playlist_member_id, int play_order); +static int __media_playlist_reset_file(const char* playlist_path); +static int __media_playlist_append_to_file(const char* playlist_path, const char* path); +static int __media_playlist_import_item_from_file(const char* playlist_path, char*** const item_list, int* item_count); +static int __media_playlist_destroy_import_item(char** item_list, int item_count); +static void __media_playlist_destroy_export_item(gpointer data); static void __media_playlist_item_add(media_playlist_item_s *item_s) { @@ -178,6 +186,220 @@ static int __media_playlist_update_play_order(int playlist_id, int playlist_memb return ret; } +static bool __media_playlist_media_info_cb(media_info_h media, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char **media_id = (char**)user_data; + ret = media_info_get_media_id(media, media_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("Fail to get file path"); + return FALSE; + } + return TRUE; +} + +static bool __media_playlist_member_cb(int playlist_member_id, media_info_h media, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + GList **list = (GList**)user_data; + char *path = NULL; + + ret = media_info_get_file_path(media, &path); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("Fail to get file path"); + return FALSE; + } + + *list = g_list_append(*list, path); + + return TRUE; +} + +static int __media_playlist_reset_file(const char* playlist_path) +{ + FILE *fp = NULL; + + fp = fopen(playlist_path, "wb"); + if(fp == NULL) + { + media_content_stderror("fopen fail"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + fputs("", fp); // remove previous playlist + + fclose(fp); + + return MEDIA_CONTENT_ERROR_NONE; +} + +static int __media_playlist_append_to_file(const char* playlist_path, const char* path) +{ + FILE *fp = NULL; + + fp = fopen(playlist_path, "a"); // append only + if(fp == NULL) + { + media_content_stderror("fopen fail"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + fputs(path, fp); + + fputs("\n", fp); + + fclose(fp); + + return MEDIA_CONTENT_ERROR_NONE; +} + +static int __media_playlist_import_item_from_file(const char* playlist_path, char*** const item_list, int* item_count) +{ + int current_index = 0; // Current record number + int current_max_size = PLAYLIST_ARRAY_SIZE; // Current max number of records in array + int tmp_str_len = 0; // Length of the string + char *buf = NULL; + char *tmp_buf = NULL; + char *tmp_str = NULL; // Next line from buffer, this string is used for parsing + + FILE *fp = NULL; + long int file_size = 0; + + *item_list = NULL; *item_count = 0; + + fp = fopen(playlist_path, "rb"); // Open as binary for precise estimation of file length + if(fp == NULL) + { + media_content_stderror("fopen fail"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + fseek(fp, 0, SEEK_END); // Move to the end of file + file_size = ftell(fp); // Here we can find the size of file + fseek(fp, 0 , SEEK_SET); // Return to the beginning of file + + if(file_size == 0) { + media_content_debug("file is empty."); + fclose(fp); + return MEDIA_CONTENT_ERROR_NONE; + } + // Allocate the memory and copy file content there + if(file_size > 0) + buf = malloc(file_size + 1); + + if(buf == NULL) + { + media_content_error("Out of Memory"); + fclose(fp); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + tmp_buf = buf; + + if(fread(buf, file_size, 1, fp) != 1) { + fclose(fp); + SAFE_FREE(buf); + media_content_stderror("fread fail"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + buf[file_size] = 0; + fclose(fp); + + // Preliminary memory allocation + *item_list = calloc(current_max_size, sizeof(char*)); + tmp_str = malloc(MAX_TMP_STR); + if (tmp_str == NULL || *item_list == NULL) { + SAFE_FREE(*item_list); + SAFE_FREE(buf); + SAFE_FREE(tmp_str); + media_content_error("Out of Memory"); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + // Here we create format string for sscanf(...) that allows to get a line from buffer + char format[25]; + snprintf(format, 25, "%%%d[^\n]", MAX_TMP_STR); + + // This cycle gets lines one by one from buffer till the end of buffer. Empty line ("\n") must be treated specifically + while((sscanf(tmp_buf, format, tmp_str) == 1) || (*tmp_buf == '\n')) { + if(*tmp_buf == '\n') {// Check if there is an empty line, skip '\n' symbol + tmp_buf += 1; + + if(tmp_buf < (buf + file_size)) + continue; // We are still in buffer + else + break; // Empty line was in the end of buffer + } + + tmp_str_len = strlen(tmp_str); // Save the length of line + + if(tmp_str[0] != '#') { // Check that the line is not a comment + if(!(current_index < (current_max_size - 1))) { // Check if we have completely filled record array + // Expand array size and relocate the array (records will be copied into new one) + current_max_size += PLAYLIST_ARRAY_EXPAND; + char **tmp_ptr = calloc(current_max_size, sizeof(char*)); + if (tmp_ptr == NULL) { + __media_playlist_destroy_import_item(*item_list, current_index); + SAFE_FREE(buf); + SAFE_FREE(tmp_str); + media_content_error("Out of Memory"); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + memmove(tmp_ptr, *item_list, sizeof(char*) * current_index); + SAFE_FREE(*item_list); + *item_list = tmp_ptr; + } + + // Save new file path (current string in tmp_str) + (*item_list)[current_index] = malloc(tmp_str_len + 1); + if ((*item_list)[current_index] == NULL) { + __media_playlist_destroy_import_item(*item_list, current_index); + SAFE_FREE(buf); + SAFE_FREE(tmp_str); + media_content_error("Out of Memory"); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + memmove((*item_list)[current_index], tmp_str, tmp_str_len + 1); + + // Increase the index of buffer + current_index += 1; + } + + tmp_buf += (tmp_str_len + 1); // Move position in buffer after the string that was parsed + } + + *item_count = current_index; // Now we need to save the number of records in array + + SAFE_FREE(buf); + SAFE_FREE(tmp_str); // Free temporary variables + + return MEDIA_CONTENT_ERROR_NONE; +} + +static int __media_playlist_destroy_import_item(char** item_list, int item_count) +{ + int i; + + for(i = 0; i < item_count; ++i) { + SAFE_FREE(item_list[i]); + item_list[i] = NULL; + } + + if (item_list != NULL) { + SAFE_FREE(item_list); + item_list = NULL; + } + + return MEDIA_CONTENT_ERROR_NONE; +} + +static void __media_playlist_destroy_export_item(gpointer data) +{ + SAFE_FREE(data); + data = NULL; +} + int media_playlist_insert_to_db(const char *name, media_playlist_h *playlist) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -190,7 +412,6 @@ int media_playlist_insert_to_db(const char *name, media_playlist_h *playlist) } media_playlist_s *_playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s)); - if(_playlist == NULL) { media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); @@ -244,8 +465,6 @@ int media_playlist_get_playlist_count_from_db(filter_h filter, int *playlist_cou { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(playlist_count != NULL) { ret = _media_db_get_group_count(filter, MEDIA_GROUP_PLAYLIST, playlist_count); @@ -263,8 +482,6 @@ int media_playlist_foreach_playlist_from_db(filter_h filter, media_playlist_cb c { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(callback == NULL) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -280,8 +497,6 @@ int media_playlist_get_media_count_from_db(int playlist_id, filter_h filter, int { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if((playlist_id > 0) && (media_count != NULL)) { ret = _media_db_get_group_item_count_by_id(playlist_id, filter, MEDIA_GROUP_PLAYLIST, media_count); @@ -299,11 +514,8 @@ int media_playlist_foreach_media_from_db(int playlist_id, filter_h filter, playl { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if((playlist_id > 0) && (callback != NULL)) { - //ret = _media_db_get_group_item_by_id(playlist_id, filter, callback, user_data, MEDIA_GROUP_PLAYLIST); ret = _media_db_get_playlist_item(playlist_id, filter, callback, user_data); } else @@ -395,12 +607,18 @@ int media_playlist_get_playlist_from_db(int playlist_id, media_playlist_h *playl while(sqlite3_step(stmt) == SQLITE_ROW) { media_playlist_s *_playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s)); + if(_playlist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } _playlist->playlist_id = (int)sqlite3_column_int(stmt, 0); if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) _playlist->name = strdup((const char *)sqlite3_column_text(stmt, 1)); - if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) - _playlist->thumbnail_path = strdup((const char *)sqlite3_column_text(stmt, 2)); + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3))) + _playlist->thumbnail_path = strdup((const char *)sqlite3_column_text(stmt, 3)); *playlist = (media_playlist_h)_playlist; } @@ -540,6 +758,11 @@ int media_playlist_set_name(media_playlist_h playlist, const char *playlist_name SAFE_FREE(_playlist->name); media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s)); + if(item == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } item->playlist_name = strdup(playlist_name); item->function = MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME; @@ -580,6 +803,11 @@ int media_playlist_set_thumbnail_path(media_playlist_h playlist, const char *pat SAFE_FREE(_playlist->thumbnail_path); media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s)); + if(item == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } item->thumbnail_path = strdup(path); item->function = MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH; @@ -618,6 +846,11 @@ int media_playlist_set_play_order(media_playlist_h playlist, int playlist_member if((_playlist != NULL) && (playlist_member_id > 0) && (play_order >= 0)) { media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s)); + if(item == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } item->playlist_member_id = playlist_member_id; item->function = MEDIA_PLAYLIST_UPDATE_PLAY_ORDER; @@ -642,6 +875,11 @@ int media_playlist_add_media(media_playlist_h playlist, const char *media_id) if(_playlist != NULL && STRING_VALID(media_id)) { media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s)); + if(item == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } item->media_id = strdup(media_id); item->function = MEDIA_PLAYLIST_ADD; @@ -673,6 +911,11 @@ int media_playlist_remove_media(media_playlist_h playlist, int playlist_member_i if((_playlist != NULL) && (playlist_member_id > 0)) { media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s)); + if(item == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } item->playlist_member_id = playlist_member_id; item->function = MEDIA_PLAYLIST_REMOVE; @@ -745,3 +988,160 @@ int media_playlist_update_to_db(media_playlist_h playlist) return ret; } + +int media_playlist_import_from_file(const char *path, const char *playlist_name, media_playlist_h *playlist) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char** import_item_list = NULL; + int import_item_count = 0; + int idx; + + if(!STRING_VALID(path)) + { + media_content_error("Invalid path"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(!STRING_VALID(playlist_name)) + { + media_content_error("Invalid playlist_name"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = media_playlist_insert_to_db(playlist_name, playlist); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("Fail to insert playlist to db"); + return ret; + } + + ret = __media_playlist_import_item_from_file(path, &import_item_list, &import_item_count); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + __media_playlist_destroy_import_item(import_item_list, import_item_count); + media_content_error("Fail to get playlist from file"); + return ret; + } + + if (import_item_count == 0) + { + media_content_debug("The playlist from file is empty"); + } + + for (idx=0; idx < import_item_count; idx++) + { + filter_h filter = NULL; + char *media_id = NULL; + char *condition = NULL; + + ret = media_filter_create(&filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + __media_playlist_destroy_import_item(import_item_list, import_item_count); + media_filter_destroy(filter); + media_content_error("error media_filter_create"); + return ret; + } + condition = sqlite3_mprintf("path = '%q'", import_item_list[idx]); + ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + __media_playlist_destroy_import_item(import_item_list, import_item_count); + media_filter_destroy(filter); + sqlite3_free(condition); + media_content_error("error media_filter_set_condition"); + return ret; + } + ret = _media_db_get_group_item(NULL, filter, __media_playlist_media_info_cb, &media_id, MEDIA_GROUP_NONE); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + __media_playlist_destroy_import_item(import_item_list, import_item_count); + media_filter_destroy(filter); + SAFE_FREE(media_id); + sqlite3_free(condition); + media_content_error("error media_info_foreach_media_from_db"); + return ret; + } + ret = media_playlist_add_media((media_playlist_h)*playlist, media_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + __media_playlist_destroy_import_item(import_item_list, import_item_count); + media_filter_destroy(filter); + SAFE_FREE(media_id); + sqlite3_free(condition); + media_content_error("error media_playlist_add_media"); + return ret; + } + media_filter_destroy(filter); + SAFE_FREE(media_id); + sqlite3_free(condition); + } + + ret = media_playlist_update_to_db(*playlist); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + __media_playlist_destroy_import_item(import_item_list, import_item_count); + media_content_error("Fail to update playlist to db"); + return ret; + } + __media_playlist_destroy_import_item(import_item_list, import_item_count); + + return ret; +} + +int media_playlist_export_to_file(media_playlist_h playlist, const char* path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_s *_playlist = (media_playlist_s*)playlist; + GList *item_list = NULL; + int idx; + + if(!STRING_VALID(path)) + { + media_content_error("Invalid path"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(_playlist == NULL) + { + media_content_error("Invalid playlist"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(_playlist->playlist_id <= 0) + { + media_content_error("Invalid playlist id"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = _media_db_get_playlist_item(_playlist->playlist_id, NULL, __media_playlist_member_cb, &item_list); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("Fail to get playlist from db"); + return ret; + } + + ret = __media_playlist_reset_file(path); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + g_list_free_full(item_list, __media_playlist_destroy_export_item); + media_content_error("Fail to init playlist file"); + return ret; + } + + for (idx=0; idx < g_list_length(item_list); idx++) + { + char *item = g_list_nth_data(item_list, idx); + ret = __media_playlist_append_to_file(path, item); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + g_list_free_full(item_list, __media_playlist_destroy_export_item); + media_content_error("Fail to export paths into file"); + return ret; + } + } + + g_list_free_full(item_list, __media_playlist_destroy_export_item); + + return ret; +} diff --git a/src/media_storage.c b/src/media_storage.c new file mode 100755 index 0000000..0e9a161 --- /dev/null +++ b/src/media_storage.c @@ -0,0 +1,454 @@ + /* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include + +static void __media_storage_get_detail(sqlite3_stmt* stmt, media_storage_h storage) +{ + media_storage_s *_storage = (media_storage_s*)storage; + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) + _storage->storage_id = strdup((const char *)sqlite3_column_text(stmt, 0)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + _storage->storage_name = strdup((const char *)sqlite3_column_text(stmt, 1)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) + _storage->storage_path = strdup((const char *)sqlite3_column_text(stmt, 2)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3))) + _storage->storage_account = strdup((const char *)sqlite3_column_text(stmt, 3)); + + _storage->storage_type = (int)sqlite3_column_int(stmt, 4); + + return; +} + +int media_storage_insert_to_db(const char *storage_name, const char *storage_path, const char *storage_account, media_content_storage_e storage_type, media_storage_h *storage) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *storage_uuid = NULL; + media_storage_s *_storage = NULL; + + if(!STRING_VALID(storage_name)) + { + media_content_error("Invalid Storage Name"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(!STRING_VALID(storage_path)) + { + media_content_error("Invalid path"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + storage_uuid = media_info_generate_uuid(); + if(storage_uuid == NULL) + { + media_content_error("Fail to get storage_id"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + //ret = media_svc_insert_storage(_content_get_db_handle(), storage_uuid, storage_name, storage_path, storage_account, storage_type); + if (ret != MS_MEDIA_ERR_NONE) + { + ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret); + return ret; + } + + _storage = (media_storage_s*)calloc(1, sizeof(media_storage_s)); + if(_storage == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _storage->storage_id = strdup(storage_uuid); + _storage->storage_path = strdup(storage_path); + _storage->storage_name = strdup(storage_name); + _storage->storage_type = storage_type; + + *storage = (media_storage_h)_storage; + + return ret; +} + +int media_storage_delete_from_db(const char *storage_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(!STRING_VALID(storage_id)) + { + media_content_error("Invalid Storage ID"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + //ret = media_svc_delete_storage(_content_get_db_handle(), storage_id); + + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); +} + +int media_storage_get_storage_info_from_db(const char *storage_id, media_storage_h *storage) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[DEFAULT_QUERY_SIZE]; + sqlite3_stmt *stmt = NULL; + + if(!STRING_VALID(storage_id) || (storage == NULL)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + memset(select_query, 0x00, sizeof(select_query)); + snprintf(select_query, sizeof(select_query), SELECT_STORAGE_INFO_FROM_STORAGE, storage_id); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_storage_s *_storage = (media_storage_s*)calloc(1, sizeof(media_storage_s)); + + if(_storage == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + __media_storage_get_detail(stmt, (media_storage_h)_storage); + + *storage = (media_storage_h)_storage; + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int media_storage_get_storage_count_from_db(filter_h filter, int *storage_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(storage_count) + { + ret = _media_db_get_group_count(filter, MEDIA_GROUP_STORAGE, storage_count); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_storage_foreach_storage_from_db(filter_h filter, media_storage_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(callback != NULL) + { + ret = _media_db_get_storage(filter, callback, user_data); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_storage_get_media_count_from_db(const char *storage_id, filter_h filter, int *media_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(STRING_VALID(storage_id) && media_count) + { + ret = _media_db_get_group_item_count(storage_id, filter, MEDIA_GROUP_STORAGE, media_count); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_storage_foreach_media_from_db(const char *storage_id, filter_h filter, media_info_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((callback != NULL) && STRING_VALID(storage_id)) + { + ret = _media_db_get_group_item(storage_id, filter, callback, user_data, MEDIA_GROUP_STORAGE); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_storage_destroy(media_storage_h storage) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_storage_s *_storage = (media_storage_s*)storage; + if(_storage) + { + SAFE_FREE(_storage->storage_id); + SAFE_FREE(_storage->storage_path); + SAFE_FREE(_storage->storage_name); + SAFE_FREE(_storage->storage_account); + SAFE_FREE(_storage); + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_storage_clone(media_storage_h *dst, media_storage_h src) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_storage_s *_src = (media_storage_s*)src; + + if(_src != NULL) + { + media_storage_s *_dst = (media_storage_s*)calloc(1, sizeof(media_storage_s)); + if(_dst == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(STRING_VALID(_src->storage_id)) + { + _dst->storage_id = strdup(_src->storage_id); + if(_dst->storage_id == NULL) + { + media_storage_destroy((media_storage_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->storage_name)) + { + _dst->storage_name = strdup(_src->storage_name); + if(_dst->storage_name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_storage_destroy((media_storage_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->storage_path)) + { + _dst->storage_path = strdup(_src->storage_path); + if(_dst->storage_path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_storage_destroy((media_storage_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->storage_account)) + { + _dst->storage_account = strdup(_src->storage_account); + if(_dst->storage_account == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_storage_destroy((media_storage_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + _dst->storage_type = _src->storage_type; + + *dst = (media_storage_h)_dst; + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_storage_get_id(media_storage_h storage, char **storage_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_storage_s *_storage = (media_storage_s*)storage; + + if(_storage && storage_id) + { + if(STRING_VALID(_storage->storage_id)) + { + *storage_id = strdup(_storage->storage_id); + if(*storage_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *storage_id = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_storage_get_name(media_storage_h storage, char **storage_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_storage_s *_storage = (media_storage_s*)storage; + + if(_storage && storage_name) + { + if(STRING_VALID(_storage->storage_name)) + { + *storage_name = strdup(_storage->storage_name); + if(*storage_name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *storage_name = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_storage_get_path(media_storage_h storage, char **storage_path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_storage_s *_storage = (media_storage_s*)storage; + + if(_storage && storage_path) + { + if(STRING_VALID(_storage->storage_path)) + { + *storage_path = strdup(_storage->storage_path); + if(*storage_path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *storage_path = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_storage_get_storage_account(media_storage_h storage, char **storage_account) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_storage_s *_storage = (media_storage_s*)storage; + + if(_storage && storage_account) + { + if(STRING_VALID(_storage->storage_account)) + { + *storage_account = strdup(_storage->storage_account); + if(*storage_account == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *storage_account = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_storage_get_type(media_storage_h storage, media_content_storage_e *storage_type) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_storage_s *_storage = (media_storage_s*)storage; + + if(_storage && storage_type) + { + *storage_type = _storage->storage_type; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} diff --git a/src/media_tag.c b/src/media_tag.c index 8522023..d3a5f01 100755 --- a/src/media_tag.c +++ b/src/media_tag.c @@ -15,7 +15,6 @@ */ -#include #include @@ -187,8 +186,6 @@ int media_tag_get_tag_count_from_db(filter_h filter, int *tag_count) { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(tag_count != NULL) { ret = _media_db_get_group_count(filter, MEDIA_GROUP_TAG, tag_count); @@ -206,8 +203,6 @@ int media_tag_foreach_tag_from_db (filter_h filter, media_tag_cb callback, void { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(callback == NULL) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -223,8 +218,6 @@ int media_tag_get_media_count_from_db(int tag_id, filter_h filter, int *media_co { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if((tag_id > 0) && (media_count != NULL)) { ret = _media_db_get_group_item_count_by_id(tag_id, filter, MEDIA_GROUP_TAG, media_count); @@ -242,8 +235,6 @@ int media_tag_foreach_media_from_db(int tag_id, filter_h filter, media_info_cb c { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_debug_func(); - if(callback == NULL) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -416,6 +407,11 @@ int media_tag_add_media(media_tag_h tag, const char *media_id) if((_tag != NULL) && STRING_VALID(media_id)) { media_tag_item_s *_item = (media_tag_item_s*)calloc(1, sizeof(media_tag_item_s)); + if(_item == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } _item->media_id = strdup(media_id); _item->function = MEDIA_TAG_ADD; @@ -446,6 +442,11 @@ int media_tag_remove_media(media_tag_h tag, const char *media_id) if(_tag != NULL && STRING_VALID(media_id)) { media_tag_item_s *_item = (media_tag_item_s*)calloc(1, sizeof(media_tag_item_s)); + if(_item == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } _item->media_id = strdup(media_id); _item->function = MEDIA_TAG_REMOVE; @@ -478,6 +479,11 @@ int media_tag_set_name(media_tag_h tag, char *tag_name) SAFE_FREE(_tag->name); media_tag_item_s *_item = (media_tag_item_s*)calloc(1, sizeof(media_tag_item_s)); + if(_item == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } _item->tag_name = strdup(tag_name); _item->function = MEDIA_TAG_UPDATE_TAG_NAME; diff --git a/src/media_util_private.c b/src/media_util_private.c index 0d3716f..b29e151 100755 --- a/src/media_util_private.c +++ b/src/media_util_private.c @@ -14,32 +14,32 @@ * limitations under the License. */ - +#include #include #include +#include +#include #include #include #include - -int _media_util_get_store_type_by_path(const char *path, int *storage_type) +int _media_util_check_file(const char *path) { - if(STRING_VALID(path)) - { - if(strncmp(path, MEDIA_CONTENT_PATH_PHONE, strlen(MEDIA_CONTENT_PATH_PHONE)) == 0) - { - *storage_type = MEDIA_CONTENT_STORAGE_INTERNAL; - } - else if(strncmp (path, MEDIA_CONTENT_PATH_MMC, strlen(MEDIA_CONTENT_PATH_MMC)) == 0) - { - *storage_type = MEDIA_CONTENT_STORAGE_EXTERNAL; + int exist; + + /* check the file exits actually */ + exist = open(path, O_RDONLY); + if(exist < 0) { + media_content_sec_debug("path [%s]", path); + media_content_stderror("open file fail"); + if (errno == EACCES || errno == EPERM) { + return MEDIA_CONTENT_ERROR_PERMISSION_DENIED; + } else { + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } } - else - { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + + close(exist); return MEDIA_CONTENT_ERROR_NONE; } @@ -51,7 +51,7 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore) char *scan_ignore = ".scan_ignore"; bool find = false; - media_content_info("dir_path : %s", dir_path); + media_content_sec_debug("dir_path : %s", dir_path); if(!STRING_VALID(dir_path)) { @@ -101,13 +101,13 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore) if(STRING_VALID(entry.d_name) && (strcmp(entry.d_name, scan_ignore) == 0)) { media_content_info("Find Ignore path"); - media_content_info("Ignore path[%s]", search_path); + media_content_sec_debug("Ignore path[%s]", search_path); find = TRUE; break; } else { - //media_content_info("entry.d_name[%s]", entry.d_name); + //media_content_sec_debug("entry.d_name[%s]", entry.d_name); continue; } } @@ -139,7 +139,7 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore) { int seek_len = leaf_path -search_path; search_path[seek_len] = '\0'; - //media_content_info("go to other dir [%s]", search_path); + //media_content_sec_debug("go to other dir [%s]", search_path); } else { diff --git a/src/media_video.c b/src/media_video.c index 77a15bc..4b8ad58 100755 --- a/src/media_video.c +++ b/src/media_video.c @@ -15,9 +15,7 @@ */ -#include #include -#include int video_meta_destroy(video_meta_h video) @@ -726,7 +724,13 @@ int video_meta_update_to_db(video_meta_h video) if(_video != NULL && STRING_VALID(_video->media_id)) { - sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, _video->played_count, _video->played_time, _video->played_position, _video->media_id); + char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,}; + memset(storage_id, 0x00, sizeof(storage_id)); + + ret = _media_db_get_storage_id_by_media_id(_video->media_id, storage_id); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, storage_id, _video->played_count, _video->played_time, _video->played_position, _video->media_id); ret = _content_query_sql(sql); sqlite3_free(sql); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6ee9acf..efefc2b 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,7 +7,7 @@ FOREACH(flag ${${fw_test}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -pie") aux_source_directory(. sources) FOREACH(src ${sources}) diff --git a/test/media-content_test.c b/test/media-content_test.c index 0086c0a..07684fd 100755 --- a/test/media-content_test.c +++ b/test/media-content_test.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -303,11 +304,7 @@ bool media_item_cb(media_info_h media, void *user_data) { char *c_value = NULL; char *media_id = NULL; - int i_value = 0; - time_t t_value = 0; - bool b_value = false; media_content_type_e media_type = 0; - unsigned long long size = 0; int ret = MEDIA_CONTENT_ERROR_NONE; if(media == NULL) @@ -332,7 +329,12 @@ bool media_item_cb(media_info_h media, void *user_data) media_content_debug("file_path : [%s]", c_value); SAFE_FREE(c_value); -#if 1 +#if 0 + int i_value = 0; + time_t t_value = 0; + bool b_value = false; + unsigned long long size = 0; + if(media_type == MEDIA_CONTENT_TYPE_MUSIC) { audio_meta_h audio; @@ -513,9 +515,7 @@ bool media_item_cb(media_info_h media, void *user_data) if(ret != MEDIA_CONTENT_ERROR_NONE) media_content_error("error when get info : [%d]", ret); media_content_debug("is_drm : [%d]", b_value); - - // build error - /* + ret = media_info_set_weather(media, "Sunny"); if(ret != MEDIA_CONTENT_ERROR_NONE) { media_content_error("Fail to set weather"); @@ -526,13 +526,13 @@ bool media_item_cb(media_info_h media, void *user_data) media_content_error("error when get info : [%d]", ret); media_content_debug("weather : [%s]", c_value); SAFE_FREE(c_value); - */ /* Media server can't update when another db handle holds DB connection by sqlite3_prepare */ //ret = media_info_set_location_tag(media, "Test location tag"); //media_info_update_to_db(media); SAFE_FREE(media_id); #endif + SAFE_FREE(media_id); return true; } @@ -540,8 +540,8 @@ bool folder_list_cb(media_folder_h folder, void *user_data) { int item_count; char *folder_id = NULL; - char *folder_path = NULL; - char *folder_name = NULL; + char *str_val = NULL; + int int_val = -1; media_content_storage_e storage_type; bool ret; media_folder_h *_folder = (media_folder_h*)user_data; @@ -558,40 +558,50 @@ bool folder_list_cb(media_folder_h folder, void *user_data) } media_content_debug("folder_id = [%s]", folder_id); - if(media_folder_get_path(folder, &folder_path) != MEDIA_CONTENT_ERROR_NONE) + if(media_folder_get_path(folder, &str_val) != MEDIA_CONTENT_ERROR_NONE) { SAFE_FREE(folder_id); media_content_error("[ERROR] media_folder_get_path is failed"); return false; } - media_content_debug("folder_path = [%s]", folder_path); - SAFE_FREE(folder_path); + media_content_debug("folder_path = [%s]", str_val); + SAFE_FREE(str_val); - if(media_folder_get_name(folder, &folder_name) != MEDIA_CONTENT_ERROR_NONE) + if(media_folder_get_name(folder, &str_val) != MEDIA_CONTENT_ERROR_NONE) { SAFE_FREE(folder_id); - SAFE_FREE(folder_path); media_content_error("[ERROR] media_folder_get_name is failed"); return false; } - media_content_debug("folder_name = [%s]", folder_name); - SAFE_FREE(folder_name); + media_content_debug("folder_name = [%s]", str_val); + SAFE_FREE(str_val); if(media_folder_get_storage_type(folder, &storage_type) != MEDIA_CONTENT_ERROR_NONE) { SAFE_FREE(folder_id); - SAFE_FREE(folder_path); - SAFE_FREE(folder_name); media_content_error("[ERROR] media_folder_get_storage_type is failed"); return false; } media_content_debug("storage_type = [%d]", storage_type); + if(media_folder_get_storage_id(folder, &str_val) != MEDIA_CONTENT_ERROR_NONE) + { + SAFE_FREE(folder_id); + media_content_error("[ERROR] media_folder_get_name is failed"); + return false; + } + media_content_debug("storage_id = [%s]", str_val); + + if(media_folder_get_order(folder, &int_val) != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("[ERROR] media_folder_get_order is failed"); + return false; + } + media_content_debug("folder_order = [%d]", int_val); + if(media_folder_get_media_count_from_db(folder_id, g_filter, &item_count) != MEDIA_CONTENT_ERROR_NONE) { SAFE_FREE(folder_id); - SAFE_FREE(folder_path); - SAFE_FREE(folder_name); media_content_error("[ERROR] media_folder_get_media_count_from_db is failed"); return false; } @@ -599,16 +609,11 @@ bool folder_list_cb(media_folder_h folder, void *user_data) if(media_folder_foreach_media_from_db(folder_id, g_filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE) { SAFE_FREE(folder_id); - SAFE_FREE(folder_path); - SAFE_FREE(folder_name); media_content_error("[ERROR] media_folder_foreach_media_from_db is failed"); return false; } SAFE_FREE(folder_id); - SAFE_FREE(folder_path); - SAFE_FREE(folder_name); - ret = true; } else @@ -653,6 +658,8 @@ bool test_album_from_db(int album_id) if(media_album_get_artist(album_h, &artist) != MEDIA_CONTENT_ERROR_NONE) { media_album_destroy(album_h); + /* fix prevent: Resource Leak */ + SAFE_FREE(album_name); return false; } @@ -897,7 +904,7 @@ int test_filter_create(void) int ret = MEDIA_CONTENT_ERROR_NONE; /* Filter for media */ - char *condition = "MEDIA_TYPE=1"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ + char *condition = "MEDIA_TYPE=3"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ //char *condition = "MEDIA_TYPE IS NOT 0 AND MEDIA_DESCRIPTION IS NOT NULL"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ ret = media_filter_create(&g_filter); @@ -919,7 +926,11 @@ int test_filter_create(void) * Or, * call media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT); */ - ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT); + /* Able to set multi column to set order */ + //ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, "MEDIA_MODIFIED_TIME, MEDIA_DISPLAY_NAME", MEDIA_CONTENT_COLLATE_DEFAULT); + //ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT); + //ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TRACK_NUM_INT, MEDIA_CONTENT_COLLATE_DEFAULT); + //ret = media_filter_set_storage(g_filter, "cfbf3d2c-71c5-4611-bccc-7cbac890146e"); /* Filter for group */ //char *g_condition = "TAG_NAME like \"\%my\%\""; @@ -928,7 +939,7 @@ int test_filter_create(void) ret = media_filter_create(&g_filter_g); //ret = media_filter_set_condition(g_filter_g, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT); - //ret = media_filter_set_order(g_filter_g, MEDIA_CONTENT_ORDER_DESC, TAG_NAME, MEDIA_CONTENT_COLLATE_DEFAULT); + ret = media_filter_set_order(g_filter_g, MEDIA_CONTENT_ORDER_DESC, TAG_NAME, MEDIA_CONTENT_COLLATE_DEFAULT); return ret; } @@ -1000,7 +1011,6 @@ int test_gallery_scenario(void) media_content_debug("folder_name [%d] : %s", i, folder_name); media_content_debug("folder_path [%d] : %s", i, folder_path); - ret = media_folder_get_media_count_from_db(folder_id, filter, &count); /* User should free these string */ SAFE_FREE(folder_id); @@ -1163,7 +1173,7 @@ int test_gallery_scenario(void) /* To check performance */ gettimeofday(&end, NULL); long time = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec); - printf("Time : %ld\n", time); + media_content_debug("Time : %ld\n", time); /* Third, Get item list of a folder */ GList *item_list = NULL; @@ -1354,7 +1364,7 @@ int test_gallery_scenario(void) media_tag_get_tag_id(tag_handle, &tag_id); media_tag_get_name(tag_handle, &tag_name); - printf("[%d] %s", tag_id, tag_name); + media_content_debug("[%d] %s", tag_id, tag_name); ret = media_tag_foreach_media_from_db(tag_id, filter, gallery_media_item_cb, &media_list_in_tag); if(ret != MEDIA_CONTENT_ERROR_NONE) { @@ -1473,13 +1483,13 @@ int test_get_all_music_files(void) media_content_error("Fail to create filter"); return ret; } - ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT); + ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_LOCALIZED); if(ret != MEDIA_CONTENT_ERROR_NONE) { media_filter_destroy(filter); media_content_error("Fail to set condition"); return ret; } - ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_NOCASE); + ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_LOCALIZED); if(ret != MEDIA_CONTENT_ERROR_NONE) { media_filter_destroy(filter); media_content_error("Fail to set order"); @@ -1575,10 +1585,10 @@ int test_media_info_operation_2(void) int test_folder_operation(void) { int ret = MEDIA_CONTENT_ERROR_NONE; - filter_h filter; + filter_h filter = NULL; media_folder_h folder = NULL; char *folder_id = NULL; - int folder_count = 0; + int count = 0; media_content_debug("\n============Folder Test============\n\n"); @@ -1594,14 +1604,16 @@ int test_folder_operation(void) media_filter_set_condition(filter, "(MEDIA_TYPE = 0 or MEDIA_TYPE = 1) and MEDIA_STORAGE_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ media_filter_set_offset(filter, 0,5); media_filter_set_order(filter,MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE); + media_filter_set_storage(filter, "cfbf3d2c-71c5-4611-bccc-7cbac890146e"); - ret = media_folder_get_folder_count_from_db(filter, &folder_count); - media_content_debug("Folder count : %d", folder_count); + ret = media_folder_get_folder_count_from_db(filter, &count); + media_content_debug("Folder count : [%d]", count); ret = media_folder_foreach_folder_from_db(filter, folder_list_cb, &folder); //test.3 get the media list in first folder filter_h m_filter = NULL; + ret = media_filter_create(&m_filter); if(ret != MEDIA_CONTENT_ERROR_NONE) { @@ -1615,15 +1627,9 @@ int test_folder_operation(void) media_filter_set_offset(m_filter, 0,5); media_filter_set_order(m_filter,MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE); - media_folder_get_folder_id(folder, &folder_id); - media_content_debug("folder_id : %s", folder_id); - ret = media_folder_foreach_media_from_db(folder_id, m_filter, media_item_cb, NULL); - if(ret != MEDIA_CONTENT_ERROR_NONE) - { media_content_error("[ERROR] media_folder_foreach_media_from_db is failed, error code : %d", ret); - } media_filter_destroy(filter); media_filter_destroy(m_filter); @@ -1641,6 +1647,7 @@ bool folder_update_cb(media_folder_h folder, void *user_data) char *folder_id = NULL; char *folder_path = NULL; char *folder_name = NULL; + int folder_order = -1; bool ret = true; if(folder != NULL) @@ -1660,6 +1667,10 @@ bool folder_update_cb(media_folder_h folder, void *user_data) media_content_debug("folder_name = [%s]", folder_name); SAFE_FREE(folder_name); + ret = media_folder_get_order(folder, &folder_order); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + media_content_debug("folder_order = [%d]", folder_order); + ret = media_folder_clone(&g_folder, folder); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -1685,7 +1696,8 @@ int test_folder_update(void) ret = media_filter_create(&filter); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - media_filter_set_condition(filter, "MEDIA_TYPE=0 and MEDIA_STORAGE_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ + ret = media_filter_set_condition(filter, "MEDIA_TYPE=0 and MEDIA_STORAGE_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ + ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, FOLDER_ORDER, MEDIA_CONTENT_COLLATE_NOCASE); ret = media_folder_get_folder_count_from_db(filter, &folder_count); @@ -1697,6 +1709,8 @@ int test_folder_update(void) ret = media_folder_set_name(g_folder, "test_folder"); + ret = media_folder_set_order(g_folder, 200); + ret = media_folder_update_to_db(g_folder); ret = media_folder_destroy(g_folder); @@ -1710,6 +1724,7 @@ int test_playlist_operation(void) media_playlist_h playlist_1 = NULL; media_playlist_h playlist_2 = NULL; media_playlist_h playlist_3 = NULL; + media_playlist_h playlist_4 = NULL; int playlist_id_1 = 0; int playlist_id_2 = 0; int playlist_id_3 = 0; @@ -1780,6 +1795,10 @@ int test_playlist_operation(void) media_content_debug("playlist_id_2 [%d]", playlist_id_2); media_content_debug("playlist_id_3 [%d]", playlist_id_3); + /* Export and import playlist */ + media_playlist_export_to_file(playlist_3, "/opt/usr/media/Music/playlist.m3u"); + media_playlist_import_from_file( "/opt/usr/media/Music/playlist.m3u", "playlist_4", &playlist_4); + /* Filter for media*/ ret = media_filter_create(&m_filter); @@ -1849,6 +1868,8 @@ int test_playlist_operation(void) media_playlist_destroy(playlist_2); if(playlist_3 != NULL) media_playlist_destroy(playlist_3); + if(playlist_4 != NULL) + media_playlist_destroy(playlist_4); g_list_free(playlist_id_list); g_list_free(playlist_member_id_list); @@ -2033,7 +2054,6 @@ int test_bookmark_operation(void) //insert bookmark to video char *thumbnail_path1 = tzplatform_mkpath(TZ_USER_CONTENT, "Images and videos/My video clips/teat11.jpg"); - ret = media_bookmark_insert_to_db(test_video_id, 400, thumbnail_path1); if(ret != MEDIA_CONTENT_ERROR_NONE) media_content_error("error media_bookmark_insert_to_db : [%d]", ret); @@ -2113,11 +2133,11 @@ int test_group_operation(void) ret = test_filter_create(); if(ret != MEDIA_CONTENT_ERROR_NONE) { - media_content_error("[%d]error(0x%08x)", __LINE__, ret); + media_content_error("[error(0x%08x)", ret); return ret; } - for(idx = 0; idx <= MEDIA_CONTENT_GROUP_KEYWORD; idx++) + for(idx = 0; idx < MEDIA_CONTENT_GROUP_MAX; idx++) { ret = media_group_get_group_count_from_db(g_filter, idx, &group_count); if(ret != MEDIA_CONTENT_ERROR_NONE) { @@ -2510,18 +2530,22 @@ int test_request_update_db(void) { int ret = MEDIA_CONTENT_ERROR_NONE; media_info_h media = NULL; + char *content_name = NULL; + bool favorite = FALSE; //get the content of Over the horizon - ret = media_info_get_media_from_db("0f999626-6218-450c-a4ad-181a3bab6ebf", &media); + ret = media_info_get_media_from_db("71b19196-5b38-4ab1-ab34-bfe05c369614", &media); if(ret != MEDIA_CONTENT_ERROR_NONE) media_content_error("media_info_get_media_from_db failed: %d", ret); - test_disconnect_database(); - ret = media_info_set_content_name(media, "TEST_content_name"); if(ret != MEDIA_CONTENT_ERROR_NONE) media_content_error("media_info_set_content_name failed: %d", ret); + ret = media_info_set_favorite(media, TRUE); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_set_favorite failed: %d", ret); + ret = media_info_update_to_db(media); if(ret == MEDIA_CONTENT_ERROR_NONE) media_content_debug("media_info_update_to_db is success"); @@ -2531,6 +2555,27 @@ int test_request_update_db(void) if(media != NULL) media_info_destroy(media); + /*get the updated value*/ + ret = media_info_get_media_from_db("71b19196-5b38-4ab1-ab34-bfe05c369614", &media); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_from_db failed: %d", ret); + + ret = media_info_get_content_name(media, &content_name); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_content_name failed: %d", ret); + else + media_content_debug("content name [%s]", content_name); + + SAFE_FREE(content_name); + + ret = media_info_get_favorite(media, &favorite); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_favorite failed: %d", ret); + else + media_content_debug("favorite [%d]", favorite); + + ret = media_info_destroy(media); + return ret; } @@ -2586,7 +2631,7 @@ bool dft_cb(media_info_h media, void *user_data) } else { - printf("invalid media_type"); + media_content_debug("invalid media_type"); } if(mime_type != NULL) @@ -2599,7 +2644,7 @@ bool dft_cb(media_info_h media, void *user_data) int DFT_test(void) { int ret = MEDIA_CONTENT_ERROR_NONE; - printf("\n============DFT_test============\n\n"); + media_content_debug("\n============DFT_test============\n\n"); filter_h filter = NULL; int media_cnt = 0; @@ -2609,50 +2654,50 @@ int DFT_test(void) ret = media_filter_create(&filter); /*Internal Memory*/ - printf("[Internal Memory]\n"); + media_content_debug("[Internal Memory]\n"); /*1. Photo ============================================================*/ ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); /*Get Photo Count*/ ret = media_info_get_media_count_from_db(filter, &media_cnt); - printf("Photo count = [%d]\n", media_cnt); + media_content_debug("Photo count = [%d]\n", media_cnt); /*Get Photo Size*/ ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); - printf("Photo size = [%d]\n", g_total_photo_size); + media_content_debug("Photo size = [%d]\n", g_total_photo_size); /*2. Video ============================================================*/ ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT); /*Get Video Count*/ ret = media_info_get_media_count_from_db(filter, &media_cnt); - printf("Video count = [%d]\n", media_cnt); + media_content_debug("Video count = [%d]\n", media_cnt); /*Get Video Size*/ ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); - printf("Video size = [%d]\n", g_total_video_size); + media_content_debug("Video size = [%d]\n", g_total_video_size); /*3. MP3 ============================================================*/ ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT); /*Get MP3 Count*/ ret = media_info_get_media_count_from_db(filter, &media_cnt); - printf("MP3 count = [%d]\n", media_cnt); + media_content_debug("MP3 count = [%d]\n", media_cnt); /*Get MP3 Size*/ ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); - printf("MP3 size = [%d]\n", g_total_mp3_size); + media_content_debug("MP3 size = [%d]\n", g_total_mp3_size); /*4. Voice Memo ============================================================*/ ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND (MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT); /*Get Voice Memo Count*/ ret = media_info_get_media_count_from_db(filter, &media_cnt); - printf("Voice Memo count = [%d]\n", media_cnt); + media_content_debug("Voice Memo count = [%d]\n", media_cnt); /*Get Voice Memo Size*/ ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); - printf("Voice Memo size = [%d]\n", g_total_voice_memo_size); + media_content_debug("Voice Memo size = [%d]\n", g_total_voice_memo_size); g_total_photo_size = 0; g_total_video_size = 0; @@ -2660,50 +2705,50 @@ int DFT_test(void) g_total_voice_memo_size = 0; /*External Memory*/ - printf("\n[External Memory]\n"); + media_content_debug("\n[External Memory]\n"); /*1. Photo ============================================================*/ ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); /*Get Photo Count*/ ret = media_info_get_media_count_from_db(filter, &media_cnt); - printf("Photo count = [%d]\n", media_cnt); + media_content_debug("Photo count = [%d]\n", media_cnt); /*Get Photo Size*/ ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); - printf("Photo size = [%d]\n", g_total_photo_size); + media_content_debug("Photo size = [%d]\n", g_total_photo_size); /*2. Video ============================================================*/ ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT); /*Get Video Count*/ ret = media_info_get_media_count_from_db(filter, &media_cnt); - printf("Video count = [%d]\n", media_cnt); + media_content_debug("Video count = [%d]\n", media_cnt); /*Get Video Size*/ ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); - printf("Video size = [%d]\n", g_total_video_size); + media_content_debug("Video size = [%d]\n", g_total_video_size); /*3. MP3 ============================================================*/ ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT); /*Get MP3 Count*/ ret = media_info_get_media_count_from_db(filter, &media_cnt); - printf("MP3 count = [%d]\n", media_cnt); + media_content_debug("MP3 count = [%d]\n", media_cnt); /*Get MP3 Size*/ ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); - printf("MP3 size = [%d]\n", g_total_mp3_size); + media_content_debug("MP3 size = [%d]\n", g_total_mp3_size); /*4. Voice Memo ============================================================*/ ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND (MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT); /*Get Voice Memo Count*/ ret = media_info_get_media_count_from_db(filter, &media_cnt); - printf("Voice Memo count = [%d]\n", media_cnt); + media_content_debug("Voice Memo count = [%d]\n", media_cnt); /*Get Voice Memo Size*/ ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); - printf("Voice Memo size = [%d]\n", g_total_voice_memo_size); + media_content_debug("Voice Memo size = [%d]\n", g_total_voice_memo_size); ret = media_filter_destroy(filter); return ret; @@ -2711,7 +2756,7 @@ int DFT_test(void) void insert_batch_cb(media_content_error_e error, void * user_data) { - printf("media_info_insert_batch_to_db completed!\n"); + media_content_debug("media_info_insert_batch_to_db completed!\n"); } int test_batch_operations() @@ -2762,7 +2807,7 @@ int test_batch_operations() void insert_burst_shot_cb(media_content_error_e error, void * user_data) { - printf("media_info_insert_burst_shot_to_db completed![%d]\n", error); + media_content_debug("media_info_insert_burst_shot_to_db completed![%d]\n", error); g_main_loop_quit(g_loop); } @@ -2806,7 +2851,7 @@ int test_insert_burst_shot_to_db(void) void _scan_cb(media_content_error_e err, void *user_data) { - printf("scan callback is called : %d\n", err); + media_content_debug("scan callback is called : %d\n", err); g_main_loop_quit(g_loop); return; @@ -2835,14 +2880,30 @@ gboolean test_scan_dir_start(gpointer data) ret = media_content_scan_folder(dir_path, TRUE, _scan_cb, NULL); if(ret != MEDIA_CONTENT_ERROR_NONE) { - media_content_error("Fail to media_content_scan_file : %d", ret); + media_content_error("Fail to test_scan_dir_start : %d", ret); return ret; } return 0; } -int test_scan_dir() +gboolean cancel_scan_dir_start(gpointer data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + const char *dir_path = "/opt/usr/media/Images"; + + ret = media_content_cancel_scan_folder(dir_path); + + if(ret == MEDIA_CONTENT_ERROR_NONE) + media_content_debug("media_content_cancel_scan_folder is success"); + else + media_content_error("media_content_cancel_scan_folder is failed"); + + return false; +} + +int test_scan_dir(int cancel) { GSource *source = NULL; GMainContext *context = NULL; @@ -2853,6 +2914,13 @@ int test_scan_dir() g_source_set_callback (source, test_scan_dir_start, NULL, NULL); g_source_attach (source, context); + if (cancel) { + GSource *cancel_src = NULL; + cancel_src = g_idle_source_new(); + g_source_set_callback (cancel_src, cancel_scan_dir_start, NULL, NULL); + g_source_attach (cancel_src, context); + } + g_main_loop_run(g_loop); g_main_loop_unref(g_loop); @@ -2870,45 +2938,45 @@ void _noti_cb(media_content_error_e error, void *user_data) { if (error == 0) { - printf("noti success! : %d\n", error); + media_content_debug("noti success! : %d\n", error); } else { - printf("error occured! : %d\n", error); + media_content_debug("error occured! : %d\n", error); } - printf("Noti from PID(%d)\n", pid); + media_content_debug("Noti from PID(%d)\n", pid); if (update_item == MEDIA_ITEM_FILE) { - printf("Noti item : MEDIA_ITEM_FILE\n"); + media_content_debug("Noti item : MEDIA_ITEM_FILE\n"); } else if (update_item == MEDIA_ITEM_DIRECTORY) { - printf("Noti item : MEDIA_ITEM_DIRECTORY\n"); + media_content_debug("Noti item : MEDIA_ITEM_DIRECTORY\n"); } if (update_type == MEDIA_CONTENT_INSERT) { - printf("Noti type : MEDIA_CONTENT_INSERT\n"); + media_content_debug("Noti type : MEDIA_CONTENT_INSERT\n"); } else if (update_type == MEDIA_CONTENT_DELETE) { - printf("Noti type : MEDIA_CONTENT_DELETE\n"); + media_content_debug("Noti type : MEDIA_CONTENT_DELETE\n"); } else if (update_type == MEDIA_CONTENT_UPDATE) { - printf("Noti type : MEDIA_CONTENT_UPDATE\n"); + media_content_debug("Noti type : MEDIA_CONTENT_UPDATE\n"); } - printf("content type : %d\n", media_type); + media_content_debug("content type : %d\n", media_type); if (path) - printf("path : %s\n", path); + media_content_debug("path : %s\n", path); else - printf("path not\n"); + media_content_debug("path not\n"); if (uuid) - printf("uuid : %s\n", uuid); + media_content_debug("uuid : %s\n", uuid); else - printf("uuid not\n"); + media_content_debug("uuid not\n"); if (mime_type) - printf("mime_type : %s\n", mime_type); + media_content_debug("mime_type : %s\n", mime_type); else - printf("mime not\n"); + media_content_debug("mime not\n"); - if (user_data) printf("String : %s\n", (char *)user_data); + if (user_data) media_content_debug("String : %s\n", (char *)user_data); //g_main_loop_quit(g_loop); return; @@ -2927,7 +2995,7 @@ gboolean _send_noti_operations(gpointer data) char *path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg"); ret = media_info_insert_to_db(path, &media_item); - if (ret < MEDIA_CONTENT_ERROR_NONE) { + if (ret != MEDIA_CONTENT_ERROR_NONE) { media_content_error("media_info_insert_to_db failed : %d", ret); media_info_destroy(media_item); return FALSE; @@ -2998,6 +3066,197 @@ int test_noti() return ret; } +int test_create_handle() +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_h media = NULL; + media_info_h info = NULL; + char *path = "/opt/usr/media/test_storage_path/cloud_other.txt"; + char *str_value = NULL; + int int_value = -1; + + ret = media_info_create_handle(&media); + + ret = media_info_set_path(media, path); + ret = media_info_set_mime_type(media, "test_mime_type"); + ret = media_info_set_title(media, "test_title"); + ret = media_info_set_album(media, "test_album"); + ret = media_info_set_artist(media, "test_artist"); + ret = media_info_set_genre(media, "test_genre"); + ret = media_info_set_width(media, 1920); + ret = media_info_set_height(media, 1080); + ret = media_info_set_recorded_date(media, "test_recorded_date"); + ret = media_info_set_thumbnail_path(media, "/opt/usr/media/test_thumbnail_path"); + ret = media_info_set_size(media, 5555); + ret = media_info_set_modified_time(media, 4444); + ret = media_info_set_media_type(media, MEDIA_CONTENT_TYPE_VIDEO); + ret = media_info_set_duration(media, 3333); + ret = media_info_set_width(media, 1111); + ret = media_info_set_height(media, 2222); + ret = media_info_set_storage_type(media, MEDIA_CONTENT_STORAGE_CLOUD); + ret = media_info_set_storage_id(media, "5e0ad455-9b84-4489-ad51-4dd93b795413"); + + ret = media_info_insert_to_db_with_data(media, &info); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("media_info_insert_to_db_with_data failed : %d\n", ret); + return ret; + } + + ret = media_info_get_file_path(info, &str_value); + media_content_debug("file_path = [%s]", str_value); + SAFE_FREE(str_value); + + ret = media_info_get_mime_type(info, &str_value); + media_content_debug("mime_type = [%s]", str_value); + SAFE_FREE(str_value); + + ret = media_info_get_title(info, &str_value); + media_content_debug("title = [%s]", str_value); + SAFE_FREE(str_value); + + ret = media_info_get_size(info,(unsigned long long*) &int_value); + media_content_debug("size = [%d]", int_value); + + ret = media_info_get_modified_time(info, (time_t*)&int_value); + media_content_debug("time = [%d]", int_value); + + ret = media_info_get_media_type(info, (media_content_type_e *)&int_value); + media_content_debug("media_type = [%d]", int_value); + + ret = media_info_get_storage_type(info, (media_content_storage_e *)&int_value); + media_content_debug("storage_type = [%d]", int_value); + + media_info_destroy(media); + media_info_destroy(info); + + return ret; + +} + +int test_storage_item_insert() +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_info_h media = NULL; + + ret = media_info_create_handle(&media); + ret = media_info_set_path(media, "/opt/storage/cloud/c_storage/test_file.png"); + ret = media_info_set_mime_type(media, "test_mime_type"); + ret = media_info_set_title(media, "test_title"); + ret = media_info_set_storage_type(media, MEDIA_CONTENT_STORAGE_CLOUD); + ret = media_info_set_storage_id(media, "2a4e8103-33e3-4846-afe9-5be4681b0dba"); + ret = media_info_set_modified_time(media, 100); + ret = media_info_set_media_type(media, MEDIA_CONTENT_TYPE_IMAGE); + ret = media_info_insert_to_db_with_data(media, NULL); + + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_insert_to_db_with_data failed : %d\n", ret); + + return ret; +} + +int test_storage() +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_storage_h storage = NULL; +#if 1 + char *storage_name = "test_storage_name"; + char *storage_path = "/opt/storage/cloud/c_storage/test_storage_path"; + char *storage_account = "test_storage_account"; +#endif + char *storage_id = NULL; + char *st_val = NULL; + media_content_storage_e storage_type_out = -1; + int storage_cnt = -1; + +#if 1 + ret = media_storage_insert_to_db(storage_name, storage_path, storage_account, MEDIA_CONTENT_STORAGE_CLOUD, &storage); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("media_storage_insert_to_db failed : %d\n", ret); + goto ERROR; + } + ret = media_storage_get_id(storage, &storage_id); + + ret = media_storage_destroy(storage); + storage = NULL; +#endif + ret = media_storage_get_storage_count_from_db(NULL, &storage_cnt); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("media_storage_get_storage_count_from_db failed : %d\n", ret); + goto ERROR; + } + media_content_debug("storage_cnt = [%d]", storage_cnt); + + //media_storage_foreach_storage_from_db(filter_h filter, media_storage_cb callback, void *user_data); + + ret = media_storage_get_storage_info_from_db(storage_id, &storage); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("media_storage_get_storage_info_from_db failed : %d\n", ret); + goto ERROR; + } + + ret = media_storage_get_id(storage, &st_val); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("media_storage_get_id failed : %d\n", ret); + goto ERROR; + } + media_content_debug("storage_id = [%s]", st_val); + SAFE_FREE(st_val); + + ret = media_storage_get_name(storage, &st_val); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("media_storage_get_name failed : %d\n", ret); + goto ERROR; + } + media_content_debug("storage_name = [%s]", st_val); + SAFE_FREE(st_val); + + ret = media_storage_get_path(storage, &st_val); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("media_storage_get_path failed : %d\n", ret); + goto ERROR; + } + media_content_debug("storage_path = [%s]", st_val); + SAFE_FREE(st_val); + + ret = media_storage_get_storage_account(storage, &st_val); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("media_storage_get_path failed : %d\n", ret); + goto ERROR; + } + media_content_debug("storage_ccount = [%s]", st_val); + SAFE_FREE(st_val); + + ret = media_storage_get_type(storage, &storage_type_out); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("media_storage_get_type failed : %d\n", ret); + goto ERROR; + } + media_content_debug("storage_type = [%d]", storage_type_out); + + //ret = media_storage_clone(media_storage_h *dst, media_storage_h src); + + //ret = media_storage_delete_from_db(storage_id); + +ERROR: + SAFE_FREE(storage_id); + SAFE_FREE(st_val); + + ret = media_storage_destroy(storage); + + return ret; +} + int main(int argc, char *argv[]) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -3008,10 +3267,6 @@ int main(int argc, char *argv[]) if(ret != MEDIA_CONTENT_ERROR_NONE) return MEDIA_CONTENT_ERROR_NONE; - ret = test_media_info_operation(); - if(ret != MEDIA_CONTENT_ERROR_NONE) - return ret; - #if 0 ret = test_move(); if(ret != MEDIA_CONTENT_ERROR_NONE) @@ -3093,13 +3348,25 @@ int main(int argc, char *argv[]) if(ret != MEDIA_CONTENT_ERROR_NONE) return MEDIA_CONTENT_ERROR_NONE; - ret = test_scan_dir(); + ret = test_scan_dir(true); if(ret != MEDIA_CONTENT_ERROR_NONE) return MEDIA_CONTENT_ERROR_NONE; ret = test_noti(); if(ret != MEDIA_CONTENT_ERROR_NONE) return MEDIA_CONTENT_ERROR_NONE; + + ret = test_storage(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; + + ret = test_storage_item_insert(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; + + ret = test_create_handle(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; #endif ret = test_disconnect_database();