forked from voipmonitor/sniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter_mysql.h
257 lines (241 loc) · 5.27 KB
/
filter_mysql.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
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
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <map>
#include <vector>
#include <deque>
#include <deque>
#include "calltable.h"
#define FLAG_RTP_ALL (1 << 0)
#define FLAG_RTP_HEAD (1 << 1)
#define FLAG_NORTP (1 << 2)
#define FLAG_SIP (1 << 3)
#define FLAG_NOSIP (1 << 4)
#define FLAG_REGISTER (1 << 5)
#define FLAG_NOREGISTER (1 << 6)
#define FLAG_GRAPH (1 << 7)
#define FLAG_NOGRAPH (1 << 8)
#define FLAG_AUDIO (1 << 9)
#define FLAG_AUDIO_WAV (1 << 10)
#define FLAG_AUDIO_OGG (1 << 11)
#define FLAG_NOWAV (1 << 12)
#define FLAG_SKIP (1 << 13)
#define FLAG_NOSKIP (1 << 14)
#define FLAG_SCRIPT (1 << 15)
#define FLAG_NOSCRIPT (1 << 16)
#define FLAG_AMOSLQO (1 << 17)
#define FLAG_BMOSLQO (1 << 18)
#define FLAG_ABMOSLQO (1 << 19)
#define FLAG_NOMOSLQO (1 << 20)
#define FLAG_HIDEMSG (1 << 21)
#define FLAG_SHOWMSG (1 << 22)
#define MAX_PREFIX 64
struct filter_db_row_base {
filter_db_row_base() {
direction = 0;
rtp = 0;
sip = 0;
reg = 0;
graph = 0;
wav = 0;
skip = 0;
mos_lqo = 0;
script = 0;
hide_message = 0;
}
int direction;
int rtp;
int sip;
int reg;
int graph;
int wav;
int skip;
int mos_lqo;
int script;
int hide_message;
};
class filter_base {
protected:
void loadBaseDataRow(class SqlDb_row *sqlRow, filter_db_row_base *baseRow);
unsigned int getFlagsFromBaseData(filter_db_row_base *baseRow);
void setCallFlagsFromFilterFlags(unsigned int *callFlags, unsigned int filterFlags);
};
class IPfilter : public filter_base {
private:
struct db_row : filter_db_row_base {
db_row() {
ip = 0;
mask = 0;
}
unsigned int ip;
int mask;
};
struct t_node {
unsigned int ip;
int mask;
int direction;
unsigned int flags;
t_node *next;
};
t_node *first_node;
public:
IPfilter();
~IPfilter();
int count;
void load();
void dump();
int add_call_flags(unsigned int *flags, unsigned int saddr, unsigned int daddr);
private:
static volatile int _sync;
public:
static void lock_sync() {
while(__sync_lock_test_and_set(&_sync, 1));
}
static void unlock_sync() {
__sync_lock_release(&_sync);
}
};
class TELNUMfilter : public filter_base {
private:
struct db_row : filter_db_row_base {
db_row() {
memset(prefix, 0, sizeof(prefix));
}
char prefix[MAX_PREFIX];
};
struct t_payload {
char prefix[MAX_PREFIX];
int direction;
unsigned int ip;
int mask;
unsigned int flags;
};
struct t_node_tel {
t_node_tel *nodes[256];
t_payload *payload;
};
t_node_tel *first_node;
public:
TELNUMfilter();
~TELNUMfilter();
int count;
void load();
void dump(t_node_tel *node = NULL);
void add_payload(t_payload *payload);
int add_call_flags(unsigned int *flags, char *telnum_src, char *telnum_dst);
private:
static volatile int _sync;
public:
static void lock_sync() {
while(__sync_lock_test_and_set(&_sync, 1));
}
static void unlock_sync() {
__sync_lock_release(&_sync);
}
};
class DOMAINfilter : public filter_base {
private:
struct db_row : filter_db_row_base{
db_row() {
}
std::string domain;
};
struct t_node {
std::string domain;
int direction;
unsigned int flags;
t_node *next;
};
t_node *first_node;
public:
DOMAINfilter();
~DOMAINfilter();
int count;
void load();
void dump();
int add_call_flags(unsigned int *flags, char *domain_src, char *domain_dst);
private:
static volatile int _sync;
public:
static void lock_sync() {
while(__sync_lock_test_and_set(&_sync, 1));
}
static void unlock_sync() {
__sync_lock_release(&_sync);
}
};
class SIP_HEADERfilter : public filter_base {
private:
struct db_row : filter_db_row_base{
db_row() {
}
std::string header;
std::string content;
bool prefix;
bool regexp;
};
struct item_data {
int direction;
bool prefix;
bool regexp;
unsigned int flags;
};
struct header_data {
std::map<std::string, item_data> strict_prefix;
std::map<std::string, item_data> regexp;
};
std::map<std::string, header_data> data;
public:
SIP_HEADERfilter();
~SIP_HEADERfilter();
int count;
void load();
void dump();
int add_call_flags(class ParsePacket *parsePacket, unsigned int *flags, char *domain_src, char *domain_dst);
void addNodes(ParsePacket *parsePacket);
private:
static volatile unsigned long loadTime;
static volatile int _sync;
public:
static unsigned long getLoadTime() {
return(loadTime);
}
static void lock_sync() {
while(__sync_lock_test_and_set(&_sync, 1));
}
static void unlock_sync() {
__sync_lock_release(&_sync);
}
};
inline void set_global_flags(unsigned int &flags) {
extern int opt_saveSIP;
extern int opt_saveRTP;
extern int opt_onlyRTPheader;
extern int opt_saveWAV;
extern int opt_audio_format;
extern int opt_saveGRAPH;
extern int opt_skipdefault;
extern int opt_hide_message_content;
if(opt_saveSIP) {
flags |= FLAG_SAVESIP;
}
if(opt_saveRTP) {
flags |= FLAG_SAVERTP;
}
if(opt_onlyRTPheader) {
flags |= FLAG_SAVERTPHEADER;
}
if(opt_saveWAV) {
flags |= (opt_audio_format == FORMAT_OGG ? FLAG_SAVEAUDIO_OGG : FLAG_SAVEAUDIO_WAV);
}
if(opt_saveGRAPH) {
flags |= FLAG_SAVEGRAPH;
}
if(opt_skipdefault) {
flags |= FLAG_SKIPCDR;
}
if(opt_hide_message_content) {
flags |= FLAG_HIDEMESSAGE;
}
}