callbacks.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2011, 2012  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1999-2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: callbacks.c,v 1.19.40.1 2012/02/07 00:44:13 each Exp $ */
00019 
00020 /*! \file */
00021 
00022 #include <config.h>
00023 
00024 #include <isc/util.h>
00025 
00026 #include <dns/callbacks.h>
00027 #include <dns/log.h>
00028 
00029 static void
00030 stdio_error_warn_callback(dns_rdatacallbacks_t *, const char *, ...)
00031      ISC_FORMAT_PRINTF(2, 3);
00032 
00033 static void
00034 isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...)
00035      ISC_FORMAT_PRINTF(2, 3);
00036 
00037 static void
00038 isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...)
00039      ISC_FORMAT_PRINTF(2, 3);
00040 
00041 /*
00042  * Private
00043  */
00044 
00045 static void
00046 stdio_error_warn_callback(dns_rdatacallbacks_t *callbacks,
00047                           const char *fmt, ...)
00048 {
00049         va_list ap;
00050 
00051         UNUSED(callbacks);
00052 
00053         va_start(ap, fmt);
00054         vfprintf(stderr, fmt, ap);
00055         va_end(ap);
00056         fprintf(stderr, "\n");
00057 }
00058 
00059 static void
00060 isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) {
00061         va_list ap;
00062 
00063         UNUSED(callbacks);
00064 
00065         va_start(ap, fmt);
00066         isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL,
00067                        DNS_LOGMODULE_MASTER, /* XXX */
00068                        ISC_LOG_ERROR, fmt, ap);
00069         va_end(ap);
00070 }
00071 
00072 static void
00073 isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) {
00074         va_list ap;
00075 
00076         UNUSED(callbacks);
00077 
00078         va_start(ap, fmt);
00079 
00080         isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL,
00081                        DNS_LOGMODULE_MASTER, /* XXX */
00082                        ISC_LOG_WARNING, fmt, ap);
00083         va_end(ap);
00084 }
00085 
00086 static void
00087 dns_rdatacallbacks_initcommon(dns_rdatacallbacks_t *callbacks) {
00088         REQUIRE(callbacks != NULL);
00089 
00090         callbacks->magic = DNS_CALLBACK_MAGIC;
00091         callbacks->add = NULL;
00092         callbacks->rawdata = NULL;
00093         callbacks->zone = NULL;
00094         callbacks->add_private = NULL;
00095         callbacks->error_private = NULL;
00096         callbacks->warn_private = NULL;
00097 }
00098 
00099 /*
00100  * Public.
00101  */
00102 
00103 void
00104 dns_rdatacallbacks_init(dns_rdatacallbacks_t *callbacks) {
00105         dns_rdatacallbacks_initcommon(callbacks);
00106         callbacks->error = isclog_error_callback;
00107         callbacks->warn = isclog_warn_callback;
00108 }
00109 
00110 void
00111 dns_rdatacallbacks_init_stdio(dns_rdatacallbacks_t *callbacks) {
00112         dns_rdatacallbacks_initcommon(callbacks);
00113         callbacks->error = stdio_error_warn_callback;
00114         callbacks->warn = stdio_error_warn_callback;
00115 }
00116 

Generated on Tue Apr 28 17:40:56 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha