Modify media_svc_publish_noti
[platform/core/api/media-content.git] / src / media_content.c
index 8d20d33..7550c65 100644 (file)
 * limitations under the License.
 */
 
-
 #include <media_info_private.h>
 #include <media_util_private.h>
+#include <mntent.h>
+#include <tzplatform_config.h>
 
 static sqlite3 *db_handle = NULL;
 static int ref_count = 0;
@@ -108,7 +109,6 @@ int _content_error_capi(int internal_error)
                return MEDIA_CONTENT_ERROR_NETWORK;
        case MS_MEDIA_ERR_PERMISSION_DENIED:
                return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
-       case MS_MEDIA_ERR_THUMB_TOO_BIG:
        case MS_MEDIA_ERR_THUMB_UNSUPPORTED:
                return MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT;
        default:
@@ -223,17 +223,10 @@ int media_content_scan_file(const char *path)
                /* check feature */
                content_retvm_if(!_media_util_check_support_media_type(path), MEDIA_CONTENT_ERROR_NOT_SUPPORTED, "Unsupported media type");
 
-               ms_user_storage_type_e storage_type;
-
-               ret = ms_user_get_storage_type(_content_get_uid(), path, &storage_type);
-               if (ret != MS_MEDIA_ERR_NONE) {
-                       content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, path);
-                       return _content_error_capi(ret);
-               }
                ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, path);
                if (ret == MS_MEDIA_ERR_NONE) {
                        /* Refresh */
-                       ret = media_svc_refresh_item(_content_get_db_handle(), false, storage_id, storage_type, path, _content_get_uid());
+                       ret = media_svc_refresh_item(_content_get_db_handle(), false, storage_id, path, _content_get_uid());
                        if (ret != MS_MEDIA_ERR_NONE) {
                                content_error("media_svc_refresh_item failed : %d", ret);
                                return _content_error_capi(ret);
@@ -241,7 +234,7 @@ int media_content_scan_file(const char *path)
 
                } else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
                        /* Insert */
-                       ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, path, _content_get_uid());
+                       ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, path, _content_get_uid());
                        if (ret != MS_MEDIA_ERR_NONE) {
                                if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
                                        content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path);
@@ -345,7 +338,6 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
        char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
-       ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
 
        content_retip_if_fail(STRING_VALID(path));
        content_retip_if_fail(callback);
@@ -359,10 +351,9 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co
        } else {
                /* This means this folder has to be deleted */
                /* Or, it is real invalid path.. check storage type */
-               ret = ms_user_get_storage_type(_content_get_uid(), path, &storage_type);
-               if (ret != MS_MEDIA_ERR_NONE) {
-                       content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, path);
-                       return _content_error_capi(ret);
+               if (!ms_user_is_valid_path(_content_get_uid(), path)) {
+                       content_sec_error("ms_user_is_valid_path failed : %d (%s)", ret, path);
+                       return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
                }
 
                content_debug("This path doesn't exists in file system... So will be deleted it from DB");
@@ -390,6 +381,42 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co
 }
 
 #ifdef _USE_TVPD_MODE
+bool _is_mounted(const char *dir_path)
+{
+       bool ret = false;
+       char mount_path[MAX_PATH_LEN] = {0,};
+       char root_path[MAX_PATH_LEN] = {0,};
+       struct mntent *mnt;
+       const char *table = "/etc/mtab";
+       FILE *fp;
+
+       snprintf(root_path, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_SYS_STORAGE), "/USBDrive");
+       if (!g_str_has_prefix(dir_path, root_path))
+               return true;
+
+       char *p = strstr(dir_path + strlen(root_path), "/");
+       if(p && p - dir_path < MAX_PATH_LEN)
+               strncpy(mount_path, dir_path, p - dir_path);
+       else
+               snprintf(mount_path, MAX_PATH_LEN, "%s", dir_path);
+
+       fp = setmntent(table, "r");
+       if (!fp) {
+               content_error("open /etc/mtab failed");
+               return false;
+       }
+       while ((mnt = getmntent(fp))) {
+               if (!strncmp(mnt->mnt_dir, mount_path, strlen(mount_path))) {
+                       ret = true;
+                       break;
+               }
+       }
+       endmntent(fp);
+
+       content_error("[NO ERROR] dir_path[%s] mount_path[%s] ret[%d]", dir_path, mount_path, ret);
+       return ret;
+}
+
 int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan_completed_cb_v2 callback, void *user_data)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
@@ -398,6 +425,7 @@ int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan
        content_retip_if_fail(STRING_VALID(path));
        content_retip_if_fail(callback);
 
+       content_retvm_if(!_is_mounted(path), MEDIA_CONTENT_ERROR_PERMISSION_DENIED, "path is not mounted");
        content_retvm_if(_media_util_is_ignorable_dir(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
 
        ret = _media_content_check_dir(path);
@@ -429,7 +457,7 @@ int media_content_cancel_scan_folder(const char *path)
 
        ret = media_directory_scanning_cancel(path, _content_get_uid());
        if (ret != MS_MEDIA_ERR_NONE)
-               content_error("media_directory_scanning_async failed : %d", ret);
+               content_error("media_directory_scanning_cancel failed : %d", ret);
 
        return _content_error_capi(ret);
 }
@@ -440,7 +468,7 @@ void _media_content_db_update_noti_cb(
                                                        media_item_update_type_e update_type,
                                                        char* path,
                                                        char* uuid,
-                                                       media_type_e content_type,
+                                                       int content_type,
                                                        char *mime_type,
                                                        void *user_data)
 {
@@ -479,15 +507,6 @@ int media_content_add_db_updated_cb(media_content_db_update_cb callback, void *u
        return _content_error_capi(ret);
 }
 
-#ifdef TIZEN_FEATURE_COMPATIBILITY
-int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *user_data)
-{
-       content_warn("DEPRECATION WARNING: media_content_set_db_updated_cb() is removed from 5.0.");
-
-       return MEDIA_CONTENT_ERROR_NONE;
-}
-#endif
-
 int media_content_remove_db_updated_cb(media_content_noti_h noti_handle)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;