lib/talloc: sync build system changes from samba4
[jra/samba/.git] / source3 / 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 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 %module tdb
27
28 %{
29
30 /* This symbol is used in both includes.h and Python.h which causes an
31    annoying compiler warning. */
32
33 #ifdef HAVE_FSTAT
34 #undef HAVE_FSTAT
35 #endif
36
37 #if (__GNUC__ >= 3)
38 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
39  * the parameter containing the format, and a2 the index of the first
40  * argument. Note that some gcc 2.x versions don't handle this
41  * properly **/
42 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
43 #else
44 #define PRINTF_ATTRIBUTE(a1, a2)
45 #endif
46
47 /* Include tdb headers */
48
49 #include "lib/tdb/include/tdb.h"
50
51 %}
52
53 /* The tdb functions will crash if a NULL tdb context is passed */
54
55 %include exception.i
56
57 %typemap(check) TDB_CONTEXT* {
58         if ($1 == NULL)
59                 SWIG_exception(SWIG_ValueError, 
60                         "tdb context must be non-NULL");
61 }
62
63 /* In and out typemaps for the TDB_DATA structure.  This is converted to
64    and from the Python string type which can contain arbitrary binary
65    data.. */
66
67 %typemap(in) TDB_DATA {
68         if (!PyString_Check($input)) {
69                 PyErr_SetString(PyExc_TypeError, "string arg expected");
70                 return NULL;
71         }
72         $1.dsize = PyString_Size($input);
73         $1.dptr = PyString_AsString($input);
74 }
75
76 %typemap(out) TDB_DATA {
77         if ($1.dptr == NULL && $1.dsize == 0) {
78                 $result = Py_None;
79         } else {
80                 $result = PyString_FromStringAndSize($1.dptr, $1.dsize);
81                 free($1.dptr);
82         }
83 }
84
85 /* Treat a mode_t as an unsigned integer */
86
87 typedef int mode_t;
88
89 /* flags to tdb_store() */
90
91 #define TDB_REPLACE 1
92 #define TDB_INSERT 2
93 #define TDB_MODIFY 3
94
95 /* flags for tdb_open() */
96
97 #define TDB_DEFAULT 0 /* just a readability place holder */
98 #define TDB_CLEAR_IF_FIRST 1
99 #define TDB_INTERNAL 2 /* don't store on disk */
100 #define TDB_NOLOCK   4 /* don't do any locking */
101 #define TDB_NOMMAP   8 /* don't use mmap */
102 #define TDB_CONVERT 16 /* convert endian (internal use) */
103 #define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */
104
105 /* Throw an IOError exception if tdb_open() or tdb_open_ex() returns NULL */
106
107 %exception {
108         $action
109         if (result == NULL) {
110                 PyErr_SetFromErrno(PyExc_IOError);
111                 SWIG_fail;
112         }
113 }
114
115 TDB_CONTEXT *tdb_open(const char *name, int hash_size, int tdb_flags,
116                       int open_flags, mode_t mode);
117
118 TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
119                          int open_flags, mode_t mode,
120                          tdb_log_func log_fn,
121                          tdb_hash_func hash_fn);
122
123 %exception;
124
125 int tdb_reopen(TDB_CONTEXT *tdb);
126
127 int tdb_reopen_all(int parent_longlived);
128
129 void tdb_logging_function(TDB_CONTEXT *tdb, tdb_log_func);
130
131 enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb);
132
133 const char *tdb_errorstr(TDB_CONTEXT *tdb);
134
135 TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key);
136
137 int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key);
138
139 int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag = TDB_REPLACE);
140
141 int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf);
142
143 int tdb_close(TDB_CONTEXT *tdb);
144
145 TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
146
147 TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key);
148
149 int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *state);
150
151 int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key);
152
153 int tdb_lockall(TDB_CONTEXT *tdb);
154
155 void tdb_unlockall(TDB_CONTEXT *tdb);
156
157 /* Low level locking functions: use with care */
158
159 int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key);
160
161 int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key);
162
163 /* Debug functions. Not used in production. */
164
165 void tdb_dump_all(TDB_CONTEXT *tdb);
166
167 int tdb_printfreelist(TDB_CONTEXT *tdb);