2 * Copyright (C) 2004, 2007-2009, 2012 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2002 Internet Software Consortium.
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.
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: txt_16.c,v 1.47 2009/12/04 22:06:37 tbox Exp $ */
20 /* Reviewed: Thu Mar 16 15:40:00 PST 2000 by bwelling */
22 #ifndef RDATA_GENERIC_TXT_16_C
23 #define RDATA_GENERIC_TXT_16_C
25 #define RRTYPE_TXT_ATTRIBUTES (0)
27 static inline isc_result_t
28 fromtext_txt(ARGS_FROMTEXT) {
41 if ((options & DNS_RDATA_UNKNOWNESCAPE) != 0) {
43 DE_CONST("#", r.base);
45 RETERR(txt_fromtext(&r, target));
49 RETERR(isc_lex_getmastertoken(lexer, &token,
50 isc_tokentype_qstring,
52 if (token.type != isc_tokentype_qstring &&
53 token.type != isc_tokentype_string)
55 RETTOK(txt_fromtext(&token.value.as_textregion, target));
58 /* Let upper layer handle eol/eof. */
59 isc_lex_ungettoken(lexer, &token);
60 return (strings == 0 ? ISC_R_UNEXPECTEDEND : ISC_R_SUCCESS);
63 static inline isc_result_t
64 totext_txt(ARGS_TOTEXT) {
69 REQUIRE(rdata->type == 16);
71 dns_rdata_toregion(rdata, ®ion);
73 while (region.length > 0) {
74 RETERR(txt_totext(®ion, target));
75 if (region.length > 0)
76 RETERR(str_totext(" ", target));
79 return (ISC_R_SUCCESS);
82 static inline isc_result_t
83 fromwire_txt(ARGS_FROMWIRE) {
94 result = txt_fromwire(source, target);
95 if (result != ISC_R_SUCCESS)
97 } while (!buffer_empty(source));
98 return (ISC_R_SUCCESS);
101 static inline isc_result_t
102 towire_txt(ARGS_TOWIRE) {
105 REQUIRE(rdata->type == 16);
109 isc_buffer_availableregion(target, ®ion);
110 if (region.length < rdata->length)
111 return (ISC_R_NOSPACE);
113 memcpy(region.base, rdata->data, rdata->length);
114 isc_buffer_add(target, rdata->length);
115 return (ISC_R_SUCCESS);
119 compare_txt(ARGS_COMPARE) {
123 REQUIRE(rdata1->type == rdata2->type);
124 REQUIRE(rdata1->rdclass == rdata2->rdclass);
125 REQUIRE(rdata1->type == 16);
127 dns_rdata_toregion(rdata1, &r1);
128 dns_rdata_toregion(rdata2, &r2);
129 return (isc_region_compare(&r1, &r2));
132 static inline isc_result_t
133 fromstruct_txt(ARGS_FROMSTRUCT) {
134 dns_rdata_txt_t *txt = source;
139 REQUIRE(source != NULL);
140 REQUIRE(txt->common.rdtype == type);
141 REQUIRE(txt->common.rdclass == rdclass);
142 REQUIRE(txt->txt != NULL && txt->txt_len != 0);
147 region.base = txt->txt;
148 region.length = txt->txt_len;
149 while (region.length > 0) {
150 length = uint8_fromregion(®ion);
151 isc_region_consume(®ion, 1);
152 if (region.length < length)
153 return (ISC_R_UNEXPECTEDEND);
154 isc_region_consume(®ion, length);
157 return (mem_tobuffer(target, txt->txt, txt->txt_len));
160 static inline isc_result_t
161 tostruct_txt(ARGS_TOSTRUCT) {
162 dns_rdata_txt_t *txt = target;
165 REQUIRE(rdata->type == 16);
166 REQUIRE(target != NULL);
168 txt->common.rdclass = rdata->rdclass;
169 txt->common.rdtype = rdata->type;
170 ISC_LINK_INIT(&txt->common, link);
172 dns_rdata_toregion(rdata, &r);
173 txt->txt_len = r.length;
174 txt->txt = mem_maybedup(mctx, r.base, r.length);
175 if (txt->txt == NULL)
176 return (ISC_R_NOMEMORY);
180 return (ISC_R_SUCCESS);
184 freestruct_txt(ARGS_FREESTRUCT) {
185 dns_rdata_txt_t *txt = source;
187 REQUIRE(source != NULL);
188 REQUIRE(txt->common.rdtype == 16);
190 if (txt->mctx == NULL)
193 if (txt->txt != NULL)
194 isc_mem_free(txt->mctx, txt->txt);
198 static inline isc_result_t
199 additionaldata_txt(ARGS_ADDLDATA) {
200 REQUIRE(rdata->type == 16);
206 return (ISC_R_SUCCESS);
209 static inline isc_result_t
210 digest_txt(ARGS_DIGEST) {
213 REQUIRE(rdata->type == 16);
215 dns_rdata_toregion(rdata, &r);
217 return ((digest)(arg, &r));
220 static inline isc_boolean_t
221 checkowner_txt(ARGS_CHECKOWNER) {
233 static inline isc_boolean_t
234 checknames_txt(ARGS_CHECKNAMES) {
236 REQUIRE(rdata->type == 16);
245 static inline isc_result_t
246 casecompare_txt(ARGS_COMPARE) {
247 return (compare_txt(rdata1, rdata2));
250 #endif /* RDATA_GENERIC_TXT_16_C */