diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2019-10-13 23:24:57 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2019-10-13 23:24:57 (GMT) |
commit | f439711a77e0719e7f1dcf4b5c5511157986c918 (patch) | |
tree | cac0cf37be2676fcf2dc958f9d9fd2fadea20653 /src/analysis/db/misc/snapshot.c | |
parent | 986125d4c2d8b049017b6d0770f16b9058076165 (diff) |
Retrieved the current snapshot identifier from servers.
Diffstat (limited to 'src/analysis/db/misc/snapshot.c')
-rw-r--r-- | src/analysis/db/misc/snapshot.c | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/src/analysis/db/misc/snapshot.c b/src/analysis/db/misc/snapshot.c index 982553b..546191b 100644 --- a/src/analysis/db/misc/snapshot.c +++ b/src/analysis/db/misc/snapshot.c @@ -210,8 +210,236 @@ bool pack_snapshot_id(const snapshot_id_t *id, packed_buffer *pbuf) /* ---------------------------------------------------------------------------------- */ +/****************************************************************************** +* * +* 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. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_snapshot_info(snapshot_info_t *info) +{ + bool result; /* Bilan à retourner */ + + result = init_snapshot_id(&info->id); + + if (result) + result = init_timestamp(&info->created); + + if (result) + { + info->name = NULL; + info->desc = NULL; + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : info = description d'instantané à initialiser. [OUT] * +* id = source de données pour l'identifiant. * +* created = source de données pour la date de création. * +* name = source de données éventuelle pour le nom. * +* desc = source de données éventuelle pour la description. * +* * +* Description : Construit une description pour instantané de base de données.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_snapshot_info_from_text(snapshot_info_t *info, const char *id, uint64_t created, const char *name, const char *desc) +{ + bool result; /* Bilan à retourner */ + + result = init_snapshot_id_from_text(&info->id, id); + + if (result) + result = init_timestamp_from_value(&info->created, created); + + if (result) + { + if (name == NULL) + info->name = NULL; + else + info->name = strdup(name); + + if (desc == NULL) + info->desc = NULL; + else + info->desc = strdup(desc); + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : info = description d'instantané à initialiser. [OUT] * +* * +* Description : Libère la mémoire occupée par une description d'instantané. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void exit_snapshot_info(snapshot_info_t *info) +{ + if (info->name != NULL) + { + free(info->name); + info->name = NULL; + } + + if (info->desc != NULL) + { + free(info->desc); + info->desc = NULL; + } + +} + + +/****************************************************************************** +* * +* Paramètres : dest = destination de la copie de description. [OUT] * +* src = source de la description à copier. * +* * +* Description : Effectue une copie de description d'instantané. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void copy_snapshot_info(snapshot_info_t *dest, const snapshot_info_t *src) +{ + exit_snapshot_info(dest); + + copy_snapshot_id(&dest->id, &src->id); + + copy_timestamp(&dest->created, &src->created); + + if (src->name != NULL) + dest->name = strdup(src->name); + + if (src->desc != NULL) + dest->desc = strdup(src->desc); + +} + + +/****************************************************************************** +* * +* Paramètres : info = informations à constituer. [OUT] * +* pbuf = paquet de données où venir puiser les infos. * +* * +* Description : Importe la description d'un identifiant d'instantané. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool unpack_snapshot_info(snapshot_info_t *info, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + rle_string string; /* Chaîne à transmettre */ + + result = unpack_snapshot_id(&info->id, pbuf); + + if (result) + result = unpack_timestamp(&info->created, pbuf); + + if (result) + { + result = unpack_rle_string(&string, pbuf); + if (result) + { + info->name = strdup(get_rle_string(&string)); + exit_rle_string(&string); + } + + } + if (result) + { + result = unpack_rle_string(&string, pbuf); + if (result) + { + info->desc = strdup(get_rle_string(&string)); + exit_rle_string(&string); + } + } + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : info = informations à sauvegarer. * +* pbuf = paquet de données où venir inscrire les infos. * +* * +* Description : Exporte la description d'un identifiant d'instantané. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +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); + + if (result) + result = pack_timestamp(&info->created, pbuf); + + if (result) + { + init_static_rle_string(&string, info->name); + + result = pack_rle_string(&string, pbuf); + + exit_rle_string(&string); + + } + + if (result) + { + init_static_rle_string(&string, info->desc); + + result = pack_rle_string(&string, pbuf); + + exit_rle_string(&string); + + } + + return result; + +} |