From e5ac820b9ea8416537b65faaf43fdc45924a66b1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 15 Sep 2010 18:49:06 +1000 Subject: s4-pyrpc: added py_return_ndr_struct() This can be used to return structures from other python interfaces as python objects Pair-Programmed-With: Andrew Bartlett --- source4/librpc/rpc/pyrpc_util.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source4/librpc/rpc/pyrpc_util.c') diff --git a/source4/librpc/rpc/pyrpc_util.c b/source4/librpc/rpc/pyrpc_util.c index 2af868c0c2..f3911eeb9a 100644 --- a/source4/librpc/rpc/pyrpc_util.c +++ b/source4/librpc/rpc/pyrpc_util.c @@ -240,3 +240,34 @@ void PyErr_SetDCERPCStatus(struct dcerpc_pipe *p, NTSTATUS status) } +/* + take a NDR structure that has a type in a python module and return + it as a python object + + r is the NDR structure pointer (a C structure) + + r_ctx is the context that is a parent of r. It will be referenced by + the resulting python object + */ +PyObject *py_return_ndr_struct(const char *module_name, const char *type_name, + TALLOC_CTX *r_ctx, void *r) +{ + PyTypeObject *py_type; + PyObject *module; + + if (r == NULL) { + Py_RETURN_NONE; + } + + module = PyImport_ImportModule(module_name); + if (module == NULL) { + return NULL; + } + + py_type = (PyTypeObject *)PyObject_GetAttrString(module, type_name); + if (py_type == NULL) { + return NULL; + } + + return py_talloc_reference_ex(py_type, r_ctx, r); +} -- cgit