These are the basic functions to work with hids.
Fixes: #11406
Signed-off-by: Jonatan Schlag jonatan.schlag@ipfire.org --- src/functions/functions.zone | 80 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+)
diff --git a/src/functions/functions.zone b/src/functions/functions.zone index bba1705..0696750 100644 --- a/src/functions/functions.zone +++ b/src/functions/functions.zone @@ -656,6 +656,69 @@ zone_config_list_ids() { echo ${ids} }
+# List all hids of a zone +zone_config_list_hids() { + assert [ $# -eq 1 ] + local zone=${1} + + local config + local hids + + for config in $(zone_configs_list ${zone}); do + # Append hids to the list + zone_config_get_hid "${zone}" "${config}" + done +} + +# get the hid from a given config +zone_config_get_hid() { + assert [ $# -eq 2 ] + local zone=${1} + local config=${2} + + local hook + + hook="$(zone_config_get_hook "${zone}" "${config}")" + hook_exec "config" "${hook}" "hid" "${zone}" "${config}" +} + +# Checks if a hid is valid for a given zone +zone_config_hid_is_valid() { + assert [ $# -eq 2] + local zone=${1} + local hid=${2} + + local _hid + for _hid in $(zone_config_list_hids "${zone}"); do + if [[ ${_hid} = ${hid} ]]; then + return ${EXIT_TRUE} + fi + done + + return ${EXIT_FALSE} +} + +# This function converts a hid to a id +zone_config_convert_hid_to_id() { + assert [ $# -eq 2 ] + local zone=${1} + local hid=${2} + + local hook + local config + + for config in $(zone_configs_list ${zone}); do + # Get hook from config + hook="$(zone_config_get_hook "${zone}" "${config}")" + if [[ "$(hook_exec "config" "${hook}" "hid" "${zone}" "${config}")" == "${hid}" ]]; then + config_get_id_from_config "${config}" + return ${EXIT_TRUE} + fi + done + + return ${EXIT_FALSE} +} + zone_show() { local zone=${1}
@@ -1114,6 +1177,23 @@ zone_config_id_is_valid() { [ -f ${zone_path}/configs/*.${id} ]; }
+# This function checks if a given hid is valid for a zone +# Return True when yes and false when no +zone_config_hid_is_valid() { + assert [ $# -eq 2 ] + local zone=${1} + local hid=${2} + + local _hid + for _hid in $(zone_config_list_hids ${zone}); do + if [[ ${_hid} == ${hid} ]]; then + return ${EXIT_TRUE} + fi + done + + return ${EXIT_FALSE} +} + zone_config_get_hook_from_id() { # Returns the hook for a given id assert [ $# -eq 2 ]