Registry server LDB backend: Don't make copies of the same type
[samba.git] / source4 / lib / gencache / gencache.h
1 #ifndef __LIB_GENCACHE_GENCACHE_H__
2 #define __LIB_GENCACHE_GENCACHE_H__
3
4 /**
5  * Cache initialisation function. Opens cache tdb file or creates
6  * it if does not exist.
7  *
8  * @return true on successful initialisation of the cache or
9  *         false on failure
10  **/
11 bool gencache_init(struct loadparm_context *lp_ctx);
12
13 /**
14  * Cache shutdown function. Closes opened cache tdb file.
15  *
16  * @return true on successful closing the cache or
17  *         false on failure during cache shutdown
18  **/
19 bool gencache_shutdown(void);
20
21 /**
22  * Set an entry in the cache file. If there's no such
23  * one, then add it.
24  *
25  * @param keystr string that represents a key of this entry
26  * @param value text representation value being cached
27  * @param timeout time when the value is expired
28  *
29  * @retval true when entry is successfuly stored
30  * @retval false on failure
31  **/
32 bool gencache_set(const char *keystr, const char *value, time_t timeout);
33
34 /**
35  * Set existing entry to the cache file.
36  *
37  * @param keystr string that represents a key of this entry
38  * @param valstr text representation value being cached
39  * @param timeout time when the value is expired
40  *
41  * @retval true when entry is successfuly set
42  * @retval false on failure
43  **/
44 bool gencache_set_only(const char *keystr, const char *valstr, time_t timeout);
45
46 /**
47  * Delete one entry from the cache file.
48  *
49  * @param keystr string that represents a key of this entry
50  *
51  * @retval true upon successful deletion
52  * @retval false in case of failure
53  **/
54 bool gencache_del(const char *keystr);
55
56 /**
57  * Get existing entry from the cache file.
58  *
59  * @param keystr string that represents a key of this entry
60  * @param valstr buffer that is allocated and filled with the entry value
61  *        buffer's disposing must be done outside
62  * @param timeout pointer to a time_t that is filled with entry's
63  *        timeout
64  *
65  * @retval true when entry is successfuly fetched
66  * @retval false for failure
67  **/
68 bool gencache_get(const char *keystr, char **valstr, time_t *timeout);
69
70 /**
71  * Iterate through all entries which key matches to specified pattern
72  *
73  * @param fn pointer to the function that will be supplied with each single
74  *        matching cache entry (key, value and timeout) as an arguments
75  * @param data void pointer to an arbitrary data that is passed directly to the fn
76  *        function on each call
77  * @param keystr_pattern pattern the existing entries' keys are matched to
78  *
79  **/
80 void gencache_iterate(void (*fn)(const char* key, const char *value, time_t timeout, void* dptr),
81                       void* data, const char* keystr_pattern);
82
83 /********************************************************************
84  lock a key
85 ********************************************************************/
86 int gencache_lock_entry( const char *key );
87
88 /********************************************************************
89  unlock a key
90 ********************************************************************/
91 void gencache_unlock_entry( const char *key );
92
93 #endif /* __LIB_GENCACHE_GENCACHE_H__ */
94