]> git.proxmox.com Git - mirror_frr.git/blame - lib/command_match.h
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / command_match.h
CommitLineData
1ab84bf3
QY
1/*
2 * Input matching routines for CLI backend.
3 *
4 * --
5 * Copyright (C) 2016 Cumulus Networks, Inc.
6 *
7 * This file is part of GNU Zebra.
8 *
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
896014f4
DL
19 * You should have received a copy of the GNU General Public License along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1ab84bf3
QY
22 */
23
24#ifndef _ZEBRA_COMMAND_MATCH_H
25#define _ZEBRA_COMMAND_MATCH_H
9d0662e0 26
1eb5e8dc 27#include "graph.h"
18be0e59 28#include "linklist.h"
1eb5e8dc 29#include "command.h"
eceb1066 30
1ab84bf3
QY
31/* These definitions exist in command.c in the current engine but should be
32 * relocated here in the new engine
33 */
d62a17ae 34enum filter_type { FILTER_RELAXED, FILTER_STRICT };
9d0662e0 35
1ab84bf3 36/* matcher result value */
d62a17ae 37enum matcher_rv {
38 MATCHER_NO_MATCH,
39 MATCHER_INCOMPLETE,
40 MATCHER_AMBIGUOUS,
41 MATCHER_OK,
9d0662e0
QY
42};
43
1ab84bf3 44/* completion match types */
d62a17ae 45enum match_type {
46 trivial_match, // the input is null
47 no_match, // the input does not match
48 partly_match, // the input matches but is incomplete
49 exact_match // the input matches and is complete
9d0662e0 50};
eceb1066 51
1ab84bf3
QY
52/* Defines which matcher_rv values constitute an error. Should be used with
53 * matcher_rv return values to do basic error checking.
9d0662e0 54 */
d62a17ae 55#define MATCHER_ERROR(matcher_rv) \
56 ((matcher_rv) == MATCHER_INCOMPLETE \
57 || (matcher_rv) == MATCHER_NO_MATCH \
58 || (matcher_rv) == MATCHER_AMBIGUOUS)
9d0662e0 59
eceb1066
QY
60/**
61 * Attempt to find an exact command match for a line of user input.
62 *
1eb5e8dc 63 * @param[in] cmdgraph command graph to match against
1ab84bf3 64 * @param[in] vline vectorized input string
17aca20b
QY
65 * @param[out] argv pointer to argument list if successful match, NULL
66 * otherwise. The elements of this list are pointers to struct cmd_token
67 * and represent the sequence of tokens matched by the inpu. The ->arg
68 * field of each token points to a copy of the input matched on it. These
69 * may be safely deleted or modified.
70 * @param[out] element pointer to matched cmd_element if successful match,
71 * or NULL when MATCHER_ERROR(rv) is true. The cmd_element may *not* be
72 * safely deleted or modified; it is the instance initialized on startup.
1ab84bf3 73 * @return matcher status
eceb1066 74 */
d62a17ae 75enum matcher_rv command_match(struct graph *cmdgraph, vector vline,
76 struct list **argv,
77 const struct cmd_element **element);
eceb1066
QY
78
79/**
1ab84bf3 80 * Compiles possible completions for a given line of user input.
eceb1066
QY
81 *
82 * @param[in] start the start node of the DFA to match against
1ab84bf3 83 * @param[in] vline vectorized input string
17aca20b
QY
84 * @param[out] completions pointer to list of cmd_token representing
85 * acceptable next inputs, or NULL when MATCHER_ERROR(rv) is true.
86 * The elements of this list are pointers to struct cmd_token and take on a
87 * variety of forms depending on the passed vline. If the last element in vline
88 * is NULL, all previous elements are considered to be complete words (the case
89 * when a space is the last token of the line) and completions are generated
90 * based on what could follow that input. If the last element in vline is not
91 * NULL and each sequential element matches the corresponding tokens of one or
92 * more commands exactly (e.g. 'encapv4' and not 'en') the same result is
93 * generated. If the last element is not NULL and the best possible match is a
94 * partial match, then the result generated will be all possible continuations
95 * of that element (e.g. 'encapv4', 'encapv6', etc for input 'en').
96 * @return matcher status
eceb1066 97 */
d62a17ae 98enum matcher_rv command_complete(struct graph *cmdgraph, vector vline,
99 struct list **completions);
eceb1066 100
1ab84bf3 101#endif /* _ZEBRA_COMMAND_MATCH_H */