diff options
Diffstat (limited to 'src/machine/machine-varlink.c')
-rw-r--r-- | src/machine/machine-varlink.c | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/src/machine/machine-varlink.c b/src/machine/machine-varlink.c index 3f95388abc..a6bf6528c4 100644 --- a/src/machine/machine-varlink.c +++ b/src/machine/machine-varlink.c @@ -3,9 +3,10 @@ #include <limits.h> #include "sd-id128.h" +#include "sd-json.h" #include "hostname-util.h" -#include "json.h" +#include "json-util.h" #include "machine-varlink.h" #include "machine.h" #include "path-util.h" @@ -17,17 +18,17 @@ static JSON_DISPATCH_ENUM_DEFINE(dispatch_machine_class, MachineClass, machine_class_from_string); -static int machine_name(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { +static int machine_name(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { char **m = ASSERT_PTR(userdata); const char *hostname; int r; assert(variant); - if (!json_variant_is_string(variant)) + if (!sd_json_variant_is_string(variant)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name)); - hostname = json_variant_string(variant); + hostname = sd_json_variant_string(variant); if (!hostname_is_valid(hostname, /* flags= */ 0)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Invalid machine name"); @@ -38,16 +39,16 @@ static int machine_name(const char *name, JsonVariant *variant, JsonDispatchFlag return 0; } -static int machine_leader(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { +static int machine_leader(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { PidRef *leader = ASSERT_PTR(userdata); _cleanup_(pidref_done) PidRef temp = PIDREF_NULL; uint64_t k; int r; - if (!json_variant_is_unsigned(variant)) + if (!sd_json_variant_is_unsigned(variant)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an integer.", strna(name)); - k = json_variant_unsigned(variant); + k = sd_json_variant_unsigned(variant); if (k > PID_T_MAX || !pid_is_valid(k)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid PID.", strna(name)); @@ -65,30 +66,30 @@ static int machine_leader(const char *name, JsonVariant *variant, JsonDispatchFl return 0; } -static int machine_ifindices(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { +static int machine_ifindices(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { Machine *m = ASSERT_PTR(userdata); _cleanup_free_ int *netif = NULL; size_t n_netif, k = 0; assert(variant); - if (!json_variant_is_array(variant)) + if (!sd_json_variant_is_array(variant)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array.", strna(name)); - n_netif = json_variant_elements(variant); + n_netif = sd_json_variant_elements(variant); netif = new(int, n_netif); if (!netif) return json_log_oom(variant, flags); - JsonVariant *i; + sd_json_variant *i; JSON_VARIANT_ARRAY_FOREACH(i, variant) { uint64_t b; - if (!json_variant_is_unsigned(i)) + if (!sd_json_variant_is_unsigned(i)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Element %zu of JSON field '%s' is not an unsigned integer.", k, strna(name)); - b = json_variant_unsigned(i); + b = sd_json_variant_unsigned(i); if (b > INT_MAX || b <= 0) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Invalid network interface index %"PRIu64, b); @@ -102,15 +103,15 @@ static int machine_ifindices(const char *name, JsonVariant *variant, JsonDispatc return 0; } -static int machine_cid(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { +static int machine_cid(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { unsigned cid, *c = ASSERT_PTR(userdata); assert(variant); - if (!json_variant_is_unsigned(variant)) + if (!sd_json_variant_is_unsigned(variant)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name)); - cid = json_variant_unsigned(variant); + cid = sd_json_variant_unsigned(variant); if (!VSOCK_CID_IS_REGULAR(cid)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a regular VSOCK CID.", strna(name)); @@ -119,22 +120,22 @@ static int machine_cid(const char *name, JsonVariant *variant, JsonDispatchFlags return 0; } -int vl_method_register(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { +int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { Manager *manager = ASSERT_PTR(userdata); _cleanup_(machine_freep) Machine *machine = NULL; int r; - static const JsonDispatch dispatch_table[] = { - { "name", JSON_VARIANT_STRING, machine_name, offsetof(Machine, name), JSON_MANDATORY }, - { "id", JSON_VARIANT_STRING, json_dispatch_id128, offsetof(Machine, id), 0 }, - { "service", JSON_VARIANT_STRING, json_dispatch_string, offsetof(Machine, service), 0 }, - { "class", JSON_VARIANT_STRING, dispatch_machine_class, offsetof(Machine, class), JSON_MANDATORY }, - { "leader", JSON_VARIANT_UNSIGNED, machine_leader, offsetof(Machine, leader), 0 }, - { "rootDirectory", JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, root_directory), 0 }, - { "ifIndices", JSON_VARIANT_ARRAY, machine_ifindices, 0, 0 }, - { "vSockCid", JSON_VARIANT_UNSIGNED, machine_cid, offsetof(Machine, vsock_cid), 0 }, - { "sshAddress", JSON_VARIANT_STRING, json_dispatch_string, offsetof(Machine, ssh_address), JSON_SAFE }, - { "sshPrivateKeyPath", JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, ssh_private_key_path), 0 }, + static const sd_json_dispatch_field dispatch_table[] = { + { "name", SD_JSON_VARIANT_STRING, machine_name, offsetof(Machine, name), SD_JSON_MANDATORY }, + { "id", SD_JSON_VARIANT_STRING, sd_json_dispatch_id128, offsetof(Machine, id), 0 }, + { "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(Machine, service), 0 }, + { "class", SD_JSON_VARIANT_STRING, dispatch_machine_class, offsetof(Machine, class), SD_JSON_MANDATORY }, + { "leader", SD_JSON_VARIANT_UNSIGNED, machine_leader, offsetof(Machine, leader), 0 }, + { "rootDirectory", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, root_directory), 0 }, + { "ifIndices", SD_JSON_VARIANT_ARRAY, machine_ifindices, 0, 0 }, + { "vSockCid", SD_JSON_VARIANT_UNSIGNED, machine_cid, offsetof(Machine, vsock_cid), 0 }, + { "sshAddress", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(Machine, ssh_address), SD_JSON_SAFE }, + { "sshPrivateKeyPath", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, ssh_private_key_path), 0 }, {} }; |