]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
parser firstclause/nextclause API changes
authorColin Vidal <colin@isc.org>
Thu, 16 Oct 2025 12:38:48 +0000 (14:38 +0200)
committerEvan Hunt <each@isc.org>
Wed, 29 Oct 2025 20:55:04 +0000 (13:55 -0700)
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.

lib/isccfg/check.c
lib/isccfg/include/isccfg/cfg.h
lib/isccfg/parser.c
tests/isccfg/grammar_test.c
tests/isccfg/parser_test.c

index 0e044a3b087144418282d71c709f02268fa4c17e..c49afa9a5f492842615e3c44ebca525eeb15863f 100644 (file)
@@ -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;
index adf83d3b888bebee53d4cff1ed49ef8c394bc16d..adc3a95eb1209f91e55d12c3b11a3282dda4ef1f 100644 (file)
@@ -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);
 
index e585557657cb60c717251241760f4faf6b4d26c4..aad26d4ddf0cbeb7b771ea17341fba1907a5b475 100644 (file)
@@ -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);
index 88e4f00160e97cdcd5b601046ce506f337b5a34b..15610a6d11fc9aecaa2bed8a564dc9af36a8ecd5 100644 (file)
@@ -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;
index 581065ac4043c80f42e07131d6e49fdc12e57e24..5b334f14d826dde76f3711e62133d1055b9933c1 100644 (file)
@@ -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