1 /* $NetBSD: nsap-ptr_23.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
2
3 /*
4 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2001 Internet Software Consortium.
6 *
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.
10 *
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.
18 */
19
20 /* Id: nsap-ptr_23.c,v 1.40 2009/12/04 22:06:37 tbox Exp */
21
22 /* Reviewed: Fri Mar 17 10:16:02 PST 2000 by gson */
23
24 /* RFC1348. Obsoleted in RFC 1706 - use PTR instead. */
25
26 #ifndef RDATA_IN_1_NSAP_PTR_23_C
27 #define RDATA_IN_1_NSAP_PTR_23_C
28
29 #define RRTYPE_NSAP_PTR_ATTRIBUTES (0)
30
31 static inline isc_result_t
fromtext_in_nsap_ptr(ARGS_FROMTEXT)32 fromtext_in_nsap_ptr(ARGS_FROMTEXT) {
33 isc_token_t token;
34 dns_name_t name;
35 isc_buffer_t buffer;
36
37 REQUIRE(type == 23);
38 REQUIRE(rdclass == 1);
39
40 UNUSED(type);
41 UNUSED(rdclass);
42 UNUSED(callbacks);
43
44 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
45 ISC_FALSE));
46
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);
52 }
53
54 static inline isc_result_t
totext_in_nsap_ptr(ARGS_TOTEXT)55 totext_in_nsap_ptr(ARGS_TOTEXT) {
56 isc_region_t region;
57 dns_name_t name;
58 dns_name_t prefix;
59 isc_boolean_t sub;
60
61 REQUIRE(rdata->type == 23);
62 REQUIRE(rdata->rdclass == 1);
63 REQUIRE(rdata->length != 0);
64
65 dns_name_init(&name, NULL);
66 dns_name_init(&prefix, NULL);
67
68 dns_rdata_toregion(rdata, ®ion);
69 dns_name_fromregion(&name, ®ion);
70
71 sub = name_prefix(&name, tctx->origin, &prefix);
72
73 return (dns_name_totext(&prefix, sub, target));
74 }
75
76 static inline isc_result_t
fromwire_in_nsap_ptr(ARGS_FROMWIRE)77 fromwire_in_nsap_ptr(ARGS_FROMWIRE) {
78 dns_name_t name;
79
80 REQUIRE(type == 23);
81 REQUIRE(rdclass == 1);
82
83 UNUSED(type);
84 UNUSED(rdclass);
85
86 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
87
88 dns_name_init(&name, NULL);
89 return (dns_name_fromwire(&name, source, dctx, options, target));
90 }
91
92 static inline isc_result_t
towire_in_nsap_ptr(ARGS_TOWIRE)93 towire_in_nsap_ptr(ARGS_TOWIRE) {
94 dns_name_t name;
95 dns_offsets_t offsets;
96 isc_region_t region;
97
98 REQUIRE(rdata->type == 23);
99 REQUIRE(rdata->rdclass == 1);
100 REQUIRE(rdata->length != 0);
101
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);
106
107 return (dns_name_towire(&name, cctx, target));
108 }
109
110 static inline int
compare_in_nsap_ptr(ARGS_COMPARE)111 compare_in_nsap_ptr(ARGS_COMPARE) {
112 dns_name_t name1;
113 dns_name_t name2;
114 isc_region_t region1;
115 isc_region_t region2;
116
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);
123
124 dns_name_init(&name1, NULL);
125 dns_name_init(&name2, NULL);
126
127 dns_rdata_toregion(rdata1, ®ion1);
128 dns_rdata_toregion(rdata2, ®ion2);
129
130 dns_name_fromregion(&name1, ®ion1);
131 dns_name_fromregion(&name2, ®ion2);
132
133 return (dns_name_rdatacompare(&name1, &name2));
134 }
135
136 static inline isc_result_t
fromstruct_in_nsap_ptr(ARGS_FROMSTRUCT)137 fromstruct_in_nsap_ptr(ARGS_FROMSTRUCT) {
138 dns_rdata_in_nsap_ptr_t *nsap_ptr = source;
139 isc_region_t region;
140
141 REQUIRE(type == 23);
142 REQUIRE(rdclass == 1);
143 REQUIRE(source != NULL);
144 REQUIRE(nsap_ptr->common.rdtype == type);
145 REQUIRE(nsap_ptr->common.rdclass == rdclass);
146
147 UNUSED(type);
148 UNUSED(rdclass);
149
150 dns_name_toregion(&nsap_ptr->owner, ®ion);
151 return (isc_buffer_copyregion(target, ®ion));
152 }
153
154 static inline isc_result_t
tostruct_in_nsap_ptr(ARGS_TOSTRUCT)155 tostruct_in_nsap_ptr(ARGS_TOSTRUCT) {
156 isc_region_t region;
157 dns_rdata_in_nsap_ptr_t *nsap_ptr = target;
158 dns_name_t name;
159
160 REQUIRE(rdata->type == 23);
161 REQUIRE(rdata->rdclass == 1);
162 REQUIRE(target != NULL);
163 REQUIRE(rdata->length != 0);
164
165 nsap_ptr->common.rdclass = rdata->rdclass;
166 nsap_ptr->common.rdtype = rdata->type;
167 ISC_LINK_INIT(&nsap_ptr->common, link);
168
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);
176 }
177
178 static inline void
freestruct_in_nsap_ptr(ARGS_FREESTRUCT)179 freestruct_in_nsap_ptr(ARGS_FREESTRUCT) {
180 dns_rdata_in_nsap_ptr_t *nsap_ptr = source;
181
182 REQUIRE(source != NULL);
183 REQUIRE(nsap_ptr->common.rdclass == 1);
184 REQUIRE(nsap_ptr->common.rdtype == 23);
185
186 if (nsap_ptr->mctx == NULL)
187 return;
188
189 dns_name_free(&nsap_ptr->owner, nsap_ptr->mctx);
190 nsap_ptr->mctx = NULL;
191 }
192
193 static inline isc_result_t
additionaldata_in_nsap_ptr(ARGS_ADDLDATA)194 additionaldata_in_nsap_ptr(ARGS_ADDLDATA) {
195 REQUIRE(rdata->type == 23);
196 REQUIRE(rdata->rdclass == 1);
197
198 UNUSED(rdata);
199 UNUSED(add);
200 UNUSED(arg);
201
202 return (ISC_R_SUCCESS);
203 }
204
205 static inline isc_result_t
digest_in_nsap_ptr(ARGS_DIGEST)206 digest_in_nsap_ptr(ARGS_DIGEST) {
207 isc_region_t r;
208 dns_name_t name;
209
210 REQUIRE(rdata->type == 23);
211 REQUIRE(rdata->rdclass == 1);
212
213 dns_rdata_toregion(rdata, &r);
214 dns_name_init(&name, NULL);
215 dns_name_fromregion(&name, &r);
216
217 return (dns_name_digest(&name, digest, arg));
218 }
219
220 static inline isc_boolean_t
checkowner_in_nsap_ptr(ARGS_CHECKOWNER)221 checkowner_in_nsap_ptr(ARGS_CHECKOWNER) {
222
223 REQUIRE(type == 23);
224 REQUIRE(rdclass == 1);
225
226 UNUSED(name);
227 UNUSED(type);
228 UNUSED(rdclass);
229 UNUSED(wildcard);
230
231 return (ISC_TRUE);
232 }
233
234 static inline isc_boolean_t
checknames_in_nsap_ptr(ARGS_CHECKNAMES)235 checknames_in_nsap_ptr(ARGS_CHECKNAMES) {
236
237 REQUIRE(rdata->type == 23);
238 REQUIRE(rdata->rdclass == 1);
239
240 UNUSED(rdata);
241 UNUSED(owner);
242 UNUSED(bad);
243
244 return (ISC_TRUE);
245 }
246
247 static inline int
casecompare_in_nsap_ptr(ARGS_COMPARE)248 casecompare_in_nsap_ptr(ARGS_COMPARE) {
249 return (compare_in_nsap_ptr(rdata1, rdata2));
250 }
251
252 #endif /* RDATA_IN_1_NSAP_PTR_23_C */
253