SET(MEDIACONTENT-PLUGIN-LIB "media-content-plugin")
SET(MEDIAEBOOK-PLUGIN-LIB "media-ebook-plugin")
SET(SRCS
- src/common/media-svc.c
- src/common/media-svc-media.c
- src/common/media-svc-album.c
- src/common/media-svc-media-folder.c
- src/common/media-svc-db-utils.c
- src/common/media-svc-util.c
- src/common/media-svc-noti.c
- src/common/media-svc-storage.c
+ src/media-svc.c
+ src/media-svc-media.c
+ src/media-svc-album.c
+ src/media-svc-media-folder.c
+ src/media-svc-db-utils.c
+ src/media-svc-util.c
+ src/media-svc-noti.c
+ src/media-svc-storage.c
)
SET(EBOOKPLUGIN_SRCS
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src/include/common ${CMAKE_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR})
FIND_PROGRAM(UNAME NAMES uname)
EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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.
+ *
+ */
+
+#ifndef _MEDIA_SVC_ALBUM_H_
+#define _MEDIA_SVC_ALBUM_H_
+
+#include <sqlite3.h>
+#include <sys/types.h>
+#include <stdbool.h>
+
+int _media_svc_get_album_id(sqlite3 *handle, const char *album, const char *artist, int *album_id);
+int _media_svc_append_album(sqlite3 *handle, bool is_direct, const char *album, const char *artist, const char *album_art, int *album_id, uid_t uid);
+
+#endif /*_MEDIA_SVC_ALBUM_H_*/
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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.
+ *
+ */
+
+
+#ifndef _MEDIA_SVC_DB_UTILS_H_
+#define _MEDIA_SVC_DB_UTILS_H_
+
+#include <stdbool.h>
+#include <sqlite3.h>
+#include <glib.h>
+#include "media-svc-env.h"
+
+#define SQLITE3_FINALIZE(x) if (x != NULL) sqlite3_finalize(x);
+#define SQLITE3_SAFE_FREE(x) {if (x != NULL) {sqlite3_free(x); x = NULL; } }
+
+int _media_svc_make_table_query(const char *table_name, media_svc_table_slist_e list, uid_t uid);
+int _media_svc_init_table_query(void);
+void _media_svc_destroy_table_query(void);
+int _media_svc_sql_query(const char *sql_str, uid_t uid);
+int _media_svc_sql_query_direct(const char *sql_str, uid_t uid);
+int _media_svc_check_table_exist(sqlite3 *db_handle, bool *exist);
+int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt);
+int _media_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt);
+int _media_svc_sql_query_list(GList **query_list, uid_t uid);
+int _media_svc_sql_query_list_direct(GList **query_list, uid_t uid);
+void _media_svc_sql_query_add(GList **query_list, char **query);
+void _media_svc_sql_query_release(GList **query_list);
+
+#endif /*_MEDIA_SVC_DB_UTILS_H_*/
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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.
+ *
+ */
+
+
+
+#ifndef _MEDIA_SVC_DEBUG_H_
+#define _MEDIA_SVC_DEBUG_H_
+
+#include <dlog.h>
+#include <errno.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "MEDIA_SERVICE"
+
+#define FONT_COLOR_RESET "\033[0m"
+#define FONT_COLOR_RED "\033[31m"
+#define FONT_COLOR_GREEN "\033[32m"
+#define FONT_COLOR_YELLOW "\033[33m"
+#define FONT_COLOR_BLUE "\033[34m"
+#define FONT_COLOR_PURPLE "\033[35m"
+#define FONT_COLOR_CYAN "\033[36m"
+#define FONT_COLOR_GRAY "\033[37m"
+
+#define media_svc_debug(fmt, arg...) do { \
+ LOGD(FONT_COLOR_RESET"" fmt "", ##arg); \
+ } while (0)
+
+#define media_svc_error(fmt, arg...) do { \
+ LOGE(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET, ##arg); \
+ } while (0)
+
+#define media_svc_debug_fenter() do { \
+ LOGD(FONT_COLOR_YELLOW"<ENTER>" FONT_COLOR_RESET); \
+ } while (0)
+
+#define media_svc_debug_fleave() do { \
+ LOGD(FONT_COLOR_YELLOW"<LEAVE>" FONT_COLOR_RESET); \
+ } while (0)
+
+#define media_svc_retm_if(expr, fmt, arg...) do { \
+ if (expr) { \
+ LOGE(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET, ##arg); \
+ return; \
+ } \
+ } while (0)
+#define media_svc_retv_if(expr, val) do { \
+ if (expr) { \
+ LOGE(FONT_COLOR_RED"" FONT_COLOR_RESET); \
+ return (val); \
+ } \
+ } while (0)
+#define media_svc_retvm_if(expr, val, fmt, arg...) do { \
+ if (expr) { \
+ LOGE(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET, ##arg); \
+ return (val); \
+ } \
+ } while (0)
+
+#define media_svc_retv_del_if(expr, val, p_str) do { \
+ if (expr) { \
+ LOGE(FONT_COLOR_RED"" FONT_COLOR_RESET); \
+ _media_svc_destroy_content_info(p_str); \
+ return (val); \
+ } \
+ } while (0)
+
+#define media_svc_sec_debug(fmt, arg...) do { \
+ SECURE_LOGI(FONT_COLOR_GREEN"" fmt "" FONT_COLOR_RESET, ##arg); \
+ } while (0)
+
+#define media_svc_sec_warn(fmt, arg...) do { \
+ SECURE_LOGW(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET, ##arg); \
+ } while (0)
+
+#define media_svc_sec_error(fmt, arg...) do { \
+ SECURE_LOGE(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET, ##arg); \
+ } while (0)
+
+#define ERR_BUF_LENGHT 256
+#define media_svc_stderror(fmt) do { \
+ char media_svc_stderror_buf[ERR_BUF_LENGHT] = {0,}; \
+ strerror_r(errno, media_svc_stderror_buf, ERR_BUF_LENGHT); \
+ LOGE(FONT_COLOR_RED""fmt" : standard error= [%s]", media_svc_stderror_buf); \
+ } while (0)
+
+#endif /*_MEDIA_SVC_DEBUG_H_*/
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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.
+ *
+ */
+
+
+
+#ifndef _MEDIA_SVC_ENV_H_
+#define _MEDIA_SVC_ENV_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * DB table information
+ */
+
+/**
+ * Table Name
+ */
+#define DB_TABLE_MEDIA "media" /**< media table*/
+#define DB_TABLE_FOLDER "folder" /**< media_folder table*/
+#define DB_TABLE_PLAYLIST "playlist" /**< playlist table*/
+#define DB_TABLE_PLAYLIST_MAP "playlist_map" /**< playlist_map table*/
+#define DB_TABLE_ALBUM "album" /**< album table*/
+#define DB_TABLE_TAG "tag" /**< tag table*/
+#define DB_TABLE_TAG_MAP "tag_map" /**< tag_map table*/
+#define DB_TABLE_BOOKMARK "bookmark" /**< bookmark table*/
+#define DB_TABLE_STORAGE "storage" /**< storage table*/
+#define DB_TABLE_FACE "face" /**< face table*/
+#define DB_TABLE_FACE_SCAN_LIST "face_scan_list" /**< face_scan_list table*/
+
+/**
+ * View Name
+ */
+#define DB_VIEW_PLAYLIST "playlist_view" /**< playlist_view*/
+#define DB_VIEW_TAG "tag_view" /**< tag_view*/
+
+/**
+ * Trigger Name
+ */
+#define DB_TRIGGER_PLAYLIST_MAP "playlist_map_cleanup" /**< media to map*/
+#define DB_TRIGGER_PLAYLIST_MAP1 "playlist_map_cleanup_1" /**< playlist to map*/
+#define DB_TRIGGER_ALBUM "album_cleanup"
+#define DB_TRIGGER_TAG_MAP "tag_map_cleanup" /**< media to map*/
+#define DB_TRIGGER_TAG_MAP1 "tag_map_cleanup_1" /**< tag to map*/
+#define DB_TRIGGER_BOOKMARK "bookmark_cleanup"
+#define DB_TRIGGER_FACE_SCAN_LIST "face_scan_list_cleanup"
+#define DB_TRIGGER_FACE "face_cleanup"
+
+/**
+ * Column Name for view
+ */
+#define DB_COLUMN_THUMBNAIL "thumbnail_path"
+#define DB_COLUMN_MAP_ID "_id"
+
+
+/**
+ * option
+ */
+#define DB_TYPE_TEXT "TEXT"
+#define DB_TYPE_INT "INTEGER"
+#define DB_TYPE_DOUBLE "DOUBLE"
+
+/**
+ * Query form
+ */
+#define DB_QUERY_TABLE_WITH_UNIQUE "CREATE TABLE IF NOT EXISTS '%s' (%s, unique(%s));"
+#define DB_QUERY_TABLE "CREATE TABLE IF NOT EXISTS '%s' (%s);"
+#define DB_QUERY_TRIGGER "CREATE TRIGGER IF NOT EXISTS '%s' DELETE ON '%s' BEGIN DELETE FROM %s WHERE %s=old.%s;END;"
+#define DB_QUERY_TRIGGER_WITH_COUNT "CREATE TRIGGER IF NOT EXISTS '%s' DELETE ON '%s' BEGIN DELETE FROM %s WHERE (SELECT count(*) FROM '%s' WHERE %s=old.%s)=1 AND %s=old.%s;END;"
+#define DB_QUERY_VIEW_PLAYLIST "CREATE VIEW IF NOT EXISTS %s AS SELECT %s FROM playlist \
+ LEFT OUTER JOIN playlist_map ON playlist.playlist_id = playlist_map.playlist_id \
+ LEFT OUTER JOIN media ON (playlist_map.media_id = media.media_id AND media.validity=1) \
+ LEFT OUTER JOIN (SELECT count(playlist_id) as playlist_media_count, playlist_id FROM playlist_map group by playlist_id) as cnt_tbl ON (cnt_tbl.playlist_id=playlist_map.playlist_id AND media.validity=1);"
+#define DB_QUERY_VIEW_TAG "CREATE VIEW IF NOT EXISTS %s AS SELECT %s FROM tag \
+ LEFT OUTER JOIN tag_map ON tag.tag_id=tag_map.tag_id \
+ LEFT OUTER JOIN media ON (tag_map.media_id = media.media_id AND media.validity=1) \
+ LEFT OUTER JOIN (SELECT count(tag_id) as tag_media_count, tag_id FROM tag_map group by tag_id) as cnt_tbl ON (cnt_tbl.tag_id=tag_map.tag_id AND media.validity=1);"
+
+
+#define MEDIA_SVC_METADATA_LEN_MAX 512 /**< Length of metadata*/
+#define MEDIA_SVC_PATHNAME_SIZE 4096 /**< Length of Path name. */
+#define MEDIA_SVC_UUID_SIZE 36 /**< Length of UUID*/
+
+#define MEDIA_SVC_TAG_UNKNOWN ""
+
+typedef enum {
+ MEDIA_SVC_QUERY_SCANNER,
+ MEDIA_SVC_QUERY_UPDATE_COMMON,
+} media_svc_query_type_e;
+
+typedef enum {
+ DB_LIST_MEDIA = 0,
+ DB_LIST_FOLDER,
+ DB_LIST_PLAYLIST_MAP,
+ DB_LIST_PLAYLIST,
+ DB_LIST_ALBUM,
+ DB_LIST_TAG_MAP,
+ DB_LIST_TAG,
+ DB_LIST_BOOKMARK,
+ DB_LIST_STORAGE,
+ DB_LIST_FACE_SCAN_LIST,
+ DB_LIST_FACE,
+ DB_LIST_MAX,
+} media_svc_table_slist_e;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_MEDIA_SVC_ENV_H_*/
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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.
+ *
+ */
+
+#ifndef _MEDIA_SVC_MEDIA_FOLDER_H_
+#define _MEDIA_SVC_MEDIA_FOLDER_H_
+
+#include <sqlite3.h>
+#include <stdbool.h>
+
+int _media_svc_update_folder_modified_time(const char *folder_path, uid_t uid);
+int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, long long int *folder_id, uid_t uid);
+int _media_svc_append_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid);
+int _media_svc_set_folder_validity(bool is_direct, const char *start_path, int validity, bool is_recursive, uid_t uid);
+int _media_svc_check_folder_by_path(sqlite3 *handle, const char *path);
+
+#endif /*_MEDIA_SVC_MEDIA_FOLDER_H_*/
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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.
+ *
+ */
+
+#ifndef _MEDIA_SVC_MEDIA_H_
+#define _MEDIA_SVC_MEDIA_H_
+
+#include <sqlite3.h>
+#include <stdbool.h>
+#include "media-svc-noti.h"
+#include "media-svc-env.h"
+
+int _media_svc_check_data_by_path(sqlite3 *handle, const char *path);
+int _media_svc_get_modified_time(sqlite3 *handle, const char *path, int *modified_time);
+int _media_svc_insert_item_stack(media_svc_content_info_s *content_info);
+int _media_svc_insert_item(media_svc_content_info_s *content_info, uid_t uid);
+int _media_svc_update_item_with_data(bool is_direct, media_svc_content_info_s *content_info, uid_t uid);
+int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path);
+int _media_svc_delete_item_by_path(const char *path, uid_t uid);
+int _media_svc_update_item_validity(const char *path, int validity, bool stack_query, uid_t uid);
+int _media_svc_update_item_by_path(const char *src_path, const char *dst_storage_id, const char *dest_path, const char *file_name, int modified_time, long long int folder_id, uid_t uid);
+int _media_svc_list_query_do(media_svc_query_type_e query_type, uid_t uid);
+int _media_svc_update_thumbnail_path(const char *path, const char *thumb_path, uid_t uid);
+int _media_svc_get_noti_info(sqlite3 *handle, const char *path, media_svc_noti_item **item);
+
+int _media_svc_append_query_list(const char *query, uid_t uid);
+int _media_svc_get_media(sqlite3 *handle, const char *sql, GList **path_list);
+
+#endif /*_MEDIA_SVC_MEDIA_H_*/
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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.
+ *
+ */
+
+#ifndef _MEDIA_SVC_NOTI_H_
+#define _MEDIA_SVC_NOTI_H_
+
+#include <media-util-noti.h>
+#include "media-svc-util.h"
+
+typedef struct _media_svc_noti_item media_svc_noti_item;
+
+struct _media_svc_noti_item {
+ int pid;
+ media_item_type_e update_item;
+ media_item_update_type_e update_type;
+ int media_type;
+ char *media_uuid;
+ char *path;
+ char *mime_type;
+};
+
+void _media_svc_set_noti_from_pid(int pid);
+void _media_svc_initialize_noti_list(void);
+void _media_svc_insert_item_to_noti_list(media_svc_content_info_s *content_info);
+void _media_svc_publish_noti_list(void);
+void _media_svc_destroy_noti_item(media_svc_noti_item *item);
+int _media_svc_publish_noti(media_item_update_type_e update_type, const char *path, int media_type, const char *uuid, const char *mime_type);
+int _media_svc_publish_dir_noti(media_item_update_type_e update_type, const char *path, const char *uuid, int pid);
+
+#endif /*_MEDIA_SVC_NOTI_H_*/
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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.
+ *
+ */
+
+#ifndef _MEDIA_SVC_STORAGE_H_
+#define _MEDIA_SVC_STORAGE_H_
+
+#include <sqlite3.h>
+
+int _media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity);
+int _media_svc_append_storage(const char *storage_id, const char *storage_path, uid_t uid);
+int _media_svc_update_storage_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid);
+int _media_svc_delete_invalid_storage(sqlite3 *handle, uid_t uid);
+int _media_svc_update_storage_validity(const char *storage_id, int validity, uid_t uid);
+int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage_id, uid_t uid);
+
+#endif /*_MEDIA_SVC_STORAGE_H_*/
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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.
+ *
+ */
+
+
+
+#ifndef _MEDIA_SVC_UTIL_H_
+#define _MEDIA_SVC_UTIL_H_
+
+#include <string.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <sqlite3.h>
+#include <time.h>
+#include <glib.h>
+#include <media-util-err.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define STRING_VALID(str) (str && strlen(str) > 0)
+
+/**
+ * Media meta data information
+ */
+typedef struct {
+ char *title; /**< track title*/
+ char *album; /**< album name*/
+ char *artist; /**< artist name*/
+ char *album_artist; /**< artist name*/
+ char *genre; /**< genre of track*/
+ char *year; /**< year*/
+ char *track_num; /**< track number*/
+ unsigned int width; /**< width*/
+ unsigned int height; /**< height*/
+ char *datetaken; /**< datetaken*/
+ unsigned short orientation; /**< orientation*/
+} media_svc_content_meta_s;
+
+/**
+ * Media data information
+ */
+typedef struct {
+ char *media_uuid; /**< Unique ID of item */
+ char *path; /**< Full path of media file */
+ char *file_name; /**< File name of media file. Display name */
+ int media_type; /**< Type of media file : internal/external */
+ char *mime_type; /**< Full path and file name of media file */
+ unsigned long long size; /**< size */
+ time_t modified_time; /**< modified time, time_t */
+ long long int folder_id; /**< Unique ID of folder */
+ int album_id; /**< Unique ID of album */
+ char *thumbnail_path; /**< Thumbnail image file path */
+ char *storage_uuid; /**< Unique ID of storage */
+ media_svc_content_meta_s media_meta; /**< meta data structure */
+} media_svc_content_info_s;
+
+/**
+ * Type definition for content type
+ */
+typedef enum {
+ MEDIA_SVC_MEDIA_TYPE_IMAGE = 0, /**< Image Content*/
+ MEDIA_SVC_MEDIA_TYPE_VIDEO = 1, /**< Video Content*/
+ MEDIA_SVC_MEDIA_TYPE_SOUND = 2, /**< Sound Content like Ringtone*/
+ MEDIA_SVC_MEDIA_TYPE_MUSIC = 3, /**< Music Content like mp3*/
+ MEDIA_SVC_MEDIA_TYPE_OTHER = 4, /**< Not media Content*/
+ MEDIA_SVC_MEDIA_TYPE_BOOK = 5, /**< Book Content like epub*/
+} media_svc_media_type_e;
+
+typedef enum {
+ MEDIA_SVC_SEARCH_TYPE_DIRECT = 0,
+ MEDIA_SVC_SEARCH_TYPE_DB,
+} media_svc_search_type_e;
+
+void _media_svc_remove_file(const char *path);
+int _media_svc_get_file_time(const char *full_path);
+char * _media_svc_get_title_from_filename(const char *filename);
+int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, const char *path, bool refresh);
+int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info);
+void _media_svc_extract_audio_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid);
+void _media_svc_extract_video_metadata(media_svc_content_info_s *content_info);
+int _media_svc_extract_book_metadata(media_svc_content_info_s *content_info);
+void _media_svc_destroy_content_info(media_svc_content_info_s *content_info);
+int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid);
+int _media_svc_get_media_type(const char *path, int *mediatype);
+bool _media_svc_is_keyword_included(const char *path, const char *keyword);
+void _media_svc_update_wordbook(const char *path, uid_t uid);
+void _media_svc_clean_wordbook(uid_t uid);
+bool _media_svc_get_matched_list(const char *keyword, uid_t uid, GList **list);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_MEDIA_SVC_UTIL_H_*/
Name: libmedia-service
Summary: Media information service library for multimedia applications
-Version: 0.5.4
+Version: 0.6.0
Release: 0
Group: Multimedia/Libraries
License: Apache-2.0
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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 "media-svc-album.h"
-#include "media-svc-debug.h"
-#include "media-svc-env.h"
-#include "media-svc-util.h"
-#include "media-svc-db-utils.h"
-
-int _media_svc_get_album_id(sqlite3 *handle, const char *album, const char *artist, int *album_id)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
-
- media_svc_retvm_if(!album, MS_MEDIA_ERR_INVALID_PARAMETER, "album is NULL");
- media_svc_retvm_if(!artist, MS_MEDIA_ERR_INVALID_PARAMETER, "artist is NULL");
-
- sql = sqlite3_mprintf("SELECT album_id FROM %s WHERE name=%Q AND artist=%Q", DB_TABLE_ALBUM, album, artist);
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- if (ret != MS_MEDIA_ERR_NONE) {
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- media_svc_debug("there is no album.");
- else
- media_svc_error("failed to get album id[%d]", ret);
-
- return ret;
- }
-
- *album_id = sqlite3_column_int(sql_stmt, 0);
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return ret;
-}
-
-int _media_svc_append_album(sqlite3 *handle, bool is_direct, const char *album, const char *artist, const char *album_art, int *album_id, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- char *sql = sqlite3_mprintf("INSERT INTO %s(name, artist, album_art) VALUES (%Q, %Q, %Q);", DB_TABLE_ALBUM, album, artist, album_art);
- if (is_direct)
- ret = _media_svc_sql_query_direct(sql, uid);
- else
- ret = _media_svc_sql_query(sql, uid);
-
- SQLITE3_SAFE_FREE(sql);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- int inserted_album_id = 0;
- ret = _media_svc_get_album_id(handle, album, artist, &inserted_album_id);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- *album_id = inserted_album_id;
-
- return MS_MEDIA_ERR_NONE;
-}
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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 <unistd.h>
-#include <media-util-db.h>
-#include <errno.h>
-
-#include "media-svc-env.h"
-#include "media-svc-debug.h"
-#include "media-svc-util.h"
-#include "media-svc-db-utils.h"
-#include "media-svc-media.h"
-
-static GHashTable *table;
-static GSList *column_list[DB_LIST_MAX];
-
-typedef struct {
- char *trigger_name;
- char *view_name;
- char *event_table;
- char *action_table;
-} table_info_s;
-
-typedef struct {
- char *name;
- char *type;
- char *option;
- bool is_unique;
- bool is_trigger;
- bool is_view;
-} column_info_s;
-
-static void __add_table_info(const char *name,
- const char *trigger_name,
- const char *event_table,
- const char *action_table,
- const char *view_name)
-{
- table_info_s *tbl = NULL;
-
- if (!name)
- return;
-
- if (trigger_name) {
- if(!event_table || !action_table)
- return;
- }
-
- tbl = g_new0(table_info_s, 1);
-
- if (trigger_name) {
- tbl->trigger_name = g_strdup(trigger_name);
- tbl->event_table = g_strdup(event_table);
- tbl->action_table = g_strdup(action_table);
- }
-
- if (view_name)
- tbl->view_name = g_strdup(view_name);
-
- g_hash_table_insert(table, (gpointer)name, (gpointer)tbl);
-}
-
-static void __add_column_info(GSList **slist,
- const char *name,
- const char *type,
- const char *option,
- bool is_unique,
- bool is_trigger,
- bool is_view)
-{
- column_info_s *col = g_new0(column_info_s, 1);
-
- col->name = g_strdup(name);
- col->type = g_strdup(type);
- col->option = g_strdup(option);
-
- col->is_unique = is_unique;
- col->is_trigger = is_trigger;
- col->is_view = is_view;
-
- *slist = g_slist_append(*slist, col);
-}
-
-static int __create_playlist_view(uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- GSList *iter = NULL;
- column_info_s *col_ptr = NULL;
- char *sql = NULL;
- GString *table_query = g_string_new(NULL);
- media_svc_retvm_if(!table_query, MS_MEDIA_ERR_INTERNAL, "g_string_new failed");
-
- for (iter = column_list[DB_LIST_PLAYLIST]; iter; iter = g_slist_next(iter)) {
- col_ptr = iter->data;
-
- if (!col_ptr)
- continue;
-
- if (col_ptr->is_view) {
- if (table_query->len != 0) {
- if (strncmp(col_ptr->name, DB_COLUMN_THUMBNAIL, strlen(DB_COLUMN_THUMBNAIL)) == 0)
- g_string_append_printf(table_query, ", playlist.%s AS p_thumbnail_path", col_ptr->name);
- else
- g_string_append_printf(table_query, ", playlist.%s", col_ptr->name);
- } else {
- g_string_append_printf(table_query, "playlist.%s", col_ptr->name);
- }
- }
- }
-
- for (iter = column_list[DB_LIST_PLAYLIST_MAP]; iter; iter = g_slist_next(iter)) {
- col_ptr = iter->data;
-
- if (!col_ptr)
- continue;
-
- if (col_ptr->is_view) {
- if (strncmp(col_ptr->name, DB_COLUMN_MAP_ID, strlen(DB_COLUMN_MAP_ID)) == 0)
- g_string_append_printf(table_query, ", playlist_media_count IS NOT NULL AS playlist_media_count, playlist_map.%s AS pm_id", col_ptr->name);
- else
- g_string_append_printf(table_query, ", playlist_map.%s", col_ptr->name);
- }
- }
-
- for (iter = column_list[DB_LIST_MEDIA]; iter; iter = g_slist_next(iter)) {
- col_ptr = iter->data;
-
- if (!col_ptr)
- continue;
-
- if (col_ptr->is_view)
- g_string_append_printf(table_query, ", media.%s", col_ptr->name);
- }
-
- sql = sqlite3_mprintf(DB_QUERY_VIEW_PLAYLIST, DB_VIEW_PLAYLIST, table_query->str);
- g_string_free(table_query, TRUE);
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
-
- return ret;
-}
-
-static int __create_tag_view(uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- GSList *iter = NULL;
- column_info_s *col_ptr = NULL;
- char *sql = NULL;
- GString *table_query = g_string_new(NULL);
- media_svc_retvm_if(!table_query, MS_MEDIA_ERR_INTERNAL, "g_string_new failed");
-
- for (iter = column_list[DB_LIST_TAG]; iter; iter = g_slist_next(iter)) {
- col_ptr = iter->data;
-
- if (!col_ptr)
- continue;
-
- if (col_ptr->is_view) {
- if (table_query->len != 0)
- g_string_append_printf(table_query, ", tag.%s", col_ptr->name);
- else
- g_string_append_printf(table_query, "tag.%s", col_ptr->name);
- }
- }
-
- for (iter = column_list[DB_LIST_TAG_MAP]; iter; iter = g_slist_next(iter)) {
- col_ptr = iter->data;
-
- if (!col_ptr)
- continue;
-
- if (col_ptr->is_view) {
- if (strncmp(col_ptr->name, DB_COLUMN_MAP_ID, strlen(DB_COLUMN_MAP_ID)) == 0)
- g_string_append_printf(table_query, ", tag_media_count IS NOT NULL AS tag_media_count, tag_map.%s AS tm_id", col_ptr->name);
- else
- g_string_append_printf(table_query, ", tag_map.%s", col_ptr->name);
- }
- }
-
- for (iter = column_list[DB_LIST_MEDIA]; iter; iter = g_slist_next(iter)) {
- col_ptr = iter->data;
-
- if (!col_ptr)
- continue;
-
- if (col_ptr->is_view)
- g_string_append_printf(table_query, ", media.%s", col_ptr->name);
- }
-
- sql = sqlite3_mprintf(DB_QUERY_VIEW_TAG, DB_VIEW_TAG, table_query->str);
- g_string_free(table_query, TRUE);
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
-
- return ret;
-}
-
-int _media_svc_make_table_query(const char *table_name, media_svc_table_slist_e list, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- GSList *iter = NULL;
- table_info_s *tb = NULL;
- column_info_s *col_ptr = NULL;
- char *sql = NULL;
- GString *table_query = g_string_new(NULL);
- GString *trigger_query = g_string_new(NULL);
- GString *unique_query = g_string_new(NULL);
-
- if (!table_query || !trigger_query || !unique_query) {
- media_svc_error("g_string_new failed");
- ret = MS_MEDIA_ERR_INTERNAL;
- goto ERROR;
- }
-
- tb = g_hash_table_lookup(table, table_name);
- if (tb == NULL) {
- media_svc_debug("lookup fail.. table name [%s] ", table_name);
- ret = MS_MEDIA_ERR_INTERNAL;
- goto ERROR;
- }
-
- for (iter = column_list[list]; iter; iter = g_slist_next(iter)) {
- col_ptr = iter->data;
- if (!col_ptr)
- continue;
-
- /*create table */
- if (col_ptr->option) {
- if (table_query->len != 0)
- g_string_append_printf(table_query, ", %s %s %s", col_ptr->name, col_ptr->type, col_ptr->option);
- else
- g_string_append_printf(table_query, "%s %s %s", col_ptr->name, col_ptr->type, col_ptr->option);
- } else {
- if (table_query->len != 0)
- g_string_append_printf(table_query, ", %s %s", col_ptr->name, col_ptr->type);
- else
- g_string_append_printf(table_query, "%s %s", col_ptr->name, col_ptr->type);
- }
-
- /*unique */
- if (col_ptr->is_unique) {
- if (unique_query->len != 0)
- g_string_append_printf(unique_query, ", %s", col_ptr->name);
- else
- g_string_append_printf(unique_query, "%s", col_ptr->name);
- }
-
- /*create trigger */
- if (col_ptr->is_trigger) {
- if (tb->trigger_name) {
- if (strncmp(table_name, DB_TABLE_ALBUM, strlen(DB_TABLE_ALBUM)) == 0) {
- g_string_append_printf(trigger_query, DB_QUERY_TRIGGER_WITH_COUNT,
- tb->trigger_name, tb->event_table, tb->action_table, tb->event_table,
- col_ptr->name, col_ptr->name, col_ptr->name, col_ptr->name);
- } else {
- g_string_append_printf(trigger_query, DB_QUERY_TRIGGER,
- tb->trigger_name, tb->event_table, tb->action_table,
- col_ptr->name, col_ptr->name);
- }
- } else {
- media_svc_error("invalid trigger name");
- }
- }
- }
-
- /*send queries */
- if (unique_query->len > 0)
- sql = sqlite3_mprintf(DB_QUERY_TABLE_WITH_UNIQUE, table_name, table_query->str, unique_query->str);
- else
- sql = sqlite3_mprintf(DB_QUERY_TABLE, table_name, table_query->str);
-
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- if (ret != MS_MEDIA_ERR_NONE)
- goto ERROR;
-
- if (trigger_query->len > 0) {
- ret = _media_svc_sql_query(trigger_query->str, uid);
- if (ret != MS_MEDIA_ERR_NONE)
- goto ERROR;
- }
-
- /*create view */
- if (strncmp(table_name, DB_TABLE_PLAYLIST, strlen(DB_TABLE_PLAYLIST)) == 0)
- ret = __create_playlist_view(uid);
- else if (strncmp(table_name, DB_TABLE_TAG, strlen(DB_TABLE_TAG)) == 0)
- ret = __create_tag_view(uid);
-
-ERROR:
- if (trigger_query)
- g_string_free(trigger_query, TRUE);
- if (unique_query)
- g_string_free(unique_query, TRUE);
- if (table_query)
- g_string_free(table_query, TRUE);
-
- return ret;
-}
-
-static void __media_svc_table_free(gpointer data)
-{
- table_info_s *tb = (table_info_s *) data;
-
- g_free(tb->trigger_name);
- g_free(tb->view_name);
- g_free(tb->event_table);
- g_free(tb->action_table);
- g_free(tb);
-}
-
-static void __media_svc_column_free(gpointer data)
-{
- column_info_s *col = (column_info_s *) data;
-
- g_free(col->name);
- g_free(col->type);
- g_free(col->option);
- g_free(col);
-}
-
-int _media_svc_init_table_query(void)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- /*variable initialize.. */
- table = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, __media_svc_table_free);
-
- /*table specification.. (table_name, trigger name, event table, action table, view name) */
- __add_table_info(DB_TABLE_MEDIA, NULL, NULL, NULL, NULL);
- __add_table_info(DB_TABLE_FOLDER, NULL, NULL, NULL, NULL);
- __add_table_info(DB_TABLE_PLAYLIST_MAP, DB_TRIGGER_PLAYLIST_MAP, DB_TABLE_MEDIA, DB_TABLE_PLAYLIST_MAP, NULL);
- __add_table_info(DB_TABLE_PLAYLIST, DB_TRIGGER_PLAYLIST_MAP1, DB_TABLE_PLAYLIST, DB_TABLE_PLAYLIST_MAP, DB_VIEW_PLAYLIST);
- __add_table_info(DB_TABLE_ALBUM, DB_TRIGGER_ALBUM, DB_TABLE_MEDIA, DB_TABLE_ALBUM, NULL);
- __add_table_info(DB_TABLE_TAG_MAP, DB_TRIGGER_TAG_MAP, DB_TABLE_MEDIA, DB_TABLE_TAG_MAP, NULL);
- __add_table_info(DB_TABLE_TAG, DB_TRIGGER_TAG_MAP1, DB_TABLE_TAG, DB_TABLE_TAG_MAP, DB_VIEW_TAG);
- __add_table_info(DB_TABLE_BOOKMARK, DB_TRIGGER_BOOKMARK, DB_TABLE_MEDIA, DB_TABLE_BOOKMARK, NULL);
- __add_table_info(DB_TABLE_STORAGE, NULL, NULL, NULL, NULL);
- __add_table_info(DB_TABLE_FACE_SCAN_LIST, DB_TRIGGER_FACE_SCAN_LIST, DB_TABLE_MEDIA, DB_TABLE_FACE_SCAN_LIST, NULL);
- __add_table_info(DB_TABLE_FACE, DB_TRIGGER_FACE, DB_TABLE_FACE_SCAN_LIST, DB_TABLE_FACE, NULL);
-
- /*insert column info.. */
- /*media*/
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_id", DB_TYPE_TEXT, "PRIMARY KEY", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_path", DB_TYPE_TEXT, "NOT NULL UNIQUE", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_display_name", DB_TYPE_TEXT, "NOT NULL", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_type", DB_TYPE_INT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_mime_type", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_size", DB_TYPE_INT, "DEFAULT 0", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_added_time", DB_TYPE_INT, "DEFAULT (unixepoch())", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_modified_time", DB_TYPE_INT, "DEFAULT 0", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "folder_id", DB_TYPE_INT, "DEFAULT 0", false, false, false);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_thumbnail_path", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_title", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "album_id", DB_TYPE_INT, "DEFAULT 0", false, false, false);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_album", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_artist", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_album_artist", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_genre", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_composer", DB_TYPE_TEXT, "DEFAULT ''", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_year", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_recorded_date", DB_TYPE_TEXT, "DEFAULT ''", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_copyright", DB_TYPE_TEXT, "DEFAULT ''", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_track_num", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_description", DB_TYPE_TEXT, "DEFAULT ''", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_bitrate", DB_TYPE_INT, "DEFAULT -1", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_bitpersample", DB_TYPE_INT, "DEFAULT 0", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_samplerate", DB_TYPE_INT, "DEFAULT -1", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_channel", DB_TYPE_INT, "DEFAULT -1", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_duration", DB_TYPE_INT, "DEFAULT -1", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_longitude", DB_TYPE_DOUBLE, "DEFAULT -200", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_latitude", DB_TYPE_DOUBLE, "DEFAULT -200", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_altitude", DB_TYPE_DOUBLE, "DEFAULT 0", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "exposure_time", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "fnumber", DB_TYPE_DOUBLE, "DEFAULT 0", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "iso", DB_TYPE_INT, "DEFAULT -1", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "model", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_width", DB_TYPE_INT, "DEFAULT -1", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_height", DB_TYPE_INT, "DEFAULT -1", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_datetaken", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "orientation", DB_TYPE_INT, "DEFAULT -1", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_rating", DB_TYPE_INT, "DEFAULT 0", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_favourite", DB_TYPE_INT, "DEFAULT 0", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_is_drm", DB_TYPE_INT, "DEFAULT 0", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_timeline", DB_TYPE_INT, "DEFAULT 0", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "storage_uuid", DB_TYPE_TEXT, NULL, false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "validity", DB_TYPE_INT, "DEFAULT 1", false, false, false);
- __add_column_info(&column_list[DB_LIST_MEDIA], "media_360", DB_TYPE_INT, "DEFAULT 0", false, false, true);
-
- /*folder*/
- __add_column_info(&column_list[DB_LIST_FOLDER], "folder_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, false, false);
- __add_column_info(&column_list[DB_LIST_FOLDER], "folder_path", DB_TYPE_TEXT, "NOT NULL", true, false, false);
- __add_column_info(&column_list[DB_LIST_FOLDER], "folder_name", DB_TYPE_TEXT, "NOT NULL", false, false, false);
- __add_column_info(&column_list[DB_LIST_FOLDER], "folder_modified_time", DB_TYPE_INT, "DEFAULT 0", false, false, false);
- __add_column_info(&column_list[DB_LIST_FOLDER], "storage_uuid", DB_TYPE_TEXT, NULL, true, false, false);
- __add_column_info(&column_list[DB_LIST_FOLDER], "validity", DB_TYPE_INT, "DEFAULT 1", false, false, false);
-
- /*playlist_map*/
- __add_column_info(&column_list[DB_LIST_PLAYLIST_MAP], "_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, false, true);
- __add_column_info(&column_list[DB_LIST_PLAYLIST_MAP], "playlist_id", DB_TYPE_INT, "NOT NULL", false, false, false);
- __add_column_info(&column_list[DB_LIST_PLAYLIST_MAP], "media_id", DB_TYPE_TEXT, "NOT NULL", false, true, false);
- __add_column_info(&column_list[DB_LIST_PLAYLIST_MAP], "playlist_member_order", DB_TYPE_INT, "NOT NULL", false, false, true);
-
- /*playlist*/
- __add_column_info(&column_list[DB_LIST_PLAYLIST], "playlist_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, true, true);
- __add_column_info(&column_list[DB_LIST_PLAYLIST], "playlist_name", DB_TYPE_TEXT, "NOT NULL UNIQUE", false, false, true);
- __add_column_info(&column_list[DB_LIST_PLAYLIST], "thumbnail_path", DB_TYPE_TEXT, NULL, false, false, true);
-
- /*album*/
- __add_column_info(&column_list[DB_LIST_ALBUM], "album_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, true, false);
- __add_column_info(&column_list[DB_LIST_ALBUM], "name", DB_TYPE_TEXT, "NOT NULL", false, false, false);
- __add_column_info(&column_list[DB_LIST_ALBUM], "artist", DB_TYPE_TEXT, NULL, false, false, false);
- __add_column_info(&column_list[DB_LIST_ALBUM], "album_art", DB_TYPE_TEXT, NULL, false, false, false);
-
- /*tag_map*/
- __add_column_info(&column_list[DB_LIST_TAG_MAP], "_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, false, true);
- __add_column_info(&column_list[DB_LIST_TAG_MAP], "tag_id", DB_TYPE_INT, "NOT NULL", true, false, false);
- __add_column_info(&column_list[DB_LIST_TAG_MAP], "media_id", DB_TYPE_TEXT, "NOT NULL", true, true, false);
-
- /*tag*/
- __add_column_info(&column_list[DB_LIST_TAG], "tag_id ", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, true, true);
- __add_column_info(&column_list[DB_LIST_TAG], "tag_name", DB_TYPE_TEXT, "NOT NULL UNIQUE", false, false, true);
-
- /*bookmark*/
- __add_column_info(&column_list[DB_LIST_BOOKMARK], "bookmark_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, false, false);
- __add_column_info(&column_list[DB_LIST_BOOKMARK], "media_id", DB_TYPE_TEXT, "NOT NULL", true, true, false);
- __add_column_info(&column_list[DB_LIST_BOOKMARK], "bookmark_marked_time", DB_TYPE_INT, "DEFAULT 0", true, false, false);
- __add_column_info(&column_list[DB_LIST_BOOKMARK], "bookmark_thumbnail_path", DB_TYPE_TEXT, NULL, false, false, false);
- __add_column_info(&column_list[DB_LIST_BOOKMARK], "bookmark_name", DB_TYPE_TEXT, NULL, false, false, false);
-
- /*storage*/
- __add_column_info(&column_list[DB_LIST_STORAGE], "storage_id", DB_TYPE_TEXT, "PRIMARY KEY", false, false, false);
- __add_column_info(&column_list[DB_LIST_STORAGE], "storage_path", DB_TYPE_TEXT, "NOT NULL", false, false, false);
- __add_column_info(&column_list[DB_LIST_STORAGE], "validity", DB_TYPE_INT, "DEFAULT 1", false, false, false);
-
- /*face scan list*/
- __add_column_info(&column_list[DB_LIST_FACE_SCAN_LIST], "media_id", DB_TYPE_TEXT, "NOT NULL UNIQUE", false, true, false);
- __add_column_info(&column_list[DB_LIST_FACE_SCAN_LIST], "modified_time", DB_TYPE_INT, "DEFAULT 0", false, false, false);
-
- /*face*/
- __add_column_info(&column_list[DB_LIST_FACE], "media_face_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, false, false);
- __add_column_info(&column_list[DB_LIST_FACE], "media_id", DB_TYPE_TEXT, "NOT NULL", true, true, false);
- __add_column_info(&column_list[DB_LIST_FACE], "face_rect_x", DB_TYPE_INT, "DEFAULT 0", true, false, false);
- __add_column_info(&column_list[DB_LIST_FACE], "face_rect_y", DB_TYPE_INT, "DEFAULT 0", true, false, false);
- __add_column_info(&column_list[DB_LIST_FACE], "face_rect_w", DB_TYPE_INT, "DEFAULT 0", true, false, false);
- __add_column_info(&column_list[DB_LIST_FACE], "face_rect_h", DB_TYPE_INT, "DEFAULT 0", true, false, false);
- __add_column_info(&column_list[DB_LIST_FACE], "face_orientation", DB_TYPE_INT, "DEFAULT 0", false, false, false);
- __add_column_info(&column_list[DB_LIST_FACE], "media_face_tag", DB_TYPE_TEXT, NULL, false, false, false);
-
- return ret;
-}
-
-void _media_svc_destroy_table_query(void)
-{
- int i = 0;
-
- /* Table Free */
- g_hash_table_destroy(table);
- table = NULL;
-
- /* Column Free */
- for (i = 0; i < DB_LIST_MAX; i++) {
- g_slist_free_full(column_list[i], __media_svc_column_free);
- column_list[i] = NULL;
- }
-}
-
-int _media_svc_sql_query(const char *sql_str, uid_t uid)
-{
- return media_db_request_update_db(sql_str, uid);
-}
-
-#define MAX_RETRY 9
-#define SLEEP_TIME 1000 * 1000
-static int __media_svc_query_direct(sqlite3 *handle, const char *query, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *zErrMsg = NULL;
- int retry_count = 0;
-
-EXEC_RETRY:
- ret = sqlite3_exec(handle, query, NULL, NULL, &zErrMsg);
- if (SQLITE_OK != ret) {
- media_svc_sec_error("Error[%s],Query[%s]", zErrMsg, query);
- SQLITE3_SAFE_FREE(zErrMsg);
- if (ret == SQLITE_BUSY) {
- ret = MS_MEDIA_ERR_DB_BUSY_FAIL;
- } else if (ret == SQLITE_CONSTRAINT) {
- ret = MS_MEDIA_ERR_DB_CONSTRAINT_FAIL;
- } else if (ret == SQLITE_FULL) {
- ret = MS_MEDIA_ERR_DB_FULL_FAIL;
- } else if (ret == SQLITE_LOCKED) {
- if (retry_count < MAX_RETRY) {
- media_svc_error("Locked retry[%d]", retry_count);
- retry_count++;
- usleep(SLEEP_TIME);
- goto EXEC_RETRY;
- }
- ret = MS_MEDIA_ERR_DB_INTERNAL;
- } else {
- ret = MS_MEDIA_ERR_DB_INTERNAL;
- }
- }
-
- return ret;
-}
-
-int _media_svc_sql_query_direct(const char *sql_str, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3 *handle = NULL;
-
- ret = media_db_connect(&handle, uid, true);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "DB connection failed");
- ret = __media_svc_query_direct(handle, sql_str, uid);
- media_db_disconnect(handle);
-
- return ret;
-}
-
-int _media_svc_check_table_exist(sqlite3 *db_handle, bool *exist)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT name FROM sqlite_master WHERE type='table' AND name=%Q;", DB_TABLE_MEDIA);
-
- ret = _media_svc_sql_prepare_to_step_simple(db_handle, sql, &sql_stmt);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step_simple failed");
-
- if (sqlite3_step(sql_stmt) != SQLITE_ROW) {
- media_svc_debug("Need to create table");
- *exist = false;
- } else {
- media_svc_debug("Already exists");
- *exist = true;
- }
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt)
-{
- int err = -1;
-
- media_svc_retvm_if(sql_str == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "invalid query");
-
- if (handle == NULL) {
- media_svc_error("handle is NULL");
- sqlite3_free((char *)sql_str);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- media_svc_sec_debug("Query[%s]", sql_str);
-
- err = sqlite3_prepare_v2(handle, sql_str, -1, stmt, NULL);
- sqlite3_free((char *)sql_str);
-
- if (err != SQLITE_OK) {
- media_svc_error("prepare error %d[%s]", err, sqlite3_errmsg(handle));
- if (err == SQLITE_CORRUPT)
- return MS_MEDIA_ERR_DB_CORRUPT;
-
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
-
- err = sqlite3_step(*stmt);
- if (err != SQLITE_ROW) {
- media_svc_debug("No record");
- SQLITE3_FINALIZE(*stmt);
- return MS_MEDIA_ERR_DB_NO_RECORD;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt)
-{
- int err = -1;
-
- media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "handle is NULL");
-
- media_svc_sec_debug("Query[%s]", sql_str);
-
- if (!STRING_VALID(sql_str)) {
- media_svc_error("invalid query");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- err = sqlite3_prepare_v2(handle, sql_str, -1, stmt, NULL);
- sqlite3_free((char *)sql_str);
-
- if (err != SQLITE_OK) {
- media_svc_error("prepare error %d[%s]", err, sqlite3_errmsg(handle));
- if (err == SQLITE_CORRUPT)
- return MS_MEDIA_ERR_DB_CORRUPT;
-
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_sql_query_list(GList **query_list, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- int idx = 0;
- int length = g_list_length(*query_list);
- char *sql = NULL;
-
- media_svc_debug("query list length : [%d]", length);
-
- for (idx = 0; idx < length; idx++) {
- sql = (char *)g_list_nth_data(*query_list, idx);
- if (STRING_VALID(sql)) {
- ret = media_db_request_update_db(sql, uid);
- if (ret != MS_MEDIA_ERR_NONE)
- media_svc_error("media_db_request_update_db failed : %d", ret);
- }
-
- SQLITE3_SAFE_FREE(sql);
- }
-
- _media_svc_sql_query_release(query_list);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_sql_query_list_direct(GList **query_list, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- int idx = 0;
- int length = g_list_length(*query_list);
- char *sql = NULL;
- char *zErrMsg = NULL;
- sqlite3 *handle = NULL;
- bool with_transaction = true;
-
- media_svc_debug("query list length[%d]", length);
- if (length == 0)
- goto ZERO_LEN;
-
- ret = media_db_connect(&handle, uid, true);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "DB connection failed");
-
- ret = sqlite3_exec(handle, "BEGIN;", NULL, NULL, &zErrMsg);
- if (SQLITE_OK != ret) {
- media_svc_sec_error("Transaction failed[%s]. Try an individual insert.", zErrMsg);
- SQLITE3_SAFE_FREE(zErrMsg);
- with_transaction = false;
- }
-
- for (idx = 0; idx < length; idx++) {
- sql = (char *)g_list_nth_data(*query_list, idx);
- if (STRING_VALID(sql)) {
- ret = __media_svc_query_direct(handle, sql, uid);
- if (ret != MS_MEDIA_ERR_NONE)
- media_svc_debug("_media_svc_query_direct failed[%s]", sql);
-
- SQLITE3_SAFE_FREE(sql);
- }
- }
-
- if (with_transaction) {
- ret = sqlite3_exec(handle, "COMMIT;", NULL, NULL, &zErrMsg);
- if (SQLITE_OK != ret) {
- media_svc_sec_error("Commit failed[%s]", zErrMsg);
- SQLITE3_SAFE_FREE(zErrMsg);
- media_db_disconnect(handle);
- _media_svc_sql_query_release(query_list);
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
- }
-
- media_db_disconnect(handle);
-
-ZERO_LEN:
- _media_svc_sql_query_release(query_list);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-void _media_svc_sql_query_add(GList **query_list, char **query)
-{
- *query_list = g_list_append(*query_list, *query);
-}
-
-void _media_svc_sql_query_release(GList **query_list)
-{
- if (*query_list) {
- g_list_free(*query_list);
- *query_list = NULL;
- }
-}
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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 <glib/gstdio.h>
-#include <media-util-user.h>
-
-#include "media-svc-media-folder.h"
-#include "media-svc-debug.h"
-#include "media-svc-env.h"
-#include "media-svc-util.h"
-#include "media-svc-db-utils.h"
-
-static int __media_svc_get_folder_id(sqlite3 *handle, const char *path, long long int *folder_id)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
-
- sql = sqlite3_mprintf("SELECT folder_id FROM %q WHERE folder_path=%Q", DB_TABLE_FOLDER, path);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step failed [%d]", ret);
-
- *folder_id = sqlite3_column_int64(sql_stmt, 0);
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return ret;
-}
-
-static int __media_svc_append_folder(bool is_direct, const char *storage_id, const char *folder_path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *folder_name = NULL;
- int folder_modified_date = 0;
-
- folder_name = g_path_get_basename(folder_path);
- folder_modified_date = _media_svc_get_file_time(folder_path);
-
- /* Sometime SQLITE3 returns NO_RECORD, so need to consider conflict case.. */
- char *sql = sqlite3_mprintf("INSERT OR IGNORE INTO %q(folder_path, folder_name, storage_uuid, folder_modified_time) VALUES (%Q, %Q, %Q, %d);",
- DB_TABLE_FOLDER, folder_path, folder_name, storage_id, folder_modified_date);
-
- if (is_direct)
- ret = _media_svc_sql_query_direct(sql, uid);
- else
- ret = _media_svc_sql_query(sql, uid);
-
- SQLITE3_SAFE_FREE(sql);
-
- g_free(folder_name);
-
- return ret;
-}
-
-int _media_svc_update_folder_modified_time(const char *folder_path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- int time = 0;
- char *query = NULL;
-
- time = _media_svc_get_file_time(folder_path);
- query = sqlite3_mprintf("UPDATE %q SET folder_modified_time=%d WHERE folder_path=%Q", DB_TABLE_FOLDER, time, folder_path);
-
- ret = _media_svc_sql_query(query, uid);
- SQLITE3_SAFE_FREE(query);
-
- return ret;
-}
-
-static int __media_svc_append_parent_folder(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- size_t next_pos = ms_user_get_root_length(path, uid);
- char *next = NULL;
- char *dir_path = NULL;
-
- do {
- next = strstr(path + next_pos, "/");
- if (next) {
- next_pos = (next - path);
- dir_path = g_strndup(path, next_pos);
- next_pos++;
- } else {
- dir_path = g_strdup(path);
- }
-
- ret = _media_svc_check_folder_by_path(handle, dir_path);
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
- ret = __media_svc_append_folder(is_direct, storage_id, dir_path, uid);
- if (ret != MS_MEDIA_ERR_NONE)
- media_svc_error("__media_svc_append_folder is failed");
- else
- media_svc_sec_debug("Append new folder path[%s]", dir_path);
- }
-
- g_free(dir_path);
- } while (next);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, long long int *folder_id, uid_t uid)
-{
- char *dir_path = NULL;
- int ret = MS_MEDIA_ERR_NONE;
-
- dir_path = g_path_get_dirname(path);
-
- ret = __media_svc_get_folder_id(handle, dir_path, folder_id);
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
- ret = __media_svc_append_parent_folder(handle, is_direct, storage_id, dir_path, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("__media_svc_append_parent_folder failed");
- goto FINALIZE;
- }
-
- ret = __media_svc_get_folder_id(handle, dir_path, folder_id);
- }
-FINALIZE:
- g_free(dir_path);
-
- return ret;
-}
-
-int _media_svc_append_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- ret = _media_svc_check_folder_by_path(handle, path);
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- ret = __media_svc_append_parent_folder(handle, true, storage_id, path, uid);
- else
- ret = _media_svc_set_folder_validity(true, path, 1, false, uid);
-
- return ret;
-}
-
-int _media_svc_set_folder_validity(bool is_direct, const char *start_path, int validity, bool is_recursive, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
-
- if (is_recursive) {
- sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE folder_path LIKE '%q/%%' OR folder_path=%Q",
- DB_TABLE_FOLDER, validity, start_path, start_path);
- } else {
- sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE folder_path=%Q", DB_TABLE_FOLDER, validity, start_path);
- }
-
- if (is_direct)
- ret = _media_svc_sql_query_direct(sql, uid);
- else
- ret = _media_svc_sql_query(sql, uid);
-
- SQLITE3_SAFE_FREE(sql);
-
- return ret;
-}
-
-int _media_svc_check_folder_by_path(sqlite3 *handle, const char *path)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
-
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- sql = sqlite3_mprintf("SELECT 1 FROM %q WHERE folder_path=%Q", DB_TABLE_FOLDER, path);
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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 <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include "media-svc-media.h"
-#include "media-svc-media-folder.h"
-#include "media-svc-debug.h"
-#include "media-svc-util.h"
-#include "media-svc-db-utils.h"
-#include "media-svc-noti.h"
-
-#define MEDIA_SVC_MAX_COMMIT_SIZE 200
-
-static __thread GList *g_media_svc_scanner_query_list = NULL;
-static __thread GList *g_media_svc_update_list = NULL;
-
-int _media_svc_check_data_by_path(sqlite3 *handle, const char *path)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
-
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
-
- sql = sqlite3_mprintf("SELECT 1 FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path);
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- SQLITE3_FINALIZE(sql_stmt);
-
- return ret;
-}
-
-int _media_svc_get_modified_time(sqlite3 *handle, const char *path, int *modified_time)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
-
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
-
- sql = sqlite3_mprintf("SELECT media_modified_time FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path);
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- *modified_time = sqlite3_column_int(sql_stmt, 0);
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static char *__media_svc_make_insert_query(media_svc_content_info_s *content_info)
-{
- return sqlite3_mprintf("INSERT INTO %q(media_id, media_path, media_display_name, media_type, media_mime_type, media_size, media_modified_time, folder_id, media_thumbnail_path, media_title, album_id, media_album, media_artist, media_album_artist, media_genre, media_year, media_track_num, media_width, media_height, media_datetaken, orientation, storage_uuid) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %lld, %Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %d, %d, %Q, %d, %Q);",
- DB_TABLE_MEDIA,
- content_info->media_uuid,
- content_info->path,
- content_info->file_name,
- content_info->media_type,
- content_info->mime_type,
- content_info->size,
- content_info->modified_time,
- content_info->folder_id,
- content_info->thumbnail_path,
- content_info->media_meta.title,
- content_info->album_id,
- content_info->media_meta.album,
- content_info->media_meta.artist,
- content_info->media_meta.album_artist,
- content_info->media_meta.genre,
- content_info->media_meta.year,
- content_info->media_meta.track_num,
- content_info->media_meta.width,
- content_info->media_meta.height,
- content_info->media_meta.datetaken,
- content_info->media_meta.orientation,
- content_info->storage_uuid);
-}
-
-int _media_svc_insert_item_stack(media_svc_content_info_s *content_info)
-{
- char *sql = __media_svc_make_insert_query(content_info);
- media_svc_retvm_if(!sql, MS_MEDIA_ERR_INVALID_PARAMETER, "make query failed");
-
- media_svc_sec_debug("Query[%s]", sql);
-
- _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_insert_item(media_svc_content_info_s *content_info, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = __media_svc_make_insert_query(content_info);
- media_svc_retvm_if(!sql, MS_MEDIA_ERR_INVALID_PARAMETER, "make query failed");
-
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "failed to insert item");
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_update_item_with_data(bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- char *sql = sqlite3_mprintf("UPDATE %q SET media_size=%lld, media_modified_time=%d, media_thumbnail_path=%Q, media_title=%Q, album_id=%d, media_album=%Q, media_artist=%Q, media_album_artist=%Q, media_genre=%Q, media_year=%Q, media_track_num=%Q, media_width=%d, media_height=%d, media_datetaken=%Q, orientation=%d, validity=1 WHERE media_path=%Q;",
- DB_TABLE_MEDIA,
- content_info->size,
- content_info->modified_time,
- content_info->thumbnail_path,
- content_info->media_meta.title,
- content_info->album_id,
- content_info->media_meta.album,
- content_info->media_meta.artist,
- content_info->media_meta.album_artist,
- content_info->media_meta.genre,
- content_info->media_meta.year,
- content_info->media_meta.track_num,
- content_info->media_meta.width,
- content_info->media_meta.height,
- content_info->media_meta.datetaken,
- content_info->media_meta.orientation,
- content_info->path
- );
-
- /* Scanner use only batch insert */
- if (is_direct) {
- media_svc_sec_debug("Query [%s]", sql);
- _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
- } else {
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- }
-
- return ret;
-}
-int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
-
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- sql = sqlite3_mprintf("SELECT media_thumbnail_path FROM %q WHERE media_path='%q'", DB_TABLE_MEDIA, path);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- if (ret != MS_MEDIA_ERR_NONE) {
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- media_svc_debug("there is no thumbnail.");
- else
- media_svc_error("error when _media_svc_get_thumbnail_path_by_path. err = [%d]", ret);
-
- return ret;
- }
-
- g_strlcpy(thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_PATHNAME_SIZE);
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_delete_item_by_path(const char *path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
-
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- sql = sqlite3_mprintf("DELETE FROM %q WHERE media_path=%Q;", DB_TABLE_MEDIA, path);
-
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "failed to delete item");
-
- return ret;
-}
-
-int _media_svc_update_item_validity(const char *path, int validity, bool stack_query, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
-
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- media_svc_debug("path=[%s], validity=[%d]", path, validity);
-
- sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE media_path='%q';", DB_TABLE_MEDIA, validity, path);
-
- if (!stack_query) {
- ret = _media_svc_sql_query_direct(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- } else {
- _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
- }
-
- return ret;
-}
-
-int _media_svc_update_thumbnail_path(const char *path, const char *thumb_path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- char *sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path=%Q WHERE media_path=%Q;", DB_TABLE_MEDIA, thumb_path, path);
-
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
-
- return ret;
-}
-
-int _media_svc_update_item_by_path(const char *src_path, const char *dst_storage_id, const char *dest_path, const char *file_name, int modified_time, long long int folder_id, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- char *query = sqlite3_mprintf("UPDATE %q SET media_path=%Q, media_display_name=%Q, media_modified_time=%d, folder_id=%lld, storage_uuid='%q' WHERE media_path=%Q;",
- DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_id, dst_storage_id, src_path);
-
- ret = _media_svc_sql_query(query, uid);
- SQLITE3_SAFE_FREE(query);
-
- return ret;
-}
-
-int _media_svc_list_query_do(media_svc_query_type_e query_type, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- /* For multiples of 200, empty requests are possible */
- switch (query_type) {
- case MEDIA_SVC_QUERY_SCANNER:
- ret = _media_svc_sql_query_list_direct(&g_media_svc_scanner_query_list, uid);
- break;
- case MEDIA_SVC_QUERY_UPDATE_COMMON:
- if (g_media_svc_update_list == NULL || g_list_length(g_media_svc_update_list) == 0)
- return MS_MEDIA_ERR_NONE;
-
- ret = _media_svc_sql_query_list(&g_media_svc_update_list, uid);
- break;
- default:
- media_svc_error("Wrong type[%d]", query_type);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Failed to request queries");
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_append_query_list(const char *query, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- media_svc_retvm_if(query == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "query is NULL");
-
- g_media_svc_update_list = g_list_append(g_media_svc_update_list, (gpointer)query);
-
- if (g_list_length(g_media_svc_update_list) >= MEDIA_SVC_MAX_COMMIT_SIZE)
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
-
- return ret;
-}
-
-int _media_svc_get_media(sqlite3 *handle, const char *sql, GList **path_list)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
-
- media_svc_retvm_if(!sql, MS_MEDIA_ERR_INVALID_PARAMETER, "query is NULL");
- media_svc_retvm_if(!path_list, MS_MEDIA_ERR_INVALID_PARAMETER, "array is NULL");
-
- ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step_simple() failed [%d]", ret);
-
- while (sqlite3_step(sql_stmt) == SQLITE_ROW)
- *path_list = g_list_append(*path_list, g_strdup((const char *)sqlite3_column_text(sql_stmt, 0)));
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return ret;
-}
-
-int _media_svc_get_noti_info(sqlite3 *handle, const char *path, media_svc_noti_item **item)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
-
- media_svc_retvm_if(item == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "item is NULL");
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- sql = sqlite3_mprintf("SELECT media_id, media_type, media_mime_type FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path);
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step() failed [%d]", ret);
-
- *item = g_new0(media_svc_noti_item, 1);
-
- (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
- (*item)->media_type = sqlite3_column_int(sql_stmt, 1);
- (*item)->mime_type = g_strdup((const char *)sqlite3_column_text(sql_stmt, 2));
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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 <unistd.h>
-#include "media-svc-noti.h"
-#include "media-svc-util.h"
-#include "media-svc-debug.h"
-
-static __thread GSList *g_inserted_noti_list = NULL;
-static __thread int g_noti_from_pid = -1;
-
-static void __media_svc_publish_noti_by_item(gpointer data, gpointer user_data)
-{
- int ret = MS_MEDIA_ERR_NONE;
- media_svc_noti_item *item = (media_svc_noti_item *)data;
-
- if (item && item->path) {
- ret = media_db_update_send(item->pid, item->update_item, item->update_type, item->path, item->media_uuid, item->media_type, item->mime_type);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_sec_error("media_db_update_send failed : %d [%s]", ret, item->path);
- } else {
- media_svc_debug("media_db_update_send success");
- }
- } else {
- media_svc_debug("invalid path");
- }
-}
-
-static void __media_svc_destroy_noti_item(gpointer data)
-{
- media_svc_noti_item *item = (media_svc_noti_item *)data;
-
- g_free(item->media_uuid);
- g_free(item->path);
- g_free(item->mime_type);
- g_free(item);
-}
-
-int _media_svc_publish_noti(media_item_update_type_e update_type, const char *path, int media_type, const char *uuid, const char *mime_type)
-{
- int ret = MS_MEDIA_ERR_NONE;
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
-
- ret = media_db_update_send(getpid(), MS_MEDIA_ITEM_FILE, update_type, path, uuid, media_type, mime_type);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Send noti failed[%d][%s]", ret, path);
-
- media_svc_sec_debug("Send noti [%s]", path);
-
- return ret;
-}
-
-int _media_svc_publish_dir_noti(media_item_update_type_e update_type, const char *path, const char *uuid, int pid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
-
- ret = media_db_update_send(pid, MS_MEDIA_ITEM_DIRECTORY, update_type, path, uuid, 0, NULL);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Send dir noti failed[%d][%s]", ret, path);
-
- media_svc_sec_debug("Send dir noti [%s]", path);
-
- return ret;
-}
-
-void _media_svc_set_noti_from_pid(int pid)
-{
- g_noti_from_pid = pid;
-}
-
-void _media_svc_initialize_noti_list(void)
-{
- if (g_inserted_noti_list)
- g_slist_free_full(g_inserted_noti_list, __media_svc_destroy_noti_item);
-
- g_inserted_noti_list = NULL;
-}
-
-void _media_svc_insert_item_to_noti_list(media_svc_content_info_s *content_info)
-{
- media_svc_noti_item *item = NULL;
-
- if (!content_info)
- return;
-
- item = g_new0(media_svc_noti_item, 1);
-
- item->pid = g_noti_from_pid;
- item->update_item = MS_MEDIA_ITEM_INSERT; /* INSERT */
- item->update_type = MS_MEDIA_ITEM_FILE;
- item->media_type = content_info->media_type;
- item->media_uuid = g_strdup(content_info->media_uuid);
- item->path = g_strdup(content_info->path);
- item->mime_type = g_strdup(content_info->mime_type);
-
- g_inserted_noti_list = g_slist_append(g_inserted_noti_list, (gpointer)item);
-}
-
-void _media_svc_publish_noti_list(void)
-{
- g_slist_foreach(g_inserted_noti_list, __media_svc_publish_noti_by_item, NULL);
-
- _media_svc_initialize_noti_list();
-}
-
-void _media_svc_destroy_noti_item(media_svc_noti_item *item)
-{
- if (!item)
- return;
-
- g_free(item->media_uuid);
- g_free(item->path);
- g_free(item->mime_type);
- g_free(item);
-}
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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 <media-util-user.h>
-#include "media-svc-debug.h"
-#include "media-svc-env.h"
-#include "media-svc-db-utils.h"
-#include "media-svc-util.h"
-#include "media-svc-storage.h"
-
-int _media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
-
- media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
- media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
- media_svc_retvm_if(validity == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "validity is NULL");
-
- *storage_path = NULL;
- *validity = 0;
-
- sql = sqlite3_mprintf("SELECT storage_path, validity FROM %q WHERE storage_id=%Q", DB_TABLE_STORAGE, storage_id);
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- *storage_path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
- *validity = sqlite3_column_int(sql_stmt, 1);
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_append_storage(const char *storage_id, const char *storage_path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = sqlite3_mprintf("INSERT INTO %q (storage_id, storage_path) values (%Q, %Q);",
- DB_TABLE_STORAGE, storage_id, storage_path);
-
- ret = _media_svc_sql_query_direct(sql, uid);
- SQLITE3_SAFE_FREE(sql);
-
- return ret;
-}
-
-int _media_svc_update_storage_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
- char *old_storage_path = NULL;
- int validity = 0;
-
- media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
- media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- /*Get old path*/
- ret = _media_svc_check_storage(handle, storage_id, &old_storage_path, &validity);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- /*Storage table update*/
- sql = sqlite3_mprintf("UPDATE %q SET storage_path=%Q WHERE storage_id=%Q", DB_TABLE_STORAGE, path, storage_id);
- ret = _media_svc_sql_query_direct(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- if (ret != MS_MEDIA_ERR_NONE) {
- g_free(old_storage_path);
- return ret;
- }
-
- /*Folder table update*/
- sql = sqlite3_mprintf("UPDATE %q SET folder_path=REPLACE(folder_path, %Q, %Q) WHERE storage_uuid=%Q", DB_TABLE_FOLDER, old_storage_path, path, storage_id);
- ret = _media_svc_sql_query_direct(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- if (ret != MS_MEDIA_ERR_NONE) {
- g_free(old_storage_path);
- return ret;
- }
-
- /*Media table update*/
- sql = sqlite3_mprintf("UPDATE %q SET media_path=REPLACE(media_path, %Q, %Q) WHERE storage_uuid=%Q", DB_TABLE_MEDIA, old_storage_path, path, storage_id);
- ret = _media_svc_sql_query_direct(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- g_free(old_storage_path);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- return ret;
-}
-
-static int __media_svc_delete_thumbnail(sqlite3 *handle)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
- sqlite3_stmt *sql_stmt = NULL;
-
- sql = sqlite3_mprintf("SELECT media_thumbnail_path FROM %q WHERE validity=0 AND media_thumbnail_path is not null", DB_TABLE_MEDIA);
- ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- while (sqlite3_step(sql_stmt) == SQLITE_ROW)
- _media_svc_remove_file((const char *)sqlite3_column_text(sql_stmt, 0));
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return ret;
-}
-
-int _media_svc_delete_invalid_storage(sqlite3 *handle, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
-
- ret = __media_svc_delete_thumbnail(handle);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to remove thumbnail");
-
- sql = sqlite3_mprintf("DELETE FROM %q WHERE validity=0;DELETE FROM %q WHERE validity=0;DELETE FROM %q WHERE validity=0;",
- DB_TABLE_MEDIA, DB_TABLE_STORAGE, DB_TABLE_FOLDER);
-
- ret = _media_svc_sql_query_direct(sql, uid);
- SQLITE3_SAFE_FREE(sql);
-
- return ret;
-}
-
-int _media_svc_update_storage_validity(const char *storage_id, int validity, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
-
- if (storage_id == NULL) {
- sql = sqlite3_mprintf("UPDATE %q SET validity=%d;UPDATE %q SET validity=%d WHERE storage_uuid IS NOT 'media';UPDATE %q SET validity=%d WHERE storage_uuid IS NOT 'media';",
- DB_TABLE_STORAGE, validity, DB_TABLE_FOLDER, validity, DB_TABLE_MEDIA, validity);
- } else {
- sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE storage_id=%Q;UPDATE %q SET validity=%d WHERE storage_uuid=%Q;UPDATE %q SET validity=%d WHERE storage_uuid=%Q;",
- DB_TABLE_STORAGE, validity, storage_id, DB_TABLE_FOLDER, validity, storage_id, DB_TABLE_MEDIA, validity, storage_id);
- }
- ret = _media_svc_sql_query_direct(sql, uid);
- SQLITE3_SAFE_FREE(sql);
-
- return ret;
-}
-
-int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
- char *internal_path = NULL;
-
- media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- ret = ms_user_get_internal_root_path(uid, &internal_path);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
-
- if (STRING_VALID(internal_path) && strncmp(path, internal_path, strlen(internal_path)) == 0) {
- g_strlcpy(storage_id, DB_TABLE_MEDIA, MEDIA_SVC_UUID_SIZE + 1);
- g_free(internal_path);
- return MS_MEDIA_ERR_NONE;
- }
-
- g_free(internal_path);
-
- sql = sqlite3_mprintf("SELECT storage_id FROM %q WHERE validity=1 AND instr(%Q, storage_path)", DB_TABLE_STORAGE, path);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0)))
- g_strlcpy(storage_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
-
- SQLITE3_FINALIZE(sql_stmt);
-
- if (!STRING_VALID(storage_id)) {
- media_svc_error("Not found valid storage id [%s]", path);
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- return ret;
-}
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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 <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/vfs.h>
-#include <ctype.h>
-#include <aul/aul.h>
-#include <mm_file.h>
-#include <libexif/exif-data.h>
-#include <uuid/uuid.h>
-#include <media-thumbnail.h>
-#include <media-util-user.h>
-#include "media-svc-util.h"
-#include "media-svc-db-utils.h"
-#include "media-svc-debug.h"
-#include "media-svc-env.h"
-#include "media-svc-album.h"
-/*For ebook metadata */
-#include <zip.h>
-#include <libxml/xmlmemory.h>
-#include <libxml/parser.h>
-#include <libxml/HTMLparser.h>
-#include <dlfcn.h>
-
-#define MEDIA_SVC_FILE_EXT_LEN_MAX 6
-
-#define MUSIC_MIME_NUM 29
-#define SOUND_MIME_NUM 2
-#define MIME_LENGTH 50
-#define IMAGE_PREFIX "image/"
-#define AUDIO_PREFIX "audio/"
-#define VIDEO_PREFIX "video/"
-#define PREFIX_LEN 6
-
-#define MEDIA_SVC_PDF_TAG_TAIL_LEN 12
-#define MEDIA_SVC_PDF_BUF_SIZE 256
-
-#define MEDIA_SVC_THUMB_WIDTH 320
-#define MEDIA_SVC_THUMB_HEIGHT 240
-
-#define PATH_PLUGIN_LIB PATH_LIBDIR"/libmedia-ebook-plugin.so"
-
-enum Exif_Orientation {
- NOT_AVAILABLE = 0,
- NORMAL = 1,
- HFLIP = 2,
- ROT_180 = 3,
- VFLIP = 4,
- TRANSPOSE = 5,
- ROT_90 = 6,
- TRANSVERSE = 7,
- ROT_270 = 8
-};
-
-static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
- /*known mime types of normal files*/
- "mpeg",
- "ogg",
- "x-ms-wma",
- "x-flac",
- "mp4",
- "mp3",
- "x-mp3", /*alias of audio/mpeg*/
- "x-mpeg", /*alias of audio/mpeg*/
- "3gpp",
- "x-ogg", /*alias of audio/ogg*/
- "vnd.ms-playready.media.pya:*.pya", /*playready*/
- "wma",
- "aac",
- "x-m4a", /*alias of audio/mp4*/
- /* below mimes are rare*/
- "x-vorbis+ogg",
- "x-flac+ogg",
- "x-matroska",
- "ac3",
- "mp2",
- "x-ape",
- "x-ms-asx",
- "vnd.rn-realaudio",
- "x-vorbis", /*alias of audio/x-vorbis+ogg*/
- "vorbis", /*alias of audio/x-vorbis+ogg*/
- "x-oggflac",
- "x-mp2", /*alias of audio/mp2*/
- "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
- "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
- "x-wav",
-};
-
-static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
- "application/x-smaf",
- "text/x-iMelody"
-};
-
-static char *__media_info_generate_uuid(void)
-{
- uuid_t uuid_value;
- char uuid_unparsed[37];
-
-RETRY_GEN:
- uuid_generate(uuid_value);
- uuid_unparse(uuid_value, uuid_unparsed);
-
- if (strlen(uuid_unparsed) < 36) {
- media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
- goto RETRY_GEN;
- }
-
- return g_strdup(uuid_unparsed);
-}
-
-static char * __media_svc_get_exif_datetaken(ExifData *ed)
-{
- ExifEntry *entry;
- char tmp[MEDIA_SVC_METADATA_LEN_MAX + 1] = { 0, };
-
- media_svc_retv_if(!ed, NULL);
-
- entry = exif_data_get_entry(ed, EXIF_TAG_DATE_TIME_ORIGINAL);
- if (entry) {
- exif_entry_get_value(entry, tmp, MEDIA_SVC_METADATA_LEN_MAX);
- if (strlen(tmp) > 0)
- return g_strdup(tmp);
- }
-
- entry = exif_data_get_entry(ed, EXIF_TAG_DATE_TIME);
- if (entry) {
- exif_entry_get_value(entry, tmp, MEDIA_SVC_METADATA_LEN_MAX);
- if (strlen(tmp) > 0)
- return g_strdup(tmp);
- }
-
- return NULL;
-}
-
-static bool __media_svc_get_exif_short(ExifData *ed, ExifTag tagtype, unsigned short *value)
-{
- ExifEntry *entry;
-
- media_svc_retv_if(!ed, false);
- media_svc_retvm_if(!value, false, "value is NULL");
-
- entry = exif_data_get_entry(ed, tagtype);
- media_svc_retv_if(!entry, false);
- *value = exif_get_short(entry->data, exif_data_get_byte_order(ed));
-
- return true;
-}
-
-static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
-{
- int idx = 0;
- int audio = 0;
- int video = 0;
-
- media_svc_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "path is null");
- media_svc_retvm_if(!mime_type, MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is null");
- media_svc_retvm_if(!media_type, MS_MEDIA_ERR_INVALID_PARAMETER, "media_type is null");
-
- /* Image */
- if (strncmp(mime_type, IMAGE_PREFIX, PREFIX_LEN) == 0) {
- *media_type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
- return MS_MEDIA_ERR_NONE;
- }
-
- /* Audio */
- if (strncmp(mime_type, AUDIO_PREFIX, PREFIX_LEN) == 0) {
- *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
-
- for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
- if (strcmp(mime_type + PREFIX_LEN, music_mime_table[idx]) == 0) {
- *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
- break;
- }
- }
-
- /* audio/x-mpegurl : .m3u file (playlist file) */
- if (strcmp(mime_type + PREFIX_LEN, "x-mpegurl") == 0)
- *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
-
- return MS_MEDIA_ERR_NONE;
- }
-
- /* Video */
- if (strncmp(mime_type, VIDEO_PREFIX, PREFIX_LEN) == 0) {
- *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
-
- /*some video files don't have video stream. in this case it is categorize as music. */
- if (strcmp(mime_type + PREFIX_LEN, "3gpp") == 0 ||
- strcmp(mime_type + PREFIX_LEN, "mp4") == 0) {
- if (mm_file_get_stream_info(path, &audio, &video) == FILEINFO_ERROR_NONE) {
- if (audio > 0 && video == 0)
- *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
- }
- }
-
- return MS_MEDIA_ERR_NONE;
- }
-
- /* ETC */
- *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
-
- for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
- if (strcmp(mime_type, sound_mime_table[idx]) == 0) {
- *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
- return MS_MEDIA_ERR_NONE;
- }
- }
-
- /*"asf" must check video stream and then categorize in directly. */
- if (strcmp(mime_type, "application/vnd.ms-asf") == 0) {
- if (mm_file_get_stream_info(path, &audio, &video) == FILEINFO_ERROR_NONE) {
- if (audio > 0 && video == 0)
- *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
- else
- *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
- }
-
- return MS_MEDIA_ERR_NONE;
- }
-
- if (strcmp(mime_type, "application/epub+zip") == 0 || strcmp(mime_type, "application/pdf") == 0)
- *media_type = MEDIA_SVC_MEDIA_TYPE_BOOK;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int __media_svc_get_mime_type(const char *path, char *mimetype)
-{
- media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
- media_svc_error("aul_get_mime_from_file fail");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
-{
- int i = 0;
-
- for (i = strlen(file_path); i >= 0; i--) {
- if (file_path[i] == '.') {
- g_strlcpy(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
- return true;
- }
-
- if (file_path[i] == '/')
- return false;
- }
- return false;
-}
-
-static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- struct statfs fs;
- char *thumb_path = NULL;
- long bsize_kbytes = 0;
- GError *error = NULL;
-
- media_svc_retvm_if(!image || size == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid image");
- media_svc_sec_debug("start save image, path [%s] image size [%d]", image_path, size);
-
- ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path error");
-
- ret = statfs(thumb_path, &fs);
- g_free(thumb_path);
- media_svc_retvm_if(ret == -1, MS_MEDIA_ERR_INTERNAL, "statfs failed");
-
- bsize_kbytes = fs.f_bsize >> 10;
- media_svc_retvm_if((bsize_kbytes * fs.f_bavail) < 1024, MS_MEDIA_ERR_NOT_ENOUGH_SPACE, "Not enough space");
-
- if (!g_file_set_contents(image_path, (const gchar *)image, (gssize)size, &error)) {
- media_svc_error("g_file_set_contents faild:%s", error->message);
- g_error_free(error);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static char *__media_svc_get_title_from_filename(const char *filename)
-{
- char *title = NULL;
- char *last_dot = NULL;
-
- media_svc_retvm_if(!STRING_VALID(filename), g_strdup(MEDIA_SVC_TAG_UNKNOWN), "Invalid path");
-
- last_dot = strrchr(filename, '.');
- if (last_dot) {
- title = g_strndup(filename, last_dot - filename);
- } else {
- title = g_strdup(filename);
- }
-
- media_svc_debug("extract title is [%s]", title);
-
- return title;
-}
-
-void _media_svc_remove_file(const char *path)
-{
- if (!STRING_VALID(path))
- return;
-
- if (remove(path) != 0)
- media_svc_stderror("fail to remove file result");
-}
-
-static int __media_svc_get_thumbnail_path(char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
- g_autofree gchar *hash = NULL;
- g_autofree gchar *thumb_dir = NULL;
-
- ret = ms_user_get_root_thumb_store_path(uid, &thumb_dir);
- media_svc_retvm_if(!STRING_VALID(thumb_dir), ret, "ms_user_get_root_thumb_store_path failed");
- media_svc_retvm_if(!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR), MS_MEDIA_ERR_INTERNAL, "Not a directory");
-
- memset(file_ext, 0, sizeof(file_ext));
- if (!__media_svc_get_file_ext(pathname, file_ext))
- media_svc_error("get file ext fail");
-
- hash = g_compute_checksum_for_string(G_CHECKSUM_MD5, pathname, -1);
- media_svc_retvm_if(!hash, MS_MEDIA_ERR_INTERNAL, "Failed to create hashname");
-
- if (img_format) {
- /* 'img_format' is mime-type */
- if (!g_str_has_prefix(img_format, IMAGE_PREFIX) || strlen(img_format) == PREFIX_LEN) {
- media_svc_error("Not proper img format");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.%s", thumb_dir, file_ext, hash, img_format + PREFIX_LEN);
- } else {
- if (strcasecmp(file_ext, "PNG") == 0)
- snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.png", thumb_dir, file_ext, hash);
- else
- snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.jpg", thumb_dir, file_ext, hash);
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_get_file_time(const char *full_path)
-{
- struct stat statbuf = { 0, };
-
- if (stat(full_path, &statbuf) == -1) {
- media_svc_stderror("stat fails.");
- return 0;
- }
-
- return statbuf.st_mtime;
-}
-
-int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, const char *path, bool refresh)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char mime_type[256] = {0, };
- media_svc_media_type_e media_type;
- struct stat st = { 0, };
-
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- content_info->path = g_strdup(path);
- content_info->file_name = g_path_get_basename(path);
-
- if (stat(path, &st) == 0) {
- content_info->modified_time = st.st_mtime;
- content_info->size = st.st_size;
- } else {
- media_svc_stderror("stat failed");
- }
-
- /* refresh is TRUE when file modified. so only modified_time and size are changed*/
- if (refresh) {
- media_svc_debug("refresh");
- return MS_MEDIA_ERR_NONE;
- }
-
- content_info->storage_uuid = g_strdup(storage_id);
- media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
- content_info->media_uuid = __media_info_generate_uuid();
- media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
- ret = __media_svc_get_mime_type(path, mime_type);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
-
- media_svc_debug("mime [%s]", mime_type);
-
- ret = __media_svc_get_media_type(path, mime_type, &media_type);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
-
- content_info->mime_type = g_strdup(mime_type);
- media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
- media_svc_sec_debug("path[%s], media_type[%d]", content_info->path, media_type);
-
- content_info->media_type = media_type;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static char * __media_svc_get_title(MMHandleType tag, const char *filename)
-{
- int ret = FILEINFO_ERROR_NONE;
- char *p = NULL;
- int size = 0;
-
- if (tag) {
- ret = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
- if (ret == FILEINFO_ERROR_NONE && size > 0) {
- while(p && isspace(*p))
- p++;
-
- return g_strdup(p);
- }
- }
-
- return __media_svc_get_title_from_filename(filename);
-}
-
-char * _media_svc_get_title_from_filename(const char *filename)
-{
- return __media_svc_get_title_from_filename(filename);
-}
-
-int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info)
-{
- unsigned short orient_value = 0;
- unsigned short exif_width = 0;
- unsigned short exif_height = 0;
- ExifData *ed = NULL;
-
- media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid content_info");
- media_svc_retvm_if(content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid media_type");
- media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
-
- content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
-
- /* Load an ExifData object from an EXIF file */
- ed = exif_data_new_from_file(content_info->path);
- if (!ed) {
- media_svc_sec_debug("There is no exif data in [ %s ]", content_info->path);
- goto GET_WIDTH_HEIGHT;
- }
-
- content_info->media_meta.datetaken = __media_svc_get_exif_datetaken(ed);
-
- if (__media_svc_get_exif_short(ed, EXIF_TAG_ORIENTATION, &orient_value)) {
- if (orient_value <= ROT_270)
- content_info->media_meta.orientation = orient_value;
- }
-
- if (__media_svc_get_exif_short(ed, EXIF_TAG_PIXEL_X_DIMENSION, &exif_width))
- content_info->media_meta.width = (unsigned int)exif_width;
-
- if (__media_svc_get_exif_short(ed, EXIF_TAG_PIXEL_Y_DIMENSION, &exif_height))
- content_info->media_meta.height = (unsigned int)exif_height;
-
- exif_data_unref(ed);
-
-GET_WIDTH_HEIGHT:
- if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
- /*Get image width, height*/
- unsigned int img_width = 0;
- unsigned int img_height = 0;
-
- if (get_image_info(content_info->path, &img_width, &img_height) != THUMB_OK)
- return MS_MEDIA_ERR_NONE;
-
- if (content_info->media_meta.width == 0)
- content_info->media_meta.width = img_width;
-
- if (content_info->media_meta.height == 0)
- content_info->media_meta.height = img_height;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static char * __media_svc_get_tag_str_value(MMHandleType tag, const char *tag_name)
-{
- int ret = FILEINFO_ERROR_NONE;
- char *p = NULL;
- int size = 0;
-
- ret = mm_file_get_attrs(tag, tag_name, &p, &size, NULL);
- if (ret == FILEINFO_ERROR_NONE && size > 0)
- return g_strdup(p);
-
- return g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-}
-
-static char * __media_svc_extract_albumart(MMHandleType tag, const char *path, uid_t uid)
-{
- int ret = FILEINFO_ERROR_NONE;
- unsigned char *image = NULL;
- unsigned int size = 0;
- char *mimetype = NULL;
- char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = { 0, };
- unsigned int mime_size = 0;
-
- ret = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
- media_svc_retvm_if(ret != FILEINFO_ERROR_NONE, NULL, "Failed to get tag artwork[%d]", ret);
- media_svc_retvm_if(!image || size == 0, NULL, "Invalid artwork");
-
- ret = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_MIME, &mimetype, &mime_size, NULL);
- media_svc_retvm_if(ret != FILEINFO_ERROR_NONE, NULL, "Failed to get tag mime[%d]", ret);
- media_svc_retvm_if(mime_size == 0, NULL, "Invalid mimetype");
-
- ret = __media_svc_get_thumbnail_path(thumb_path, path, mimetype, uid);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, NULL, "Failed to get thumbnail path");
-
- ret = __media_svc_save_image(image, size, thumb_path, uid);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, NULL, "Fail to save thumbnail");
-
- return g_strdup(thumb_path);
-}
-
-void _media_svc_extract_audio_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
-{
- MMHandleType tag = 0;
- char *p = NULL;
- unsigned int size = 0;
- int mmf_error = FILEINFO_ERROR_NONE;
- int album_id = 0;
- int ret = MS_MEDIA_ERR_NONE;
- bool support_albumart = ms_user_thumb_support(uid, content_info->path);
-
- /*Get Content Tag attribute ===========*/
- if (support_albumart)
- mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
- else
- mmf_error = mm_file_create_tag_attrs_no_albumart(&tag, content_info->path);
-
- if (mmf_error != FILEINFO_ERROR_NONE) {
- content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
- content_info->album_id = 0;
- return;
- }
-
- content_info->media_meta.title = __media_svc_get_title(tag, content_info->file_name);
- content_info->media_meta.album = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM);
- content_info->media_meta.artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ARTIST);
- content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST);
- content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE);
- content_info->media_meta.track_num = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_TRACK_NUM);
-
- mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE && size == 4)
- content_info->media_meta.year = g_strdup(p);
- else
- content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-
- /*Do not extract artwork for the USB Storage content*/
- if (support_albumart)
- content_info->thumbnail_path = __media_svc_extract_albumart(tag, content_info->path, uid);
-
- ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
- media_svc_debug("album does not exist. So start to make album art");
- if (strlen(content_info->media_meta.album) > 0 && strlen(content_info->media_meta.artist) > 0)
- ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
- else
- ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
- }
- content_info->album_id = album_id;
-
- if (mm_file_destroy_tag_attrs(tag) != FILEINFO_ERROR_NONE)
- media_svc_error("destroy failed");
-}
-
-void _media_svc_extract_video_metadata(media_svc_content_info_s *content_info)
-{
- /* All metadata fields must be empty strings until media_video is deleted */
- content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
- content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
- content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
- content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
- content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
- content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
- content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
- content_info->album_id = 0;
-}
-
-static gchar * __media_svc_get_zipfile_string(zip_t *z, const char *fname)
-{
- int err = 0;
- zip_int64_t index_num = 0;
- zip_file_t *file = NULL;
- zip_stat_t sb = {0, };
- gchar *buf = NULL;
-
- media_svc_retvm_if(!z, NULL, "z is NULL");
- media_svc_retvm_if(!fname, NULL, "fname is NULL");
-
- index_num = zip_name_locate(z, fname, ZIP_FL_NOCASE);
- media_svc_retvm_if(index_num == -1, NULL, "fname is not exists [%s]", fname);
-
- err = zip_stat_index(z, index_num, ZIP_STAT_SIZE, &sb);
- media_svc_retvm_if(err == -1, NULL, "zip_stat_index failed");
-
- file = zip_fopen_index(z, index_num, ZIP_FL_UNCHANGED);
- media_svc_retvm_if(!file, NULL, "zip_fopen_index failed");
-
- buf = g_malloc0(sb.size + 1);
-
- err = zip_fread(file, buf, sb.size);
- zip_fclose(file);
-
- if (err == -1) {
- g_free(buf);
- buf = NULL;
- }
-
- return buf;
-}
-
-static xmlNodePtr __media_svc_find_node(xmlNodePtr node, const char *key)
-{
- xmlNodePtr tmp = NULL;
-
- media_svc_retvm_if(!node, NULL, "node is NULL");
- media_svc_retvm_if(!key, NULL, "key is NULL");
-
- for (tmp = node->children; tmp; tmp = tmp->next) {
- if (xmlIsBlankNode(tmp))
- continue;
-
- if (g_str_has_suffix((gchar *)tmp->name, key))
- return tmp;
- }
-
- return NULL;
-}
-
-static char * __media_svc_remove_escape_c(const char *value)
-{
- int start = -1;
- int end = 0;
- int len, i;
-
- media_svc_retv_if(!value, NULL);
-
- len = strlen(value);
-
- for (i = 0; i < len; i++) {
- if (value[i] != 10 && value[i] != 32) { // 10='\n' 32=' '
- if (start == -1)
- start = i;
-
- end = i;
- }
- }
-
- end = end - start + 1;
-
- return g_strndup(value + start, end);
-}
-
-static char * __media_svc_find_and_get_value(xmlNodePtr node, const char *key)
-{
- xmlNodePtr tmp = NULL;
- char *tmp_res = NULL;
- char *res = NULL;
-
- media_svc_retvm_if(!node, NULL, "node is NULL");
- media_svc_retvm_if(!key, NULL, "key is NULL");
-
- for (tmp = node->children; tmp; tmp = tmp->next) {
- if (xmlIsBlankNode(tmp))
- continue;
-
- if (tmp->children) {
- tmp_res = __media_svc_find_and_get_value(tmp, key);
- if (tmp_res) {
- res = __media_svc_remove_escape_c(tmp_res);
- xmlFree(tmp_res);
- return res;
- }
- }
-
- if (g_str_has_suffix((gchar *)tmp->name, key))
- return (char *)xmlNodeGetContent(tmp);
- }
-
- return NULL;
-}
-
-static gboolean __media_svc_get_epub_root_file(zip_t *z, char **opf_file)
-{
- gchar *buf = NULL;
- gchar *tmp_buf = NULL;
- xmlDocPtr doc = NULL;
- xmlNodePtr node = NULL;
-
- media_svc_retvm_if(!z, FALSE, "z is NULL");
- media_svc_retvm_if(!opf_file, FALSE, "opf_file is NULL");
-
- buf = __media_svc_get_zipfile_string(z, "META-INF/container.xml");
- media_svc_retvm_if(!buf, FALSE, "buf is NULL");
-
- tmp_buf = g_strrstr(buf, ">");
- if (tmp_buf)
- *(tmp_buf + 1) = '\0';
-
- doc = xmlParseDoc((const xmlChar *)buf);
- g_free(buf);
- media_svc_retvm_if(!doc, FALSE, "doc is NULL");
-
- node = xmlDocGetRootElement(doc);
- node = __media_svc_find_node(node, "rootfiles");
- node = __media_svc_find_node(node, "rootfile");
-
- *opf_file = (char *)xmlGetProp(node, (const xmlChar *)"full-path");
- media_svc_sec_debug("OPF [%s]", *opf_file);
- xmlFreeDoc(doc);
-
- return TRUE;
-}
-
-static gboolean __media_svc_get_xml_metadata(const xmlChar *buffer, gboolean is_pdf, media_svc_content_info_s *content_info)
-{
- xmlDocPtr doc = NULL;
- xmlNodePtr root = NULL;
-
- media_svc_retvm_if(!buffer, FALSE, "buffer is NULL");
- media_svc_retvm_if(!content_info, FALSE, "content_info is NULL");
-
- doc = xmlParseDoc(buffer);
- media_svc_retv_if(!doc, FALSE);
-
- root = xmlDocGetRootElement(doc);
- if (!root) {
- xmlFreeDoc(doc);
- return FALSE;
- }
-
- content_info->media_meta.title = __media_svc_find_and_get_value(root, "title");
- /* In the case of PDF, if there is no title, it may not be a metadata block. Search for the next xml block*/
- if (is_pdf && !content_info->media_meta.title) {
- xmlFreeDoc(doc);
- return FALSE;
- }
-
- content_info->media_meta.artist = __media_svc_find_and_get_value(root, "creator");
- if (!content_info->media_meta.artist)
- content_info->media_meta.artist = __media_svc_find_and_get_value(root, "author");
- content_info->media_meta.genre = __media_svc_find_and_get_value(root, "subject");
-
- xmlFreeDoc(doc);
-
- return TRUE;
-}
-
-static int __media_svc_get_epub_metadata(media_svc_content_info_s *content_info)
-{
- int err = 0;
- zip_t *z = NULL;
- gchar *buf = NULL;
- char *opf_path = NULL;
-
- media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content_info is NULL");
-
- //1. open epub
- z = zip_open(content_info->path, ZIP_RDONLY, &err);
- media_svc_retvm_if(err == -1, MS_MEDIA_ERR_INTERNAL, "zip_open failed");
-
- //2. find and read opf file
- if (!__media_svc_get_epub_root_file(z, &opf_path)) {
- media_svc_error("__media_svc_get_epub_root_file failed");
- zip_close(z);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- //3. get metadata
- buf = __media_svc_get_zipfile_string(z, opf_path);
- xmlFree(opf_path);
- zip_close(z);
- media_svc_retvm_if(!buf, MS_MEDIA_ERR_INTERNAL, "__media_svc_get_zipfile_string failed");
-
- if (!__media_svc_get_xml_metadata((const xmlChar *)buf, FALSE, content_info))
- media_svc_error("__media_svc_get_xml_metadata failed");
-
- g_free(buf);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int __media_svc_get_pdf_metadata(media_svc_content_info_s *content_info)
-{
- int fd = 0;
- int start_pos = 0;
- int end_pos = 0;
- int cur_pos = 0;
- int search_limit = 0;
- char tmp[MEDIA_SVC_PDF_BUF_SIZE + 1] = {0, };
- gchar *meta_buf = NULL;
- char *found = NULL;
-
- media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content_info is NULL");
- media_svc_retvm_if(content_info->size < 256, MS_MEDIA_ERR_INTERNAL, "open failed");
-
- fd = open(content_info->path, O_RDONLY);
- media_svc_retvm_if(fd < 0, MS_MEDIA_ERR_INTERNAL, "open failed");
-
- search_limit = content_info->size - MEDIA_SVC_PDF_TAG_TAIL_LEN;
-
- while (cur_pos <= search_limit) {
- if (lseek(fd, cur_pos, SEEK_SET) == -1)
- break;
-
- memset(&tmp, 0x00, MEDIA_SVC_PDF_BUF_SIZE + 1);
-
- if (read(fd, &tmp, MEDIA_SVC_PDF_BUF_SIZE) != MEDIA_SVC_PDF_BUF_SIZE) {
- media_svc_error("read failed");
- break;
- }
-
- //1.Find <x:xmpmeta .. </x:xmpmeta> block
- if (start_pos == 0 && (found = strstr(tmp, "<x:xmpmeta"))) {
- start_pos = cur_pos + (found - tmp);
-// media_svc_error("FIND START_POS[%d]", start_pos);
- found = NULL;
- }
-
-
- if (start_pos != 0 && (found = strstr(tmp, "</x:xmpmeta>"))) {
- end_pos = cur_pos + (found - tmp) + MEDIA_SVC_PDF_TAG_TAIL_LEN;
-// media_svc_error("FIND END_POS[%d]", end_pos);
- found = NULL;
- }
-
- //2.get metadata using xml parser
- if (start_pos && end_pos) {
- if (lseek(fd, start_pos, SEEK_SET) == -1)
- break;
-
- meta_buf = g_malloc0(end_pos - start_pos + 1);
-
- if (read(fd, meta_buf, end_pos - start_pos) == end_pos - start_pos) {
- if (__media_svc_get_xml_metadata((const xmlChar *)meta_buf, TRUE, content_info)) {
- g_free(meta_buf);
- break;
- }
- }
-
- g_free(meta_buf);
-
- start_pos = 0;
- end_pos = 0;
- }
-
- cur_pos += 240;
-
- }
-
- close(fd);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_extract_book_metadata(media_svc_content_info_s *content_info)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content info is NULL");
-
- if (g_str_has_suffix(content_info->mime_type, "epub+zip"))
- ret = __media_svc_get_epub_metadata(content_info);
- else
- ret = __media_svc_get_pdf_metadata(content_info);
-
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "failed to extract metadata");
- if (!content_info->media_meta.title || strlen(content_info->media_meta.title) == 0) {
- g_free(content_info->media_meta.title);
- content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
-{
- media_svc_retm_if(!content_info, "content info is NULL");
-
- /* Delete media_svc_content_info_s */
- g_free(content_info->media_uuid);
- g_free(content_info->path);
- g_free(content_info->file_name);
- g_free(content_info->mime_type);
- g_free(content_info->thumbnail_path);
- g_free(content_info->storage_uuid);
-
- /* Delete media_svc_content_meta_s */
- g_free(content_info->media_meta.title);
- g_free(content_info->media_meta.album);
- g_free(content_info->media_meta.artist);
- g_free(content_info->media_meta.album_artist);
- g_free(content_info->media_meta.genre);
- g_free(content_info->media_meta.year);
- g_free(content_info->media_meta.track_num);
- g_free(content_info->media_meta.datetaken);
-}
-
-int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- media_svc_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
- media_svc_retvm_if(!thumb_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid thumb_path");
- media_svc_retvm_if(!g_file_test(path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "File doesn't exist[%s]", path);
-
- if (!ms_user_thumb_support(uid, path)) {
- media_svc_sec_error("origin path(%s) is invalid", path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- media_svc_sec_debug("Path[%s] Type[%d]", path, media_type);
-
- //1. make thumb path
- ret = __media_svc_get_thumbnail_path(thumb_path, path, NULL, uid);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Failed to create thumbnail path[%d]", ret);
-
- //2. save thumbnail
- if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
- ret = create_image_thumbnail_to_file(path, MEDIA_SVC_THUMB_WIDTH, MEDIA_SVC_THUMB_HEIGHT, thumb_path, true);
- else
- ret = create_video_thumbnail_to_file(path, MEDIA_SVC_THUMB_WIDTH, MEDIA_SVC_THUMB_HEIGHT, thumb_path, true);
-
- return (ret == THUMB_OK) ? MS_MEDIA_ERR_NONE : MS_MEDIA_ERR_INTERNAL;
-}
-
-int _media_svc_get_media_type(const char *path, int *mediatype)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char mime_type[256] = {0};
- media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
-
- media_svc_retvm_if(mediatype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mediatype is NULL");
-
- ret = __media_svc_get_mime_type(path, mime_type);
- if (ret == MS_MEDIA_ERR_NONE)
- __media_svc_get_media_type(path, mime_type, &media_type);
- else
- media_svc_error("__media_svc_get_mime_type failed");
-
- *mediatype = media_type;
-
- return ret;
-}
-
-bool _media_svc_is_keyword_included(const char *path, const char *keyword)
-{
- bool ret = false;
- void *handle = NULL;
- bool (*svc_search) (const char *, const char *);
-
- media_svc_retvm_if(!path, false, "Invalid path");
- media_svc_retvm_if(!keyword, false, "Invalid keyword");
-
- handle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY);
- media_svc_retvm_if(!handle, false, "dlopen failed");
-
- if (g_str_has_suffix(path, "epub") || g_str_has_suffix(path, "EPUB"))
- svc_search = dlsym(handle, "media_svc_epub_is_keyword_included");
- else
- svc_search = dlsym(handle, "media_svc_pdf_is_keyword_included");
-
- if (!svc_search) {
- media_svc_error("dlsym failed - %s", dlerror());
- dlclose(handle);
- return false;
- }
-
- ret = svc_search(path, keyword);
- dlclose(handle);
-
- return ret;
-}
-
-static int __media_svc_create_wordbook_db(const char *path, sqlite3 **handle)
-{
- int ret = SQLITE_OK;
- sqlite3 *db_handle = NULL;
- char *err = NULL;
-
- ret = sqlite3_open_v2(path, &db_handle, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
- media_svc_retvm_if(ret != SQLITE_OK, ret, "sqlite3_open_v2 failed : %d", ret);
-
- ret = sqlite3_exec(db_handle, "PRAGMA journal_mode = OFF;", NULL, NULL, &err);
- if (ret != SQLITE_OK)
- goto ERROR;
-
- ret = sqlite3_exec(db_handle, "CREATE TABLE IF NOT EXISTS files(id integer primary key autoincrement, path text unique, validity integer default 1);", NULL, NULL, &err);
- if (ret != SQLITE_OK)
- goto ERROR;
-
- ret = sqlite3_exec(db_handle, "CREATE TABLE IF NOT EXISTS words(file_id integer, word text, frequency integer default 1, unique(file_id, word));", NULL, NULL, &err);
- if (ret != SQLITE_OK)
- goto ERROR;
-
- ret = sqlite3_exec(db_handle, "CREATE TRIGGER IF NOT EXISTS TR_files_words DELETE ON files BEGIN DELETE FROM words WHERE file_id = old.id;END;", NULL, NULL, &err);
- if (ret != SQLITE_OK)
- goto ERROR;
-
- *handle = db_handle;
-
- return SQLITE_OK;
-
-ERROR:
- media_svc_error("sqlite3_exec failed : %s", err);
- SQLITE3_SAFE_FREE(err);
- sqlite3_close_v2(db_handle);
-
- return ret;
-}
-
-static bool __media_svc_get_wordbook_handle(uid_t uid, sqlite3 **handle)
-{
- int ret = SQLITE_OK;
- char *db_path = NULL;
-
- ms_user_get_wordbook_db_path(uid, &db_path);
- if (!db_path)
- return false;
-
- ret = sqlite3_open_v2(db_path, handle, SQLITE_OPEN_READWRITE, NULL);
- if (ret != SQLITE_OK) {
- ret = __media_svc_create_wordbook_db(db_path, handle);
- free(db_path);
- media_svc_retvm_if(ret != SQLITE_OK, false, "__media_svc_create_wordbook_db failed : %d", ret);
- } else {
- ret = sqlite3_exec(*handle, "PRAGMA journal_mode = OFF;", NULL, NULL, NULL);
- if (ret != SQLITE_OK)
- media_svc_error("Failed to change journal mode [%d]", ret);
- }
-
- return true;
-}
-
-static bool __media_svc_is_exist_in_wordbook(sqlite3 *db_handle, const char *path)
-{
- int ret = SQLITE_OK;
- char *err = NULL;
- char *query = NULL;
-
- query = sqlite3_mprintf("UPDATE files SET validity=1 WHERE path = %Q", path);
-
- ret = sqlite3_exec(db_handle, query, NULL, NULL, &err);
- SQLITE3_SAFE_FREE(query);
- if (ret != SQLITE_OK) {
- media_svc_error("Query failed. [%s]", err);
- SQLITE3_SAFE_FREE(err);
- return false;
- }
-
- return sqlite3_changes(db_handle) > 0 ? true : false;
-}
-
-static void __media_svc_insert_to_wordbook(sqlite3 *db_handle, const char *path)
-{
- void *handle = NULL;
- void (*svc_update) (sqlite3 *, const char *);
- char *query = NULL;
-
- query = sqlite3_mprintf("INSERT INTO files(path) VALUES(%Q);", path);
- sqlite3_exec(db_handle, query, NULL, NULL, NULL);
- sqlite3_free(query);
-
- handle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY);
- if (!handle) {
- media_svc_error("dlopen failed");
- return;
- }
-
- if (g_str_has_suffix(path, "epub") || g_str_has_suffix(path, "EPUB"))
- svc_update = dlsym(handle, "media_svc_epub_insert_to_db");
- else
- svc_update = dlsym(handle, "media_svc_pdf_insert_to_db");
-
- if (!svc_update) {
- media_svc_error("dlsym failed - %s", dlerror());
- dlclose(handle);
- return;
- }
-
- svc_update(db_handle, path);
- dlclose(handle);
-}
-
-void _media_svc_update_wordbook(const char *path, uid_t uid)
-{
- sqlite3 *db_handle = NULL;
-
- if (!path) {
- media_svc_error("Invalid path");
- return;
- }
-
- // check db..
- if (!__media_svc_get_wordbook_handle(uid, &db_handle))
- return;
-
- if (__media_svc_is_exist_in_wordbook(db_handle, path)) {
- sqlite3_close_v2(db_handle);
- return;
- }
-
- // if no item, insert to db..
- __media_svc_insert_to_wordbook(db_handle, path);
- sqlite3_close_v2(db_handle);
-}
-
-void _media_svc_clean_wordbook(uid_t uid)
-{
- sqlite3 *db_handle = NULL;
-
- if (!__media_svc_get_wordbook_handle(uid, &db_handle))
- return;
-
- sqlite3_exec(db_handle, "DELETE FROM files where validity = 0;", NULL, NULL, NULL);
- sqlite3_exec(db_handle, "UPDATE files SET validity = 0;", NULL, NULL, NULL);
- sqlite3_close_v2(db_handle);
-}
-
-bool _media_svc_get_matched_list(const char *keyword, uid_t uid, GList **list)
-{
- int ret = SQLITE_OK;
- sqlite3 *handle = NULL;
- sqlite3_stmt *stmt = NULL;
- char *query = NULL;
-
- media_svc_retvm_if(!list, false, "list is NULL");
- media_svc_retvm_if(!keyword, false, "keyword is NULL");
- media_svc_retvm_if(!__media_svc_get_wordbook_handle(uid, &handle), false, "Failed to get handle");
-
- query = sqlite3_mprintf("SELECT files.path FROM files JOIN (SELECT file_id, sum(frequency) AS freq_sum FROM words WHERE word LIKE '%q%%' GROUP BY file_id ORDER BY freq_sum DESC) w ON files.id = w.file_id;", keyword);
- ret = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
- SQLITE3_SAFE_FREE(query);
-
- if (ret != SQLITE_OK) {
- media_svc_error("Query failed[%d]", ret);
- sqlite3_close_v2(handle);
- return false;
- }
-
- while (sqlite3_step(stmt) == SQLITE_ROW)
- *list = g_list_append(*list, g_strdup((char *)sqlite3_column_text(stmt, 0)));
-
- sqlite3_finalize(stmt);
- sqlite3_close_v2(handle);
-
- return true;
-}
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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 "media-svc-media.h"
-#include "media-svc-debug.h"
-#include "media-svc-util.h"
-#include "media-svc-db-utils.h"
-#include "media-svc-env.h"
-#include "media-svc-media-folder.h"
-#include "media-svc-album.h"
-#include "media-svc-noti.h"
-#include "media-svc-storage.h"
-
-#include <iniparser.h>
-
-#define CONTENT_INI_DEFAULT_PATH SYSCONFDIR"/multimedia/media_content_config.ini"
-
-//static __thread int g_media_svc_data_cnt = 0;
-static __thread int g_media_svc_cur_data_cnt = 0;
-
-/* Flag for items to be published by notification */
-static __thread bool g_insert_with_noti = false;
-
-#define BATCH_ITEM_COUNT_MAX 100
-
-int media_svc_check_table_exist(sqlite3 *handle, bool *exist)
-{
- return _media_svc_check_table_exist(handle, exist);
-}
-
-int media_svc_create_table(uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- media_svc_debug_fenter();
-
- ret = _media_svc_init_table_query();
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_init_table_query fail.");
- goto ERROR;
- }
-
- /*create media table*/
- ret = _media_svc_make_table_query(DB_TABLE_MEDIA, DB_LIST_MEDIA, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_make_table_query fail.");
- goto ERROR;
- }
-
- /*create folder table*/
- ret = _media_svc_make_table_query(DB_TABLE_FOLDER, DB_LIST_FOLDER, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_make_table_query fail.");
- goto ERROR;
- }
-
- /*create playlist_map table*/
- ret = _media_svc_make_table_query(DB_TABLE_PLAYLIST_MAP, DB_LIST_PLAYLIST_MAP, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_make_table_query fail.");
- goto ERROR;
- }
-
- /*create playlist table*/
- ret = _media_svc_make_table_query(DB_TABLE_PLAYLIST, DB_LIST_PLAYLIST, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_make_table_query fail.");
- goto ERROR;
- }
-
- /* create album table*/
- ret = _media_svc_make_table_query(DB_TABLE_ALBUM, DB_LIST_ALBUM, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_make_table_query fail.");
- goto ERROR;
- }
-
- /*create tag_map table*/
- ret = _media_svc_make_table_query(DB_TABLE_TAG_MAP, DB_LIST_TAG_MAP, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_make_table_query fail.");
- goto ERROR;
- }
-
- /*create tag table*/
- ret = _media_svc_make_table_query(DB_TABLE_TAG, DB_LIST_TAG, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_make_table_query fail.");
- goto ERROR;
- }
-
- /*create bookmark table*/
- ret = _media_svc_make_table_query(DB_TABLE_BOOKMARK, DB_LIST_BOOKMARK, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_make_table_query fail.");
- goto ERROR;
- }
-
- /*create storage table from tizen 2.4 */
- ret = _media_svc_make_table_query(DB_TABLE_STORAGE, DB_LIST_STORAGE, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_make_table_query fail.");
- goto ERROR;
- }
-
- /*create face table. from tizen 3.0*/
- ret = _media_svc_make_table_query(DB_TABLE_FACE_SCAN_LIST, DB_LIST_FACE_SCAN_LIST, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_make_table_query fail.");
- goto ERROR;
- }
-
- ret = _media_svc_make_table_query(DB_TABLE_FACE, DB_LIST_FACE, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_make_table_query fail.");
- goto ERROR;
- }
-ERROR:
- _media_svc_destroy_table_query();
-
- media_svc_debug_fleave();
-
- return ret;
-}
-
-int media_svc_check_item_exist_by_path(sqlite3 *handle, const char *storage_id, const char *path)
-{
- return _media_svc_check_data_by_path(handle, path);
-}
-
-int media_svc_get_modified_time(sqlite3 *handle, const char *storage_id, const char *path, int *modified_time)
-{
- return _media_svc_get_modified_time(handle, path, modified_time);
-}
-
-int media_svc_insert_item_begin(bool with_noti, int from_pid)
-{
- g_media_svc_cur_data_cnt = 0;
-
- /* Prepare for making noti item list */
- if (with_noti) {
- media_svc_debug("making noti list from pid[%d]", from_pid);
- _media_svc_initialize_noti_list();
- _media_svc_set_noti_from_pid(from_pid);
- g_insert_with_noti = true;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int media_svc_insert_item_end(uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- media_svc_debug_fenter();
-
- if (g_media_svc_cur_data_cnt > 0) {
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
- if (g_insert_with_noti) {
- media_svc_debug("sending noti list");
- _media_svc_publish_noti_list();
- g_insert_with_noti = false;
- _media_svc_set_noti_from_pid(-1);
- }
- }
-
- g_media_svc_cur_data_cnt = 0;
-
- return ret;
-}
-
-int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- long long int folder_id = 0;
-
- media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- media_svc_content_info_s content_info = { 0, };
-
- /*Set media info*/
- ret = _media_svc_set_media_info(&content_info, storage_id, path, false);
- if (ret != MS_MEDIA_ERR_NONE)
- return ret;
-
- switch (content_info.media_type) {
- case MEDIA_SVC_MEDIA_TYPE_IMAGE:
- ret = _media_svc_extract_image_metadata(&content_info);
- break;
- case MEDIA_SVC_MEDIA_TYPE_VIDEO:
- _media_svc_extract_video_metadata(&content_info);
- break;
- case MEDIA_SVC_MEDIA_TYPE_SOUND:
- case MEDIA_SVC_MEDIA_TYPE_MUSIC:
- _media_svc_extract_audio_metadata(handle, true, &content_info, uid);
- break;
- case MEDIA_SVC_MEDIA_TYPE_BOOK:
- ret = _media_svc_extract_book_metadata(&content_info);
- break;
- default:
- /* The 'TITLE' should always be filled in */
- content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
- break;
- }
-
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- /*Set or Get folder id*/
- ret = _media_svc_get_and_append_folder_id_by_path(handle, true, storage_id, path, &folder_id, uid);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- content_info.folder_id = folder_id;
- media_svc_retv_del_if(content_info.folder_id <= 0, MS_MEDIA_ERR_INTERNAL, &content_info);
-
- ret = _media_svc_insert_item_stack(&content_info);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- if (g_insert_with_noti)
- _media_svc_insert_item_to_noti_list(&content_info);
-
- /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
- if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- if (g_insert_with_noti)
- _media_svc_publish_noti_list();
-
- g_media_svc_cur_data_cnt = 0;
- }
-
- _media_svc_destroy_content_info(&content_info);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- long long int folder_id = 0;
-
- media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- media_svc_content_info_s content_info = { 0, };
-
- /*Set media info*/
- ret = _media_svc_set_media_info(&content_info, storage_id, path, false);
- if (ret != MS_MEDIA_ERR_NONE)
- return ret;
-
- switch (content_info.media_type) {
- case MEDIA_SVC_MEDIA_TYPE_IMAGE:
- ret = _media_svc_extract_image_metadata(&content_info);
- break;
- case MEDIA_SVC_MEDIA_TYPE_VIDEO:
- _media_svc_extract_video_metadata(&content_info);
- break;
- case MEDIA_SVC_MEDIA_TYPE_SOUND:
- case MEDIA_SVC_MEDIA_TYPE_MUSIC:
- _media_svc_extract_audio_metadata(handle, false, &content_info, uid);
- break;
- case MEDIA_SVC_MEDIA_TYPE_BOOK:
- ret = _media_svc_extract_book_metadata(&content_info);
- break;
- default:
- /* The 'TITLE' should always be filled in */
- content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
- break;
- }
-
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- /*Set or Get folder id*/
- ret = _media_svc_get_and_append_folder_id_by_path(handle, false, storage_id, path, &folder_id, uid);
- media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
- content_info.folder_id = folder_id;
- media_svc_retv_del_if(content_info.folder_id <= 0, MS_MEDIA_ERR_INTERNAL, &content_info);
-
- /* Extracting thumbnail */
- if (content_info.thumbnail_path == NULL) {
- if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
- char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
-
- ret = _media_svc_create_thumbnail(content_info.path, thumb_path, content_info.media_type, uid);
- if (ret == MS_MEDIA_ERR_NONE)
- content_info.thumbnail_path = g_strdup(thumb_path);
- }
- }
-
- ret = _media_svc_insert_item(&content_info, uid);
- if (ret == MS_MEDIA_ERR_NONE) {
- media_svc_debug("Insertion is successful. Sending noti for this");
- _media_svc_publish_noti(MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
- } else if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
- media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
- }
-
- _media_svc_destroy_content_info(&content_info);
- return ret;
-}
-
-int media_svc_move_item(sqlite3 *handle,
- const char *src_path,
- const char *dest_path,
- const char *media_id,
- int media_type,
- const char *mime_type,
- uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *file_name = NULL;
- char *folder_path = NULL;
- int modified_time = 0;
- long long int folder_id = 0;
- char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
- char dst_stg_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
-
- media_svc_debug_fenter();
-
- media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- media_svc_retvm_if(!STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
- media_svc_retvm_if(!STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
- media_svc_retvm_if(!STRING_VALID(media_id), MS_MEDIA_ERR_INVALID_PARAMETER, "media_id is NULL");
- media_svc_retvm_if(!STRING_VALID(mime_type), MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is NULL");
-
- /* Get storage_id */
- ret = _media_svc_get_storage_uuid(handle, dest_path, dst_stg_id, uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- /*check and update folder*/
- ret = _media_svc_get_and_append_folder_id_by_path(handle, false, dst_stg_id, dest_path, &folder_id, uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- /*get filename*/
- file_name = g_path_get_basename(dest_path);
-
- /*get modified_time*/
- modified_time = _media_svc_get_file_time(dest_path);
-
- /*get old thumbnail_path and remove thumbnail */
- ret = _media_svc_get_thumbnail_path_by_path(handle, src_path, old_thumb_path);
- if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
- media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
- g_free(file_name);
- return ret;
- }
-
- _media_svc_remove_file(old_thumb_path);
-
- /*move item*/
- ret = _media_svc_update_item_by_path(src_path, dst_stg_id, dest_path, file_name, modified_time, folder_id, uid);
- g_free(file_name);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- media_svc_debug("Move is successful. Sending noti for this");
- _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, src_path, media_type, media_id, mime_type);
-
- /*update folder modified_time*/
- folder_path = g_path_get_dirname(dest_path);
- ret = _media_svc_update_folder_modified_time(folder_path, uid);
- g_free(folder_path);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int media_svc_set_item_validity(const char *path, int validity, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- ret = _media_svc_update_item_validity(path, validity, true, uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
- if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- g_media_svc_cur_data_cnt = 0;
- }
-
- return ret;
-}
-
-int media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
- media_svc_noti_item *noti_item = NULL;
-
- media_svc_debug_fenter();
-
- /*Get thumbnail path to delete*/
- ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
- media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
-
- /* Get notification info */
- ret = _media_svc_get_noti_info(handle, path, ¬i_item);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- /*Delete item*/
- ret = _media_svc_delete_item_by_path(path, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
- _media_svc_destroy_noti_item(noti_item);
-
- return ret;
- }
-
- /* Send notification */
- media_svc_debug("Deletion is successful. Sending noti for this");
- _media_svc_publish_noti(MS_MEDIA_ITEM_DELETE, path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
- _media_svc_destroy_noti_item(noti_item);
-
- /*Delete thumbnail*/
- _media_svc_remove_file(thumb_path);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
- media_svc_content_info_s content_info = {0, };
- media_svc_noti_item *noti_item = NULL;
-
- media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- /*Set media info*/
- ret = _media_svc_set_media_info(&content_info, NULL, path, true);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- /* Initialize thumbnail information to remake thumbnail. */
- ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
- if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD)
- goto REFRESH_FINALIZE;
-
- if (strlen(thumb_path) > 0) {
- _media_svc_remove_file(thumb_path);
-
- ret = _media_svc_update_thumbnail_path(path, NULL, uid);
- if (ret != MS_MEDIA_ERR_NONE)
- goto REFRESH_FINALIZE;
- }
-
- /* Get notification info */
- ret = _media_svc_get_noti_info(handle, path, ¬i_item);
- if (ret != MS_MEDIA_ERR_NONE)
- goto REFRESH_FINALIZE;
-
- content_info.media_type = noti_item->media_type;
- content_info.mime_type = g_strdup(noti_item->mime_type);
-
- switch (content_info.media_type) {
- case MEDIA_SVC_MEDIA_TYPE_IMAGE:
- ret = _media_svc_extract_image_metadata(&content_info);
- break;
- case MEDIA_SVC_MEDIA_TYPE_VIDEO:
- _media_svc_extract_video_metadata(&content_info);
- break;
- case MEDIA_SVC_MEDIA_TYPE_SOUND:
- case MEDIA_SVC_MEDIA_TYPE_MUSIC:
- _media_svc_extract_audio_metadata(handle, is_direct, &content_info, uid);
- break;
- case MEDIA_SVC_MEDIA_TYPE_BOOK:
- ret = _media_svc_extract_book_metadata(&content_info);
- break;
- default:
- /* The 'TITLE' should always be filled in */
- content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
- break;
- }
-
- if (ret != MS_MEDIA_ERR_NONE)
- goto REFRESH_FINALIZE;
-
- /* Extracting thumbnail */
- if (content_info.thumbnail_path == NULL) {
- if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
- memset(thumb_path, 0, sizeof(thumb_path));
-
- ret = _media_svc_create_thumbnail(content_info.path, thumb_path, content_info.media_type, uid);
- if (ret == MS_MEDIA_ERR_NONE)
- content_info.thumbnail_path = g_strdup(thumb_path);
- }
- }
-
- ret = _media_svc_update_item_with_data(is_direct, &content_info, uid);
-
- if (ret == MS_MEDIA_ERR_NONE) {
- if (is_direct) {
- /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
- if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
- if (ret != MS_MEDIA_ERR_NONE)
- goto REFRESH_FINALIZE;
-
- g_media_svc_cur_data_cnt = 0;
- }
- } else {
- /* Except scanner case */
- media_svc_debug("Update is successful. Sending noti for this");
- _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
- }
- } else {
- media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
- }
-
-REFRESH_FINALIZE:
- _media_svc_destroy_content_info(&content_info);
- _media_svc_destroy_noti_item(noti_item);
-
- return ret;
-}
-
-int media_svc_send_dir_update_noti(const char *dir_path, const char *folder_id, int update_type, int pid)
-{
- media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
-
- return _media_svc_publish_dir_noti((media_item_update_type_e)update_type, dir_path, folder_id, pid);
-}
-
-int media_svc_publish_update_noti(const char *path, int media_type, const char *uuid, const char *mime_type)
-{
- return _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, path, media_type, uuid, mime_type);
-}
-
-int media_svc_set_storage_validity(const char *storage_id, int validity, uid_t uid)
-{
- return _media_svc_update_storage_validity(storage_id, validity, uid);
-}
-
-int media_svc_get_storage_id(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
-{
- return _media_svc_get_storage_uuid(handle, path, storage_id, uid);
-}
-
-int media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity)
-{
- return _media_svc_check_storage(handle, storage_id, storage_path, validity);
-}
-
-int media_svc_update_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
-{
- return _media_svc_update_storage_path(handle, storage_id, storage_path, uid);
-}
-
-int media_svc_insert_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
- media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
-
- ret = _media_svc_append_storage(storage_id, storage_path, uid);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
-
- /* Remove external storage that validity is 0 */
- ret = _media_svc_delete_invalid_storage(handle, uid);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Delete invalid storage failed : %d", ret);
-
- return ret;
-}
-
-int media_svc_insert_folder(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
-{
- media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- return _media_svc_append_by_folder_path(handle, storage_id, path, uid);
-}
-
-int media_svc_set_folder_validity(const char *start_path, int validity, bool is_recursive, uid_t uid)
-{
- return _media_svc_set_folder_validity(true, start_path, validity, is_recursive, uid);
-}
-
-int media_svc_check_folder_exist_by_path(sqlite3 *handle, const char *folder_path)
-{
- return _media_svc_check_folder_by_path(handle, folder_path);
-}
-
-int media_svc_append_query(const char *query, uid_t uid)
-{
- return _media_svc_append_query_list(query, uid);
-}
-
-int media_svc_send_query(uid_t uid)
-{
- return _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
-}
-
-int media_svc_get_media_type(const char *path, int *mediatype)
-{
- return _media_svc_get_media_type(path, mediatype);
-}
-
-int media_svc_create_thumbnail(const char *file_path, int media_type, uid_t uid, char **thumbnail_path)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = { 0, };
- char *sql = NULL;
-
- // 1. Check media type
- if (media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE && media_type != MEDIA_SVC_MEDIA_TYPE_VIDEO)
- return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
-
- // 2. try to create thumbnail
- ret = _media_svc_create_thumbnail(file_path, thumb_path, media_type, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("Failed to create thumbnail [%d]", ret);
- if (ret == MS_MEDIA_ERR_THUMB_UNSUPPORTED)
- return ret;
- }
-
- // 3. Update creation result to media db
- sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path='%q' WHERE media_path='%q';", DB_TABLE_MEDIA, thumb_path, file_path);
-
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("Failed to update media db [%d]", ret);
- *thumbnail_path = g_strdup("");
- } else {
- *thumbnail_path = g_strdup(thumb_path);
- }
-
- return ret;
-}
-
-static int __media_svc_get_ebook_search_type(void)
-{
- dictionary *dict = NULL;
- static int _ebook_search_type = -1;
-
- if (_ebook_search_type == -1) {
- dict = iniparser_load(CONTENT_INI_DEFAULT_PATH);
- if (!dict) {
- media_svc_error("%s load failed. Use direct search.", CONTENT_INI_DEFAULT_PATH);
- return MEDIA_SVC_SEARCH_TYPE_DIRECT;
- }
-
- _ebook_search_type = iniparser_getint(dict, "media-content-config:ebook_search_type", 0);
- media_svc_debug("ebook_search_type [%d]", _ebook_search_type);
-
- iniparser_freedict(dict);
- }
-
- return _ebook_search_type;
-}
-
-int media_svc_get_book_by_keyword(sqlite3 *handle, const char *keyword, uid_t uid, GList **result)
-{
- int ret = MS_MEDIA_ERR_NONE;
- GList *item_list = NULL;
- GList *iter = NULL;
- char *query = NULL;
-
- media_svc_retvm_if(!handle, MS_MEDIA_ERR_INVALID_PARAMETER, "db handle is NULL");
- media_svc_retvm_if(!keyword, MS_MEDIA_ERR_INVALID_PARAMETER, "keyword is NULL");
- media_svc_retvm_if(!result, MS_MEDIA_ERR_INVALID_PARAMETER, "result is NULL");
-
- query = sqlite3_mprintf("SELECT media_path FROM %q WHERE media_type=%d AND validity=1;",
- DB_TABLE_MEDIA, MEDIA_SVC_MEDIA_TYPE_BOOK);
-
- ret = _media_svc_get_media(handle, query, &item_list);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_media failed");
-
- if (__media_svc_get_ebook_search_type() == MEDIA_SVC_SEARCH_TYPE_DB) {
- for (iter = item_list; iter; iter = g_list_next(iter))
- _media_svc_update_wordbook((char *)iter->data, uid);
-
- _media_svc_clean_wordbook(uid);
-
- if (!_media_svc_get_matched_list(keyword, uid, result))
- media_svc_error("_media_svc_get_matched_list failed");
- } else {
- for (iter = item_list; iter; iter = g_list_next(iter)) {
- if (_media_svc_is_keyword_included((char *)iter->data, keyword))
- *result = g_list_append(*result, g_strdup((gchar *)iter->data));
- }
- }
-
- g_list_free_full(item_list, g_free);
-
- return ret;
-}
-
-int media_svc_check_db(sqlite3 *handle, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- bool exist = false;
-
- ret = media_svc_check_table_exist(handle, &exist);
- if (ret != MS_MEDIA_ERR_NONE)
- return ret;
-
- if (!exist)
- ret = media_svc_create_table(uid);
-
- return ret;
-}
\ No newline at end of file
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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.
- *
- */
-
-#ifndef _MEDIA_SVC_ALBUM_H_
-#define _MEDIA_SVC_ALBUM_H_
-
-#include <sqlite3.h>
-#include <sys/types.h>
-#include <stdbool.h>
-
-int _media_svc_get_album_id(sqlite3 *handle, const char *album, const char *artist, int *album_id);
-int _media_svc_append_album(sqlite3 *handle, bool is_direct, const char *album, const char *artist, const char *album_art, int *album_id, uid_t uid);
-
-#endif /*_MEDIA_SVC_ALBUM_H_*/
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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.
- *
- */
-
-
-#ifndef _MEDIA_SVC_DB_UTILS_H_
-#define _MEDIA_SVC_DB_UTILS_H_
-
-#include <stdbool.h>
-#include <sqlite3.h>
-#include <glib.h>
-#include "media-svc-env.h"
-
-#define SQLITE3_FINALIZE(x) if (x != NULL) sqlite3_finalize(x);
-#define SQLITE3_SAFE_FREE(x) {if (x != NULL) {sqlite3_free(x); x = NULL; } }
-
-int _media_svc_make_table_query(const char *table_name, media_svc_table_slist_e list, uid_t uid);
-int _media_svc_init_table_query(void);
-void _media_svc_destroy_table_query(void);
-int _media_svc_sql_query(const char *sql_str, uid_t uid);
-int _media_svc_sql_query_direct(const char *sql_str, uid_t uid);
-int _media_svc_check_table_exist(sqlite3 *db_handle, bool *exist);
-int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt);
-int _media_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt);
-int _media_svc_sql_query_list(GList **query_list, uid_t uid);
-int _media_svc_sql_query_list_direct(GList **query_list, uid_t uid);
-void _media_svc_sql_query_add(GList **query_list, char **query);
-void _media_svc_sql_query_release(GList **query_list);
-
-#endif /*_MEDIA_SVC_DB_UTILS_H_*/
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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.
- *
- */
-
-
-
-#ifndef _MEDIA_SVC_DEBUG_H_
-#define _MEDIA_SVC_DEBUG_H_
-
-#include <dlog.h>
-#include <errno.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "MEDIA_SERVICE"
-
-#define FONT_COLOR_RESET "\033[0m"
-#define FONT_COLOR_RED "\033[31m"
-#define FONT_COLOR_GREEN "\033[32m"
-#define FONT_COLOR_YELLOW "\033[33m"
-#define FONT_COLOR_BLUE "\033[34m"
-#define FONT_COLOR_PURPLE "\033[35m"
-#define FONT_COLOR_CYAN "\033[36m"
-#define FONT_COLOR_GRAY "\033[37m"
-
-#define media_svc_debug(fmt, arg...) do { \
- LOGD(FONT_COLOR_RESET"" fmt "", ##arg); \
- } while (0)
-
-#define media_svc_error(fmt, arg...) do { \
- LOGE(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET, ##arg); \
- } while (0)
-
-#define media_svc_debug_fenter() do { \
- LOGD(FONT_COLOR_YELLOW"<ENTER>" FONT_COLOR_RESET); \
- } while (0)
-
-#define media_svc_debug_fleave() do { \
- LOGD(FONT_COLOR_YELLOW"<LEAVE>" FONT_COLOR_RESET); \
- } while (0)
-
-#define media_svc_retm_if(expr, fmt, arg...) do { \
- if (expr) { \
- LOGE(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET, ##arg); \
- return; \
- } \
- } while (0)
-#define media_svc_retv_if(expr, val) do { \
- if (expr) { \
- LOGE(FONT_COLOR_RED"" FONT_COLOR_RESET); \
- return (val); \
- } \
- } while (0)
-#define media_svc_retvm_if(expr, val, fmt, arg...) do { \
- if (expr) { \
- LOGE(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET, ##arg); \
- return (val); \
- } \
- } while (0)
-
-#define media_svc_retv_del_if(expr, val, p_str) do { \
- if (expr) { \
- LOGE(FONT_COLOR_RED"" FONT_COLOR_RESET); \
- _media_svc_destroy_content_info(p_str); \
- return (val); \
- } \
- } while (0)
-
-#define media_svc_sec_debug(fmt, arg...) do { \
- SECURE_LOGI(FONT_COLOR_GREEN"" fmt "" FONT_COLOR_RESET, ##arg); \
- } while (0)
-
-#define media_svc_sec_warn(fmt, arg...) do { \
- SECURE_LOGW(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET, ##arg); \
- } while (0)
-
-#define media_svc_sec_error(fmt, arg...) do { \
- SECURE_LOGE(FONT_COLOR_RED"" fmt "" FONT_COLOR_RESET, ##arg); \
- } while (0)
-
-#define ERR_BUF_LENGHT 256
-#define media_svc_stderror(fmt) do { \
- char media_svc_stderror_buf[ERR_BUF_LENGHT] = {0,}; \
- strerror_r(errno, media_svc_stderror_buf, ERR_BUF_LENGHT); \
- LOGE(FONT_COLOR_RED""fmt" : standard error= [%s]", media_svc_stderror_buf); \
- } while (0)
-
-#endif /*_MEDIA_SVC_DEBUG_H_*/
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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.
- *
- */
-
-
-
-#ifndef _MEDIA_SVC_ENV_H_
-#define _MEDIA_SVC_ENV_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * DB table information
- */
-
-/**
- * Table Name
- */
-#define DB_TABLE_MEDIA "media" /**< media table*/
-#define DB_TABLE_FOLDER "folder" /**< media_folder table*/
-#define DB_TABLE_PLAYLIST "playlist" /**< playlist table*/
-#define DB_TABLE_PLAYLIST_MAP "playlist_map" /**< playlist_map table*/
-#define DB_TABLE_ALBUM "album" /**< album table*/
-#define DB_TABLE_TAG "tag" /**< tag table*/
-#define DB_TABLE_TAG_MAP "tag_map" /**< tag_map table*/
-#define DB_TABLE_BOOKMARK "bookmark" /**< bookmark table*/
-#define DB_TABLE_STORAGE "storage" /**< storage table*/
-#define DB_TABLE_FACE "face" /**< face table*/
-#define DB_TABLE_FACE_SCAN_LIST "face_scan_list" /**< face_scan_list table*/
-
-/**
- * View Name
- */
-#define DB_VIEW_PLAYLIST "playlist_view" /**< playlist_view*/
-#define DB_VIEW_TAG "tag_view" /**< tag_view*/
-
-/**
- * Trigger Name
- */
-#define DB_TRIGGER_PLAYLIST_MAP "playlist_map_cleanup" /**< media to map*/
-#define DB_TRIGGER_PLAYLIST_MAP1 "playlist_map_cleanup_1" /**< playlist to map*/
-#define DB_TRIGGER_ALBUM "album_cleanup"
-#define DB_TRIGGER_TAG_MAP "tag_map_cleanup" /**< media to map*/
-#define DB_TRIGGER_TAG_MAP1 "tag_map_cleanup_1" /**< tag to map*/
-#define DB_TRIGGER_BOOKMARK "bookmark_cleanup"
-#define DB_TRIGGER_FACE_SCAN_LIST "face_scan_list_cleanup"
-#define DB_TRIGGER_FACE "face_cleanup"
-
-/**
- * Column Name for view
- */
-#define DB_COLUMN_THUMBNAIL "thumbnail_path"
-#define DB_COLUMN_MAP_ID "_id"
-
-
-/**
- * option
- */
-#define DB_TYPE_TEXT "TEXT"
-#define DB_TYPE_INT "INTEGER"
-#define DB_TYPE_DOUBLE "DOUBLE"
-
-/**
- * Query form
- */
-#define DB_QUERY_TABLE_WITH_UNIQUE "CREATE TABLE IF NOT EXISTS '%s' (%s, unique(%s));"
-#define DB_QUERY_TABLE "CREATE TABLE IF NOT EXISTS '%s' (%s);"
-#define DB_QUERY_TRIGGER "CREATE TRIGGER IF NOT EXISTS '%s' DELETE ON '%s' BEGIN DELETE FROM %s WHERE %s=old.%s;END;"
-#define DB_QUERY_TRIGGER_WITH_COUNT "CREATE TRIGGER IF NOT EXISTS '%s' DELETE ON '%s' BEGIN DELETE FROM %s WHERE (SELECT count(*) FROM '%s' WHERE %s=old.%s)=1 AND %s=old.%s;END;"
-#define DB_QUERY_VIEW_PLAYLIST "CREATE VIEW IF NOT EXISTS %s AS SELECT %s FROM playlist \
- LEFT OUTER JOIN playlist_map ON playlist.playlist_id = playlist_map.playlist_id \
- LEFT OUTER JOIN media ON (playlist_map.media_id = media.media_id AND media.validity=1) \
- LEFT OUTER JOIN (SELECT count(playlist_id) as playlist_media_count, playlist_id FROM playlist_map group by playlist_id) as cnt_tbl ON (cnt_tbl.playlist_id=playlist_map.playlist_id AND media.validity=1);"
-#define DB_QUERY_VIEW_TAG "CREATE VIEW IF NOT EXISTS %s AS SELECT %s FROM tag \
- LEFT OUTER JOIN tag_map ON tag.tag_id=tag_map.tag_id \
- LEFT OUTER JOIN media ON (tag_map.media_id = media.media_id AND media.validity=1) \
- LEFT OUTER JOIN (SELECT count(tag_id) as tag_media_count, tag_id FROM tag_map group by tag_id) as cnt_tbl ON (cnt_tbl.tag_id=tag_map.tag_id AND media.validity=1);"
-
-
-#define MEDIA_SVC_METADATA_LEN_MAX 512 /**< Length of metadata*/
-#define MEDIA_SVC_PATHNAME_SIZE 4096 /**< Length of Path name. */
-#define MEDIA_SVC_UUID_SIZE 36 /**< Length of UUID*/
-
-#define MEDIA_SVC_TAG_UNKNOWN ""
-
-typedef enum {
- MEDIA_SVC_QUERY_SCANNER,
- MEDIA_SVC_QUERY_UPDATE_COMMON,
-} media_svc_query_type_e;
-
-typedef enum {
- DB_LIST_MEDIA = 0,
- DB_LIST_FOLDER,
- DB_LIST_PLAYLIST_MAP,
- DB_LIST_PLAYLIST,
- DB_LIST_ALBUM,
- DB_LIST_TAG_MAP,
- DB_LIST_TAG,
- DB_LIST_BOOKMARK,
- DB_LIST_STORAGE,
- DB_LIST_FACE_SCAN_LIST,
- DB_LIST_FACE,
- DB_LIST_MAX,
-} media_svc_table_slist_e;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_MEDIA_SVC_ENV_H_*/
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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.
- *
- */
-
-#ifndef _MEDIA_SVC_MEDIA_FOLDER_H_
-#define _MEDIA_SVC_MEDIA_FOLDER_H_
-
-#include <sqlite3.h>
-#include <stdbool.h>
-
-int _media_svc_update_folder_modified_time(const char *folder_path, uid_t uid);
-int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, long long int *folder_id, uid_t uid);
-int _media_svc_append_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid);
-int _media_svc_set_folder_validity(bool is_direct, const char *start_path, int validity, bool is_recursive, uid_t uid);
-int _media_svc_check_folder_by_path(sqlite3 *handle, const char *path);
-
-#endif /*_MEDIA_SVC_MEDIA_FOLDER_H_*/
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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.
- *
- */
-
-#ifndef _MEDIA_SVC_MEDIA_H_
-#define _MEDIA_SVC_MEDIA_H_
-
-#include <sqlite3.h>
-#include <stdbool.h>
-#include "media-svc-noti.h"
-#include "media-svc-env.h"
-
-int _media_svc_check_data_by_path(sqlite3 *handle, const char *path);
-int _media_svc_get_modified_time(sqlite3 *handle, const char *path, int *modified_time);
-int _media_svc_insert_item_stack(media_svc_content_info_s *content_info);
-int _media_svc_insert_item(media_svc_content_info_s *content_info, uid_t uid);
-int _media_svc_update_item_with_data(bool is_direct, media_svc_content_info_s *content_info, uid_t uid);
-int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path);
-int _media_svc_delete_item_by_path(const char *path, uid_t uid);
-int _media_svc_update_item_validity(const char *path, int validity, bool stack_query, uid_t uid);
-int _media_svc_update_item_by_path(const char *src_path, const char *dst_storage_id, const char *dest_path, const char *file_name, int modified_time, long long int folder_id, uid_t uid);
-int _media_svc_list_query_do(media_svc_query_type_e query_type, uid_t uid);
-int _media_svc_update_thumbnail_path(const char *path, const char *thumb_path, uid_t uid);
-int _media_svc_get_noti_info(sqlite3 *handle, const char *path, media_svc_noti_item **item);
-
-int _media_svc_append_query_list(const char *query, uid_t uid);
-int _media_svc_get_media(sqlite3 *handle, const char *sql, GList **path_list);
-
-#endif /*_MEDIA_SVC_MEDIA_H_*/
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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.
- *
- */
-
-#ifndef _MEDIA_SVC_NOTI_H_
-#define _MEDIA_SVC_NOTI_H_
-
-#include <media-util-noti.h>
-#include "media-svc-util.h"
-
-typedef struct _media_svc_noti_item media_svc_noti_item;
-
-struct _media_svc_noti_item {
- int pid;
- media_item_type_e update_item;
- media_item_update_type_e update_type;
- int media_type;
- char *media_uuid;
- char *path;
- char *mime_type;
-};
-
-void _media_svc_set_noti_from_pid(int pid);
-void _media_svc_initialize_noti_list(void);
-void _media_svc_insert_item_to_noti_list(media_svc_content_info_s *content_info);
-void _media_svc_publish_noti_list(void);
-void _media_svc_destroy_noti_item(media_svc_noti_item *item);
-int _media_svc_publish_noti(media_item_update_type_e update_type, const char *path, int media_type, const char *uuid, const char *mime_type);
-int _media_svc_publish_dir_noti(media_item_update_type_e update_type, const char *path, const char *uuid, int pid);
-
-#endif /*_MEDIA_SVC_NOTI_H_*/
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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.
- *
- */
-
-#ifndef _MEDIA_SVC_STORAGE_H_
-#define _MEDIA_SVC_STORAGE_H_
-
-#include <sqlite3.h>
-
-int _media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity);
-int _media_svc_append_storage(const char *storage_id, const char *storage_path, uid_t uid);
-int _media_svc_update_storage_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid);
-int _media_svc_delete_invalid_storage(sqlite3 *handle, uid_t uid);
-int _media_svc_update_storage_validity(const char *storage_id, int validity, uid_t uid);
-int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage_id, uid_t uid);
-
-#endif /*_MEDIA_SVC_STORAGE_H_*/
+++ /dev/null
-/*
- * libmedia-service
- *
- * Copyright (c) 2000 - 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.
- *
- */
-
-
-
-#ifndef _MEDIA_SVC_UTIL_H_
-#define _MEDIA_SVC_UTIL_H_
-
-#include <string.h>
-#include <stdbool.h>
-#include <sys/types.h>
-#include <sqlite3.h>
-#include <time.h>
-#include <glib.h>
-#include <media-util-err.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define STRING_VALID(str) (str && strlen(str) > 0)
-
-/**
- * Media meta data information
- */
-typedef struct {
- char *title; /**< track title*/
- char *album; /**< album name*/
- char *artist; /**< artist name*/
- char *album_artist; /**< artist name*/
- char *genre; /**< genre of track*/
- char *year; /**< year*/
- char *track_num; /**< track number*/
- unsigned int width; /**< width*/
- unsigned int height; /**< height*/
- char *datetaken; /**< datetaken*/
- unsigned short orientation; /**< orientation*/
-} media_svc_content_meta_s;
-
-/**
- * Media data information
- */
-typedef struct {
- char *media_uuid; /**< Unique ID of item */
- char *path; /**< Full path of media file */
- char *file_name; /**< File name of media file. Display name */
- int media_type; /**< Type of media file : internal/external */
- char *mime_type; /**< Full path and file name of media file */
- unsigned long long size; /**< size */
- time_t modified_time; /**< modified time, time_t */
- long long int folder_id; /**< Unique ID of folder */
- int album_id; /**< Unique ID of album */
- char *thumbnail_path; /**< Thumbnail image file path */
- char *storage_uuid; /**< Unique ID of storage */
- media_svc_content_meta_s media_meta; /**< meta data structure */
-} media_svc_content_info_s;
-
-/**
- * Type definition for content type
- */
-typedef enum {
- MEDIA_SVC_MEDIA_TYPE_IMAGE = 0, /**< Image Content*/
- MEDIA_SVC_MEDIA_TYPE_VIDEO = 1, /**< Video Content*/
- MEDIA_SVC_MEDIA_TYPE_SOUND = 2, /**< Sound Content like Ringtone*/
- MEDIA_SVC_MEDIA_TYPE_MUSIC = 3, /**< Music Content like mp3*/
- MEDIA_SVC_MEDIA_TYPE_OTHER = 4, /**< Not media Content*/
- MEDIA_SVC_MEDIA_TYPE_BOOK = 5, /**< Book Content like epub*/
-} media_svc_media_type_e;
-
-typedef enum {
- MEDIA_SVC_SEARCH_TYPE_DIRECT = 0,
- MEDIA_SVC_SEARCH_TYPE_DB,
-} media_svc_search_type_e;
-
-void _media_svc_remove_file(const char *path);
-int _media_svc_get_file_time(const char *full_path);
-char * _media_svc_get_title_from_filename(const char *filename);
-int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, const char *path, bool refresh);
-int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info);
-void _media_svc_extract_audio_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid);
-void _media_svc_extract_video_metadata(media_svc_content_info_s *content_info);
-int _media_svc_extract_book_metadata(media_svc_content_info_s *content_info);
-void _media_svc_destroy_content_info(media_svc_content_info_s *content_info);
-int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid);
-int _media_svc_get_media_type(const char *path, int *mediatype);
-bool _media_svc_is_keyword_included(const char *path, const char *keyword);
-void _media_svc_update_wordbook(const char *path, uid_t uid);
-void _media_svc_clean_wordbook(uid_t uid);
-bool _media_svc_get_matched_list(const char *keyword, uid_t uid, GList **list);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_MEDIA_SVC_UTIL_H_*/
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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 "media-svc-album.h"
+#include "media-svc-debug.h"
+#include "media-svc-env.h"
+#include "media-svc-util.h"
+#include "media-svc-db-utils.h"
+
+int _media_svc_get_album_id(sqlite3 *handle, const char *album, const char *artist, int *album_id)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+
+ media_svc_retvm_if(!album, MS_MEDIA_ERR_INVALID_PARAMETER, "album is NULL");
+ media_svc_retvm_if(!artist, MS_MEDIA_ERR_INVALID_PARAMETER, "artist is NULL");
+
+ sql = sqlite3_mprintf("SELECT album_id FROM %s WHERE name=%Q AND artist=%Q", DB_TABLE_ALBUM, album, artist);
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
+ media_svc_debug("there is no album.");
+ else
+ media_svc_error("failed to get album id[%d]", ret);
+
+ return ret;
+ }
+
+ *album_id = sqlite3_column_int(sql_stmt, 0);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return ret;
+}
+
+int _media_svc_append_album(sqlite3 *handle, bool is_direct, const char *album, const char *artist, const char *album_art, int *album_id, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ char *sql = sqlite3_mprintf("INSERT INTO %s(name, artist, album_art) VALUES (%Q, %Q, %Q);", DB_TABLE_ALBUM, album, artist, album_art);
+ if (is_direct)
+ ret = _media_svc_sql_query_direct(sql, uid);
+ else
+ ret = _media_svc_sql_query(sql, uid);
+
+ SQLITE3_SAFE_FREE(sql);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ int inserted_album_id = 0;
+ ret = _media_svc_get_album_id(handle, album, artist, &inserted_album_id);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ *album_id = inserted_album_id;
+
+ return MS_MEDIA_ERR_NONE;
+}
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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 <unistd.h>
+#include <media-util-db.h>
+#include <errno.h>
+
+#include "media-svc-env.h"
+#include "media-svc-debug.h"
+#include "media-svc-util.h"
+#include "media-svc-db-utils.h"
+#include "media-svc-media.h"
+
+static GHashTable *table;
+static GSList *column_list[DB_LIST_MAX];
+
+typedef struct {
+ char *trigger_name;
+ char *view_name;
+ char *event_table;
+ char *action_table;
+} table_info_s;
+
+typedef struct {
+ char *name;
+ char *type;
+ char *option;
+ bool is_unique;
+ bool is_trigger;
+ bool is_view;
+} column_info_s;
+
+static void __add_table_info(const char *name,
+ const char *trigger_name,
+ const char *event_table,
+ const char *action_table,
+ const char *view_name)
+{
+ table_info_s *tbl = NULL;
+
+ if (!name)
+ return;
+
+ if (trigger_name) {
+ if(!event_table || !action_table)
+ return;
+ }
+
+ tbl = g_new0(table_info_s, 1);
+
+ if (trigger_name) {
+ tbl->trigger_name = g_strdup(trigger_name);
+ tbl->event_table = g_strdup(event_table);
+ tbl->action_table = g_strdup(action_table);
+ }
+
+ if (view_name)
+ tbl->view_name = g_strdup(view_name);
+
+ g_hash_table_insert(table, (gpointer)name, (gpointer)tbl);
+}
+
+static void __add_column_info(GSList **slist,
+ const char *name,
+ const char *type,
+ const char *option,
+ bool is_unique,
+ bool is_trigger,
+ bool is_view)
+{
+ column_info_s *col = g_new0(column_info_s, 1);
+
+ col->name = g_strdup(name);
+ col->type = g_strdup(type);
+ col->option = g_strdup(option);
+
+ col->is_unique = is_unique;
+ col->is_trigger = is_trigger;
+ col->is_view = is_view;
+
+ *slist = g_slist_append(*slist, col);
+}
+
+static int __create_playlist_view(uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ GSList *iter = NULL;
+ column_info_s *col_ptr = NULL;
+ char *sql = NULL;
+ GString *table_query = g_string_new(NULL);
+ media_svc_retvm_if(!table_query, MS_MEDIA_ERR_INTERNAL, "g_string_new failed");
+
+ for (iter = column_list[DB_LIST_PLAYLIST]; iter; iter = g_slist_next(iter)) {
+ col_ptr = iter->data;
+
+ if (!col_ptr)
+ continue;
+
+ if (col_ptr->is_view) {
+ if (table_query->len != 0) {
+ if (strncmp(col_ptr->name, DB_COLUMN_THUMBNAIL, strlen(DB_COLUMN_THUMBNAIL)) == 0)
+ g_string_append_printf(table_query, ", playlist.%s AS p_thumbnail_path", col_ptr->name);
+ else
+ g_string_append_printf(table_query, ", playlist.%s", col_ptr->name);
+ } else {
+ g_string_append_printf(table_query, "playlist.%s", col_ptr->name);
+ }
+ }
+ }
+
+ for (iter = column_list[DB_LIST_PLAYLIST_MAP]; iter; iter = g_slist_next(iter)) {
+ col_ptr = iter->data;
+
+ if (!col_ptr)
+ continue;
+
+ if (col_ptr->is_view) {
+ if (strncmp(col_ptr->name, DB_COLUMN_MAP_ID, strlen(DB_COLUMN_MAP_ID)) == 0)
+ g_string_append_printf(table_query, ", playlist_media_count IS NOT NULL AS playlist_media_count, playlist_map.%s AS pm_id", col_ptr->name);
+ else
+ g_string_append_printf(table_query, ", playlist_map.%s", col_ptr->name);
+ }
+ }
+
+ for (iter = column_list[DB_LIST_MEDIA]; iter; iter = g_slist_next(iter)) {
+ col_ptr = iter->data;
+
+ if (!col_ptr)
+ continue;
+
+ if (col_ptr->is_view)
+ g_string_append_printf(table_query, ", media.%s", col_ptr->name);
+ }
+
+ sql = sqlite3_mprintf(DB_QUERY_VIEW_PLAYLIST, DB_VIEW_PLAYLIST, table_query->str);
+ g_string_free(table_query, TRUE);
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+
+ return ret;
+}
+
+static int __create_tag_view(uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ GSList *iter = NULL;
+ column_info_s *col_ptr = NULL;
+ char *sql = NULL;
+ GString *table_query = g_string_new(NULL);
+ media_svc_retvm_if(!table_query, MS_MEDIA_ERR_INTERNAL, "g_string_new failed");
+
+ for (iter = column_list[DB_LIST_TAG]; iter; iter = g_slist_next(iter)) {
+ col_ptr = iter->data;
+
+ if (!col_ptr)
+ continue;
+
+ if (col_ptr->is_view) {
+ if (table_query->len != 0)
+ g_string_append_printf(table_query, ", tag.%s", col_ptr->name);
+ else
+ g_string_append_printf(table_query, "tag.%s", col_ptr->name);
+ }
+ }
+
+ for (iter = column_list[DB_LIST_TAG_MAP]; iter; iter = g_slist_next(iter)) {
+ col_ptr = iter->data;
+
+ if (!col_ptr)
+ continue;
+
+ if (col_ptr->is_view) {
+ if (strncmp(col_ptr->name, DB_COLUMN_MAP_ID, strlen(DB_COLUMN_MAP_ID)) == 0)
+ g_string_append_printf(table_query, ", tag_media_count IS NOT NULL AS tag_media_count, tag_map.%s AS tm_id", col_ptr->name);
+ else
+ g_string_append_printf(table_query, ", tag_map.%s", col_ptr->name);
+ }
+ }
+
+ for (iter = column_list[DB_LIST_MEDIA]; iter; iter = g_slist_next(iter)) {
+ col_ptr = iter->data;
+
+ if (!col_ptr)
+ continue;
+
+ if (col_ptr->is_view)
+ g_string_append_printf(table_query, ", media.%s", col_ptr->name);
+ }
+
+ sql = sqlite3_mprintf(DB_QUERY_VIEW_TAG, DB_VIEW_TAG, table_query->str);
+ g_string_free(table_query, TRUE);
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+
+ return ret;
+}
+
+int _media_svc_make_table_query(const char *table_name, media_svc_table_slist_e list, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ GSList *iter = NULL;
+ table_info_s *tb = NULL;
+ column_info_s *col_ptr = NULL;
+ char *sql = NULL;
+ GString *table_query = g_string_new(NULL);
+ GString *trigger_query = g_string_new(NULL);
+ GString *unique_query = g_string_new(NULL);
+
+ if (!table_query || !trigger_query || !unique_query) {
+ media_svc_error("g_string_new failed");
+ ret = MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
+ }
+
+ tb = g_hash_table_lookup(table, table_name);
+ if (tb == NULL) {
+ media_svc_debug("lookup fail.. table name [%s] ", table_name);
+ ret = MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
+ }
+
+ for (iter = column_list[list]; iter; iter = g_slist_next(iter)) {
+ col_ptr = iter->data;
+ if (!col_ptr)
+ continue;
+
+ /*create table */
+ if (col_ptr->option) {
+ if (table_query->len != 0)
+ g_string_append_printf(table_query, ", %s %s %s", col_ptr->name, col_ptr->type, col_ptr->option);
+ else
+ g_string_append_printf(table_query, "%s %s %s", col_ptr->name, col_ptr->type, col_ptr->option);
+ } else {
+ if (table_query->len != 0)
+ g_string_append_printf(table_query, ", %s %s", col_ptr->name, col_ptr->type);
+ else
+ g_string_append_printf(table_query, "%s %s", col_ptr->name, col_ptr->type);
+ }
+
+ /*unique */
+ if (col_ptr->is_unique) {
+ if (unique_query->len != 0)
+ g_string_append_printf(unique_query, ", %s", col_ptr->name);
+ else
+ g_string_append_printf(unique_query, "%s", col_ptr->name);
+ }
+
+ /*create trigger */
+ if (col_ptr->is_trigger) {
+ if (tb->trigger_name) {
+ if (strncmp(table_name, DB_TABLE_ALBUM, strlen(DB_TABLE_ALBUM)) == 0) {
+ g_string_append_printf(trigger_query, DB_QUERY_TRIGGER_WITH_COUNT,
+ tb->trigger_name, tb->event_table, tb->action_table, tb->event_table,
+ col_ptr->name, col_ptr->name, col_ptr->name, col_ptr->name);
+ } else {
+ g_string_append_printf(trigger_query, DB_QUERY_TRIGGER,
+ tb->trigger_name, tb->event_table, tb->action_table,
+ col_ptr->name, col_ptr->name);
+ }
+ } else {
+ media_svc_error("invalid trigger name");
+ }
+ }
+ }
+
+ /*send queries */
+ if (unique_query->len > 0)
+ sql = sqlite3_mprintf(DB_QUERY_TABLE_WITH_UNIQUE, table_name, table_query->str, unique_query->str);
+ else
+ sql = sqlite3_mprintf(DB_QUERY_TABLE, table_name, table_query->str);
+
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ if (ret != MS_MEDIA_ERR_NONE)
+ goto ERROR;
+
+ if (trigger_query->len > 0) {
+ ret = _media_svc_sql_query(trigger_query->str, uid);
+ if (ret != MS_MEDIA_ERR_NONE)
+ goto ERROR;
+ }
+
+ /*create view */
+ if (strncmp(table_name, DB_TABLE_PLAYLIST, strlen(DB_TABLE_PLAYLIST)) == 0)
+ ret = __create_playlist_view(uid);
+ else if (strncmp(table_name, DB_TABLE_TAG, strlen(DB_TABLE_TAG)) == 0)
+ ret = __create_tag_view(uid);
+
+ERROR:
+ if (trigger_query)
+ g_string_free(trigger_query, TRUE);
+ if (unique_query)
+ g_string_free(unique_query, TRUE);
+ if (table_query)
+ g_string_free(table_query, TRUE);
+
+ return ret;
+}
+
+static void __media_svc_table_free(gpointer data)
+{
+ table_info_s *tb = (table_info_s *) data;
+
+ g_free(tb->trigger_name);
+ g_free(tb->view_name);
+ g_free(tb->event_table);
+ g_free(tb->action_table);
+ g_free(tb);
+}
+
+static void __media_svc_column_free(gpointer data)
+{
+ column_info_s *col = (column_info_s *) data;
+
+ g_free(col->name);
+ g_free(col->type);
+ g_free(col->option);
+ g_free(col);
+}
+
+int _media_svc_init_table_query(void)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ /*variable initialize.. */
+ table = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, __media_svc_table_free);
+
+ /*table specification.. (table_name, trigger name, event table, action table, view name) */
+ __add_table_info(DB_TABLE_MEDIA, NULL, NULL, NULL, NULL);
+ __add_table_info(DB_TABLE_FOLDER, NULL, NULL, NULL, NULL);
+ __add_table_info(DB_TABLE_PLAYLIST_MAP, DB_TRIGGER_PLAYLIST_MAP, DB_TABLE_MEDIA, DB_TABLE_PLAYLIST_MAP, NULL);
+ __add_table_info(DB_TABLE_PLAYLIST, DB_TRIGGER_PLAYLIST_MAP1, DB_TABLE_PLAYLIST, DB_TABLE_PLAYLIST_MAP, DB_VIEW_PLAYLIST);
+ __add_table_info(DB_TABLE_ALBUM, DB_TRIGGER_ALBUM, DB_TABLE_MEDIA, DB_TABLE_ALBUM, NULL);
+ __add_table_info(DB_TABLE_TAG_MAP, DB_TRIGGER_TAG_MAP, DB_TABLE_MEDIA, DB_TABLE_TAG_MAP, NULL);
+ __add_table_info(DB_TABLE_TAG, DB_TRIGGER_TAG_MAP1, DB_TABLE_TAG, DB_TABLE_TAG_MAP, DB_VIEW_TAG);
+ __add_table_info(DB_TABLE_BOOKMARK, DB_TRIGGER_BOOKMARK, DB_TABLE_MEDIA, DB_TABLE_BOOKMARK, NULL);
+ __add_table_info(DB_TABLE_STORAGE, NULL, NULL, NULL, NULL);
+ __add_table_info(DB_TABLE_FACE_SCAN_LIST, DB_TRIGGER_FACE_SCAN_LIST, DB_TABLE_MEDIA, DB_TABLE_FACE_SCAN_LIST, NULL);
+ __add_table_info(DB_TABLE_FACE, DB_TRIGGER_FACE, DB_TABLE_FACE_SCAN_LIST, DB_TABLE_FACE, NULL);
+
+ /*insert column info.. */
+ /*media*/
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_id", DB_TYPE_TEXT, "PRIMARY KEY", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_path", DB_TYPE_TEXT, "NOT NULL UNIQUE", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_display_name", DB_TYPE_TEXT, "NOT NULL", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_type", DB_TYPE_INT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_mime_type", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_size", DB_TYPE_INT, "DEFAULT 0", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_added_time", DB_TYPE_INT, "DEFAULT (unixepoch())", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_modified_time", DB_TYPE_INT, "DEFAULT 0", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "folder_id", DB_TYPE_INT, "DEFAULT 0", false, false, false);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_thumbnail_path", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_title", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "album_id", DB_TYPE_INT, "DEFAULT 0", false, false, false);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_album", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_artist", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_album_artist", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_genre", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_composer", DB_TYPE_TEXT, "DEFAULT ''", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_year", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_recorded_date", DB_TYPE_TEXT, "DEFAULT ''", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_copyright", DB_TYPE_TEXT, "DEFAULT ''", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_track_num", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_description", DB_TYPE_TEXT, "DEFAULT ''", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_bitrate", DB_TYPE_INT, "DEFAULT -1", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_bitpersample", DB_TYPE_INT, "DEFAULT 0", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_samplerate", DB_TYPE_INT, "DEFAULT -1", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_channel", DB_TYPE_INT, "DEFAULT -1", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_duration", DB_TYPE_INT, "DEFAULT -1", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_longitude", DB_TYPE_DOUBLE, "DEFAULT -200", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_latitude", DB_TYPE_DOUBLE, "DEFAULT -200", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_altitude", DB_TYPE_DOUBLE, "DEFAULT 0", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "exposure_time", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "fnumber", DB_TYPE_DOUBLE, "DEFAULT 0", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "iso", DB_TYPE_INT, "DEFAULT -1", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "model", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_width", DB_TYPE_INT, "DEFAULT -1", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_height", DB_TYPE_INT, "DEFAULT -1", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_datetaken", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "orientation", DB_TYPE_INT, "DEFAULT -1", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_rating", DB_TYPE_INT, "DEFAULT 0", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_favourite", DB_TYPE_INT, "DEFAULT 0", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_is_drm", DB_TYPE_INT, "DEFAULT 0", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_timeline", DB_TYPE_INT, "DEFAULT 0", false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "storage_uuid", DB_TYPE_TEXT, NULL, false, false, true);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "validity", DB_TYPE_INT, "DEFAULT 1", false, false, false);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "media_360", DB_TYPE_INT, "DEFAULT 0", false, false, true);
+
+ /*folder*/
+ __add_column_info(&column_list[DB_LIST_FOLDER], "folder_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, false, false);
+ __add_column_info(&column_list[DB_LIST_FOLDER], "folder_path", DB_TYPE_TEXT, "NOT NULL", true, false, false);
+ __add_column_info(&column_list[DB_LIST_FOLDER], "folder_name", DB_TYPE_TEXT, "NOT NULL", false, false, false);
+ __add_column_info(&column_list[DB_LIST_FOLDER], "folder_modified_time", DB_TYPE_INT, "DEFAULT 0", false, false, false);
+ __add_column_info(&column_list[DB_LIST_FOLDER], "storage_uuid", DB_TYPE_TEXT, NULL, true, false, false);
+ __add_column_info(&column_list[DB_LIST_FOLDER], "validity", DB_TYPE_INT, "DEFAULT 1", false, false, false);
+
+ /*playlist_map*/
+ __add_column_info(&column_list[DB_LIST_PLAYLIST_MAP], "_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, false, true);
+ __add_column_info(&column_list[DB_LIST_PLAYLIST_MAP], "playlist_id", DB_TYPE_INT, "NOT NULL", false, false, false);
+ __add_column_info(&column_list[DB_LIST_PLAYLIST_MAP], "media_id", DB_TYPE_TEXT, "NOT NULL", false, true, false);
+ __add_column_info(&column_list[DB_LIST_PLAYLIST_MAP], "playlist_member_order", DB_TYPE_INT, "NOT NULL", false, false, true);
+
+ /*playlist*/
+ __add_column_info(&column_list[DB_LIST_PLAYLIST], "playlist_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, true, true);
+ __add_column_info(&column_list[DB_LIST_PLAYLIST], "playlist_name", DB_TYPE_TEXT, "NOT NULL UNIQUE", false, false, true);
+ __add_column_info(&column_list[DB_LIST_PLAYLIST], "thumbnail_path", DB_TYPE_TEXT, NULL, false, false, true);
+
+ /*album*/
+ __add_column_info(&column_list[DB_LIST_ALBUM], "album_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, true, false);
+ __add_column_info(&column_list[DB_LIST_ALBUM], "name", DB_TYPE_TEXT, "NOT NULL", false, false, false);
+ __add_column_info(&column_list[DB_LIST_ALBUM], "artist", DB_TYPE_TEXT, NULL, false, false, false);
+ __add_column_info(&column_list[DB_LIST_ALBUM], "album_art", DB_TYPE_TEXT, NULL, false, false, false);
+
+ /*tag_map*/
+ __add_column_info(&column_list[DB_LIST_TAG_MAP], "_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, false, true);
+ __add_column_info(&column_list[DB_LIST_TAG_MAP], "tag_id", DB_TYPE_INT, "NOT NULL", true, false, false);
+ __add_column_info(&column_list[DB_LIST_TAG_MAP], "media_id", DB_TYPE_TEXT, "NOT NULL", true, true, false);
+
+ /*tag*/
+ __add_column_info(&column_list[DB_LIST_TAG], "tag_id ", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, true, true);
+ __add_column_info(&column_list[DB_LIST_TAG], "tag_name", DB_TYPE_TEXT, "NOT NULL UNIQUE", false, false, true);
+
+ /*bookmark*/
+ __add_column_info(&column_list[DB_LIST_BOOKMARK], "bookmark_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, false, false);
+ __add_column_info(&column_list[DB_LIST_BOOKMARK], "media_id", DB_TYPE_TEXT, "NOT NULL", true, true, false);
+ __add_column_info(&column_list[DB_LIST_BOOKMARK], "bookmark_marked_time", DB_TYPE_INT, "DEFAULT 0", true, false, false);
+ __add_column_info(&column_list[DB_LIST_BOOKMARK], "bookmark_thumbnail_path", DB_TYPE_TEXT, NULL, false, false, false);
+ __add_column_info(&column_list[DB_LIST_BOOKMARK], "bookmark_name", DB_TYPE_TEXT, NULL, false, false, false);
+
+ /*storage*/
+ __add_column_info(&column_list[DB_LIST_STORAGE], "storage_id", DB_TYPE_TEXT, "PRIMARY KEY", false, false, false);
+ __add_column_info(&column_list[DB_LIST_STORAGE], "storage_path", DB_TYPE_TEXT, "NOT NULL", false, false, false);
+ __add_column_info(&column_list[DB_LIST_STORAGE], "validity", DB_TYPE_INT, "DEFAULT 1", false, false, false);
+
+ /*face scan list*/
+ __add_column_info(&column_list[DB_LIST_FACE_SCAN_LIST], "media_id", DB_TYPE_TEXT, "NOT NULL UNIQUE", false, true, false);
+ __add_column_info(&column_list[DB_LIST_FACE_SCAN_LIST], "modified_time", DB_TYPE_INT, "DEFAULT 0", false, false, false);
+
+ /*face*/
+ __add_column_info(&column_list[DB_LIST_FACE], "media_face_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, false, false);
+ __add_column_info(&column_list[DB_LIST_FACE], "media_id", DB_TYPE_TEXT, "NOT NULL", true, true, false);
+ __add_column_info(&column_list[DB_LIST_FACE], "face_rect_x", DB_TYPE_INT, "DEFAULT 0", true, false, false);
+ __add_column_info(&column_list[DB_LIST_FACE], "face_rect_y", DB_TYPE_INT, "DEFAULT 0", true, false, false);
+ __add_column_info(&column_list[DB_LIST_FACE], "face_rect_w", DB_TYPE_INT, "DEFAULT 0", true, false, false);
+ __add_column_info(&column_list[DB_LIST_FACE], "face_rect_h", DB_TYPE_INT, "DEFAULT 0", true, false, false);
+ __add_column_info(&column_list[DB_LIST_FACE], "face_orientation", DB_TYPE_INT, "DEFAULT 0", false, false, false);
+ __add_column_info(&column_list[DB_LIST_FACE], "media_face_tag", DB_TYPE_TEXT, NULL, false, false, false);
+
+ return ret;
+}
+
+void _media_svc_destroy_table_query(void)
+{
+ int i = 0;
+
+ /* Table Free */
+ g_hash_table_destroy(table);
+ table = NULL;
+
+ /* Column Free */
+ for (i = 0; i < DB_LIST_MAX; i++) {
+ g_slist_free_full(column_list[i], __media_svc_column_free);
+ column_list[i] = NULL;
+ }
+}
+
+int _media_svc_sql_query(const char *sql_str, uid_t uid)
+{
+ return media_db_request_update_db(sql_str, uid);
+}
+
+#define MAX_RETRY 9
+#define SLEEP_TIME 1000 * 1000
+static int __media_svc_query_direct(sqlite3 *handle, const char *query, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *zErrMsg = NULL;
+ int retry_count = 0;
+
+EXEC_RETRY:
+ ret = sqlite3_exec(handle, query, NULL, NULL, &zErrMsg);
+ if (SQLITE_OK != ret) {
+ media_svc_sec_error("Error[%s],Query[%s]", zErrMsg, query);
+ SQLITE3_SAFE_FREE(zErrMsg);
+ if (ret == SQLITE_BUSY) {
+ ret = MS_MEDIA_ERR_DB_BUSY_FAIL;
+ } else if (ret == SQLITE_CONSTRAINT) {
+ ret = MS_MEDIA_ERR_DB_CONSTRAINT_FAIL;
+ } else if (ret == SQLITE_FULL) {
+ ret = MS_MEDIA_ERR_DB_FULL_FAIL;
+ } else if (ret == SQLITE_LOCKED) {
+ if (retry_count < MAX_RETRY) {
+ media_svc_error("Locked retry[%d]", retry_count);
+ retry_count++;
+ usleep(SLEEP_TIME);
+ goto EXEC_RETRY;
+ }
+ ret = MS_MEDIA_ERR_DB_INTERNAL;
+ } else {
+ ret = MS_MEDIA_ERR_DB_INTERNAL;
+ }
+ }
+
+ return ret;
+}
+
+int _media_svc_sql_query_direct(const char *sql_str, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3 *handle = NULL;
+
+ ret = media_db_connect(&handle, uid, true);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "DB connection failed");
+ ret = __media_svc_query_direct(handle, sql_str, uid);
+ media_db_disconnect(handle);
+
+ return ret;
+}
+
+int _media_svc_check_table_exist(sqlite3 *db_handle, bool *exist)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = sqlite3_mprintf("SELECT name FROM sqlite_master WHERE type='table' AND name=%Q;", DB_TABLE_MEDIA);
+
+ ret = _media_svc_sql_prepare_to_step_simple(db_handle, sql, &sql_stmt);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step_simple failed");
+
+ if (sqlite3_step(sql_stmt) != SQLITE_ROW) {
+ media_svc_debug("Need to create table");
+ *exist = false;
+ } else {
+ media_svc_debug("Already exists");
+ *exist = true;
+ }
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt)
+{
+ int err = -1;
+
+ media_svc_retvm_if(sql_str == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "invalid query");
+
+ if (handle == NULL) {
+ media_svc_error("handle is NULL");
+ sqlite3_free((char *)sql_str);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ media_svc_sec_debug("Query[%s]", sql_str);
+
+ err = sqlite3_prepare_v2(handle, sql_str, -1, stmt, NULL);
+ sqlite3_free((char *)sql_str);
+
+ if (err != SQLITE_OK) {
+ media_svc_error("prepare error %d[%s]", err, sqlite3_errmsg(handle));
+ if (err == SQLITE_CORRUPT)
+ return MS_MEDIA_ERR_DB_CORRUPT;
+
+ return MS_MEDIA_ERR_DB_INTERNAL;
+ }
+
+ err = sqlite3_step(*stmt);
+ if (err != SQLITE_ROW) {
+ media_svc_debug("No record");
+ SQLITE3_FINALIZE(*stmt);
+ return MS_MEDIA_ERR_DB_NO_RECORD;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt)
+{
+ int err = -1;
+
+ media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "handle is NULL");
+
+ media_svc_sec_debug("Query[%s]", sql_str);
+
+ if (!STRING_VALID(sql_str)) {
+ media_svc_error("invalid query");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ err = sqlite3_prepare_v2(handle, sql_str, -1, stmt, NULL);
+ sqlite3_free((char *)sql_str);
+
+ if (err != SQLITE_OK) {
+ media_svc_error("prepare error %d[%s]", err, sqlite3_errmsg(handle));
+ if (err == SQLITE_CORRUPT)
+ return MS_MEDIA_ERR_DB_CORRUPT;
+
+ return MS_MEDIA_ERR_DB_INTERNAL;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_sql_query_list(GList **query_list, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ int idx = 0;
+ int length = g_list_length(*query_list);
+ char *sql = NULL;
+
+ media_svc_debug("query list length : [%d]", length);
+
+ for (idx = 0; idx < length; idx++) {
+ sql = (char *)g_list_nth_data(*query_list, idx);
+ if (STRING_VALID(sql)) {
+ ret = media_db_request_update_db(sql, uid);
+ if (ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("media_db_request_update_db failed : %d", ret);
+ }
+
+ SQLITE3_SAFE_FREE(sql);
+ }
+
+ _media_svc_sql_query_release(query_list);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_sql_query_list_direct(GList **query_list, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ int idx = 0;
+ int length = g_list_length(*query_list);
+ char *sql = NULL;
+ char *zErrMsg = NULL;
+ sqlite3 *handle = NULL;
+ bool with_transaction = true;
+
+ media_svc_debug("query list length[%d]", length);
+ if (length == 0)
+ goto ZERO_LEN;
+
+ ret = media_db_connect(&handle, uid, true);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "DB connection failed");
+
+ ret = sqlite3_exec(handle, "BEGIN;", NULL, NULL, &zErrMsg);
+ if (SQLITE_OK != ret) {
+ media_svc_sec_error("Transaction failed[%s]. Try an individual insert.", zErrMsg);
+ SQLITE3_SAFE_FREE(zErrMsg);
+ with_transaction = false;
+ }
+
+ for (idx = 0; idx < length; idx++) {
+ sql = (char *)g_list_nth_data(*query_list, idx);
+ if (STRING_VALID(sql)) {
+ ret = __media_svc_query_direct(handle, sql, uid);
+ if (ret != MS_MEDIA_ERR_NONE)
+ media_svc_debug("_media_svc_query_direct failed[%s]", sql);
+
+ SQLITE3_SAFE_FREE(sql);
+ }
+ }
+
+ if (with_transaction) {
+ ret = sqlite3_exec(handle, "COMMIT;", NULL, NULL, &zErrMsg);
+ if (SQLITE_OK != ret) {
+ media_svc_sec_error("Commit failed[%s]", zErrMsg);
+ SQLITE3_SAFE_FREE(zErrMsg);
+ media_db_disconnect(handle);
+ _media_svc_sql_query_release(query_list);
+ return MS_MEDIA_ERR_DB_INTERNAL;
+ }
+ }
+
+ media_db_disconnect(handle);
+
+ZERO_LEN:
+ _media_svc_sql_query_release(query_list);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+void _media_svc_sql_query_add(GList **query_list, char **query)
+{
+ *query_list = g_list_append(*query_list, *query);
+}
+
+void _media_svc_sql_query_release(GList **query_list)
+{
+ if (*query_list) {
+ g_list_free(*query_list);
+ *query_list = NULL;
+ }
+}
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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 <glib/gstdio.h>
+#include <media-util-user.h>
+
+#include "media-svc-media-folder.h"
+#include "media-svc-debug.h"
+#include "media-svc-env.h"
+#include "media-svc-util.h"
+#include "media-svc-db-utils.h"
+
+static int __media_svc_get_folder_id(sqlite3 *handle, const char *path, long long int *folder_id)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+
+ sql = sqlite3_mprintf("SELECT folder_id FROM %q WHERE folder_path=%Q", DB_TABLE_FOLDER, path);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step failed [%d]", ret);
+
+ *folder_id = sqlite3_column_int64(sql_stmt, 0);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return ret;
+}
+
+static int __media_svc_append_folder(bool is_direct, const char *storage_id, const char *folder_path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *folder_name = NULL;
+ int folder_modified_date = 0;
+
+ folder_name = g_path_get_basename(folder_path);
+ folder_modified_date = _media_svc_get_file_time(folder_path);
+
+ /* Sometime SQLITE3 returns NO_RECORD, so need to consider conflict case.. */
+ char *sql = sqlite3_mprintf("INSERT OR IGNORE INTO %q(folder_path, folder_name, storage_uuid, folder_modified_time) VALUES (%Q, %Q, %Q, %d);",
+ DB_TABLE_FOLDER, folder_path, folder_name, storage_id, folder_modified_date);
+
+ if (is_direct)
+ ret = _media_svc_sql_query_direct(sql, uid);
+ else
+ ret = _media_svc_sql_query(sql, uid);
+
+ SQLITE3_SAFE_FREE(sql);
+
+ g_free(folder_name);
+
+ return ret;
+}
+
+int _media_svc_update_folder_modified_time(const char *folder_path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ int time = 0;
+ char *query = NULL;
+
+ time = _media_svc_get_file_time(folder_path);
+ query = sqlite3_mprintf("UPDATE %q SET folder_modified_time=%d WHERE folder_path=%Q", DB_TABLE_FOLDER, time, folder_path);
+
+ ret = _media_svc_sql_query(query, uid);
+ SQLITE3_SAFE_FREE(query);
+
+ return ret;
+}
+
+static int __media_svc_append_parent_folder(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ size_t next_pos = ms_user_get_root_length(path, uid);
+ char *next = NULL;
+ char *dir_path = NULL;
+
+ do {
+ next = strstr(path + next_pos, "/");
+ if (next) {
+ next_pos = (next - path);
+ dir_path = g_strndup(path, next_pos);
+ next_pos++;
+ } else {
+ dir_path = g_strdup(path);
+ }
+
+ ret = _media_svc_check_folder_by_path(handle, dir_path);
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+ ret = __media_svc_append_folder(is_direct, storage_id, dir_path, uid);
+ if (ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("__media_svc_append_folder is failed");
+ else
+ media_svc_sec_debug("Append new folder path[%s]", dir_path);
+ }
+
+ g_free(dir_path);
+ } while (next);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, long long int *folder_id, uid_t uid)
+{
+ char *dir_path = NULL;
+ int ret = MS_MEDIA_ERR_NONE;
+
+ dir_path = g_path_get_dirname(path);
+
+ ret = __media_svc_get_folder_id(handle, dir_path, folder_id);
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+ ret = __media_svc_append_parent_folder(handle, is_direct, storage_id, dir_path, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("__media_svc_append_parent_folder failed");
+ goto FINALIZE;
+ }
+
+ ret = __media_svc_get_folder_id(handle, dir_path, folder_id);
+ }
+FINALIZE:
+ g_free(dir_path);
+
+ return ret;
+}
+
+int _media_svc_append_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ ret = _media_svc_check_folder_by_path(handle, path);
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
+ ret = __media_svc_append_parent_folder(handle, true, storage_id, path, uid);
+ else
+ ret = _media_svc_set_folder_validity(true, path, 1, false, uid);
+
+ return ret;
+}
+
+int _media_svc_set_folder_validity(bool is_direct, const char *start_path, int validity, bool is_recursive, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = NULL;
+
+ if (is_recursive) {
+ sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE folder_path LIKE '%q/%%' OR folder_path=%Q",
+ DB_TABLE_FOLDER, validity, start_path, start_path);
+ } else {
+ sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE folder_path=%Q", DB_TABLE_FOLDER, validity, start_path);
+ }
+
+ if (is_direct)
+ ret = _media_svc_sql_query_direct(sql, uid);
+ else
+ ret = _media_svc_sql_query(sql, uid);
+
+ SQLITE3_SAFE_FREE(sql);
+
+ return ret;
+}
+
+int _media_svc_check_folder_by_path(sqlite3 *handle, const char *path)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ sql = sqlite3_mprintf("SELECT 1 FROM %q WHERE folder_path=%Q", DB_TABLE_FOLDER, path);
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MS_MEDIA_ERR_NONE;
+}
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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 <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include "media-svc-media.h"
+#include "media-svc-media-folder.h"
+#include "media-svc-debug.h"
+#include "media-svc-util.h"
+#include "media-svc-db-utils.h"
+#include "media-svc-noti.h"
+
+#define MEDIA_SVC_MAX_COMMIT_SIZE 200
+
+static __thread GList *g_media_svc_scanner_query_list = NULL;
+static __thread GList *g_media_svc_update_list = NULL;
+
+int _media_svc_check_data_by_path(sqlite3 *handle, const char *path)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
+
+ sql = sqlite3_mprintf("SELECT 1 FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path);
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return ret;
+}
+
+int _media_svc_get_modified_time(sqlite3 *handle, const char *path, int *modified_time)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
+
+ sql = sqlite3_mprintf("SELECT media_modified_time FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path);
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ *modified_time = sqlite3_column_int(sql_stmt, 0);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static char *__media_svc_make_insert_query(media_svc_content_info_s *content_info)
+{
+ return sqlite3_mprintf("INSERT INTO %q(media_id, media_path, media_display_name, media_type, media_mime_type, media_size, media_modified_time, folder_id, media_thumbnail_path, media_title, album_id, media_album, media_artist, media_album_artist, media_genre, media_year, media_track_num, media_width, media_height, media_datetaken, orientation, storage_uuid) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %lld, %Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %d, %d, %Q, %d, %Q);",
+ DB_TABLE_MEDIA,
+ content_info->media_uuid,
+ content_info->path,
+ content_info->file_name,
+ content_info->media_type,
+ content_info->mime_type,
+ content_info->size,
+ content_info->modified_time,
+ content_info->folder_id,
+ content_info->thumbnail_path,
+ content_info->media_meta.title,
+ content_info->album_id,
+ content_info->media_meta.album,
+ content_info->media_meta.artist,
+ content_info->media_meta.album_artist,
+ content_info->media_meta.genre,
+ content_info->media_meta.year,
+ content_info->media_meta.track_num,
+ content_info->media_meta.width,
+ content_info->media_meta.height,
+ content_info->media_meta.datetaken,
+ content_info->media_meta.orientation,
+ content_info->storage_uuid);
+}
+
+int _media_svc_insert_item_stack(media_svc_content_info_s *content_info)
+{
+ char *sql = __media_svc_make_insert_query(content_info);
+ media_svc_retvm_if(!sql, MS_MEDIA_ERR_INVALID_PARAMETER, "make query failed");
+
+ media_svc_sec_debug("Query[%s]", sql);
+
+ _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_insert_item(media_svc_content_info_s *content_info, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = __media_svc_make_insert_query(content_info);
+ media_svc_retvm_if(!sql, MS_MEDIA_ERR_INVALID_PARAMETER, "make query failed");
+
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "failed to insert item");
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_update_item_with_data(bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ char *sql = sqlite3_mprintf("UPDATE %q SET media_size=%lld, media_modified_time=%d, media_thumbnail_path=%Q, media_title=%Q, album_id=%d, media_album=%Q, media_artist=%Q, media_album_artist=%Q, media_genre=%Q, media_year=%Q, media_track_num=%Q, media_width=%d, media_height=%d, media_datetaken=%Q, orientation=%d, validity=1 WHERE media_path=%Q;",
+ DB_TABLE_MEDIA,
+ content_info->size,
+ content_info->modified_time,
+ content_info->thumbnail_path,
+ content_info->media_meta.title,
+ content_info->album_id,
+ content_info->media_meta.album,
+ content_info->media_meta.artist,
+ content_info->media_meta.album_artist,
+ content_info->media_meta.genre,
+ content_info->media_meta.year,
+ content_info->media_meta.track_num,
+ content_info->media_meta.width,
+ content_info->media_meta.height,
+ content_info->media_meta.datetaken,
+ content_info->media_meta.orientation,
+ content_info->path
+ );
+
+ /* Scanner use only batch insert */
+ if (is_direct) {
+ media_svc_sec_debug("Query [%s]", sql);
+ _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
+ } else {
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ }
+
+ return ret;
+}
+int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ sql = sqlite3_mprintf("SELECT media_thumbnail_path FROM %q WHERE media_path='%q'", DB_TABLE_MEDIA, path);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MS_MEDIA_ERR_NONE) {
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
+ media_svc_debug("there is no thumbnail.");
+ else
+ media_svc_error("error when _media_svc_get_thumbnail_path_by_path. err = [%d]", ret);
+
+ return ret;
+ }
+
+ g_strlcpy(thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_PATHNAME_SIZE);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_delete_item_by_path(const char *path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = NULL;
+
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ sql = sqlite3_mprintf("DELETE FROM %q WHERE media_path=%Q;", DB_TABLE_MEDIA, path);
+
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "failed to delete item");
+
+ return ret;
+}
+
+int _media_svc_update_item_validity(const char *path, int validity, bool stack_query, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = NULL;
+
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ media_svc_debug("path=[%s], validity=[%d]", path, validity);
+
+ sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE media_path='%q';", DB_TABLE_MEDIA, validity, path);
+
+ if (!stack_query) {
+ ret = _media_svc_sql_query_direct(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ } else {
+ _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
+ }
+
+ return ret;
+}
+
+int _media_svc_update_thumbnail_path(const char *path, const char *thumb_path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ char *sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path=%Q WHERE media_path=%Q;", DB_TABLE_MEDIA, thumb_path, path);
+
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+
+ return ret;
+}
+
+int _media_svc_update_item_by_path(const char *src_path, const char *dst_storage_id, const char *dest_path, const char *file_name, int modified_time, long long int folder_id, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ char *query = sqlite3_mprintf("UPDATE %q SET media_path=%Q, media_display_name=%Q, media_modified_time=%d, folder_id=%lld, storage_uuid='%q' WHERE media_path=%Q;",
+ DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_id, dst_storage_id, src_path);
+
+ ret = _media_svc_sql_query(query, uid);
+ SQLITE3_SAFE_FREE(query);
+
+ return ret;
+}
+
+int _media_svc_list_query_do(media_svc_query_type_e query_type, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ /* For multiples of 200, empty requests are possible */
+ switch (query_type) {
+ case MEDIA_SVC_QUERY_SCANNER:
+ ret = _media_svc_sql_query_list_direct(&g_media_svc_scanner_query_list, uid);
+ break;
+ case MEDIA_SVC_QUERY_UPDATE_COMMON:
+ if (g_media_svc_update_list == NULL || g_list_length(g_media_svc_update_list) == 0)
+ return MS_MEDIA_ERR_NONE;
+
+ ret = _media_svc_sql_query_list(&g_media_svc_update_list, uid);
+ break;
+ default:
+ media_svc_error("Wrong type[%d]", query_type);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Failed to request queries");
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_append_query_list(const char *query, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ media_svc_retvm_if(query == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "query is NULL");
+
+ g_media_svc_update_list = g_list_append(g_media_svc_update_list, (gpointer)query);
+
+ if (g_list_length(g_media_svc_update_list) >= MEDIA_SVC_MAX_COMMIT_SIZE)
+ ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
+
+ return ret;
+}
+
+int _media_svc_get_media(sqlite3 *handle, const char *sql, GList **path_list)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+
+ media_svc_retvm_if(!sql, MS_MEDIA_ERR_INVALID_PARAMETER, "query is NULL");
+ media_svc_retvm_if(!path_list, MS_MEDIA_ERR_INVALID_PARAMETER, "array is NULL");
+
+ ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step_simple() failed [%d]", ret);
+
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW)
+ *path_list = g_list_append(*path_list, g_strdup((const char *)sqlite3_column_text(sql_stmt, 0)));
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return ret;
+}
+
+int _media_svc_get_noti_info(sqlite3 *handle, const char *path, media_svc_noti_item **item)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+
+ media_svc_retvm_if(item == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "item is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ sql = sqlite3_mprintf("SELECT media_id, media_type, media_mime_type FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path);
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step() failed [%d]", ret);
+
+ *item = g_new0(media_svc_noti_item, 1);
+
+ (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
+ (*item)->media_type = sqlite3_column_int(sql_stmt, 1);
+ (*item)->mime_type = g_strdup((const char *)sqlite3_column_text(sql_stmt, 2));
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MS_MEDIA_ERR_NONE;
+}
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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 <unistd.h>
+#include "media-svc-noti.h"
+#include "media-svc-util.h"
+#include "media-svc-debug.h"
+
+static __thread GSList *g_inserted_noti_list = NULL;
+static __thread int g_noti_from_pid = -1;
+
+static void __media_svc_publish_noti_by_item(gpointer data, gpointer user_data)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ media_svc_noti_item *item = (media_svc_noti_item *)data;
+
+ if (item && item->path) {
+ ret = media_db_update_send(item->pid, item->update_item, item->update_type, item->path, item->media_uuid, item->media_type, item->mime_type);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_sec_error("media_db_update_send failed : %d [%s]", ret, item->path);
+ } else {
+ media_svc_debug("media_db_update_send success");
+ }
+ } else {
+ media_svc_debug("invalid path");
+ }
+}
+
+static void __media_svc_destroy_noti_item(gpointer data)
+{
+ media_svc_noti_item *item = (media_svc_noti_item *)data;
+
+ g_free(item->media_uuid);
+ g_free(item->path);
+ g_free(item->mime_type);
+ g_free(item);
+}
+
+int _media_svc_publish_noti(media_item_update_type_e update_type, const char *path, int media_type, const char *uuid, const char *mime_type)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
+
+ ret = media_db_update_send(getpid(), MS_MEDIA_ITEM_FILE, update_type, path, uuid, media_type, mime_type);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Send noti failed[%d][%s]", ret, path);
+
+ media_svc_sec_debug("Send noti [%s]", path);
+
+ return ret;
+}
+
+int _media_svc_publish_dir_noti(media_item_update_type_e update_type, const char *path, const char *uuid, int pid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
+
+ ret = media_db_update_send(pid, MS_MEDIA_ITEM_DIRECTORY, update_type, path, uuid, 0, NULL);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Send dir noti failed[%d][%s]", ret, path);
+
+ media_svc_sec_debug("Send dir noti [%s]", path);
+
+ return ret;
+}
+
+void _media_svc_set_noti_from_pid(int pid)
+{
+ g_noti_from_pid = pid;
+}
+
+void _media_svc_initialize_noti_list(void)
+{
+ if (g_inserted_noti_list)
+ g_slist_free_full(g_inserted_noti_list, __media_svc_destroy_noti_item);
+
+ g_inserted_noti_list = NULL;
+}
+
+void _media_svc_insert_item_to_noti_list(media_svc_content_info_s *content_info)
+{
+ media_svc_noti_item *item = NULL;
+
+ if (!content_info)
+ return;
+
+ item = g_new0(media_svc_noti_item, 1);
+
+ item->pid = g_noti_from_pid;
+ item->update_item = MS_MEDIA_ITEM_INSERT; /* INSERT */
+ item->update_type = MS_MEDIA_ITEM_FILE;
+ item->media_type = content_info->media_type;
+ item->media_uuid = g_strdup(content_info->media_uuid);
+ item->path = g_strdup(content_info->path);
+ item->mime_type = g_strdup(content_info->mime_type);
+
+ g_inserted_noti_list = g_slist_append(g_inserted_noti_list, (gpointer)item);
+}
+
+void _media_svc_publish_noti_list(void)
+{
+ g_slist_foreach(g_inserted_noti_list, __media_svc_publish_noti_by_item, NULL);
+
+ _media_svc_initialize_noti_list();
+}
+
+void _media_svc_destroy_noti_item(media_svc_noti_item *item)
+{
+ if (!item)
+ return;
+
+ g_free(item->media_uuid);
+ g_free(item->path);
+ g_free(item->mime_type);
+ g_free(item);
+}
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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 <media-util-user.h>
+#include "media-svc-debug.h"
+#include "media-svc-env.h"
+#include "media-svc-db-utils.h"
+#include "media-svc-util.h"
+#include "media-svc-storage.h"
+
+int _media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+
+ media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+ media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
+ media_svc_retvm_if(validity == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "validity is NULL");
+
+ *storage_path = NULL;
+ *validity = 0;
+
+ sql = sqlite3_mprintf("SELECT storage_path, validity FROM %q WHERE storage_id=%Q", DB_TABLE_STORAGE, storage_id);
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ *storage_path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
+ *validity = sqlite3_column_int(sql_stmt, 1);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_append_storage(const char *storage_id, const char *storage_path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = sqlite3_mprintf("INSERT INTO %q (storage_id, storage_path) values (%Q, %Q);",
+ DB_TABLE_STORAGE, storage_id, storage_path);
+
+ ret = _media_svc_sql_query_direct(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+
+ return ret;
+}
+
+int _media_svc_update_storage_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = NULL;
+ char *old_storage_path = NULL;
+ int validity = 0;
+
+ media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+ media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ /*Get old path*/
+ ret = _media_svc_check_storage(handle, storage_id, &old_storage_path, &validity);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ /*Storage table update*/
+ sql = sqlite3_mprintf("UPDATE %q SET storage_path=%Q WHERE storage_id=%Q", DB_TABLE_STORAGE, path, storage_id);
+ ret = _media_svc_sql_query_direct(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ g_free(old_storage_path);
+ return ret;
+ }
+
+ /*Folder table update*/
+ sql = sqlite3_mprintf("UPDATE %q SET folder_path=REPLACE(folder_path, %Q, %Q) WHERE storage_uuid=%Q", DB_TABLE_FOLDER, old_storage_path, path, storage_id);
+ ret = _media_svc_sql_query_direct(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ g_free(old_storage_path);
+ return ret;
+ }
+
+ /*Media table update*/
+ sql = sqlite3_mprintf("UPDATE %q SET media_path=REPLACE(media_path, %Q, %Q) WHERE storage_uuid=%Q", DB_TABLE_MEDIA, old_storage_path, path, storage_id);
+ ret = _media_svc_sql_query_direct(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ g_free(old_storage_path);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ return ret;
+}
+
+static int __media_svc_delete_thumbnail(sqlite3 *handle)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = NULL;
+ sqlite3_stmt *sql_stmt = NULL;
+
+ sql = sqlite3_mprintf("SELECT media_thumbnail_path FROM %q WHERE validity=0 AND media_thumbnail_path is not null", DB_TABLE_MEDIA);
+ ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW)
+ _media_svc_remove_file((const char *)sqlite3_column_text(sql_stmt, 0));
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return ret;
+}
+
+int _media_svc_delete_invalid_storage(sqlite3 *handle, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = NULL;
+
+ ret = __media_svc_delete_thumbnail(handle);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to remove thumbnail");
+
+ sql = sqlite3_mprintf("DELETE FROM %q WHERE validity=0;DELETE FROM %q WHERE validity=0;DELETE FROM %q WHERE validity=0;",
+ DB_TABLE_MEDIA, DB_TABLE_STORAGE, DB_TABLE_FOLDER);
+
+ ret = _media_svc_sql_query_direct(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+
+ return ret;
+}
+
+int _media_svc_update_storage_validity(const char *storage_id, int validity, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = NULL;
+
+ if (storage_id == NULL) {
+ sql = sqlite3_mprintf("UPDATE %q SET validity=%d;UPDATE %q SET validity=%d WHERE storage_uuid IS NOT 'media';UPDATE %q SET validity=%d WHERE storage_uuid IS NOT 'media';",
+ DB_TABLE_STORAGE, validity, DB_TABLE_FOLDER, validity, DB_TABLE_MEDIA, validity);
+ } else {
+ sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE storage_id=%Q;UPDATE %q SET validity=%d WHERE storage_uuid=%Q;UPDATE %q SET validity=%d WHERE storage_uuid=%Q;",
+ DB_TABLE_STORAGE, validity, storage_id, DB_TABLE_FOLDER, validity, storage_id, DB_TABLE_MEDIA, validity, storage_id);
+ }
+ ret = _media_svc_sql_query_direct(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+
+ return ret;
+}
+
+int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+ char *internal_path = NULL;
+
+ media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ ret = ms_user_get_internal_root_path(uid, &internal_path);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
+
+ if (STRING_VALID(internal_path) && strncmp(path, internal_path, strlen(internal_path)) == 0) {
+ g_strlcpy(storage_id, DB_TABLE_MEDIA, MEDIA_SVC_UUID_SIZE + 1);
+ g_free(internal_path);
+ return MS_MEDIA_ERR_NONE;
+ }
+
+ g_free(internal_path);
+
+ sql = sqlite3_mprintf("SELECT storage_id FROM %q WHERE validity=1 AND instr(%Q, storage_path)", DB_TABLE_STORAGE, path);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0)))
+ g_strlcpy(storage_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ if (!STRING_VALID(storage_id)) {
+ media_svc_error("Not found valid storage id [%s]", path);
+ ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ return ret;
+}
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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 <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/vfs.h>
+#include <ctype.h>
+#include <aul/aul.h>
+#include <mm_file.h>
+#include <libexif/exif-data.h>
+#include <uuid/uuid.h>
+#include <media-thumbnail.h>
+#include <media-util-user.h>
+#include "media-svc-util.h"
+#include "media-svc-db-utils.h"
+#include "media-svc-debug.h"
+#include "media-svc-env.h"
+#include "media-svc-album.h"
+/*For ebook metadata */
+#include <zip.h>
+#include <libxml/xmlmemory.h>
+#include <libxml/parser.h>
+#include <libxml/HTMLparser.h>
+#include <dlfcn.h>
+
+#define MEDIA_SVC_FILE_EXT_LEN_MAX 6
+
+#define MUSIC_MIME_NUM 29
+#define SOUND_MIME_NUM 2
+#define MIME_LENGTH 50
+#define IMAGE_PREFIX "image/"
+#define AUDIO_PREFIX "audio/"
+#define VIDEO_PREFIX "video/"
+#define PREFIX_LEN 6
+
+#define MEDIA_SVC_PDF_TAG_TAIL_LEN 12
+#define MEDIA_SVC_PDF_BUF_SIZE 256
+
+#define MEDIA_SVC_THUMB_WIDTH 320
+#define MEDIA_SVC_THUMB_HEIGHT 240
+
+#define PATH_PLUGIN_LIB PATH_LIBDIR"/libmedia-ebook-plugin.so"
+
+enum Exif_Orientation {
+ NOT_AVAILABLE = 0,
+ NORMAL = 1,
+ HFLIP = 2,
+ ROT_180 = 3,
+ VFLIP = 4,
+ TRANSPOSE = 5,
+ ROT_90 = 6,
+ TRANSVERSE = 7,
+ ROT_270 = 8
+};
+
+static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
+ /*known mime types of normal files*/
+ "mpeg",
+ "ogg",
+ "x-ms-wma",
+ "x-flac",
+ "mp4",
+ "mp3",
+ "x-mp3", /*alias of audio/mpeg*/
+ "x-mpeg", /*alias of audio/mpeg*/
+ "3gpp",
+ "x-ogg", /*alias of audio/ogg*/
+ "vnd.ms-playready.media.pya:*.pya", /*playready*/
+ "wma",
+ "aac",
+ "x-m4a", /*alias of audio/mp4*/
+ /* below mimes are rare*/
+ "x-vorbis+ogg",
+ "x-flac+ogg",
+ "x-matroska",
+ "ac3",
+ "mp2",
+ "x-ape",
+ "x-ms-asx",
+ "vnd.rn-realaudio",
+ "x-vorbis", /*alias of audio/x-vorbis+ogg*/
+ "vorbis", /*alias of audio/x-vorbis+ogg*/
+ "x-oggflac",
+ "x-mp2", /*alias of audio/mp2*/
+ "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
+ "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
+ "x-wav",
+};
+
+static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
+ "application/x-smaf",
+ "text/x-iMelody"
+};
+
+static char *__media_info_generate_uuid(void)
+{
+ uuid_t uuid_value;
+ char uuid_unparsed[37];
+
+RETRY_GEN:
+ uuid_generate(uuid_value);
+ uuid_unparse(uuid_value, uuid_unparsed);
+
+ if (strlen(uuid_unparsed) < 36) {
+ media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
+ goto RETRY_GEN;
+ }
+
+ return g_strdup(uuid_unparsed);
+}
+
+static char * __media_svc_get_exif_datetaken(ExifData *ed)
+{
+ ExifEntry *entry;
+ char tmp[MEDIA_SVC_METADATA_LEN_MAX + 1] = { 0, };
+
+ media_svc_retv_if(!ed, NULL);
+
+ entry = exif_data_get_entry(ed, EXIF_TAG_DATE_TIME_ORIGINAL);
+ if (entry) {
+ exif_entry_get_value(entry, tmp, MEDIA_SVC_METADATA_LEN_MAX);
+ if (strlen(tmp) > 0)
+ return g_strdup(tmp);
+ }
+
+ entry = exif_data_get_entry(ed, EXIF_TAG_DATE_TIME);
+ if (entry) {
+ exif_entry_get_value(entry, tmp, MEDIA_SVC_METADATA_LEN_MAX);
+ if (strlen(tmp) > 0)
+ return g_strdup(tmp);
+ }
+
+ return NULL;
+}
+
+static bool __media_svc_get_exif_short(ExifData *ed, ExifTag tagtype, unsigned short *value)
+{
+ ExifEntry *entry;
+
+ media_svc_retv_if(!ed, false);
+ media_svc_retvm_if(!value, false, "value is NULL");
+
+ entry = exif_data_get_entry(ed, tagtype);
+ media_svc_retv_if(!entry, false);
+ *value = exif_get_short(entry->data, exif_data_get_byte_order(ed));
+
+ return true;
+}
+
+static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
+{
+ int idx = 0;
+ int audio = 0;
+ int video = 0;
+
+ media_svc_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "path is null");
+ media_svc_retvm_if(!mime_type, MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is null");
+ media_svc_retvm_if(!media_type, MS_MEDIA_ERR_INVALID_PARAMETER, "media_type is null");
+
+ /* Image */
+ if (strncmp(mime_type, IMAGE_PREFIX, PREFIX_LEN) == 0) {
+ *media_type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
+ return MS_MEDIA_ERR_NONE;
+ }
+
+ /* Audio */
+ if (strncmp(mime_type, AUDIO_PREFIX, PREFIX_LEN) == 0) {
+ *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
+
+ for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
+ if (strcmp(mime_type + PREFIX_LEN, music_mime_table[idx]) == 0) {
+ *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
+ break;
+ }
+ }
+
+ /* audio/x-mpegurl : .m3u file (playlist file) */
+ if (strcmp(mime_type + PREFIX_LEN, "x-mpegurl") == 0)
+ *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
+
+ return MS_MEDIA_ERR_NONE;
+ }
+
+ /* Video */
+ if (strncmp(mime_type, VIDEO_PREFIX, PREFIX_LEN) == 0) {
+ *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
+
+ /*some video files don't have video stream. in this case it is categorize as music. */
+ if (strcmp(mime_type + PREFIX_LEN, "3gpp") == 0 ||
+ strcmp(mime_type + PREFIX_LEN, "mp4") == 0) {
+ if (mm_file_get_stream_info(path, &audio, &video) == FILEINFO_ERROR_NONE) {
+ if (audio > 0 && video == 0)
+ *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
+ }
+ }
+
+ return MS_MEDIA_ERR_NONE;
+ }
+
+ /* ETC */
+ *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
+
+ for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
+ if (strcmp(mime_type, sound_mime_table[idx]) == 0) {
+ *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
+ return MS_MEDIA_ERR_NONE;
+ }
+ }
+
+ /*"asf" must check video stream and then categorize in directly. */
+ if (strcmp(mime_type, "application/vnd.ms-asf") == 0) {
+ if (mm_file_get_stream_info(path, &audio, &video) == FILEINFO_ERROR_NONE) {
+ if (audio > 0 && video == 0)
+ *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
+ else
+ *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+ }
+
+ if (strcmp(mime_type, "application/epub+zip") == 0 || strcmp(mime_type, "application/pdf") == 0)
+ *media_type = MEDIA_SVC_MEDIA_TYPE_BOOK;
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static int __media_svc_get_mime_type(const char *path, char *mimetype)
+{
+ media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
+ media_svc_error("aul_get_mime_from_file fail");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
+{
+ int i = 0;
+
+ for (i = strlen(file_path); i >= 0; i--) {
+ if (file_path[i] == '.') {
+ g_strlcpy(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
+ return true;
+ }
+
+ if (file_path[i] == '/')
+ return false;
+ }
+ return false;
+}
+
+static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ struct statfs fs;
+ char *thumb_path = NULL;
+ long bsize_kbytes = 0;
+ GError *error = NULL;
+
+ media_svc_retvm_if(!image || size == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid image");
+ media_svc_sec_debug("start save image, path [%s] image size [%d]", image_path, size);
+
+ ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path error");
+
+ ret = statfs(thumb_path, &fs);
+ g_free(thumb_path);
+ media_svc_retvm_if(ret == -1, MS_MEDIA_ERR_INTERNAL, "statfs failed");
+
+ bsize_kbytes = fs.f_bsize >> 10;
+ media_svc_retvm_if((bsize_kbytes * fs.f_bavail) < 1024, MS_MEDIA_ERR_NOT_ENOUGH_SPACE, "Not enough space");
+
+ if (!g_file_set_contents(image_path, (const gchar *)image, (gssize)size, &error)) {
+ media_svc_error("g_file_set_contents faild:%s", error->message);
+ g_error_free(error);
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static char *__media_svc_get_title_from_filename(const char *filename)
+{
+ char *title = NULL;
+ char *last_dot = NULL;
+
+ media_svc_retvm_if(!STRING_VALID(filename), g_strdup(MEDIA_SVC_TAG_UNKNOWN), "Invalid path");
+
+ last_dot = strrchr(filename, '.');
+ if (last_dot) {
+ title = g_strndup(filename, last_dot - filename);
+ } else {
+ title = g_strdup(filename);
+ }
+
+ media_svc_debug("extract title is [%s]", title);
+
+ return title;
+}
+
+void _media_svc_remove_file(const char *path)
+{
+ if (!STRING_VALID(path))
+ return;
+
+ if (remove(path) != 0)
+ media_svc_stderror("fail to remove file result");
+}
+
+static int __media_svc_get_thumbnail_path(char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
+ g_autofree gchar *hash = NULL;
+ g_autofree gchar *thumb_dir = NULL;
+
+ ret = ms_user_get_root_thumb_store_path(uid, &thumb_dir);
+ media_svc_retvm_if(!STRING_VALID(thumb_dir), ret, "ms_user_get_root_thumb_store_path failed");
+ media_svc_retvm_if(!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR), MS_MEDIA_ERR_INTERNAL, "Not a directory");
+
+ memset(file_ext, 0, sizeof(file_ext));
+ if (!__media_svc_get_file_ext(pathname, file_ext))
+ media_svc_error("get file ext fail");
+
+ hash = g_compute_checksum_for_string(G_CHECKSUM_MD5, pathname, -1);
+ media_svc_retvm_if(!hash, MS_MEDIA_ERR_INTERNAL, "Failed to create hashname");
+
+ if (img_format) {
+ /* 'img_format' is mime-type */
+ if (!g_str_has_prefix(img_format, IMAGE_PREFIX) || strlen(img_format) == PREFIX_LEN) {
+ media_svc_error("Not proper img format");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.%s", thumb_dir, file_ext, hash, img_format + PREFIX_LEN);
+ } else {
+ if (strcasecmp(file_ext, "PNG") == 0)
+ snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.png", thumb_dir, file_ext, hash);
+ else
+ snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.jpg", thumb_dir, file_ext, hash);
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_get_file_time(const char *full_path)
+{
+ struct stat statbuf = { 0, };
+
+ if (stat(full_path, &statbuf) == -1) {
+ media_svc_stderror("stat fails.");
+ return 0;
+ }
+
+ return statbuf.st_mtime;
+}
+
+int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, const char *path, bool refresh)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char mime_type[256] = {0, };
+ media_svc_media_type_e media_type;
+ struct stat st = { 0, };
+
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ content_info->path = g_strdup(path);
+ content_info->file_name = g_path_get_basename(path);
+
+ if (stat(path, &st) == 0) {
+ content_info->modified_time = st.st_mtime;
+ content_info->size = st.st_size;
+ } else {
+ media_svc_stderror("stat failed");
+ }
+
+ /* refresh is TRUE when file modified. so only modified_time and size are changed*/
+ if (refresh) {
+ media_svc_debug("refresh");
+ return MS_MEDIA_ERR_NONE;
+ }
+
+ content_info->storage_uuid = g_strdup(storage_id);
+ media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
+
+ content_info->media_uuid = __media_info_generate_uuid();
+ media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
+
+ ret = __media_svc_get_mime_type(path, mime_type);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
+
+ media_svc_debug("mime [%s]", mime_type);
+
+ ret = __media_svc_get_media_type(path, mime_type, &media_type);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
+
+ content_info->mime_type = g_strdup(mime_type);
+ media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
+
+ media_svc_sec_debug("path[%s], media_type[%d]", content_info->path, media_type);
+
+ content_info->media_type = media_type;
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static char * __media_svc_get_title(MMHandleType tag, const char *filename)
+{
+ int ret = FILEINFO_ERROR_NONE;
+ char *p = NULL;
+ int size = 0;
+
+ if (tag) {
+ ret = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
+ if (ret == FILEINFO_ERROR_NONE && size > 0) {
+ while(p && isspace(*p))
+ p++;
+
+ return g_strdup(p);
+ }
+ }
+
+ return __media_svc_get_title_from_filename(filename);
+}
+
+char * _media_svc_get_title_from_filename(const char *filename)
+{
+ return __media_svc_get_title_from_filename(filename);
+}
+
+int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info)
+{
+ unsigned short orient_value = 0;
+ unsigned short exif_width = 0;
+ unsigned short exif_height = 0;
+ ExifData *ed = NULL;
+
+ media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid content_info");
+ media_svc_retvm_if(content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid media_type");
+ media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
+
+ content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
+
+ /* Load an ExifData object from an EXIF file */
+ ed = exif_data_new_from_file(content_info->path);
+ if (!ed) {
+ media_svc_sec_debug("There is no exif data in [ %s ]", content_info->path);
+ goto GET_WIDTH_HEIGHT;
+ }
+
+ content_info->media_meta.datetaken = __media_svc_get_exif_datetaken(ed);
+
+ if (__media_svc_get_exif_short(ed, EXIF_TAG_ORIENTATION, &orient_value)) {
+ if (orient_value <= ROT_270)
+ content_info->media_meta.orientation = orient_value;
+ }
+
+ if (__media_svc_get_exif_short(ed, EXIF_TAG_PIXEL_X_DIMENSION, &exif_width))
+ content_info->media_meta.width = (unsigned int)exif_width;
+
+ if (__media_svc_get_exif_short(ed, EXIF_TAG_PIXEL_Y_DIMENSION, &exif_height))
+ content_info->media_meta.height = (unsigned int)exif_height;
+
+ exif_data_unref(ed);
+
+GET_WIDTH_HEIGHT:
+ if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
+ /*Get image width, height*/
+ unsigned int img_width = 0;
+ unsigned int img_height = 0;
+
+ if (get_image_info(content_info->path, &img_width, &img_height) != THUMB_OK)
+ return MS_MEDIA_ERR_NONE;
+
+ if (content_info->media_meta.width == 0)
+ content_info->media_meta.width = img_width;
+
+ if (content_info->media_meta.height == 0)
+ content_info->media_meta.height = img_height;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static char * __media_svc_get_tag_str_value(MMHandleType tag, const char *tag_name)
+{
+ int ret = FILEINFO_ERROR_NONE;
+ char *p = NULL;
+ int size = 0;
+
+ ret = mm_file_get_attrs(tag, tag_name, &p, &size, NULL);
+ if (ret == FILEINFO_ERROR_NONE && size > 0)
+ return g_strdup(p);
+
+ return g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+}
+
+static char * __media_svc_extract_albumart(MMHandleType tag, const char *path, uid_t uid)
+{
+ int ret = FILEINFO_ERROR_NONE;
+ unsigned char *image = NULL;
+ unsigned int size = 0;
+ char *mimetype = NULL;
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = { 0, };
+ unsigned int mime_size = 0;
+
+ ret = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
+ media_svc_retvm_if(ret != FILEINFO_ERROR_NONE, NULL, "Failed to get tag artwork[%d]", ret);
+ media_svc_retvm_if(!image || size == 0, NULL, "Invalid artwork");
+
+ ret = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_MIME, &mimetype, &mime_size, NULL);
+ media_svc_retvm_if(ret != FILEINFO_ERROR_NONE, NULL, "Failed to get tag mime[%d]", ret);
+ media_svc_retvm_if(mime_size == 0, NULL, "Invalid mimetype");
+
+ ret = __media_svc_get_thumbnail_path(thumb_path, path, mimetype, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, NULL, "Failed to get thumbnail path");
+
+ ret = __media_svc_save_image(image, size, thumb_path, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, NULL, "Fail to save thumbnail");
+
+ return g_strdup(thumb_path);
+}
+
+void _media_svc_extract_audio_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
+{
+ MMHandleType tag = 0;
+ char *p = NULL;
+ unsigned int size = 0;
+ int mmf_error = FILEINFO_ERROR_NONE;
+ int album_id = 0;
+ int ret = MS_MEDIA_ERR_NONE;
+ bool support_albumart = ms_user_thumb_support(uid, content_info->path);
+
+ /*Get Content Tag attribute ===========*/
+ if (support_albumart)
+ mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
+ else
+ mmf_error = mm_file_create_tag_attrs_no_albumart(&tag, content_info->path);
+
+ if (mmf_error != FILEINFO_ERROR_NONE) {
+ content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
+ content_info->album_id = 0;
+ return;
+ }
+
+ content_info->media_meta.title = __media_svc_get_title(tag, content_info->file_name);
+ content_info->media_meta.album = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM);
+ content_info->media_meta.artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ARTIST);
+ content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST);
+ content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE);
+ content_info->media_meta.track_num = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_TRACK_NUM);
+
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL);
+ if (mmf_error == FILEINFO_ERROR_NONE && size == 4)
+ content_info->media_meta.year = g_strdup(p);
+ else
+ content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+
+ /*Do not extract artwork for the USB Storage content*/
+ if (support_albumart)
+ content_info->thumbnail_path = __media_svc_extract_albumart(tag, content_info->path, uid);
+
+ ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+ media_svc_debug("album does not exist. So start to make album art");
+ if (strlen(content_info->media_meta.album) > 0 && strlen(content_info->media_meta.artist) > 0)
+ ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
+ else
+ ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
+ }
+ content_info->album_id = album_id;
+
+ if (mm_file_destroy_tag_attrs(tag) != FILEINFO_ERROR_NONE)
+ media_svc_error("destroy failed");
+}
+
+void _media_svc_extract_video_metadata(media_svc_content_info_s *content_info)
+{
+ /* All metadata fields must be empty strings until media_video is deleted */
+ content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
+ content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+ content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+ content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+ content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+ content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+ content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+ content_info->album_id = 0;
+}
+
+static gchar * __media_svc_get_zipfile_string(zip_t *z, const char *fname)
+{
+ int err = 0;
+ zip_int64_t index_num = 0;
+ zip_file_t *file = NULL;
+ zip_stat_t sb = {0, };
+ gchar *buf = NULL;
+
+ media_svc_retvm_if(!z, NULL, "z is NULL");
+ media_svc_retvm_if(!fname, NULL, "fname is NULL");
+
+ index_num = zip_name_locate(z, fname, ZIP_FL_NOCASE);
+ media_svc_retvm_if(index_num == -1, NULL, "fname is not exists [%s]", fname);
+
+ err = zip_stat_index(z, index_num, ZIP_STAT_SIZE, &sb);
+ media_svc_retvm_if(err == -1, NULL, "zip_stat_index failed");
+
+ file = zip_fopen_index(z, index_num, ZIP_FL_UNCHANGED);
+ media_svc_retvm_if(!file, NULL, "zip_fopen_index failed");
+
+ buf = g_malloc0(sb.size + 1);
+
+ err = zip_fread(file, buf, sb.size);
+ zip_fclose(file);
+
+ if (err == -1) {
+ g_free(buf);
+ buf = NULL;
+ }
+
+ return buf;
+}
+
+static xmlNodePtr __media_svc_find_node(xmlNodePtr node, const char *key)
+{
+ xmlNodePtr tmp = NULL;
+
+ media_svc_retvm_if(!node, NULL, "node is NULL");
+ media_svc_retvm_if(!key, NULL, "key is NULL");
+
+ for (tmp = node->children; tmp; tmp = tmp->next) {
+ if (xmlIsBlankNode(tmp))
+ continue;
+
+ if (g_str_has_suffix((gchar *)tmp->name, key))
+ return tmp;
+ }
+
+ return NULL;
+}
+
+static char * __media_svc_remove_escape_c(const char *value)
+{
+ int start = -1;
+ int end = 0;
+ int len, i;
+
+ media_svc_retv_if(!value, NULL);
+
+ len = strlen(value);
+
+ for (i = 0; i < len; i++) {
+ if (value[i] != 10 && value[i] != 32) { // 10='\n' 32=' '
+ if (start == -1)
+ start = i;
+
+ end = i;
+ }
+ }
+
+ end = end - start + 1;
+
+ return g_strndup(value + start, end);
+}
+
+static char * __media_svc_find_and_get_value(xmlNodePtr node, const char *key)
+{
+ xmlNodePtr tmp = NULL;
+ char *tmp_res = NULL;
+ char *res = NULL;
+
+ media_svc_retvm_if(!node, NULL, "node is NULL");
+ media_svc_retvm_if(!key, NULL, "key is NULL");
+
+ for (tmp = node->children; tmp; tmp = tmp->next) {
+ if (xmlIsBlankNode(tmp))
+ continue;
+
+ if (tmp->children) {
+ tmp_res = __media_svc_find_and_get_value(tmp, key);
+ if (tmp_res) {
+ res = __media_svc_remove_escape_c(tmp_res);
+ xmlFree(tmp_res);
+ return res;
+ }
+ }
+
+ if (g_str_has_suffix((gchar *)tmp->name, key))
+ return (char *)xmlNodeGetContent(tmp);
+ }
+
+ return NULL;
+}
+
+static gboolean __media_svc_get_epub_root_file(zip_t *z, char **opf_file)
+{
+ gchar *buf = NULL;
+ gchar *tmp_buf = NULL;
+ xmlDocPtr doc = NULL;
+ xmlNodePtr node = NULL;
+
+ media_svc_retvm_if(!z, FALSE, "z is NULL");
+ media_svc_retvm_if(!opf_file, FALSE, "opf_file is NULL");
+
+ buf = __media_svc_get_zipfile_string(z, "META-INF/container.xml");
+ media_svc_retvm_if(!buf, FALSE, "buf is NULL");
+
+ tmp_buf = g_strrstr(buf, ">");
+ if (tmp_buf)
+ *(tmp_buf + 1) = '\0';
+
+ doc = xmlParseDoc((const xmlChar *)buf);
+ g_free(buf);
+ media_svc_retvm_if(!doc, FALSE, "doc is NULL");
+
+ node = xmlDocGetRootElement(doc);
+ node = __media_svc_find_node(node, "rootfiles");
+ node = __media_svc_find_node(node, "rootfile");
+
+ *opf_file = (char *)xmlGetProp(node, (const xmlChar *)"full-path");
+ media_svc_sec_debug("OPF [%s]", *opf_file);
+ xmlFreeDoc(doc);
+
+ return TRUE;
+}
+
+static gboolean __media_svc_get_xml_metadata(const xmlChar *buffer, gboolean is_pdf, media_svc_content_info_s *content_info)
+{
+ xmlDocPtr doc = NULL;
+ xmlNodePtr root = NULL;
+
+ media_svc_retvm_if(!buffer, FALSE, "buffer is NULL");
+ media_svc_retvm_if(!content_info, FALSE, "content_info is NULL");
+
+ doc = xmlParseDoc(buffer);
+ media_svc_retv_if(!doc, FALSE);
+
+ root = xmlDocGetRootElement(doc);
+ if (!root) {
+ xmlFreeDoc(doc);
+ return FALSE;
+ }
+
+ content_info->media_meta.title = __media_svc_find_and_get_value(root, "title");
+ /* In the case of PDF, if there is no title, it may not be a metadata block. Search for the next xml block*/
+ if (is_pdf && !content_info->media_meta.title) {
+ xmlFreeDoc(doc);
+ return FALSE;
+ }
+
+ content_info->media_meta.artist = __media_svc_find_and_get_value(root, "creator");
+ if (!content_info->media_meta.artist)
+ content_info->media_meta.artist = __media_svc_find_and_get_value(root, "author");
+ content_info->media_meta.genre = __media_svc_find_and_get_value(root, "subject");
+
+ xmlFreeDoc(doc);
+
+ return TRUE;
+}
+
+static int __media_svc_get_epub_metadata(media_svc_content_info_s *content_info)
+{
+ int err = 0;
+ zip_t *z = NULL;
+ gchar *buf = NULL;
+ char *opf_path = NULL;
+
+ media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content_info is NULL");
+
+ //1. open epub
+ z = zip_open(content_info->path, ZIP_RDONLY, &err);
+ media_svc_retvm_if(err == -1, MS_MEDIA_ERR_INTERNAL, "zip_open failed");
+
+ //2. find and read opf file
+ if (!__media_svc_get_epub_root_file(z, &opf_path)) {
+ media_svc_error("__media_svc_get_epub_root_file failed");
+ zip_close(z);
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ //3. get metadata
+ buf = __media_svc_get_zipfile_string(z, opf_path);
+ xmlFree(opf_path);
+ zip_close(z);
+ media_svc_retvm_if(!buf, MS_MEDIA_ERR_INTERNAL, "__media_svc_get_zipfile_string failed");
+
+ if (!__media_svc_get_xml_metadata((const xmlChar *)buf, FALSE, content_info))
+ media_svc_error("__media_svc_get_xml_metadata failed");
+
+ g_free(buf);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static int __media_svc_get_pdf_metadata(media_svc_content_info_s *content_info)
+{
+ int fd = 0;
+ int start_pos = 0;
+ int end_pos = 0;
+ int cur_pos = 0;
+ int search_limit = 0;
+ char tmp[MEDIA_SVC_PDF_BUF_SIZE + 1] = {0, };
+ gchar *meta_buf = NULL;
+ char *found = NULL;
+
+ media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content_info is NULL");
+ media_svc_retvm_if(content_info->size < 256, MS_MEDIA_ERR_INTERNAL, "open failed");
+
+ fd = open(content_info->path, O_RDONLY);
+ media_svc_retvm_if(fd < 0, MS_MEDIA_ERR_INTERNAL, "open failed");
+
+ search_limit = content_info->size - MEDIA_SVC_PDF_TAG_TAIL_LEN;
+
+ while (cur_pos <= search_limit) {
+ if (lseek(fd, cur_pos, SEEK_SET) == -1)
+ break;
+
+ memset(&tmp, 0x00, MEDIA_SVC_PDF_BUF_SIZE + 1);
+
+ if (read(fd, &tmp, MEDIA_SVC_PDF_BUF_SIZE) != MEDIA_SVC_PDF_BUF_SIZE) {
+ media_svc_error("read failed");
+ break;
+ }
+
+ //1.Find <x:xmpmeta .. </x:xmpmeta> block
+ if (start_pos == 0 && (found = strstr(tmp, "<x:xmpmeta"))) {
+ start_pos = cur_pos + (found - tmp);
+// media_svc_error("FIND START_POS[%d]", start_pos);
+ found = NULL;
+ }
+
+
+ if (start_pos != 0 && (found = strstr(tmp, "</x:xmpmeta>"))) {
+ end_pos = cur_pos + (found - tmp) + MEDIA_SVC_PDF_TAG_TAIL_LEN;
+// media_svc_error("FIND END_POS[%d]", end_pos);
+ found = NULL;
+ }
+
+ //2.get metadata using xml parser
+ if (start_pos && end_pos) {
+ if (lseek(fd, start_pos, SEEK_SET) == -1)
+ break;
+
+ meta_buf = g_malloc0(end_pos - start_pos + 1);
+
+ if (read(fd, meta_buf, end_pos - start_pos) == end_pos - start_pos) {
+ if (__media_svc_get_xml_metadata((const xmlChar *)meta_buf, TRUE, content_info)) {
+ g_free(meta_buf);
+ break;
+ }
+ }
+
+ g_free(meta_buf);
+
+ start_pos = 0;
+ end_pos = 0;
+ }
+
+ cur_pos += 240;
+
+ }
+
+ close(fd);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int _media_svc_extract_book_metadata(media_svc_content_info_s *content_info)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content info is NULL");
+
+ if (g_str_has_suffix(content_info->mime_type, "epub+zip"))
+ ret = __media_svc_get_epub_metadata(content_info);
+ else
+ ret = __media_svc_get_pdf_metadata(content_info);
+
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "failed to extract metadata");
+ if (!content_info->media_meta.title || strlen(content_info->media_meta.title) == 0) {
+ g_free(content_info->media_meta.title);
+ content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
+{
+ media_svc_retm_if(!content_info, "content info is NULL");
+
+ /* Delete media_svc_content_info_s */
+ g_free(content_info->media_uuid);
+ g_free(content_info->path);
+ g_free(content_info->file_name);
+ g_free(content_info->mime_type);
+ g_free(content_info->thumbnail_path);
+ g_free(content_info->storage_uuid);
+
+ /* Delete media_svc_content_meta_s */
+ g_free(content_info->media_meta.title);
+ g_free(content_info->media_meta.album);
+ g_free(content_info->media_meta.artist);
+ g_free(content_info->media_meta.album_artist);
+ g_free(content_info->media_meta.genre);
+ g_free(content_info->media_meta.year);
+ g_free(content_info->media_meta.track_num);
+ g_free(content_info->media_meta.datetaken);
+}
+
+int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ media_svc_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
+ media_svc_retvm_if(!thumb_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid thumb_path");
+ media_svc_retvm_if(!g_file_test(path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "File doesn't exist[%s]", path);
+
+ if (!ms_user_thumb_support(uid, path)) {
+ media_svc_sec_error("origin path(%s) is invalid", path);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ media_svc_sec_debug("Path[%s] Type[%d]", path, media_type);
+
+ //1. make thumb path
+ ret = __media_svc_get_thumbnail_path(thumb_path, path, NULL, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Failed to create thumbnail path[%d]", ret);
+
+ //2. save thumbnail
+ if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
+ ret = create_image_thumbnail_to_file(path, MEDIA_SVC_THUMB_WIDTH, MEDIA_SVC_THUMB_HEIGHT, thumb_path, true);
+ else
+ ret = create_video_thumbnail_to_file(path, MEDIA_SVC_THUMB_WIDTH, MEDIA_SVC_THUMB_HEIGHT, thumb_path, true);
+
+ return (ret == THUMB_OK) ? MS_MEDIA_ERR_NONE : MS_MEDIA_ERR_INTERNAL;
+}
+
+int _media_svc_get_media_type(const char *path, int *mediatype)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char mime_type[256] = {0};
+ media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
+
+ media_svc_retvm_if(mediatype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mediatype is NULL");
+
+ ret = __media_svc_get_mime_type(path, mime_type);
+ if (ret == MS_MEDIA_ERR_NONE)
+ __media_svc_get_media_type(path, mime_type, &media_type);
+ else
+ media_svc_error("__media_svc_get_mime_type failed");
+
+ *mediatype = media_type;
+
+ return ret;
+}
+
+bool _media_svc_is_keyword_included(const char *path, const char *keyword)
+{
+ bool ret = false;
+ void *handle = NULL;
+ bool (*svc_search) (const char *, const char *);
+
+ media_svc_retvm_if(!path, false, "Invalid path");
+ media_svc_retvm_if(!keyword, false, "Invalid keyword");
+
+ handle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY);
+ media_svc_retvm_if(!handle, false, "dlopen failed");
+
+ if (g_str_has_suffix(path, "epub") || g_str_has_suffix(path, "EPUB"))
+ svc_search = dlsym(handle, "media_svc_epub_is_keyword_included");
+ else
+ svc_search = dlsym(handle, "media_svc_pdf_is_keyword_included");
+
+ if (!svc_search) {
+ media_svc_error("dlsym failed - %s", dlerror());
+ dlclose(handle);
+ return false;
+ }
+
+ ret = svc_search(path, keyword);
+ dlclose(handle);
+
+ return ret;
+}
+
+static int __media_svc_create_wordbook_db(const char *path, sqlite3 **handle)
+{
+ int ret = SQLITE_OK;
+ sqlite3 *db_handle = NULL;
+ char *err = NULL;
+
+ ret = sqlite3_open_v2(path, &db_handle, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
+ media_svc_retvm_if(ret != SQLITE_OK, ret, "sqlite3_open_v2 failed : %d", ret);
+
+ ret = sqlite3_exec(db_handle, "PRAGMA journal_mode = OFF;", NULL, NULL, &err);
+ if (ret != SQLITE_OK)
+ goto ERROR;
+
+ ret = sqlite3_exec(db_handle, "CREATE TABLE IF NOT EXISTS files(id integer primary key autoincrement, path text unique, validity integer default 1);", NULL, NULL, &err);
+ if (ret != SQLITE_OK)
+ goto ERROR;
+
+ ret = sqlite3_exec(db_handle, "CREATE TABLE IF NOT EXISTS words(file_id integer, word text, frequency integer default 1, unique(file_id, word));", NULL, NULL, &err);
+ if (ret != SQLITE_OK)
+ goto ERROR;
+
+ ret = sqlite3_exec(db_handle, "CREATE TRIGGER IF NOT EXISTS TR_files_words DELETE ON files BEGIN DELETE FROM words WHERE file_id = old.id;END;", NULL, NULL, &err);
+ if (ret != SQLITE_OK)
+ goto ERROR;
+
+ *handle = db_handle;
+
+ return SQLITE_OK;
+
+ERROR:
+ media_svc_error("sqlite3_exec failed : %s", err);
+ SQLITE3_SAFE_FREE(err);
+ sqlite3_close_v2(db_handle);
+
+ return ret;
+}
+
+static bool __media_svc_get_wordbook_handle(uid_t uid, sqlite3 **handle)
+{
+ int ret = SQLITE_OK;
+ char *db_path = NULL;
+
+ ms_user_get_wordbook_db_path(uid, &db_path);
+ if (!db_path)
+ return false;
+
+ ret = sqlite3_open_v2(db_path, handle, SQLITE_OPEN_READWRITE, NULL);
+ if (ret != SQLITE_OK) {
+ ret = __media_svc_create_wordbook_db(db_path, handle);
+ free(db_path);
+ media_svc_retvm_if(ret != SQLITE_OK, false, "__media_svc_create_wordbook_db failed : %d", ret);
+ } else {
+ ret = sqlite3_exec(*handle, "PRAGMA journal_mode = OFF;", NULL, NULL, NULL);
+ if (ret != SQLITE_OK)
+ media_svc_error("Failed to change journal mode [%d]", ret);
+ }
+
+ return true;
+}
+
+static bool __media_svc_is_exist_in_wordbook(sqlite3 *db_handle, const char *path)
+{
+ int ret = SQLITE_OK;
+ char *err = NULL;
+ char *query = NULL;
+
+ query = sqlite3_mprintf("UPDATE files SET validity=1 WHERE path = %Q", path);
+
+ ret = sqlite3_exec(db_handle, query, NULL, NULL, &err);
+ SQLITE3_SAFE_FREE(query);
+ if (ret != SQLITE_OK) {
+ media_svc_error("Query failed. [%s]", err);
+ SQLITE3_SAFE_FREE(err);
+ return false;
+ }
+
+ return sqlite3_changes(db_handle) > 0 ? true : false;
+}
+
+static void __media_svc_insert_to_wordbook(sqlite3 *db_handle, const char *path)
+{
+ void *handle = NULL;
+ void (*svc_update) (sqlite3 *, const char *);
+ char *query = NULL;
+
+ query = sqlite3_mprintf("INSERT INTO files(path) VALUES(%Q);", path);
+ sqlite3_exec(db_handle, query, NULL, NULL, NULL);
+ sqlite3_free(query);
+
+ handle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY);
+ if (!handle) {
+ media_svc_error("dlopen failed");
+ return;
+ }
+
+ if (g_str_has_suffix(path, "epub") || g_str_has_suffix(path, "EPUB"))
+ svc_update = dlsym(handle, "media_svc_epub_insert_to_db");
+ else
+ svc_update = dlsym(handle, "media_svc_pdf_insert_to_db");
+
+ if (!svc_update) {
+ media_svc_error("dlsym failed - %s", dlerror());
+ dlclose(handle);
+ return;
+ }
+
+ svc_update(db_handle, path);
+ dlclose(handle);
+}
+
+void _media_svc_update_wordbook(const char *path, uid_t uid)
+{
+ sqlite3 *db_handle = NULL;
+
+ if (!path) {
+ media_svc_error("Invalid path");
+ return;
+ }
+
+ // check db..
+ if (!__media_svc_get_wordbook_handle(uid, &db_handle))
+ return;
+
+ if (__media_svc_is_exist_in_wordbook(db_handle, path)) {
+ sqlite3_close_v2(db_handle);
+ return;
+ }
+
+ // if no item, insert to db..
+ __media_svc_insert_to_wordbook(db_handle, path);
+ sqlite3_close_v2(db_handle);
+}
+
+void _media_svc_clean_wordbook(uid_t uid)
+{
+ sqlite3 *db_handle = NULL;
+
+ if (!__media_svc_get_wordbook_handle(uid, &db_handle))
+ return;
+
+ sqlite3_exec(db_handle, "DELETE FROM files where validity = 0;", NULL, NULL, NULL);
+ sqlite3_exec(db_handle, "UPDATE files SET validity = 0;", NULL, NULL, NULL);
+ sqlite3_close_v2(db_handle);
+}
+
+bool _media_svc_get_matched_list(const char *keyword, uid_t uid, GList **list)
+{
+ int ret = SQLITE_OK;
+ sqlite3 *handle = NULL;
+ sqlite3_stmt *stmt = NULL;
+ char *query = NULL;
+
+ media_svc_retvm_if(!list, false, "list is NULL");
+ media_svc_retvm_if(!keyword, false, "keyword is NULL");
+ media_svc_retvm_if(!__media_svc_get_wordbook_handle(uid, &handle), false, "Failed to get handle");
+
+ query = sqlite3_mprintf("SELECT files.path FROM files JOIN (SELECT file_id, sum(frequency) AS freq_sum FROM words WHERE word LIKE '%q%%' GROUP BY file_id ORDER BY freq_sum DESC) w ON files.id = w.file_id;", keyword);
+ ret = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
+ SQLITE3_SAFE_FREE(query);
+
+ if (ret != SQLITE_OK) {
+ media_svc_error("Query failed[%d]", ret);
+ sqlite3_close_v2(handle);
+ return false;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW)
+ *list = g_list_append(*list, g_strdup((char *)sqlite3_column_text(stmt, 0)));
+
+ sqlite3_finalize(stmt);
+ sqlite3_close_v2(handle);
+
+ return true;
+}
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 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 "media-svc-media.h"
+#include "media-svc-debug.h"
+#include "media-svc-util.h"
+#include "media-svc-db-utils.h"
+#include "media-svc-env.h"
+#include "media-svc-media-folder.h"
+#include "media-svc-album.h"
+#include "media-svc-noti.h"
+#include "media-svc-storage.h"
+
+#include <iniparser.h>
+
+#define CONTENT_INI_DEFAULT_PATH SYSCONFDIR"/multimedia/media_content_config.ini"
+
+//static __thread int g_media_svc_data_cnt = 0;
+static __thread int g_media_svc_cur_data_cnt = 0;
+
+/* Flag for items to be published by notification */
+static __thread bool g_insert_with_noti = false;
+
+#define BATCH_ITEM_COUNT_MAX 100
+
+int media_svc_check_table_exist(sqlite3 *handle, bool *exist)
+{
+ return _media_svc_check_table_exist(handle, exist);
+}
+
+int media_svc_create_table(uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ media_svc_debug_fenter();
+
+ ret = _media_svc_init_table_query();
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_init_table_query fail.");
+ goto ERROR;
+ }
+
+ /*create media table*/
+ ret = _media_svc_make_table_query(DB_TABLE_MEDIA, DB_LIST_MEDIA, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_make_table_query fail.");
+ goto ERROR;
+ }
+
+ /*create folder table*/
+ ret = _media_svc_make_table_query(DB_TABLE_FOLDER, DB_LIST_FOLDER, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_make_table_query fail.");
+ goto ERROR;
+ }
+
+ /*create playlist_map table*/
+ ret = _media_svc_make_table_query(DB_TABLE_PLAYLIST_MAP, DB_LIST_PLAYLIST_MAP, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_make_table_query fail.");
+ goto ERROR;
+ }
+
+ /*create playlist table*/
+ ret = _media_svc_make_table_query(DB_TABLE_PLAYLIST, DB_LIST_PLAYLIST, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_make_table_query fail.");
+ goto ERROR;
+ }
+
+ /* create album table*/
+ ret = _media_svc_make_table_query(DB_TABLE_ALBUM, DB_LIST_ALBUM, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_make_table_query fail.");
+ goto ERROR;
+ }
+
+ /*create tag_map table*/
+ ret = _media_svc_make_table_query(DB_TABLE_TAG_MAP, DB_LIST_TAG_MAP, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_make_table_query fail.");
+ goto ERROR;
+ }
+
+ /*create tag table*/
+ ret = _media_svc_make_table_query(DB_TABLE_TAG, DB_LIST_TAG, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_make_table_query fail.");
+ goto ERROR;
+ }
+
+ /*create bookmark table*/
+ ret = _media_svc_make_table_query(DB_TABLE_BOOKMARK, DB_LIST_BOOKMARK, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_make_table_query fail.");
+ goto ERROR;
+ }
+
+ /*create storage table from tizen 2.4 */
+ ret = _media_svc_make_table_query(DB_TABLE_STORAGE, DB_LIST_STORAGE, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_make_table_query fail.");
+ goto ERROR;
+ }
+
+ /*create face table. from tizen 3.0*/
+ ret = _media_svc_make_table_query(DB_TABLE_FACE_SCAN_LIST, DB_LIST_FACE_SCAN_LIST, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_make_table_query fail.");
+ goto ERROR;
+ }
+
+ ret = _media_svc_make_table_query(DB_TABLE_FACE, DB_LIST_FACE, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_make_table_query fail.");
+ goto ERROR;
+ }
+ERROR:
+ _media_svc_destroy_table_query();
+
+ media_svc_debug_fleave();
+
+ return ret;
+}
+
+int media_svc_check_item_exist_by_path(sqlite3 *handle, const char *storage_id, const char *path)
+{
+ return _media_svc_check_data_by_path(handle, path);
+}
+
+int media_svc_get_modified_time(sqlite3 *handle, const char *storage_id, const char *path, int *modified_time)
+{
+ return _media_svc_get_modified_time(handle, path, modified_time);
+}
+
+int media_svc_insert_item_begin(bool with_noti, int from_pid)
+{
+ g_media_svc_cur_data_cnt = 0;
+
+ /* Prepare for making noti item list */
+ if (with_noti) {
+ media_svc_debug("making noti list from pid[%d]", from_pid);
+ _media_svc_initialize_noti_list();
+ _media_svc_set_noti_from_pid(from_pid);
+ g_insert_with_noti = true;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int media_svc_insert_item_end(uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ media_svc_debug_fenter();
+
+ if (g_media_svc_cur_data_cnt > 0) {
+ ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
+ if (g_insert_with_noti) {
+ media_svc_debug("sending noti list");
+ _media_svc_publish_noti_list();
+ g_insert_with_noti = false;
+ _media_svc_set_noti_from_pid(-1);
+ }
+ }
+
+ g_media_svc_cur_data_cnt = 0;
+
+ return ret;
+}
+
+int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ long long int folder_id = 0;
+
+ media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ media_svc_content_info_s content_info = { 0, };
+
+ /*Set media info*/
+ ret = _media_svc_set_media_info(&content_info, storage_id, path, false);
+ if (ret != MS_MEDIA_ERR_NONE)
+ return ret;
+
+ switch (content_info.media_type) {
+ case MEDIA_SVC_MEDIA_TYPE_IMAGE:
+ ret = _media_svc_extract_image_metadata(&content_info);
+ break;
+ case MEDIA_SVC_MEDIA_TYPE_VIDEO:
+ _media_svc_extract_video_metadata(&content_info);
+ break;
+ case MEDIA_SVC_MEDIA_TYPE_SOUND:
+ case MEDIA_SVC_MEDIA_TYPE_MUSIC:
+ _media_svc_extract_audio_metadata(handle, true, &content_info, uid);
+ break;
+ case MEDIA_SVC_MEDIA_TYPE_BOOK:
+ ret = _media_svc_extract_book_metadata(&content_info);
+ break;
+ default:
+ /* The 'TITLE' should always be filled in */
+ content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
+ break;
+ }
+
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
+
+ /*Set or Get folder id*/
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, true, storage_id, path, &folder_id, uid);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
+
+ content_info.folder_id = folder_id;
+ media_svc_retv_del_if(content_info.folder_id <= 0, MS_MEDIA_ERR_INTERNAL, &content_info);
+
+ ret = _media_svc_insert_item_stack(&content_info);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
+
+ if (g_insert_with_noti)
+ _media_svc_insert_item_to_noti_list(&content_info);
+
+ /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
+ if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
+ ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
+
+ if (g_insert_with_noti)
+ _media_svc_publish_noti_list();
+
+ g_media_svc_cur_data_cnt = 0;
+ }
+
+ _media_svc_destroy_content_info(&content_info);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ long long int folder_id = 0;
+
+ media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ media_svc_content_info_s content_info = { 0, };
+
+ /*Set media info*/
+ ret = _media_svc_set_media_info(&content_info, storage_id, path, false);
+ if (ret != MS_MEDIA_ERR_NONE)
+ return ret;
+
+ switch (content_info.media_type) {
+ case MEDIA_SVC_MEDIA_TYPE_IMAGE:
+ ret = _media_svc_extract_image_metadata(&content_info);
+ break;
+ case MEDIA_SVC_MEDIA_TYPE_VIDEO:
+ _media_svc_extract_video_metadata(&content_info);
+ break;
+ case MEDIA_SVC_MEDIA_TYPE_SOUND:
+ case MEDIA_SVC_MEDIA_TYPE_MUSIC:
+ _media_svc_extract_audio_metadata(handle, false, &content_info, uid);
+ break;
+ case MEDIA_SVC_MEDIA_TYPE_BOOK:
+ ret = _media_svc_extract_book_metadata(&content_info);
+ break;
+ default:
+ /* The 'TITLE' should always be filled in */
+ content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
+ break;
+ }
+
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
+
+ /*Set or Get folder id*/
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, false, storage_id, path, &folder_id, uid);
+ media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
+
+ content_info.folder_id = folder_id;
+ media_svc_retv_del_if(content_info.folder_id <= 0, MS_MEDIA_ERR_INTERNAL, &content_info);
+
+ /* Extracting thumbnail */
+ if (content_info.thumbnail_path == NULL) {
+ if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
+
+ ret = _media_svc_create_thumbnail(content_info.path, thumb_path, content_info.media_type, uid);
+ if (ret == MS_MEDIA_ERR_NONE)
+ content_info.thumbnail_path = g_strdup(thumb_path);
+ }
+ }
+
+ ret = _media_svc_insert_item(&content_info, uid);
+ if (ret == MS_MEDIA_ERR_NONE) {
+ media_svc_debug("Insertion is successful. Sending noti for this");
+ _media_svc_publish_noti(MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
+ } else if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
+ media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
+ }
+
+ _media_svc_destroy_content_info(&content_info);
+ return ret;
+}
+
+int media_svc_move_item(sqlite3 *handle,
+ const char *src_path,
+ const char *dest_path,
+ const char *media_id,
+ int media_type,
+ const char *mime_type,
+ uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char *file_name = NULL;
+ char *folder_path = NULL;
+ int modified_time = 0;
+ long long int folder_id = 0;
+ char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
+ char dst_stg_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
+
+ media_svc_debug_fenter();
+
+ media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
+ media_svc_retvm_if(!STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
+ media_svc_retvm_if(!STRING_VALID(media_id), MS_MEDIA_ERR_INVALID_PARAMETER, "media_id is NULL");
+ media_svc_retvm_if(!STRING_VALID(mime_type), MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is NULL");
+
+ /* Get storage_id */
+ ret = _media_svc_get_storage_uuid(handle, dest_path, dst_stg_id, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ /*check and update folder*/
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, false, dst_stg_id, dest_path, &folder_id, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ /*get filename*/
+ file_name = g_path_get_basename(dest_path);
+
+ /*get modified_time*/
+ modified_time = _media_svc_get_file_time(dest_path);
+
+ /*get old thumbnail_path and remove thumbnail */
+ ret = _media_svc_get_thumbnail_path_by_path(handle, src_path, old_thumb_path);
+ if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
+ media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
+ g_free(file_name);
+ return ret;
+ }
+
+ _media_svc_remove_file(old_thumb_path);
+
+ /*move item*/
+ ret = _media_svc_update_item_by_path(src_path, dst_stg_id, dest_path, file_name, modified_time, folder_id, uid);
+ g_free(file_name);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ media_svc_debug("Move is successful. Sending noti for this");
+ _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, src_path, media_type, media_id, mime_type);
+
+ /*update folder modified_time*/
+ folder_path = g_path_get_dirname(dest_path);
+ ret = _media_svc_update_folder_modified_time(folder_path, uid);
+ g_free(folder_path);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int media_svc_set_item_validity(const char *path, int validity, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ ret = _media_svc_update_item_validity(path, validity, true, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
+ if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
+ ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ g_media_svc_cur_data_cnt = 0;
+ }
+
+ return ret;
+}
+
+int media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
+ media_svc_noti_item *noti_item = NULL;
+
+ media_svc_debug_fenter();
+
+ /*Get thumbnail path to delete*/
+ ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
+ media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
+
+ /* Get notification info */
+ ret = _media_svc_get_noti_info(handle, path, ¬i_item);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ /*Delete item*/
+ ret = _media_svc_delete_item_by_path(path, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
+ _media_svc_destroy_noti_item(noti_item);
+
+ return ret;
+ }
+
+ /* Send notification */
+ media_svc_debug("Deletion is successful. Sending noti for this");
+ _media_svc_publish_noti(MS_MEDIA_ITEM_DELETE, path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
+ _media_svc_destroy_noti_item(noti_item);
+
+ /*Delete thumbnail*/
+ _media_svc_remove_file(thumb_path);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
+ media_svc_content_info_s content_info = {0, };
+ media_svc_noti_item *noti_item = NULL;
+
+ media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ /*Set media info*/
+ ret = _media_svc_set_media_info(&content_info, NULL, path, true);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+
+ /* Initialize thumbnail information to remake thumbnail. */
+ ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
+ if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD)
+ goto REFRESH_FINALIZE;
+
+ if (strlen(thumb_path) > 0) {
+ _media_svc_remove_file(thumb_path);
+
+ ret = _media_svc_update_thumbnail_path(path, NULL, uid);
+ if (ret != MS_MEDIA_ERR_NONE)
+ goto REFRESH_FINALIZE;
+ }
+
+ /* Get notification info */
+ ret = _media_svc_get_noti_info(handle, path, ¬i_item);
+ if (ret != MS_MEDIA_ERR_NONE)
+ goto REFRESH_FINALIZE;
+
+ content_info.media_type = noti_item->media_type;
+ content_info.mime_type = g_strdup(noti_item->mime_type);
+
+ switch (content_info.media_type) {
+ case MEDIA_SVC_MEDIA_TYPE_IMAGE:
+ ret = _media_svc_extract_image_metadata(&content_info);
+ break;
+ case MEDIA_SVC_MEDIA_TYPE_VIDEO:
+ _media_svc_extract_video_metadata(&content_info);
+ break;
+ case MEDIA_SVC_MEDIA_TYPE_SOUND:
+ case MEDIA_SVC_MEDIA_TYPE_MUSIC:
+ _media_svc_extract_audio_metadata(handle, is_direct, &content_info, uid);
+ break;
+ case MEDIA_SVC_MEDIA_TYPE_BOOK:
+ ret = _media_svc_extract_book_metadata(&content_info);
+ break;
+ default:
+ /* The 'TITLE' should always be filled in */
+ content_info.media_meta.title = _media_svc_get_title_from_filename(content_info.file_name);
+ break;
+ }
+
+ if (ret != MS_MEDIA_ERR_NONE)
+ goto REFRESH_FINALIZE;
+
+ /* Extracting thumbnail */
+ if (content_info.thumbnail_path == NULL) {
+ if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+ memset(thumb_path, 0, sizeof(thumb_path));
+
+ ret = _media_svc_create_thumbnail(content_info.path, thumb_path, content_info.media_type, uid);
+ if (ret == MS_MEDIA_ERR_NONE)
+ content_info.thumbnail_path = g_strdup(thumb_path);
+ }
+ }
+
+ ret = _media_svc_update_item_with_data(is_direct, &content_info, uid);
+
+ if (ret == MS_MEDIA_ERR_NONE) {
+ if (is_direct) {
+ /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
+ if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
+ ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
+ if (ret != MS_MEDIA_ERR_NONE)
+ goto REFRESH_FINALIZE;
+
+ g_media_svc_cur_data_cnt = 0;
+ }
+ } else {
+ /* Except scanner case */
+ media_svc_debug("Update is successful. Sending noti for this");
+ _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
+ }
+ } else {
+ media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
+ }
+
+REFRESH_FINALIZE:
+ _media_svc_destroy_content_info(&content_info);
+ _media_svc_destroy_noti_item(noti_item);
+
+ return ret;
+}
+
+int media_svc_send_dir_update_noti(const char *dir_path, const char *folder_id, int update_type, int pid)
+{
+ media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
+
+ return _media_svc_publish_dir_noti((media_item_update_type_e)update_type, dir_path, folder_id, pid);
+}
+
+int media_svc_publish_update_noti(const char *path, int media_type, const char *uuid, const char *mime_type)
+{
+ return _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, path, media_type, uuid, mime_type);
+}
+
+int media_svc_set_storage_validity(const char *storage_id, int validity, uid_t uid)
+{
+ return _media_svc_update_storage_validity(storage_id, validity, uid);
+}
+
+int media_svc_get_storage_id(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
+{
+ return _media_svc_get_storage_uuid(handle, path, storage_id, uid);
+}
+
+int media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity)
+{
+ return _media_svc_check_storage(handle, storage_id, storage_path, validity);
+}
+
+int media_svc_update_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
+{
+ return _media_svc_update_storage_path(handle, storage_id, storage_path, uid);
+}
+
+int media_svc_insert_storage(sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+ media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
+
+ ret = _media_svc_append_storage(storage_id, storage_path, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
+
+ /* Remove external storage that validity is 0 */
+ ret = _media_svc_delete_invalid_storage(handle, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Delete invalid storage failed : %d", ret);
+
+ return ret;
+}
+
+int media_svc_insert_folder(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
+{
+ media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ return _media_svc_append_by_folder_path(handle, storage_id, path, uid);
+}
+
+int media_svc_set_folder_validity(const char *start_path, int validity, bool is_recursive, uid_t uid)
+{
+ return _media_svc_set_folder_validity(true, start_path, validity, is_recursive, uid);
+}
+
+int media_svc_check_folder_exist_by_path(sqlite3 *handle, const char *folder_path)
+{
+ return _media_svc_check_folder_by_path(handle, folder_path);
+}
+
+int media_svc_append_query(const char *query, uid_t uid)
+{
+ return _media_svc_append_query_list(query, uid);
+}
+
+int media_svc_send_query(uid_t uid)
+{
+ return _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
+}
+
+int media_svc_get_media_type(const char *path, int *mediatype)
+{
+ return _media_svc_get_media_type(path, mediatype);
+}
+
+int media_svc_create_thumbnail(const char *file_path, int media_type, uid_t uid, char **thumbnail_path)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = { 0, };
+ char *sql = NULL;
+
+ // 1. Check media type
+ if (media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE && media_type != MEDIA_SVC_MEDIA_TYPE_VIDEO)
+ return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
+
+ // 2. try to create thumbnail
+ ret = _media_svc_create_thumbnail(file_path, thumb_path, media_type, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Failed to create thumbnail [%d]", ret);
+ if (ret == MS_MEDIA_ERR_THUMB_UNSUPPORTED)
+ return ret;
+ }
+
+ // 3. Update creation result to media db
+ sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path='%q' WHERE media_path='%q';", DB_TABLE_MEDIA, thumb_path, file_path);
+
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Failed to update media db [%d]", ret);
+ *thumbnail_path = g_strdup("");
+ } else {
+ *thumbnail_path = g_strdup(thumb_path);
+ }
+
+ return ret;
+}
+
+static int __media_svc_get_ebook_search_type(void)
+{
+ dictionary *dict = NULL;
+ static int _ebook_search_type = -1;
+
+ if (_ebook_search_type == -1) {
+ dict = iniparser_load(CONTENT_INI_DEFAULT_PATH);
+ if (!dict) {
+ media_svc_error("%s load failed. Use direct search.", CONTENT_INI_DEFAULT_PATH);
+ return MEDIA_SVC_SEARCH_TYPE_DIRECT;
+ }
+
+ _ebook_search_type = iniparser_getint(dict, "media-content-config:ebook_search_type", 0);
+ media_svc_debug("ebook_search_type [%d]", _ebook_search_type);
+
+ iniparser_freedict(dict);
+ }
+
+ return _ebook_search_type;
+}
+
+int media_svc_get_book_by_keyword(sqlite3 *handle, const char *keyword, uid_t uid, GList **result)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ GList *item_list = NULL;
+ GList *iter = NULL;
+ char *query = NULL;
+
+ media_svc_retvm_if(!handle, MS_MEDIA_ERR_INVALID_PARAMETER, "db handle is NULL");
+ media_svc_retvm_if(!keyword, MS_MEDIA_ERR_INVALID_PARAMETER, "keyword is NULL");
+ media_svc_retvm_if(!result, MS_MEDIA_ERR_INVALID_PARAMETER, "result is NULL");
+
+ query = sqlite3_mprintf("SELECT media_path FROM %q WHERE media_type=%d AND validity=1;",
+ DB_TABLE_MEDIA, MEDIA_SVC_MEDIA_TYPE_BOOK);
+
+ ret = _media_svc_get_media(handle, query, &item_list);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_media failed");
+
+ if (__media_svc_get_ebook_search_type() == MEDIA_SVC_SEARCH_TYPE_DB) {
+ for (iter = item_list; iter; iter = g_list_next(iter))
+ _media_svc_update_wordbook((char *)iter->data, uid);
+
+ _media_svc_clean_wordbook(uid);
+
+ if (!_media_svc_get_matched_list(keyword, uid, result))
+ media_svc_error("_media_svc_get_matched_list failed");
+ } else {
+ for (iter = item_list; iter; iter = g_list_next(iter)) {
+ if (_media_svc_is_keyword_included((char *)iter->data, keyword))
+ *result = g_list_append(*result, g_strdup((gchar *)iter->data));
+ }
+ }
+
+ g_list_free_full(item_list, g_free);
+
+ return ret;
+}
+
+int media_svc_check_db(sqlite3 *handle, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ bool exist = false;
+
+ ret = media_svc_check_table_exist(handle, &exist);
+ if (ret != MS_MEDIA_ERR_NONE)
+ return ret;
+
+ if (!exist)
+ ret = media_svc_create_table(uid);
+
+ return ret;
+}
\ No newline at end of file