foo
This commit is contained in:
		
							parent
							
								
									4f608586a9
								
							
						
					
					
						commit
						c42e9d07b5
					
				
					 5 changed files with 75 additions and 16 deletions
				
			
		|  | @ -124,3 +124,4 @@ bool HistoryProxyModel::filterAcceptsRow(int source_row, const QModelIndex &sour | |||
| { | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -28,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent) | |||
|     ui->historyHTTPTable->setShowGrid(true); | ||||
|     ui->historyHTTPTable->setEditTriggers(QAbstractItemView::NoEditTriggers); | ||||
|     ui->historyHTTPTable->setModel(&history_proxy); | ||||
|     connect(ui->historyHTTPTable->selectionModel(), SIGNAL (selectionChanged(QItemSelection, QItemSelection)), this, SLOT (on_selectionChange(QItemSelection))); | ||||
| } | ||||
| 
 | ||||
| MainWindow::~MainWindow() | ||||
|  | @ -41,10 +42,15 @@ void MainWindow::updateHistory() { | |||
|     ui->historyHTTPTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); | ||||
| } | ||||
| 
 | ||||
| void MainWindow::on_selectionChange(const QItemSelection &selection) | ||||
| { | ||||
|     if(!selection.indexes().isEmpty()) { | ||||
|         auto index = selection.indexes().value(0); | ||||
|         qDebug() << history_proxy.itemData(index)[0].toInt(); | ||||
|         //ui->textEdit->setText();
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void MainWindow::on_searchEdit_textEdited(const QString &arg1) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| void MainWindow::on_historyHTTPTable_cellClicked(int row, int column) | ||||
| { | ||||
| } | ||||
|  |  | |||
|  | @ -26,6 +26,6 @@ public: | |||
| public slots: | ||||
|     void updateHistory(); | ||||
| private slots: | ||||
|     void on_selectionChange(const QItemSelection& selection); | ||||
|     void on_searchEdit_textEdited(const QString &arg1); | ||||
|     void on_historyHTTPTable_cellClicked(int row, int column); | ||||
| }; | ||||
|  |  | |||
							
								
								
									
										57
									
								
								session.cpp
									
										
									
									
									
								
							
							
						
						
									
										57
									
								
								session.cpp
									
										
									
									
									
								
							|  | @ -54,6 +54,21 @@ bool Session::table_exists(std::string name) { | |||
|     return rc == SQLITE_ROW; | ||||
| } | ||||
| 
 | ||||
| bool Session::reset(sqlite3_stmt *stmt) | ||||
| { | ||||
|     auto res = sqlite3_reset(stmt); | ||||
|     if(res != SQLITE_ROW  || | ||||
|        res != SQLITE_DONE || | ||||
|        res != SQLITE_OK) { | ||||
|         qDebug() << "cannot reset statement"; | ||||
|         qDebug() << sqlite3_errmsg(db); | ||||
|         unload(); | ||||
|         throw; | ||||
|         return false; | ||||
|     } | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| void Session::prepare_tables() { | ||||
|     if(table_exists("setting")) { | ||||
|         prepare(get_setting, &stmt_get_setting); | ||||
|  | @ -81,6 +96,10 @@ void Session::prepare_tables() { | |||
|     } | ||||
| 
 | ||||
|     prepare(get_all_history, &stmt_get_all_history); | ||||
|     prepare(get_request, &stmt_get_request); | ||||
|     prepare(get_request_headers, &stmt_get_request_headers); | ||||
|     prepare(get_response, &stmt_get_response); | ||||
|     prepare(get_response_headers, &stmt_get_response_headers); | ||||
|     prepare(update_setting, &stmt_update_setting); | ||||
| 
 | ||||
|     prepare(insert_request, &stmt_insert_request); | ||||
|  | @ -112,7 +131,7 @@ bool Session::isLoaded() { | |||
| } | ||||
| 
 | ||||
| std::optional<std::string> Session::getSetting(std::string key) { | ||||
|     sqlite3_reset(stmt_get_setting); | ||||
|     reset(stmt_get_setting); | ||||
| 
 | ||||
|     int j = 1; | ||||
| 
 | ||||
|  | @ -136,7 +155,7 @@ std::optional<std::string> Session::getSetting(std::string key) { | |||
| std::vector<HistoryItem>* Session::getHistoryItems() { | ||||
|     qDebug() << "history items generated"; | ||||
|     // todo check reset return code
 | ||||
|     sqlite3_reset(stmt_get_all_history); | ||||
|     reset(stmt_get_all_history); | ||||
| 
 | ||||
|     std::vector<HistoryItem>* result = new std::vector<HistoryItem>(); | ||||
| 
 | ||||
|  | @ -170,13 +189,33 @@ std::vector<HistoryItem>* Session::getHistoryItems() { | |||
|     return result; | ||||
| } | ||||
| 
 | ||||
| std::optional<std::tuple<std::string, std::string>> Session::getRequest(int id) | ||||
| { | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| std::optional<std::map<std::string, std::string>> Session::getRequestHeader(int id) | ||||
| { | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| std::optional<std::tuple<std::string, std::string>> Session::getResponse(int id) | ||||
| { | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| std::optional<std::map<std::string, std::string>> Session::getResponseHeader(int id) | ||||
| { | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| void Session::bind_text(sqlite3_stmt* stmt, int id, std::string text) { | ||||
|     //qDebug() << id << " " << text.c_str() << " " << strlen(text.c_str());
 | ||||
|     sqlite3_bind_text(stmt, id, text.c_str(), -1, SQLITE_TRANSIENT); | ||||
| } | ||||
| 
 | ||||
| int Session::saveRequest(http::Flow flow) { | ||||
|     sqlite3_reset(stmt_insert_request); | ||||
|     reset(stmt_insert_request); | ||||
| 
 | ||||
|     int j = 1; | ||||
|     bind_text(stmt_insert_request, j++, flow.request.server_ip_address); | ||||
|  | @ -214,7 +253,7 @@ int Session::saveRequest(http::Flow flow) { | |||
| } | ||||
| 
 | ||||
| int Session::saveRequestHeader(std::string key, std::string value, int id) { | ||||
|     sqlite3_reset(stmt_insert_request_header); | ||||
|     reset(stmt_insert_request_header); | ||||
| 
 | ||||
|     int j = 1; | ||||
| 
 | ||||
|  | @ -233,7 +272,7 @@ int Session::saveRequestHeader(std::string key, std::string value, int id) { | |||
| } | ||||
| 
 | ||||
| int Session::saveResponse(http::Flow flow) { | ||||
|     sqlite3_reset(stmt_insert_response); | ||||
|     reset(stmt_insert_response); | ||||
| 
 | ||||
|     int j = 1; | ||||
| 
 | ||||
|  | @ -261,7 +300,7 @@ int Session::saveResponse(http::Flow flow) { | |||
| } | ||||
| 
 | ||||
| int Session::saveResponseHeader(std::string key, std::string value, int id) { | ||||
|     sqlite3_reset(stmt_insert_response_header); | ||||
|     reset(stmt_insert_response_header); | ||||
| 
 | ||||
|     int j = 1; | ||||
| 
 | ||||
|  | @ -280,7 +319,7 @@ int Session::saveResponseHeader(std::string key, std::string value, int id) { | |||
| } | ||||
| 
 | ||||
| int Session::saveFlow(http::Flow flow) { | ||||
|     sqlite3_reset(stmt_insert_flow); | ||||
|     reset(stmt_insert_flow); | ||||
| 
 | ||||
|     int request_id = saveRequest(flow); | ||||
|     int response_id = saveResponse(flow); | ||||
|  | @ -305,7 +344,7 @@ int Session::saveFlow(http::Flow flow) { | |||
| bool Session::saveSetting(std::string key, std::string value) { | ||||
|     auto old_value = getSetting(key); | ||||
|     if(!old_value) { | ||||
|         sqlite3_reset(stmt_insert_setting); | ||||
|         reset(stmt_insert_setting); | ||||
|         int j = 1; | ||||
| 
 | ||||
|         bind_text(stmt_insert_setting, j++, key); | ||||
|  | @ -320,7 +359,7 @@ bool Session::saveSetting(std::string key, std::string value) { | |||
| 
 | ||||
|         return sqlite3_last_insert_rowid(db); | ||||
|     } else { | ||||
|         sqlite3_reset(stmt_update_setting); | ||||
|         reset(stmt_update_setting); | ||||
|         int j = 1; | ||||
| 
 | ||||
|         bind_text(stmt_update_setting, j++, value); | ||||
|  |  | |||
							
								
								
									
										17
									
								
								session.h
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								session.h
									
										
									
									
									
								
							|  | @ -31,7 +31,7 @@ private: | |||
|                                             key TEXT, | ||||
|                                             value TEXT, | ||||
|                                             request_id INTEGER, | ||||
|                                             FOREIGN KEY(request_id) REFERENCES request(referer_id) ON UPDATE CASCADE ON DELETE CASCADE | ||||
|                                             FOREIGN KEY(request_id) REFERENCES request(id) ON UPDATE CASCADE ON DELETE CASCADE | ||||
|                                             ); )rstr"; | ||||
|     const char* create_response_tbl = R"rstr( CREATE TABLE response( | ||||
|                                       id INTEGER PRIMARY KEY AUTOINCREMENT, | ||||
|  | @ -47,7 +47,7 @@ private: | |||
|                                              key TEXT, | ||||
|                                              value TEXT, | ||||
|                                              response_id INTEGER, | ||||
|                                              FOREIGN KEY(response_id) REFERENCES response(referer_id) ON UPDATE CASCADE ON DELETE CASCADE | ||||
|                                              FOREIGN KEY(response_id) REFERENCES response(id) ON UPDATE CASCADE ON DELETE CASCADE | ||||
|                                              ); )rstr"; | ||||
|     const char* create_flow_tbl = R"rstr( CREATE TABLE flow( | ||||
|                                   id INTEGER PRIMARY KEY AUTOINCREMENT, | ||||
|  | @ -64,6 +64,10 @@ private: | |||
| 
 | ||||
|     const char* get_tbl = R"rstr( SELECT name FROM sqlite_master WHERE type='table' AND name=?; )rstr"; | ||||
|     const char* get_setting = R"rstr( SELECT value FROM setting WHERE key=?; )rstr"; | ||||
|     const char* get_request = R"rstr( SELECT req.content FROM flow f JOIN request req ON f.request_id=req.id WHERE f.id=?; )rstr"; | ||||
|     const char* get_response = R"rstr( SELECT res.content FROM flow f JOIN response res ON f.response_id=res.id WHERE f.id=?; )rstr"; | ||||
|     const char* get_request_headers = R"rstr(  SELECT * FROM response_header WHERE response_id=?; )rstr"; | ||||
|     const char* get_response_headers = R"rstr(  SELECT * FROM request_header WHERE request_id=?; )rstr"; | ||||
|     const char* get_all_history = R"rstr( SELECT f.id,req.timestamp_start,req.method,req.scheme,req.host,req.port,req.path,res.status_code,res.reason,res.timestamp_end-res.timestamp_start,length(res.content) FROM flow f JOIN request req ON f.request_id=req.id JOIN response res ON f.response_id=res.id; )rstr"; | ||||
| 
 | ||||
|     const char* insert_request = R"rstr( INSERT INTO request (server_ip_address, tls, content, scheme, method, host, port, http_version, path, timestamp_start, timestamp_end, error) VALUES (?,?,?,?,?,?,?,?,?,?,?,?); )rstr"; | ||||
|  | @ -79,6 +83,10 @@ private: | |||
|     bool loaded = false; | ||||
| 
 | ||||
|     sqlite3_stmt* stmt_get_setting = nullptr; | ||||
|     sqlite3_stmt* stmt_get_request = nullptr; | ||||
|     sqlite3_stmt* stmt_get_response = nullptr; | ||||
|     sqlite3_stmt* stmt_get_request_headers = nullptr; | ||||
|     sqlite3_stmt* stmt_get_response_headers = nullptr; | ||||
|     sqlite3_stmt* stmt_get_all_history = nullptr; | ||||
| 
 | ||||
|     sqlite3_stmt* stmt_insert_request = nullptr; | ||||
|  | @ -96,6 +104,7 @@ private: | |||
|     bool prepare_and_exec(const char* query); | ||||
|     void bind_text(sqlite3_stmt* stmt, int id, std::string text); | ||||
|     bool table_exists(std::string name); | ||||
|     bool reset(sqlite3_stmt* stmt); | ||||
| public: | ||||
|     explicit Session(QObject *parent = nullptr); | ||||
|     ~Session(); | ||||
|  | @ -105,6 +114,10 @@ public: | |||
|     bool isLoaded(); | ||||
|     std::optional<std::string> getSetting(std::string key); | ||||
|     std::vector<HistoryItem>* getHistoryItems(); | ||||
|     std::optional<std::tuple<std::string, std::string>> getRequest(int id); | ||||
|     std::optional<std::map<std::string, std::string>> getRequestHeader(int id); | ||||
|     std::optional<std::tuple<std::string, std::string>> getResponse(int id); | ||||
|     std::optional<std::map<std::string, std::string>> getResponseHeader(int id); | ||||
| public slots: | ||||
|     int saveRequest(http::Flow flow); | ||||
|     int saveRequestHeader(std::string key, std::string value, int id); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue