wip
This commit is contained in:
parent
1b1f626c61
commit
d4f6dfa0b5
3 changed files with 54 additions and 23 deletions
|
@ -97,7 +97,6 @@ namespace http {
|
||||||
|
|
||||||
struct Request
|
struct Request
|
||||||
{
|
{
|
||||||
std::string server_conn_id;
|
|
||||||
std::string server_ip_address;
|
std::string server_ip_address;
|
||||||
|
|
||||||
bool tls;
|
bool tls;
|
||||||
|
@ -128,6 +127,7 @@ struct Response {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Flow {
|
struct Flow {
|
||||||
|
std::string uid;
|
||||||
Request request;
|
Request request;
|
||||||
Response response;
|
Response response;
|
||||||
};
|
};
|
||||||
|
@ -139,8 +139,10 @@ inline void from_json(const json& j, Flow& flow) {
|
||||||
if(!j.contains("flow")) {
|
if(!j.contains("flow")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
j.at("flow").at("id").get_to(flow.id);
|
||||||
|
|
||||||
if(j.at("flow").contains("server_conn")) {
|
if(j.at("flow").contains("server_conn")) {
|
||||||
j.at("flow").at("server_conn").at("id").get_to(flow.request.server_conn_id);
|
|
||||||
j.at("flow").at("server_conn").at("tls_established").get_to(flow.request.tls);
|
j.at("flow").at("server_conn").at("tls_established").get_to(flow.request.tls);
|
||||||
}
|
}
|
||||||
if(j.at("flow").contains("request")) {
|
if(j.at("flow").contains("request")) {
|
||||||
|
|
63
session.cpp
63
session.cpp
|
@ -116,30 +116,57 @@ void Session::bind_text(sqlite3_stmt* stmt, int id, std::string text) {
|
||||||
sqlite3_bind_text(stmt, id, text.c_str(), -1, SQLITE_TRANSIENT);
|
sqlite3_bind_text(stmt, id, text.c_str(), -1, SQLITE_TRANSIENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::saveRequest(http::Flow flow) {
|
int Session::get_last_id() {
|
||||||
bind_text(stmt_insert_request, 1, flow.request.server_conn_id);
|
auto rc = sqlite3_step(stmt_insert_request);
|
||||||
bind_text(stmt_insert_request, 2, flow.request.server_ip_address);
|
sqlite3_reset(stmt_insert_request);
|
||||||
sqlite3_bind_int(stmt_insert_request, 3, flow.request.tls);
|
if(rc != SQLITE_DONE) {
|
||||||
bind_text(stmt_insert_request, 4, flow.request.content);
|
qDebug() << "error getting last id" << rc;
|
||||||
bind_text(stmt_insert_request, 5, flow.request.scheme);
|
qDebug() << sqlite3_errmsg(db);
|
||||||
bind_text(stmt_insert_request, 6, flow.request.method);
|
return -1;
|
||||||
bind_text(stmt_insert_request, 7, flow.request.host);
|
}
|
||||||
bind_text(stmt_insert_request, 8, flow.request.address);
|
return -1;
|
||||||
sqlite3_bind_int(stmt_insert_request, 9, flow.request.port);
|
}
|
||||||
bind_text(stmt_insert_request, 10, flow.request.http_version);
|
|
||||||
bind_text(stmt_insert_request, 11, flow.request.path);
|
int Session::saveRequest(http::Flow flow) {
|
||||||
sqlite3_bind_double(stmt_insert_request, 12, flow.request.timestamp_start);
|
int j = 1;
|
||||||
sqlite3_bind_double(stmt_insert_request, 13, flow.request.timestamp_end);
|
bind_text(stmt_insert_request, j++, flow.request.server_ip_address);
|
||||||
bind_text(stmt_insert_request, 14, flow.request.error);
|
|
||||||
|
sqlite3_bind_int(stmt_insert_request, j++, flow.request.tls);
|
||||||
|
|
||||||
|
bind_text(stmt_insert_request, j++, flow.request.content);
|
||||||
|
bind_text(stmt_insert_request, j++, flow.request.scheme);
|
||||||
|
bind_text(stmt_insert_request, j++, flow.request.method);
|
||||||
|
bind_text(stmt_insert_request, j++, flow.request.host);
|
||||||
|
bind_text(stmt_insert_request, j++, flow.request.address);
|
||||||
|
|
||||||
|
sqlite3_bind_int(stmt_insert_request, j++, flow.request.port);
|
||||||
|
|
||||||
|
bind_text(stmt_insert_request, j++, flow.request.http_version);
|
||||||
|
bind_text(stmt_insert_request, j++, flow.request.path);
|
||||||
|
|
||||||
|
sqlite3_bind_double(stmt_insert_request, j++, flow.request.timestamp_start);
|
||||||
|
sqlite3_bind_double(stmt_insert_request, j++, flow.request.timestamp_end);
|
||||||
|
|
||||||
|
bind_text(stmt_insert_request, j++, flow.request.error);
|
||||||
|
|
||||||
auto rc = sqlite3_step(stmt_insert_request);
|
auto rc = sqlite3_step(stmt_insert_request);
|
||||||
sqlite3_reset(stmt_insert_request);
|
sqlite3_reset(stmt_insert_request);
|
||||||
if(rc != SQLITE_DONE) {
|
if(rc != SQLITE_DONE) {
|
||||||
qDebug() << "inserting request failed" << rc;
|
qDebug() << "inserting request failed" << rc;
|
||||||
qDebug() << sqlite3_errmsg(db);
|
qDebug() << sqlite3_errmsg(db);
|
||||||
throw;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::saveResponse(http::Flow flow) {
|
int Session::saveResponse(http::Flow flow) {
|
||||||
throw;
|
|
||||||
|
auto rc = sqlite3_step(stmt_insert_response);
|
||||||
|
sqlite3_reset(stmt_insert_response);
|
||||||
|
if(rc != SQLITE_DONE) {
|
||||||
|
qDebug() << "inserting response failed" << rc;
|
||||||
|
qDebug() << sqlite3_errmsg(db);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ private:
|
||||||
); )rstr";
|
); )rstr";
|
||||||
const char* create_flow_tbl = R"rstr( CREATE TABLE flow(
|
const char* create_flow_tbl = R"rstr( CREATE TABLE flow(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
uid TEXT UNIQUE NOT NULL,
|
||||||
request_id INTEGER,
|
request_id INTEGER,
|
||||||
response_id INTEGER,
|
response_id INTEGER,
|
||||||
FOREIGN KEY(request_id) REFERENCES request(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
FOREIGN KEY(request_id) REFERENCES request(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
|
@ -62,7 +63,7 @@ private:
|
||||||
const char* last_inserted_id = R"rstr( SELECT last_insert_rowid(); )rstr";
|
const char* last_inserted_id = R"rstr( SELECT last_insert_rowid(); )rstr";
|
||||||
const char* check_tbl = R"rstr( SELECT name FROM sqlite_master WHERE type='table' AND name=?; )rstr";
|
const char* check_tbl = R"rstr( SELECT name FROM sqlite_master WHERE type='table' AND name=?; )rstr";
|
||||||
const char* check_session_info = R"rstr( SELECT value FROM session WHERE key=?; )rstr";
|
const char* check_session_info = R"rstr( SELECT value FROM session WHERE key=?; )rstr";
|
||||||
const char* insert_request = R"rstr( INSERT INTO request (server_conn_id, server_ip_address, tls, content, scheme, method, host, address, port, http_version, path, timestamp_start, timestamp_end, error) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?); )rstr";
|
const char* insert_request = R"rstr( INSERT INTO request (server_ip_address, tls, content, scheme, method, host, address, port, http_version, path, timestamp_start, timestamp_end, error) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?); )rstr";
|
||||||
const char* insert_request_header = R"rstr( INSERT INTO request_header (key, value, request_id) VALUES (?,?,?); )rstr";
|
const char* insert_request_header = R"rstr( INSERT INTO request_header (key, value, request_id) VALUES (?,?,?); )rstr";
|
||||||
const char* insert_response = R"rstr( INSERT INTO response (status_code, http_version, reason, content, timestamp_start, timestamp_end) VALUES (?,?,?,?,?,?); )rstr";
|
const char* insert_response = R"rstr( INSERT INTO response (status_code, http_version, reason, content, timestamp_start, timestamp_end) VALUES (?,?,?,?,?,?); )rstr";
|
||||||
const char* insert_response_header = R"rstr( INSERT INTO response_header (key, value, response_id) VALUES (?,?,?); )rstr";
|
const char* insert_response_header = R"rstr( INSERT INTO response_header (key, value, response_id) VALUES (?,?,?); )rstr";
|
||||||
|
@ -85,6 +86,7 @@ private:
|
||||||
void prepare(const char* query, sqlite3_stmt** stmt);
|
void prepare(const char* query, sqlite3_stmt** stmt);
|
||||||
bool prepare_and_exec(const char* query);
|
bool prepare_and_exec(const char* query);
|
||||||
void bind_text(sqlite3_stmt* stmt, int id, std::string text);
|
void bind_text(sqlite3_stmt* stmt, int id, std::string text);
|
||||||
|
int get_last_id();
|
||||||
public:
|
public:
|
||||||
explicit Session(QObject *parent = nullptr);
|
explicit Session(QObject *parent = nullptr);
|
||||||
~Session();
|
~Session();
|
||||||
|
@ -93,8 +95,8 @@ public:
|
||||||
void unload();
|
void unload();
|
||||||
bool isLoaded();
|
bool isLoaded();
|
||||||
public slots:
|
public slots:
|
||||||
void saveRequest(http::Flow flow);
|
int saveRequest(http::Flow flow);
|
||||||
void saveResponse(http::Flow flow);
|
int saveResponse(http::Flow flow);
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue