"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/dns/callbacks.c" (4 Sep 2020, 2404 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "callbacks.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 /*! \file */
   13 
   14 #include <isc/print.h>
   15 #include <isc/util.h>
   16 
   17 #include <dns/callbacks.h>
   18 #include <dns/log.h>
   19 
   20 static void
   21 stdio_error_warn_callback(dns_rdatacallbacks_t *, const char *, ...)
   22     ISC_FORMAT_PRINTF(2, 3);
   23 
   24 static void
   25 isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...)
   26     ISC_FORMAT_PRINTF(2, 3);
   27 
   28 static void
   29 isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...)
   30     ISC_FORMAT_PRINTF(2, 3);
   31 
   32 /*
   33  * Private
   34  */
   35 
   36 static void
   37 stdio_error_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt,
   38               ...) {
   39     va_list ap;
   40 
   41     UNUSED(callbacks);
   42 
   43     va_start(ap, fmt);
   44     vfprintf(stderr, fmt, ap);
   45     va_end(ap);
   46     fprintf(stderr, "\n");
   47 }
   48 
   49 static void
   50 isclog_error_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) {
   51     va_list ap;
   52 
   53     UNUSED(callbacks);
   54 
   55     va_start(ap, fmt);
   56     isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL,
   57                DNS_LOGMODULE_MASTER, /* XXX */
   58                ISC_LOG_ERROR, fmt, ap);
   59     va_end(ap);
   60 }
   61 
   62 static void
   63 isclog_warn_callback(dns_rdatacallbacks_t *callbacks, const char *fmt, ...) {
   64     va_list ap;
   65 
   66     UNUSED(callbacks);
   67 
   68     va_start(ap, fmt);
   69 
   70     isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL,
   71                DNS_LOGMODULE_MASTER, /* XXX */
   72                ISC_LOG_WARNING, fmt, ap);
   73     va_end(ap);
   74 }
   75 
   76 static void
   77 dns_rdatacallbacks_initcommon(dns_rdatacallbacks_t *callbacks) {
   78     REQUIRE(callbacks != NULL);
   79 
   80     callbacks->magic = DNS_CALLBACK_MAGIC;
   81     callbacks->add = NULL;
   82     callbacks->rawdata = NULL;
   83     callbacks->zone = NULL;
   84     callbacks->add_private = NULL;
   85     callbacks->error_private = NULL;
   86     callbacks->warn_private = NULL;
   87 }
   88 
   89 /*
   90  * Public.
   91  */
   92 
   93 void
   94 dns_rdatacallbacks_init(dns_rdatacallbacks_t *callbacks) {
   95     dns_rdatacallbacks_initcommon(callbacks);
   96     callbacks->error = isclog_error_callback;
   97     callbacks->warn = isclog_warn_callback;
   98 }
   99 
  100 void
  101 dns_rdatacallbacks_init_stdio(dns_rdatacallbacks_t *callbacks) {
  102     dns_rdatacallbacks_initcommon(callbacks);
  103     callbacks->error = stdio_error_warn_callback;
  104     callbacks->warn = stdio_error_warn_callback;
  105 }