diff options
author | Internet Software Consortium, Inc <@isc.org> | 2007-09-07 14:11:04 -0600 |
---|---|---|
committer | LaMont Jones <lamont@debian.org> | 2007-09-07 14:11:04 -0600 |
commit | 4dd5eedee98c3fc2f40a45078bc7006cd5efd7f0 (patch) | |
tree | 85b4b951eb54c6a7d489139cdc8f8a0b1fb87eeb /bin/tests/cfg_test.c | |
parent | e71238b670ee683d2177c93695465bb6b181c4b8 (diff) | |
download | bind9-4dd5eedee98c3fc2f40a45078bc7006cd5efd7f0.tar.gz |
9.2.0a1
Diffstat (limited to 'bin/tests/cfg_test.c')
-rw-r--r-- | bin/tests/cfg_test.c | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/bin/tests/cfg_test.c b/bin/tests/cfg_test.c new file mode 100644 index 00000000..fd496b51 --- /dev/null +++ b/bin/tests/cfg_test.c @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2001 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. + */ + +/* $Id: cfg_test.c,v 1.9 2001/05/31 11:00:40 tale Exp $ */ + +#include <config.h> + +#include <errno.h> +#include <stdlib.h> + +#include <isc/mem.h> +#include <isc/string.h> +#include <isc/util.h> + +#include <isccfg/cfg.h> + +#include <dns/log.h> + +static void +check_result(isc_result_t result, const char *format, ...) { + va_list args; + + if (result == ISC_R_SUCCESS) + return; + + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + fprintf(stderr, ": %s\n", isc_result_totext(result)); + exit(1); +} + +static void +output(void *closure, const char *text, int textlen) { + UNUSED(closure); + (void) fwrite(text, 1, textlen, stdout); +} + +static void +usage() { + fprintf(stderr, "usage: cfg_test --rndc|--named conffile\n"); + exit(1); +} + +int +main(int argc, char **argv) { + isc_result_t result; + isc_mem_t *mctx = NULL; + isc_log_t *lctx = NULL; + isc_logconfig_t *lcfg = NULL; + isc_logdestination_t destination; + cfg_parser_t *pctx = NULL; + cfg_obj_t *cfg = NULL; + cfg_type_t *type = NULL; + + RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + + result = isc_log_create(mctx, &lctx, &lcfg); + check_result(result, "isc_log_create()"); + isc_log_setcontext(lctx); + + /* + * Create and install the default channel. + */ + destination.file.stream = stderr; + destination.file.name = NULL; + destination.file.versions = ISC_LOG_ROLLNEVER; + destination.file.maximum_size = 0; + result = isc_log_createchannel(lcfg, "_default", + ISC_LOG_TOFILEDESC, + ISC_LOG_DYNAMIC, + &destination, ISC_LOG_PRINTTIME); + check_result(result, "isc_log_createchannel()"); + result = isc_log_usechannel(lcfg, "_default", NULL, NULL); + check_result(result, "isc_log_usechannel()"); + + /* + * Set the initial debug level. + */ + isc_log_setdebuglevel(lctx, 2); + + if (argc < 3) + usage(); + + if (strcmp(argv[1], "--named") == 0) + type = &cfg_type_namedconf; + else if (strcmp(argv[1], "--rndc") == 0) + type = &cfg_type_rndcconf; + else + usage(); + + RUNTIME_CHECK(cfg_parser_create(mctx, lctx, &pctx) == ISC_R_SUCCESS); + + result = cfg_parse_file(pctx, argv[2], type, &cfg); + + fprintf(stderr, "read config: %s\n", isc_result_totext(result)); + + if (result != ISC_R_SUCCESS) + exit(1); + + cfg_print(cfg, output, NULL); + + cfg_obj_destroy(pctx, &cfg); + + cfg_parser_destroy(&pctx); + + isc_log_destroy(&lctx); + isc_mem_stats(mctx, stderr); + isc_mem_destroy(&mctx); + + return (0); +} |