summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/analysis')
-rw-r--r--plugins/pychrysalide/analysis/project.c80
1 files changed, 75 insertions, 5 deletions
diff --git a/plugins/pychrysalide/analysis/project.c b/plugins/pychrysalide/analysis/project.c
index 1a85f71..137efbf 100644
--- a/plugins/pychrysalide/analysis/project.c
+++ b/plugins/pychrysalide/analysis/project.c
@@ -45,6 +45,9 @@ static PyObject *py_study_project_new(PyTypeObject *, PyObject *, PyObject *);
/* Procède à l'enregistrement d'un projet donné. */
static PyObject *py_study_project_save(PyObject *, PyObject *);
+/* Détermine si un contenu doit être écarté ou conservé. */
+static bool filter_loadable_content_with_python(GLoadedContent *, PyObject *);
+
/* Assure l'intégration de contenus binaires dans un projet. */
static PyObject *py_study_project_discover_binary_content(PyObject *, PyObject *);
@@ -135,6 +138,57 @@ static PyObject *py_study_project_save(PyObject *self, PyObject *args)
/******************************************************************************
* *
+* Paramètres : content = contenu chargeable à étudier ou NULL à la fin. *
+* callable = procédure de filtre en Python. *
+* *
+* Description : Détermine si un contenu doit être écarté ou conservé. *
+* *
+* Retour : true si le contenu doit être conservé, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool filter_loadable_content_with_python(GLoadedContent *content, PyObject *callable)
+{
+ bool result; /* Bilan à retourner */
+ PyGILState_STATE gstate; /* Sauvegarde d'environnement */
+ PyObject *arg; /* Argument à fournir au filtre*/
+ PyObject *status; /* Bilan de l'analyse */
+
+ gstate = PyGILState_Ensure();
+
+ if (content == NULL)
+ {
+ Py_DECREF(callable);
+ result = false;
+ }
+
+ else
+ {
+ arg = pygobject_new(G_OBJECT(content));
+
+ status = PyObject_CallFunctionObjArgs(callable, arg, NULL);
+
+ if (PyErr_Occurred())
+ PyErr_Print();
+
+ result = status == NULL || status == Py_False || status == Py_None ? false : true;
+ Py_XDECREF(status);
+
+ Py_DECREF(arg);
+
+ }
+
+ PyGILState_Release(gstate);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : self = projet d'étude à manipuler. *
* args = arguments accompagnant l'appel. *
* *
@@ -148,16 +202,32 @@ static PyObject *py_study_project_save(PyObject *self, PyObject *args)
static PyObject *py_study_project_discover_binary_content(PyObject *self, PyObject *args)
{
- GStudyProject *project; /* Version GLib du format */
- int ret; /* Bilan de lecture des args. */
+ PyObject *callable; /* Filtre de contenus éventuel */
GBinContent *content; /* Instance de contenu binaire */
+ int ret; /* Bilan de lecture des args. */
+ GStudyProject *project; /* Version GLib du format */
- project = G_STUDY_PROJECT(pygobject_get(self));
+ callable = NULL;
- ret = PyArg_ParseTuple(args, "O&", convert_to_binary_content, &content);
+ ret = PyArg_ParseTuple(args, "O&|O&",
+ convert_to_binary_content, &content,
+ convert_to_callable, &callable);
if (!ret) return NULL;
- g_study_project_discover_binary_content(project, content);
+ project = G_STUDY_PROJECT(pygobject_get(self));
+
+ if (callable != NULL)
+ {
+ Py_INCREF(callable);
+
+ g_study_project_discover_binary_content(project, content,
+ (filter_loadable_cb)filter_loadable_content_with_python,
+ callable);
+
+ }
+
+ else
+ g_study_project_discover_binary_content(project, content, NULL, NULL);
Py_RETURN_NONE;