Import bind-9.3.4
[dragonfly.git] / contrib / bind-9.3 / lib / dns / include / dns / compress.h
blob042a4ea51a96ba37af48b8099cc2544647e3f60d
1 /*
2 * Copyright (C) 2004, 2006 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2002 Internet Software Consortium.
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.
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.
18 /* $Id: compress.h,v 1.29.2.2.8.3 2006/03/02 00:37:20 marka Exp $ */
20 #ifndef DNS_COMPRESS_H
21 #define DNS_COMPRESS_H 1
23 #include <isc/lang.h>
24 #include <isc/region.h>
26 #include <dns/types.h>
28 ISC_LANG_BEGINDECLS
30 #define DNS_COMPRESS_NONE 0x00 /* no compression */
31 #define DNS_COMPRESS_GLOBAL14 0x01 /* "normal" compression. */
32 #define DNS_COMPRESS_ALL 0x01 /* all compression. */
35 * Direct manipulation of the structures is strongly discouraged.
38 #define DNS_COMPRESS_TABLESIZE 64
39 #define DNS_COMPRESS_INITIALNODES 16
41 typedef struct dns_compressnode dns_compressnode_t;
43 struct dns_compressnode {
44 isc_region_t r;
45 isc_uint16_t offset;
46 isc_uint16_t count;
47 isc_uint8_t labels;
48 dns_compressnode_t *next;
51 struct dns_compress {
52 unsigned int magic; /* Magic number. */
53 unsigned int allowed; /* Allowed methods. */
54 int edns; /* Edns version or -1. */
55 /* Global compression table. */
56 dns_compressnode_t *table[DNS_COMPRESS_TABLESIZE];
57 /* Preallocated nodes for the table. */
58 dns_compressnode_t initialnodes[DNS_COMPRESS_INITIALNODES];
59 isc_uint16_t count; /* Number of nodes. */
60 isc_mem_t *mctx; /* Memory context. */
63 typedef enum {
64 DNS_DECOMPRESS_ANY, /* Any compression */
65 DNS_DECOMPRESS_STRICT, /* Allowed compression */
66 DNS_DECOMPRESS_NONE /* No compression */
67 } dns_decompresstype_t;
69 struct dns_decompress {
70 unsigned int magic; /* Magic number. */
71 unsigned int allowed; /* Allowed methods. */
72 int edns; /* Edns version or -1. */
73 dns_decompresstype_t type; /* Strict checking */
76 isc_result_t
77 dns_compress_init(dns_compress_t *cctx, int edns, isc_mem_t *mctx);
79 * Inialise the compression context structure pointed to by 'cctx'.
81 * Requires:
82 * 'cctx' is a valid dns_compress_t structure.
83 * 'mctx' is an initialized memory context.
84 * Ensures:
85 * cctx->global is initialized.
87 * Returns:
88 * ISC_R_SUCCESS
89 * failures from dns_rbt_create()
92 void
93 dns_compress_invalidate(dns_compress_t *cctx);
96 * Invalidate the compression structure pointed to by cctx.
98 * Requires:
99 * 'cctx' to be initialized.
102 void
103 dns_compress_setmethods(dns_compress_t *cctx, unsigned int allowed);
106 * Sets allowed compression methods.
108 * Requires:
109 * 'cctx' to be initialized.
112 unsigned int
113 dns_compress_getmethods(dns_compress_t *cctx);
116 * Gets allowed compression methods.
118 * Requires:
119 * 'cctx' to be initialized.
121 * Returns:
122 * allowed compression bitmap.
126 dns_compress_getedns(dns_compress_t *cctx);
129 * Gets edns value.
131 * Requires:
132 * 'cctx' to be initialized.
134 * Returns:
135 * -1 .. 255
138 isc_boolean_t
139 dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name,
140 dns_name_t *prefix, isc_uint16_t *offset);
142 * Finds longest possible match of 'name' in the global compression table.
144 * Requires:
145 * 'cctx' to be initialized.
146 * 'name' to be a absolute name.
147 * 'prefix' to be initialized.
148 * 'offset' to point to an isc_uint16_t.
150 * Ensures:
151 * 'prefix' and 'offset' are valid if ISC_TRUE is returned.
153 * Returns:
154 * ISC_TRUE / ISC_FALSE
157 void
158 dns_compress_add(dns_compress_t *cctx, const dns_name_t *name,
159 const dns_name_t *prefix, isc_uint16_t offset);
161 * Add compression pointers for 'name' to the compression table,
162 * not replacing existing pointers.
164 * Requires:
165 * 'cctx' initialized
167 * 'name' must be initialized and absolute, and must remain
168 * valid until the message compression is complete.
170 * 'prefix' must be a prefix returned by
171 * dns_compress_findglobal(), or the same as 'name'.
174 void
175 dns_compress_rollback(dns_compress_t *cctx, isc_uint16_t offset);
178 * Remove any compression pointers from global table >= offset.
180 * Requires:
181 * 'cctx' is initialized.
184 void
185 dns_decompress_init(dns_decompress_t *dctx, int edns,
186 dns_decompresstype_t type);
189 * Initializes 'dctx'.
190 * Records 'edns' and 'type' into the structure.
192 * Requires:
193 * 'dctx' to be a valid pointer.
196 void
197 dns_decompress_invalidate(dns_decompress_t *dctx);
200 * Invalidates 'dctx'.
202 * Requires:
203 * 'dctx' to be initialized
206 void
207 dns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed);
210 * Sets 'dctx->allowed' to 'allowed'.
212 * Requires:
213 * 'dctx' to be initialized
216 unsigned int
217 dns_decompress_getmethods(dns_decompress_t *dctx);
220 * Returns 'dctx->allowed'
222 * Requires:
223 * 'dctx' to be initialized
227 dns_decompress_edns(dns_decompress_t *dctx);
230 * Returns 'dctx->edns'
232 * Requires:
233 * 'dctx' to be initialized
236 dns_decompresstype_t
237 dns_decompress_type(dns_decompress_t *dctx);
240 * Returns 'dctx->type'
242 * Requires:
243 * 'dctx' to be initialized
246 ISC_LANG_ENDDECLS
248 #endif /* DNS_COMPRESS_H */