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.32.18.6 2006/03/02 00:37:21 marka Exp $ */
20 #ifndef DNS_COMPRESS_H
21 #define DNS_COMPRESS_H 1
24 #include <isc/region.h>
26 #include <dns/types.h>
30 #define DNS_COMPRESS_NONE 0x00 /*%< no compression */
31 #define DNS_COMPRESS_GLOBAL14 0x01 /*%< "normal" compression. */
32 #define DNS_COMPRESS_ALL 0x01 /*%< all compression. */
33 #define DNS_COMPRESS_CASESENSITIVE 0x02 /*%< case sensitive compression. */
36 * Direct manipulation of the structures is strongly discouraged.
39 #define DNS_COMPRESS_TABLESIZE 64
40 #define DNS_COMPRESS_INITIALNODES 16
42 typedef struct dns_compressnode dns_compressnode_t;
44 struct dns_compressnode {
49 dns_compressnode_t *next;
53 unsigned int magic; /*%< Magic number. */
54 unsigned int allowed; /*%< Allowed methods. */
55 int edns; /*%< Edns version or -1. */
56 /*% Global compression table. */
57 dns_compressnode_t *table[DNS_COMPRESS_TABLESIZE];
58 /*% Preallocated nodes for the table. */
59 dns_compressnode_t initialnodes[DNS_COMPRESS_INITIALNODES];
60 isc_uint16_t count; /*%< Number of nodes. */
61 isc_mem_t *mctx; /*%< Memory context. */
65 DNS_DECOMPRESS_ANY, /*%< Any compression */
66 DNS_DECOMPRESS_STRICT, /*%< Allowed compression */
67 DNS_DECOMPRESS_NONE /*%< No compression */
68 } dns_decompresstype_t;
70 struct dns_decompress {
71 unsigned int magic; /*%< Magic number. */
72 unsigned int allowed; /*%< Allowed methods. */
73 int edns; /*%< Edns version or -1. */
74 dns_decompresstype_t type; /*%< Strict checking */
78 dns_compress_init(dns_compress_t *cctx, int edns, isc_mem_t *mctx);
80 * Inialise the compression context structure pointed to by 'cctx'.
83 * \li 'cctx' is a valid dns_compress_t structure.
84 * \li 'mctx' is an initialized memory context.
86 * \li cctx->global is initialized.
90 * \li failures from dns_rbt_create()
94 dns_compress_invalidate(dns_compress_t *cctx);
97 * Invalidate the compression structure pointed to by cctx.
100 *\li 'cctx' to be initialized.
104 dns_compress_setmethods(dns_compress_t *cctx, unsigned int allowed);
107 * Sets allowed compression methods.
110 *\li 'cctx' to be initialized.
114 dns_compress_getmethods(dns_compress_t *cctx);
117 * Gets allowed compression methods.
120 *\li 'cctx' to be initialized.
123 *\li allowed compression bitmap.
127 dns_compress_setsensitive(dns_compress_t *cctx, isc_boolean_t sensitive);
130 * Preserve the case of compressed domain names.
133 * 'cctx' to be initialized.
137 dns_compress_getsensitive(dns_compress_t *cctx);
139 * Return whether case is to be preservered when compressing
143 * 'cctx' to be initialized.
147 dns_compress_getedns(dns_compress_t *cctx);
153 *\li 'cctx' to be initialized.
160 dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name,
161 dns_name_t *prefix, isc_uint16_t *offset);
163 * Finds longest possible match of 'name' in the global compression table.
166 *\li 'cctx' to be initialized.
167 *\li 'name' to be a absolute name.
168 *\li 'prefix' to be initialized.
169 *\li 'offset' to point to an isc_uint16_t.
172 *\li 'prefix' and 'offset' are valid if ISC_TRUE is returned.
175 *\li #ISC_TRUE / #ISC_FALSE
179 dns_compress_add(dns_compress_t *cctx, const dns_name_t *name,
180 const dns_name_t *prefix, isc_uint16_t offset);
182 * Add compression pointers for 'name' to the compression table,
183 * not replacing existing pointers.
186 *\li 'cctx' initialized
188 *\li 'name' must be initialized and absolute, and must remain
189 * valid until the message compression is complete.
191 *\li 'prefix' must be a prefix returned by
192 * dns_compress_findglobal(), or the same as 'name'.
196 dns_compress_rollback(dns_compress_t *cctx, isc_uint16_t offset);
199 * Remove any compression pointers from global table >= offset.
202 *\li 'cctx' is initialized.
206 dns_decompress_init(dns_decompress_t *dctx, int edns,
207 dns_decompresstype_t type);
210 * Initializes 'dctx'.
211 * Records 'edns' and 'type' into the structure.
214 *\li 'dctx' to be a valid pointer.
218 dns_decompress_invalidate(dns_decompress_t *dctx);
221 * Invalidates 'dctx'.
224 *\li 'dctx' to be initialized
228 dns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed);
231 * Sets 'dctx->allowed' to 'allowed'.
234 *\li 'dctx' to be initialized
238 dns_decompress_getmethods(dns_decompress_t *dctx);
241 * Returns 'dctx->allowed'
244 *\li 'dctx' to be initialized
248 dns_decompress_edns(dns_decompress_t *dctx);
251 * Returns 'dctx->edns'
254 *\li 'dctx' to be initialized
258 dns_decompress_type(dns_decompress_t *dctx);
261 * Returns 'dctx->type'
264 *\li 'dctx' to be initialized
269 #endif /* DNS_COMPRESS_H */