From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonatan Schlag To: network@lists.ipfire.org Subject: [PATCH v2 1/8] zone: add config hid functions Date: Wed, 26 Jul 2017 10:44:37 +0200 Message-ID: <1501058684-19861-1-git-send-email-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4592714959029559098==" List-Id: --===============4592714959029559098== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable These are the basic functions to work with hids. Fixes: #11406 Signed-off-by: Jonatan Schlag --- 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} } =20 +# List all hids of a zone +zone_config_list_hids() { + assert [ $# -eq 1 ] + local zone=3D${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=3D${1} + local config=3D${2} + + local hook + + hook=3D"$(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=3D${1} + local hid=3D${2} + + local _hid + for _hid in $(zone_config_list_hids "${zone}"); do + if [[ ${_hid} =3D ${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=3D${1} + local hid=3D${2} + + local hook + local config + + for config in $(zone_configs_list ${zone}); do + # Get hook from config + hook=3D"$(zone_config_get_hook "${zone}" "${config}")" + if [[ "$(hook_exec "config" "${hook}" "hid" "${zone}" "${config}")" =3D=3D= "${hid}" ]]; then + config_get_id_from_config "${config}" + return ${EXIT_TRUE} + fi + done + + return ${EXIT_FALSE} +} + zone_show() { local zone=3D${1} =20 @@ -1114,6 +1177,23 @@ zone_config_id_is_valid() { [ -f ${zone_path}/configs/*.${id} ]; } =20 +# 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=3D${1} + local hid=3D${2} + + local _hid + for _hid in $(zone_config_list_hids ${zone}); do + if [[ ${_hid} =3D=3D ${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 ] --=20 2.6.3 --===============4592714959029559098==--