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