Coverage Report

Created: 2026-09-06 06:17

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
12.2k
#define RRTYPE_URI_ATTRIBUTES (0)
18
19
static isc_result_t
20
1.09k
fromtext_uri(ARGS_FROMTEXT) {
21
1.09k
  isc_token_t token;
22
23
1.09k
  REQUIRE(type == dns_rdatatype_uri);
24
25
1.09k
  UNUSED(type);
26
1.09k
  UNUSED(rdclass);
27
1.09k
  UNUSED(origin);
28
1.09k
  UNUSED(options);
29
1.09k
  UNUSED(callbacks);
30
31
  /*
32
   * Priority
33
   */
34
1.09k
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
35
1.09k
              false));
36
1.09k
  if (token.value.as_ulong > 0xffffU) {
37
29
    RETTOK(ISC_R_RANGE);
38
29
  }
39
1.06k
  RETERR(uint16_tobuffer(token.value.as_ulong, target));
40
41
  /*
42
   * Weight
43
   */
44
1.06k
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
45
1.06k
              false));
46
1.02k
  if (token.value.as_ulong > 0xffffU) {
47
20
    RETTOK(ISC_R_RANGE);
48
20
  }
49
1.00k
  RETERR(uint16_tobuffer(token.value.as_ulong, target));
50
51
  /*
52
   * Target URI (non empty).
53
   */
54
1.00k
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
55
1.00k
              false));
56
960
  if (token.type != isc_tokentype_qstring ||
57
957
      token.value.as_textregion.length == 0)
58
6
  {
59
6
    RETTOK(DNS_R_SYNTAX);
60
6
  }
61
954
  RETTOK(multitxt_fromtext(&token.value.as_textregion, target));
62
952
  return ISC_R_SUCCESS;
