Commit b4b4adc0 authored by Andreas Gustafsson's avatar Andreas Gustafsson
Browse files

added convenience function dns_name_format() for use in formatting

log messages
parent 5646eb8c
42. [cleanup] Simplified logging of messages with embedded domain
names by introducing a new convenience function
dns_name_format().
41. [feature] Use PR_SET_KEEPCAPS on Linux 2.3.99-pre3 and later
to allow 'named' to run as a non-root user while
......
......@@ -1128,6 +1128,31 @@ dns_name_print(dns_name_t *name, FILE *stream);
* Any error that dns_name_totext() can return.
*/
void
dns_name_format(dns_name_t *name, char *cp, unsigned int size);
/*
* Format 'name' as text appropriate for use in log messages.
*
* Store the formatted name at 'cp', writing no more than
* 'size' bytes. The resulting string is guaranteed to be
* null terminated.
*
* The formatted name will have a terminating dot only if it is
* the root.
*
* This function cannot fail, instead any errors are indicated
* in the returned text.
*
* Requires:
*
* 'name' is a valid name.
*
* 'cp' points a valid character array of size 'size'.
*
* 'size' > 0.
*
*/
ISC_LANG_ENDDECLS
#endif /* DNS_NAME_H */
......@@ -3035,3 +3035,29 @@ dns_name_print(dns_name_t *name, FILE *stream) {
return (ISC_R_SUCCESS);
}
void
dns_name_format(dns_name_t *name, char *cp, unsigned int size)
{
isc_result_t result;
isc_buffer_t buf;
isc_boolean_t omit_final_dot = ISC_TRUE;
REQUIRE(size > 0);
if (dns_name_equal(name, dns_rootname))
omit_final_dot = ISC_FALSE;
/* Leave room for null termination after buffer. */
isc_buffer_init(&buf, cp, size - 1, ISC_BUFFERTYPE_TEXT);
result = dns_name_totext(name, omit_final_dot, &buf);
if (result == ISC_R_SUCCESS) {
/* Null terminate. */
isc_region_t r;
isc_buffer_used(&buf, &r);
((char *) r.base)[r.length] = '\0';
} else {
snprintf(cp, size, "<unknown>");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment