added test program for new configuration parser
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: Makefile.in,v 1.107 2001/02/01 23:41:40 sjacob Exp $
|
||||
# $Id: Makefile.in,v 1.108 2001/02/15 05:15:27 gson Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
@@ -21,19 +21,21 @@ top_srcdir = @top_srcdir@
|
||||
|
||||
@BIND9_INCLUDES@
|
||||
|
||||
CINCLUDES = ${DNS_INCLUDES} ${ISC_INCLUDES} ${LWRES_INCLUDES} \
|
||||
${OMAPI_INCLUDES}
|
||||
CINCLUDES = ${DNS_INCLUDES} ${ISC_INCLUDES} ${ISCCFG_INCLUDES} \
|
||||
${LWRES_INCLUDES} ${OMAPI_INCLUDES}
|
||||
|
||||
CDEFINES =
|
||||
CWARNINGS =
|
||||
|
||||
DNSLIBS = ../../lib/dns/libdns.@A@ @DNS_OPENSSL_LIBS@ @DNS_GSSAPI_LIBS@
|
||||
ISCLIBS = ../../lib/isc/libisc.@A@
|
||||
ISCCFGLIBS = ../../lib/isccfg/libisccfg.@A@
|
||||
OMAPILIBS = ../../lib/omapi/libomapi.@A@
|
||||
LWRESLIBS = ../../lib/lwres/liblwres.@A@
|
||||
|
||||
DNSDEPLIBS = ../../lib/dns/libdns.@A@
|
||||
ISCDEPLIBS = ../../lib/isc/libisc.@A@
|
||||
ISCCFGDEPLIBS = ../../lib/isccfg/libisccfg.@A@
|
||||
OMAPIDEPLIBS = ../../lib/omapi/libomapi.@A@
|
||||
LWRESDEPLIBS = ../../lib/lwres/liblwres.@A@
|
||||
|
||||
@@ -47,6 +49,7 @@ TARGETS = genrandom
|
||||
XTARGETS = adb_test \
|
||||
byaddr_test \
|
||||
byname_test \
|
||||
cfg_test \
|
||||
compress_test \
|
||||
db_test \
|
||||
dispatch_tcp_test \
|
||||
@@ -301,6 +304,10 @@ journalprint: journalprint.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL} ${PURIFY} ${CC} ${CFLAGS} -o $@ journalprint.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
cfg_test: cfg_test.@O@ ${ISCCFGDEPLIBS} ${ISCDEPLIBS}
|
||||
${LIBTOOL} ${CC} ${CFLAGS} -o $@ cfg_test.@O@ \
|
||||
${ISCCFGLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
distclean::
|
||||
rm -f headerdep_test.sh
|
||||
|
||||
|
||||
146
bin/tests/cfg_test.c
Normal file
146
bin/tests/cfg_test.c
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (C) 1999, 2000 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.1 2001/02/15 05:15:27 gson 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>
|
||||
#include <dns/namedconf.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;
|
||||
|
||||
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);
|
||||
|
||||
#if 1
|
||||
/* Example of how to extract stuff from a configuration. */
|
||||
{
|
||||
cfg_obj_t *options = NULL;
|
||||
cfg_obj_t *version = NULL;
|
||||
|
||||
result = cfg_map_get(cfg, "options", &options);
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
result = cfg_map_get(options, "version", &version);
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
fprintf(stderr, "(server version is \"%s\")\n",
|
||||
cfg_obj_asstring(version));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
cfg_obj_destroy(pctx, &cfg);
|
||||
|
||||
cfg_parser_destroy(&pctx);
|
||||
|
||||
isc_log_destroy(&lctx);
|
||||
isc_mem_stats(mctx, stderr);
|
||||
isc_mem_destroy(&mctx);
|
||||
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user