]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/functions/functions.hook
settings: Some code refactoring
[people/ms/network.git] / src / functions / functions.hook
index a48a86d42967cf1a9c2b1f1838b6d3c359b0217f..11887cdbf4b43241b1a398df59ad0815da585b49 100644 (file)
@@ -19,7 +19,7 @@
 #                                                                             #
 ###############################################################################
 
-function hook_dir() {
+hook_dir() {
        local type=${1}
 
        if [ -n "${type}" ]; then
@@ -30,7 +30,7 @@ function hook_dir() {
 }
 NETWORK_HOOKS_DIR_ZONES="$(hook_dir zone)"
 
-function hook_exists() {
+hook_exists() {
        local type=${1}
        local hook=${2}
 
@@ -43,7 +43,7 @@ function hook_exists() {
        [ ! -d "${hook}" ] && [ -x "${hook}" ]
 }
 
-function hook_exec() {
+hook_exec() {
        local type="${1}"
        assert isset type
 
@@ -86,27 +86,25 @@ function hook_exec() {
                ${EXIT_COMMAND_NOT_FOUND}|${EXIT_NOT_SUPPORTED})
                        log ERROR "Hook '${hook}' does not implement the method '${cmd}':"
                        log ERROR "  arguments: $@"
-                       exit ${EXIT_COMMAND_NOT_FOUND}
+                       return ${EXIT_COMMAND_NOT_FOUND}
                        ;;
                ${EXIT_ERROR_ASSERT})
                        log ERROR "Hook exited with an assertion error."
-                       exit ${EXIT_ERROR_ASSERT}
+                       return ${EXIT_ERROR_ASSERT}
                        ;;
        esac
 
        return ${ret}
 }
 
-function hook_list() {
+hook_list() {
        local type="${1}"
 
        local dir="$(hook_dir "${type}")"
        assert isset dir
 
        local hook
-       for hook in ${dir}/*; do
-               hook="$(basename "${hook}")"
-
+       for hook in $(list_directory "${dir}"); do
                if hook_exists "${type}" "${hook}"; then
                        echo "${hook}"
                fi
@@ -114,7 +112,7 @@ function hook_list() {
 }
 
 # The default help function.
-function hook_help() {
+hook_help() {
        # If no man page has been configured, we print an error message.
        if [ -z "${HOOK_MANPAGE}" ]; then
                error "There is no help available for hook '${HOOK}'. Exiting."
@@ -126,7 +124,31 @@ function hook_help() {
        exit $?
 }
 
-function config_get_hook() {
+# 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
+       for setting in ${HOOK_SETTINGS[*]}; do
+               local default="DEFAULT_${setting}"
+
+               # Sets the default or empty
+               assign "${setting}" "${!default}"
+       done
+}
+
+config_get_hook() {
        local config=${1}
 
        assert isset config
@@ -138,31 +160,31 @@ function config_get_hook() {
        )
 }
 
-function hook_zone_exists() {
-       hook_exists zone $@
+hook_zone_exists() {
+       hook_exists zone "$@"
 }
 
-function hook_zone_exec() {
-       hook_exec zone $@
+hook_zone_exec() {
+       hook_exec zone "$@"
 }
 
-function hook_zone_get_all() {
+hook_zone_get_all() {
        hook_list zone
 }
 
-function hook_config_exists() {
-       hook_exists config $@
+hook_config_exists() {
+       hook_exists config "$@"
 }
 
-function hook_config_exec() {
-       hook_exec config $@
+hook_config_exec() {
+       hook_exec config "$@"
 }
 
-function hook_config_get_all() {
+hook_config_get_all() {
        hook_list config
 }
 
-function hook_valid_command() {
+hook_valid_command() {
        local type="${1}"
        local cmd="${2}"
 
@@ -184,11 +206,11 @@ function hook_valid_command() {
        return ${EXIT_FALSE}
 }
 
-function hook_valid_command_config() {
+hook_valid_command_config() {
        local cmd="${1}"
 
        case "${cmd}" in
-               create|remove|edit|up|down|status)
+               new|destroy|edit|up|down|status|hid)
                        return ${EXIT_TRUE}
                        ;;
        esac
@@ -196,7 +218,7 @@ function hook_valid_command_config() {
        return ${EXIT_FALSE}
 }
 
-function hook_valid_command_port() {
+hook_valid_command_port() {
        local cmd="${1}"
 
        case "${cmd}" in
@@ -216,7 +238,7 @@ function hook_valid_command_port() {
                        ;;
 
                # Status
-               status|info)
+               status|children)
                        return ${EXIT_TRUE}
                        ;;
        esac
@@ -224,7 +246,7 @@ function hook_valid_command_port() {
        return ${EXIT_FALSE}
 }
 
-function hook_valid_command_zone() {
+hook_valid_command_zone() {
        local cmd="${1}"
 
        case "${cmd}" in
@@ -233,7 +255,7 @@ function hook_valid_command_zone() {
                        return ${EXIT_TRUE}
                        ;;
 
-               config_create|config_edit|config_remove|config_show)
+               config_new|config_destroy|config_edit|config_show)
                        return ${EXIT_TRUE}
                        ;;
 
@@ -248,7 +270,7 @@ function hook_valid_command_zone() {
                        ;;
 
                # Ports
-               port_add|port_edit|port_create|port_remove|port_show|port_status|port_up|port_down)
+               port_attach|port_detach|port_edit|port_create|port_remove|port_status|port_up|port_down)
                        return ${EXIT_TRUE}
                        ;;