Merge from vendor branch LIBARCHIVE:
[dragonfly.git] / contrib / bind-9.3 / lib / dns / include / dns / masterdump.h
1 /*
2  * Copyright (C) 2004, 2005  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2002  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: masterdump.h,v 1.22.12.10 2005/09/06 02:12:41 marka Exp $ */
19
20 #ifndef DNS_MASTERDUMP_H
21 #define DNS_MASTERDUMP_H 1
22
23 /***
24  ***    Imports
25  ***/
26
27 #include <stdio.h>
28
29 #include <isc/lang.h>
30
31 #include <dns/types.h>
32
33 /***
34  *** Types
35  ***/
36
37 typedef struct dns_master_style dns_master_style_t;
38
39 /***
40  *** Definitions
41  ***/
42
43 /*
44  * Flags affecting master file formatting.  Flags 0x0000FFFF
45  * define the formatting of the rdata part and are defined in
46  * rdata.h.
47  */
48
49 /* Omit the owner name when possible. */
50 #define DNS_STYLEFLAG_OMIT_OWNER        0x00010000U
51
52 /*
53  * Omit the TTL when possible.  If DNS_STYLEFLAG_TTL is
54  * also set, this means no TTLs are ever printed
55  * because $TTL directives are generated before every
56  * change in the TTL.  In this case, no columns need to
57  * be reserved for the TTL.  Master files generated with
58  * these options will be rejected by BIND 4.x because it
59  * does not recognize the $TTL directive.
60  *
61  * If DNS_STYLEFLAG_TTL is not also set, the TTL will be
62  * omitted when it is equal to the previous TTL.
63  * This is correct according to RFC1035, but the
64  * TTLs may be silently misinterpreted by older
65  * versions of BIND which use the SOA MINTTL as a
66  * default TTL value.
67  */
68 #define DNS_STYLEFLAG_OMIT_TTL          0x00020000U
69
70 /* Omit the class when possible. */
71 #define DNS_STYLEFLAG_OMIT_CLASS        0x00040000U
72
73 /* Output $TTL directives. */
74 #define DNS_STYLEFLAG_TTL               0x00080000U
75
76 /*
77  * Output $ORIGIN directives and print owner names relative to
78  * the origin when possible.
79  */
80 #define DNS_STYLEFLAG_REL_OWNER         0x00100000U
81
82 /* Print domain names in RR data in relative form when possible.
83    For this to take effect, DNS_STYLEFLAG_REL_OWNER must also be set. */
84 #define DNS_STYLEFLAG_REL_DATA          0x00200000U
85
86 /* Print the trust level of each rdataset. */
87 #define DNS_STYLEFLAG_TRUST             0x00400000U
88
89 /* Print negative caching entries. */
90 #define DNS_STYLEFLAG_NCACHE            0x00800000U
91
92 /* Never print the TTL */
93 #define DNS_STYLEFLAG_NO_TTL            0x01000000U
94                     
95 /* Never print the CLASS */
96 #define DNS_STYLEFLAG_NO_CLASS          0x02000000U 
97
98 ISC_LANG_BEGINDECLS
99
100 /***
101  ***    Constants
102  ***/
103
104 /*
105  * The default master file style.
106  *
107  * This uses $TTL directives to avoid the need to dedicate a
108  * tab stop for the TTL.  The class is only printed for the first
109  * rrset in the file and shares a tab stop with the RR type.
110  */
111 LIBDNS_EXTERNAL_DATA extern const dns_master_style_t dns_master_style_default;
112
113 /*
114  * A master file style that dumps zones to a very generic format easily
115  * imported/checked with external tools.
116  */
117 LIBDNS_EXTERNAL_DATA extern const dns_master_style_t dns_master_style_full;
118
119 /*
120  * A master file style that prints explicit TTL values on each 
121  * record line, never using $TTL statements.  The TTL has a tab 
122  * stop of its own, but the class and type share one.
123  */
124 LIBDNS_EXTERNAL_DATA extern const dns_master_style_t
125                                         dns_master_style_explicitttl;
126
127 /*
128  * A master style format designed for cache files.  It prints explicit TTL
129  * values on each record line and never uses $ORIGIN or relative names.
130  */
131 LIBDNS_EXTERNAL_DATA extern const dns_master_style_t dns_master_style_cache;
132
133 /*
134  * A master style that prints name, ttl, class, type, and value on 
135  * every line.  Similar to explicitttl above, but more verbose.  
136  * Intended for generating master files which can be easily parsed 
137  * by perl scripts and similar applications.
138  */
139 LIBDNS_EXTERNAL_DATA extern const dns_master_style_t dns_master_style_simple;
140
141 /*
142  * The style used for debugging, "dig" output, etc.
143  */
144 LIBDNS_EXTERNAL_DATA extern const dns_master_style_t dns_master_style_debug;
145
146 /***
147  ***    Functions
148  ***/
149
150 void
151 dns_dumpctx_attach(dns_dumpctx_t *source, dns_dumpctx_t **target);
152 /*
153  * Attach to a dump context.
154  *
155  * Require:
156  *      'source' to be valid.
157  *      'target' to be non NULL and '*target' to be NULL.
158  */
159
160 void
161 dns_dumpctx_detach(dns_dumpctx_t **dctxp);
162 /*
163  * Detach from a dump context.
164  *
165  * Require:
166  *      'dctxp' to point to a valid dump context.
167  *
168  * Ensures:
169  *      '*dctxp' is NULL.
170  */
171
172 void
173 dns_dumpctx_cancel(dns_dumpctx_t *dctx);
174 /*
175  * Cancel a in progress dump.
176  *
177  * Require:
178  *      'dctx' to be valid.
179  */
180
181 dns_dbversion_t *
182 dns_dumpctx_version(dns_dumpctx_t *dctx);
183 /*
184  * Return the version handle (if any) of the database being dumped.
185  *
186  * Require:
187  *      'dctx' to be valid.
188  */
189
190 dns_db_t *
191 dns_dumpctx_db(dns_dumpctx_t *dctx);
192 /*
193  * Return the database being dumped.
194  *
195  * Require:
196  *      'dctx' to be valid.
197  */
198
199
200 isc_result_t
201 dns_master_dumptostreaminc(isc_mem_t *mctx, dns_db_t *db,
202                            dns_dbversion_t *version,
203                            const dns_master_style_t *style, FILE *f,
204                            isc_task_t *task, dns_dumpdonefunc_t done,
205                            void *done_arg, dns_dumpctx_t **dctxp);
206
207 isc_result_t
208 dns_master_dumptostream(isc_mem_t *mctx, dns_db_t *db,
209                         dns_dbversion_t *version,
210                         const dns_master_style_t *style, FILE *f);
211 /*
212  * Dump the database 'db' to the steam 'f' in RFC1035 master
213  * file format, in the style defined by 'style'
214  * (e.g., &dns_default_master_style_default)
215  *
216  * Temporary dynamic memory may be allocated from 'mctx'.
217  *
218  * Require:
219  *      'task' to be valid.
220  *      'done' to be non NULL.
221  *      'dctxp' to be non NULL && '*dctxp' to be NULL.
222  * 
223  * Returns:
224  *      ISC_R_SUCCESS
225  *      DNS_R_CONTINUE  dns_master_dumptostreaminc() only.
226  *      ISC_R_NOMEMORY
227  *      Any database or rrset iterator error.
228  *      Any dns_rdata_totext() error code.
229  */
230
231 isc_result_t
232 dns_master_dumpinc(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
233                    const dns_master_style_t *style, const char *filename,
234                    isc_task_t *task, dns_dumpdonefunc_t done, void *done_arg,
235                    dns_dumpctx_t **dctxp);
236
237 isc_result_t
238 dns_master_dump(isc_mem_t *mctx, dns_db_t *db,
239                 dns_dbversion_t *version,
240                 const dns_master_style_t *style, const char *filename);
241 /*
242  * Dump the database 'db' to the file 'filename' in RFC1035 master
243  * file format, in the style defined by 'style'
244  * (e.g., &dns_default_master_style_default)
245  *
246  * Temporary dynamic memory may be allocated from 'mctx'.
247  *
248  * Returns:
249  *      ISC_R_SUCCESS
250  *      DNS_R_CONTINUE  dns_master_dumpinc() only.
251  *      ISC_R_NOMEMORY
252  *      Any database or rrset iterator error.
253  *      Any dns_rdata_totext() error code.
254  */
255
256 isc_result_t
257 dns_master_rdatasettotext(dns_name_t *owner_name,
258                           dns_rdataset_t *rdataset,
259                           const dns_master_style_t *style,
260                           isc_buffer_t *target);
261 /*
262  * Convert 'rdataset' to text format, storing the result in 'target'.
263  *
264  * Notes:
265  *      The rdata cursor position will be changed.
266  *
267  * Requires:
268  *      'rdataset' is a valid non-question rdataset.
269  *
270  *      'rdataset' is not empty.
271  */
272
273 isc_result_t
274 dns_master_questiontotext(dns_name_t *owner_name,
275                           dns_rdataset_t *rdataset,
276                           const dns_master_style_t *style,
277                           isc_buffer_t *target);
278
279 isc_result_t
280 dns_master_dumpnodetostream(isc_mem_t *mctx, dns_db_t *db,
281                             dns_dbversion_t *version,
282                             dns_dbnode_t *node, dns_name_t *name,
283                             const dns_master_style_t *style,
284                             FILE *f);
285
286 isc_result_t
287 dns_master_dumpnode(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
288                     dns_dbnode_t *node, dns_name_t *name,
289                     const dns_master_style_t *style, const char *filename);
290
291 isc_result_t
292 dns_master_stylecreate(dns_master_style_t **style, unsigned int flags,
293                        unsigned int ttl_column, unsigned int class_column,
294                        unsigned int type_column, unsigned int rdata_column,
295                        unsigned int line_length, unsigned int tab_width,
296                        isc_mem_t *mctx);
297
298 void
299 dns_master_styledestroy(dns_master_style_t **style, isc_mem_t *mctx);
300
301 ISC_LANG_ENDDECLS
302
303 #endif /* DNS_MASTERDUMP_H */