mf_4.c 4.75 KB
Newer Older
1
/*
David Lawrence's avatar
David Lawrence committed
2
 * Copyright (C) 1998-2000  Internet Software Consortium.
3
 *
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.
16 17
 */

18
/* $Id: mf_4.c,v 1.36 2000/12/01 01:40:27 gson Exp $ */
James Brister's avatar
James Brister committed
19 20

/* reviewed: Wed Mar 15 17:47:33 PST 2000 by brister */
Mark Andrews's avatar
Mark Andrews committed
21

22 23
#ifndef RDATA_GENERIC_MF_4_C
#define RDATA_GENERIC_MF_4_C
24

25 26
#define RRTYPE_MF_ATTRIBUTES (0)

27
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
28
fromtext_mf(ARGS_FROMTEXT) {
29 30 31 32
	isc_token_t token;
	dns_name_t name;
	isc_buffer_t buffer;

Mark Andrews's avatar
Mark Andrews committed
33
	REQUIRE(type == 4);
Mark Andrews's avatar
Mark Andrews committed
34

James Brister's avatar
James Brister committed
35
	UNUSED(rdclass);
36

37 38
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
				      ISC_FALSE));
39 40

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

46
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
47
totext_mf(ARGS_TOTEXT) {
48 49 50 51 52
	isc_region_t region;
	dns_name_t name;
	dns_name_t prefix;
	isc_boolean_t sub;

Mark Andrews's avatar
Mark Andrews committed
53
	REQUIRE(rdata->type == 4);
54
	REQUIRE(rdata->length != 0);
55 56

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

59 60 61
	dns_rdata_toregion(rdata, &region);
	dns_name_fromregion(&name, &region);

62
	sub = name_prefix(&name, tctx->origin, &prefix);
63

James Brister's avatar
James Brister committed
64
	return (dns_name_totext(&prefix, sub, target));
65 66
}

67
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
68
fromwire_mf(ARGS_FROMWIRE) {
69 70
        dns_name_t name;

Mark Andrews's avatar
Mark Andrews committed
71
	REQUIRE(type == 4);
Mark Andrews's avatar
Mark Andrews committed
72

James Brister's avatar
James Brister committed
73
	UNUSED(rdclass);
Mark Andrews's avatar
Mark Andrews committed
74

75
	dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
76

77
        dns_name_init(&name, NULL);
James Brister's avatar
James Brister committed
78
        return (dns_name_fromwire(&name, source, dctx, downcase, target));
79 80
}

81
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
82
towire_mf(ARGS_TOWIRE) {
83 84 85
	dns_name_t name;
	isc_region_t region;

Mark Andrews's avatar
Mark Andrews committed
86
	REQUIRE(rdata->type == 4);
87
	REQUIRE(rdata->length != 0);
88

89
	dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
Mark Andrews's avatar
Mark Andrews committed
90

91 92 93 94
	dns_name_init(&name, NULL);
	dns_rdata_toregion(rdata, &region);
	dns_name_fromregion(&name, &region);

James Brister's avatar
James Brister committed
95
	return (dns_name_towire(&name, cctx, target));
96 97
}

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

Mark Andrews's avatar
Mark Andrews committed
105
	REQUIRE(rdata1->type == rdata2->type);
106
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
107
	REQUIRE(rdata1->type == 4);
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);

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

123
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
124
fromstruct_mf(ARGS_FROMSTRUCT) {
125 126
	dns_rdata_mf_t *mf = source;
	isc_region_t region;
Mark Andrews's avatar
Mark Andrews committed
127

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

133 134
	UNUSED(rdclass);

135 136
	dns_name_toregion(&mf->mf, &region);
	return (isc_buffer_copyregion(target, &region));
137 138
}

139
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
140
tostruct_mf(ARGS_TOSTRUCT) {
141 142 143
	dns_rdata_mf_t *mf = target;
	isc_region_t r;
	dns_name_t name;
Mark Andrews's avatar
Mark Andrews committed
144

Mark Andrews's avatar
Mark Andrews committed
145
	REQUIRE(rdata->type == 4);
146
	REQUIRE(target != NULL);
147
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
148

149 150 151
	mf->common.rdclass = rdata->rdclass;
	mf->common.rdtype = rdata->type;
	ISC_LINK_INIT(&mf->common, link);
152

153 154 155 156 157 158 159
	dns_name_init(&name, NULL);
	dns_rdata_toregion(rdata, &r);
	dns_name_fromregion(&name, &r);
	dns_name_init(&mf->mf, NULL);
	RETERR(name_duporclone(&name, mctx, &mf->mf));
	mf->mctx = mctx;
	return (ISC_R_SUCCESS);
160
}
161

162
static inline void
David Lawrence's avatar
David Lawrence committed
163
freestruct_mf(ARGS_FREESTRUCT) {
164 165
	dns_rdata_mf_t *mf = source;

166
	REQUIRE(source != NULL);
167
	REQUIRE(mf->common.rdtype == 4);
168

169 170 171 172
	if (mf->mctx == NULL)
		return;
	dns_name_free(&mf->mf, mf->mctx);
	mf->mctx = NULL;
173
}
174

175
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
176
additionaldata_mf(ARGS_ADDLDATA) {
Bob Halley's avatar
Bob Halley committed
177 178 179
	dns_name_t name;
	isc_region_t region;

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

Bob Halley's avatar
Bob Halley committed
182 183 184
	dns_name_init(&name, NULL);
	dns_rdata_toregion(rdata, &region);
	dns_name_fromregion(&name, &region);
185

James Brister's avatar
James Brister committed
186
	return ((add)(arg, &name, dns_rdatatype_a));
187 188
}

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

	REQUIRE(rdata->type == 4);

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

James Brister's avatar
James Brister committed
200
	return (dns_name_digest(&name, digest, arg));
Bob Halley's avatar
Bob Halley committed
201 202
}

203
#endif	/* RDATA_GENERIC_MF_4_C */