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 #ifndef DNS_CALLBACKS_H
13 #define DNS_CALLBACKS_H 1
14 
15 /*! \file dns/callbacks.h */
16 
17 /***
18  ***	Imports
19  ***/
20 
21 #include <isc/lang.h>
22 #include <isc/magic.h>
23 
24 #include <dns/types.h>
25 
26 ISC_LANG_BEGINDECLS
27 
28 /***
29  ***	Types
30  ***/
31 
32 #define DNS_CALLBACK_MAGIC     ISC_MAGIC('C', 'L', 'L', 'B')
33 #define DNS_CALLBACK_VALID(cb) ISC_MAGIC_VALID(cb, DNS_CALLBACK_MAGIC)
34 
35 struct dns_rdatacallbacks {
36 	unsigned int magic;
37 
38 	/*%
39 	 * dns_load_master calls this when it has rdatasets to commit.
40 	 */
41 	dns_addrdatasetfunc_t add;
42 
43 	/*%
44 	 * This is called when reading in a database image from a 'map'
45 	 * format zone file.
46 	 */
47 	dns_deserializefunc_t deserialize;
48 
49 	/*%
50 	 * dns_master_load*() call this when loading a raw zonefile,
51 	 * to pass back information obtained from the file header
52 	 */
53 	dns_rawdatafunc_t rawdata;
54 	dns_zone_t *	  zone;
55 
56 	/*%
57 	 * dns_load_master / dns_rdata_fromtext call this to issue a error.
58 	 */
59 	void (*error)(struct dns_rdatacallbacks *, const char *, ...);
60 	/*%
61 	 * dns_load_master / dns_rdata_fromtext call this to issue a warning.
62 	 */
63 	void (*warn)(struct dns_rdatacallbacks *, const char *, ...);
64 	/*%
65 	 * Private data handles for use by the above callback functions.
66 	 */
67 	void *add_private;
68 	void *deserialize_private;
69 	void *error_private;
70 	void *warn_private;
71 };
72 
73 /***
74  ***	Initialization
75  ***/
76 
77 void
78 dns_rdatacallbacks_init(dns_rdatacallbacks_t *callbacks);
79 /*%<
80  * Initialize 'callbacks'.
81  *
82  * \li	'magic' is set to DNS_CALLBACK_MAGIC
83  *
84  * \li	'error' and 'warn' are set to default callbacks that print the
85  *	error message through the DNS library log context.
86  *
87  *\li	All other elements are initialized to NULL.
88  *
89  * Requires:
90  *  \li    'callbacks' is a valid dns_rdatacallbacks_t,
91  */
92 
93 void
94 dns_rdatacallbacks_init_stdio(dns_rdatacallbacks_t *callbacks);
95 /*%<
96  * Like dns_rdatacallbacks_init, but logs to stdio.
97  */
98 
99 ISC_LANG_ENDDECLS
100 
101 #endif /* DNS_CALLBACKS_H */
102