Repository navigation
Expand file tree
/
Copy pathfilter_call.h
More file actions
1220 lines (1155 loc) · 31.6 KB
/
Copy pathfilter_call.h
File metadata and controls
1220 lines (1155 loc) · 31.6 KB
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
#ifndef FILTER_CALL_H
#define FILTER_CALL_H
#include <math.h>
#include "filter_record.h"
#include "calltable.h"
#include "country_detect.h"
inline Call *recCall(void *rec) {
return(((sChartsCallData*)rec)->call());
}
inline cDbTablesContent *recTablesContent(void *rec) {
return(((sChartsCallData*)rec)->tables_content());
}
inline bool recIsCall(void *rec) {
return(((sChartsCallData*)rec)->type == sChartsCallData::_call);
}
struct sTableColumns {
sTableColumns(unsigned table_enum, const char **names, unsigned names_count,
cDbTableContent::sColumnValues **col, bool *col_resolved) {
this->table_enum = table_enum;
this->names = names;
this->names_count = names_count;
this->col = col;
this->col_resolved = col_resolved;
tc = NULL;
rows = 0;
}
sTableColumns(const sTableColumns&) = delete;
sTableColumns& operator = (const sTableColumns&) = delete;
void init(cDbTablesContent *tc) {
this->tc = tc;
int countRows = tc->getCountRows(table_enum);
rows = countRows > 0 ? countRows : 0;
memset(col, 0, sizeof(col[0]) * names_count);
memset(col_resolved, 0, sizeof(col_resolved[0]) * names_count);
}
cDbTableContent::sColumnValues *column(unsigned index, cDbTableContent::eColumnValues type) {
if(!col_resolved[index]) {
col[index] = tc->getColumnValues(table_enum, names[index], type);
col_resolved[index] = true;
}
return(col[index]);
}
long long value_int(unsigned index, unsigned row, bool *null = NULL) {
cDbTableContent::sColumnValues *values = column(index, cDbTableContent::_cv_int);
if(null) {
*null = !values || values->isNull(row);
}
return(values ? values->value_int(row) : 0);
}
vmIP value_ip(unsigned index, unsigned row) {
cDbTableContent::sColumnValues *values = column(index, cDbTableContent::_cv_ip);
return(values ? values->value_ip(row) : 0);
}
unsigned table_enum;
const char **names;
unsigned names_count;
cDbTablesContent *tc;
unsigned rows;
cDbTableContent::sColumnValues **col;
bool *col_resolved;
};
struct sRtpStreamColumns : public sTableColumns {
enum eColumn {
_c_saddr,
_c_sport,
_c_daddr,
_c_dport,
_c_received,
_c_rtp_ptime,
_c_sdp_ptime,
_c_flags,
_c_last
};
sRtpStreamColumns()
: sTableColumns(_t_cdr_rtp, columnNames(), _c_last, col_buffer, col_resolved_buffer) {
}
static const char **columnNames() {
static const char *names[_c_last] = { "saddr", "sport", "daddr", "dport", "received", "rtp_ptime", "sdp_ptime", "flags" };
return(names);
}
cDbTableContent::sColumnValues *col_buffer[_c_last];
bool col_resolved_buffer[_c_last];
};
struct sSdpRowColumns : public sTableColumns {
enum eColumn {
_c_ip,
_c_port,
_c_is_caller,
_c_ptime,
_c_leg_index,
_c_last
};
sSdpRowColumns()
: sTableColumns(_t_cdr_sdp, columnNames(), _c_last, col_buffer, col_resolved_buffer) {
}
static const char **columnNames() {
static const char *names[_c_last] = { "ip", "port", "is_caller", "ptime", "leg_index" };
return(names);
}
cDbTableContent::sColumnValues *col_buffer[_c_last];
bool col_resolved_buffer[_c_last];
};
class cRecordFilterItem_CallProxy : public cRecordFilterItem_IP {
public:
cRecordFilterItem_CallProxy(cRecordFilter *parent)
: cRecordFilterItem_IP(parent, 0) {
}
bool check(void *rec, bool *findInBlackList = NULL) {
if(findInBlackList) {
*findInBlackList = false;
}
set<vmIP> proxies;
getProxies(rec, &proxies);
for(set<vmIP>::iterator iter = proxies.begin(); iter != proxies.end(); iter++) {
if(check_ip(*iter)) {
return(true);
}
}
return(false);
}
void checkWhiteBlack(void *rec, bool *white, bool *black) {
*white = false;
*black = false;
set<vmIP> proxies;
getProxies(rec, &proxies);
for(set<vmIP>::iterator iter = proxies.begin(); iter != proxies.end(); iter++) {
bool proxy_white;
bool proxy_black;
checkWhiteBlack_ip(*iter, &proxy_white, &proxy_black);
if(proxy_white) {
*white = true;
}
if(proxy_black) {
*black = true;
}
}
}
private:
void getProxies(void *rec, set<vmIP> *proxies) {
if(!recIsCall(rec)) {
cDbTablesContent *tc = recTablesContent(rec);
int count = tc->getCountRows(_t_cdr_proxy);
for(int i = 0; i < count; i++) {
proxies->insert(tc->getValue_ip(_t_cdr_proxy, "dst", NULL, i));
}
return;
}
Call *call = recCall(rec);
if(call->saved_data) {
*proxies = call->saved_data->proxies;
} else {
call->getProxies(call->branch_main(), proxies);
}
}
};
class cRecordFilterItem_Fixed : public cRecordFilterItem_base {
public:
cRecordFilterItem_Fixed(cRecordFilter *parent, bool rslt)
: cRecordFilterItem_base(parent, 0) {
this->rslt = rslt;
}
bool check(void */*rec*/, bool *findInBlackList = NULL) {
if(findInBlackList) {
*findInBlackList = false;
}
return(rslt);
}
private:
bool rslt;
};
class cRecordFilterItem_CheckStringOr : public cRecordFilterItem_base {
public:
struct sItem {
sItem() {
_not = false;
}
ListCheckString pattern;
bool _not;
};
public:
cRecordFilterItem_CheckStringOr(cRecordFilter *parent, unsigned recordFieldIndex, const char *filter, const char *separators, const char *separatorsSeparator, bool enableNull = false);
void setEmptyAsNull() {
emptyAsNull = true;
}
bool check(void *rec, bool *findInBlackList = NULL);
void setNoLock() {
for(unsigned i = 0; i < items.size(); i++) {
items[i].pattern.setNoLock();
}
}
protected:
bool checkValue(const char *value);
protected:
vector<sItem> items;
bool null;
bool emptyAsNull;
};
class cRecordFilterItem_CustomHeader : public cRecordFilterItem_CheckStringOr {
public:
cRecordFilterItem_CustomHeader(cRecordFilter *parent, const char *customHeader, const char *filter, const char *separators, const char *separatorsSeparator, bool enableNull = false)
: cRecordFilterItem_CheckStringOr(parent, 0, filter, separators, separatorsSeparator, enableNull) {
this->customHeader = customHeader;
}
bool check(void *rec, bool *findInBlackList = NULL);
private:
string customHeader;
};
class cRecordFilterItem_CustomHeaderNum : public cRecordFilterItem_rec {
public:
cRecordFilterItem_CustomHeaderNum(cRecordFilter *parent, const char *customHeader, cRecordFilterItem_base::eCmpCond cond, double value)
: cRecordFilterItem_rec(parent) {
this->customHeader = customHeader;
this->cond = cond;
this->value = value;
}
bool check(void *rec, bool *findInBlackList = NULL);
private:
string customHeader;
cRecordFilterItem_base::eCmpCond cond;
double value;
};
class cRecordFilterItem_SipResponseNum : public cRecordFilterItem_base {
public:
struct sRange {
int from;
int to;
};
public:
cRecordFilterItem_SipResponseNum(cRecordFilter *parent, unsigned recordFieldIndex, const char *filter);
bool check(void *rec, bool *findInBlackList = NULL);
static bool isNumFilter(const char *filter);
private:
static string trimNumSuffix(string item);
static sRange parseRange(string item);
static bool inRanges(vector<sRange> *ranges, int num);
private:
vector<sRange> ranges;
vector<sRange> ranges_not;
};
class cRecordFilterItem_SipResponse : public cRecordFilterItem_rec {
public:
struct sItem {
sItem() {
num = NULL;
_not = false;
}
cRecordFilterItem_SipResponseNum *num;
ListCheckString pattern;
bool _not;
};
public:
cRecordFilterItem_SipResponse(cRecordFilter *parent, const char *filter);
~cRecordFilterItem_SipResponse();
bool check(void *rec, bool *findInBlackList = NULL);
void setNoLock() {
for(unsigned i = 0; i < items.size(); i++) {
items[i].pattern.setNoLock();
}
}
private:
cRecordFilterItem_SipResponse(const cRecordFilterItem_SipResponse &other);
cRecordFilterItem_SipResponse &operator = (const cRecordFilterItem_SipResponse &other);
private:
vector<sItem> items;
bool positive_never;
};
class cRecordFilterItem_SipResponseAll : public cRecordFilterItem_rec {
public:
struct sItem {
sItem() {
num = -1;
}
int num;
ListCheckString pattern;
};
struct sResponse {
sResponse() {
num = 0;
}
int num;
string response;
};
public:
cRecordFilterItem_SipResponseAll(cRecordFilter *parent, const char *filter);
bool check(void *rec, bool *findInBlackList = NULL);
void setNoLock() {
for(unsigned i = 0; i < items.size(); i++) {
items[i].pattern.setNoLock();
}
for(unsigned i = 0; i < items_not.size(); i++) {
items_not[i].pattern.setNoLock();
}
}
private:
static void getResponses(void *rec, vector<sResponse> *responses);
static bool checkItem(vector<sResponse> *responses, sItem *item);
private:
vector<sItem> items;
vector<sItem> items_not;
};
class cRecordFilterItem_SipRequestHist : public cRecordFilterItem_rec {
public:
struct sItem {
sItem() {
count = 0;
_not = false;
}
ListCheckString pattern;
unsigned count;
bool _not;
};
public:
cRecordFilterItem_SipRequestHist(cRecordFilter *parent, const char *filter);
bool check(void *rec, bool *findInBlackList = NULL);
void setNoLock() {
for(unsigned i = 0; i < items.size(); i++) {
items[i].pattern.setNoLock();
}
}
private:
vector<sItem> items;
};
class cRecordFilterItem_Reason : public cRecordFilterItem_rec {
public:
enum eTypeReason {
_sip,
_q850
};
struct sItem {
sItem() {
null = false;
num = -1;
_not = false;
}
bool null;
int num;
bool _not;
ListCheckString pattern;
};
public:
cRecordFilterItem_Reason(cRecordFilter *parent, eTypeReason typeReason, const char *filter);
bool check(void *rec, bool *findInBlackList = NULL);
void setNoLock() {
for(unsigned i = 0; i < items.size(); i++) {
items[i].pattern.setNoLock();
}
}
private:
eTypeReason typeReason;
vector<sItem> items;
bool positive_never;
};
class cRecordFilterItem_CdrField : public cRecordFilterItem_rec {
public:
enum eCond {
_ge,
_gt,
_lt,
_eq,
_mos
};
public:
cRecordFilterItem_CdrField(cRecordFilter *parent, const char *columns, double divisor, eCond cond, double value);
bool check(void *rec, bool *findInBlackList = NULL);
private:
vector<string> columns;
vector<unsigned> slots;
double divisor;
eCond cond;
double value;
};
class cRecordFilterItem_CdrFieldsSum : public cRecordFilterItem_rec {
public:
struct sColumn {
string column;
double multiplier;
unsigned slot;
};
public:
cRecordFilterItem_CdrFieldsSum(cRecordFilter *parent, double value)
: cRecordFilterItem_rec(parent) {
this->value = value;
}
void addColumn(string column, double multiplier);
bool check(void *rec, bool *findInBlackList = NULL);
private:
vector<sColumn> columns;
double value;
};
class cCallFilter;
class cRecordFilterItem_CallSubFilter : public cRecordFilterItem_rec {
public:
cRecordFilterItem_CallSubFilter(cRecordFilter *parent, cCallFilter *subFilter, bool negative)
: cRecordFilterItem_rec(parent) {
this->subFilter = subFilter;
this->negative = negative;
}
~cRecordFilterItem_CallSubFilter();
bool check(void *rec, bool *findInBlackList = NULL);
private:
cCallFilter *subFilter;
bool negative;
};
class cRecordFilterItem_CallStream : public cRecordFilterItem_rec {
public:
enum eField {
_sf_count,
_sf_received,
_sf_rtp_ptime,
_sf_diff_rtp_sdp_ptime,
_sf_sdp_row_ptime,
_sf_in_multiple_calls
};
enum eSide {
_any,
_caller,
_called
};
public:
cRecordFilterItem_CallStream(cRecordFilter *parent, eField field, eSide side = _any)
: cRecordFilterItem_rec(parent) {
this->field = field;
this->side = side;
this->ge_set = false;
this->lt_set = false;
this->le_set = false;
this->ge = 0;
this->lt = 0;
this->le = 0;
}
void setGe(double ge) {
this->ge = ge;
this->ge_set = true;
}
void setLt(double lt) {
this->lt = lt;
this->lt_set = true;
}
void setLe(double le) {
this->le = le;
this->le_set = true;
}
bool isSet() {
return(ge_set || lt_set || le_set);
}
bool check(void *rec, bool *findInBlackList = NULL);
static unsigned rtpStreamsSize(void *rec, sRtpStreamColumns *columns);
static bool rtpStream(void *rec, sRtpStreamColumns *columns, unsigned index, Call::sSavedData::sRtpStream *stream);
static unsigned sdpRowsSize(void *rec, sSdpRowColumns *columns);
static bool sdpRow(void *rec, sSdpRowColumns *columns, unsigned index, s_sdp_store_data *sdp_row);
static bool matchSide(eSide side, bool is_caller, bool caller_flag_value) {
return(side == _any ||
(side == _caller ? is_caller == caller_flag_value : is_caller != caller_flag_value));
}
private:
bool cmpValue(double streamValue) {
return((!ge_set || streamValue >= ge) &&
(!lt_set || streamValue < lt) &&
(!le_set || streamValue <= le));
}
bool getStreamValue(void *rec, sRtpStreamColumns *columns, unsigned index, double *streamValue);
bool getSdpRowValue(void *rec, sSdpRowColumns *columns, unsigned index, double *streamValue);
private:
eField field;
eSide side;
bool ge_set;
bool lt_set;
bool le_set;
double ge;
double lt;
double le;
};
class cRecordFilterItem_CallStreamIpPort : public cRecordFilterItem_rec {
public:
enum eTarget {
_t_rtp_src,
_t_rtp_dst,
_t_sdp
};
public:
cRecordFilterItem_CallStreamIpPort(cRecordFilter *parent, eTarget target,
cRecordFilterItem_CallStream::eSide side = cRecordFilterItem_CallStream::_any,
bool negative = false)
: cRecordFilterItem_rec(parent) {
this->target = target;
this->side = side;
this->negative = negative;
}
void addEntries(const char *value, bool negative_entries);
void addPortRange(unsigned port_min, unsigned port_max) {
sEntry entry;
entry.ip_set = false;
entry.port_set = true;
entry.port_min = port_min;
entry.port_max = port_max;
entries.push_back(entry);
}
bool isSet() {
return(entries.size() > 0);
}
bool check(void *rec, bool *findInBlackList = NULL);
private:
struct sEntry {
bool ip_set;
vmIP ip_min;
vmIP ip_max;
bool port_set;
unsigned port_min;
unsigned port_max;
};
bool parseEntry(const char *value, sEntry *entry, bool *entry_negative);
bool matchEntries(vmIPport *ip_port);
private:
eTarget target;
cRecordFilterItem_CallStream::eSide side;
bool negative;
vector<sEntry> entries;
};
class cRecordFilterItem_Dscp : public cRecordFilterItem_base {
public:
cRecordFilterItem_Dscp(cRecordFilter *parent, unsigned recordFieldIndex)
: cRecordFilterItem_base(parent, recordFieldIndex) {
eq = -1;
ge = -1;
lt = -1;
}
bool check(void *rec, bool *findInBlackList = NULL);
public:
int eq;
int ge;
int lt;
};
class cRecordFilterItem_Dtmf : public cRecordFilterItem_rec {
public:
struct sItem {
sItem() {
_not = false;
}
ListCheckString pattern;
bool _not;
};
struct sStream {
sStream(vmIP saddr, vmIP daddr) {
this->saddr = saddr;
this->daddr = daddr;
}
bool operator < (const sStream &other) const {
return(saddr < other.saddr ? true : saddr > other.saddr ? false : daddr < other.daddr);
}
vmIP saddr;
vmIP daddr;
};
public:
cRecordFilterItem_Dtmf(cRecordFilter *parent, const char *filter);
bool check(void *rec, bool *findInBlackList = NULL);
void setNoLock() {
for(unsigned i = 0; i < items.size(); i++) {
items[i].pattern.setNoLock();
}
}
private:
string chars;
vector<sItem> items;
};
class cRecordFilterItem_DtmfCount : public cRecordFilterItem_rec {
public:
cRecordFilterItem_DtmfCount(cRecordFilter *parent, unsigned count_ge, unsigned count_lt)
: cRecordFilterItem_rec(parent) {
this->count_ge = count_ge;
this->count_lt = count_lt;
}
bool check(void *rec, bool *findInBlackList = NULL);
private:
unsigned count_ge;
unsigned count_lt;
};
class cRecordFilterItem_CountryCode : public cRecordFilterItem_base {
public:
cRecordFilterItem_CountryCode(cRecordFilter *parent, unsigned recordFieldIndex, const char *filter);
bool check(void *rec, bool *findInBlackList = NULL);
private:
set<string> codes;
bool all;
};
class cRecordFilterItem_Trunk : public cRecordFilterItem_rec {
public:
cRecordFilterItem_Trunk(cRecordFilter *parent, int trunk, vector<string> *ips);
~cRecordFilterItem_Trunk();
bool check(void *rec, bool *findInBlackList = NULL);
void setNoLock() {
for(unsigned i = 0; i < groups.size(); i++) {
groups[i]->setNoLock();
}
}
private:
cRecordFilterItem_Trunk(const cRecordFilterItem_Trunk &other);
cRecordFilterItem_Trunk &operator = (const cRecordFilterItem_Trunk &other);
private:
int trunk;
vector<ListIP_wb*> groups;
};
class cRecordFilterItem_AB : public cRecordFilterItem_rec {
public:
enum eComb {
_comb_values,
_comb_sides_or,
_comb_sides_and
};
public:
cRecordFilterItem_AB(cRecordFilter *parent, eComb comb)
: cRecordFilterItem_rec(parent) {
this->comb = comb;
for(int i = 0; i < 2; i++) {
items[i] = NULL;
proxies[i] = NULL;
}
}
~cRecordFilterItem_AB() {
for(int i = 0; i < 2; i++) {
if(items[i]) {
delete items[i];
}
if(proxies[i]) {
delete proxies[i];
}
}
}
bool check(void *rec, bool *findInBlackList = NULL);
void setNoLock() {
for(int i = 0; i < 2; i++) {
if(items[i]) {
items[i]->setNoLock();
}
if(proxies[i]) {
proxies[i]->setNoLock();
}
}
}
public:
eComb comb;
cRecordFilterItem_base *items[2];
cRecordFilterItem_base *proxies[2];
};
class cRecordFilterItem_Call : public cRecordFilterItem_rec {
public:
enum eTypeFilter {
_tf_codec,
_tf_codec_exclude,
_tf_codec_ab_eq,
_tf_codec_ab_diff,
_tf_custom_headers_cond,
_tf_flags,
_tf_bye,
_tf_who_hangup,
_tf_one_way,
_tf_missing_rtp,
_tf_flags_eq,
_tf_rtp_state,
_tf_country_compare_numbers,
_tf_country_compare_ips,
_tf_ccs_license
};
struct sCodecData {
int payload_ab[2];
int mos_f2_ab[2];
int payload;
bool payload_null;
bool rtp_rows_match;
};
enum eRtpState {
_rs_na,
_rs_missing,
_rs_exists,
_rs_zero_one,
_rs_one_way,
_rs_two_way
};
public:
cRecordFilterItem_Call(cRecordFilter *parent, eTypeFilter typeFilter, const char *filter);
cRecordFilterItem_Call(cRecordFilter *parent, eTypeFilter typeFilter, u_int64_t filter_num, u_int64_t filter_num2 = 0);
void setCodecAllStreams(bool codec_all_streams) {
this->codec_all_streams = codec_all_streams;
}
bool check(void *rec, bool *findInBlackList = NULL);
private:
bool codecMatch(int codec) {
return(codec >= 0 && filter_int.find(codec) != filter_int.end());
}
void getSaddrExists(void *rec, bool *a_saddr, bool *b_saddr);
void getCodecData(void *rec, sCodecData *codecData);
int rtpMosF2Mult10(RTP *rtp);
int sqlAnd(int cond1, int cond2) {
return(cond1 == 0 || cond2 == 0 ? 0 :
cond1 < 0 || cond2 < 0 ? -1 : 1);
}
int sqlOr(int cond1, int cond2) {
return(cond1 > 0 || cond2 > 0 ? 1 :
cond1 < 0 || cond2 < 0 ? -1 : 0);
}
private:
eTypeFilter typeFilter;
string filter;
set<int> filter_int;
u_int64_t filter_num;
u_int64_t filter_num2;
bool codec_all_streams;
eRtpState rtp_state;
};
class cCallFilter : public cRecordFilter {
public:
enum eAbItemType {
_ab_ip,
_ab_phone_number,
_ab_check_string,
_ab_country_code,
_ab_num_list,
_ab_cdr_mos,
_ab_cdr_ge
};
struct sAbDef {
sAbDef(eAbItemType itemType, unsigned field1, unsigned field2) {
this->itemType = itemType;
this->field1 = field1;
this->field2 = field2;
column1 = NULL;
column2 = NULL;
codebook_table = NULL;
codebook_column = NULL;
phoneNumberType = PhoneNumber::_tn_norm;
splitSeparators = NULL;
splitSeparatorsSeparator = NULL;
proxyName = NULL;
sideCombination = false;
revertNegation = false;
zeroIsValue = false;
enableNull = false;
emptyAsNull = false;
divisor = 1;
value_mult = 1;
value_offset = 0;
}
sAbDef(eAbItemType itemType, const char *column1, const char *column2) {
this->itemType = itemType;
field1 = 0;
field2 = 0;
this->column1 = column1;
this->column2 = column2;
codebook_table = NULL;
codebook_column = NULL;
phoneNumberType = PhoneNumber::_tn_norm;
splitSeparators = NULL;
splitSeparatorsSeparator = NULL;
proxyName = NULL;
sideCombination = false;
revertNegation = false;
zeroIsValue = false;
enableNull = false;
emptyAsNull = false;
divisor = 1;
value_mult = 1;
value_offset = 0;
}
sAbDef &codebook(const char *table, const char *column) {
codebook_table = table;
codebook_column = column;
return(*this);
}
sAbDef &phoneType(PhoneNumber::eTypeNumber type) {
phoneNumberType = type;
return(*this);
}
sAbDef &splitBy(const char *separators, const char *separatorsSeparator) {
splitSeparators = separators;
splitSeparatorsSeparator = separatorsSeparator;
return(*this);
}
sAbDef &proxy(const char *name) {
proxyName = name;
return(*this);
}
sAbDef &sideComb() {
sideCombination = true;
return(*this);
}
sAbDef &revertNeg() {
revertNegation = true;
return(*this);
}
sAbDef &zeroValue() {
zeroIsValue = true;
return(*this);
}
sAbDef &nullValue() {
enableNull = true;
return(*this);
}
sAbDef &emptyNull() {
emptyAsNull = true;
return(*this);
}
sAbDef &cdrValue(double divisor, double value_mult = 1, double value_offset = 0) {
this->divisor = divisor;
this->value_mult = value_mult;
this->value_offset = value_offset;
return(*this);
}
eAbItemType itemType;
unsigned field1;
unsigned field2;
const char *column1;
const char *column2;
const char *codebook_table;
const char *codebook_column;
PhoneNumber::eTypeNumber phoneNumberType;
const char *splitSeparators;
const char *splitSeparatorsSeparator;
const char *proxyName;
bool sideCombination;
bool revertNegation;
bool zeroIsValue;
bool enableNull;
bool emptyAsNull;
double divisor;
double value_mult;
double value_offset;
};
class cFilterData {
public:
struct sItem {
sItem() {
used = false;
}
string name;
string value;
bool used;
};
public:
void add(const string &key, const string &name, const string &value) {
sItem *item = &data[key];
item->name = name;
item->value = value;
}
void setUsed(const char *key) {
if(key) {
data[key].used = true;
}
}
void setUnused(const char *key) {
if(key) {
data[key].used = false;
}
}
string &operator [] (const string &key) {
sItem *item = &data[key];
item->used = true;
return(item->value);
}
string getUnusedKeys(const char *ignoreKeys) {
string rslt;
for(map<string, sItem>::iterator iter = data.begin(); iter != data.end(); iter++) {
if(!iter->second.used && !iter->second.value.empty() &&
!existsKeyInList(iter->first, ignoreKeys) &&
!existsKeyInList(iter->second.name, ignoreKeys)) {
rslt += (rslt.empty() ? "" : ",") + iter->second.name;
}
}
return(rslt);
}
private:
bool existsKeyInList(const string &key, const char *keyList) {
string keyDelim = "," + key + ",";
return(strstr(keyList, keyDelim.c_str()) != NULL);
}
private:
map<string, sItem> data;
};
public:
cCallFilter(const char *filter, const char *keyPrefix = NULL, bool nested = false, cCodebookCache *codebookCache = NULL);
void setFilter(const char *filter, const char *keyPrefix = NULL, bool nested = false);
bool existsUnsupportedKeys() {
return(!unsupportedKeys.empty());
}
string getUnsupportedKeys() {
return(unsupportedKeys);
}
static bool isIpFilterKey(const char *key);
static string reduceFilterToIpKeys(const char *filter, const char *keyPrefix, bool *approx = NULL);
static string reduceFilterCombToIpKeys(const char *filters_comb, const char *keyPrefix);
int64_t getField_int(void *rec, unsigned registerFieldIndex) {
if(!recIsCall(rec)) {
return(getField_int_tc(recTablesContent(rec), registerFieldIndex));
}
Call *call = recCall(rec);
switch(registerFieldIndex) {
case cf_calldate:
return(call->calltime_s());
case cf_id_sensor:
return(call->useSensorId);
case cf_lastSIPresponseNum:
return(call->branch_main()->lastSIPresponseNum);
case cf_callerport:
return(call->isClosed() ?
call->branch_main()->sipcallerport_rslt.getPort() :
call->getSipcallerport(call->branch_main()).getPort());
case cf_calledport:
return(call->isClosed() ?
call->branch_main()->sipcalledport_rslt.getPort() :
call->getSipcalledport(call->branch_main()).getPort());
case cf_called_international:
return(!isLocalByPhoneNumber(call->get_called(call->branch_main()), call->getSipcalledip_corrected(call->branch_main())));
case cf_vlan:
return(call->branch_main()->getVlan());
}
return(0);
}
int64_t getField_int_tc(cDbTablesContent *tc, unsigned registerFieldIndex);
double getField_float(void *rec, unsigned registerFieldIndex, bool *null);
double getField_float_tc(cDbTablesContent *tc, unsigned registerFieldIndex, bool *null);
vmIP getField_ip(void *rec, unsigned registerFieldIndex) {
if(!recIsCall(rec)) {
return(getField_ip_tc(recTablesContent(rec), registerFieldIndex));
}
Call *call = recCall(rec);
switch(registerFieldIndex) {
case cf_callerip:
return(call->isClosed() ?
call->branch_main()->sipcallerip_rslt :
call->getSipcallerip_corrected(call->branch_main()));
case cf_calledip:
return(call->isClosed() ?
call->branch_main()->sipcalledip_rslt :
call->getSipcalledip_corrected(call->branch_main()));
case cf_callerip_encaps:
return(call->isClosed() ?
call->branch_main()->sipcallerip_encaps_rslt :
call->getSipcallerip_encaps(call->branch_main(), true));
case cf_calledip_encaps:
return(call->isClosed() ?
call->branch_main()->sipcalledip_encaps_rslt :
call->getSipcalledip_encaps(call->branch_main(), true, true));
case cf_rtp_src:
case cf_rtp_dst: {
int side = registerFieldIndex == cf_rtp_src ? 0 : 1;