xref: /openbsd/usr.bin/dig/lib/dns/rdata/generic/txt_16.c (revision 1fb015a8)
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 static inline isc_result_t
generic_totext_txt(ARGS_TOTEXT)23 generic_totext_txt(ARGS_TOTEXT) {
24 	isc_region_t region;
25 
26 	UNUSED(tctx);
27 
28 	dns_rdata_toregion(rdata, &region);
29 
30 	while (region.length > 0) {
31 		RETERR(txt_totext(&region, 1, target));
32 		if (region.length > 0)
33 			RETERR(isc_str_tobuffer(" ", target));
34 	}
35 
36 	return (ISC_R_SUCCESS);
37 }
38 
39 static inline isc_result_t
generic_fromwire_txt(ARGS_FROMWIRE)40 generic_fromwire_txt(ARGS_FROMWIRE) {
41 	isc_result_t result;
42 
43 	UNUSED(type);
44 	UNUSED(dctx);
45 	UNUSED(rdclass);
46 	UNUSED(options);
47 
48 	do {
49 		result = txt_fromwire(source, target);
50 		if (result != ISC_R_SUCCESS)
51 			return (result);
52 	} while (!buffer_empty(source));
53 	return (ISC_R_SUCCESS);
54 }
55 
56 static inline isc_result_t
totext_txt(ARGS_TOTEXT)57 totext_txt(ARGS_TOTEXT) {
58 
59 	REQUIRE(rdata->type == dns_rdatatype_txt);
60 
61 	return (generic_totext_txt(rdata, tctx, target));
62 }
63 
64 static inline isc_result_t
fromwire_txt(ARGS_FROMWIRE)65 fromwire_txt(ARGS_FROMWIRE) {
66 
67 	REQUIRE(type == dns_rdatatype_txt);
68 
69 	return (generic_fromwire_txt(rdclass, type, source, dctx, options,
70 				     target));
71 }
72 
73 static inline isc_result_t
towire_txt(ARGS_TOWIRE)74 towire_txt(ARGS_TOWIRE) {
75 
76 	REQUIRE(rdata->type == dns_rdatatype_txt);
77 
78 	UNUSED(cctx);
79 
80 	return (isc_mem_tobuffer(target, rdata->data, rdata->length));
81 }
82 
83 #endif	/* RDATA_GENERIC_TXT_16_C */
84