/
prop_nodefilter.c
1421 lines (1125 loc) · 24.8 KB
/
prop_nodefilter.c
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
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Property trees
* Copyright (C) 2008 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdarg.h>
#include <unistd.h>
#include <math.h>
#include "arch/atomic.h"
#include "showtime.h"
#include "prop_i.h"
#include "prop_nodefilter.h"
#include "misc/pixmap.h"
#include "misc/string.h"
#define MAX_SORT_KEYS 4
TAILQ_HEAD(nfnode_queue, nfnode);
LIST_HEAD(nfn_pred_list, nfn_pred);
LIST_HEAD(prop_nf_pred_list, prop_nf_pred);
/**
*
*/
typedef struct sortmap {
char *str;
int val;
} sortmap_t;
/**
*
*/
typedef struct nfn_pred {
LIST_ENTRY(nfn_pred) nfnp_link;
prop_sub_t *nfnp_sub;
struct prop_nf_pred *nfnp_conf;
struct nfnode *nfnp_nfn;
char nfnp_set;
} nfn_pred_t;
/**
*
*/
typedef struct nfnode {
TAILQ_ENTRY(nfnode) in_link;
TAILQ_ENTRY(nfnode) out_link;
prop_t *in;
prop_t *out;
prop_sub_t *multisub;
struct nfn_pred_list preds;
struct prop_nf *nf;
int16_t pos;
char inserted:1;
char frozen:1;
char sortkey_type[MAX_SORT_KEYS];
#define SORTKEY_NONE 0
#define SORTKEY_RSTR 1
#define SORTKEY_INT 2
#define SORTKEY_FLOAT 3
#define SORTKEY_CSTR 4
prop_sub_t *sortsub[MAX_SORT_KEYS];
union {
rstr_t *rstr;
const char *cstr;
int i;
float f;
} sk[MAX_SORT_KEYS];
} nfnode_t;
/**
*
*/
typedef struct prop_nf_pred {
LIST_ENTRY(prop_nf_pred) pnp_link;
char **pnp_path;
prop_nf_cmp_t pnp_cf;
prop_nf_mode_t pnp_mode;
prop_sub_t *pnp_enable_sub;
int pnp_id;
char pnp_enabled;
char *pnp_str;
int pnp_int;
struct prop_nf *pnp_nf;
} prop_nf_pred_t;
/**
*
*/
typedef struct prop_nf {
int pnf_refcount;
int flags;
int pred_tally;
int nodecount;
prop_t *src;
prop_t *dst;
prop_sub_t *srcsub;
prop_sub_t *dstsub;
prop_sub_t *filtersub;
struct nfnode_queue in;
struct nfnode_queue out;
char *filter;
int pos_valid;
char *sortkey[MAX_SORT_KEYS];
sortmap_t *sortmap[MAX_SORT_KEYS];
struct prop_nf_pred_list preds;
char pending_have_more;
int sortorder[MAX_SORT_KEYS];
int sort_hide_on_missing[MAX_SORT_KEYS];
} prop_nf_t;
/**
*
*/
static void
sortmap_free(sortmap_t *map)
{
sortmap_t *m = map;
if(m == NULL)
return;
for(;m->str != NULL; m++)
free(m->str);
free(map);
}
/**
*
*/
static sortmap_t *
sortmap_create(const prop_nf_sort_strmap_t *src)
{
const prop_nf_sort_strmap_t *s = src;
int cnt = 0;
for(;s->str != NULL; s++)
cnt++;
sortmap_t *m, *map = malloc((1 + cnt) * sizeof(sortmap_t));
for(m = map, s = src; s->str != NULL; s++, m++) {
m->str = strdup(s->str);
m->val = s->val;
}
m->str = NULL;
m->val = s->val;
return map;
}
/**
*
*/
static void
nfnp_destroy(nfn_pred_t *nfnp)
{
LIST_REMOVE(nfnp, nfnp_link);
prop_unsubscribe0(nfnp->nfnp_sub);
free(nfnp);
}
/**
* Evalue all predicates for a node. return 1 if the node should be filtered out
*/
static int
eval_preds(nfnode_t *nfn)
{
nfn_pred_t *nfnp;
prop_nf_pred_t *pnp;
LIST_FOREACH(nfnp, &nfn->preds, nfnp_link) {
if(!nfnp->nfnp_set)
continue;
pnp = nfnp->nfnp_conf;
if(pnp->pnp_mode == PROP_NF_MODE_INCLUDE) {
if(!pnp->pnp_enabled)
return 1;
} else {
if(pnp->pnp_enabled)
return 1;
}
}
return 0;
}
/**
*
*/
static void
nf_renumber(prop_nf_t *nf)
{
int pos;
nfnode_t *nfn;
if(nf->pos_valid)
return;
nf->pos_valid = 1;
pos = 0;
TAILQ_FOREACH(nfn, &nf->in, in_link)
nfn->pos = pos++;
}
/**
*
*/
static int
filterstr(const char *s, const char *q)
{
return !!mystrstr(s, q);
}
/**
*
*/
static int
nf_filtercheck(prop_t *p, const char *q)
{
prop_t *c;
while(p->hp_originator != NULL)
p = p->hp_originator;
switch(p->hp_type) {
case PROP_RSTRING:
return filterstr(rstr_get(p->hp_rstring), q);
case PROP_CSTRING:
return filterstr(p->hp_cstring, q);
case PROP_LINK:
return filterstr(rstr_get(p->hp_link_rtitle), q);
case PROP_DIR:
TAILQ_FOREACH(c, &p->hp_childs, hp_parent_link)
if(nf_filtercheck(c, q))
return 1;
break;
default:
break;
}
return 0;
}
/**
*
*/
static int
nf_egress_cmp(const nfnode_t *a, const nfnode_t *b)
{
int i;
int r;
for(i = 0; i < MAX_SORT_KEYS; i++) {
if(a->nf->sortkey[i] == NULL)
continue;
if(a->sortkey_type[i] != b->sortkey_type[i])
return a->sortkey_type[i] - b->sortkey_type[i];
switch(a->sortkey_type[i]) {
case SORTKEY_RSTR:
r = dictcmp(rstr_get(a->sk[i].rstr), rstr_get(b->sk[i].rstr));
break;
case SORTKEY_CSTR:
r = dictcmp(a->sk[i].cstr, b->sk[i].cstr);
break;
case SORTKEY_INT:
r = a->sk[i].i - b->sk[i].i;
break;
case SORTKEY_FLOAT:
if(a->sk[i].f < b->sk[i].f)
r = -1;
else if(a->sk[i].f > b->sk[i].f)
r = 1;
else
r = 0;
break;
default:
r = 0;
break;
}
if(r)
return r * a->nf->sortorder[i];
}
return a->pos - b->pos;
}
/**
*
*/
static int
nf_sort_cmp(const void *A, const void *B)
{
const nfnode_t *a = *(const nfnode_t **)A;
const nfnode_t *b = *(const nfnode_t **)B;
return nf_egress_cmp(a, b);
}
/**
* Resort the entire list
*/
static void
nf_sort(prop_nf_t *nf)
{
int i = 0;
nfnode_t *nfn, **v = malloc(nf->nodecount * sizeof(nfnode_t *));
TAILQ_FOREACH(nfn, &nf->out, out_link)
v[i++] = nfn;
assert(i == nf->nodecount);
qsort(v, i, sizeof(nfnode_t *), nf_sort_cmp);
TAILQ_INIT(&nf->out);
for(i = 0; i < nf->nodecount; i++)
TAILQ_INSERT_TAIL(&nf->out, v[i], out_link);
free(v);
}
/**
* Insert a node according to the sorting criteria
* Optionally move the output node if it's created
*/
static void
nf_insert_node(prop_nf_t *nf, nfnode_t *nfn)
{
nfnode_t *b;
if(nfn->inserted)
TAILQ_REMOVE(&nf->out, nfn, out_link);
nfn->inserted = 1;
if(nfn->sortkey_type[0] == SORTKEY_NONE &&
nfn->sortkey_type[1] == SORTKEY_NONE &&
nfn->sortkey_type[2] == SORTKEY_NONE &&
nfn->sortkey_type[3] == SORTKEY_NONE) {
b = TAILQ_NEXT(nfn, in_link);
while(b != NULL && b->inserted == 0)
b = TAILQ_NEXT(b, in_link);
if(b != NULL) {
TAILQ_INSERT_BEFORE(b, nfn, out_link);
} else {
TAILQ_INSERT_TAIL(&nf->out, nfn, out_link);
}
} else {
nf_renumber(nf);
TAILQ_INSERT_SORTED(&nf->out, nfn, out_link, nf_egress_cmp);
}
if(nfn->out == NULL)
return;
b = nfn;
do {
b = TAILQ_NEXT(b, out_link);
} while(b != NULL && b->out == NULL);
prop_move0(nfn->out, b ? b->out : NULL, nf->dstsub);
}
/**
* Update node in egress properety tree
*/
static void
nf_update_egress(prop_nf_t *nf, nfnode_t *nfn)
{
nfnode_t *b;
int en = 1;
int i;
// If sorting is enabled but this node don't have a key, hide it
for(i = 0; i < MAX_SORT_KEYS; i++)
if(nf->sortkey[i] != NULL && nfn->sortkey_type[i] == SORTKEY_NONE &&
nf->sort_hide_on_missing[i])
en = 0;
// Check filtering
if(en && nf->filter != NULL && !nf_filtercheck(nfn->in, nf->filter))
en = 0;
if(eval_preds(nfn))
en = 0;
if(en != !nfn->out)
return;
if(en) {
assert(nfn->out == NULL);
nfn->out = prop_make(NULL, 0, NULL);
prop_link0(nfn->in, nfn->out, NULL, 0);
b = nfn;
do {
b = TAILQ_NEXT(b, out_link);
} while(b != NULL && b->out == NULL);
prop_set_parent0(nfn->out, nf->dst, b ? b->out : NULL, nf->dstsub);
} else {
prop_destroy0(nfn->out);
nfn->out = NULL;
}
}
/**
*
*/
static void
nf_multi_filter(void *opaque, prop_event_t event, ...)
{
nfnode_t *nfn = opaque;
prop_nf_t *nf = nfn->nf;
nf_update_egress(nf, nfn);
}
/**
*
*/
static void
nf_update_multisub(prop_nf_t *nf, nfnode_t *nfn)
{
if(!nf->filter == !nfn->multisub)
return;
if(nf->filter) {
nfn->multisub =
prop_subscribe(PROP_SUB_INTERNAL | PROP_SUB_MULTI | PROP_SUB_DONTLOCK,
PROP_TAG_CALLBACK, nf_multi_filter, nfn,
PROP_TAG_ROOT, nfn->in,
NULL);
} else {
prop_unsubscribe0(nfn->multisub);
nfn->multisub = NULL;
}
}
/**
*
*/
static void
nfnp_update_str(void *opaque, const char *str)
{
nfn_pred_t *nfnp = opaque;
prop_nf_pred_t *pnp = nfnp->nfnp_conf;
nfnode_t *nfn = nfnp->nfnp_nfn;
int s = 0;
switch(pnp->pnp_cf) {
case PROP_NF_CMP_EQ:
s = !strcmp(str?:"", pnp->pnp_str);
break;
case PROP_NF_CMP_NEQ:
s = !!strcmp(str?:"", pnp->pnp_str);
break;
}
if(nfnp->nfnp_set == s)
return;
nfnp->nfnp_set = s;
nf_update_egress(nfn->nf, nfn);
}
/**
*
*/
static void
nfnp_update_int(void *opaque, int val)
{
nfn_pred_t *nfnp = opaque;
prop_nf_pred_t *pnp = nfnp->nfnp_conf;
nfnode_t *nfn = nfnp->nfnp_nfn;
int s = 0;
switch(pnp->pnp_cf) {
case PROP_NF_CMP_EQ:
s = val == pnp->pnp_int;
break;
case PROP_NF_CMP_NEQ:
s = val != pnp->pnp_int;
break;
}
if(nfnp->nfnp_set == s)
return;
nfnp->nfnp_set = s;
nf_update_egress(nfn->nf, nfn);
}
/**
*
*/
static void
nfn_insert_pred(prop_nf_t *nf, nfnode_t *nfn, prop_nf_pred_t *pnp)
{
nfn_pred_t *nfnp = calloc(1, sizeof(nfn_pred_t));
nfnp->nfnp_conf = pnp;
nfnp->nfnp_nfn = nfn;
LIST_INSERT_HEAD(&nfn->preds, nfnp, nfnp_link);
if(pnp->pnp_str != NULL) {
nfnp->nfnp_sub =
prop_subscribe(PROP_SUB_INTERNAL | PROP_SUB_DONTLOCK,
PROP_TAG_CALLBACK_STRING, nfnp_update_str, nfnp,
PROP_TAG_NAMED_ROOT, nfn->in, "node",
PROP_TAG_NAME_VECTOR, pnp->pnp_path,
NULL);
} else {
nfnp->nfnp_sub =
prop_subscribe(PROP_SUB_INTERNAL | PROP_SUB_DONTLOCK,
PROP_TAG_CALLBACK_INT, nfnp_update_int, nfnp,
PROP_TAG_NAMED_ROOT, nfn->in, "node",
PROP_TAG_NAME_VECTOR, pnp->pnp_path,
NULL);
}
}
/**
*
*/
static void
nfn_insert_preds(prop_nf_t *nf, nfnode_t *nfn)
{
prop_nf_pred_t *pnp;
LIST_FOREACH(pnp, &nf->preds, pnp_link)
nfn_insert_pred(nf, nfn, pnp);
}
static void
nf_set_sortkey_x(int x, nfnode_t *nfn, prop_event_t event, va_list ap)
{
rstr_t *r;
if(nfn->sortkey_type[x] == SORTKEY_RSTR)
rstr_release(nfn->sk[x].rstr);
switch(event) {
case PROP_SET_RSTRING:
case PROP_SET_RLINK:
r = va_arg(ap, rstr_t *);
const sortmap_t *map = nfn->nf->sortmap[x];
if(map != NULL) {
for(; map->str != NULL; map++) {
if(!strcmp(map->str, rstr_get(r)))
break;
}
nfn->sk[x].i = map->val;
nfn->sortkey_type[x] = SORTKEY_INT;
} else {
nfn->sk[x].rstr = rstr_dup(r);
nfn->sortkey_type[x] = SORTKEY_RSTR;
}
break;
case PROP_SET_INT:
nfn->sk[x].i = va_arg(ap, int);
nfn->sortkey_type[x] = SORTKEY_INT;
break;
case PROP_SET_FLOAT:
nfn->sk[x].f = va_arg(ap, double);
nfn->sortkey_type[x] = SORTKEY_FLOAT;
break;
default:
nfn->sortkey_type[x] = SORTKEY_NONE;
break;
}
if(nfn->frozen) {
return;
}
nf_insert_node(nfn->nf, nfn);
nf_update_egress(nfn->nf, nfn);
}
/**
*
*/
static void
nf_set_sortkey_0(void *opaque, prop_event_t event, ...)
{
va_list ap;
va_start(ap, event);
nf_set_sortkey_x(0, opaque, event, ap);
va_end(ap);
}
/**
*
*/
static void
nf_set_sortkey_1(void *opaque, prop_event_t event, ...)
{
va_list ap;
va_start(ap, event);
nf_set_sortkey_x(1, opaque, event, ap);
va_end(ap);
}
/**
*
*/
static void
nf_set_sortkey_2(void *opaque, prop_event_t event, ...)
{
va_list ap;
va_start(ap, event);
nf_set_sortkey_x(2, opaque, event, ap);
va_end(ap);
}
/**
*
*/
static void
nf_set_sortkey_3(void *opaque, prop_event_t event, ...)
{
va_list ap;
va_start(ap, event);
nf_set_sortkey_x(3, opaque, event, ap);
va_end(ap);
}
/**
*
*/
static void
nf_update_order_x(prop_nf_t *nf, nfnode_t *nfn, int x)
{
if(nfn->sortsub[x]) {
prop_unsubscribe0(nfn->sortsub[x]);
nfn->sortsub[x] = NULL;
}
if(nf->sortkey[x] == NULL) {
if(nfn->sortkey_type[x] == SORTKEY_RSTR)
rstr_release(nfn->sk[x].rstr);
nfn->sortkey_type[x] = SORTKEY_NONE;
nf_insert_node(nf, nfn);
} else {
nfn->sortsub[x] =
prop_subscribe(PROP_SUB_INTERNAL | PROP_SUB_DONTLOCK |
PROP_SUB_DIRECT_UPDATE,
PROP_TAG_CALLBACK,
x == 0 ? nf_set_sortkey_0 :
x == 1 ? nf_set_sortkey_1 :
x == 2 ? nf_set_sortkey_2 :
nf_set_sortkey_3, nfn,
PROP_TAG_NAMED_ROOT, nfn->in, "node",
PROP_TAG_NAMESTR, nf->sortkey[x],
NULL);
}
}
static void
nf_update_order_all(prop_nf_t *nf, nfnode_t *nfn)
{
int i;
for(i = 0; i < MAX_SORT_KEYS; i++)
nf_update_order_x(nf, nfn, i);
}
/**
*
*/
static void
nf_add_node(prop_nf_t *nf, prop_t *node, nfnode_t *b)
{
nfnode_t *nfn = calloc(1, sizeof(nfnode_t));
prop_tag_set(node, nf, nfn);
nf->nodecount++;
if(b != NULL) {
TAILQ_INSERT_BEFORE(b, nfn, in_link);
nf->pos_valid = 0;
} else {
if(nf->pos_valid) {
nfnode_t *l = TAILQ_LAST(&nf->in, nfnode_queue);
nfn->pos = l ? l->pos + 1 : 0;
}
TAILQ_INSERT_TAIL(&nf->in, nfn, in_link);
}
nfn->nf = nf;
nfn->in = node;
nf_update_multisub(nf, nfn);
nfn_insert_preds(nf, nfn);
nf_update_order_all(nf, nfn);
nf_update_egress(nf, nfn);
}
/**
*
*/
static void
nf_add_nodes(prop_nf_t *nf, prop_vec_t *pv, nfnode_t *b)
{
int i;
nfnode_t *nfn;
if(b != NULL)
nf->pos_valid = 0;
const int len = prop_vec_len(pv);
nf->nodecount += len;
for(i = 0; i < len; i++) {
prop_t *p = prop_vec_get(pv, i);
nfn = calloc(1, sizeof(nfnode_t));
prop_tag_set(p, nf, nfn);
if(nf->pos_valid) {
nfnode_t *l = TAILQ_LAST(&nf->in, nfnode_queue);
nfn->pos = l ? l->pos + 1 : 0;
}
if(b != NULL) {
TAILQ_INSERT_BEFORE(b, nfn, in_link);
} else {
TAILQ_INSERT_TAIL(&nf->in, nfn, in_link);
}
nfn->nf = nf;
nfn->in = p;
nfn->frozen = 1;
nf_update_multisub(nf, nfn);
nfn_insert_preds(nf, nfn);
nf_update_order_all(nf, nfn);
}
nf_sort(nf);
TAILQ_FOREACH(nfn, &nf->out, out_link) {
nfn->frozen = 0;
nf_update_egress(nf, nfn);
}
}
/**
*
*/
static void
nf_del_node(prop_nf_t *nf, nfnode_t *nfn)
{
int i;
nfn_pred_t *nfnp;
nf->pos_valid = 0;
nf->nodecount--;
TAILQ_REMOVE(&nf->in, nfn, in_link);
TAILQ_REMOVE(&nf->out, nfn, out_link);
if(nfn->out != NULL)
prop_destroy0(nfn->out);
if(nfn->multisub != NULL)
prop_unsubscribe0(nfn->multisub);
for(i = 0; i < MAX_SORT_KEYS; i++) {
if(nfn->sortsub[i] != NULL)
prop_unsubscribe0(nfn->sortsub[i]);
}
while((nfnp = LIST_FIRST(&nfn->preds)) != NULL)
nfnp_destroy(nfnp);
for(i = 0; i < MAX_SORT_KEYS; i++)
if(nfn->sortkey_type[i] == SORTKEY_RSTR)
rstr_release(nfn->sk[i].rstr);
free(nfn);
}
/**
*
*/
static void
nf_move_node(prop_nf_t *nf, nfnode_t *nfn, nfnode_t *b)
{
nf->pos_valid = 0;
TAILQ_REMOVE(&nf->in, nfn, in_link);
if(b != NULL) {
TAILQ_INSERT_BEFORE(b, nfn, in_link);
} else {
TAILQ_INSERT_TAIL(&nf->in, nfn, in_link);
}
nf_insert_node(nf, nfn);
}
/**
*
*/
static nfnode_t *
nf_find_node(prop_nf_t *nf, prop_t *node)
{
if(node == NULL)
return NULL;
nfnode_t *nfn = prop_tag_get(node, nf);
assert(nfn != NULL);
return nfn;
}
/**
*
*/
static void
nf_destroy_pred(struct prop_nf_pred *pnp)
{
LIST_REMOVE(pnp, pnp_link);
strvec_free(pnp->pnp_path);
if(pnp->pnp_enable_sub != NULL)
prop_unsubscribe0(pnp->pnp_enable_sub);
free(pnp->pnp_str);
free(pnp);
}
/**
*
*/
static void
nf_destroy_preds(prop_nf_t *nf)
{
struct prop_nf_pred *pnp;
while((pnp = LIST_FIRST(&nf->preds)) != NULL)
nf_destroy_pred(pnp);
}
/**
*
*/
static void
nf_clear(prop_nf_t *nf)
{
nfnode_t *nfn;
while((nfn = TAILQ_FIRST(&nf->in)) != NULL) {
prop_tag_clear(nfn->in, nf);
nf_del_node(nf, nfn);
}
nf->pos_valid = 1;
}
/**
*
*/
static void
prop_nf_release0(struct prop_nf *pnf)
{
int i;
pnf->pnf_refcount--;
if(pnf->pnf_refcount > 0)
return;
if(pnf->srcsub != NULL)
prop_unsubscribe0(pnf->srcsub);
if(!(pnf->flags & PROP_NF_AUTODESTROY))
nf_clear(pnf);
prop_unsubscribe0(pnf->dstsub);
prop_destroy0(pnf->dst);
assert(TAILQ_FIRST(&pnf->in) == NULL);
assert(TAILQ_FIRST(&pnf->out) == NULL);
if(pnf->filtersub != NULL)
prop_unsubscribe0(pnf->filtersub);
for(i = 0; i < MAX_SORT_KEYS; i++) {
free(pnf->sortkey[i]);
sortmap_free(pnf->sortmap[i]);
}
free(pnf->filter);
nf_destroy_preds(pnf);
assert(TAILQ_FIRST(&pnf->in) == NULL);
assert(TAILQ_FIRST(&pnf->out)== NULL);
free(pnf);
}
/**
*
*/
static void
prop_nf_src_cb(void *opaque, prop_event_t event, ...)