From 5cae7eea451f2b7d65b5892e2c1dafc70f8b836e Mon Sep 17 00:00:00 2001 From: Chris Hall Date: Sun, 13 Feb 2011 23:11:45 +0000 Subject: Second tranche of updates for pipework branch. modified: bgpd/bgp_connection.c modified: bgpd/bgp_debug.c modified: bgpd/bgp_engine.h modified: bgpd/bgp_main.c modified: bgpd/bgp_packet.c modified: bgpd/bgp_peer.c modified: bgpd/bgp_route.c modified: bgpd/bgp_routemap.c modified: bgpd/bgp_session.c modified: bgpd/bgp_vty.c modified: bgpd/bgpd.c modified: bgpd/bgpd.h modified: configure.ac modified: isisd/dict.h modified: isisd/isis_misc.c modified: isisd/isis_routemap.c modified: isisd/isis_spf.c modified: lib/Makefile.am modified: lib/command.c modified: lib/command.h modified: lib/command_execute.h modified: lib/command_parse.c modified: lib/command_parse.h modified: lib/command_queue.c modified: lib/command_queue.h modified: lib/elstring.h modified: lib/heap.c modified: lib/if.c modified: lib/if.h modified: lib/keychain.c modified: lib/keystroke.c modified: lib/keystroke.h modified: lib/list_util.c modified: lib/list_util.h modified: lib/log.c modified: lib/log.h modified: lib/memory.c modified: lib/memory.h modified: lib/memtypes.c modified: lib/misc.h modified: lib/mqueue.c modified: lib/mqueue.h deleted: lib/node_type.h modified: lib/pthread_safe.c modified: lib/qfstring.c modified: lib/qiovec.c modified: lib/qiovec.h modified: lib/qpath.c modified: lib/qpnexus.c modified: lib/qpnexus.h modified: lib/qpselect.c modified: lib/qpthreads.h modified: lib/qstring.c modified: lib/qstring.h modified: lib/qtime.c modified: lib/qtime.h modified: lib/qtimers.c modified: lib/qtimers.h modified: lib/routemap.c modified: lib/symtab.h modified: lib/thread.h deleted: lib/uty.h modified: lib/vector.c modified: lib/vector.h modified: lib/version.h.in modified: lib/vio_fifo.c modified: lib/vio_fifo.h modified: lib/vio_lines.c modified: lib/vio_lines.h modified: lib/vty.c modified: lib/vty.h modified: lib/vty_cli.c modified: lib/vty_cli.h modified: lib/vty_io.c modified: lib/vty_io.h modified: lib/vty_io_basic.c modified: lib/vty_io_basic.h modified: lib/vty_io_file.c modified: lib/vty_io_file.h modified: lib/vty_io_shell.c modified: lib/vty_io_term.c modified: lib/vty_io_term.h modified: lib/vty_local.h modified: lib/vty_pipe.c modified: lib/workqueue.h modified: lib/zebra.h modified: ospf6d/ospf6_lsa.c modified: ripngd/ripngd.c modified: tests/test-list_util.c modified: tests/test-vector.c modified: vtysh/vtysh.c modified: vtysh/vtysh_config.c --- lib/command_execute.h | 135 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 90 insertions(+), 45 deletions(-) (limited to 'lib/command_execute.h') diff --git a/lib/command_execute.h b/lib/command_execute.h index 6a7e2e4b..c1a2bdd0 100644 --- a/lib/command_execute.h +++ b/lib/command_execute.h @@ -23,59 +23,104 @@ #ifndef _ZEBRA_COMMAND_EXECUTE_H #define _ZEBRA_COMMAND_EXECUTE_H -#include "command.h" +#include "command_local.h" #include "command_parse.h" -#include "node_type.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 (const char* line, node_type_t node, - cmd_return_code_t* 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 "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, cmd_arg_vector_argc(parsed), - cmd_arg_vector_argv(parsed)) ; + exec_null = 0, + + exec_special, /* not a simple command */ + + exec_fetch, + exec_parse, + exec_open_pipes, + exec_execute, + exec_success, + exec_complete, } ; +typedef enum cmd_exec_state cmd_exec_state_t ; + +typedef struct cmd_exec* cmd_exec ; + +struct cmd_exec +{ + vty vty ; /* parent */ -#define cmd_parse_reset_keep(parsed) cmd_parse_reset(parsed, 0) -#define cmd_parse_reset_free(parsed) cmd_parse_reset(parsed, 1) + qstring line ; /* pointer to qstring in vf */ + cmd_do_t to_do ; /* for cli driven stuff */ -extern void config_replace_string (struct cmd_element *, char *, ...); + cmd_parse_type_t parse_type ; /* how should parse */ + bool out_enabled ; /* as required */ + bool reflect_enabled ; /* as required */ + + cmd_parsed_t parsed ; /* embedded */ + + 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 + * + */ -/* 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 *); +extern cmd_exec cmd_exec_new(vty vty) ; +extern cmd_exec cmd_exec_free(cmd_exec exec) ; -/* "" global */ -extern char *command_cr; +extern cmd_return_code_t cmd_read_config(vty vty, cmd_command first_cmd, + bool ignore_warning) ; +extern cmd_return_code_t cmd_end(vty vty) ; +extern cmd_return_code_t cmd_exit(vty vty) ; + +extern cmd_return_code_t cmd_open_pipes(vty vty) ; + +extern cmd_return_code_t cmd_execute(vty vty) ; + + + + + + +#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 */ -- cgit v1.2.3