2 * Copyright (C) 2004 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.3 2004/03/09 06:11:14 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. */
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
{
48 dns_compressnode_t
*next
;
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. */
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 */
77 dns_compress_init(dns_compress_t
*cctx
, int edns
, isc_mem_t
*mctx
);
79 * Inialise the compression context structure pointed to by 'cctx'.
82 * 'cctx' is a valid dns_compress_t structure.
83 * 'mctx' is an initialized memory context.
85 * cctx->global is initialized.
89 * failures from dns_rbt_create()
93 dns_compress_invalidate(dns_compress_t
*cctx
);
96 * Invalidate the compression structure pointed to by cctx.
99 * 'cctx' to be initialized.
103 dns_compress_setmethods(dns_compress_t
*cctx
, unsigned int allowed
);
106 * Sets allowed compression methods.
109 * 'cctx' to be initialized.
113 dns_compress_getmethods(dns_compress_t
*cctx
);
116 * Gets allowed compression methods.
119 * 'cctx' to be initialized.
122 * allowed compression bitmap.
126 dns_compress_getedns(dns_compress_t
*cctx
);
132 * 'cctx' to be initialized.
139 dns_compress_findglobal(dns_compress_t
*cctx
, 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.
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.
151 * 'prefix' and 'offset' are valid if ISC_TRUE is returned.
154 * ISC_TRUE / ISC_FALSE
158 dns_compress_add(dns_compress_t
*cctx
, dns_name_t
*name
, dns_name_t
*prefix
,
159 isc_uint16_t offset
);
161 * Add compression pointers for 'name' to the compression table,
162 * not replacing existing pointers.
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'.
175 dns_compress_rollback(dns_compress_t
*cctx
, isc_uint16_t offset
);
178 * Remove any compression pointers from global table >= offset.
181 * 'cctx' is initialized.
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.
193 * 'dctx' to be a valid pointer.
197 dns_decompress_invalidate(dns_decompress_t
*dctx
);
200 * Invalidates 'dctx'.
203 * 'dctx' to be initialized
207 dns_decompress_setmethods(dns_decompress_t
*dctx
, unsigned int allowed
);
210 * Sets 'dctx->allowed' to 'allowed'.
213 * 'dctx' to be initialized
217 dns_decompress_getmethods(dns_decompress_t
*dctx
);
220 * Returns 'dctx->allowed'
223 * 'dctx' to be initialized
227 dns_decompress_edns(dns_decompress_t
*dctx
);
230 * Returns 'dctx->edns'
233 * 'dctx' to be initialized
237 dns_decompress_type(dns_decompress_t
*dctx
);
240 * Returns 'dctx->type'
243 * 'dctx' to be initialized
248 #endif /* DNS_COMPRESS_H */