settings: Some code refactoring
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Mar 2019 13:04:35 +0000 (14:04 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Mar 2019 13:04:35 +0000 (14:04 +0100)
No functional changes

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.hook
src/functions/functions.ports
src/functions/functions.zone

index fb68037..11887cd 100644 (file)
@@ -124,6 +124,19 @@ hook_help() {
        exit $?
 }
 
+# Dummy functions being overlayed by hooks
+hook_check_settings() {
+       :
+}
+
+hook_check_config_settings() {
+       :
+}
+
+hook_check_port_settings() {
+       :
+}
+
 # Sets all settings in HOOK_SETTINGS to their DEFAULT_* values
 hook_set_defaults() {
        local setting
index fb22715..d8a9140 100644 (file)
@@ -94,15 +94,9 @@ port_settings_read() {
 port_settings_write() {
        local port="${1}"
        assert isset port
-       shift
-
-       local args
-       if function_exists "hook_check_settings"; then
-               list_append args "--check=\"hook_check_settings\""
-       fi
-       list_append args HOOK ${HOOK_SETTINGS[*]}
 
-       settings_write "$(port_file "${port}")" ${args}
+       settings_write "$(port_file "${port}")" \
+               --check="hook_check_settings" HOOK ${HOOK_SETTINGS[*]}
 }
 
 port_file() {
index a0d3cfb..e81371b 100644 (file)
@@ -1267,13 +1267,8 @@ zone_settings_write() {
        local zone="${1}"
        assert isset zone
 
-       local args
-       if function_exists "hook_check_settings"; then
-               list_append args "--check=\"hook_check_settings\""
-       fi
-       list_append args HOOK ${HOOK_SETTINGS[*]}
-
-       settings_write "${NETWORK_ZONES_DIR}/${zone}/settings" ${args}
+       settings_write "${NETWORK_ZONES_DIR}/${zone}/settings" \
+               --check="hook_check_settings" HOOK ${HOOK_SETTINGS[*]}
 }
 
 zone_settings_set() {
@@ -1328,7 +1323,7 @@ zone_config_settings_read() {
 }
 
 zone_config_settings_write() {
-       assert [ $# -ge 2 ]
+       assert [ $# -eq 2 ]
 
        local zone="${1}"
        local hook="${2}"
@@ -1336,14 +1331,9 @@ zone_config_settings_write() {
 
        assert isset id
 
-       local args
-       if function_exists "hook_check_config_settings"; then
-               list_append args "--check=\"hook_check_config_settings\""
-       fi
-       list_append args ${HOOK_CONFIG_SETTINGS}
-
        local path="${NETWORK_ZONES_DIR}/${zone}/configs/${hook}.${id}"
-       settings_write "${path}" ${args}
+       settings_write "${path}" \
+               --check="hook_check_config_settings" ${HOOK_CONFIG_SETTINGS[*]}
 }
 
 zone_config_settings_destroy() {
@@ -1416,20 +1406,14 @@ zone_port_settings_read() {
 }
 
 zone_port_settings_write() {
-       assert [ $# -ge 2 ]
+       assert [ $# -eq 2 ]
 
        local zone="${1}"
        local port="${2}"
-       shift 2
-
-       local args
-       if function_exists "hook_check_port_settings"; then
-               list_append args "--check=\"hook_check_port_settings\""
-       fi
-       list_append args ${HOOK_PORT_SETTINGS}
 
        local path="${NETWORK_ZONES_DIR}/${zone}/ports/${port}"
-       settings_write "${path}" ${args}
+       settings_write "${path}" \
+               --check="hook_check_port_settings" ${HOOK_PORT_SETTINGS[*]}
 }
 
 zone_port_settings_remove() {