Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / txt_16.c
blob9437a511a9c143c229f5b34b6e7c8a7a3cacf745
1 /* $NetBSD: txt_16.c,v 1.7 2015/07/08 17:28:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2007-2009, 2012, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2002 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: txt_16.c,v 1.47 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Thu Mar 16 15:40:00 PST 2000 by bwelling */
24 #ifndef RDATA_GENERIC_TXT_16_C
25 #define RDATA_GENERIC_TXT_16_C
27 #define RRTYPE_TXT_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_txt(ARGS_FROMTEXT) {
31 isc_token_t token;
32 int strings;
34 REQUIRE(type == 16);
36 UNUSED(type);
37 UNUSED(rdclass);
38 UNUSED(origin);
39 UNUSED(options);
40 UNUSED(callbacks);
42 strings = 0;
43 if ((options & DNS_RDATA_UNKNOWNESCAPE) != 0) {
44 isc_textregion_t r;
45 DE_CONST("#", r.base);
46 r.length = 1;
47 RETERR(txt_fromtext(&r, target));
48 strings++;
50 for (;;) {
51 RETERR(isc_lex_getmastertoken(lexer, &token,
52 isc_tokentype_qstring,
53 ISC_TRUE));
54 if (token.type != isc_tokentype_qstring &&
55 token.type != isc_tokentype_string)
56 break;
57 RETTOK(txt_fromtext(&token.value.as_textregion, target));
58 strings++;
60 /* Let upper layer handle eol/eof. */
61 isc_lex_ungettoken(lexer, &token);
62 return (strings == 0 ? ISC_R_UNEXPECTEDEND : ISC_R_SUCCESS);
65 static inline isc_result_t
66 totext_txt(ARGS_TOTEXT) {
67 isc_region_t region;
69 UNUSED(tctx);
71 REQUIRE(rdata->type == 16);
73 dns_rdata_toregion(rdata, &region);
75 while (region.length > 0) {
76 RETERR(txt_totext(&region, ISC_TRUE, target));
77 if (region.length > 0)
78 RETERR(str_totext(" ", target));
81 return (ISC_R_SUCCESS);
84 static inline isc_result_t
85 fromwire_txt(ARGS_FROMWIRE) {
86 isc_result_t result;
88 REQUIRE(type == 16);
90 UNUSED(type);
91 UNUSED(dctx);
92 UNUSED(rdclass);
93 UNUSED(options);
95 do {
96 result = txt_fromwire(source, target);
97 if (result != ISC_R_SUCCESS)
98 return (result);
99 } while (!buffer_empty(source));
100 return (ISC_R_SUCCESS);
103 static inline isc_result_t
104 towire_txt(ARGS_TOWIRE) {
105 isc_region_t region;
107 REQUIRE(rdata->type == 16);
109 UNUSED(cctx);
111 isc_buffer_availableregion(target, &region);
112 if (region.length < rdata->length)
113 return (ISC_R_NOSPACE);
115 memmove(region.base, rdata->data, rdata->length);
116 isc_buffer_add(target, rdata->length);
117 return (ISC_R_SUCCESS);
120 static inline int
121 compare_txt(ARGS_COMPARE) {
122 isc_region_t r1;
123 isc_region_t r2;
125 REQUIRE(rdata1->type == rdata2->type);
126 REQUIRE(rdata1->rdclass == rdata2->rdclass);
127 REQUIRE(rdata1->type == 16);
129 dns_rdata_toregion(rdata1, &r1);
130 dns_rdata_toregion(rdata2, &r2);
131 return (isc_region_compare(&r1, &r2));
134 static inline isc_result_t
135 fromstruct_txt(ARGS_FROMSTRUCT) {
136 dns_rdata_txt_t *txt = source;
137 isc_region_t region;
138 isc_uint8_t length;
140 REQUIRE(type == 16);
141 REQUIRE(source != NULL);
142 REQUIRE(txt->common.rdtype == type);
143 REQUIRE(txt->common.rdclass == rdclass);
144 REQUIRE(txt->txt != NULL && txt->txt_len != 0);
146 UNUSED(type);
147 UNUSED(rdclass);
149 region.base = txt->txt;
150 region.length = txt->txt_len;
151 while (region.length > 0) {
152 length = uint8_fromregion(&region);
153 isc_region_consume(&region, 1);
154 if (region.length < length)
155 return (ISC_R_UNEXPECTEDEND);
156 isc_region_consume(&region, length);
159 return (mem_tobuffer(target, txt->txt, txt->txt_len));
162 static inline isc_result_t
163 tostruct_txt(ARGS_TOSTRUCT) {
164 dns_rdata_txt_t *txt = target;
165 isc_region_t r;
167 REQUIRE(rdata->type == 16);
168 REQUIRE(target != NULL);
170 txt->common.rdclass = rdata->rdclass;
171 txt->common.rdtype = rdata->type;
172 ISC_LINK_INIT(&txt->common, link);
174 dns_rdata_toregion(rdata, &r);
175 txt->txt_len = r.length;
176 txt->txt = mem_maybedup(mctx, r.base, r.length);
177 if (txt->txt == NULL)
178 return (ISC_R_NOMEMORY);
180 txt->offset = 0;
181 txt->mctx = mctx;
182 return (ISC_R_SUCCESS);
185 static inline void
186 freestruct_txt(ARGS_FREESTRUCT) {
187 dns_rdata_txt_t *txt = source;
189 REQUIRE(source != NULL);
190 REQUIRE(txt->common.rdtype == 16);
192 if (txt->mctx == NULL)
193 return;
195 if (txt->txt != NULL)
196 isc_mem_free(txt->mctx, txt->txt);
197 txt->mctx = NULL;
200 static inline isc_result_t
201 additionaldata_txt(ARGS_ADDLDATA) {
202 REQUIRE(rdata->type == 16);
204 UNUSED(rdata);
205 UNUSED(add);
206 UNUSED(arg);
208 return (ISC_R_SUCCESS);
211 static inline isc_result_t
212 digest_txt(ARGS_DIGEST) {
213 isc_region_t r;
215 REQUIRE(rdata->type == 16);
217 dns_rdata_toregion(rdata, &r);
219 return ((digest)(arg, &r));
222 static inline isc_boolean_t
223 checkowner_txt(ARGS_CHECKOWNER) {
225 REQUIRE(type == 16);
227 UNUSED(name);
228 UNUSED(type);
229 UNUSED(rdclass);
230 UNUSED(wildcard);
232 return (ISC_TRUE);
235 static inline isc_boolean_t
236 checknames_txt(ARGS_CHECKNAMES) {
238 REQUIRE(rdata->type == 16);
240 UNUSED(rdata);
241 UNUSED(owner);
242 UNUSED(bad);
244 return (ISC_TRUE);
247 static inline isc_result_t
248 casecompare_txt(ARGS_COMPARE) {
249 return (compare_txt(rdata1, rdata2));
252 isc_result_t
253 dns_rdata_txt_first(dns_rdata_txt_t *txt) {
255 REQUIRE(txt != NULL);
256 REQUIRE(txt->common.rdtype == 16);
257 REQUIRE(txt->txt != NULL || txt->txt_len == 0);
259 if (txt->txt_len == 0)
260 return (ISC_R_NOMORE);
262 txt->offset = 0;
263 return (ISC_R_SUCCESS);
266 isc_result_t
267 dns_rdata_txt_next(dns_rdata_txt_t *txt) {
268 isc_region_t r;
269 isc_uint8_t length;
271 REQUIRE(txt != NULL);
272 REQUIRE(txt->common.rdtype == 16);
273 REQUIRE(txt->txt != NULL && txt->txt_len != 0);
275 INSIST(txt->offset + 1 <= txt->txt_len);
276 r.base = txt->txt + txt->offset;
277 r.length = txt->txt_len - txt->offset;
278 length = uint8_fromregion(&r);
279 INSIST(txt->offset + 1 + length <= txt->txt_len);
280 txt->offset = txt->offset + 1 + length;
281 if (txt->offset == txt->txt_len)
282 return (ISC_R_NOMORE);
283 return (ISC_R_SUCCESS);
286 isc_result_t
287 dns_rdata_txt_current(dns_rdata_txt_t *txt, dns_rdata_txt_string_t *string) {
288 isc_region_t r;
290 REQUIRE(txt != NULL);
291 REQUIRE(string != NULL);
292 REQUIRE(txt->common.rdtype == 16);
293 REQUIRE(txt->txt != NULL);
294 REQUIRE(txt->offset < txt->txt_len);
296 INSIST(txt->offset + 1 <= txt->txt_len);
297 r.base = txt->txt + txt->offset;
298 r.length = txt->txt_len - txt->offset;
300 string->length = uint8_fromregion(&r);
301 isc_region_consume(&r, 1);
302 string->data = r.base;
303 INSIST(txt->offset + 1 + string->length <= txt->txt_len);
305 return (ISC_R_SUCCESS);
307 #endif /* RDATA_GENERIC_TXT_16_C */