mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-02 15:45:25 +00:00
Preliminary testing of new iterator methods.
This commit is contained in:
@@ -89,7 +89,7 @@ delete_name(void *data, void *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_data(void *data) {
|
print_name(dns_name_t *name) {
|
||||||
isc_buffer_t target;
|
isc_buffer_t target;
|
||||||
char *buffer[256];
|
char *buffer[256];
|
||||||
|
|
||||||
@@ -98,11 +98,69 @@ print_data(void *data) {
|
|||||||
/*
|
/*
|
||||||
* ISC_FALSE means absolute names have the final dot added.
|
* ISC_FALSE means absolute names have the final dot added.
|
||||||
*/
|
*/
|
||||||
dns_name_totext(data, ISC_FALSE, &target);
|
dns_name_totext(name, ISC_FALSE, &target);
|
||||||
|
|
||||||
printf("%.*s", (int)target.used, (char *)target.base);
|
printf("%.*s", (int)target.used, (char *)target.base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
iterate(dns_rbt_t *rbt, dns_name_t *name, isc_boolean_t forward) {
|
||||||
|
dns_name_t *foundname, *origin;
|
||||||
|
dns_rbtnode_t *node = NULL;
|
||||||
|
dns_rbtnodechain_t chain;
|
||||||
|
dns_fixedname_t fixedfoundname, fixedorigin;
|
||||||
|
dns_result_t result;
|
||||||
|
dns_result_t (*move)(dns_rbtnodechain_t *chain, dns_name_t *name,
|
||||||
|
dns_name_t *origin);
|
||||||
|
|
||||||
|
if (forward) {
|
||||||
|
printf("iterating forward\n" );
|
||||||
|
move = dns_rbtnodechain_next;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printf("iterating backward\n" );
|
||||||
|
move = dns_rbtnodechain_prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
dns_rbtnodechain_init(&chain, mctx);
|
||||||
|
|
||||||
|
result = dns_rbt_findnode(rbt, name, NULL, &node, &chain,
|
||||||
|
ISC_FALSE, NULL, NULL);
|
||||||
|
if (result != DNS_R_SUCCESS)
|
||||||
|
printf("start not found!\n");
|
||||||
|
|
||||||
|
else {
|
||||||
|
dns_fixedname_init(&fixedfoundname);
|
||||||
|
dns_fixedname_init(&fixedorigin);
|
||||||
|
foundname = dns_fixedname_name(&fixedfoundname);
|
||||||
|
origin = dns_fixedname_name(&fixedorigin);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
result = move(&chain, foundname, origin);
|
||||||
|
if (result == DNS_R_NEWORIGIN) {
|
||||||
|
printf(" new origin: ");
|
||||||
|
print_name(origin);
|
||||||
|
printf("\n");
|
||||||
|
dns_fixedname_init(&fixedorigin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == DNS_R_SUCCESS ||
|
||||||
|
result == DNS_R_NEWORIGIN) {
|
||||||
|
print_name(foundname);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (result != DNS_R_NOMORE)
|
||||||
|
printf("UNEXEPCTED ITERATION ERROR: %s",
|
||||||
|
dns_result_totext(result));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dns_fixedname_init(&fixedfoundname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define CMDCHECK(s) (strncasecmp(command, (s), length) == 0)
|
#define CMDCHECK(s) (strncasecmp(command, (s), length) == 0)
|
||||||
#define PRINTERR(r) if (r != DNS_R_SUCCESS) \
|
#define PRINTERR(r) if (r != DNS_R_SUCCESS) \
|
||||||
printf("... %s\n", dns_result_totext(r));
|
printf("... %s\n", dns_result_totext(r));
|
||||||
@@ -115,7 +173,6 @@ main (int argc, char **argv) {
|
|||||||
dns_rbt_t *rbt;
|
dns_rbt_t *rbt;
|
||||||
int length, ch;
|
int length, ch;
|
||||||
isc_boolean_t show_final_mem = ISC_FALSE;
|
isc_boolean_t show_final_mem = ISC_FALSE;
|
||||||
isc_buffer_t textname;
|
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
@@ -225,22 +282,15 @@ main (int argc, char **argv) {
|
|||||||
switch (result) {
|
switch (result) {
|
||||||
case DNS_R_SUCCESS:
|
case DNS_R_SUCCESS:
|
||||||
printf("found exact: ");
|
printf("found exact: ");
|
||||||
print_data(data);
|
print_name(data);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
break;
|
break;
|
||||||
case DNS_R_PARTIALMATCH:
|
case DNS_R_PARTIALMATCH:
|
||||||
printf("found parent: ");
|
printf("found parent: ");
|
||||||
print_data(data);
|
print_name(data);
|
||||||
|
printf("\n\t(foundname: ");
|
||||||
isc_buffer_init(&textname,
|
print_name(foundname);
|
||||||
buffer, 255,
|
printf(")\n");
|
||||||
ISC_BUFFERTYPE_TEXT);
|
|
||||||
dns_name_totext(foundname,
|
|
||||||
ISC_FALSE,
|
|
||||||
&textname);
|
|
||||||
printf("\n\t(foundname: %.*s)\n",
|
|
||||||
(int)textname.used,
|
|
||||||
(char *)textname.base);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case DNS_R_NOTFOUND:
|
case DNS_R_NOTFOUND:
|
||||||
@@ -256,6 +306,21 @@ main (int argc, char **argv) {
|
|||||||
delete_name(name, NULL);
|
delete_name(name, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (CMDCHECK("forward")) {
|
||||||
|
name = create_name(arg);
|
||||||
|
if (name != NULL) {
|
||||||
|
iterate(rbt, name, ISC_TRUE);
|
||||||
|
|
||||||
|
delete_name(name, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (CMDCHECK("backward")) {
|
||||||
|
name = create_name(arg);
|
||||||
|
if (name != NULL) {
|
||||||
|
iterate(rbt, name, ISC_FALSE);
|
||||||
|
|
||||||
|
delete_name(name, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (CMDCHECK("print")) {
|
} else if (CMDCHECK("print")) {
|
||||||
if (arg == NULL || *arg == '\0')
|
if (arg == NULL || *arg == '\0')
|
||||||
|
@@ -16,6 +16,8 @@ search q.d.e.f.vix.com
|
|||||||
search just-parent.a.vix.com
|
search just-parent.a.vix.com
|
||||||
search no-real-parent.vix.com
|
search no-real-parent.vix.com
|
||||||
search does.not.exist.at.all
|
search does.not.exist.at.all
|
||||||
|
forward vix.com.
|
||||||
|
backward g.h.vix.com.
|
||||||
nuke d.e.f.vix.com
|
nuke d.e.f.vix.com
|
||||||
print
|
print
|
||||||
add x.a.vix.com
|
add x.a.vix.com
|
||||||
@@ -34,3 +36,5 @@ add a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.
|
|||||||
add b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.
|
add b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.
|
||||||
print
|
print
|
||||||
quit
|
quit
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user