rbt_test.c revision caa252e5adf952d8981c7dacd28c5d2296ff5896
/*
* Copyright (C) 2004, 2005, 2007, 2009, 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2001 Internet Software Consortium.
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* 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.
*/
/* $Id: rbt_test.c,v 1.52 2011/08/28 23:46:41 tbox Exp $ */
#include <config.h>
#include <stdlib.h>
#include <isc/commandline.h>
#include <dns/fixedname.h>
char *progname;
#define DNSNAMELEN 255
static dns_name_t *
create_name(char *s) {
int length;
static dns_name_t *name;
if (s == NULL || *s == '\0') {
printf("missing name argument\n");
return (NULL);
}
/*
* It isn't really necessary in this program to create individual
* memory spaces for each name structure and its associated character
* string. It is done here to provide a relatively easy way to test
* the callback from dns_rbt_deletename that is supposed to free the
* data associated with a node.
*
* The buffer for the actual name will immediately follow the
* name structure.
*/
printf("out of memory!\n");
return (NULL);
}
if (result != ISC_R_SUCCESS) {
printf("dns_name_fromtext(%s) failed: %s\n",
s, dns_result_totext(result));
return (NULL);
}
return (name);
}
static void
}
static void
char buffer[1024];
/*
* ISC_FALSE means absolute names have the final dot added.
*/
}
static void
printf("checking chain information for ");
printf("\n");
switch (result) {
case ISC_R_SUCCESS:
printf(" found exact.");
break;
case DNS_R_PARTIALMATCH:
printf(" found parent.");
break;
case ISC_R_NOTFOUND:
printf(" name not found.");
break;
default:
return;
}
printf(" data at node: ");
} else
printf(" no data at node.");
printf("\n name from dns_rbt_findnode: ");
}
if (result == ISC_R_SUCCESS) {
printf("\n name from dns_rbtnodechain_current: ");
if (result == ISC_R_SUCCESS)
else
printf("\n (foundname = ");
printf(", origin = ");
printf(")\n");
printf(" nodes returned from each function "
"DO NOT match!\n");
} else
printf("\n result from dns_rbtnodechain_current: %s\n",
printf(" level_matches = %d, level_count = %d\n",
}
static void
dns_name_t *origin);
if (forward) {
printf("iterating forward\n" );
origin);
} else {
printf("iterating backward\n" );
origin);
}
printf("start not found!\n");
else {
for (;;) {
if (result == DNS_R_NEWORIGIN) {
printf(" new origin: ");
printf("\n");
}
if (result == ISC_R_SUCCESS ||
result == DNS_R_NEWORIGIN) {
printf("\n");
} else {
if (result != ISC_R_NOMORE)
printf("UNEXEPCTED ITERATION ERROR: %s",
break;
}
}
}
}
#define PRINTERR(r) if (r != ISC_R_SUCCESS) \
int
const char *whitespace;
void *data;
progname++;
else
switch (ch) {
case 'm':
break;
}
}
if (argc > 1) {
exit(1);
}
/*
* So isc_mem_stats() can report any allocation leaks.
*/
if (result != ISC_R_SUCCESS) {
printf("isc_mem_create: %s: exiting\n",
exit(1);
}
if (result != ISC_R_SUCCESS) {
printf("dns_rbt_create: %s: exiting\n",
exit(1);
}
whitespace = " \t";
printf("line to long (%lu max), ignored\n",
(unsigned long)sizeof(buffer) - 2);
continue;
}
if (*command == '#')
continue;
*arg++ = '\0';
}
if (*command != '\0') {
if (CMDCHECK("add")) {
}
} else if (CMDCHECK("delete")) {
}
} else if (CMDCHECK("nuke")) {
printf("nuking name %s "
"and its descendants\n", arg);
ISC_TRUE);
}
} else if (CMDCHECK("search")) {
printf("searching for name %s ... ",
arg);
&data);
switch (result) {
case ISC_R_SUCCESS:
printf("found exact: ");
putchar('\n');
break;
case DNS_R_PARTIALMATCH:
printf("found parent: ");
printf("\n\t(foundname: ");
printf(")\n");
break;
case ISC_R_NOTFOUND:
printf("NOT FOUND!\n");
break;
case ISC_R_NOMEMORY:
printf("OUT OF MEMORY!\n");
break;
default:
printf("UNEXPECTED RESULT\n");
}
}
} else if (CMDCHECK("check")) {
/*
* Or "chain". I know, I know. Lame name.
* I was having a hard time thinking of a
* name (especially one that did not have
* a conflicting first letter with another
* command) that would differentiate this
* from the search command.
*
* But it is just a test program, eh?
*/
}
} else if (CMDCHECK("forward")) {
} else if (CMDCHECK("backward")) {
} else if (CMDCHECK("print")) {
else
printf("usage: print\n");
} else if (CMDCHECK("quit")) {
break;
else
printf("usage: quit\n");
} else {
printf("a(dd) NAME, d(elete) NAME, "
"s(earch) NAME, p(rint), or q(uit)\n");
}
}
}
if (show_final_mem)
return (0);
}