summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/contents/restricted.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/analysis/contents/restricted.c')
-rw-r--r--plugins/pychrysalide/analysis/contents/restricted.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/plugins/pychrysalide/analysis/contents/restricted.c b/plugins/pychrysalide/analysis/contents/restricted.c
index 703f79b..4521578 100644
--- a/plugins/pychrysalide/analysis/contents/restricted.c
+++ b/plugins/pychrysalide/analysis/contents/restricted.c
@@ -31,19 +31,21 @@
#include <i18n.h>
-#include <analysis/contents/restricted.h>
+#include <i18n.h>
+#include <analysis/contents/restricted-int.h>
#include "../content.h"
-#include "../storage/serialize.h"
#include "../../access.h"
#include "../../helpers.h"
#include "../../arch/vmpa.h"
-/* Crée un nouvel objet Python de type 'BinContent'. */
-static PyObject *py_restricted_content_new(PyTypeObject *, PyObject *, PyObject *);
+CREATE_DYN_CONSTRUCTOR(restricted_content, G_TYPE_RESTRICTED_CONTENT);
+
+/* Initialise une instance sur la base du dérivé de GObject. */
+static int py_restricted_content_init(PyObject *, PyObject *, PyObject *);
/* Indique l'espace de restriction appliqué à un contenu. */
static PyObject *py_restricted_content_get_range(PyObject *, void *);
@@ -52,25 +54,24 @@ static PyObject *py_restricted_content_get_range(PyObject *, void *);
/******************************************************************************
* *
-* Paramètres : type = type de l'objet à instancier. *
+* Paramètres : self = objet à initialiser (théoriquement). *
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
* *
-* Description : Crée un nouvel objet Python de type 'BinContent'. *
+* Description : Initialise une instance sur la base du dérivé de GObject. *
* *
-* Retour : Instance Python mise en place. *
+* Retour : 0. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_restricted_content_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+static int py_restricted_content_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- PyObject *result; /* Instance à retourner */
- GBinContent *content; /* Instance GLib correspondante*/
+ GBinContent *internal; /* Instance GLib correspondante*/
mrange_t range; /* Restriction à appliquer */
int ret; /* Bilan de lecture des args. */
- GBinContent *restricted; /* Création GLib à transmettre */
+ GRestrictedContent *content; /* Version GLib du contenu */
#define RESTRICTED_CONTENT_DOC \
"RestrictedContent restricts access to a given area for a binary content." \
@@ -82,14 +83,27 @@ static PyObject *py_restricted_content_new(PyTypeObject *type, PyObject *args, P
"Where content is a pychrysalide.analysis.BinContent instance and range" \
" a Python object which can be converted into pychrysalide.arch.mrange."
- ret = PyArg_ParseTuple(args, "O&O&", convert_to_binary_content, &content, convert_any_to_mrange, &range);
- if (!ret) return NULL;
+ /* Récupération des paramètres */
- restricted = g_restricted_content_new(content, &range);
+ ret = PyArg_ParseTuple(args, "O&O&", convert_to_binary_content, &internal, convert_any_to_mrange, &range);
+ if (!ret) return -1;
- result = pygobject_new(G_OBJECT(restricted));
+ /* Initialisation d'un objet GLib */
- return result;
+ ret = forward_pygobjet_init(self);
+ if (ret == -1) return -1;
+
+ /* Eléments de base */
+
+ content = G_RESTRICTED_CONTENT(pygobject_get(self));
+
+ if (!g_restricted_content_create(content, internal, &range))
+ {
+ PyErr_SetString(PyExc_ValueError, _("Unable to create restricted content."));
+ return -1;
+ }
+
+ return 0;
}
@@ -166,7 +180,9 @@ PyTypeObject *get_python_restricted_content_type(void)
.tp_methods = py_restricted_content_methods,
.tp_getset = py_restricted_content_getseters,
- .tp_new = py_restricted_content_new
+
+ .tp_init = py_restricted_content_init,
+ .tp_new = py_restricted_content_new,
};
@@ -201,10 +217,10 @@ bool ensure_python_restricted_content_is_registered(void)
dict = PyModule_GetDict(module);
- if (!ensure_python_serializable_object_is_registered())
+ if (!ensure_python_binary_content_is_registered())
return false;
- if (!register_class_for_pygobject(dict, G_TYPE_RESTRICTED_CONTENT, type, &PyGObject_Type))
+ if (!register_class_for_pygobject(dict, G_TYPE_RESTRICTED_CONTENT, type))
return false;
}