forked from voipmonitor/sniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter_options.cpp
133 lines (130 loc) · 5.32 KB
/
filter_options.cpp
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
#include "filter_options.h"
#include "options.h"
cOptionsFilter::cOptionsFilter(const char *filter) {
setFilter(filter);
}
void cOptionsFilter::setFilter(const char *filter) {
JsonItem jsonData;
jsonData.parse(filter);
map<string, string> filterData;
for(unsigned int i = 0; i < jsonData.getLocalCount(); i++) {
JsonItem *item = jsonData.getLocalItem(i);
string filterTypeName = item->getLocalName();
string filterValue = item->getLocalValue();
if(filterValue.empty()) {
continue;
}
filterData[filterTypeName] = filterValue;
}
if(!filterData["ip_src"].empty() &&
filterData["ip_src_dst_type"] == "0") {
cRecordFilterItem_IP *filter1 = new cRecordFilterItem_IP(this, of_ip_src);
filter1->addWhite(filterData["ip_src"].c_str());
cRecordFilterItem_IP *filter2 = new cRecordFilterItem_IP(this, of_ip_dst);
filter2->addWhite(filterData["ip_src"].c_str());
addFilter(filter1, filter2);
} else {
cRecordFilterItems gItems(cRecordFilterItems::_and);
if(!filterData["ip_src"].empty()) {
cRecordFilterItem_IP *filter = new cRecordFilterItem_IP(this, of_ip_src);
filter->addWhite(filterData["ip_src"].c_str());
gItems.addFilter(filter);
}
if(!filterData["ip_dst"].empty()) {
cRecordFilterItem_IP *filter = new cRecordFilterItem_IP(this, of_ip_dst);
filter->addWhite(filterData["ip_dst"].c_str());
gItems.addFilter(filter);
}
if(gItems.isSet()) {
addFilter(&gItems);
}
}
if(!filterData["number_src"].empty() &&
filterData["number_src_dst_type"] == "0") {
cRecordFilterItem_CheckString *filter1 = new cRecordFilterItem_CheckString(this, of_number_src);
filter1->addWhite(filterData["number_src"].c_str());
cRecordFilterItem_CheckString *filter2 = new cRecordFilterItem_CheckString(this, of_number_dst);
filter2->addWhite(filterData["number_src"].c_str());
addFilter(filter1, filter2);
} else {
cRecordFilterItems gItems(cRecordFilterItems::_and);
if(!filterData["number_src"].empty()) {
cRecordFilterItem_CheckString *filter = new cRecordFilterItem_CheckString(this, of_number_src);
filter->addWhite(filterData["number_src"].c_str());
gItems.addFilter(filter);
}
if(!filterData["number_dst"].empty()) {
cRecordFilterItem_CheckString *filter = new cRecordFilterItem_CheckString(this, of_number_dst);
filter->addWhite(filterData["number_dst"].c_str());
gItems.addFilter(filter);
}
if(gItems.isSet()) {
addFilter(&gItems);
}
}
if(!filterData["domain_src"].empty() &&
filterData["domain_src_dst_type"] == "0") {
cRecordFilterItem_CheckString *filter1 = new cRecordFilterItem_CheckString(this, of_domain_src);
filter1->addWhite(filterData["domain_src"].c_str());
cRecordFilterItem_CheckString *filter2 = new cRecordFilterItem_CheckString(this, of_domain_dst);
filter2->addWhite(filterData["domain_src"].c_str());
addFilter(filter1, filter2);
} else {
cRecordFilterItems gItems(cRecordFilterItems::_and);
if(!filterData["domain_src"].empty()) {
cRecordFilterItem_CheckString *filter = new cRecordFilterItem_CheckString(this, of_domain_src);
filter->addWhite(filterData["domain_src"].c_str());
gItems.addFilter(filter);
}
if(!filterData["domain_dst"].empty()) {
cRecordFilterItem_CheckString *filter = new cRecordFilterItem_CheckString(this, of_domain_dst);
filter->addWhite(filterData["domain_dst"].c_str());
gItems.addFilter(filter);
}
if(gItems.isSet()) {
addFilter(&gItems);
}
}
if(atoi(filterData["qualify_state"].c_str()) == 1) {
cRecordFilterItem_numList *filter = new cRecordFilterItem_numList(this, of_qualify_ok);
filter->addNum(1);
addFilter(filter);
} else if(atoi(filterData["qualify_state"].c_str()) == 2) {
cRecordFilterItem_numList *filter = new cRecordFilterItem_numList(this, of_qualify_ok);
filter->addNum(0);
filter->addNum(-1);
addFilter(filter);
}
if(!filterData["response_time_ge"].empty()) {
cRecordFilterItem_numInterval *filter = new cRecordFilterItem_numInterval(this, of_response_time_ms, atol(filterData["response_time_ge"].c_str()), cRecordFilterItem_base::_ge);
addFilter(filter);
}
if(!filterData["response_time_lt"].empty()) {
cRecordFilterItem_numInterval *filter1 = new cRecordFilterItem_numInterval(this, of_response_time_ms, atol(filterData["response_time_lt"].c_str()), cRecordFilterItem_base::_lt);
addFilter(filter1);
cRecordFilterItem_numInterval *filter2 = new cRecordFilterItem_numInterval(this, of_response_time_ms, 0, cRecordFilterItem_base::_ge);
addFilter(filter2);
}
if(!filterData["response_number"].empty()) {
vector<string> response_numbers_str = split(filterData["response_number"].c_str(), split(",|;| |", "|"), true);
vector<int> response_numbers;
for(unsigned i = 0; i < response_numbers_str.size(); i++) {
int response_number = atoi(response_numbers_str[i].c_str());
if(response_number > 0) {
response_numbers.push_back(response_number);
}
}
if(response_numbers.size()) {
cRecordFilterItem_numList *filter = new cRecordFilterItem_numList(this, of_last_response_number);
for(unsigned i = 0; i < response_numbers.size(); i++) {
filter->addNum(response_numbers[i]);
}
addFilter(filter);
}
}
if(!filterData["sensor_id"].empty()) {
cRecordFilterItem_numList *filter = new cRecordFilterItem_numList(this, of_id_sensor);
filter->addNum(atoi(filterData["sensor_id"].c_str()) >= 0 ? atoi(filterData["sensor_id"].c_str()) : -1);
addFilter(filter);
}
}