summaryrefslogtreecommitdiff
path: root/plugins/yaml/node.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-12-11 00:01:03 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-12-11 00:01:03 (GMT)
commit700425c7d1e884882603eb49cec2a6a6c4118686 (patch)
treecc451fbd6d0611edf49e1c4368adc8c1a8ef30b0 /plugins/yaml/node.c
parent48395d4471d87c20bdbd06bbab1ae3af938ff823 (diff)
Improved the search of Yaml nodes.
Diffstat (limited to 'plugins/yaml/node.c')
-rw-r--r--plugins/yaml/node.c257
1 files changed, 23 insertions, 234 deletions
diff --git a/plugins/yaml/node.c b/plugins/yaml/node.c
index e2abeca..9c815d6 100644
--- a/plugins/yaml/node.c
+++ b/plugins/yaml/node.c
@@ -1,6 +1,6 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * node.c - ligne de contenu Yaml
+ * node.c - définition de noeud Yaml
*
* Copyright (C) 2019 Cyrille Bagard
*
@@ -24,32 +24,13 @@
#include "node.h"
-#include <malloc.h>
#include <string.h>
-#include "collection.h"
+#include "node-int.h"
-/* Noeud d'une arborescence au format Yaml (instance) */
-struct _GYamlNode
-{
- GObject parent; /* A laisser en premier */
-
- GYamlLine *key; /* Clef principale du noeud */
- GYamlCollection *collection; /* Collection de noeuds */
-
-};
-
-/* Noeud d'une arborescence au format Yaml (classe) */
-struct _GYamlNodeClass
-{
- GObjectClass parent; /* A laisser en premier */
-
-};
-
-
/* Initialise la classe des noeuds d'arborescence Yaml. */
static void g_yaml_node_class_init(GYamlNodeClass *);
@@ -106,8 +87,6 @@ static void g_yaml_node_class_init(GYamlNodeClass *klass)
static void g_yaml_node_init(GYamlNode *node)
{
- node->key = NULL;
- node->collection = NULL;
}
@@ -126,10 +105,6 @@ static void g_yaml_node_init(GYamlNode *node)
static void g_yaml_node_dispose(GYamlNode *node)
{
- g_clear_object(&node->key);
-
- g_clear_object(&node->collection);
-
G_OBJECT_CLASS(g_yaml_node_parent_class)->dispose(G_OBJECT(node));
}
@@ -156,121 +131,11 @@ static void g_yaml_node_finalize(GYamlNode *node)
/******************************************************************************
* *
-* Paramètres : key = line Yaml représentant la clef du futur noeud. *
-* *
-* Description : Construit un noeud d'arborescence Yaml. *
-* *
-* Retour : Instance mise en place ou NULL en cas d'échec. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GYamlNode *g_yaml_node_new(GYamlLine *key)
-{
- GYamlNode *result; /* Structure à retourner */
-
- result = g_object_new(G_TYPE_YAML_NODE, NULL);
-
- /**
- * Le paragraphe "3.2.2.1. Keys Order" des spécifications précise
- * qu'une séquence n'est qu'un noeud sans correspondance clef/valeur.
- *
- * Cette situation doit donc être prise en compte.
- */
-
- if (key != NULL)
- {
- result->key = key;
- g_object_ref(G_OBJECT(key));
- }
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : node = noeud d'arborescence Yaml à consulter. *
-* *
-* Description : Fournit la ligne principale associée à un noeud. *
-* *
-* Retour : Ligne Yaml à l'origine du noeud. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GYamlLine *g_yaml_node_get_yaml_line(const GYamlNode *node)
-{
- GYamlLine *result; /* Ligne d'origine à renvoyer */
-
- result = node->key;
-
- if (result != NULL)
- g_object_ref(G_OBJECT(result));
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : node = noeud d'arborescence Yaml à compléter. *
-* collec = collection de noeuds Yaml. *
-* *
-* Description : Attache une collection de noeuds Yaml à un noeud. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_yaml_node_set_collection(GYamlNode *node, GYamlCollection *collec)
-{
- g_clear_object(&node->collection);
-
- g_object_ref_sink(G_OBJECT(collec));
- node->collection = collec;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : node = noeud d'arborescence Yaml à consulter. *
-* *
-* Description : Fournit une éventuelle collection rattachée à un noeud. *
-* *
-* Retour : Collection de noeuds Yaml ou NULL. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GYamlCollection *g_yaml_node_get_collection(const GYamlNode *node)
-{
- GYamlCollection *result; /* Collection à renvoyer */
-
- result = node->collection;
-
- if (result != NULL)
- g_object_ref(G_OBJECT(result));
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : node = noeud d'arborescence Yaml à consulter. *
-* path = chemin d'accès à parcourir. *
-* nodes = liste de noeuds avec correspondance établie. [OUT] *
-* count = quantité de ces noeuds. [OUT] *
+* Paramètres : node = noeud d'arborescence Yaml à consulter. *
+* path = chemin d'accès à parcourir. *
+* prepare = indication sur une préparation d'un prochain appel.*
+* nodes = liste de noeuds avec correspondance établie. [OUT] *
+* count = quantité de ces noeuds. [OUT] *
* *
* Description : Recherche les noeuds correspondant à un chemin. *
* *
@@ -280,101 +145,24 @@ GYamlCollection *g_yaml_node_get_collection(const GYamlNode *node)
* *
******************************************************************************/
-void _g_yaml_node_find_by_path(GYamlNode *node, const char *path, GYamlNode ***nodes, size_t *count)
+void _g_yaml_node_find_by_path(GYamlNode *node, const char *path, bool prepare, GYamlNode ***nodes, size_t *count)
{
- GYamlLine *line; /* Ligne Yaml liée au noeud */
- const char *key; /* Clef associée au noeud */
- char *next; /* Prochaine partie du chemin */
- size_t cmplen; /* Etendue de la comparaison */
- int ret; /* Bilan d'une comparaison */
- GYamlCollection *collec; /* Collection de noeuds */
-
- if (path[0] == '\0')
- goto exit;
-
- line = g_yaml_node_get_yaml_line(node);
-
- if (path[0] == '/')
- {
- path++;
-
- if (path[0] == '\0')
- goto matched;
-
- }
-
- /* Correspondance au niveau du noeud ? */
-
- if (line != NULL)
- {
- key = g_yaml_line_get_key(line);
-
- next = strchr(path, '/');
-
- if (next == NULL)
- ret = strcmp(path, key);
-
- else
- {
- cmplen = next - path;
-
- if (cmplen == 0)
- goto cont;
-
- ret = strncmp(path, key, cmplen);
-
- }
-
- if (ret != 0)
- goto done;
-
- else if (next != NULL)
- {
- path += cmplen;
- goto cont;
- }
-
- matched:
-
- *nodes = realloc(*nodes, ++(*count) * sizeof(GYamlNode **));
-
- g_object_ref(G_OBJECT(node));
- (*nodes)[*count - 1] = node;
-
- goto done;
-
- }
-
- cont:
-
- collec = g_yaml_node_get_collection(node);
-
- if (collec != NULL)
- {
- _g_yaml_collection_find_by_path(collec, path, nodes, count);
-
- g_object_unref(G_OBJECT(collec));
-
- }
-
- done:
-
- if (line != NULL)
- g_object_unref(G_OBJECT(line));
+ GYamlNodeClass *class; /* Classe de l'instance */
- exit:
+ class = G_YAML_NODE_GET_CLASS(node);
- ;
+ class->find(node, path, prepare, nodes, count);
}
/******************************************************************************
* *
-* Paramètres : node = noeud d'arborescence Yaml à consulter. *
-* path = chemin d'accès à parcourir. *
-* nodes = liste de noeuds avec correspondance établie. [OUT] *
-* count = quantité de ces noeuds. [OUT] *
+* Paramètres : node = noeud d'arborescence Yaml à consulter. *
+* path = chemin d'accès à parcourir. *
+* prepare = indication sur une préparation d'un prochain appel.*
+* nodes = liste de noeuds avec correspondance établie. [OUT] *
+* count = quantité de ces noeuds. [OUT] *
* *
* Description : Recherche les noeuds correspondant à un chemin. *
* *
@@ -384,20 +172,21 @@ void _g_yaml_node_find_by_path(GYamlNode *node, const char *path, GYamlNode ***n
* *
******************************************************************************/
-void g_yaml_node_find_by_path(GYamlNode *node, const char *path, GYamlNode ***nodes, size_t *count)
+void g_yaml_node_find_by_path(GYamlNode *node, const char *path, bool prepare, GYamlNode ***nodes, size_t *count)
{
*nodes = NULL;
*count = 0;
- _g_yaml_node_find_by_path(node, path, nodes, count);
+ _g_yaml_node_find_by_path(node, path, prepare, nodes, count);
}
/******************************************************************************
* *
-* Paramètres : node = noeud d'arborescence Yaml à consulter. *
-* path = chemin d'accès à parcourir. *
+* Paramètres : node = noeud d'arborescence Yaml à consulter. *
+* path = chemin d'accès à parcourir. *
+* prepare = indication sur une préparation d'un prochain appel.*
* *
* Description : Recherche l'unique noeud correspondant à un chemin. *
* *
@@ -407,14 +196,14 @@ void g_yaml_node_find_by_path(GYamlNode *node, const char *path, GYamlNode ***no
* *
******************************************************************************/
-GYamlNode *g_yaml_node_find_one_by_path(GYamlNode *node, const char *path)
+GYamlNode *g_yaml_node_find_one_by_path(GYamlNode *node, const char *path, bool prepare)
{
GYamlNode *result; /* Trouvaille unique à renvoyer*/
GYamlNode **nodes; /* Liste de noeuds trouvés */
size_t count; /* Taille de cette liste */
size_t i; /* Boucle de parcours */
- g_yaml_node_find_by_path(node, path, &nodes, &count);
+ g_yaml_node_find_by_path(node, path, prepare, &nodes, &count);
if (count == 1)
{