[master] add cfg_parse_buffer3() function with linenum parameter

4482.	[cleanup]	Change #4455 was incomplete. [RT #43252]
This commit is contained in:
Evan Hunt 2016-10-10 17:11:21 -07:00
parent d3f29e7a4f
commit 676ac3cc82
15 changed files with 511 additions and 31 deletions

View file

@ -1,3 +1,5 @@
4482. [cleanup] Change #4455 was incomplete. [RT #43252]
4481. [func] dig: make +class, +crypto, +multiline, +rrcomments,
+onesoa, +qr, +ttlid, +ttlunits and -u per lookup
rather than global. [RT #42450]

View file

@ -305,7 +305,7 @@ ns_config_parsedefaults(cfg_parser_t *parser, cfg_obj_t **conf) {
isc_buffer_init(&b, defaultconf, sizeof(defaultconf) - 1);
isc_buffer_add(&b, sizeof(defaultconf) - 1);
return (cfg_parse_buffer2(parser, &b, __FILE__,
return (cfg_parse_buffer3(parser, &b, __FILE__, 0,
&cfg_type_namedconf, conf));
}

View file

@ -2123,7 +2123,7 @@ catz_addmodzone_taskaction(isc_task_t *task, isc_event_t *event0) {
confbuf = NULL;
dns_catz_generate_zonecfg(ev->origin, ev->entry, &confbuf);
cfg_parser_reset(cfg->add_parser);
result = cfg_parse_buffer2(cfg->add_parser, confbuf, "catz",
result = cfg_parse_buffer3(cfg->add_parser, confbuf, "catz", 0,
&cfg_type_addzoneconf, &zoneconf);
isc_buffer_free(&confbuf);
if (result != ISC_R_SUCCESS) {
@ -6738,7 +6738,7 @@ data_to_cfg(dns_view_t *view, MDB_val *key, MDB_val *data,
putstr(text, ";\n");
cfg_parser_reset(ns_g_addparser);
result = cfg_parse_buffer2(ns_g_addparser, *text, zone_name,
result = cfg_parse_buffer3(ns_g_addparser, *text, zone_name, 0,
&cfg_type_addzoneconf, &zoneconf);
if (result != ISC_R_SUCCESS) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
@ -11296,8 +11296,8 @@ newzone_parse(ns_server_t *server, char *command, dns_view_t **viewp,
isc_buffer_forward(&argbuf, 3);
cfg_parser_reset(ns_g_addparser);
CHECK(cfg_parse_buffer2(ns_g_addparser, &argbuf, bn,
&cfg_type_addzoneconf, &zoneconf));
CHECK(cfg_parse_buffer3(ns_g_addparser, &argbuf, bn, 0,
&cfg_type_addzoneconf, &zoneconf));
CHECK(cfg_map_get(zoneconf, "zone", &zlist));
if (! cfg_obj_islist(zlist))
CHECK(ISC_R_FAILURE);

3
configure vendored
View file

@ -23168,7 +23168,7 @@ ac_config_commands="$ac_config_commands chmod"
# elsewhere if there's a good reason for doing so.
#
ac_config_files="$ac_config_files make/Makefile make/mkdep Makefile bin/Makefile bin/check/Makefile bin/confgen/Makefile bin/confgen/unix/Makefile bin/delv/Makefile bin/dig/Makefile bin/dnssec/Makefile bin/named/Makefile bin/named/unix/Makefile bin/nsupdate/Makefile bin/pkcs11/Makefile bin/python/Makefile bin/python/isc/Makefile bin/python/isc/utils.py bin/python/isc/tests/Makefile bin/python/dnssec-checkds.py bin/python/dnssec-coverage.py bin/python/dnssec-keymgr.py bin/python/isc/__init__.py bin/python/isc/checkds.py bin/python/isc/coverage.py bin/python/isc/dnskey.py bin/python/isc/eventlist.py bin/python/isc/keydict.py bin/python/isc/keyevent.py bin/python/isc/keymgr.py bin/python/isc/keyseries.py bin/python/isc/keyzone.py bin/python/isc/policy.py bin/python/isc/rndc.py bin/python/isc/tests/dnskey_test.py bin/python/isc/tests/policy_test.py bin/rndc/Makefile bin/tests/Makefile bin/tests/atomic/Makefile bin/tests/db/Makefile bin/tests/dst/Makefile bin/tests/dst/Kdh.+002+18602.key bin/tests/dst/Kdh.+002+18602.private bin/tests/dst/Kdh.+002+48957.key bin/tests/dst/Kdh.+002+48957.private bin/tests/dst/Ktest.+001+00002.key bin/tests/dst/Ktest.+001+54622.key bin/tests/dst/Ktest.+001+54622.private bin/tests/dst/Ktest.+003+23616.key bin/tests/dst/Ktest.+003+23616.private bin/tests/dst/Ktest.+003+49667.key bin/tests/dst/dst_2_data bin/tests/dst/t2_data_1 bin/tests/dst/t2_data_2 bin/tests/dst/t2_dsasig bin/tests/dst/t2_rsasig bin/tests/hashes/Makefile bin/tests/headerdep_test.sh bin/tests/master/Makefile bin/tests/mem/Makefile bin/tests/names/Makefile bin/tests/net/Makefile bin/tests/pkcs11/Makefile bin/tests/pkcs11/benchmarks/Makefile bin/tests/rbt/Makefile bin/tests/resolver/Makefile bin/tests/sockaddr/Makefile bin/tests/system/Makefile bin/tests/system/builtin/Makefile bin/tests/system/conf.sh bin/tests/system/dlz/prereq.sh bin/tests/system/dlzexternal/Makefile bin/tests/system/dlzexternal/ns1/named.conf bin/tests/system/dyndb/Makefile bin/tests/system/dyndb/driver/Makefile bin/tests/system/filter-aaaa/Makefile bin/tests/system/geoip/Makefile bin/tests/system/inline/checkdsa.sh bin/tests/system/lwresd/Makefile bin/tests/system/pipelined/Makefile bin/tests/system/resolver/Makefile bin/tests/system/rndc/Makefile bin/tests/system/rpz/Makefile bin/tests/system/rsabigexponent/Makefile bin/tests/system/statistics/Makefile bin/tests/system/tkey/Makefile bin/tests/system/tsiggss/Makefile bin/tests/tasks/Makefile bin/tests/timers/Makefile bin/tests/virtual-time/Makefile bin/tests/virtual-time/conf.sh bin/tools/Makefile contrib/scripts/check-secure-delegation.pl contrib/scripts/zone-edit.sh doc/Makefile doc/arm/Makefile doc/arm/noteversion.xml doc/arm/pkgversion.xml doc/arm/releaseinfo.xml doc/doxygen/Doxyfile doc/doxygen/Makefile doc/doxygen/doxygen-input-filter doc/misc/Makefile doc/tex/Makefile doc/tex/armstyle.sty doc/xsl/Makefile doc/xsl/isc-docbook-chunk.xsl doc/xsl/isc-docbook-html.xsl doc/xsl/isc-manpage.xsl doc/xsl/isc-notes-html.xsl isc-config.sh lib/Makefile lib/bind9/Makefile lib/bind9/include/Makefile lib/bind9/include/bind9/Makefile lib/dns/Makefile lib/dns/include/Makefile lib/dns/include/dns/Makefile lib/dns/include/dst/Makefile lib/dns/tests/Makefile lib/irs/Makefile lib/irs/include/Makefile lib/irs/include/irs/Makefile lib/irs/include/irs/netdb.h lib/irs/include/irs/platform.h lib/isc/$arch/Makefile lib/isc/$arch/include/Makefile lib/isc/$arch/include/isc/Makefile lib/isc/$thread_dir/Makefile lib/isc/$thread_dir/include/Makefile lib/isc/$thread_dir/include/isc/Makefile lib/isc/Makefile lib/isc/include/Makefile lib/isc/include/isc/Makefile lib/isc/include/isc/platform.h lib/isc/include/pk11/Makefile lib/isc/include/pkcs11/Makefile lib/isc/tests/Makefile lib/isc/nls/Makefile lib/isc/unix/Makefile lib/isc/unix/include/Makefile lib/isc/unix/include/isc/Makefile lib/isc/unix/include/pkcs11/Makefile lib/isccc/Makefile lib/isccc/include/Makefile lib/isccc/include/isccc/Makefile lib/isccfg/Makefile lib/isccfg/include/Makefile lib/isccfg/include/isccfg/Makefile lib/lwres/Makefile lib/lwres/include/Makefile lib/lwres/include/lwres/Makefile lib/lwres/include/lwres/netdb.h lib/lwres/include/lwres/platform.h lib/lwres/man/Makefile lib/lwres/tests/Makefile lib/lwres/unix/Makefile lib/lwres/unix/include/Makefile lib/lwres/unix/include/lwres/Makefile lib/tests/Makefile lib/tests/include/Makefile lib/tests/include/tests/Makefile lib/samples/Makefile lib/samples/Makefile-postinstall unit/Makefile unit/unittest.sh"
ac_config_files="$ac_config_files make/Makefile make/mkdep Makefile bin/Makefile bin/check/Makefile bin/confgen/Makefile bin/confgen/unix/Makefile bin/delv/Makefile bin/dig/Makefile bin/dnssec/Makefile bin/named/Makefile bin/named/unix/Makefile bin/nsupdate/Makefile bin/pkcs11/Makefile bin/python/Makefile bin/python/isc/Makefile bin/python/isc/utils.py bin/python/isc/tests/Makefile bin/python/dnssec-checkds.py bin/python/dnssec-coverage.py bin/python/dnssec-keymgr.py bin/python/isc/__init__.py bin/python/isc/checkds.py bin/python/isc/coverage.py bin/python/isc/dnskey.py bin/python/isc/eventlist.py bin/python/isc/keydict.py bin/python/isc/keyevent.py bin/python/isc/keymgr.py bin/python/isc/keyseries.py bin/python/isc/keyzone.py bin/python/isc/policy.py bin/python/isc/rndc.py bin/python/isc/tests/dnskey_test.py bin/python/isc/tests/policy_test.py bin/rndc/Makefile bin/tests/Makefile bin/tests/atomic/Makefile bin/tests/db/Makefile bin/tests/dst/Makefile bin/tests/dst/Kdh.+002+18602.key bin/tests/dst/Kdh.+002+18602.private bin/tests/dst/Kdh.+002+48957.key bin/tests/dst/Kdh.+002+48957.private bin/tests/dst/Ktest.+001+00002.key bin/tests/dst/Ktest.+001+54622.key bin/tests/dst/Ktest.+001+54622.private bin/tests/dst/Ktest.+003+23616.key bin/tests/dst/Ktest.+003+23616.private bin/tests/dst/Ktest.+003+49667.key bin/tests/dst/dst_2_data bin/tests/dst/t2_data_1 bin/tests/dst/t2_data_2 bin/tests/dst/t2_dsasig bin/tests/dst/t2_rsasig bin/tests/hashes/Makefile bin/tests/headerdep_test.sh bin/tests/master/Makefile bin/tests/mem/Makefile bin/tests/names/Makefile bin/tests/net/Makefile bin/tests/pkcs11/Makefile bin/tests/pkcs11/benchmarks/Makefile bin/tests/rbt/Makefile bin/tests/resolver/Makefile bin/tests/sockaddr/Makefile bin/tests/system/Makefile bin/tests/system/builtin/Makefile bin/tests/system/conf.sh bin/tests/system/dlz/prereq.sh bin/tests/system/dlzexternal/Makefile bin/tests/system/dlzexternal/ns1/named.conf bin/tests/system/dyndb/Makefile bin/tests/system/dyndb/driver/Makefile bin/tests/system/filter-aaaa/Makefile bin/tests/system/geoip/Makefile bin/tests/system/inline/checkdsa.sh bin/tests/system/lwresd/Makefile bin/tests/system/pipelined/Makefile bin/tests/system/resolver/Makefile bin/tests/system/rndc/Makefile bin/tests/system/rpz/Makefile bin/tests/system/rsabigexponent/Makefile bin/tests/system/statistics/Makefile bin/tests/system/tkey/Makefile bin/tests/system/tsiggss/Makefile bin/tests/tasks/Makefile bin/tests/timers/Makefile bin/tests/virtual-time/Makefile bin/tests/virtual-time/conf.sh bin/tools/Makefile contrib/scripts/check-secure-delegation.pl contrib/scripts/zone-edit.sh doc/Makefile doc/arm/Makefile doc/arm/noteversion.xml doc/arm/pkgversion.xml doc/arm/releaseinfo.xml doc/doxygen/Doxyfile doc/doxygen/Makefile doc/doxygen/doxygen-input-filter doc/misc/Makefile doc/tex/Makefile doc/tex/armstyle.sty doc/xsl/Makefile doc/xsl/isc-docbook-chunk.xsl doc/xsl/isc-docbook-html.xsl doc/xsl/isc-manpage.xsl doc/xsl/isc-notes-html.xsl isc-config.sh lib/Makefile lib/bind9/Makefile lib/bind9/include/Makefile lib/bind9/include/bind9/Makefile lib/dns/Makefile lib/dns/include/Makefile lib/dns/include/dns/Makefile lib/dns/include/dst/Makefile lib/dns/tests/Makefile lib/irs/Makefile lib/irs/include/Makefile lib/irs/include/irs/Makefile lib/irs/include/irs/netdb.h lib/irs/include/irs/platform.h lib/isc/$arch/Makefile lib/isc/$arch/include/Makefile lib/isc/$arch/include/isc/Makefile lib/isc/$thread_dir/Makefile lib/isc/$thread_dir/include/Makefile lib/isc/$thread_dir/include/isc/Makefile lib/isc/Makefile lib/isc/include/Makefile lib/isc/include/isc/Makefile lib/isc/include/isc/platform.h lib/isc/include/pk11/Makefile lib/isc/include/pkcs11/Makefile lib/isc/tests/Makefile lib/isc/nls/Makefile lib/isc/unix/Makefile lib/isc/unix/include/Makefile lib/isc/unix/include/isc/Makefile lib/isc/unix/include/pkcs11/Makefile lib/isccc/Makefile lib/isccc/include/Makefile lib/isccc/include/isccc/Makefile lib/isccfg/Makefile lib/isccfg/include/Makefile lib/isccfg/include/isccfg/Makefile lib/isccfg/tests/Makefile lib/lwres/Makefile lib/lwres/include/Makefile lib/lwres/include/lwres/Makefile lib/lwres/include/lwres/netdb.h lib/lwres/include/lwres/platform.h lib/lwres/man/Makefile lib/lwres/tests/Makefile lib/lwres/unix/Makefile lib/lwres/unix/include/Makefile lib/lwres/unix/include/lwres/Makefile lib/tests/Makefile lib/tests/include/Makefile lib/tests/include/tests/Makefile lib/samples/Makefile lib/samples/Makefile-postinstall unit/Makefile unit/unittest.sh"
#
@ -24310,6 +24310,7 @@ do
"lib/isccfg/Makefile") CONFIG_FILES="$CONFIG_FILES lib/isccfg/Makefile" ;;
"lib/isccfg/include/Makefile") CONFIG_FILES="$CONFIG_FILES lib/isccfg/include/Makefile" ;;
"lib/isccfg/include/isccfg/Makefile") CONFIG_FILES="$CONFIG_FILES lib/isccfg/include/isccfg/Makefile" ;;
"lib/isccfg/tests/Makefile") CONFIG_FILES="$CONFIG_FILES lib/isccfg/tests/Makefile" ;;
"lib/lwres/Makefile") CONFIG_FILES="$CONFIG_FILES lib/lwres/Makefile" ;;
"lib/lwres/include/Makefile") CONFIG_FILES="$CONFIG_FILES lib/lwres/include/Makefile" ;;
"lib/lwres/include/lwres/Makefile") CONFIG_FILES="$CONFIG_FILES lib/lwres/include/lwres/Makefile" ;;

View file

@ -5192,6 +5192,7 @@ AC_CONFIG_FILES([
lib/isccfg/Makefile
lib/isccfg/include/Makefile
lib/isccfg/include/isccfg/Makefile
lib/isccfg/tests/Makefile
lib/lwres/Makefile
lib/lwres/include/Makefile
lib/lwres/include/lwres/Makefile

View file

@ -4,4 +4,5 @@ prop: test-suite = bind9
tp: dns
tp: isc
tp: isccfg
tp: lwres

5
lib/isccfg/Atffile Normal file
View file

@ -0,0 +1,5 @@
Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = bind9
tp: tests

View file

@ -4,8 +4,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# $Id$
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@ -32,6 +30,7 @@ ISCCFGDEPLIBS = libisccfg.@A@
LIBS = @LIBS@
SUBDIRS = include
TESTDIRS = @UNITTESTS@
# Alphabetically
OBJS = aclconf.@O@ dnsconf.@O@ log.@O@ namedconf.@O@ \

View file

@ -106,15 +106,20 @@ cfg_parser_setcallback(cfg_parser_t *pctx,
*/
isc_result_t
cfg_parse_file(cfg_parser_t *pctx, const char *filename,
cfg_parse_file(cfg_parser_t *pctx, const char *file,
const cfg_type_t *type, cfg_obj_t **ret);
isc_result_t
cfg_parse_buffer(cfg_parser_t *pctx, isc_buffer_t *buffer,
const cfg_type_t *type, cfg_obj_t **ret);
isc_result_t
cfg_parse_buffer2(cfg_parser_t *pctx, isc_buffer_t *buffer,
const char *bufname, const cfg_type_t *type,
const char *file, const cfg_type_t *type,
cfg_obj_t **ret);
isc_result_t
cfg_parse_buffer3(cfg_parser_t *pctx, isc_buffer_t *buffer,
const char *file, unsigned int line,
const cfg_type_t *type, cfg_obj_t **ret);
/*%<
* Read a configuration containing data of type 'type'
* and make '*ret' point to its parse tree.
@ -123,10 +128,14 @@ cfg_parse_buffer2(cfg_parser_t *pctx, isc_buffer_t *buffer,
* (isc_parse_file()) or the buffer 'buffer'
* (isc_parse_buffer()).
*
* If 'bufname' is not NULL, it is a name for the buffer that
* can be reported when logging errors.
* If 'file' is not NULL, it is the name of the file, or a name to use
* for the buffer in place of the filename, when logging errors.
*
* Returns an error if the file does not parse correctly.
* If 'line' is not 0, then it is the beginning line number to report
* when logging errors. This is useful when passing text that has been
* read from the middle of a file.
*
* Returns an error if the file or buffer does not parse correctly.
*
* Requires:
*\li "filename" is valid.

View file

@ -1306,7 +1306,7 @@ cfg_parse_rpz_policy(cfg_parser_t *pctx, const cfg_type_t *type,
cfg_obj_t **ret)
{
isc_result_t result;
cfg_obj_t *obj;
cfg_obj_t *obj = NULL;
const cfg_tuplefielddef_t *fields;
CHECK(cfg_create_tuple(pctx, type, &obj));
@ -1338,11 +1338,10 @@ cleanup:
static isc_result_t
cfg_parse_kv_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
const cfg_tuplefielddef_t *fields, *f;
cfg_obj_t *obj;
cfg_obj_t *obj = NULL;
int fn;
isc_result_t result;
obj = NULL;
CHECK(cfg_create_tuple(pctx, type, &obj));
/*

View file

@ -133,11 +133,17 @@ static cfg_type_t cfg_type_implicitlist = {
void
cfg_print_obj(cfg_printer_t *pctx, const cfg_obj_t *obj) {
REQUIRE(pctx != NULL);
REQUIRE(obj != NULL);
obj->type->print(pctx, obj);
}
void
cfg_print_chars(cfg_printer_t *pctx, const char *text, int len) {
REQUIRE(pctx != NULL);
REQUIRE(text != NULL);
pctx->f(pctx->closure, text, len);
}
@ -176,11 +182,15 @@ print_close(cfg_printer_t *pctx) {
isc_result_t
cfg_parse_obj(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
isc_result_t result;
INSIST(ret != NULL && *ret == NULL);
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
result = type->parse(pctx, type, ret);
if (result != ISC_R_SUCCESS)
return (result);
INSIST(*ret != NULL);
ENSURE(*ret != NULL);
return (ISC_R_SUCCESS);
}
@ -189,6 +199,9 @@ cfg_print(const cfg_obj_t *obj,
void (*f)(void *closure, const char *text, int textlen),
void *closure)
{
REQUIRE(obj != NULL);
REQUIRE(f != NULL);
cfg_printx(obj, 0, f, closure);
}
@ -198,6 +211,10 @@ cfg_printx(const cfg_obj_t *obj, unsigned int flags,
void *closure)
{
cfg_printer_t pctx;
REQUIRE(obj != NULL);
REQUIRE(f != NULL);
pctx.f = f;
pctx.closure = closure;
pctx.indent = 0;
@ -216,6 +233,10 @@ cfg_create_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
unsigned int nfields = 0;
int i;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
for (f = fields; f->name != NULL; f++)
nfields++;
@ -246,6 +267,10 @@ cfg_parse_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret)
cfg_obj_t *obj = NULL;
unsigned int i;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
CHECK(cfg_create_tuple(pctx, type, &obj));
for (f = fields, i = 0; f->name != NULL; f++, i++)
CHECK(cfg_parse_obj(pctx, f->type, &obj->value.tuple[i]));
@ -261,10 +286,15 @@ cfg_parse_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret)
void
cfg_print_tuple(cfg_printer_t *pctx, const cfg_obj_t *obj) {
unsigned int i;
const cfg_tuplefielddef_t *fields = obj->type->of;
const cfg_tuplefielddef_t *fields;
const cfg_tuplefielddef_t *f;
isc_boolean_t need_space = ISC_FALSE;
REQUIRE(pctx != NULL);
REQUIRE(obj != NULL);
fields = obj->type->of;
for (f = fields, i = 0; f->name != NULL; f++, i++) {
const cfg_obj_t *fieldobj = obj->value.tuple[i];
if (need_space && fieldobj->type->rep != &cfg_rep_void)
@ -281,6 +311,11 @@ cfg_doc_tuple(cfg_printer_t *pctx, const cfg_type_t *type) {
const cfg_tuplefielddef_t *f;
isc_boolean_t need_space = ISC_FALSE;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
fields = type->of;
for (f = fields; f->name != NULL; f++) {
if (need_space)
cfg_print_cstr(pctx, " ");
@ -320,6 +355,7 @@ cfg_tuple_get(const cfg_obj_t *tupleobj, const char* name) {
const cfg_tuplefielddef_t *f;
REQUIRE(tupleobj != NULL && tupleobj->type->rep == &cfg_rep_tuple);
REQUIRE(name != NULL);
fields = tupleobj->type->of;
for (f = fields, i = 0; f->name != NULL; f++, i++) {
@ -333,6 +369,9 @@ cfg_tuple_get(const cfg_obj_t *tupleobj, const char* name) {
isc_result_t
cfg_parse_special(cfg_parser_t *pctx, int special) {
isc_result_t result;
REQUIRE(pctx != NULL);
CHECK(cfg_gettoken(pctx, 0));
if (pctx->token.type == isc_tokentype_special &&
pctx->token.value.as_char == special)
@ -354,6 +393,7 @@ cfg_parse_special(cfg_parser_t *pctx, int special) {
static isc_result_t
parse_semicolon(cfg_parser_t *pctx) {
isc_result_t result;
CHECK(cfg_gettoken(pctx, 0));
if (pctx->token.type == isc_tokentype_special &&
pctx->token.value.as_char == ';')
@ -371,6 +411,7 @@ parse_semicolon(cfg_parser_t *pctx) {
static isc_result_t
parse_eof(cfg_parser_t *pctx) {
isc_result_t result;
CHECK(cfg_gettoken(pctx, 0));
if (pctx->token.type == isc_tokentype_eof)
@ -396,6 +437,7 @@ cfg_parser_create(isc_mem_t *mctx, isc_log_t *lctx, cfg_parser_t **ret) {
isc_lexspecials_t specials;
REQUIRE(mctx != NULL);
REQUIRE(lctx != NULL);
REQUIRE(ret != NULL && *ret == NULL);
pctx = isc_mem_get(mctx, sizeof(*pctx));
@ -485,6 +527,8 @@ cfg_parser_setcallback(cfg_parser_t *pctx,
cfg_parsecallback_t callback,
void *arg)
{
REQUIRE(pctx != NULL);
pctx->callback = callback;
pctx->callbackarg = arg;
}
@ -544,7 +588,10 @@ cfg_parse_file(cfg_parser_t *pctx, const char *filename,
isc_result_t result;
cfg_listelt_t *elt;
REQUIRE(pctx != NULL);
REQUIRE(filename != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
CHECK(parser_openfile(pctx, filename));
@ -565,20 +612,36 @@ isc_result_t
cfg_parse_buffer(cfg_parser_t *pctx, isc_buffer_t *buffer,
const cfg_type_t *type, cfg_obj_t **ret)
{
return (cfg_parse_buffer2(pctx, buffer, NULL, type, ret));
return (cfg_parse_buffer3(pctx, buffer, NULL, 0, type, ret));
}
isc_result_t
cfg_parse_buffer2(cfg_parser_t *pctx, isc_buffer_t *buffer,
const char *bufname, const cfg_type_t *type,
const char *file, const cfg_type_t *type,
cfg_obj_t **ret)
{
return (cfg_parse_buffer3(pctx, buffer, file, 0, type, ret));
}
isc_result_t
cfg_parse_buffer3(cfg_parser_t *pctx, isc_buffer_t *buffer,
const char *file, unsigned int line,
const cfg_type_t *type, cfg_obj_t **ret)
{
isc_result_t result;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
REQUIRE(buffer != NULL);
REQUIRE(ret != NULL && *ret == NULL);
CHECK(isc_lex_openbuffer(pctx->lexer, buffer));
pctx->buf_name = bufname;
pctx->buf_name = file;
if (line != 0U)
CHECK(isc_lex_setsourceline(pctx->lexer, line));
CHECK(parse2(pctx, type, ret));
pctx->buf_name = NULL;
@ -590,15 +653,21 @@ void
cfg_parser_attach(cfg_parser_t *src, cfg_parser_t **dest) {
REQUIRE(src != NULL);
REQUIRE(dest != NULL && *dest == NULL);
isc_refcount_increment(&src->references, NULL);
*dest = src;
}
void
cfg_parser_destroy(cfg_parser_t **pctxp) {
cfg_parser_t *pctx = *pctxp;
cfg_parser_t *pctx;
unsigned int refs;
REQUIRE(pctxp != NULL && *pctxp != NULL);
pctx = *pctxp;
*pctxp = NULL;
isc_refcount_decrement(&pctx->references, &refs);
if (refs == 0) {
isc_lex_destroy(&pctx->lexer);
@ -611,7 +680,6 @@ cfg_parser_destroy(cfg_parser_t **pctxp) {
CLEANUP_OBJ(pctx->closed_files);
isc_mem_putanddetach(&pctx->mctx, pctx, sizeof(*pctx));
}
*pctxp = NULL;
}
/*
@ -619,18 +687,30 @@ cfg_parser_destroy(cfg_parser_t **pctxp) {
*/
isc_result_t
cfg_parse_void(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
REQUIRE(pctx != NULL);
REQUIRE(ret != NULL && *ret == NULL);
UNUSED(type);
return (cfg_create_obj(pctx, &cfg_type_void, ret));
}
void
cfg_print_void(cfg_printer_t *pctx, const cfg_obj_t *obj) {
REQUIRE(pctx != NULL);
REQUIRE(obj != NULL);
UNUSED(pctx);
UNUSED(obj);
}
void
cfg_doc_void(cfg_printer_t *pctx, const cfg_type_t *type) {
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
UNUSED(pctx);
UNUSED(type);
}
@ -657,6 +737,9 @@ cfg_parse_percentage(cfg_parser_t *pctx, const cfg_type_t *type,
cfg_obj_t *obj = NULL;
isc_uint64_t percent;
REQUIRE(pctx != NULL);
REQUIRE(ret != NULL && *ret == NULL);
UNUSED(type);
CHECK(cfg_gettoken(pctx, 0));
@ -686,6 +769,9 @@ cfg_print_percentage(cfg_printer_t *pctx, const cfg_obj_t *obj) {
char buf[64];
int n;
REQUIRE(pctx != NULL);
REQUIRE(obj != NULL);
n = snprintf(buf, sizeof(buf), "%u%%", obj->value.uint32);
INSIST(n > 0 && (size_t)n < sizeof(buf));
cfg_print_chars(pctx, buf, strlen(buf));
@ -720,6 +806,9 @@ cfg_parse_fixedpoint(cfg_parser_t *pctx, const cfg_type_t *type,
size_t n1, n2, n3, l;
const char *p;
REQUIRE(pctx != NULL);
REQUIRE(ret != NULL && *ret == NULL);
UNUSED(type);
CHECK(cfg_gettoken(pctx, 0));
@ -765,6 +854,9 @@ cfg_print_fixedpoint(cfg_printer_t *pctx, const cfg_obj_t *obj) {
char buf[64];
int n;
REQUIRE(pctx != NULL);
REQUIRE(obj != NULL);
n = snprintf(buf, sizeof(buf), "%u.%02u",
obj->value.uint32/100, obj->value.uint32%100);
INSIST(n > 0 && (size_t)n < sizeof(buf));
@ -795,6 +887,10 @@ isc_result_t
cfg_parse_uint32(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
isc_result_t result;
cfg_obj_t *obj = NULL;
REQUIRE(pctx != NULL);
REQUIRE(ret != NULL && *ret == NULL);
UNUSED(type);
CHECK(cfg_gettoken(pctx, ISC_LEXOPT_NUMBER | ISC_LEXOPT_CNUMBER));
@ -819,6 +915,7 @@ cfg_print_cstr(cfg_printer_t *pctx, const char *s) {
void
cfg_print_rawuint(cfg_printer_t *pctx, unsigned int u) {
char buf[32];
snprintf(buf, sizeof(buf), "%u", u);
cfg_print_cstr(pctx, buf);
}
@ -864,6 +961,7 @@ cfg_obj_asuint64(const cfg_obj_t *obj) {
void
cfg_print_uint64(cfg_printer_t *pctx, const cfg_obj_t *obj) {
char buf[32];
snprintf(buf, sizeof(buf), "%" ISC_PRINT_QUADFORMAT "u",
obj->value.uint64);
cfg_print_cstr(pctx, buf);
@ -907,6 +1005,10 @@ create_string(cfg_parser_t *pctx, const char *contents, const cfg_type_t *type,
isc_result_t
cfg_parse_qstring(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
isc_result_t result;
REQUIRE(pctx != NULL);
REQUIRE(ret != NULL && *ret == NULL);
UNUSED(type);
CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING));
@ -914,10 +1016,8 @@ cfg_parse_qstring(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
cfg_parser_error(pctx, CFG_LOG_NEAR, "expected quoted string");
return (ISC_R_UNEXPECTEDTOKEN);
}
return (create_string(pctx,
TOKEN_STRING(pctx),
&cfg_type_qstring,
ret));
return (create_string(pctx, TOKEN_STRING(pctx),
&cfg_type_qstring, ret));
cleanup:
return (result);
}
@ -925,6 +1025,7 @@ cfg_parse_qstring(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
static isc_result_t
parse_ustring(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
isc_result_t result;
UNUSED(type);
CHECK(cfg_gettoken(pctx, 0));
@ -945,6 +1046,10 @@ cfg_parse_astring(cfg_parser_t *pctx, const cfg_type_t *type,
cfg_obj_t **ret)
{
isc_result_t result;
REQUIRE(pctx != NULL);
REQUIRE(ret != NULL && *ret == NULL);
UNUSED(type);
CHECK(cfg_getstringtoken(pctx));
@ -961,6 +1066,10 @@ cfg_parse_sstring(cfg_parser_t *pctx, const cfg_type_t *type,
cfg_obj_t **ret)
{
isc_result_t result;
REQUIRE(pctx != NULL);
REQUIRE(ret != NULL && *ret == NULL);
UNUSED(type);
CHECK(cfg_getstringtoken(pctx));
@ -977,6 +1086,7 @@ parse_btext(cfg_parser_t *pctx, const cfg_type_t *type,
cfg_obj_t **ret)
{
isc_result_t result;
UNUSED(type);
CHECK(cfg_gettoken(pctx, ISC_LEXOPT_BTEXT));
@ -1011,6 +1121,10 @@ doc_btext(cfg_printer_t *pctx, const cfg_type_t *type) {
isc_boolean_t
cfg_is_enum(const char *s, const char *const *enums) {
const char * const *p;
REQUIRE(s != NULL);
REQUIRE(enums != NULL);
for (p = enums; *p != NULL; p++) {
if (strcasecmp(*p, s) == 0)
return (ISC_TRUE);
@ -1021,6 +1135,7 @@ cfg_is_enum(const char *s, const char *const *enums) {
static isc_result_t
check_enum(cfg_parser_t *pctx, cfg_obj_t *obj, const char *const *enums) {
const char *s = obj->value.string.base;
if (cfg_is_enum(s, enums))
return (ISC_R_SUCCESS);
cfg_parser_error(pctx, 0, "'%s' unexpected", s);
@ -1031,6 +1146,11 @@ isc_result_t
cfg_parse_enum(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
isc_result_t result;
cfg_obj_t *obj = NULL;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
CHECK(parse_ustring(pctx, NULL, &obj));
CHECK(check_enum(pctx, obj, type->of));
*ret = obj;
@ -1043,6 +1163,10 @@ cfg_parse_enum(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
void
cfg_doc_enum(cfg_printer_t *pctx, const cfg_type_t *type) {
const char * const *p;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
cfg_print_cstr(pctx, "( ");
for (p = type->of; *p != NULL; p++) {
cfg_print_cstr(pctx, *p);
@ -1054,6 +1178,9 @@ cfg_doc_enum(cfg_printer_t *pctx, const cfg_type_t *type) {
void
cfg_print_ustring(cfg_printer_t *pctx, const cfg_obj_t *obj) {
REQUIRE(pctx != NULL);
REQUIRE(obj != NULL);
cfg_print_chars(pctx, obj->value.string.base, obj->value.string.length);
}
@ -1153,6 +1280,10 @@ cfg_parse_boolean(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret)
isc_result_t result;
isc_boolean_t value;
cfg_obj_t *obj = NULL;
REQUIRE(pctx != NULL);
REQUIRE(ret != NULL && ret != NULL);
UNUSED(type);
result = cfg_gettoken(pctx, 0);
@ -1189,6 +1320,9 @@ cfg_parse_boolean(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret)
void
cfg_print_boolean(cfg_printer_t *pctx, const cfg_obj_t *obj) {
REQUIRE(pctx != NULL);
REQUIRE(obj != NULL);
if (obj->value.boolean)
cfg_print_cstr(pctx, "yes");
else
@ -1207,6 +1341,11 @@ LIBISCCFG_EXTERNAL_DATA cfg_type_t cfg_type_boolean = {
isc_result_t
cfg_create_list(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **obj) {
isc_result_t result;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
REQUIRE(obj != NULL && *obj == NULL);
CHECK(cfg_create_obj(pctx, type, obj));
ISC_LIST_INIT((*obj)->value.list);
cleanup:
@ -1216,6 +1355,7 @@ cfg_create_list(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **obj) {
static isc_result_t
create_listelt(cfg_parser_t *pctx, cfg_listelt_t **eltp) {
cfg_listelt_t *elt;
elt = isc_mem_get(pctx->mctx, sizeof(*elt));
if (elt == NULL)
return (ISC_R_NOMEMORY);
@ -1252,6 +1392,10 @@ cfg_parse_listelt(cfg_parser_t *pctx, const cfg_type_t *elttype,
cfg_listelt_t *elt = NULL;
cfg_obj_t *value = NULL;
REQUIRE(pctx != NULL);
REQUIRE(elttype != NULL);
REQUIRE(ret != NULL && *ret == NULL);
CHECK(create_listelt(pctx, &elt));
result = cfg_parse_obj(pctx, elttype, &value);
@ -1327,6 +1471,11 @@ cfg_parse_bracketed_list(cfg_parser_t *pctx, const cfg_type_t *type,
cfg_obj_t **ret)
{
isc_result_t result;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
CHECK(cfg_parse_special(pctx, '{'));
CHECK(parse_list(pctx, type, ret));
CHECK(cfg_parse_special(pctx, '}'));
@ -1336,6 +1485,9 @@ cfg_parse_bracketed_list(cfg_parser_t *pctx, const cfg_type_t *type,
void
cfg_print_bracketed_list(cfg_printer_t *pctx, const cfg_obj_t *obj) {
REQUIRE(pctx != NULL);
REQUIRE(obj != NULL);
print_open(pctx);
print_list(pctx, obj);
print_close(pctx);
@ -1343,6 +1495,9 @@ cfg_print_bracketed_list(cfg_printer_t *pctx, const cfg_obj_t *obj) {
void
cfg_doc_bracketed_list(cfg_printer_t *pctx, const cfg_type_t *type) {
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
cfg_print_cstr(pctx, "{ ");
cfg_doc_obj(pctx, type->of);
cfg_print_cstr(pctx, "; ... }");
@ -1361,6 +1516,10 @@ cfg_parse_spacelist(cfg_parser_t *pctx, const cfg_type_t *listtype,
const cfg_type_t *listof = listtype->of;
isc_result_t result;
REQUIRE(pctx != NULL);
REQUIRE(listtype != NULL);
REQUIRE(ret != NULL && *ret == NULL);
CHECK(cfg_create_list(pctx, listtype, &listobj));
for (;;) {
@ -1386,6 +1545,9 @@ cfg_print_spacelist(cfg_printer_t *pctx, const cfg_obj_t *obj) {
const cfg_list_t *list = &obj->value.list;
const cfg_listelt_t *elt;
REQUIRE(pctx != NULL);
REQUIRE(obj != NULL);
for (elt = ISC_LIST_HEAD(*list);
elt != NULL;
elt = ISC_LIST_NEXT(elt, link)) {
@ -1472,6 +1634,10 @@ cfg_parse_mapbody(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret)
isc_symvalue_t symval;
cfg_list_t *list = NULL;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
CHECK(create_map(pctx, type, &obj));
obj->value.map.clausesets = clausesets;
@ -1660,6 +1826,11 @@ parse_symtab_elt(cfg_parser_t *pctx, const char *name,
isc_result_t
cfg_parse_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
isc_result_t result;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
CHECK(cfg_parse_special(pctx, '{'));
CHECK(cfg_parse_mapbody(pctx, type, ret));
CHECK(cfg_parse_special(pctx, '}'));
@ -1671,13 +1842,18 @@ cfg_parse_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
* Subroutine for cfg_parse_named_map() and cfg_parse_addressed_map().
*/
static isc_result_t
parse_any_named_map(cfg_parser_t *pctx, cfg_type_t *nametype, const cfg_type_t *type,
cfg_obj_t **ret)
parse_any_named_map(cfg_parser_t *pctx, cfg_type_t *nametype,
const cfg_type_t *type, cfg_obj_t **ret)
{
isc_result_t result;
cfg_obj_t *idobj = NULL;
cfg_obj_t *mapobj = NULL;
REQUIRE(pctx != NULL);
REQUIRE(nametype != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
CHECK(cfg_parse_obj(pctx, nametype, &idobj));
CHECK(cfg_parse_map(pctx, type, &mapobj));
mapobj->value.map.id = idobj;
@ -1736,6 +1912,9 @@ cfg_print_mapbody(cfg_printer_t *pctx, const cfg_obj_t *obj) {
isc_result_t result = ISC_R_SUCCESS;
const cfg_clausedef_t * const *clauseset;
REQUIRE(pctx != NULL);
REQUIRE(obj != NULL);
for (clauseset = obj->value.map.clausesets;
*clauseset != NULL;
clauseset++)
@ -1780,6 +1959,9 @@ cfg_doc_mapbody(cfg_printer_t *pctx, const cfg_type_t *type) {
const cfg_clausedef_t * const *clauseset;
const cfg_clausedef_t *clause;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
for (clauseset = type->of; *clauseset != NULL; clauseset++) {
for (clause = *clauseset;
clause->name != NULL;
@ -1808,6 +1990,9 @@ static struct flagtext {
void
cfg_print_map(cfg_printer_t *pctx, const cfg_obj_t *obj) {
REQUIRE(pctx != NULL);
REQUIRE(obj != NULL);
if (obj->value.map.id != NULL) {
cfg_print_obj(pctx, obj->value.map.id);
cfg_print_cstr(pctx, " ");
@ -1838,6 +2023,9 @@ cfg_doc_map(cfg_printer_t *pctx, const cfg_type_t *type) {
const cfg_clausedef_t * const *clauseset;
const cfg_clausedef_t *clause;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
if (type->parse == cfg_parse_named_map) {
cfg_doc_obj(pctx, &cfg_type_astring);
cfg_print_cstr(pctx, " ");
@ -1902,7 +2090,9 @@ cfg_map_getname(const cfg_obj_t *mapobj) {
unsigned int
cfg_map_count(const cfg_obj_t *mapobj) {
const cfg_map_t *map;
REQUIRE(mapobj != NULL && mapobj->type->rep == &cfg_rep_map);
map = &mapobj->value.map;
return (isc_symtab_count(map->symtab));
}
@ -2089,6 +2279,9 @@ cfg_parse_rawaddr(cfg_parser_t *pctx, unsigned int flags, isc_netaddr_t *na) {
const char *wild = "";
const char *prefix = "";
REQUIRE(pctx != NULL);
REQUIRE(na != NULL);
CHECK(cfg_gettoken(pctx, 0));
result = token_addr(pctx, flags, na);
if (result == ISC_R_UNEXPECTEDTOKEN) {
@ -2117,6 +2310,9 @@ isc_boolean_t
cfg_lookingat_netaddr(cfg_parser_t *pctx, unsigned int flags) {
isc_result_t result;
isc_netaddr_t na_dummy;
REQUIRE(pctx != NULL);
result = token_addr(pctx, flags, &na_dummy);
return (ISC_TF(result == ISC_R_SUCCESS));
}
@ -2125,6 +2321,9 @@ isc_result_t
cfg_parse_rawport(cfg_parser_t *pctx, unsigned int flags, in_port_t *port) {
isc_result_t result;
REQUIRE(pctx != NULL);
REQUIRE(port != NULL);
CHECK(cfg_gettoken(pctx, ISC_LEXOPT_NUMBER));
if ((flags & CFG_ADDR_WILDOK) != 0 &&
@ -2155,6 +2354,9 @@ cfg_print_rawaddr(cfg_printer_t *pctx, const isc_netaddr_t *na) {
char text[128];
isc_buffer_t buf;
REQUIRE(pctx != NULL);
REQUIRE(na != NULL);
isc_buffer_init(&buf, text, sizeof(text));
result = isc_netaddr_totext(na, &buf);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
@ -2166,6 +2368,9 @@ isc_result_t
cfg_parse_dscp(cfg_parser_t *pctx, isc_dscp_t *dscp) {
isc_result_t result;
REQUIRE(pctx != NULL);
REQUIRE(dscp != NULL);
CHECK(cfg_gettoken(pctx, ISC_LEXOPT_NUMBER | ISC_LEXOPT_CNUMBER));
if (pctx->token.type != isc_tokentype_number) {
@ -2271,6 +2476,10 @@ cfg_parse_netprefix(cfg_parser_t *pctx, const cfg_type_t *type,
isc_result_t result;
isc_netaddr_t netaddr;
unsigned int addrlen = 0, prefixlen;
REQUIRE(pctx != NULL);
REQUIRE(ret != NULL && *ret == NULL);
UNUSED(type);
CHECK(cfg_parse_rawaddr(pctx, CFG_ADDR_V4OK | CFG_ADDR_V4PREFIXOK |
@ -2414,7 +2623,14 @@ LIBISCCFG_EXTERNAL_DATA cfg_type_t cfg_type_sockaddrdscp = {
isc_result_t
cfg_parse_sockaddr(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
const unsigned int *flagp = type->of;
const unsigned int *flagp;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
flagp = type->of;
return (parse_sockaddrsub(pctx, &cfg_type_sockaddr, *flagp, ret));
}
@ -2424,6 +2640,9 @@ cfg_print_sockaddr(cfg_printer_t *pctx, const cfg_obj_t *obj) {
in_port_t port;
char buf[ISC_NETADDR_FORMATSIZE];
REQUIRE(pctx != NULL);
REQUIRE(obj != NULL);
isc_netaddr_fromsockaddr(&netaddr, &obj->value.sockaddr);
isc_netaddr_format(&netaddr, buf, sizeof(buf));
cfg_print_cstr(pctx, buf);
@ -2442,6 +2661,10 @@ void
cfg_doc_sockaddr(cfg_printer_t *pctx, const cfg_type_t *type) {
const unsigned int *flagp = type->of;
int n = 0;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
cfg_print_cstr(pctx, "( ");
if (*flagp & CFG_ADDR_V4OK) {
cfg_print_cstr(pctx, "<ipv4_address>");
@ -2493,6 +2716,8 @@ isc_result_t
cfg_gettoken(cfg_parser_t *pctx, int options) {
isc_result_t result;
REQUIRE(pctx != NULL);
if (pctx->seen_eof)
return (ISC_R_SUCCESS);
@ -2549,6 +2774,8 @@ cfg_gettoken(cfg_parser_t *pctx, int options) {
void
cfg_ungettoken(cfg_parser_t *pctx) {
REQUIRE(pctx != NULL);
if (pctx->seen_eof)
return;
isc_lex_ungettoken(pctx->lexer, &pctx->token);
@ -2558,6 +2785,9 @@ cfg_ungettoken(cfg_parser_t *pctx) {
isc_result_t
cfg_peektoken(cfg_parser_t *pctx, int options) {
isc_result_t result;
REQUIRE(pctx != NULL);
CHECK(cfg_gettoken(pctx, options));
cfg_ungettoken(pctx);
cleanup:
@ -2587,6 +2817,10 @@ cfg_getstringtoken(cfg_parser_t *pctx) {
void
cfg_parser_error(cfg_parser_t *pctx, unsigned int flags, const char *fmt, ...) {
va_list args;
REQUIRE(pctx != NULL);
REQUIRE(fmt != NULL);
va_start(args, fmt);
parser_complain(pctx, ISC_FALSE, flags, fmt, args);
va_end(args);
@ -2596,6 +2830,10 @@ cfg_parser_error(cfg_parser_t *pctx, unsigned int flags, const char *fmt, ...) {
void
cfg_parser_warning(cfg_parser_t *pctx, unsigned int flags, const char *fmt, ...) {
va_list args;
REQUIRE(pctx != NULL);
REQUIRE(fmt != NULL);
va_start(args, fmt);
parser_complain(pctx, ISC_TRUE, flags, fmt, args);
va_end(args);
@ -2705,6 +2943,10 @@ cfg_obj_log(const cfg_obj_t *obj, isc_log_t *lctx, int level,
va_list ap;
char msgbuf[2048];
REQUIRE(obj != NULL);
REQUIRE(lctx != NULL);
REQUIRE(fmt != NULL);
if (! isc_log_wouldlog(lctx, level))
return;
@ -2722,11 +2964,15 @@ cfg_obj_log(const cfg_obj_t *obj, isc_log_t *lctx, int level,
const char *
cfg_obj_file(const cfg_obj_t *obj) {
REQUIRE(obj != NULL);
return (obj->file);
}
unsigned int
cfg_obj_line(const cfg_obj_t *obj) {
REQUIRE(obj != NULL);
return (obj->line);
}
@ -2735,6 +2981,10 @@ cfg_create_obj(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
isc_result_t result;
cfg_obj_t *obj;
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
obj = isc_mem_get(pctx->mctx, sizeof(cfg_obj_t));
if (obj == NULL)
return (ISC_R_NOMEMORY);
@ -2798,6 +3048,10 @@ free_map(cfg_parser_t *pctx, cfg_obj_t *obj) {
isc_boolean_t
cfg_obj_istype(const cfg_obj_t *obj, const cfg_type_t *type) {
REQUIRE(obj != NULL);
REQUIRE(type != NULL);
return (ISC_TF(obj->type == type));
}
@ -2827,6 +3081,7 @@ void
cfg_obj_attach(cfg_obj_t *src, cfg_obj_t **dest) {
REQUIRE(src != NULL);
REQUIRE(dest != NULL && *dest == NULL);
isc_refcount_increment(&src->references, NULL);
*dest = src;
}
@ -2839,11 +3094,17 @@ free_noop(cfg_parser_t *pctx, cfg_obj_t *obj) {
void
cfg_doc_obj(cfg_printer_t *pctx, const cfg_type_t *type) {
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
type->doc(pctx, type);
}
void
cfg_doc_terminal(cfg_printer_t *pctx, const cfg_type_t *type) {
REQUIRE(pctx != NULL);
REQUIRE(type != NULL);
cfg_print_cstr(pctx, "<");
cfg_print_cstr(pctx, type->name);
cfg_print_cstr(pctx, ">");
@ -2855,6 +3116,7 @@ cfg_print_grammar(const cfg_type_t *type,
void *closure)
{
cfg_printer_t pctx;
pctx.f = f;
pctx.closure = closure;
pctx.indent = 0;
@ -2877,6 +3139,7 @@ cfg_parser_mapadd(cfg_parser_t *pctx, cfg_obj_t *mapobj,
REQUIRE(pctx != NULL);
REQUIRE(mapobj != NULL && mapobj->type->rep == &cfg_rep_map);
REQUIRE(obj != NULL);
REQUIRE(clausename != NULL);
map = &mapobj->value.map;

5
lib/isccfg/tests/Atffile Normal file
View file

@ -0,0 +1,5 @@
Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = bind9
tp-glob: *_test

View file

@ -0,0 +1,51 @@
# Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
# Attempt to disable parallel processing.
.NOTPARALLEL:
.NO_PARALLEL:
VERSION=@BIND9_VERSION@
@BIND9_MAKE_INCLUDES@
CINCLUDES = -I. -Iinclude \
${DNS_INCLUDES} ${ISC_INCLUDES} ${ISCCFG_INCLUDES} \
@DST_OPENSSL_INC@
CDEFINES = @CRYPTO@ -DTESTS="\"${top_builddir}/lib/dns/tests/\""
ISCLIBS = ../../isc/libisc.@A@
ISCDEPLIBS = ../../isc/libisc.@A@
DNSLIBS = ../../dns/libdns.@A@ @DNS_CRYPTO_LIBS@
DNSDEPLIBS = ../../dns/libdns.@A@
ISCCFGLIBS = ../libisccfg.@A@
ISCCFGDEPLIBS = ../libisccfg.@A@
LIBS = @LIBS@ @ATFLIBS@
OBJS =
SRCS = parser_test.c
SUBDIRS =
TARGETS = parser_test@EXEEXT@
@BIND9_MAKE_RULES@
parser_test@EXEEXT@: parser_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS} ${ISCCFGDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
parser_test.@O@ ${ISCCFGLIBS} ${DNSLIBS} \
${ISCLIBS} ${LIBS}
unit::
sh ${top_srcdir}/unit/unittest.sh
clean distclean::
rm -f ${TARGETS}
rm -f atf.out

View file

@ -0,0 +1,143 @@
/*
* Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <config.h>
#include <atf-c.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <isc/buffer.h>
#include <isc/lex.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/types.h>
#include <isc/util.h>
#include <isccfg/cfg.h>
#include <isccfg/grammar.h>
#include <isccfg/namedconf.h>
#define CHECK(r) \
do { \
result = (r); \
if (result != ISC_R_SUCCESS) \
goto cleanup; \
} while (0)
isc_mem_t *mctx = NULL;
isc_log_t *lctx = NULL;
static isc_logcategory_t categories[] = {
{ "", 0 },
{ "client", 0 },
{ "network", 0 },
{ "update", 0 },
{ "queries", 0 },
{ "unmatched", 0 },
{ "update-security", 0 },
{ "query-errors", 0 },
{ NULL, 0 }
};
static void
cleanup() {
if (lctx != NULL)
isc_log_destroy(&lctx);
if (mctx != NULL)
isc_mem_destroy(&mctx);
}
static isc_result_t
setup() {
isc_result_t result;
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
CHECK(isc_mem_create(0, 0, &mctx));
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
CHECK(isc_log_create(mctx, &lctx, &logconfig));
isc_log_registercategories(lctx, categories);
isc_log_setcontext(lctx);
destination.file.stream = stderr;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
CHECK(isc_log_createchannel(logconfig, "stderr",
ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC,
&destination, 0));
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
return (ISC_R_SUCCESS);
cleanup:
cleanup();
return (result);
}
ATF_TC(parse_buffer);
ATF_TC_HEAD(parse_buffer, tc) {
atf_tc_set_md_var(tc, "descr", "cfg_parse_buffer");
}
ATF_TC_BODY(parse_buffer, tc) {
isc_result_t result;
unsigned char text[] = "options\n{\nrecursion yes;\n};\n";
isc_buffer_t buf1, buf2;
cfg_parser_t *p1 = NULL, *p2 = NULL;
cfg_obj_t *c1 = NULL, *c2 = NULL;
UNUSED(tc);
setup();
isc_buffer_init(&buf1, &text[0], sizeof(text) - 1);
isc_buffer_add(&buf1, sizeof(text) - 1);
/* Parse with default line numbering */
result = cfg_parser_create(mctx, lctx, &p1);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = cfg_parse_buffer3(p1, &buf1, "text1", 0,
&cfg_type_namedconf, &c1);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
ATF_REQUIRE_EQ(p1->line, 5);
isc_buffer_init(&buf2, &text[0], sizeof(text) - 1);
isc_buffer_add(&buf2, sizeof(text) - 1);
/* Parse with changed line number */
result = cfg_parser_create(mctx, lctx, &p2);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = cfg_parse_buffer3(p2, &buf2, "text2", 100,
&cfg_type_namedconf, &c2);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
ATF_REQUIRE_EQ(p2->line, 104);
cfg_obj_destroy(p1, &c1);
cfg_obj_destroy(p2, &c2);
cfg_parser_destroy(&p1);
cfg_parser_destroy(&p2);
cleanup();
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, parse_buffer);
return (atf_no_error());
}

View file

@ -64,6 +64,7 @@ cfg_parse_boolean
cfg_parse_bracketed_list
cfg_parse_buffer
cfg_parse_buffer2
cfg_parse_buffer3
cfg_parse_dscp
cfg_parse_enum
cfg_parse_file