Coverage Report

Created: 2026-10-17 06:53

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
14.2k
#define RRTYPE_URI_ATTRIBUTES (0)
18
19
static isc_result_t
20
1.12k
fromtext_uri(ARGS_FROMTEXT) {
21
1.12k
  isc_token_t token;
22
23
1.12k
  REQUIRE(type == dns_rdatatype_uri);
24
25
1.12k
  UNUSED(type);
26
1.12k
  UNUSED(rdclass);
27
1.12k
  UNUSED(origin);
28
1.12k
  UNUSED(options);
29
1.12k
  UNUSED(callbacks);
30
31
  /*
32
   * Priority
33
   */
34
1.12k
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
35
1.12k
              false));
36
1.12k
  if (token.value.as_ulong > 0xffffU) {
37
27
    RETTOK(ISC_R_RANGE);
38
27
  }
39
1.09k
  RETERR(uint16_tobuffer(token.value.as_ulong, target));
40
41
  /*
42
   * Weight
43
   */
44
1.09k
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
45
1.09k
              false));
46
1.05k
  if (token.value.as_ulong > 0xffffU) {
47
13
    RETTOK(ISC_R_RANGE);
48
13
  }
49
1.04k
  RETERR(uint16_tobuffer(token.value.as_ulong, target));
50
51
  /*
52
   * Target URI (non empty).
53
   */
54
1.04k
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
55
1.04k
              false));
56
1.01k
  if (token.type != isc_tokentype_qstring ||
57
1.01k
      token.value.as_textregion.length == 0)
58
9
  {
59
9
    RETTOK(DNS_R_SYNTAX);
60
9
  }
61
1.00k
  RETTOK(multitxt_fromtext(&token.value.as_textregion, target));
62
997
  return ISC_R_SUCCESS;
63
1.00k
}
64
65
static isc_result_t
66
2.15k
totext_uri(ARGS_TOTEXT) {
67
2.15k
  isc_region_t region;
68
2.15k
  unsigned short priority, weight;
69
2.15k
  char buf[sizeof("65000 ")];
70
71
2.15k
  UNUSED(tctx);
72
73
2.15k
  REQUIRE(rdata->type == dns_rdatatype_uri);
74
2.15k
  REQUIRE(rdata->length != 0);
75
76
2.15k
  dns_rdata_toregion(rdata, &region);
77
78
  /*
79
   * Priority
80
   */
81
2.15k
  priority = uint16_fromregion(&region);
82
2.15k
  isc_region_consume(&region, 2);
83
2.15k
  snprintf(buf, sizeof(buf), "%u ", priority);
84
2.15k
  RETERR(str_totext(buf, target));
85
86
  /*
87
   * Weight
88
   */
89
2.15k
  weight = uint16_fromregion(&region);
90
2.15k
  isc_region_consume(&region, 2);
91
2.15k
  snprintf(buf, sizeof(buf), "%u ", weight);
92
2.15k
  RETERR(str_totext(buf, target));
93
94
  /*
95
   * Target URI
96
   */
97
2.15k
  RETERR(multitxt_totext(&region, target));
98
2.15k
  return ISC_R_SUCCESS;
99
2.15k
}
100
101
static isc_result_t
102
3.24k
fromwire_uri(ARGS_FROMWIRE) {
103
3.24k
  isc_region_t region;
104
105
3.24k
  REQUIRE(type == dns_rdatatype_uri);
106
107
3.24k
  UNUSED(type);
108
3.24k
  UNUSED(rdclass);
109
3.24k
  UNUSED(dctx);
110
111
  /*
112
   * Priority, weight and target URI (non empty).
113
   */
114
3.24k
  isc_buffer_activeregion(source, &region);
115
3.24k
  if (region.length < 5) {
116
18
    return ISC_R_UNEXPECTEDEND;
117
18
  }
118
3.22k
  isc_buffer_forward(source, region.length);
119
3.22k
  return mem_tobuffer(target, region.base, region.length);
120
3.24k
}
121
122
static isc_result_t
123
1.09k
towire_uri(ARGS_TOWIRE) {
124
1.09k
  isc_region_t region;
125
126
1.09k
  REQUIRE(rdata->type == dns_rdatatype_uri);
127
1.09k
  REQUIRE(rdata->length != 0);
128
129
1.09k
  UNUSED(cctx);
130
131
1.09k
  dns_rdata_toregion(rdata, &region);
132
1.09k
  return mem_tobuffer(target, region.base, region.length);
133
1.09k
}
134
135
static int
136
5.94k
compare_uri(ARGS_COMPARE) {
137
5.94k
  isc_region_t r1;
138
5.94k
  isc_region_t r2;
139
5.94k
  int order;
140
141
5.94k
  REQUIRE(rdata1->type == rdata2->type);
142
5.94k
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
143
5.94k
  REQUIRE(rdata1->type == dns_rdatatype_uri);
144
5.94k
  REQUIRE(rdata1->length != 0);
145
5.94k
  REQUIRE(rdata2->length != 0);
146
147
5.94k
  dns_rdata_toregion(rdata1, &r1);
148
5.94k
  dns_rdata_toregion(rdata2, &r2);
149
150
  /*
151
   * Priority
152
   */
153
5.94k
  order = memcmp(r1.base, r2.base, 2);
154
5.94k
  if (order != 0) {
155
844
    return order < 0 ? -1 : 1;
156
844
  }
157
5.10k
  isc_region_consume(&r1, 2);
158
5.10k
  isc_region_consume(&r2, 2);
159
160
  /*
161
   * Weight
162
   */
163
5.10k
  order = memcmp(r1.base, r2.base, 2);
164
5.10k
  if (order != 0) {
165
2.24k
    return order < 0 ? -1 : 1;
166
2.24k
  }
167
2.85k
  isc_region_consume(&r1, 2);
168
2.85k
  isc_region_consume(&r2, 2);
169
170
2.85k
  return isc_region_compare(&r1, &r2);
171
5.10k
}
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 = sr.base;
232
0
  return ISC_R_SUCCESS;
233
0
}
234
235
static isc_result_t
236
0
additionaldata_uri(ARGS_ADDLDATA) {
237
0
  REQUIRE(rdata->type == dns_rdatatype_uri);
238
239
0
  UNUSED(rdata);
240
0
  UNUSED(owner);
241
0
  UNUSED(add);
242
0
  UNUSED(arg);
243
244
0
  return ISC_R_SUCCESS;
245
0
}
246
247
static isc_result_t
248
0
digest_uri(ARGS_DIGEST) {
249
0
  isc_region_t r;
250
251
0
  REQUIRE(rdata->type == dns_rdatatype_uri);
252
253
0
  dns_rdata_toregion(rdata, &r);
254
255
0
  return (digest)(arg, &r);
256
0
}
257
258
static bool
259
0
checkowner_uri(ARGS_CHECKOWNER) {
260
0
  REQUIRE(type == dns_rdatatype_uri);
261
262
0
  UNUSED(name);
263
0
  UNUSED(type);
264
0
  UNUSED(rdclass);
265
0
  UNUSED(wildcard);
266
267
0
  return true;
268
0
}
269
270
static bool
271
0
checknames_uri(ARGS_CHECKNAMES) {
272
0
  REQUIRE(rdata->type == dns_rdatatype_uri);
273
274
0
  UNUSED(rdata);
275
0
  UNUSED(owner);
276
0
  UNUSED(bad);
277
278
0
  return true;
279
0
}
280
281
static int
282
0
casecompare_uri(ARGS_COMPARE) {
283
0
  return compare_uri(rdata1, rdata2);
284
0
}
285
286
#endif /* GENERIC_URI_256_C */