rbt_test.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 1999-2001, 2004, 2005, 2007, 2009, 2011, 2012, 2014-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $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>
const 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);
}