mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-02 15:45:25 +00:00
dns_name_cat() -> dns_name_concatenate()
Changed behaviour so that it is intuitive w.r.t. absolute names. If 'prefix' is absolute then 'suffix' must be NULL. If 'prefix' or 'suffix' is absolute then the result is absolute.
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: compress.c,v 1.3 1999/02/24 06:31:31 marka Exp $ */
|
/* $Id: compress.c,v 1.4 1999/02/26 00:25:12 marka Exp $ */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -145,7 +145,8 @@ dns_compress_localinit(dns_compress_t *cctx, dns_name_t *owner,
|
|||||||
dns_name_fromregion(&prefix, ®ion);
|
dns_name_fromregion(&prefix, ®ion);
|
||||||
isc_buffer_init(&t, namebuf, sizeof namebuf,
|
isc_buffer_init(&t, namebuf, sizeof namebuf,
|
||||||
ISC_BUFFERTYPE_BINARY);
|
ISC_BUFFERTYPE_BINARY);
|
||||||
result = dns_name_cat(&prefix, &suffix, &name, &t);
|
result = dns_name_concatenate(&prefix, &suffix, &name,
|
||||||
|
&t);
|
||||||
if (result != DNS_R_SUCCESS)
|
if (result != DNS_R_SUCCESS)
|
||||||
return (DNS_R_SUCCESS);
|
return (DNS_R_SUCCESS);
|
||||||
data = isc_mem_get(cctx->mctx, sizeof *data);
|
data = isc_mem_get(cctx->mctx, sizeof *data);
|
||||||
@@ -386,7 +387,7 @@ compress_add(dns_rbt_t *root, dns_name_t *prefix, dns_name_t *suffix,
|
|||||||
dns_name_getlabelsequence(prefix, start, count, &name);
|
dns_name_getlabelsequence(prefix, start, count, &name);
|
||||||
isc_buffer_init(&target, buffer, sizeof buffer,
|
isc_buffer_init(&target, buffer, sizeof buffer,
|
||||||
ISC_BUFFERTYPE_BINARY);
|
ISC_BUFFERTYPE_BINARY);
|
||||||
result = dns_name_cat(&name, suffix, &full, &target);
|
result = dns_name_concatenate(&name, suffix, &full, &target);
|
||||||
if (result != DNS_R_SUCCESS)
|
if (result != DNS_R_SUCCESS)
|
||||||
return;
|
return;
|
||||||
data = isc_mem_get(mctx, sizeof *data);
|
data = isc_mem_get(mctx, sizeof *data);
|
||||||
@@ -471,7 +472,7 @@ compress_find(dns_rbt_t *root, dns_name_t *name, dns_name_t *prefix,
|
|||||||
buf[1] = bits;
|
buf[1] = bits;
|
||||||
dns_name_fromregion(&tmpprefix, ®ion);
|
dns_name_fromregion(&tmpprefix, ®ion);
|
||||||
isc_buffer_clear(workspace);
|
isc_buffer_clear(workspace);
|
||||||
result = dns_name_cat(&tmpprefix, &tmpsuffix,
|
result = dns_name_concatenate(&tmpprefix, &tmpsuffix,
|
||||||
&tmpname, workspace);
|
&tmpname, workspace);
|
||||||
if (result != DNS_R_SUCCESS)
|
if (result != DNS_R_SUCCESS)
|
||||||
continue;
|
continue;
|
||||||
@@ -522,7 +523,8 @@ compress_find(dns_rbt_t *root, dns_name_t *name, dns_name_t *prefix,
|
|||||||
dns_name_init(&tmpprefix, NULL);
|
dns_name_init(&tmpprefix, NULL);
|
||||||
else
|
else
|
||||||
dns_name_getlabelsequence(name, 0, start - 1, &tmpprefix);
|
dns_name_getlabelsequence(name, 0, start - 1, &tmpprefix);
|
||||||
result = dns_name_cat(&tmpprefix, &tmpsuffix, prefix, workspace);
|
result = dns_name_concatenate(&tmpprefix, &tmpsuffix, prefix,
|
||||||
|
workspace);
|
||||||
if (result != DNS_R_SUCCESS)
|
if (result != DNS_R_SUCCESS)
|
||||||
return (ISC_FALSE);
|
return (ISC_FALSE);
|
||||||
*offset = *data;
|
*offset = *data;
|
||||||
|
@@ -208,10 +208,12 @@ dns_compress_add(dns_compress_t *cctx, dns_name_t *prefix,
|
|||||||
dns_name_t *suffix, isc_uint16_t offset);
|
dns_name_t *suffix, isc_uint16_t offset);
|
||||||
/*
|
/*
|
||||||
* Add compression pointers for labels in prefix to RBT's.
|
* Add compression pointers for labels in prefix to RBT's.
|
||||||
|
* If 'prefix' is absolute 'suffix' must be NULL.
|
||||||
*
|
*
|
||||||
* Requires:
|
* Requires:
|
||||||
* 'cctx' initalised
|
* 'cctx' initalised
|
||||||
* 'prefix' to be initalised
|
* 'prefix' to be initalised
|
||||||
|
* 'suffix' to be initalised or NULL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -663,11 +663,11 @@ dns_result_t dns_name_totext(dns_name_t *name,
|
|||||||
* DNS_R_NOSPACE
|
* DNS_R_NOSPACE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
dns_result_t dns_name_cat(dns_name_t *prefix, dns_name_t *suffix,
|
dns_result_t dns_name_concatenate(dns_name_t *prefix, dns_name_t *suffix,
|
||||||
dns_name_t *name, isc_buffer_t *target);
|
dns_name_t *name, isc_buffer_t *target);
|
||||||
/*
|
/*
|
||||||
* Concatenate 'prefix' & 'suffix' and return the result in 'name'.
|
* Concatenate 'prefix' & 'suffix' and return the result in 'name'.
|
||||||
* If either 'prefix' or 'suffix' is absolute the result is absolute.
|
* If 'prefix' is absolute 'suffix' must be NULL.
|
||||||
*
|
*
|
||||||
* Requires:
|
* Requires:
|
||||||
* 'prefix' to be initalised
|
* 'prefix' to be initalised
|
||||||
|
@@ -2049,8 +2049,8 @@ dns_name_towire(dns_name_t *name, dns_compress_t *cctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
dns_result_t
|
dns_result_t
|
||||||
dns_name_cat(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name,
|
dns_name_concatenate(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name,
|
||||||
isc_buffer_t *target)
|
isc_buffer_t *target)
|
||||||
{
|
{
|
||||||
unsigned char *ndata;
|
unsigned char *ndata;
|
||||||
unsigned char *offsets;
|
unsigned char *offsets;
|
||||||
@@ -2059,27 +2059,31 @@ dns_name_cat(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name,
|
|||||||
unsigned int labels;
|
unsigned int labels;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
isc_boolean_t absolute = ISC_FALSE;
|
isc_boolean_t absolute = ISC_FALSE;
|
||||||
|
dns_name_t tmp_name;
|
||||||
|
|
||||||
REQUIRE(VALID_NAME(name));
|
|
||||||
REQUIRE(VALID_NAME(prefix));
|
REQUIRE(VALID_NAME(prefix));
|
||||||
|
if (prefix->labels != 0 &&
|
||||||
|
(prefix->attributes & DNS_NAMEATTR_ABSOLUTE) != 0)
|
||||||
|
REQUIRE(suffix == NULL);
|
||||||
if (suffix != NULL)
|
if (suffix != NULL)
|
||||||
REQUIRE(VALID_NAME(suffix));
|
REQUIRE(VALID_NAME(suffix));
|
||||||
|
if (name != NULL)
|
||||||
|
REQUIRE(VALID_NAME(name));
|
||||||
REQUIRE(isc_buffer_type(target) == ISC_BUFFERTYPE_BINARY);
|
REQUIRE(isc_buffer_type(target) == ISC_BUFFERTYPE_BINARY);
|
||||||
REQUIRE((name->attributes & DNS_NAMEATTR_READONLY) == 0);
|
REQUIRE((name->attributes & DNS_NAMEATTR_READONLY) == 0);
|
||||||
|
|
||||||
|
if (name == NULL) {
|
||||||
|
name = &tmp_name;
|
||||||
|
dns_name_init(name, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
nrem = target->length - target->used;
|
nrem = target->length - target->used;
|
||||||
ndata = (unsigned char *)target->base + target->used;
|
ndata = (unsigned char *)target->base + target->used;
|
||||||
if (nrem > 255)
|
if (nrem > 255)
|
||||||
nrem = 255;
|
nrem = 255;
|
||||||
if (prefix->labels != 0 &&
|
|
||||||
(prefix->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) {
|
count = prefix->length;
|
||||||
count = prefix->length - 1;
|
labels = prefix->labels;
|
||||||
labels = prefix->labels - 1;
|
|
||||||
absolute = ISC_TRUE;
|
|
||||||
} else {
|
|
||||||
count = prefix->length;
|
|
||||||
labels = prefix->labels;
|
|
||||||
}
|
|
||||||
if (count > nrem)
|
if (count > nrem)
|
||||||
return (DNS_R_NOSPACE);
|
return (DNS_R_NOSPACE);
|
||||||
memcpy(ndata, prefix->ndata, count);
|
memcpy(ndata, prefix->ndata, count);
|
||||||
@@ -2088,42 +2092,24 @@ dns_name_cat(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name,
|
|||||||
|
|
||||||
/* append suffix */
|
/* append suffix */
|
||||||
if (suffix != NULL) {
|
if (suffix != NULL) {
|
||||||
if (suffix->labels != 0 &&
|
count = suffix->length;
|
||||||
(suffix->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) {
|
labels += suffix->labels;
|
||||||
count = suffix->length - 1;
|
|
||||||
labels += suffix->labels - 1;
|
|
||||||
absolute = ISC_TRUE;
|
|
||||||
} else {
|
|
||||||
count = suffix->length;
|
|
||||||
labels += suffix->labels;
|
|
||||||
}
|
|
||||||
if (count > nrem)
|
if (count > nrem)
|
||||||
return (DNS_R_NOSPACE);
|
return (DNS_R_NOSPACE);
|
||||||
memcpy(ndata, suffix->ndata, count);
|
memcpy(ndata, suffix->ndata, count);
|
||||||
ndata += count;
|
ndata += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (absolute) {
|
|
||||||
/* root label */
|
|
||||||
if (nrem < 1)
|
|
||||||
return (DNS_R_NOSPACE);
|
|
||||||
*ndata++ = 0;
|
|
||||||
labels++;
|
|
||||||
}
|
|
||||||
|
|
||||||
name->ndata = (unsigned char *)target->base + target->used;
|
name->ndata = (unsigned char *)target->base + target->used;
|
||||||
name->labels = labels;
|
name->labels = labels;
|
||||||
name->length = ndata - name->ndata;
|
name->length = ndata - name->ndata;
|
||||||
if (absolute)
|
|
||||||
name->attributes |= DNS_NAMEATTR_ABSOLUTE;
|
|
||||||
else
|
|
||||||
name->attributes &= ~DNS_NAMEATTR_ABSOLUTE;
|
|
||||||
|
|
||||||
INIT_OFFSETS(name, offsets, odata);
|
INIT_OFFSETS(name, offsets, odata);
|
||||||
if (name->length > 0)
|
if (name->length > 0) {
|
||||||
set_offsets(name, offsets, ISC_FALSE, ISC_FALSE, ISC_FALSE);
|
set_offsets(name, offsets, ISC_FALSE, ISC_FALSE, ISC_TRUE);
|
||||||
|
compact(name, offsets);
|
||||||
compact(name, offsets);
|
} else
|
||||||
|
name->attributes &= ~DNS_NAMEATTR_ABSOLUTE;
|
||||||
|
|
||||||
isc_buffer_add(target, name->length);
|
isc_buffer_add(target, name->length);
|
||||||
return (DNS_R_SUCCESS);
|
return (DNS_R_SUCCESS);
|
||||||
|
Reference in New Issue
Block a user