1999-01-28 23:53:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1999 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stddef.h>
|
1999-01-29 07:05:09 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1999-01-28 23:53:36 +00:00
|
|
|
|
|
|
|
#include <isc/assertions.h>
|
|
|
|
#include <isc/error.h>
|
|
|
|
#include <isc/boolean.h>
|
|
|
|
#include <isc/region.h>
|
|
|
|
|
|
|
|
#include <dns/types.h>
|
|
|
|
#include <dns/result.h>
|
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdataclass.h>
|
|
|
|
#include <dns/rdatatype.h>
|
|
|
|
#include <dns/rdatalist.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/compress.h>
|
|
|
|
#include <dns/db.h>
|
|
|
|
|
1999-01-29 07:05:09 +00:00
|
|
|
static void
|
|
|
|
makename(isc_mem_t *mctx, char *text, dns_name_t *name, dns_name_t *origin) {
|
|
|
|
char b[255];
|
|
|
|
isc_buffer_t source, target;
|
|
|
|
size_t len;
|
|
|
|
isc_region_t r1, r2;
|
|
|
|
dns_result_t result;
|
|
|
|
|
|
|
|
if (origin == NULL)
|
|
|
|
origin = dns_rootname;
|
|
|
|
dns_name_init(name, NULL);
|
|
|
|
len = strlen(text);
|
|
|
|
isc_buffer_init(&source, text, len, ISC_BUFFERTYPE_TEXT);
|
|
|
|
isc_buffer_add(&source, len);
|
|
|
|
isc_buffer_init(&target, b, sizeof b, ISC_BUFFERTYPE_BINARY);
|
|
|
|
result = dns_name_fromtext(name, &source, origin, ISC_FALSE, &target);
|
|
|
|
RUNTIME_CHECK(result == DNS_R_SUCCESS);
|
|
|
|
dns_name_toregion(name, &r1);
|
|
|
|
r2.base = isc_mem_get(mctx, r1.length);
|
|
|
|
RUNTIME_CHECK(r2.base != NULL);
|
|
|
|
r2.length = r1.length;
|
|
|
|
memcpy(r2.base, r1.base, r1.length);
|
|
|
|
dns_name_fromregion(name, &r2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
freename(isc_mem_t *mctx, dns_name_t *name) {
|
|
|
|
isc_region_t r;
|
|
|
|
|
|
|
|
dns_name_toregion(name, &r);
|
|
|
|
isc_mem_put(mctx, r.base, r.length);
|
|
|
|
dns_name_invalidate(name);
|
|
|
|
}
|
|
|
|
|
1999-01-28 23:53:36 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[]) {
|
|
|
|
isc_mem_t *mctx = NULL;
|
|
|
|
dns_db_t *db;
|
|
|
|
dns_dbnode_t *node;
|
|
|
|
dns_result_t result;
|
1999-01-29 07:05:09 +00:00
|
|
|
dns_name_t name, base, *origin;
|
1999-01-28 23:53:36 +00:00
|
|
|
dns_offsets_t offsets;
|
|
|
|
size_t len;
|
1999-01-29 07:05:09 +00:00
|
|
|
isc_buffer_t source, target;
|
1999-01-28 23:53:36 +00:00
|
|
|
char s[1000];
|
1999-01-29 07:05:09 +00:00
|
|
|
char b[255];
|
|
|
|
#if 0
|
|
|
|
FILE *f;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stderr, "usage: db_test filename\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
f = fopen(argv[1], "r");
|
|
|
|
if (f == NULL) {
|
|
|
|
fprintf(stderr, "fopen failed.\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
#endif
|
1999-01-28 23:53:36 +00:00
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
|
|
|
|
|
1999-01-29 07:05:09 +00:00
|
|
|
makename(mctx, "vix.com.", &base, NULL);
|
|
|
|
|
1999-01-28 23:53:36 +00:00
|
|
|
db = NULL;
|
1999-01-29 07:05:09 +00:00
|
|
|
result = dns_db_create(mctx, "rbt", &base, ISC_FALSE, 1, 0, NULL,
|
1999-01-28 23:53:36 +00:00
|
|
|
&db);
|
|
|
|
RUNTIME_CHECK(result == DNS_R_SUCCESS);
|
|
|
|
|
|
|
|
origin = dns_rootname;
|
1999-01-29 07:05:09 +00:00
|
|
|
#if 0
|
|
|
|
while (fgets(s, sizeof s, f) != NULL) {
|
|
|
|
dns_name_init(&name, offsets);
|
1999-01-28 23:53:36 +00:00
|
|
|
len = strlen(s);
|
1999-01-29 07:05:09 +00:00
|
|
|
if (len > 0 && s[len - 1] == '\n') {
|
|
|
|
len--;
|
|
|
|
s[len] = '\0';
|
|
|
|
}
|
1999-01-28 23:53:36 +00:00
|
|
|
isc_buffer_init(&source, s, len, ISC_BUFFERTYPE_TEXT);
|
|
|
|
isc_buffer_add(&source, len);
|
1999-01-29 07:05:09 +00:00
|
|
|
isc_buffer_init(&target, b, sizeof b, ISC_BUFFERTYPE_BINARY);
|
1999-01-28 23:53:36 +00:00
|
|
|
result = dns_name_fromtext(&name, &source, origin, ISC_FALSE,
|
|
|
|
&target);
|
1999-01-29 07:05:09 +00:00
|
|
|
if (result != DNS_R_SUCCESS) {
|
|
|
|
printf("bad db name: %s\n", dns_result_totext(result));
|
|
|
|
continue;
|
|
|
|
}
|
1999-01-28 23:53:36 +00:00
|
|
|
node = NULL;
|
|
|
|
result = dns_db_findnode(db, &name, ISC_TRUE, &node);
|
|
|
|
RUNTIME_CHECK(result == DNS_R_SUCCESS);
|
1999-01-29 07:05:09 +00:00
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
result = dns_db_load(db, argv[1]);
|
|
|
|
if (result != DNS_R_SUCCESS) {
|
|
|
|
printf("couldn't load master file: %s\n",
|
|
|
|
dns_result_totext(result));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (gets(s) != NULL) {
|
|
|
|
dns_name_init(&name, offsets);
|
|
|
|
len = strlen(s);
|
|
|
|
isc_buffer_init(&source, s, len, ISC_BUFFERTYPE_TEXT);
|
|
|
|
isc_buffer_add(&source, len);
|
|
|
|
isc_buffer_init(&target, b, sizeof b, ISC_BUFFERTYPE_BINARY);
|
|
|
|
result = dns_name_fromtext(&name, &source, origin, ISC_FALSE,
|
|
|
|
&target);
|
|
|
|
if (result != DNS_R_SUCCESS) {
|
|
|
|
printf("bad name: %s\n", dns_result_totext(result));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
node = NULL;
|
|
|
|
result = dns_db_findnode(db, &name, ISC_FALSE, &node);
|
|
|
|
if (result == DNS_R_NOTFOUND)
|
|
|
|
printf("not found\n");
|
|
|
|
else if (result != DNS_R_SUCCESS)
|
|
|
|
printf("%s\n", dns_result_totext(result));
|
|
|
|
else {
|
|
|
|
printf("success\n");
|
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
}
|
1999-01-28 23:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dns_db_detach(&db);
|
1999-01-29 07:05:09 +00:00
|
|
|
freename(mctx, &base);
|
1999-01-28 23:53:36 +00:00
|
|
|
|
|
|
|
isc_mem_stats(mctx, stdout);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|