summaryrefslogtreecommitdiff
path: root/src/analysis/scan/patterns/tokens/nodes/choice.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/scan/patterns/tokens/nodes/choice.c')
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/choice.c342
1 files changed, 251 insertions, 91 deletions
diff --git a/src/analysis/scan/patterns/tokens/nodes/choice.c b/src/analysis/scan/patterns/tokens/nodes/choice.c
index df6ae45..102c7de 100644
--- a/src/analysis/scan/patterns/tokens/nodes/choice.c
+++ b/src/analysis/scan/patterns/tokens/nodes/choice.c
@@ -24,6 +24,9 @@
#include "choice.h"
+#include <assert.h>
+
+
#include "choice-int.h"
@@ -48,6 +51,9 @@ static void g_scan_token_node_choice_finalize(GScanTokenNodeChoice *);
/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+/* Communique l'intérêt d'un noeud au sein d'une analyse. */
+static float g_scan_token_node_choice_compute_weight_for_scan(const GScanTokenNodeChoice *);
+
/* Prend acte d'une nouvelle propriété pour le noeud. */
static void g_scan_token_node_choice_apply_flags(GScanTokenNodeChoice *, ScanTokenNodeFlags);
@@ -55,13 +61,16 @@ static void g_scan_token_node_choice_apply_flags(GScanTokenNodeChoice *, ScanTok
static void g_scan_token_node_choice_visit(GScanTokenNodeChoice *, scan_tree_points_t *);
/* Inscrit la définition d'un motif dans un moteur de recherche. */
-static bool g_scan_token_node_choice_enroll(GScanTokenNodeChoice *, GScanContext *, GEngineBackend *, size_t, size_t *);
+static bool g_scan_token_node_choice_enroll(GScanTokenNodeChoice *, GEngineBackend *, size_t, size_t *);
+
+/* Récupère un identifiant final pour un atome d'octets. */
+static bool g_scan_token_node_choice_build_id(GScanTokenNodeChoice *, GEngineBackend *);
/* Transforme les correspondances locales en trouvailles. */
-static void g_scan_token_node_choice_check_forward(const GScanTokenNodeChoice *, GScanContext *, GBinContent *, pending_matches_t *, node_search_offset_t *, bool, bool *);
+static void g_scan_token_node_choice_check_forward(const GScanTokenNodeChoice *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
/* Transforme les correspondances locales en trouvailles. */
-static void g_scan_token_node_choice_check_backward(const GScanTokenNodeChoice *, GScanContext *, GBinContent *, pending_matches_t *, node_search_offset_t *, bool, bool *);
+static void g_scan_token_node_choice_check_backward(const GScanTokenNodeChoice *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
@@ -98,9 +107,11 @@ static void g_scan_token_node_choice_class_init(GScanTokenNodeChoiceClass *klass
node = G_SCAN_TOKEN_NODE_CLASS(klass);
+ node->compute_weight = (compute_scan_token_node_weight_fc)g_scan_token_node_choice_compute_weight_for_scan;
node->apply = (apply_scan_token_node_flags_fc)g_scan_token_node_choice_apply_flags;
node->visit = (visit_scan_token_node_fc)g_scan_token_node_choice_visit;
node->enroll = (enroll_scan_token_node_fc)g_scan_token_node_choice_enroll;
+ node->build_id = (build_scan_token_node_id_fc)g_scan_token_node_choice_build_id;
node->check_forward = (check_scan_token_node_fc)g_scan_token_node_choice_check_forward;
node->check_backward = (check_scan_token_node_fc)g_scan_token_node_choice_check_backward;
@@ -227,6 +238,51 @@ void g_scan_token_node_choice_add(GScanTokenNodeChoice *choice, GScanTokenNode *
/******************************************************************************
* *
+* Paramètres : node = noeud de motif à consulter. *
+* *
+* Description : Communique l'intérêt d'un noeud au sein d'une analyse. *
+* *
+* Retour : Poids de l'importance pour un départ de scan. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static float g_scan_token_node_choice_compute_weight_for_scan(const GScanTokenNodeChoice *node)
+{
+ float result; /* Valeur à retourner */
+ size_t weight_count; /* Nombre de comptabilisations */
+ size_t i; /* Boucle de parcours */
+ float weight; /* Nouveau poids à intégrer */
+
+ result = 0;
+
+ weight_count = 0;
+
+ for (i = 0; i < node->count; i++)
+ {
+ weight = g_scan_token_node_compute_weight_for_scan(node->children[i]);
+
+ if (weight > 0)
+ {
+ result += weight;
+ weight_count++;
+ }
+
+ }
+
+ if (weight_count != node->count)
+ result = 0;
+ else
+ result /= weight_count;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : node = noeud de motif à mettre à jour. *
* flags = propriétés particulières à associer au noeud. *
* *
@@ -274,9 +330,6 @@ static void g_scan_token_node_choice_visit(GScanTokenNodeChoice *node, scan_tree
for (i = 0; i < node->count; i++)
{
- tmp_points.first_node = NULL;
- tmp_points.last_node = NULL;
-
tmp_points.first_plain = NULL;
tmp_points.best_masked = NULL;
@@ -296,7 +349,6 @@ static void g_scan_token_node_choice_visit(GScanTokenNodeChoice *node, scan_tree
/******************************************************************************
* *
* Paramètres : node = définition de la bribe à enregistrer. *
-* context = contexte de l'analyse à mener. *
* backend = moteur de recherche à préchauffer. *
* maxsize = taille max. des atomes (mise en commun optimisée). *
* slow = niveau de ralentissement induit (0 = idéal). [OUT] *
@@ -309,7 +361,7 @@ static void g_scan_token_node_choice_visit(GScanTokenNodeChoice *node, scan_tree
* *
******************************************************************************/
-static bool g_scan_token_node_choice_enroll(GScanTokenNodeChoice *node, GScanContext *context, GEngineBackend *backend, size_t maxsize, size_t *slow)
+static bool g_scan_token_node_choice_enroll(GScanTokenNodeChoice *node, GEngineBackend *backend, size_t maxsize, size_t *slow)
{
bool result; /* Statut à retourner */
size_t i; /* Boucle de parcours */
@@ -317,7 +369,7 @@ static bool g_scan_token_node_choice_enroll(GScanTokenNodeChoice *node, GScanCon
result = true;
for (i = 0; i < node->count && result; i++)
- result = _g_scan_token_node_enroll(node->children[i], context, backend, maxsize, slow);
+ result = _g_scan_token_node_enroll(node->children[i], backend, maxsize, slow);
return result;
@@ -326,13 +378,38 @@ static bool g_scan_token_node_choice_enroll(GScanTokenNodeChoice *node, GScanCon
/******************************************************************************
* *
-* Paramètres : node = définition de la bribe à manipuler. *
-* context = contexte de l'analyse à mener. *
-* content = accès au contenu brut pour vérifications (optim.) *
-* matches = suivi des correspondances à consolider. *
-* offset = tolérance dans les positions à appliquer. *
-* not = indique si les résultats doivent être inversés. *
-* skip = détermine si l'analyse est différée. [OUT] *
+* Paramètres : node = définition de la bribe à peaufiner. *
+* backend = moteur de recherche à préchauffer. *
+* *
+* Description : Récupère un identifiant final pour un atome d'octets. *
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_node_choice_build_id(GScanTokenNodeChoice *node, GEngineBackend *backend)
+{
+ bool result; /* Statut à retourner */
+ size_t i; /* Boucle de parcours #1 */
+
+ result = true;
+
+ for (i = 0; i < node->count && result; i++)
+ result = g_scan_token_node_build_id(node->children[i], backend);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
* *
* Description : Transforme les correspondances locales en trouvailles. *
* *
@@ -342,78 +419,117 @@ static bool g_scan_token_node_choice_enroll(GScanTokenNodeChoice *node, GScanCon
* *
******************************************************************************/
-static void g_scan_token_node_choice_check_forward(const GScanTokenNodeChoice *node, GScanContext *context, GBinContent *content, pending_matches_t *matches, node_search_offset_t *offset, bool not, bool *skip)
+static void g_scan_token_node_choice_check_forward(const GScanTokenNodeChoice *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
{
- pending_matches_t init_matches; /* Correspondances initiales */
- node_search_offset_t init_offset; /* Intervales initiaux */
- size_t new_offset; /* Décompte d'intervales */
+ bool initialized; /* Initialisation du suivi ? */
+ match_area_t *collected_areas; /* Zones mises en place ici */
+ size_t collected_count; /* Quantité de ces zones */
+ TokenNodeCheckFlags local_cflags; /* Particularités nouvelles */
size_t i; /* Boucle de parcours */
- pending_matches_t tmp_matches; /* Copie locale de travail #1 */
- node_search_offset_t tmp_offset; /* Copie locale de travail #2 */
+ scan_node_check_params_t local_params; /* Rassemblement de paramètres */
+
+ if (0x1) printf("=================== CHECK :: %s (skip? %d)\n", __FUNCTION__, *skip);
if (*skip)
return;
- /* Copie des contextes de départ */
+ /* Lancement des sous-traitements */
- copy_pending_matches(&init_matches, matches);
+ initialized = false;
- exit_pending_matches(matches);
- init_pending_matches(matches, &init_matches.content_start, &init_matches.content_end);
+ collected_areas = NULL;
+ collected_count = 0;
- copy_node_search_offset(&init_offset, offset);
+ local_cflags = (cflags & ~TNCF_UPDATE_IN_PLACE) | TNCF_CREATE_NEW;
- exit_node_search_offset(offset);
- init_node_search_offset(offset);
+ for (i = 0; i < node->count; i++)
+ {
+ local_params = *params;
- /* Lancement des sous-traitements */
+ local_params.created_areas = NULL;
+ local_params.created_count = 0;
- new_offset = 0;
+ local_params.kept_areas = NULL;
+ local_params.kept_count = 0;
- for (i = 0; i < node->count; i++)
- {
- copy_pending_matches(&tmp_matches, &init_matches);
- copy_node_search_offset(&tmp_offset, &init_offset);
+ if ((cflags & TNCF_CREATE_NEW) == 0 && (i + 1) == node->count)
+ local_cflags = cflags;
+
+ _g_scan_token_node_check_forward(node->children[i], &local_params, local_cflags, skip);
- _g_scan_token_node_check_forward(node->children[i], context, content,
- &tmp_matches, &tmp_offset, not, skip);
+ initialized |= local_params.initialized;
- merge_pending_matches(matches, &tmp_matches);
- merge_node_search_offset(offset, &tmp_offset);
+ if (local_cflags & TNCF_KEEP_DISCARDED)
+ {
+ merge_match_areas(&collected_areas, &local_params.kept_areas);
+ collected_count += local_params.kept_count;
+ }
- if (tmp_offset.used > 0)
- new_offset++;
+ else if (local_cflags & TNCF_CREATE_NEW)
+ {
+ merge_match_areas(&collected_areas, &local_params.created_areas);
+ collected_count += local_params.created_count;
+ }
- exit_pending_matches(&tmp_matches);
- exit_node_search_offset(&tmp_offset);
+ else
+ {
+ assert(local_cflags & TNCF_UPDATE_IN_PLACE);
+
+ merge_match_areas(&collected_areas, &local_params.main_areas);
+ collected_count += local_params.main_count;
+
+ }
}
- /* Sortie propre */
+ /* Enregistrement des résultats finaux */
- exit_pending_matches(&init_matches);
- exit_node_search_offset(&init_offset);
+ if (collected_count > 1)
+ sort_match_areas_no_dup(&collected_areas, &collected_count, compare_match_area_as_dl_item, NULL);
- /* "Alternative" directe en cas de motif(s) non terminé(s) par un intervale */
+ if (0x1) printf("[%s] collected: #%zu (bis)\n", __FUNCTION__, collected_count);
- if (new_offset != node->count)
+ params->initialized = initialized;
+
+ if (cflags & TNCF_KEEP_DISCARDED)
{
- assert(node->count > 1);
- add_range_to_node_search_offset(offset, 0, 0, NULL);
+ params->kept_areas = collected_areas;
+ params->kept_count = collected_count;
}
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ params->created_areas = collected_areas;
+ params->created_count = collected_count;
+ }
+
+ else
+ {
+ assert(cflags & TNCF_UPDATE_IN_PLACE);
+
+ params->main_areas = collected_areas;
+ params->main_count = collected_count;
+
+ }
+
+
+
+
+
+ /// TODO : gestion des offets en sortie : ajout (+ ajout d'un test en Python)
+
+
+
+
}
/******************************************************************************
* *
-* Paramètres : node = définition de la bribe à manipuler. *
-* context = contexte de l'analyse à mener. *
-* content = accès au contenu brut pour vérifications (optim.) *
-* matches = suivi des correspondances à consolider. *
-* offsets = tolérance dans les positions à appliquer. *
-* not = indique si les résultats doivent être inversés. *
-* skip = détermine si l'analyse est différée. [OUT] *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
* *
* Description : Transforme les correspondances locales en trouvailles. *
* *
@@ -423,64 +539,108 @@ static void g_scan_token_node_choice_check_forward(const GScanTokenNodeChoice *n
* *
******************************************************************************/
-static void g_scan_token_node_choice_check_backward(const GScanTokenNodeChoice *node, GScanContext *context, GBinContent *content, pending_matches_t *matches, node_search_offset_t *offset, bool not, bool *skip)
+static void g_scan_token_node_choice_check_backward(const GScanTokenNodeChoice *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
{
- pending_matches_t init_matches; /* Correspondances initiales */
- node_search_offset_t init_offset; /* Intervales initiaux */
- size_t new_offset; /* Décompte d'intervales */
+ match_area_t *collected_areas; /* Zones mises en place ici */
+ size_t collected_count; /* Quantité de ces zones */
+ TokenNodeCheckFlags local_cflags; /* Particularités nouvelles */
size_t i; /* Boucle de parcours */
- pending_matches_t tmp_matches; /* Copie locale de travail #1 */
- node_search_offset_t tmp_offset; /* Copie locale de travail #2 */
+ scan_node_check_params_t local_params; /* Rassemblement de paramètres */
+
+ if (0x1) printf("=================== CHECK :: %s (skip? %d)\n", __FUNCTION__, *skip);
if (*skip)
return;
- /* Copie des contextes de départ */
+ /**
+ * En lecture à rebourd, au moins un noeud a été solicité pour analyse (lors
+ * du sens de lecture normal). Donc l'initialisation a déjà dû avoir lieu.
+ */
- copy_pending_matches(&init_matches, matches);
-
- exit_pending_matches(matches);
- init_pending_matches(matches, &init_matches.content_start, &init_matches.content_end);
-
- copy_node_search_offset(&init_offset, offset);
-
- exit_node_search_offset(offset);
- init_node_search_offset(offset);
+ assert(params->initialized);
/* Lancement des sous-traitements */
- new_offset = 0;
+ collected_areas = NULL;
+ collected_count = 0;
+
+ local_cflags = (cflags & ~TNCF_UPDATE_IN_PLACE) | TNCF_CREATE_NEW;
for (i = 0; i < node->count; i++)
{
- copy_pending_matches(&tmp_matches, &init_matches);
- copy_node_search_offset(&tmp_offset, &init_offset);
+ local_params = *params;
+
+ local_params.created_areas = NULL;
+ local_params.created_count = 0;
+
+ local_params.kept_areas = NULL;
+ local_params.kept_count = 0;
+
+ if ((cflags & TNCF_CREATE_NEW) == 0 && (i + 1) == node->count)
+ local_cflags = cflags;
- _g_scan_token_node_check_backward(node->children[i], context, content,
- &tmp_matches, &tmp_offset, not, skip);
+ _g_scan_token_node_check_backward(node->children[i], &local_params, local_cflags, skip);
- merge_pending_matches(matches, &tmp_matches);
- merge_node_search_offset(offset, &tmp_offset);
+ if (local_cflags & TNCF_KEEP_DISCARDED)
+ {
+ merge_match_areas(&collected_areas, &local_params.kept_areas);
+ collected_count += local_params.kept_count;
+ }
- if (tmp_offset.used > 0)
- new_offset++;
+ else if (local_cflags & TNCF_CREATE_NEW)
+ {
+ merge_match_areas(&collected_areas, &local_params.created_areas);
+ collected_count += local_params.created_count;
+ }
- exit_pending_matches(&tmp_matches);
- exit_node_search_offset(&tmp_offset);
+ else
+ {
+ assert(local_cflags & TNCF_UPDATE_IN_PLACE);
+
+ merge_match_areas(&collected_areas, &local_params.main_areas);
+ collected_count += local_params.main_count;
+
+ }
}
- /* Sortie propre */
+ /* Enregistrement des résultats finaux */
- exit_pending_matches(&init_matches);
- exit_node_search_offset(&init_offset);
+ if (collected_count > 1)
+ sort_match_areas_no_dup(&collected_areas, &collected_count, compare_match_area_as_dl_item, NULL);
- /* "Alternative" directe en cas de motif(s) non terminé(s) par un intervale */
+ if (0x1) printf("[%s] collected: #%zu (bis)\n", __FUNCTION__, collected_count);
- if (new_offset != node->count)
+ if (cflags & TNCF_KEEP_DISCARDED)
{
- assert(node->count > 1);
- add_range_to_node_search_offset(offset, 0, 0, NULL);
+ params->kept_areas = collected_areas;
+ params->kept_count = collected_count;
}
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ params->created_areas = collected_areas;
+ params->created_count = collected_count;
+ }
+
+ else
+ {
+ assert(cflags & TNCF_UPDATE_IN_PLACE);
+
+ params->main_areas = collected_areas;
+ params->main_count = collected_count;
+
+ }
+
+
+
+
+
+ /// TODO : gestion des offets en sortie : ajout (+ ajout d'un test en Python)
+
+
+
+
+
+
}