summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/db/items
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-09-12 21:44:24 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-09-12 21:44:38 (GMT)
commit682159e73cfbf8ec61d2f2aba765be1016a30ded (patch)
tree9477af8765263667b20a48c53835aa9b3be73a2a /plugins/pychrysalide/analysis/db/items
parent57f6179e22f880bbcff031714e8576cf9bd488ac (diff)
Extended the Python API for update databases.
Diffstat (limited to 'plugins/pychrysalide/analysis/db/items')
-rw-r--r--plugins/pychrysalide/analysis/db/items/bookmark.c223
-rw-r--r--plugins/pychrysalide/analysis/db/items/bookmark.h17
-rw-r--r--plugins/pychrysalide/analysis/db/items/module.c1
3 files changed, 240 insertions, 1 deletions
diff --git a/plugins/pychrysalide/analysis/db/items/bookmark.c b/plugins/pychrysalide/analysis/db/items/bookmark.c
index 783efa6..468f38c 100644
--- a/plugins/pychrysalide/analysis/db/items/bookmark.c
+++ b/plugins/pychrysalide/analysis/db/items/bookmark.c
@@ -33,6 +33,7 @@
#include <plugins/dt.h>
+#include "../collection.h"
#include "../item.h"
#include "../../../access.h"
#include "../../../helpers.h"
@@ -40,6 +41,9 @@
+/* --------------------- ELABORATION D'UN ELEMENT DE COLLECTION --------------------- */
+
+
/* Crée un nouvel objet Python de type 'DbBookmark'. */
static PyObject *py_db_bookmark_new(PyTypeObject *, PyObject *, PyObject *);
@@ -54,6 +58,19 @@ static PyObject *py_db_bookmark_get_comment(PyObject *, void *);
+/* ---------------------- DEFINITION DE LA COLLECTION ASSOCIEE ---------------------- */
+
+
+/* Crée un nouvel objet Python de type 'BookmarkCollection'. */
+static PyObject *py_bookmark_collection_new(PyTypeObject *, PyObject *, PyObject *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* ELABORATION D'UN ELEMENT DE COLLECTION */
+/* ---------------------------------------------------------------------------------- */
+
+
/******************************************************************************
* *
* Paramètres : type = type de l'objet à instancier. *
@@ -144,7 +161,7 @@ static int py_db_bookmark_init(PyObject *self, PyObject *args, PyObject *kwds)
"\n" \
"Instances can be created using the following constructor:\n" \
"\n" \
- " DbBookmark(addr, comment=None)" \
+ " DbBookmark(addr, comment=None)\n" \
"\n" \
"Where addr is a location of type pychrysalide.arch.vmpa and" \
" comment is a string or None.\n" \
@@ -400,3 +417,207 @@ int convert_to_db_bookmark(PyObject *arg, void *dst)
return result;
}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* DEFINITION DE LA COLLECTION ASSOCIEE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type de l'objet à instancier. *
+* args = arguments fournis à l'appel. *
+* kwds = arguments de type key=val fournis. *
+* *
+* Description : Crée un nouvel objet Python de type 'BookmarkCollection'. *
+* *
+* Retour : Instance Python mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_bookmark_collection_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *result; /* Objet à retourner */
+ PyTypeObject *base; /* Type de base à dériver */
+ bool first_time; /* Evite les multiples passages*/
+ GType gtype; /* Nouveau type de processeur */
+ bool status; /* Bilan d'un enregistrement */
+
+#define BOOKMARK_COLLECTION_DOC \
+ "BookmarkCollection remembers all bookmark definitions.\n" \
+ "\n" \
+ "Instances can be created using the following constructor:\n" \
+ "\n" \
+ " DbBookmark()\n" \
+ "\n" \
+ "There should be no need for creating such instances manually."
+
+ /* Validations diverses */
+
+ base = get_python_db_bookmark_type();
+
+ if (type == base)
+ goto simple_way;
+
+ /* Mise en place d'un type dédié */
+
+ first_time = (g_type_from_name(type->tp_name) == 0);
+
+ gtype = build_dynamic_type(G_TYPE_DB_BOOKMARK, type->tp_name, NULL, NULL, NULL);
+
+ if (first_time)
+ {
+ status = register_class_for_dynamic_pygobject(gtype, type, base);
+
+ if (!status)
+ {
+ result = NULL;
+ goto exit;
+ }
+
+ }
+
+ /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
+
+ simple_way:
+
+ result = PyType_GenericNew(type, args, kwds);
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_bookmark_collection_type(void)
+{
+ static PyMethodDef py_bookmark_collection_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_bookmark_collection_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_bookmark_collection_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.analysis.db.items.BookmarkCollection",
+ .tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = BOOKMARK_COLLECTION_DOC,
+
+ .tp_methods = py_bookmark_collection_methods,
+ .tp_getset = py_bookmark_collection_getseters,
+
+ .tp_new = py_bookmark_collection_new,
+
+ };
+
+ return &py_bookmark_collection_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide....BookmarkCollection'.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool ensure_python_bookmark_collection_is_registered(void)
+{
+ PyTypeObject *type; /* Type Python 'DbBookmark' */
+ PyObject *module; /* Module à recompléter */
+ PyObject *dict; /* Dictionnaire du module */
+
+ type = get_python_bookmark_collection_type();
+
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.analysis.db.items");
+
+ dict = PyModule_GetDict(module);
+
+ if (!ensure_python_db_item_is_registered())
+ return false;
+
+ if (!register_class_for_pygobject(dict, G_TYPE_BM_COLLECTION, type, get_python_db_collection_type()))
+ return false;
+
+ }
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en collection de signets. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_bookmark_collection(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_bookmark_collection_type());
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to bookmark collection");
+ break;
+
+ case 1:
+ *((GBookmarkCollection **)dst) = G_BM_COLLECTION(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/analysis/db/items/bookmark.h b/plugins/pychrysalide/analysis/db/items/bookmark.h
index bcf1c11..504795f 100644
--- a/plugins/pychrysalide/analysis/db/items/bookmark.h
+++ b/plugins/pychrysalide/analysis/db/items/bookmark.h
@@ -31,6 +31,9 @@
+/* --------------------- ELABORATION D'UN ELEMENT DE COLLECTION --------------------- */
+
+
/* Fournit un accès à une définition de type à diffuser. */
PyTypeObject *get_python_db_bookmark_type(void);
@@ -42,4 +45,18 @@ int convert_to_db_bookmark(PyObject *, void *);
+/* ---------------------- DEFINITION DE LA COLLECTION ASSOCIEE ---------------------- */
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_bookmark_collection_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.analysis.db.items.BookmarkCollection'. */
+bool ensure_python_bookmark_collection_is_registered(void);
+
+/* Tente de convertir en collection de signets. */
+int convert_to_bookmark_collection(PyObject *, void *);
+
+
+
#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_ITEMS_BOOKMARK_H */
diff --git a/plugins/pychrysalide/analysis/db/items/module.c b/plugins/pychrysalide/analysis/db/items/module.c
index fcf636f..04349b5 100644
--- a/plugins/pychrysalide/analysis/db/items/module.c
+++ b/plugins/pychrysalide/analysis/db/items/module.c
@@ -89,6 +89,7 @@ bool populate_analysis_db_items_module(void)
result = true;
+ if (result) result = ensure_python_bookmark_collection_is_registered();
if (result) result = ensure_python_db_bookmark_is_registered();
if (result) result = ensure_python_db_comment_is_registered();