8f473c61e6be6071b889fbbb1d8d2f09a1da8b44
[ira/wip.git] / source4 / lib / tdb / swig / tdb.i
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Swig interface to tdb.
5
6    Copyright (C) 2004,2005 Tim Potter <tpot@samba.org>
7
8      ** NOTE! The following LGPL license applies to the tdb
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 2 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, write to the Free Software
24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25 */
26
27 %module tdb
28
29 %{
30
31 /* This symbol is used in both includes.h and Python.h which causes an
32    annoying compiler warning. */
33
34 #ifdef HAVE_FSTAT
35 #undef HAVE_FSTAT
36 #endif
37
38 #if (__GNUC__ >= 3)
39 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
40  * the parameter containing the format, and a2 the index of the first
41  * argument. Note that some gcc 2.x versions don't handle this
42  * properly **/
43 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
44 #else
45 #define PRINTF_ATTRIBUTE(a1, a2)
46 #endif
47
48 /* Include tdb headers */
49
50 #include "lib/tdb/include/tdb.h"
51
52 %}
53
54 /* The tdb functions will crash if a NULL tdb context is passed */
55
56 %include exception.i
57
58 %typemap(check) TDB_CONTEXT* {
59         if ($1 == NULL)
60                 SWIG_exception(SWIG_ValueError, 
61                         "tdb context must be non-NULL");
62 }
63
64 /* In and out typemaps for the TDB_DATA structure.  This is converted to
65    and from the Python string type which can contain arbitrary binary
66    data.. */
67
68 %typemap(in) TDB_DATA {
69         if (!PyString_Check($input)) {
70                 PyErr_SetString(PyExc_TypeError, "string arg expected");
71                 return NULL;
72         }
73         $1.dsize = PyString_Size($input);
74         $1.dptr = PyString_AsString($input);
75 }
76
77 %typemap(out) TDB_DATA {
78         if ($1.dptr == NULL && $1.dsize == 0) {
79                 $result = Py_None;
80         } else {
81                 $result = PyString_FromStringAndSize($1.dptr, $1.dsize);
82                 free($1.dptr);
83         }
84 }
85
86 /* Treat a mode_t as an unsigned integer */
87
88 typedef int mode_t;
89
90 /* flags to tdb_store() */
91
92 #define TDB_REPLACE 1
93 #define TDB_INSERT 2
94 #define TDB_MODIFY 3
95
96 /* flags for tdb_open() */
97
98 #define TDB_DEFAULT 0 /* just a readability place holder */
99 #define TDB_CLEAR_IF_FIRST 1
100 #define TDB_INTERNAL 2 /* don't store on disk */
101 #define TDB_NOLOCK   4 /* don't do any locking */
102 #define TDB_NOMMAP   8 /* don't use mmap */
103 #define TDB_CONVERT 16 /* convert endian (internal use) */
104 #define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */
105
106 /* Throw an IOError exception if tdb_open() or tdb_open_ex() returns NULL */
107
108 %exception {
109         $action
110         if (result == NULL) {
111                 PyErr_SetFromErrno(PyExc_IOError);
112                 SWIG_fail;
113         }
114 }
115
116 %rename tdb_open open;
117 TDB_CONTEXT *tdb_open(const char *name, int hash_size, int tdb_flags,
118                       int open_flags, mode_t mode);
119
120 %rename tdb_open_ex open_ex;
121 TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
122                          int open_flags, mode_t mode,
123                          tdb_log_func log_fn,
124                          tdb_hash_func hash_fn);
125
126 %exception;
127
128 %rename tdb_reopen reopen;
129 int tdb_reopen(TDB_CONTEXT *tdb);
130
131 %rename tdb_reopen_all reopen_all;
132 int tdb_reopen_all(void);
133
134 %rename tdb_logging_function logging_function;
135 void tdb_logging_function(TDB_CONTEXT *tdb, tdb_log_func);
136
137 %rename tdb_error error;
138 enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb);
139
140 %rename tdb_errorstr errorstr;
141 const char *tdb_errorstr(TDB_CONTEXT *tdb);
142
143 %rename tdb_fetch fetch;
144 TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key);
145
146 %rename tdb_delete delete;
147 int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key);
148
149 %rename tdb_store store;
150 int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag = TDB_REPLACE);
151
152 %rename tdb_append append;
153 int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf);
154
155 %rename tdb_close close;
156 int tdb_close(TDB_CONTEXT *tdb);
157
158 %rename tdb_firstkey firstkey;
159 TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
160
161 %rename tdb_nextkey nextkey;
162 TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key);
163
164 %rename tdb_traverse traverse;
165 int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *state);
166
167 %rename tdb_exists exists;
168 int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key);
169
170 %rename tdb_lockall lockall;
171 int tdb_lockall(TDB_CONTEXT *tdb);
172
173 %rename tdb_unlockall unlockall;
174 void tdb_unlockall(TDB_CONTEXT *tdb);
175
176 /* Low level locking functions: use with care */
177
178 %rename tdb_chainlock chainlock;
179 int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key);
180
181 %rename tdb_chainunlock chainunlock;
182 int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key);
183
184 /* Debug functions. Not used in production. */
185
186 %rename tdb_dump_all dump_all;
187 void tdb_dump_all(TDB_CONTEXT *tdb);
188
189 %rename tdb_printfreelist printfreelist;
190 int tdb_printfreelist(TDB_CONTEXT *tdb);