bigsnitch/httpflow.h
2020-09-10 21:26:41 +02:00

55 lines
2 KiB
C++

#pragma once
#include <includes.h>
namespace http {
inline void to_json(json& j, const Flow& flow) {}
inline void from_json(const json& j, Flow& flow) {
//std::cout << std::setw(4) << j << "\n\n";
json j_flow;
if(!json_get(j, j_flow, "flow")) {
return;
}
json_get(j_flow, flow.uid, "id");
if(json j_request; json_get(j_flow, j_request, "request")) {
json_get(j_request, flow.request.tls, "server_conn", "tls_established");
json_get(j_request, flow.request.port, "port");
json_get(j_request, flow.request.host, "host");
json_get(j_request, flow.request.scheme, "scheme");
json_get(j_request, flow.request.path, "path");
json_get(j_request, flow.request.content, "content");
json_get(j_request, flow.request.method, "method");
json_get(j_request, flow.request.http_version, "http_version");
json_get(j_request, flow.request.timestamp_start, "timestamp_start");
json_get(j_request, flow.request.timestamp_end, "timestamp_end");
json j_headers;
if(json_get(j_request, j_headers, "headers")) {
for(auto& [k,v] : j_headers.items()) {
flow.request.headers.push_back(std::make_tuple(v.at(0), v.at(1)));
}
}
}
if(json j_response; json_get(j_flow, j_response, "response")) {
json_get(j_response, flow.response.status_code, "status_code");
json_get(j_response, flow.response.http_version, "http_version");
json_get(j_response, flow.response.reason, "reason");
json_get(j_response, flow.response.content, "content");
json_get(j_response, flow.response.timestamp_start, "timestamp_start");
json_get(j_response, flow.response.timestamp_end, "timestamp_end");
json j_headers;
if(json_get(j_response, j_headers, "headers")) {
for(auto& [k,v] : j_headers.items()) {
flow.response.headers.push_back(std::make_tuple(v.at(0), v.at(1)));
}
}
}
}
}
Q_DECLARE_METATYPE(http::Flow)