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);
}
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);
}
void (*f)(void *closure, const char *text, int textlen),
void *closure)
{
+ REQUIRE(obj != NULL);
+ REQUIRE(f != NULL);
+
cfg_printx(obj, 0, f, closure);
}
void *closure)
{
cfg_printer_t pctx;
+
+ REQUIRE(obj != NULL);
+ REQUIRE(f != NULL);
+
pctx.f = f;
pctx.closure = closure;
pctx.indent = 0;
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++;
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]));
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)
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, " ");
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++) {
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)
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 == ';')
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)
isc_lexspecials_t specials;
REQUIRE(mctx != NULL);
+ REQUIRE(lctx != NULL);
REQUIRE(ret != NULL && *ret == NULL);
pctx = isc_mem_get(mctx, sizeof(*pctx));
cfg_parsecallback_t callback,
void *arg)
{
+ REQUIRE(pctx != NULL);
+
pctx->callback = callback;
pctx->callbackarg = arg;
}
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));
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;
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);
CLEANUP_OBJ(pctx->closed_files);
isc_mem_putanddetach(&pctx->mctx, pctx, sizeof(*pctx));
}
- *pctxp = NULL;
}
/*
*/
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);
}
cfg_obj_t *obj = NULL;
isc_uint64_t percent;
+ REQUIRE(pctx != NULL);
+ REQUIRE(ret != NULL && *ret == NULL);
+
UNUSED(type);
CHECK(cfg_gettoken(pctx, 0));
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));
size_t n1, n2, n3, l;
const char *p;
+ REQUIRE(pctx != NULL);
+ REQUIRE(ret != NULL && *ret == NULL);
+
UNUSED(type);
CHECK(cfg_gettoken(pctx, 0));
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));
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));
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);
}
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);
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));
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);
}
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));
cfg_obj_t **ret)
{
isc_result_t result;
+
+ REQUIRE(pctx != NULL);
+ REQUIRE(ret != NULL && *ret == NULL);
+
UNUSED(type);
CHECK(cfg_getstringtoken(pctx));
cfg_obj_t **ret)
{
isc_result_t result;
+
+ REQUIRE(pctx != NULL);
+ REQUIRE(ret != NULL && *ret == NULL);
+
UNUSED(type);
CHECK(cfg_getstringtoken(pctx));
cfg_obj_t **ret)
{
isc_result_t result;
+
UNUSED(type);
CHECK(cfg_gettoken(pctx, ISC_LEXOPT_BTEXT));
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);
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);
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;
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);
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);
}
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);
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
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:
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);
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);
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, '}'));
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);
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, "; ... }");
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 (;;) {
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)) {
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;
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, '}'));
* 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;
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++)
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;
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, " ");
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, " ");
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));
}
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) {
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));
}
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 &&
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);
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) {
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 |
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));
}
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);
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>");
cfg_gettoken(cfg_parser_t *pctx, int options) {
isc_result_t result;
+ REQUIRE(pctx != NULL);
+
if (pctx->seen_eof)
return (ISC_R_SUCCESS);
void
cfg_ungettoken(cfg_parser_t *pctx) {
+ REQUIRE(pctx != NULL);
+
if (pctx->seen_eof)
return;
isc_lex_ungettoken(pctx->lexer, &pctx->token);
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:
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);
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);
va_list ap;
char msgbuf[2048];
+ REQUIRE(obj != NULL);
+ REQUIRE(lctx != NULL);
+ REQUIRE(fmt != NULL);
+
if (! isc_log_wouldlog(lctx, level))
return;
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);
}
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);
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));
}
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;
}
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, ">");
void *closure)
{
cfg_printer_t pctx;
+
pctx.f = f;
pctx.closure = closure;
pctx.indent = 0;
REQUIRE(pctx != NULL);
REQUIRE(mapobj != NULL && mapobj->type->rep == &cfg_rep_map);
REQUIRE(obj != NULL);
+ REQUIRE(clausename != NULL);
map = &mapobj->value.map;
--- /dev/null
+/*
+ * 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());
+}