isc_buffer_t *target);
/*%<
* Convert 'name' into wire format, compressing it as specified by the
- * compression context 'cctx', and storing the result in 'target'.
+ * compression context 'cctx' (or leaving it uncompressed if 'cctx' is
+ * NULL), and storing the result in 'target'.
*
* Notes:
* \li If compression is permitted, then the cctx table may be updated.
/*
* Convert 'name' into wire format, compressing it as specified by the
- * compression context 'cctx', and storing the result in 'target'.
+ * compression context 'cctx' (or without compressing if 'cctx'
+ * is NULL), and storing the result in 'target'.
*/
REQUIRE(DNS_NAME_VALID(name));
- REQUIRE(cctx != NULL);
REQUIRE(ISC_BUFFER_VALID(target));
+ if (cctx == NULL) {
+ if (isc_buffer_availablelength(target) < name->length) {
+ return ISC_R_NOSPACE;
+ }
+ memmove(isc_buffer_used(target), name->ndata, name->length);
+ isc_buffer_add(target, name->length);
+ return ISC_R_SUCCESS;
+ }
+
compress = !name->attributes.nocompress &&
dns_compress_getpermitted(cctx);
multi = compress && dns_compress_getmultiuse(cctx);
ISC_R_SUCCESS);
} else {
/* Owner name compression */
- dns_compress_setmultiuse(cctx, true);
+ if (cctx != NULL) {
+ dns_compress_setmultiuse(cctx, true);
+ }
assert_int_equal(dns_name_towire(name1, cctx, &source),
ISC_R_SUCCESS);
- dns_compress_setmultiuse(cctx, true);
+ if (cctx != NULL) {
+ dns_compress_setmultiuse(cctx, true);
+ }
assert_int_equal(dns_name_towire(name2, cctx, &source),
ISC_R_SUCCESS);
assert_int_equal(dns_name_towire(name2, cctx, &source),
ISC_R_SUCCESS);
- dns_compress_setmultiuse(cctx, true);
+ if (cctx != NULL) {
+ dns_compress_setmultiuse(cctx, true);
+ }
assert_int_equal(dns_name_towire(name3, cctx, &source),
ISC_R_SUCCESS);
}
r.length = sizeof(plain3);
dns_name_fromregion(&name4, &r);
+ /* Test 0: no compression context */
+ compress_test(&name1, &name2, &name3, plain, sizeof(plain), plain,
+ sizeof(plain), NULL, DNS_DECOMPRESS_NEVER, true);
+ compress_test(&name1, &name2, &name3, plain, sizeof(plain), plain,
+ sizeof(plain), NULL, DNS_DECOMPRESS_NEVER, false);
+
/* Test 1: off, rdata */
permitted = false;
dns_compress_init(&cctx, mctx, 0);