1/* $NetBSD: callbacks.c,v 1.5 2022/09/23 12:15:29 christos Exp $ */ 2 3/* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16/*! \file */ 17 18#include <isc/print.h> 19#include <isc/util.h> 20 21#include <dns/callbacks.h> 22#include <dns/log.h> 23 24static void 25stdio_error_warn_callback(dns_rdatacallbacks_t *, const char *, ...) 26 ISC_FORMAT_PRINTF(2, 3); 27 28static void 29isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) 30 ISC_FORMAT_PRINTF(2, 3); 31 32static void 33isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) 34 ISC_FORMAT_PRINTF(2, 3); 35 36/* 37 * Private 38 */ 39 40static void 41stdio_error_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, 42 ...) { 43 va_list ap; 44 45 UNUSED(callbacks); 46 47 va_start(ap, fmt); 48 vfprintf(stderr, fmt, ap); 49 va_end(ap); 50 fprintf(stderr, "\n"); 51} 52 53static void 54isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) { 55 va_list ap; 56 57 UNUSED(callbacks); 58 59 va_start(ap, fmt); 60 isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL, 61 DNS_LOGMODULE_MASTER, /* XXX */ 62 ISC_LOG_ERROR, fmt, ap); 63 va_end(ap); 64} 65 66static void 67isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) { 68 va_list ap; 69 70 UNUSED(callbacks); 71 72 va_start(ap, fmt); 73 74 isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL, 75 DNS_LOGMODULE_MASTER, /* XXX */ 76 ISC_LOG_WARNING, fmt, ap); 77 va_end(ap); 78} 79 80static void 81dns_rdatacallbacks_initcommon(dns_rdatacallbacks_t *callbacks) { 82 REQUIRE(callbacks != NULL); 83 84 callbacks->magic = DNS_CALLBACK_MAGIC; 85 callbacks->add = NULL; 86 callbacks->rawdata = NULL; 87 callbacks->zone = NULL; 88 callbacks->add_private = NULL; 89 callbacks->error_private = NULL; 90 callbacks->warn_private = NULL; 91} 92 93/* 94 * Public. 95 */ 96 97void 98dns_rdatacallbacks_init(dns_rdatacallbacks_t *callbacks) { 99 dns_rdatacallbacks_initcommon(callbacks); 100 callbacks->error = isclog_error_callback; 101 callbacks->warn = isclog_warn_callback; 102} 103 104void 105dns_rdatacallbacks_init_stdio(dns_rdatacallbacks_t *callbacks) { 106 dns_rdatacallbacks_initcommon(callbacks); 107 callbacks->error = stdio_error_warn_callback; 108 callbacks->warn = stdio_error_warn_callback; 109} 110