1135446Strhodes/*
2254897Serwin * Copyright (C) 2004, 2005, 2007, 2011  Internet Systems Consortium, Inc. ("ISC")
3135446Strhodes * Copyright (C) 1999-2001  Internet Software Consortium.
4135446Strhodes *
5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any
6135446Strhodes * purpose with or without fee is hereby granted, provided that the above
7135446Strhodes * copyright notice and this permission notice appear in all copies.
8135446Strhodes *
9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11135446Strhodes * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15135446Strhodes * PERFORMANCE OF THIS SOFTWARE.
16135446Strhodes */
17135446Strhodes
18254897Serwin/* $Id: callbacks.c,v 1.19 2011/12/09 23:47:05 tbox Exp $ */
19135446Strhodes
20170222Sdougb/*! \file */
21170222Sdougb
22135446Strhodes#include <config.h>
23135446Strhodes
24135446Strhodes#include <isc/util.h>
25135446Strhodes
26135446Strhodes#include <dns/callbacks.h>
27135446Strhodes#include <dns/log.h>
28135446Strhodes
29135446Strhodesstatic void
30135446Strhodesstdio_error_warn_callback(dns_rdatacallbacks_t *, const char *, ...)
31135446Strhodes     ISC_FORMAT_PRINTF(2, 3);
32135446Strhodes
33135446Strhodesstatic void
34135446Strhodesisclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...)
35135446Strhodes     ISC_FORMAT_PRINTF(2, 3);
36135446Strhodes
37135446Strhodesstatic void
38135446Strhodesisclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...)
39135446Strhodes     ISC_FORMAT_PRINTF(2, 3);
40135446Strhodes
41135446Strhodes/*
42135446Strhodes * Private
43135446Strhodes */
44135446Strhodes
45135446Strhodesstatic void
46135446Strhodesstdio_error_warn_callback(dns_rdatacallbacks_t *callbacks,
47135446Strhodes			  const char *fmt, ...)
48135446Strhodes{
49135446Strhodes	va_list ap;
50135446Strhodes
51135446Strhodes	UNUSED(callbacks);
52135446Strhodes
53135446Strhodes	va_start(ap, fmt);
54135446Strhodes	vfprintf(stderr, fmt, ap);
55135446Strhodes	va_end(ap);
56135446Strhodes	fprintf(stderr, "\n");
57135446Strhodes}
58135446Strhodes
59135446Strhodesstatic void
60135446Strhodesisclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) {
61135446Strhodes	va_list ap;
62135446Strhodes
63135446Strhodes	UNUSED(callbacks);
64135446Strhodes
65135446Strhodes	va_start(ap, fmt);
66135446Strhodes	isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL,
67135446Strhodes		       DNS_LOGMODULE_MASTER, /* XXX */
68135446Strhodes		       ISC_LOG_ERROR, fmt, ap);
69135446Strhodes	va_end(ap);
70135446Strhodes}
71135446Strhodes
72135446Strhodesstatic void
73135446Strhodesisclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) {
74135446Strhodes	va_list ap;
75135446Strhodes
76135446Strhodes	UNUSED(callbacks);
77135446Strhodes
78135446Strhodes	va_start(ap, fmt);
79135446Strhodes
80135446Strhodes	isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL,
81135446Strhodes		       DNS_LOGMODULE_MASTER, /* XXX */
82135446Strhodes		       ISC_LOG_WARNING, fmt, ap);
83135446Strhodes	va_end(ap);
84135446Strhodes}
85135446Strhodes
86135446Strhodesstatic void
87135446Strhodesdns_rdatacallbacks_initcommon(dns_rdatacallbacks_t *callbacks) {
88135446Strhodes	REQUIRE(callbacks != NULL);
89135446Strhodes
90135446Strhodes	callbacks->add = NULL;
91254897Serwin	callbacks->rawdata = NULL;
92254897Serwin	callbacks->zone = NULL;
93135446Strhodes	callbacks->add_private = NULL;
94135446Strhodes	callbacks->error_private = NULL;
95135446Strhodes	callbacks->warn_private = NULL;
96135446Strhodes}
97135446Strhodes
98135446Strhodes/*
99135446Strhodes * Public.
100135446Strhodes */
101135446Strhodes
102135446Strhodesvoid
103135446Strhodesdns_rdatacallbacks_init(dns_rdatacallbacks_t *callbacks) {
104135446Strhodes	dns_rdatacallbacks_initcommon(callbacks);
105135446Strhodes	callbacks->error = isclog_error_callback;
106135446Strhodes	callbacks->warn = isclog_warn_callback;
107135446Strhodes}
108135446Strhodes
109135446Strhodesvoid
110135446Strhodesdns_rdatacallbacks_init_stdio(dns_rdatacallbacks_t *callbacks) {
111135446Strhodes	dns_rdatacallbacks_initcommon(callbacks);
112135446Strhodes	callbacks->error = stdio_error_warn_callback;
113135446Strhodes	callbacks->warn = stdio_error_warn_callback;
114135446Strhodes}
115135446Strhodes
116