Change thumbnail generation location
[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 get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, 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_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
509         if (ret < 0) {
510                 __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
511                 return MEDIA_SVC_PLUGIN_ERROR;
512         }
513
514         return MEDIA_SVC_PLUGIN_ERROR_NONE;
515 }
516
517 int check_storage(void * handle, const char *storage_id, char **storage_path, int *validity, 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_check_storage(handle, storage_id, storage_path, validity, 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 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)
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_insert_storage(handle, storage_id, storage_name, storage_path, storage_type, 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 update_storage(void *handle, const char *storage_id, const char *storage_path, 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_update_storage(handle, storage_id, storage_path, 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 delete_storage(void * handle, const char *storage_id, 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_delete_storage(handle, storage_id, 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_storage_validity(void * handle, const char *storage_id, 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, storage_id, 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 set_all_storage_validity(void * handle, int validity, 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_set_storage_validity(handle, NULL, validity, 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 get_storage_id(void * handle, const char *path, char *storage_id, uid_t uid, char **err_msg)
626 {
627         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
628
629         if (handle == NULL) {
630                 __set_error_message(ERR_HANDLE, err_msg);
631                 return MEDIA_SVC_PLUGIN_ERROR;
632         }
633
634         ret = media_svc_get_storage_id(handle, path, storage_id, uid);
635         if (ret < 0) {
636                 __set_error_message(ret, err_msg);
637                 return MEDIA_SVC_PLUGIN_ERROR;
638         }
639
640         return MEDIA_SVC_PLUGIN_ERROR_NONE;
641 }
642
643 int set_storage_scan_status(void *handle, const char *storage_id, int status, uid_t uid, char **err_msg)
644 {
645         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
646         media_svc_scan_status_type_e storage_status = status;
647
648         ret = media_svc_set_storage_scan_status(storage_id, storage_status, uid);
649         if (ret < 0) {
650                 __set_error_message(ret, err_msg);
651                 return MEDIA_SVC_PLUGIN_ERROR;
652         }
653
654         return MEDIA_SVC_PLUGIN_ERROR_NONE;
655 }
656
657 int get_storage_list(void *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count, char **err_msg)
658 {
659         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
660
661         if (handle == NULL) {
662                 __set_error_message(ERR_HANDLE, err_msg);
663                 return MEDIA_SVC_PLUGIN_ERROR;
664         }
665
666         if (count == NULL) {
667                 __set_error_message(ERR_HANDLE, err_msg);
668                 return MEDIA_SVC_PLUGIN_ERROR;
669         }
670
671         ret = media_svc_get_storage_list(handle, storage_list, storage_id_list, scan_status_list, count);
672         if (ret < 0) {
673                 __set_error_message(ret, err_msg);
674                 return MEDIA_SVC_PLUGIN_ERROR;
675         }
676
677         return MEDIA_SVC_PLUGIN_ERROR_NONE;
678 }
679
680 int update_item_begin(void *handle, int item_cnt, char **err_msg)
681 {
682         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
683
684         ret = media_svc_update_item_begin(item_cnt);
685         if (ret < 0) {
686                 __set_error_message(ret, err_msg);
687                 return MEDIA_SVC_PLUGIN_ERROR;
688         }
689
690         return MEDIA_SVC_PLUGIN_ERROR_NONE;
691 }
692
693 int update_item_end(void *handle, uid_t uid, char **err_msg)
694 {
695         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
696
697         ret = media_svc_update_item_end(uid);
698         if (ret < 0) {
699                 __set_error_message(ret, err_msg);
700                 return MEDIA_SVC_PLUGIN_ERROR;
701         }
702
703         return MEDIA_SVC_PLUGIN_ERROR_NONE;
704 }
705
706 int update_item_meta(void *handle, const char *file_path, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
707 {
708         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
709
710         if (handle == NULL) {
711                 __set_error_message(ERR_HANDLE, err_msg);
712                 return MEDIA_SVC_PLUGIN_ERROR;
713         }
714
715         if (file_path == NULL) {
716                 __set_error_message(ERR_HANDLE, err_msg);
717                 return MEDIA_SVC_PLUGIN_ERROR;
718         }
719
720         if (storage_id == NULL) {
721                 __set_error_message(ERR_HANDLE, err_msg);
722                 return MEDIA_SVC_PLUGIN_ERROR;
723         }
724
725         ret = media_svc_update_item_meta(handle, file_path, storage_id, storage_type, uid);
726         if (ret < 0) {
727                 __set_error_message(ret, err_msg);
728                 return MEDIA_SVC_PLUGIN_ERROR;
729         }
730
731         return MEDIA_SVC_PLUGIN_ERROR_NONE;
732 }
733
734 int insert_item_scan(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
735 {
736         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
737
738         if (handle == NULL) {
739                 __set_error_message(ERR_HANDLE, err_msg);
740                 return MEDIA_SVC_PLUGIN_ERROR;
741         }
742
743         if (!STRING_VALID(file_path)) {
744                 __set_error_message(ERR_FILE_PATH, err_msg);
745                 return MEDIA_SVC_PLUGIN_ERROR;
746         }
747
748         if (!STORAGE_VALID(storage_type)) {
749                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
750                 return MEDIA_SVC_PLUGIN_ERROR;
751         }
752
753         ret = media_svc_insert_item_pass1(handle, storage_id, storage_type, file_path, FALSE, uid);
754         if (ret < 0) {
755                 __set_error_message(ret, err_msg);
756                 return MEDIA_SVC_PLUGIN_ERROR;
757         }
758
759         return MEDIA_SVC_PLUGIN_ERROR_NONE;
760 }
761
762 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)
763 {
764         /* For scanner V2 */
765         return MEDIA_SVC_PLUGIN_ERROR_NONE;
766 }
767
768 int update_one_extract_item(void* handle, const char* storage_id, int storage_type, void* data, int burst, char** err_msg)
769 {
770         /* For scanner V2 */
771         return MEDIA_SVC_PLUGIN_ERROR_NONE;
772 }
773
774 int query_do_update_list(void* handle, char** err_msg)
775 {
776         /* For scanner V2 */
777         return MEDIA_SVC_PLUGIN_ERROR_NONE;
778 }
779
780 int insert_folder_begin(void * handle, int item_cnt, char **err_msg)
781 {
782         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
783
784         ret = media_svc_insert_folder_begin(item_cnt);
785         if (ret < 0) {
786                 __set_error_message(ret, err_msg);
787                 return MEDIA_SVC_PLUGIN_ERROR;
788         }
789
790         return MEDIA_SVC_PLUGIN_ERROR_NONE;
791 }
792
793 int insert_folder_end(void *handle, uid_t uid, char **err_msg)
794 {
795         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
796
797         ret = media_svc_insert_folder_end(uid);
798         if (ret < 0) {
799                 __set_error_message(ret, err_msg);
800                 return MEDIA_SVC_PLUGIN_ERROR;
801         }
802
803         return MEDIA_SVC_PLUGIN_ERROR_NONE;
804 }
805
806 int insert_folder(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
807 {
808         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
809
810         if (handle == NULL) {
811                 __set_error_message(ERR_HANDLE, err_msg);
812                 return MEDIA_SVC_PLUGIN_ERROR;
813         }
814
815         if (!STRING_VALID(file_path)) {
816                 __set_error_message(ERR_FILE_PATH, err_msg);
817                 return MEDIA_SVC_PLUGIN_ERROR;
818         }
819
820         if (!STORAGE_VALID(storage_type)) {
821                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
822                 return MEDIA_SVC_PLUGIN_ERROR;
823         }
824
825         ret = media_svc_insert_folder(handle, storage_id, storage_type, file_path, uid);
826         if (ret < 0) {
827                 __set_error_message(ret, err_msg);
828                 return MEDIA_SVC_PLUGIN_ERROR;
829         }
830
831         return MEDIA_SVC_PLUGIN_ERROR_NONE;
832 }
833
834 int delete_invalid_folder(void * handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
835 {
836         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
837
838         ret = media_svc_delete_invalid_folder(storage_id, storage_type, uid);
839         if (ret < 0) {
840                 __set_error_message(ret, err_msg);
841                 return MEDIA_SVC_PLUGIN_ERROR;
842         }
843
844         return MEDIA_SVC_PLUGIN_ERROR_NONE;
845 }
846
847 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)
848 {
849         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
850
851         if (handle == NULL) {
852                 __set_error_message(ERR_HANDLE, err_msg);
853                 return MEDIA_SVC_PLUGIN_ERROR;
854         }
855
856         ret = media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
857         if (ret < 0) {
858                 __set_error_message(ret, err_msg);
859                 return MEDIA_SVC_PLUGIN_ERROR;
860         }
861
862         return MEDIA_SVC_PLUGIN_ERROR_NONE;
863 }
864
865 int get_folder_scan_status(void *handle, const char *storage_id, const char *path, int *status, char **err_msg)
866 {
867         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
868         int storage_status = 0;
869
870         if (handle == NULL) {
871                 __set_error_message(ERR_HANDLE, err_msg);
872                 return MEDIA_SVC_PLUGIN_ERROR;
873         }
874
875         ret = media_svc_get_folder_scan_status(handle, storage_id, path, &storage_status);
876         if (ret < 0) {
877                 __set_error_message(ret, err_msg);
878                 return MEDIA_SVC_PLUGIN_ERROR;
879         }
880
881         *status = storage_status;
882
883         return ret;
884 }
885
886 int set_folder_scan_status(void *handle, const char *storage_id, const char *path, int status, uid_t uid, char **err_msg)
887 {
888         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
889         int storage_status = status;
890
891         ret = media_svc_set_folder_scan_status(storage_id, path, storage_status, uid);
892         if (ret < 0) {
893                 __set_error_message(ret, err_msg);
894                 return MEDIA_SVC_PLUGIN_ERROR;
895         }
896
897         return ret;
898 }
899
900 int check_folder_modified(void *handle, const char *path, const char *storage_id, bool *modified, char **err_msg)
901 {
902         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
903         *modified = TRUE;
904
905         if (handle == NULL) {
906                 __set_error_message(ERR_HANDLE, err_msg);
907                 return MEDIA_SVC_PLUGIN_ERROR;
908         }
909
910         if (!STRING_VALID(path)) {
911                 __set_error_message(ERR_FILE_PATH, err_msg);
912                 return MEDIA_SVC_PLUGIN_ERROR;
913         }
914
915         ret = media_svc_get_folder_modified_time(handle, path, storage_id, modified);
916         if (ret < 0) {
917                 __set_error_message(ret, err_msg);
918                 return MEDIA_SVC_PLUGIN_ERROR;
919         }
920
921         return ret;
922 }
923
924 int get_null_scan_folder_list(void *handle, const char *storage_id, const char *folder_path, char ***folder_list, int *count, char **err_msg)
925 {
926         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
927
928         if (handle == NULL) {
929                 __set_error_message(ERR_HANDLE, err_msg);
930                 return MEDIA_SVC_PLUGIN_ERROR;
931         }
932
933         if (count == NULL) {
934                 __set_error_message(ERR_HANDLE, err_msg);
935                 return MEDIA_SVC_PLUGIN_ERROR;
936         }
937
938         ret = media_svc_get_null_scan_folder_list(handle, storage_id, folder_path, folder_list, count);
939         if (ret < 0) {
940                 __set_error_message(ret, err_msg);
941                 return MEDIA_SVC_PLUGIN_ERROR;
942         }
943
944         return ret;
945 }
946
947 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)
948 {
949         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
950
951         ret = media_svc_change_validity_item_batch(storage_id, path, des_validity, src_validity, uid);
952         if (ret < 0) {
953                 __set_error_message(ret, err_msg);
954                 return MEDIA_SVC_PLUGIN_ERROR;
955         }
956
957         return ret;
958 }
959
960 int check_folder_exist(void * handle, const char *storage_id, const char *folder_path, char **err_msg)
961 {
962         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
963
964         if (handle == NULL) {
965                 __set_error_message(ERR_HANDLE, err_msg);
966                 return MEDIA_SVC_PLUGIN_ERROR;
967         }
968
969         ret = media_svc_check_folder_exist_by_path(handle, storage_id, folder_path);
970         if (ret < 0) {
971                 __set_error_message(ret, err_msg);
972                 return MEDIA_SVC_PLUGIN_ERROR;
973         }
974
975         return MEDIA_SVC_PLUGIN_ERROR_NONE;
976 }
977
978 int get_folder_id(void * handle, const char *storage_id, const char *path, char *folder_id, char **err_msg)
979 {
980         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
981
982         if (handle == NULL) {
983                 __set_error_message(ERR_HANDLE, err_msg);
984                 return MEDIA_SVC_PLUGIN_ERROR;
985         }
986
987         ret = media_svc_get_folder_id(handle, storage_id, path, folder_id);
988         if (ret < 0) {
989                 __set_error_message(ret, err_msg);
990                 return MEDIA_SVC_PLUGIN_ERROR;
991         }
992
993         return MEDIA_SVC_PLUGIN_ERROR_NONE;
994 }
995
996 int get_media_type(void *handle, const char *path, int *mediatype, char **err_msg)
997 {
998         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
999
1000         if (handle == NULL) {
1001                 __set_error_message(ERR_HANDLE, err_msg);
1002                 return MEDIA_SVC_PLUGIN_ERROR;
1003         }
1004
1005         ret = media_svc_get_media_type(path, mediatype);
1006         if (ret < 0) {
1007                 __set_error_message(ret, err_msg);
1008                 return MEDIA_SVC_PLUGIN_ERROR;
1009         }
1010
1011         return MEDIA_SVC_PLUGIN_ERROR_NONE;
1012 }
1013
1014