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