change media db open options (check_db issue)
[platform/core/multimedia/libmedia-service.git] / plugin / media-content-plugin.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 <sys/stat.h>
24 #include <mm_file.h>
25 #include <media-thumbnail.h>
26 #include "media-svc.h"
27 #include "media-svc-util.h"
28
29 #define MEDIA_SVC_PLUGIN_ERROR_NONE             0
30 #define MEDIA_SVC_PLUGIN_ERROR                  -1
31
32 #define STRING_VALID(str)       \
33         ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
34 #define STORAGE_VALID(storage)\
35         (((storage == MEDIA_SVC_STORAGE_INTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL)) ? TRUE : FALSE)
36
37
38 typedef enum {
39         ERR_HANDLE = 1,
40         ERR_FILE_PATH,
41         ERR_FOLDER_PATH,
42         ERR_MIME_TYPE,
43         ERR_NOT_MEDIAFILE,
44         ERR_STORAGE_TYPE,
45         ERR_CHECK_ITEM,
46         ERR_MAX,
47 } media_svc_error_type_e;
48
49 static void __set_error_message(int err_type, char **err_msg);
50
51 static void __set_error_message(int err_type, char **err_msg)
52 {
53         if (err_msg)
54                 *err_msg = NULL;
55         else
56                 return;
57
58         if (err_type == ERR_HANDLE)
59                 *err_msg = strdup("invalid handle");
60         else if (err_type == ERR_FILE_PATH)
61                 *err_msg = strdup("invalid file path");
62         else if (err_type == ERR_FOLDER_PATH)
63                 *err_msg = strdup("invalid folder path");
64         else if (err_type == ERR_MIME_TYPE)
65                 *err_msg = strdup("invalid mime type");
66         else if (err_type == ERR_NOT_MEDIAFILE)
67                 *err_msg = strdup("not media content");
68         else if (err_type == ERR_STORAGE_TYPE)
69                 *err_msg = strdup("invalid storage type");
70         else if (err_type == ERR_CHECK_ITEM)
71                 *err_msg = strdup("item does not exist");
72         else if (err_type == MS_MEDIA_ERR_DB_CONNECT_FAIL)
73                 *err_msg = strdup("DB connect error");
74         else if (err_type == MS_MEDIA_ERR_DB_DISCONNECT_FAIL)
75                 *err_msg = strdup("DB disconnect error");
76         else if (err_type == MS_MEDIA_ERR_INVALID_PARAMETER)
77                 *err_msg = strdup("invalid parameter");
78         else if (err_type == MS_MEDIA_ERR_DB_INTERNAL)
79                 *err_msg = strdup("DB internal error");
80         else if (err_type == MS_MEDIA_ERR_DB_NO_RECORD)
81                 *err_msg = strdup("not found in DB");
82         else if (err_type == MS_MEDIA_ERR_INTERNAL)
83                 *err_msg = strdup("media service internal error");
84         else if (err_type == MS_MEDIA_ERR_DB_CORRUPT)
85                 *err_msg = strdup("DB corrupt error");
86         else
87                 *err_msg = strdup("error unknown");
88
89         return;
90 }
91
92 int connect_db(void **handle, uid_t uid, char **err_msg)
93 {
94         int ret = media_svc_connect(handle, uid, true);
95
96         if (ret < 0) {
97                 __set_error_message(ret, err_msg);
98                 return MEDIA_SVC_PLUGIN_ERROR;
99         }
100
101         return MEDIA_SVC_PLUGIN_ERROR_NONE;
102 }
103
104 int disconnect_db(void *handle, char **err_msg)
105 {
106         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
107
108         if (handle == NULL) {
109                 __set_error_message(ERR_HANDLE, err_msg);
110                 return MEDIA_SVC_PLUGIN_ERROR;
111         }
112
113         ret = media_svc_disconnect(handle);
114         if (ret < 0) {
115                 __set_error_message(ret, err_msg);
116                 return MEDIA_SVC_PLUGIN_ERROR;
117         }
118
119         return MEDIA_SVC_PLUGIN_ERROR_NONE;
120 }
121
122 int check_item_exist(void *handle, const char *file_path, bool *modified, char **err_msg)
123 {
124         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
125         *modified = TRUE;
126
127         if (handle == NULL) {
128                 __set_error_message(ERR_HANDLE, err_msg);
129                 return MEDIA_SVC_PLUGIN_ERROR;
130         }
131
132         if (!STRING_VALID(file_path)) {
133                 __set_error_message(ERR_FILE_PATH, err_msg);
134                 return MEDIA_SVC_PLUGIN_ERROR;
135         }
136
137         ret = media_svc_check_item_exist_by_path(handle, file_path);
138         if (ret == MS_MEDIA_ERR_NONE) {
139                 time_t modified_time = 0;
140                 unsigned long long file_size = 0;
141                 struct stat st;
142
143                 ret = media_svc_get_file_info(handle, file_path, &modified_time, &file_size);
144                 if (ret == MS_MEDIA_ERR_NONE) {
145                         memset(&st, 0, sizeof(struct stat));
146                         if (stat(file_path, &st) == 0) {
147                                 if ((st.st_mtime != modified_time) || (st.st_size != file_size))
148                                         *modified = TRUE;
149                                 else
150                                         *modified = FALSE;
151                         }
152                 }
153
154                 return MEDIA_SVC_PLUGIN_ERROR_NONE;     /*exist */
155         }
156
157         __set_error_message(ERR_CHECK_ITEM, err_msg);
158
159         return MEDIA_SVC_PLUGIN_ERROR;          /*not exist */
160 }
161
162 int insert_item_begin(void *handle, int item_cnt, int with_noti, int from_pid, char **err_msg)
163 {
164         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
165
166         if (handle == NULL) {
167                 __set_error_message(ERR_HANDLE, err_msg);
168                 return MEDIA_SVC_PLUGIN_ERROR;
169         }
170
171         ret = media_svc_insert_item_begin(handle, item_cnt, with_noti, from_pid);
172         if (ret < 0) {
173                 __set_error_message(ret, err_msg);
174                 return MEDIA_SVC_PLUGIN_ERROR;
175         }
176
177         return MEDIA_SVC_PLUGIN_ERROR_NONE;
178 }
179
180 int insert_item_end(void *handle, uid_t uid, char **err_msg)
181 {
182         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
183
184         if (handle == NULL) {
185                 __set_error_message(ERR_HANDLE, err_msg);
186                 return MEDIA_SVC_PLUGIN_ERROR;
187         }
188
189         ret = media_svc_insert_item_end(handle, uid);
190         if (ret < 0) {
191                 __set_error_message(ret, err_msg);
192                 return MEDIA_SVC_PLUGIN_ERROR;
193         }
194
195         return MEDIA_SVC_PLUGIN_ERROR_NONE;
196 }
197
198 int insert_item(void *handle, const char *file_path, int storage_type, uid_t uid, char **err_msg)
199 {
200         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
201
202         if (handle == NULL) {
203                 __set_error_message(ERR_HANDLE, err_msg);
204                 return MEDIA_SVC_PLUGIN_ERROR;
205         }
206
207         if (!STRING_VALID(file_path)) {
208                 __set_error_message(ERR_FILE_PATH, err_msg);
209                 return MEDIA_SVC_PLUGIN_ERROR;
210         }
211
212         if (!STORAGE_VALID(storage_type)) {
213                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
214                 return MEDIA_SVC_PLUGIN_ERROR;
215         }
216
217         ret = media_svc_insert_item_bulk(handle, storage_type, file_path, FALSE, uid);
218         if (ret < 0) {
219                 __set_error_message(ret, err_msg);
220                 return MEDIA_SVC_PLUGIN_ERROR;
221         }
222
223         return MEDIA_SVC_PLUGIN_ERROR_NONE;
224 }
225
226 int insert_item_immediately(void *handle, const char *file_path, int storage_type, uid_t uid, char **err_msg)
227 {
228         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
229
230         if (handle == NULL) {
231                 __set_error_message(ERR_HANDLE, err_msg);
232                 return MEDIA_SVC_PLUGIN_ERROR;
233         }
234
235         if (!STRING_VALID(file_path)) {
236                 __set_error_message(ERR_FILE_PATH, err_msg);
237                 return MEDIA_SVC_PLUGIN_ERROR;
238         }
239
240         if (!STORAGE_VALID(storage_type)) {
241                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
242                 return MEDIA_SVC_PLUGIN_ERROR;
243         }
244
245         ret = media_svc_insert_item_immediately(handle, storage_type, file_path, uid);
246         if (ret < 0) {
247                 __set_error_message(ret, err_msg);
248                 return MEDIA_SVC_PLUGIN_ERROR;
249         }
250
251         return MEDIA_SVC_PLUGIN_ERROR_NONE;
252 }
253
254 int insert_burst_item(void *handle, const char *file_path, int storage_type, uid_t uid, char **err_msg)
255 {
256         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
257
258         if (handle == NULL) {
259                 __set_error_message(ERR_HANDLE, err_msg);
260                 return MEDIA_SVC_PLUGIN_ERROR;
261         }
262
263         if (!STRING_VALID(file_path)) {
264                 __set_error_message(ERR_FILE_PATH, err_msg);
265                 return MEDIA_SVC_PLUGIN_ERROR;
266         }
267
268         if (!STORAGE_VALID(storage_type)) {
269                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
270                 return MEDIA_SVC_PLUGIN_ERROR;
271         }
272
273         ret = media_svc_insert_item_bulk(handle, storage_type, file_path, TRUE, uid);
274         if (ret < 0) {
275                 __set_error_message(ret, err_msg);
276                 return MEDIA_SVC_PLUGIN_ERROR;
277         }
278
279         return MEDIA_SVC_PLUGIN_ERROR_NONE;
280 }
281
282 int set_all_storage_items_validity(void *handle, int storage_type, int validity, uid_t uid, char **err_msg)
283 {
284         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
285
286         if (handle == NULL) {
287                 __set_error_message(ERR_HANDLE, err_msg);
288                 return MEDIA_SVC_PLUGIN_ERROR;
289         }
290
291         if (!STORAGE_VALID(storage_type)) {
292                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
293                 return MEDIA_SVC_PLUGIN_ERROR;
294         }
295
296         ret = media_svc_set_all_storage_items_validity(handle, storage_type, validity, uid);
297         if (ret < 0) {
298                 __set_error_message(ret, err_msg);
299                 return MEDIA_SVC_PLUGIN_ERROR;
300         }
301
302         return MEDIA_SVC_PLUGIN_ERROR_NONE;
303 }
304
305 int set_folder_item_validity(void *handle, const char *folder_path, int validity, int recursive, uid_t uid, char **err_msg)
306 {
307         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
308
309         if (handle == NULL) {
310                 __set_error_message(ERR_HANDLE, err_msg);
311                 return MEDIA_SVC_PLUGIN_ERROR;
312         }
313
314         if (!STRING_VALID(folder_path)) {
315                 __set_error_message(ERR_FOLDER_PATH, err_msg);
316                 return MEDIA_SVC_PLUGIN_ERROR;
317         }
318
319         ret = media_svc_set_folder_items_validity(handle, folder_path, validity, recursive, uid);
320         if (ret < 0) {
321                 __set_error_message(ret, err_msg);
322                 return MEDIA_SVC_PLUGIN_ERROR;
323         }
324
325         return MEDIA_SVC_PLUGIN_ERROR_NONE;
326 }
327
328 int set_item_validity_begin(void *handle, int item_cnt, char **err_msg)
329 {
330         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
331
332         if (handle == NULL) {
333                 __set_error_message(ERR_HANDLE, err_msg);
334                 return MEDIA_SVC_PLUGIN_ERROR;
335         }
336
337         ret = media_svc_set_item_validity_begin(handle, item_cnt);
338         if (ret < 0) {
339                 __set_error_message(ret, err_msg);
340                 return MEDIA_SVC_PLUGIN_ERROR;
341         }
342
343         return MEDIA_SVC_PLUGIN_ERROR_NONE;
344 }
345
346 int set_item_validity_end(void *handle, uid_t uid, char **err_msg)
347 {
348         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
349
350         if (handle == NULL) {
351                 __set_error_message(ERR_HANDLE, err_msg);
352                 return MEDIA_SVC_PLUGIN_ERROR;
353         }
354
355         ret = media_svc_set_item_validity_end(handle, uid);
356         if (ret < 0) {
357                 __set_error_message(ret, err_msg);
358                 return MEDIA_SVC_PLUGIN_ERROR;
359         }
360
361         return MEDIA_SVC_PLUGIN_ERROR_NONE;
362 }
363
364 int set_item_validity(void *handle, const char *file_path, int storage_type, int validity, uid_t uid, char **err_msg)
365 {
366         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
367
368         if (handle == NULL) {
369                 __set_error_message(ERR_HANDLE, err_msg);
370                 return MEDIA_SVC_PLUGIN_ERROR;
371         }
372
373         if (!STRING_VALID(file_path)) {
374                 __set_error_message(ERR_FILE_PATH, err_msg);
375                 return MEDIA_SVC_PLUGIN_ERROR;
376         }
377
378         if (!STORAGE_VALID(storage_type)) {
379                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
380                 return MEDIA_SVC_PLUGIN_ERROR;
381         }
382
383         ret = media_svc_set_item_validity(handle, file_path, validity, uid);
384
385         if (ret < 0) {
386                 __set_error_message(ret, err_msg);
387                 return MEDIA_SVC_PLUGIN_ERROR;
388         }
389
390         return MEDIA_SVC_PLUGIN_ERROR_NONE;
391 }
392
393 int delete_item(void *handle, const char *file_path, uid_t uid, char **err_msg)
394 {
395         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
396
397         if (handle == NULL) {
398                 __set_error_message(ERR_HANDLE, err_msg);
399                 return MEDIA_SVC_PLUGIN_ERROR;
400         }
401
402         if (!STRING_VALID(file_path)) {
403                 __set_error_message(ERR_FILE_PATH, err_msg);
404                 return MEDIA_SVC_PLUGIN_ERROR;
405         }
406
407         ret = media_svc_check_item_exist_by_path(handle, file_path);
408         if (ret == 0) {
409                 ret = media_svc_delete_item_by_path(handle, "media", file_path, uid);
410
411                 if (ret < 0) {
412                         __set_error_message(ret, err_msg);
413                         return MEDIA_SVC_PLUGIN_ERROR;
414                 } else
415                         return MEDIA_SVC_PLUGIN_ERROR_NONE;
416         }
417
418         __set_error_message(ERR_CHECK_ITEM, err_msg);   /*not exist in DB so can't delete item. */
419         return MEDIA_SVC_PLUGIN_ERROR;
420 }
421
422 int delete_all_items_in_storage(void *handle, int storage_type, uid_t uid, char **err_msg)
423 {
424         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
425
426         if (handle == NULL) {
427                 __set_error_message(ERR_HANDLE, err_msg);
428                 return MEDIA_SVC_PLUGIN_ERROR;
429         }
430
431         if (!STORAGE_VALID(storage_type)) {
432                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
433                 return MEDIA_SVC_PLUGIN_ERROR;
434         }
435
436         ret = media_svc_delete_all_items_in_storage(handle, storage_type, uid);
437         if (ret < 0) {
438                 __set_error_message(ret, err_msg);
439                 return MEDIA_SVC_PLUGIN_ERROR;
440         }
441
442         return MEDIA_SVC_PLUGIN_ERROR_NONE;
443 }
444
445 int delete_all_invalid_items_in_storage(void *handle, int storage_type, uid_t uid, char **err_msg)
446 {
447         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
448
449         if (handle == NULL) {
450                 __set_error_message(ERR_HANDLE, err_msg);
451                 return MEDIA_SVC_PLUGIN_ERROR;
452         }
453
454         if (!STORAGE_VALID(storage_type)) {
455                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
456                 return MEDIA_SVC_PLUGIN_ERROR;
457         }
458
459         ret = media_svc_delete_invalid_items_in_storage(handle, storage_type, uid);
460         if (ret < 0) {
461                 __set_error_message(ret, err_msg);
462                 return MEDIA_SVC_PLUGIN_ERROR;
463         }
464
465         return MEDIA_SVC_PLUGIN_ERROR_NONE;
466 }
467
468 int delete_all_invalid_items_in_folder(void *handle, const char *folder_path, uid_t uid, char **err_msg)
469 {
470         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
471
472         if (handle == NULL) {
473                 __set_error_message(ERR_HANDLE, err_msg);
474                 return MEDIA_SVC_PLUGIN_ERROR;
475         }
476
477         if (!STRING_VALID(folder_path)) {
478                 __set_error_message(ERR_FOLDER_PATH, err_msg);
479                 return MEDIA_SVC_PLUGIN_ERROR;
480         }
481
482         ret = media_svc_delete_invalid_items_in_folder(handle, folder_path, uid);
483         if (ret < 0) {
484                 __set_error_message(ret, err_msg);
485                 return MEDIA_SVC_PLUGIN_ERROR;
486         }
487
488         return MEDIA_SVC_PLUGIN_ERROR_NONE;
489 }
490
491
492 int update_begin(void)
493 {
494         return MEDIA_SVC_PLUGIN_ERROR_NONE;
495 }
496
497 int update_end(uid_t uid)
498 {
499         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
500
501         ret = thumbnail_request_extract_all_thumbs(uid);
502         if (ret < 0) {
503                 return MEDIA_SVC_PLUGIN_ERROR;
504         }
505
506         return MEDIA_SVC_PLUGIN_ERROR_NONE;
507 }
508
509 int send_dir_update_noti(void *handle, const char *dir_path, char **err_msg)
510 {
511         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
512
513         if (!STRING_VALID(dir_path)) {
514                 __set_error_message(ERR_FOLDER_PATH, err_msg);
515                 return MEDIA_SVC_PLUGIN_ERROR;
516         }
517
518         ret = media_svc_send_dir_update_noti(handle, dir_path);
519         if (ret < 0) {
520                 __set_error_message(ret, err_msg);
521                 return MEDIA_SVC_PLUGIN_ERROR;
522         }
523
524         return MEDIA_SVC_PLUGIN_ERROR_NONE;
525 }
526
527 int count_delete_items_in_folder(void *handle, const char *folder_path, int *count, char **err_msg)
528 {
529         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
530
531         if (handle == NULL) {
532                 __set_error_message(ERR_HANDLE, err_msg);
533                 return MEDIA_SVC_PLUGIN_ERROR;
534         }
535
536         if (count == NULL) {
537                 __set_error_message(ERR_HANDLE, err_msg);
538                 return MEDIA_SVC_PLUGIN_ERROR;
539         }
540
541         if (!STRING_VALID(folder_path)) {
542                 __set_error_message(ERR_FOLDER_PATH, err_msg);
543                 return MEDIA_SVC_PLUGIN_ERROR;
544         }
545
546         ret = media_svc_count_invalid_items_in_folder(handle, folder_path, count);
547         if (ret < 0) {
548                 __set_error_message(ret, err_msg);
549                 return MEDIA_SVC_PLUGIN_ERROR;
550         }
551
552         return MEDIA_SVC_PLUGIN_ERROR_NONE;
553 }
554
555 int check_db(void *handle, uid_t uid, char **err_msg)
556 {
557         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
558
559         /*check db schema*/
560         ret = media_svc_create_table(handle, uid);
561         if (ret < 0) {
562                 __set_error_message(ret, err_msg);
563                 return MEDIA_SVC_PLUGIN_ERROR;
564         }
565
566         /*check db version*/
567         ret = media_svc_check_db_upgrade(handle, uid);
568         if (ret < 0) {
569                 __set_error_message(ret, err_msg);
570                 return MEDIA_SVC_PLUGIN_ERROR;
571         }
572
573         return MEDIA_SVC_PLUGIN_ERROR_NONE;
574 }
575
576 int check_db_corrupt(void *handle, char **err_msg)
577 {
578         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
579
580         /*check db version*/
581         ret = media_svc_check_db_corrupt(handle);
582         if (ret < 0) {
583                 __set_error_message(ret, err_msg);
584                 return MEDIA_SVC_PLUGIN_ERROR;
585         }
586
587         return MEDIA_SVC_PLUGIN_ERROR_NONE;
588 }
589
590 int get_folder_list(void *handle, char *start_path, char ***folder_list, int **modified_time_list, int **item_num_list, int *count, char **err_msg)
591 {
592         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
593
594         if (handle == NULL) {
595                 __set_error_message(ERR_HANDLE, err_msg);
596                 return MEDIA_SVC_PLUGIN_ERROR;
597         }
598
599         if (count == NULL) {
600                 __set_error_message(ERR_HANDLE, err_msg);
601                 return MEDIA_SVC_PLUGIN_ERROR;
602         }
603
604         ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t **)modified_time_list, item_num_list, count);
605         if (ret < 0) {
606                 __set_error_message(ret, err_msg);
607                 return MEDIA_SVC_PLUGIN_ERROR;
608         }
609
610         return MEDIA_SVC_PLUGIN_ERROR_NONE;
611 }
612
613 int update_folder_time(void *handle, char *folder_path, uid_t uid, char **err_msg)
614 {
615         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
616
617         if (handle == NULL) {
618                 __set_error_message(ERR_HANDLE, err_msg);
619                 return MEDIA_SVC_PLUGIN_ERROR;
620         }
621
622         if (folder_path == NULL) {
623                 __set_error_message(ERR_HANDLE, err_msg);
624                 return MEDIA_SVC_PLUGIN_ERROR;
625         }
626
627         ret = media_svc_update_folder_time(handle, folder_path, uid);
628         if (ret < 0) {
629                 __set_error_message(ret, err_msg);
630                 return MEDIA_SVC_PLUGIN_ERROR;
631         }
632
633         return MEDIA_SVC_PLUGIN_ERROR_NONE;
634 }
635
636 int update_item_begin(void *handle, int item_cnt, char **err_msg)
637 {
638         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
639
640         if (handle == NULL) {
641                 __set_error_message(ERR_HANDLE, err_msg);
642                 return MEDIA_SVC_PLUGIN_ERROR;
643         }
644
645         ret = media_svc_update_item_begin(handle, item_cnt);
646         if (ret < 0) {
647                 __set_error_message(ret, err_msg);
648                 return MEDIA_SVC_PLUGIN_ERROR;
649         }
650
651         return MEDIA_SVC_PLUGIN_ERROR_NONE;
652 }
653
654 int update_item_end(void *handle, uid_t uid, char **err_msg)
655 {
656         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
657
658         if (handle == NULL) {
659                 __set_error_message(ERR_HANDLE, err_msg);
660                 return MEDIA_SVC_PLUGIN_ERROR;
661         }
662
663         ret = media_svc_update_item_end(handle, uid);
664         if (ret < 0) {
665                 __set_error_message(ret, err_msg);
666                 return MEDIA_SVC_PLUGIN_ERROR;
667         }
668
669         return MEDIA_SVC_PLUGIN_ERROR_NONE;
670 }
671
672 int update_item_meta(void *handle, const char *file_path, int storage_type, uid_t uid, char **err_msg)
673 {
674         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
675
676         if (handle == NULL) {
677                 __set_error_message(ERR_HANDLE, err_msg);
678                 return MEDIA_SVC_PLUGIN_ERROR;
679         }
680
681         if (file_path == NULL) {
682                 __set_error_message(ERR_HANDLE, err_msg);
683                 return MEDIA_SVC_PLUGIN_ERROR;
684         }
685
686         ret = media_svc_update_item_meta(handle, file_path, storage_type, uid);
687         if (ret < 0) {
688                 __set_error_message(ret, err_msg);
689                 return MEDIA_SVC_PLUGIN_ERROR;
690         }
691
692         return MEDIA_SVC_PLUGIN_ERROR_NONE;
693 }