]> git.proxmox.com Git - mirror_frr.git/blob - lib/command_graph.h
11cea9bd4289f7c509d9afa19ab115df4e328073
[mirror_frr.git] / lib / command_graph.h
1 /*
2 * CLI graph handling
3 *
4 * --
5 * Copyright (C) 2016 Cumulus Networks, Inc.
6 * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
7 * Copyright (C) 2013 by Open Source Routing.
8 * Copyright (C) 2013 by Internet Systems Consortium, Inc. ("ISC")
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 * Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25 #ifndef _FRR_COMMAND_GRAPH_H
26 #define _FRR_COMMAND_GRAPH_H
27
28 #include <stdbool.h>
29 #include <stdint.h>
30
31 #include "memory.h"
32 #include "vector.h"
33 #include "graph.h"
34
35 DECLARE_MTYPE(CMD_ARG)
36
37 struct vty;
38
39 /**
40 * Types for tokens.
41 *
42 * The type determines what kind of data the token can match (in the
43 * matching use case) or hold (in the argv use case).
44 */
45 enum cmd_token_type
46 {
47 WORD_TKN, // words
48 VARIABLE_TKN, // almost anything
49 RANGE_TKN, // integer range
50 IPV4_TKN, // IPV4 addresses
51 IPV4_PREFIX_TKN, // IPV4 network prefixes
52 IPV6_TKN, // IPV6 prefixes
53 IPV6_PREFIX_TKN, // IPV6 network prefixes
54
55 /* plumbing types */
56 FORK_TKN, // marks subgraph beginning
57 JOIN_TKN, // marks subgraph end
58 START_TKN, // first token in line
59 END_TKN, // last token in line
60
61 SPECIAL_TKN = FORK_TKN,
62 };
63
64 /* Command attributes */
65 enum
66 {
67 CMD_ATTR_NORMAL,
68 CMD_ATTR_DEPRECATED,
69 CMD_ATTR_HIDDEN,
70 };
71
72 /* Comamand token struct. */
73 struct cmd_token
74 {
75 enum cmd_token_type type; // token type
76 uint8_t attr; // token attributes
77 bool allowrepeat; // matcher allowed to match token repetively?
78 uint32_t refcnt;
79
80 char *text; // token text
81 char *desc; // token description
82 long long min, max; // for ranges
83 char *arg; // user input that matches this token
84 char *varname;
85
86 struct graph_node *forkjoin; // paired FORK/JOIN for JOIN/FORK
87 };
88
89 /* Structure of command element. */
90 struct cmd_element
91 {
92 const char *string; /* Command specification by string. */
93 const char *doc; /* Documentation of this command. */
94 int daemon; /* Daemon to which this command belong. */
95 uint8_t attr; /* Command attributes */
96
97 /* handler function for command */
98 int (*func) (const struct cmd_element *, struct vty *, int, struct cmd_token *[]);
99
100 const char *name; /* symbol name for debugging */
101 };
102
103 /* text for <cr> command */
104 #define CMD_CR_TEXT "<cr>"
105
106 /* memory management for cmd_token */
107 extern struct cmd_token *cmd_token_new (enum cmd_token_type, uint8_t attr,
108 const char *text, const char *desc);
109 extern struct cmd_token *cmd_token_dup (struct cmd_token *);
110 extern void cmd_token_del (struct cmd_token *);
111 extern void cmd_token_varname_set(struct cmd_token *token, const char *varname);
112
113 extern void cmd_graph_parse (struct graph *graph, struct cmd_element *cmd);
114 extern void cmd_graph_names (struct graph *graph);
115 extern void cmd_graph_merge (struct graph *old, struct graph *new, int direction);
116
117 #endif /* _FRR_COMMAND_GRAPH_H */