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