summaryrefslogtreecommitdiff
path: root/source4/librpc
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-09-15 18:49:06 +1000
committerAndrew Tridgell <tridge@samba.org>2010-09-16 07:24:01 +1000
commite5ac820b9ea8416537b65faaf43fdc45924a66b1 (patch)
treebf856fa625aef5baacbf1e998cfe361e5a062761 /source4/librpc
parentf89f3cf30fad625d03de600b85e542791125c8f5 (diff)
downloadsamba-e5ac820b9ea8416537b65faaf43fdc45924a66b1.tar.gz
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>
Diffstat (limited to 'source4/librpc')
-rw-r--r--source4/librpc/rpc/pyrpc_util.c31
-rw-r--r--source4/librpc/rpc/pyrpc_util.h3
2 files changed, 34 insertions, 0 deletions
diff --git a/source4/librpc/rpc/pyrpc_util.c b/source4/librpc/rpc/pyrpc_util.c
index 2af868c0c2c..f3911eeb9ab 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);
+}
diff --git a/source4/librpc/rpc/pyrpc_util.h b/source4/librpc/rpc/pyrpc_util.h
index abd7f6ba7b9..1efe112a112 100644
--- a/source4/librpc/rpc/pyrpc_util.h
+++ b/source4/librpc/rpc/pyrpc_util.h
@@ -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__ */