forked from voipmonitor/sniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.h
97 lines (90 loc) · 2.73 KB
/
http.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
#ifndef HTTP_H
#define HTTP_H
#include "pcap_queue_block.h"
#include "tcpreassembly.h"
struct HttpDataCache_id {
HttpDataCache_id(u_int32_t ip_src, u_int32_t ip_dst,
u_int16_t port_src, u_int16_t port_dst,
string *http, string *body,
string *http_master = NULL, string *body_master = NULL) {
this->ip_src = ip_src;
this->ip_dst = ip_dst;
this->port_src = port_src;
this->port_dst = port_dst;
if(http) {
this->http = *http;
}
if(body) {
this->body = *body;
}
if(http_master) {
this->http_master = *http_master;
}
if(body_master) {
this->body_master = *body_master;
}
}
u_int32_t ip_src;
u_int32_t ip_dst;
u_int16_t port_src;
u_int16_t port_dst;
string http;
string body;
string http_master;
string body_master;
bool operator < (const HttpDataCache_id& other) const {
return((this->ip_src < other.ip_src) ? 1 : (this->ip_src > other.ip_src) ? 0 :
(this->ip_dst < other.ip_dst) ? 1 : (this->ip_dst > other.ip_dst) ? 0 :
(this->port_src < other.port_src) ? 1 : (this->port_src > other.port_src) ? 0 :
(this->port_dst < other.port_dst) ? 1 : (this->port_dst > other.port_dst) ? 0 :
(this->http < other.http) ? 1 : (this->http > other.http) ? 0 :
(this->body < other.body) ? 1 : (this->body > other.body) ? 0 :
(this->http_master < other.http_master) ? 1 : (this->http_master > other.http_master) ? 0 :
(this->body_master < other.body_master));
}
};
struct HttpDataCache {
HttpDataCache(uint32_t id = 0, u_int64_t timestamp = 0) {
this->id = id;
this->timestamp = timestamp;
}
uint32_t id;
u_int64_t timestamp;
};
class HttpCache {
public:
HttpCache();
HttpDataCache get(u_int32_t ip_src, u_int32_t ip_dst,
u_int16_t port_src, u_int16_t port_dst,
string *http, string *body,
string *http_master = NULL, string *body_master = NULL);
void add(u_int32_t ip_src, u_int32_t ip_dst,
u_int16_t port_src, u_int16_t port_dst,
string *http, string *body,
string *http_master, string *body_master,
u_int32_t id, u_int64_t timestamp);
void cleanup();
void clear();
private:
map<HttpDataCache_id, HttpDataCache> cache;
u_int64_t cleanupCounter;
u_int64_t lastAddTimestamp;
};
class HttpData : public TcpReassemblyProcessData {
public:
HttpData();
~HttpData();
void processData(u_int32_t ip_src, u_int32_t ip_dst,
u_int16_t port_src, u_int16_t port_dst,
TcpReassemblyData *data,
bool debugSave);
string getUri(string &request);
string getUriValue(string &uri, const char *valueName);
string getUriPathValue(string &uri, const char *valueName);
string getTag(string &data, const char *tag);
string getJsonValue(string &data, const char *valueName);
private:
unsigned int counterProcessData;
HttpCache cache;
};
#endif