1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-05 20:58:40 +03:00

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 <abartlet@samba.org>
This commit is contained in:
Andrew Tridgell 2010-09-15 18:49:06 +10:00
parent f89f3cf30f
commit e5ac820b9e
2 changed files with 34 additions and 0 deletions

View File

@ -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);
}

View File

@ -55,4 +55,7 @@ bool py_check_dcerpc_type(PyObject *obj, const char *module, const char *typenam
bool PyInterface_AddNdrRpcMethods(PyTypeObject *object, const struct PyNdrRpcMethodDef *mds);
PyObject *py_dcerpc_interface_init_helper(PyTypeObject *type, PyObject *args, PyObject *kwargs, const struct ndr_interface_table *table);
PyObject *py_return_ndr_struct(const char *module_name, const char *type_name,
TALLOC_CTX *r_ctx, void *r);
#endif /* __PYRPC_UTIL_H__ */