lib/torture: protect torture_assert[_goto]() with a do { } while(0) block
[bbaumbach/samba-autobuild/.git] / lib / ldb / pyldb.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    Python interface to ldb.
5
6    Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org>
7
8      ** NOTE! The following LGPL license applies to the ldb
9      ** library. This does NOT imply that all of Samba is released
10      ** under the LGPL
11    
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 3 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, see <http://www.gnu.org/licenses/>.
24 */
25
26 #ifndef _PYLDB_H_
27 #define _PYLDB_H_
28
29 #include <talloc.h>
30
31 typedef struct {
32         PyObject_HEAD
33         TALLOC_CTX *mem_ctx;
34         struct ldb_context *ldb_ctx;
35 } PyLdbObject;
36
37 /* pyldb_Ldb_AS_LDBCONTEXT() does not check argument validity,
38    pyldb_Ldb_AsLdbContext() does */
39 #define pyldb_Ldb_AS_LDBCONTEXT(pyobj) ((PyLdbObject *)pyobj)->ldb_ctx
40
41 #define pyldb_Ldb_AsLdbContext(pyobj)           \
42         (pyldb_check_type(pyobj, "Ldb") ?       \
43          pyldb_Ldb_AS_LDBCONTEXT(pyobj) : NULL)
44
45 typedef struct {
46         PyObject_HEAD
47         TALLOC_CTX *mem_ctx;
48         struct ldb_dn *dn;
49 } PyLdbDnObject;
50
51 PyObject *pyldb_Dn_FromDn(struct ldb_dn *);
52 bool pyldb_Object_AsDn(TALLOC_CTX *mem_ctx, PyObject *object, struct ldb_context *ldb_ctx, struct ldb_dn **dn);
53 #define pyldb_Dn_AS_DN(pyobj) ((PyLdbDnObject *)pyobj)->dn
54
55 bool pyldb_check_type(PyObject *obj, const char *type_name);
56
57 typedef struct {
58         PyObject_HEAD
59         TALLOC_CTX *mem_ctx;
60         struct ldb_message *msg;
61 } PyLdbMessageObject;
62 #define pyldb_Message_AsMessage(pyobj) ((PyLdbMessageObject *)pyobj)->msg
63
64 typedef struct {
65         PyObject_HEAD
66         TALLOC_CTX *mem_ctx;
67         struct ldb_module *mod;
68 } PyLdbModuleObject;
69 #define pyldb_Module_AsModule(pyobj) ((PyLdbModuleObject *)pyobj)->mod
70
71 /*
72  * NOTE: el (and so the return value of
73  * pyldb_MessageElement_AsMessageElement()) may not be a valid talloc
74  * context, it could be part of an array
75  */
76
77 typedef struct {
78         PyObject_HEAD
79         TALLOC_CTX *mem_ctx;
80         struct ldb_message_element *el;
81 } PyLdbMessageElementObject;
82
83 #define pyldb_MessageElement_AsMessageElement(pyobj) ((PyLdbMessageElementObject *)pyobj)->el
84
85 typedef struct {
86         PyObject_HEAD
87         TALLOC_CTX *mem_ctx;
88         struct ldb_parse_tree *tree;
89 } PyLdbTreeObject;
90 #define pyldb_Tree_AsTree(pyobj) ((PyLdbTreeObject *)pyobj)->tree
91
92 typedef struct {
93         PyObject_HEAD
94         TALLOC_CTX *mem_ctx;
95         PyObject *msgs;
96         PyObject *referals;
97         PyObject *controls;
98 } PyLdbResultObject;
99
100 typedef struct {
101         PyObject_HEAD
102         TALLOC_CTX *mem_ctx;
103         struct ldb_control *data;
104 } PyLdbControlObject;
105
106 #define PyErr_LDB_ERROR_IS_ERR_RAISE(err,ret,ldb) do { \
107         if (ret != LDB_SUCCESS) { \
108                 PyErr_SetLdbError(err, ret, ldb); \
109                 return NULL; \
110         } \
111 } while(0)
112
113 /* Picked out of thin air. To do this properly, we should probably have some part of the 
114  * errors in LDB be allocated to bindings ? */
115 #define LDB_ERR_PYTHON_EXCEPTION        142
116
117 #endif /* _PYLDB_H_ */