The function prototype for command_parse_format() is better left in
command.h, so that the bison-generated header file doesn't need to be
included for that.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
WORD tokens (which are also used for "LINE..." input) should really
accept all characters.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
When a user erroneously defines two commands which can
match the same input and at least one of the tokens defined
last in the command is a selector or option, the matcher
does not detect an ambiguous match and matches the command
installed first (leftmost in the graph).
Fix is to do a full walkthrough of the follow set when
matching the final token in a command to check that there
is exactly one possible match, and to throw an ambiguity
error otherwise.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Fix a few memory issues:
* Not freeing tab-completions upon input match failure
* Invalid write when null-terminating tab-completions
* Not freeing argv[] itself in additinon to elements
* Use XFREE() instead of free() as appropriate
* Not freeing final token of an [option] during parsing
Make a few minor changes to CLI internals:
* Improve documentation on matching & completion functions
* Only make one copy of cmd_token's when building argv,
instead of three
* Don't make a copy of the matching cmd_element
Make one major(ish) change to CLI internals:
* Change all pointers to struct cmd_element to const
Code outside of the core CLI units should never have an
occasion to modify the internal state of the command system.
Doing so could easily amount to having a CLI interface that
changes during runtime, and could conceivably lead to security
issues. Explicitly disallowing this removes any chance of
confusion.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Each token now knows whether it is part of a hidden
or deprecated command. Command completion logic hides
such tokens when generating completions. Command
matching logic works as before and will still match on
hidden and deprecated commands.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Adds a missing check that resulted in partial token
matches being accepted as exact matches when calculating
input completions.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Range matching function was returning 0 instead of no_match
on failed match, causing all input to match ranges.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
When the user tab- or ?-completes when the character prior to
the position of the cursor is a space, completion logic is
passed null. Explicitly handle this case instead of using
partly_match, which has special logic associated with it to
allow abbreviating certain tokens.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Shotgun commit:
* Remove shim sources from Makefile.am
* Move new types to command.c / command.h
* Rewrite command.c / command.h
* Refactor shim types to real types in matcher
and parser
* Initial refactor pass on vty.c
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Fix incorrect assumption that the set of first tokens
of all commands are perfectly unambiguous
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
- cmd_make_strvec returns null pointer if str
begins with a '#'
- disallow options nested options
- NULL out state variable in parser
- flip backwards comparison
- fix memory leak in lexer
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Gnu-style code, add copyright headers, cleanup some
random style issues, shuffle around code into
relevant units, add docs.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Disambiguation logic now compares full paths
instead of defaulting to an ambiguous match
if the heads cannot be disambiguated
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Completions now include nodes that the input
partially matches as well as the children of
nodes those that the input exactly matches.
Also some minor cleanup and bugfixes.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Variables now allow strings beginning with numbers
to match, ranges and numbers are now long long to
fix OOB parses resulting in integer wraparounds.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
When building argv for matched command, only the
last node was being copied to argv; the rest were
added by reference. Additionally the regex for
certain tokens was too restrictive and disallowed
characters allowed by the old parser; these have
been reinstated.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Various memory leaks have been fixed and the quagga
memory macros are in use. Also consolidated the argv
and matching code into one graph traversal.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Fixed a variety of failure cases and wrote a nice
doc string. Reverted add_node doc string to correct
explanation of procedure.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Queries may be run against DFA's to find matching
cmd_element, and argument lists may be constructed.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>