summaryrefslogtreecommitdiff
path: root/src/common/xml.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-10-13 23:24:57 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-10-13 23:24:57 (GMT)
commitf439711a77e0719e7f1dcf4b5c5511157986c918 (patch)
treecac0cf37be2676fcf2dc958f9d9fd2fadea20653 /src/common/xml.c
parent986125d4c2d8b049017b6d0770f16b9058076165 (diff)
Retrieved the current snapshot identifier from servers.
Diffstat (limited to 'src/common/xml.c')
-rw-r--r--src/common/xml.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/src/common/xml.c b/src/common/xml.c
index aaed2ea..3774359 100644
--- a/src/common/xml.c
+++ b/src/common/xml.c
@@ -25,6 +25,8 @@
#include "xml.h"
+#include <inttypes.h>
+#include <malloc.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -453,6 +455,43 @@ bool qck_get_node_prop_long_value(xmlNodePtr node, const char *name, long *out)
/******************************************************************************
* *
+* Paramètres : node = noeud dont une propriété est à lire. *
+* name = nom de la propriété à lire. *
+* out = valeur entière lue depuis le contenu textuel. [OUT] *
+* *
+* Description : Obtient la valeur entière d'une propriété d'un élément. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool qck_get_node_prop_uint64_value(xmlNodePtr node, const char *name, uint64_t *out)
+{
+ bool result; /* Bilan à retourner */
+ char *value; /* Valeur brute lue */
+
+ value = qck_get_node_prop_value(node, name);
+
+ if (value)
+ {
+ result = true;
+
+ *out = strtoull(value, NULL, 10);
+ free(value);
+
+ }
+ else
+ result = false;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : xpathCtx = contexte à utiliser pour les recherches. *
* path = chemin d'accès au noeud à traiter. *
* name = nom de la propriété à lire. *
@@ -522,6 +561,41 @@ bool get_node_prop_long_value(xmlXPathContextPtr xpathCtx, const char *path, con
/******************************************************************************
* *
+* Paramètres : xpathCtx = contexte à utiliser pour les recherches. *
+* path = chemin d'accès au noeud à traiter. *
+* name = nom de la propriété à lire. *
+* out = valeur entière obtenue via contenu textuel. [OUT] *
+* *
+* Description : Obtient la valeur entière d'une propriété d'un élément. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool get_node_prop_uint64_value(xmlXPathContextPtr xpathCtx, const char *path, const char *name, uint64_t *out)
+{
+ bool result; /* Bilan à retourner */
+ xmlXPathObjectPtr xpathObj; /* Point de départ XML */
+
+ result = NULL;
+
+ xpathObj = get_node_xpath_object(xpathCtx, path);
+ if (xpathObj == NULL) return NULL;
+
+ if (xpathObj->nodesetval->nodeNr > 0)
+ result = qck_get_node_prop_uint64_value(xpathObj->nodesetval->nodeTab[0], name, out);
+
+ xmlXPathFreeObject(xpathObj);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : node = noeud de texte avec un lien avec le document XML. *
* *
* Description : Construit un chemin d'accès complet selon le fichier XML. *
@@ -1250,3 +1324,67 @@ bool add_long_attribute_to_node(xmlDocPtr xdoc, xmlXPathContextPtr context, cons
return _add_long_attribute_to_node(node, name, value);
}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud dont le contenu est à mettre à jour. *
+* name = nom de la propriété à créer. *
+* value = valeur numérique à placer. *
+* *
+* Description : Ajoute une propriété à un noeud existant donné. *
+* *
+* Retour : true en cas de succès, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool _add_uint64_attribute_to_node(xmlNodePtr node, const char *name, uint64_t value)
+{
+ bool result; /* Bilan à retourner */
+ char *tmp; /* Stockage temporaire */
+ int ret; /* Bilan de l'impression */
+
+ ret = asprintf(&tmp, "%" PRIu64, value);
+
+ if (ret == -1)
+ result = false;
+
+ else
+ {
+ result = _add_string_attribute_to_node(node, name, tmp);
+ free(tmp);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : xdoc = structure XML chargée. *
+* context = contexte à utiliser pour les recherches. *
+* path = chemin d'accès au noeud visé. *
+* name = nom de la propriété à créer. *
+* value = valeur numérique à placer. *
+* *
+* Description : Ajoute une propriété à un noeud existant donné. *
+* *
+* Retour : true en cas de succès, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_uint64_attribute_to_node(xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path, const char *name, uint64_t value)
+{
+ xmlNodePtr node; /* Noeud à modifier */
+
+ node = ensure_node_exist(xdoc, context, path);
+ if (node == NULL) return false;
+
+ return _add_uint64_attribute_to_node(node, name, value);
+
+}