summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/db
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-09-25 22:20:25 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-09-25 22:20:25 (GMT)
commit6ed1e4110eb19b78f76154aa095a74414531f04c (patch)
treed1c3562cb6e180baff3c388a3bb3574b0a02213b /plugins/pychrysalide/analysis/db
parent3dc843b3f7991dcd738a30821ff56c7fe13f1094 (diff)
Prepared history for database items.
Diffstat (limited to 'plugins/pychrysalide/analysis/db')
-rw-r--r--plugins/pychrysalide/analysis/db/client.c60
-rw-r--r--plugins/pychrysalide/analysis/db/collection.c26
-rw-r--r--plugins/pychrysalide/analysis/db/constants.c1
-rw-r--r--plugins/pychrysalide/analysis/db/item.c40
4 files changed, 110 insertions, 17 deletions
diff --git a/plugins/pychrysalide/analysis/db/client.c b/plugins/pychrysalide/analysis/db/client.c
index 13966f5..e5b67da 100644
--- a/plugins/pychrysalide/analysis/db/client.c
+++ b/plugins/pychrysalide/analysis/db/client.c
@@ -51,6 +51,9 @@ static PyObject *py_hub_client_stop(PyObject *, PyObject *);
/* Effectue une demande de sauvegarde de l'état courant. */
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 *);
+
/******************************************************************************
@@ -146,7 +149,7 @@ static PyObject *py_hub_client_new(PyTypeObject *type, PyObject *args, PyObject
/******************************************************************************
* *
-* Paramètres : self = serveur à manipuler. *
+* Paramètres : self = client à manipuler. *
* args = paramètres à transmettre à l'appel natif. *
* *
* Description : Démarre la connexion à la base de données. *
@@ -201,7 +204,7 @@ static PyObject *py_hub_client_start(PyObject *self, PyObject *args)
/******************************************************************************
* *
-* Paramètres : self = serveur à manipuler. *
+* Paramètres : self = client à manipuler. *
* args = arguments d'appel non utilisés ici. *
* *
* Description : Arrête la connexion à la base de données. *
@@ -238,7 +241,7 @@ static PyObject *py_hub_client_stop(PyObject *self, PyObject *args)
/******************************************************************************
* *
-* Paramètres : self = serveur à manipuler. *
+* Paramètres : self = client à manipuler. *
* args = arguments d'appel non utilisés ici. *
* *
* Description : Effectue une demande de sauvegarde de l'état courant. *
@@ -279,6 +282,56 @@ static PyObject *py_hub_client_save(PyObject *self, PyObject *args)
/******************************************************************************
* *
+* Paramètres : self = client à manipuler. *
+* args = arguments d'appel à consulter. *
+* *
+* Description : Active les éléments en amont d'un horodatage donné. *
+* *
+* Retour : True si la commande a bien été envoyée, False sinon. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_hub_client_set_last_active(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ unsigned long long timestamp; /* Horodatage de limite */
+ int ret; /* Bilan de lecture des args. */
+ GHubClient *client; /* Version native du serveur */
+ bool status; /* Bilan de l'opération */
+
+#define HUB_CLIENT_SET_LAST_ACTIVE_METHOD PYTHON_METHOD_DEF \
+( \
+ set_last_active, "$self, timestamp, /", \
+ METH_VARARGS, py_hub_client, \
+ "Define the timestamp of the last active item in the collection" \
+ " and returns the status of the request transmission." \
+ "\n" \
+ "This method should not be used directly. Prefer calling" \
+ " pychrysalide.analysis.LoadedBinary.set_last_active() instead," \
+ " as some items may be volatile and thus not handled by clients." \
+)
+
+ ret = PyArg_ParseTuple(args, "K", &timestamp);
+ if (!ret) return NULL;
+
+ client = G_HUB_CLIENT(pygobject_get(self));
+
+ status = g_hub_client_set_last_active(client, timestamp);
+
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : - *
* *
* Description : Fournit un accès à une définition de type à diffuser. *
@@ -295,6 +348,7 @@ PyTypeObject *get_python_hub_client_type(void)
HUB_CLIENT_START_METHOD,
HUB_CLIENT_STOP_METHOD,
HUB_CLIENT_SAVE_METHOD,
+ HUB_CLIENT_SET_LAST_ACTIVE_METHOD,
{ NULL }
};
diff --git a/plugins/pychrysalide/analysis/db/collection.c b/plugins/pychrysalide/analysis/db/collection.c
index e62c17e..53cdccc 100644
--- a/plugins/pychrysalide/analysis/db/collection.c
+++ b/plugins/pychrysalide/analysis/db/collection.c
@@ -59,10 +59,9 @@ static PyObject *py_db_collection_get_items(PyObject *self, void *closure)
{
PyObject *result; /* Trouvailles à retourner */
GDbCollection *collec; /* Version native */
- size_t counter; /* Décompte des éléments */
- GList *items; /* Eléments déjà en place */
- GList *iter; /* Boucle de parcours */
- int ret; /* Bilan d'une extension */
+ size_t count; /* Décompte des éléments */
+ GDbItem **items; /* Eléments déjà en place */
+ size_t i; /* Boucle de parcours */
#define DB_COLLECTION_ITEMS_ATTRIB PYTHON_GET_DEF_FULL \
( \
@@ -74,22 +73,21 @@ static PyObject *py_db_collection_get_items(PyObject *self, void *closure)
collec = G_DB_COLLECTION(pygobject_get(self));
- counter = 0;
- result = PyTuple_New(counter);
-
g_db_collection_rlock(collec);
- items = g_db_collection_get_items(G_DB_COLLECTION(collec));
-
- for (iter = g_list_first(items); iter != NULL; iter = g_list_next(iter))
- {
- ret = _PyTuple_Resize(&result, ++counter);
- if (ret == -1) break;
+ items = g_db_collection_get_items(G_DB_COLLECTION(collec), &count);
- PyTuple_SetItem(result, counter - 1, pygobject_new(G_OBJECT(iter->data)));
+ result = PyTuple_New(count);
+ for (i = 0; i < count; i++)
+ {
+ PyTuple_SetItem(result, i, pygobject_new(G_OBJECT(items[i])));
+ g_object_unref(G_OBJECT(items[i]));
}
+ if (items != NULL)
+ free(items);
+
g_db_collection_runlock(collec);
return result;
diff --git a/plugins/pychrysalide/analysis/db/constants.c b/plugins/pychrysalide/analysis/db/constants.c
index 46d0876..07c7a06 100644
--- a/plugins/pychrysalide/analysis/db/constants.c
+++ b/plugins/pychrysalide/analysis/db/constants.c
@@ -96,6 +96,7 @@ bool define_db_item_constants(PyTypeObject *type)
if (result) result = add_const_to_group(values, "UPDATED", DIF_UPDATED);
if (result) result = add_const_to_group(values, "VOLATILE", DIF_VOLATILE);
if (result) result = add_const_to_group(values, "BROKEN", DIF_BROKEN);
+ if (result) result = add_const_to_group(values, "DISABLED", DIF_DISABLED);
if (!result)
{
diff --git a/plugins/pychrysalide/analysis/db/item.c b/plugins/pychrysalide/analysis/db/item.c
index 0923268..7ef30af 100644
--- a/plugins/pychrysalide/analysis/db/item.c
+++ b/plugins/pychrysalide/analysis/db/item.c
@@ -48,6 +48,9 @@ static PyObject *py_db_item_remove_flag(PyObject *, PyObject *);
/* Décrit l'élément de collection en place. */
static PyObject *py_db_item_get_label(PyObject *, void *);
+/* Fournit l'horodatage associé à l'élément de collection. */
+static PyObject *py_db_item_get_timestamp(PyObject *, void *);
+
/* Indique les propriétés particulières appliquées à l'élément. */
static PyObject *py_db_item_get_flags(PyObject *, void *);
@@ -178,6 +181,42 @@ static PyObject *py_db_item_get_label(PyObject *self, void *closure)
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
+* Description : Fournit l'horodatage associé à l'élément de collection. *
+* *
+* Retour : Date de création de l'élément. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_db_item_get_timestamp(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GDbItem *item; /* Elément à consulter */
+ timestamp_t timestamp; /* Horodatage de l'élément */
+
+#define DB_ITEM_TIMESTAMP_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ timestamp, py_db_item, \
+ "Timestamp of the item creation." \
+)
+
+ item = G_DB_ITEM(pygobject_get(self));
+
+ timestamp = g_db_item_get_timestamp(item);
+
+ result = PyLong_FromUnsignedLongLong(timestamp);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
* Description : Indique les propriétés particulières appliquées à l'élément. *
* *
* Retour : Propriétés actives de l'élément. *
@@ -232,6 +271,7 @@ PyTypeObject *get_python_db_item_type(void)
static PyGetSetDef py_db_item_getseters[] = {
DB_ITEM_LABEL_ATTRIB,
+ DB_ITEM_TIMESTAMP_ATTRIB,
DB_ITEM_FLAGS_ATTRIB,
{ NULL }
};