Structure improvements

Renamed HashOps to Hasher.
Improved Craplog files tree structure.
This commit is contained in:
Valentino Orlandi 2024-04-27 18:04:01 +02:00
parent 88e080fb4d
commit eba625e5b3
Signed by: elB4RTO
GPG key ID: 1719E976DB2D4E71
21 changed files with 111 additions and 97 deletions

View file

@ -133,24 +133,25 @@ set(PROJECT_SOURCES
modules/craplog/craplog.h
modules/craplog/craplog.cpp
modules/craplog/modules/lib.h
modules/craplog/modules/datetime.h
modules/craplog/modules/datetime.cpp
modules/craplog/modules/donuts.h
modules/craplog/modules/donuts.cpp
modules/craplog/modules/formats.h
modules/craplog/modules/formats.cpp
modules/craplog/modules/hash.h
modules/craplog/modules/hash.cpp
modules/craplog/modules/logs.h
modules/craplog/modules/logs.cpp
modules/craplog/modules/sha256.h
modules/craplog/modules/sha256.cpp
modules/craplog/modules/workers/lib.h
modules/craplog/modules/workers/lister.h
modules/craplog/modules/workers/lister.cpp
modules/craplog/modules/workers/parser.h
modules/craplog/modules/workers/parser.cpp
modules/craplog/modules/workers/impl/loglinedata.cpp
modules/craplog/modules/hasher.h
modules/craplog/modules/hasher.cpp
modules/craplog/modules/hasher/sha256.h
modules/craplog/modules/hasher/sha256.cpp
modules/craplog/utilities/datetime.h
modules/craplog/utilities/datetime.cpp
modules/craplog/utilities/logs.h
modules/craplog/utilities/logs.cpp
modules/craplog/workers/lib.h
modules/craplog/workers/lister.h
modules/craplog/workers/lister.cpp
modules/craplog/workers/parser.h
modules/craplog/workers/parser.cpp
modules/craplog/workers/parser/logs_data.h
modules/craplog/workers/parser/logs_data.cpp
modules/crapview/lib.h
modules/crapview/crapview.h
@ -299,8 +300,9 @@ add_executable(LogDocTester
modules/exceptions.h
modules/exceptions.cpp
modules/craplog/modules/lib.h
modules/craplog/modules/workers/lib.h
modules/craplog/modules/workers/impl/loglinedata.cpp
modules/craplog/workers/lib.h
modules/craplog/workers/parser/logs_data.h
modules/craplog/workers/parser/logs_data.cpp
utilities/gzip.h
utilities/gzip.cpp
utilities/io.h
@ -308,12 +310,12 @@ add_executable(LogDocTester
utilities/strings.h
utilities/strings.cpp
utilities/vectors.h
modules/craplog/modules/datetime.h
modules/craplog/modules/datetime.cpp
modules/craplog/modules/formats.h
modules/craplog/modules/formats.cpp
modules/craplog/modules/logs.h
modules/craplog/modules/logs.cpp
modules/craplog/utilities/datetime.h
modules/craplog/utilities/datetime.cpp
modules/craplog/utilities/logs.h
modules/craplog/utilities/logs.cpp
modules/crapview/utilities/filters.h
modules/crapview/utilities/filters.cpp
)

View file

@ -2105,7 +2105,7 @@ void MainWindow::makeInitialChecks()
ok &= false;
} else {
this->craplog.setHashesDatabasePath( this->db_hashes_path );
this->craplog.hashOps.loadUsedHashesLists( this->db_hashes_path + "/" + DatabasesNames::hashes );
this->craplog.hasher.loadUsedHashesLists( this->db_hashes_path + "/" + DatabasesNames::hashes );
}
}
}

View file

