dname_39.c 4.77 KB
Newer Older
Mark Andrews's avatar
Mark Andrews committed
1
/*
Bob Halley's avatar
Bob Halley committed
2
 * Copyright (C) 1999, 2000  Internet Software Consortium.
3
 *
Mark Andrews's avatar
Mark Andrews committed
4 5 6
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
7
 *
8 9 10 11 12 13 14 15
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Mark Andrews's avatar
Mark Andrews committed
16 17
 */

18
/* $Id: dname_39.c,v 1.26 2000/10/25 05:43:30 marka Exp $ */
Mark Andrews's avatar
Mark Andrews committed
19

20 21 22
/* Reviewed: Wed Mar 15 16:52:38 PST 2000 by explorer */

/* draft-ietf-dnsind-dname-02.txt */
Mark Andrews's avatar
Mark Andrews committed
23

24 25
#ifndef RDATA_GENERIC_DNAME_39_C
#define RDATA_GENERIC_DNAME_39_C
Mark Andrews's avatar
Mark Andrews committed
26

27 28
#define RRTYPE_DNAME_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON)

29
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
30
fromtext_dname(ARGS_FROMTEXT) {
Mark Andrews's avatar
Mark Andrews committed
31 32 33 34
	isc_token_t token;
	dns_name_t name;
	isc_buffer_t buffer;

35 36
	UNUSED(rdclass);

Mark Andrews's avatar
Mark Andrews committed
37
	REQUIRE(type == 39);
38

Mark Andrews's avatar
Mark Andrews committed
39
	RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
40

Mark Andrews's avatar
Mark Andrews committed
41
	dns_name_init(&name, NULL);
42
	buffer_fromregion(&buffer, &token.value.as_region);
Mark Andrews's avatar
Mark Andrews committed
43 44 45 46
	origin = (origin != NULL) ? origin : dns_rootname;
	return (dns_name_fromtext(&name, &buffer, origin, downcase, target));
}

47
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
48
totext_dname(ARGS_TOTEXT) {
Mark Andrews's avatar
Mark Andrews committed
49 50 51 52 53 54
	isc_region_t region;
	dns_name_t name;
	dns_name_t prefix;
	isc_boolean_t sub;

	REQUIRE(rdata->type == 39);
55
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
56 57 58 59 60 61 62

	dns_name_init(&name, NULL);
	dns_name_init(&prefix, NULL);

	dns_rdata_toregion(rdata, &region);
	dns_name_fromregion(&name, &region);

63
	sub = name_prefix(&name, tctx->origin, &prefix);
Mark Andrews's avatar
Mark Andrews committed
64 65 66 67

	return (dns_name_totext(&prefix, sub, target));
}

68
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
69
fromwire_dname(ARGS_FROMWIRE) {
Mark Andrews's avatar
Mark Andrews committed
70 71
	dns_name_t name;

72 73
	UNUSED(rdclass);

Mark Andrews's avatar
Mark Andrews committed
74 75
	REQUIRE(type == 39);

76
	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
Mark Andrews's avatar
Mark Andrews committed
77

Mark Andrews's avatar
Mark Andrews committed
78 79 80 81
	dns_name_init(&name, NULL);
	return(dns_name_fromwire(&name, source, dctx, downcase, target));
}

82
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
83
towire_dname(ARGS_TOWIRE) {
Mark Andrews's avatar
Mark Andrews committed
84 85 86 87
	dns_name_t name;
	isc_region_t region;

	REQUIRE(rdata->type == 39);
88
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
89

90
	dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
Mark Andrews's avatar
Mark Andrews committed
91 92 93 94 95 96 97
	dns_name_init(&name, NULL);
	dns_rdata_toregion(rdata, &region);
	dns_name_fromregion(&name, &region);

	return (dns_name_towire(&name, cctx, target));
}

