source: trunk/server/lib/util/util_tdb.h

Last change on this file was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 7.3 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3
4 tdb utility functions
5
6 Copyright (C) Andrew Tridgell 1992-2006
7
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.
12
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.
17
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/>.
20*/
21
22#ifndef _____LIB_UTIL_UTIL_TDB_H__
23#define _____LIB_UTIL_UTIL_TDB_H__
24
25/***************************************************************
26 Make a TDB_DATA and keep the const warning in one place
27****************************************************************/
28TDB_DATA make_tdb_data(const uint8_t *dptr, size_t dsize);
29bool tdb_data_equal(TDB_DATA t1, TDB_DATA t2);
30TDB_DATA string_tdb_data(const char *string);
31TDB_DATA string_term_tdb_data(const char *string);
32
33/****************************************************************************
34 Lock a chain by string. Return -1 if lock failed.
35****************************************************************************/
36int tdb_lock_bystring(struct tdb_context *tdb, const char *keyval);
37
38/****************************************************************************
39 Unlock a chain by string.
40****************************************************************************/
41void tdb_unlock_bystring(struct tdb_context *tdb, const char *keyval);
42
43/****************************************************************************
44 Read lock a chain by string. Return -1 if lock failed.
45****************************************************************************/
46int tdb_read_lock_bystring(struct tdb_context *tdb, const char *keyval);
47
48/****************************************************************************
49 Read unlock a chain by string.
50****************************************************************************/
51void tdb_read_unlock_bystring(struct tdb_context *tdb, const char *keyval);
52
53/****************************************************************************
54 Fetch a int32_t value by a arbitrary blob key, return -1 if not found.
55 Output is int32_t in native byte order.
56****************************************************************************/
57int32_t tdb_fetch_int32_byblob(struct tdb_context *tdb, TDB_DATA key);
58
59/****************************************************************************
60 Fetch a int32_t value by string key, return -1 if not found.
61 Output is int32_t in native byte order.
62****************************************************************************/
63int32_t tdb_fetch_int32(struct tdb_context *tdb, const char *keystr);
64
65/****************************************************************************
66 Store a int32_t value by an arbitrary blob key, return 0 on success, -1 on failure.
67 Input is int32_t in native byte order. Output in tdb is in little-endian.
68****************************************************************************/
69int tdb_store_int32_byblob(struct tdb_context *tdb, TDB_DATA key, int32_t v);
70
71/****************************************************************************
72 Store a int32_t value by string key, return 0 on success, -1 on failure.
73 Input is int32_t in native byte order. Output in tdb is in little-endian.
74****************************************************************************/
75int tdb_store_int32(struct tdb_context *tdb, const char *keystr, int32_t v);
76
77/****************************************************************************
78 Fetch a uint32_t value by a arbitrary blob key, return -1 if not found.
79 Output is uint32_t in native byte order.
80****************************************************************************/
81bool tdb_fetch_uint32_byblob(struct tdb_context *tdb, TDB_DATA key, uint32_t *value);
82
83/****************************************************************************
84 Fetch a uint32_t value by string key, return -1 if not found.
85 Output is uint32_t in native byte order.
86****************************************************************************/
87bool tdb_fetch_uint32(struct tdb_context *tdb, const char *keystr, uint32_t *value);
88
89/****************************************************************************
90 Store a uint32_t value by an arbitrary blob key, return 0 on success, -1 on failure.
91 Input is uint32_t in native byte order. Output in tdb is in little-endian.
92****************************************************************************/
93bool tdb_store_uint32_byblob(struct tdb_context *tdb, TDB_DATA key, uint32_t value);
94
95/****************************************************************************
96 Store a uint32_t value by string key, return 0 on success, -1 on failure.
97 Input is uint32_t in native byte order. Output in tdb is in little-endian.
98****************************************************************************/
99bool tdb_store_uint32(struct tdb_context *tdb, const char *keystr, uint32_t value);
100
101/****************************************************************************
102 Store a buffer by a null terminated string key. Return 0 on success, -1
103 on failure.
104****************************************************************************/
105int tdb_store_bystring(struct tdb_context *tdb, const char *keystr, TDB_DATA data, int flags);
106
107/****************************************************************************
108 Fetch a buffer using a null terminated string key. Don't forget to call
109 free() on the result dptr.
110****************************************************************************/
111TDB_DATA tdb_fetch_bystring(struct tdb_context *tdb, const char *keystr);
112
113/****************************************************************************
114 Delete an entry using a null terminated string key.
115****************************************************************************/
116int tdb_delete_bystring(struct tdb_context *tdb, const char *keystr);
117
118/****************************************************************************
119 Atomic integer change. Returns old value. To create, set initial value in *oldval.
120****************************************************************************/
121int32_t tdb_change_int32_atomic(struct tdb_context *tdb, const char *keystr, int32_t *oldval, int32_t change_val);
122
123/****************************************************************************
124 Atomic unsigned integer change. Returns old value. To create, set initial value in *oldval.
125****************************************************************************/
126bool tdb_change_uint32_atomic(struct tdb_context *tdb, const char *keystr, uint32_t *oldval, uint32_t change_val);
127
128/****************************************************************************
129 Allow tdb_delete to be used as a tdb_traversal_fn.
130****************************************************************************/
131int tdb_traverse_delete_fn(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf,
132 void *state);
133
134#endif /* _____LIB_UTIL_UTIL_TDB_H__ */
135
Note: See TracBrowser for help on using the repository browser.