diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-05-02 14:26:21 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-06-12 18:42:22 +0200 |
commit | 309a747fa6cfeac0a0165543f23a924866727c9b (patch) | |
tree | a51242aa3ac87243c0614bf93d27e9083182e485 /src/libsystemd-network | |
parent | json: merge json_dispatch_path() + json_dispatch_absolute_path() (diff) | |
download | systemd-309a747fa6cfeac0a0165543f23a924866727c9b.tar.xz systemd-309a747fa6cfeac0a0165543f23a924866727c9b.zip |
libsystemd: turn json.[ch] into a public API
This is preparation for making our Varlink API a public API. Since our
Varlink API is built on top of our JSON API we need to make that public
first (it's a nice API, but JSON APIs there are already enough, this is
purely about the Varlink angle).
I made most of the json.h APIs public, and just placed them in
sd-json.h. Sometimes I wasn't so sure however, since the underlying data
structures would have to be made public too. If in doubt I didn#t risk
it, and moved the relevant API to src/libsystemd/sd-json/json-util.h
instead (without any sd_* symbol prefixes).
This is mostly a giant search/replace patch.
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r-- | src/libsystemd-network/dhcp-client-id-internal.h | 4 | ||||
-rw-r--r-- | src/libsystemd-network/dhcp-server-lease-internal.h | 6 | ||||
-rw-r--r-- | src/libsystemd-network/fuzz-lldp-rx.c | 4 | ||||
-rw-r--r-- | src/libsystemd-network/lldp-neighbor.c | 11 | ||||
-rw-r--r-- | src/libsystemd-network/lldp-neighbor.h | 4 | ||||
-rw-r--r-- | src/libsystemd-network/lldp-rx-internal.h | 4 | ||||
-rw-r--r-- | src/libsystemd-network/sd-dhcp-client-id.c | 3 | ||||
-rw-r--r-- | src/libsystemd-network/sd-dhcp-server-lease.c | 91 | ||||
-rw-r--r-- | src/libsystemd-network/sd-lldp-rx.c | 10 |
9 files changed, 70 insertions, 67 deletions
diff --git a/src/libsystemd-network/dhcp-client-id-internal.h b/src/libsystemd-network/dhcp-client-id-internal.h index 655f17b2e9..382575e7a2 100644 --- a/src/libsystemd-network/dhcp-client-id-internal.h +++ b/src/libsystemd-network/dhcp-client-id-internal.h @@ -2,9 +2,9 @@ #pragma once #include "sd-dhcp-client-id.h" +#include "sd-json.h" #include "dhcp-duid-internal.h" -#include "json.h" #include "macro.h" #include "siphash24.h" #include "sparse-endian.h" @@ -57,4 +57,4 @@ static inline bool client_id_data_size_is_valid(size_t size) { void client_id_hash_func(const sd_dhcp_client_id *client_id, struct siphash *state); int client_id_compare_func(const sd_dhcp_client_id *a, const sd_dhcp_client_id *b); -int json_dispatch_client_id(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata); +int json_dispatch_client_id(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata); diff --git a/src/libsystemd-network/dhcp-server-lease-internal.h b/src/libsystemd-network/dhcp-server-lease-internal.h index 7626552811..f206e0118f 100644 --- a/src/libsystemd-network/dhcp-server-lease-internal.h +++ b/src/libsystemd-network/dhcp-server-lease-internal.h @@ -2,10 +2,10 @@ #pragma once #include "sd-dhcp-server-lease.h" +#include "sd-json.h" #include "dhcp-client-id-internal.h" #include "dhcp-server-internal.h" -#include "json.h" #include "time-util.h" typedef struct sd_dhcp_server_lease { @@ -33,8 +33,8 @@ int dhcp_server_cleanup_expired_leases(sd_dhcp_server *server); sd_dhcp_server_lease* dhcp_server_get_static_lease(sd_dhcp_server *server, const DHCPRequest *req); -int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, JsonVariant **v); -int dhcp_server_static_leases_append_json(sd_dhcp_server *server, JsonVariant **v); +int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, sd_json_variant **v); +int dhcp_server_static_leases_append_json(sd_dhcp_server *server, sd_json_variant **v); int dhcp_server_save_leases(sd_dhcp_server *server); int dhcp_server_load_leases(sd_dhcp_server *server); diff --git a/src/libsystemd-network/fuzz-lldp-rx.c b/src/libsystemd-network/fuzz-lldp-rx.c index dad1038ca0..00e6d81809 100644 --- a/src/libsystemd-network/fuzz-lldp-rx.c +++ b/src/libsystemd-network/fuzz-lldp-rx.c @@ -24,7 +24,7 @@ int lldp_network_bind_raw_socket(int ifindex) { int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { _cleanup_(sd_event_unrefp) sd_event *e = NULL; _cleanup_(sd_lldp_rx_unrefp) sd_lldp_rx *lldp_rx = NULL; - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; _cleanup_(memstream_done) MemStream m = {}; FILE *f; @@ -44,7 +44,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { assert_se(lldp_rx_build_neighbors_json(lldp_rx, &v) >= 0); assert_se(f = memstream_init(&m)); - (void) json_variant_dump(v, JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR, f, NULL); + (void) sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_COLOR, f, NULL); assert_se(sd_lldp_rx_stop(lldp_rx) >= 0); assert_se(sd_lldp_rx_detach_event(lldp_rx) >= 0); diff --git a/src/libsystemd-network/lldp-neighbor.c b/src/libsystemd-network/lldp-neighbor.c index a4384ac2e1..77e516c1a8 100644 --- a/src/libsystemd-network/lldp-neighbor.c +++ b/src/libsystemd-network/lldp-neighbor.c @@ -5,6 +5,7 @@ #include "ether-addr-util.h" #include "hexdecoct.h" #include "in-addr-util.h" +#include "json-util.h" #include "lldp-neighbor.h" #include "memory-util.h" #include "missing_network.h" @@ -761,7 +762,7 @@ int sd_lldp_neighbor_get_timestamp(sd_lldp_neighbor *n, clockid_t clock, uint64_ return 0; } -int lldp_neighbor_build_json(sd_lldp_neighbor *n, JsonVariant **ret) { +int lldp_neighbor_build_json(sd_lldp_neighbor *n, sd_json_variant **ret) { const char *chassis_id = NULL, *port_id = NULL, *port_description = NULL, *system_name = NULL, *system_description = NULL; uint16_t cc = 0; @@ -778,13 +779,13 @@ int lldp_neighbor_build_json(sd_lldp_neighbor *n, JsonVariant **ret) { valid_cc = sd_lldp_neighbor_get_enabled_capabilities(n, &cc) >= 0; - return json_build(ret, JSON_BUILD_OBJECT( + return sd_json_build(ret, SD_JSON_BUILD_OBJECT( JSON_BUILD_PAIR_STRING_NON_EMPTY("ChassisID", chassis_id), - JSON_BUILD_PAIR_BYTE_ARRAY("RawChassisID", n->id.chassis_id, n->id.chassis_id_size), + SD_JSON_BUILD_PAIR_BYTE_ARRAY("RawChassisID", n->id.chassis_id, n->id.chassis_id_size), JSON_BUILD_PAIR_STRING_NON_EMPTY("PortID", port_id), - JSON_BUILD_PAIR_BYTE_ARRAY("RawPortID", n->id.port_id, n->id.port_id_size), + SD_JSON_BUILD_PAIR_BYTE_ARRAY("RawPortID", n->id.port_id, n->id.port_id_size), JSON_BUILD_PAIR_STRING_NON_EMPTY("PortDescription", port_description), JSON_BUILD_PAIR_STRING_NON_EMPTY("SystemName", system_name), JSON_BUILD_PAIR_STRING_NON_EMPTY("SystemDescription", system_description), - JSON_BUILD_PAIR_CONDITION(valid_cc, "EnabledCapabilities", JSON_BUILD_UNSIGNED(cc)))); + SD_JSON_BUILD_PAIR_CONDITION(valid_cc, "EnabledCapabilities", SD_JSON_BUILD_UNSIGNED(cc)))); } diff --git a/src/libsystemd-network/lldp-neighbor.h b/src/libsystemd-network/lldp-neighbor.h index 06ba4c7460..57ac3a3f20 100644 --- a/src/libsystemd-network/lldp-neighbor.h +++ b/src/libsystemd-network/lldp-neighbor.h @@ -5,10 +5,10 @@ #include <stdbool.h> #include <sys/types.h> +#include "sd-json.h" #include "sd-lldp-rx.h" #include "hash-funcs.h" -#include "json.h" #include "lldp-rx-internal.h" #include "time-util.h" @@ -91,4 +91,4 @@ sd_lldp_neighbor *lldp_neighbor_new(size_t raw_size); int lldp_neighbor_parse(sd_lldp_neighbor *n); void lldp_neighbor_start_ttl(sd_lldp_neighbor *n); bool lldp_neighbor_equal(const sd_lldp_neighbor *a, const sd_lldp_neighbor *b); -int lldp_neighbor_build_json(sd_lldp_neighbor *n, JsonVariant **ret); +int lldp_neighbor_build_json(sd_lldp_neighbor *n, sd_json_variant **ret); diff --git a/src/libsystemd-network/lldp-rx-internal.h b/src/libsystemd-network/lldp-rx-internal.h index e914c6bfc6..33f0add399 100644 --- a/src/libsystemd-network/lldp-rx-internal.h +++ b/src/libsystemd-network/lldp-rx-internal.h @@ -2,10 +2,10 @@ #pragma once #include "sd-event.h" +#include "sd-json.h" #include "sd-lldp-rx.h" #include "hashmap.h" -#include "json.h" #include "network-common.h" #include "prioq.h" @@ -37,7 +37,7 @@ struct sd_lldp_rx { const char* lldp_rx_event_to_string(sd_lldp_rx_event_t e) _const_; sd_lldp_rx_event_t lldp_rx_event_from_string(const char *s) _pure_; -int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, JsonVariant **ret); +int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, sd_json_variant **ret); #define log_lldp_rx_errno(lldp_rx, error, fmt, ...) \ log_interface_prefix_full_errno( \ diff --git a/src/libsystemd-network/sd-dhcp-client-id.c b/src/libsystemd-network/sd-dhcp-client-id.c index cab04f05e5..3e06501906 100644 --- a/src/libsystemd-network/sd-dhcp-client-id.c +++ b/src/libsystemd-network/sd-dhcp-client-id.c @@ -3,6 +3,7 @@ #include "alloc-util.h" #include "dhcp-client-id-internal.h" #include "iovec-util.h" +#include "json-util.h" #include "unaligned.h" #include "utf8.h" @@ -179,7 +180,7 @@ int client_id_compare_func(const sd_dhcp_client_id *a, const sd_dhcp_client_id * return memcmp_nn(a->raw, a->size, b->raw, b->size); } -int json_dispatch_client_id(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { +int json_dispatch_client_id(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { sd_dhcp_client_id *client_id = ASSERT_PTR(userdata); _cleanup_(iovec_done) struct iovec iov = {}; int r; diff --git a/src/libsystemd-network/sd-dhcp-server-lease.c b/src/libsystemd-network/sd-dhcp-server-lease.c index 2f84d51e65..69a285b44a 100644 --- a/src/libsystemd-network/sd-dhcp-server-lease.c +++ b/src/libsystemd-network/sd-dhcp-server-lease.c @@ -3,6 +3,7 @@ #include "dhcp-server-lease-internal.h" #include "fd-util.h" #include "fs-util.h" +#include "json-util.h" #include "mkdir.h" #include "tmpfile-util.h" @@ -209,19 +210,19 @@ int sd_dhcp_server_set_static_lease( return 0; } -static int dhcp_server_lease_append_json(sd_dhcp_server_lease *lease, JsonVariant **ret) { +static int dhcp_server_lease_append_json(sd_dhcp_server_lease *lease, sd_json_variant **ret) { assert(lease); assert(ret); - return json_build(ret, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_BYTE_ARRAY("ClientId", lease->client_id.raw, lease->client_id.size), + return sd_json_build(ret, + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_BYTE_ARRAY("ClientId", lease->client_id.raw, lease->client_id.size), JSON_BUILD_PAIR_IN4_ADDR_NON_NULL("Address", &(struct in_addr) { .s_addr = lease->address }), JSON_BUILD_PAIR_STRING_NON_EMPTY("Hostname", lease->hostname))); } -int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; sd_dhcp_server_lease *lease; usec_t now_b, now_r; int r; @@ -238,7 +239,7 @@ int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, JsonVariant **v return r; HASHMAP_FOREACH(lease, server->bound_leases_by_client_id) { - _cleanup_(json_variant_unrefp) JsonVariant *w = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL; r = dhcp_server_lease_append_json(lease, &w); if (r < 0) @@ -246,14 +247,14 @@ int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, JsonVariant **v usec_t exp_r = map_clock_usec_raw(lease->expiration, now_b, now_r); - r = json_variant_merge_objectb(&w, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_UNSIGNED("ExpirationUSec", lease->expiration), - JSON_BUILD_PAIR_UNSIGNED("ExpirationRealtimeUSec", exp_r))); + r = sd_json_variant_merge_objectb(&w, + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_UNSIGNED("ExpirationUSec", lease->expiration), + SD_JSON_BUILD_PAIR_UNSIGNED("ExpirationRealtimeUSec", exp_r))); if (r < 0) return r; - r = json_variant_append_array(&array, w); + r = sd_json_variant_append_array(&array, w); if (r < 0) return r; } @@ -261,8 +262,8 @@ int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, JsonVariant **v return json_variant_set_field_non_null(v, "Leases", array); } -int dhcp_server_static_leases_append_json(sd_dhcp_server *server, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +int dhcp_server_static_leases_append_json(sd_dhcp_server *server, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; sd_dhcp_server_lease *lease; int r; @@ -270,13 +271,13 @@ int dhcp_server_static_leases_append_json(sd_dhcp_server *server, JsonVariant ** assert(v); HASHMAP_FOREACH(lease, server->static_leases_by_client_id) { - _cleanup_(json_variant_unrefp) JsonVariant *w = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL; r = dhcp_server_lease_append_json(lease, &w); if (r < 0) return r; - r = json_variant_append_array(&array, w); + r = sd_json_variant_append_array(&array, w); if (r < 0) return r; } @@ -285,7 +286,7 @@ int dhcp_server_static_leases_append_json(sd_dhcp_server *server, JsonVariant ** } int dhcp_server_save_leases(sd_dhcp_server *server) { - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; _cleanup_free_ char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; sd_id128_t boot_id; @@ -307,10 +308,10 @@ int dhcp_server_save_leases(sd_dhcp_server *server) { if (r < 0) return r; - r = json_build(&v, JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_ID128("BootID", boot_id), + r = sd_json_build(&v, SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_ID128("BootID", boot_id), JSON_BUILD_PAIR_IN4_ADDR("Address", &(struct in_addr) { .s_addr = server->address }), - JSON_BUILD_PAIR_UNSIGNED("PrefixLength", + SD_JSON_BUILD_PAIR_UNSIGNED("PrefixLength", in4_addr_netmask_to_prefixlen(&(struct in_addr) { .s_addr = server->netmask })))); if (r < 0) return r; @@ -329,7 +330,7 @@ int dhcp_server_save_leases(sd_dhcp_server *server) { (void) fchmod(fileno(f), 0644); - r = json_variant_dump(v, JSON_FORMAT_NEWLINE | JSON_FORMAT_FLUSH, f, /* prefix = */ NULL); + r = sd_json_variant_dump(v, SD_JSON_FORMAT_NEWLINE | SD_JSON_FORMAT_FLUSH, f, /* prefix = */ NULL); if (r < 0) goto failure; @@ -344,20 +345,20 @@ failure: return r; } -static int json_dispatch_dhcp_lease(sd_dhcp_server *server, JsonVariant *v, bool use_boottime) { - static const JsonDispatch dispatch_table_boottime[] = { - { "ClientId", JSON_VARIANT_ARRAY, json_dispatch_client_id, offsetof(sd_dhcp_server_lease, client_id), JSON_MANDATORY }, - { "Address", JSON_VARIANT_ARRAY, json_dispatch_in_addr, offsetof(sd_dhcp_server_lease, address), JSON_MANDATORY }, - { "Hostname", JSON_VARIANT_STRING, json_dispatch_string, offsetof(sd_dhcp_server_lease, hostname), 0 }, - { "ExpirationUSec", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(sd_dhcp_server_lease, expiration), JSON_MANDATORY }, - { "ExpirationRealtimeUSec", _JSON_VARIANT_TYPE_INVALID, NULL, 0, JSON_MANDATORY }, +static int json_dispatch_dhcp_lease(sd_dhcp_server *server, sd_json_variant *v, bool use_boottime) { + static const sd_json_dispatch_field dispatch_table_boottime[] = { + { "ClientId", SD_JSON_VARIANT_ARRAY, json_dispatch_client_id, offsetof(sd_dhcp_server_lease, client_id), SD_JSON_MANDATORY }, + { "Address", SD_JSON_VARIANT_ARRAY, json_dispatch_in_addr, offsetof(sd_dhcp_server_lease, address), SD_JSON_MANDATORY }, + { "Hostname", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(sd_dhcp_server_lease, hostname), 0 }, + { "ExpirationUSec", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(sd_dhcp_server_lease, expiration), SD_JSON_MANDATORY }, + { "ExpirationRealtimeUSec", _SD_JSON_VARIANT_TYPE_INVALID, NULL, 0, SD_JSON_MANDATORY }, {} }, dispatch_table_realtime[] = { - { "ClientId", JSON_VARIANT_ARRAY, json_dispatch_client_id, offsetof(sd_dhcp_server_lease, client_id), JSON_MANDATORY }, - { "Address", JSON_VARIANT_ARRAY, json_dispatch_in_addr, offsetof(sd_dhcp_server_lease, address), JSON_MANDATORY }, - { "Hostname", JSON_VARIANT_STRING, json_dispatch_string, offsetof(sd_dhcp_server_lease, hostname), 0 }, - { "ExpirationUSec", _JSON_VARIANT_TYPE_INVALID, NULL, 0, JSON_MANDATORY }, - { "ExpirationRealtimeUSec", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(sd_dhcp_server_lease, expiration), JSON_MANDATORY }, + { "ClientId", SD_JSON_VARIANT_ARRAY, json_dispatch_client_id, offsetof(sd_dhcp_server_lease, client_id), SD_JSON_MANDATORY }, + { "Address", SD_JSON_VARIANT_ARRAY, json_dispatch_in_addr, offsetof(sd_dhcp_server_lease, address), SD_JSON_MANDATORY }, + { "Hostname", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(sd_dhcp_server_lease, hostname), 0 }, + { "ExpirationUSec", _SD_JSON_VARIANT_TYPE_INVALID, NULL, 0, SD_JSON_MANDATORY }, + { "ExpirationRealtimeUSec", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(sd_dhcp_server_lease, expiration), SD_JSON_MANDATORY }, {} }; @@ -376,7 +377,7 @@ static int json_dispatch_dhcp_lease(sd_dhcp_server *server, JsonVariant *v, bool .n_ref = 1, }; - r = json_dispatch(v, use_boottime ? dispatch_table_boottime : dispatch_table_realtime, JSON_ALLOW_EXTENSIONS, lease); + r = sd_json_dispatch(v, use_boottime ? dispatch_table_boottime : dispatch_table_realtime, SD_JSON_ALLOW_EXTENSIONS, lease); if (r < 0) return r; @@ -414,25 +415,25 @@ typedef struct SavedInfo { sd_id128_t boot_id; struct in_addr address; uint8_t prefixlen; - JsonVariant *leases; + sd_json_variant *leases; } SavedInfo; static void saved_info_done(SavedInfo *info) { if (!info) return; - json_variant_unref(info->leases); + sd_json_variant_unref(info->leases); } static int load_leases_file(int dir_fd, const char *path, SavedInfo *ret) { - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; int r; assert(dir_fd >= 0 || dir_fd == AT_FDCWD); assert(path); assert(ret); - r = json_parse_file_at( + r = sd_json_parse_file_at( /* f = */ NULL, dir_fd, path, @@ -443,15 +444,15 @@ static int load_leases_file(int dir_fd, const char *path, SavedInfo *ret) { if (r < 0) return r; - static const JsonDispatch dispatch_lease_file_table[] = { - { "BootID", JSON_VARIANT_STRING, json_dispatch_id128, offsetof(SavedInfo, boot_id), JSON_MANDATORY }, - { "Address", JSON_VARIANT_ARRAY, json_dispatch_in_addr, offsetof(SavedInfo, address), JSON_MANDATORY }, - { "PrefixLength", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint8, offsetof(SavedInfo, prefixlen), JSON_MANDATORY }, - { "Leases", JSON_VARIANT_ARRAY, json_dispatch_variant, offsetof(SavedInfo, leases), JSON_MANDATORY }, + static const sd_json_dispatch_field dispatch_lease_file_table[] = { + { "BootID", SD_JSON_VARIANT_STRING, sd_json_dispatch_id128, offsetof(SavedInfo, boot_id), SD_JSON_MANDATORY }, + { "Address", SD_JSON_VARIANT_ARRAY, json_dispatch_in_addr, offsetof(SavedInfo, address), SD_JSON_MANDATORY }, + { "PrefixLength", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint8, offsetof(SavedInfo, prefixlen), SD_JSON_MANDATORY }, + { "Leases", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, offsetof(SavedInfo, leases), SD_JSON_MANDATORY }, {} }; - return json_dispatch(v, dispatch_lease_file_table, JSON_ALLOW_EXTENSIONS, ret); + return sd_json_dispatch(v, dispatch_lease_file_table, SD_JSON_ALLOW_EXTENSIONS, ret); } int dhcp_server_load_leases(sd_dhcp_server *server) { @@ -478,7 +479,7 @@ int dhcp_server_load_leases(sd_dhcp_server *server) { n = hashmap_size(server->bound_leases_by_client_id); - JsonVariant *i; + sd_json_variant *i; JSON_VARIANT_ARRAY_FOREACH(i, info.leases) RET_GATHER(r, json_dispatch_dhcp_lease(server, i, /* use_boottime = */ sd_id128_equal(info.boot_id, boot_id))); diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index 74000ffb8b..029ee0282c 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -4,13 +4,13 @@ #include <linux/sockios.h> #include <sys/ioctl.h> +#include "sd-json.h" #include "sd-lldp-rx.h" #include "alloc-util.h" #include "ether-addr-util.h" #include "event-util.h" #include "fd-util.h" -#include "json.h" #include "lldp-neighbor.h" #include "lldp-network.h" #include "lldp-rx-internal.h" @@ -491,8 +491,8 @@ int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***ret) { return k; } -int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, JsonVariant **ret) { - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; +int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, sd_json_variant **ret) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; int r; assert(lldp_rx); @@ -500,13 +500,13 @@ int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, JsonVariant **ret) { sd_lldp_neighbor *n; HASHMAP_FOREACH(n, lldp_rx->neighbor_by_id) { - _cleanup_(json_variant_unrefp) JsonVariant *w = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL; r = lldp_neighbor_build_json(n, &w); if (r < 0) return r; - r = json_variant_append_array(&v, w); + r = sd_json_variant_append_array(&v, w); if (r < 0) return r; } |