1/*	$NetBSD: master_test.c,v 1.2.6.1 2012/06/05 21:15:19 bouyer Exp $	*/
2
3/*
4 * Copyright (C) 2004, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2001  Internet Software Consortium.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19
20/* Id: master_test.c,v 1.32 2009/09/02 23:48:01 tbox Exp  */
21
22#include <config.h>
23
24#include <stdlib.h>
25#include <string.h>
26
27#include <isc/buffer.h>
28#include <isc/mem.h>
29#include <isc/util.h>
30
31#include <dns/callbacks.h>
32#include <dns/master.h>
33#include <dns/name.h>
34#include <dns/rdataset.h>
35#include <dns/result.h>
36
37isc_mem_t *mctx;
38
39static isc_result_t
40print_dataset(void *arg, dns_name_t *owner, dns_rdataset_t *dataset) {
41	char buf[64*1024];
42	isc_buffer_t target;
43	isc_result_t result;
44
45	UNUSED(arg);
46
47	isc_buffer_init(&target, buf, 64*1024);
48	result = dns_rdataset_totext(dataset, owner, ISC_FALSE, ISC_FALSE,
49				     &target);
50	if (result == ISC_R_SUCCESS)
51		fprintf(stdout, "%.*s\n", (int)target.used,
52					  (char*)target.base);
53	else
54		fprintf(stdout, "dns_rdataset_totext: %s\n",
55			dns_result_totext(result));
56
57	return (ISC_R_SUCCESS);
58}
59
60int
61main(int argc, char *argv[]) {
62	isc_result_t result;
63	dns_name_t origin;
64	isc_buffer_t source;
65	isc_buffer_t target;
66	unsigned char name_buf[255];
67	dns_rdatacallbacks_t callbacks;
68
69	UNUSED(argc);
70
71	RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
72
73	if (argv[1]) {
74		isc_buffer_init(&source, argv[1], strlen(argv[1]));
75		isc_buffer_add(&source, strlen(argv[1]));
76		isc_buffer_setactive(&source, strlen(argv[1]));
77		isc_buffer_init(&target, name_buf, 255);
78		dns_name_init(&origin, NULL);
79		result = dns_name_fromtext(&origin, &source, dns_rootname,
80					   0, &target);
81		if (result != ISC_R_SUCCESS) {
82			fprintf(stdout, "dns_name_fromtext: %s\n",
83				dns_result_totext(result));
84			exit(1);
85		}
86
87		dns_rdatacallbacks_init_stdio(&callbacks);
88		callbacks.add = print_dataset;
89
90		result = dns_master_loadfile(argv[1], &origin, &origin,
91					     dns_rdataclass_in, 0,
92					     &callbacks, mctx);
93		fprintf(stdout, "dns_master_loadfile: %s\n",
94			dns_result_totext(result));
95	}
96	return (0);
97}
98