Add to scan dcm after media scanning was done
[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 check_item_exist(void *handle, const char *storage_id, const char *file_path, bool *modified, char **err_msg)
124 {
125         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
126         *modified = TRUE;
127
128         if (handle == NULL) {
129                 __set_error_message(ERR_HANDLE, err_msg);
130                 return MEDIA_SVC_PLUGIN_ERROR;
131         }
132
133         if (!STRING_VALID(file_path)) {
134                 __set_error_message(ERR_FILE_PATH, err_msg);
135                 return MEDIA_SVC_PLUGIN_ERROR;
136         }
137
138         time_t modified_time = 0;
139         unsigned long long file_size = 0;
140         struct stat st;
141
142         ret = media_svc_get_file_info(handle, storage_id, file_path, &modified_time, &file_size);
143         if (ret == MS_MEDIA_ERR_NONE) {
144                 memset(&st, 0, sizeof(struct stat));
145                 if (stat(file_path, &st) == 0) {
146                         if ((st.st_mtime != modified_time) || (st.st_size != file_size))
147                                 *modified = TRUE;
148                         else
149                                 *modified = FALSE;
150                 }
151
152                 return MEDIA_SVC_PLUGIN_ERROR_NONE;     /*exist */
153         }
154
155         __set_error_message(ERR_CHECK_ITEM, err_msg);
156
157         return MEDIA_SVC_PLUGIN_ERROR;          /*not exist */
158 }
159
160 int insert_item_begin(void *handle, int item_cnt, int with_noti, int from_pid, char **err_msg)
161 {
162         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
163
164         ret = media_svc_insert_item_begin(item_cnt, with_noti, from_pid);
165         if (ret < 0) {
166                 __set_error_message(ret, err_msg);
167                 return MEDIA_SVC_PLUGIN_ERROR;
168         }
169
170         return MEDIA_SVC_PLUGIN_ERROR_NONE;
171 }
172
173 int insert_item_end(void *handle, uid_t uid, char **err_msg)
174 {
175         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
176
177         ret = media_svc_insert_item_end(uid);
178         if (ret < 0) {
179                 __set_error_message(ret, err_msg);
180                 return MEDIA_SVC_PLUGIN_ERROR;
181         }
182
183         return MEDIA_SVC_PLUGIN_ERROR_NONE;
184 }
185
186 int insert_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
187 {
188         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
189
190         if (handle == NULL) {
191                 __set_error_message(ERR_HANDLE, err_msg);
192                 return MEDIA_SVC_PLUGIN_ERROR;
193         }
194
195         if (!STRING_VALID(file_path)) {
196                 __set_error_message(ERR_FILE_PATH, err_msg);
197                 return MEDIA_SVC_PLUGIN_ERROR;
198         }
199
200         if (!STORAGE_VALID(storage_type)) {
201                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
202                 return MEDIA_SVC_PLUGIN_ERROR;
203         }
204
205         ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, FALSE, uid);
206         if (ret < 0) {
207                 __set_error_message(ret, err_msg);
208                 return MEDIA_SVC_PLUGIN_ERROR;
209         }
210
211         return MEDIA_SVC_PLUGIN_ERROR_NONE;
212 }
213
214 int insert_item_immediately(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
215 {
216         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
217
218         if (handle == NULL) {
219                 __set_error_message(ERR_HANDLE, err_msg);
220                 return MEDIA_SVC_PLUGIN_ERROR;
221         }
222
223         if (!STRING_VALID(file_path)) {
224                 __set_error_message(ERR_FILE_PATH, err_msg);
225                 return MEDIA_SVC_PLUGIN_ERROR;
226         }
227
228         if (!STORAGE_VALID(storage_type)) {
229                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
230                 return MEDIA_SVC_PLUGIN_ERROR;
231         }
232
233         ret = media_svc_insert_item_immediately(handle, storage_id, storage_type, file_path, uid);
234         if (ret < 0) {
235                 __set_error_message(ret, err_msg);
236                 return MEDIA_SVC_PLUGIN_ERROR;
237         }
238
239         return MEDIA_SVC_PLUGIN_ERROR_NONE;
240 }
241
242 int insert_burst_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
243 {
244         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
245
246         if (handle == NULL) {
247                 __set_error_message(ERR_HANDLE, err_msg);
248                 return MEDIA_SVC_PLUGIN_ERROR;
249         }
250
251         if (!STRING_VALID(file_path)) {
252                 __set_error_message(ERR_FILE_PATH, err_msg);
253                 return MEDIA_SVC_PLUGIN_ERROR;
254         }
255
256         if (!STORAGE_VALID(storage_type)) {
257                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
258                 return MEDIA_SVC_PLUGIN_ERROR;
259         }
260
261         ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, TRUE, uid);
262         if (ret < 0) {
263                 __set_error_message(ret, err_msg);
264                 return MEDIA_SVC_PLUGIN_ERROR;
265         }
266
267         return MEDIA_SVC_PLUGIN_ERROR_NONE;
268 }
269
270 int set_all_storage_items_validity(void *handle, const char *storage_id, int storage_type, int validity, uid_t uid, char **err_msg)
271 {
272         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
273
274         if (!STORAGE_VALID(storage_type)) {
275                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
276                 return MEDIA_SVC_PLUGIN_ERROR;
277         }
278
279         ret = media_svc_set_all_storage_items_validity(storage_id, storage_type, validity, uid);
280         if (ret < 0) {
281                 __set_error_message(ret, err_msg);
282                 return MEDIA_SVC_PLUGIN_ERROR;
283         }
284
285         return MEDIA_SVC_PLUGIN_ERROR_NONE;
286 }
287
288 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)
289 {
290         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
291
292         if (handle == NULL) {
293                 __set_error_message(ERR_HANDLE, err_msg);
294                 return MEDIA_SVC_PLUGIN_ERROR;
295         }
296
297         if (!STRING_VALID(folder_path)) {
298                 __set_error_message(ERR_FOLDER_PATH, err_msg);
299                 return MEDIA_SVC_PLUGIN_ERROR;
300         }
301
302         ret = media_svc_set_folder_items_validity(handle, storage_id, folder_path, validity, recursive, uid);
303         if (ret < 0) {
304                 __set_error_message(ret, err_msg);
305                 return MEDIA_SVC_PLUGIN_ERROR;
306         }
307
308         return MEDIA_SVC_PLUGIN_ERROR_NONE;
309 }
310
311 int set_item_validity_begin(void *handle, int item_cnt, char **err_msg)
312 {
313         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
314
315         ret = media_svc_set_item_validity_begin(item_cnt);
316         if (ret < 0) {
317                 __set_error_message(ret, err_msg);
318                 return MEDIA_SVC_PLUGIN_ERROR;
319         }
320
321         return MEDIA_SVC_PLUGIN_ERROR_NONE;
322 }
323
324 int set_item_validity_end(void *handle, uid_t uid, char **err_msg)
325 {
326         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
327
328         ret = media_svc_set_item_validity_end(uid);
329         if (ret < 0) {
330                 __set_error_message(ret, err_msg);
331                 return MEDIA_SVC_PLUGIN_ERROR;
332         }
333
334         return MEDIA_SVC_PLUGIN_ERROR_NONE;
335 }
336
337 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)
338 {
339         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
340
341         if (!STRING_VALID(file_path)) {
342                 __set_error_message(ERR_FILE_PATH, err_msg);
343                 return MEDIA_SVC_PLUGIN_ERROR;
344         }
345
346         ret = media_svc_set_item_validity(storage_id, file_path, validity, uid);
347
348         if (ret < 0) {
349                 __set_error_message(ret, err_msg);
350                 return MEDIA_SVC_PLUGIN_ERROR;
351         }
352
353         return MEDIA_SVC_PLUGIN_ERROR_NONE;
354 }
355
356 int delete_item(void *handle, const char *storage_id, const char *file_path, uid_t uid, char **err_msg)
357 {
358         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
359
360         if (handle == NULL) {
361                 __set_error_message(ERR_HANDLE, err_msg);
362                 return MEDIA_SVC_PLUGIN_ERROR;
363         }
364
365         if (!STRING_VALID(file_path)) {
366                 __set_error_message(ERR_FILE_PATH, err_msg);
367                 return MEDIA_SVC_PLUGIN_ERROR;
368         }
369
370         ret = media_svc_check_item_exist_by_path(handle, storage_id, file_path);
371         if (ret == 0) {
372                 ret = media_svc_delete_item_by_path(handle, storage_id, file_path, uid);
373
374                 if (ret < 0) {
375                         __set_error_message(ret, err_msg);
376                         return MEDIA_SVC_PLUGIN_ERROR;
377                 } else
378                         return MEDIA_SVC_PLUGIN_ERROR_NONE;
379         }
380
381         __set_error_message(ERR_CHECK_ITEM, err_msg);   /*not exist in DB so can't delete item. */
382         return MEDIA_SVC_PLUGIN_ERROR;
383 }
384
385 int delete_all_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
386 {
387         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
388
389         if (!STORAGE_VALID(storage_type)) {
390                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
391                 return MEDIA_SVC_PLUGIN_ERROR;
392         }
393
394         ret = media_svc_delete_all_items_in_storage(storage_id, storage_type, uid);
395         if (ret < 0) {
396                 __set_error_message(ret, err_msg);
397                 return MEDIA_SVC_PLUGIN_ERROR;
398         }
399
400         return MEDIA_SVC_PLUGIN_ERROR_NONE;
401 }
402
403 int delete_all_invalid_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
404 {
405         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
406
407         if (handle == NULL) {
408                 __set_error_message(ERR_HANDLE, err_msg);
409                 return MEDIA_SVC_PLUGIN_ERROR;
410         }
411
412         if (!STORAGE_VALID(storage_type)) {
413                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
414                 return MEDIA_SVC_PLUGIN_ERROR;
415         }
416
417         ret = media_svc_delete_invalid_items_in_storage(handle, storage_id, storage_type, uid);
418         if (ret < 0) {
419                 __set_error_message(ret, err_msg);
420                 return MEDIA_SVC_PLUGIN_ERROR;
421         }
422
423         return MEDIA_SVC_PLUGIN_ERROR_NONE;
424 }
425
426 int delete_all_invalid_items_in_folder(void *handle, const char *storage_id, const char *folder_path, bool is_recursve, uid_t uid, char **err_msg)
427 {
428         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
429
430         if (handle == NULL) {
431                 __set_error_message(ERR_HANDLE, err_msg);
432                 return MEDIA_SVC_PLUGIN_ERROR;
433         }
434
435         if (!STRING_VALID(folder_path)) {
436                 __set_error_message(ERR_FOLDER_PATH, err_msg);
437                 return MEDIA_SVC_PLUGIN_ERROR;
438         }
439
440         ret = media_svc_delete_invalid_items_in_folder(handle, storage_id, folder_path, is_recursve, uid);
441         if (ret < 0) {
442                 __set_error_message(ret, err_msg);
443                 return MEDIA_SVC_PLUGIN_ERROR;
444         }
445
446         return MEDIA_SVC_PLUGIN_ERROR_NONE;
447 }
448
449
450 int update_begin(void)
451 {
452         return MEDIA_SVC_PLUGIN_ERROR_NONE;
453 }
454
455 int update_end(const char *start_path, uid_t uid)
456 {
457 #if 0
458         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
459
460         ret = thumbnail_request_extract_all_thumbs(uid);
461         if (ret < 0) {
462                 return MEDIA_SVC_PLUGIN_ERROR;
463         }
464 #endif
465         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
466
467         ret = dcm_svc_request_extract_all(uid);
468         if (ret < 0) {
469                 return MEDIA_SVC_PLUGIN_ERROR;
470         }
471         return MEDIA_SVC_PLUGIN_ERROR_NONE;
472 }
473
474 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)
475 {
476         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
477
478         if (!STRING_VALID(dir_path)) {
479                 __set_error_message(ERR_FOLDER_PATH, err_msg);
480                 return MEDIA_SVC_PLUGIN_ERROR;
481         }
482
483         ret = media_svc_send_dir_update_noti(handle, storage_id, dir_path, folder_id, (media_item_update_type_e)update_type, pid);
484         if (ret < 0) {
485                 __set_error_message(ret, err_msg);
486                 return MEDIA_SVC_PLUGIN_ERROR;
487         }
488
489         return MEDIA_SVC_PLUGIN_ERROR_NONE;
490 }
491
492 int count_delete_items_in_folder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
493 {
494         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
495
496         if (handle == NULL) {
497                 __set_error_message(ERR_HANDLE, err_msg);
498                 return MEDIA_SVC_PLUGIN_ERROR;
499         }
500
501         if (count == NULL) {
502                 __set_error_message(ERR_HANDLE, err_msg);
503                 return MEDIA_SVC_PLUGIN_ERROR;
504         }
505
506         if (!STRING_VALID(folder_path)) {
507                 __set_error_message(ERR_FOLDER_PATH, err_msg);
508                 return MEDIA_SVC_PLUGIN_ERROR;
509         }
510
511         ret = media_svc_count_invalid_items_in_folder(handle, storage_id, folder_path, count);
512         if (ret < 0) {
513                 __set_error_message(ret, err_msg);
514                 return MEDIA_SVC_PLUGIN_ERROR;
515         }
516
517         return MEDIA_SVC_PLUGIN_ERROR_NONE;
518 }
519
520 int check_db(void *handle, uid_t uid, char **err_msg)
521 {
522         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
523         int user_version = -1;
524
525         ret = media_svc_get_user_version(handle, &user_version);
526         if (ret < 0) {
527                 __set_error_message(ret, err_msg);
528                 return MEDIA_SVC_PLUGIN_ERROR;
529         }
530
531         if (user_version == 0) {
532                 /*check db schema*/
533                 ret = media_svc_create_table(uid);
534                 if (ret < 0) {
535                         __set_error_message(ret, err_msg);
536                         return MEDIA_SVC_PLUGIN_ERROR;
537                 }
538         } else {
539                 /*check db version*/
540                 ret = media_svc_check_db_upgrade(handle, user_version, uid);
541                 if (ret < 0) {
542                         __set_error_message(ret, err_msg);
543                         return MEDIA_SVC_PLUGIN_ERROR;
544                 }
545         }
546
547         return MEDIA_SVC_PLUGIN_ERROR_NONE;
548 }
549
550 int check_db_corrupt(void *handle, char **err_msg)
551 {
552         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
553
554         /*check db version*/
555         ret = media_svc_check_db_corrupt(handle);
556         if (ret < 0) {
557                 __set_error_message(ret, err_msg);
558                 return MEDIA_SVC_PLUGIN_ERROR;
559         }
560
561         return MEDIA_SVC_PLUGIN_ERROR_NONE;
562 }
563
564 int get_folder_list(void *handle, const char *storage_id, char *start_path, char ***folder_list, int **modified_time_list, int **item_num_list, int *count, char **err_msg)
565 {
566         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
567
568         if (handle == NULL) {
569                 __set_error_message(ERR_HANDLE, err_msg);
570                 return MEDIA_SVC_PLUGIN_ERROR;
571         }
572
573         if (count == NULL) {
574                 __set_error_message(ERR_HANDLE, err_msg);
575                 return MEDIA_SVC_PLUGIN_ERROR;
576         }
577
578         ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t **)modified_time_list, item_num_list, count);
579         if (ret < 0) {
580                 __set_error_message(ret, err_msg);
581                 return MEDIA_SVC_PLUGIN_ERROR;
582         }
583
584         return MEDIA_SVC_PLUGIN_ERROR_NONE;
585 }
586
587 int update_folder_time(void *handle, const char *storage_id, char *folder_path, uid_t uid, char **err_msg)
588 {
589         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
590
591         if (handle == NULL) {
592                 __set_error_message(ERR_HANDLE, err_msg);
593                 return MEDIA_SVC_PLUGIN_ERROR;
594         }
595
596         if (folder_path == NULL) {
597                 __set_error_message(ERR_HANDLE, err_msg);
598                 return MEDIA_SVC_PLUGIN_ERROR;
599         }
600
601         ret = media_svc_update_folder_time(handle, storage_id, folder_path, uid);
602         if (ret < 0) {
603                 __set_error_message(ret, err_msg);
604                 return MEDIA_SVC_PLUGIN_ERROR;
605         }
606
607         return MEDIA_SVC_PLUGIN_ERROR_NONE;
608 }
609
610 int get_uuid(void * handle, char **uuid, char **err_msg)
611 {
612         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
613
614         ret = media_svc_generate_uuid(uuid);
615         if (ret < 0) {
616                 __set_error_message(ret, err_msg);
617                 return MEDIA_SVC_PLUGIN_ERROR;
618         }
619
620         return MEDIA_SVC_PLUGIN_ERROR_NONE;
621 }
622
623 int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg)
624 {
625         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
626
627         if (handle == NULL) {
628                 __set_error_message(ERR_HANDLE, err_msg);
629                 return MEDIA_SVC_PLUGIN_ERROR;
630         }
631
632         ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
633         if (ret < 0) {
634                 __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
635                 return MEDIA_SVC_PLUGIN_ERROR;
636         }
637
638         return MEDIA_SVC_PLUGIN_ERROR_NONE;
639 }
640
641 int check_storage(void * handle, const char *storage_id, const char *storage_name, char **storage_path, int *validity, char **err_msg)
642 {
643         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
644
645         if (handle == NULL) {
646                 __set_error_message(ERR_HANDLE, err_msg);
647                 return MEDIA_SVC_PLUGIN_ERROR;
648         }
649
650         ret = media_svc_check_storage(handle, storage_id, storage_name, storage_path, validity);
651         if (ret < 0) {
652                 __set_error_message(ret, err_msg);
653                 return MEDIA_SVC_PLUGIN_ERROR;
654         }
655
656         return MEDIA_SVC_PLUGIN_ERROR_NONE;
657 }
658
659 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)
660 {
661         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
662
663         if (handle == NULL) {
664                 __set_error_message(ERR_HANDLE, err_msg);
665                 return MEDIA_SVC_PLUGIN_ERROR;
666         }
667
668         ret = media_svc_insert_storage(handle, storage_id, storage_name, storage_path, NULL, storage_type, uid);
669         if (ret < 0) {
670                 __set_error_message(ret, err_msg);
671                 return MEDIA_SVC_PLUGIN_ERROR;
672         }
673
674         return MEDIA_SVC_PLUGIN_ERROR_NONE;
675 }
676
677 int update_storage(void *handle, const char *storage_id, const char *storage_path, uid_t uid, char **err_msg)
678 {
679         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
680
681         if (handle == NULL) {
682                 __set_error_message(ERR_HANDLE, err_msg);
683                 return MEDIA_SVC_PLUGIN_ERROR;
684         }
685
686         ret = media_svc_update_storage(handle, storage_id, storage_path, 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 }
694
695 int delete_storage(void * handle, const char *storage_id, const char *storage_name, uid_t uid, char **err_msg)
696 {
697         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
698
699         if (handle == NULL) {
700                 __set_error_message(ERR_HANDLE, err_msg);
701                 return MEDIA_SVC_PLUGIN_ERROR;
702         }
703
704         ret = media_svc_delete_storage(handle, storage_id, storage_name, uid);
705         if (ret < 0) {
706                 __set_error_message(ret, err_msg);
707                 return MEDIA_SVC_PLUGIN_ERROR;
708         }
709
710         return MEDIA_SVC_PLUGIN_ERROR_NONE;
711 }
712
713 int set_storage_validity(void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg)
714 {
715         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
716
717         if (handle == NULL) {
718                 __set_error_message(ERR_HANDLE, err_msg);
719                 return MEDIA_SVC_PLUGIN_ERROR;
720         }
721
722         ret = media_svc_set_storage_validity(handle, storage_id, validity, uid);
723         if (ret < 0) {
724                 __set_error_message(ret, err_msg);
725                 return MEDIA_SVC_PLUGIN_ERROR;
726         }
727
728         return MEDIA_SVC_PLUGIN_ERROR_NONE;
729 }
730
731 int set_all_storage_validity(void * handle, int validity, char **err_msg, uid_t uid)
732 {
733         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
734
735         if (handle == NULL) {
736                 __set_error_message(ERR_HANDLE, err_msg);
737                 return MEDIA_SVC_PLUGIN_ERROR;
738         }
739
740         ret = media_svc_set_storage_validity(handle, NULL, validity, uid);
741         if (ret < 0) {
742                 __set_error_message(ret, err_msg);
743                 return MEDIA_SVC_PLUGIN_ERROR;
744         }
745
746         return MEDIA_SVC_PLUGIN_ERROR_NONE;
747 }
748
749 int get_storage_id(void * handle, const char *path, char *storage_id, char **err_msg)
750 {
751         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
752
753         if (handle == NULL) {
754                 __set_error_message(ERR_HANDLE, err_msg);
755                 return MEDIA_SVC_PLUGIN_ERROR;
756         }
757
758         ret = media_svc_get_storage_id(handle, path, storage_id);
759         if (ret < 0) {
760                 __set_error_message(ret, err_msg);
761                 return MEDIA_SVC_PLUGIN_ERROR;
762         }
763
764         return MEDIA_SVC_PLUGIN_ERROR_NONE;
765 }
766
767 int get_storage_scan_status(void * handle, const char *storage_id, int *status, char **err_msg)
768 {
769         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
770         media_svc_scan_status_type_e storage_status = 0;
771
772         if (handle == NULL) {
773                 __set_error_message(ERR_HANDLE, err_msg);
774                 return MEDIA_SVC_PLUGIN_ERROR;
775         }
776
777         ret = media_svc_get_storage_scan_status(handle, storage_id, &storage_status);
778         if (ret < 0) {
779                 __set_error_message(ret, err_msg);
780                 return MEDIA_SVC_PLUGIN_ERROR;
781         }
782
783         *status = storage_status;
784
785         return MEDIA_SVC_PLUGIN_ERROR_NONE;
786 }
787
788 int set_storage_scan_status(void *handle, const char *storage_id, int status, uid_t uid, char **err_msg)
789 {
790         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
791         media_svc_scan_status_type_e storage_status = status;
792
793         ret = media_svc_set_storage_scan_status(storage_id, storage_status, uid);
794         if (ret < 0) {
795                 __set_error_message(ret, err_msg);
796                 return MEDIA_SVC_PLUGIN_ERROR;
797         }
798
799         return MEDIA_SVC_PLUGIN_ERROR_NONE;
800 }
801
802 int get_storage_list(void *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count, char **err_msg)
803 {
804         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
805
806         if (handle == NULL) {
807                 __set_error_message(ERR_HANDLE, err_msg);
808                 return MEDIA_SVC_PLUGIN_ERROR;
809         }
810
811         if (count == NULL) {
812                 __set_error_message(ERR_HANDLE, err_msg);
813                 return MEDIA_SVC_PLUGIN_ERROR;
814         }
815
816         ret = media_svc_get_storage_list(handle, storage_list, storage_id_list, scan_status_list, count);
817         if (ret < 0) {
818                 __set_error_message(ret, err_msg);
819                 return MEDIA_SVC_PLUGIN_ERROR;
820         }
821
822         return MEDIA_SVC_PLUGIN_ERROR_NONE;
823 }
824
825 int update_item_begin(void *handle, int item_cnt, char **err_msg)
826 {
827         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
828
829         ret = media_svc_update_item_begin(item_cnt);
830         if (ret < 0) {
831                 __set_error_message(ret, err_msg);
832                 return MEDIA_SVC_PLUGIN_ERROR;
833         }
834
835         return MEDIA_SVC_PLUGIN_ERROR_NONE;
836 }
837
838 int update_item_end(void *handle, uid_t uid, char **err_msg)
839 {
840         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
841
842         ret = media_svc_update_item_end(uid);
843         if (ret < 0) {
844                 __set_error_message(ret, err_msg);
845                 return MEDIA_SVC_PLUGIN_ERROR;
846         }
847
848         return MEDIA_SVC_PLUGIN_ERROR_NONE;
849 }
850
851 int update_item_meta(void *handle, const char *file_path, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
852 {
853         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
854
855         if (handle == NULL) {
856                 __set_error_message(ERR_HANDLE, err_msg);
857                 return MEDIA_SVC_PLUGIN_ERROR;
858         }
859
860         if (file_path == NULL) {
861                 __set_error_message(ERR_HANDLE, err_msg);
862                 return MEDIA_SVC_PLUGIN_ERROR;
863         }
864
865         if (storage_id == NULL) {
866                 __set_error_message(ERR_HANDLE, err_msg);
867                 return MEDIA_SVC_PLUGIN_ERROR;
868         }
869
870         ret = media_svc_update_item_meta(handle, file_path, storage_id, storage_type, uid);
871         if (ret < 0) {
872                 __set_error_message(ret, err_msg);
873                 return MEDIA_SVC_PLUGIN_ERROR;
874         }
875
876         return MEDIA_SVC_PLUGIN_ERROR_NONE;
877 }
878
879 int insert_item_scan(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
880 {
881         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
882
883         if (handle == NULL) {
884                 __set_error_message(ERR_HANDLE, err_msg);
885                 return MEDIA_SVC_PLUGIN_ERROR;
886         }
887
888         if (!STRING_VALID(file_path)) {
889                 __set_error_message(ERR_FILE_PATH, err_msg);
890                 return MEDIA_SVC_PLUGIN_ERROR;
891         }
892
893         if (!STORAGE_VALID(storage_type)) {
894                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
895                 return MEDIA_SVC_PLUGIN_ERROR;
896         }
897
898         ret = media_svc_insert_item_pass1(handle, storage_id, storage_type, file_path, FALSE, uid);
899         if (ret < 0) {
900                 __set_error_message(ret, err_msg);
901                 return MEDIA_SVC_PLUGIN_ERROR;
902         }
903
904         return MEDIA_SVC_PLUGIN_ERROR_NONE;
905 }
906
907 int update_item_extract(void * handle, const char *storage_id, int storage_type, int scan_type, uid_t uid, const char *path, int burst, char **err_msg)
908 {
909         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
910
911         if (handle == NULL) {
912                 __set_error_message(ERR_HANDLE, err_msg);
913                 return MEDIA_SVC_PLUGIN_ERROR;
914         }
915
916         if (!STORAGE_VALID(storage_type)) {
917                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
918                 return MEDIA_SVC_PLUGIN_ERROR;
919         }
920
921         ret = media_svc_insert_item_pass2(handle, storage_id, storage_type, scan_type, path, burst, uid);
922         if (ret < 0) {
923                 __set_error_message(ret, err_msg);
924                 return MEDIA_SVC_PLUGIN_ERROR;
925         }
926
927         return MEDIA_SVC_PLUGIN_ERROR_NONE;
928 }
929
930 int insert_folder_begin(void * handle, int item_cnt, char **err_msg)
931 {
932         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
933
934         ret = media_svc_insert_folder_begin(item_cnt);
935         if (ret < 0) {
936                 __set_error_message(ret, err_msg);
937                 return MEDIA_SVC_PLUGIN_ERROR;
938         }
939
940         return MEDIA_SVC_PLUGIN_ERROR_NONE;
941 }
942
943 int insert_folder_end(void *handle, uid_t uid, char **err_msg)
944 {
945         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
946
947         ret = media_svc_insert_folder_end(uid);
948         if (ret < 0) {
949                 __set_error_message(ret, err_msg);
950                 return MEDIA_SVC_PLUGIN_ERROR;
951         }
952
953         return MEDIA_SVC_PLUGIN_ERROR_NONE;
954 }
955
956 int insert_folder(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
957 {
958         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
959
960         if (handle == NULL) {
961                 __set_error_message(ERR_HANDLE, err_msg);
962                 return MEDIA_SVC_PLUGIN_ERROR;
963         }
964
965         if (!STRING_VALID(file_path)) {
966                 __set_error_message(ERR_FILE_PATH, err_msg);
967                 return MEDIA_SVC_PLUGIN_ERROR;
968         }
969
970         if (!STORAGE_VALID(storage_type)) {
971                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
972                 return MEDIA_SVC_PLUGIN_ERROR;
973         }
974
975         ret = media_svc_insert_folder(handle, storage_id, storage_type, file_path, uid);
976         if (ret < 0) {
977                 __set_error_message(ret, err_msg);
978                 return MEDIA_SVC_PLUGIN_ERROR;
979         }
980
981         return MEDIA_SVC_PLUGIN_ERROR_NONE;
982 }
983
984 int delete_invalid_folder(void * handle, const char *storage_id, uid_t uid, char **err_msg)
985 {
986         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
987
988         ret = media_svc_delete_invalid_folder(storage_id, uid);
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 set_folder_validity(void * handle, const char *storage_id, const char* start_path, int validity, bool is_recursive, uid_t uid, 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_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
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 int get_folder_scan_status(void *handle, const char *storage_id, const char *path, int *status, char **err_msg)
1016 {
1017         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1018         int storage_status = 0;
1019
1020         if (handle == NULL) {
1021                 __set_error_message(ERR_HANDLE, err_msg);
1022                 return MEDIA_SVC_PLUGIN_ERROR;
1023         }
1024
1025         ret = media_svc_get_folder_scan_status(handle, storage_id, path, &storage_status);
1026         if (ret < 0) {
1027                 __set_error_message(ret, err_msg);
1028                 return MEDIA_SVC_PLUGIN_ERROR;
1029         }
1030
1031         *status = storage_status;
1032
1033         return ret;
1034 }
1035
1036 int set_folder_scan_status(void *handle, const char *storage_id, const char *path, int status, uid_t uid, char **err_msg)
1037 {
1038         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1039         int storage_status = status;
1040
1041         ret = media_svc_set_folder_scan_status(storage_id, path, storage_status, uid);
1042         if (ret < 0) {
1043                 __set_error_message(ret, err_msg);
1044                 return MEDIA_SVC_PLUGIN_ERROR;
1045         }
1046
1047         return ret;
1048 }
1049
1050 int check_folder_modified(void *handle, const char *path, const char *storage_id, bool *modified, char **err_msg)
1051 {
1052         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1053         *modified = TRUE;
1054
1055         if (handle == NULL) {
1056                 __set_error_message(ERR_HANDLE, err_msg);
1057                 return MEDIA_SVC_PLUGIN_ERROR;
1058         }
1059
1060         if (!STRING_VALID(path)) {
1061                 __set_error_message(ERR_FILE_PATH, err_msg);
1062                 return MEDIA_SVC_PLUGIN_ERROR;
1063         }
1064
1065         ret = media_svc_get_folder_modified_time(handle, path, storage_id, modified);
1066         if (ret < 0) {
1067                 __set_error_message(ret, err_msg);
1068                 return MEDIA_SVC_PLUGIN_ERROR;
1069         }
1070
1071         return ret;
1072 }
1073
1074 int get_null_scan_folder_list(void *handle, const char *storage_id, const char *folder_path, char ***folder_list, int *count, char **err_msg)
1075 {
1076         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1077
1078         if (handle == NULL) {
1079                 __set_error_message(ERR_HANDLE, err_msg);
1080                 return MEDIA_SVC_PLUGIN_ERROR;
1081         }
1082
1083         if (count == NULL) {
1084                 __set_error_message(ERR_HANDLE, err_msg);
1085                 return MEDIA_SVC_PLUGIN_ERROR;
1086         }
1087
1088         ret = media_svc_get_null_scan_folder_list(handle, storage_id, folder_path, folder_list, count);
1089         if (ret < 0) {
1090                 __set_error_message(ret, err_msg);
1091                 return MEDIA_SVC_PLUGIN_ERROR;
1092         }
1093
1094         return ret;
1095 }
1096
1097 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)
1098 {
1099         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1100
1101         ret = media_svc_change_validity_item_batch(storage_id, path, des_validity, src_validity, uid);
1102         if (ret < 0) {
1103                 __set_error_message(ret, err_msg);
1104                 return MEDIA_SVC_PLUGIN_ERROR;
1105         }
1106
1107         return ret;
1108 }
1109
1110 int delete_invalid_folder_by_path(void * handle, const char *storage_id, const char *folder_path, uid_t uid, int *delete_count, char **err_msg)
1111 {
1112         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1113
1114         if (handle == NULL) {
1115                 __set_error_message(ERR_HANDLE, err_msg);
1116                 return MEDIA_SVC_PLUGIN_ERROR;
1117         }
1118
1119         ret = media_svc_delete_invalid_folder_by_path(handle, storage_id, folder_path, uid, delete_count);
1120         if (ret < 0) {
1121                 __set_error_message(ret, err_msg);
1122                 return MEDIA_SVC_PLUGIN_ERROR;
1123         }
1124
1125         return MEDIA_SVC_PLUGIN_ERROR_NONE;
1126 }
1127
1128 int check_folder_exist(void * handle, const char *storage_id, const char *folder_path, char **err_msg)
1129 {
1130         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1131
1132         if (handle == NULL) {
1133                 __set_error_message(ERR_HANDLE, err_msg);
1134                 return MEDIA_SVC_PLUGIN_ERROR;
1135         }
1136
1137         ret = media_svc_check_folder_exist_by_path(handle, storage_id, folder_path);
1138         if (ret < 0) {
1139                 __set_error_message(ret, err_msg);
1140                 return MEDIA_SVC_PLUGIN_ERROR;
1141         }
1142
1143         return MEDIA_SVC_PLUGIN_ERROR_NONE;
1144 }
1145
1146 int count_subfolder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
1147 {
1148         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1149         int cnt = 0;
1150
1151         if (handle == NULL) {
1152                 __set_error_message(ERR_HANDLE, err_msg);
1153                 return MEDIA_SVC_PLUGIN_ERROR;
1154         }
1155
1156         ret = media_svc_check_subfolder_by_path(handle, storage_id, folder_path, &cnt);
1157         if (ret < 0) {
1158                 __set_error_message(ret, err_msg);
1159                 return MEDIA_SVC_PLUGIN_ERROR;
1160         }
1161
1162         *count = cnt;
1163
1164         return MEDIA_SVC_PLUGIN_ERROR_NONE;
1165 }
1166
1167 int get_folder_id(void * handle, const char *storage_id, const char *path, char *folder_id, char **err_msg)
1168 {
1169         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1170
1171         if (handle == NULL) {
1172                 __set_error_message(ERR_HANDLE, err_msg);
1173                 return MEDIA_SVC_PLUGIN_ERROR;
1174         }
1175
1176         ret = media_svc_get_folder_id(handle, storage_id, path, folder_id);
1177         if (ret < 0) {
1178                 __set_error_message(ret, err_msg);
1179                 return MEDIA_SVC_PLUGIN_ERROR;
1180         }
1181
1182         return MEDIA_SVC_PLUGIN_ERROR_NONE;
1183 }
1184
1185