master_test.c revision 27ffc5a69779c3c7224580a89aa2bf0a3ff8c16d
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley/*
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * Copyright (C) 1999 Internet Software Consortium.
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley *
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * Permission to use, copy, modify, and distribute this software for any
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * purpose with or without fee is hereby granted, provided that the above
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * copyright notice and this permission notice appear in all copies.
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley *
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * SOFTWARE.
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley */
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews#include <config.h>
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews#include <stdio.h>
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews#include <stdlib.h>
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews#include <isc/mem.h>
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews#include <isc/buffer.h>
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews#include <isc/error.h>
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews#include <dns/master.h>
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews#include <dns/name.h>
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews#include <dns/rdataset.h>
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews#include <dns/result.h>
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews#include <dns/types.h>
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
a01f52a731f03c9d61357ac872f3d228db56a0afBob Halleydns_result_t print_dataset(void *arg, dns_name_t *owner,
a01f52a731f03c9d61357ac872f3d228db56a0afBob Halley dns_rdataset_t *dataset);
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrewsisc_mem_t *mctx;
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrewsdns_result_t
a01f52a731f03c9d61357ac872f3d228db56a0afBob Halleyprint_dataset(void *arg, dns_name_t *owner, dns_rdataset_t *dataset) {
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews char buf[64*1024];
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews isc_buffer_t target;
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews dns_result_t result;
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
a01f52a731f03c9d61357ac872f3d228db56a0afBob Halley arg = arg; /*unused*/
0c67279acb4a6ac356879498b220645755d77cc9Mark Andrews
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews isc_buffer_init(&target, buf, 64*1024, ISC_BUFFERTYPE_TEXT);
8d6024e7cffbd84fa8d06ce50c60307d7b3b49c2Michael Graff result = dns_rdataset_totext(dataset, owner, ISC_FALSE, ISC_FALSE,
8d6024e7cffbd84fa8d06ce50c60307d7b3b49c2Michael Graff &target);
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews if (result == DNS_R_SUCCESS)
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews fprintf(stdout, "%.*s\n", (int)target.used,
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews (char*)target.base);
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews else
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews fprintf(stdout, "dns_rdataset_totext: %s\n",
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews dns_result_totext(result));
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews return (DNS_R_SUCCESS);
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews}
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrewsint
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrewsmain(int argc, char *argv[]) {
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews dns_result_t result;
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews dns_name_t origin;
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews isc_buffer_t source;
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews isc_buffer_t target;
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews unsigned char name_buf[255];
0c67279acb4a6ac356879498b220645755d77cc9Mark Andrews int soacount = 0;
0c67279acb4a6ac356879498b220645755d77cc9Mark Andrews int nscount = 0;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dns_rdatacallbacks_t callbacks;
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews argc = argc;
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews if (argv[1]) {
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews isc_buffer_init(&source, argv[1], strlen(argv[1]),
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews ISC_BUFFERTYPE_TEXT);
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews isc_buffer_add(&source, strlen(argv[1]));
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews isc_buffer_setactive(&source, strlen(argv[1]));
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews isc_buffer_init(&target, name_buf, 255, ISC_BUFFERTYPE_BINARY);
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews dns_name_init(&origin, NULL);
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews result = dns_name_fromtext(&origin, &source, dns_rootname,
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews ISC_FALSE, &target);
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews if (result != DNS_R_SUCCESS) {
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews fprintf(stdout, "dns_name_fromtext: %s\n",
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews dns_result_totext(result));
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews exit(1);
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews }
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews dns_rdatacallbacks_init(&callbacks);
a01f52a731f03c9d61357ac872f3d228db56a0afBob Halley callbacks.add = print_dataset;
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews
27ffc5a69779c3c7224580a89aa2bf0a3ff8c16dBob Halley result = dns_master_loadfile(argv[1], &origin, &origin, 1,
27ffc5a69779c3c7224580a89aa2bf0a3ff8c16dBob Halley ISC_FALSE,
27ffc5a69779c3c7224580a89aa2bf0a3ff8c16dBob Halley &soacount, &nscount,
27ffc5a69779c3c7224580a89aa2bf0a3ff8c16dBob Halley &callbacks, mctx);
27ffc5a69779c3c7224580a89aa2bf0a3ff8c16dBob Halley fprintf(stdout, "dns_master_loadfile: %s\n",
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews dns_result_totext(result));
0c67279acb4a6ac356879498b220645755d77cc9Mark Andrews if (result == DNS_R_SUCCESS)
0c67279acb4a6ac356879498b220645755d77cc9Mark Andrews fprintf(stdout, "soacount = %d, nscount = %d\n",
0c67279acb4a6ac356879498b220645755d77cc9Mark Andrews soacount, nscount);
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews }
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews exit(0);
3ff55a3111fe09f517218905248974b8319b2c59Mark Andrews}