diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-11-01 18:36:12 +0100 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2023-11-02 02:19:21 +0100 |
commit | f1b622a00ce614654fcdff309a2394cfae3b3a88 (patch) | |
tree | 0c54e3da87805ec8c33da5276c3cb22e20652b5e /src/shared/varlink.h | |
parent | fuzz: limit the size of the input (diff) | |
download | systemd-f1b622a00ce614654fcdff309a2394cfae3b3a88.tar.xz systemd-f1b622a00ce614654fcdff309a2394cfae3b3a88.zip |
varlink,json: introduce new varlink_dispatch() helper
varlink_dispatch() is a simple wrapper around json_dispatch() that
returns clean, standards-compliant InvalidParameter error back to
clients, if the specified JSON cannot be parsed properly.
For this json_dispatch() is extended to return the offending field's
name. Because it already has quite a few parameters, I then renamed
json_dispatch() to json_dispatch_full() and made json_dispatch() a
wrapper around it that passes the new argument as NULL. While doing so I
figured we should also get rid of the bad= argument in the short
wrapper, since it's only used in the OCI code.
To simplify the OCI code this adds a second wrapper oci_dispatch()
around json_dispatch_full(), that fills in bad= the way we want.
Net result: instead of one json_dispatch() call there are now:
1. json_dispatch_full() for the fully feature mother of all dispathers.
2. json_dispatch() for the simpler version that you want to use most of
the time.
3. varlink_dispatch() that generates nice Varlink errors
4. oci_dispatch() that does the OCI specific error handling
And that's all there is.
Diffstat (limited to 'src/shared/varlink.h')
-rw-r--r-- | src/shared/varlink.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/shared/varlink.h b/src/shared/varlink.h index 516d3b5a90..6ec708aba2 100644 --- a/src/shared/varlink.h +++ b/src/shared/varlink.h @@ -115,6 +115,9 @@ int varlink_error_errno(Varlink *v, int error); int varlink_notify(Varlink *v, JsonVariant *parameters); int varlink_notifyb(Varlink *v, ...); +/* Parsing incoming data via json_dispatch() and generate a nice error on parse errors */ +int varlink_dispatch(Varlink *v, JsonVariant *parameters, const JsonDispatch table[], void *userdata); + /* Write outgoing fds into the socket (to be associated with the next enqueued message) */ int varlink_push_fd(Varlink *v, int fd); int varlink_dup_fd(Varlink *v, int fd); |