-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWebBroker.cpp
More file actions
63 lines (53 loc) · 2.1 KB
/
Copy pathWebBroker.cpp
File metadata and controls
63 lines (53 loc) · 2.1 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
#include "WebBroker.h"
#include <sstream>
using namespace std;
void WebBroker::register_connection(const std::string& client, unsigned short port) {
stringstream ss;
ss << R"({"type": "connection", "client": ")" << client << R"(", port: ")" << port << "}";
send(ss.str());
}
void WebBroker::register_request(const std::string& client, unsigned short client_port,
const std::string& host, unsigned short host_port) {
stringstream ss;
ss << R"({"type": "request",)"
<< R"("client": ")" << client << R"(", port: ")" << client_port << ","
<< R"("host": ")" << host << R"(", port: ")" << host_port
<< "}";
send(ss.str());
}
void WebBroker::register_dnsquery(const std::string& client, unsigned short client_port, const std::string& host, unsigned short host_port) {
stringstream ss;
ss << R"({"type": "request",)"
<< R"("client": ")" << client << R"(", port: ")" << client_port << ","
<< R"("host": ")" << host << R"(", port: ")" << host_port
<< "}";
send(ss.str());
}
void WebBroker::register_netflow(const std::string& client, unsigned short client_port, const std::string& host, unsigned short host_port, size_t bytes) {
stringstream ss;
ss << R"({"type": "request",)"
<< R"("client": ")" << client << R"(", client_port: ")" << client_port << ","
<< R"("host": ")" << host << R"(", host_port: ")" << host_port
<< R"(, "bytes": )" << bytes
<< "}";
send(ss.str());
}
void WebBroker::register_block(const std::string& client, unsigned short client_port, const std::string& host, unsigned short host_port, const std::string& reason) {
stringstream ss;
ss << R"({"type": "block",)"
<< R"("client": ")" << client << R"(", client_port: ")" << client_port << ","
<< R"("host": ")" << host << R"(", host_port: ")" << host_port
<< R"(, "reason": )" << reason
<< "}";
send(ss.str());
}
void WebBroker::send(std::string&& x) {
for(auto& callback : callbacks) callback(x);
}
size_t WebBroker::register_callback(callback&& x) {
callbacks.emplace_back(move(x));
return callbacks.size() - 1;
}
void WebBroker::unregister_callback(size_t i) {
callbacks.erase(callbacks.begin()+i);
}