Prevent issue fix
[platform/core/multimedia/libmedia-service.git] / src / common / media-svc.c
1 /*
2  * libmedia-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <string.h>
23 #include <errno.h>
24 #include <media-util.h>
25 #include "media-svc.h"
26 #include "media-svc-media.h"
27 #include "media-svc-debug.h"
28 #include "media-svc-util.h"
29 #include "media-svc-db-utils.h"
30 #include "media-svc-env.h"
31 #include "media-svc-media-folder.h"
32 #include "media-svc-album.h"
33 #include "media-svc-noti.h"
34 #include "media-svc-storage.h"
35
36 static __thread int g_media_svc_item_validity_data_cnt = 1;
37 static __thread int g_media_svc_item_validity_cur_data_cnt = 0;
38
39 static __thread int g_media_svc_move_item_data_cnt = 1;
40 static __thread int g_media_svc_move_item_cur_data_cnt = 0;
41
42 static __thread int g_media_svc_insert_item_data_cnt = 1;
43 static __thread int g_media_svc_insert_item_cur_data_cnt = 0;
44
45 static __thread int g_media_svc_update_item_data_cnt = 1;
46 static __thread int g_media_svc_update_item_cur_data_cnt = 0;
47
48 static __thread int g_media_svc_insert_folder_data_cnt = 1;
49 static __thread int g_media_svc_insert_folder_cur_data_cnt = 0;
50
51 /* Flag for items to be published by notification */
52 static __thread int g_insert_with_noti = FALSE;
53
54 #define DEFAULT_MEDIA_SVC_STORAGE_ID "media"
55
56 typedef struct {
57         int media_type;
58         char *path;
59 } media_svc_item_info_s;
60
61 static bool __media_svc_check_storage(media_svc_storage_type_e storage_type, bool check_all)
62 {
63         if (check_all == TRUE) {
64                 if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL)
65                         && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)
66                         && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB)
67                         && (storage_type != MEDIA_SVC_STORAGE_CLOUD)) {
68                         media_svc_error("storage type is incorrect[%d]", storage_type);
69                         return FALSE;
70                 }
71         } else {
72                 if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL)
73                         && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)
74                         && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB)) {
75                         media_svc_error("storage type is incorrect[%d]", storage_type);
76                         return FALSE;
77                 }
78         }
79
80         return TRUE;
81 }
82
83 int media_svc_connect(MediaSvcHandle **handle, uid_t uid, bool need_write)
84 {
85         int ret = MS_MEDIA_ERR_NONE;
86         MediaDBHandle *db_handle = NULL;
87
88         media_svc_debug_fenter();
89
90         ret = media_db_connect(&db_handle, uid, need_write);
91         if (ret != MS_MEDIA_ERR_NONE)
92                 return ret;
93
94         *handle = db_handle;
95         return MS_MEDIA_ERR_NONE;
96 }
97
98 int media_svc_disconnect(MediaSvcHandle *handle)
99 {
100         MediaDBHandle *db_handle = (MediaDBHandle *)handle;
101
102         media_svc_debug_fenter();
103
104         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
105
106         int ret = MS_MEDIA_ERR_NONE;
107
108         ret = media_db_disconnect(db_handle);
109         return ret;
110 }
111
112 int media_svc_create_table(MediaSvcHandle *handle, uid_t uid)
113 {
114         int ret = MS_MEDIA_ERR_NONE;
115         sqlite3 *db_handle = (sqlite3 *)handle;
116
117         media_svc_debug_fenter();
118
119         ret = _media_svc_init_table_query(MEDIA_SVC_DB_TABLE_MEDIA);
120         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
121
122         /*create media table*/
123         ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_LIST_MEDIA, uid);
124         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
125
126         /*create folder table*/
127         ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_LIST_FOLDER, uid);
128         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
129
130         /*create playlist_map table*/
131         ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, MEDIA_SVC_DB_LIST_PLAYLIST_MAP, uid);
132         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
133
134         /*create playlist table*/
135         ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_LIST_PLAYLIST, uid);
136         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
137
138         /* create album table*/
139         ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_ALBUM, MEDIA_SVC_DB_LIST_ALBUM, uid);
140         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
141
142         /*create tag_map table*/
143         ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_TAG_MAP, MEDIA_SVC_DB_LIST_TAG_MAP, uid);
144         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
145
146         /*create tag table*/
147         ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_LIST_TAG, uid);
148         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
149
150         /*create bookmark table*/
151         ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_BOOKMARK, MEDIA_SVC_DB_LIST_BOOKMARK, uid);
152         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
153
154         /*create storage table. from tizen 2.4*/
155         ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_LIST_STORAGE, uid);
156         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
157
158 #if 0
159         /*init storage table*/
160         ret = _media_svc_init_storage(db_handle, uid);
161         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
162 #endif
163         /*create face table. from tizen 3.0*/
164         ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_FACE_SCAN_LIST, MEDIA_SVC_DB_LIST_FACE_SCAN_LIST, uid);
165         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
166
167         ret = _media_svc_make_table_query(db_handle, MEDIA_SVC_DB_TABLE_FACE, MEDIA_SVC_DB_LIST_FACE, uid);
168         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
169
170         _media_svc_destroy_table_query();
171
172         media_svc_debug_fleave();
173
174         return MS_MEDIA_ERR_NONE;
175 }
176
177 int media_svc_get_storage_type(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
178 {
179         int ret = MS_MEDIA_ERR_NONE;
180         media_svc_storage_type_e type;
181
182         ret = _media_svc_get_storage_type_by_path(path, &type, uid);
183         media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_storage_type_by_path failed : %d", ret);
184
185         *storage_type = type;
186
187         return ret;
188 }
189
190 int media_svc_get_file_info(MediaSvcHandle *handle, const char *storage_id, const char *path, time_t *modified_time, unsigned long long *size)
191 {
192         int ret = MS_MEDIA_ERR_NONE;
193         sqlite3 *db_handle = (sqlite3 *)handle;
194
195         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
196         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
197
198         ret = _media_svc_get_fileinfo_by_path(db_handle, storage_id, path, modified_time, size);
199
200         return ret;
201 }
202
203 int media_svc_check_item_exist_by_path(MediaSvcHandle *handle, const char *storage_id, const char *path)
204 {
205         int ret = MS_MEDIA_ERR_NONE;
206         sqlite3 *db_handle = (sqlite3 *)handle;
207         int count = -1;
208
209         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
210         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
211         media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
212
213         ret = _media_svc_count_record_with_path(db_handle, storage_id, path, &count);
214         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
215
216         if (count > 0) {
217                 media_svc_debug("item is exist in database");
218                 return MS_MEDIA_ERR_NONE;
219         } else {
220                 media_svc_debug("item is not exist in database");
221                 return MS_MEDIA_ERR_DB_NO_RECORD;
222         }
223
224         return MS_MEDIA_ERR_NONE;
225 }
226
227 int media_svc_insert_item_begin(MediaSvcHandle *handle, int data_cnt, int with_noti, int from_pid)
228 {
229         sqlite3 *db_handle = (sqlite3 *)handle;
230
231         media_svc_debug("Transaction data count : [%d]", data_cnt);
232
233         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
234         media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
235
236         g_media_svc_insert_item_data_cnt = data_cnt;
237         g_media_svc_insert_item_cur_data_cnt = 0;
238
239         /* Prepare for making noti item list */
240         if (with_noti) {
241                 media_svc_debug("making noti list from pid[%d]", from_pid);
242                 if (_media_svc_create_noti_list(data_cnt) != MS_MEDIA_ERR_NONE)
243                         return MS_MEDIA_ERR_OUT_OF_MEMORY;
244
245                 _media_svc_set_noti_from_pid(from_pid);
246                 g_insert_with_noti = TRUE;
247         }
248
249         return MS_MEDIA_ERR_NONE;
250 }
251
252 int media_svc_insert_item_end(MediaSvcHandle *handle, uid_t uid)
253 {
254         int ret = MS_MEDIA_ERR_NONE;
255         sqlite3 *db_handle = (sqlite3 *)handle;
256
257         media_svc_debug_fenter();
258
259         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
260
261         if (g_media_svc_insert_item_cur_data_cnt > 0) {
262
263                 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM, uid);
264                 if (g_insert_with_noti) {
265                         media_svc_debug("sending noti list");
266                         _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt);
267                         _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt);
268                         g_insert_with_noti = FALSE;
269                         _media_svc_set_noti_from_pid(-1);
270                 }
271         }
272
273         g_media_svc_insert_item_data_cnt = 1;
274         g_media_svc_insert_item_cur_data_cnt = 0;
275
276         return ret;
277 }
278
279 int media_svc_insert_item_bulk(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, int is_burst, uid_t uid)
280 {
281         int ret = MS_MEDIA_ERR_NONE;
282         sqlite3 *db_handle = (sqlite3 *)handle;
283         char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
284         media_svc_media_type_e media_type;
285
286         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
287         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
288         media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
289         media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
290
291         media_svc_content_info_s content_info;
292         memset(&content_info, 0, sizeof(media_svc_content_info_s));
293
294         /*Set media info*/
295         /* if drm_contentinfo is not NULL, the file is OMA DRM.*/
296         ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
297         if (ret != MS_MEDIA_ERR_NONE)
298                 return ret;
299
300         if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
301                 /*Do nothing.*/
302         } else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
303                 ret = _media_svc_extract_image_metadata(db_handle, &content_info);
304         } else {
305                 ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
306         }
307         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
308
309         /*Set or Get folder id*/
310         ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, path, storage_type, folder_uuid, uid);
311         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
312
313         ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
314         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
315
316         if (g_media_svc_insert_item_data_cnt == 1) {
317
318                 ret = _media_svc_insert_item_with_data(db_handle, storage_id, &content_info, is_burst, FALSE, uid);
319                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
320
321                 if (g_insert_with_noti)
322                         _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt++);
323
324         } else if (g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) {
325
326                 ret = _media_svc_insert_item_with_data(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
327                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
328
329                 if (g_insert_with_noti)
330                         _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
331
332                 g_media_svc_insert_item_cur_data_cnt++;
333
334         } else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) {
335
336                 ret = _media_svc_insert_item_with_data(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
337                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
338
339                 if (g_insert_with_noti)
340                         _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
341
342                 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM, uid);
343                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
344
345                 if (g_insert_with_noti) {
346                         _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
347                         _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
348
349                         /* Recreate noti list */
350                         ret = _media_svc_create_noti_list(g_media_svc_insert_item_data_cnt);
351                         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
352                 }
353
354                 g_media_svc_insert_item_cur_data_cnt = 0;
355
356         } else {
357                 media_svc_error("Error in media_svc_insert_item_bulk");
358                 _media_svc_destroy_content_info(&content_info);
359                 return MS_MEDIA_ERR_INTERNAL;
360         }
361
362         _media_svc_destroy_content_info(&content_info);
363
364         return MS_MEDIA_ERR_NONE;
365 }
366
367 int media_svc_insert_item_immediately(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, uid_t uid)
368 {
369         int ret = MS_MEDIA_ERR_NONE;
370         sqlite3 *db_handle = (sqlite3 *)handle;
371         char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
372         media_svc_media_type_e media_type;
373         int ini_val = _media_svc_get_ini_value();
374
375         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
376         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
377         media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
378         media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
379
380         media_svc_content_info_s content_info;
381         memset(&content_info, 0, sizeof(media_svc_content_info_s));
382
383         /*Set media info*/
384         ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
385         if (ret != MS_MEDIA_ERR_NONE) {
386                 return ret;
387         }
388
389         if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
390                 /*Do nothing.*/
391         } else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
392                 ret = _media_svc_extract_image_metadata(db_handle, &content_info);
393         } else {
394                 ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
395         }
396
397         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
398
399         /*Set or Get folder id*/
400         ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, path, storage_type, folder_uuid, uid);
401         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
402
403         ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
404         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
405 #if 1
406         /* Extracting thumbnail */
407         if (ini_val == 1) {
408                 if (content_info.thumbnail_path == NULL) {
409                         if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
410                                 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
411                                 int width = 0;
412                                 int height = 0;
413
414                                 ret = _media_svc_request_thumbnail_with_origin_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid);
415                                 if (ret == MS_MEDIA_ERR_NONE)
416                                         ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
417
418                                 if (content_info.media_meta.width <= 0)
419                                         content_info.media_meta.width = width;
420
421                                 if (content_info.media_meta.height <= 0)
422                                         content_info.media_meta.height = height;
423                         }
424                 }
425         }
426 #endif
427
428         ret = _media_svc_insert_item_with_data(db_handle, storage_id, &content_info, FALSE, FALSE, uid);
429
430         if (ret == MS_MEDIA_ERR_NONE) {
431                 media_svc_debug("Insertion is successful. Sending noti for this");
432                 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
433         } else if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
434                 media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
435         }
436
437         _media_svc_destroy_content_info(&content_info);
438         return ret;
439 }
440
441 int media_svc_move_item(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e src_storage, const char *src_path,
442                         media_svc_storage_type_e dest_storage, const char *dest_path, uid_t uid)
443 {
444         int ret = MS_MEDIA_ERR_NONE;
445         sqlite3 *db_handle = (sqlite3 *)handle;
446         char *file_name = NULL;
447         char *folder_path = NULL;
448         int modified_time = 0;
449         char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
450         char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
451         char new_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
452         int media_type = -1;
453
454         media_svc_debug_fenter();
455
456         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
457         media_svc_retvm_if(!STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
458         media_svc_retvm_if(!STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
459         media_svc_retvm_if(__media_svc_check_storage(src_storage, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid src_storage");
460         media_svc_retvm_if(__media_svc_check_storage(dest_storage, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid dest_storage");
461
462         /*check and update folder*/
463         ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, dest_path, dest_storage, folder_uuid, uid);
464         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
465
466         /*get filename*/
467         file_name = g_path_get_basename(dest_path);
468
469         /*get modified_time*/
470         modified_time = _media_svc_get_file_time(dest_path);
471
472         /*get thumbnail_path to update. only for Imgae and Video items. Audio share album_art(thumbnail)*/
473         ret = _media_svc_get_media_type_by_path(db_handle, storage_id, src_path, &media_type);
474         if (ret != MS_MEDIA_ERR_NONE) {
475                 media_svc_error("_media_svc_get_media_type_by_path failed");
476                 SAFE_FREE(file_name);
477                 return ret;
478         }
479
480         if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
481                 /*get old thumbnail_path*/
482                 ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, src_path, old_thumb_path);
483                 if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
484                         media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
485                         SAFE_FREE(file_name);
486                         return ret;
487                 }
488
489                 /* If old thumb path is default or not */
490                 char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
491                 if (STRING_VALID(default_thumbnail_path) && (strncmp(old_thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) == 0))
492                         strncpy(new_thumb_path, default_thumbnail_path, sizeof(new_thumb_path));
493                 else
494                         _media_svc_get_thumbnail_path(dest_storage, new_thumb_path, dest_path, THUMB_EXT, uid);
495
496                 SAFE_FREE(default_thumbnail_path);
497         }
498
499         if (g_media_svc_move_item_data_cnt == 1) {
500
501                 /*update item*/
502                 if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
503                         ret = _media_svc_update_item_by_path(db_handle, storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, FALSE, uid);
504                 } else {
505                         ret = _media_svc_update_item_by_path(db_handle, storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, FALSE, uid);
506                 }
507                 SAFE_FREE(file_name);
508                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
509
510                 media_svc_debug("Move is successful. Sending noti for this");
511
512                 /* Get notification info */
513                 media_svc_noti_item *noti_item = NULL;
514                 ret = _media_svc_get_noti_info(db_handle, storage_id, dest_path, MS_MEDIA_ITEM_FILE, &noti_item);
515                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
516
517                 /* Send notification for move */
518                 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, src_path, media_type, noti_item->media_uuid, noti_item->mime_type);
519                 _media_svc_destroy_noti_item(noti_item);
520
521                 /*update folder modified_time*/
522                 folder_path = g_path_get_dirname(dest_path);
523                 ret = _media_svc_update_folder_modified_time_by_folder_uuid(db_handle, folder_uuid, folder_path, FALSE, uid);
524                 SAFE_FREE(folder_path);
525                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
526
527                 ret = _media_svc_update_folder_table(db_handle, storage_id, uid);
528                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
529
530         } else if (g_media_svc_move_item_cur_data_cnt < (g_media_svc_move_item_data_cnt - 1)) {
531
532                 /*update item*/
533                 if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
534                         ret = _media_svc_update_item_by_path(db_handle, storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE, uid);
535                 } else {
536                         ret = _media_svc_update_item_by_path(db_handle, storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
537                 }
538                 SAFE_FREE(file_name);
539                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
540
541                 /*update folder modified_time*/
542                 folder_path = g_path_get_dirname(dest_path);
543                 ret = _media_svc_update_folder_modified_time_by_folder_uuid(db_handle, folder_uuid, folder_path, TRUE, uid);
544                 SAFE_FREE(folder_path);
545                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
546
547                 g_media_svc_move_item_cur_data_cnt++;
548
549         } else if (g_media_svc_move_item_cur_data_cnt == (g_media_svc_move_item_data_cnt - 1)) {
550
551                 /*update item*/
552                 if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
553                         ret = _media_svc_update_item_by_path(db_handle, storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE, uid);
554                 } else {
555                         ret = _media_svc_update_item_by_path(db_handle, storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
556                 }
557                 SAFE_FREE(file_name);
558                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
559
560                 /*update folder modified_time*/
561                 folder_path = g_path_get_dirname(dest_path);
562                 ret = _media_svc_update_folder_modified_time_by_folder_uuid(db_handle, folder_uuid, folder_path, TRUE, uid);
563                 SAFE_FREE(folder_path);
564                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
565
566                 /*update db*/
567                 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM, uid);
568                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
569
570                 g_media_svc_move_item_cur_data_cnt = 0;
571
572         } else {
573                 media_svc_error("Error in media_svc_move_item");
574                 return MS_MEDIA_ERR_INTERNAL;
575         }
576
577         /*rename thumbnail file*/
578 /*      if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) { */
579         if ((strlen(old_thumb_path) > 0) && (STRING_VALID(MEDIA_SVC_THUMB_DEFAULT_PATH)) && (strncmp(old_thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, strlen(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) {
580                 ret = _media_svc_rename_file(old_thumb_path, new_thumb_path);
581                 if (ret != MS_MEDIA_ERR_NONE)
582                         media_svc_error("_media_svc_rename_file failed : %d", ret);
583         }
584 /*      } */
585
586         return MS_MEDIA_ERR_NONE;
587 }
588
589 int media_svc_set_item_validity_begin(MediaSvcHandle *handle, int data_cnt)
590 {
591         sqlite3 *db_handle = (sqlite3 *)handle;
592
593         media_svc_debug("Transaction data count : [%d]", data_cnt);
594
595         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
596         media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
597
598         g_media_svc_item_validity_data_cnt = data_cnt;
599         g_media_svc_item_validity_cur_data_cnt = 0;
600
601         return MS_MEDIA_ERR_NONE;
602 }
603
604 int media_svc_set_item_validity_end(MediaSvcHandle *handle, uid_t uid)
605 {
606         int ret = MS_MEDIA_ERR_NONE;
607         sqlite3 *db_handle = (sqlite3 *)handle;
608
609         media_svc_debug_fenter();
610
611         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
612
613         if (g_media_svc_item_validity_cur_data_cnt > 0) {
614
615                 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
616         }
617
618         g_media_svc_item_validity_data_cnt = 1;
619         g_media_svc_item_validity_cur_data_cnt = 0;
620
621         return ret;
622 }
623
624 int media_svc_set_item_validity(MediaSvcHandle *handle, const char *storage_id, const char *path, int validity, uid_t uid)
625 {
626         int ret = MS_MEDIA_ERR_NONE;
627         sqlite3 *db_handle = (sqlite3 *)handle;
628
629         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
630         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
631         media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
632
633         media_svc_debug("path=[%s], validity=[%d]", path, validity);
634
635         if (g_media_svc_item_validity_data_cnt == 1) {
636
637                 return _media_svc_update_item_validity(db_handle, storage_id, path, validity, FALSE, uid);
638
639         } else if (g_media_svc_item_validity_cur_data_cnt < (g_media_svc_item_validity_data_cnt - 1)) {
640
641                 ret = _media_svc_update_item_validity(db_handle, storage_id, path, validity, TRUE, uid);
642                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
643
644                 g_media_svc_item_validity_cur_data_cnt++;
645
646         } else if (g_media_svc_item_validity_cur_data_cnt == (g_media_svc_item_validity_data_cnt - 1)) {
647
648                 ret = _media_svc_update_item_validity(db_handle, storage_id, path, validity, TRUE, uid);
649                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
650
651                 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
652                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
653
654                 g_media_svc_item_validity_cur_data_cnt = 0;
655
656         } else {
657
658                 media_svc_error("Error in media_svc_set_item_validity");
659                 return MS_MEDIA_ERR_INTERNAL;
660         }
661
662         return MS_MEDIA_ERR_NONE;
663 }
664
665 int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *storage_id, const char *path, uid_t uid)
666 {
667         int ret = MS_MEDIA_ERR_NONE;
668         sqlite3 *db_handle = (sqlite3 *)handle;
669         char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
670
671         media_svc_debug_fenter();
672
673         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
674         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
675         media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
676
677         int media_type = -1;
678         ret = _media_svc_get_media_type_by_path(db_handle, storage_id, path, &media_type);
679         media_svc_retv_if((ret != MS_MEDIA_ERR_NONE), ret);
680
681 #if 0
682         if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
683                 /*Get thumbnail path to delete*/
684                 ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
685                 media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
686         } else if ((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
687                 int count = 0;
688                 ret = _media_svc_get_media_count_with_album_id_by_path(db_handle, path, &count);
689                 media_svc_retv_if((ret != MS_MEDIA_ERR_NONE), ret);
690
691                 if (count == 1) {
692                         /*Get thumbnail path to delete*/
693                         ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
694                         media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
695                 }
696         }
697 #endif
698         /*Get thumbnail path to delete*/
699         ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
700         media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
701
702         if (g_media_svc_insert_item_data_cnt == 1) {
703
704                 /* Get notification info */
705                 media_svc_noti_item *noti_item = NULL;
706                 ret = _media_svc_get_noti_info(db_handle, storage_id, path, MS_MEDIA_ITEM_FILE, &noti_item);
707                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
708
709                 /*Delete item*/
710                 ret = _media_svc_delete_item_by_path(db_handle, storage_id, path, FALSE, uid);
711                 if (ret != MS_MEDIA_ERR_NONE) {
712                         media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
713                         _media_svc_destroy_noti_item(noti_item);
714
715                         return ret;
716                 }
717
718                 /* Send notification */
719                 media_svc_debug("Deletion is successful. Sending noti for this");
720                 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_DELETE, path, media_type, noti_item->media_uuid, noti_item->mime_type);
721                 _media_svc_destroy_noti_item(noti_item);
722         } else {
723                 ret = _media_svc_delete_item_by_path(db_handle, storage_id, path, TRUE, uid);
724                 if (ret != MS_MEDIA_ERR_NONE) {
725                         media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
726                         return ret;
727                 }
728
729         }
730
731         /*Delete thumbnail*/
732         char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
733         if ((strlen(thumb_path) > 0) && ((STRING_VALID(default_thumbnail_path)) && (strncmp(thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) != 0))) {
734 /*
735                 int thumb_count = 1;
736                 // Get count of media, which contains same thumbnail for music
737                 if ((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) ||(media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
738                         ret = _media_svc_get_thumbnail_count(db_handle, storage_id, thumb_path, &thumb_count);
739                         if (ret != MS_MEDIA_ERR_NONE) {
740                                 media_svc_error("Failed to get thumbnail count : %d", ret);
741                         }
742                 }
743
744                 if (thumb_count == 1) {
745 */
746                         ret = _media_svc_remove_file(thumb_path);
747                         if (ret != MS_MEDIA_ERR_NONE) {
748                                 media_svc_error("fail to remove thumbnail file.");
749                         }
750 //              }
751         }
752
753         SAFE_FREE(default_thumbnail_path);
754
755         return MS_MEDIA_ERR_NONE;
756 }
757
758 int media_svc_delete_all_items_in_storage(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
759 {
760         int ret = MS_MEDIA_ERR_NONE;
761         sqlite3 *db_handle = (sqlite3 *)handle;
762
763         media_svc_debug("media_svc_delete_all_items_in_storage [%d]", storage_type);
764
765         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
766         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
767         media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
768
769         ret = _media_svc_truncate_table(db_handle, storage_id, storage_type, uid);
770         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
771
772         if (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB) {
773                 char *internal_thumb_path = _media_svc_get_thumb_internal_path(uid);
774                 char *external_thumb_path = _media_svc_get_thumb_external_path(uid);
775
776                 const char *dirpath = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? internal_thumb_path : external_thumb_path;
777
778                 /* remove thumbnails */
779                 if (STRING_VALID(dirpath))
780                         ret = _media_svc_remove_all_files_in_dir(dirpath);
781                 SAFE_FREE(internal_thumb_path);
782                 SAFE_FREE(external_thumb_path);
783                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
784         }
785
786         return MS_MEDIA_ERR_NONE;
787 }
788
789 int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
790 {
791         sqlite3 *db_handle = (sqlite3 *)handle;
792
793         media_svc_debug_fenter();
794
795         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
796         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
797         media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
798
799         /*Delete from DB and remove thumbnail files*/
800         return _media_svc_delete_invalid_items(db_handle, storage_id, storage_type, uid);
801 }
802
803 int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, bool is_recursive, uid_t uid)
804 {
805         sqlite3 *db_handle = (sqlite3 *)handle;
806
807         media_svc_debug_fenter();
808
809         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
810         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
811
812         /*Delete from DB and remove thumbnail files*/
813         return _media_svc_delete_invalid_folder_items(db_handle, storage_id, folder_path, is_recursive, uid);
814 }
815
816 int media_svc_set_all_storage_items_validity(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, int validity, uid_t uid)
817 {
818         sqlite3 *db_handle = (sqlite3 *)handle;
819
820         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
821         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
822         media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
823
824         return _media_svc_update_storage_item_validity(db_handle, storage_id, storage_type, validity, uid);
825 }
826
827 int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, int validity, int recursive, uid_t uid)
828 {
829         sqlite3 *db_handle = (sqlite3 *)handle;
830
831         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
832         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
833         media_svc_retvm_if(!STRING_VALID(folder_path), MS_MEDIA_ERR_INVALID_PARAMETER, "folder_path is NULL");
834
835         if (recursive)
836                 return _media_svc_update_recursive_folder_item_validity(db_handle, storage_id, folder_path, validity, uid);
837         else
838                 return _media_svc_update_folder_item_validity(db_handle, storage_id, folder_path, validity, uid);
839 }
840
841 int media_svc_refresh_item(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, uid_t uid)
842 {
843         int ret = MS_MEDIA_ERR_NONE;
844         sqlite3 *db_handle = (sqlite3 *)handle;
845         media_svc_media_type_e media_type;
846         int ini_val = _media_svc_get_ini_value();
847
848         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
849         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
850         media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
851         media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
852
853         media_svc_content_info_s content_info;
854         memset(&content_info, 0, sizeof(media_svc_content_info_s));
855
856         /*Set media info*/
857         ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, TRUE);
858         if (ret != MS_MEDIA_ERR_NONE) {
859                 return ret;
860         }
861
862         /* Initialize thumbnail information to remake thumbnail. */
863         if (ini_val == 1) {
864                 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1];
865                 ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
866                 if (ret != MS_MEDIA_ERR_NONE) {
867                         _media_svc_destroy_content_info(&content_info);
868                         return ret;
869                 }
870
871                 if (g_file_test(thumb_path, G_FILE_TEST_EXISTS) && (STRING_VALID(MEDIA_SVC_THUMB_DEFAULT_PATH)) && (strncmp(thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, strlen(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) {
872                         ret = _media_svc_remove_file(thumb_path);
873                         if (ret != MS_MEDIA_ERR_NONE) {
874                                 media_svc_error("_media_svc_remove_file failed : %s", thumb_path);
875                         }
876                 }
877
878                 ret = _media_svc_update_thumbnail_path(db_handle, storage_id, path, NULL, uid);
879                 if (ret != MS_MEDIA_ERR_NONE) {
880                         _media_svc_destroy_content_info(&content_info);
881                         return ret;
882                 }
883         }
884
885         /* Get notification info */
886         media_svc_noti_item *noti_item = NULL;
887         ret = _media_svc_get_noti_info(db_handle, storage_id, path, MS_MEDIA_ITEM_FILE, &noti_item);
888         if (ret != MS_MEDIA_ERR_NONE) {
889                 _media_svc_destroy_content_info(&content_info);
890                 return ret;
891         }
892
893         media_type = noti_item->media_type;
894         content_info.media_type = media_type;
895
896         if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
897                 /*Do nothing.*/
898         } else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
899                 ret = _media_svc_extract_image_metadata(db_handle, &content_info);
900         } else {
901                 ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
902         }
903
904         if (ret != MS_MEDIA_ERR_NONE) {
905                 _media_svc_destroy_noti_item(noti_item);
906                 _media_svc_destroy_content_info(&content_info);
907                 return ret;
908         }
909 #if 1
910         /* Extracting thumbnail */
911         if (ini_val == 1) {
912                 if (content_info.thumbnail_path == NULL) {
913                         if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
914                                 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
915                                 int width = 0;
916                                 int height = 0;
917
918                                 ret = _media_svc_request_thumbnail_with_origin_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid);
919                                 if (ret == MS_MEDIA_ERR_NONE) {
920                                         ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
921                                 }
922
923                                 if (content_info.media_meta.width <= 0)
924                                         content_info.media_meta.width = width;
925
926                                 if (content_info.media_meta.height <= 0)
927                                         content_info.media_meta.height = height;
928                         }
929                 }
930         }
931
932 #endif
933
934         ret = _media_svc_update_item_with_data(db_handle, storage_id, &content_info, uid);
935
936         if (ret == MS_MEDIA_ERR_NONE) {
937                 media_svc_debug("Update is successful. Sending noti for this");
938                 _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
939         } else {
940                 media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
941         }
942
943         _media_svc_destroy_content_info(&content_info);
944         _media_svc_destroy_noti_item(noti_item);
945
946         return ret;
947 }
948
949 int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, const char *src_path, const char *dst_path, uid_t uid)
950 {
951         sqlite3 *db_handle = (sqlite3 *)handle;
952         int ret = MS_MEDIA_ERR_NONE;
953
954         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
955         media_svc_retvm_if(src_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
956         media_svc_retvm_if(dst_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "dst_path is NULL");
957
958         media_svc_debug("Src path : %s, Dst Path : %s", src_path, dst_path);
959
960         ret = _media_svc_sql_begin_trans(db_handle, uid);
961         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
962
963         /* Update all folder record's modified date, which are changed above */
964         char *update_folder_modified_time_sql = NULL;
965         time_t date;
966         time(&date);
967
968         update_folder_modified_time_sql = sqlite3_mprintf("UPDATE folder SET modified_time = %d WHERE path LIKE '%q';", date, dst_path);
969
970         ret = media_db_request_update_db_batch(update_folder_modified_time_sql, uid);
971         //ret = _media_svc_sql_query(db_handle, update_folder_modified_time_sql, uid);
972         sqlite3_free(update_folder_modified_time_sql);
973
974         if (ret != SQLITE_OK) {
975                 media_svc_error("failed to update folder modified time");
976                 _media_svc_sql_rollback_trans(db_handle, uid);
977
978                 return MS_MEDIA_ERR_DB_INTERNAL;
979         }
980
981         /* Update all items */
982         char *select_all_sql = NULL;
983         sqlite3_stmt *sql_stmt = NULL;
984         char dst_child_path[MEDIA_SVC_PATHNAME_SIZE + 1];
985
986         snprintf(dst_child_path, sizeof(dst_child_path), "%s/%%", dst_path);
987
988         select_all_sql = sqlite3_mprintf("SELECT media_uuid, path, thumbnail_path, media_type from media where folder_uuid IN ( SELECT folder_uuid FROM folder where path='%q' or path like '%q');", dst_path, dst_child_path);
989
990         media_svc_debug("[SQL query] : %s", select_all_sql);
991
992         ret = _media_svc_sql_prepare_to_step_simple(db_handle, select_all_sql, &sql_stmt);
993         if (ret != MS_MEDIA_ERR_NONE) {
994                 media_svc_error("error when media_svc_rename_folder. err = [%d]", ret);
995                 _media_svc_sql_rollback_trans(db_handle, uid);
996                 return ret;
997         }
998
999         while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
1000                 char media_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
1001                 char media_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
1002                 char media_thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
1003                 char media_new_thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
1004                 /*int media_type; */
1005                 bool no_thumb = FALSE;
1006
1007                 if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0))) {
1008                         strncpy(media_uuid,     (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(media_uuid));
1009                         media_uuid[sizeof(media_uuid) - 1] = '\0';
1010                 } else {
1011                         media_svc_error("media UUID is NULL");
1012                         return MS_MEDIA_ERR_DB_INTERNAL;
1013                 }
1014
1015                 if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 1))) {
1016                         strncpy(media_path,     (const char *)sqlite3_column_text(sql_stmt, 1), sizeof(media_path));
1017                         media_path[sizeof(media_path) - 1] = '\0';
1018                 } else {
1019                         media_svc_error("media path is NULL");
1020                         return MS_MEDIA_ERR_DB_INTERNAL;
1021                 }
1022
1023                 if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 2))) {
1024                         strncpy(media_thumb_path,       (const char *)sqlite3_column_text(sql_stmt, 2), sizeof(media_thumb_path));
1025                         media_thumb_path[sizeof(media_thumb_path) - 1] = '\0';
1026                 } else {
1027                         media_svc_debug("media thumb path doesn't exist in DB");
1028                         no_thumb = TRUE;
1029                 }
1030
1031                 /*media_type = sqlite3_column_int(sql_stmt, 3); */
1032
1033                 /* Update path, thumbnail path of this item */
1034                 char *replaced_path = NULL;
1035                 replaced_path = _media_svc_replace_path(media_path, src_path, dst_path);
1036                 if (replaced_path == NULL) {
1037                         media_svc_error("_media_svc_replace_path failed");
1038                         SQLITE3_FINALIZE(sql_stmt);
1039                         _media_svc_sql_rollback_trans(db_handle, uid);
1040                         return MS_MEDIA_ERR_INTERNAL;
1041                 }
1042
1043                 media_svc_debug("New media path : %s", replaced_path);
1044                 media_svc_storage_type_e storage_type;
1045
1046                 if (!no_thumb) {
1047                         /* If old thumb path is default or not */
1048                         char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
1049                         if (STRING_VALID(default_thumbnail_path) && (strncmp(media_thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) == 0)) {
1050                                 strncpy(media_new_thumb_path, default_thumbnail_path, sizeof(media_new_thumb_path) - 1);
1051                         } else {
1052                                 ret = _media_svc_get_storage_type_by_path(replaced_path, &storage_type, uid);
1053                                 if (ret != MS_MEDIA_ERR_NONE) {
1054                                         media_svc_error("_media_svc_get_storage_type_by_path failed : %d", ret);
1055                                         SAFE_FREE(replaced_path);
1056                                         SAFE_FREE(default_thumbnail_path);
1057                                         _media_svc_sql_rollback_trans(db_handle, uid);
1058                                         return ret;
1059                                 }
1060
1061                                 ret = _media_svc_get_thumbnail_path(storage_type, media_new_thumb_path, replaced_path, THUMB_EXT, uid);
1062                                 if (ret != MS_MEDIA_ERR_NONE) {
1063                                         media_svc_error("_media_svc_get_thumbnail_path failed : %d", ret);
1064                                         SAFE_FREE(replaced_path);
1065                                         SAFE_FREE(default_thumbnail_path);
1066                                         SQLITE3_FINALIZE(sql_stmt);
1067                                         _media_svc_sql_rollback_trans(db_handle, uid);
1068                                         return ret;
1069                                 }
1070                         }
1071
1072                         SAFE_FREE(default_thumbnail_path);
1073
1074                         /*media_svc_debug("New media thumbnail path : %s", media_new_thumb_path); */
1075                 }
1076
1077                 char *update_item_sql = NULL;
1078
1079                 if (no_thumb) {
1080                         update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q' WHERE media_uuid='%q'", replaced_path, media_uuid);
1081                 } else {
1082 #if 0
1083                         if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1084                                 update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_new_thumb_path, media_uuid);
1085                         } else {
1086                                 update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_thumb_path, media_uuid);
1087                         }
1088 #else
1089                         update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_new_thumb_path, media_uuid);
1090 #endif
1091                 }
1092
1093                 ret = media_db_request_update_db_batch(update_item_sql, uid);
1094                 /*ret = _media_svc_sql_query(db_handle, update_item_sql, uid); */
1095                 sqlite3_free(update_item_sql);
1096                 SAFE_FREE(replaced_path);
1097
1098                 if (ret != SQLITE_OK) {
1099                         media_svc_error("failed to update item");
1100                         SQLITE3_FINALIZE(sql_stmt);
1101                         _media_svc_sql_rollback_trans(db_handle, uid);
1102
1103                         return MS_MEDIA_ERR_DB_INTERNAL;
1104                 }
1105
1106                 /* Rename thumbnail file of file system */
1107                 char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
1108                 if ((!no_thumb) && (strncmp(media_thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) != 0)) {
1109                         ret = _media_svc_rename_file(media_thumb_path, media_new_thumb_path);
1110                         if (ret != MS_MEDIA_ERR_NONE) {
1111                                 media_svc_error("_media_svc_rename_file failed : %d", ret);
1112                         }
1113                 }
1114
1115                 SAFE_FREE(default_thumbnail_path);
1116         }
1117
1118         SQLITE3_FINALIZE(sql_stmt);
1119
1120         ret = _media_svc_sql_end_trans(db_handle, uid);
1121         if (ret != MS_MEDIA_ERR_NONE) {
1122                 media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback");
1123                 _media_svc_sql_rollback_trans(db_handle, uid);
1124                 return ret;
1125         }
1126
1127         media_svc_debug("Folder update is successful. Sending noti for this");
1128         /* Get notification info */
1129         media_svc_noti_item *noti_item = NULL;
1130         ret = _media_svc_get_noti_info(db_handle, storage_id, dst_path, MS_MEDIA_ITEM_DIRECTORY, &noti_item);
1131         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1132
1133         _media_svc_publish_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, src_path, -1, noti_item->media_uuid, NULL);
1134         _media_svc_destroy_noti_item(noti_item);
1135
1136         return MS_MEDIA_ERR_NONE;
1137 }
1138
1139 int media_svc_request_update_db(const char *db_query, uid_t uid)
1140 {
1141         media_svc_retvm_if(!STRING_VALID(db_query), MS_MEDIA_ERR_INVALID_PARAMETER, "db_query is NULL");
1142
1143         return _media_svc_sql_query(NULL, db_query, uid);
1144 }
1145
1146 int media_svc_send_dir_update_noti(MediaSvcHandle *handle, const char *storage_id, const char *dir_path, const char *folder_id, media_item_update_type_e update_type, int pid)
1147 {
1148         int ret = MS_MEDIA_ERR_NONE;
1149         sqlite3 *db_handle = (sqlite3 *)handle;
1150         char *uuid = NULL;
1151
1152         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1153         media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
1154
1155         /* Get notification info */
1156         media_svc_noti_item *noti_item = NULL;
1157         ret = _media_svc_get_noti_info(db_handle, storage_id, dir_path, MS_MEDIA_ITEM_DIRECTORY, &noti_item);
1158         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1159
1160         if (folder_id != NULL) {
1161                 uuid = folder_id;
1162         } else {
1163                 uuid = noti_item->media_uuid;
1164         }
1165
1166         ret = _media_svc_publish_dir_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, dir_path, -1, noti_item->media_uuid, NULL, pid);
1167         ret = _media_svc_publish_dir_noti_v2(MS_MEDIA_ITEM_DIRECTORY, update_type, dir_path, -1, uuid, NULL, pid);
1168         _media_svc_destroy_noti_item(noti_item);
1169
1170         return ret;
1171 }
1172
1173 int media_svc_count_invalid_items_in_folder(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, int *count)
1174 {
1175         sqlite3 *db_handle = (sqlite3 *)handle;
1176
1177         media_svc_debug_fenter();
1178
1179         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1180         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1181         media_svc_retvm_if(folder_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "folder_path is NULL");
1182         media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL");
1183
1184         return _media_svc_count_invalid_folder_items(db_handle, storage_id, folder_path, count);
1185 }
1186
1187 int media_svc_check_db_upgrade(MediaSvcHandle *handle, bool *need_full_scan, uid_t uid)
1188 {
1189         sqlite3 *db_handle = (sqlite3 *)handle;
1190
1191         media_svc_debug_fenter();
1192
1193         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1194
1195         return _media_svc_check_db_upgrade(db_handle, need_full_scan, uid);
1196 }
1197
1198 int media_svc_check_db_corrupt(MediaSvcHandle *handle)
1199 {
1200         sqlite3 *db_handle = (sqlite3 *)handle;
1201
1202         media_svc_debug_fenter();
1203
1204         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1205
1206         return _media_db_check_corrupt(db_handle);
1207 }
1208
1209 int media_svc_get_folder_list(MediaSvcHandle *handle, char *start_path, char ***folder_list, time_t **modified_time_list, int **item_num_list, int *count)
1210 {
1211         sqlite3 *db_handle = (sqlite3 *)handle;
1212
1213         media_svc_debug_fenter();
1214
1215         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1216         media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL");
1217
1218         return _media_svc_get_all_folders(db_handle, start_path, folder_list, modified_time_list, item_num_list, count);
1219 }
1220
1221 int media_svc_update_folder_time(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, uid_t uid)
1222 {
1223         int ret = MS_MEDIA_ERR_NONE;
1224         sqlite3 *db_handle = (sqlite3 *)handle;
1225         time_t sto_time = 0;
1226         int cur_time = _media_svc_get_file_time(folder_path);
1227         char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
1228
1229         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1230
1231         ret = _media_svc_get_folder_info_by_foldername(db_handle, storage_id, folder_path, folder_uuid, &sto_time);
1232         if (ret == MS_MEDIA_ERR_NONE) {
1233                 if (sto_time != cur_time) {
1234                         ret = _media_svc_update_folder_modified_time_by_folder_uuid(db_handle, folder_uuid, folder_path, FALSE, uid);
1235                 }
1236         }
1237
1238         return ret;
1239 }
1240
1241 int media_svc_update_item_begin(MediaSvcHandle *handle, int data_cnt)
1242 {
1243         sqlite3 *db_handle = (sqlite3 *)handle;
1244
1245         media_svc_debug("Transaction data count : [%d]", data_cnt);
1246
1247         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1248         media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
1249
1250         g_media_svc_update_item_data_cnt = data_cnt;
1251         g_media_svc_update_item_cur_data_cnt = 0;
1252
1253         return MS_MEDIA_ERR_NONE;
1254 }
1255
1256 int media_svc_update_item_end(MediaSvcHandle *handle, uid_t uid)
1257 {
1258         int ret = MS_MEDIA_ERR_NONE;
1259         sqlite3 *db_handle = (sqlite3 *)handle;
1260
1261         media_svc_debug_fenter();
1262
1263         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1264
1265         if (g_media_svc_update_item_cur_data_cnt > 0) {
1266
1267                 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
1268         }
1269
1270         g_media_svc_update_item_data_cnt = 1;
1271         g_media_svc_update_item_cur_data_cnt = 0;
1272
1273         return ret;
1274 }
1275
1276 int media_svc_update_item_meta(MediaSvcHandle *handle, const char *file_path, int storage_type, uid_t uid)
1277 {
1278         int ret = MS_MEDIA_ERR_NONE;
1279         sqlite3 *db_handle = (sqlite3 *)handle;
1280
1281         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1282
1283         media_svc_media_type_e media_type;
1284
1285         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1286         media_svc_retvm_if(!STRING_VALID(file_path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
1287         media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
1288
1289         media_svc_content_info_s content_info;
1290         memset(&content_info, 0, sizeof(media_svc_content_info_s));
1291
1292         /*Set media info*/
1293         ret = _media_svc_set_media_info(&content_info, DEFAULT_MEDIA_SVC_STORAGE_ID, storage_type, file_path, &media_type, FALSE);
1294         if (ret != MS_MEDIA_ERR_NONE) {
1295                 return ret;
1296         }
1297
1298         if (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
1299                 ret = _media_svc_extract_music_metadata_for_update(db_handle, &content_info, media_type);
1300         } else {
1301                 return MS_MEDIA_ERR_NONE;
1302         }
1303
1304         if (ret != MS_MEDIA_ERR_NONE) {
1305                 _media_svc_destroy_content_info(&content_info);
1306                 return ret;
1307         }
1308
1309         if (g_media_svc_update_item_data_cnt == 1) {
1310
1311                 ret = _media_svc_update_meta_with_data(db_handle, &content_info);
1312                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1313
1314         } else if (g_media_svc_update_item_cur_data_cnt < (g_media_svc_update_item_data_cnt - 1)) {
1315
1316                 ret = _media_svc_update_meta_with_data(db_handle, &content_info);
1317                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1318
1319                 g_media_svc_update_item_cur_data_cnt++;
1320
1321         } else if (g_media_svc_update_item_cur_data_cnt == (g_media_svc_update_item_data_cnt - 1)) {
1322
1323                 ret = _media_svc_update_meta_with_data(db_handle, &content_info);
1324                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1325
1326                 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
1327                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1328
1329                 g_media_svc_update_item_cur_data_cnt = 0;
1330
1331         } else {
1332                 media_svc_error("Error in media_svc_update_item_meta");
1333                 _media_svc_destroy_content_info(&content_info);
1334                 return MS_MEDIA_ERR_INTERNAL;
1335         }
1336
1337         _media_svc_destroy_content_info(&content_info);
1338
1339         return ret;
1340 }
1341
1342 int media_svc_publish_noti(MediaSvcHandle *handle, media_item_type_e update_item, media_item_update_type_e update_type, const char *path, media_type_e media_type, const char *uuid, const char *mime_type)
1343 {
1344         return _media_svc_publish_noti(update_item, update_type, path, media_type, uuid, mime_type);
1345 }
1346
1347 int media_svc_get_pinyin(MediaSvcHandle *handle, const char *src_str, char **pinyin_str)
1348 {
1349         media_svc_retvm_if(!STRING_VALID(src_str), MS_MEDIA_ERR_INVALID_PARAMETER, "String is NULL");
1350
1351         return _media_svc_get_pinyin_str(src_str, pinyin_str);
1352 }
1353
1354 int media_svc_check_pinyin_support(bool *support)
1355 {
1356         *support = _media_svc_check_pinyin_support();
1357
1358         return MS_MEDIA_ERR_NONE;
1359 }
1360
1361 int media_svc_set_storage_validity(MediaSvcHandle *handle, const char *storage_id, int validity, uid_t uid)
1362 {
1363         int ret = MS_MEDIA_ERR_NONE;
1364         sqlite3 * db_handle = (sqlite3 *)handle;
1365
1366         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1367
1368         ret = _media_svc_update_storage_validity(db_handle, storage_id, validity, uid);
1369         media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update storage validity failed: %d", ret);
1370
1371         ret = _media_svc_update_media_view(db_handle, uid);
1372         media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);
1373
1374         return ret;
1375 }
1376
1377 int media_svc_get_storage_id(MediaSvcHandle *handle, const char *path, char *storage_id)
1378 {
1379         int ret = MS_MEDIA_ERR_NONE;
1380         sqlite3 * db_handle = (sqlite3 *)handle;
1381
1382         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1383         media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
1384
1385         ret = _media_svc_get_storage_uuid(db_handle, path, storage_id);
1386
1387         return ret;
1388 }
1389
1390 int media_svc_get_storage_path(MediaSvcHandle *handle, const char *storage_uuid, char **storage_path)
1391 {
1392         int ret = MS_MEDIA_ERR_NONE;
1393         sqlite3 * db_handle = (sqlite3 *)handle;
1394
1395         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1396         media_svc_retvm_if(storage_uuid == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_uuid is NULL");
1397
1398         ret = _media_svc_get_storage_path(db_handle, storage_uuid, storage_path);
1399
1400         return ret;
1401 }
1402
1403 int media_svc_get_storage_scan_status(MediaSvcHandle *handle, const char *storage_uuid, media_svc_scan_status_type_e *storage_status)
1404 {
1405         int ret = MS_MEDIA_ERR_NONE;
1406         sqlite3 * db_handle = (sqlite3 *)handle;
1407
1408         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1409         media_svc_retvm_if(storage_uuid == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_uuid is NULL");
1410
1411         ret = _media_svc_get_storage_scan_status(db_handle, storage_uuid, storage_status);
1412
1413         return ret;
1414 }
1415
1416 int media_svc_set_storage_scan_status(MediaSvcHandle *handle, const char *storage_uuid, media_svc_scan_status_type_e storage_status, uid_t uid)
1417 {
1418         int ret = MS_MEDIA_ERR_NONE;
1419         sqlite3 * db_handle = (sqlite3 *)handle;
1420
1421         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1422
1423         ret = _media_svc_set_storage_scan_status(db_handle, storage_uuid, storage_status, uid);
1424
1425         return ret;
1426 }
1427
1428 int media_svc_get_storage_list(MediaSvcHandle *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count)
1429 {
1430         sqlite3 * db_handle = (sqlite3 *)handle;
1431
1432         media_svc_debug_fenter();
1433
1434         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1435         media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL");
1436
1437         return _media_svc_get_all_storage(db_handle, storage_list, storage_id_list, scan_status_list, count);
1438 }
1439
1440 static int __media_svc_copy_para_to_content(media_svc_content_info_s *content_info, media_svc_content_info_s *new_content_info)
1441 {
1442         int ret = MS_MEDIA_ERR_NONE;
1443
1444         media_svc_retvm_if(content_info == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1445         media_svc_retvm_if(new_content_info == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1446
1447         if (content_info->storage_type == MEDIA_SVC_STORAGE_CLOUD) {
1448                 new_content_info->size = content_info->size;
1449                 new_content_info->modified_time = content_info->modified_time;
1450                 new_content_info->is_drm = content_info->is_drm;
1451                 new_content_info->media_type = content_info->media_type;
1452
1453                 if (STRING_VALID(content_info->mime_type)) {
1454                         ret = __media_svc_malloc_and_strncpy(&new_content_info->mime_type, content_info->mime_type);
1455                         if (ret != MS_MEDIA_ERR_NONE)
1456                                 media_svc_error("strcpy mime_type failed");
1457                 }
1458
1459                 if (STRING_VALID(content_info->thumbnail_path)) {
1460                         ret = __media_svc_malloc_and_strncpy(&new_content_info->thumbnail_path, content_info->thumbnail_path);
1461                         if (ret != MS_MEDIA_ERR_NONE)
1462                                 media_svc_error("strcpy thumbnail_path failed");
1463                 }
1464
1465                 new_content_info->media_meta.duration = content_info->media_meta.duration;
1466                 new_content_info->media_meta.width = content_info->media_meta.width;
1467                 new_content_info->media_meta.height = content_info->media_meta.height;
1468         }
1469
1470         if (content_info->added_time > 0)
1471                 new_content_info->added_time = content_info->added_time;
1472         new_content_info->last_played_time = content_info->last_played_time;
1473         new_content_info->played_count = content_info->played_count;
1474         new_content_info->favourate = content_info->favourate;
1475
1476         if (STRING_VALID(content_info->file_name)) {
1477                         ret = __media_svc_malloc_and_strncpy(&new_content_info->file_name, content_info->file_name);
1478                         if (ret != MS_MEDIA_ERR_NONE)
1479                                 media_svc_error("strcpy file_name failed");
1480         }
1481
1482         if (STRING_VALID(content_info->media_meta.title)) {
1483                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.title, content_info->media_meta.title);
1484                 if (ret != MS_MEDIA_ERR_NONE)
1485                         media_svc_error("strcpy title failed");
1486         }
1487
1488         if (STRING_VALID(content_info->media_meta.album)) {
1489                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.album, content_info->media_meta.album);
1490                 if (ret != MS_MEDIA_ERR_NONE)
1491                         media_svc_error("strcpy album failed");
1492         }
1493
1494         if (STRING_VALID(content_info->media_meta.artist)) {
1495                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.artist, content_info->media_meta.artist);
1496                 if (ret != MS_MEDIA_ERR_NONE)
1497                         media_svc_error("strcpy artist failed");
1498         }
1499
1500         if (STRING_VALID(content_info->media_meta.genre)) {
1501                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.genre, content_info->media_meta.genre);
1502                 if (ret != MS_MEDIA_ERR_NONE)
1503                         media_svc_error("strcpy genre failed");
1504         }
1505
1506         if (STRING_VALID(content_info->media_meta.composer)) {
1507                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.composer, content_info->media_meta.composer);
1508                 if (ret != MS_MEDIA_ERR_NONE)
1509                         media_svc_error("strcpy composer failed");
1510         }
1511
1512         if (STRING_VALID(content_info->media_meta.year)) {
1513                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.year, content_info->media_meta.year);
1514                 if (ret != MS_MEDIA_ERR_NONE)
1515                         media_svc_error("strcpy year failed");
1516         }
1517
1518         if (STRING_VALID(content_info->media_meta.recorded_date)) {
1519                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.recorded_date, content_info->media_meta.recorded_date);
1520                 if (ret != MS_MEDIA_ERR_NONE)
1521                         media_svc_error("strcpy recorded_date failed");
1522         }
1523
1524         if (STRING_VALID(content_info->media_meta.copyright)) {
1525                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.copyright, content_info->media_meta.copyright);
1526                 if (ret != MS_MEDIA_ERR_NONE)
1527                         media_svc_error("strcpy copyright failed");
1528         }
1529
1530         if (STRING_VALID(content_info->media_meta.track_num)) {
1531                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.track_num, content_info->media_meta.track_num);
1532                 if (ret != MS_MEDIA_ERR_NONE)
1533                         media_svc_error("strcpy track_num failed");
1534         }
1535
1536         if (STRING_VALID(content_info->media_meta.description)) {
1537                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.description, content_info->media_meta.description);
1538                 if (ret != MS_MEDIA_ERR_NONE)
1539                         media_svc_error("strcpy description failed");
1540         }
1541
1542         if (STRING_VALID(content_info->media_meta.weather)) {
1543                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.weather, content_info->media_meta.weather);
1544                 if (ret != MS_MEDIA_ERR_NONE)
1545                         media_svc_error("strcpy weather failed");
1546         }
1547
1548         if (STRING_VALID(content_info->media_meta.category)) {
1549                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.category, content_info->media_meta.category);
1550                 if (ret != MS_MEDIA_ERR_NONE)
1551                         media_svc_error("strcpy category failed");
1552         }
1553
1554         if (STRING_VALID(content_info->media_meta.keyword)) {
1555                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.keyword, content_info->media_meta.keyword);
1556                 if (ret != MS_MEDIA_ERR_NONE)
1557                         media_svc_error("strcpy keyword failed");
1558         }
1559
1560         if (STRING_VALID(content_info->media_meta.location_tag)) {
1561                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.location_tag, content_info->media_meta.location_tag);
1562                 if (ret != MS_MEDIA_ERR_NONE)
1563                         media_svc_error("strcpy location_tag failed");
1564         }
1565
1566         if (STRING_VALID(content_info->media_meta.content_name)) {
1567                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.content_name, content_info->media_meta.content_name);
1568                 if (ret != MS_MEDIA_ERR_NONE)
1569                         media_svc_error("strcpy content_name failed");
1570         }
1571
1572         if (STRING_VALID(content_info->media_meta.age_rating)) {
1573                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.age_rating, content_info->media_meta.age_rating);
1574                 if (ret != MS_MEDIA_ERR_NONE)
1575                         media_svc_error("strcpy age_rating failed");
1576         }
1577
1578         if (STRING_VALID(content_info->media_meta.author)) {
1579                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.author, content_info->media_meta.author);
1580                 if (ret != MS_MEDIA_ERR_NONE)
1581                         media_svc_error("strcpy author failed");
1582         }
1583
1584         if (STRING_VALID(content_info->media_meta.provider)) {
1585                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.provider, content_info->media_meta.provider);
1586                 if (ret != MS_MEDIA_ERR_NONE)
1587                         media_svc_error("strcpy provider failed");
1588         }
1589
1590         if (STRING_VALID(content_info->media_meta.datetaken)) {
1591                 ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.datetaken, content_info->media_meta.datetaken);
1592                 if (ret != MS_MEDIA_ERR_NONE)
1593                         media_svc_error("strcpy datetaken failed");
1594
1595                 new_content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1596                 if (new_content_info->timeline == 0) {
1597                         media_svc_error("Failed to get timeline : %s", new_content_info->media_meta.datetaken);
1598                         new_content_info->timeline = new_content_info->modified_time;
1599                 } else {
1600                         media_svc_debug("Timeline : %ld", new_content_info->timeline);
1601                 }
1602         }
1603
1604         //new_content_info->media_meta.bitrate = content_info->media_meta.bitrate;
1605         //new_content_info->media_meta.samplerate = content_info->media_meta.samplerate;
1606         //new_content_info->media_meta.channel = content_info->media_meta.channel;
1607         //new_content_info->media_meta.orientation = content_info->media_meta.orientation;
1608
1609         if (content_info->media_meta.longitude != MEDIA_SVC_DEFAULT_GPS_VALUE)
1610                 new_content_info->media_meta.longitude = content_info->media_meta.longitude;
1611         if (content_info->media_meta.latitude != MEDIA_SVC_DEFAULT_GPS_VALUE)
1612                 new_content_info->media_meta.latitude = content_info->media_meta.latitude;
1613         if (content_info->media_meta.altitude != MEDIA_SVC_DEFAULT_GPS_VALUE)
1614                 new_content_info->media_meta.altitude = content_info->media_meta.altitude;
1615
1616         new_content_info->media_meta.rating = content_info->media_meta.rating;
1617
1618         return 0;
1619 }
1620
1621 int media_svc_insert_item_immediately_with_data(MediaSvcHandle *handle, media_svc_content_info_s *content_info, uid_t uid)
1622 {
1623         int ret = MS_MEDIA_ERR_NONE;
1624         sqlite3 *db_handle = (sqlite3 *)handle;
1625         char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
1626         bool append_album = FALSE;
1627
1628         /* Checking parameters if they are valid */
1629         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1630         media_svc_retvm_if(content_info == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "content_info is NULL");
1631         media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "file_path is NULL");
1632
1633         if (content_info->storage_type == MEDIA_SVC_STORAGE_CLOUD) {
1634                 media_svc_retvm_if(!STRING_VALID(content_info->mime_type), MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is NULL");
1635
1636                 if ((content_info->media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (content_info->media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1637                         media_svc_error("invalid media_type condition[%d]", content_info->media_type);
1638                         return MS_MEDIA_ERR_INVALID_PARAMETER;
1639                 }
1640
1641                 if (content_info->size <= 0) {
1642                         media_svc_error("invalid size condition[%d]", content_info->size);
1643                         return MS_MEDIA_ERR_INVALID_PARAMETER;
1644                 }
1645
1646                 if (content_info->modified_time <= 0) {
1647                         media_svc_error("invalid modified_time condition[%d]", content_info->modified_time);
1648                         return MS_MEDIA_ERR_INVALID_PARAMETER;
1649                 }
1650         }
1651
1652         media_svc_debug("storage[%d], path[%s], media_type[%d]", content_info->storage_type, content_info->path, content_info->media_type);
1653
1654         media_svc_content_info_s _new_content_info;
1655         memset(&_new_content_info, 0, sizeof(media_svc_content_info_s));
1656
1657         media_svc_media_type_e media_type;
1658
1659         ret = _media_svc_set_media_info(&_new_content_info, content_info->storage_uuid, content_info->storage_type, content_info->path, &media_type, FALSE);
1660         media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "fail _media_svc_set_media_info");
1661
1662         if (content_info->storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1663                 if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
1664                         /*Do nothing.*/
1665                 } else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1666                         ret = _media_svc_extract_image_metadata(db_handle, &_new_content_info);
1667                 } else {
1668                         ret = _media_svc_extract_media_metadata(db_handle, &_new_content_info, uid);
1669                 }
1670
1671                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1672
1673                 /* Extracting thumbnail */
1674                 int ini_val = _media_svc_get_ini_value();
1675                 if (ini_val == 1) {
1676                         if (_new_content_info.thumbnail_path == NULL) {
1677                                 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1678                                         char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
1679                                         int width = 0;
1680                                         int height = 0;
1681
1682                                         ret = _media_svc_request_thumbnail_with_origin_size(_new_content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid);
1683                                         if (ret == MS_MEDIA_ERR_NONE) {
1684                                                 ret = __media_svc_malloc_and_strncpy(&(_new_content_info.thumbnail_path), thumb_path);
1685                                         }
1686
1687                                         if (_new_content_info.media_meta.width <= 0)
1688                                                 _new_content_info.media_meta.width = width;
1689
1690                                         if (_new_content_info.media_meta.height <= 0)
1691                                                 _new_content_info.media_meta.height = height;
1692                                 }
1693                         }
1694                 }
1695         }
1696
1697         /* set othere data to the structure, which is passed as parameters */
1698         __media_svc_copy_para_to_content(content_info, &_new_content_info);
1699
1700         /* Set or Get folder id */
1701         ret = _media_svc_get_and_append_folder_id_by_path(handle, _new_content_info.storage_uuid, _new_content_info.path, _new_content_info.storage_type, folder_uuid, uid);
1702         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1703
1704         ret = __media_svc_malloc_and_strncpy(&_new_content_info.folder_uuid, folder_uuid);
1705         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &_new_content_info);
1706
1707         /* register album table data */
1708
1709         int album_id = 0;
1710         if (_new_content_info.media_type == MEDIA_SVC_MEDIA_TYPE_SOUND || _new_content_info.media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
1711                 ret = _media_svc_get_album_id(handle, _new_content_info.media_meta.album, _new_content_info.media_meta.artist, &album_id);
1712
1713                 if (ret != MS_MEDIA_ERR_NONE) {
1714                         if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1715                                 media_svc_debug("album does not exist. So start to make album art");
1716                                 append_album = TRUE;
1717                         } else {
1718                                 media_svc_debug("other error");
1719                                 append_album = FALSE;
1720                         }
1721                 } else {
1722                         _new_content_info.album_id = album_id;
1723                         append_album = FALSE;
1724
1725                         if ((!strncmp(_new_content_info.media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
1726                                 (!strncmp(_new_content_info.media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
1727
1728                                 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1729                         } else {
1730
1731                                 media_svc_debug("album already exists. don't need to make album art");
1732                                 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &_new_content_info.thumbnail_path);
1733                                 media_svc_retv_del_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret, &_new_content_info);
1734                         }
1735                 }
1736         }
1737
1738         if (append_album == TRUE) {
1739
1740                 if ((strncmp(_new_content_info.media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
1741                         (strncmp(_new_content_info.media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
1742                         ret = _media_svc_append_album(handle, _new_content_info.media_meta.album, _new_content_info.media_meta.artist, _new_content_info.thumbnail_path, &album_id, uid);
1743                 else
1744                         ret = _media_svc_append_album(handle, _new_content_info.media_meta.album, _new_content_info.media_meta.artist, NULL, &album_id, uid);
1745
1746                 _new_content_info.album_id = album_id;
1747         }
1748
1749         /* Insert to db - calling _media_svc_insert_item_with_data */
1750         ret = _media_svc_insert_item_with_data(db_handle, _new_content_info.storage_uuid, &_new_content_info, FALSE, FALSE, uid);
1751
1752         if (ret == MS_MEDIA_ERR_NONE) {
1753                 media_svc_debug("Insertion is successful.");
1754         }
1755
1756         if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
1757                 media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
1758         }
1759
1760         _media_svc_destroy_content_info(&_new_content_info);
1761
1762         /* handling returned value - important */
1763         return ret;
1764 }
1765
1766 void media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1767 {
1768         _media_svc_destroy_content_info(content_info);
1769 }
1770
1771 int media_svc_generate_uuid(char **uuid)
1772 {
1773         char *gen_uuid = NULL;
1774         gen_uuid = _media_info_generate_uuid();
1775         media_svc_retvm_if(gen_uuid == NULL, MS_MEDIA_ERR_INTERNAL, "Fail to generate uuid");
1776
1777         *uuid = strdup(gen_uuid);
1778
1779         return MS_MEDIA_ERR_NONE;
1780 }
1781
1782 int media_svc_get_mmc_info(MediaSvcHandle *handle, char **storage_name, char **storage_path, int *validity, bool *info_exist)
1783 {
1784         sqlite3 * db_handle = (sqlite3 *)handle;
1785
1786         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1787
1788         return _media_svc_get_mmc_info(db_handle, storage_name, storage_path, validity, info_exist);
1789 }
1790
1791 int media_svc_check_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_name, char **storage_path, int *validity)
1792 {
1793         sqlite3 * db_handle = (sqlite3 *)handle;
1794
1795         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1796         media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1797         media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
1798         media_svc_retvm_if(validity == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "validity is NULL");
1799
1800         return _media_svc_check_storage(db_handle, storage_id, storage_name, storage_path, validity);
1801 }
1802
1803 int media_svc_update_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_path, uid_t uid)
1804 {
1805         sqlite3 * db_handle = (sqlite3 *)handle;
1806
1807         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1808         media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1809         media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
1810
1811         return _media_svc_update_storage_path(db_handle, storage_id, storage_path, uid);
1812 }
1813
1814 int media_svc_insert_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_name, const char *storage_path, const char *storage_account, media_svc_storage_type_e storage_type, uid_t uid)
1815 {
1816         int ret = MS_MEDIA_ERR_NONE;
1817         sqlite3 *db_handle = (sqlite3 *)handle;
1818
1819         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1820         media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1821         media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
1822         media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
1823
1824         ret = _media_svc_append_storage(db_handle, storage_id, storage_name, storage_path, storage_account, storage_type, uid);
1825         media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
1826
1827         if (strcmp(storage_id, MEDIA_SVC_DB_TABLE_MEDIA)) {
1828                 ret = _media_svc_create_media_table_with_id(db_handle, storage_id, uid);
1829                 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "create media table failed : %d", ret);
1830
1831                 ret = _media_svc_update_media_view(db_handle, uid);
1832                 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);
1833         }
1834
1835         return ret;
1836 }
1837
1838 int media_svc_delete_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_name, uid_t uid)
1839 {
1840         int ret = MS_MEDIA_ERR_NONE;
1841         sqlite3 *db_handle = (sqlite3 *)handle;
1842         media_svc_storage_type_e storage_type;
1843
1844         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1845         media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1846
1847         ret = _media_svc_get_storage_type(db_handle, storage_id, &storage_type);
1848         media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_storage_type_by_path failed : %d", ret);
1849
1850         ret = _media_svc_delete_storage(db_handle, storage_id, storage_name, uid);
1851         media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "remove storage failed : %d", ret);
1852
1853         ret = _media_svc_delete_folder_by_storage_id(db_handle, storage_id, storage_type, uid);
1854         if (ret != MS_MEDIA_ERR_NONE) {
1855                 media_svc_error("fail to _media_svc_delete_folder_by_storage_id. error : [%d]", ret);
1856         }
1857
1858         if (storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB) {
1859                 ret = _media_svc_drop_media_table(db_handle, storage_id, uid);
1860                 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "drop table failed : %d", ret);
1861
1862                 ret = _media_svc_update_media_view(db_handle, uid);
1863                 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);
1864         }
1865
1866         return ret;
1867 }
1868
1869 int media_svc_insert_folder_begin(MediaSvcHandle *handle, int data_cnt)
1870 {
1871         sqlite3 * db_handle = (sqlite3 *)handle;
1872
1873         media_svc_debug("Transaction data count : [%d]", data_cnt);
1874
1875         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1876         media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
1877
1878         g_media_svc_insert_folder_data_cnt = data_cnt;
1879         g_media_svc_insert_folder_cur_data_cnt = 0;
1880
1881         return MS_MEDIA_ERR_NONE;
1882 }
1883
1884 int media_svc_insert_folder_end(MediaSvcHandle *handle, uid_t uid)
1885 {
1886         int ret = MS_MEDIA_ERR_NONE;
1887         sqlite3 * db_handle = (sqlite3 *)handle;
1888
1889         media_svc_debug_fenter();
1890
1891         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1892
1893         if (g_media_svc_insert_folder_cur_data_cnt > 0) {
1894
1895                 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_FOLDER, uid);
1896         }
1897
1898         g_media_svc_insert_folder_data_cnt = 1;
1899         g_media_svc_insert_folder_cur_data_cnt = 0;
1900
1901         return ret;
1902 }
1903
1904 int media_svc_insert_folder(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, uid_t uid)
1905 {
1906         int ret = MS_MEDIA_ERR_NONE;
1907         sqlite3 * db_handle = (sqlite3 *)handle;
1908         char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
1909
1910         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1911         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1912         media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
1913         media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
1914
1915         if (g_media_svc_insert_folder_data_cnt == 1) {
1916
1917                 ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, FALSE, uid);
1918
1919         } else if (g_media_svc_insert_folder_cur_data_cnt < (g_media_svc_insert_folder_data_cnt - 1)) {
1920
1921                 ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, TRUE, uid);
1922                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1923
1924                 g_media_svc_insert_folder_cur_data_cnt++;
1925
1926         } else if (g_media_svc_insert_folder_cur_data_cnt == (g_media_svc_insert_folder_data_cnt - 1)) {
1927
1928                 ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, TRUE, uid);
1929                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1930
1931                 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_FOLDER, uid);
1932                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
1933
1934                 g_media_svc_insert_folder_cur_data_cnt = 0;
1935
1936         } else {
1937                 media_svc_error("Error in media_svc_set_insert_folder");
1938                 return MS_MEDIA_ERR_INTERNAL;
1939         }
1940
1941         return ret;
1942 }
1943
1944 int media_svc_delete_invalid_folder(MediaSvcHandle *handle, const char *storage_id, uid_t uid)
1945 {
1946         int ret = MS_MEDIA_ERR_NONE;
1947         sqlite3 * db_handle = (sqlite3 *)handle;
1948
1949         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1950
1951         ret = _media_svc_delete_invalid_folder(db_handle, storage_id, uid);
1952
1953         return ret;
1954 }
1955
1956 int media_svc_set_folder_validity(MediaSvcHandle *handle, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid)
1957 {
1958         int ret = MS_MEDIA_ERR_NONE;
1959         sqlite3 * db_handle = (sqlite3 *)handle;
1960
1961         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1962
1963         ret = _media_svc_set_folder_validity(db_handle, storage_id, start_path, validity, is_recursive, uid);
1964
1965         return ret;
1966 }
1967
1968 int media_svc_insert_item_pass1(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, int is_burst, uid_t uid)
1969 {
1970         int ret = MS_MEDIA_ERR_NONE;
1971         sqlite3 * db_handle = (sqlite3 *)handle;
1972         char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
1973         media_svc_media_type_e media_type;
1974
1975         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
1976         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
1977         media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
1978         media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
1979
1980         media_svc_content_info_s content_info;
1981         memset(&content_info, 0, sizeof(media_svc_content_info_s));
1982
1983         /*Set basic media info*/
1984         ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
1985         if (ret != MS_MEDIA_ERR_NONE) {
1986                 media_svc_error("_media_svc_set_media_info fail %d", ret);
1987                 return ret;
1988         }
1989
1990         //media_svc_debug("total %d, cur %d insert flag %d", g_media_svc_insert_item_data_cnt, g_media_svc_insert_item_cur_data_cnt, g_insert_with_noti);
1991
1992         /*Set or Get folder id*/
1993         ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, path, storage_type, folder_uuid, uid);
1994         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1995
1996         ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
1997         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
1998
1999         if (g_media_svc_insert_item_data_cnt == 1) {
2000
2001                 ret = _media_svc_insert_item_pass1(db_handle, storage_id, &content_info, is_burst, FALSE, uid);
2002                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
2003
2004                 if (g_insert_with_noti)
2005                         _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt++);
2006         } else if (g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) {
2007
2008                 ret = _media_svc_insert_item_pass1(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
2009                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
2010
2011                 if (g_insert_with_noti)
2012                         _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
2013
2014                 media_svc_debug("g_media_svc_insert_item_cur_data_cnt %d", g_media_svc_insert_item_cur_data_cnt);
2015                 g_media_svc_insert_item_cur_data_cnt++;
2016
2017         } else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) {
2018
2019                 ret = _media_svc_insert_item_pass1(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
2020                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
2021
2022                 if (g_insert_with_noti)
2023                         _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
2024
2025                 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM, uid);
2026                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
2027
2028                 media_svc_debug("_media_svc_list_query_do over");
2029
2030                 if (g_insert_with_noti) {
2031                         media_svc_debug("publish noti list %d", g_media_svc_insert_item_cur_data_cnt);
2032                         _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
2033                         _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
2034
2035                         /* Recreate noti list */
2036                         ret = _media_svc_create_noti_list(g_media_svc_insert_item_data_cnt);
2037                         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
2038                 }
2039
2040                 g_media_svc_insert_item_cur_data_cnt = 0;
2041
2042         } else {
2043                 media_svc_error("Error in media_svc_insert_item_pass1");
2044                 _media_svc_destroy_content_info(&content_info);
2045                 return MS_MEDIA_ERR_INTERNAL;
2046         }
2047
2048         _media_svc_destroy_content_info(&content_info);
2049
2050         return MS_MEDIA_ERR_NONE;
2051 }
2052
2053 int media_svc_insert_item_pass2(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, int scan_type, const char *extract_path, int is_burst, uid_t uid)
2054 {
2055         int ret = MS_MEDIA_ERR_NONE;
2056         sqlite3 * db_handle = (sqlite3 *)handle;
2057         sqlite3_stmt *sql_stmt = NULL;
2058         media_svc_media_type_e media_type;
2059         media_svc_content_info_s content_info;
2060         GArray *db_data_array = NULL;
2061         media_svc_item_info_s *db_data = NULL;
2062         int idx = 0;
2063         char *sql = NULL;
2064
2065         media_svc_debug_fenter();
2066
2067         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
2068         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
2069         media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
2070
2071         if (scan_type == MS_MSG_DIRECTORY_SCANNING) {
2072                 sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL AND path LIKE '%q/%%'", storage_id, extract_path);
2073         } else if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
2074                 char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0, };
2075                 ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, extract_path, folder_uuid, uid);
2076                 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
2077
2078                 sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL AND folder_uuid = '%q'", storage_id, folder_uuid);
2079         } else { /*Storage Scanning*/
2080                 sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL", storage_id);
2081         }
2082
2083         ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
2084         if (ret != MS_MEDIA_ERR_NONE) {
2085                 media_svc_error("error when get list. err = [%d]", ret);
2086                 return ret;
2087         }
2088
2089         db_data_array = g_array_new(FALSE, FALSE, sizeof(media_svc_item_info_s*));
2090         if (db_data_array == NULL) {
2091                 media_svc_error("db_data_array is NULL. Out of memory");
2092                 return MS_MEDIA_ERR_OUT_OF_MEMORY;
2093         }
2094
2095         while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
2096                 db_data = NULL;
2097                 db_data = malloc(sizeof(media_svc_item_info_s));
2098                 if (db_data == NULL) {
2099                         media_svc_error("Out of memory");
2100                         continue;
2101                 }
2102
2103                 db_data->path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
2104                 db_data->media_type = (int)sqlite3_column_int(sql_stmt, 1);
2105
2106                 g_array_append_val(db_data_array, db_data);
2107         }
2108
2109         SQLITE3_FINALIZE(sql_stmt);
2110
2111         while (db_data_array->len != 0) {
2112                 db_data = NULL;
2113                 db_data = g_array_index(db_data_array, media_svc_item_info_s*, 0);
2114                 g_array_remove_index(db_data_array, 0);
2115
2116                 if ((db_data == NULL) || (db_data->path == NULL)) {
2117                         media_svc_error("invalid db data");
2118                         continue;
2119                 }
2120
2121                 media_type = db_data->media_type;
2122                 media_svc_debug("path is %s, media type %d", db_data->path, media_type);
2123                 memset(&content_info, 0, sizeof(media_svc_content_info_s));
2124                 __media_svc_malloc_and_strncpy(&content_info.path, db_data->path);
2125
2126                 content_info.media_type = media_type;
2127                 content_info.storage_type = storage_type;
2128
2129                 _media_svc_set_default_value(&content_info, FALSE);
2130
2131                 if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
2132                         /*Do nothing.*/
2133                 } else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
2134                         ret = _media_svc_extract_image_metadata(db_handle, &content_info);
2135                 } else {
2136                         ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
2137                 }
2138
2139                 ret = _media_svc_insert_item_pass2(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
2140
2141                 _media_svc_destroy_content_info(&content_info);
2142                 SAFE_FREE(db_data->path);
2143                 SAFE_FREE(db_data);
2144                 idx++;
2145         }
2146
2147         if (idx > 0)
2148                 ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
2149
2150         g_array_free(db_data_array, FALSE);
2151         db_data_array = NULL;
2152
2153         media_svc_debug_fleave();
2154
2155         return MS_MEDIA_ERR_NONE;
2156 }
2157
2158 int media_svc_delete_invalid_folder_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, uid_t uid, int *delete_count)
2159 {
2160         int ret = MS_MEDIA_ERR_NONE;
2161         sqlite3 * db_handle = (sqlite3 *)handle;
2162
2163         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
2164
2165         ret = _media_svc_delete_invalid_folder_by_path(db_handle, storage_id, folder_path, uid, delete_count);
2166
2167         return ret;
2168 }
2169
2170 int media_svc_check_folder_exist_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path)
2171 {
2172         int ret = MS_MEDIA_ERR_NONE;
2173         sqlite3 * db_handle = (sqlite3 *)handle;
2174         int count = -1;
2175
2176         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
2177         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
2178         media_svc_retvm_if(!STRING_VALID(folder_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
2179
2180         ret = _media_svc_count_folder_with_path(db_handle, storage_id, folder_path, &count);
2181         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
2182
2183         if (count > 0) {
2184                 media_svc_debug("item is exist in database");
2185                 return MS_MEDIA_ERR_NONE;
2186         } else {
2187                 media_svc_debug("item is not exist in database");
2188                 return MS_MEDIA_ERR_DB_NO_RECORD;
2189         }
2190
2191         return MS_MEDIA_ERR_NONE;
2192 }
2193
2194 int media_svc_check_subfolder_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, int *count)
2195 {
2196         int ret = MS_MEDIA_ERR_NONE;
2197         sqlite3 * db_handle = (sqlite3 *)handle;
2198         int cnt = -1;
2199
2200         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
2201         media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
2202         media_svc_retvm_if(!STRING_VALID(folder_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
2203
2204         *count = 0;
2205         ret = _media_svc_count_subfolder_with_path(db_handle, storage_id, folder_path, &cnt);
2206         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
2207         *count = cnt;
2208
2209         if (cnt > 0) {
2210                 media_svc_debug("item is exist in database");
2211                 return MS_MEDIA_ERR_NONE;
2212         } else {
2213                 media_svc_debug("item is not exist in database");
2214                 return MS_MEDIA_ERR_DB_NO_RECORD;
2215         }
2216
2217         return MS_MEDIA_ERR_NONE;
2218 }
2219
2220 int media_svc_get_folder_id(MediaSvcHandle *handle, const char *storage_id, const char *path, char *folder_id)
2221 {
2222         int ret = MS_MEDIA_ERR_NONE;
2223         sqlite3 * db_handle = (sqlite3 *)handle;
2224
2225         media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
2226         media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
2227
2228         ret = _media_svc_get_folder_uuid(db_handle, storage_id, path, folder_id);
2229
2230         return ret;
2231 }
2232