PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/bind9/lib/dns/callbacks.c

https://bitbucket.org/freebsd/freebsd-head/
C | 113 lines | 64 code | 25 blank | 24 comment | 1 complexity | 904cc36d81155add832d5d9313d1e4f9 MD5 | raw file
  1/*
  2 * Copyright (C) 2004, 2005, 2007, 2012  Internet Systems Consortium, Inc. ("ISC")
  3 * Copyright (C) 1999-2001  Internet Software Consortium.
  4 *
  5 * Permission to use, copy, modify, and/or distribute this software for any
  6 * purpose with or without fee is hereby granted, provided that the above
  7 * copyright notice and this permission notice appear in all copies.
  8 *
  9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
 10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 11 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 15 * PERFORMANCE OF THIS SOFTWARE.
 16 */
 17
 18/* $Id$ */
 19
 20/*! \file */
 21
 22#include <config.h>
 23
 24#include <isc/util.h>
 25
 26#include <dns/callbacks.h>
 27#include <dns/log.h>
 28
 29static void
 30stdio_error_warn_callback(dns_rdatacallbacks_t *, const char *, ...)
 31     ISC_FORMAT_PRINTF(2, 3);
 32
 33static void
 34isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...)
 35     ISC_FORMAT_PRINTF(2, 3);
 36
 37static void
 38isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...)
 39     ISC_FORMAT_PRINTF(2, 3);
 40
 41/*
 42 * Private
 43 */
 44
 45static void
 46stdio_error_warn_callback(dns_rdatacallbacks_t *callbacks,
 47			  const char *fmt, ...)
 48{
 49	va_list ap;
 50
 51	UNUSED(callbacks);
 52
 53	va_start(ap, fmt);
 54	vfprintf(stderr, fmt, ap);
 55	va_end(ap);
 56	fprintf(stderr, "\n");
 57}
 58
 59static void
 60isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) {
 61	va_list ap;
 62
 63	UNUSED(callbacks);
 64
 65	va_start(ap, fmt);
 66	isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL,
 67		       DNS_LOGMODULE_MASTER, /* XXX */
 68		       ISC_LOG_ERROR, fmt, ap);
 69	va_end(ap);
 70}
 71
 72static void
 73isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) {
 74	va_list ap;
 75
 76	UNUSED(callbacks);
 77
 78	va_start(ap, fmt);
 79
 80	isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL,
 81		       DNS_LOGMODULE_MASTER, /* XXX */
 82		       ISC_LOG_WARNING, fmt, ap);
 83	va_end(ap);
 84}
 85
 86static void
 87dns_rdatacallbacks_initcommon(dns_rdatacallbacks_t *callbacks) {
 88	REQUIRE(callbacks != NULL);
 89
 90	callbacks->add = NULL;
 91	callbacks->add_private = NULL;
 92	callbacks->error_private = NULL;
 93	callbacks->warn_private = NULL;
 94}
 95
 96/*
 97 * Public.
 98 */
 99
100void
101dns_rdatacallbacks_init(dns_rdatacallbacks_t *callbacks) {
102	dns_rdatacallbacks_initcommon(callbacks);
103	callbacks->error = isclog_error_callback;
104	callbacks->warn = isclog_warn_callback;
105}
106
107void
108dns_rdatacallbacks_init_stdio(dns_rdatacallbacks_t *callbacks) {
109	dns_rdatacallbacks_initcommon(callbacks);
110	callbacks->error = stdio_error_warn_callback;
111	callbacks->warn = stdio_error_warn_callback;
112}
113