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