Merge from vendor branch LIBARCHIVE:
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / dns / callbacks.c
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and 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: callbacks.c,v 1.12.2.1 2004/03/09 06:11:00 marka Exp $ */
19
20 #include <config.h>
21
22 #include <isc/util.h>
23
24 #include <dns/callbacks.h>
25 #include <dns/log.h>
26
27 static void
28 stdio_error_warn_callback(dns_rdatacallbacks_t *, const char *, ...)
29      ISC_FORMAT_PRINTF(2, 3);
30
31 static void
32 isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...)
33      ISC_FORMAT_PRINTF(2, 3);
34
35 static void
36 isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...)
37      ISC_FORMAT_PRINTF(2, 3);
38
39 /*
40  * Private
41  */
42
43 static void
44 stdio_error_warn_callback(dns_rdatacallbacks_t *callbacks,
45                           const char *fmt, ...)
46 {
47         va_list ap;
48
49         UNUSED(callbacks);
50
51         va_start(ap, fmt);
52         vfprintf(stderr, fmt, ap);
53         va_end(ap);
54         fprintf(stderr, "\n");
55 }
56
57 static void
58 isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) {
59         va_list ap;
60
61         UNUSED(callbacks);
62
63         va_start(ap, fmt);
64         isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL,
65                        DNS_LOGMODULE_MASTER, /* XXX */
66                        ISC_LOG_ERROR, fmt, ap);
67         va_end(ap);
68 }
69
70 static void
71 isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) {
72         va_list ap;
73
74         UNUSED(callbacks);
75
76         va_start(ap, fmt);
77
78         isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL,
79                        DNS_LOGMODULE_MASTER, /* XXX */
80                        ISC_LOG_WARNING, fmt, ap);
81         va_end(ap);
82 }
83
84 static void
85 dns_rdatacallbacks_initcommon(dns_rdatacallbacks_t *callbacks) {
86         REQUIRE(callbacks != NULL);
87
88         callbacks->add = NULL;
89         callbacks->add_private = NULL;
90         callbacks->error_private = NULL;
91         callbacks->warn_private = NULL;
92 }
93
94 /*
95  * Public.
96  */
97
98 void
99 dns_rdatacallbacks_init(dns_rdatacallbacks_t *callbacks) {
100         dns_rdatacallbacks_initcommon(callbacks);
101         callbacks->error = isclog_error_callback;
102         callbacks->warn = isclog_warn_callback;
103 }
104
105 void
106 dns_rdatacallbacks_init_stdio(dns_rdatacallbacks_t *callbacks) {
107         dns_rdatacallbacks_initcommon(callbacks);
108         callbacks->error = stdio_error_warn_callback;
109         callbacks->warn = stdio_error_warn_callback;
110 }
111