simplify cfg_parser API

- the cfg_parser_create() and cfg_parser_destroy() calls are no
  longer used outside parser.c, so they are now static functions
- cfg_parser_attach(), cfg_parser_reset(), and cfg_parser_setflags()
  are no longer used at all, and have been removed.
- cfg_parser_mapadd() has been renamed for clarity to cfg_map_add().
This commit is contained in:
Evan Hunt 2025-10-22 10:41:05 -07:00
parent d03f6e6fd4
commit 4f7f2dae59
3 changed files with 37 additions and 114 deletions

View file

@ -13236,7 +13236,7 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view,
cfg_obj_attach(zoneconf, &cfg->nzf_config);
} else {
cfg_obj_t *z = UNCONST(zoneobj);
CHECK(cfg_parser_mapadd(cfg->nzf_config, z, "zone"));
CHECK(cfg_map_add(cfg->nzf_config, z, "zone"));
}
cleanup_config = true;
#endif /* HAVE_LMDB */
@ -13487,7 +13487,7 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view,
#ifndef HAVE_LMDB
/* Store the new zone configuration; also in NZF if applicable */
z = UNCONST(zoneobj);
CHECK(cfg_parser_mapadd(cfg->nzf_config, z, "zone"));
CHECK(cfg_map_add(cfg->nzf_config, z, "zone"));
#endif /* HAVE_LMDB */
if (added) {

View file

@ -85,34 +85,6 @@ typedef isc_result_t (*cfg_parsecallback_t)(const char *clausename,
*** Functions
***/
void
cfg_parser_attach(cfg_parser_t *src, cfg_parser_t **dest);
/*%<
* Reference a parser object.
*/
isc_result_t
cfg_parser_create(isc_mem_t *mctx, cfg_parser_t **ret);
/*%<
* Create a configuration file parser. Any warning and error
* messages will be logged.
*
* The parser object returned can be used for a single call
* to cfg_parse_file() or cfg_parse_buffer(). It must not
* be reused for parsing multiple files or buffers.
*/
void
cfg_parser_setflags(cfg_parser_t *pctx, unsigned int flags, bool turn_on);
/*%<
* Set parser context flags. The flags are not checked for sensibility.
* If 'turn_on' is 'true' the flags will be set, otherwise the flags will
* be cleared.
*
* Requires:
*\li "pctx" is not NULL.
*/
isc_result_t
cfg_parse_file(isc_mem_t *mctx, const char *file, const cfg_type_t *type,
unsigned int flags, cfg_obj_t **ret);
@ -152,31 +124,6 @@ cfg_parse_buffer(isc_mem_t *mctx, isc_buffer_t *buffer, const char *file,
*\li others - file contains errors
*/
isc_result_t
cfg_parser_mapadd(cfg_obj_t *mapobj, cfg_obj_t *obj, const char *clause);
/*%<
* Add the object 'obj' to the specified clause in mapbody 'mapobj'.
* Used for adding new zones.
*
* Require:
* \li 'obj' is a valid cfg_obj_t.
* \li 'mapobj' is a valid cfg_obj_t of type map.
*/
void
cfg_parser_reset(cfg_parser_t *pctx);
/*%<
* Reset an existing parser so it can be re-used for a new file or
* buffer.
*/
void
cfg_parser_destroy(cfg_parser_t **pctxp);
/*%<
* Remove a reference to a configuration parser; destroy it if there are no
* more references.
*/
cfg_obj_t *
cfg_parser_currentfile(cfg_parser_t *pctx);
/*%<
@ -225,6 +172,17 @@ cfg_map_get(const cfg_obj_t *mapobj, const char *name, const cfg_obj_t **obj);
* \li #ISC_R_NOTFOUND - name not found in map
*/
isc_result_t
cfg_map_add(cfg_obj_t *mapobj, cfg_obj_t *obj, const char *clause);
/*%<
* Add the object 'obj' to the specified clause in mapbody 'mapobj'.
* Used for adding new zones.
*
* Require:
* \li 'obj' is a valid cfg_obj_t.
* \li 'mapobj' is a valid cfg_obj_t of type map.
*/
const cfg_obj_t *
cfg_map_getname(const cfg_obj_t *mapobj);
/*%<

View file

@ -519,8 +519,8 @@ static cfg_type_t cfg_type_filelist = { "filelist", NULL,
print_list, NULL,
&cfg_rep_list, &cfg_type_qstring };
isc_result_t
cfg_parser_create(isc_mem_t *mctx, cfg_parser_t **ret) {
static isc_result_t
parser_create(isc_mem_t *mctx, cfg_parser_t **ret) {
isc_result_t result;
cfg_parser_t *pctx;
isc_lexspecials_t specials;
@ -582,14 +582,24 @@ cleanup:
return result;
}
void
cfg_parser_setflags(cfg_parser_t *pctx, unsigned int flags, bool turn_on) {
REQUIRE(pctx != NULL);
static void
parser_destroy(cfg_parser_t **pctxp) {
cfg_parser_t *pctx;
if (turn_on) {
pctx->flags |= flags;
} else {
pctx->flags &= ~flags;
REQUIRE(pctxp != NULL && *pctxp != NULL);
pctx = *pctxp;
*pctxp = NULL;
if (isc_refcount_decrement(&pctx->references) == 1) {
isc_lex_destroy(&pctx->lexer);
/*
* Cleaning up open_files does not
* close the files; that was already done
* by closing the lexer.
*/
CLEANUP_OBJ(pctx->open_files);
CLEANUP_OBJ(pctx->closed_files);
isc_mem_putanddetach(&pctx->mctx, pctx, sizeof(*pctx));
}
}
@ -617,21 +627,6 @@ cleanup:
return result;
}
void
cfg_parser_reset(cfg_parser_t *pctx) {
REQUIRE(pctx != NULL);
if (pctx->lexer != NULL) {
isc_lex_close(pctx->lexer);
}
pctx->seen_eof = false;
pctx->ungotten = false;
pctx->errors = 0;
pctx->warnings = 0;
pctx->line = 0;
}
/*
* Parse a configuration using a pctx where a lexer has already
* been set up with a source.
@ -685,7 +680,7 @@ cfg_parse_file(isc_mem_t *mctx, const char *filename, const cfg_type_t *type,
REQUIRE(ret != NULL && *ret == NULL);
REQUIRE_PCTX_FLAGS(flags);
CHECK(cfg_parser_create(mctx, &pctx));
CHECK(parser_create(mctx, &pctx));
pctx->flags = flags;
CHECK(parser_openfile(pctx, filename));
@ -700,7 +695,7 @@ cfg_parse_file(isc_mem_t *mctx, const char *filename, const cfg_type_t *type,
cleanup:
if (pctx != NULL) {
cfg_parser_destroy(&pctx);
parser_destroy(&pctx);
}
return result;
@ -719,7 +714,7 @@ cfg_parse_buffer(isc_mem_t *mctx, isc_buffer_t *buffer, const char *file,
REQUIRE(ret != NULL && *ret == NULL);
REQUIRE_PCTX_FLAGS(flags);
CHECK(cfg_parser_create(mctx, &pctx));
CHECK(parser_create(mctx, &pctx));
CHECK(isc_lex_openbuffer(pctx->lexer, buffer));
pctx->buf_name = file;
@ -734,42 +729,12 @@ cfg_parse_buffer(isc_mem_t *mctx, isc_buffer_t *buffer, const char *file,
cleanup:
if (pctx != NULL) {
cfg_parser_destroy(&pctx);
parser_destroy(&pctx);
}
return result;
}
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);
*dest = src;
}
void
cfg_parser_destroy(cfg_parser_t **pctxp) {
cfg_parser_t *pctx;
REQUIRE(pctxp != NULL && *pctxp != NULL);
pctx = *pctxp;
*pctxp = NULL;
if (isc_refcount_decrement(&pctx->references) == 1) {
isc_lex_destroy(&pctx->lexer);
/*
* Cleaning up open_files does not
* close the files; that was already done
* by closing the lexer.
*/
CLEANUP_OBJ(pctx->open_files);
CLEANUP_OBJ(pctx->closed_files);
isc_mem_putanddetach(&pctx->mctx, pctx, sizeof(*pctx));
}
}
/*
* void
*/
@ -3927,7 +3892,7 @@ cfg_print_grammar(const cfg_type_t *type, unsigned int flags,
}
isc_result_t
cfg_parser_mapadd(cfg_obj_t *mapobj, cfg_obj_t *obj, const char *clausename) {
cfg_map_add(cfg_obj_t *mapobj, cfg_obj_t *obj, const char *clausename) {
isc_result_t result = ISC_R_SUCCESS;
const cfg_map_t *map = NULL;
isc_symvalue_t symval;