rbt_test.c revision b313f1f0c08d08097cbe339faf5353ca59091d2f
/*
* Copyright (C) 1999, 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* 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 INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM 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.40 2000/11/20 22:01:53 gson Exp $ */
#include <config.h>
#include <stdlib.h>
#ifndef ISC_MEM_TRACKLINES
#define ISC_MEM_TRACKLINES
#endif
#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 {
while (1) {
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.
*/
isc_mem_debugging = 2;
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 (%d max), ignored\n",
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);
}