From 7902cf2833215b3022d90c20327d5ff75ea59c5e Mon Sep 17 00:00:00 2001 From: Valentino Orlandi Date: Sun, 4 Feb 2024 01:22:08 +0100 Subject: [PATCH] Updates --- logdoctor/main.cpp | 1 + .../craplog/modules/workers/parser.cpp | 8 +++---- .../modules/craplog/modules/workers/parser.h | 9 ++++---- logdoctor/modules/crapview/crapview.cpp | 23 ++++++++++--------- logdoctor/modules/crapview/crapview.h | 6 ++--- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/logdoctor/main.cpp b/logdoctor/main.cpp index 00848b70..749961c1 100644 --- a/logdoctor/main.cpp +++ b/logdoctor/main.cpp @@ -11,6 +11,7 @@ int main(int argc, char *argv[]) qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); + qRegisterMetaType(); MainWindow w; w.show(); diff --git a/logdoctor/modules/craplog/modules/workers/parser.cpp b/logdoctor/modules/craplog/modules/workers/parser.cpp index 35b239ad..71f9a2c4 100644 --- a/logdoctor/modules/craplog/modules/workers/parser.cpp +++ b/logdoctor/modules/craplog/modules/workers/parser.cpp @@ -19,13 +19,13 @@ #include -CraplogParser::CraplogParser( const WebServer web_server, const DialogsLevel dialogs_level, const std::string& db_data_path, const std::string& db_hashes_path, const LogsFormat& logs_format, const bw_lists_t& blacklists, const worker_files_t& log_files, QObject* parent ) +CraplogParser::CraplogParser( const WebServer web_server, const DialogsLevel dialogs_level, const std::string& db_data_path, const std::string& db_hashes_path, const LogsFormat& logs_format, const Blacklist& blacklist, const worker_files_t& log_files, QObject* parent ) : QObject { parent } , web_server { web_server } , dialogs_level { dialogs_level } , db_data_path { db_data_path } , db_hashes_path { db_hashes_path } - , blacklists { blacklists } + , blacklist { blacklist } , logs_format { logs_format } , files_to_use { log_files } { @@ -358,11 +358,11 @@ void CraplogParser::storeLogLines() bool CraplogParser::storeData( DatabaseWrapper& db, const QString& db_name ) { // get blacklist items - const bool check_bl_cli { this->blacklists.at( 20 ).used }; + const bool check_bl_cli { this->blacklist.client.used }; const std::vector empty; const std::vector& bl_cli_list{ (check_bl_cli) - ? this->blacklists.at( 20 ).list + ? this->blacklist.client.list : empty }; // prepare the database related studd diff --git a/logdoctor/modules/craplog/modules/workers/parser.h b/logdoctor/modules/craplog/modules/workers/parser.h index 6dd18432..809ed4e2 100644 --- a/logdoctor/modules/craplog/modules/workers/parser.h +++ b/logdoctor/modules/craplog/modules/workers/parser.h @@ -6,12 +6,13 @@ #include "modules/craplog/modules/lib.h" +#include "modules/blacklists/modules/blacklist.h" + #include #include -struct BWlist; struct LogLineData; class DatabaseWrapper; @@ -25,7 +26,6 @@ class CraplogParser final : public QObject using logs_file_t = std::tuple; using worker_files_t = std::vector; - using bw_lists_t = std::unordered_map; public: @@ -35,7 +35,7 @@ public: const std::string& db_data_path, const std::string& db_hashes_path, const LogsFormat& logs_format, - const bw_lists_t& blacklists, + const Blacklist& blacklist, const worker_files_t& log_files, QObject* parent=nullptr ); @@ -100,8 +100,7 @@ private: /////////////////// //// BLACKLIST //// - // { log_field_id : BWlist } - const bw_lists_t blacklists; + const Blacklist blacklist; ////////////// //// LOGS //// diff --git a/logdoctor/modules/crapview/crapview.cpp b/logdoctor/modules/crapview/crapview.cpp index 030370ad..6f275deb 100644 --- a/logdoctor/modules/crapview/crapview.cpp +++ b/logdoctor/modules/crapview/crapview.cpp @@ -7,7 +7,8 @@ #include "modules/dialogs.h" #include "modules/exceptions.h" -#include "modules/craplog/modules/lib.h" + +#include "modules/warnlists/modules/warnlist.h" #include "modules/crapview/modules/lib.h" @@ -163,7 +164,7 @@ void Crapview::sliceClicked( QPieSlice* slice ) } -void Crapview::drawWarn( QTableWidget* table, QChartView* chart, const QChart::ChartTheme& theme, const QString web_server, const QString year, const QString month, const QString day, const QString hour, const std::unordered_map& warnlists ) const +void Crapview::drawWarn( QTableWidget* table, QChartView* chart, const QChart::ChartTheme& theme, const QString web_server, const QString year, const QString month, const QString day, const QString hour, const Warnlist& warnlist ) const { std::optional result; @@ -191,38 +192,38 @@ void Crapview::drawWarn( QTableWidget* table, QChartView* chart, const QChart::C const auto items{ std::move(*result) }; const auto check_warnings{ - [&warnlists](const std::array& line)->std::tuple> + [&warnlist](const std::array& line)->std::tuple> { bool is_warning{ false }; std::vector warning_cols; warning_cols.reserve(4ul); - if ( warnlists.at( 11ul ).used ) { // method - if ( VecOps::contains( warnlists.at( 11ul ).list, line.at( 7ul ).toStdString() ) ) { + if ( warnlist.method.used ) { + if ( VecOps::contains( warnlist.method.list, line.at( 7ul ).toStdString() ) ) { is_warning |= true; warning_cols.emplace_back( 4 ); } } - if ( warnlists.at( 12ul ).used ) { // uri + if ( warnlist.uri.used ) { const auto target{ line.at( 8ul ).toStdString() }; - const auto& list{ warnlists.at( 12ul ).list }; + const auto& list{ warnlist.uri.list }; if ( std::any_of( list.cbegin(), list.cend(), [&target](std::string_view flag){ return StringOps::startsWith( target, flag ); } ) ) { // match found! skip this line is_warning |= true; warning_cols.emplace_back( 5 ); } } - if ( warnlists.at( 20ul ).used ) { // client + if ( warnlist.client.used ) { const auto target{ line.at( 12ul ).toStdString() }; - const auto& list{ warnlists.at( 20ul ).list }; + const auto& list{ warnlist.client.list }; if ( std::any_of( list.cbegin(), list.cend(), [&target](std::string_view flag){ return StringOps::startsWith( target, flag ); } ) ) { // match found! skip this line is_warning |= true; warning_cols.emplace_back( 9 ); } } - if ( warnlists.at( 21ul ).used ) { // user-agent + if ( warnlist.user_agent.used ) { const auto target{ line.at( 11ul ).toStdString() }; - const auto& list{ warnlists.at( 21ul ).list }; + const auto& list{ warnlist.user_agent.list }; if ( std::any_of( list.cbegin(), list.cend(), [&target](std::string_view flag){ return StringOps::startsWith( target, flag ); } ) ) { // match found! skip this line is_warning |= true; diff --git a/logdoctor/modules/crapview/crapview.h b/logdoctor/modules/crapview/crapview.h index ada204a7..60eb9a07 100644 --- a/logdoctor/modules/crapview/crapview.h +++ b/logdoctor/modules/crapview/crapview.h @@ -9,7 +9,7 @@ #include -struct BWlist; +struct Warnlist; class QTableWidget; @@ -123,14 +123,14 @@ public: \param month The printable month name \param day The day \param hout The hour - \param warnlists The warnlists to check against + \param warnlist The warnlists to check against */ void drawWarn( QTableWidget* table, QChartView* chart, const QChart::ChartTheme& theme, const QString web_server, const QString year, const QString month, const QString day, const QString hour, - const std::unordered_map& warnlists + const Warnlist& warnlist ) const;