98
static inline int
David Lawrence's avatar
David Lawrence committed
99
compare_dname(ARGS_COMPARE) {
Mark Andrews's avatar
Mark Andrews committed
100 101 102 103 104 105
	dns_name_t name1;
	dns_name_t name2;
	isc_region_t region1;
	isc_region_t region2;

	REQUIRE(rdata1->type == rdata2->type);
106
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
107
	REQUIRE(rdata1->type == 39);
108 109
	REQUIRE(rdata1->length != 0);
	REQUIRE(rdata2->length != 0);
Mark Andrews's avatar
Mark Andrews committed
110 111 112 113 114 115 116 117 118 119

	dns_name_init(&name1, NULL);
	dns_name_init(&name2, NULL);

	dns_rdata_toregion(rdata1, &region1);
	dns_rdata_toregion(rdata2, &region2);

	dns_name_fromregion(&name1, &region1);
	dns_name_fromregion(&name2, &region2);

120
	return (dns_name_rdatacompare(&name1, &name2));
Mark Andrews's avatar
Mark Andrews committed
121 122
}

123
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
124
fromstruct_dname(ARGS_FROMSTRUCT) {
125 126
	dns_rdata_dname_t *dname = source;
	isc_region_t region;
Mark Andrews's avatar
Mark Andrews committed
127 128

	REQUIRE(type == 39);
129 130 131
	REQUIRE(source != NULL);
	REQUIRE(dname->common.rdtype == type);
	REQUIRE(dname->common.rdclass == rdclass);
Mark Andrews's avatar
Mark Andrews committed
132

133 134
	dns_name_toregion(&dname->dname, &region);
	return (isc_buffer_copyregion(target, &region));
Mark Andrews's avatar
Mark Andrews committed
135 136
}

137
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
138
tostruct_dname(ARGS_TOSTRUCT) {
139 140 141
	isc_region_t region;
	dns_rdata_dname_t *dname = target;
	dns_name_t name;
Mark Andrews's avatar
Mark Andrews committed
142

143 144
	REQUIRE(rdata->type == 39);
	REQUIRE(target != NULL);
145
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
146

147 148 149 150 151 152 153 154 155 156 157
	dname->common.rdclass = rdata->rdclass;
	dname->common.rdtype = rdata->type;
	ISC_LINK_INIT(&dname->common, link);

	dns_name_init(&name, NULL);
	dns_rdata_toregion(rdata, &region);
	dns_name_fromregion(&name, &region);
	dns_name_init(&dname->dname, NULL);
	RETERR(name_duporclone(&name, mctx, &dname->dname));
	dname->mctx = mctx;
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
158
}
159

160
static inline void
David Lawrence's avatar
David Lawrence committed
161
freestruct_dname(ARGS_FREESTRUCT) {
162 163
	dns_rdata_dname_t *dname = source;

164
	REQUIRE(source != NULL);
165
	REQUIRE(dname->common.rdtype == 39);
166

167 168
	if (dname->mctx == NULL)
		return;
169

170 171
	dns_name_free(&dname->dname, dname->mctx);
	dname->mctx = NULL;
172
}
173

174
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
175
additionaldata_dname(ARGS_ADDLDATA) {
176
	UNUSED(rdata);
177 178
	UNUSED(add);
	UNUSED(arg);
179

180
	REQUIRE(rdata->type == 39);
181

182
	return (ISC_R_SUCCESS);
183 184
}

185
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
186
digest_dname(ARGS_DIGEST) {
Bob Halley's avatar
Bob Halley committed
187 188 189 190 191 192 193 194 195 196 197 198
	isc_region_t r;
	dns_name_t name;

	REQUIRE(rdata->type == 39);

	dns_rdata_toregion(rdata, &r);
	dns_name_init(&name, NULL);
	dns_name_fromregion(&name, &r);

	return (dns_name_digest(&name, digest, arg));
}

199
#endif	/* RDATA_GENERIC_DNAME_39_C */