Cleanup references to module objects returned from PyImport_ImportModule
[gd/samba-autobuild/.git] / source4 / librpc / rpc / pyrpc_util.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    Python interface to DCE/RPC library - utility functions.
5
6    Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
7    Copyright (C) 2010 Andrew Tridgell <tridge@samba.org>
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #ifndef __PYRPC_UTIL_H__
24 #define __PYRPC_UTIL_H__
25
26 #include "librpc/rpc/pyrpc.h"
27
28 #define PyErr_FromNdrError(err) Py_BuildValue("(is)", err, ndr_map_error2string(err))
29
30 #define PyErr_SetNdrError(err) \
31                 PyErr_SetObject(PyExc_RuntimeError, PyErr_FromNdrError(err))
32
33 void PyErr_SetDCERPCStatus(struct dcerpc_pipe *p, NTSTATUS status);
34
35 typedef NTSTATUS (*py_dcerpc_call_fn) (struct dcerpc_binding_handle *, TALLOC_CTX *, void *);
36 typedef bool (*py_data_pack_fn) (PyObject *args, PyObject *kwargs, void *r);
37 typedef PyObject *(*py_data_unpack_fn) (void *r);
38
39 struct PyNdrRpcMethodDef {
40         const char *name;
41         const char *doc;
42         py_dcerpc_call_fn call;
43         py_data_pack_fn pack_in_data;
44         py_data_unpack_fn unpack_out_data;
45         uint32_t opnum;
46         const struct ndr_interface_table *table;
47 };
48
49 bool py_check_dcerpc_type(PyObject *obj, const char *module, const char *type_name);
50 bool PyInterface_AddNdrRpcMethods(PyTypeObject *object, const struct PyNdrRpcMethodDef *mds);
51 PyObject *py_dcerpc_interface_init_helper(PyTypeObject *type, PyObject *args, PyObject *kwargs, const struct ndr_interface_table *table);
52
53 struct ndr_syntax_id;
54 PyObject *py_dcerpc_syntax_init_helper(PyTypeObject *type, PyObject *args, PyObject *kwargs,
55                                        const struct ndr_syntax_id *syntax);
56
57 PyObject *py_return_ndr_struct(const char *module_name, const char *type_name,
58                                TALLOC_CTX *r_ctx, void *r);
59
60 PyObject *PyString_FromStringOrNULL(const char *str);
61
62 PyObject *pyrpc_import_union(PyTypeObject *type, TALLOC_CTX *mem_ctx, int level,
63                              const void *in, const char *typename);
64 void *pyrpc_export_union(PyTypeObject *type, TALLOC_CTX *mem_ctx, int level,
65                          PyObject *in, const char *typename);
66
67 PyObject *py_dcerpc_ndr_pointer_deref(PyTypeObject *type, PyObject *obj);
68 PyObject *py_dcerpc_ndr_pointer_wrap(PyTypeObject *type, PyObject *obj);
69
70 #endif /* __PYRPC_UTIL_H__ */