From: Colin Vidal Date: Thu, 16 Oct 2025 12:38:48 +0000 (+0200) Subject: parser firstclause/nextclause API changes X-Git-Tag: v9.21.15~22^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35c8768fde248521d63d0fe96a15dd4eba248dfa;p=thirdparty%2Fbind9.git parser firstclause/nextclause API changes In order to make upcoming configuration tree changes easier, the cfg_map_firstclause() and _nextclause() functions have been changed to return the clause itself rather than only the clause name. --- diff --git a/lib/isccfg/check.c b/lib/isccfg/check.c index 0e044a3b087..c49afa9a5f4 100644 --- a/lib/isccfg/check.c +++ b/lib/isccfg/check.c @@ -3191,7 +3191,7 @@ isccfg_check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, bool inline_signing = false; bool check_keys = (flags & BIND_CHECK_KEYS) != 0; const void *clauses = NULL; - const char *option = NULL; + const cfg_clausedef_t *option = NULL; const char *kaspname = NULL; const char *dir = NULL; static const char *acls[] = { @@ -3516,16 +3516,18 @@ isccfg_check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, while (option != NULL) { obj = NULL; bool topt = false; - (void)cfg_map_get(zoptions, option, &obj); + (void)cfg_map_get(zoptions, option->name, &obj); if (obj == NULL && toptions != NULL) { - (void)cfg_map_get(toptions, option, &obj); + (void)cfg_map_get(toptions, option->name, &obj); topt = true; } - if (obj != NULL && !cfg_clause_validforzone(option, ztype)) { + if (obj != NULL && + !cfg_clause_validforzone(option->name, ztype)) + { cfg_obj_log(obj, ISC_LOG_WARNING, "option '%s' is not allowed " "in '%s' zone '%s'%s%s%s", - option, typestr, znamestr, + option->name, typestr, znamestr, topt ? " (referencing template '" : "", topt ? tmplname : "", topt ? "')" : ""); result = ISC_R_FAILURE; diff --git a/lib/isccfg/include/isccfg/cfg.h b/lib/isccfg/include/isccfg/cfg.h index adf83d3b888..adc3a95eb12 100644 --- a/lib/isccfg/include/isccfg/cfg.h +++ b/lib/isccfg/include/isccfg/cfg.h @@ -67,6 +67,11 @@ typedef struct cfg_obj cfg_obj_t; */ typedef struct cfg_listelt cfg_listelt_t; +/*% + * A configuration clause definition. + */ +typedef struct cfg_clausedef cfg_clausedef_t; + /*% * A callback function to be called when parsing an option * that needs to be interpreted at parsing time, like @@ -539,10 +544,11 @@ cfg_obj_line(const cfg_obj_t *obj); * Return the line in file where this object was defined. */ -const char * +const cfg_clausedef_t * cfg_map_firstclause(const cfg_type_t *map, const void **clauses, unsigned int *idx); -const char * + +const cfg_clausedef_t * cfg_map_nextclause(const cfg_type_t *map, const void **clauses, unsigned int *idx); diff --git a/lib/isccfg/parser.c b/lib/isccfg/parser.c index e585557657c..aad26d4ddf0 100644 --- a/lib/isccfg/parser.c +++ b/lib/isccfg/parser.c @@ -2891,7 +2891,7 @@ cfg_map_count(const cfg_obj_t *mapobj) { return isc_symtab_count(map->symtab); } -const char * +const cfg_clausedef_t * cfg_map_firstclause(const cfg_type_t *map, const void **clauses, unsigned int *idx) { cfg_clausedef_t *const *clauseset; @@ -2912,10 +2912,10 @@ cfg_map_firstclause(const cfg_type_t *map, const void **clauses, return NULL; } } - return (*clauseset)[*idx].name; + return &(*clauseset)[*idx]; } -const char * +const cfg_clausedef_t * cfg_map_nextclause(const cfg_type_t *map, const void **clauses, unsigned int *idx) { cfg_clausedef_t *const *clauseset; @@ -2937,7 +2937,7 @@ cfg_map_nextclause(const cfg_type_t *map, const void **clauses, return NULL; } } - return (*clauseset)[*idx].name; + return &(*clauseset)[*idx]; } /* Parse an arbitrary token, storing its raw text representation. */ @@ -4037,7 +4037,7 @@ breakout: symval.as_pointer = obj; } - result = isc_symtab_define(map->symtab, clausename, + result = isc_symtab_define(map->symtab, clause->name, SYMTAB_DUMMY_TYPE, symval, isc_symexists_reject); INSIST(result == ISC_R_SUCCESS); diff --git a/tests/isccfg/grammar_test.c b/tests/isccfg/grammar_test.c index 88e4f00160e..15610a6d11f 100644 --- a/tests/isccfg/grammar_test.c +++ b/tests/isccfg/grammar_test.c @@ -74,13 +74,13 @@ assert_text(const char *text) { static const cfg_clausedef_t * find_clause(const cfg_type_t *map, const char *name) { - const char *found_name = NULL; + const cfg_clausedef_t *found = NULL; const void *clauses = NULL; unsigned int idx; - found_name = cfg_map_firstclause(map, &clauses, &idx); - while (name != NULL && strcasecmp(name, found_name)) { - found_name = cfg_map_nextclause(map, &clauses, &idx); + found = cfg_map_firstclause(map, &clauses, &idx); + while (name != NULL && strcasecmp(name, found->name)) { + found = cfg_map_nextclause(map, &clauses, &idx); } return ((cfg_clausedef_t *)clauses) + idx; diff --git a/tests/isccfg/parser_test.c b/tests/isccfg/parser_test.c index 581065ac404..5b334f14d82 100644 --- a/tests/isccfg/parser_test.c +++ b/tests/isccfg/parser_test.c @@ -174,36 +174,38 @@ ISC_RUN_TEST_IMPL(parse_buffer) { /* test cfg_map_firstclause() */ ISC_RUN_TEST_IMPL(cfg_map_firstclause) { - const char *name = NULL; const void *clauses = NULL; unsigned int idx; + const cfg_clausedef_t *clause = NULL; - name = cfg_map_firstclause(&cfg_type_zoneopts, &clauses, &idx); - assert_non_null(name); + clause = cfg_map_firstclause(&cfg_type_zoneopts, &clauses, &idx); + assert_non_null(clause); + assert_non_null(clause->name); assert_non_null(clauses); assert_int_equal(idx, 0); } /* test cfg_map_nextclause() */ ISC_RUN_TEST_IMPL(cfg_map_nextclause) { - const char *name = NULL; const void *clauses = NULL; unsigned int idx; + const cfg_clausedef_t *clause = NULL; - name = cfg_map_firstclause(&cfg_type_zoneopts, &clauses, &idx); - assert_non_null(name); + clause = cfg_map_firstclause(&cfg_type_zoneopts, &clauses, &idx); + assert_non_null(clause); + assert_non_null(clause->name); assert_non_null(clauses); assert_int_equal(idx, ISC_R_SUCCESS); do { - name = cfg_map_nextclause(&cfg_type_zoneopts, &clauses, &idx); - if (name != NULL) { + clause = cfg_map_nextclause(&cfg_type_zoneopts, &clauses, &idx); + if (clause != NULL) { assert_non_null(clauses); } else { assert_null(clauses); assert_int_equal(idx, 0); } - } while (name != NULL); + } while (clause != NULL); } static void