Coverage Report

Created: 2026-01-24 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/lib/dns/callbacks.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
/*! \file */
15
16
#include <isc/log.h>
17
#include <isc/util.h>
18
19
#include <dns/callbacks.h>
20
21
static void
22
stdio_error_warn_callback(dns_rdatacallbacks_t *, const char *, ...)
23
  ISC_FORMAT_PRINTF(2, 3);
24
25
static void
26
isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...)
27
  ISC_FORMAT_PRINTF(2, 3);
28
29
static void
30
isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...)
31
  ISC_FORMAT_PRINTF(2, 3);
32
33
/*
34
 * Private
35
 */
36
37
static void
38
stdio_error_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt,
39
0
        ...) {
40
0
  va_list ap;
41
42
0
  UNUSED(callbacks);
43
44
0
  va_start(ap, fmt);
45
0
  vfprintf(stderr, fmt, ap);
46
0
  va_end(ap);
47
0
  fprintf(stderr, "\n");
48
0
}
49
50
static void
51
12.6k
isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) {
52
12.6k
  va_list ap;
53
54
12.6k
  UNUSED(callbacks);
55
56
12.6k
  va_start(ap, fmt);
57
12.6k
  isc_log_vwrite(DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER, /* XXX */
58
12.6k
           ISC_LOG_ERROR, fmt, ap);
59
12.6k
  va_end(ap);
60
12.6k
}
61
62
static void
63
13.4k
isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) {
64
13.4k
  va_list ap;
65
66
13.4k
  UNUSED(callbacks);
67
68
13.4k
  va_start(ap, fmt);
69
70
13.4k
  isc_log_vwrite(DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER, /* XXX */
71
13.4k
           ISC_LOG_WARNING, fmt, ap);
72
13.4k
  va_end(ap);
73
13.4k
}
74
75
static void
76
23.1k
dns_rdatacallbacks_initcommon(dns_rdatacallbacks_t *callbacks) {
77
23.1k
  REQUIRE(callbacks != NULL);
78
79
23.1k
  *callbacks = (dns_rdatacallbacks_t){
80
23.1k
    .magic = DNS_CALLBACK_MAGIC,
81
23.1k
  };
82
23.1k
}
83
84
/*
85
 * Public.
86
 */
87
88
void
89
23.1k
dns_rdatacallbacks_init(dns_rdatacallbacks_t *callbacks) {
90
23.1k
  dns_rdatacallbacks_initcommon(callbacks);
91
23.1k
  callbacks->error = isclog_error_callback;
92
23.1k
  callbacks->warn = isclog_warn_callback;
93
23.1k
}
94
95
void
96
0
dns_rdatacallbacks_init_stdio(dns_rdatacallbacks_t *callbacks) {
97
0
  dns_rdatacallbacks_initcommon(callbacks);
98
0
  callbacks->error = stdio_error_warn_callback;
99
0
  callbacks->warn = stdio_error_warn_callback;
100
0
}