diff options
Diffstat (limited to 'lib/command_execute.h')
-rw-r--r-- | lib/command_execute.h | 133 |
1 files changed, 89 insertions, 44 deletions
diff --git a/lib/command_execute.h b/lib/command_execute.h index a5a807c8..97033b6e 100644 --- a/lib/command_execute.h +++ b/lib/command_execute.h @@ -23,57 +23,102 @@ #ifndef _ZEBRA_COMMAND_EXECUTE_H #define _ZEBRA_COMMAND_EXECUTE_H -#include "command.h" - -extern vector cmd_make_strvec (const char *); -extern vector cmd_add_to_strvec (vector v, const char* str) ; -extern void cmd_free_strvec (vector); -extern vector cmd_describe_command (vector, int, int *status); -extern vector cmd_complete_command (vector, int, int *status); -extern const char *cmd_prompt (enum node_type); -extern enum cmd_return_code -config_from_file (struct vty* vty, FILE *fp, struct cmd_element* first_cmd, - qstring buf, bool stop_on_warning) ; -extern enum node_type node_parent (enum node_type); -extern enum cmd_return_code cmd_execute_command (struct vty *vty, - enum cmd_parse_type type, struct cmd_element **cmd) ; -extern enum cmd_return_code cmd_execute_command_strict (struct vty *vty, - enum cmd_parse_type type, struct cmd_element **cmd) ; - -extern cmd_parsed cmd_parse_init_new(cmd_parsed parsed) ; -extern cmd_parsed cmd_parse_reset(cmd_parsed parsed, bool free_structure) ; -extern enum cmd_return_code cmd_parse_command(struct vty* vty, - enum cmd_parse_type type) ; -extern enum cmd_return_code cmd_dispatch(struct vty* vty, bool no_queue) ; - -Inline enum cmd_return_code -cmd_dispatch_call(struct vty* vty) +#include "command_local.h" +#include "command_parse.h" +#include "vty_common.h" +#include "qstring.h" +#include "mqueue.h" +#include "qpnexus.h" +#include "thread.h" + +/*============================================================================== + * This is stuff which is used to parse and then execute commands. + */ + +/* State of the execution loop + */ +enum cmd_exec_state { - cmd_parsed parsed = vty->parsed ; - return (*(parsed->cmd->func))(parsed->cmd, vty, - vector_length(&parsed->vline), - (const char * const*)vector_body(&parsed->vline)) ; + exec_null = 0, /* not started, yet */ + exec_fetch, /* fetch command line */ + exec_open_pipes, /* open pipes on command line */ + exec_execute, /* execute standard command */ + exec_special, /* execute special command */ + exec_done_cmd, /* command has completed */ + exec_hiatus, /* while issues are dealt with */ + exec_stopped, /* command loop has stopped */ } ; +typedef enum cmd_exec_state cmd_exec_state_t ; + +typedef struct cmd_exec* cmd_exec ; + +struct cmd_exec +{ + vty vty ; /* parent */ + + cmd_action_t action ; /* to do + line */ -#define cmd_parse_reset_keep(parsed) cmd_parse_reset(parsed, 0) -#define cmd_parse_reset_free(parsed) cmd_parse_reset(parsed, 1) + cmd_context context ; /* how to parse/execute */ -extern void config_replace_string (struct cmd_element *, char *, ...); + bool out_suppress ; /* for configuration reading */ + bool reflect ; /* actually reflect */ -/* Export typical functions. */ -extern struct cmd_element config_end_cmd; -extern struct cmd_element config_exit_cmd; -extern struct cmd_element config_quit_cmd; -extern struct cmd_element config_help_cmd; -extern struct cmd_element config_list_cmd; -extern char *host_config_file (void); -extern void host_config_set (char *); + cmd_parsed parsed ; /* parsing and its result */ -/* "<cr>" global */ -extern char *command_cr; + uint password_failures ; /* AUTH_NODE & AUTH_ENABLE_NODE */ + + cmd_exec_state_t state ; /* for cq_process */ + qpn_nexus locus ; /* for cq_process */ + + cmd_return_code_t ret ; /* for cq_process */ + + union + { + mqueue_block mqb ; /* for cq_process */ + struct thread* thread ; + } cq ; +} ; + +/*============================================================================== + * Functions + * + */ + +extern cmd_exec cmd_exec_new(vty vty) ; +extern cmd_exec cmd_exec_free(cmd_exec exec) ; + +extern cmd_return_code_t cmd_read_config(vty vty, cmd_command first_cmd, + bool ignore_warning) ; +extern cmd_return_code_t cmd_open_pipes(vty vty) ; + +extern cmd_return_code_t cmd_execute(vty vty) ; + +extern cmd_context cmd_context_new(void) ; +extern cmd_context cmd_context_new_save(cmd_context src, qpath file_here) ; +extern cmd_context cmd_context_restore(cmd_context dst, cmd_context src) ; +extern cmd_context cmd_context_free(cmd_context context, bool copy) ; + + +#if 0 + +extern enum cmd_return_code cmd_execute_command (vty vty, + cmd_parse_type_t type, struct cmd_command **cmd) ; +extern enum cmd_return_code cmd_execute_command_strict (vty vty, + enum cmd_parse_type type, struct cmd_command **cmd) ; + + +extern void config_replace_string (cmd_command, char *, ...); -#ifdef QDEBUG -extern const char *debug_banner; #endif +/*============================================================================== + * Inlines + */ + +Inline bool +cmd_is_direct(cmd_parsed parsed) +{ + return ((parsed->cmd->attr & CMD_ATTR_DIRECT) != 0) ; +} ; + #endif /* _ZEBRA_COMMAND_EXECUTE_H */ |