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.
This commit is contained in:
Lennart Poettering
2023-11-02 01:19:21 +00:00
committed by Luca Boccassi
parent d0404391e5
commit f1b622a00c
24 changed files with 171 additions and 116 deletions
+6 -6
View File
@@ -157,8 +157,8 @@ static int vl_method_get_user_record(Varlink *link, JsonVariant *parameters, Var
assert(parameters);
r = json_dispatch(parameters, dispatch_table, NULL, 0, &p);
if (r < 0)
r = varlink_dispatch(link, parameters, dispatch_table, &p);
if (r != 0)
return r;
if (!streq_ptr(p.service, "io.systemd.Machine"))
@@ -322,8 +322,8 @@ static int vl_method_get_group_record(Varlink *link, JsonVariant *parameters, Va
assert(parameters);
r = json_dispatch(parameters, dispatch_table, NULL, 0, &p);
if (r < 0)
r = varlink_dispatch(link, parameters, dispatch_table, &p);
if (r != 0)
return r;
if (!streq_ptr(p.service, "io.systemd.Machine"))
@@ -367,8 +367,8 @@ static int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, Var
assert(parameters);
r = json_dispatch(parameters, dispatch_table, NULL, 0, &p);
if (r < 0)
r = varlink_dispatch(link, parameters, dispatch_table, &p);
if (r != 0)
return r;
if (!streq_ptr(p.service, "io.systemd.Machine"))