/* This is called from main when a daemon is invoked with -v or --version. */
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)
- 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
return strcmp(a->cmd, b->cmd);
}
+static int is_config(struct vty *vty)
+{
+ if (vty->node <= CONFIG_NODE)
+ return 0;
+ else if (vty->node > CONFIG_NODE && vty->node < _LAST_OSMOVTY_NODE)
+ return 1;
+ else if (host.app_info->is_config_node)
+ return host.app_info->is_config_node(vty, vty->node);
+ else
+ return vty->node > CONFIG_NODE;
+}
+
/* Sort each node's command element according to command string. */
void sort_node()
{
char *p;
char buf[DECIMAL_STRLEN_MAX + 1];
char *endptr = NULL;
- unsigned long min, max, val;
if (str == NULL)
return 1;
- val = strtoul(str, &endptr, 10);
- if (*endptr != '\0')
- return 0;
-
- range++;
- p = strchr(range, '-');
- if (p == NULL)
- return 0;
- if (p - range > DECIMAL_STRLEN_MAX)
- return 0;
- strncpy(buf, range, p - range);
- buf[p - range] = '\0';
- min = strtoul(buf, &endptr, 10);
- if (*endptr != '\0')
- return 0;
-
- range = p + 1;
- p = strchr(range, '>');
- if (p == NULL)
- return 0;
- if (p - range > DECIMAL_STRLEN_MAX)
- return 0;
- strncpy(buf, range, p - range);
- buf[p - range] = '\0';
- max = strtoul(buf, &endptr, 10);
- if (*endptr != '\0')
- return 0;
-
- if (val < min || val > max)
- return 0;
+ if (range[1] == '-') {
+ signed long min = 0, max = 0, val;
+
+ val = strtol(str, &endptr, 10);
+ if (*endptr != '\0')
+ return 0;
+
+ range += 2;
+ p = strchr(range, '-');
+ if (p == NULL)
+ return 0;
+ if (p - range > DECIMAL_STRLEN_MAX)
+ return 0;
+ strncpy(buf, range, p - range);
+ buf[p - range] = '\0';
+ min = -strtol(buf, &endptr, 10);
+ if (*endptr != '\0')
+ return 0;
+
+ range = p + 1;
+ p = strchr(range, '>');
+ if (p == NULL)
+ return 0;
+ if (p - range > DECIMAL_STRLEN_MAX)
+ return 0;
+ strncpy(buf, range, p - range);
+ buf[p - range] = '\0';
+ max = strtol(buf, &endptr, 10);
+ if (*endptr != '\0')
+ return 0;
+
+ if (val < min || val > max)
+ return 0;
+ } else {
+ unsigned long min, max, val;
+
+ val = strtoul(str, &endptr, 10);
+ if (*endptr != '\0')
+ return 0;
+
+ range++;
+ p = strchr(range, '-');
+ if (p == NULL)
+ return 0;
+ if (p - range > DECIMAL_STRLEN_MAX)
+ return 0;
+ strncpy(buf, range, p - range);
+ buf[p - range] = '\0';
+ min = strtoul(buf, &endptr, 10);
+ if (*endptr != '\0')
+ return 0;
+
+ range = p + 1;
+ p = strchr(range, '>');
+ if (p == NULL)
+ return 0;
+ if (p - range > DECIMAL_STRLEN_MAX)
+ return 0;
+ strncpy(buf, range, p - range);
+ buf[p - range] = '\0';
+ max = strtoul(buf, &endptr, 10);
+ if (*endptr != '\0')
+ return 0;
+
+ if (val < min || val > max)
+ return 0;
+ }
return 1;
}
{
assert(vty->node > CONFIG_NODE);
- if (vty_go_parent_cb)
- vty_go_parent_cb(vty);
+ if (host.app_info->go_parent_cb)
+ host.app_info->go_parent_cb(vty);
else
vty->node = CONFIG_NODE;
if (vtysh)
return saved_ret;
- /* This assumes all nodes above CONFIG_NODE are childs of CONFIG_NODE */
+ /* Go to parent for config nodes to attempt to find the right command */
while (ret != CMD_SUCCESS && ret != CMD_WARNING
- && vty->node > CONFIG_NODE) {
+ && is_config(vty)) {
vty_go_parent(vty);
ret = cmd_execute_command_real(vline, vty, cmd);
tried = 1;
/* Try again with setting node to CONFIG_NODE */
while (ret != CMD_SUCCESS && ret != CMD_WARNING
&& ret != CMD_ERR_NOTHING_TODO
- && vty->node != CONFIG_NODE) {
+ && vty->node != CONFIG_NODE && is_config(vty)) {
vty_go_parent(vty);
ret = cmd_execute_command_strict(vline, vty, NULL);
}
DEFUN(show_version,
show_version_cmd, "show version", SHOW_STR "Displays program version\n")
{
- vty_out(vty, "%s %s (%s).%s", host.prog_name, host.prog_version,
- host.name ? host.name : "", VTY_NEWLINE);
- vty_out(vty, "%s%s", host.prog_copyright, VTY_NEWLINE);
+ vty_out(vty, "%s %s (%s).%s", host.app_info->name,
+ host.app_info->version,
+ host.app_info->name ? host.app_info->name : "", VTY_NEWLINE);
+ vty_out(vty, "%s%s", host.app_info->copyright, VTY_NEWLINE);
return CMD_SUCCESS;
}
/* Config file header print. */
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_out(file_vty, "!\n");