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