1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
|
/*
* Media Server
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* This file defines api utilities of contents manager engines.
*
* @file media-server-db-svc.c
* @author Yong Yeon Kim(yy9875.kim@samsung.com)
* @version 1.0
* @brief This file implements main database operation.
*/
#include <dlfcn.h>
#include <aul/aul.h>
#include "media-server-utils.h"
#include "media-server-inotify.h"
#include "media-server-drm.h"
#include "media-server-db-svc.h"
GMutex * db_mutex;
extern GMutex *queue_mutex;
GAsyncQueue* soc_queue;
GArray *reg_list;
GMutex *list_mutex;
GMutex *queue_mutex;
#define MS_REGISTER_COUNT 100 /*For bundle commit*/
#define MS_VALID_COUNT 100 /*For bundle commit*/
#define MS_MOVE_COUNT 100 /*For bundle commit*/
void **func_handle = NULL; /*dlopen handel*/
enum func_list {
eCHECK,
eCONNECT,
eDISCONNECT,
eEXIST,
eINSERT_BEGIN,
eINSERT_END,
eINSERT_BATCH,
eINSERT,
eMOVE_BEGIN,
eMOVE_END,
eMOVE,
eSET_ALL_VALIDITY,
eSET_VALIDITY_BEGIN,
eSET_VALIDITY_END,
eSET_VALIDITY,
eDELETE,
eDELETE_ALL,
eDELETE_INVALID_ITEMS,
eUPDATE_BEGIN,
eUPDATE_END,
eREFRESH_ITEM,
eFUNC_MAX
};
static void
_ms_insert_reg_list(const char *path)
{
char *reg_path = strdup(path);
g_mutex_lock(list_mutex);
g_array_append_val(reg_list, reg_path);
g_mutex_unlock(list_mutex);
}
static bool
_ms_find_reg_list(const char *path)
{
int list_index;
int len = reg_list->len;
char *data;
bool res = false;
g_mutex_lock(list_mutex);
MS_DBG("array length : %d", len);
for(list_index = 0; list_index < len; list_index++) {
data = g_array_index (reg_list, char*, list_index);
if(!strcmp(data, path))
res = true;
}
g_mutex_unlock(list_mutex);
return res;
}
static void
_ms_delete_reg_list(const char *path)
{
int list_index;
int len = reg_list->len;
char *data;
MS_DBG("Delete : %s", path);
g_mutex_lock(list_mutex);
for(list_index = 0; list_index < len; list_index++) {
data = g_array_index (reg_list, char*, list_index);
if(!strcmp(data, path)) {
MS_DBG("Delete complete : %s", data);
MS_SAFE_FREE(data);
g_array_remove_index(reg_list, list_index);
break;
}
}
g_mutex_unlock(list_mutex);
}
static int
_ms_get_mime(const char *path, char *mimetype)
{
int ret = 0;
if (path == NULL)
return MS_ERR_ARG_INVALID;
/*get content type and mime type from file. */
/*in case of drm file. */
if (ms_is_drm_file(path)) {
ms_inoti_add_ignore_file(path);
ret = ms_get_mime_in_drm_info(path, mimetype);
if (ret != MS_ERR_NONE) {
MS_DBG_ERR("Fail to get mime");
return MS_ERR_MIME_GET_FAIL;
}
} else {
/*in case of normal files */
if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
MS_DBG_ERR("aul_get_mime_from_file fail");
return MS_ERR_MIME_GET_FAIL;
}
}
return MS_ERR_NONE;
}
#define CONFIG_PATH "/opt/data/file-manager-service/plugin-config"
#define EXT ".so"
#define EXT_LEN 3
GArray *so_array;
void ***func_array;
int lib_num;
static int
_ms_check_category(const char *path, const char *mimetype, int index)
{
int ret;
char *err_msg = NULL;
ret = ((CHECK_ITEM)func_array[index][eCHECK])(path, mimetype, &err_msg);
if (ret != 0) {
MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, index), err_msg, path);
MS_SAFE_FREE(err_msg);
}
return ret;
}
static int
_ms_token_data(char *buf, char **name)
{
int len;
char* pos = NULL;
pos = strstr(buf, EXT);
if (pos == NULL) {
MS_DBG_ERR("This is not shared object library.");
name = NULL;
return -1;
} else {
len = pos - buf + EXT_LEN;
*name = strndup(buf, len);
MS_DBG("%s", *name);
}
return 0;
}
static bool
_ms_load_config()
{
char *cret;
int ret;
FILE *fp;
char *so_name = NULL;
char buf[256] = {0};
fp = fopen(CONFIG_PATH, "rt");
if (fp == NULL) {
MS_DBG_ERR("fp is NULL");
return MS_ERR_FILE_OPEN_FAIL;
}
while(1) {
cret = fgets(buf, 256, fp);
if (cret == NULL)
break;
ret = _ms_token_data(buf, &so_name);
if (ret == 0) {
/*add to array*/
g_array_append_val(so_array, so_name);
so_name = NULL;
}
}
fclose(fp);
return MS_ERR_NONE;
}
int
ms_load_functions(void)
{
int lib_index = 0, func_index;
char func_list[eFUNC_MAX][40] = {
"check_item",
"connect",
"disconnect",
"check_item_exist",
"insert_item_begin",
"insert_item_end",
"insert_item",
"insert_item_immediately",
"move_item_begin",
"move_item_end",
"move_item",
"set_all_storage_items_validity",
"set_item_validity_begin",
"set_item_validity_end",
"set_item_validity",
"delete_item",
"delete_all_items_in_storage",
"delete_all_invalid_items_in_storage",
"update_begin",
"update_end",
"refresh_item"
};
/*init array for adding name of so*/
so_array = g_array_new(FALSE, FALSE, sizeof(char*));
/*load information of so*/
_ms_load_config();
if(so_array->len == 0) {
MS_DBG("There is no information for functions");
return -1;
}
/*the number of functions*/
lib_num = so_array->len;
MS_DBG("The number of information of so : %d", lib_num);
func_handle = malloc(sizeof(void*) * lib_num);
while(lib_index < lib_num) {
/*get handle*/
MS_DBG("[name of so : %s]", g_array_index(so_array, char*, lib_index));
func_handle[lib_index] = dlopen(g_array_index(so_array, char*, lib_index), RTLD_LAZY);
if (!func_handle[lib_index]) {
MS_DBG_ERR("%s", dlerror());
return -1;
}
lib_index++;
}
dlerror(); /* Clear any existing error */
/*allocate for array of functions*/
func_array = malloc(sizeof(void*) * lib_num);
for(lib_index = 0 ; lib_index < lib_num; lib_index ++) {
func_array[lib_index] = malloc(sizeof(void*) * eFUNC_MAX);
}
/*add functions to array */
for (lib_index = 0; lib_index < lib_num; lib_index++) {
for (func_index = 0; func_index < eFUNC_MAX ; func_index++) {
func_array[lib_index][func_index] = dlsym(func_handle[lib_index], func_list[func_index]);
}
}
return MS_ERR_NONE;
}
void
ms_unload_functions(void)
{
int lib_index;
for (lib_index = 0; lib_index < lib_num; lib_index ++)
dlclose(func_handle[lib_index]);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
if (func_array[lib_index]) {
MS_SAFE_FREE(func_array[lib_index]);
}
}
MS_SAFE_FREE (func_array);
MS_SAFE_FREE (func_handle);
if (so_array) g_array_free(so_array, TRUE);
}
int
ms_connect_db(void ***handle)
{
int lib_index;
int ret;
char * err_msg = NULL;
/*Lock mutex for openning db*/
g_mutex_lock(db_mutex);
*handle = malloc (sizeof (void*) * lib_num);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((CONNECT)func_array[lib_index][eCONNECT])(&((*handle)[lib_index]), &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
g_mutex_unlock(db_mutex);
return MS_ERR_DB_CONNECT_FAIL;
}
}
MS_DBG("connect Media DB");
g_mutex_unlock(db_mutex);
return MS_ERR_NONE;
}
int
ms_disconnect_db(void ***handle)
{
int lib_index;
int ret;
char * err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((DISCONNECT)func_array[lib_index][eDISCONNECT])((*handle)[lib_index], &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
return MS_ERR_DB_DISCONNECT_FAIL;
}
}
MS_SAFE_FREE(*handle);
MS_DBG("Disconnect Media DB");
return MS_ERR_NONE;
}
int
ms_validate_item(void **handle, char *path)
{
int lib_index;
int res = MS_ERR_NONE;
int ret;
char *err_msg = NULL;
char mimetype[255] = {0};
ms_storage_type_t storage_type;
ret = _ms_get_mime(path, mimetype);
if (ret != MS_ERR_NONE) {
MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
return ret;
}
storage_type = ms_get_storage_type_by_full(path);
MS_DBG("[%s] %s", mimetype, path);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
if (!_ms_check_category(path, mimetype, lib_index)) {
/*check exist in Media DB, If file is not exist, insert data in DB. */
ret = ((CHECK_ITEM_EXIST)func_array[lib_index][eEXIST])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG("not exist in %d. insert data", lib_index);
MS_SAFE_FREE(err_msg);
ret = ((INSERT_ITEM)func_array[lib_index][eINSERT_BATCH])(handle[lib_index], path, storage_type, mimetype, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, path);
MS_SAFE_FREE(err_msg);
res = MS_ERR_DB_INSERT_RECORD_FAIL;
}
} else {
/*if meta data of file exist, change valid field to "1" */
ret = ((SET_ITEM_VALIDITY)func_array[lib_index][eSET_VALIDITY])(handle[lib_index], path, true, mimetype, true, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, path);
MS_SAFE_FREE(err_msg);
res = MS_ERR_DB_UPDATE_RECORD_FAIL;
}
}
}
}
if (ms_is_drm_file(path)) {
ret = ms_drm_register(path);
}
return res;
}
int
ms_invalidate_all_items(void **handle, ms_storage_type_t store_type)
{
int lib_index;
int res = MS_ERR_NONE;
int ret;
char *err_msg = NULL;
MS_DBG("");
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((SET_ALL_STORAGE_ITEMS_VALIDITY)func_array[lib_index][eSET_ALL_VALIDITY])(handle[lib_index], store_type, false, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
res = MS_ERR_DB_UPDATE_RECORD_FAIL;
}
}
MS_DBG("");
return res;
}
int
ms_register_file(void **handle, const char *path, GAsyncQueue* queue)
{
MS_DBG("[%d]register file : %s", syscall(__NR_gettid), path);
int res = MS_ERR_NONE;
int ret;
if (path == NULL) {
return MS_ERR_ARG_INVALID;
}
/*check item in DB. If it exist in DB, return directly.*/
ret = ms_check_exist(handle, path);
if (ret == MS_ERR_NONE) {
MS_DBG("Already exist");
return MS_ERR_NONE;
}
g_mutex_lock(queue_mutex);
/*first request for this file*/
if(!_ms_find_reg_list(path)) {
/*insert registering file list*/
_ms_insert_reg_list(path);
} else {
MS_DBG("______________________ALREADY INSERTING");
if(queue != NULL) {
MS_DBG("Need reply");
soc_queue = queue;
}
g_mutex_unlock(queue_mutex);
return MS_ERR_NOW_REGISTER_FILE;
}
g_mutex_unlock(queue_mutex);
ret = ms_insert_item(handle, path);
if (ret != MS_ERR_NONE) {
int lib_index;
char mimetype[255];
ms_storage_type_t storage_type;
ret = _ms_get_mime(path, mimetype);
if (ret != MS_ERR_NONE) {
MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
res = MS_ERR_MIME_GET_FAIL;
goto END;
}
storage_type = ms_get_storage_type_by_full(path);
MS_DBG("[%s] %s", mimetype, path);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
/*check item is already inserted*/
if (!_ms_check_category(path, mimetype, lib_index)) {
char *err_msg = NULL;
ret = ((CHECK_ITEM_EXIST)func_array[lib_index][eEXIST])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
if (ret == 0) {
res = MS_ERR_NONE;
} else {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
res = MS_ERR_DB_INSERT_RECORD_FAIL;
}
}
}
}
END:
if (ms_is_drm_file(path)) {
ret = ms_drm_register(path);
}
g_mutex_lock(queue_mutex);
_ms_delete_reg_list(path);
if (soc_queue != NULL) {
MS_DBG("%d", res);
g_async_queue_push(soc_queue, GINT_TO_POINTER(res+MS_ERR_MAX));
MS_DBG("Return OK");
}
soc_queue = NULL;
g_mutex_unlock(queue_mutex);
return res;
}
int
ms_insert_item_batch(void **handle, const char *path)
{
int lib_index;
int res = MS_ERR_NONE;
int ret;
char mimetype[255] = {0};
char *err_msg = NULL;
ms_storage_type_t storage_type;
ret = _ms_get_mime(path, mimetype);
if (ret != MS_ERR_NONE) {
MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
return ret;
}
storage_type = ms_get_storage_type_by_full(path);
MS_DBG("[%s] %s", mimetype, path);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
if (!_ms_check_category(path, mimetype, lib_index)) {
ret = ((INSERT_ITEM)func_array[lib_index][eINSERT_BATCH])(handle[lib_index], path, storage_type, mimetype, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
res = MS_ERR_DB_INSERT_RECORD_FAIL;
}
}
}
if (ms_is_drm_file(path)) {
ret = ms_drm_register(path);
res = ret;
}
return res;
}
int
ms_insert_item(void **handle, const char *path)
{
int lib_index;
int res = MS_ERR_NONE;
int ret;
char mimetype[255] = {0};
char *err_msg = NULL;
ms_storage_type_t storage_type;
ret = _ms_get_mime(path, mimetype);
if (ret != MS_ERR_NONE) {
MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
return ret;
}
storage_type = ms_get_storage_type_by_full(path);
MS_DBG("[%s] %s", mimetype, path);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
if (!_ms_check_category(path, mimetype, lib_index)) {
ret = ((INSERT_ITEM_IMMEDIATELY)func_array[lib_index][eINSERT])(handle[lib_index], path, storage_type, mimetype, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
res = MS_ERR_DB_INSERT_RECORD_FAIL;
}
}
}
return res;
}
int
ms_delete_item(void **handle, const char *path)
{
int lib_index;
int res = MS_ERR_NONE;
int ret;
char *err_msg = NULL;
ms_storage_type_t storage_type;
storage_type = ms_get_storage_type_by_full(path);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((CHECK_ITEM_EXIST)func_array[lib_index][eEXIST])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
if (ret == 0) {
ret = ((DELETE_ITEM)func_array[lib_index][eDELETE])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
if (ret !=0 ) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
res = MS_ERR_DB_DELETE_RECORD_FAIL;
}
} else {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
res = MS_ERR_DB_DELETE_RECORD_FAIL;
}
}
if (ms_is_drm_file(path)) {
ms_drm_unregister(path);
}
return res;
}
int
ms_move_item(void **handle,
ms_storage_type_t src_store, ms_storage_type_t dst_store,
const char *src_path, const char *dst_path)
{
int lib_index;
int res = MS_ERR_NONE;
int ret;
char mimetype[255];
char *err_msg = NULL;
ret = _ms_get_mime(dst_path, mimetype);
if (ret != MS_ERR_NONE) {
MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
return ret;
}
MS_DBG("[%s] %s", mimetype, dst_path);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
if (!_ms_check_category(dst_path, mimetype, lib_index)) {
ret = ((MOVE_ITEM)func_array[lib_index][eMOVE])(handle[lib_index], src_path, src_store,
dst_path, dst_store, mimetype, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
res = MS_ERR_DB_UPDATE_RECORD_FAIL;
}
}
}
return res;
}
bool
ms_delete_all_items(void **handle, ms_storage_type_t store_type)
{
int lib_index;
int ret = 0;
char *err_msg = NULL;
/* To reset media db when differnet mmc is inserted. */
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((DELETE_ALL_ITEMS_IN_STORAGE)func_array[lib_index][eDELETE_ALL])(handle[lib_index], store_type, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
return false;
}
}
return true;
}
bool
ms_delete_invalid_items(void **handle, ms_storage_type_t store_type)
{
int lib_index;
int ret;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((DELETE_ALL_INVALID_ITMES_IN_STORAGE)func_array[lib_index][eDELETE_INVALID_ITEMS])(handle[lib_index], store_type, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
return false;
}
}
return true;
}
int
ms_refresh_item(void **handle, const char *path)
{
int lib_index;
int res = MS_ERR_NONE;
int ret;
char mimetype[255];
char *err_msg = NULL;
ms_storage_type_t storage_type;
ret = _ms_get_mime(path, mimetype);
if (ret != MS_ERR_NONE) {
MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
return ret;
}
MS_DBG("[%s] %s", mimetype, path);
storage_type = ms_get_storage_type_by_full(path);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
if (!_ms_check_category(path, mimetype, lib_index)) {
ret = ((REFRESH_ITEM)func_array[lib_index][eREFRESH_ITEM])(handle[lib_index], path, storage_type, mimetype, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
res = MS_ERR_DB_UPDATE_RECORD_FAIL;
}
}
}
return res;
}
int
ms_check_exist(void **handle, const char *path)
{
int lib_index;
int ret;
char *err_msg = NULL;
ms_storage_type_t storage_type;
storage_type = ms_get_storage_type_by_full(path);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((CHECK_ITEM_EXIST)func_array[lib_index][eEXIST])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
if (ret != 0) {
return MS_ERR_DB_EXIST_ITEM_FAIL;
}
}
return MS_ERR_NONE;
}
/****************************************************************************************************
FOR BULK COMMIT
*****************************************************************************************************/
void
ms_register_start(void **handle)
{
int lib_index;
int ret = 0;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((INSERT_ITEM_BEGIN)func_array[lib_index][eINSERT_BEGIN])(handle[lib_index], MS_REGISTER_COUNT, &err_msg);/*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
}
}
void
ms_register_end(void **handle)
{
int lib_index;
int ret = 0;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((INSERT_ITEM_END)func_array[lib_index][eINSERT_END])(handle[lib_index], &err_msg);/*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
}
}
void
ms_validate_start(void **handle)
{
int lib_index;
int ret = 0;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((SET_ITEM_VALIDITY_BEGIN)func_array[lib_index][eSET_VALIDITY_BEGIN])(handle[lib_index], MS_VALID_COUNT, &err_msg);/*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
}
}
void
ms_validate_end(void **handle)
{
int lib_index;
int ret = 0;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((SET_ITEM_VALIDITY_END)func_array[lib_index][eSET_VALIDITY_END])(handle[lib_index], &err_msg);/*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
}
}
void
ms_move_start(void **handle)
{
int lib_index;
int ret = 0;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((MOVE_ITEM_BEGIN)func_array[lib_index][eMOVE_BEGIN])(handle[lib_index], MS_MOVE_COUNT, &err_msg);/*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
}
}
void
ms_move_end(void **handle)
{
int lib_index;
int ret = 0;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
ret = ((MOVE_ITEM_END)func_array[lib_index][eMOVE_END])(handle[lib_index], &err_msg);/*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
}
}
|