563. [func] New public functions dns_rdatatype_format() and

dns_rdataclass_format(), for convenient formatting
                        of rdata type/class mnemonics in log messages.
This commit is contained in:
Andreas Gustafsson 2000-11-15 19:05:32 +00:00
parent 046bd40fd1
commit d3a86da2e8
4 changed files with 85 additions and 3 deletions

View file

@ -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'

View file

@ -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 */

View file

@ -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 */

View file

@ -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 <config.h>
#include <ctype.h>
@ -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, "<unknown>");
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, "<unknown>");
array[size - 1] = '\0';
}
}
/* XXXRTH Should we use a hash table here? */
isc_result_t