txt_16.c revision 1.5
1/*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/* Reviewed: Thu Mar 16 15:40:00 PST 2000 by bwelling */
18
19#ifndef RDATA_GENERIC_TXT_16_C
20#define RDATA_GENERIC_TXT_16_C
21
22#define RRTYPE_TXT_ATTRIBUTES (0)
23
24static inline isc_result_t
25generic_totext_txt(ARGS_TOTEXT) {
26	isc_region_t region;
27
28	UNUSED(tctx);
29
30	dns_rdata_toregion(rdata, &region);
31
32	while (region.length > 0) {
33		RETERR(txt_totext(&region, ISC_TRUE, target));
34		if (region.length > 0)
35			RETERR(str_totext(" ", target));
36	}
37
38	return (ISC_R_SUCCESS);
39}
40
41static inline isc_result_t
42generic_fromwire_txt(ARGS_FROMWIRE) {
43	isc_result_t result;
44
45	UNUSED(type);
46	UNUSED(dctx);
47	UNUSED(rdclass);
48	UNUSED(options);
49
50	do {
51		result = txt_fromwire(source, target);
52		if (result != ISC_R_SUCCESS)
53			return (result);
54	} while (!buffer_empty(source));
55	return (ISC_R_SUCCESS);
56}
57
58static inline isc_result_t
59totext_txt(ARGS_TOTEXT) {
60
61	REQUIRE(rdata->type == dns_rdatatype_txt);
62
63	return (generic_totext_txt(rdata, tctx, target));
64}
65
66static inline isc_result_t
67fromwire_txt(ARGS_FROMWIRE) {
68
69	REQUIRE(type == dns_rdatatype_txt);
70
71	return (generic_fromwire_txt(rdclass, type, source, dctx, options,
72				     target));
73}
74
75static inline isc_result_t
76towire_txt(ARGS_TOWIRE) {
77
78	REQUIRE(rdata->type == dns_rdatatype_txt);
79
80	UNUSED(cctx);
81
82	return (mem_tobuffer(target, rdata->data, rdata->length));
83}
84
85
86static inline isc_result_t
87generic_fromstruct_txt(ARGS_FROMSTRUCT) {
88	dns_rdata_txt_t *txt = source;
89	isc_region_t region;
90	uint8_t length;
91
92	REQUIRE(source != NULL);
93	REQUIRE(txt->common.rdtype == type);
94	REQUIRE(txt->common.rdclass == rdclass);
95	REQUIRE(txt->txt != NULL && txt->txt_len != 0);
96
97	UNUSED(type);
98	UNUSED(rdclass);
99
100	region.base = txt->txt;
101	region.length = txt->txt_len;
102	while (region.length > 0) {
103		length = uint8_fromregion(&region);
104		isc_region_consume(&region, 1);
105		if (region.length < length)
106			return (ISC_R_UNEXPECTEDEND);
107		isc_region_consume(&region, length);
108	}
109
110	return (mem_tobuffer(target, txt->txt, txt->txt_len));
111}
112
113static inline isc_result_t
114generic_tostruct_txt(ARGS_TOSTRUCT) {
115	dns_rdata_txt_t *txt = target;
116	isc_region_t r;
117
118	REQUIRE(target != NULL);
119	REQUIRE(txt->common.rdclass == rdata->rdclass);
120	REQUIRE(txt->common.rdtype == rdata->type);
121	REQUIRE(!ISC_LINK_LINKED(&txt->common, link));
122
123	dns_rdata_toregion(rdata, &r);
124	txt->txt_len = r.length;
125	txt->txt = mem_maybedup(r.base, r.length);
126	if (txt->txt == NULL)
127		return (ISC_R_NOMEMORY);
128
129	txt->offset = 0;
130	return (ISC_R_SUCCESS);
131}
132
133static inline void
134generic_freestruct_txt(ARGS_FREESTRUCT) {
135	dns_rdata_txt_t *txt = source;
136
137	REQUIRE(source != NULL);
138
139	if (txt->txt != NULL)
140		free(txt->txt);
141}
142
143static inline isc_result_t
144fromstruct_txt(ARGS_FROMSTRUCT) {
145
146	REQUIRE(type == dns_rdatatype_txt);
147
148	return (generic_fromstruct_txt(rdclass, type, source, target));
149}
150
151static inline isc_result_t
152tostruct_txt(ARGS_TOSTRUCT) {
153	dns_rdata_txt_t *txt = target;
154
155	REQUIRE(rdata->type == dns_rdatatype_txt);
156	REQUIRE(target != NULL);
157
158	txt->common.rdclass = rdata->rdclass;
159	txt->common.rdtype = rdata->type;
160	ISC_LINK_INIT(&txt->common, link);
161
162	return (generic_tostruct_txt(rdata, target));
163}
164
165static inline void
166freestruct_txt(ARGS_FREESTRUCT) {
167	dns_rdata_txt_t *txt = source;
168
169	REQUIRE(source != NULL);
170	REQUIRE(txt->common.rdtype == dns_rdatatype_txt);
171
172	generic_freestruct_txt(source);
173}
174
175static inline isc_boolean_t
176checkowner_txt(ARGS_CHECKOWNER) {
177
178	REQUIRE(type == dns_rdatatype_txt);
179
180	UNUSED(name);
181	UNUSED(type);
182	UNUSED(rdclass);
183	UNUSED(wildcard);
184
185	return (ISC_TRUE);
186}
187
188
189#endif	/* RDATA_GENERIC_TXT_16_C */
190