feat: add transactional evidence importer

This commit is contained in:
grayTerminal-sh 2026-07-19 21:03:12 +02:00
parent d3a2124f8b
commit 2b9d560da7
29 changed files with 4324 additions and 2 deletions

View file

@ -53,6 +53,7 @@ TEST_TOOL_CATALOG := tests/test_tool_catalog
TEST_TOOL_INITIALIZER := tests/test_tool_initializer TEST_TOOL_INITIALIZER := tests/test_tool_initializer
TEST_FILE_HASH := tests/test_file_hash TEST_FILE_HASH := tests/test_file_hash
TEST_EVIDENCE_COPY := tests/test_evidence_copy TEST_EVIDENCE_COPY := tests/test_evidence_copy
TEST_EVIDENCE_IMPORTER := tests/test_evidence_importer
all: $(TARGET) all: $(TARGET)
@ -228,6 +229,22 @@ $(TEST_EVIDENCE_COPY): \
-DEVIDENCE_COPY_ENABLE_TEST_HOOKS \ -DEVIDENCE_COPY_ENABLE_TEST_HOOKS \
$^ -o $@ $(TEST_LDFLAGS) $^ -o $@ $(TEST_LDFLAGS)
$(TEST_EVIDENCE_IMPORTER): \
tests/test_evidence_importer.c \
src/core/evidence_importer.c \
src/core/evidence_copy.c \
src/core/file_hash.c \
src/dao/evidence_dao.c \
src/models/evidence_record.c \
src/database/database.c \
src/database/schema.c \
src/database/statement.c \
src/database/transaction.c \
src/database/error.c
$(CC) $(TEST_CFLAGS) \
-DEVIDENCE_IMPORTER_ENABLE_TEST_HOOKS \
$^ -o $@ $(TEST_LDFLAGS) -lsqlite3
test: \ test: \
$(TEST_NODE) \ $(TEST_NODE) \
$(TEST_TREE_MODEL) \ $(TEST_TREE_MODEL) \
@ -250,7 +267,8 @@ test: \
$(TEST_TOOL_CATALOG) \ $(TEST_TOOL_CATALOG) \
$(TEST_TOOL_INITIALIZER) \ $(TEST_TOOL_INITIALIZER) \
$(TEST_FILE_HASH) \ $(TEST_FILE_HASH) \
$(TEST_EVIDENCE_COPY) $(TEST_EVIDENCE_COPY) \
$(TEST_EVIDENCE_IMPORTER)
@echo "Exécution des tests..." @echo "Exécution des tests..."
@./$(TEST_NODE) @./$(TEST_NODE)
@./$(TEST_TREE_MODEL) @./$(TEST_TREE_MODEL)
@ -274,6 +292,7 @@ test: \
@$(TEST_TOOL_INITIALIZER) @$(TEST_TOOL_INITIALIZER)
@$(TEST_FILE_HASH) @$(TEST_FILE_HASH)
@$(TEST_EVIDENCE_COPY) @$(TEST_EVIDENCE_COPY)
@$(TEST_EVIDENCE_IMPORTER)
@echo "Tous les tests sont valides." @echo "Tous les tests sont valides."
%.o: %.c %.o: %.c
@ -305,7 +324,8 @@ clean:
$(TEST_TOOL_CATALOG) \ $(TEST_TOOL_CATALOG) \
$(TEST_TOOL_INITIALIZER) \ $(TEST_TOOL_INITIALIZER) \
$(TEST_FILE_HASH) \ $(TEST_FILE_HASH) \
$(TEST_EVIDENCE_COPY) $(TEST_EVIDENCE_COPY) \
$(TEST_EVIDENCE_IMPORTER)
.PHONY: clean run test .PHONY: clean run test

View file

