From a927f24d94ebdd35488f4a2243b01699b75e18c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Va=C5=A1ek?= <david.vasek@nic.cz>
Date: Mon, 20 Jun 2022 17:34:30 +0200
Subject: [PATCH] conf: simplify the code and wording of error messages

---
 doc/man/knot.conf.5in |  4 ++++
 doc/reference.rst     |  4 ++++
 src/knot/conf/tools.c | 31 ++++++++-----------------------
 3 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/doc/man/knot.conf.5in b/doc/man/knot.conf.5in
index 066c0c5712..d360292da3 100644
--- a/doc/man/knot.conf.5in
+++ b/doc/man/knot.conf.5in
@@ -2263,6 +2263,10 @@ has the \fIgroup\fP property defined, matching another catalog template.
 .INDENT 0.0
 .INDENT 3.5
 This option must be set if and only if \fI\%catalog\-role\fP is \fIinterpret\fP\&.
+.sp
+Nested catalog zones aren\(aqt supported. Therefore catalog templates can\(aqt use
+\fI\%catalog\-template\fP, \fI\%catalog\-role\fP, \fI\%catalog\-zone\fP,
+and \fI\%catalog\-group\fP options.
 .UNINDENT
 .UNINDENT
 .sp
diff --git a/doc/reference.rst b/doc/reference.rst
index f20fc6f07a..9dacdcb600 100644
--- a/doc/reference.rst
+++ b/doc/reference.rst
@@ -2460,6 +2460,10 @@ has the *group* property defined, matching another catalog template.
 .. NOTE::
    This option must be set if and only if :ref:`zone_catalog-role` is *interpret*.
 
+   Nested catalog zones aren't supported. Therefore catalog templates can't use
+   :ref:`zone_catalog-template`, :ref:`zone_catalog-role`, :ref:`zone_catalog-zone`,
+   and :ref:`zone_catalog-group` options.
+
 *Default:* not set
 
 .. _zone_catalog-zone:
diff --git a/src/knot/conf/tools.c b/src/knot/conf/tools.c
index 2171a523c6..693bf064fe 100644
--- a/src/knot/conf/tools.c
+++ b/src/knot/conf/tools.c
@@ -796,11 +796,11 @@ int check_template(
 
 #define CHECK_CATZ_TPL(option, option_string) \
 { \
-	val = conf_rawid_get_txn(args->extra->conf, args->extra->txn, \
-		                 C_TPL, option, catalog_tpl.data, \
-		                 catalog_tpl.len); \
+	conf_val_t val = conf_rawid_get_txn(args->extra->conf, args->extra->txn, \
+	                                    C_TPL, option, catalog_tpl.data, \
+	                                    catalog_tpl.len); \
 	if (val.code == KNOT_EOK) { \
-		args->err_str = option_string " in a catalog template"; \
+		args->err_str = "'" option_string "' in a catalog template"; \
 		return KNOT_EINVAL; \
 	} \
 }
@@ -861,25 +861,10 @@ int check_zone(
 	if (role == CATALOG_ROLE_INTERPRET) {
 		conf_val(&catalog_tpl);
 		while (catalog_tpl.code == KNOT_EOK) {
-			conf_val_t val = conf_rawid_get_txn(args->extra->conf, args->extra->txn,
-			                                    C_TPL, C_CATALOG_ROLE, catalog_tpl.data,
-			                                    catalog_tpl.len);
-			switch (conf_opt(&val)) {
-			case CATALOG_ROLE_INTERPRET:
-			case CATALOG_ROLE_GENERATE:
-				args->err_str = "catalog zone cannot interpret other catalog zones";
-				return KNOT_EINVAL;
-			case CATALOG_ROLE_MEMBER:
-				args->err_str = "catalog zone cannot interpret generated member zones";
-				return KNOT_EINVAL;
-			default:
-				break;
-			}
-
-			CHECK_CATZ_TPL(C_CATALOG_TPL, "'catalog-template'");
-			CHECK_CATZ_TPL(C_CATALOG_ZONE, "'catalog-zone'");
-			CHECK_CATZ_TPL(C_CATALOG_GROUP, "'catalog-group'");
-
+			CHECK_CATZ_TPL(C_CATALOG_TPL,   "catalog-template");
+			CHECK_CATZ_TPL(C_CATALOG_ROLE,  "catalog-role");
+			CHECK_CATZ_TPL(C_CATALOG_ZONE,  "catalog-zone");
+			CHECK_CATZ_TPL(C_CATALOG_GROUP, "catalog-group");
 			conf_val_next(&catalog_tpl);
 		}
 	}
-- 
GitLab