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