diff options
-rw-r--r-- | src/network/networkd-json.c | 46 | ||||
-rw-r--r-- | src/shared/json.c | 7 | ||||
-rw-r--r-- | src/shared/json.h | 5 |
3 files changed, 27 insertions, 31 deletions
diff --git a/src/network/networkd-json.c b/src/network/networkd-json.c index 96973e1ec2..ef3153642b 100644 --- a/src/network/networkd-json.c +++ b/src/network/networkd-json.c @@ -80,7 +80,7 @@ static int addresses_append_json(Set *addresses, JsonVariant **v) { return r; } - return json_variant_merge_pair(v, "Addresses", array); + return json_variant_set_field_non_null(v, "Addresses", array); } static int neighbor_build_json(Neighbor *n, JsonVariant **ret) { @@ -121,7 +121,7 @@ static int neighbors_append_json(Set *neighbors, JsonVariant **v) { return r; } - return json_variant_merge_pair(v, "Neighbors", array); + return json_variant_set_field_non_null(v, "Neighbors", array); } static int nexthop_group_build_json(NextHop *nexthop, JsonVariant **ret) { @@ -202,7 +202,7 @@ static int nexthops_append_json(Set *nexthops, JsonVariant **v) { return r; } - return json_variant_merge_pair(v, "NextHops", array); + return json_variant_set_field_non_null(v, "NextHops", array); } static int route_build_json(Route *route, JsonVariant **ret) { @@ -284,7 +284,7 @@ static int routes_append_json(Set *routes, JsonVariant **v) { return r; } - return json_variant_merge_pair(v, "Routes", array); + return json_variant_set_field_non_null(v, "Routes", array); } static int routing_policy_rule_build_json(RoutingPolicyRule *rule, JsonVariant **ret) { @@ -363,7 +363,7 @@ static int routing_policy_rules_append_json(Set *rules, JsonVariant **v) { return r; } - return json_variant_merge_pair(v, "RoutingPolicyRules", array); + return json_variant_set_field_non_null(v, "RoutingPolicyRules", array); } static int network_append_json(Network *network, JsonVariant **v) { @@ -522,7 +522,7 @@ static int dns_append_json(Link *link, JsonVariant **v) { } } - return json_variant_merge_pair(v, "DNS", array); + return json_variant_set_field_non_null(v, "DNS", array); } static int server_append_json_one_addr(int family, const union in_addr_union *a, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **array) { @@ -646,7 +646,7 @@ static int ntp_append_json(Link *link, JsonVariant **v) { } } - return json_variant_merge_pair(v, "NTP", array); + return json_variant_set_field_non_null(v, "NTP", array); } static int sip_append_json(Link *link, JsonVariant **v) { @@ -679,7 +679,7 @@ static int sip_append_json(Link *link, JsonVariant **v) { return r; } - return json_variant_merge_pair(v, "SIP", array); + return json_variant_set_field_non_null(v, "SIP", array); } static int domain_append_json(int family, const char *domain, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **array) { @@ -775,7 +775,7 @@ static int domains_append_json(Link *link, bool is_route, JsonVariant **v) { } } - return json_variant_merge_pair(v, is_route ? "RouteDomains" : "SearchDomains", array); + return json_variant_set_field_non_null(v, is_route ? "RouteDomains" : "SearchDomains", array); } static int nta_append_json(const char *nta, NetworkConfigSource s, JsonVariant **array) { @@ -813,7 +813,7 @@ static int ntas_append_json(Link *link, JsonVariant **v) { return r; } - return json_variant_merge_pair(v, "DNSSECNegativeTrustAnchors", array); + return json_variant_set_field_non_null(v, "DNSSECNegativeTrustAnchors", array); } static int dns_misc_append_json(Link *link, JsonVariant **v) { @@ -897,7 +897,7 @@ static int dns_misc_append_json(Link *link, JsonVariant **v) { return r; } - return json_variant_merge_pair(v, "DNSSettings", array); + return json_variant_set_field_non_null(v, "DNSSettings", array); } static int captive_portal_append_json(Link *link, JsonVariant **v) { @@ -936,11 +936,11 @@ static int pref64_append_json(Link *link, JsonVariant **v) { return r; } - r = json_variant_merge_pair(&w, "PREF64", array); + r = json_variant_set_field_non_null(&w, "PREF64", array); if (r < 0) return r; - return json_variant_merge_pair(v, "NDisc", w); + return json_variant_set_field_non_null(v, "NDisc", w); } static int dhcp_server_offered_leases_append_json(Link *link, JsonVariant **v) { @@ -972,7 +972,7 @@ static int dhcp_server_offered_leases_append_json(Link *link, JsonVariant **v) { return r; } - return json_variant_merge_pair(v, "Leases", array); + return json_variant_set_field_non_null(v, "Leases", array); } static int dhcp_server_static_leases_append_json(Link *link, JsonVariant **v) { @@ -1005,7 +1005,7 @@ static int dhcp_server_static_leases_append_json(Link *link, JsonVariant **v) { return r; } - return json_variant_merge_pair(v, "StaticLeases", array); + return json_variant_set_field_non_null(v, "StaticLeases", array); } static int dhcp_server_append_json(Link *link, JsonVariant **v) { @@ -1033,7 +1033,7 @@ static int dhcp_server_append_json(Link *link, JsonVariant **v) { if (r < 0) return r; - return json_variant_merge_pair(v, "DHCPServer", w); + return json_variant_set_field_non_null(v, "DHCPServer", w); } static int dhcp6_client_lease_append_json(Link *link, JsonVariant **v) { @@ -1066,7 +1066,7 @@ static int dhcp6_client_lease_append_json(Link *link, JsonVariant **v) { if (r < 0) return r; - return json_variant_merge_pair(v, "Lease", w); + return json_variant_set_field_non_null(v, "Lease", w); } static int dhcp6_client_pd_append_json(Link *link, JsonVariant **v) { @@ -1104,7 +1104,7 @@ static int dhcp6_client_pd_append_json(Link *link, JsonVariant **v) { return r; } - return json_variant_merge_pair(v, "Prefixes", array); + return json_variant_set_field_non_null(v, "Prefixes", array); } static int dhcp6_client_append_json(Link *link, JsonVariant **v) { @@ -1125,7 +1125,7 @@ static int dhcp6_client_append_json(Link *link, JsonVariant **v) { if (r < 0) return r; - return json_variant_merge_pair(v, "DHCPv6Client", w); + return json_variant_set_field_non_null(v, "DHCPv6Client", w); } static int dhcp_client_lease_append_json(Link *link, JsonVariant **v) { @@ -1158,7 +1158,7 @@ static int dhcp_client_lease_append_json(Link *link, JsonVariant **v) { if (r < 0) return r; - return json_variant_merge_pair(v, "Lease", w); + return json_variant_set_field_non_null(v, "Lease", w); } static int dhcp_client_pd_append_json(Link *link, JsonVariant **v) { @@ -1194,7 +1194,7 @@ static int dhcp_client_pd_append_json(Link *link, JsonVariant **v) { if (r < 0) return r; - return json_variant_merge_pair(v, "6rdPrefix", array); + return json_variant_set_field_non_null(v, "6rdPrefix", array); } static int dhcp_client_append_json(Link *link, JsonVariant **v) { @@ -1215,7 +1215,7 @@ static int dhcp_client_append_json(Link *link, JsonVariant **v) { if (r < 0) return r; - return json_variant_merge_pair(v, "DHCPv4Client", w); + return json_variant_set_field_non_null(v, "DHCPv4Client", w); } int link_build_json(Link *link, JsonVariant **ret) { @@ -1374,7 +1374,7 @@ static int links_append_json(Manager *manager, JsonVariant **v) { return r; } - return json_variant_merge_pair(v, "Interfaces", array); + return json_variant_set_field_non_null(v, "Interfaces", array); } int manager_build_json(Manager *manager, JsonVariant **ret) { diff --git a/src/shared/json.c b/src/shared/json.c index 8b2598dfa7..e17f89564d 100644 --- a/src/shared/json.c +++ b/src/shared/json.c @@ -2104,13 +2104,6 @@ int json_variant_merge_objectb(JsonVariant **v, ...) { return json_variant_merge_object(v, w); } -int json_variant_merge_pair(JsonVariant **v, const char *name, JsonVariant *w) { - assert(v); - assert(name); - - return json_variant_merge_objectb(v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_VARIANT_NON_NULL(name, w))); -} - int json_variant_append_array(JsonVariant **v, JsonVariant *element) { _cleanup_(json_variant_unrefp) JsonVariant *nv = NULL; bool blank; diff --git a/src/shared/json.h b/src/shared/json.h index 3e9424c240..861ef495b5 100644 --- a/src/shared/json.h +++ b/src/shared/json.h @@ -211,6 +211,10 @@ int json_variant_set_field_unsigned(JsonVariant **v, const char *field, uint64_t int json_variant_set_field_boolean(JsonVariant **v, const char *field, bool b); int json_variant_set_field_strv(JsonVariant **v, const char *field, char **l); +static inline int json_variant_set_field_non_null(JsonVariant **v, const char *field, JsonVariant *value) { + return value && !json_variant_is_null(value) ? json_variant_set_field(v, field, value) : 0; +} + JsonVariant *json_variant_find(JsonVariant *haystack, JsonVariant *needle); int json_variant_append_array(JsonVariant **v, JsonVariant *element); @@ -219,7 +223,6 @@ int json_variant_append_array_nodup(JsonVariant **v, JsonVariant *element); int json_variant_merge_object(JsonVariant **v, JsonVariant *m); int json_variant_merge_objectb(JsonVariant **v, ...); -int json_variant_merge_pair(JsonVariant **v, const char *name, JsonVariant *w); int json_variant_strv(JsonVariant *v, char ***ret); |