Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control command refactor v2 #940

Closed

Conversation

Labels
None yet
Projects
None yet
3 participants
@nmathewson
Copy link
Contributor

@nmathewson nmathewson commented Apr 12, 2019

No description provided.

nmathewson added 7 commits Apr 12, 2019
Use a table-based lookup to find the right command handler.  This
will serve as the basement for several future improvements, as we
improve the API for parsing commands.
There _is_ an underlying logic to these commands, but it isn't
wholly uniform, given years of tweaks and changes.  Fortunately I
think there is a superset that will work.

This commit adds a parser for some of the most basic cases -- the
ones currently handled by getargs_helper() and some of the
object-taking ones.  Soon will come initial tests; then I'll start using
the parser.

After that, I'll expand the parser to handle the other cases that come
up in the controller protocol.
This is preliminary work for fixing 29984; no behavior has changed.
The first line break in particular was mishandled: it was discarded
if no arguments came before it, which made it impossible to
distinguish arguments from the first line of the body.

To solve this, we need to allocate a copy of the command rather than
using NUL to separate it, since we might have "COMMAND\n" as our input.

Fixes ticket 29984.
@coveralls
Copy link

@coveralls coveralls commented Apr 12, 2019

Pull Request Test Coverage Report for Build 4844

  • 81 of 390 (20.77%) changed or added relevant lines in 8 files are covered.
  • 1183 unchanged lines in 17 files lost coverage.
  • Overall coverage increased (+0.4%) to 62.648%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/core/mainloop/connection.c 0 1 0.0%
src/lib/encoding/kvline.c 20 21 95.24%
src/feature/control/control_getinfo.c 0 2 0.0%
src/lib/encoding/confline.c 0 3 0.0%
src/feature/control/control.c 0 23 0.0%
src/lib/encoding/qstring.c 0 32 0.0%
src/feature/control/control_auth.c 0 41 0.0%
src/feature/control/control_cmd.c 61 267 22.85%
Files with Coverage Reduction New Missed Lines %
src/core/or/relay.c 1 49.33%
src/feature/control/control_getinfo.c 2 27.51%
src/feature/dirauth/shared_random.c 3 85.64%
src/feature/control/control_auth.c 4 12.09%
src/feature/relay/onion_queue.c 8 58.82%
src/feature/dirauth/dirvote.c 9 64.74%
src/feature/dirparse/microdesc_parse.c 10 91.38%
src/lib/log/util_bug.c 16 50.82%
src/lib/crypt_ops/crypto_openssl_mgt.c 21 80.99%
src/feature/hs/hs_common.c 24 83.9%
Totals Coverage Status
Change from base Build 4713: 0.4%
Covered Lines: 46469
Relevant Lines: 74175

💛 - Coveralls

nmathewson added 15 commits Apr 12, 2019
(This should be all of the command that work nicely with positional
arguments only.)

Some of these commands should probably treat extra arguments as
incorrect, but for now I'm trying to be careful not to break
any existing users.
The two options are mutually exclusive, since otherwise an entry
like "Foo" would be ambiguous.  We want to have the ability to treat
entries like this as keys, though, since some controller commands
interpret them as flags.
This should let us handle all (or nearly all) of the remaining
commands.
Here we get to throw away a LOT of unused code, since most of the
old parsing was redundant with kvline.
This command does not fit perfectly with the others, since its
second argument is optional and may contain equal signs.  Still,
it's probably better to squeeze it into the new metaformat, since
doing so allows us to remove several pieces of the old
command-parsing machinery.
This function decodes something different from the usual c-escaped
format.

It is only used in controller authorization.
These two presented their own challenge, because of their use of
QString, and their distinguished handling of quoted versus
non-quoted values.
Now that the legacy handlers are gone, we can simplify the
structures and macros here.
Copy link
Contributor

@tlyu tlyu left a comment

Minor comment suggestions inline. Also, this maybe needs a changes file for ticket 29984?

src/feature/control/control.c Outdated Show resolved Hide resolved
src/feature/control/control.c Show resolved Hide resolved
Copy link
Contributor

@tlyu tlyu left a comment

Mostly minor issues, plus a couple of technical debt items.

src/feature/control/control_cmd.c Show resolved Hide resolved
src/feature/control/control_cmd_args_st.h Outdated Show resolved Hide resolved
src/feature/control/control_cmd.h Outdated Show resolved Hide resolved
src/feature/control/control_cmd_args_st.h Outdated Show resolved Hide resolved
src/feature/control/control_cmd.c Outdated Show resolved Hide resolved
nmathewson added 2 commits Apr 24, 2019
…inebreaks

Fix grammar in documentation for control_split_incoming_command().
Copy link
Contributor

@tlyu tlyu left a comment

Minor typo and tech debt comment

src/feature/control/control_cmd.c Outdated Show resolved Hide resolved
return -1;
}

if (syntax->allowed_keywords) {
Copy link
Contributor

@tlyu tlyu Apr 24, 2019

This is a little better now that it's in a helper function. I still think this is a great place for an early return. (and it makes even more sense because there's no need for a goto.

Copy link
Contributor Author

@nmathewson nmathewson Apr 25, 2019

I think in this case I'd like to keep it as-is -- I anticipate that there are likely to be more kinds of check in the future, such as required keywords.

Copy link
Contributor

@tlyu tlyu Apr 25, 2019

I prefer to take the extra nesting out now, and add it back when we need it due to future complexity. It's not a strong preference in this case.

@nmathewson
Copy link
Contributor Author

@nmathewson nmathewson commented Apr 25, 2019

Now squashed as #980

@nmathewson nmathewson closed this Apr 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment