Coverage Report

Created: 2025-11-11 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/lib/dns/rdata/generic/uri_256.c
Line
Count
Source
1
/*
2
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3
 *
4
 * SPDX-License-Identifier: MPL-2.0
5
 *
6
 * This Source Code Form is subject to the terms of the Mozilla Public
7
 * License, v. 2.0. If a copy of the MPL was not distributed with this
8
 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
9
 *
10
 * See the COPYRIGHT file distributed with this work for additional
11
 * information regarding copyright ownership.
12
 */
13
14
#ifndef GENERIC_URI_256_C
15
#define GENERIC_URI_256_C 1
16
17
11.3k
#define RRTYPE_URI_ATTRIBUTES (0)
18
19
static isc_result_t
20
1.01k
fromtext_uri(ARGS_FROMTEXT) {
21
1.01k
  isc_token_t token;
22
23
1.01k
  REQUIRE(type == dns_rdatatype_uri);
24
25
1.01k
  UNUSED(type);
26
1.01k
  UNUSED(rdclass);
27
1.01k
  UNUSED(origin);
28
1.01k
  UNUSED(options);
29
1.01k
  UNUSED(callbacks);
30
31
  /*
32
   * Priority
33
   */
34
1.01k
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
35
1.01k
              false));
36
1.01k
  if (token.value.as_ulong > 0xffffU) {
37
25
    RETTOK(ISC_R_RANGE);
38
25
  }
39
985
  RETERR(uint16_tobuffer(token.value.as_ulong, target));
40
41
  /*
42
   * Weight
43
   */
44
985
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
45
985
              false));
46
948
  if (token.value.as_ulong > 0xffffU) {
47
9
    RETTOK(ISC_R_RANGE);
48
9
  }
49
939
  RETERR(uint16_tobuffer(token.value.as_ulong, target));
50
51
  /*
52
   * Target URI
53
   */
54
939
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
55
939
              false));
56
920
  if (token.type != isc_tokentype_qstring) {
57
2
    RETTOK(DNS_R_SYNTAX);
58
2
  }
59
918
  RETTOK(multitxt_fromtext(&token.value.as_textregion, target));
60
916
  return ISC_R_SUCCESS;
