summaryrefslogtreecommitdiff
path: root/src/analysis/db/item.c
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 /src/analysis/db/item.c
parent3dc843b3f7991dcd738a30821ff56c7fe13f1094 (diff)
Prepared history for database items.
Diffstat (limited to 'src/analysis/db/item.c')
-rw-r--r--src/analysis/db/item.c171
1 files changed, 106 insertions, 65 deletions
diff --git a/src/analysis/db/item.c b/src/analysis/db/item.c
index efa2cdf..f9c4201 100644
--- a/src/analysis/db/item.c
+++ b/src/analysis/db/item.c
@@ -462,7 +462,7 @@ bool g_db_item_apply(GDbItem *item, GLoadedBinary *binary)
{
bool result; /* Bilan à faire remonter */
- assert(g_db_item_is_active(item));
+ assert(!g_db_item_has_flag(item, DIF_DISABLED));
result = G_DB_ITEM_GET_CLASS(item)->apply(item, binary);
@@ -491,7 +491,7 @@ bool g_db_item_cancel(GDbItem *item, GLoadedBinary *binary)
{
bool result; /* Bilan à faire remonter */
- assert(!g_db_item_is_active(item));
+ assert(g_db_item_has_flag(item, DIF_DISABLED));
result = G_DB_ITEM_GET_CLASS(item)->cancel(item, binary);
@@ -533,7 +533,7 @@ char *g_db_item_get_label(GDbItem *item)
* *
* Description : Fournit l'horodatage associé à l'élément de collection. *
* *
-* Retour : Date d'activité de l'élément. *
+* Retour : Date de création de l'élément. *
* *
* Remarques : - *
* *
@@ -541,56 +541,9 @@ char *g_db_item_get_label(GDbItem *item)
timestamp_t g_db_item_get_timestamp(const GDbItem *item)
{
- return item->timestamp;
+ timestamp_t result; /* Horodatage à retourner */
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : item = élément de collection à mettre à jour. *
-* binary = binaire chargé en mémoire à modifier. *
-* first = horodatage du premier élément désactivé ou NULL. *
-* *
-* Description : Active ou désactive un élément de collection en place. *
-* *
-* Retour : Bilan de la mise à jour de l'élément. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool g_db_item_set_activity(GDbItem *item, GLoadedBinary *binary, timestamp_t *first)
-{
- bool result; /* Bilan à faire remonter */
- bool active; /* Etat avant changement */
-
- active = g_db_item_is_active(item);
-
- /* Archivage de l'état */
-
- if (first == NULL)
- {
- assert(!active);
- item->timestamp = item->created;
- }
- else
- {
- assert(active);
- item->timestamp = --(*first);
- }
-
- /* Application de l'état */
-
- if (binary != NULL)
- {
- if (active)
- result = g_db_item_cancel(item, binary);
- else
- result = g_db_item_apply(item, binary);
- }
- else
- result = true;
+ result = item->created;
return result;
@@ -599,19 +552,20 @@ bool g_db_item_set_activity(GDbItem *item, GLoadedBinary *binary, timestamp_t *f
/******************************************************************************
* *
-* Paramètres : item = élément de collection à consulter. *
+* Paramètres : item = base d'éléments à mettre à jour. *
+* flag = type de propriété à traiter. *
* *
-* Description : Indique si l'élément est activé ou désactivé. *
+* Description : Applique un ensemble de propriétés à un élément. *
* *
-* Retour : Etat de l'activité de l'élément. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-bool g_db_item_is_active(const GDbItem *item)
+void g_db_item_set_flags(GDbItem *item, DbItemFlags flag)
{
- return (cmp_timestamp(&item->created, &item->timestamp) == 0);
+ g_atomic_int_set(&item->atomic_flags, flag);
}
@@ -684,6 +638,50 @@ DbItemFlags g_db_item_get_flags(const GDbItem *item)
}
+/******************************************************************************
+* *
+* Paramètres : item = élément de collection à mettre à jour. *
+* binary = binaire chargé en mémoire à modifier. *
+* *
+* Description : Active ou désactive un élément de collection en place. *
+* *
+* Retour : Bilan de la mise à jour de l'élément. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_db_item_switch_state(GDbItem *item, GLoadedBinary *binary)
+{
+ bool result; /* Bilan à faire remonter */
+ bool enabled; /* Etat avant changement */
+
+ enabled = !g_db_item_has_flag(item, DIF_DISABLED);
+
+ /* Archivage de l'état */
+
+ if (enabled)
+ g_db_item_add_flag(item, DIF_DISABLED);
+ else
+ g_db_item_remove_flag(item, DIF_DISABLED);
+
+ /* Application de l'état */
+
+ if (binary != NULL)
+ {
+ if (enabled)
+ result = g_db_item_cancel(item, binary);
+ else
+ result = g_db_item_apply(item, binary);
+ }
+ else
+ result = true;
+
+ return result;
+
+}
+
+
/* ---------------------------------------------------------------------------------- */
/* MANIPULATIONS AVEC UNE BASE DE DONNEES */
@@ -692,6 +690,30 @@ DbItemFlags g_db_item_get_flags(const GDbItem *item)
/******************************************************************************
* *
+* Paramètres : item = base d'éléments à consulter. *
+* values = tableau d'éléments à compléter. [OUT] *
+* count = nombre de descriptions renseignées. [OUT] *
+* *
+* Description : Décrit les colonnes utiles à un chargement de données. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_db_item_setup_load(const GDbItem *item, bound_value **values, size_t *count)
+{
+ *values = NULL;
+ *count = 0;
+
+ return G_DB_ITEM_GET_CLASS(item)->store(NULL, values, count);
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : item = base d'éléments à charger depuis les réponses. *
* values = tableau d'éléments à consulter. *
* count = nombre de descriptions renseignées. *
@@ -707,14 +729,23 @@ DbItemFlags g_db_item_get_flags(const GDbItem *item)
static bool _g_db_item_load(GDbItem *item, const bound_value *values, size_t count)
{
bool result; /* Bilan global à retourner */
+ const bound_value *value; /* Valeur à intégrer */
result = load_timestamp(&item->created, "created", values, count);
if (result)
- result = load_timestamp(&item->timestamp, "timestamp", values, count);
+ result = load_rle_string(&item->author, "author", values, count);
if (result)
- result = load_rle_string(&item->author, "author", values, count);
+ {
+ value = find_bound_value(values, count, "flags");
+
+ result = (value != NULL && value->type == SQLITE_INTEGER);
+
+ if (result)
+ item->flags = value->integer;
+
+ }
return result;
@@ -763,6 +794,7 @@ bool g_db_item_load(GDbItem *item, const bound_value *values, size_t count)
static bool _g_db_item_store(const GDbItem *item, bound_value **values, size_t *count)
{
bool result; /* Bilan à retourner */
+ bound_value *value; /* Valeur à éditer / définir */
if (item == NULL)
result = store_timestamp(NULL, "created", values, count);
@@ -772,17 +804,26 @@ static bool _g_db_item_store(const GDbItem *item, bound_value **values, size_t *
if (result)
{
if (item == NULL)
- result = store_timestamp(NULL, "timestamp", values, count);
+ result = store_rle_string(NULL, "author", values, count);
else
- result = store_timestamp(&item->timestamp, "timestamp", values, count);
+ result = store_rle_string(&item->author, "author", values, count);
}
if (result)
{
- if (item == NULL)
- result = store_rle_string(NULL, "author", values, count);
- else
- result = store_rle_string(&item->author, "author", values, count);
+ *values = realloc(*values, ++(*count) * sizeof(bound_value));
+
+ value = &(*values)[*count - 1];
+
+ value->cname = "flags";
+ value->built_name = false;
+ value->type = SQLITE_INTEGER;
+
+ value->has_value = (item != NULL);
+
+ if (value->has_value)
+ value->integer = g_db_item_get_flags(item);
+
}
return result;