Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / lp_107.c
blobddfe0d76d2972a1f1bf00f0ce2fa6e906d0916e4
1 /* $NetBSD: lp_107.c,v 1.1.1.3 2014/12/10 03:34:42 christos Exp $ */
3 /*
4 * Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 #ifndef RDATA_GENERIC_LP_107_C
20 #define RDATA_GENERIC_LP_107_C
22 #include <string.h>
24 #include <isc/net.h>
26 #define RRTYPE_LP_ATTRIBUTES (0)
28 static inline isc_result_t
29 fromtext_lp(ARGS_FROMTEXT) {
30 isc_token_t token;
31 dns_name_t name;
32 isc_buffer_t buffer;
34 REQUIRE(type == 107);
36 UNUSED(type);
37 UNUSED(rdclass);
38 UNUSED(callbacks);
40 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
41 ISC_FALSE));
42 if (token.value.as_ulong > 0xffffU)
43 RETTOK(ISC_R_RANGE);
44 RETERR(uint16_tobuffer(token.value.as_ulong, target));
46 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
47 ISC_FALSE));
49 dns_name_init(&name, NULL);
50 buffer_fromregion(&buffer, &token.value.as_region);
51 origin = (origin != NULL) ? origin : dns_rootname;
52 return (dns_name_fromtext(&name, &buffer, origin, options, target));
55 static inline isc_result_t
56 totext_lp(ARGS_TOTEXT) {
57 isc_region_t region;
58 dns_name_t name;
59 dns_name_t prefix;
60 isc_boolean_t sub;
61 char buf[sizeof("64000")];
62 unsigned short num;
64 REQUIRE(rdata->type == 107);
65 REQUIRE(rdata->length != 0);
67 dns_name_init(&name, NULL);
68 dns_name_init(&prefix, NULL);
70 dns_rdata_toregion(rdata, &region);
71 num = uint16_fromregion(&region);
72 isc_region_consume(&region, 2);
73 sprintf(buf, "%u", num);
74 RETERR(str_totext(buf, target));
76 RETERR(str_totext(" ", target));
78 dns_name_fromregion(&name, &region);
79 sub = name_prefix(&name, tctx->origin, &prefix);
80 return (dns_name_totext(&prefix, sub, target));
83 static inline isc_result_t
84 fromwire_lp(ARGS_FROMWIRE) {
85 dns_name_t name;
86 isc_region_t sregion;
88 REQUIRE(type == 107);
90 UNUSED(type);
91 UNUSED(rdclass);
93 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
95 dns_name_init(&name, NULL);
97 isc_buffer_activeregion(source, &sregion);
98 if (sregion.length < 2)
99 return (ISC_R_UNEXPECTEDEND);
100 RETERR(mem_tobuffer(target, sregion.base, 2));
101 isc_buffer_forward(source, 2);
102 return (dns_name_fromwire(&name, source, dctx, options, target));
105 static inline isc_result_t
106 towire_lp(ARGS_TOWIRE) {
108 REQUIRE(rdata->type == 107);
109 REQUIRE(rdata->length != 0);
111 UNUSED(cctx);
113 return (mem_tobuffer(target, rdata->data, rdata->length));
116 static inline int
117 compare_lp(ARGS_COMPARE) {
118 isc_region_t region1;
119 isc_region_t region2;
121 REQUIRE(rdata1->type == rdata2->type);
122 REQUIRE(rdata1->rdclass == rdata2->rdclass);
123 REQUIRE(rdata1->type == 107);
124 REQUIRE(rdata1->length != 0);
125 REQUIRE(rdata2->length != 0);
127 dns_rdata_toregion(rdata1, &region1);
128 dns_rdata_toregion(rdata2, &region2);
130 return (isc_region_compare(&region1, &region2));
133 static inline isc_result_t
134 fromstruct_lp(ARGS_FROMSTRUCT) {
135 dns_rdata_lp_t *lp = source;
136 isc_region_t region;
138 REQUIRE(type == 107);
139 REQUIRE(source != NULL);
140 REQUIRE(lp->common.rdtype == type);
141 REQUIRE(lp->common.rdclass == rdclass);
143 UNUSED(type);
144 UNUSED(rdclass);
146 RETERR(uint16_tobuffer(lp->pref, target));
147 dns_name_toregion(&lp->lp, &region);
148 return (isc_buffer_copyregion(target, &region));
151 static inline isc_result_t
152 tostruct_lp(ARGS_TOSTRUCT) {
153 isc_region_t region;
154 dns_rdata_lp_t *lp = target;
155 dns_name_t name;
157 REQUIRE(rdata->type == 107);
158 REQUIRE(target != NULL);
159 REQUIRE(rdata->length != 0);
161 lp->common.rdclass = rdata->rdclass;
162 lp->common.rdtype = rdata->type;
163 ISC_LINK_INIT(&lp->common, link);
165 dns_name_init(&name, NULL);
166 dns_rdata_toregion(rdata, &region);
167 lp->pref = uint16_fromregion(&region);
168 isc_region_consume(&region, 2);
169 dns_name_fromregion(&name, &region);
170 dns_name_init(&lp->lp, NULL);
171 RETERR(name_duporclone(&name, mctx, &lp->lp));
172 lp->mctx = mctx;
173 return (ISC_R_SUCCESS);
176 static inline void
177 freestruct_lp(ARGS_FREESTRUCT) {
178 dns_rdata_lp_t *lp = source;
180 REQUIRE(source != NULL);
181 REQUIRE(lp->common.rdtype == 107);
183 if (lp->mctx == NULL)
184 return;
186 dns_name_free(&lp->lp, lp->mctx);
187 lp->mctx = NULL;
190 static inline isc_result_t
191 additionaldata_lp(ARGS_ADDLDATA) {
192 dns_name_t name;
193 dns_offsets_t offsets;
194 isc_region_t region;
195 isc_result_t result;
197 REQUIRE(rdata->type == 107);
199 dns_name_init(&name, offsets);
200 dns_rdata_toregion(rdata, &region);
201 isc_region_consume(&region, 2);
202 dns_name_fromregion(&name, &region);
204 result = (add)(arg, &name, dns_rdatatype_l32);
205 if (result != ISC_R_SUCCESS)
206 return (result);
207 return ((add)(arg, &name, dns_rdatatype_l64));
210 static inline isc_result_t
211 digest_lp(ARGS_DIGEST) {
212 isc_region_t region;
214 REQUIRE(rdata->type == 107);
216 dns_rdata_toregion(rdata, &region);
217 return ((digest)(arg, &region));
220 static inline isc_boolean_t
221 checkowner_lp(ARGS_CHECKOWNER) {
223 REQUIRE(type == 107);
225 UNUSED(type);
226 UNUSED(rdclass);
227 UNUSED(name);
228 UNUSED(wildcard);
230 return (ISC_TRUE);
233 static inline isc_boolean_t
234 checknames_lp(ARGS_CHECKNAMES) {
236 REQUIRE(rdata->type == 107);
238 UNUSED(bad);
239 UNUSED(owner);
241 return (ISC_TRUE);
244 static inline int
245 casecompare_lp(ARGS_COMPARE) {
246 dns_name_t name1;
247 dns_name_t name2;
248 isc_region_t region1;
249 isc_region_t region2;
250 int order;
252 REQUIRE(rdata1->type == rdata2->type);
253 REQUIRE(rdata1->rdclass == rdata2->rdclass);
254 REQUIRE(rdata1->type == 107);
255 REQUIRE(rdata1->length != 0);
256 REQUIRE(rdata2->length != 0);
258 order = memcmp(rdata1->data, rdata2->data, 2);
259 if (order != 0)
260 return (order < 0 ? -1 : 1);
262 dns_name_init(&name1, NULL);
263 dns_name_init(&name2, NULL);
265 dns_rdata_toregion(rdata1, &region1);
266 dns_rdata_toregion(rdata2, &region2);
268 isc_region_consume(&region1, 2);
269 isc_region_consume(&region2, 2);
271 dns_name_fromregion(&name1, &region1);
272 dns_name_fromregion(&name2, &region2);
274 return (dns_name_rdatacompare(&name1, &name2));
277 #endif /* RDATA_GENERIC_LP_107_C */