61
918
}
62
63
static isc_result_t
64
1.98k
totext_uri(ARGS_TOTEXT) {
65
1.98k
  isc_region_t region;
66
1.98k
  unsigned short priority, weight;
67
1.98k
  char buf[sizeof("65000 ")];
68
69
1.98k
  UNUSED(tctx);
70
71
1.98k
  REQUIRE(rdata->type == dns_rdatatype_uri);
72
1.98k
  REQUIRE(rdata->length != 0);
73
74
1.98k
  dns_rdata_toregion(rdata, &region);
75
76
  /*
77
   * Priority
78
   */
79
1.98k
  priority = uint16_fromregion(&region);
80
1.98k
  isc_region_consume(&region, 2);
81
1.98k
  snprintf(buf, sizeof(buf), "%u ", priority);
82
1.98k
  RETERR(str_totext(buf, target));
83
84
  /*
85
   * Weight
86
   */
87
1.98k
  weight = uint16_fromregion(&region);
88
1.98k
  isc_region_consume(&region, 2);
89
1.98k
  snprintf(buf, sizeof(buf), "%u ", weight);
90
1.98k
  RETERR(str_totext(buf, target));
91
92
  /*
93
   * Target URI
94
   */
95
1.98k
  RETERR(multitxt_totext(&region, target));
96
1.98k
  return ISC_R_SUCCESS;
97
1.98k
}
98
99
static isc_result_t
100
2.52k
fromwire_uri(ARGS_FROMWIRE) {
101
2.52k
  isc_region_t region;
102
103
2.52k
  REQUIRE(type == dns_rdatatype_uri);
104
105
2.52k
  UNUSED(type);
106
2.52k
  UNUSED(rdclass);
107
2.52k
  UNUSED(dctx);
108
109
  /*
110
   * Priority, weight
111
   */
112
2.52k
  isc_buffer_activeregion(source, &region);
113
2.52k
  if (region.length < 4) {
114
14
    return ISC_R_UNEXPECTEDEND;
115
14
  }
116
117
  /*
118
   * Priority, weight and target URI
119
   */
120
2.51k
  isc_buffer_forward(source, region.length);
121
2.51k
  return mem_tobuffer(target, region.base, region.length);
122
2.52k
}
123
124
static isc_result_t
125
1.01k
towire_uri(ARGS_TOWIRE) {
126
1.01k
  isc_region_t region;
127
128
1.01k
  REQUIRE(rdata->type == dns_rdatatype_uri);
129
1.01k
  REQUIRE(rdata->length != 0);
130
131
1.01k
  UNUSED(cctx);
132
133
1.01k
  dns_rdata_toregion(rdata, &region);
134
1.01k
  return mem_tobuffer(target, region.base, region.length);
135
1.01k
}
136
137
static int
138
3.55k
compare_uri(ARGS_COMPARE) {
139
3.55k
  isc_region_t r1;
140
3.55k
  isc_region_t r2;
141
3.55k
  int order;
142
143
3.55k
  REQUIRE(rdata1->type == rdata2->type);
144
3.55k
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
145
3.55k
  REQUIRE(rdata1->type == dns_rdatatype_uri);
146
3.55k
  REQUIRE(rdata1->length != 0);
147
3.55k
  REQUIRE(rdata2->length != 0);
148
149
3.55k
  dns_rdata_toregion(rdata1, &r1);
150
3.55k
  dns_rdata_toregion(rdata2, &r2);
151
152
  /*
153
   * Priority
154
   */
155
3.55k
  order = memcmp(r1.base, r2.base, 2);
156
3.55k
  if (order != 0) {
157
945
    return order < 0 ? -1 : 1;
158
945
  }
159
2.60k
  isc_region_consume(&r1, 2);
160
2.60k
  isc_region_consume(&r2, 2);
161
162
  /*
163
   * Weight
164
   */
165
2.60k
  order = memcmp(r1.base, r2.base, 2);
166
2.60k
  if (order != 0) {
167
934
    return order < 0 ? -1 : 1;
168
934
  }
169
1.67k
  isc_region_consume(&r1, 2);
170
1.67k
  isc_region_consume(&r2, 2);
171
172
1.67k
  return isc_region_compare(&r1, &r2);
173
2.60k
}
174
175
static isc_result_t
176
0
fromstruct_uri(ARGS_FROMSTRUCT) {
177
0
  dns_rdata_uri_t *uri = source;
178
179
0
  REQUIRE(type == dns_rdatatype_uri);
180
0
  REQUIRE(uri != NULL);
181
0
  REQUIRE(uri->common.rdtype == type);
182
0
  REQUIRE(uri->common.rdclass == rdclass);
183
0
  REQUIRE(uri->target != NULL && uri->tgt_len != 0);
184
185
0
  UNUSED(type);
186
0
  UNUSED(rdclass);
187
188
  /*
189
   * Priority
190
   */
191
0
  RETERR(uint16_tobuffer(uri->priority, target));
192
193
  /*
194
   * Weight
195
   */
196
0
  RETERR(uint16_tobuffer(uri->weight, target));
197
198
  /*
199
   * Target URI
200
   */
201
0
  return mem_tobuffer(target, uri->target, uri->tgt_len);
202
0
}
203
204
static isc_result_t
205
0
tostruct_uri(ARGS_TOSTRUCT) {
206
0
  dns_rdata_uri_t *uri = target;
207
0
  isc_region_t sr;
208
209
0
  REQUIRE(rdata->type == dns_rdatatype_uri);
210
0
  REQUIRE(uri != NULL);
211
0
  REQUIRE(rdata->length >= 4);
212
213
0
  DNS_RDATACOMMON_INIT(uri, rdata->type, rdata->rdclass);
214
215
0
  dns_rdata_toregion(rdata, &sr);
216
217
  /*
218
   * Priority
219
   */
220
0
  uri->priority = uint16_fromregion(&sr);
221
0
  isc_region_consume(&sr, 2);
222
223
  /*
224
   * Weight
225
   */
226
0
  uri->weight = uint16_fromregion(&sr);
227
0
  isc_region_consume(&sr, 2);
228
229
  /*
230
   * Target URI
231
   */
232
0
  uri->tgt_len = sr.length;
233
0
  uri->target = mem_maybedup(mctx, sr.base, sr.length);
234
0
  uri->mctx = mctx;
235
0
  return ISC_R_SUCCESS;
236
0
}
237
238
static void
239
0
freestruct_uri(ARGS_FREESTRUCT) {
240
0
  dns_rdata_uri_t *uri = (dns_rdata_uri_t *)source;
241
242
0
  REQUIRE(uri != NULL);
243
0
  REQUIRE(uri->common.rdtype == dns_rdatatype_uri);
244
245
0
  if (uri->mctx == NULL) {
246
0
    return;
247
0
  }
248
249
0
  if (uri->target != NULL) {
250
0
    isc_mem_free(uri->mctx, uri->target);
251
0
  }
252
0
  uri->mctx = NULL;
253
0
}
254
255
static isc_result_t
256
0
additionaldata_uri(ARGS_ADDLDATA) {
257
0
  REQUIRE(rdata->type == dns_rdatatype_uri);
258
259
0
  UNUSED(rdata);
260
0
  UNUSED(owner);
261
0
  UNUSED(add);
262
0
  UNUSED(arg);
263
264
0
  return ISC_R_SUCCESS;
265
0
}
266
267
static isc_result_t
268
0
digest_uri(ARGS_DIGEST) {
269
0
  isc_region_t r;
270
271
0
  REQUIRE(rdata->type == dns_rdatatype_uri);
272
273
0
  dns_rdata_toregion(rdata, &r);
274
275
0
  return (digest)(arg, &r);
276
0
}
277
278
static bool
279
0
checkowner_uri(ARGS_CHECKOWNER) {
280
0
  REQUIRE(type == dns_rdatatype_uri);
281
282
0
  UNUSED(name);
283
0
  UNUSED(type);
284
0
  UNUSED(rdclass);
285
0
  UNUSED(wildcard);
286
287
0
  return true;
288
0
}
289
290
static bool
291
0
checknames_uri(ARGS_CHECKNAMES) {
292
0
  REQUIRE(rdata->type == dns_rdatatype_uri);
293
294
0
  UNUSED(rdata);
295
0
  UNUSED(owner);
296
0
  UNUSED(bad);
297
298
0
  return true;
299
0
}
300
301
static int
302
0
casecompare_uri(ARGS_COMPARE) {
303
0
  return compare_uri(rdata1, rdata2);
304
0
}
305
306
#endif /* GENERIC_URI_256_C */