PageRenderTime 52ms CodeModel.GetById 41ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/bind9/lib/dns/include/dns/compress.h

https://bitbucket.org/freebsd/freebsd-head/
C++ Header | 269 lines | 77 code | 43 blank | 149 comment | 0 complexity | 202af452851451770337d0e3f3d24ff7 MD5 | raw file
  1/*
  2 * Copyright (C) 2004-2007, 2009  Internet Systems Consortium, Inc. ("ISC")
  3 * Copyright (C) 1999-2002  Internet Software Consortium.
  4 *
  5 * Permission to use, copy, modify, and/or 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: compress.h,v 1.42 2009/01/17 23:47:43 tbox Exp $ */
 19
 20#ifndef DNS_COMPRESS_H
 21#define DNS_COMPRESS_H 1
 22
 23#include <isc/lang.h>
 24#include <isc/region.h>
 25
 26#include <dns/types.h>
 27
 28ISC_LANG_BEGINDECLS
 29
 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. */
 34
 35/*! \file dns/compress.h
 36 *	Direct manipulation of the structures is strongly discouraged.
 37 */
 38
 39#define DNS_COMPRESS_TABLESIZE 64
 40#define DNS_COMPRESS_INITIALNODES 16
 41
 42typedef struct dns_compressnode dns_compressnode_t;
 43
 44struct dns_compressnode {
 45	isc_region_t		r;
 46	isc_uint16_t		offset;
 47	isc_uint16_t		count;
 48	isc_uint8_t		labels;
 49	dns_compressnode_t	*next;
 50};
 51
 52struct dns_compress {
 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. */
 62};
 63
 64typedef enum {
 65	DNS_DECOMPRESS_ANY,			/*%< Any compression */
 66	DNS_DECOMPRESS_STRICT,			/*%< Allowed compression */
 67	DNS_DECOMPRESS_NONE			/*%< No compression */
 68} dns_decompresstype_t;
 69
 70struct 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 */
 75};
 76
 77isc_result_t
 78dns_compress_init(dns_compress_t *cctx, int edns, isc_mem_t *mctx);
 79/*%<
 80 *	Initialise the compression context structure pointed to by 'cctx'.
 81 *
 82 *	Requires:
 83 *	\li	'cctx' is a valid dns_compress_t structure.
 84 *	\li	'mctx' is an initialized memory context.
 85 *	Ensures:
 86 *	\li	cctx->global is initialized.
 87 *
 88 *	Returns:
 89 *	\li	#ISC_R_SUCCESS
 90 *	\li	failures from dns_rbt_create()
 91 */
 92
 93void
 94dns_compress_invalidate(dns_compress_t *cctx);
 95
 96/*%<
 97 *	Invalidate the compression structure pointed to by cctx.
 98 *
 99 *	Requires:
100 *\li		'cctx' to be initialized.
101 */
102
103void
104dns_compress_setmethods(dns_compress_t *cctx, unsigned int allowed);
105
106/*%<
107 *	Sets allowed compression methods.
108 *
109 *	Requires:
110 *\li		'cctx' to be initialized.
111 */
112
113unsigned int
114dns_compress_getmethods(dns_compress_t *cctx);
115
116/*%<
117 *	Gets allowed compression methods.
118 *
119 *	Requires:
120 *\li		'cctx' to be initialized.
121 *
122 *	Returns:
123 *\li		allowed compression bitmap.
124 */
125
126void
127dns_compress_setsensitive(dns_compress_t *cctx, isc_boolean_t sensitive);
128
129/*
130 *	Preserve the case of compressed domain names.
131 *
132 *	Requires:
133 *		'cctx' to be initialized.
134 */
135
136isc_boolean_t
137dns_compress_getsensitive(dns_compress_t *cctx);
138/*
139 *	Return whether case is to be preserved when compressing
140 *	domain names.
141 *
142 *	Requires:
143 *		'cctx' to be initialized.
144 */
145
146int
147dns_compress_getedns(dns_compress_t *cctx);
148
149/*%<
150 *	Gets edns value.
151 *
152 *	Requires:
153 *\li		'cctx' to be initialized.
154 *
155 *	Returns:
156 *\li		-1 .. 255
157 */
158
159isc_boolean_t
160dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name,
161			dns_name_t *prefix, isc_uint16_t *offset);
162/*%<
163 *	Finds longest possible match of 'name' in the global compression table.
164 *
165 *	Requires:
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.
170 *
171 *	Ensures:
172 *\li		'prefix' and 'offset' are valid if ISC_TRUE is 	returned.
173 *
174 *	Returns:
175 *\li		#ISC_TRUE / #ISC_FALSE
176 */
177
178void
179dns_compress_add(dns_compress_t *cctx, const dns_name_t *name,
180		 const dns_name_t *prefix, isc_uint16_t offset);
181/*%<
182 *	Add compression pointers for 'name' to the compression table,
183 *	not replacing existing pointers.
184 *
185 *	Requires:
186 *\li		'cctx' initialized
187 *
188 *\li		'name' must be initialized and absolute, and must remain
189 *		valid until the message compression is complete.
190 *
191 *\li		'prefix' must be a prefix returned by
192 *		dns_compress_findglobal(), or the same as 'name'.
193 */
194
195void
196dns_compress_rollback(dns_compress_t *cctx, isc_uint16_t offset);
197
198/*%<
199 *	Remove any compression pointers from global table >= offset.
200 *
201 *	Requires:
202 *\li		'cctx' is initialized.
203 */
204
205void
206dns_decompress_init(dns_decompress_t *dctx, int edns,
207		    dns_decompresstype_t type);
208
209/*%<
210 *	Initializes 'dctx'.
211 *	Records 'edns' and 'type' into the structure.
212 *
213 *	Requires:
214 *\li		'dctx' to be a valid pointer.
215 */
216
217void
218dns_decompress_invalidate(dns_decompress_t *dctx);
219
220/*%<
221 *	Invalidates 'dctx'.
222 *
223 *	Requires:
224 *\li		'dctx' to be initialized
225 */
226
227void
228dns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed);
229
230/*%<
231 *	Sets 'dctx->allowed' to 'allowed'.
232 *
233 *	Requires:
234 *\li		'dctx' to be initialized
235 */
236
237unsigned int
238dns_decompress_getmethods(dns_decompress_t *dctx);
239
240/*%<
241 *	Returns 'dctx->allowed'
242 *
243 *	Requires:
244 *\li		'dctx' to be initialized
245 */
246
247int
248dns_decompress_edns(dns_decompress_t *dctx);
249
250/*%<
251 *	Returns 'dctx->edns'
252 *
253 *	Requires:
254 *\li		'dctx' to be initialized
255 */
256
257dns_decompresstype_t
258dns_decompress_type(dns_decompress_t *dctx);
259
260/*%<
261 *	Returns 'dctx->type'
262 *
263 *	Requires:
264 *\li		'dctx' to be initialized
265 */
266
267ISC_LANG_ENDDECLS
268
269#endif /* DNS_COMPRESS_H */