Merge from vendor branch FILE:
[dragonfly.git] / contrib / bind-9.3 / lib / dns / include / dns / rdataslab.h
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2002  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: rdataslab.h,v 1.20.2.2.2.4 2004/03/08 09:04:39 marka Exp $ */
19
20 #ifndef DNS_RDATASLAB_H
21 #define DNS_RDATASLAB_H 1
22
23 /*
24  * DNS Rdata Slab
25  *
26  * Implements storage of rdatasets into slabs of memory.
27  *
28  * MP:
29  *      Clients of this module must impose any required synchronization.
30  *
31  * Reliability:
32  *      This module deals with low-level byte streams.  Errors in any of
33  *      the functions are likely to crash the server or corrupt memory.
34  *
35  *      If the caller passes invalid memory references, these functions are
36  *      likely to crash the server or corrupt memory.
37  *
38  * Resources:
39  *      None.
40  *
41  * Security:
42  *      None.
43  *
44  * Standards:
45  *      None.
46  */
47
48 /***
49  *** Imports
50  ***/
51
52 #include <isc/lang.h>
53
54 #include <dns/types.h>
55
56 ISC_LANG_BEGINDECLS
57
58 #define DNS_RDATASLAB_FORCE 0x1
59 #define DNS_RDATASLAB_EXACT 0x2
60
61 /***
62  *** Functions
63  ***/
64
65 isc_result_t
66 dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
67                            isc_region_t *region, unsigned int reservelen);
68 /*
69  * Slabify a rdataset.  The slab area will be allocated and returned
70  * in 'region'.
71  *
72  * Requires:
73  *      'rdataset' is valid.
74  *
75  * Ensures:
76  *      'region' will have base pointing to the start of allocated memory,
77  *      with the slabified region beginning at region->base + reservelen.
78  *      region->length contains the total length allocated.
79  *
80  * Returns:
81  *      ISC_R_SUCCESS           - successful completion
82  *      ISC_R_NOMEMORY          - no memory.
83  *      <XXX others>
84  */
85
86 void
87 dns_rdataslab_tordataset(unsigned char *slab, unsigned int reservelen,
88                          dns_rdataclass_t rdclass, dns_rdatatype_t rdtype,
89                          dns_rdatatype_t covers, dns_ttl_t ttl,
90                          dns_rdataset_t *rdataset);
91 /*
92  * Construct an rdataset from a slab.
93  *
94  * Requires:
95  *      'slab' points to a slab.
96  *      'rdataset' is disassociated.
97  *
98  * Ensures:
99  *      'rdataset' is associated and points to a valid rdataest.
100  */
101
102 unsigned int
103 dns_rdataslab_size(unsigned char *slab, unsigned int reservelen);
104 /*
105  * Return the total size of an rdataslab.
106  *
107  * Requires:
108  *      'slab' points to a slab.
109  *
110  * Returns:
111  *      The number of bytes in the slab, including the reservelen.
112  */
113
114 isc_result_t
115 dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab,
116                     unsigned int reservelen, isc_mem_t *mctx,
117                     dns_rdataclass_t rdclass, dns_rdatatype_t type,
118                     unsigned int flags, unsigned char **tslabp);
119 /*
120  * Merge 'oslab' and 'nslab'.
121  */
122
123 isc_result_t
124 dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab,
125                        unsigned int reservelen, isc_mem_t *mctx,
126                        dns_rdataclass_t rdclass, dns_rdatatype_t type,
127                        unsigned int flags, unsigned char **tslabp);
128 /*
129  * Subtract 'sslab' from 'mslab'.  If 'exact' is true then all elements
130  * of 'sslab' must exist in 'mslab'.
131  *
132  * XXX
133  * valid flags are DNS_RDATASLAB_EXACT
134  */
135
136 isc_boolean_t
137 dns_rdataslab_equal(unsigned char *slab1, unsigned char *slab2,
138                     unsigned int reservelen);
139
140 /*
141  * Compare two rdataslabs for equality.  This does _not_ do a full
142  * DNSSEC comparison.
143  *
144  * Requires:
145  *      'slab1' and 'slab2' point to slabs.
146  *
147  * Returns:
148  *      ISC_TRUE if the slabs are equal, ISC_FALSE otherwise.
149  */
150
151 isc_boolean_t
152 dns_rdataslab_equalx(unsigned char *slab1, unsigned char *slab2,
153                      unsigned int reservelen, dns_rdataclass_t rdclass, 
154                      dns_rdatatype_t type);
155 /*
156  * Compare two rdataslabs for DNSSEC equality. 
157  *
158  * Requires:
159  *      'slab1' and 'slab2' point to slabs.
160  *
161  * Returns:
162  *      ISC_TRUE if the slabs are equal, ISC_FALSE otherwise.
163  */
164
165 ISC_LANG_ENDDECLS
166
167 #endif /* DNS_RDATASLAB_H */