torproject / tor Public
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
Ticket30007 refactor control response formatting #956
Closed
Closed
Conversation
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.
(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.
Split the core reply formatting code out of control_fmt.c into control_proto.c. The remaining code in control_format.c deals with specific subsystems and will eventually move to join those subsystems.
Refer to control-spec.txt grammar productions in comments in control_proto.c for clarity.
Create a set of abstractions for controller commands and events to output replies to the control channel. The control protocol has a relatively consistent SMTP-like structure, so it's helpful when code that implements control commands and events doesn't explicitly format everything on its own.
Manually fix up some reply-generating code that the Coccinelle scripts won't match. Some more complicated ones remain -- these are mostly ones that accumulate data to send, and then call connection_buf_add() or connection_write_str_to_buf() directly.
Clean up some minor formatting quirks after the Coccinelle run.
|
This includes the commits of #940. The manual merge commit is because GitHub doesn't seem willing to make a trial merge commit automatically for this branch. |
Pull Request Test Coverage Report for Build 4742
|
|
Superseded by #984, which is a rebased version. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
overview:
The text was updated successfully, but these errors were encountered: