2 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 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: nsap-ptr_23.c,v 1.40 2009/12/04 22:06:37 tbox Exp $ */
20 /* Reviewed: Fri Mar 17 10:16:02 PST 2000 by gson */
22 /* RFC1348. Obsoleted in RFC 1706 - use PTR instead. */
24 #ifndef RDATA_IN_1_NSAP_PTR_23_C
25 #define RDATA_IN_1_NSAP_PTR_23_C
27 #define RRTYPE_NSAP_PTR_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_in_nsap_ptr(ARGS_FROMTEXT) {
36 REQUIRE(rdclass == 1);
42 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
45 dns_name_init(&name, NULL);
46 buffer_fromregion(&buffer, &token.value.as_region);
47 origin = (origin != NULL) ? origin : dns_rootname;
48 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
49 return (ISC_R_SUCCESS);
52 static inline isc_result_t
53 totext_in_nsap_ptr(ARGS_TOTEXT) {
59 REQUIRE(rdata->type == 23);
60 REQUIRE(rdata->rdclass == 1);
61 REQUIRE(rdata->length != 0);
63 dns_name_init(&name, NULL);
64 dns_name_init(&prefix, NULL);
66 dns_rdata_toregion(rdata, ®ion);
67 dns_name_fromregion(&name, ®ion);
69 sub = name_prefix(&name, tctx->origin, &prefix);
71 return (dns_name_totext(&prefix, sub, target));
74 static inline isc_result_t
75 fromwire_in_nsap_ptr(ARGS_FROMWIRE) {
79 REQUIRE(rdclass == 1);
84 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
86 dns_name_init(&name, NULL);
87 return (dns_name_fromwire(&name, source, dctx, options, target));
90 static inline isc_result_t
91 towire_in_nsap_ptr(ARGS_TOWIRE) {
93 dns_offsets_t offsets;
96 REQUIRE(rdata->type == 23);
97 REQUIRE(rdata->rdclass == 1);
98 REQUIRE(rdata->length != 0);
100 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
101 dns_name_init(&name, offsets);
102 dns_rdata_toregion(rdata, ®ion);
103 dns_name_fromregion(&name, ®ion);
105 return (dns_name_towire(&name, cctx, target));
109 compare_in_nsap_ptr(ARGS_COMPARE) {
112 isc_region_t region1;
113 isc_region_t region2;
115 REQUIRE(rdata1->type == rdata2->type);
116 REQUIRE(rdata1->rdclass == rdata2->rdclass);
117 REQUIRE(rdata1->type == 23);
118 REQUIRE(rdata1->rdclass == 1);
119 REQUIRE(rdata1->length != 0);
120 REQUIRE(rdata2->length != 0);
122 dns_name_init(&name1, NULL);
123 dns_name_init(&name2, NULL);
125 dns_rdata_toregion(rdata1, ®ion1);
126 dns_rdata_toregion(rdata2, ®ion2);
128 dns_name_fromregion(&name1, ®ion1);
129 dns_name_fromregion(&name2, ®ion2);
131 return (dns_name_rdatacompare(&name1, &name2));
134 static inline isc_result_t
135 fromstruct_in_nsap_ptr(ARGS_FROMSTRUCT) {
136 dns_rdata_in_nsap_ptr_t *nsap_ptr = source;
140 REQUIRE(rdclass == 1);
141 REQUIRE(source != NULL);
142 REQUIRE(nsap_ptr->common.rdtype == type);
143 REQUIRE(nsap_ptr->common.rdclass == rdclass);
148 dns_name_toregion(&nsap_ptr->owner, ®ion);
149 return (isc_buffer_copyregion(target, ®ion));
152 static inline isc_result_t
153 tostruct_in_nsap_ptr(ARGS_TOSTRUCT) {
155 dns_rdata_in_nsap_ptr_t *nsap_ptr = target;
158 REQUIRE(rdata->type == 23);
159 REQUIRE(rdata->rdclass == 1);
160 REQUIRE(target != NULL);
161 REQUIRE(rdata->length != 0);
163 nsap_ptr->common.rdclass = rdata->rdclass;
164 nsap_ptr->common.rdtype = rdata->type;
165 ISC_LINK_INIT(&nsap_ptr->common, link);
167 dns_name_init(&name, NULL);
168 dns_rdata_toregion(rdata, ®ion);
169 dns_name_fromregion(&name, ®ion);
170 dns_name_init(&nsap_ptr->owner, NULL);
171 RETERR(name_duporclone(&name, mctx, &nsap_ptr->owner));
172 nsap_ptr->mctx = mctx;
173 return (ISC_R_SUCCESS);
177 freestruct_in_nsap_ptr(ARGS_FREESTRUCT) {
178 dns_rdata_in_nsap_ptr_t *nsap_ptr = source;
180 REQUIRE(source != NULL);
181 REQUIRE(nsap_ptr->common.rdclass == 1);
182 REQUIRE(nsap_ptr->common.rdtype == 23);
184 if (nsap_ptr->mctx == NULL)
187 dns_name_free(&nsap_ptr->owner, nsap_ptr->mctx);
188 nsap_ptr->mctx = NULL;
191 static inline isc_result_t
192 additionaldata_in_nsap_ptr(ARGS_ADDLDATA) {
193 REQUIRE(rdata->type == 23);
194 REQUIRE(rdata->rdclass == 1);
200 return (ISC_R_SUCCESS);
203 static inline isc_result_t
204 digest_in_nsap_ptr(ARGS_DIGEST) {
208 REQUIRE(rdata->type == 23);
209 REQUIRE(rdata->rdclass == 1);
211 dns_rdata_toregion(rdata, &r);
212 dns_name_init(&name, NULL);
213 dns_name_fromregion(&name, &r);
215 return (dns_name_digest(&name, digest, arg));
218 static inline isc_boolean_t
219 checkowner_in_nsap_ptr(ARGS_CHECKOWNER) {
222 REQUIRE(rdclass == 1);
232 static inline isc_boolean_t
233 checknames_in_nsap_ptr(ARGS_CHECKNAMES) {
235 REQUIRE(rdata->type == 23);
236 REQUIRE(rdata->rdclass == 1);
246 casecompare_in_nsap_ptr(ARGS_COMPARE) {
247 return (compare_in_nsap_ptr(rdata1, rdata2));
250 #endif /* RDATA_IN_1_NSAP_PTR_23_C */