1999-03-06 03:55:54 +00:00
|
|
|
/*
|
2007-05-15 23:46:57 +00:00
|
|
|
* Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
|
2001-01-09 22:01:04 +00:00
|
|
|
* Copyright (C) 1999-2001 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2007-06-18 23:47:57 +00:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
1999-03-06 03:55:54 +00:00
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2004-03-05 05:14:21 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
1999-03-06 03:55:54 +00:00
|
|
|
*/
|
|
|
|
|
2007-06-18 23:47:57 +00:00
|
|
|
/* $Id: compress_test.c,v 1.34 2007/06/18 23:47:26 tbox Exp $ */
|
2005-04-27 04:57:32 +00:00
|
|
|
|
|
|
|
/*! \file */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
1999-02-24 06:31:35 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2000-11-10 05:34:16 +00:00
|
|
|
#include <string.h>
|
1999-02-24 06:31:35 +00:00
|
|
|
|
2000-04-12 17:35:37 +00:00
|
|
|
#include <isc/buffer.h>
|
1999-10-06 20:07:25 +00:00
|
|
|
#include <isc/commandline.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/mem.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
2000-04-12 17:35:37 +00:00
|
|
|
|
1999-02-24 06:31:35 +00:00
|
|
|
#include <dns/compress.h>
|
|
|
|
#include <dns/name.h>
|
|
|
|
|
1999-04-28 03:03:56 +00:00
|
|
|
unsigned char plain1[] = "\003yyy\003foo";
|
|
|
|
unsigned char plain2[] = "\003bar\003yyy\003foo";
|
1999-02-24 06:31:35 +00:00
|
|
|
unsigned char plain3[] = "\003xxx\003bar\003foo";
|
2000-05-08 14:38:29 +00:00
|
|
|
unsigned char plain[] = "\003yyy\003foo\0\003bar\003yyy\003foo\0\003"
|
|
|
|
"bar\003yyy\003foo\0\003xxx\003bar\003foo";
|
1999-02-24 06:31:35 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Result concatenate (plain1, plain2, plain2, plain3).
|
|
|
|
*/
|
1999-02-24 06:31:35 +00:00
|
|
|
int raw = 0;
|
1999-03-04 06:50:05 +00:00
|
|
|
int verbose = 0;
|
1999-02-24 06:31:35 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
void
|
|
|
|
test(unsigned int, dns_name_t *, dns_name_t *, dns_name_t *,
|
|
|
|
unsigned char *, unsigned int);
|
1999-02-24 06:31:35 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[]) {
|
|
|
|
dns_name_t name1;
|
|
|
|
dns_name_t name2;
|
|
|
|
dns_name_t name3;
|
|
|
|
isc_region_t region;
|
|
|
|
int c;
|
|
|
|
|
1999-10-06 20:07:25 +00:00
|
|
|
while ((c = isc_commandline_parse(argc, argv, "rv")) != -1) {
|
1999-02-24 06:31:35 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'r':
|
|
|
|
raw++;
|
|
|
|
break;
|
1999-03-04 06:50:05 +00:00
|
|
|
case 'v':
|
|
|
|
verbose++;
|
|
|
|
break;
|
1999-02-24 06:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_name_init(&name1, NULL);
|
|
|
|
region.base = plain1;
|
2001-11-27 01:56:32 +00:00
|
|
|
region.length = sizeof(plain1);
|
1999-02-24 06:31:35 +00:00
|
|
|
dns_name_fromregion(&name1, ®ion);
|
|
|
|
|
|
|
|
dns_name_init(&name2, NULL);
|
|
|
|
region.base = plain2;
|
2001-11-27 01:56:32 +00:00
|
|
|
region.length = sizeof(plain2);
|
1999-02-24 06:31:35 +00:00
|
|
|
dns_name_fromregion(&name2, ®ion);
|
|
|
|
|
|
|
|
dns_name_init(&name3, NULL);
|
|
|
|
region.base = plain3;
|
2001-11-27 01:56:32 +00:00
|
|
|
region.length = sizeof(plain3);
|
1999-02-24 06:31:35 +00:00
|
|
|
dns_name_fromregion(&name3, ®ion);
|
|
|
|
|
2001-11-27 01:56:32 +00:00
|
|
|
test(DNS_COMPRESS_NONE, &name1, &name2, &name3, plain, sizeof(plain));
|
1999-02-24 06:31:35 +00:00
|
|
|
test(DNS_COMPRESS_GLOBAL14, &name1, &name2, &name3, plain,
|
2001-11-27 01:56:32 +00:00
|
|
|
sizeof(plain));
|
|
|
|
test(DNS_COMPRESS_ALL, &name1, &name2, &name3, plain, sizeof(plain));
|
1999-02-24 06:31:35 +00:00
|
|
|
|
2000-05-08 20:12:46 +00:00
|
|
|
return (0);
|
1999-02-24 06:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
test(unsigned int allowed, dns_name_t *name1, dns_name_t *name2,
|
|
|
|
dns_name_t *name3, unsigned char *result, unsigned int length)
|
|
|
|
{
|
|
|
|
isc_mem_t *mctx = NULL;
|
|
|
|
dns_compress_t cctx;
|
|
|
|
dns_decompress_t dctx;
|
|
|
|
isc_buffer_t source;
|
|
|
|
isc_buffer_t target;
|
|
|
|
dns_name_t name;
|
|
|
|
unsigned char buf1[1024];
|
|
|
|
unsigned char buf2[1024];
|
|
|
|
|
1999-03-04 06:50:05 +00:00
|
|
|
if (verbose) {
|
2000-06-01 19:11:07 +00:00
|
|
|
const char *s;
|
1999-03-04 06:50:05 +00:00
|
|
|
switch (allowed) {
|
|
|
|
case DNS_COMPRESS_NONE: s = "DNS_COMPRESS_NONE"; break;
|
|
|
|
case DNS_COMPRESS_GLOBAL14: s = "DNS_COMPRESS_GLOBAL14"; break;
|
2000-04-04 18:30:55 +00:00
|
|
|
/* case DNS_COMPRESS_ALL: s = "DNS_COMPRESS_ALL"; break; */
|
2006-02-26 22:57:18 +00:00
|
|
|
default: s = "UNKNOWN"; break;
|
1999-03-04 06:50:05 +00:00
|
|
|
}
|
|
|
|
fprintf(stdout, "Allowed = %s\n", s);
|
|
|
|
}
|
1999-02-24 06:31:35 +00:00
|
|
|
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&source, buf1, sizeof(buf1));
|
2000-04-06 22:03:35 +00:00
|
|
|
RUNTIME_CHECK(dns_compress_init(&cctx, -1, mctx) == ISC_R_SUCCESS);
|
1999-02-24 06:31:35 +00:00
|
|
|
|
2000-04-06 22:03:35 +00:00
|
|
|
RUNTIME_CHECK(dns_name_towire(name1, &cctx, &source) == ISC_R_SUCCESS);
|
1999-02-24 06:31:35 +00:00
|
|
|
|
2000-04-04 18:30:55 +00:00
|
|
|
/*
|
2000-08-01 01:33:37 +00:00
|
|
|
RUNTIME_CHECK(dns_compress_localinit(&cctx, name1, &source) ==
|
2000-04-06 22:03:35 +00:00
|
|
|
ISC_R_SUCCESS);
|
2000-04-04 18:30:55 +00:00
|
|
|
*/
|
1999-02-24 06:31:35 +00:00
|
|
|
dns_compress_setmethods(&cctx, allowed);
|
2000-04-06 22:03:35 +00:00
|
|
|
RUNTIME_CHECK(dns_name_towire(name2, &cctx, &source) == ISC_R_SUCCESS);
|
|
|
|
RUNTIME_CHECK(dns_name_towire(name2, &cctx, &source) == ISC_R_SUCCESS);
|
|
|
|
RUNTIME_CHECK(dns_name_towire(name3, &cctx, &source) == ISC_R_SUCCESS);
|
1999-02-24 06:31:35 +00:00
|
|
|
|
2000-04-04 18:30:55 +00:00
|
|
|
/*
|
1999-02-24 06:31:35 +00:00
|
|
|
dns_compress_localinvalidate(&cctx);
|
2000-04-04 18:30:55 +00:00
|
|
|
*/
|
1999-05-03 03:07:16 +00:00
|
|
|
dns_compress_rollback(&cctx, 0); /* testing only */
|
1999-02-24 06:31:35 +00:00
|
|
|
dns_compress_invalidate(&cctx);
|
|
|
|
|
|
|
|
if (raw) {
|
|
|
|
unsigned int i;
|
2001-11-27 00:56:32 +00:00
|
|
|
for (i = 0; i < source.used; /* */ ) {
|
1999-02-24 06:31:35 +00:00
|
|
|
fprintf(stdout, "%02x",
|
|
|
|
((unsigned char *)source.base)[i]);
|
|
|
|
if ((++i % 20) == 0)
|
|
|
|
fputs("\n", stdout);
|
|
|
|
else
|
|
|
|
if (i == source.used)
|
|
|
|
fputs("\n", stdout);
|
|
|
|
else
|
|
|
|
fputs(" ", stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_buffer_setactive(&source, source.used);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&target, buf2, sizeof(buf2));
|
2000-11-14 23:29:55 +00:00
|
|
|
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
|
1999-02-24 06:31:35 +00:00
|
|
|
|
|
|
|
dns_name_init(&name, NULL);
|
|
|
|
RUNTIME_CHECK(dns_name_fromwire(&name, &source, &dctx, ISC_FALSE,
|
2000-04-06 22:03:35 +00:00
|
|
|
&target) == ISC_R_SUCCESS);
|
1999-02-24 06:31:35 +00:00
|
|
|
dns_decompress_setmethods(&dctx, allowed);
|
2000-04-04 18:30:55 +00:00
|
|
|
/*
|
1999-02-24 06:31:35 +00:00
|
|
|
dns_decompress_localinit(&dctx, &name, &source);
|
2000-04-04 18:30:55 +00:00
|
|
|
*/
|
1999-02-24 06:31:35 +00:00
|
|
|
RUNTIME_CHECK(dns_name_fromwire(&name, &source, &dctx, ISC_FALSE,
|
2000-04-06 22:03:35 +00:00
|
|
|
&target) == ISC_R_SUCCESS);
|
1999-02-24 06:31:35 +00:00
|
|
|
RUNTIME_CHECK(dns_name_fromwire(&name, &source, &dctx, ISC_FALSE,
|
2000-04-06 22:03:35 +00:00
|
|
|
&target) == ISC_R_SUCCESS);
|
1999-02-24 06:31:35 +00:00
|
|
|
RUNTIME_CHECK(dns_name_fromwire(&name, &source, &dctx, ISC_FALSE,
|
2000-04-06 22:03:35 +00:00
|
|
|
&target) == ISC_R_SUCCESS);
|
2000-04-04 18:30:55 +00:00
|
|
|
/*
|
1999-02-24 06:31:35 +00:00
|
|
|
dns_decompress_localinvalidate(&dctx);
|
2000-04-04 18:30:55 +00:00
|
|
|
*/
|
1999-02-24 06:31:35 +00:00
|
|
|
dns_decompress_invalidate(&dctx);
|
|
|
|
|
|
|
|
if (raw) {
|
|
|
|
unsigned int i;
|
2001-11-27 00:56:32 +00:00
|
|
|
for (i = 0; i < target.used; /* */ ) {
|
1999-02-24 06:31:35 +00:00
|
|
|
fprintf(stdout, "%02x",
|
|
|
|
((unsigned char *)target.base)[i]);
|
|
|
|
if ((++i % 20) == 0)
|
|
|
|
fputs("\n", stdout);
|
|
|
|
else
|
|
|
|
if (i == target.used)
|
|
|
|
fputs("\n", stdout);
|
|
|
|
else
|
|
|
|
fputs(" ", stdout);
|
|
|
|
}
|
|
|
|
fputs("\n", stdout);
|
1999-04-28 03:03:56 +00:00
|
|
|
fflush(stdout);
|
1999-02-24 06:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RUNTIME_CHECK(target.used == length);
|
|
|
|
RUNTIME_CHECK(memcmp(target.base, result, target.used) == 0);
|
|
|
|
isc_mem_destroy(&mctx);
|
|
|
|
}
|