Coverage Report

Created: 2026-06-07 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/samba/third_party/ngtcp2/lib/ngtcp2_callbacks.c
Line
Count
Source
1
/*
2
 * ngtcp2
3
 *
4
 * Copyright (c) 2025 ngtcp2 contributors
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining
7
 * a copy of this software and associated documentation files (the
8
 * "Software"), to deal in the Software without restriction, including
9
 * without limitation the rights to use, copy, modify, merge, publish,
10
 * distribute, sublicense, and/or sell copies of the Software, and to
11
 * permit persons to whom the Software is furnished to do so, subject to
12
 * the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be
15
 * included in all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 */
25
#include "ngtcp2_callbacks.h"
26
27
#include <string.h>
28
#include <assert.h>
29
30
#include "ngtcp2_unreachable.h"
31
32
static void callbacks_copy(ngtcp2_callbacks *dest, const ngtcp2_callbacks *src,
33
0
                           int callbacks_version) {
34
0
  assert(callbacks_version != NGTCP2_CALLBACKS_VERSION);
35
36
0
  memcpy(dest, src, ngtcp2_callbackslen_version(callbacks_version));
37
0
}
38
39
const ngtcp2_callbacks *ngtcp2_callbacks_convert_to_latest(
40
0
  ngtcp2_callbacks *dest, int callbacks_version, const ngtcp2_callbacks *src) {
41
0
  if (callbacks_version == NGTCP2_CALLBACKS_VERSION) {
42
0
    return src;
43
0
  }
44
45
0
  *dest = (ngtcp2_callbacks){0};
46
47
0
  callbacks_copy(dest, src, callbacks_version);
48
49
0
  return dest;
50
0
}
51
52
void ngtcp2_callbacks_convert_to_old(int callbacks_version,
53
                                     ngtcp2_callbacks *dest,
54
0
                                     const ngtcp2_callbacks *src) {
55
0
  assert(callbacks_version != NGTCP2_CALLBACKS_VERSION);
56
57
0
  callbacks_copy(dest, src, callbacks_version);
58
0
}
59
60
0
size_t ngtcp2_callbackslen_version(int callbacks_version) {
61
0
  ngtcp2_callbacks callbacks;
62
63
0
  switch (callbacks_version) {
64
0
  case NGTCP2_CALLBACKS_VERSION:
65
0
    return sizeof(callbacks);
66
0
  case NGTCP2_CALLBACKS_V2:
67
0
    return offsetof(ngtcp2_callbacks, begin_path_validation) +
68
0
           sizeof(callbacks.begin_path_validation);
69
0
  case NGTCP2_CALLBACKS_V1:
70
0
    return offsetof(ngtcp2_callbacks, tls_early_data_rejected) +
71
0
           sizeof(callbacks.tls_early_data_rejected);
72
0
  default:
73
0
    ngtcp2_unreachable();
74
0
  }
75
0
}