check for type "master" / "slave" at the same time as checking
for "primary" / "secondary" as we step through the maps.
Checking "primary" then "master" or "master" then "primary" does
not work as the synomym is not checked for to stop the search.
Similarly with "secondary" and "slave".
(cherry picked from commit
a3c6516a75786c5716beb56410186ecc52057983)
const cfg_obj_t **obj) {
int i;
- for (i = 0;; i++) {
- if (maps[i] == NULL) {
- return (ISC_R_NOTFOUND);
- }
+ for (i = 0; maps[i] != NULL; i++) {
if (cfg_map_get(maps[i], name, obj) == ISC_R_SUCCESS) {
return (ISC_R_SUCCESS);
}
}
+ return (ISC_R_NOTFOUND);
}
isc_result_t
-named_checknames_get(const cfg_obj_t **maps, const char *which,
+named_checknames_get(const cfg_obj_t **maps, const char *const names[],
const cfg_obj_t **obj) {
const cfg_listelt_t *element;
const cfg_obj_t *checknames;
int i;
REQUIRE(maps != NULL);
- REQUIRE(which != NULL);
+ REQUIRE(names != NULL);
REQUIRE(obj != NULL && *obj == NULL);
- for (i = 0;; i++) {
- if (maps[i] == NULL) {
- return (ISC_R_NOTFOUND);
- }
+ for (i = 0; maps[i] != NULL; i++) {
checknames = NULL;
if (cfg_map_get(maps[i], "check-names", &checknames) ==
ISC_R_SUCCESS) {
{
value = cfg_listelt_value(element);
type = cfg_tuple_get(value, "type");
- if (strcasecmp(cfg_obj_asstring(type), which) ==
- 0) {
- *obj = cfg_tuple_get(value, "mode");
- return (ISC_R_SUCCESS);
+
+ for (size_t j = 0; names[j] != NULL; j++) {
+ if (strcasecmp(cfg_obj_asstring(type),
+ names[j]) == 0) {
+ *obj = cfg_tuple_get(value,
+ "mode");
+ return (ISC_R_SUCCESS);
+ }
}
}
}
}
+ return (ISC_R_NOTFOUND);
}
int
const cfg_obj_t **obj);
isc_result_t
-named_checknames_get(const cfg_obj_t **maps, const char *name,
+named_checknames_get(const cfg_obj_t **maps, const char *const names[],
const cfg_obj_t **obj);
int
return (true);
}
+static const char *const response_synonyms[] = { "response", NULL };
+
/*
* Configure 'view' according to 'vconfig', taking defaults from 'config'
* where values are missing in 'vconfig'.
/* Check-names. */
obj = NULL;
- result = named_checknames_get(maps, "response", &obj);
+ result = named_checknames_get(maps, response_synonyms, &obj);
INSIST(result == ISC_R_SUCCESS);
str = cfg_obj_asstring(obj);
return (strtoargvsub(mctx, s, argcp, argvp, 0));
}
+static const char *const primary_synonyms[] = { "primary", "master", NULL };
+
+static const char *const secondary_synonyms[] = { "secondary", "slave", NULL };
+
static void
checknames(dns_zonetype_t ztype, const cfg_obj_t **maps,
const cfg_obj_t **objp) {
switch (ztype) {
case dns_zone_secondary:
case dns_zone_mirror:
- result = named_checknames_get(maps, "secondary", objp);
- if (result != ISC_R_SUCCESS) {
- result = named_checknames_get(maps, "slave", objp);
- }
+ result = named_checknames_get(maps, secondary_synonyms, objp);
break;
case dns_zone_primary:
- result = named_checknames_get(maps, "primary", objp);
- if (result != ISC_R_SUCCESS) {
- result = named_checknames_get(maps, "master", objp);
- }
+ result = named_checknames_get(maps, primary_synonyms, objp);
break;
default:
INSIST(0);