summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-10-12 16:21:03 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-10-12 16:25:05 (GMT)
commit986125d4c2d8b049017b6d0770f16b9058076165 (patch)
treec89e6b7967a731e68d72f6d5a2150b0347db4ef3 /src
parent96afc0325e1c85bf1a76d63c6441cf8f044708fe (diff)
Defined a new type dedicated to snapshot identifiers.
Diffstat (limited to 'src')
-rw-r--r--src/analysis/db/cdb.c25
-rw-r--r--src/analysis/db/misc/Makefile.am1
-rw-r--r--src/analysis/db/misc/snapshot.c217
-rw-r--r--src/analysis/db/misc/snapshot.h82
-rw-r--r--src/analysis/db/misc/timestamp.c4
-rw-r--r--src/analysis/db/snapshot.c140
-rw-r--r--src/analysis/db/snapshot.h5
7 files changed, 404 insertions, 70 deletions
diff --git a/src/analysis/db/cdb.c b/src/analysis/db/cdb.c
index e03b875..2013750 100644
--- a/src/analysis/db/cdb.c
+++ b/src/analysis/db/cdb.c
@@ -297,7 +297,10 @@ GCdbArchive *g_cdb_archive_new(const char *basedir, const char *tmpdir, const rl
GCdbArchive *result; /* Adresse à retourner */
int ret; /* Retour d'un appel */
struct stat finfo; /* Information sur l'archive */
- const char *id; /* Identifiant d'instantané */
+ snapshot_id_t id; /* Identifiant d'instantané */
+#ifndef NDEBUG
+ bool status; /* Validité de l'identifiant */
+#endif
result = g_object_new(G_TYPE_CDB_ARCHIVE, NULL);
@@ -343,10 +346,14 @@ GCdbArchive *g_cdb_archive_new(const char *basedir, const char *tmpdir, const rl
/* Récupération de la base courante */
- id = g_db_snapshot_get_current_id(result->snapshot);
- assert(id != NULL);
+#ifndef NDEBUG
+ status = g_db_snapshot_get_current_id(result->snapshot, &id);
+ assert(status);
+#else
+ g_db_snapshot_get_current_id(result->snapshot, &id);
+#endif
- result->db = g_db_snapshot_get_database(result->snapshot, id);
+ result->db = g_db_snapshot_get_database(result->snapshot, &id);
if (result->db == NULL)
{
@@ -372,10 +379,14 @@ GCdbArchive *g_cdb_archive_new(const char *basedir, const char *tmpdir, const rl
/* Récupération de la base courante */
- id = g_db_snapshot_get_current_id(result->snapshot);
- assert(id != NULL);
+#ifndef NDEBUG
+ status = g_db_snapshot_get_current_id(result->snapshot, &id);
+ assert(status);
+#else
+ g_db_snapshot_get_current_id(result->snapshot, &id);
+#endif
- result->db = g_db_snapshot_get_database(result->snapshot, id);
+ result->db = g_db_snapshot_get_database(result->snapshot, &id);
if (result->db == NULL)
{
diff --git a/src/analysis/db/misc/Makefile.am b/src/analysis/db/misc/Makefile.am
index ebe92e1..c702145 100644
--- a/src/analysis/db/misc/Makefile.am
+++ b/src/analysis/db/misc/Makefile.am
@@ -3,6 +3,7 @@ noinst_LTLIBRARIES = libanalysisdbmisc.la
libanalysisdbmisc_la_SOURCES = \
rlestr.h rlestr.c \
+ snapshot.h snapshot.c \
timestamp.h timestamp.c
libanalysisdbmisc_la_LIBADD =
diff --git a/src/analysis/db/misc/snapshot.c b/src/analysis/db/misc/snapshot.c
new file mode 100644
index 0000000..982553b
--- /dev/null
+++ b/src/analysis/db/misc/snapshot.c
@@ -0,0 +1,217 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * snapshot.c - encodage des informations utiles aux instantanés
+ *
+ * Copyright (C) 2019 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "snapshot.h"
+
+
+#include <string.h>
+#include <openssl/rand.h>
+
+
+#include "../../../core/logs.h"
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IDENTIFIANTS DES INSTANTANES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : id = identifiant d'instantané à initialiser. [OUT] *
+* *
+* Description : Construit un identifiant pour instantané de base de données. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool init_snapshot_id(snapshot_id_t *id)
+{
+ bool result; /* Bilan à retourner */
+ int ret; /* Bilan d'une génération */
+ unsigned char rand[SNAP_ID_RAND_SZ]; /* Tirage aléatoire */
+ size_t i; /* Boucle de parcours */
+
+ static char *alphabet = "0123456789abcdef";
+
+ ret = RAND_bytes(rand, SNAP_ID_RAND_SZ);
+
+ if (ret != 1)
+ {
+ LOG_ERROR_OPENSSL;
+ result = false;
+ }
+
+ else
+ {
+ for (i = 0; i < SNAP_ID_RAND_SZ; i++)
+ {
+ id->name[i * 2 + 0] = alphabet[rand[i] & 0xf];
+ id->name[i * 2 + 1] = alphabet[(rand[i] >> 4) & 0xf];
+ }
+
+ id->name[i * 2] = '\0';
+
+ result = true;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : id = identifiant d'instantané à initialiser. [OUT] *
+* text = source de données pour la constitution. *
+* *
+* Description : Construit un identifiant pour instantané de base de données. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool init_snapshot_id_from_text(snapshot_id_t *id, const char *text)
+{
+ bool result; /* Bilan à retourner */
+
+ result = (strlen(text) == (SNAP_ID_HEX_SZ - 1));
+
+ if (result)
+ strcpy(id->name, text);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : dest = destination de la copie d'indentifiant. [OUT] *
+* src = source de l'identifiant à copier. *
+* *
+* Description : Effectue une copie d'identifiant d'instantané. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void copy_snapshot_id(snapshot_id_t *dest, const snapshot_id_t *src)
+{
+ memcpy(dest->name, src->name, SNAP_ID_HEX_SZ);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : id1 = premier identifiant à comparer. *
+* id2 = second identifiant à comparer. *
+* *
+* Description : Effectue la comparaison entre deux identifiants. *
+* *
+* Retour : Résultat de la comparaison : -1, 0 ou 1. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int cmp_snapshot_id(const snapshot_id_t *id1, const snapshot_id_t *id2)
+{
+ int result; /* Bilan à retourner */
+
+ result = memcmp(id1->name, id2->name, SNAP_ID_HEX_SZ);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : id = informations à constituer. [OUT] *
+* pbuf = paquet de données où venir puiser les infos. *
+* *
+* Description : Importe la définition d'un identifiant d'instantané. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool unpack_snapshot_id(snapshot_id_t *id, packed_buffer *pbuf)
+{
+ bool result; /* Bilan à retourner */
+
+ result = extract_packed_buffer(pbuf, id->name, SNAP_ID_HEX_SZ, false);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : id = informations à sauvegarer. *
+* pbuf = paquet de données où venir inscrire les infos. *
+* *
+* Description : Exporte la définition d'un identifiant d'instantané. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool pack_snapshot_id(const snapshot_id_t *id, packed_buffer *pbuf)
+{
+ bool result; /* Bilan à retourner */
+
+ result = extend_packed_buffer(pbuf, id->name, SNAP_ID_HEX_SZ, false);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* PROPRIETES DES INSTANTANES */
+/* ---------------------------------------------------------------------------------- */
+
+
+
+
+
+
+
diff --git a/src/analysis/db/misc/snapshot.h b/src/analysis/db/misc/snapshot.h
new file mode 100644
index 0000000..4aaa6f9
--- /dev/null
+++ b/src/analysis/db/misc/snapshot.h
@@ -0,0 +1,82 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * snapshot.h - prototypes pour l'encodage des informations utiles aux instantanés
+ *
+ * Copyright (C) 2019 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_DB_MISC_SNAPSHOT_H
+#define _ANALYSIS_DB_MISC_SNAPSHOT_H
+
+
+#include <stdbool.h>
+#include <stdint.h>
+
+
+#include "../../../common/packed.h"
+
+
+
+/* -------------------------- IDENTIFIANTS DES INSTANTANES -------------------------- */
+
+
+#define SNAP_ID_RAND_SZ 32
+#define SNAP_ID_HEX_SZ (SNAP_ID_RAND_SZ * 2 + 1)
+
+/* Représentation d'un instantané */
+typedef struct _snapshot_id_t
+{
+ char name[SNAP_ID_HEX_SZ];
+
+} snapshot_id_t;
+
+
+/* Construit un identifiant pour instantané de base de données. */
+bool init_snapshot_id(snapshot_id_t *);
+
+/* Construit un identifiant pour instantané de base de données. */
+bool init_snapshot_id_from_text(snapshot_id_t *, const char *);
+
+#define snapshot_id_as_string(id) (id)->name
+
+/* Effectue une copie d'identifiant d'instantané. */
+void copy_snapshot_id(snapshot_id_t *, const snapshot_id_t *);
+
+/* Effectue la comparaison entre deux identifiants. */
+int cmp_snapshot_id(const snapshot_id_t *, const snapshot_id_t *);
+
+/* Importe la définition d'un identifiant d'instantané. */
+bool unpack_snapshot_id(snapshot_id_t *, packed_buffer *);
+
+/* Exporte la définition d'un identifiant d'instantané. */
+bool pack_snapshot_id(const snapshot_id_t *, packed_buffer *);
+
+
+
+/* --------------------------- PROPRIETES DES INSTANTANES --------------------------- */
+
+
+
+
+
+
+
+
+
+#endif /* _ANALYSIS_DB_MISC_SNAPSHOT_H */
diff --git a/src/analysis/db/misc/timestamp.c b/src/analysis/db/misc/timestamp.c
index 6453953..12299eb 100644
--- a/src/analysis/db/misc/timestamp.c
+++ b/src/analysis/db/misc/timestamp.c
@@ -79,8 +79,8 @@ bool timestamp_is_younger(timestamp_t stamp, timestamp_t limit)
/******************************************************************************
* *
-* Paramètres : t1 = première chaîne à comparer. *
-* t2 = seconde chaîne à comparer. *
+* Paramètres : t1 = premier horodatage à comparer. *
+* t2 = second horodatage à comparer. *
* *
* Description : Effectue la comparaison entre deux horodatages. *
* *
diff --git a/src/analysis/db/snapshot.c b/src/analysis/db/snapshot.c
index d75ac49..a5b7280 100644
--- a/src/analysis/db/snapshot.c
+++ b/src/analysis/db/snapshot.c
@@ -29,7 +29,6 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <openssl/rand.h>
#include <i18n.h>
@@ -55,7 +54,7 @@ typedef struct _snapshot_node_t
char *name; /* Nom de l'instantané */
char *desc; /* Description associée */
- char *id; /* Identifiant attribué */
+ snapshot_id_t id; /* Identifiant attribué */
char *path; /* Fichier extrait */
struct _snapshot_node_t **children; /* Sous-noeuds rattachés */
@@ -65,7 +64,7 @@ typedef struct _snapshot_node_t
/* Constitue un nouveau noeud d'instantané. */
-static snapshot_node_t *create_snapshot_node(const char *);
+static snapshot_node_t *create_snapshot_node(const snapshot_id_t *);
/* Libère la mémoire occupée par un noeud d'instantané. */
static void destroy_snapshot_node(snapshot_node_t *);
@@ -80,7 +79,7 @@ static bool check_snapshot_nodes(const snapshot_node_t *);
static DBError save_snapshot_node(const snapshot_node_t *, xmlDocPtr, xmlXPathContextPtr, struct archive *);
/* Recherche le noeud d'instantané lié à un identifiant. */
-static snapshot_node_t *find_snapshot_node(snapshot_node_t *, const char *);
+static snapshot_node_t *find_snapshot_node(snapshot_node_t *, const snapshot_id_t *);
/* Ajoute un instantané comme prolongement d'un instantané. */
static void add_snapshot_node(snapshot_node_t *, snapshot_node_t *);
@@ -145,36 +144,23 @@ static GDbSnapshot *g_db_snapshot_new(const char *, const char *);
* *
******************************************************************************/
-static snapshot_node_t *create_snapshot_node(const char *id)
+static snapshot_node_t *create_snapshot_node(const snapshot_id_t *id)
{
snapshot_node_t *result; /* Nouvel instantané à renvoyer*/
- int ret; /* Bilan d'une génération */
- unsigned char rand[32]; /* Tirage aléatoire */
- size_t i; /* Boucle de parcours */
- char _id[65]; /* Identifiant nouveau */
-
- static char *alphabet = "0123456789abcdef";
+ snapshot_id_t _id; /* Identifiant nouveau */
+ bool status; /* Bilan d'une génération */
if (id == NULL)
{
- ret = RAND_bytes(rand, sizeof(rand));
+ status = init_snapshot_id(&_id);
- if (ret != 1)
+ if (!status)
{
- LOG_ERROR_OPENSSL;
result = NULL;
goto exit;
}
- for (i = 0; i < sizeof(rand); i++)
- {
- _id[i * 2 + 0] = alphabet[rand[i] & 0xf];
- _id[i * 2 + 1] = alphabet[(rand[i] >> 4) & 0xf];
- }
-
- _id[64] = '\0';
-
- id = _id;
+ id = &_id;
}
@@ -185,7 +171,7 @@ static snapshot_node_t *create_snapshot_node(const char *id)
result->name = NULL;
result->desc = NULL;
- result->id = strdup(id);
+ copy_snapshot_id(&result->id, id);
result->path = NULL;
result->children = NULL;
@@ -224,8 +210,6 @@ static void destroy_snapshot_node(snapshot_node_t *node)
if (node->desc != NULL)
free(node->desc);
- free(node->id);
-
if (node->path != NULL)
{
ret = unlink(node->path);
@@ -262,7 +246,9 @@ static bool setup_snapshot_node_db_path(snapshot_node_t *node, const char *tmpdi
bool result; /* Bilan à retourner */
int ret; /* Bilan d'une génération */
- ret = asprintf(&node->path, "%s" G_DIR_SEPARATOR_S "%s_%s_db.sql", tmpdir, hash, node->id);
+ ret = asprintf(&node->path, "%s" G_DIR_SEPARATOR_S "%s_%s_db.sql",
+ tmpdir, hash, snapshot_id_as_string(&node->id));
+
result = (ret > 0);
if (result)
@@ -296,7 +282,8 @@ static bool check_snapshot_nodes(const snapshot_node_t *node)
result = (node->path != NULL);
if (!result)
- log_variadic_message(LMT_ERROR, _("Database is missing for snapshot '%s'"), node->id);
+ log_variadic_message(LMT_ERROR, _("Database is missing for snapshot '%s'"),
+ snapshot_id_as_string(&node->id));
for (i = 0; i < node->count && result; i++)
result = check_snapshot_nodes(node->children[i]);
@@ -333,7 +320,7 @@ static DBError save_snapshot_node(const snapshot_node_t *node, xmlDocPtr xdoc, x
/* Sauvegarde de la base de données */
- ret = asprintf(&name, "%s.db", node->id);
+ ret = asprintf(&name, "%s.db", snapshot_id_as_string(&node->id));
if (ret < 0)
{
@@ -382,7 +369,7 @@ static DBError save_snapshot_node(const snapshot_node_t *node, xmlDocPtr xdoc, x
goto exit;
}
- status = _add_string_attribute_to_node(xml_node, "id", node->id);
+ status = _add_string_attribute_to_node(xml_node, "id", snapshot_id_as_string(&node->id));
if (!status)
{
@@ -392,7 +379,7 @@ static DBError save_snapshot_node(const snapshot_node_t *node, xmlDocPtr xdoc, x
if (node->parent != NULL)
{
- status = _add_string_attribute_to_node(xml_node, "parent", node->parent->id);
+ status = _add_string_attribute_to_node(xml_node, "parent", snapshot_id_as_string(&node->parent->id));
if (!status)
{
@@ -429,12 +416,12 @@ static DBError save_snapshot_node(const snapshot_node_t *node, xmlDocPtr xdoc, x
* *
******************************************************************************/
-static snapshot_node_t *find_snapshot_node(snapshot_node_t *node, const char *id)
+static snapshot_node_t *find_snapshot_node(snapshot_node_t *node, const snapshot_id_t *id)
{
snapshot_node_t *result; /* Noeud trouvé à renvoyer */
size_t i; /* Boucle de parcours */
- if (strcmp(node->id, id) == 0)
+ if (cmp_snapshot_id(&node->id, id) == 0)
result = node;
else
@@ -697,9 +684,11 @@ GDbSnapshot *g_db_snapshot_new_from_xml(const char *tmpdir, const char *hash, xm
size_t count; /* Nombre de contenus premiers */
size_t i; /* Boucle de parcours */
xmlNodePtr xml_node; /* Noeud XML avec propriétés */
- char *parent_id; /* Identifiant de noeud parent */
+ char *raw_id; /* Identifiant brut à convertir*/
+ snapshot_id_t parent_id; /* Identifiant de noeud parent */
snapshot_node_t *parent; /* Instantané parent trouvé */
- char *node_id; /* Identifiant de noeud courant*/
+ snapshot_id_t node_id; /* Identifiant de noeud courant*/
+ bool status; /* Bilan d'une conversion */
snapshot_node_t *node; /* Instantané nouveau constitué*/
result = g_db_snapshot_new(tmpdir, hash);
@@ -714,33 +703,47 @@ GDbSnapshot *g_db_snapshot_new_from_xml(const char *tmpdir, const char *hash, xm
{
xml_node = NODE_FROM_PATH_OBJ(xobject, i);
- parent_id = qck_get_node_prop_value(xml_node, "parent");
+ raw_id = qck_get_node_prop_value(xml_node, "parent");
- if (parent_id == NULL)
+ if (raw_id == NULL)
parent = NULL;
else
{
if (result->nodes == NULL)
parent = NULL;
+
else
- parent = find_snapshot_node(result->nodes, parent_id);
+ {
+ status = init_snapshot_id_from_text(&node_id, raw_id);
+
+ if (status)
+ parent = find_snapshot_node(result->nodes, &parent_id);
+ else
+ parent = NULL;
- free(parent_id);
+ }
+
+ free(raw_id);
if (parent == NULL)
goto bad_xml;
}
- node_id = qck_get_node_prop_value(xml_node, "id");
+ raw_id = qck_get_node_prop_value(xml_node, "id");
- if (node_id == NULL)
+ if (raw_id == NULL)
goto bad_xml;
- node = create_snapshot_node(node_id);
+ status = init_snapshot_id_from_text(&node_id, raw_id);
+
+ free(raw_id);
- free(node_id);
+ if (!status)
+ goto bad_xml;
+
+ node = create_snapshot_node(&node_id);
if (node == NULL)
goto bad_xml;
@@ -763,14 +766,20 @@ GDbSnapshot *g_db_snapshot_new_from_xml(const char *tmpdir, const char *hash, xm
/* Détermination de l'instantané courant */
- node_id = get_node_text_value(context, "/ChrysalideBinary/CurrentSnapshot");
+ raw_id = get_node_text_value(context, "/ChrysalideBinary/CurrentSnapshot");
- if (node_id == NULL)
+ if (raw_id == NULL)
result->current = result->nodes;
+
else
{
- result->current = find_snapshot_node(result->nodes, node_id);
- free(node_id);
+ status = init_snapshot_id_from_text(&node_id, raw_id);
+
+ free(raw_id);
+
+ if (status)
+ result->current = find_snapshot_node(result->nodes, &node_id);
+
}
if (result->current == NULL)
@@ -812,7 +821,9 @@ bool g_db_snapshot_fill(GDbSnapshot *snap, struct archive *archive)
int ret; /* Bilan d'un appel */
const char *path; /* Désignation d'un fichier */
const char *dot; /* Début de l'extension */
- char *node_id; /* Identifiant de noeud */
+ char *raw_id; /* Identifiant brut à convertir*/
+ snapshot_id_t node_id; /* Identifiant de noeud courant*/
+ bool status; /* Bilan d'une conversion */
snapshot_node_t *node; /* Instantané trouvé */
result = false;
@@ -826,11 +837,16 @@ bool g_db_snapshot_fill(GDbSnapshot *snap, struct archive *archive)
if (!_endswith(path, ".db", &dot))
continue;
- node_id = strndup(path, dot - path);
+ raw_id = strndup(path, dot - path);
+
+ status = init_snapshot_id_from_text(&node_id, raw_id);
- node = find_snapshot_node(snap->nodes, node_id);
+ free(raw_id);
- free(node_id);
+ if (!status)
+ break;
+
+ node = find_snapshot_node(snap->nodes, &node_id);
if (!setup_snapshot_node_db_path(node, snap->tmpdir, snap->hash))
break;
@@ -877,7 +893,8 @@ DBError g_db_snapshot_save(const GDbSnapshot *snap, xmlDocPtr xdoc, xmlXPathCont
assert(snap->current != NULL);
- status = add_content_to_node(xdoc, context, "/ChrysalideBinary/CurrentSnapshot", snap->current->id);
+ status = add_content_to_node(xdoc, context, "/ChrysalideBinary/CurrentSnapshot",
+ snapshot_id_as_string(&snap->current->id));
if (!status)
result = DBE_XML_ERROR;
@@ -893,25 +910,30 @@ DBError g_db_snapshot_save(const GDbSnapshot *snap, xmlDocPtr xdoc, xmlXPathCont
/******************************************************************************
* *
* Paramètres : snap = gestionnaire d'instantanés à consulter. *
+* id = identifiant de l'instantané courant. [OUT] *
* *
* Description : Fournit l'identifiant de l'instanné courant. *
* *
-* Retour : Identifiant de l'instantané courant. *
+* Retour : Validité de la trouvaille. *
* *
* Remarques : - *
* *
******************************************************************************/
-const char *g_db_snapshot_get_current_id(const GDbSnapshot *snap)
+bool g_db_snapshot_get_current_id(const GDbSnapshot *snap, snapshot_id_t *id)
{
- char *result; /* Indentifiant à retourner */
+ bool result; /* Bilan à retourner */
assert(snap->current != NULL);
if (snap->current == NULL)
- result = NULL;
+ result = false;
+
else
- result = snap->current->id;
+ {
+ copy_snapshot_id(id, &snap->current->id);
+ result = true;
+ }
return result;
@@ -931,7 +953,7 @@ const char *g_db_snapshot_get_current_id(const GDbSnapshot *snap)
* *
******************************************************************************/
-sqlite3 *g_db_snapshot_get_database(const GDbSnapshot *snap, const char *id)
+sqlite3 *g_db_snapshot_get_database(const GDbSnapshot *snap, const snapshot_id_t *id)
{
sqlite3 *result; /* Base SQLite à retourner */
snapshot_node_t *node; /* Instantané trouvé */
@@ -941,7 +963,7 @@ sqlite3 *g_db_snapshot_get_database(const GDbSnapshot *snap, const char *id)
if (node == NULL)
{
- log_variadic_message(LMT_ERROR, _("Snapshot not found for id '%s'"), id);
+ log_variadic_message(LMT_ERROR, _("Snapshot not found for id '%s'"), *id);
result = NULL;
}
diff --git a/src/analysis/db/snapshot.h b/src/analysis/db/snapshot.h
index 452debd..f568ba3 100644
--- a/src/analysis/db/snapshot.h
+++ b/src/analysis/db/snapshot.h
@@ -34,6 +34,7 @@
#include "protocol.h"
+#include "misc/snapshot.h"
@@ -68,10 +69,10 @@ bool g_db_snapshot_fill(GDbSnapshot *, struct archive *);
DBError g_db_snapshot_save(const GDbSnapshot *, xmlDocPtr, xmlXPathContextPtr, struct archive *);
/* Fournit l'identifiant de l'instanné courant. */
-const char *g_db_snapshot_get_current_id(const GDbSnapshot *);
+bool g_db_snapshot_get_current_id(const GDbSnapshot *, snapshot_id_t *);
/* Fournit la base de données correspondant à instanné donné. */
-sqlite3 *g_db_snapshot_get_database(const GDbSnapshot *, const char *);
+sqlite3 *g_db_snapshot_get_database(const GDbSnapshot *, const snapshot_id_t *);