1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or 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.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
#ifndef RDATA_GENERIC_DOA_259_C
#define RDATA_GENERIC_DOA_259_C
#define RRTYPE_DOA_ATTRIBUTES (0)
static inline isc_result_t
totext_doa(ARGS_TOTEXT) {
char buf[sizeof("4294967295 ")];
isc_region_t region;
uint32_t n;
REQUIRE(rdata != NULL);
REQUIRE(rdata->type == dns_rdatatype_doa);
REQUIRE(rdata->length != 0);
UNUSED(tctx);
dns_rdata_toregion(rdata, ®ion);
/*
* DOA-ENTERPRISE
*/
n = uint32_fromregion(®ion);
isc_region_consume(®ion, 4);
snprintf(buf, sizeof(buf), "%u ", n);
RETERR(str_totext(buf, target));
/*
* DOA-TYPE
*/
n = uint32_fromregion(®ion);
isc_region_consume(®ion, 4);
snprintf(buf, sizeof(buf), "%u ", n);
RETERR(str_totext(buf, target));
/*
* DOA-LOCATION
*/
n = uint8_fromregion(®ion);
isc_region_consume(®ion, 1);
snprintf(buf, sizeof(buf), "%u ", n);
RETERR(str_totext(buf, target));
/*
* DOA-MEDIA-TYPE
*/
RETERR(txt_totext(®ion, ISC_TRUE, target));
RETERR(str_totext(" ", target));
/*
* DOA-DATA
*/
if (region.length == 0) {
return (str_totext("-", target));
} else {
return (isc_base64_totext(®ion, 60, "", target));
}
}
static inline isc_result_t
fromwire_doa(ARGS_FROMWIRE) {
isc_region_t region;
UNUSED(rdclass);
UNUSED(dctx);
UNUSED(options);
REQUIRE(type == dns_rdatatype_doa);
isc_buffer_activeregion(source, ®ion);
/*
* DOA-MEDIA-TYPE may be an empty <character-string> (i.e.,
* comprising of just the length octet) and DOA-DATA can have
* zero length.
*/
if (region.length < 4 + 4 + 1 + 1) {
return (ISC_R_UNEXPECTEDEND);
}
/*
* Check whether DOA-MEDIA-TYPE length is not malformed.
*/
if (region.base[9] > region.length - 10) {
return (ISC_R_UNEXPECTEDEND);
}
isc_buffer_forward(source, region.length);
return (mem_tobuffer(target, region.base, region.length));
}
static inline isc_result_t
towire_doa(ARGS_TOWIRE) {
isc_region_t region;
UNUSED(cctx);
REQUIRE(rdata != NULL);
REQUIRE(rdata->type == dns_rdatatype_doa);
REQUIRE(rdata->length != 0);
dns_rdata_toregion(rdata, ®ion);
return (mem_tobuffer(target, region.base, region.length));
}
static inline isc_result_t
fromstruct_doa(ARGS_FROMSTRUCT) {
dns_rdata_doa_t *doa = source;
REQUIRE(type == dns_rdatatype_doa);
REQUIRE(source != NULL);
REQUIRE(doa->common.rdtype == dns_rdatatype_doa);
REQUIRE(doa->common.rdclass == rdclass);
RETERR(uint32_tobuffer(doa->enterprise, target));
RETERR(uint32_tobuffer(doa->type, target));
RETERR(uint8_tobuffer(doa->location, target));
RETERR(uint8_tobuffer(doa->mediatype_len, target));
RETERR(mem_tobuffer(target, doa->mediatype, doa->mediatype_len));
return (mem_tobuffer(target, doa->data, doa->data_len));
}
static inline isc_result_t
tostruct_doa(ARGS_TOSTRUCT) {
dns_rdata_doa_t *doa = target;
isc_region_t region;
REQUIRE(rdata != NULL);
REQUIRE(rdata->type == dns_rdatatype_doa);
REQUIRE(rdata->length != 0);
doa->common.rdclass = rdata->rdclass;
doa->common.rdtype = rdata->type;
ISC_LINK_INIT(&doa->common, link);
dns_rdata_toregion(rdata, ®ion);
/*
* DOA-ENTERPRISE
*/
if (region.length < 4) {
return (ISC_R_UNEXPECTEDEND);
}
doa->enterprise = uint32_fromregion(®ion);
isc_region_consume(®ion, 4);
/*
* DOA-TYPE
*/
if (region.length < 4) {
return (ISC_R_UNEXPECTEDEND);
}
doa->type = uint32_fromregion(®ion);
isc_region_consume(®ion, 4);
/*
* DOA-LOCATION
*/
if (region.length < 1) {
return (ISC_R_UNEXPECTEDEND);
}
doa->location = uint8_fromregion(®ion);
isc_region_consume(®ion, 1);
/*
* DOA-MEDIA-TYPE
*/
if (region.length < 1) {
return (ISC_R_UNEXPECTEDEND);
}
doa->mediatype_len = uint8_fromregion(®ion);
isc_region_consume(®ion, 1);
INSIST(doa->mediatype_len <= region.length);
doa->mediatype = mem_maybedup(region.base, doa->mediatype_len);
if (doa->mediatype == NULL) {
goto cleanup;
}
isc_region_consume(®ion, doa->mediatype_len);
/*
* DOA-DATA
*/
doa->data_len = region.length;
doa->data = NULL;
if (doa->data_len > 0) {
doa->data = mem_maybedup(region.base, doa->data_len);
if (doa->data == NULL) {
goto cleanup;
}
isc_region_consume(®ion, doa->data_len);
}
return (ISC_R_SUCCESS);
cleanup:
free(doa->mediatype);
return (ISC_R_NOMEMORY);
}
#endif /* RDATA_GENERIC_DOA_259_C */
|