diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2019-10-19 12:50:37 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2019-10-19 12:50:37 (GMT) |
commit | d7c69bcb27a7d06932cd25021144b6cbbe4eb82f (patch) | |
tree | b014aa31a1c9d9ce4afddf505b727cabacf15e44 /src/analysis/db/misc | |
parent | bcdf953ef6616c404d013f3473fb12a7bf43440b (diff) |
Exchanged the list of all snapshots.
Diffstat (limited to 'src/analysis/db/misc')
-rw-r--r-- | src/analysis/db/misc/rlestr.c | 2 | ||||
-rw-r--r-- | src/analysis/db/misc/snapshot.c | 78 | ||||
-rw-r--r-- | src/analysis/db/misc/snapshot.h | 14 | ||||
-rw-r--r-- | src/analysis/db/misc/timestamp.c | 19 | ||||
-rw-r--r-- | src/analysis/db/misc/timestamp.h | 3 |
5 files changed, 108 insertions, 8 deletions
diff --git a/src/analysis/db/misc/rlestr.c b/src/analysis/db/misc/rlestr.c index 0fe182b..c1cc866 100644 --- a/src/analysis/db/misc/rlestr.c +++ b/src/analysis/db/misc/rlestr.c @@ -286,7 +286,7 @@ bool unpack_rle_string(rle_string *str, packed_buffer *pbuf) if (result && str->length > 0) { - str->data = (char *)malloc(str->length + 1); + str->data = malloc(str->length + 1); str->dynamic = true; result = extract_packed_buffer(pbuf, str->data, str->length + 1, false); diff --git a/src/analysis/db/misc/snapshot.c b/src/analysis/db/misc/snapshot.c index 546191b..9aa096f 100644 --- a/src/analysis/db/misc/snapshot.c +++ b/src/analysis/db/misc/snapshot.c @@ -41,6 +41,25 @@ * * * Paramètres : id = identifiant d'instantané à initialiser. [OUT] * * * +* Description : Prépare un identifiant pour instantané à une définition. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void setup_empty_snapshot_id(snapshot_id_t *id) +{ + memset(id, 0, sizeof(snapshot_id_t)); + +} + + +/****************************************************************************** +* * +* 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. * @@ -214,6 +233,32 @@ bool pack_snapshot_id(const snapshot_id_t *id, packed_buffer *pbuf) * * * Paramètres : info = description d'instantané à initialiser. [OUT] * * * +* Description : Prépare une description pour instantané à une définition. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void setup_empty_snapshot_info(snapshot_info_t *info) +{ + setup_empty_snapshot_id(&info->parent_id); + + setup_empty_snapshot_id(&info->id); + + setup_empty_timestamp(&info->created); + + info->name = NULL; + info->desc = NULL; + +} + + +/****************************************************************************** +* * +* Paramètres : info = description d'instantané à initialiser. [OUT] * +* * * Description : Construit une description pour instantané de base de données.* * * * Retour : Bilan de l'opération. * @@ -226,7 +271,10 @@ bool init_snapshot_info(snapshot_info_t *info) { bool result; /* Bilan à retourner */ - result = init_snapshot_id(&info->id); + result = init_snapshot_id_from_text(&info->parent_id, NO_SNAPSHOT_ROOT); + + if (result) + result = init_snapshot_id(&info->id); if (result) result = init_timestamp(&info->created); @@ -262,7 +310,10 @@ bool init_snapshot_info_from_text(snapshot_info_t *info, const char *id, uint64_ { bool result; /* Bilan à retourner */ - result = init_snapshot_id_from_text(&info->id, id); + result = init_snapshot_id_from_text(&info->parent_id, NO_SNAPSHOT_ROOT); + + if (result) + result = init_snapshot_id_from_text(&info->id, id); if (result) result = init_timestamp_from_value(&info->created, created); @@ -332,6 +383,8 @@ void copy_snapshot_info(snapshot_info_t *dest, const snapshot_info_t *src) { exit_snapshot_info(dest); + copy_snapshot_id(&dest->parent_id, &src->parent_id); + copy_snapshot_id(&dest->id, &src->id); copy_timestamp(&dest->created, &src->created); @@ -362,19 +415,26 @@ bool unpack_snapshot_info(snapshot_info_t *info, packed_buffer *pbuf) { bool result; /* Bilan à retourner */ rle_string string; /* Chaîne à transmettre */ + const char *text; /* Valeur textuelle obtenue */ - result = unpack_snapshot_id(&info->id, pbuf); + result = unpack_snapshot_id(&info->parent_id, pbuf); + + if (result) + result = unpack_snapshot_id(&info->id, pbuf); if (result) result = unpack_timestamp(&info->created, pbuf); if (result) { + init_static_rle_string(&string, NULL); + result = unpack_rle_string(&string, pbuf); if (result) { - info->name = strdup(get_rle_string(&string)); + text = get_rle_string(&string); + info->name = (text != NULL ? strdup(text) : NULL); exit_rle_string(&string); } @@ -382,11 +442,14 @@ bool unpack_snapshot_info(snapshot_info_t *info, packed_buffer *pbuf) if (result) { + init_static_rle_string(&string, NULL); + result = unpack_rle_string(&string, pbuf); if (result) { - info->desc = strdup(get_rle_string(&string)); + text = get_rle_string(&string); + info->desc = (text != NULL ? strdup(text) : NULL); exit_rle_string(&string); } @@ -415,7 +478,10 @@ bool pack_snapshot_info(const snapshot_info_t *info, packed_buffer *pbuf) bool result; /* Bilan à retourner */ rle_string string; /* Chaîne à transmettre */ - result = pack_snapshot_id(&info->id, pbuf); + result = pack_snapshot_id(&info->parent_id, pbuf); + + if (result) + result = pack_snapshot_id(&info->id, pbuf); if (result) result = pack_timestamp(&info->created, pbuf); diff --git a/src/analysis/db/misc/snapshot.h b/src/analysis/db/misc/snapshot.h index 37fad7f..8f9a598 100644 --- a/src/analysis/db/misc/snapshot.h +++ b/src/analysis/db/misc/snapshot.h @@ -49,6 +49,13 @@ typedef struct _snapshot_id_t } snapshot_id_t; +/* Identifiant d'un parent de racine */ +#define NO_SNAPSHOT_ROOT "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + + +/* Prépare un identifiant pour instantané à une définition. */ +void setup_empty_snapshot_id(snapshot_id_t *); + /* Construit un identifiant pour instantané de base de données. */ bool init_snapshot_id(snapshot_id_t *); @@ -77,6 +84,7 @@ bool pack_snapshot_id(const snapshot_id_t *, packed_buffer *); /* Description d'un instantané */ typedef struct _snapshot_info_t { + snapshot_id_t parent_id; /* Identifiant du propriétaire */ snapshot_id_t id; /* Identifiant attribué */ timestamp_t created; /* Date de création */ @@ -87,6 +95,9 @@ typedef struct _snapshot_info_t } snapshot_info_t; +/* Prépare une description pour instantané à une définition. */ +void setup_empty_snapshot_info(snapshot_info_t *); + /* Construit une description pour instantané de base de données. */ bool init_snapshot_info(snapshot_info_t *); @@ -96,8 +107,9 @@ bool init_snapshot_info_from_text(snapshot_info_t *, const char *, uint64_t, con /* Libère la mémoire occupée par une description d'instantané. */ void exit_snapshot_info(snapshot_info_t *); +#define get_snapshot_info_parent_id(nfo) &(nfo)->parent_id #define get_snapshot_info_id(nfo) &(nfo)->id -#define get_snapshot_info_creation(nfo) (nfo)->created +#define get_snapshot_info_created(nfo) (nfo)->created #define get_snapshot_info_name(nfo) (nfo)->name #define get_snapshot_info_desc(nfo) (nfo)->desc diff --git a/src/analysis/db/misc/timestamp.c b/src/analysis/db/misc/timestamp.c index dfc6f25..4d457e2 100644 --- a/src/analysis/db/misc/timestamp.c +++ b/src/analysis/db/misc/timestamp.c @@ -37,6 +37,25 @@ * * * Paramètres : timestamp = horodatage à initialiser. [OUT] * * * +* Description : Prépare un horodatage à une définition. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void setup_empty_timestamp(timestamp_t *timestamp) +{ + *timestamp = 0; + +} + + +/****************************************************************************** +* * +* Paramètres : timestamp = horodatage à initialiser. [OUT] * +* * * Description : Obtient un horodatage initialisé au moment même. * * * * Retour : Bilan de l'opération. * diff --git a/src/analysis/db/misc/timestamp.h b/src/analysis/db/misc/timestamp.h index 7f6290876..52b99f8 100644 --- a/src/analysis/db/misc/timestamp.h +++ b/src/analysis/db/misc/timestamp.h @@ -38,6 +38,9 @@ typedef uint64_t timestamp_t; +/* Prépare un horodatage à une définition. */ +void setup_empty_timestamp(timestamp_t *); + /* Obtient un horodatage initialisé au moment même. */ bool init_timestamp(timestamp_t *); |