r17607: Adapt the Samba4 directory structure for tdb. Makes it easier to diff.
authorVolker Lendecke <vlendec@samba.org>
Fri, 18 Aug 2006 16:25:09 +0000 (16:25 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:38:42 +0000 (11:38 -0500)
Let's see what it breaks. For me it works :-)

Volker
(This used to be commit 337be14b432e5dfd80c7418b2db4fe0087259b77)

35 files changed:
source3/Makefile.in
source3/include/includes.h
source3/tdb/Makefile [deleted file]
source3/tdb/Makefile.in [new file with mode: 0644]
source3/tdb/aclocal.m4 [new file with mode: 0644]
source3/tdb/autogen.sh [new file with mode: 0755]
source3/tdb/common/dump.c [moved from source3/tdb/dump.c with 100% similarity]
source3/tdb/common/error.c [moved from source3/tdb/error.c with 100% similarity]
source3/tdb/common/freelist.c [moved from source3/tdb/freelist.c with 100% similarity]
source3/tdb/common/io.c [moved from source3/tdb/io.c with 100% similarity]
source3/tdb/common/lock.c [moved from source3/tdb/lock.c with 100% similarity]
source3/tdb/common/open.c [moved from source3/tdb/open.c with 100% similarity]
source3/tdb/common/tdb.c [moved from source3/tdb/tdb.c with 100% similarity]
source3/tdb/common/tdb_private.h [moved from source3/tdb/tdb_private.h with 100% similarity]
source3/tdb/common/tdbback.c [moved from source3/tdb/tdbback.c with 100% similarity]
source3/tdb/common/tdbutil.c [moved from source3/tdb/tdbutil.c with 100% similarity]
source3/tdb/common/transaction.c [moved from source3/tdb/transaction.c with 100% similarity]
source3/tdb/common/traverse.c [moved from source3/tdb/traverse.c with 100% similarity]
source3/tdb/config.m4 [new file with mode: 0644]
source3/tdb/config.mk [new file with mode: 0644]
source3/tdb/configure.in [new file with mode: 0644]
source3/tdb/docs/README [moved from source3/tdb/README with 66% similarity]
source3/tdb/docs/tdb.magic [moved from source3/tdb/tdb.magic with 100% similarity]
source3/tdb/include/tdb.h [moved from source3/tdb/tdb.h with 100% similarity]
source3/tdb/include/tdbback.h [moved from source3/tdb/tdbback.h with 100% similarity]
source3/tdb/include/tdbconfig.h.in [new file with mode: 0644]
source3/tdb/include/tdbutil.h [moved from source3/tdb/tdbutil.h with 100% similarity]
source3/tdb/swig/Tdb.py [new file with mode: 0644]
source3/tdb/swig/tdb.i [new file with mode: 0644]
source3/tdb/tdb.pc.in [new file with mode: 0644]
source3/tdb/tools/tdbbackup.c [moved from source3/tdb/tdbbackup.c with 100% similarity]
source3/tdb/tools/tdbdump.c [moved from source3/tdb/tdbdump.c with 100% similarity]
source3/tdb/tools/tdbtest.c [moved from source3/tdb/tdbtest.c with 100% similarity]
source3/tdb/tools/tdbtool.c [moved from source3/tdb/tdbtool.c with 100% similarity]
source3/tdb/tools/tdbtorture.c [moved from source3/tdb/tdbtorture.c with 100% similarity]

index 0ff5872063bb5f40829ac40d9e2b27b60c740b66..8f4f50a41acaeeaa79963ac5c911810344fe99d6 100644 (file)
@@ -116,7 +116,7 @@ LIBSMBSHAREMODES=bin/libsmbsharemodes.a @LIBSMBSHAREMODES_SHARED@
 LIBSMBSHAREMODES_MAJOR=0
 LIBSMBSHAREMODES_MINOR=2
 
-FLAGS1 = $(CFLAGS) @FLAGS1@ -Iinclude -I$(srcdir)/include -I$(srcdir)/tdb @SMBWRAP_INC@ -I. $(CPPFLAGS) -I$(srcdir) -D_SAMBA_BUILD_ 
+FLAGS1 = $(CFLAGS) @FLAGS1@ -Iinclude -I$(srcdir)/include -I$(srcdir)/tdb/include @SMBWRAP_INC@ -I. $(CPPFLAGS) -I$(srcdir) -D_SAMBA_BUILD_ 
 FLAGS2 =
 FLAGS3 = 
 FLAGS4 = 
@@ -176,10 +176,11 @@ MODULES = $(VFS_MODULES) $(PDB_MODULES) $(RPC_MODULES) $(IDMAP_MODULES) $(CHARSE
 # object file lists
 ######################################################################
 
-TDBBASE_OBJ = tdb/tdb.o tdb/dump.o tdb/error.o tdb/freelist.o tdb/io.o \
-       tdb/lock.o tdb/open.o tdb/transaction.o tdb/traverse.o
+TDBBASE_OBJ = tdb/common/tdb.o tdb/common/dump.o tdb/common/error.o \
+       tdb/common/freelist.o tdb/common/io.o tdb/common/lock.o \
+       tdb/common/open.o tdb/common/transaction.o tdb/common/traverse.o
 
-TDB_OBJ = $(TDBBASE_OBJ) tdb/tdbutil.o tdb/tdbback.o
+TDB_OBJ = $(TDBBASE_OBJ) tdb/common/tdbutil.o tdb/common/tdbback.o
 
 SMBLDAP_OBJ = @SMBLDAP@ @SMBLDAPUTIL@
 
@@ -545,7 +546,7 @@ CAC_OBJ = $(LIBSMBCLIENT_OBJ) \
                         libmsrpc/cac_lsarpc.o libmsrpc/cac_winreg.o libmsrpc/cac_samr.o \
                         libmsrpc/cac_svcctl.o
 
-LIBSMBSHAREMODES_OBJ = libsmb/smb_share_modes.o tdb/tdb.o
+LIBSMBSHAREMODES_OBJ = libsmb/smb_share_modes.o $(TDB_BASE_OBJ)
 
 # This shared library is intended for linking with unit test programs
 # to test Samba internals.  It's called libbigballofmud.so to
@@ -751,11 +752,12 @@ POPT_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
 INIPARSER_OBJ = iniparser/src/iniparser.o iniparser/src/dictionary.o \
                iniparser/src/strlib.o
 
-TDBBACKUP_OBJ = tdb/tdbbackup.o tdb/tdbback.o $(SNPRINTF_OBJ) $(TDBBASE_OBJ)
+TDBBACKUP_OBJ = tdb/tools/tdbbackup.o tdb/common/tdbback.o $(SNPRINTF_OBJ) \
+       $(TDBBASE_OBJ)
 
-TDBTOOL_OBJ = tdb/tdbtool.o $(TDBBASE_OBJ) $(SNPRINTF_OBJ)
+TDBTOOL_OBJ = tdb/tools/tdbtool.o $(TDBBASE_OBJ) $(SNPRINTF_OBJ)
 
-TDBDUMP_OBJ = tdb/tdbdump.o $(TDBBASE_OBJ) $(SNPRINTF_OBJ)
+TDBDUMP_OBJ = tdb/tools/tdbdump.o $(TDBBASE_OBJ) $(SNPRINTF_OBJ)
 
 NTLM_AUTH_OBJ1 = utils/ntlm_auth.o utils/ntlm_auth_diagnostics.o 
 
@@ -1655,6 +1657,7 @@ TOPFILES=dynconfig.o dynconfig.@PICSUFFIX@
 
 clean: delheaders python_clean
        -rm -f core */*~ *~ */*.o */*.@PICSUFFIX@ */*.@SHLIBEXT@ \
+               tdb/*/*.o tdb/*/*.@PICSUFFIX@ tdb/*/*.@SHLIBEXT@ \
                $(TOPFILES) $(BIN_PROGS) $(SBIN_PROGS) $(ROOT_SBIN_PROGS) \
                $(MODULES) $(TORTURE_PROGS) $(LIBSMBCLIENT) \
                $(LIBSMBSHAREMODES) $(EVERYTHING_PROGS) $(LIBMSRPC) \
index 86d7f069cda8bc97b41d17d6e1a750b7fd13823a..bd65edbab03ccd15ee14cb63e5b57d081af49f05 100644 (file)
@@ -913,9 +913,9 @@ extern int errno;
 #include "xfile.h"
 #include "intl.h"
 #include "dlinklist.h"
-#include "tdb/tdb.h"
-#include "tdb/tdbutil.h"
-#include "tdb/tdbback.h"
+#include "tdb.h"
+#include "tdbutil.h"
+#include "tdbback.h"
 
 #include "talloc.h"
 /* And a little extension. Abort on type mismatch */
diff --git a/source3/tdb/Makefile b/source3/tdb/Makefile
deleted file mode 100644 (file)
index e824a7c..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Makefile for tdb directory
-#
-
-CFLAGS = -DSTANDALONE -DTDB_DEBUG -g -DHAVE_MMAP=1
-CC = gcc
-
-ADMINPROGS = tdbdump tdbbackup
-PROGS = tdbtest tdbtool tdbtorture
-TDB_OBJ = tdb.o tdbback.o dump.o error.o freelist.o io.o lock.o open.o traverse.o transaction.o
-
-default: $(PROGS)
-
-admintools: $(ADMINPROGS)
-
-tdbtest: tdbtest.o $(TDB_OBJ)
-       $(CC) $(CFLAGS) -o tdbtest tdbtest.o $(TDB_OBJ) -lgdbm
-
-tdbtool: tdbtool.o $(TDB_OBJ)
-       $(CC) $(CFLAGS) -o tdbtool tdbtool.o $(TDB_OBJ)
-
-tdbtorture: tdbtorture.o $(TDB_OBJ)
-       $(CC) $(CFLAGS) -o tdbtorture tdbtorture.o $(TDB_OBJ)
-
-tdbdump: tdbdump.o $(TDB_OBJ)
-       $(CC) $(CFLAGS) -o tdbdump tdbdump.o $(TDB_OBJ)
-
-tdbbackup: tdbbackup.o $(TDB_OBJ)
-       $(CC) $(CFLAGS) -o tdbbackup tdbbackup.o $(TDB_OBJ)
-
-clean:
-       rm -f $(PROGS) *.o *~ *% core test.db test.tdb test.gdbm
diff --git a/source3/tdb/Makefile.in b/source3/tdb/Makefile.in
new file mode 100644 (file)
index 0000000..1c23aae
--- /dev/null
@@ -0,0 +1,54 @@
+#
+# Makefile for tdb directory
+#
+
+CFLAGS = -Iinclude @CFLAGS@
+CC = @CC@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+bindir = @bindir@
+includedir = @includedir@
+libdir = @libdir@
+
+PROGS = bin/tdbtool bin/tdbtorture
+TDB_OBJ = common/tdb.o common/dump.o common/io.o common/lock.o \
+       common/open.o common/traverse.o common/freelist.o common/error.o \
+       common/transaction.o
+
+all: $(PROGS)
+
+.c.o:
+       @echo Compiling $*.c
+       @$(CC) $(CFLAGS) -c $< -o $@
+
+install: all
+       mkdir -p $(bindir)
+       mkdir -p $(includedir)
+       mkdir -p $(libdir) 
+       mkdir -p $(libdir)/pkgconfig
+       cp $(PROGS) $(bindir)
+       cp include/tdb.h $(includedir)
+       cp tdb.pc $(libdir)/pkgconfig
+
+bin/tdbtest: tools/tdbtest.o $(TDB_OBJ)
+       $(CC) $(CFLAGS) -o bin/tdbtest tools/tdbtest.o $(TDB_OBJ) -lgdbm
+
+bin/tdbtool: tools/tdbtool.o $(TDB_OBJ)
+       $(CC) $(CFLAGS) -o bin/tdbtool tools/tdbtool.o $(TDB_OBJ)
+
+bin/tdbtorture: tools/tdbtorture.o $(TDB_OBJ)
+       $(CC) $(CFLAGS) -o bin/tdbtorture tools/tdbtorture.o $(TDB_OBJ)
+
+bin/tdbdump: tools/tdbdump.o $(TDB_OBJ)
+       $(CC) $(CFLAGS) -o bin/tdbdump tools/tdbdump.o $(TDB_OBJ)
+
+bin/tdbbackup: tools/tdbbackup.o $(TDB_OBJ)
+       $(CC) $(CFLAGS) -o bin/tdbbackup tools/tdbbackup.o $(TDB_OBJ)
+
+clean:
+       rm -f $(PROGS) common/*.o tools/*.o *~ *.bak */*~ */*.bak *% core test.db test.tdb test.gdbm
+
+installcheck: install
+       $(bindir)/tdbtorture
+
+test: installcheck
diff --git a/source3/tdb/aclocal.m4 b/source3/tdb/aclocal.m4
new file mode 100644 (file)
index 0000000..cdc2a2f
--- /dev/null
@@ -0,0 +1,12 @@
+dnl see if a declaration exists for a function or variable
+dnl defines HAVE_function_DECL if it exists
+dnl AC_HAVE_DECL(var, includes)
+AC_DEFUN(AC_HAVE_DECL,
+[
+ AC_CACHE_CHECK([for $1 declaration],ac_cv_have_$1_decl,[
+    AC_TRY_COMPILE([$2],[int i = (int)$1],
+        ac_cv_have_$1_decl=yes,ac_cv_have_$1_decl=no)])
+ if test x"$ac_cv_have_$1_decl" = x"yes"; then
+    AC_DEFINE([HAVE_]translit([$1], [a-z], [A-Z])[_DECL],1,[Whether $1() is available])
+ fi
+])
diff --git a/source3/tdb/autogen.sh b/source3/tdb/autogen.sh
new file mode 100755 (executable)
index 0000000..89053ad
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+autoheader || exit 1
+autoconf || exit 1
+
+echo "Now run ./configure and then make."
+exit 0
+
similarity index 100%
rename from source3/tdb/dump.c
rename to source3/tdb/common/dump.c
similarity index 100%
rename from source3/tdb/io.c
rename to source3/tdb/common/io.c
similarity index 100%
rename from source3/tdb/lock.c
rename to source3/tdb/common/lock.c
similarity index 100%
rename from source3/tdb/open.c
rename to source3/tdb/common/open.c
similarity index 100%
rename from source3/tdb/tdb.c
rename to source3/tdb/common/tdb.c
diff --git a/source3/tdb/config.m4 b/source3/tdb/config.m4
new file mode 100644 (file)
index 0000000..cb08017
--- /dev/null
@@ -0,0 +1,37 @@
+AC_CHECK_FUNCS(mmap pread pwrite getpagesize utime)
+AC_CHECK_HEADERS(getopt.h sys/select.h sys/time.h)
+
+AC_HAVE_DECL(pread, [#include <unistd.h>])
+AC_HAVE_DECL(pwrite, [#include <unistd.h>])
+
+AC_MSG_CHECKING([for Python])
+
+PYTHON=
+AC_ARG_WITH(python,
+[  --with-python=PYTHONNAME  build Python libraries],
+[ case "${withval-python}" in
+  yes)
+        PYTHON=python
+        ;;
+  no)
+        PYTHON=
+        ;;
+  *)
+        PYTHON=${withval-python}
+        ;;
+  esac ])
+
+if test x"$PYTHON" != "x"; then
+       incdir=`python -c 'import sys; print "%s/include/python%d.%d" % (sys.prefix, sys.version_info[[0]], sys.version_info[[1]])'`
+       CPPFLAGS="$CPPFLAGS -I $incdir"
+fi
+
+if test x"$PYTHON" != "x"; then
+       AC_MSG_RESULT([${withval-python}])
+else
+       SMB_ENABLE(swig_tdb, NO)
+       AC_MSG_RESULT(no)
+fi
+
+AC_SUBST(PYTHON)
diff --git a/source3/tdb/config.mk b/source3/tdb/config.mk
new file mode 100644 (file)
index 0000000..b1e6e82
--- /dev/null
@@ -0,0 +1,71 @@
+################################################
+# Start SUBSYSTEM LIBTDB
+[LIBRARY::LIBTDB]
+VERSION = 0.0.1
+SO_VERSION = 0
+DESCRIPTION = Trivial Database Library
+OBJ_FILES = \
+       common/tdb.o common/dump.o common/io.o common/lock.o \
+       common/open.o common/traverse.o common/freelist.o \
+       common/error.o common/transaction.o common/tdbutil.o
+PUBLIC_DEPENDENCIES = \
+               LIBREPLACE
+PUBLIC_HEADERS = include/tdb.h
+#
+# End SUBSYSTEM ldb
+################################################
+
+################################################
+# Start BINARY tdbtool
+[BINARY::tdbtool]
+INSTALLDIR = BINDIR
+ENABLE = NO
+OBJ_FILES= \
+               tools/tdbtool.o
+PRIVATE_DEPENDENCIES = \
+               LIBTDB
+# End BINARY tdbtool
+################################################
+
+################################################
+# Start BINARY tdbtorture
+[BINARY::tdbtorture]
+INSTALLDIR = BINDIR
+OBJ_FILES= \
+               tools/tdbtorture.o
+PRIVATE_DEPENDENCIES = \
+               LIBTDB
+# End BINARY tdbtorture
+################################################
+
+################################################
+# Start BINARY tdbdump
+[BINARY::tdbdump]
+INSTALLDIR = BINDIR
+OBJ_FILES= \
+               tools/tdbdump.o
+PRIVATE_DEPENDENCIES = \
+               LIBTDB
+# End BINARY tdbdump
+################################################
+
+################################################
+# Start BINARY tdbbackup
+[BINARY::tdbbackup]
+INSTALLDIR = BINDIR
+ENABLE = NO
+OBJ_FILES= \
+               tools/tdbbackup.o
+PRIVATE_DEPENDENCIES = \
+               LIBTDB
+# End BINARY tdbbackup
+################################################
+
+#######################
+# Start LIBRARY swig_tdb
+[LIBRARY::swig_tdb]
+LIBRARY_REALNAME = swig/_tdb.$(SHLIBEXT)
+OBJ_FILES = swig/tdb_wrap.o
+PUBLIC_DEPENDENCIES = LIBTDB DYNCONFIG
+# End LIBRARY swig_tdb
+#######################
diff --git a/source3/tdb/configure.in b/source3/tdb/configure.in
new file mode 100644 (file)
index 0000000..0a72af2
--- /dev/null
@@ -0,0 +1,13 @@
+AC_DEFUN([SMB_MODULE_DEFAULT], [echo -n ""])
+AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""])
+AC_DEFUN([SMB_ENABLE], [echo -n ""])
+AC_INIT(include/tdb.h)
+AC_CONFIG_HEADER(include/config.h)
+AC_PROG_CC
+AC_SYS_LARGEFILE
+AC_CHECK_SIZEOF(off_t,cross)
+AC_CHECK_SIZEOF(size_t,cross)
+AC_CHECK_SIZEOF(ssize_t,cross)
+AC_FUNC_MMAP
+sinclude(config.m4)
+AC_OUTPUT(Makefile tdb.pc)
similarity index 66%
rename from source3/tdb/README
rename to source3/tdb/docs/README
index fac3eacb4db3c2c1f1353057e16c28eb0d5c9761..b31ce36ab149b7416043990de4f2eda528e66637 100644 (file)
@@ -15,7 +15,6 @@ Compilation
 -----------
 
 add HAVE_MMAP=1 to use mmap instead of read/write
-add TDB_DEBUG=1 for verbose debug info
 add NOLOCK=1 to disable locking code
 
 Testing
@@ -41,6 +40,7 @@ The interface is very similar to gdbm except for the following:
 - no tdbm_reorganise() function
 - no tdbm_sync() function. No operations are cached in the library anyway
 - added a tdb_traverse() function for traversing the whole database
+- added transactions support
 
 A general rule for using tdb is that the caller frees any returned
 TDB_DATA structures. Just call free(p.dptr) to free a TDB_DATA
@@ -68,6 +68,19 @@ TDB_CONTEXT *tdb_open(char *name, int hash_size, int tdb_flags,
                    memory. The filename is ignored in this case.
     TDB_NOLOCK - don't do any locking
     TDB_NOMMAP - don't use mmap
+    TDB_NOSYNC - don't synchronise transactions to disk
+
+----------------------------------------------------------------------
+TDB_CONTEXT *tdb_open_ex(char *name, int hash_size, int tdb_flags,
+                        int open_flags, mode_t mode,
+                        tdb_log_func log_fn,
+                        tdb_hash_func hash_fn)
+
+This is like tdb_open(), but allows you to pass an initial logging and
+hash function. Be careful when passing a hash function - all users of
+the database must use the same hash function or you will get data
+corruption.
+
 
 ----------------------------------------------------------------------
 char *tdb_error(TDB_CONTEXT *tdb);
@@ -114,7 +127,25 @@ int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb,
 
    if fn is NULL then it is not called
 
-   a non-zero return value from fn() indicates that the traversal should stop
+   a non-zero return value from fn() indicates that the traversal
+   should stop. Traversal callbacks may not start transactions.
+
+----------------------------------------------------------------------
+int tdb_traverse_read(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb,
+                     TDB_DATA key, TDB_DATA dbuf, void *state), void *state);
+
+   traverse the entire database - calling fn(tdb, key, data, state) on
+   each element, but marking the database read only during the
+   traversal, so any write operations will fail. This allows tdb to
+   use read locks, which increases the parallelism possible during the
+   traversal.
+
+   return -1 on error or the record count traversed
+
+   if fn is NULL then it is not called
+
+   a non-zero return value from fn() indicates that the traversal
+   should stop. Traversal callbacks may not start transactions.
 
 ----------------------------------------------------------------------
 TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
@@ -165,3 +196,40 @@ int tdb_lockchain(TDB_CONTEXT *tdb, TDB_DATA key);
 int tdb_unlockchain(TDB_CONTEXT *tdb, TDB_DATA key);
 
    unlock one hash chain
+
+----------------------------------------------------------------------
+int tdb_transaction_start(TDB_CONTEXT *tdb)
+
+   start a transaction. All operations after the transaction start can
+   either be committed with tdb_transaction_commit() or cancelled with
+   tdb_transaction_cancel(). 
+
+   If you call tdb_transaction_start() again on the same tdb context
+   while a transaction is in progress, then the same transaction
+   buffer is re-used. The number of tdb_transaction_{commit,cancel}
+   operations must match the number of successful
+   tdb_transaction_start() calls.
+
+   Note that transactions are by default disk synchronous, and use a
+   recover area in the database to automatically recover the database
+   on the next open if the system crashes during a transaction. You
+   can disable the synchronous transaction recovery setup using the
+   TDB_NOSYNC flag, which will greatly speed up operations at the risk
+   of corrupting your database if the system crashes.
+
+   Operations made within a transaction are not visible to other users
+   of the database until a successful commit.
+
+----------------------------------------------------------------------
+int tdb_transaction_cancel(TDB_CONTEXT *tdb)
+
+   cancel a current transaction, discarding all write and lock
+   operations that have been made since the transaction started.
+
+
+----------------------------------------------------------------------
+int tdb_transaction_commit(TDB_CONTEXT *tdb)
+
+   commit a current transaction, updating the database and releasing
+   the transaction locks.
+
similarity index 100%
rename from source3/tdb/tdb.h
rename to source3/tdb/include/tdb.h
diff --git a/source3/tdb/include/tdbconfig.h.in b/source3/tdb/include/tdbconfig.h.in
new file mode 100644 (file)
index 0000000..d6d2c09
--- /dev/null
@@ -0,0 +1,58 @@
+/* include/tdbconfig.h.in.  Generated from configure.in by autoheader.  */
+
+/* Define to 1 if you have the `getpagesize' function. */
+#undef HAVE_GETPAGESIZE
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the `mmap' function. */
+#undef HAVE_MMAP
+
+/* Define to 1 if you have the `pread' function. */
+#undef HAVE_PREAD
+
+/* Define to 1 if you have the `pwrite' function. */
+#undef HAVE_PWRITE
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
diff --git a/source3/tdb/swig/Tdb.py b/source3/tdb/swig/Tdb.py
new file mode 100644 (file)
index 0000000..aac7a90
--- /dev/null
@@ -0,0 +1,116 @@
+"""Provide a more Pythonic and object-oriented interface to tdb."""
+
+#
+# Swig interface to Samba
+#
+# Copyright (C) Tim Potter 2006
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#   
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#   
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+import os
+from tdb import *
+
+# Open flags
+
+DEFAULT        = TDB_DEFAULT
+CLEAR_IF_FIRST = TDB_CLEAR_IF_FIRST
+INTERNAL       = TDB_INTERNAL
+NOLOCK         = TDB_NOLOCK
+NOMMAP         = TDB_NOMMAP
+
+# Class representing a TDB file
+
+class Tdb:
+
+    # Create and destroy Tdb objects
+
+    def __init__(self, name, hash_size = 0, flags = TDB_DEFAULT,
+                 open_flags = os.O_RDWR | os.O_CREAT, mode = 0600):
+        self.tdb = tdb_open(name, hash_size, flags, open_flags, mode)
+        if self.tdb is None:
+            raise IOError, tdb_errorstr(self.tdb)
+        
+    def __del__(self):
+        self.close()
+
+    def close(self):
+        if hasattr(self, 'tdb') and self.tdb is not None:
+            if tdb_close(self.tdb) == -1:
+                raise IOError, tdb_errorstr(self.tdb)
+            self.tdb = None
+
+    # Random access to keys, values
+
+    def __getitem__(self, key):
+        result = tdb_fetch(self.tdb, key)
+        if result is None:
+            raise KeyError, '%s: %s' % (key, tdb_errorstr(self.tdb))
+        return result
+
+    def __setitem__(self, key, item):
+        if tdb_store(self.tdb, key, item) == -1:
+            raise IOError, tdb_errorstr(self.tdb)
+
+    def __delitem__(self, key):
+        if not tdb_exists(self.tdb, key):
+            raise KeyError, '%s: %s' % (key, tdb_errorstr(self.tdb))
+        tdb_delete(self.tdb, key)
+
+    def has_key(self, key):
+        return tdb_exists(self.tdb, key)
+
+    # Tdb iterator
+
+    class TdbIterator:
+        def __init__(self, tdb):
+            self.tdb = tdb
+            self.key = None
+
+        def __iter__(self):
+            return self
+            
+        def next(self):
+            if self.key is None:
+                self.key = tdb_firstkey(self.tdb)
+                if self.key is None:
+                    raise StopIteration
+                return self.key
+            else:
+                self.key = tdb_nextkey(self.tdb, self.key)
+                if self.key is None:
+                    raise StopIteration
+                return self.key
+
+    def __iter__(self):
+        return Tdb.TdbIterator(self.tdb)
+
+    # Implement other dict functions using TdbIterator
+
+    def keys(self):
+        return [k for k in iter(self)]
+
+    def values(self):
+        return [self[k] for k in iter(self)]
+
+    def items(self):
+        return [(k, self[k]) for k in iter(self)]
+
+    def __len__(self):
+        return len(self.keys())
+
+    def clear(self):
+        for k in iter(self):
+            del(self[k])
diff --git a/source3/tdb/swig/tdb.i b/source3/tdb/swig/tdb.i
new file mode 100644 (file)
index 0000000..98bf644
--- /dev/null
@@ -0,0 +1,168 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   Swig interface to tdb.
+
+   Copyright (C) 2004,2005 Tim Potter <tpot@samba.org>
+
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+%module tdb
+
+%{
+
+/* This symbol is used in both includes.h and Python.h which causes an
+   annoying compiler warning. */
+
+#ifdef HAVE_FSTAT
+#undef HAVE_FSTAT
+#endif
+
+#if (__GNUC__ >= 3)
+/** Use gcc attribute to check printf fns.  a1 is the 1-based index of
+ * the parameter containing the format, and a2 the index of the first
+ * argument. Note that some gcc 2.x versions don't handle this
+ * properly **/
+#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
+#else
+#define PRINTF_ATTRIBUTE(a1, a2)
+#endif
+
+/* Include tdb headers */
+
+#include "lib/tdb/include/tdb.h"
+
+%}
+
+/* The tdb functions will crash if a NULL tdb context is passed */
+
+%include exception.i
+
+%typemap(check) TDB_CONTEXT* {
+       if ($1 == NULL)
+               SWIG_exception(SWIG_ValueError, 
+                       "tdb context must be non-NULL");
+}
+
+/* In and out typemaps for the TDB_DATA structure.  This is converted to
+   and from the Python string type which can contain arbitrary binary
+   data.. */
+
+%typemap(in) TDB_DATA {
+       if (!PyString_Check($input)) {
+               PyErr_SetString(PyExc_TypeError, "string arg expected");
+               return NULL;
+       }
+       $1.dsize = PyString_Size($input);
+       $1.dptr = PyString_AsString($input);
+}
+
+%typemap(out) TDB_DATA {
+       if ($1.dptr == NULL && $1.dsize == 0) {
+               $result = Py_None;
+       } else {
+               $result = PyString_FromStringAndSize($1.dptr, $1.dsize);
+               free($1.dptr);
+       }
+}
+
+/* Treat a mode_t as an unsigned integer */
+
+typedef int mode_t;
+
+/* flags to tdb_store() */
+
+#define TDB_REPLACE 1
+#define TDB_INSERT 2
+#define TDB_MODIFY 3
+
+/* flags for tdb_open() */
+
+#define TDB_DEFAULT 0 /* just a readability place holder */
+#define TDB_CLEAR_IF_FIRST 1
+#define TDB_INTERNAL 2 /* don't store on disk */
+#define TDB_NOLOCK   4 /* don't do any locking */
+#define TDB_NOMMAP   8 /* don't use mmap */
+#define TDB_CONVERT 16 /* convert endian (internal use) */
+#define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */
+
+/* Throw an IOError exception if tdb_open() or tdb_open_ex() returns NULL */
+
+%exception {
+       $action
+       if (result == NULL) {
+               PyErr_SetFromErrno(PyExc_IOError);
+               SWIG_fail;
+       }
+}
+
+TDB_CONTEXT *tdb_open(const char *name, int hash_size, int tdb_flags,
+                     int open_flags, mode_t mode);
+
+TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
+                        int open_flags, mode_t mode,
+                        tdb_log_func log_fn,
+                        tdb_hash_func hash_fn);
+
+%exception;
+
+int tdb_reopen(TDB_CONTEXT *tdb);
+
+int tdb_reopen_all(int parent_longlived);
+
+void tdb_logging_function(TDB_CONTEXT *tdb, tdb_log_func);
+
+enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb);
+
+const char *tdb_errorstr(TDB_CONTEXT *tdb);
+
+TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key);
+
+int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key);
+
+int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag = TDB_REPLACE);
+
+int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf);
+
+int tdb_close(TDB_CONTEXT *tdb);
+
+TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
+
+TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key);
+
+int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *state);
+
+int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key);
+
+int tdb_lockall(TDB_CONTEXT *tdb);
+
+void tdb_unlockall(TDB_CONTEXT *tdb);
+
+/* Low level locking functions: use with care */
+
+int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key);
+
+int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key);
+
+/* Debug functions. Not used in production. */
+
+void tdb_dump_all(TDB_CONTEXT *tdb);
+
+int tdb_printfreelist(TDB_CONTEXT *tdb);
diff --git a/source3/tdb/tdb.pc.in b/source3/tdb/tdb.pc.in
new file mode 100644 (file)
index 0000000..0d54afe
--- /dev/null
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: tdb
+Description: A trivial database
+Version: 4.0
+#Libs: @LIBS@ -L${libdir} -ltdb
+Cflags: -I${includedir} @CFLAGS@