From f1b622a00ce614654fcdff309a2394cfae3b3a88 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 1 Nov 2023 18:36:12 +0100 Subject: 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. --- src/sysext/sysext.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/sysext') diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c index 4d72019966..858868c0c5 100644 --- a/src/sysext/sysext.c +++ b/src/sysext/sysext.c @@ -377,8 +377,8 @@ static int vl_method_unmerge(Varlink *link, JsonVariant *parameters, VarlinkMeth assert(link); - 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; r = parse_image_class_parameter(link, p.class, &image_class, &hierarchies); @@ -1115,17 +1115,12 @@ static int parse_merge_parameters(Varlink *link, JsonVariant *parameters, Method { "noexec", JSON_VARIANT_BOOLEAN, json_dispatch_boolean, offsetof(MethodMergeParameters, noexec), 0 }, {} }; - int r; assert(link); assert(parameters); assert(p); - r = json_dispatch(parameters, dispatch_table, NULL, 0, p); - if (r < 0) - return r; - - return 0; + return varlink_dispatch(link, parameters, dispatch_table, p); } static int vl_method_merge(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { @@ -1142,7 +1137,7 @@ static int vl_method_merge(Varlink *link, JsonVariant *parameters, VarlinkMethod assert(link); r = parse_merge_parameters(link, parameters, &p); - if (r < 0) + if (r != 0) return r; r = parse_image_class_parameter(link, p.class, &image_class, &hierarchies); @@ -1245,7 +1240,7 @@ static int vl_method_refresh(Varlink *link, JsonVariant *parameters, VarlinkMeth assert(link); r = parse_merge_parameters(link, parameters, &p); - if (r < 0) + if (r != 0) return r; r = parse_image_class_parameter(link, p.class, &image_class, &hierarchies); @@ -1322,8 +1317,8 @@ static int vl_method_list(Varlink *link, JsonVariant *parameters, VarlinkMethodF assert(link); - 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; r = parse_image_class_parameter(link, p.class, &image_class, NULL); -- cgit v1.2.3