summaryrefslogtreecommitdiff
path: root/src/analysis/db/items/comment.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-05-08 09:28:58 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-05-08 09:28:58 (GMT)
commit86ba53836168bcc591f532f2419fa290de601572 (patch)
tree91c96614d6f7e3fd75800a52c0166c91c7f8ef31 /src/analysis/db/items/comment.c
parent28e53c2498903090182ebeb128347fcd92896cd9 (diff)
Updated the core functions dealing with SQLite databases.
Diffstat (limited to 'src/analysis/db/items/comment.c')
-rw-r--r--src/analysis/db/items/comment.c183
1 files changed, 103 insertions, 80 deletions
diff --git a/src/analysis/db/items/comment.c b/src/analysis/db/items/comment.c
index 7eb7906..6ac37fd 100644
--- a/src/analysis/db/items/comment.c
+++ b/src/analysis/db/items/comment.c
@@ -113,12 +113,12 @@ static bool g_db_comment_apply(GDbComment *, GLoadedBinary *);
/* Annule l'impression d'un commentaire dans du code de binaire. */
static bool g_db_comment_cancel(GDbComment *, GLoadedBinary *);
-/* Constitue les champs destinés à une insertion / modification. */
-static bool g_db_comment_prepare_db_statement(GDbComment *, bound_value **, size_t *);
-
/* Charge les valeurs utiles pour un commentaire. */
static bool g_db_comment_load(GDbComment *, const bound_value *, size_t);
+/* Constitue les champs destinés à une insertion / modification. */
+static bool g_db_comment_store(GDbComment *, bound_value **, size_t *);
+
/* Associe un contenu formaté supplémentaire à un commentaire. */
static void g_db_comment_add_rle_string(GDbComment *, const rle_string *);
@@ -236,8 +236,8 @@ static void g_db_comment_class_init(GDbCommentClass *klass)
item->apply = (run_item_fc)g_db_comment_apply;
item->cancel = (run_item_fc)g_db_comment_cancel;
- item->prepare_stmt = (prepare_db_statement)g_db_comment_prepare_db_statement;
item->load = (load_db_item_fc)g_db_comment_load;
+ item->store = (store_db_item_fc)g_db_comment_store;
}
@@ -694,8 +694,7 @@ static bool g_db_comment_run(GDbComment *comment, GLoadedBinary *binary, bool ap
if (apply)
{
comment->old_count = scount;
- comment->old_inlined = (GLineGenerator **)realloc(comment->old_inlined,
- comment->old_count * sizeof(GLineGenerator *));
+ comment->old_inlined = realloc(comment->old_inlined, comment->old_count * sizeof(GLineGenerator *));
}
for (i = 0; i < scount && result; i++)
@@ -805,7 +804,7 @@ static bool g_db_comment_run(GDbComment *comment, GLoadedBinary *binary, bool ap
assert(comment->old_count == 0);
comment->old_count = 1;
- comment->oldies = (GDbComment **)calloc(comment->old_count, sizeof(GDbComment *));
+ comment->oldies = calloc(comment->old_count, sizeof(GDbComment *));
}
@@ -876,8 +875,7 @@ static bool g_db_comment_run(GDbComment *comment, GLoadedBinary *binary, bool ap
if (apply)
{
comment->old_count += scount;
- comment->oldies = (GDbComment **)realloc(comment->oldies,
- comment->old_count * sizeof(GDbComment *));
+ comment->oldies = realloc(comment->oldies, comment->old_count * sizeof(GDbComment *));
}
for (i = 0; i < scount && result; i++)
@@ -970,73 +968,6 @@ static bool g_db_comment_cancel(GDbComment *comment, GLoadedBinary *binary)
/******************************************************************************
* *
-* Paramètres : comment = base d'éléments sur laquelle s'appuyer. *
-* values = couples de champs et de valeurs à lier. [OUT] *
-* count = nombre de ces couples. [OUT] *
-* *
-* Description : Constitue les champs destinés à une insertion / modification.*
-* *
-* Retour : Etat du besoin en sauvegarde. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static bool g_db_comment_prepare_db_statement(GDbComment *comment, bound_value **values, size_t *count)
-{
- bool status; /* Bilan d'opération initiale */
- bound_value *value; /* Valeur à éditer / définir */
- rle_string text; /* Texte brut récupéré */
-
- status = G_DB_ITEM_CLASS(g_db_comment_parent_class)->prepare_stmt(G_DB_ITEM(comment), values, count);
- if (!status) return false;
-
- status = prepare_vmpa_db_statement(&comment->addr, NULL, values, count);
- if (!status) return false;
-
- *count += 1;
- *values = (bound_value *)realloc(*values, *count * sizeof(bound_value));
-
- value = &(*values)[*count - 1];
-
- value->cname = "flags";
- value->built_name = false;
- value->type = SQLITE_INTEGER;
- value->integer = comment->flags;
- value->delete = NULL;
-
- init_dynamic_rle_string(&text, g_db_comment_get_text(comment));
- status &= prepare_db_statement_for_rle_string(&text, "text", values, count);
- exit_rle_string(&text);
-
- if (!status) return false;
-
- *count += 2;
- *values = (bound_value *)realloc(*values, *count * sizeof(bound_value));
-
- value = &(*values)[*count - 2];
-
- value->cname = "inlined";
- value->built_name = false;
- value->type = SQLITE_BOOLEAN;
- value->boolean = comment->inlined;
- value->delete = NULL;
-
- value = &(*values)[*count - 1];
-
- value->cname = "repeatable";
- value->built_name = false;
- value->type = SQLITE_BOOLEAN;
- value->boolean = comment->repeatable;
- value->delete = NULL;
-
- return true;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : comment = commentaire textuel à charger depuis les réponses. *
* values = tableau d'éléments à consulter. *
* count = nombre de descriptions renseignées. *
@@ -1101,6 +1032,98 @@ static bool g_db_comment_load(GDbComment *comment, const bound_value *values, si
/******************************************************************************
* *
+* Paramètres : comment = base d'éléments sur laquelle s'appuyer. *
+* values = couples de champs et de valeurs à lier. [OUT] *
+* count = nombre de ces couples. [OUT] *
+* *
+* Description : Constitue les champs destinés à une insertion / modification.*
+* *
+* Retour : Etat du besoin en sauvegarde. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_db_comment_store(GDbComment *comment, bound_value **values, size_t *count)
+{
+ bool status; /* Bilan d'opération initiale */
+ bound_value *value; /* Valeur à éditer / définir */
+ rle_string text; /* Texte brut récupéré */
+
+ if (comment == NULL)
+ status = G_DB_ITEM_CLASS(g_db_comment_parent_class)->store(NULL, values, count);
+ else
+ status = G_DB_ITEM_CLASS(g_db_comment_parent_class)->store(G_DB_ITEM(comment), values, count);
+
+ if (!status) return false;
+
+ if (comment == NULL)
+ status = store_vmpa(NULL, NULL, values, count);
+ else
+ status = store_vmpa(&comment->addr, NULL, values, count);
+
+ if (!status) return false;
+
+ *count += 1;
+ *values = realloc(*values, *count * sizeof(bound_value));
+
+ value = &(*values)[*count - 1];
+
+ value->cname = "flags";
+ value->built_name = false;
+ value->type = SQLITE_INTEGER;
+ value->integer = comment->flags;
+ value->delete = NULL;
+
+ value->has_value = (comment != NULL);
+
+ if (value->has_value)
+ {
+ init_dynamic_rle_string(&text, g_db_comment_get_text(comment));
+ status = store_rle_string(&text, "text", values, count);
+ exit_rle_string(&text);
+ }
+
+ if (!status) return false;
+
+ *count += 2;
+ *values = realloc(*values, *count * sizeof(bound_value));
+
+ value = &(*values)[*count - 2];
+
+ value->cname = "inlined";
+ value->built_name = false;
+ value->type = SQLITE_BOOLEAN;
+
+ value->has_value = (comment != NULL);
+
+ if (value->has_value)
+ {
+ value->boolean = comment->inlined;
+ value->delete = NULL;
+ }
+
+ value = &(*values)[*count - 1];
+
+ value->cname = "repeatable";
+ value->built_name = false;
+ value->type = SQLITE_BOOLEAN;
+
+ value->has_value = (comment != NULL);
+
+ if (value->has_value)
+ {
+ value->boolean = comment->repeatable;
+ value->delete = NULL;
+ }
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : comment = informations à consulter. *
* *
* Description : Fournit l'adresse associée à un commentaire. *
@@ -1649,11 +1672,11 @@ static bool g_comment_collection_setup_load(GCommentCollection *collec, bound_va
values, count);
if (!status) return false;
- if (!setup_load_for_vmpa(NULL, values, count))
+ if (!store_vmpa(NULL, NULL, values, count))
return false;
*count += 1;
- *values = (bound_value *)realloc(*values, *count * sizeof(bound_value));
+ *values = realloc(*values, *count * sizeof(bound_value));
value = &(*values)[*count - 1];
@@ -1661,11 +1684,11 @@ static bool g_comment_collection_setup_load(GCommentCollection *collec, bound_va
value->built_name = false;
value->type = SQLITE_INTEGER;
- if (!setup_load_of_rle_string(NULL, "text", values, count))
+ if (!store_rle_string(NULL, "text", values, count))
return false;
*count += 2;
- *values = (bound_value *)realloc(*values, *count * sizeof(bound_value));
+ *values = realloc(*values, *count * sizeof(bound_value));
value = &(*values)[*count - 2];