@ -19,9 +19,9 @@
#include "modules/craplog/modules/lib.h"
#include "modules/craplog/modules/donuts.h"
#include "modules/craplog/modules/logs.h"
#include "modules/craplog/modules/workers/lister.h"
#include "modules/craplog/modules/workers/parser.h"
#include "modules/craplog/workers/lister.h"
#include "modules/craplog/workers/parser.h"
#include "modules/craplog/utilities/logs.h"
#include <QPainter>
#include <QWaitCondition>
@ -87,7 +87,7 @@ DialogsLevel Craplog::getDialogsLevel() const noexcept
void Craplog::setDialogsLevel( const DialogsLevel new_level ) noexcept
{
this->dialogs_level = new_level;
this->hashOps.setDialogLevel( new_level );
this->hasher.setDialogLevel( new_level );
}
const std::string& Craplog::getStatsDatabasePath() const noexcept
@ -307,7 +307,7 @@ void Craplog::scanLogsDir()
this->dialogs_level,
this->logs_paths.at( this->current_web_server ),
this->logs_formats.at( this->current_web_server ),
this->hashOps,
this->hasher,
[this]( const std::string& file_name )
{ return this->isFileNameValid( file_name ); }
) };
@ -789,7 +789,7 @@ void Craplog::updateChartData( const size_t total_size, const size_t total_lines
void Craplog::storeFilesHashes( QWaitCondition* wc, bool* successful) noexcept
{
try {
this->hashOps.insertUsedHashes( this->db_hashes_path, this->used_files_hashes, this->current_web_server );
this->hasher.insertUsedHashes( this->db_hashes_path, this->used_files_hashes, this->current_web_server );
*successful |= true;
} catch (...) {
DialogSec::errFailedInsertUsedHashes();

View file

@ -4,10 +4,10 @@
#include "lib.h"
#include "modules/craplog/modules/hash.h"
#include "modules/craplog/modules/hasher.h"
#include "modules/craplog/modules/formats.h"
#include "modules/craplog/modules/workers/lib.h"
#include "modules/craplog/workers/lib.h"
#include <QtCharts>
@ -240,7 +240,7 @@ public:
//// OPERATIONS ////
// logs usage control
HashOps hashOps;
Hasher hasher;
//////////////

View file

@ -1,5 +1,7 @@
#include "hash.h"
#include "hasher.h"
#include "hasher/sha256.h"
#include "globals/db_names.h"
@ -13,21 +15,19 @@
#include "modules/database/database.h"
#include "sha256.h"
#include <ios>
#include <QVariant>
void HashOps::setDialogLevel( const DialogsLevel new_level ) noexcept
void Hasher::setDialogLevel( const DialogsLevel new_level ) noexcept
{
this->dialogs_level = new_level;
}
// reads the database holding the already used hashes
bool HashOps::loadUsedHashesLists( const std::string& db_path ) noexcept
bool Hasher::loadUsedHashesLists( const std::string& db_path ) noexcept
{
DatabaseWrapper db{ DatabaseHandler::get( DatabaseType::Hashes ) };
@ -56,7 +56,7 @@ bool HashOps::loadUsedHashesLists( const std::string& db_path ) noexcept
// returns the hash
void HashOps::digestFile( const std::string& file_path, std::string& hash )
void Hasher::digestFile( const std::string& file_path, std::string& hash )
{
std::string content;
try {
@ -109,7 +109,7 @@ void HashOps::digestFile( const std::string& file_path, std::string& hash )
// check if the given hash is from a file which has been used already
bool HashOps::hasBeenUsed( const std::string &file_hash, const WebServer& web_server) const noexcept
bool Hasher::hasBeenUsed( const std::string &file_hash, const WebServer& web_server) const noexcept
{
const auto& ws_hashes{ this->hashes.at( web_server ) };
return std::any_of(
@ -119,7 +119,7 @@ bool HashOps::hasBeenUsed( const std::string &file_hash, const WebServer& web_se
}
void HashOps::insertUsedHashes( const std::string& db_path, const std::vector<std::string>& hashes, const WebServer& web_server )
void Hasher::insertUsedHashes( const std::string& db_path, const std::vector<std::string>& hashes, const WebServer& web_server )
{
const bool explain_msg{ this->dialogs_level > DL_ESSENTIAL };
const bool explain_err{ this->dialogs_level == DL_EXPLANATORY };

View file

@ -1,5 +1,5 @@
#ifndef LOGDOCTOR__CRAPLOG__MODULES__HASH_H
#define LOGDOCTOR__CRAPLOG__MODULES__HASH_H
#ifndef LOGDOCTOR__CRAPLOG__MODULES__HASHER_H
#define LOGDOCTOR__CRAPLOG__MODULES__HASHER_H
#include "main_lib.h"
@ -15,11 +15,11 @@ enum class WebServer;
class QSqlQuery;
//! HashOps
//! Hasher
/*!
Operations for the hashes
Operations on the logs hashes
*/
class HashOps final
class Hasher final
{
public:
@ -83,4 +83,4 @@ private:
};
#endif // LOGDOCTOR__CRAPLOG__MODULES__HASH_H
#endif // LOGDOCTOR__CRAPLOG__MODULES__HASHER_H

View file

@ -1,7 +1,7 @@
#include "datetime.h"
#include "lib.h"
#include "modules/craplog/modules/lib.h"
#include "modules/exceptions.h"
#include "utilities/strings.h"

View file

@ -1,5 +1,5 @@
#ifndef LOGDOCTOR__CRAPLOG__MODULES__DATETIME_H
#define LOGDOCTOR__CRAPLOG__MODULES__DATETIME_H
#ifndef LOGDOCTOR__CRAPLOG__UTILITIES__DATETIME_H
#define LOGDOCTOR__CRAPLOG__UTILITIES__DATETIME_H
#include <stdint.h>
@ -29,4 +29,4 @@ std::vector<std::string> processDateTime( std::string_view datetime, const LogsF
} // namespace DateTimeOps
#endif // LOGDOCTOR__CRAPLOG__MODULES__DATETIME_H
#endif // LOGDOCTOR__CRAPLOG__UTILITIES__DATETIME_H

View file

@ -1,8 +1,8 @@
#ifndef LOGDOCTOR__CRAPLOG__MODULES__LOGS_H
#define LOGDOCTOR__CRAPLOG__MODULES__LOGS_H
#ifndef LOGDOCTOR__CRAPLOG__UTILITIES__LOGS_H
#define LOGDOCTOR__CRAPLOG__UTILITIES__LOGS_H
#include "lib.h"
#include "modules/craplog/modules/lib.h"
//! LogOps
@ -27,4 +27,4 @@ LogType defineFileType(
} // namespace LogOps
#endif // LOGDOCTOR__CRAPLOG__MODULES__LOGS_H
#endif // LOGDOCTOR__CRAPLOG__UTILITIES__LOGS_H

View file

@ -0,0 +1,27 @@
#ifndef LOGDOCTOR__CRAPLOG__WORKERS__LIB_H
#define LOGDOCTOR__CRAPLOG__WORKERS__LIB_H
#include <QMetaType>
//! Signals which dialog to show
enum class WorkerDialog {
errGeneric, // 1 arg
errDirNotExists, // 1 arg
errFailedDefiningLogType, // 1 arg
errFailedParsingLogs, // 1 arg
errDatabaseFileNotFound, // 1 arg
errDatabaseFileNotFile, // 1 arg
errDatabaseFileNotReadable, // 1 arg
errDatabaseFileNotWritable, // 1 arg
errDatabaseFailedOpening, // 2 args
errDatabaseFailedExecuting, // 3 args
warnFileNotReadable, // 1 arg
warnEmptyFile, // 1 arg
};
Q_DECLARE_METATYPE(WorkerDialog)
#endif // LOGDOCTOR__CRAPLOG__WORKERS__LIB_H

View file

@ -7,19 +7,19 @@
#include "modules/exceptions.h"
#include "modules/craplog/modules/lib.h"
#include "modules/craplog/modules/hash.h"
#include "modules/craplog/modules/logs.h"
#include "modules/craplog/modules/hasher.h"
#include "modules/craplog/utilities/logs.h"
#include "modules/craplog/modules/workers/lib.h"
#include "modules/craplog/workers/lib.h"
CraplogLister::CraplogLister( const WebServer web_server, const DialogsLevel dialogs_level, const std::string& logs_path, const LogsFormat& logs_format, const HashOps& hashOps, const std::function<bool(const std::string&)> check_filename, QObject* parent )
CraplogLister::CraplogLister( const WebServer web_server, const DialogsLevel dialogs_level, const std::string& logs_path, const LogsFormat& logs_format, const Hasher& hasher, const std::function<bool(const std::string&)> check_filename, QObject* parent )
: QObject { parent }
, web_server { web_server }
, dialogs_level { dialogs_level }
, logs_path { logs_path }
, logs_format { logs_format }
, hashOps { hashOps }
, hasher { hasher }
, check_filename { check_filename }
{
@ -112,7 +112,7 @@ void CraplogLister::work()
std::string hash;
try {
this->hashOps.digestFile( path, hash );
this->hasher.digestFile( path, hash );
} catch ( GenericException& e ) {
// failed to digest
emit this->showDialog( WorkerDialog::errGeneric,
@ -122,7 +122,7 @@ void CraplogLister::work()
// push in the list
emit this->pushLogFile( LogFile{
false, this->hashOps.hasBeenUsed( hash, this->web_server ),
false, this->hasher.hasBeenUsed( hash, this->web_server ),
size, name, hash, path } );
}
this->quit();

View file

@ -8,7 +8,7 @@
struct LogsFormat;
struct LogFile;
class HashOps;
class Hasher;
enum class WorkerDialog;
@ -24,7 +24,7 @@ public:
const DialogsLevel dialogs_level,
const std::string& logs_path,
const LogsFormat& logs_format,
const HashOps& hashOps,
const Hasher& hasher,
const std::function<bool(const std::string&)> check_filename,
QObject* parent=nullptr
);
@ -55,7 +55,7 @@ private:
const LogsFormat& logs_format;
const HashOps& hashOps;
const Hasher& hasher;
const std::function<bool(const std::string&)> check_filename;

View file

@ -1,6 +1,10 @@
#include "parser.h"
#include "parser/logs_data.h"
#include "lib.h"
#include "globals/db_names.h"
#include "utilities/checks.h"
@ -12,8 +16,6 @@
#include "modules/dialogs.h"
#include "modules/exceptions.h"
#include "modules/craplog/modules/workers/lib.h"
#include <QWaitCondition>
#include <QSqlDatabase>
#include <QSqlQuery>

View file

@ -1,10 +1,10 @@
#include "../lib.h"
#include "logs_data.h"
#include "modules/exceptions.h"
#include "modules/craplog/modules/lib.h"
#include "modules/craplog/modules/datetime.h"
#include "modules/craplog/utilities/datetime.h"
#include "utilities/strings.h"
#include "utilities/vectors.h"

View file

@ -1,33 +1,14 @@
#ifndef LOGDOCTOR__CRAPLOG__WORKERS__LIB_H
#define LOGDOCTOR__CRAPLOG__WORKERS__LIB_H
#ifndef LOGDOCTOR__CRAPLOG__WORKERS__PARSER__LOGS_DATA_H
#define LOGDOCTOR__CRAPLOG__WORKERS__PARSER__LOGS_DATA_H
#include <QMetaType>
#include <string>
#include <vector>
enum LogsFormatField : uint32_t;
struct LogsFormat;
//! Signals which dialog to show
enum class WorkerDialog {
errGeneric, // 1 arg
errDirNotExists, // 1 arg
errFailedDefiningLogType, // 1 arg
errFailedParsingLogs, // 1 arg
errDatabaseFileNotFound, // 1 arg
errDatabaseFileNotFile, // 1 arg
errDatabaseFileNotReadable, // 1 arg
errDatabaseFileNotWritable, // 1 arg
errDatabaseFailedOpening, // 2 args
errDatabaseFailedExecuting, // 3 args
warnFileNotReadable, // 1 arg
warnEmptyFile, // 1 arg
};
Q_DECLARE_METATYPE(WorkerDialog)
enum LogsFormatField : __uint32_t;
class LogsFormat;
//! FieldData
@ -44,7 +25,8 @@ struct FieldData final
~FieldData() noexcept = default;
FieldData(FieldData&& other) noexcept = default;
FieldData& operator=(FieldData&& rhs) noexcept = default;
Q_DISABLE_COPY(FieldData)
FieldData(const FieldData &) = delete;
FieldData &operator=(const FieldData &) = delete;
//! Returns whether the field contains data
inline operator bool() const noexcept
@ -82,7 +64,8 @@ struct LogLineData final
~LogLineData() noexcept = default;
LogLineData(LogLineData&& other) noexcept = default;
LogLineData& operator=(LogLineData&& rhs) noexcept = delete;
Q_DISABLE_COPY(LogLineData)
LogLineData(const LogLineData &) = delete;
LogLineData &operator=(const LogLineData &) = delete;
//! Returns the total size of all the fields' data
size_t size() const noexcept;
@ -141,4 +124,4 @@ private:
};
#endif // LOGDOCTOR__CRAPLOG__WORKERS__LIB_H
#endif // LOGDOCTOR__CRAPLOG__WORKERS__PARSER__LOGS_DATA_H

View file

@ -12,10 +12,10 @@
#include "modules/exceptions.h"
#include "modules/craplog/modules/datetime.h"
#include "modules/craplog/modules/formats.h"
#include "modules/craplog/modules/logs.h"
#include "modules/craplog/modules/workers/lib.h"
#include "modules/craplog/utilities/datetime.h"
#include "modules/craplog/utilities/logs.h"
#include "modules/craplog/workers/parser/logs_data.h"
#include "modules/crapview/utilities/filters.h"