]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/header-zone
hostapd: Set default WMM settings
[people/ms/network.git] / src / header-zone
index e9b7c91389d4e96b4bfa9b151df70dbe92bfa0f4..ead4a32c0512fb6170f6191ead4544286cd217e6 100644 (file)
@@ -34,17 +34,39 @@ hook_new() {
        assert isset zone
        shift
 
-       zone_settings_read "${zone}"
-
-       hook_parse_cmdline $@
+       if ! hook_parse_cmdline "$@"; then
+               return ${EXIT_ERROR}
+       fi
 
-       zone_settings_write "${zone}"
+       if ! zone_settings_write "${zone}"; then
+               log ERROR "Could not write settings for zone ${zone}"
+               return ${EXIT_ERROR}
+       fi
 
        exit ${EXIT_OK}
 }
 
 hook_edit() {
-       hook_new $@
+       local zone="${1}"
+       assert isset zone
+       shift
+
+       if ! zone_settings_read "${zone}"; then
+               log ERROR "Could not read settings for zone ${zone}"
+               return ${EXIT_ERROR}
+       fi
+
+       if ! hook_parse_cmdline "$@"; then
+               return ${EXIT_ERROR}
+       fi
+
+       if ! zone_settings_write "${zone}"; then
+               log ERROR "Could not write settings for zone ${zone}"
+               return ${EXIT_ERROR}
+       fi
+
+       exit ${EXIT_OK}
+
 }
 
 hook_remove() {
@@ -90,7 +112,7 @@ hook_port() {
        local ret
        case "${action}" in
                add|create|edit|rem|show)
-                       hook_port_${action} "${zone}" $@
+                       hook_port_${action} "${zone}" "$@"
                        ret=$?
                        ;;
                *)
@@ -128,7 +150,7 @@ hook_default_port_create() {
 }
 
 hook_port_create() {
-       hook_default_port_create $@
+       hook_default_port_create "$@"
 }
 
 hook_default_port_remove() {
@@ -141,7 +163,7 @@ hook_default_port_remove() {
 }
 
 hook_port_remove() {
-       hook_default_port_remove $@
+       hook_default_port_remove "$@"
 }
 
 hook_port_up() {
@@ -162,7 +184,7 @@ hook_config() {
 
        local ret
        case "${action}" in
-               create|edit|rem|show)
+               new|destroy|edit|show)
                        hook_config_${action} "${zone}" "$@"
                        exit $?
                        ;;
@@ -199,18 +221,62 @@ hook_config_cmd() {
        hook_config_exec "${hook_config}" "${cmd}" "${zone}" "$@"
 }
 
-hook_config_create() {
+hook_config_new() {
        assert [ $# -ge 2 ]
 
-       hook_config_cmd "create" "$@"
+       hook_config_cmd "new" "$@"
 }
 
-hook_config_edit() {
-       hook_config_cmd "edit" "$@"
+hook_config_destroy() {
+       assert [ $# -eq 2 ]
+       local zone=${1}
+       # The id must be the id and not the hid.
+       local id=${2}
+
+       shift 2
+
+       # Check if we get a valid id
+       if ! zone_config_id_is_valid ${zone} ${id}; then
+               log ERROR "ID: ${id} is not a valid id for zone ${zone}"
+       fi
+
+       local hook=$(zone_config_get_hook_from_id ${zone}  ${id})
+       assert isset hook
+
+       # First we bring the hook down
+       hook_config_cmd "down" "${zone}" "${hook}" "${hook}.${id}"
+
+       # If a hook_destroy function is implemented in the hook this function will be executed.
+       # If not a empty defined in header-config is executed.
+       if ! hook_config_cmd "destroy" "${zone}" "${hook}" "${hook}.${id}" "$@"; then
+
+               # A better error message should printed inside the hook.
+               # We will not bring the config up because we do not know if it is safe or if some parts are already destroyed.
+               log ERROR "Could not destroy config with the follwoing id: ${id}"
+               return ${EXIT_ERROR}
+       fi
+
+       # Now we delete the config of the zone
+       zone_config_settings_destroy "${zone}" "${hook}.${id}"
 }
 
-hook_config_remove() {
-       hook_config_cmd "remove" "$@"
+hook_config_edit() {
+       assert [ $# -ge 2 ]
+       local zone=${1}
+       # The id must be the id and not the hid.
+       local id=${2}
+
+       shift 2
+
+       # Check if we get a valid id
+       if ! zone_config_id_is_valid ${zone} ${id}; then
+               log ERROR "ID: ${id} is not a valid id for zone ${zone}"
+       fi
+
+       local hook=$(zone_config_get_hook_from_id ${zone} ${id})
+       assert isset hook
+
+       hook_config_cmd "edit" "${zone}" "${hook}" "${hook}.${id}" "$@"
 }
 
 hook_config_show() {