Merge "Fix playlist/tag bulk update" into tizen
[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-util.h>
27 #include "media-svc.h"
28 #include "media-svc-util.h"
29
30 #define MEDIA_SVC_PLUGIN_ERROR_NONE             0
31 #define MEDIA_SVC_PLUGIN_ERROR                  -1
32
33 #define STRING_VALID(str)       \
34         ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
35 #define STORAGE_VALID(storage)\
36         (((storage == MEDIA_SVC_STORAGE_INTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL_USB)) ? TRUE : FALSE)
37
38
39 typedef enum {
40         ERR_HANDLE = 1,
41         ERR_FILE_PATH,
42         ERR_FOLDER_PATH,
43         ERR_MIME_TYPE,
44         ERR_NOT_MEDIAFILE,
45         ERR_STORAGE_TYPE,
46         ERR_CHECK_ITEM,
47         ERR_MAX,
48 } media_svc_error_type_e;
49
50 static void __set_error_message(int err_type, char **err_msg);
51
52 static void __set_error_message(int err_type, char **err_msg)
53 {
54         if (err_msg)
55                 *err_msg = NULL;
56         else
57                 return;
58
59         if (err_type == ERR_HANDLE)
60                 *err_msg = strdup("invalid handle");
61         else if (err_type == ERR_FILE_PATH)
62                 *err_msg = strdup("invalid file path");
63         else if (err_type == ERR_FOLDER_PATH)
64                 *err_msg = strdup("invalid folder path");
65         else if (err_type == ERR_MIME_TYPE)
66                 *err_msg = strdup("invalid mime type");
67         else if (err_type == ERR_NOT_MEDIAFILE)
68                 *err_msg = strdup("not media content");
69         else if (err_type == ERR_STORAGE_TYPE)
70                 *err_msg = strdup("invalid storage type");
71         else if (err_type == ERR_CHECK_ITEM)
72                 *err_msg = strdup("item does not exist");
73         else if (err_type == MS_MEDIA_ERR_DB_CONNECT_FAIL)
74                 *err_msg = strdup("DB connect error");
75         else if (err_type == MS_MEDIA_ERR_DB_DISCONNECT_FAIL)
76                 *err_msg = strdup("DB disconnect error");
77         else if (err_type == MS_MEDIA_ERR_INVALID_PARAMETER)
78                 *err_msg = strdup("invalid parameter");
79         else if (err_type == MS_MEDIA_ERR_DB_INTERNAL)
80                 *err_msg = strdup("DB internal error");
81         else if (err_type == MS_MEDIA_ERR_DB_NO_RECORD)
82                 *err_msg = strdup("not found in DB");
83         else if (err_type == MS_MEDIA_ERR_INTERNAL)
84                 *err_msg = strdup("media service internal error");
85         else if (err_type == MS_MEDIA_ERR_DB_CORRUPT)
86                 *err_msg = strdup("DB corrupt error");
87         else
88                 *err_msg = strdup("error unknown");
89
90         return;
91 }
92
93 int connect_db(void **handle, uid_t uid, char **err_msg)
94 {
95         int ret = media_svc_connect(handle, uid, true);
96
97         if (ret < 0) {
98                 __set_error_message(ret, err_msg);
99                 return MEDIA_SVC_PLUGIN_ERROR;
100         }
101
102         return MEDIA_SVC_PLUGIN_ERROR_NONE;
103 }
104
105 int disconnect_db(void *handle, char **err_msg)
106 {
107         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
108
109         if (handle == NULL) {
110                 __set_error_message(ERR_HANDLE, err_msg);
111                 return MEDIA_SVC_PLUGIN_ERROR;
112         }
113
114         ret = media_svc_disconnect(handle);
115         if (ret < 0) {
116                 __set_error_message(ret, err_msg);
117                 return MEDIA_SVC_PLUGIN_ERROR;
118         }
119
120         return MEDIA_SVC_PLUGIN_ERROR_NONE;
121 }
122
123 int cleanup_db(void *handle, uid_t uid, char **err_msg)
124 {
125         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
126
127         if (handle == NULL) {
128                 __set_error_message(ERR_HANDLE, err_msg);
129                 return MEDIA_SVC_PLUGIN_ERROR;
130         }
131
132         ret = media_svc_cleanup_db(handle, uid);
133         if (ret < 0) {
134                 __set_error_message(ret, err_msg);
135                 return MEDIA_SVC_PLUGIN_ERROR;
136         }
137
138         return MEDIA_SVC_PLUGIN_ERROR_NONE;
139 }
140
141 int check_item_exist(void *handle, const char *storage_id, const char *file_path, bool *modified, char **err_msg)
142 {
143         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
144         *modified = TRUE;
145
146         if (handle == NULL) {
147                 __set_error_message(ERR_HANDLE, err_msg);
148                 return MEDIA_SVC_PLUGIN_ERROR;
149         }
150
151         if (!STRING_VALID(file_path)) {
152                 __set_error_message(ERR_FILE_PATH, err_msg);
153                 return MEDIA_SVC_PLUGIN_ERROR;
154         }
155
156         time_t modified_time = 0;
157         unsigned long long file_size = 0;
158         struct stat st;
159
160         ret = media_svc_get_file_info(handle, storage_id, file_path, &modified_time, &file_size);
161         if (ret == MS_MEDIA_ERR_NONE) {
162                 memset(&st, 0, sizeof(struct stat));
163                 if (stat(file_path, &st) == 0) {
164                         if ((st.st_mtime != modified_time) || (st.st_size != file_size))
165                                 *modified = TRUE;
166                         else
167                                 *modified = FALSE;
168                 }
169
170                 return MEDIA_SVC_PLUGIN_ERROR_NONE;     /*exist */
171         }
172
173         __set_error_message(ERR_CHECK_ITEM, err_msg);
174
175         return MEDIA_SVC_PLUGIN_ERROR;          /*not exist */
176 }
177
178 int insert_item_begin(void *handle, int item_cnt, int with_noti, int from_pid, char **err_msg)
179 {
180         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
181
182         ret = media_svc_insert_item_begin(item_cnt, with_noti, from_pid);
183         if (ret < 0) {
184                 __set_error_message(ret, err_msg);
185                 return MEDIA_SVC_PLUGIN_ERROR;
186         }
187
188         return MEDIA_SVC_PLUGIN_ERROR_NONE;
189 }
190
191 int insert_item_end(void *handle, uid_t uid, char **err_msg)
192 {
193         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
194
195         ret = media_svc_insert_item_end(uid);
196         if (ret < 0) {
197                 __set_error_message(ret, err_msg);
198                 return MEDIA_SVC_PLUGIN_ERROR;
199         }
200
201         return MEDIA_SVC_PLUGIN_ERROR_NONE;
202 }
203
204 int insert_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
205 {
206         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
207
208         if (handle == NULL) {
209                 __set_error_message(ERR_HANDLE, err_msg);
210                 return MEDIA_SVC_PLUGIN_ERROR;
211         }
212
213         if (!STRING_VALID(file_path)) {
214                 __set_error_message(ERR_FILE_PATH, err_msg);
215                 return MEDIA_SVC_PLUGIN_ERROR;
216         }
217
218         if (!STORAGE_VALID(storage_type)) {
219                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
220                 return MEDIA_SVC_PLUGIN_ERROR;
221         }
222
223         ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, FALSE, uid);
224         if (ret < 0) {
225                 __set_error_message(ret, err_msg);
226                 return MEDIA_SVC_PLUGIN_ERROR;
227         }
228
229         return MEDIA_SVC_PLUGIN_ERROR_NONE;
230 }
231
232 int insert_burst_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
233 {
234         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
235
236         if (handle == NULL) {
237                 __set_error_message(ERR_HANDLE, err_msg);
238                 return MEDIA_SVC_PLUGIN_ERROR;
239         }
240
241         if (!STRING_VALID(file_path)) {
242                 __set_error_message(ERR_FILE_PATH, err_msg);
243                 return MEDIA_SVC_PLUGIN_ERROR;
244         }
245
246         if (!STORAGE_VALID(storage_type)) {
247                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
248                 return MEDIA_SVC_PLUGIN_ERROR;
249         }
250
251         ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, TRUE, uid);
252         if (ret < 0) {
253                 __set_error_message(ret, err_msg);
254                 return MEDIA_SVC_PLUGIN_ERROR;
255         }
256
257         return MEDIA_SVC_PLUGIN_ERROR_NONE;
258 }
259
260 int set_all_storage_items_validity(void *handle, const char *storage_id, int storage_type, int validity, uid_t uid, char **err_msg)
261 {
262         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
263
264         if (!STORAGE_VALID(storage_type)) {
265                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
266                 return MEDIA_SVC_PLUGIN_ERROR;
267         }
268
269         ret = media_svc_set_all_storage_items_validity(storage_id, storage_type, validity, uid);
270         if (ret < 0) {
271                 __set_error_message(ret, err_msg);
272                 return MEDIA_SVC_PLUGIN_ERROR;
273         }
274
275         return MEDIA_SVC_PLUGIN_ERROR_NONE;
276 }
277
278 int set_folder_item_validity(void *handle, const char *storage_id, const char *folder_path, int validity, int recursive, uid_t uid, char **err_msg)
279 {
280         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
281
282         if (handle == NULL) {
283                 __set_error_message(ERR_HANDLE, err_msg);
284                 return MEDIA_SVC_PLUGIN_ERROR;
285         }
286
287         if (!STRING_VALID(folder_path)) {
288                 __set_error_message(ERR_FOLDER_PATH, err_msg);
289                 return MEDIA_SVC_PLUGIN_ERROR;
290         }
291
292         ret = media_svc_set_folder_items_validity(handle, storage_id, folder_path, validity, recursive, uid);
293         if (ret < 0) {
294                 __set_error_message(ret, err_msg);
295                 return MEDIA_SVC_PLUGIN_ERROR;
296         }
297
298         return MEDIA_SVC_PLUGIN_ERROR_NONE;
299 }
300
301 int set_item_validity_begin(void *handle, int item_cnt, char **err_msg)
302 {
303         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
304
305         ret = media_svc_set_item_validity_begin(item_cnt);
306         if (ret < 0) {
307                 __set_error_message(ret, err_msg);
308                 return MEDIA_SVC_PLUGIN_ERROR;
309         }
310
311         return MEDIA_SVC_PLUGIN_ERROR_NONE;
312 }
313
314 int set_item_validity_end(void *handle, uid_t uid, char **err_msg)
315 {
316         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
317
318         ret = media_svc_set_item_validity_end(uid);
319         if (ret < 0) {
320                 __set_error_message(ret, err_msg);
321                 return MEDIA_SVC_PLUGIN_ERROR;
322         }
323
324         return MEDIA_SVC_PLUGIN_ERROR_NONE;
325 }
326
327 int set_item_validity(void *handle, const char *storage_id, const char *file_path, int storage_type, int validity, uid_t uid, char **err_msg)
328 {
329         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
330
331         if (!STRING_VALID(file_path)) {
332                 __set_error_message(ERR_FILE_PATH, err_msg);
333                 return MEDIA_SVC_PLUGIN_ERROR;
334         }
335
336         ret = media_svc_set_item_validity(storage_id, file_path, validity, uid);
337
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 delete_item(void *handle, const char *storage_id, const char *file_path, 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         if (!STRING_VALID(file_path)) {
356                 __set_error_message(ERR_FILE_PATH, err_msg);
357                 return MEDIA_SVC_PLUGIN_ERROR;
358         }
359
360         ret = media_svc_check_item_exist_by_path(handle, storage_id, file_path);
361         if (ret == 0) {
362                 ret = media_svc_delete_item_by_path(handle, storage_id, file_path, uid);
363
364                 if (ret < 0) {
365                         __set_error_message(ret, err_msg);
366                         return MEDIA_SVC_PLUGIN_ERROR;
367                 } else
368                         return MEDIA_SVC_PLUGIN_ERROR_NONE;
369         }
370
371         __set_error_message(ERR_CHECK_ITEM, err_msg);   /*not exist in DB so can't delete item. */
372         return MEDIA_SVC_PLUGIN_ERROR;
373 }
374
375 int delete_all_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
376 {
377         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
378
379         if (!STORAGE_VALID(storage_type)) {
380                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
381                 return MEDIA_SVC_PLUGIN_ERROR;
382         }
383
384         ret = media_svc_delete_all_items_in_storage(storage_id, storage_type, uid);
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_all_invalid_items_in_storage(void *handle, const char *storage_id, int storage_type, 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 (!STORAGE_VALID(storage_type)) {
403                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
404                 return MEDIA_SVC_PLUGIN_ERROR;
405         }
406
407         ret = media_svc_delete_invalid_items_in_storage(handle, storage_id, storage_type, uid);
408         if (ret < 0) {
409                 __set_error_message(ret, err_msg);
410                 return MEDIA_SVC_PLUGIN_ERROR;
411         }
412
413         return MEDIA_SVC_PLUGIN_ERROR_NONE;
414 }
415
416 int send_dir_update_noti(void *handle, const char *storage_id, const char *dir_path, const char *folder_id, int update_type, int pid, char **err_msg)
417 {
418         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
419
420         if (!STRING_VALID(dir_path)) {
421                 __set_error_message(ERR_FOLDER_PATH, err_msg);
422                 return MEDIA_SVC_PLUGIN_ERROR;
423         }
424
425         ret = media_svc_send_dir_update_noti(handle, storage_id, dir_path, folder_id, (media_item_update_type_e)update_type, pid);
426         if (ret < 0) {
427                 __set_error_message(ret, err_msg);
428                 return MEDIA_SVC_PLUGIN_ERROR;
429         }
430
431         return MEDIA_SVC_PLUGIN_ERROR_NONE;
432 }
433
434 int check_db(void *handle, uid_t uid, char **err_msg)
435 {
436         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
437         int user_version = -1;
438
439         ret = media_svc_get_user_version(handle, &user_version);
440         if (ret < 0) {
441                 __set_error_message(ret, err_msg);
442                 return MEDIA_SVC_PLUGIN_ERROR;
443         }
444
445         if (user_version == 0) {
446                 /*check db schema*/
447                 ret = media_svc_create_table(uid);
448                 if (ret < 0) {
449                         __set_error_message(ret, err_msg);
450                         return MEDIA_SVC_PLUGIN_ERROR;
451                 }
452         } else {
453                 /*check db version*/
454                 ret = media_svc_check_db_upgrade(handle, user_version, uid);
455                 if (ret < 0) {
456                         __set_error_message(ret, err_msg);
457                         return MEDIA_SVC_PLUGIN_ERROR;
458                 }
459         }
460
461         return MEDIA_SVC_PLUGIN_ERROR_NONE;
462 }
463
464 int update_folder_time(void *handle, const char *storage_id, char *folder_path, uid_t uid, char **err_msg)
465 {
466         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
467
468         if (handle == NULL) {
469                 __set_error_message(ERR_HANDLE, err_msg);
470                 return MEDIA_SVC_PLUGIN_ERROR;
471         }
472
473         if (folder_path == NULL) {
474                 __set_error_message(ERR_HANDLE, err_msg);
475                 return MEDIA_SVC_PLUGIN_ERROR;
476         }
477
478         ret = media_svc_update_folder_time(handle, storage_id, folder_path, uid);
479         if (ret < 0) {
480                 __set_error_message(ret, err_msg);
481                 return MEDIA_SVC_PLUGIN_ERROR;
482         }
483
484         return MEDIA_SVC_PLUGIN_ERROR_NONE;
485 }
486
487 int get_uuid(void * handle, char **uuid, char **err_msg)
488 {
489         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
490
491         ret = media_svc_generate_uuid(uuid);
492         if (ret < 0) {
493                 __set_error_message(ret, err_msg);
494                 return MEDIA_SVC_PLUGIN_ERROR;
495         }
496
497         return MEDIA_SVC_PLUGIN_ERROR_NONE;
498 }
499
500 int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg)
501 {
502         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
503
504         if (handle == NULL) {
505                 __set_error_message(ERR_HANDLE, err_msg);
506                 return MEDIA_SVC_PLUGIN_ERROR;
507         }
508
509         ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
510         if (ret < 0) {
511                 __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
512                 return MEDIA_SVC_PLUGIN_ERROR;
513         }
514
515         return MEDIA_SVC_PLUGIN_ERROR_NONE;
516 }
517
518 int check_storage(void * handle, const char *storage_id, char **storage_path, int *validity, uid_t uid, char **err_msg)
519 {
520         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
521
522         if (handle == NULL) {
523                 __set_error_message(ERR_HANDLE, err_msg);
524                 return MEDIA_SVC_PLUGIN_ERROR;
525         }
526
527         ret = media_svc_check_storage(handle, storage_id, storage_path, validity, uid);
528         if (ret < 0) {
529                 __set_error_message(ret, err_msg);
530                 return MEDIA_SVC_PLUGIN_ERROR;
531         }
532
533         return MEDIA_SVC_PLUGIN_ERROR_NONE;
534 }
535
536 int insert_storage(void *handle, const char *storage_id, int storage_type, const char *storage_name, const char *storage_path, uid_t uid, char **err_msg)
537 {
538         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
539
540         if (handle == NULL) {
541                 __set_error_message(ERR_HANDLE, err_msg);
542                 return MEDIA_SVC_PLUGIN_ERROR;
543         }
544
545         ret = media_svc_insert_storage(handle, storage_id, storage_name, storage_path, storage_type, uid);
546         if (ret < 0) {
547                 __set_error_message(ret, err_msg);
548                 return MEDIA_SVC_PLUGIN_ERROR;
549         }
550
551         return MEDIA_SVC_PLUGIN_ERROR_NONE;
552 }
553
554 int update_storage(void *handle, const char *storage_id, const char *storage_path, uid_t uid, char **err_msg)
555 {
556         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
557
558         if (handle == NULL) {
559                 __set_error_message(ERR_HANDLE, err_msg);
560                 return MEDIA_SVC_PLUGIN_ERROR;
561         }
562
563         ret = media_svc_update_storage(handle, storage_id, storage_path, uid);
564         if (ret < 0) {
565                 __set_error_message(ret, err_msg);
566                 return MEDIA_SVC_PLUGIN_ERROR;
567         }
568
569         return MEDIA_SVC_PLUGIN_ERROR_NONE;
570 }
571
572 int delete_storage(void * handle, const char *storage_id, uid_t uid, char **err_msg)
573 {
574         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
575
576         if (handle == NULL) {
577                 __set_error_message(ERR_HANDLE, err_msg);
578                 return MEDIA_SVC_PLUGIN_ERROR;
579         }
580
581         ret = media_svc_delete_storage(handle, storage_id, uid);
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 set_storage_validity(void * handle, const char *storage_id, int validity, uid_t uid, 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         ret = media_svc_set_storage_validity(handle, storage_id, validity, uid);
600         if (ret < 0) {
601                 __set_error_message(ret, err_msg);
602                 return MEDIA_SVC_PLUGIN_ERROR;
603         }
604
605         return MEDIA_SVC_PLUGIN_ERROR_NONE;
606 }
607
608 int set_all_storage_validity(void * handle, int validity, uid_t uid, char **err_msg)
609 {
610         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
611
612         if (handle == NULL) {
613                 __set_error_message(ERR_HANDLE, err_msg);
614                 return MEDIA_SVC_PLUGIN_ERROR;
615         }
616
617         ret = media_svc_set_storage_validity(handle, NULL, validity, uid);
618         if (ret < 0) {
619                 __set_error_message(ret, err_msg);
620                 return MEDIA_SVC_PLUGIN_ERROR;
621         }
622
623         return MEDIA_SVC_PLUGIN_ERROR_NONE;
624 }
625
626 int get_storage_id(void * handle, const char *path, char *storage_id, uid_t uid, char **err_msg)
627 {
628         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
629
630         if (handle == NULL) {
631                 __set_error_message(ERR_HANDLE, err_msg);
632                 return MEDIA_SVC_PLUGIN_ERROR;
633         }
634
635         ret = media_svc_get_storage_id(handle, path, storage_id, uid);
636         if (ret < 0) {
637                 __set_error_message(ret, err_msg);
638                 return MEDIA_SVC_PLUGIN_ERROR;
639         }
640
641         return MEDIA_SVC_PLUGIN_ERROR_NONE;
642 }
643
644 int set_storage_scan_status(void *handle, const char *storage_id, int status, uid_t uid, char **err_msg)
645 {
646         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
647         media_svc_scan_status_type_e storage_status = status;
648
649         ret = media_svc_set_storage_scan_status(storage_id, storage_status, uid);
650         if (ret < 0) {
651                 __set_error_message(ret, err_msg);
652                 return MEDIA_SVC_PLUGIN_ERROR;
653         }
654
655         return MEDIA_SVC_PLUGIN_ERROR_NONE;
656 }
657
658 int get_storage_list(void *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count, char **err_msg)
659 {
660         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
661
662         if (handle == NULL) {
663                 __set_error_message(ERR_HANDLE, err_msg);
664                 return MEDIA_SVC_PLUGIN_ERROR;
665         }
666
667         if (count == NULL) {
668                 __set_error_message(ERR_HANDLE, err_msg);
669                 return MEDIA_SVC_PLUGIN_ERROR;
670         }
671
672         ret = media_svc_get_storage_list(handle, storage_list, storage_id_list, scan_status_list, count);
673         if (ret < 0) {
674                 __set_error_message(ret, err_msg);
675                 return MEDIA_SVC_PLUGIN_ERROR;
676         }
677
678         return MEDIA_SVC_PLUGIN_ERROR_NONE;
679 }
680
681 int update_item_begin(void *handle, int item_cnt, char **err_msg)
682 {
683         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
684
685         ret = media_svc_update_item_begin(item_cnt);
686         if (ret < 0) {
687                 __set_error_message(ret, err_msg);
688                 return MEDIA_SVC_PLUGIN_ERROR;
689         }
690
691         return MEDIA_SVC_PLUGIN_ERROR_NONE;
692 }
693
694 int update_item_end(void *handle, uid_t uid, char **err_msg)
695 {
696         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
697
698         ret = media_svc_update_item_end(uid);
699         if (ret < 0) {
700                 __set_error_message(ret, err_msg);
701                 return MEDIA_SVC_PLUGIN_ERROR;
702         }
703
704         return MEDIA_SVC_PLUGIN_ERROR_NONE;
705 }
706
707 int update_item_meta(void *handle, const char *file_path, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
708 {
709         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
710
711         if (handle == NULL) {
712                 __set_error_message(ERR_HANDLE, err_msg);
713                 return MEDIA_SVC_PLUGIN_ERROR;
714         }
715
716         if (file_path == NULL) {
717                 __set_error_message(ERR_HANDLE, err_msg);
718                 return MEDIA_SVC_PLUGIN_ERROR;
719         }
720
721         if (storage_id == NULL) {
722                 __set_error_message(ERR_HANDLE, err_msg);
723                 return MEDIA_SVC_PLUGIN_ERROR;
724         }
725
726         ret = media_svc_update_item_meta(handle, file_path, storage_id, storage_type, uid);
727         if (ret < 0) {
728                 __set_error_message(ret, err_msg);
729                 return MEDIA_SVC_PLUGIN_ERROR;
730         }
731
732         return MEDIA_SVC_PLUGIN_ERROR_NONE;
733 }
734
735 int insert_item_scan(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
736 {
737         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
738
739         if (handle == NULL) {
740                 __set_error_message(ERR_HANDLE, err_msg);
741                 return MEDIA_SVC_PLUGIN_ERROR;
742         }
743
744         if (!STRING_VALID(file_path)) {
745                 __set_error_message(ERR_FILE_PATH, err_msg);
746                 return MEDIA_SVC_PLUGIN_ERROR;
747         }
748
749         if (!STORAGE_VALID(storage_type)) {
750                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
751                 return MEDIA_SVC_PLUGIN_ERROR;
752         }
753
754         ret = media_svc_insert_item_pass1(handle, storage_id, storage_type, file_path, FALSE, uid);
755         if (ret < 0) {
756                 __set_error_message(ret, err_msg);
757                 return MEDIA_SVC_PLUGIN_ERROR;
758         }
759
760         return MEDIA_SVC_PLUGIN_ERROR_NONE;
761 }
762
763 int get_extract_list(void* handle, const char* storage_id, int storage_type, int scan_type, const char* path, int burst, uid_t uid, void* array, char** err_msg)
764 {
765         /* For scanner V2 */
766         return MEDIA_SVC_PLUGIN_ERROR_NONE;
767 }
768
769 int update_one_extract_item(void* handle, const char* storage_id, int storage_type, void* data, int burst, char** err_msg)
770 {
771         /* For scanner V2 */
772         return MEDIA_SVC_PLUGIN_ERROR_NONE;
773 }
774
775 int query_do_update_list(void* handle, char** err_msg)
776 {
777         /* For scanner V2 */
778         return MEDIA_SVC_PLUGIN_ERROR_NONE;
779 }
780
781 int insert_folder_begin(void * handle, int item_cnt, char **err_msg)
782 {
783         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
784
785         ret = media_svc_insert_folder_begin(item_cnt);
786         if (ret < 0) {
787                 __set_error_message(ret, err_msg);
788                 return MEDIA_SVC_PLUGIN_ERROR;
789         }
790
791         return MEDIA_SVC_PLUGIN_ERROR_NONE;
792 }
793
794 int insert_folder_end(void *handle, uid_t uid, char **err_msg)
795 {
796         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
797
798         ret = media_svc_insert_folder_end(uid);
799         if (ret < 0) {
800                 __set_error_message(ret, err_msg);
801                 return MEDIA_SVC_PLUGIN_ERROR;
802         }
803
804         return MEDIA_SVC_PLUGIN_ERROR_NONE;
805 }
806
807 int insert_folder(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
808 {
809         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
810
811         if (handle == NULL) {
812                 __set_error_message(ERR_HANDLE, err_msg);
813                 return MEDIA_SVC_PLUGIN_ERROR;
814         }
815
816         if (!STRING_VALID(file_path)) {
817                 __set_error_message(ERR_FILE_PATH, err_msg);
818                 return MEDIA_SVC_PLUGIN_ERROR;
819         }
820
821         if (!STORAGE_VALID(storage_type)) {
822                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
823                 return MEDIA_SVC_PLUGIN_ERROR;
824         }
825
826         ret = media_svc_insert_folder(handle, storage_id, storage_type, file_path, uid);
827         if (ret < 0) {
828                 __set_error_message(ret, err_msg);
829                 return MEDIA_SVC_PLUGIN_ERROR;
830         }
831
832         return MEDIA_SVC_PLUGIN_ERROR_NONE;
833 }
834
835 int delete_invalid_folder(void * handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
836 {
837         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
838
839         ret = media_svc_delete_invalid_folder(storage_id, storage_type, uid);
840         if (ret < 0) {
841                 __set_error_message(ret, err_msg);
842                 return MEDIA_SVC_PLUGIN_ERROR;
843         }
844
845         return MEDIA_SVC_PLUGIN_ERROR_NONE;
846 }
847
848 int set_folder_validity(void * handle, const char *storage_id, const char* start_path, int validity, bool is_recursive, uid_t uid, char **err_msg)
849 {
850         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
851
852         if (handle == NULL) {
853                 __set_error_message(ERR_HANDLE, err_msg);
854                 return MEDIA_SVC_PLUGIN_ERROR;
855         }
856
857         ret = media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
858         if (ret < 0) {
859                 __set_error_message(ret, err_msg);
860                 return MEDIA_SVC_PLUGIN_ERROR;
861         }
862
863         return MEDIA_SVC_PLUGIN_ERROR_NONE;
864 }
865
866 int get_folder_scan_status(void *handle, const char *storage_id, const char *path, int *status, char **err_msg)
867 {
868         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
869         int storage_status = 0;
870
871         if (handle == NULL) {
872                 __set_error_message(ERR_HANDLE, err_msg);
873                 return MEDIA_SVC_PLUGIN_ERROR;
874         }
875
876         ret = media_svc_get_folder_scan_status(handle, storage_id, path, &storage_status);
877         if (ret < 0) {
878                 __set_error_message(ret, err_msg);
879                 return MEDIA_SVC_PLUGIN_ERROR;
880         }
881
882         *status = storage_status;
883
884         return ret;
885 }
886
887 int set_folder_scan_status(void *handle, const char *storage_id, const char *path, int status, uid_t uid, char **err_msg)
888 {
889         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
890         int storage_status = status;
891
892         ret = media_svc_set_folder_scan_status(storage_id, path, storage_status, uid);
893         if (ret < 0) {
894                 __set_error_message(ret, err_msg);
895                 return MEDIA_SVC_PLUGIN_ERROR;
896         }
897
898         return ret;
899 }
900
901 int check_folder_modified(void *handle, const char *path, const char *storage_id, bool *modified, char **err_msg)
902 {
903         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
904         *modified = TRUE;
905
906         if (handle == NULL) {
907                 __set_error_message(ERR_HANDLE, err_msg);
908                 return MEDIA_SVC_PLUGIN_ERROR;
909         }
910
911         if (!STRING_VALID(path)) {
912                 __set_error_message(ERR_FILE_PATH, err_msg);
913                 return MEDIA_SVC_PLUGIN_ERROR;
914         }
915
916         ret = media_svc_get_folder_modified_time(handle, path, storage_id, modified);
917         if (ret < 0) {
918                 __set_error_message(ret, err_msg);
919                 return MEDIA_SVC_PLUGIN_ERROR;
920         }
921
922         return ret;
923 }
924
925 int get_null_scan_folder_list(void *handle, const char *storage_id, const char *folder_path, char ***folder_list, int *count, char **err_msg)
926 {
927         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
928
929         if (handle == NULL) {
930                 __set_error_message(ERR_HANDLE, err_msg);
931                 return MEDIA_SVC_PLUGIN_ERROR;
932         }
933
934         if (count == NULL) {
935                 __set_error_message(ERR_HANDLE, err_msg);
936                 return MEDIA_SVC_PLUGIN_ERROR;
937         }
938
939         ret = media_svc_get_null_scan_folder_list(handle, storage_id, folder_path, folder_list, count);
940         if (ret < 0) {
941                 __set_error_message(ret, err_msg);
942                 return MEDIA_SVC_PLUGIN_ERROR;
943         }
944
945         return ret;
946 }
947
948 int change_validity_item_batch(void **handle, const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid, char **err_msg)
949 {
950         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
951
952         ret = media_svc_change_validity_item_batch(storage_id, path, des_validity, src_validity, uid);
953         if (ret < 0) {
954                 __set_error_message(ret, err_msg);
955                 return MEDIA_SVC_PLUGIN_ERROR;
956         }
957
958         return ret;
959 }
960
961 int check_folder_exist(void * handle, const char *storage_id, const char *folder_path, char **err_msg)
962 {
963         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
964
965         if (handle == NULL) {
966                 __set_error_message(ERR_HANDLE, err_msg);
967                 return MEDIA_SVC_PLUGIN_ERROR;
968         }
969
970         ret = media_svc_check_folder_exist_by_path(handle, storage_id, folder_path);
971         if (ret < 0) {
972                 __set_error_message(ret, err_msg);
973                 return MEDIA_SVC_PLUGIN_ERROR;
974         }
975
976         return MEDIA_SVC_PLUGIN_ERROR_NONE;
977 }
978
979 int get_folder_id(void * handle, const char *storage_id, const char *path, char *folder_id, char **err_msg)
980 {
981         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
982
983         if (handle == NULL) {
984                 __set_error_message(ERR_HANDLE, err_msg);
985                 return MEDIA_SVC_PLUGIN_ERROR;
986         }
987
988         ret = media_svc_get_folder_id(handle, storage_id, path, folder_id);
989         if (ret < 0) {
990                 __set_error_message(ret, err_msg);
991                 return MEDIA_SVC_PLUGIN_ERROR;
992         }
993
994         return MEDIA_SVC_PLUGIN_ERROR_NONE;
995 }
996
997 int get_media_type(void *handle, const char *path, int *mediatype, char **err_msg)
998 {
999         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1000
1001         if (handle == NULL) {
1002                 __set_error_message(ERR_HANDLE, err_msg);
1003                 return MEDIA_SVC_PLUGIN_ERROR;
1004         }
1005
1006         ret = media_svc_get_media_type(path, mediatype);
1007         if (ret < 0) {
1008                 __set_error_message(ret, err_msg);
1009                 return MEDIA_SVC_PLUGIN_ERROR;
1010         }
1011
1012         return MEDIA_SVC_PLUGIN_ERROR_NONE;
1013 }
1014
1015