From 7eed0538ae79394a10ac9667a798237457ac2373 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Fri, 6 Sep 2013 16:51:59 +0200 Subject: vty: Refactored vty_go_parent(), 'end' and 'exit' Put all 'exit' logic into vty_go_parent() and replace the implementations of 'exit' and 'end' by generic ones that use vty_go_parent(). --- src/vty/command.c | 57 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/vty/command.c b/src/vty/command.c index 7f502dbe..3892dddd 100644 --- a/src/vty/command.c +++ b/src/vty/command.c @@ -1889,10 +1889,22 @@ enum node_type vty_go_parent(struct vty *vty) { assert(vty->node > CONFIG_NODE); - if (host.app_info->go_parent_cb) - host.app_info->go_parent_cb(vty); - else - vty->node = CONFIG_NODE; + switch (vty->node) { + case CONFIG_NODE: + break; + + case CFG_LOG_NODE: + case VTY_NODE: + vty->node = CONFIG_NODE; + break; + + default: + if (host.app_info->go_parent_cb) + host.app_info->go_parent_cb(vty); + else + vty->node = CONFIG_NODE; + break; + } return vty->node; } @@ -2266,13 +2278,9 @@ gDEFUN(config_exit, vty->node = ENABLE_NODE; vty_config_unlock(vty); break; - case VTY_NODE: - vty->node = CONFIG_NODE; - break; - case CFG_LOG_NODE: - vty->node = CONFIG_NODE; - break; default: + if (vty->node > CONFIG_NODE) + vty_go_parent (vty); break; } return CMD_SUCCESS; @@ -2282,19 +2290,24 @@ gDEFUN(config_exit, gDEFUN(config_end, config_end_cmd, "end", "End current mode and change to enable mode.") { - switch (vty->node) { - case VIEW_NODE: - case ENABLE_NODE: - /* Nothing to do. */ - break; - case CFG_LOG_NODE: - case CONFIG_NODE: - case VTY_NODE: + if (vty->node > ENABLE_NODE) { + enum node_type last_node = CONFIG_NODE; + + /* Repeatedly call go_parent until a top node is reached. */ + while (vty->node > CONFIG_NODE) { + if (vty->node == last_node) { + /* Ensure termination, this shouldn't happen. */ + break; + } + last_node = vty->node; + vty_go_parent(vty); + } + vty_config_unlock(vty); - vty->node = ENABLE_NODE; - break; - default: - break; + if (vty->node > ENABLE_NODE) + vty->node = ENABLE_NODE; + vty->index = NULL; + vty->index_sub = NULL; } return CMD_SUCCESS; } -- cgit v1.2.3