Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / dns / rdata / in_1 / srv_33.c
blob8f02fca8e26fb347a1623bec7951842e7305d765
1 /*
2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001, 2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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: srv_33.c,v 1.36.2.3 2004/03/09 06:11:38 marka Exp $ */
20 /* Reviewed: Fri Mar 17 13:01:00 PST 2000 by bwelling */
22 /* RFC 2782 */
24 #ifndef RDATA_IN_1_SRV_33_C
25 #define RDATA_IN_1_SRV_33_C
27 #define RRTYPE_SRV_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_in_srv(ARGS_FROMTEXT) {
31 isc_token_t token;
32 dns_name_t name;
33 isc_buffer_t buffer;
35 REQUIRE(type == 33);
36 REQUIRE(rdclass == 1);
38 UNUSED(type);
39 UNUSED(rdclass);
40 UNUSED(callbacks);
43 * Priority.
45 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
46 ISC_FALSE));
47 if (token.value.as_ulong > 0xffffU)
48 RETTOK(ISC_R_RANGE);
49 RETERR(uint16_tobuffer(token.value.as_ulong, target));
52 * Weight.
54 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
55 ISC_FALSE));
56 if (token.value.as_ulong > 0xffffU)
57 RETTOK(ISC_R_RANGE);
58 RETERR(uint16_tobuffer(token.value.as_ulong, target));
61 * Port.
63 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
64 ISC_FALSE));
65 if (token.value.as_ulong > 0xffffU)
66 RETTOK(ISC_R_RANGE);
67 RETERR(uint16_tobuffer(token.value.as_ulong, target));
70 * Target.
72 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
73 ISC_FALSE));
74 dns_name_init(&name, NULL);
75 buffer_fromregion(&buffer, &token.value.as_region);
76 origin = (origin != NULL) ? origin : dns_rootname;
77 RETTOK(dns_name_fromtext(&name, &buffer, origin, downcase, target));
78 return (ISC_R_SUCCESS);
81 static inline isc_result_t
82 totext_in_srv(ARGS_TOTEXT) {
83 isc_region_t region;
84 dns_name_t name;
85 dns_name_t prefix;
86 isc_boolean_t sub;
87 char buf[sizeof "64000"];
88 unsigned short num;
90 REQUIRE(rdata->type == 33);
91 REQUIRE(rdata->rdclass == 1);
92 REQUIRE(rdata->length != 0);
94 dns_name_init(&name, NULL);
95 dns_name_init(&prefix, NULL);
98 * Priority.
100 dns_rdata_toregion(rdata, &region);
101 num = uint16_fromregion(&region);
102 isc_region_consume(&region, 2);
103 sprintf(buf, "%u", num);
104 RETERR(str_totext(buf, target));
105 RETERR(str_totext(" ", target));
108 * Weight.
110 num = uint16_fromregion(&region);
111 isc_region_consume(&region, 2);
112 sprintf(buf, "%u", num);
113 RETERR(str_totext(buf, target));
114 RETERR(str_totext(" ", target));
117 * Port.
119 num = uint16_fromregion(&region);
120 isc_region_consume(&region, 2);
121 sprintf(buf, "%u", num);
122 RETERR(str_totext(buf, target));
123 RETERR(str_totext(" ", target));
126 * Target.
128 dns_name_fromregion(&name, &region);
129 sub = name_prefix(&name, tctx->origin, &prefix);
130 return (dns_name_totext(&prefix, sub, target));
133 static inline isc_result_t
134 fromwire_in_srv(ARGS_FROMWIRE) {
135 dns_name_t name;
136 isc_region_t sr;
138 REQUIRE(type == 33);
139 REQUIRE(rdclass == 1);
141 UNUSED(type);
142 UNUSED(rdclass);
144 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
146 dns_name_init(&name, NULL);
149 * Priority, weight, port.
151 isc_buffer_activeregion(source, &sr);
152 if (sr.length < 6)
153 return (ISC_R_UNEXPECTEDEND);
154 RETERR(mem_tobuffer(target, sr.base, 6));
155 isc_buffer_forward(source, 6);
158 * Target.
160 return (dns_name_fromwire(&name, source, dctx, downcase, target));
163 static inline isc_result_t
164 towire_in_srv(ARGS_TOWIRE) {
165 dns_name_t name;
166 dns_offsets_t offsets;
167 isc_region_t sr;
169 REQUIRE(rdata->type == 33);
170 REQUIRE(rdata->length != 0);
172 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
174 * Priority, weight, port.
176 dns_rdata_toregion(rdata, &sr);
177 RETERR(mem_tobuffer(target, sr.base, 6));
178 isc_region_consume(&sr, 6);
181 * Target.
183 dns_name_init(&name, offsets);
184 dns_name_fromregion(&name, &sr);
185 return (dns_name_towire(&name, cctx, target));
188 static inline int
189 compare_in_srv(ARGS_COMPARE) {
190 dns_name_t name1;
191 dns_name_t name2;
192 isc_region_t region1;
193 isc_region_t region2;
194 int order;
196 REQUIRE(rdata1->type == rdata2->type);
197 REQUIRE(rdata1->rdclass == rdata2->rdclass);
198 REQUIRE(rdata1->type == 33);
199 REQUIRE(rdata1->rdclass == 1);
200 REQUIRE(rdata1->length != 0);
201 REQUIRE(rdata2->length != 0);
204 * Priority, weight, port.
206 order = memcmp(rdata1->data, rdata2->data, 6);
207 if (order != 0)
208 return (order < 0 ? -1 : 1);
211 * Target.
213 dns_name_init(&name1, NULL);
214 dns_name_init(&name2, NULL);
216 dns_rdata_toregion(rdata1, &region1);
217 dns_rdata_toregion(rdata2, &region2);
219 isc_region_consume(&region1, 6);
220 isc_region_consume(&region2, 6);
222 dns_name_fromregion(&name1, &region1);
223 dns_name_fromregion(&name2, &region2);
225 return (dns_name_rdatacompare(&name1, &name2));
228 static inline isc_result_t
229 fromstruct_in_srv(ARGS_FROMSTRUCT) {
230 dns_rdata_in_srv_t *srv = source;
231 isc_region_t region;
233 REQUIRE(type == 33);
234 REQUIRE(rdclass == 1);
235 REQUIRE(source != NULL);
236 REQUIRE(srv->common.rdtype == type);
237 REQUIRE(srv->common.rdclass == rdclass);
239 UNUSED(type);
240 UNUSED(rdclass);
242 RETERR(uint16_tobuffer(srv->priority, target));
243 RETERR(uint16_tobuffer(srv->weight, target));
244 RETERR(uint16_tobuffer(srv->port, target));
245 dns_name_toregion(&srv->target, &region);
246 return (isc_buffer_copyregion(target, &region));
249 static inline isc_result_t
250 tostruct_in_srv(ARGS_TOSTRUCT) {
251 isc_region_t region;
252 dns_rdata_in_srv_t *srv = target;
253 dns_name_t name;
255 REQUIRE(rdata->rdclass == 1);
256 REQUIRE(rdata->type == 33);
257 REQUIRE(target != NULL);
258 REQUIRE(rdata->length != 0);
260 srv->common.rdclass = rdata->rdclass;
261 srv->common.rdtype = rdata->type;
262 ISC_LINK_INIT(&srv->common, link);
264 dns_name_init(&name, NULL);
265 dns_rdata_toregion(rdata, &region);
266 srv->priority = uint16_fromregion(&region);
267 isc_region_consume(&region, 2);
268 srv->weight = uint16_fromregion(&region);
269 isc_region_consume(&region, 2);
270 srv->port = uint16_fromregion(&region);
271 isc_region_consume(&region, 2);
272 dns_name_fromregion(&name, &region);
273 dns_name_init(&srv->target, NULL);
274 RETERR(name_duporclone(&name, mctx, &srv->target));
275 srv->mctx = mctx;
276 return (ISC_R_SUCCESS);
279 static inline void
280 freestruct_in_srv(ARGS_FREESTRUCT) {
281 dns_rdata_in_srv_t *srv = source;
283 REQUIRE(source != NULL);
284 REQUIRE(srv->common.rdclass == 1);
285 REQUIRE(srv->common.rdtype == 33);
287 if (srv->mctx == NULL)
288 return;
290 dns_name_free(&srv->target, srv->mctx);
291 srv->mctx = NULL;
294 static inline isc_result_t
295 additionaldata_in_srv(ARGS_ADDLDATA) {
296 dns_name_t name;
297 dns_offsets_t offsets;
298 isc_region_t region;
300 REQUIRE(rdata->type == 33);
301 REQUIRE(rdata->rdclass == 1);
303 dns_name_init(&name, offsets);
304 dns_rdata_toregion(rdata, &region);
305 isc_region_consume(&region, 6);
306 dns_name_fromregion(&name, &region);
308 return ((add)(arg, &name, dns_rdatatype_a));
311 static inline isc_result_t
312 digest_in_srv(ARGS_DIGEST) {
313 isc_region_t r1, r2;
314 dns_name_t name;
316 REQUIRE(rdata->type == 33);
317 REQUIRE(rdata->rdclass == 1);
319 dns_rdata_toregion(rdata, &r1);
320 r2 = r1;
321 isc_region_consume(&r2, 6);
322 r1.length = 6;
323 RETERR((digest)(arg, &r1));
324 dns_name_init(&name, NULL);
325 dns_name_fromregion(&name, &r2);
326 return (dns_name_digest(&name, digest, arg));
329 #endif /* RDATA_IN_1_SRV_33_C */