2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 1992-2006
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef _____LIB_UTIL_UTIL_TDB_H__
23 #define _____LIB_UTIL_UTIL_TDB_H__
25 /***************************************************************
26 Make a TDB_DATA and keep the const warning in one place
27 ****************************************************************/
28 TDB_DATA
make_tdb_data(const uint8_t *dptr
, size_t dsize
);
29 bool tdb_data_equal(TDB_DATA t1
, TDB_DATA t2
);
30 bool tdb_data_is_empty(TDB_DATA d
);
31 TDB_DATA
string_tdb_data(const char *string
);
32 TDB_DATA
string_term_tdb_data(const char *string
);
34 /****************************************************************************
35 Lock a chain by string. Return non-zero if lock failed.
36 ****************************************************************************/
37 int tdb_lock_bystring(struct tdb_context
*tdb
, const char *keyval
);
39 /****************************************************************************
40 Unlock a chain by string.
41 ****************************************************************************/
42 void tdb_unlock_bystring(struct tdb_context
*tdb
, const char *keyval
);
44 /****************************************************************************
45 Read lock a chain by string. Return non-zero if lock failed.
46 ****************************************************************************/
47 int tdb_read_lock_bystring(struct tdb_context
*tdb
, const char *keyval
);
49 /****************************************************************************
50 Read unlock a chain by string.
51 ****************************************************************************/
52 void tdb_read_unlock_bystring(struct tdb_context
*tdb
, const char *keyval
);
54 /****************************************************************************
55 Lock a chain, with timeout.
56 ****************************************************************************/
57 int tdb_chainlock_with_timeout( struct tdb_context
*tdb
, TDB_DATA key
,
58 unsigned int timeout
);
60 /****************************************************************************
61 Lock a chain by string, with timeout Return non-zero if lock failed.
62 ****************************************************************************/
63 int tdb_lock_bystring_with_timeout(struct tdb_context
*tdb
, const char *keyval
,
66 /****************************************************************************
67 Readlock a chain by string, with timeout Return non-zero if lock failed.
68 ****************************************************************************/
69 int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT
*tdb
, const char *keyval
,
70 unsigned int timeout
);
72 /****************************************************************************
73 Fetch a int32_t value by a arbitrary blob key, return -1 if not found.
74 Output is int32_t in native byte order.
75 ****************************************************************************/
76 int32_t tdb_fetch_int32_byblob(struct tdb_context
*tdb
, TDB_DATA key
);
78 /****************************************************************************
79 Fetch a int32_t value by string key, return -1 if not found.
80 Output is int32_t in native byte order.
81 ****************************************************************************/
82 int32_t tdb_fetch_int32(struct tdb_context
*tdb
, const char *keystr
);
84 /****************************************************************************
85 Store a int32_t value by an arbitrary blob key, return 0 on success, -ve on failure.
86 Input is int32_t in native byte order. Output in tdb is in little-endian.
87 ****************************************************************************/
88 int tdb_store_int32_byblob(struct tdb_context
*tdb
, TDB_DATA key
, int32_t v
);
90 /****************************************************************************
91 Store a int32_t value by string key, return 0 on success, -ve on failure.
92 Input is int32_t in native byte order. Output in tdb is in little-endian.
93 ****************************************************************************/
94 int tdb_store_int32(struct tdb_context
*tdb
, const char *keystr
, int32_t v
);
96 /****************************************************************************
97 Fetch a uint32_t value by a arbitrary blob key, return -1 if not found.
98 Output is uint32_t in native byte order.
99 ****************************************************************************/
100 bool tdb_fetch_uint32_byblob(struct tdb_context
*tdb
, TDB_DATA key
, uint32_t *value
);
102 /****************************************************************************
103 Fetch a uint32_t value by string key, return -1 if not found.
104 Output is uint32_t in native byte order.
105 ****************************************************************************/
106 bool tdb_fetch_uint32(struct tdb_context
*tdb
, const char *keystr
, uint32_t *value
);
108 /****************************************************************************
109 Store a uint32_t value by an arbitrary blob key, return true on success, false on failure.
110 Input is uint32_t in native byte order. Output in tdb is in little-endian.
111 ****************************************************************************/
112 bool tdb_store_uint32_byblob(struct tdb_context
*tdb
, TDB_DATA key
, uint32_t value
);
114 /****************************************************************************
115 Store a uint32_t value by string key, return true on success, false on failure.
116 Input is uint32_t in native byte order. Output in tdb is in little-endian.
117 ****************************************************************************/
118 bool tdb_store_uint32(struct tdb_context
*tdb
, const char *keystr
, uint32_t value
);
120 /****************************************************************************
121 Store a buffer by a null terminated string key. Return 0 on success, -ve
123 ****************************************************************************/
124 int tdb_store_bystring(struct tdb_context
*tdb
, const char *keystr
, TDB_DATA data
, int flags
);
126 /****************************************************************************
127 Fetch a buffer using a null terminated string key. Don't forget to call
128 free() on the result dptr.
129 ****************************************************************************/
130 TDB_DATA
tdb_fetch_bystring(struct tdb_context
*tdb
, const char *keystr
);
132 /****************************************************************************
133 Delete an entry using a null terminated string key. 0 on success, -ve on err.
134 ****************************************************************************/
135 int tdb_delete_bystring(struct tdb_context
*tdb
, const char *keystr
);
137 /****************************************************************************
138 Atomic integer change. Returns old value. To create, set initial value in *oldval.
139 ****************************************************************************/
140 int32_t tdb_change_int32_atomic(struct tdb_context
*tdb
, const char *keystr
, int32_t *oldval
, int32_t change_val
);
142 /****************************************************************************
143 Atomic unsigned integer change. Returns old value. To create, set initial value in *oldval.
144 ****************************************************************************/
145 bool tdb_change_uint32_atomic(struct tdb_context
*tdb
, const char *keystr
, uint32_t *oldval
, uint32_t change_val
);
147 /****************************************************************************
148 Allow tdb_delete to be used as a tdb_traversal_fn.
149 ****************************************************************************/
150 int tdb_traverse_delete_fn(struct tdb_context
*the_tdb
, TDB_DATA key
, TDB_DATA dbuf
,
153 /****************************************************************************
154 Return an NTSTATUS from a TDB_ERROR
155 ****************************************************************************/
157 NTSTATUS
map_nt_error_from_tdb(enum TDB_ERROR err
);
159 #endif /* _____LIB_UTIL_UTIL_TDB_H__ */