From 19f4d25fd5b35b1375b0b9f13b66770ee4a66154 Mon Sep 17 00:00:00 2001 From: Brian Wellington Date: Thu, 3 Aug 2000 19:50:12 +0000 Subject: [PATCH] Add dns_master_dumpnode, dns_master_dumpnodetostream, and dns_master_style_explicitttl. --- lib/dns/include/dns/masterdump.h | 15 ++++- lib/dns/masterdump.c | 96 +++++++++++++++++++++++++++++++- 2 files changed, 109 insertions(+), 2 deletions(-) diff --git a/lib/dns/include/dns/masterdump.h b/lib/dns/include/dns/masterdump.h index 5fb740a197..485ea486b1 100644 --- a/lib/dns/include/dns/masterdump.h +++ b/lib/dns/include/dns/masterdump.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: masterdump.h,v 1.12 2000/08/01 01:24:20 tale Exp $ */ +/* $Id: masterdump.h,v 1.13 2000/08/03 19:50:11 bwelling Exp $ */ #ifndef DNS_MASTERDUMP_H #define DNS_MASTERDUMP_H 1 @@ -53,6 +53,7 @@ ISC_LANG_BEGINDECLS * The default masterfile style. */ extern const dns_master_style_t dns_master_style_default; +extern const dns_master_style_t dns_master_style_explicitttl; /*** @@ -95,6 +96,18 @@ dns_master_dump(isc_mem_t *mctx, dns_db_t *db, * Any dns_rdata_totext() error code. */ +isc_result_t +dns_master_dumpnodetostream(isc_mem_t *mctx, dns_db_t *db, + dns_dbversion_t *version, + dns_dbnode_t *node, dns_name_t *name, + const dns_master_style_t *style, + FILE *f); + +isc_result_t +dns_master_dumpnode(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version, + dns_dbnode_t *node, dns_name_t *name, + const dns_master_style_t *style, const char *filename); + ISC_LANG_ENDDECLS #endif /* DNS_MASTERDUMP_H */ diff --git a/lib/dns/masterdump.c b/lib/dns/masterdump.c index 0cb3fae5de..378ad8bbd4 100644 --- a/lib/dns/masterdump.c +++ b/lib/dns/masterdump.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: masterdump.c,v 1.29 2000/08/01 01:22:31 tale Exp $ */ +/* $Id: masterdump.c,v 1.30 2000/08/03 19:50:12 bwelling Exp $ */ #include @@ -136,6 +136,21 @@ dns_master_style_default = { DNS_STYLEFLAG_TTL | DNS_STYLEFLAG_COMMENT | DNS_STYLEFLAG_MULTILINE, + 24, 32, 32, 40, 80, 8 +}; + +/* + * A master file style that prints TTL values on each record line, + * never using $TTL statements. + */ +const dns_master_style_t +dns_master_style_explicitttl = { + DNS_STYLEFLAG_OMIT_OWNER | + DNS_STYLEFLAG_OMIT_CLASS | + DNS_STYLEFLAG_REL_OWNER | + DNS_STYLEFLAG_REL_DATA | + DNS_STYLEFLAG_COMMENT | + DNS_STYLEFLAG_MULTILINE, 24, 24, 24, 32, 80, 8 }; @@ -812,3 +827,82 @@ dns_master_dump(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version, return (result); } + +/* + * Dump a database node into a master file. + */ +isc_result_t +dns_master_dumpnodetostream(isc_mem_t *mctx, dns_db_t *db, + dns_dbversion_t *version, + dns_dbnode_t *node, dns_name_t *name, + const dns_master_style_t *style, + FILE *f) +{ + isc_result_t result; + isc_buffer_t buffer; + char *bufmem; + isc_stdtime_t now; + dns_totext_ctx_t ctx; + dns_rdatasetiter_t *rdsiter = NULL; + + result = totext_ctx_init(style, &ctx); + if (result != ISC_R_SUCCESS) { + UNEXPECTED_ERROR(__FILE__, __LINE__, + "could not set master file style"); + return (ISC_R_UNEXPECTED); + } + + isc_stdtime_get(&now); + + bufmem = isc_mem_get(mctx, initial_buffer_length); + if (bufmem == NULL) + return (ISC_R_NOMEMORY); + + isc_buffer_init(&buffer, bufmem, initial_buffer_length); + + result = dns_db_allrdatasets(db, node, version, now, &rdsiter); + if (result != ISC_R_SUCCESS) + goto failure; + result = dump_rdatasets(mctx, name, rdsiter, &ctx, &buffer, f); + if (result != ISC_R_SUCCESS) + goto failure; + dns_rdatasetiter_destroy(&rdsiter); + + result = ISC_R_SUCCESS; + + failure: + isc_mem_put(mctx, buffer.base, buffer.length); + return (result); +} + +isc_result_t +dns_master_dumpnode(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version, + dns_dbnode_t *node, dns_name_t *name, + const dns_master_style_t *style, const char *filename) +{ + FILE *f = NULL; + isc_result_t result; + + result = isc_stdio_open(filename, "w", &f); + if (result != ISC_R_SUCCESS) { + isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR, + "dumping node to file: %s: open: %s", filename, + isc_result_totext(result)); + return (ISC_R_UNEXPECTED); + } + + result = dns_master_dumpnodetostream(mctx, db, version, node, name, + style, f); + + result = isc_stdio_close(f); + if (result != ISC_R_SUCCESS) { + isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR, + "dumping master file: %s: close: %s", filename, + isc_result_totext(result)); + return (ISC_R_UNEXPECTED); + } + + return (result); +}