diff --git a/CHANGES b/CHANGES index 1b7afcfa77..d2ece5b427 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,8 @@ + 563. [func] New public functions dns_rdatatype_format() and + dns_rdataclass_format(), for convenient formatting + of rdata type/class mnemonics in log messages. + 562. [cleanup] Moved lib/dns/*conf.c to bin/named where they belong. 561. [func] The 'datasize', 'stacksize', 'coresize' and 'files' diff --git a/lib/dns/include/dns/rdataclass.h b/lib/dns/include/dns/rdataclass.h index cfefea1a81..b715f7ce4e 100644 --- a/lib/dns/include/dns/rdataclass.h +++ b/lib/dns/include/dns/rdataclass.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rdataclass.h,v 1.15 2000/11/09 23:55:02 bwelling Exp $ */ +/* $Id: rdataclass.h,v 1.16 2000/11/15 19:05:30 gson Exp $ */ #ifndef DNS_RDATACLASS_H #define DNS_RDATACLASS_H 1 @@ -60,6 +60,20 @@ dns_rdataclass_totext(dns_rdataclass_t rdclass, isc_buffer_t *target); * ISC_R_NOSPACE target buffer is too small */ +void +dns_rdataclass_format(dns_rdataclass_t rdclass, + char *array, unsigned int size); +/* + * Format a human-readable representation of the class 'rdclass' + * into the character array 'array', which is of size 'size'. + * The resulting string is guaranteed to be null-terminated. + */ + +#define DNS_RDATACLASS_FORMATSIZE sizeof("CLASS65535") +/* + * Minimum size of array to pass to dns_rdataclass_format(). + */ + ISC_LANG_ENDDECLS #endif /* DNS_RDATACLASS_H */ diff --git a/lib/dns/include/dns/rdatatype.h b/lib/dns/include/dns/rdatatype.h index f37ec3049b..40d55c57ea 100644 --- a/lib/dns/include/dns/rdatatype.h +++ b/lib/dns/include/dns/rdatatype.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rdatatype.h,v 1.14 2000/11/09 23:55:03 bwelling Exp $ */ +/* $Id: rdatatype.h,v 1.15 2000/11/15 19:05:32 gson Exp $ */ #ifndef DNS_RDATATYPE_H #define DNS_RDATATYPE_H 1 @@ -60,6 +60,22 @@ dns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t *target); * ISC_R_NOSPACE target buffer is too small */ +void +dns_rdatatype_format(dns_rdatatype_t rdtype + char *array, unsigned int size); +/* + * Format a human-readable representation of the type 'rdtype' + * into the character array 'array', which is of size 'size'. + * The resulting string is guaranteed to be null-terminated. + */ + +#define DNS_RDATATYPE_FORMATSIZE sizeof("TYPE65535") +/* + * Minimum size of array to pass to dns_rdatatype_format(). + * May need to be adjusted if a new RR type with a very long + * name is defined. + */ + ISC_LANG_ENDDECLS #endif /* DNS_RDATATYPE_H */ diff --git a/lib/dns/rdata.c b/lib/dns/rdata.c index fc6b3ce20b..5850459135 100644 --- a/lib/dns/rdata.c +++ b/lib/dns/rdata.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rdata.c,v 1.123 2000/11/14 23:29:53 bwelling Exp $ */ +/* $Id: rdata.c,v 1.124 2000/11/15 19:05:28 gson Exp $ */ #include #include @@ -1018,7 +1018,30 @@ dns_rdataclass_totext(dns_rdataclass_t rdclass, isc_buffer_t *target) { sprintf(buf, "CLASS%u", rdclass); return (str_totext(buf, target)); } +} +void +dns_rdataclass_format(dns_rdataclass_t rdclass, + char *array, unsigned int size) +{ + isc_result_t result; + isc_buffer_t buf; + + isc_buffer_init(&buf, array, size); + result = dns_rdataclass_totext(rdclass, &buf); + /* + * Null terminate. + */ + if (result == ISC_R_SUCCESS) { + if (isc_buffer_availablelength(&buf) >= 1) + isc_buffer_putuint8(&buf, 0); + else + result = ISC_R_NOSPACE; + } + if (result != ISC_R_SUCCESS) { + snprintf(array, size, ""); + array[size - 1] = '\0'; + } } isc_result_t @@ -1068,6 +1091,31 @@ dns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t *target) { return (str_totext(typeattr[type].name, target)); } +void +dns_rdatatype_format(dns_rdatatype_t rdtype + char *array, unsigned int size); +{ + isc_result_t result; + isc_buffer_t buf; + + isc_buffer_init(&buf, array, size); + result = dns_type_totext(rdclass, &buf); + /* + * Null terminate. + */ + if (result == ISC_R_SUCCESS) { + if (isc_buffer_availablelength(&buf) >= 1) + isc_buffer_putuint8(&buf, 0); + else + result = ISC_R_NOSPACE; + } + if (result != ISC_R_SUCCESS) { + snprintf(array, size, ""); + array[size - 1] = '\0'; + } +} + + /* XXXRTH Should we use a hash table here? */ isc_result_t