master_test.c revision 9a791981764b0e19e0e48f6bd55edf5ad5272f4b
20a96edbf9894e327a99f21acf3571422df5c7b0Tinderbox User/*
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Copyright (C) 1999 Internet Software Consortium.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Permission to use, copy, modify, and distribute this software for any
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * purpose with or without fee is hereby granted, provided that the above
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * copyright notice and this permission notice appear in all copies.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
f97d56e757b9a293ffbaa915ca4d792ae84ba85aTinderbox User * SOFTWARE.
f97d56e757b9a293ffbaa915ca4d792ae84ba85aTinderbox User */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#include <config.h>
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#include <stdio.h>
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#include <stdlib.h>
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#include <string.h>
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt#include <isc/mem.h>
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt#include <isc/buffer.h>
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt#include <isc/error.h>
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt#include <dns/master.h>
3d751891410f9892ca1c1deba2f7d8556ae91b0cMark Andrews#include <dns/name.h>
ac5ed748602c890d596bed07b0b23b8b5f42b2f6Mark Andrews#include <dns/rdataset.h>
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#include <dns/result.h>
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver#include <dns/types.h>
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntisc_result_t print_dataset(void *arg, dns_name_t *owner,
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_rdataset_t *dataset);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsisc_mem_t *mctx;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsisc_result_t
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsprint_dataset(void *arg, dns_name_t *owner, dns_rdataset_t *dataset) {
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews char buf[64*1024];
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_buffer_t target;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_result_t result;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews arg = arg; /*unused*/
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_buffer_init(&target, buf, 64*1024, ISC_BUFFERTYPE_TEXT);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews result = dns_rdataset_totext(dataset, owner, ISC_FALSE, ISC_FALSE,
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews &target);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (result == DNS_R_SUCCESS)
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt fprintf(stdout, "%.*s\n", (int)target.used,
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt (char*)target.base);
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt else
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt fprintf(stdout, "dns_rdataset_totext: %s\n",
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt dns_result_totext(result));
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt return (DNS_R_SUCCESS);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverint
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryvermain(int argc, char *argv[]) {
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt isc_result_t result;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt dns_name_t origin;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt isc_buffer_t source;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt isc_buffer_t target;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt unsigned char name_buf[255];
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt int soacount = 0;
06e28e50bd06bf3127b560c97a81f67306bacb02Mark Andrews int nscount = 0;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt dns_rdatacallbacks_t callbacks;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt argc = argc;
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver if (argv[1]) {
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_buffer_init(&source, argv[1], strlen(argv[1]),
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver ISC_BUFFERTYPE_TEXT);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver isc_buffer_add(&source, strlen(argv[1]));
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver isc_buffer_setactive(&source, strlen(argv[1]));
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver isc_buffer_init(&target, name_buf, 255, ISC_BUFFERTYPE_BINARY);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver dns_name_init(&origin, NULL);
88112d5fcb6b9e1d0f80105a9d2a6f09440c2401Mark Andrews result = dns_name_fromtext(&origin, &source, dns_rootname,
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver ISC_FALSE, &target);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver if (result != DNS_R_SUCCESS) {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver fprintf(stdout, "dns_name_fromtext: %s\n",
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_result_totext(result));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews exit(1);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews }
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt dns_rdatacallbacks_init_stdio(&callbacks);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews callbacks.add = print_dataset;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews result = dns_master_loadfile(argv[1], &origin, &origin, 1,
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver ISC_FALSE,
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver &soacount, &nscount,
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver &callbacks, mctx);
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt fprintf(stdout, "dns_master_loadfile: %s\n",
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt dns_result_totext(result));
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt if (result == DNS_R_SUCCESS)
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver fprintf(stdout, "soacount = %d, nscount = %d\n",
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt soacount, nscount);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver }
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt return (0);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver}
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver