/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 | 13.1k | isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) { |
52 | 13.1k | va_list ap; |
53 | | |
54 | 13.1k | UNUSED(callbacks); |
55 | | |
56 | 13.1k | va_start(ap, fmt); |
57 | 13.1k | isc_log_vwrite(DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER, /* XXX */ |
58 | 13.1k | ISC_LOG_ERROR, fmt, ap); |
59 | 13.1k | va_end(ap); |
60 | 13.1k | } |
61 | | |
62 | | static void |
63 | 14.5k | isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) { |
64 | 14.5k | va_list ap; |
65 | | |
66 | 14.5k | UNUSED(callbacks); |
67 | | |
68 | 14.5k | va_start(ap, fmt); |
69 | | |
70 | 14.5k | isc_log_vwrite(DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER, /* XXX */ |
71 | 14.5k | ISC_LOG_WARNING, fmt, ap); |
72 | 14.5k | va_end(ap); |
73 | 14.5k | } |
74 | | |
75 | | static void |
76 | 24.5k | dns_rdatacallbacks_initcommon(dns_rdatacallbacks_t *callbacks) { |
77 | 24.5k | REQUIRE(callbacks != NULL); |
78 | | |
79 | 24.5k | *callbacks = (dns_rdatacallbacks_t){ |
80 | 24.5k | .magic = DNS_CALLBACK_MAGIC, |
81 | 24.5k | }; |
82 | 24.5k | } |
83 | | |
84 | | /* |
85 | | * Public. |
86 | | */ |
87 | | |
88 | | void |
89 | 24.5k | dns_rdatacallbacks_init(dns_rdatacallbacks_t *callbacks) { |
90 | 24.5k | dns_rdatacallbacks_initcommon(callbacks); |
91 | 24.5k | callbacks->error = isclog_error_callback; |
92 | 24.5k | callbacks->warn = isclog_warn_callback; |
93 | 24.5k | } |
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 | } |