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