[VTY] Introduce "struct vty_app_info" for vty_init() function

This commit is contained in:
Harald Welte 2010-05-25 23:00:45 +02:00
parent 4ebdf74728
commit 237f6241f2
4 changed files with 22 additions and 19 deletions

View File

@ -58,9 +58,7 @@ struct host {
const char *motd; const char *motd;
char *motdfile; char *motdfile;
const char *prog_name; const struct vty_app_info *app_info;
const char *prog_version;
const char *prog_copyright;
}; };
/* There are some command levels which called from command node. */ /* There are some command levels which called from command node. */
@ -387,6 +385,4 @@ void print_version(int print_copyright);
extern void *tall_vty_cmd_ctx; extern void *tall_vty_cmd_ctx;
enum node_type (*vty_go_parent_cb)(struct vty *vty);
#endif /* _ZEBRA_COMMAND_H */ #endif /* _ZEBRA_COMMAND_H */

View File

@ -127,8 +127,16 @@ static inline char *vty_newline(struct vty *vty)
return VTY_NEWLINE; return VTY_NEWLINE;
} }
struct vty_app_info {
char *name;
char *version;
char *copyright;
void *tall_ctx;
enum node_type (*go_parent_cb)(struct vty *vty);
};
/* Prototypes. */ /* Prototypes. */
void vty_init(const char *name, const char *version, const char *copyright); void vty_init(struct vty_app_info *app_info);
int vty_read_config_file(const char *file_name, void *priv); int vty_read_config_file(const char *file_name, void *priv);
void vty_init_vtysh (void); void vty_init_vtysh (void);
void vty_reset (void); void vty_reset (void);

View File

@ -84,9 +84,9 @@ const char *default_motd = "";
/* This is called from main when a daemon is invoked with -v or --version. */ /* This is called from main when a daemon is invoked with -v or --version. */
void print_version(int print_copyright) void print_version(int print_copyright)
{ {
printf("%s version %s\n", host.prog_name, host.prog_version); printf("%s version %s\n", host.app_info->name, host.app_info->version);
if (print_copyright) if (print_copyright)
printf("\n%s\n", host.prog_copyright); printf("\n%s\n", host.app_info->copyright);
} }
/* Utility function to concatenate argv argument into a single string /* Utility function to concatenate argv argument into a single string
@ -1751,8 +1751,8 @@ enum node_type vty_go_parent(struct vty *vty)
{ {
assert(vty->node > CONFIG_NODE); assert(vty->node > CONFIG_NODE);
if (vty_go_parent_cb) if (host.app_info->go_parent_cb)
vty_go_parent_cb(vty); host.app_info->go_parent_cb(vty);
else else
vty->node = CONFIG_NODE; vty->node = CONFIG_NODE;
@ -2162,9 +2162,10 @@ gDEFUN(config_exit,
DEFUN(show_version, DEFUN(show_version,
show_version_cmd, "show version", SHOW_STR "Displays program version\n") show_version_cmd, "show version", SHOW_STR "Displays program version\n")
{ {
vty_out(vty, "%s %s (%s).%s", host.prog_name, host.prog_version, vty_out(vty, "%s %s (%s).%s", host.app_info->name,
host.name ? host.name : "", VTY_NEWLINE); host.app_info->version,
vty_out(vty, "%s%s", host.prog_copyright, VTY_NEWLINE); host.app_info->name ? host.app_info->name : "", VTY_NEWLINE);
vty_out(vty, "%s%s", host.app_info->copyright, VTY_NEWLINE);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -2258,7 +2259,7 @@ DEFUN(config_write_file,
/* Config file header print. */ /* Config file header print. */
vty_out(file_vty, "!\n! %s (%s) configuration saved from vty\n!", vty_out(file_vty, "!\n! %s (%s) configuration saved from vty\n!",
host.prog_name, host.prog_version); host.app_info->name, host.app_info->version);
//vty_time_print (file_vty, 1); //vty_time_print (file_vty, 1);
vty_out(file_vty, "!\n"); vty_out(file_vty, "!\n");

View File

@ -1633,17 +1633,15 @@ void vty_init_vtysh()
extern void *tall_bsc_ctx; extern void *tall_bsc_ctx;
/* Install vty's own commands like `who' command. */ /* Install vty's own commands like `who' command. */
void vty_init(const char *name, const char *version, const char *copyright) void vty_init(struct vty_app_info *app_info)
{ {
tall_vty_ctx = talloc_named_const(NULL, 0, "vty"); tall_vty_ctx = talloc_named_const(app_info->tall_ctx, 0, "vty");
tall_vty_vec_ctx = talloc_named_const(tall_vty_ctx, 0, "vty_vector"); tall_vty_vec_ctx = talloc_named_const(tall_vty_ctx, 0, "vty_vector");
tall_vty_cmd_ctx = talloc_named_const(tall_vty_ctx, 0, "vty_command"); tall_vty_cmd_ctx = talloc_named_const(tall_vty_ctx, 0, "vty_command");
cmd_init(1); cmd_init(1);
host.prog_name = name; host.app_info = app_info;
host.prog_version = version;
host.prog_copyright = copyright;
/* For further configuration read, preserve current directory. */ /* For further configuration read, preserve current directory. */
vty_save_cwd(); vty_save_cwd();