summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-10-12 16:53:17 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-10-12 16:53:17 +0200
commit7d371c684d6638c1def19b5900cbff14eaef0af3 (patch)
treefc5dcbfcbffca6db6896e752a59c3d4ee2667e01 /source3
parenta52e729f304c1edbd3842f837f4b2b11222bbc57 (diff)
downloadsamba-7d371c684d6638c1def19b5900cbff14eaef0af3.tar.gz
samba-7d371c684d6638c1def19b5900cbff14eaef0af3.tar.bz2
samba-7d371c684d6638c1def19b5900cbff14eaef0af3.zip
Sync util_tdb implementations.
Diffstat (limited to 'source3')
-rw-r--r--source3/Makefile.in2
-rw-r--r--source3/include/util_tdb.h32
-rw-r--r--source3/lib/util_tdb.c297
3 files changed, 17 insertions, 314 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index b5328400ba..a72d673b1b 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -227,7 +227,7 @@ MODULES = $(VFS_MODULES) $(PDB_MODULES) $(RPC_MODULES) $(IDMAP_MODULES) \
# object file lists
######################################################################
-TDB_LIB_OBJ = lib/util_tdb.o \
+TDB_LIB_OBJ = lib/util_tdb.o ../lib/util/util_tdb.o \
lib/dbwrap.o lib/dbwrap_tdb.o \
lib/dbwrap_ctdb.o \
lib/dbwrap_rbt.o @LIBTDB_STATIC@
diff --git a/source3/include/util_tdb.h b/source3/include/util_tdb.h
index fcc723c511..107d0b1bd5 100644
--- a/source3/include/util_tdb.h
+++ b/source3/include/util_tdb.h
@@ -48,34 +48,34 @@ struct tdb_validation_status {
typedef int (*tdb_validate_data_func)(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state);
-TDB_DATA make_tdb_data(const uint8 *dptr, size_t dsize);
+TDB_DATA make_tdb_data(const uint8_t *dptr, size_t dsize);
TDB_DATA string_tdb_data(const char *string);
TDB_DATA string_term_tdb_data(const char *string);
TDB_LIST_NODE *tdb_search_keys(struct tdb_context*, const char*);
void tdb_search_list_free(TDB_LIST_NODE*);
-int tdb_chainlock_with_timeout( TDB_CONTEXT *tdb, TDB_DATA key,
+int tdb_chainlock_with_timeout( struct tdb_context *tdb, TDB_DATA key,
unsigned int timeout);
int tdb_lock_bystring(struct tdb_context *tdb, const char *keyval);
-int tdb_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
+int tdb_lock_bystring_with_timeout(struct tdb_context *tdb, const char *keyval,
int timeout);
void tdb_unlock_bystring(struct tdb_context *tdb, const char *keyval);
int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
unsigned int timeout);
-void tdb_read_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval);
-
-int32 tdb_fetch_int32_byblob(TDB_CONTEXT *tdb, TDB_DATA key);
-int32 tdb_fetch_int32(struct tdb_context *tdb, const char *keystr);
-bool tdb_store_uint32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, uint32 value);
-bool tdb_store_uint32(struct tdb_context *tdb, const char *keystr, uint32 value);
-int tdb_store_int32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, int32 v);
-int tdb_store_int32(struct tdb_context *tdb, const char *keystr, int32 v);
-bool tdb_fetch_uint32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, uint32 *value);
-bool tdb_fetch_uint32(struct tdb_context *tdb, const char *keystr, uint32 *value);
-int32 tdb_change_int32_atomic(struct tdb_context *tdb, const char *keystr, int32 *oldval, int32 change_val);
-bool tdb_change_uint32_atomic(TDB_CONTEXT *tdb, const char *keystr,
- uint32 *oldval, uint32 change_val);
+void tdb_read_unlock_bystring(struct tdb_context *tdb, const char *keyval);
+
+int32_t tdb_fetch_int32_byblob(struct tdb_context *tdb, TDB_DATA key);
+int32_t tdb_fetch_int32(struct tdb_context *tdb, const char *keystr);
+bool tdb_store_uint32_byblob(struct tdb_context *tdb, TDB_DATA key, uint32_t value);
+bool tdb_store_uint32(struct tdb_context *tdb, const char *keystr, uint32_t value);
+int tdb_store_int32_byblob(struct tdb_context *tdb, TDB_DATA key, int32_t v);
+int tdb_store_int32(struct tdb_context *tdb, const char *keystr, int32_t v);
+bool tdb_fetch_uint32_byblob(struct tdb_context *tdb, TDB_DATA key, uint32_t *value);
+bool tdb_fetch_uint32(struct tdb_context *tdb, const char *keystr, uint32_t *value);
+int32_t tdb_change_int32_atomic(struct tdb_context *tdb, const char *keystr, int32_t *oldval, int32_t change_val);
+bool tdb_change_uint32_atomic(struct tdb_context *tdb, const char *keystr,
+ uint32_t *oldval, uint32_t change_val);
int tdb_store_bystring(struct tdb_context *tdb, const char *keystr, TDB_DATA data, int flags);
int tdb_trans_store_bystring(TDB_CONTEXT *tdb, const char *keystr,
diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c
index 8257232667..bb568bc22e 100644
--- a/source3/lib/util_tdb.c
+++ b/source3/lib/util_tdb.c
@@ -39,28 +39,6 @@ static void gotalarm_sig(void)
gotalarm = 1;
}
-/***************************************************************
- Make a TDB_DATA and keep the const warning in one place
-****************************************************************/
-
-TDB_DATA make_tdb_data(const uint8 *dptr, size_t dsize)
-{
- TDB_DATA ret;
- ret.dptr = CONST_DISCARD(uint8 *, dptr);
- ret.dsize = dsize;
- return ret;
-}
-
-TDB_DATA string_tdb_data(const char *string)
-{
- return make_tdb_data((const uint8 *)string, string ? strlen(string) : 0 );
-}
-
-TDB_DATA string_term_tdb_data(const char *string)
-{
- return make_tdb_data((const uint8 *)string, string ? strlen(string) + 1 : 0);
-}
-
/****************************************************************************
Lock a chain with timeout (in seconds).
****************************************************************************/
@@ -109,17 +87,6 @@ int tdb_chainlock_with_timeout( TDB_CONTEXT *tdb, TDB_DATA key, unsigned int tim
return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_WRLCK);
}
-/****************************************************************************
- Lock a chain by string. Return -1 if timeout or lock failed.
-****************************************************************************/
-
-int tdb_lock_bystring(TDB_CONTEXT *tdb, const char *keyval)
-{
- TDB_DATA key = string_term_tdb_data(keyval);
-
- return tdb_chainlock(tdb, key);
-}
-
int tdb_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
int timeout)
{
@@ -129,17 +96,6 @@ int tdb_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
}
/****************************************************************************
- Unlock a chain by string.
-****************************************************************************/
-
-void tdb_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval)
-{
- TDB_DATA key = string_term_tdb_data(keyval);
-
- tdb_chainunlock(tdb, key);
-}
-
-/****************************************************************************
Read lock a chain by string. Return -1 if timeout or lock failed.
****************************************************************************/
@@ -150,155 +106,8 @@ int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval, un
return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_RDLCK);
}
-/****************************************************************************
- Read unlock a chain by string.
-****************************************************************************/
-
-void tdb_read_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval)
-{
- TDB_DATA key = string_term_tdb_data(keyval);
-
- tdb_chainunlock_read(tdb, key);
-}
-
-
-/****************************************************************************
- Fetch a int32 value by a arbitrary blob key, return -1 if not found.
- Output is int32 in native byte order.
-****************************************************************************/
-
-int32 tdb_fetch_int32_byblob(TDB_CONTEXT *tdb, TDB_DATA key)
-{
- TDB_DATA data;
- int32 ret;
-
- data = tdb_fetch(tdb, key);
- if (!data.dptr || data.dsize != sizeof(int32)) {
- SAFE_FREE(data.dptr);
- return -1;
- }
-
- ret = IVAL(data.dptr,0);
- SAFE_FREE(data.dptr);
- return ret;
-}
-
-/****************************************************************************
- Fetch a int32 value by string key, return -1 if not found.
- Output is int32 in native byte order.
-****************************************************************************/
-
-int32 tdb_fetch_int32(TDB_CONTEXT *tdb, const char *keystr)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_fetch_int32_byblob(tdb, key);
-}
-
-/****************************************************************************
- Store a int32 value by an arbitary blob key, return 0 on success, -1 on failure.
- Input is int32 in native byte order. Output in tdb is in little-endian.
-****************************************************************************/
-
-int tdb_store_int32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, int32 v)
-{
- TDB_DATA data;
- int32 v_store;
-
- SIVAL(&v_store,0,v);
- data.dptr = (uint8 *)&v_store;
- data.dsize = sizeof(int32);
-
- return tdb_store(tdb, key, data, TDB_REPLACE);
-}
-
-/****************************************************************************
- Store a int32 value by string key, return 0 on success, -1 on failure.
- Input is int32 in native byte order. Output in tdb is in little-endian.
-****************************************************************************/
-
-int tdb_store_int32(TDB_CONTEXT *tdb, const char *keystr, int32 v)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_store_int32_byblob(tdb, key, v);
-}
-
-/****************************************************************************
- Fetch a uint32 value by a arbitrary blob key, return -1 if not found.
- Output is uint32 in native byte order.
-****************************************************************************/
-
-bool tdb_fetch_uint32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, uint32 *value)
-{
- TDB_DATA data;
-
- data = tdb_fetch(tdb, key);
- if (!data.dptr || data.dsize != sizeof(uint32)) {
- SAFE_FREE(data.dptr);
- return False;
- }
-
- *value = IVAL(data.dptr,0);
- SAFE_FREE(data.dptr);
- return True;
-}
-
-/****************************************************************************
- Fetch a uint32 value by string key, return -1 if not found.
- Output is uint32 in native byte order.
-****************************************************************************/
-
-bool tdb_fetch_uint32(TDB_CONTEXT *tdb, const char *keystr, uint32 *value)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_fetch_uint32_byblob(tdb, key, value);
-}
-
-/****************************************************************************
- Store a uint32 value by an arbitary blob key, return 0 on success, -1 on failure.
- Input is uint32 in native byte order. Output in tdb is in little-endian.
-****************************************************************************/
-
-bool tdb_store_uint32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, uint32 value)
-{
- TDB_DATA data;
- uint32 v_store;
- bool ret = True;
-
- SIVAL(&v_store, 0, value);
- data.dptr = (uint8 *)&v_store;
- data.dsize = sizeof(uint32);
- if (tdb_store(tdb, key, data, TDB_REPLACE) == -1)
- ret = False;
- return ret;
-}
-
-/****************************************************************************
- Store a uint32 value by string key, return 0 on success, -1 on failure.
- Input is uint32 in native byte order. Output in tdb is in little-endian.
-****************************************************************************/
-
-bool tdb_store_uint32(TDB_CONTEXT *tdb, const char *keystr, uint32 value)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_store_uint32_byblob(tdb, key, value);
-}
-/****************************************************************************
- Store a buffer by a null terminated string key. Return 0 on success, -1
- on failure.
-****************************************************************************/
-
-int tdb_store_bystring(TDB_CONTEXT *tdb, const char *keystr, TDB_DATA data, int flags)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_store(tdb, key, data, flags);
-}
int tdb_trans_store_bystring(TDB_CONTEXT *tdb, const char *keystr,
TDB_DATA data, int flags)
@@ -309,112 +118,6 @@ int tdb_trans_store_bystring(TDB_CONTEXT *tdb, const char *keystr,
}
/****************************************************************************
- Fetch a buffer using a null terminated string key. Don't forget to call
- free() on the result dptr.
-****************************************************************************/
-
-TDB_DATA tdb_fetch_bystring(TDB_CONTEXT *tdb, const char *keystr)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_fetch(tdb, key);
-}
-
-/****************************************************************************
- Delete an entry using a null terminated string key.
-****************************************************************************/
-
-int tdb_delete_bystring(TDB_CONTEXT *tdb, const char *keystr)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_delete(tdb, key);
-}
-
-/****************************************************************************
- Atomic integer change. Returns old value. To create, set initial value in *oldval.
-****************************************************************************/
-
-int32 tdb_change_int32_atomic(TDB_CONTEXT *tdb, const char *keystr, int32 *oldval, int32 change_val)
-{
- int32 val;
- int32 ret = -1;
-
- if (tdb_lock_bystring(tdb, keystr) == -1)
- return -1;
-
- if ((val = tdb_fetch_int32(tdb, keystr)) == -1) {
- /* The lookup failed */
- if (tdb_error(tdb) != TDB_ERR_NOEXIST) {
- /* but not because it didn't exist */
- goto err_out;
- }
-
- /* Start with 'old' value */
- val = *oldval;
-
- } else {
- /* It worked, set return value (oldval) to tdb data */
- *oldval = val;
- }
-
- /* Increment value for storage and return next time */
- val += change_val;
-
- if (tdb_store_int32(tdb, keystr, val) == -1)
- goto err_out;
-
- ret = 0;
-
- err_out:
-
- tdb_unlock_bystring(tdb, keystr);
- return ret;
-}
-
-/****************************************************************************
- Atomic unsigned integer change. Returns old value. To create, set initial value in *oldval.
-****************************************************************************/
-
-bool tdb_change_uint32_atomic(TDB_CONTEXT *tdb, const char *keystr, uint32 *oldval, uint32 change_val)
-{
- uint32 val;
- bool ret = False;
-
- if (tdb_lock_bystring(tdb, keystr) == -1)
- return False;
-
- if (!tdb_fetch_uint32(tdb, keystr, &val)) {
- /* It failed */
- if (tdb_error(tdb) != TDB_ERR_NOEXIST) {
- /* and not because it didn't exist */
- goto err_out;
- }
-
- /* Start with 'old' value */
- val = *oldval;
-
- } else {
- /* it worked, set return value (oldval) to tdb data */
- *oldval = val;
-
- }
-
- /* get a new value to store */
- val += change_val;
-
- if (!tdb_store_uint32(tdb, keystr, val))
- goto err_out;
-
- ret = True;
-
- err_out:
-
- tdb_unlock_bystring(tdb, keystr);
- return ret;
-}
-
-/****************************************************************************
Useful pair of routines for packing/unpacking data consisting of
integers and strings.
****************************************************************************/