1 /* $NetBSD: callbacks.h,v 1.7 2025/01/26 16:25:26 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 #pragma once 17 18 /*! \file dns/callbacks.h */ 19 20 /*** 21 *** Imports 22 ***/ 23 24 #include <isc/lang.h> 25 #include <isc/magic.h> 26 27 #include <dns/types.h> 28 29 ISC_LANG_BEGINDECLS 30 31 /*** 32 *** Types 33 ***/ 34 35 #define DNS_CALLBACK_MAGIC ISC_MAGIC('C', 'L', 'L', 'B') 36 #define DNS_CALLBACK_VALID(cb) ISC_MAGIC_VALID(cb, DNS_CALLBACK_MAGIC) 37 38 struct dns_rdatacallbacks { 39 unsigned int magic; 40 41 /*% 42 * dns_load_master calls 'add' when it has an rdataset to add 43 * to the database. If defined, it calls 'setup' before and 44 * 'commit' after adding rdatasets. 45 * 46 * Some database implementations will commit each rdataset as 47 * soon as it's added, in which case 'setup' and 'commit' need 48 * not be defined. However, other implementations can be 49 * optimized by grouping rdatasets into a transaction; the 50 * setup and commit functions allow this transaction to be 51 * opened and committed. 52 */ 53 dns_addrdatasetfunc_t add; 54 dns_transactionfunc_t setup; 55 dns_transactionfunc_t commit; 56 57 /*% 58 * dns_master_load*() call this when loading a raw zonefile, 59 * to pass back information obtained from the file header 60 */ 61 dns_rawdatafunc_t rawdata; 62 dns_zone_t *zone; 63 64 /*% 65 * dns_load_master / dns_rdata_fromtext call this to issue a error. 66 */ 67 void (*error)(struct dns_rdatacallbacks *, const char *, ...); 68 /*% 69 * dns_load_master / dns_rdata_fromtext call this to issue a warning. 70 */ 71 void (*warn)(struct dns_rdatacallbacks *, const char *, ...); 72 /*% 73 * Private data handles for use by the above callback functions. 74 */ 75 void *add_private; 76 void *error_private; 77 void *warn_private; 78 }; 79 80 /*** 81 *** Initialization 82 ***/ 83 84 void 85 dns_rdatacallbacks_init(dns_rdatacallbacks_t *callbacks); 86 /*%< 87 * Initialize 'callbacks'. 88 * 89 * \li 'magic' is set to DNS_CALLBACK_MAGIC 90 * 91 * \li 'error' and 'warn' are set to default callbacks that print the 92 * error message through the DNS library log context. 93 * 94 *\li All other elements are initialized to NULL. 95 * 96 * Requires: 97 * \li 'callbacks' is a valid dns_rdatacallbacks_t, 98 */ 99 100 void 101 dns_rdatacallbacks_init_stdio(dns_rdatacallbacks_t *callbacks); 102 /*%< 103 * Like dns_rdatacallbacks_init, but logs to stdio. 104 */ 105 106 ISC_LANG_ENDDECLS 107