Remove un-called dlopen function
[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 delete_all_invalid_items_in_folder(void *handle, const char *storage_id, const char *folder_path, bool is_recursve, uid_t uid, char **err_msg)
399 {
400         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
401
402         if (handle == NULL) {
403                 __set_error_message(ERR_HANDLE, err_msg);
404                 return MEDIA_SVC_PLUGIN_ERROR;
405         }
406
407         if (!STRING_VALID(folder_path)) {
408                 __set_error_message(ERR_FOLDER_PATH, err_msg);
409                 return MEDIA_SVC_PLUGIN_ERROR;
410         }
411
412         ret = media_svc_delete_invalid_items_in_folder(handle, storage_id, folder_path, is_recursve, uid);
413         if (ret < 0) {
414                 __set_error_message(ret, err_msg);
415                 return MEDIA_SVC_PLUGIN_ERROR;
416         }
417
418         return MEDIA_SVC_PLUGIN_ERROR_NONE;
419 }
420
421 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)
422 {
423         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
424
425         if (!STRING_VALID(dir_path)) {
426                 __set_error_message(ERR_FOLDER_PATH, err_msg);
427                 return MEDIA_SVC_PLUGIN_ERROR;
428         }
429
430         ret = media_svc_send_dir_update_noti(handle, storage_id, dir_path, folder_id, (media_item_update_type_e)update_type, pid);
431         if (ret < 0) {
432                 __set_error_message(ret, err_msg);
433                 return MEDIA_SVC_PLUGIN_ERROR;
434         }
435
436         return MEDIA_SVC_PLUGIN_ERROR_NONE;
437 }
438
439 int count_delete_items_in_folder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
440 {
441         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
442
443         if (handle == NULL) {
444                 __set_error_message(ERR_HANDLE, err_msg);
445                 return MEDIA_SVC_PLUGIN_ERROR;
446         }
447
448         if (count == NULL) {
449                 __set_error_message(ERR_HANDLE, err_msg);
450                 return MEDIA_SVC_PLUGIN_ERROR;
451         }
452
453         if (!STRING_VALID(folder_path)) {
454                 __set_error_message(ERR_FOLDER_PATH, err_msg);
455                 return MEDIA_SVC_PLUGIN_ERROR;
456         }
457
458         ret = media_svc_count_invalid_items_in_folder(handle, storage_id, folder_path, count);
459         if (ret < 0) {
460                 __set_error_message(ret, err_msg);
461                 return MEDIA_SVC_PLUGIN_ERROR;
462         }
463
464         return MEDIA_SVC_PLUGIN_ERROR_NONE;
465 }
466
467 int check_db(void *handle, uid_t uid, char **err_msg)
468 {
469         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
470         int user_version = -1;
471
472         ret = media_svc_get_user_version(handle, &user_version);
473         if (ret < 0) {
474                 __set_error_message(ret, err_msg);
475                 return MEDIA_SVC_PLUGIN_ERROR;
476         }
477
478         if (user_version == 0) {
479                 /*check db schema*/
480                 ret = media_svc_create_table(uid);
481                 if (ret < 0) {
482                         __set_error_message(ret, err_msg);
483                         return MEDIA_SVC_PLUGIN_ERROR;
484                 }
485         } else {
486                 /*check db version*/
487                 ret = media_svc_check_db_upgrade(handle, user_version, uid);
488                 if (ret < 0) {
489                         __set_error_message(ret, err_msg);
490                         return MEDIA_SVC_PLUGIN_ERROR;
491                 }
492         }
493
494         return MEDIA_SVC_PLUGIN_ERROR_NONE;
495 }
496
497 int check_db_corrupt(void *handle, char **err_msg)
498 {
499         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
500
501         /*check db version*/
502         ret = media_svc_check_db_corrupt(handle);
503         if (ret < 0) {
504                 __set_error_message(ret, err_msg);
505                 return MEDIA_SVC_PLUGIN_ERROR;
506         }
507
508         return MEDIA_SVC_PLUGIN_ERROR_NONE;
509 }
510
511 int get_folder_list(void *handle, const char *storage_id, char *start_path, char ***folder_list, int **modified_time_list, int **item_num_list, int *count, char **err_msg)
512 {
513         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
514
515         if (handle == NULL) {
516                 __set_error_message(ERR_HANDLE, err_msg);
517                 return MEDIA_SVC_PLUGIN_ERROR;
518         }
519
520         if (count == NULL) {
521                 __set_error_message(ERR_HANDLE, err_msg);
522                 return MEDIA_SVC_PLUGIN_ERROR;
523         }
524
525         ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t **)modified_time_list, item_num_list, count);
526         if (ret < 0) {
527                 __set_error_message(ret, err_msg);
528                 return MEDIA_SVC_PLUGIN_ERROR;
529         }
530
531         return MEDIA_SVC_PLUGIN_ERROR_NONE;
532 }
533
534 int update_folder_time(void *handle, const char *storage_id, char *folder_path, uid_t uid, char **err_msg)
535 {
536         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
537
538         if (handle == NULL) {
539                 __set_error_message(ERR_HANDLE, err_msg);
540                 return MEDIA_SVC_PLUGIN_ERROR;
541         }
542
543         if (folder_path == NULL) {
544                 __set_error_message(ERR_HANDLE, err_msg);
545                 return MEDIA_SVC_PLUGIN_ERROR;
546         }
547
548         ret = media_svc_update_folder_time(handle, storage_id, folder_path, uid);
549         if (ret < 0) {
550                 __set_error_message(ret, err_msg);
551                 return MEDIA_SVC_PLUGIN_ERROR;
552         }
553
554         return MEDIA_SVC_PLUGIN_ERROR_NONE;
555 }
556
557 int get_uuid(void * handle, char **uuid, char **err_msg)
558 {
559         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
560
561         ret = media_svc_generate_uuid(uuid);
562         if (ret < 0) {
563                 __set_error_message(ret, err_msg);
564                 return MEDIA_SVC_PLUGIN_ERROR;
565         }
566
567         return MEDIA_SVC_PLUGIN_ERROR_NONE;
568 }
569
570 int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg)
571 {
572         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
573
574         if (handle == NULL) {
575                 __set_error_message(ERR_HANDLE, err_msg);
576                 return MEDIA_SVC_PLUGIN_ERROR;
577         }
578
579         ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
580         if (ret < 0) {
581                 __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
582                 return MEDIA_SVC_PLUGIN_ERROR;
583         }
584
585         return MEDIA_SVC_PLUGIN_ERROR_NONE;
586 }
587
588 int check_storage(void * handle, const char *storage_id, const char *storage_name, char **storage_path, int *validity, uid_t uid, char **err_msg)
589 {
590         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
591
592         if (handle == NULL) {
593                 __set_error_message(ERR_HANDLE, err_msg);
594                 return MEDIA_SVC_PLUGIN_ERROR;
595         }
596
597         ret = media_svc_check_storage(handle, storage_id, storage_name, storage_path, validity, uid);
598         if (ret < 0) {
599                 __set_error_message(ret, err_msg);
600                 return MEDIA_SVC_PLUGIN_ERROR;
601         }
602
603         return MEDIA_SVC_PLUGIN_ERROR_NONE;
604 }
605
606 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)
607 {
608         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
609
610         if (handle == NULL) {
611                 __set_error_message(ERR_HANDLE, err_msg);
612                 return MEDIA_SVC_PLUGIN_ERROR;
613         }
614
615         ret = media_svc_insert_storage(handle, storage_id, storage_name, storage_path, storage_type, uid);
616         if (ret < 0) {
617                 __set_error_message(ret, err_msg);
618                 return MEDIA_SVC_PLUGIN_ERROR;
619         }
620
621         return MEDIA_SVC_PLUGIN_ERROR_NONE;
622 }
623
624 int update_storage(void *handle, const char *storage_id, const char *storage_path, uid_t uid, char **err_msg)
625 {
626         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
627
628         if (handle == NULL) {
629                 __set_error_message(ERR_HANDLE, err_msg);
630                 return MEDIA_SVC_PLUGIN_ERROR;
631         }
632
633         ret = media_svc_update_storage(handle, storage_id, storage_path, uid);
634         if (ret < 0) {
635                 __set_error_message(ret, err_msg);
636                 return MEDIA_SVC_PLUGIN_ERROR;
637         }
638
639         return MEDIA_SVC_PLUGIN_ERROR_NONE;
640 }
641
642 int delete_storage(void * handle, const char *storage_id, const char *storage_name, uid_t uid, char **err_msg)
643 {
644         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
645
646         if (handle == NULL) {
647                 __set_error_message(ERR_HANDLE, err_msg);
648                 return MEDIA_SVC_PLUGIN_ERROR;
649         }
650
651         ret = media_svc_delete_storage(handle, storage_id, storage_name, uid);
652         if (ret < 0) {
653                 __set_error_message(ret, err_msg);
654                 return MEDIA_SVC_PLUGIN_ERROR;
655         }
656
657         return MEDIA_SVC_PLUGIN_ERROR_NONE;
658 }
659
660 int set_storage_validity(void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg)
661 {
662         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
663
664         if (handle == NULL) {
665                 __set_error_message(ERR_HANDLE, err_msg);
666                 return MEDIA_SVC_PLUGIN_ERROR;
667         }
668
669         ret = media_svc_set_storage_validity(handle, storage_id, validity, uid);
670         if (ret < 0) {
671                 __set_error_message(ret, err_msg);
672                 return MEDIA_SVC_PLUGIN_ERROR;
673         }
674
675         return MEDIA_SVC_PLUGIN_ERROR_NONE;
676 }
677
678 int set_all_storage_validity(void * handle, int validity, uid_t uid, char **err_msg)
679 {
680         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
681
682         if (handle == NULL) {
683                 __set_error_message(ERR_HANDLE, err_msg);
684                 return MEDIA_SVC_PLUGIN_ERROR;
685         }
686
687         ret = media_svc_set_storage_validity(handle, NULL, validity, uid);
688         if (ret < 0) {
689                 __set_error_message(ret, err_msg);
690                 return MEDIA_SVC_PLUGIN_ERROR;
691         }
692
693         return MEDIA_SVC_PLUGIN_ERROR_NONE;
694 }
695
696 int get_storage_id(void * handle, const char *path, char *storage_id, uid_t uid, char **err_msg)
697 {
698         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
699
700         if (handle == NULL) {
701                 __set_error_message(ERR_HANDLE, err_msg);
702                 return MEDIA_SVC_PLUGIN_ERROR;
703         }
704
705         ret = media_svc_get_storage_id(handle, path, storage_id, uid);
706         if (ret < 0) {
707                 __set_error_message(ret, err_msg);
708                 return MEDIA_SVC_PLUGIN_ERROR;
709         }
710
711         return MEDIA_SVC_PLUGIN_ERROR_NONE;
712 }
713
714 int set_storage_scan_status(void *handle, const char *storage_id, int status, uid_t uid, char **err_msg)
715 {
716         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
717         media_svc_scan_status_type_e storage_status = status;
718
719         ret = media_svc_set_storage_scan_status(storage_id, storage_status, uid);
720         if (ret < 0) {
721                 __set_error_message(ret, err_msg);
722                 return MEDIA_SVC_PLUGIN_ERROR;
723         }
724
725         return MEDIA_SVC_PLUGIN_ERROR_NONE;
726 }
727
728 int get_storage_list(void *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count, char **err_msg)
729 {
730         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
731
732         if (handle == NULL) {
733                 __set_error_message(ERR_HANDLE, err_msg);
734                 return MEDIA_SVC_PLUGIN_ERROR;
735         }
736
737         if (count == NULL) {
738                 __set_error_message(ERR_HANDLE, err_msg);
739                 return MEDIA_SVC_PLUGIN_ERROR;
740         }
741
742         ret = media_svc_get_storage_list(handle, storage_list, storage_id_list, scan_status_list, count);
743         if (ret < 0) {
744                 __set_error_message(ret, err_msg);
745                 return MEDIA_SVC_PLUGIN_ERROR;
746         }
747
748         return MEDIA_SVC_PLUGIN_ERROR_NONE;
749 }
750
751 int update_item_begin(void *handle, int item_cnt, char **err_msg)
752 {
753         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
754
755         ret = media_svc_update_item_begin(item_cnt);
756         if (ret < 0) {
757                 __set_error_message(ret, err_msg);
758                 return MEDIA_SVC_PLUGIN_ERROR;
759         }
760
761         return MEDIA_SVC_PLUGIN_ERROR_NONE;
762 }
763
764 int update_item_end(void *handle, uid_t uid, char **err_msg)
765 {
766         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
767
768         ret = media_svc_update_item_end(uid);
769         if (ret < 0) {
770                 __set_error_message(ret, err_msg);
771                 return MEDIA_SVC_PLUGIN_ERROR;
772         }
773
774         return MEDIA_SVC_PLUGIN_ERROR_NONE;
775 }
776
777 int update_item_meta(void *handle, const char *file_path, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
778 {
779         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
780
781         if (handle == NULL) {
782                 __set_error_message(ERR_HANDLE, err_msg);
783                 return MEDIA_SVC_PLUGIN_ERROR;
784         }
785
786         if (file_path == NULL) {
787                 __set_error_message(ERR_HANDLE, err_msg);
788                 return MEDIA_SVC_PLUGIN_ERROR;
789         }
790
791         if (storage_id == NULL) {
792                 __set_error_message(ERR_HANDLE, err_msg);
793                 return MEDIA_SVC_PLUGIN_ERROR;
794         }
795
796         ret = media_svc_update_item_meta(handle, file_path, storage_id, storage_type, uid);
797         if (ret < 0) {
798                 __set_error_message(ret, err_msg);
799                 return MEDIA_SVC_PLUGIN_ERROR;
800         }
801
802         return MEDIA_SVC_PLUGIN_ERROR_NONE;
803 }
804
805 int insert_item_scan(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
806 {
807         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
808
809         if (handle == NULL) {
810                 __set_error_message(ERR_HANDLE, err_msg);
811                 return MEDIA_SVC_PLUGIN_ERROR;
812         }
813
814         if (!STRING_VALID(file_path)) {
815                 __set_error_message(ERR_FILE_PATH, err_msg);
816                 return MEDIA_SVC_PLUGIN_ERROR;
817         }
818
819         if (!STORAGE_VALID(storage_type)) {
820                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
821                 return MEDIA_SVC_PLUGIN_ERROR;
822         }
823
824         ret = media_svc_insert_item_pass1(handle, storage_id, storage_type, file_path, FALSE, uid);
825         if (ret < 0) {
826                 __set_error_message(ret, err_msg);
827                 return MEDIA_SVC_PLUGIN_ERROR;
828         }
829
830         return MEDIA_SVC_PLUGIN_ERROR_NONE;
831 }
832
833 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)
834 {
835 #if 0
836         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
837
838         if (handle == NULL) {
839                 __set_error_message(ERR_HANDLE, err_msg);
840                 return MEDIA_SVC_PLUGIN_ERROR;
841         }
842
843         if (!STORAGE_VALID(storage_type)) {
844                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
845                 return MEDIA_SVC_PLUGIN_ERROR;
846         }
847
848         ret = media_svc_pass2_get_extract_list(handle, storage_id, storage_type, scan_type, path, burst, uid, array);
849         if (ret < 0) {
850                 __set_error_message(ret, err_msg);
851                 return MEDIA_SVC_PLUGIN_ERROR;
852         }
853 #endif
854         return MEDIA_SVC_PLUGIN_ERROR_NONE;
855 }
856
857 int update_one_extract_item(void* handle, const char* storage_id, int storage_type, void* data, int burst, char** err_msg)
858 {
859 #if 0
860         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
861
862         if (handle == NULL) {
863                 __set_error_message(ERR_HANDLE, err_msg);
864                 return MEDIA_SVC_PLUGIN_ERROR;
865         }
866
867         if (!STORAGE_VALID(storage_type)) {
868                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
869                 return MEDIA_SVC_PLUGIN_ERROR;
870         }
871
872         ret = media_svc_insert_one_item_pass2(handle, storage_id, storage_type, data, burst);
873         if (ret < 0) {
874                 __set_error_message(ret, err_msg);
875                 return MEDIA_SVC_PLUGIN_ERROR;
876         }
877 #endif
878         return MEDIA_SVC_PLUGIN_ERROR_NONE;
879 }
880
881 int query_do_update_list(void* handle, char** err_msg)
882 {
883 #if 0
884         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
885
886         if (handle == NULL) {
887                 __set_error_message(ERR_HANDLE, err_msg);
888                 return MEDIA_SVC_PLUGIN_ERROR;
889         }
890
891         ret = media_svc_query_do_update_list(handle);
892         if (ret < 0) {
893                 __set_error_message(ret, err_msg);
894                 return MEDIA_SVC_PLUGIN_ERROR;
895         }
896 #endif
897         return MEDIA_SVC_PLUGIN_ERROR_NONE;
898 }
899
900 int insert_folder_begin(void * handle, int item_cnt, char **err_msg)
901 {
902         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
903
904         ret = media_svc_insert_folder_begin(item_cnt);
905         if (ret < 0) {
906                 __set_error_message(ret, err_msg);
907                 return MEDIA_SVC_PLUGIN_ERROR;
908         }
909
910         return MEDIA_SVC_PLUGIN_ERROR_NONE;
911 }
912
913 int insert_folder_end(void *handle, uid_t uid, char **err_msg)
914 {
915         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
916
917         ret = media_svc_insert_folder_end(uid);
918         if (ret < 0) {
919                 __set_error_message(ret, err_msg);
920                 return MEDIA_SVC_PLUGIN_ERROR;
921         }
922
923         return MEDIA_SVC_PLUGIN_ERROR_NONE;
924 }
925
926 int insert_folder(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
927 {
928         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
929
930         if (handle == NULL) {
931                 __set_error_message(ERR_HANDLE, err_msg);
932                 return MEDIA_SVC_PLUGIN_ERROR;
933         }
934
935         if (!STRING_VALID(file_path)) {
936                 __set_error_message(ERR_FILE_PATH, err_msg);
937                 return MEDIA_SVC_PLUGIN_ERROR;
938         }
939
940         if (!STORAGE_VALID(storage_type)) {
941                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
942                 return MEDIA_SVC_PLUGIN_ERROR;
943         }
944
945         ret = media_svc_insert_folder(handle, storage_id, storage_type, file_path, uid);
946         if (ret < 0) {
947                 __set_error_message(ret, err_msg);
948                 return MEDIA_SVC_PLUGIN_ERROR;
949         }
950
951         return MEDIA_SVC_PLUGIN_ERROR_NONE;
952 }
953
954 int delete_invalid_folder(void * handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
955 {
956         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
957
958         ret = media_svc_delete_invalid_folder(storage_id, storage_type, uid);
959         if (ret < 0) {
960                 __set_error_message(ret, err_msg);
961                 return MEDIA_SVC_PLUGIN_ERROR;
962         }
963
964         return MEDIA_SVC_PLUGIN_ERROR_NONE;
965 }
966
967 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)
968 {
969         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
970
971         if (handle == NULL) {
972                 __set_error_message(ERR_HANDLE, err_msg);
973                 return MEDIA_SVC_PLUGIN_ERROR;
974         }
975
976         ret = media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
977         if (ret < 0) {
978                 __set_error_message(ret, err_msg);
979                 return MEDIA_SVC_PLUGIN_ERROR;
980         }
981
982         return MEDIA_SVC_PLUGIN_ERROR_NONE;
983 }
984
985 int delete_invalid_folder_by_path(void * handle, const char *storage_id, const char *folder_path, uid_t uid, int *delete_count, char **err_msg)
986 {
987         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
988
989         if (handle == NULL) {
990                 __set_error_message(ERR_HANDLE, err_msg);
991                 return MEDIA_SVC_PLUGIN_ERROR;
992         }
993
994         ret = media_svc_delete_invalid_folder_by_path(handle, storage_id, folder_path, uid, delete_count);
995         if (ret < 0) {
996                 __set_error_message(ret, err_msg);
997                 return MEDIA_SVC_PLUGIN_ERROR;
998         }
999
1000         return MEDIA_SVC_PLUGIN_ERROR_NONE;
1001 }
1002
1003 int get_folder_scan_status(void *handle, const char *storage_id, const char *path, int *status, char **err_msg)
1004 {
1005         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1006         int storage_status = 0;
1007
1008         if (handle == NULL) {
1009                 __set_error_message(ERR_HANDLE, err_msg);
1010                 return MEDIA_SVC_PLUGIN_ERROR;
1011         }
1012
1013         ret = media_svc_get_folder_scan_status(handle, storage_id, path, &storage_status);
1014         if (ret < 0) {
1015                 __set_error_message(ret, err_msg);
1016                 return MEDIA_SVC_PLUGIN_ERROR;
1017         }
1018
1019         *status = storage_status;
1020
1021         return ret;
1022 }
1023
1024 int set_folder_scan_status(void *handle, const char *storage_id, const char *path, int status, uid_t uid, char **err_msg)
1025 {
1026         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1027         int storage_status = status;
1028
1029         ret = media_svc_set_folder_scan_status(storage_id, path, storage_status, uid);
1030         if (ret < 0) {
1031                 __set_error_message(ret, err_msg);
1032                 return MEDIA_SVC_PLUGIN_ERROR;
1033         }
1034
1035         return ret;
1036 }
1037
1038 int check_folder_modified(void *handle, const char *path, const char *storage_id, bool *modified, char **err_msg)
1039 {
1040         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1041         *modified = TRUE;
1042
1043         if (handle == NULL) {
1044                 __set_error_message(ERR_HANDLE, err_msg);
1045                 return MEDIA_SVC_PLUGIN_ERROR;
1046         }
1047
1048         if (!STRING_VALID(path)) {
1049                 __set_error_message(ERR_FILE_PATH, err_msg);
1050                 return MEDIA_SVC_PLUGIN_ERROR;
1051         }
1052
1053         ret = media_svc_get_folder_modified_time(handle, path, storage_id, modified);
1054         if (ret < 0) {
1055                 __set_error_message(ret, err_msg);
1056                 return MEDIA_SVC_PLUGIN_ERROR;
1057         }
1058
1059         return ret;
1060 }
1061
1062 int get_null_scan_folder_list(void *handle, const char *storage_id, const char *folder_path, char ***folder_list, int *count, char **err_msg)
1063 {
1064         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1065
1066         if (handle == NULL) {
1067                 __set_error_message(ERR_HANDLE, err_msg);
1068                 return MEDIA_SVC_PLUGIN_ERROR;
1069         }
1070
1071         if (count == NULL) {
1072                 __set_error_message(ERR_HANDLE, err_msg);
1073                 return MEDIA_SVC_PLUGIN_ERROR;
1074         }
1075
1076         ret = media_svc_get_null_scan_folder_list(handle, storage_id, folder_path, folder_list, count);
1077         if (ret < 0) {
1078                 __set_error_message(ret, err_msg);
1079                 return MEDIA_SVC_PLUGIN_ERROR;
1080         }
1081
1082         return ret;
1083 }
1084
1085 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)
1086 {
1087         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1088
1089         ret = media_svc_change_validity_item_batch(storage_id, path, des_validity, src_validity, uid);
1090         if (ret < 0) {
1091                 __set_error_message(ret, err_msg);
1092                 return MEDIA_SVC_PLUGIN_ERROR;
1093         }
1094
1095         return ret;
1096 }
1097
1098 int check_folder_exist(void * handle, const char *storage_id, const char *folder_path, char **err_msg)
1099 {
1100         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1101
1102         if (handle == NULL) {
1103                 __set_error_message(ERR_HANDLE, err_msg);
1104                 return MEDIA_SVC_PLUGIN_ERROR;
1105         }
1106
1107         ret = media_svc_check_folder_exist_by_path(handle, storage_id, folder_path);
1108         if (ret < 0) {
1109                 __set_error_message(ret, err_msg);
1110                 return MEDIA_SVC_PLUGIN_ERROR;
1111         }
1112
1113         return MEDIA_SVC_PLUGIN_ERROR_NONE;
1114 }
1115
1116 int count_subfolder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
1117 {
1118         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1119         int cnt = 0;
1120
1121         if (handle == NULL) {
1122                 __set_error_message(ERR_HANDLE, err_msg);
1123                 return MEDIA_SVC_PLUGIN_ERROR;
1124         }
1125
1126         ret = media_svc_check_subfolder_by_path(handle, storage_id, folder_path, &cnt);
1127         if (ret < 0) {
1128                 __set_error_message(ret, err_msg);
1129                 return MEDIA_SVC_PLUGIN_ERROR;
1130         }
1131
1132         *count = cnt;
1133
1134         return MEDIA_SVC_PLUGIN_ERROR_NONE;
1135 }
1136
1137 int get_folder_id(void * handle, const char *storage_id, const char *path, char *folder_id, char **err_msg)
1138 {
1139         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1140
1141         if (handle == NULL) {
1142                 __set_error_message(ERR_HANDLE, err_msg);
1143                 return MEDIA_SVC_PLUGIN_ERROR;
1144         }
1145
1146         ret = media_svc_get_folder_id(handle, storage_id, path, folder_id);
1147         if (ret < 0) {
1148                 __set_error_message(ret, err_msg);
1149                 return MEDIA_SVC_PLUGIN_ERROR;
1150         }
1151
1152         return MEDIA_SVC_PLUGIN_ERROR_NONE;
1153 }
1154
1155 int get_media_type(void *handle, const char *path, int *mediatype, char **err_msg)
1156 {
1157         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1158
1159         if (handle == NULL) {
1160                 __set_error_message(ERR_HANDLE, err_msg);
1161                 return MEDIA_SVC_PLUGIN_ERROR;
1162         }
1163
1164         ret = media_svc_get_media_type(path, mediatype);
1165         if (ret < 0) {
1166                 __set_error_message(ret, err_msg);
1167                 return MEDIA_SVC_PLUGIN_ERROR;
1168         }
1169
1170         return MEDIA_SVC_PLUGIN_ERROR_NONE;
1171 }
1172
1173