1 /* $NetBSD: nsap-ptr_23.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: nsap-ptr_23.c,v 1.40 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Fri Mar 17 10:16:02 PST 2000 by gson */
24 /* RFC1348. Obsoleted in RFC 1706 - use PTR instead. */
26 #ifndef RDATA_IN_1_NSAP_PTR_23_C
27 #define RDATA_IN_1_NSAP_PTR_23_C
29 #define RRTYPE_NSAP_PTR_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_in_nsap_ptr(ARGS_FROMTEXT
) {
38 REQUIRE(rdclass
== 1);
44 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
47 dns_name_init(&name
, NULL
);
48 buffer_fromregion(&buffer
, &token
.value
.as_region
);
49 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
50 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
51 return (ISC_R_SUCCESS
);
54 static inline isc_result_t
55 totext_in_nsap_ptr(ARGS_TOTEXT
) {
61 REQUIRE(rdata
->type
== 23);
62 REQUIRE(rdata
->rdclass
== 1);
63 REQUIRE(rdata
->length
!= 0);
65 dns_name_init(&name
, NULL
);
66 dns_name_init(&prefix
, NULL
);
68 dns_rdata_toregion(rdata
, ®ion
);
69 dns_name_fromregion(&name
, ®ion
);
71 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
73 return (dns_name_totext(&prefix
, sub
, target
));
76 static inline isc_result_t
77 fromwire_in_nsap_ptr(ARGS_FROMWIRE
) {
81 REQUIRE(rdclass
== 1);
86 dns_decompress_setmethods(dctx
, DNS_COMPRESS_NONE
);
88 dns_name_init(&name
, NULL
);
89 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
92 static inline isc_result_t
93 towire_in_nsap_ptr(ARGS_TOWIRE
) {
95 dns_offsets_t offsets
;
98 REQUIRE(rdata
->type
== 23);
99 REQUIRE(rdata
->rdclass
== 1);
100 REQUIRE(rdata
->length
!= 0);
102 dns_compress_setmethods(cctx
, DNS_COMPRESS_NONE
);
103 dns_name_init(&name
, offsets
);
104 dns_rdata_toregion(rdata
, ®ion
);
105 dns_name_fromregion(&name
, ®ion
);
107 return (dns_name_towire(&name
, cctx
, target
));
111 compare_in_nsap_ptr(ARGS_COMPARE
) {
114 isc_region_t region1
;
115 isc_region_t region2
;
117 REQUIRE(rdata1
->type
== rdata2
->type
);
118 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
119 REQUIRE(rdata1
->type
== 23);
120 REQUIRE(rdata1
->rdclass
== 1);
121 REQUIRE(rdata1
->length
!= 0);
122 REQUIRE(rdata2
->length
!= 0);
124 dns_name_init(&name1
, NULL
);
125 dns_name_init(&name2
, NULL
);
127 dns_rdata_toregion(rdata1
, ®ion1
);
128 dns_rdata_toregion(rdata2
, ®ion2
);
130 dns_name_fromregion(&name1
, ®ion1
);
131 dns_name_fromregion(&name2
, ®ion2
);
133 return (dns_name_rdatacompare(&name1
, &name2
));
136 static inline isc_result_t
137 fromstruct_in_nsap_ptr(ARGS_FROMSTRUCT
) {
138 dns_rdata_in_nsap_ptr_t
*nsap_ptr
= source
;
142 REQUIRE(rdclass
== 1);
143 REQUIRE(source
!= NULL
);
144 REQUIRE(nsap_ptr
->common
.rdtype
== type
);
145 REQUIRE(nsap_ptr
->common
.rdclass
== rdclass
);
150 dns_name_toregion(&nsap_ptr
->owner
, ®ion
);
151 return (isc_buffer_copyregion(target
, ®ion
));
154 static inline isc_result_t
155 tostruct_in_nsap_ptr(ARGS_TOSTRUCT
) {
157 dns_rdata_in_nsap_ptr_t
*nsap_ptr
= target
;
160 REQUIRE(rdata
->type
== 23);
161 REQUIRE(rdata
->rdclass
== 1);
162 REQUIRE(target
!= NULL
);
163 REQUIRE(rdata
->length
!= 0);
165 nsap_ptr
->common
.rdclass
= rdata
->rdclass
;
166 nsap_ptr
->common
.rdtype
= rdata
->type
;
167 ISC_LINK_INIT(&nsap_ptr
->common
, link
);
169 dns_name_init(&name
, NULL
);
170 dns_rdata_toregion(rdata
, ®ion
);
171 dns_name_fromregion(&name
, ®ion
);
172 dns_name_init(&nsap_ptr
->owner
, NULL
);
173 RETERR(name_duporclone(&name
, mctx
, &nsap_ptr
->owner
));
174 nsap_ptr
->mctx
= mctx
;
175 return (ISC_R_SUCCESS
);
179 freestruct_in_nsap_ptr(ARGS_FREESTRUCT
) {
180 dns_rdata_in_nsap_ptr_t
*nsap_ptr
= source
;
182 REQUIRE(source
!= NULL
);
183 REQUIRE(nsap_ptr
->common
.rdclass
== 1);
184 REQUIRE(nsap_ptr
->common
.rdtype
== 23);
186 if (nsap_ptr
->mctx
== NULL
)
189 dns_name_free(&nsap_ptr
->owner
, nsap_ptr
->mctx
);
190 nsap_ptr
->mctx
= NULL
;
193 static inline isc_result_t
194 additionaldata_in_nsap_ptr(ARGS_ADDLDATA
) {
195 REQUIRE(rdata
->type
== 23);
196 REQUIRE(rdata
->rdclass
== 1);
202 return (ISC_R_SUCCESS
);
205 static inline isc_result_t
206 digest_in_nsap_ptr(ARGS_DIGEST
) {
210 REQUIRE(rdata
->type
== 23);
211 REQUIRE(rdata
->rdclass
== 1);
213 dns_rdata_toregion(rdata
, &r
);
214 dns_name_init(&name
, NULL
);
215 dns_name_fromregion(&name
, &r
);
217 return (dns_name_digest(&name
, digest
, arg
));
220 static inline isc_boolean_t
221 checkowner_in_nsap_ptr(ARGS_CHECKOWNER
) {
224 REQUIRE(rdclass
== 1);
234 static inline isc_boolean_t
235 checknames_in_nsap_ptr(ARGS_CHECKNAMES
) {
237 REQUIRE(rdata
->type
== 23);
238 REQUIRE(rdata
->rdclass
== 1);
248 casecompare_in_nsap_ptr(ARGS_COMPARE
) {
249 return (compare_in_nsap_ptr(rdata1
, rdata2
));
252 #endif /* RDATA_IN_1_NSAP_PTR_23_C */