/* Generic CLI Installation. */ int cli_install_gen (struct cli_tree *ctree, int mode, u_char privilege, u_int16_t flags, struct cli_element *cel) { struct cli_builder cb; struct cli_node *node; vector parent; int index, max; /* Set flags. */ if (flags) SET_FLAG (cel->flags, flags); /* Check help string is there. */ cli_check_help (cel, &index, &max); if (mode > MAX_MODE) return -1; /* Lookup root node. */ node = vector_lookup_index (ctree->modes, mode); /* Install a new root node. */ if (! node) { node = cli_node_new (); vector_set_index (ctree->modes, mode, node); } /* Update IFNAME token and help string. */ if (ifname_expand_token) cli_ifname_reflect (cel, index, max); /* Set initial value before calling cli_build(). */ parent = vector_init (VECTOR_MIN_SIZE); vector_set (parent, node); cb.str = cel->str; cb.index = 0; cli_build (parent, NULL, NULL, &cb, cel, privilege, 0); vector_free (parent); return 0; }
struct config * config_get (int index, char *line) { struct config *config; struct config *config_loop; struct list *master; struct listnode *nn; config = config_loop = NULL; master = vector_lookup_index (configvec, index); if (! master) { master = list_new (); master->del = (void (*) (void *))config_del; master->cmp = (int (*)(void *, void *)) config_cmp; vector_set_index (configvec, index, master); } LIST_LOOP (master, config_loop, nn) { if (strcmp (config_loop->name, line) == 0) config = config_loop; } if (! config) { config = config_new (); config->line = list_new (); config->line->del = (void (*) (void *))line_del; config->line->cmp = (int (*)(void *, void *)) line_cmp; config->name = XSTRDUP (MTYPE_VTYSH_CONFIG_LINE, line); config->index = index; listnode_add (master, config); } return config; }