Merge from vendor branch LIBARCHIVE:
[dragonfly.git] / contrib / bind-9.3 / lib / dns / include / dns / cache.h
1 /*
2  * Copyright (C) 2004, 2006  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: cache.h,v 1.17.12.5 2006/03/02 00:37:20 marka Exp $ */
19
20 #ifndef DNS_CACHE_H
21 #define DNS_CACHE_H 1
22
23 /*****
24  ***** Module Info
25  *****/
26
27 /*
28  * cache
29  *
30  * Defines dns_cache_t, the cache object.
31  *
32  * Notes:
33  *      A cache object contains DNS data of a single class.
34  *      Multiple classes will be handled by creating multiple
35  *      views, each with a different class and its own cache.
36  *
37  * MP:
38  *      See notes at the individual functions.
39  *
40  * Reliability:
41  *
42  * Resources:
43  *
44  * Security:
45  *
46  * Standards:
47  */
48
49 /***
50  ***    Imports
51  ***/
52
53 #include <isc/lang.h>
54 #include <isc/stdtime.h>
55
56 #include <dns/types.h>
57
58 ISC_LANG_BEGINDECLS
59
60 /***
61  ***    Functions
62  ***/
63
64 isc_result_t
65 dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
66                  isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
67                  const char *db_type, unsigned int db_argc, char **db_argv,
68                  dns_cache_t **cachep);
69 /*
70  * Create a new DNS cache.
71  *
72  * Requires:
73  *
74  *      'mctx' is a valid memory context
75  *
76  *      'taskmgr' is a valid task manager and 'timermgr' is a valid timer
77  *      manager, or both are NULL.  If NULL, no periodic cleaning of the
78  *      cache will take place.
79  *
80  *      'cachep' is a valid pointer, and *cachep == NULL
81  *
82  * Ensures:
83  *
84  *      '*cachep' is attached to the newly created cache
85  *
86  * Returns:
87  *
88  *      ISC_R_SUCCESS
89  *      ISC_R_NOMEMORY
90  */
91
92 void
93 dns_cache_attach(dns_cache_t *cache, dns_cache_t **targetp);
94 /*
95  * Attach *targetp to cache.
96  *
97  * Requires:
98  *
99  *      'cache' is a valid cache.
100  *
101  *      'targetp' points to a NULL dns_cache_t *.
102  *
103  * Ensures:
104  *
105  *      *targetp is attached to cache.
106  */
107
108 void
109 dns_cache_detach(dns_cache_t **cachep);
110 /*
111  * Detach *cachep from its cache.
112  *
113  * Requires:
114  *
115  *      'cachep' points to a valid cache.
116  *
117  * Ensures:
118  *
119  *      *cachep is NULL.
120  *
121  *      If '*cachep' is the last reference to the cache,
122  *
123  *              All resources used by the cache will be freed
124  */
125
126 void
127 dns_cache_attachdb(dns_cache_t *cache, dns_db_t **dbp);
128 /*
129  * Attach *dbp to the cache's database.
130  *
131  * Notes:
132  *
133  *      This may be used to get a reference to the database for
134  *      the purpose of cache lookups (XXX currently it is also
135  *      the way to add data to the cache, but having a
136  *      separate dns_cache_add() interface instead would allow
137  *      more control over memory usage).
138  *      The caller should call dns_db_detach() on the reference
139  *      when it is no longer needed.
140  *
141  * Requires:
142  *
143  *      'cache' is a valid cache.
144  *
145  *      'dbp' points to a NULL dns_db *.
146  *
147  * Ensures:
148  *
149  *      *dbp is attached to the database.
150  */
151
152
153 isc_result_t
154 dns_cache_setfilename(dns_cache_t *cahce, const char *filename);
155 /*
156  * If 'filename' is non-NULL, make the cache persistent.
157  * The cache's data will be stored in the given file.
158  * If 'filename' is NULL, make the cache non-persistent.
159  * Files that are no longer used are not unlinked automatically.
160  *
161  * Returns:
162  *      ISC_R_SUCCESS
163  *      ISC_R_NOMEMORY
164  *      Various file-related failures
165  */
166
167 isc_result_t
168 dns_cache_load(dns_cache_t *cache);
169 /*
170  * If the cache has a file name, load the cache contents from the file.
171  * Previous cache contents are not discarded.
172  * If no file name has been set, do nothing and return success.
173  *
174  * MT:
175  *      Multiple simultaneous attempts to load or dump the cache
176  *      will be serialized with respect to one another, but
177  *      the cache may be read and updated while the dump is
178  *      in progress.  Updates performed during loading
179  *      may or may not be preserved, and reads may return
180  *      either the old or the newly loaded data.
181  *
182  * Returns:
183  *
184  *      ISC_R_SUCCESS
185  *      Various failures depending on the database implementation type
186  */
187
188 isc_result_t
189 dns_cache_dump(dns_cache_t *cache);
190 /*
191  * If the cache has a file name, write the cache contents to disk,
192  * overwriting any preexisting file.  If no file name has been set,
193  * do nothing and return success.
194  *
195  * MT:
196  *      Multiple simultaneous attempts to load or dump the cache
197  *      will be serialized with respect to one another, but
198  *      the cache may be read and updated while the dump is
199  *      in progress.  Updates performed during the dump may
200  *      or may not be reflected in the dumped file.
201  *
202  * Returns:
203  *
204  *      ISC_R_SUCCESS
205  *      Various failures depending on the database implementation type
206  */
207
208 isc_result_t
209 dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now);
210 /*
211  * Force immediate cleaning of the cache, freeing all rdatasets
212  * whose TTL has expired as of 'now' and that have no pending
213  * references.
214  */
215
216 void
217 dns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int interval);
218 /*
219  * Set the periodic cache cleaning interval to 'interval' seconds.
220  */
221
222 void
223 dns_cache_setcachesize(dns_cache_t *cache, isc_uint32_t size);
224 /*
225  * Set the maximum cache size.  0 means unlimited.
226  */
227
228 isc_result_t
229 dns_cache_flush(dns_cache_t *cache);
230 /*
231  * Flushes all data from the cache.
232  *
233  * Returns:
234  *      ISC_R_SUCCESS
235  *      ISC_R_NOMEMORY
236  */
237
238 isc_result_t
239 dns_cache_flushname(dns_cache_t *cache, dns_name_t *name);
240 /*
241  * Flushes a given name from the cache.
242  *
243  * Requires:
244  *      'cache' to be valid.
245  *      'name' to be valid.
246  *
247  * Returns:
248  *      ISC_R_SUCCESS
249  *      ISC_R_NOMEMORY
250  *      other error returns.
251  */
252
253 ISC_LANG_ENDDECLS
254
255 #endif /* DNS_CACHE_H */