2 * Copyright (C) 2004, 2007-2009, 2012, 2014, 2015 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 /* Reviewed: Thu Mar 16 15:40:00 PST 2000 by bwelling */
20 #ifndef RDATA_GENERIC_TXT_16_C
21 #define RDATA_GENERIC_TXT_16_C
23 #define RRTYPE_TXT_ATTRIBUTES (0)
25 static inline isc_result_t
26 generic_fromtext_txt(ARGS_FROMTEXT) {
37 if ((options & DNS_RDATA_UNKNOWNESCAPE) != 0) {
39 DE_CONST("#", r.base);
41 RETERR(txt_fromtext(&r, target));
45 RETERR(isc_lex_getmastertoken(lexer, &token,
46 isc_tokentype_qstring,
48 if (token.type != isc_tokentype_qstring &&
49 token.type != isc_tokentype_string)
51 RETTOK(txt_fromtext(&token.value.as_textregion, target));
54 /* Let upper layer handle eol/eof. */
55 isc_lex_ungettoken(lexer, &token);
56 return (strings == 0 ? ISC_R_UNEXPECTEDEND : ISC_R_SUCCESS);
59 static inline isc_result_t
60 generic_totext_txt(ARGS_TOTEXT) {
65 dns_rdata_toregion(rdata, ®ion);
67 while (region.length > 0) {
68 RETERR(txt_totext(®ion, ISC_TRUE, target));
69 if (region.length > 0)
70 RETERR(str_totext(" ", target));
73 return (ISC_R_SUCCESS);
76 static inline isc_result_t
77 generic_fromwire_txt(ARGS_FROMWIRE) {
86 result = txt_fromwire(source, target);
87 if (result != ISC_R_SUCCESS)
89 } while (!buffer_empty(source));
90 return (ISC_R_SUCCESS);
93 static inline isc_result_t
94 fromtext_txt(ARGS_FROMTEXT) {
96 REQUIRE(type == dns_rdatatype_txt);
98 return (generic_fromtext_txt(rdclass, type, lexer, origin, options,
102 static inline isc_result_t
103 totext_txt(ARGS_TOTEXT) {
105 REQUIRE(rdata->type == dns_rdatatype_txt);
107 return (generic_totext_txt(rdata, tctx, target));
110 static inline isc_result_t
111 fromwire_txt(ARGS_FROMWIRE) {
113 REQUIRE(type == dns_rdatatype_txt);
115 return (generic_fromwire_txt(rdclass, type, source, dctx, options,
119 static inline isc_result_t
120 towire_txt(ARGS_TOWIRE) {
122 REQUIRE(rdata->type == dns_rdatatype_txt);
126 return (mem_tobuffer(target, rdata->data, rdata->length));
130 compare_txt(ARGS_COMPARE) {
134 REQUIRE(rdata1->type == rdata2->type);
135 REQUIRE(rdata1->rdclass == rdata2->rdclass);
136 REQUIRE(rdata1->type == dns_rdatatype_txt);
138 dns_rdata_toregion(rdata1, &r1);
139 dns_rdata_toregion(rdata2, &r2);
140 return (isc_region_compare(&r1, &r2));
143 static inline isc_result_t
144 generic_fromstruct_txt(ARGS_FROMSTRUCT) {
145 dns_rdata_txt_t *txt = source;
149 REQUIRE(source != NULL);
150 REQUIRE(txt->common.rdtype == type);
151 REQUIRE(txt->common.rdclass == rdclass);
152 REQUIRE(txt->txt != NULL && txt->txt_len != 0);
157 region.base = txt->txt;
158 region.length = txt->txt_len;
159 while (region.length > 0) {
160 length = uint8_fromregion(®ion);
161 isc_region_consume(®ion, 1);
162 if (region.length < length)
163 return (ISC_R_UNEXPECTEDEND);
164 isc_region_consume(®ion, length);
167 return (mem_tobuffer(target, txt->txt, txt->txt_len));
170 static inline isc_result_t
171 generic_tostruct_txt(ARGS_TOSTRUCT) {
172 dns_rdata_txt_t *txt = target;
175 REQUIRE(target != NULL);
176 REQUIRE(txt->common.rdclass == rdata->rdclass);
177 REQUIRE(txt->common.rdtype == rdata->type);
178 REQUIRE(!ISC_LINK_LINKED(&txt->common, link));
180 dns_rdata_toregion(rdata, &r);
181 txt->txt_len = r.length;
182 txt->txt = mem_maybedup(mctx, r.base, r.length);
183 if (txt->txt == NULL)
184 return (ISC_R_NOMEMORY);
188 return (ISC_R_SUCCESS);
192 generic_freestruct_txt(ARGS_FREESTRUCT) {
193 dns_rdata_txt_t *txt = source;
195 REQUIRE(source != NULL);
197 if (txt->mctx == NULL)
200 if (txt->txt != NULL)
201 isc_mem_free(txt->mctx, txt->txt);
205 static inline isc_result_t
206 fromstruct_txt(ARGS_FROMSTRUCT) {
208 REQUIRE(type == dns_rdatatype_txt);
210 return (generic_fromstruct_txt(rdclass, type, source, target));
213 static inline isc_result_t
214 tostruct_txt(ARGS_TOSTRUCT) {
215 dns_rdata_txt_t *txt = target;
217 REQUIRE(rdata->type == dns_rdatatype_txt);
218 REQUIRE(target != NULL);
220 txt->common.rdclass = rdata->rdclass;
221 txt->common.rdtype = rdata->type;
222 ISC_LINK_INIT(&txt->common, link);
224 return (generic_tostruct_txt(rdata, target, mctx));
228 freestruct_txt(ARGS_FREESTRUCT) {
229 dns_rdata_txt_t *txt = source;
231 REQUIRE(source != NULL);
232 REQUIRE(txt->common.rdtype == dns_rdatatype_txt);
234 generic_freestruct_txt(source);
237 static inline isc_result_t
238 additionaldata_txt(ARGS_ADDLDATA) {
239 REQUIRE(rdata->type == dns_rdatatype_txt);
245 return (ISC_R_SUCCESS);
248 static inline isc_result_t
249 digest_txt(ARGS_DIGEST) {
252 REQUIRE(rdata->type == dns_rdatatype_txt);
254 dns_rdata_toregion(rdata, &r);
256 return ((digest)(arg, &r));
259 static inline isc_boolean_t
260 checkowner_txt(ARGS_CHECKOWNER) {
262 REQUIRE(type == dns_rdatatype_txt);
272 static inline isc_boolean_t
273 checknames_txt(ARGS_CHECKNAMES) {
275 REQUIRE(rdata->type == dns_rdatatype_txt);
284 static inline isc_result_t
285 casecompare_txt(ARGS_COMPARE) {
286 return (compare_txt(rdata1, rdata2));
290 generic_txt_first(dns_rdata_txt_t *txt) {
292 REQUIRE(txt != NULL);
293 REQUIRE(txt->txt != NULL || txt->txt_len == 0);
295 if (txt->txt_len == 0)
296 return (ISC_R_NOMORE);
299 return (ISC_R_SUCCESS);
303 generic_txt_next(dns_rdata_txt_t *txt) {
307 REQUIRE(txt != NULL);
308 REQUIRE(txt->txt != NULL && txt->txt_len != 0);
310 INSIST(txt->offset + 1 <= txt->txt_len);
311 r.base = txt->txt + txt->offset;
312 r.length = txt->txt_len - txt->offset;
313 length = uint8_fromregion(&r);
314 INSIST(txt->offset + 1 + length <= txt->txt_len);
315 txt->offset = txt->offset + 1 + length;
316 if (txt->offset == txt->txt_len)
317 return (ISC_R_NOMORE);
318 return (ISC_R_SUCCESS);
322 generic_txt_current(dns_rdata_txt_t *txt, dns_rdata_txt_string_t *string) {
325 REQUIRE(txt != NULL);
326 REQUIRE(string != NULL);
327 REQUIRE(txt->txt != NULL);
328 REQUIRE(txt->offset < txt->txt_len);
330 INSIST(txt->offset + 1 <= txt->txt_len);
331 r.base = txt->txt + txt->offset;
332 r.length = txt->txt_len - txt->offset;
334 string->length = uint8_fromregion(&r);
335 isc_region_consume(&r, 1);
336 string->data = r.base;
337 INSIST(txt->offset + 1 + string->length <= txt->txt_len);
339 return (ISC_R_SUCCESS);
343 dns_rdata_txt_first(dns_rdata_txt_t *txt) {
345 REQUIRE(txt != NULL);
346 REQUIRE(txt->common.rdtype == dns_rdatatype_txt);
348 return (generic_txt_first(txt));
352 dns_rdata_txt_next(dns_rdata_txt_t *txt) {
354 REQUIRE(txt != NULL);
355 REQUIRE(txt->common.rdtype == dns_rdatatype_txt);
357 return (generic_txt_next(txt));
361 dns_rdata_txt_current(dns_rdata_txt_t *txt, dns_rdata_txt_string_t *string) {
363 REQUIRE(txt != NULL);
364 REQUIRE(txt->common.rdtype == dns_rdatatype_txt);
366 return (generic_txt_current(txt, string));
368 #endif /* RDATA_GENERIC_TXT_16_C */