]> git.proxmox.com Git - mirror_frr.git/blob - lib/command_match.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / lib / command_match.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Input matching routines for CLI backend.
4 *
5 * --
6 * Copyright (C) 2016 Cumulus Networks, Inc.
7 */
8
9 #ifndef _ZEBRA_COMMAND_MATCH_H
10 #define _ZEBRA_COMMAND_MATCH_H
11
12 #include "graph.h"
13 #include "linklist.h"
14 #include "command.h"
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 /* These definitions exist in command.c in the current engine but should be
21 * relocated here in the new engine
22 */
23 enum cmd_filter_type { FILTER_RELAXED, FILTER_STRICT };
24
25 /* matcher result value */
26 enum matcher_rv {
27 MATCHER_NO_MATCH,
28 MATCHER_INCOMPLETE,
29 MATCHER_AMBIGUOUS,
30 MATCHER_OK,
31 };
32
33 /* completion match types */
34 enum match_type {
35 trivial_match, // the input is null
36 no_match, // the input does not match
37 partly_match, // the input matches but is incomplete
38 exact_match // the input matches and is complete
39 };
40
41 /* Defines which matcher_rv values constitute an error. Should be used with
42 * matcher_rv return values to do basic error checking.
43 */
44 #define MATCHER_ERROR(matcher_rv) \
45 ((matcher_rv) == MATCHER_INCOMPLETE \
46 || (matcher_rv) == MATCHER_NO_MATCH \
47 || (matcher_rv) == MATCHER_AMBIGUOUS)
48
49 /**
50 * Attempt to find an exact command match for a line of user input.
51 *
52 * @param[in] cmdgraph command graph to match against
53 * @param[in] vline vectorized input string
54 * @param[out] argv pointer to argument list if successful match, NULL
55 * otherwise. The elements of this list are pointers to struct cmd_token
56 * and represent the sequence of tokens matched by the input. The ->arg
57 * field of each token points to a copy of the input matched on it. These
58 * may be safely deleted or modified.
59 * @param[out] element pointer to matched cmd_element if successful match,
60 * or NULL when MATCHER_ERROR(rv) is true. The cmd_element may *not* be
61 * safely deleted or modified; it is the instance initialized on startup.
62 * @return matcher status
63 */
64 enum matcher_rv command_match(struct graph *cmdgraph, vector vline,
65 struct list **argv,
66 const struct cmd_element **element);
67
68 /**
69 * Compiles possible completions for a given line of user input.
70 *
71 * @param[in] start the start node of the DFA to match against
72 * @param[in] vline vectorized input string
73 * @param[out] completions pointer to list of cmd_token representing
74 * acceptable next inputs, or NULL when MATCHER_ERROR(rv) is true.
75 * The elements of this list are pointers to struct cmd_token and take on a
76 * variety of forms depending on the passed vline. If the last element in vline
77 * is NULL, all previous elements are considered to be complete words (the case
78 * when a space is the last token of the line) and completions are generated
79 * based on what could follow that input. If the last element in vline is not
80 * NULL and each sequential element matches the corresponding tokens of one or
81 * more commands exactly (e.g. 'encapv4' and not 'en') the same result is
82 * generated. If the last element is not NULL and the best possible match is a
83 * partial match, then the result generated will be all possible continuations
84 * of that element (e.g. 'encapv4', 'encapv6', etc for input 'en').
85 * @return matcher status
86 */
87 enum matcher_rv command_complete(struct graph *cmdgraph, vector vline,
88 struct list **completions);
89
90 #ifdef __cplusplus
91 }
92 #endif
93
94 #endif /* _ZEBRA_COMMAND_MATCH_H */