summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/pychrysalide/analysis/db/client.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/plugins/pychrysalide/analysis/db/client.c b/plugins/pychrysalide/analysis/db/client.c
index afece26..f9ce001 100644
--- a/plugins/pychrysalide/analysis/db/client.c
+++ b/plugins/pychrysalide/analysis/db/client.c
@@ -25,6 +25,7 @@
#include "client.h"
+#include <assert.h>
#include <pygobject.h>
@@ -36,6 +37,7 @@
#include "collection.h"
#include "../../access.h"
#include "../../helpers.h"
+#include "../../struct.h"
@@ -54,6 +56,9 @@ static PyObject *py_hub_client_save(PyObject *, PyObject *);
/* Active les éléments en amont d'un horodatage donné. */
static PyObject *py_hub_client_set_last_active(PyObject *, PyObject *);
+/* Fournit la liste des instantanés existants. */
+static PyObject *py_hub_client_get_snapshots(PyObject *, void *);
+
/* Fournit l'identifiant de l'instantané courant. */
static PyObject *py_hub_client_get_current_snapshot(PyObject *, void *);
@@ -338,6 +343,137 @@ static PyObject *py_hub_client_set_last_active(PyObject *self, PyObject *args)
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
+* Description : Fournit la liste des instantanés existants. *
+* *
+* Retour : Liste d'instantanés ou None. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_hub_client_get_snapshots(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GHubClient *client; /* Version native du serveur */
+ snapshot_info_t *info; /* Liste d'instantanés présents*/
+ size_t count; /* Taille de cette liste */
+ bool status; /* Validité de cet identifiant */
+ PyTypeObject *base; /* Modèle d'objet à créer */
+ size_t i; /* Boucle de parcours */
+ PyObject *item; /* Nouvelle description */
+ char *text; /* Valeur textuelle à placer */
+ PyObject *attrib; /* Attribut à constituer */
+ int ret; /* Bilan d'une mise en place */
+ bool failed; /* Détection d'une erreur */
+
+#define HUB_CLIENT_SNAPSHOTS_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ snapshots, py_hub_client, \
+ "List of all existing snapshots, provided as a tuple of pychrysalide.PyStructObject." \
+ "\n" \
+ "Each snapshot is characterised by the following properties :\n" \
+ "* parent_id : identifier of the parent snapshot;\n" \
+ "* id : identifier of the snapshot;\n" \
+ "* created : timestamp of the creation date;\n" \
+ "* name : name of the snapshot, or None;\n" \
+ "* desc : description of the snapshot, or None." \
+)
+
+ client = G_HUB_CLIENT(pygobject_get(self));
+
+ status = g_hub_client_get_snapshots(client, &info, &count);
+
+ if (status)
+ {
+ result = PyTuple_New(count);
+
+ base = get_python_py_struct_type();
+
+ failed = false;
+
+ for (i = 0; i < count; i++)
+ {
+ item = PyObject_CallFunction((PyObject *)base, NULL);
+ assert(item != NULL);
+
+ text = snapshot_id_as_string(get_snapshot_info_parent_id(&info[i]));
+ attrib = PyUnicode_FromString(text);
+ ret = PyDict_SetItemString(item, "parent_id", attrib);
+ if (ret != 0) break;
+
+ text = snapshot_id_as_string(get_snapshot_info_id(&info[i]));
+ attrib = PyUnicode_FromString(text);
+ ret = PyDict_SetItemString(item, "id", attrib);
+ if (ret != 0) break;
+
+ attrib = PyLong_FromUnsignedLongLong(get_snapshot_info_created(&info[i]));
+ ret = PyDict_SetItemString(item, "created", attrib);
+ if (ret != 0) break;
+
+ text = get_snapshot_info_name(&info[i]);
+
+ if (text != NULL)
+ attrib = PyUnicode_FromString(text);
+ else
+ {
+ attrib = Py_None;
+ Py_INCREF(attrib);
+ }
+
+ ret = PyDict_SetItemString(item, "name", attrib);
+ if (ret != 0) break;
+
+ text = get_snapshot_info_desc(&info[i]);
+
+ if (text != NULL)
+ attrib = PyUnicode_FromString(text);
+ else
+ {
+ attrib = Py_None;
+ Py_INCREF(attrib);
+ }
+
+ ret = PyDict_SetItemString(item, "desc", attrib);
+ if (ret != 0) break;
+
+ PyTuple_SetItem(result, i, item);
+
+ }
+
+ failed = (i < count);
+
+ for (i = 0; i < count; i++)
+ exit_snapshot_info(&info[i]);
+
+ free(info);
+
+ if (failed)
+ goto on_failure;
+
+ }
+
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ return result;
+
+ on_failure:
+
+ Py_DECREF(result);
+
+ return NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
* Description : Fournit l'identifiant de l'instantané courant. *
* *
* Retour : Identifiant d'instantané ou None. *
@@ -452,6 +588,7 @@ PyTypeObject *get_python_hub_client_type(void)
};
static PyGetSetDef py_hub_client_getseters[] = {
+ HUB_CLIENT_SNAPSHOTS_ATTRIB,
HUB_CLIENT_CURRENT_SNAPSHOT_ATTRIB,
{ NULL }
};