@ -0,0 +1,132 @@
/******************************************************************************
* @file evidence_importer.h
* @brief Orchestration de limport transactionnel des preuves.
******************************************************************************/
#ifndef LABFY_INVESTIGATION_EVIDENCE_IMPORTER_H
#define LABFY_INVESTIGATION_EVIDENCE_IMPORTER_H
#include "database/database.h"
#include "models/evidence_record.h"
#include <gio/gio.h>
#include <glib.h>
G_BEGIN_DECLS
/**
* @brief Catégories derreurs du module EvidenceImporter.
*/
typedef enum
{
EVIDENCE_IMPORTER_ERROR_INVALID_ARGUMENT,
EVIDENCE_IMPORTER_ERROR_MEMORY,
EVIDENCE_IMPORTER_ERROR_CANCELLED,
EVIDENCE_IMPORTER_ERROR_DESTINATION,
EVIDENCE_IMPORTER_ERROR_COPY,
EVIDENCE_IMPORTER_ERROR_MODEL,
EVIDENCE_IMPORTER_ERROR_DATABASE,
EVIDENCE_IMPORTER_ERROR_ROLLBACK
} EvidenceImporterError;
/**
* @brief Domaine derreurs du module EvidenceImporter.
*/
#define EVIDENCE_IMPORTER_ERROR \
evidence_importer_error_quark()
/**
* @brief Retourne le domaine derreurs du module.
*/
GQuark evidence_importer_error_quark(void);
/**
* @brief Service opaque orchestrant limport des preuves.
*
* Lobjet emprunte la connexion Database reçue à sa création.
*/
typedef struct EvidenceImporter EvidenceImporter;
/**
* @brief Paramètres empruntés dun import de preuve.
*
* Les chaînes restent la propriété de lappelant.
*
* source_path, destination_directory, relative_directory et
* type_identifier sont obligatoires.
*
* collected_at, source et description sont facultatifs.
*/
typedef struct
{
const char *source_path;
const char *destination_directory;
const char *relative_directory;
const char *type_identifier;
const char *collected_at;
const char *source;
const char *description;
} EvidenceImportRequest;
/**
* @brief Crée un service dimport utilisant une connexion existante.
*
* La connexion est empruntée et doit rester valide pendant toute la durée
* de vie de limporteur.
*
* @param database Connexion ouverte et migrée.
* @param error Adresse recevant une éventuelle erreur.
*
* @return Nouvel importeur, ou NULL.
*/
EvidenceImporter *evidence_importer_new(
Database *database,
GError **error
);
/**
* @brief Libère un importeur.
*
* La connexion Database empruntée nest pas fermée.
* Cette fonction accepte NULL.
*
* @param evidence_importer Importeur à libérer.
*/
void evidence_importer_free(
EvidenceImporter *evidence_importer
);
/**
* @brief Importe une preuve de manière transactionnelle.
*
* Après succès :
*
* - le fichier est présent dans lenquête ;
* - le modèle est enregistré dans SQLite ;
* - le EvidenceRecord retourné appartient à lappelant.
*
* Après échec :
*
* - aucun EvidenceRecord nest retourné ;
* - aucune transaction démarrée par limporteur ne reste active ;
* - toute copie créée par lopération est supprimée lorsque cela est
* encore possible.
*
* @param evidence_importer Service dimport.
* @param request Paramètres empruntés de limport.
* @param cancellable Objet dannulation facultatif.
* @param error Adresse recevant une éventuelle erreur.
*
* @return Nouveau EvidenceRecord, ou NULL.
*/
EvidenceRecord *evidence_importer_import(
EvidenceImporter *evidence_importer,
const EvidenceImportRequest *request,
GCancellable *cancellable,
GError **error
);
G_END_DECLS
#endif

View file

@ -0,0 +1,29 @@
/******************************************************************************
* @file evidence_importer_test.h
* @brief Crochets réservés aux tests de EvidenceImporter.
******************************************************************************/
#ifndef LABFY_INVESTIGATION_EVIDENCE_IMPORTER_TEST_H
#define LABFY_INVESTIGATION_EVIDENCE_IMPORTER_TEST_H
#include <glib.h>
G_BEGIN_DECLS
void evidence_importer_test_reset_hooks(void);
void evidence_importer_test_set_cancel_after_copy(
gboolean enabled
);
void evidence_importer_test_set_commit_failure(
gboolean enabled
);
void evidence_importer_test_set_cleanup_failure(
gboolean enabled
);
G_END_DECLS
#endif

BIN
labfy-investigation Executable file

Binary file not shown.

1476
src/core/evidence_importer.c Normal file

File diff suppressed because it is too large Load diff

BIN
tests/test_background_task Executable file

Binary file not shown.

BIN
tests/test_database Executable file

Binary file not shown.

BIN
tests/test_error Executable file

Binary file not shown.

BIN
tests/test_evidence_copy Executable file

Binary file not shown.

BIN
tests/test_evidence_dao Executable file

Binary file not shown.

BIN
tests/test_evidence_importer Executable file

Binary file not shown.

File diff suppressed because it is too large Load diff

BIN
tests/test_evidence_record Executable file

Binary file not shown.

BIN
tests/test_file_hash Executable file

Binary file not shown.

BIN
tests/test_investigation_dao Executable file

Binary file not shown.

BIN
tests/test_investigation_node Executable file

Binary file not shown.

BIN
tests/test_investigation_project Executable file

Binary file not shown.

BIN
tests/test_investigation_record Executable file

Binary file not shown.

BIN
tests/test_investigation_session Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
tests/test_statement Executable file

Binary file not shown.

BIN
tests/test_task_manager Executable file

Binary file not shown.

BIN
tests/test_tool_catalog Executable file

Binary file not shown.

BIN
tests/test_tool_initializer Executable file

Binary file not shown.

BIN
tests/test_tool_process Executable file

Binary file not shown.

BIN
tests/test_tool_registry Executable file

Binary file not shown.

BIN
tests/test_tool_task Executable file

Binary file not shown.

BIN
tests/test_transaction Executable file

Binary file not shown.