63
954
}
64
65
static isc_result_t
66
1.58k
totext_uri(ARGS_TOTEXT) {
67
1.58k
  isc_region_t region;
68
1.58k
  unsigned short priority, weight;
69
1.58k
  char buf[sizeof("65000 ")];
70
71
1.58k
  UNUSED(tctx);
72
73
1.58k
  REQUIRE(rdata->type == dns_rdatatype_uri);
74
1.58k
  REQUIRE(rdata->length != 0);
75
76
1.58k
  dns_rdata_toregion(rdata, &region);
77
78
  /*
79
   * Priority
80
   */
81
1.58k
  priority = uint16_fromregion(&region);
82
1.58k
  isc_region_consume(&region, 2);
83
1.58k
  snprintf(buf, sizeof(buf), "%u ", priority);
84
1.58k
  RETERR(str_totext(buf, target));
85
86
  /*
87
   * Weight
88
   */
89
1.58k
  weight = uint16_fromregion(&region);
90
1.58k
  isc_region_consume(&region, 2);
91
1.58k
  snprintf(buf, sizeof(buf), "%u ", weight);
92
1.58k
  RETERR(str_totext(buf, target));
93
94
  /*
95
   * Target URI
96
   */
97
1.58k
  RETERR(multitxt_totext(&region, target));
98
1.58k
  return ISC_R_SUCCESS;
99
1.58k
}
100
101
static isc_result_t
102
2.28k
fromwire_uri(ARGS_FROMWIRE) {
103
2.28k
  isc_region_t region;
104
105
2.28k
  REQUIRE(type == dns_rdatatype_uri);
106
107
2.28k
  UNUSED(type);
108
2.28k
  UNUSED(rdclass);
109
2.28k
  UNUSED(dctx);
110
111
  /*
112
   * Priority, weight and target URI (non empty).
113
   */
114
2.28k
  isc_buffer_activeregion(source, &region);
115
2.28k
  if (region.length < 5) {
116
16
    return ISC_R_UNEXPECTEDEND;
117
16
  }
118
2.26k
  isc_buffer_forward(source, region.length);
119
2.26k
  return mem_tobuffer(target, region.base, region.length);
120
2.28k
}
121
122
static isc_result_t
123
819
towire_uri(ARGS_TOWIRE) {
124
819
  isc_region_t region;
125
126
819
  REQUIRE(rdata->type == dns_rdatatype_uri);
127
819
  REQUIRE(rdata->length != 0);
128
129
819
  UNUSED(cctx);
130
131
819
  dns_rdata_toregion(rdata, &region);
132
819
  return mem_tobuffer(target, region.base, region.length);
133
819
}
134
135
static int
136
7.75k
compare_uri(ARGS_COMPARE) {
137
7.75k
  isc_region_t r1;
138
7.75k
  isc_region_t r2;
139
7.75k
  int order;
140
141
7.75k
  REQUIRE(rdata1->type == rdata2->type);
142
7.75k
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
143
7.75k
  REQUIRE(rdata1->type == dns_rdatatype_uri);
144
7.75k
  REQUIRE(rdata1->length != 0);
145
7.75k
  REQUIRE(rdata2->length != 0);
146
147
7.75k
  dns_rdata_toregion(rdata1, &r1);
148
7.75k
  dns_rdata_toregion(rdata2, &r2);
149
150
  /*
151
   * Priority
152
   */
153
7.75k
  order = memcmp(r1.base, r2.base, 2);
154
7.75k
  if (order != 0) {
155
1.84k
    return order < 0 ? -1 : 1;
156
1.84k
  }
157
5.90k
  isc_region_consume(&r1, 2);
158
5.90k
  isc_region_consume(&r2, 2);
159
160
  /*
161
   * Weight
162
   */
163
5.90k
  order = memcmp(r1.base, r2.base, 2);
164
5.90k
  if (order != 0) {
165
3.08k
    return order < 0 ? -1 : 1;
166
3.08k
  }
167
2.82k
  isc_region_consume(&r1, 2);
168
2.82k
  isc_region_consume(&r2, 2);
169
170
2.82k
  return isc_region_compare(&r1, &r2);
171
5.90k
}
172
173
static isc_result_t
174
0
fromstruct_uri(ARGS_FROMSTRUCT) {
175
0
  dns_rdata_uri_t *uri = source;
176
177
0
  REQUIRE(type == dns_rdatatype_uri);
178
0
  REQUIRE(uri != NULL);
179
0
  REQUIRE(uri->common.rdtype == type);
180
0
  REQUIRE(uri->common.rdclass == rdclass);
181
0
  REQUIRE(uri->target != NULL && uri->tgt_len != 0);
182
183
0
  UNUSED(type);
184
0
  UNUSED(rdclass);
185
186
  /*
187
   * Priority
188
   */
189
0
  RETERR(uint16_tobuffer(uri->priority, target));
190
191
  /*
192
   * Weight
193
   */
194
0
  RETERR(uint16_tobuffer(uri->weight, target));
195
196
  /*
197
   * Target URI
198
   */
199
0
  return mem_tobuffer(target, uri->target, uri->tgt_len);
200
0
}
201
202
static isc_result_t
203
0
tostruct_uri(ARGS_TOSTRUCT) {
204
0
  dns_rdata_uri_t *uri = target;
205
0
  isc_region_t sr;
206
207
0
  REQUIRE(rdata->type == dns_rdatatype_uri);
208
0
  REQUIRE(uri != NULL);
209
0
  REQUIRE(rdata->length > 4);
210
211
0
  DNS_RDATACOMMON_INIT(uri, rdata->type, rdata->rdclass);
212
213
0
  dns_rdata_toregion(rdata, &sr);
214
215
  /*
216
   * Priority
217
   */
218
0
  uri->priority = uint16_fromregion(&sr);
219
0
  isc_region_consume(&sr, 2);
220
221
  /*
222
   * Weight
223
   */
224
0
  uri->weight = uint16_fromregion(&sr);
225
0
  isc_region_consume(&sr, 2);
226
227
  /*
228
   * Target URI
229
   */
230
0
  uri->tgt_len = sr.length;
231
0
  uri->target = mem_maybedup(mctx, sr.base, sr.length);
232
0
  uri->mctx = mctx;
233
0
  return ISC_R_SUCCESS;
234
0
}
235
236
static void
237
0
freestruct_uri(ARGS_FREESTRUCT) {
238
0
  dns_rdata_uri_t *uri = (dns_rdata_uri_t *)source;
239
240
0
  REQUIRE(uri != NULL);
241
0
  REQUIRE(uri->common.rdtype == dns_rdatatype_uri);
242
243
0
  if (uri->mctx == NULL) {
244
0
    return;
245
0
  }
246
247
0
  if (uri->target != NULL) {
248
0
    isc_mem_free(uri->mctx, uri->target);
249
0
  }
250
0
  uri->mctx = NULL;
251
0
}
252
253
static isc_result_t
254
0
additionaldata_uri(ARGS_ADDLDATA) {
255
0
  REQUIRE(rdata->type == dns_rdatatype_uri);
256
257
0
  UNUSED(rdata);
258
0
  UNUSED(owner);
259
0
  UNUSED(add);
260
0
  UNUSED(arg);
261
262
0
  return ISC_R_SUCCESS;
263
0
}
264
265
static isc_result_t
266
0
digest_uri(ARGS_DIGEST) {
267
0
  isc_region_t r;
268
269
0
  REQUIRE(rdata->type == dns_rdatatype_uri);
270
271
0
  dns_rdata_toregion(rdata, &r);
272
273
0
  return (digest)(arg, &r);
274
0
}
275
276
static bool
277
0
checkowner_uri(ARGS_CHECKOWNER) {
278
0
  REQUIRE(type == dns_rdatatype_uri);
279
280
0
  UNUSED(name);
281
0
  UNUSED(type);
282
0
  UNUSED(rdclass);
283
0
  UNUSED(wildcard);
284
285
0
  return true;
286
0
}
287
288
static bool
289
0
checknames_uri(ARGS_CHECKNAMES) {
290
0
  REQUIRE(rdata->type == dns_rdatatype_uri);
291
292
0
  UNUSED(rdata);
293
0
  UNUSED(owner);
294
0
  UNUSED(bad);
295
296
0
  return true;
297
0
}
298
299
static int
300
0
casecompare_uri(ARGS_COMPARE) {
301
0
  return compare_uri(rdata1, rdata2);
302
0
}
303
304
#endif /* GENERIC_URI_256_C */