-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathfilter_call.h
209 lines (191 loc) · 5.27 KB
/
filter_call.h
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
#ifndef FILTER_CALL_H
#define FILTER_CALL_H
#include "filter_record.h"
#include "calltable.h"
#include "country_detect.h"
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;
}
Call *call = (Call*)rec;
set<vmIP> proxies;
call->getProxies(((Call*)rec)->branch_main(), &proxies, true, true);
if(proxies.size()) {
for(set<vmIP>::iterator iter = proxies.begin(); iter != proxies.end(); iter++) {
bool _findInBlackList = false;
if(check_ip(*iter, &_findInBlackList)) {
return(true);
} else if(_findInBlackList) {
if(findInBlackList) {
*findInBlackList = _findInBlackList;
}
return(false);
}
}
}
return(false);
}
};
class cRecordFilterItem_CustomHeader : public cRecordFilterItem_CheckString {
public:
cRecordFilterItem_CustomHeader(cRecordFilter *parent, const char *customHeader)
: cRecordFilterItem_CheckString(parent, 0) {
this->customHeader = customHeader;
}
bool check(void *rec, bool *findInBlackList = NULL);
private:
string customHeader;
};
class cRecordFilterItem_Call : public cRecordFilterItem_rec {
public:
cRecordFilterItem_Call(cRecordFilter *parent, const char *filter)
: cRecordFilterItem_rec(parent) {
this->filter = filter;
}
bool check(void *rec, bool *findInBlackList = NULL);
private:
string filter;
};
class cCallFilter : public cRecordFilter {
public:
cCallFilter(const char *filter);
void setFilter(const char *filter);
int64_t getField_int(void *rec, unsigned registerFieldIndex) {
switch(registerFieldIndex) {
case cf_calldate:
return(((Call*)rec)->calltime_s());
case cf_id_sensor:
return(((Call*)rec)->useSensorId);
case cf_connect_duration:
return(((Call*)rec)->connect_duration_active_s());
case cf_called_international:
return(!isLocalByPhoneNumber(((Call*)rec)->get_called(((Call*)rec)->branch_main()), ((Call*)rec)->getSipcalledip(((Call*)rec)->branch_main(), true, true)));
case cf_vlan:
return(((Call*)rec)->branch_main()->vlan);
}
return(0);
}
vmIP getField_ip(void *rec, unsigned registerFieldIndex) {
switch(registerFieldIndex) {
case cf_callerip:
return(((Call*)rec)->getSipcallerip(((Call*)rec)->branch_main(), true));
case cf_calledip:
return(((Call*)rec)->getSipcalledip(((Call*)rec)->branch_main(), true, true));
case cf_callerip_encaps:
return(((Call*)rec)->getSipcallerip_encaps(((Call*)rec)->branch_main(), true));
case cf_calledip_encaps:
return(((Call*)rec)->getSipcalledip_encaps(((Call*)rec)->branch_main(), true, true));
}
return(0);
}
const char *getField_string(void *rec, unsigned registerFieldIndex) {
switch(registerFieldIndex) {
case cf_caller:
return(((Call*)rec)->branch_main()->caller.c_str());
case cf_called:
return(((Call*)rec)->get_called(((Call*)rec)->branch_main()));
case cf_callerdomain:
return(((Call*)rec)->branch_main()->caller_domain.c_str());
case cf_calleddomain:
return(((Call*)rec)->get_called_domain(((Call*)rec)->branch_main()));
case cf_calleragent:
return(((Call*)rec)->branch_main()->a_ua.c_str());
case cf_calledagent:
return(((Call*)rec)->branch_main()->b_ua.c_str());
case cf_callid:
return(((Call*)rec)->fbasename);
}
return("");
}
};
class cUserRestriction {
public:
enum eTypeSrc {
_ts_cdr,
_ts_message,
_ts_other
};
enum eCombCond {
_cc_and,
_cc_or
};
public:
cUserRestriction();
~cUserRestriction();
void load(unsigned uid, bool *useCustomHeaders, SqlDb *sqlDb = NULL);
void apply();
void clear();
bool check(eTypeSrc type_src,
vmIP *ip_src, vmIP *ip_dst,
const char *number_src, const char *number_dst, const char *number_contact,
const char *domain_src, const char *domain_dst, const char *domain_contact,
u_int16_t vlan,
map<string, string> *ch);
private:
unsigned uid;
string src_ip;
string src_number;
string src_domain;
string src_vlan;
string src_ch_cdr;
string src_ch_message;
ListIP *cond_ip;
ListPhoneNumber *cond_number;
ListCheckString *cond_domain;
list<u_int16_t> *cond_vlan;
class cLogicHierarchyAndOr *cond_ch_cdr;
cLogicHierarchyAndOr *cond_ch_message;
eCombCond comb_cond;
};
class cLogicHierarchyAndOr {
public:
class cItem {
public:
cItem(int level) {
this->level = level;
}
virtual ~cItem() {}
protected:
virtual bool eval(void */*data*/) {
return(true);
}
protected:
int level;
friend class cLogicHierarchyAndOr;
};
public:
cLogicHierarchyAndOr();
virtual ~cLogicHierarchyAndOr();
void set(const char *src);
bool eval(void *data);
protected:
virtual cItem *createItem(int level, const char *data);
private:
bool eval(unsigned *index, void *data);
void clear();
private:
vector<cItem*> items;
};
class cLogicHierarchyAndOr_custom_header : public cLogicHierarchyAndOr {
public:
class cItemCustomHeader : public cItem {
public:
cItemCustomHeader(int level, const char *custom_header, const char *pattern) : cItem(level) {
this->custom_header = custom_header;
this->pattern = pattern;
}
protected:
virtual bool eval(void *data);
protected:
string custom_header;
string pattern;
};
protected:
virtual cItem *createItem(int level, const char *data);
};
#endif