1 | #ifndef _____LIB_UTIL_UTIL_TDB_H__
|
---|
2 | #define _____LIB_UTIL_UTIL_TDB_H__
|
---|
3 |
|
---|
4 |
|
---|
5 | /***************************************************************
|
---|
6 | Make a TDB_DATA and keep the const warning in one place
|
---|
7 | ****************************************************************/
|
---|
8 | TDB_DATA make_tdb_data(const uint8_t *dptr, size_t dsize);
|
---|
9 | TDB_DATA string_tdb_data(const char *string);
|
---|
10 | TDB_DATA string_term_tdb_data(const char *string);
|
---|
11 |
|
---|
12 | /****************************************************************************
|
---|
13 | Lock a chain by string. Return -1 if lock failed.
|
---|
14 | ****************************************************************************/
|
---|
15 | int tdb_lock_bystring(struct tdb_context *tdb, const char *keyval);
|
---|
16 |
|
---|
17 | /****************************************************************************
|
---|
18 | Unlock a chain by string.
|
---|
19 | ****************************************************************************/
|
---|
20 | void tdb_unlock_bystring(struct tdb_context *tdb, const char *keyval);
|
---|
21 |
|
---|
22 | /****************************************************************************
|
---|
23 | Read lock a chain by string. Return -1 if lock failed.
|
---|
24 | ****************************************************************************/
|
---|
25 | int tdb_read_lock_bystring(struct tdb_context *tdb, const char *keyval);
|
---|
26 |
|
---|
27 | /****************************************************************************
|
---|
28 | Read unlock a chain by string.
|
---|
29 | ****************************************************************************/
|
---|
30 | void tdb_read_unlock_bystring(struct tdb_context *tdb, const char *keyval);
|
---|
31 |
|
---|
32 | /****************************************************************************
|
---|
33 | Fetch a int32_t value by a arbitrary blob key, return -1 if not found.
|
---|
34 | Output is int32_t in native byte order.
|
---|
35 | ****************************************************************************/
|
---|
36 | int32_t tdb_fetch_int32_byblob(struct tdb_context *tdb, TDB_DATA key);
|
---|
37 |
|
---|
38 | /****************************************************************************
|
---|
39 | Fetch a int32_t value by string key, return -1 if not found.
|
---|
40 | Output is int32_t in native byte order.
|
---|
41 | ****************************************************************************/
|
---|
42 | int32_t tdb_fetch_int32(struct tdb_context *tdb, const char *keystr);
|
---|
43 |
|
---|
44 | /****************************************************************************
|
---|
45 | Store a int32_t value by an arbitary blob key, return 0 on success, -1 on failure.
|
---|
46 | Input is int32_t in native byte order. Output in tdb is in little-endian.
|
---|
47 | ****************************************************************************/
|
---|
48 | int tdb_store_int32_byblob(struct tdb_context *tdb, TDB_DATA key, int32_t v);
|
---|
49 |
|
---|
50 | /****************************************************************************
|
---|
51 | Store a int32_t value by string key, return 0 on success, -1 on failure.
|
---|
52 | Input is int32_t in native byte order. Output in tdb is in little-endian.
|
---|
53 | ****************************************************************************/
|
---|
54 | int tdb_store_int32(struct tdb_context *tdb, const char *keystr, int32_t v);
|
---|
55 |
|
---|
56 | /****************************************************************************
|
---|
57 | Fetch a uint32_t value by a arbitrary blob key, return -1 if not found.
|
---|
58 | Output is uint32_t in native byte order.
|
---|
59 | ****************************************************************************/
|
---|
60 | bool tdb_fetch_uint32_byblob(struct tdb_context *tdb, TDB_DATA key, uint32_t *value);
|
---|
61 |
|
---|
62 | /****************************************************************************
|
---|
63 | Fetch a uint32_t value by string key, return -1 if not found.
|
---|
64 | Output is uint32_t in native byte order.
|
---|
65 | ****************************************************************************/
|
---|
66 | bool tdb_fetch_uint32(struct tdb_context *tdb, const char *keystr, uint32_t *value);
|
---|
67 |
|
---|
68 | /****************************************************************************
|
---|
69 | Store a uint32_t value by an arbitary blob key, return 0 on success, -1 on failure.
|
---|
70 | Input is uint32_t in native byte order. Output in tdb is in little-endian.
|
---|
71 | ****************************************************************************/
|
---|
72 | bool tdb_store_uint32_byblob(struct tdb_context *tdb, TDB_DATA key, uint32_t value);
|
---|
73 |
|
---|
74 | /****************************************************************************
|
---|
75 | Store a uint32_t value by string key, return 0 on success, -1 on failure.
|
---|
76 | Input is uint32_t in native byte order. Output in tdb is in little-endian.
|
---|
77 | ****************************************************************************/
|
---|
78 | bool tdb_store_uint32(struct tdb_context *tdb, const char *keystr, uint32_t value);
|
---|
79 |
|
---|
80 | /****************************************************************************
|
---|
81 | Store a buffer by a null terminated string key. Return 0 on success, -1
|
---|
82 | on failure.
|
---|
83 | ****************************************************************************/
|
---|
84 | int tdb_store_bystring(struct tdb_context *tdb, const char *keystr, TDB_DATA data, int flags);
|
---|
85 |
|
---|
86 | /****************************************************************************
|
---|
87 | Fetch a buffer using a null terminated string key. Don't forget to call
|
---|
88 | free() on the result dptr.
|
---|
89 | ****************************************************************************/
|
---|
90 | TDB_DATA tdb_fetch_bystring(struct tdb_context *tdb, const char *keystr);
|
---|
91 |
|
---|
92 | /****************************************************************************
|
---|
93 | Delete an entry using a null terminated string key.
|
---|
94 | ****************************************************************************/
|
---|
95 | int tdb_delete_bystring(struct tdb_context *tdb, const char *keystr);
|
---|
96 |
|
---|
97 | /****************************************************************************
|
---|
98 | Atomic integer change. Returns old value. To create, set initial value in *oldval.
|
---|
99 | ****************************************************************************/
|
---|
100 | int32_t tdb_change_int32_atomic(struct tdb_context *tdb, const char *keystr, int32_t *oldval, int32_t change_val);
|
---|
101 |
|
---|
102 | /****************************************************************************
|
---|
103 | Atomic unsigned integer change. Returns old value. To create, set initial value in *oldval.
|
---|
104 | ****************************************************************************/
|
---|
105 | bool tdb_change_uint32_atomic(struct tdb_context *tdb, const char *keystr, uint32_t *oldval, uint32_t change_val);
|
---|
106 |
|
---|
107 | /****************************************************************************
|
---|
108 | Allow tdb_delete to be used as a tdb_traversal_fn.
|
---|
109 | ****************************************************************************/
|
---|
110 | int tdb_traverse_delete_fn(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf,
|
---|
111 | void *state);
|
---|
112 |
|
---|
113 | #endif /* _____LIB_UTIL_UTIL_TDB_H__ */
|
---|
114 |
|
---|