Commit Graph

53 Commits

Author SHA1 Message Date
Quentin Young
54c5dce6a5 lib: Macroize CLI matcher tracing
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-12-02 18:26:47 +00:00
David Lamparter
2ab402707f lib: move command_parse_format prototype
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>
2016-12-01 18:45:22 +01:00
David Lamparter
8af5502876 lib: allow all characters in WORD tokens
WORD tokens (which are also used for "LINE..." input) should really
accept all characters.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-12-01 17:25:56 +01:00
Quentin Young
3c7ca60c41 lib: Fix nondeterministic command matches in rare cases
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>
2016-11-15 22:15:18 +00:00
Quentin Young
17aca20bfb lib, vtysh: Fix memory leaks, change cmd_element to const
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>
2016-11-12 01:06:32 +00:00
Quentin Young
90e9905f07 lib: Allow '-' to match VARIABLE_TKN
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-11-11 20:37:43 +00:00
Quentin Young
ce882f8168 lib: Implement hidden and deprecated commands
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>
2016-11-10 23:17:07 +00:00
Quentin Young
e8d5696d45 lib: Allow '_' in arguments to VARIABLE_TKN
second attempt

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-20 19:24:36 +00:00
Quentin Young
8c9474817e Revert "lib: Allow '_' in arguments to VARIABLE_TKN"
This reverts commit e0a467872b.
2016-10-20 19:21:37 +00:00
Quentin Young
e0a467872b lib: Allow '_' in arguments to VARIABLE_TKN
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-20 19:17:36 +00:00
Quentin Young
faf2a19de0 lib: Improve formatting for matcher tracing output
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-07 18:40:37 +00:00
Quentin Young
03ca8d3dff lib: Check match level when calculating completions
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>
2016-10-06 00:03:39 +00:00
Quentin Young
b4f56274fa lib: Add tracing capabilities to command matcher
Compile with -DTRACE_MATCHER to enable matcher
debugging to stdout.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-10-05 23:56:17 +00:00
Quentin Young
cc0a8be633 lib: Allow / and . to match VARIABLE_TKN, fix range matches
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>
2016-10-04 20:56:30 +00:00
Quentin Young
a78596c42d lib: explicitly support the case of empty input for completions
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>
2016-10-02 04:47:31 +00:00
Quentin Young
97e5b7c0b3 lib: argv fixes, XFREE -> free, rm decl in matcher
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-22 20:26:07 +00:00
Quentin Young
b87c0c3cf0 lib: Remove last remnants of NUMBER_TKN...again
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-22 18:26:11 +00:00
Quentin Young
287a4acf83 lib: Use listnode_add_before for prepending nodes
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-21 23:55:39 +00:00
Donald Sharp
460a768914 Merge remote-tracking branch 'origin/cmaster-next' into vtysh-grammar 2016-09-20 21:17:34 -04:00
Quentin Young
d0bfb22c22 lib: Initial refactor pass on CLI backend
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>
2016-09-19 23:46:51 +00:00
Quentin Young
040f39843e lib: Fix memory leak in ipv6_prefix_match
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-13 21:22:34 +00:00
Quentin Young
795d02785a lib: Fix various memory leaks
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-13 19:55:37 +00:00
Quentin Young
67c02c9449 lib: Fix memory leak in matcher
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-13 18:39:56 +00:00
Quentin Young
ee761cc086 lib: Move string completions out of command_match.c
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-13 18:33:55 +00:00
Quentin Young
ee551f4827 lib: Fix various matching bugs
Missed a copy, disambigs forgot to walkback

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-13 01:16:22 +00:00
Quentin Young
8d8cf5e322 lib: Fix dangling pointer in matcher
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-08 23:53:06 +00:00
Quentin Young
1eb5e8dcd1 lib: Continue matching system refactor
Most things back to working, all CLI units refactored
to use improved graph implementation.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-07 04:05:07 +00:00
Quentin Young
55589d304c lib: Refactor CLI interface function names
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-08-11 17:50:58 +00:00
Quentin Young
ca90e05104 lib: Add completion string convenience functions
And set END_GN default text to <cr>, and scrub
a coupld of extraneous files

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-08-10 18:31:15 +00:00
Quentin Young
eaf46b79b6 lib: Fix broken disambiguation on leader tokens
Fix incorrect assumption that the set of first tokens
of all commands are perfectly unambiguous

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-08-10 15:04:21 +00:00
Quentin Young
78602b8029 lib: Remove unnecessary node pointer
Selector and option heads had pointers to their
ends, but this turned out to be unnecessary

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-08-09 21:31:11 +00:00
Quentin Young
4427e9b3ee lib: Fix various minor bugs
- 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>
2016-08-09 17:37:01 +00:00
Quentin Young
1ab84bf32f lib: Code cleanup, formatting, & headers
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>
2016-08-08 21:11:14 +00:00
Quentin Young
39fb395f7d lib: Improve matching disambiguation
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>
2016-08-05 02:08:16 +00:00
Quentin Young
b389976966 lib: Unrefactor to signed long long for ranges
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-08-04 18:16:26 +00:00
Quentin Young
5a8bbed0b1 lib: Add support for negative ranges
And convert range delimiters to signed int

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-08-04 16:18:31 +00:00
Quentin Young
8aeffd7ae1 lib: Fix use after free in matcher
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-08-03 19:49:02 +00:00
Quentin Young
6ce82b63cd lib: Implement status variable
Matcher now keeps track of why it failed

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-08-03 19:22:27 +00:00
Quentin Young
54431328fc lib: Implement full command disambiguation logic
Disambiguation is smarter and somewhat more compact.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-08-03 02:01:52 +00:00
Quentin Young
279712aa19 lib: Reorganize command matcher
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-08-02 16:23:54 +00:00
Quentin Young
e1cbb2ff67 lib: Add partial completion support
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>
2016-08-01 20:30:14 +00:00
Quentin Young
e648e61a74 lib: Fix OOB range parses, variable matches
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>
2016-08-01 18:36:30 +00:00
Quentin Young
1a8c390d4a lib: Fixed bad node copy, modified token regex
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>
2016-08-01 17:03:39 +00:00
Quentin Young
6d53a10e4c lib: Add partial matching support
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-08-01 13:18:25 +00:00
Quentin Young
3a7f549361 lib: Retab command_match.c
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-07-29 18:34:10 +00:00
Quentin Young
0b02e39d9b lib: Re-add partial IPV4 matching support
Also removed debugging output for matcher.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-07-29 18:27:59 +00:00
Quentin Young
de9d7e4f3c lib: Cleanup some memory issues in CLI
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>
2016-07-29 15:54:03 +00:00
Quentin Young
76699ae7e0 lib: Improve argv construction
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>
2016-07-27 23:30:21 +00:00
Quentin Young
eceb106640 lib: Add matching and argv support
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>
2016-07-27 01:35:46 +00:00
Quentin Young
a53fbbf5f0 lib: Incremental matching improvement
Shotgun changes to matching system

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-07-26 14:02:36 +00:00