diff --git a/lib/dns/include/dns/name.h b/lib/dns/include/dns/name.h index ae840785fb..f25ecd5d9b 100644 --- a/lib/dns/include/dns/name.h +++ b/lib/dns/include/dns/name.h @@ -1240,16 +1240,19 @@ dns_name_settotextfilter(dns_name_totextfilter_t proc); isc_result_t dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target); +void +dns_name_copynf(const dns_name_t *source, dns_name_t *dest); /*%< - * Makes 'dest' refer to a copy of the name in 'source'. The data are - * either copied to 'target' or the dedicated buffer in 'dest'. + * Makes 'dest' refer to a copy of the name in 'source'. The data are either + * copied to 'target' or in case of dns_name_copyfixed the dedicated buffer in + * 'dest'. * * Requires: * \li 'source' is a valid name. * * \li 'dest' is an initialized name with a dedicated buffer. * - * \li 'target' is NULL or an initialized buffer. + * \li 'target' is an initialized buffer. * * \li Either dest has a dedicated buffer or target != NULL. * diff --git a/lib/dns/name.c b/lib/dns/name.c index 7ff29e3665..65b4eb1909 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -2456,50 +2456,46 @@ dns_name_fromstring2(dns_name_t *target, const char *src, return (result); } +static isc_result_t -dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) { +name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) { unsigned char *ndata; /* * Make dest a copy of source. */ - REQUIRE(VALID_NAME(source)); - REQUIRE(VALID_NAME(dest)); - REQUIRE(target != NULL || dest->buffer != NULL); - - if (target == NULL) { - target = dest->buffer; - isc_buffer_clear(dest->buffer); - } - REQUIRE(BINDABLE(dest)); /* * Set up. */ - if (target->length - target->used < source->length) + if (target->length - target->used < source->length) { return (ISC_R_NOSPACE); + } ndata = (unsigned char *)target->base + target->used; dest->ndata = target->base; - if (source->length != 0) + if (source->length != 0) { memmove(ndata, source->ndata, source->length); + } dest->ndata = ndata; dest->labels = source->labels; dest->length = source->length; - if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) + if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) { dest->attributes = DNS_NAMEATTR_ABSOLUTE; - else + } else { dest->attributes = 0; + } if (dest->labels > 0 && dest->offsets != NULL) { - if (source->offsets != NULL) + if (source->offsets != NULL) { memmove(dest->offsets, source->offsets, source->labels); - else + } else { set_offsets(dest, dest->offsets, NULL); + } } isc_buffer_add(target, dest->length); @@ -2507,6 +2503,27 @@ dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) return (ISC_R_SUCCESS); } +isc_result_t +dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) +{ + REQUIRE(VALID_NAME(source)); + REQUIRE(VALID_NAME(dest)); + REQUIRE(target != NULL); + + return (name_copy(source, dest, target)); +} + +void +dns_name_copynf(const dns_name_t *source, dns_name_t *dest) +{ + REQUIRE(VALID_NAME(source)); + REQUIRE(VALID_NAME(dest)); + REQUIRE(dest->buffer != NULL); + + isc_buffer_clear(dest->buffer); + RUNTIME_CHECK(name_copy(source, dest, dest->buffer) == ISC_R_SUCCESS); +} + void dns_name_destroy(void) { RUNTIME_CHECK(isc_once_do(&once, thread_key_mutex_init) diff --git a/lib/dns/win32/libdns.def.in b/lib/dns/win32/libdns.def.in index d44f6036f0..c415559a84 100644 --- a/lib/dns/win32/libdns.def.in +++ b/lib/dns/win32/libdns.def.in @@ -540,6 +540,7 @@ dns_name_clone dns_name_compare dns_name_concatenate dns_name_copy +dns_name_copynf dns_name_countlabels dns_name_destroy dns_name_digest