* Copyright (C) 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 https://mozilla.org/MPL/2.0/.
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
#define ISCCFG_GRAMMAR_H 1
/*! \file isccfg/grammar.h */
#include <isc/refcount.h>
#include <isc/sockaddr.h>
* Definitions shared between the configuration parser
* and the grammars; not visible to users of the parser.
/*% Clause may occur multiple times (e.g., "zone") */
#define CFG_CLAUSEFLAG_MULTI 0x00000001
/*% Clause is obsolete */
#define CFG_CLAUSEFLAG_OBSOLETE 0x00000002
/*% Clause is not implemented, and may never be */
#define CFG_CLAUSEFLAG_NOTIMP 0x00000004
/*% Clause is not implemented yet */
#define CFG_CLAUSEFLAG_NYI 0x00000008
/*% Default value has changed since earlier release */
#define CFG_CLAUSEFLAG_NEWDEFAULT 0x00000010
* Clause needs to be interpreted during parsing
* by calling a callback function, like the
#define CFG_CLAUSEFLAG_CALLBACK 0x00000020
/*% A option that is only used in testing. */
#define CFG_CLAUSEFLAG_TESTONLY 0x00000040
/*% A configuration option that was not configured at compile time. */
#define CFG_CLAUSEFLAG_NOTCONFIGURED 0x00000080
/*% A option for a experimental feature. */
#define CFG_CLAUSEFLAG_EXPERIMENTAL 0x00000100
/*% A configuration option that is ineffective due to
* compile time options, but is harmless. */
#define CFG_CLAUSEFLAG_NOOP 0x00000200
/*% Clause is obsolete in a future release */
#define CFG_CLAUSEFLAG_DEPRECATED 0x00000400
* Zone types for which a clause is valid:
* These share space with CFG_CLAUSEFLAG values, but count
#define CFG_ZONE_MASTER 0x80000000
#define CFG_ZONE_SLAVE 0x40000000
#define CFG_ZONE_STUB 0x20000000
#define CFG_ZONE_HINT 0x10000000
#define CFG_ZONE_FORWARD 0x08000000
#define CFG_ZONE_STATICSTUB 0x04000000
#define CFG_ZONE_REDIRECT 0x02000000
#define CFG_ZONE_DELEGATION 0x01000000
#define CFG_ZONE_INVIEW 0x00800000
typedef struct cfg_clausedef cfg_clausedef_t;
typedef struct cfg_tuplefielddef cfg_tuplefielddef_t;
typedef struct cfg_printer cfg_printer_t;
typedef ISC_LIST(cfg_listelt_t) cfg_list_t;
typedef struct cfg_map cfg_map_t;
typedef struct cfg_rep cfg_rep_t;
* Function types for configuration object methods
typedef isc_result_t (*cfg_parsefunc_t)(cfg_parser_t *, const cfg_type_t *type,
typedef void (*cfg_printfunc_t)(cfg_printer_t *, const cfg_obj_t *);
typedef void (*cfg_docfunc_t)(cfg_printer_t *, const cfg_type_t *);
typedef void (*cfg_freefunc_t)(cfg_parser_t *, cfg_obj_t *);
* A configuration printer object. This is an abstract
* interface to a destination to which text can be printed
* by calling the function 'f'.
void (*f)(void *closure, const char *text, int textlen);
/*% A clause definition. */
/*% A tuple field definition. */
struct cfg_tuplefielddef {
/*% A configuration object type definition. */
const char *name; /*%< For debugging purposes only */
cfg_docfunc_t doc; /*%< Print grammar description */
cfg_rep_t * rep; /*%< Data representation */
const void * of; /*%< Additional data for meta-types */
/*% A keyword-type definition, for things like "port <integer>". */
cfg_obj_t *id; /*%< Used for 'named maps' like keys, zones, &c */
const cfg_clausedef_t * const *clausesets; /*%< The clauses that
typedef struct cfg_netprefix cfg_netprefix_t;
isc_netaddr_t address; /* IP4/IP6 */
* A configuration data representation.
const char * name; /*%< For debugging only */
cfg_freefunc_t free; /*%< How to free this kind of data. */
* A configuration object. This is the main building block
* of the configuration parse tree.
isc_textregion_t string; /*%< null terminated, too */
cfg_netprefix_t netprefix;
isc_refcount_t references; /*%< reference counter */
ISC_LINK(cfg_listelt_t) link;
/*% The parser object. */
/*% We are at the end of all input. */
/*% The current token has been pushed back. */
* The stack of currently active files, represented
* as a configuration list of configuration strings.
* The head is the top-level file, subsequent elements
* (if any) are the nested include files, and the
* last element is the file currently being parsed.
* Names of files that we have parsed and closed
* and were previously on the open_file list.
* We keep these objects around after closing
* the files because the file names may still be
* referenced from other configuration objects
* for use in reporting semantic errors after
cfg_obj_t * closed_files;
* Name of a buffer being parsed; used only for
* Current line number. We maintain our own
* copy of this so that it is available even
* when a file has just been closed.
* Parser context flags, used for maintaining state
* from one token to the next.
/*%< Reference counter */
isc_refcount_t references;
cfg_parsecallback_t callback;
/* Parser context flags */
#define CFG_PCTX_SKIP 0x1
#define CFG_PCTX_NODEPRECATED 0x2
* Flags defining whether to accept certain types of network addresses.
#define CFG_ADDR_V4OK 0x00000001
#define CFG_ADDR_V4PREFIXOK 0x00000002
#define CFG_ADDR_V6OK 0x00000004
#define CFG_ADDR_WILDOK 0x00000008
#define CFG_ADDR_DSCPOK 0x00000010
#define CFG_ADDR_MASK (CFG_ADDR_V6OK|CFG_ADDR_V4OK)
* Predefined data representation types.
LIBISCCFG_EXTERNAL_DATA extern cfg_rep_t cfg_rep_uint32;
LIBISCCFG_EXTERNAL_DATA extern cfg_rep_t cfg_rep_uint64;
LIBISCCFG_EXTERNAL_DATA extern cfg_rep_t cfg_rep_string;
LIBISCCFG_EXTERNAL_DATA extern cfg_rep_t cfg_rep_boolean;
LIBISCCFG_EXTERNAL_DATA extern cfg_rep_t cfg_rep_map;
LIBISCCFG_EXTERNAL_DATA extern cfg_rep_t cfg_rep_list;
LIBISCCFG_EXTERNAL_DATA extern cfg_rep_t cfg_rep_tuple;
LIBISCCFG_EXTERNAL_DATA extern cfg_rep_t cfg_rep_sockaddr;
LIBISCCFG_EXTERNAL_DATA extern cfg_rep_t cfg_rep_netprefix;
LIBISCCFG_EXTERNAL_DATA extern cfg_rep_t cfg_rep_void;
LIBISCCFG_EXTERNAL_DATA extern cfg_rep_t cfg_rep_fixedpoint;
LIBISCCFG_EXTERNAL_DATA extern cfg_rep_t cfg_rep_percentage;
* Predefined configuration object types.
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_boolean;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_uint32;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_uint64;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_qstring;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_astring;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_ustring;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_sstring;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_bracketed_text;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_sockaddr;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_sockaddrdscp;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_netaddr;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_netaddr4;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_netaddr4wild;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_netaddr6;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_netaddr6wild;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_netprefix;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_void;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_token;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_unsupported;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_fixedpoint;
LIBISCCFG_EXTERNAL_DATA extern cfg_type_t cfg_type_percentage;
cfg_gettoken(cfg_parser_t *pctx, int options);
cfg_peektoken(cfg_parser_t *pctx, int options);
cfg_ungettoken(cfg_parser_t *pctx);
#define CFG_LEXOPT_QSTRING (ISC_LEXOPT_QSTRING | ISC_LEXOPT_QSTRINGMULTILINE)
cfg_create_obj(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **objp);
cfg_print_rawuint(cfg_printer_t *pctx, unsigned int u);
cfg_parse_uint32(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_print_uint32(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_print_uint64(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_parse_qstring(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_print_ustring(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_parse_astring(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_parse_sstring(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_parse_rawaddr(cfg_parser_t *pctx, unsigned int flags, isc_netaddr_t *na);
cfg_print_rawaddr(cfg_printer_t *pctx, const isc_netaddr_t *na);
cfg_lookingat_netaddr(cfg_parser_t *pctx, unsigned int flags);
cfg_parse_rawport(cfg_parser_t *pctx, unsigned int flags, in_port_t *port);
cfg_parse_dscp(cfg_parser_t *pctx, isc_dscp_t *dscp);
cfg_parse_sockaddr(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_parse_boolean(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_print_sockaddr(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_print_boolean(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_doc_sockaddr(cfg_printer_t *pctx, const cfg_type_t *type);
cfg_parse_netprefix(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_parse_special(cfg_parser_t *pctx, int special);
/*%< Parse a required special character 'special'. */
cfg_create_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **objp);
cfg_parse_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_print_tuple(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_doc_tuple(cfg_printer_t *pctx, const cfg_type_t *type);
cfg_create_list(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **objp);
cfg_parse_listelt(cfg_parser_t *pctx, const cfg_type_t *elttype,
cfg_parse_bracketed_list(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_print_bracketed_list(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_doc_bracketed_list(cfg_printer_t *pctx, const cfg_type_t *type);
cfg_parse_spacelist(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_print_spacelist(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_parse_enum(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_doc_enum(cfg_printer_t *pctx, const cfg_type_t *type);
cfg_print_chars(cfg_printer_t *pctx, const char *text, int len);
/*%< Print 'len' characters at 'text' */
cfg_print_cstr(cfg_printer_t *pctx, const char *s);
/*%< Print the null-terminated string 's' */
cfg_parse_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_parse_named_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_parse_addressed_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_parse_netprefix_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **
cfg_print_map(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_doc_map(cfg_printer_t *pctx, const cfg_type_t *type);
cfg_parse_mapbody(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_print_mapbody(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_doc_mapbody(cfg_printer_t *pctx, const cfg_type_t *type);
cfg_parse_void(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_print_void(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_doc_void(cfg_printer_t *pctx, const cfg_type_t *type);
cfg_parse_fixedpoint(cfg_parser_t *pctx, const cfg_type_t *type,
cfg_print_fixedpoint(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_parse_percentage(cfg_parser_t *pctx, const cfg_type_t *type,
cfg_print_percentage(cfg_printer_t *pctx, const cfg_obj_t *obj);
cfg_parse_obj(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
cfg_print_obj(cfg_printer_t *pctx, const cfg_obj_t *obj);