r15092: Remove some swig stuff that didn't work out and the %rename call.
[bbaumbach/samba-autobuild/.git] / source4 / lib / ldb / swig / ldb.i
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Swig interface to ldb.
5
6    Copyright (C) 2005,2006 Tim Potter <tpot@samba.org>
7    Copyright (C) 2006 Simo Sorce <idra@samba.org>
8
9      ** NOTE! The following LGPL license applies to the ldb
10      ** library. This does NOT imply that all of Samba is released
11      ** under the LGPL
12    
13    This library is free software; you can redistribute it and/or
14    modify it under the terms of the GNU Lesser General Public
15    License as published by the Free Software Foundation; either
16    version 2 of the License, or (at your option) any later version.
17
18    This library is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21    Lesser General Public License for more details.
22
23    You should have received a copy of the GNU Lesser General Public
24    License along with this library; if not, write to the Free Software
25    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 */
27
28 %module ldb
29
30 %{
31
32 /* Some typedefs to help swig along */
33
34 typedef unsigned char uint8_t;
35 typedef unsigned long long uint64_t;
36 typedef long long int64_t;
37
38 /* Include headers */
39
40 #include "lib/ldb/include/ldb.h"
41 #include "lib/talloc/talloc.h"
42
43 %}
44
45 %include "carrays.i"
46 %include "exception.i"
47
48 /* 
49  * Wrap struct ldb_context
50  */
51
52 /* The ldb functions will crash if a NULL ldb context is passed so
53    catch this before it happens. */
54
55 %typemap(check) struct ldb_context* {
56         if ($1 == NULL)
57                 SWIG_exception(SWIG_ValueError, 
58                         "ldb context must be non-NULL");
59 }
60
61 /* 
62  * Wrap TALLOC_CTX
63  */
64
65 /* Use talloc_init() to create a parameter to pass to ldb_init().  Don't
66    forget to free it using talloc_free() afterwards. */
67
68 TALLOC_CTX *talloc_init(char *name);
69 int talloc_free(TALLOC_CTX *ptr);
70
71 /*
72  * Wrap struct ldb_val
73  */
74
75 %typemap(in) struct ldb_val * (struct ldb_val temp) {
76         $1 = &temp;
77         if (!PyString_Check($input)) {
78                 PyErr_SetString(PyExc_TypeError, "string arg expected");
79                 return NULL;
80         }
81         $1->length = PyString_Size($input);
82         $1->data = PyString_AsString($input);
83 }
84
85 %typemap(out) struct ldb_val * {
86         if ($1->data == NULL && $1->length == 0) {
87                 Py_INCREF(Py_None);
88                 $result = Py_None;
89         } else {
90                 $result = PyString_FromStringAndSize($1->data, $1->length);
91         }
92 }
93
94 enum ldb_scope {LDB_SCOPE_DEFAULT=-1, 
95                 LDB_SCOPE_BASE=0, 
96                 LDB_SCOPE_ONELEVEL=1,
97                 LDB_SCOPE_SUBTREE=2};
98
99 /*
100  * Wrap struct ldb_result
101  */
102
103 %typemap(in, numinputs=0) struct ldb_result **OUT (struct ldb_result *temp_ldb_result) {
104         $1 = &temp_ldb_result;
105 }
106
107 %typemap(argout) struct ldb_result ** {
108         resultobj = SWIG_NewPointerObj(*$1, SWIGTYPE_p_ldb_result, 0);
109 }       
110
111 %types(struct ldb_result *);
112
113 /*
114  * Wrap struct ldb_message_element
115  */
116
117 %array_functions(struct ldb_val, ldb_val_array);
118
119 struct ldb_message_element {
120         unsigned int flags;
121         const char *name;
122         unsigned int num_values;
123         struct ldb_val *values;
124 };
125
126 /*
127  * Wrap struct ldb_message
128  */
129
130 %array_functions(struct ldb_message_element, ldb_message_element_array);
131
132 struct ldb_message {
133         struct ldb_dn *dn;
134         unsigned int num_elements;
135         struct ldb_message_element *elements;
136         void *private_data;
137 };
138
139 /*
140  * Wrap struct ldb_result
141  */
142
143 %array_functions(struct ldb_message *, ldb_message_ptr_array);
144
145 struct ldb_result {
146         unsigned int count;
147         struct ldb_message **msgs;
148         char **refs;
149         struct ldb_control **controls;
150 };
151
152 /*
153  * Wrap ldb functions 
154  */
155
156 struct ldb_context *ldb_init(TALLOC_CTX *mem_ctx);
157
158 const char *ldb_errstring(struct ldb_context *ldb);
159
160 int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[]);
161
162 int ldb_search(struct ldb_context *ldb, const struct ldb_dn *base, enum ldb_scope scope, const char *expression, const char * const *attrs, struct ldb_result **OUT);
163
164 int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn);
165
166 int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct ldb_dn *newdn);
167
168 int ldb_add(struct ldb_context *ldb, const struct ldb_message *message);
169
170 struct ldb_message *ldb_msg_new(void *mem_ctx);
171 struct ldb_message_element *ldb_msg_find_element(const struct ldb_message *msg, const char *attr_name);
172 int ldb_msg_add_value(struct ldb_message *msg, const char *attr_name, const struct ldb_val *val);