summaryrefslogtreecommitdiffstats
path: root/src/resolve
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-05-02 14:26:21 +0200
committerLennart Poettering <lennart@poettering.net>2024-06-12 18:42:22 +0200
commit309a747fa6cfeac0a0165543f23a924866727c9b (patch)
treea51242aa3ac87243c0614bf93d27e9083182e485 /src/resolve
parentjson: merge json_dispatch_path() + json_dispatch_absolute_path() (diff)
downloadsystemd-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/resolve')
-rw-r--r--src/resolve/fuzz-resource-record.c4
-rw-r--r--src/resolve/resolvectl.c247
-rw-r--r--src/resolve/resolved-dns-cache.c54
-rw-r--r--src/resolve/resolved-dns-cache.h2
-rw-r--r--src/resolve/resolved-dns-rr.c321
-rw-r--r--src/resolve/resolved-dns-rr.h9
-rw-r--r--src/resolve/resolved-dns-scope.c18
-rw-r--r--src/resolve/resolved-dns-scope.h2
-rw-r--r--src/resolve/resolved-dns-server.c38
-rw-r--r--src/resolve/resolved-dns-server.h5
-rw-r--r--src/resolve/resolved-manager.c92
-rw-r--r--src/resolve/resolved-manager.h2
-rw-r--r--src/resolve/resolved-varlink.c277
-rw-r--r--src/resolve/test-resolved-packet.c12
14 files changed, 544 insertions, 539 deletions
diff --git a/src/resolve/fuzz-resource-record.c b/src/resolve/fuzz-resource-record.c
index f792167aff..b1ff0d87e9 100644
--- a/src/resolve/fuzz-resource-record.c
+++ b/src/resolve/fuzz-resource-record.c
@@ -8,7 +8,7 @@
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL, *copy = 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;
@@ -27,7 +27,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
(void) fprintf(f, "%s", strna(dns_resource_record_to_string(rr)));
assert_se(dns_resource_record_to_json(rr, &v) >= 0);
- assert_se(json_variant_dump(v, JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR|JSON_FORMAT_SOURCE, f, NULL) >= 0);
+ assert_se(sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_COLOR|SD_JSON_FORMAT_SOURCE, f, NULL) >= 0);
assert_se(dns_resource_record_to_wire_format(rr, false) >= 0);
assert_se(dns_resource_record_to_wire_format(rr, true) >= 0);
diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c
index f2e9e7a96b..63fb7d6d39 100644
--- a/src/resolve/resolvectl.c
+++ b/src/resolve/resolvectl.c
@@ -5,6 +5,7 @@
#include <net/if.h>
#include "sd-bus.h"
+#include "sd-json.h"
#include "sd-netlink.h"
#include "af-list.h"
@@ -22,7 +23,7 @@
#include "format-util.h"
#include "gcrypt-util.h"
#include "hostname-util.h"
-#include "json.h"
+#include "json-util.h"
#include "main-func.h"
#include "missing_network.h"
#include "netlink-util.h"
@@ -56,7 +57,7 @@ static uint16_t arg_type = 0;
static uint16_t arg_class = 0;
static bool arg_legend = true;
static uint64_t arg_flags = 0;
-static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
+static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
static PagerFlags arg_pager_flags = 0;
bool arg_ifindex_permissive = false; /* If true, don't generate an error if the specified interface index doesn't exist */
static const char *arg_service_family = NULL;
@@ -184,7 +185,7 @@ static void print_source(uint64_t flags, usec_t rtt) {
if (!arg_legend)
return;
- if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))
+ if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
return;
if (flags == 0)
@@ -253,7 +254,7 @@ static int resolve_host(sd_bus *bus, const char *name) {
assert(name);
- if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))
+ if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Use --json=pretty with --type=A or --type=AAAA to acquire address record information in JSON format.");
log_debug("Resolving %s (family %s, interface %s).", name, af_to_name(arg_family) ?: "*", isempty(arg_ifname) ? "*" : arg_ifname);
@@ -354,7 +355,7 @@ static int resolve_address(sd_bus *bus, int family, const union in_addr_union *a
assert(IN_SET(family, AF_INET, AF_INET6));
assert(address);
- if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))
+ if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Use --json=pretty with --type= to acquire resource record information in JSON format.");
if (ifindex <= 0)
@@ -448,8 +449,8 @@ static int output_rr_packet(const void *d, size_t l, int ifindex) {
if (r < 0)
return log_error_errno(r, "Failed to parse RR: %m");
- if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
- _cleanup_(json_variant_unrefp) JsonVariant *j = NULL;
+ if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL;
r = dns_resource_record_to_json(rr, &j);
if (r < 0)
return log_error_errno(r, "Failed to convert RR to JSON: %m");
@@ -457,7 +458,7 @@ static int output_rr_packet(const void *d, size_t l, int ifindex) {
if (!j)
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "JSON formatting for records of type %s (%u) not available.", dns_type_to_string(rr->key->type), rr->key->type);
- r = json_variant_dump(j, arg_json_format_flags, NULL, NULL);
+ r = sd_json_variant_dump(j, arg_json_format_flags, NULL, NULL);
if (r < 0)
return r;
@@ -970,7 +971,7 @@ static int resolve_service(sd_bus *bus, const char *name, const char *type, cons
static int verb_service(int argc, char **argv, void *userdata) {
sd_bus *bus = userdata;
- if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))
+ if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Use --json=pretty with --type= to acquire resource record information in JSON format.");
if (argc == 2)
@@ -1032,7 +1033,7 @@ static int verb_openpgp(int argc, char **argv, void *userdata) {
sd_bus *bus = userdata;
int q, r = 0;
- if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))
+ if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Use --json=pretty with --type= to acquire resource record information in JSON format.");
STRV_FOREACH(p, argv + 1) {
@@ -1086,7 +1087,7 @@ static int verb_tlsa(int argc, char **argv, void *userdata) {
const char *family = "tcp";
int q, r = 0;
- if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))
+ if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Use --json=pretty with --type= to acquire resource record information in JSON format.");
if (service_family_is_valid(argv[1])) {
@@ -1105,7 +1106,7 @@ static int verb_tlsa(int argc, char **argv, void *userdata) {
static int show_statistics(int argc, char **argv, void *userdata) {
_cleanup_(table_unrefp) Table *table = NULL;
- JsonVariant *reply = NULL;
+ sd_json_variant *reply = NULL;
_cleanup_(varlink_unrefp) Varlink *vl = NULL;
int r;
@@ -1117,23 +1118,23 @@ static int show_statistics(int argc, char **argv, void *userdata) {
if (r < 0)
return r;
- if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))
- return json_variant_dump(reply, arg_json_format_flags, NULL, NULL);
+ if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ return sd_json_variant_dump(reply, arg_json_format_flags, NULL, NULL);
struct statistics {
- JsonVariant *transactions;
- JsonVariant *cache;
- JsonVariant *dnssec;
+ sd_json_variant *transactions;
+ sd_json_variant *cache;
+ sd_json_variant *dnssec;
} statistics;
- static const JsonDispatch statistics_dispatch_table[] = {
- { "transactions", JSON_VARIANT_OBJECT, json_dispatch_variant_noref, offsetof(struct statistics, transactions), JSON_MANDATORY },
- { "cache", JSON_VARIANT_OBJECT, json_dispatch_variant_noref, offsetof(struct statistics, cache), JSON_MANDATORY },
- { "dnssec", JSON_VARIANT_OBJECT, json_dispatch_variant_noref, offsetof(struct statistics, dnssec), JSON_MANDATORY },
+ static const sd_json_dispatch_field statistics_dispatch_table[] = {
+ { "transactions", SD_JSON_VARIANT_OBJECT, sd_json_dispatch_variant_noref, offsetof(struct statistics, transactions), SD_JSON_MANDATORY },
+ { "cache", SD_JSON_VARIANT_OBJECT, sd_json_dispatch_variant_noref, offsetof(struct statistics, cache), SD_JSON_MANDATORY },
+ { "dnssec", SD_JSON_VARIANT_OBJECT, sd_json_dispatch_variant_noref, offsetof(struct statistics, dnssec), SD_JSON_MANDATORY },
{},
};
- r = json_dispatch(reply, statistics_dispatch_table, JSON_LOG, &statistics);
+ r = sd_json_dispatch(reply, statistics_dispatch_table, SD_JSON_LOG, &statistics);
if (r < 0)
return r;
@@ -1146,17 +1147,17 @@ static int show_statistics(int argc, char **argv, void *userdata) {
uint64_t n_failure_responses_served_stale_total;
} transactions;
- static const JsonDispatch transactions_dispatch_table[] = {
- { "currentTransactions", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct transactions, n_current_transactions), JSON_MANDATORY },
- { "totalTransactions", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct transactions, n_transactions_total), JSON_MANDATORY },
- { "totalTimeouts", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct transactions, n_timeouts_total), JSON_MANDATORY },
- { "totalTimeoutsServedStale", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct transactions, n_timeouts_served_stale_total), JSON_MANDATORY },
- { "totalFailedResponses", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct transactions, n_failure_responses_total), JSON_MANDATORY },
- { "totalFailedResponsesServedStale", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct transactions, n_failure_responses_served_stale_total), JSON_MANDATORY },
+ static const sd_json_dispatch_field transactions_dispatch_table[] = {
+ { "currentTransactions", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct transactions, n_current_transactions), SD_JSON_MANDATORY },
+ { "totalTransactions", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct transactions, n_transactions_total), SD_JSON_MANDATORY },
+ { "totalTimeouts", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct transactions, n_timeouts_total), SD_JSON_MANDATORY },
+ { "totalTimeoutsServedStale", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct transactions, n_timeouts_served_stale_total), SD_JSON_MANDATORY },
+ { "totalFailedResponses", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct transactions, n_failure_responses_total), SD_JSON_MANDATORY },
+ { "totalFailedResponsesServedStale", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct transactions, n_failure_responses_served_stale_total), SD_JSON_MANDATORY },
{},
};
- r = json_dispatch(statistics.transactions, transactions_dispatch_table, JSON_LOG, &transactions);
+ r = sd_json_dispatch(statistics.transactions, transactions_dispatch_table, SD_JSON_LOG, &transactions);
if (r < 0)
return r;
@@ -1166,14 +1167,14 @@ static int show_statistics(int argc, char **argv, void *userdata) {
uint64_t n_cache_miss;
} cache;
- static const JsonDispatch cache_dispatch_table[] = {
- { "size", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct cache, cache_size), JSON_MANDATORY },
- { "hits", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct cache, n_cache_hit), JSON_MANDATORY },
- { "misses", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct cache, n_cache_miss), JSON_MANDATORY },
+ static const sd_json_dispatch_field cache_dispatch_table[] = {
+ { "size", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct cache, cache_size), SD_JSON_MANDATORY },
+ { "hits", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct cache, n_cache_hit), SD_JSON_MANDATORY },
+ { "misses", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct cache, n_cache_miss), SD_JSON_MANDATORY },
{},
};
- r = json_dispatch(statistics.cache, cache_dispatch_table, JSON_LOG, &cache);
+ r = sd_json_dispatch(statistics.cache, cache_dispatch_table, SD_JSON_LOG, &cache);
if (r < 0)
return r;
@@ -1184,15 +1185,15 @@ static int show_statistics(int argc, char **argv, void *userdata) {
uint64_t n_dnssec_indeterminate;
} dnsssec;
- static const JsonDispatch dnssec_dispatch_table[] = {
- { "secure", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct dnsssec, n_dnssec_secure), JSON_MANDATORY },
- { "insecure", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct dnsssec, n_dnssec_insecure), JSON_MANDATORY },
- { "bogus", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct dnsssec, n_dnssec_bogus), JSON_MANDATORY },
- { "indeterminate", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct dnsssec, n_dnssec_indeterminate), JSON_MANDATORY },
+ static const sd_json_dispatch_field dnssec_dispatch_table[] = {
+ { "secure", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct dnsssec, n_dnssec_secure), SD_JSON_MANDATORY },
+ { "insecure", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct dnsssec, n_dnssec_insecure), SD_JSON_MANDATORY },
+ { "bogus", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct dnsssec, n_dnssec_bogus), SD_JSON_MANDATORY },
+ { "indeterminate", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct dnsssec, n_dnssec_indeterminate), SD_JSON_MANDATORY },
{},
};
- r = json_dispatch(statistics.dnssec, dnssec_dispatch_table, JSON_LOG, &dnsssec);
+ r = sd_json_dispatch(statistics.dnssec, dnssec_dispatch_table, SD_JSON_LOG, &dnsssec);
if (r < 0)
return r;
@@ -1263,7 +1264,7 @@ static int show_statistics(int argc, char **argv, void *userdata) {
}
static int reset_statistics(int argc, char **argv, void *userdata) {
- JsonVariant *reply = NULL;
+ sd_json_variant *reply = NULL;
_cleanup_(varlink_unrefp) Varlink *vl = NULL;
int r;
@@ -1275,8 +1276,8 @@ static int reset_statistics(int argc, char **argv, void *userdata) {
if (r < 0)
return r;
- if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))
- return json_variant_dump(reply, arg_json_format_flags, NULL, NULL);
+ if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))
+ return sd_json_variant_dump(reply, arg_json_format_flags, NULL, NULL);
return 0;
}
@@ -2676,8 +2677,8 @@ static int verb_log_level(int argc, char *argv[], void *userdata) {
return verb_log_control_common(bus, "org.freedesktop.resolve1", argv[0], argc == 2 ? argv[1] : NULL);
}
-static int print_question(char prefix, const char *color, JsonVariant *question) {
- JsonVariant *q = NULL;
+static int print_question(char prefix, const char *color, sd_json_variant *question) {
+ sd_json_variant *q = NULL;
int r;
assert(color);
@@ -2703,24 +2704,24 @@ static int print_question(char prefix, const char *color, JsonVariant *question)
return 0;
}
-static int print_answer(JsonVariant *answer) {
- JsonVariant *a;
+static int print_answer(sd_json_variant *answer) {
+ sd_json_variant *a;
int r;
JSON_VARIANT_ARRAY_FOREACH(a, answer) {
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
_cleanup_free_ void *d = NULL;
- JsonVariant *jraw;
+ sd_json_variant *jraw;
const char *s;
size_t l;
- jraw = json_variant_by_key(a, "raw");
+ jraw = sd_json_variant_by_key(a, "raw");
if (!jraw) {
log_warning("Received monitor answer lacking valid raw data, ignoring.");
continue;
}
- r = json_variant_unbase64(jraw, &d, &l);
+ r = sd_json_variant_unbase64(jraw, &d, &l);
if (r < 0) {
log_warning_errno(r, "Failed to undo base64 encoding of monitor answer raw data, ignoring.");
continue;
@@ -2746,27 +2747,27 @@ static int print_answer(JsonVariant *answer) {
return 0;
}
-static void monitor_query_dump(JsonVariant *v) {
- _cleanup_(json_variant_unrefp) JsonVariant *question = NULL, *answer = NULL, *collected_questions = NULL;
+static void monitor_query_dump(sd_json_variant *v) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *question = NULL, *answer = NULL, *collected_questions = NULL;
int rcode = -1, error = 0, ede_code = -1;
const char *state = NULL, *result = NULL, *ede_msg = NULL;
assert(v);
- JsonDispatch dispatch_table[] = {
- { "question", JSON_VARIANT_ARRAY, json_dispatch_variant, PTR_TO_SIZE(&question), JSON_MANDATORY },
- { "answer", JSON_VARIANT_ARRAY, json_dispatch_variant, PTR_TO_SIZE(&answer), 0 },
- { "collectedQuestions", JSON_VARIANT_ARRAY, json_dispatch_variant, PTR_TO_SIZE(&collected_questions), 0 },
- { "state", JSON_VARIANT_STRING, json_dispatch_const_string, PTR_TO_SIZE(&state), JSON_MANDATORY },
- { "result", JSON_VARIANT_STRING, json_dispatch_const_string, PTR_TO_SIZE(&result), 0 },
- { "rcode", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, PTR_TO_SIZE(&rcode), 0 },
- { "errno", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, PTR_TO_SIZE(&error), 0 },
- { "extendedDNSErrorCode", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, PTR_TO_SIZE(&ede_code), 0 },
- { "extendedDNSErrorMessage", JSON_VARIANT_STRING, json_dispatch_const_string, PTR_TO_SIZE(&ede_msg), 0 },
+ sd_json_dispatch_field dispatch_table[] = {
+ { "question", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, PTR_TO_SIZE(&question), SD_JSON_MANDATORY },
+ { "answer", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, PTR_TO_SIZE(&answer), 0 },
+ { "collectedQuestions", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, PTR_TO_SIZE(&collected_questions), 0 },
+ { "state", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, PTR_TO_SIZE(&state), SD_JSON_MANDATORY },
+ { "result", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, PTR_TO_SIZE(&result), 0 },
+ { "rcode", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, PTR_TO_SIZE(&rcode), 0 },
+ { "errno", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, PTR_TO_SIZE(&error), 0 },
+ { "extendedDNSErrorCode", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, PTR_TO_SIZE(&ede_code), 0 },
+ { "extendedDNSErrorMessage", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, PTR_TO_SIZE(&ede_msg), 0 },
{}
};
- if (json_dispatch(v, dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, NULL) < 0)
+ if (sd_json_dispatch(v, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, NULL) < 0)
return;
/* First show the current question */
@@ -2799,7 +2800,7 @@ static void monitor_query_dump(JsonVariant *v) {
static int monitor_reply(
Varlink *link,
- JsonVariant *parameters,
+ sd_json_variant *parameters,
const char *error_id,
VarlinkReplyFlags flags,
void *userdata) {
@@ -2819,7 +2820,7 @@ static int monitor_reply(
return 0;
}
- if (json_variant_by_key(parameters, "ready")) {
+ if (sd_json_variant_by_key(parameters, "ready")) {
/* The first message coming in will just indicate that we are now subscribed. We let our
* caller know if they asked for it. Once the caller sees this they should know that we are
* not going to miss any queries anymore. */
@@ -2827,11 +2828,11 @@ static int monitor_reply(
return 0;
}
- if (arg_json_format_flags & JSON_FORMAT_OFF) {
+ if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
monitor_query_dump(parameters);
printf("\n");
} else
- json_variant_dump(parameters, arg_json_format_flags, NULL, NULL);
+ sd_json_variant_dump(parameters, arg_json_format_flags, NULL, NULL);
fflush(stdout);
@@ -2882,27 +2883,27 @@ static int verb_monitor(int argc, char *argv[], void *userdata) {
return c;
}
-static int dump_cache_item(JsonVariant *item) {
+static int dump_cache_item(sd_json_variant *item) {
struct item_info {
- JsonVariant *key;
- JsonVariant *rrs;
+ sd_json_variant *key;
+ sd_json_variant *rrs;
const char *type;
uint64_t until;
} item_info = {};
- static const JsonDispatch dispatch_table[] = {
- { "key", JSON_VARIANT_OBJECT, json_dispatch_variant_noref, offsetof(struct item_info, key), JSON_MANDATORY },
- { "rrs", JSON_VARIANT_ARRAY, json_dispatch_variant_noref, offsetof(struct item_info, rrs), 0 },
- { "type", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(struct item_info, type), 0 },
- { "until", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct item_info, until), 0 },
+ static const sd_json_dispatch_field dispatch_table[] = {
+ { "key", SD_JSON_VARIANT_OBJECT, sd_json_dispatch_variant_noref, offsetof(struct item_info, key), SD_JSON_MANDATORY },
+ { "rrs", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant_noref, offsetof(struct item_info, rrs), 0 },
+ { "type", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct item_info, type), 0 },
+ { "until", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct item_info, until), 0 },
{},
};
_cleanup_(dns_resource_key_unrefp) DnsResourceKey *k = NULL;
int r, c = 0;
- r = json_dispatch(item, dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &item_info);
+ r = sd_json_dispatch(item, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &item_info);
if (r < 0)
return r;
@@ -2913,19 +2914,19 @@ static int dump_cache_item(JsonVariant *item) {
if (item_info.type)
printf("%s %s%s%s\n", DNS_RESOURCE_KEY_TO_STRING(k), ansi_highlight_red(), item_info.type, ansi_normal());
else {
- JsonVariant *i;
+ sd_json_variant *i;
JSON_VARIANT_ARRAY_FOREACH(i, item_info.rrs) {
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
_cleanup_free_ void *data = NULL;
- JsonVariant *raw;
+ sd_json_variant *raw;
size_t size;
- raw = json_variant_by_key(i, "raw");
+ raw = sd_json_variant_by_key(i, "raw");
if (!raw)
return log_error_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE), "raw field missing from RR JSON data.");
- r = json_variant_unbase64(raw, &data, &size);
+ r = sd_json_variant_unbase64(raw, &data, &size);
if (r < 0)
return log_error_errno(r, "Unable to decode raw RR JSON data: %m");
@@ -2941,30 +2942,30 @@ static int dump_cache_item(JsonVariant *item) {
return c;
}
-static int dump_cache_scope(JsonVariant *scope) {
+static int dump_cache_scope(sd_json_variant *scope) {
struct scope_info {
const char *protocol;
int family;
int ifindex;
const char *ifname;
- JsonVariant *cache;
+ sd_json_variant *cache;
} scope_info = {
.family = AF_UNSPEC,
};
- JsonVariant *i;
+ sd_json_variant *i;
int r, c = 0;
- static const JsonDispatch dispatch_table[] = {
- { "protocol", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(struct scope_info, protocol), JSON_MANDATORY },
- { "family", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(struct scope_info, family), 0 },
- { "ifindex", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(struct scope_info, ifindex), 0 },
- { "ifname", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(struct scope_info, ifname), 0 },
- { "cache", JSON_VARIANT_ARRAY, json_dispatch_variant_noref, offsetof(struct scope_info, cache), JSON_MANDATORY },
+ static const sd_json_dispatch_field dispatch_table[] = {
+ { "protocol", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct scope_info, protocol), SD_JSON_MANDATORY },
+ { "family", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(struct scope_info, family), 0 },
+ { "ifindex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(struct scope_info, ifindex), 0 },
+ { "ifname", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct scope_info, ifname), 0 },
+ { "cache", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant_noref, offsetof(struct scope_info, cache), SD_JSON_MANDATORY },
{},
};
- r = json_dispatch(scope, dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &scope_info);
+ r = sd_json_dispatch(scope, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &scope_info);
if (r < 0)
return r;
@@ -2997,7 +2998,7 @@ static int dump_cache_scope(JsonVariant *scope) {
}
static int verb_show_cache(int argc, char *argv[], void *userdata) {
- JsonVariant *reply = NULL, *d = NULL;
+ sd_json_variant *reply = NULL, *d = NULL;
_cleanup_(varlink_unrefp) Varlink *vl = NULL;
int r;
@@ -3009,17 +3010,17 @@ static int verb_show_cache(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
- d = json_variant_by_key(reply, "dump");
+ d = sd_json_variant_by_key(reply, "dump");
if (!d)
return log_error_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
"DumpCache() response is missing 'dump' key.");
- if (!json_variant_is_array(d))
+ if (!sd_json_variant_is_array(d))
return log_error_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
"DumpCache() response 'dump' field not an array");
- if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
- JsonVariant *i;
+ if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ sd_json_variant *i;
JSON_VARIANT_ARRAY_FOREACH(i, d) {
r = dump_cache_scope(i);
@@ -3030,10 +3031,10 @@ static int verb_show_cache(int argc, char *argv[], void *userdata) {
return 0;
}
- return json_variant_dump(d, arg_json_format_flags, NULL, NULL);
+ return sd_json_variant_dump(d, arg_json_format_flags, NULL, NULL);
}
-static int dump_server_state(JsonVariant *server) {
+static int dump_server_state(sd_json_variant *server) {
_cleanup_(table_unrefp) Table *table = NULL;
TableCell *cell;
@@ -3060,27 +3061,27 @@ static int dump_server_state(JsonVariant *server) {
int r;
- static const JsonDispatch dispatch_table[] = {
- { "Server", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(struct server_state, server_name), JSON_MANDATORY },
- { "Type", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(struct server_state, type), JSON_MANDATORY },
- { "Interface", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(struct server_state, ifname), 0 },
- { "InterfaceIndex", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(struct server_state, ifindex), 0 },
- { "VerifiedFeatureLevel", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(struct server_state, verified_feature_level), 0 },
- { "PossibleFeatureLevel", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(struct server_state, possible_feature_level), 0 },
- { "DNSSECMode", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(struct server_state, dnssec_mode), JSON_MANDATORY },
- { "DNSSECSupported", JSON_VARIANT_BOOLEAN, json_dispatch_boolean, offsetof(struct server_state, dnssec_supported), JSON_MANDATORY },
- { "ReceivedUDPFragmentMax", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct server_state, received_udp_fragment_max), JSON_MANDATORY },
- { "FailedUDPAttempts", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct server_state, n_failed_udp), JSON_MANDATORY },
- { "FailedTCPAttempts", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(struct server_state, n_failed_tcp), JSON_MANDATORY },
- { "PacketTruncated", JSON_VARIANT_BOOLEAN, json_dispatch_boolean, offsetof(struct server_state, packet_truncated), JSON_MANDATORY },
- { "PacketBadOpt", JSON_VARIANT_BOOLEAN, json_dispatch_boolean, offsetof(struct server_state, packet_bad_opt), JSON_MANDATORY },
- { "PacketRRSIGMissing", JSON_VARIANT_BOOLEAN, json_dispatch_boolean, offsetof(struct server_state, packet_rrsig_missing), JSON_MANDATORY },
- { "PacketInvalid", JSON_VARIANT_BOOLEAN, json_dispatch_boolean, offsetof(struct server_state, packet_invalid), JSON_MANDATORY },
- { "PacketDoOff", JSON_VARIANT_BOOLEAN, json_dispatch_boolean, offsetof(struct server_state, packet_do_off), JSON_MANDATORY },
+ static const sd_json_dispatch_field dispatch_table[] = {
+ { "Server", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct server_state, server_name), SD_JSON_MANDATORY },
+ { "Type", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct server_state, type), SD_JSON_MANDATORY },
+ { "Interface", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct server_state, ifname), 0 },
+ { "InterfaceIndex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(struct server_state, ifindex), 0 },
+ { "VerifiedFeatureLevel", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct server_state, verified_feature_level), 0 },
+ { "PossibleFeatureLevel", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct server_state, possible_feature_level), 0 },
+ { "DNSSECMode", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct server_state, dnssec_mode), SD_JSON_MANDATORY },
+ { "DNSSECSupported", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(struct server_state, dnssec_supported), SD_JSON_MANDATORY },
+ { "ReceivedUDPFragmentMax", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct server_state, received_udp_fragment_max), SD_JSON_MANDATORY },
+ { "FailedUDPAttempts", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct server_state, n_failed_udp), SD_JSON_MANDATORY },
+ { "FailedTCPAttempts", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct server_state, n_failed_tcp), SD_JSON_MANDATORY },
+ { "PacketTruncated", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(struct server_state, packet_truncated), SD_JSON_MANDATORY },
+ { "PacketBadOpt", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(struct server_state, packet_bad_opt), SD_JSON_MANDATORY },
+ { "PacketRRSIGMissing", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(struct server_state, packet_rrsig_missing), SD_JSON_MANDATORY },
+ { "PacketInvalid", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(struct server_state, packet_invalid), SD_JSON_MANDATORY },
+ { "PacketDoOff", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(struct server_state, packet_do_off), SD_JSON_MANDATORY },
{},
};
- r = json_dispatch(server, dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &server_state);
+ r = sd_json_dispatch(server, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &server_state);
if (r < 0)
return r;
@@ -3171,7 +3172,7 @@ static int dump_server_state(JsonVariant *server) {
}
static int verb_show_server_state(int argc, char *argv[], void *userdata) {
- JsonVariant *reply = NULL, *d = NULL;
+ sd_json_variant *reply = NULL, *d = NULL;
_cleanup_(varlink_unrefp) Varlink *vl = NULL;
int r;
@@ -3183,17 +3184,17 @@ static int verb_show_server_state(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
- d = json_variant_by_key(reply, "dump");
+ d = sd_json_variant_by_key(reply, "dump");
if (!d)
return log_error_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
"DumpCache() response is missing 'dump' key.");
- if (!json_variant_is_array(d))
+ if (!sd_json_variant_is_array(d))
return log_error_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
"DumpCache() response 'dump' field not an array");
- if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
- JsonVariant *i;
+ if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
+ sd_json_variant *i;
JSON_VARIANT_ARRAY_FOREACH(i, d) {
r = dump_server_state(i);
@@ -3204,7 +3205,7 @@ static int verb_show_server_state(int argc, char *argv[], void *userdata) {
return 0;
}
- return json_variant_dump(d, arg_json_format_flags, NULL, NULL);
+ return sd_json_variant_dump(d, arg_json_format_flags, NULL, NULL);
}
static void help_protocol_types(void) {
@@ -3934,7 +3935,7 @@ static int native_parse_argv(int argc, char *argv[]) {
break;
case 'j':
- arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
+ arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO;
break;
case '?':
diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c
index 90619085c4..afda571ed5 100644
--- a/src/resolve/resolved-dns-cache.c
+++ b/src/resolve/resolved-dns-cache.c
@@ -1425,8 +1425,8 @@ void dns_cache_dump(DnsCache *cache, FILE *f) {
}
}
-int dns_cache_dump_to_json(DnsCache *cache, JsonVariant **ret) {
- _cleanup_(json_variant_unrefp) JsonVariant *c = NULL;
+int dns_cache_dump_to_json(DnsCache *cache, sd_json_variant **ret) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *c = NULL;
DnsCacheItem *i;
int r;
@@ -1434,17 +1434,17 @@ int dns_cache_dump_to_json(DnsCache *cache, JsonVariant **ret) {
assert(ret);
HASHMAP_FOREACH(i, cache->by_key) {
- _cleanup_(json_variant_unrefp) JsonVariant *d = NULL, *k = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *d = NULL, *k = NULL;
r = dns_resource_key_to_json(i->key, &k);
if (r < 0)
return r;
if (i->rr) {
- _cleanup_(json_variant_unrefp) JsonVariant *l = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *l = NULL;
LIST_FOREACH(by_key, j, i) {
- _cleanup_(json_variant_unrefp) JsonVariant *rj = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *rj = NULL;
assert(j->rr);
@@ -1456,48 +1456,48 @@ int dns_cache_dump_to_json(DnsCache *cache, JsonVariant **ret) {
if (r < 0)
return r;
- r = json_variant_append_arrayb(
+ r = sd_json_variant_append_arrayb(
&l,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_VARIANT("rr", rj),
- JSON_BUILD_PAIR_BASE64("raw", j->rr->wire_format, j->rr->wire_format_size)));
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_VARIANT("rr", rj),
+ SD_JSON_BUILD_PAIR_BASE64("raw", j->rr->wire_format, j->rr->wire_format_size)));
if (r < 0)
return r;
}
if (!l) {
- r = json_variant_new_array(&l, NULL, 0);
+ r = sd_json_variant_new_array(&l, NULL, 0);
if (r < 0)
return r;
}
- r = json_build(&d,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_VARIANT("key", k),
- JSON_BUILD_PAIR_VARIANT("rrs", l),
- JSON_BUILD_PAIR_UNSIGNED("until", i->until)));
+ r = sd_json_build(&d,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_VARIANT("key", k),
+ SD_JSON_BUILD_PAIR_VARIANT("rrs", l),
+ SD_JSON_BUILD_PAIR_UNSIGNED("until", i->until)));
} else if (i->type == DNS_CACHE_NODATA) {
- r = json_build(&d,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_VARIANT("key", k),
- JSON_BUILD_PAIR_EMPTY_ARRAY("rrs"),
- JSON_BUILD_PAIR_UNSIGNED("until", i->until)));
+ r = sd_json_build(&d,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_VARIANT("key", k),
+ SD_JSON_BUILD_PAIR_EMPTY_ARRAY("rrs"),
+ SD_JSON_BUILD_PAIR_UNSIGNED("until", i->until)));
} else
- r = json_build(&d,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_VARIANT("key", k),
- JSON_BUILD_PAIR_STRING("type", dns_cache_item_type_to_string(i)),
- JSON_BUILD_PAIR_UNSIGNED("until", i->until)));
+ r = sd_json_build(&d,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_VARIANT("key", k),
+ SD_JSON_BUILD_PAIR_STRING("type", dns_cache_item_type_to_string(i)),
+ SD_JSON_BUILD_PAIR_UNSIGNED("until", i->until)));
if (r < 0)
return r;
- r = json_variant_append_array(&c, d);
+ r = sd_json_variant_append_array(&c, d);
if (r < 0)
return r;
}
if (!c)
- return json_variant_new_array(ret, NULL, 0);
+ return sd_json_variant_new_array(ret, NULL, 0);
*ret = TAKE_PTR(c);
return 0;
diff --git a/src/resolve/resolved-dns-cache.h b/src/resolve/resolved-dns-cache.h
index 6a45b95a60..d8b71a3c2a 100644
--- a/src/resolve/resolved-dns-cache.h
+++ b/src/resolve/resolved-dns-cache.h
@@ -51,7 +51,7 @@ int dns_cache_lookup(
int dns_cache_check_conflicts(DnsCache *cache, DnsResourceRecord *rr, int owner_family, const union in_addr_union *owner_address);
void dns_cache_dump(DnsCache *cache, FILE *f);
-int dns_cache_dump_to_json(DnsCache *cache, JsonVariant **ret);
+int dns_cache_dump_to_json(DnsCache *cache, sd_json_variant **ret);
bool dns_cache_is_empty(DnsCache *cache);
diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c
index 204d4a625e..a2e9196261 100644
--- a/src/resolve/resolved-dns-rr.c
+++ b/src/resolve/resolved-dns-rr.c
@@ -7,6 +7,7 @@
#include "dns-type.h"
#include "escape.h"
#include "hexdecoct.h"
+#include "json-util.h"
#include "memory-util.h"
#include "resolved-dns-dnssec.h"
#include "resolved-dns-packet.h"
@@ -2130,34 +2131,34 @@ int dns_resource_record_new_from_raw(DnsResourceRecord **ret, const void *data,
return dns_packet_read_rr(p, ret, NULL, NULL);
}
-int dns_resource_key_to_json(DnsResourceKey *key, JsonVariant **ret) {
+int dns_resource_key_to_json(DnsResourceKey *key, sd_json_variant **ret) {
assert(key);
assert(ret);
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("class", JSON_BUILD_INTEGER(key->class)),
- JSON_BUILD_PAIR("type", JSON_BUILD_INTEGER(key->type)),
- JSON_BUILD_PAIR("name", JSON_BUILD_STRING(dns_resource_key_name(key)))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("class", SD_JSON_BUILD_INTEGER(key->class)),
+ SD_JSON_BUILD_PAIR("type", SD_JSON_BUILD_INTEGER(key->type)),
+ SD_JSON_BUILD_PAIR("name", SD_JSON_BUILD_STRING(dns_resource_key_name(key)))));
}
-int dns_resource_key_from_json(JsonVariant *v, DnsResourceKey **ret) {
+int dns_resource_key_from_json(sd_json_variant *v, DnsResourceKey **ret) {
_cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
uint16_t type = 0, class = 0;
const char *name = NULL;
int r;
- JsonDispatch dispatch_table[] = {
- { "class", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint16, PTR_TO_SIZE(&class), JSON_MANDATORY },
- { "type", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint16, PTR_TO_SIZE(&type), JSON_MANDATORY },
- { "name", JSON_VARIANT_STRING, json_dispatch_const_string, PTR_TO_SIZE(&name), JSON_MANDATORY },
+ sd_json_dispatch_field dispatch_table[] = {
+ { "class", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, PTR_TO_SIZE(&class), SD_JSON_MANDATORY },
+ { "type", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, PTR_TO_SIZE(&type), SD_JSON_MANDATORY },
+ { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, PTR_TO_SIZE(&name), SD_JSON_MANDATORY },
{}
};
assert(v);
assert(ret);
- r = json_dispatch(v, dispatch_table, 0, NULL);
+ r = sd_json_dispatch(v, dispatch_table, 0, NULL);
if (r < 0)
return r;
@@ -2169,34 +2170,34 @@ int dns_resource_key_from_json(JsonVariant *v, DnsResourceKey **ret) {
return 0;
}
-static int type_bitmap_to_json(Bitmap *b, JsonVariant **ret) {
- _cleanup_(json_variant_unrefp) JsonVariant *l = NULL;
+static int type_bitmap_to_json(Bitmap *b, sd_json_variant **ret) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *l = NULL;
unsigned t;
int r;
assert(ret);
BITMAP_FOREACH(t, b) {
- _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
- r = json_variant_new_unsigned(&v, t);
+ r = sd_json_variant_new_unsigned(&v, t);
if (r < 0)
return r;
- r = json_variant_append_array(&l, v);
+ r = sd_json_variant_append_array(&l, v);
if (r < 0)
return r;
}
if (!l)
- return json_variant_new_array(ret, NULL, 0);
+ return sd_json_variant_new_array(ret, NULL, 0);
*ret = TAKE_PTR(l);
return 0;
}
-static int txt_to_json(DnsTxtItem *items, JsonVariant **ret) {
- JsonVariant **elements = NULL;
+static int txt_to_json(DnsTxtItem *items, sd_json_variant **ret) {
+ sd_json_variant **elements = NULL;
size_t n = 0;
int r;
@@ -2208,22 +2209,22 @@ static int txt_to_json(DnsTxtItem *items, JsonVariant **ret) {
goto finalize;
}
- r = json_variant_new_octescape(elements + n, i->data, i->length);
+ r = sd_json_variant_new_octescape(elements + n, i->data, i->length);
if (r < 0)
goto finalize;
n++;
}
- r = json_variant_new_array(ret, elements, n);
+ r = sd_json_variant_new_array(ret, elements, n);
finalize:
- json_variant_unref_many(elements, n);
+ sd_json_variant_unref_many(elements, n);
return r;
}
-static int svc_params_to_json(DnsSvcParam *params, JsonVariant **ret) {
- JsonVariant **elements = NULL;
+static int svc_params_to_json(DnsSvcParam *params, sd_json_variant **ret) {
+ sd_json_variant **elements = NULL;
size_t n = 0;
int r;
@@ -2235,21 +2236,21 @@ static int svc_params_to_json(DnsSvcParam *params, JsonVariant **ret) {
goto finalize;
}
- r = json_variant_new_base64(elements + n, i->value, i->length);
+ r = sd_json_variant_new_base64(elements + n, i->value, i->length);
if (r < 0)
goto finalize;
n++;
}
- r = json_variant_new_array(ret, elements, n);
+ r = sd_json_variant_new_array(ret, elements, n);
finalize:
- json_variant_unref_many(elements, n);
+ sd_json_variant_unref_many(elements, n);
return r;
}
-int dns_resource_record_to_json(DnsResourceRecord *rr, JsonVariant **ret) {
- _cleanup_(json_variant_unrefp) JsonVariant *k = NULL;
+int dns_resource_record_to_json(DnsResourceRecord *rr, sd_json_variant **ret) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *k = NULL;
int r;
assert(rr);
@@ -2262,201 +2263,201 @@ int dns_resource_record_to_json(DnsResourceRecord *rr, JsonVariant **ret) {
switch (rr->unparsable ? _DNS_TYPE_INVALID : rr->key->type) {
case DNS_TYPE_SRV:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("priority", JSON_BUILD_UNSIGNED(rr->srv.priority)),
- JSON_BUILD_PAIR("weight", JSON_BUILD_UNSIGNED(rr->srv.weight)),
- JSON_BUILD_PAIR("port", JSON_BUILD_UNSIGNED(rr->srv.port)),
- JSON_BUILD_PAIR("name", JSON_BUILD_STRING(rr->srv.name))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("priority", SD_JSON_BUILD_UNSIGNED(rr->srv.priority)),
+ SD_JSON_BUILD_PAIR("weight", SD_JSON_BUILD_UNSIGNED(rr->srv.weight)),
+ SD_JSON_BUILD_PAIR("port", SD_JSON_BUILD_UNSIGNED(rr->srv.port)),
+ SD_JSON_BUILD_PAIR("name", SD_JSON_BUILD_STRING(rr->srv.name))));
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("name", JSON_BUILD_STRING(rr->ptr.name))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("name", SD_JSON_BUILD_STRING(rr->ptr.name))));
case DNS_TYPE_HINFO:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("cpu", JSON_BUILD_STRING(rr->hinfo.cpu)),
- JSON_BUILD_PAIR("os", JSON_BUILD_STRING(rr->hinfo.os))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("cpu", SD_JSON_BUILD_STRING(rr->hinfo.cpu)),
+ SD_JSON_BUILD_PAIR("os", SD_JSON_BUILD_STRING(rr->hinfo.os))));
case DNS_TYPE_SPF:
case DNS_TYPE_TXT: {
- _cleanup_(json_variant_unrefp) JsonVariant *l = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *l = NULL;
r = txt_to_json(rr->txt.items, &l);
if (r < 0)
return r;
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("items", JSON_BUILD_VARIANT(l))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("items", SD_JSON_BUILD_VARIANT(l))));
}
case DNS_TYPE_A:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("address", JSON_BUILD_IN4_ADDR(&rr->a.in_addr))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("address", JSON_BUILD_IN4_ADDR(&rr->a.in_addr))));
case DNS_TYPE_AAAA:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("address", JSON_BUILD_IN6_ADDR(&rr->aaaa.in6_addr))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("address", JSON_BUILD_IN6_ADDR(&rr->aaaa.in6_addr))));
case DNS_TYPE_SOA:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("mname", JSON_BUILD_STRING(rr->soa.mname)),
- JSON_BUILD_PAIR("rname", JSON_BUILD_STRING(rr->soa.rname)),
- JSON_BUILD_PAIR("serial", JSON_BUILD_UNSIGNED(rr->soa.serial)),
- JSON_BUILD_PAIR("refresh", JSON_BUILD_UNSIGNED(rr->soa.refresh)),
- JSON_BUILD_PAIR("expire", JSON_BUILD_UNSIGNED(rr->soa.retry)),
- JSON_BUILD_PAIR("minimum", JSON_BUILD_UNSIGNED(rr->soa.minimum))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("mname", SD_JSON_BUILD_STRING(rr->soa.mname)),
+ SD_JSON_BUILD_PAIR("rname", SD_JSON_BUILD_STRING(rr->soa.rname)),
+ SD_JSON_BUILD_PAIR("serial", SD_JSON_BUILD_UNSIGNED(rr->soa.serial)),
+ SD_JSON_BUILD_PAIR("refresh", SD_JSON_BUILD_UNSIGNED(rr->soa.refresh)),
+ SD_JSON_BUILD_PAIR("expire", SD_JSON_BUILD_UNSIGNED(rr->soa.retry)),
+ SD_JSON_BUILD_PAIR("minimum", SD_JSON_BUILD_UNSIGNED(rr->soa.minimum))));
case DNS_TYPE_MX:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("priority", JSON_BUILD_UNSIGNED(rr->mx.priority)),
- JSON_BUILD_PAIR("exchange", JSON_BUILD_STRING(rr->mx.exchange))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("priority", SD_JSON_BUILD_UNSIGNED(rr->mx.priority)),
+ SD_JSON_BUILD_PAIR("exchange", SD_JSON_BUILD_STRING(rr->mx.exchange))));
case DNS_TYPE_LOC:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("version", JSON_BUILD_UNSIGNED(rr->loc.version)),
- JSON_BUILD_PAIR("size", JSON_BUILD_UNSIGNED(rr->loc.size)),
- JSON_BUILD_PAIR("horiz_pre", JSON_BUILD_UNSIGNED(rr->loc.horiz_pre)),
- JSON_BUILD_PAIR("vert_pre", JSON_BUILD_UNSIGNED(rr->loc.vert_pre)),
- JSON_BUILD_PAIR("latitude", JSON_BUILD_UNSIGNED(rr->loc.latitude)),
- JSON_BUILD_PAIR("longitude", JSON_BUILD_UNSIGNED(rr->loc.longitude)),
- JSON_BUILD_PAIR("altitude", JSON_BUILD_UNSIGNED(rr->loc.altitude))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("version", SD_JSON_BUILD_UNSIGNED(rr->loc.version)),
+ SD_JSON_BUILD_PAIR("size", SD_JSON_BUILD_UNSIGNED(rr->loc.size)),
+ SD_JSON_BUILD_PAIR("horiz_pre", SD_JSON_BUILD_UNSIGNED(rr->loc.horiz_pre)),
+ SD_JSON_BUILD_PAIR("vert_pre", SD_JSON_BUILD_UNSIGNED(rr->loc.vert_pre)),
+ SD_JSON_BUILD_PAIR("latitude", SD_JSON_BUILD_UNSIGNED(rr->loc.latitude)),
+ SD_JSON_BUILD_PAIR("longitude", SD_JSON_BUILD_UNSIGNED(rr->loc.longitude)),
+ SD_JSON_BUILD_PAIR("altitude", SD_JSON_BUILD_UNSIGNED(rr->loc.altitude))));
case DNS_TYPE_DS:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("keyTag", JSON_BUILD_UNSIGNED(rr->ds.key_tag)),
- JSON_BUILD_PAIR("algorithm", JSON_BUILD_UNSIGNED(rr->ds.algorithm)),
- JSON_BUILD_PAIR("digestType", JSON_BUILD_UNSIGNED(rr->ds.digest_type)),
- JSON_BUILD_PAIR("digest", JSON_BUILD_HEX(rr->ds.digest, rr->ds.digest_size))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("keyTag", SD_JSON_BUILD_UNSIGNED(rr->ds.key_tag)),
+ SD_JSON_BUILD_PAIR("algorithm", SD_JSON_BUILD_UNSIGNED(rr->ds.algorithm)),
+ SD_JSON_BUILD_PAIR("digestType", SD_JSON_BUILD_UNSIGNED(rr->ds.digest_type)),
+ SD_JSON_BUILD_PAIR("digest", SD_JSON_BUILD_HEX(rr->ds.digest, rr->ds.digest_size))));
case DNS_TYPE_SSHFP:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("algorithm", JSON_BUILD_UNSIGNED(rr->sshfp.algorithm)),
- JSON_BUILD_PAIR("fptype", JSON_BUILD_UNSIGNED(rr->sshfp.fptype)),
- JSON_BUILD_PAIR("fingerprint", JSON_BUILD_HEX(rr->sshfp.fingerprint, rr->sshfp.fingerprint_size))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("algorithm", SD_JSON_BUILD_UNSIGNED(rr->sshfp.algorithm)),
+ SD_JSON_BUILD_PAIR("fptype", SD_JSON_BUILD_UNSIGNED(rr->sshfp.fptype)),
+ SD_JSON_BUILD_PAIR("fingerprint", SD_JSON_BUILD_HEX(rr->sshfp.fingerprint, rr->sshfp.fingerprint_size))));
case DNS_TYPE_DNSKEY:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("flags", JSON_BUILD_UNSIGNED(rr->dnskey.flags)),
- JSON_BUILD_PAIR("protocol", JSON_BUILD_UNSIGNED(rr->dnskey.protocol)),
- JSON_BUILD_PAIR("algorithm", JSON_BUILD_UNSIGNED(rr->dnskey.algorithm)),
- JSON_BUILD_PAIR("dnskey", JSON_BUILD_BASE64(rr->dnskey.key, rr->dnskey.key_size))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("flags", SD_JSON_BUILD_UNSIGNED(rr->dnskey.flags)),
+ SD_JSON_BUILD_PAIR("protocol", SD_JSON_BUILD_UNSIGNED(rr->dnskey.protocol)),
+ SD_JSON_BUILD_PAIR("algorithm", SD_JSON_BUILD_UNSIGNED(rr->dnskey.algorithm)),
+ SD_JSON_BUILD_PAIR("dnskey", SD_JSON_BUILD_BASE64(rr->dnskey.key, rr->dnskey.key_size))));
case DNS_TYPE_RRSIG:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("signer", JSON_BUILD_STRING(rr->rrsig.signer)),
- JSON_BUILD_PAIR("typeCovered", JSON_BUILD_UNSIGNED(rr->rrsig.type_covered)),
- JSON_BUILD_PAIR("algorithm", JSON_BUILD_UNSIGNED(rr->rrsig.algorithm)),
- JSON_BUILD_PAIR("labels", JSON_BUILD_UNSIGNED(rr->rrsig.labels)),
- JSON_BUILD_PAIR("originalTtl", JSON_BUILD_UNSIGNED(rr->rrsig.original_ttl)),
- JSON_BUILD_PAIR("expiration", JSON_BUILD_UNSIGNED(rr->rrsig.expiration)),
- JSON_BUILD_PAIR("inception", JSON_BUILD_UNSIGNED(rr->rrsig.inception)),
- JSON_BUILD_PAIR("keyTag", JSON_BUILD_UNSIGNED(rr->rrsig.key_tag)),
- JSON_BUILD_PAIR("signature", JSON_BUILD_BASE64(rr->rrsig.signature, rr->rrsig.signature_size))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("signer", SD_JSON_BUILD_STRING(rr->rrsig.signer)),
+ SD_JSON_BUILD_PAIR("typeCovered", SD_JSON_BUILD_UNSIGNED(rr->rrsig.type_covered)),
+ SD_JSON_BUILD_PAIR("algorithm", SD_JSON_BUILD_UNSIGNED(rr->rrsig.algorithm)),
+ SD_JSON_BUILD_PAIR("labels", SD_JSON_BUILD_UNSIGNED(rr->rrsig.labels)),
+ SD_JSON_BUILD_PAIR("originalTtl", SD_JSON_BUILD_UNSIGNED(rr->rrsig.original_ttl)),
+ SD_JSON_BUILD_PAIR("expiration", SD_JSON_BUILD_UNSIGNED(rr->rrsig.expiration)),
+ SD_JSON_BUILD_PAIR("inception", SD_JSON_BUILD_UNSIGNED(rr->rrsig.inception)),
+ SD_JSON_BUILD_PAIR("keyTag", SD_JSON_BUILD_UNSIGNED(rr->rrsig.key_tag)),
+ SD_JSON_BUILD_PAIR("signature", SD_JSON_BUILD_BASE64(rr->rrsig.signature, rr->rrsig.signature_size))));
case DNS_TYPE_NSEC: {
- _cleanup_(json_variant_unrefp) JsonVariant *bm = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *bm = NULL;
r = type_bitmap_to_json(rr->nsec.types, &bm);
if (r < 0)
return r;
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("nextDomain", JSON_BUILD_STRING(rr->nsec.next_domain_name)),
- JSON_BUILD_PAIR("types", JSON_BUILD_VARIANT(bm))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("nextDomain", SD_JSON_BUILD_STRING(rr->nsec.next_domain_name)),
+ SD_JSON_BUILD_PAIR("types", SD_JSON_BUILD_VARIANT(bm))));
}
case DNS_TYPE_NSEC3: {
- _cleanup_(json_variant_unrefp) JsonVariant *bm = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *bm = NULL;
r = type_bitmap_to_json(rr->nsec3.types, &bm);
if (r < 0)
return r;
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("algorithm", JSON_BUILD_UNSIGNED(rr->nsec3.algorithm)),
- JSON_BUILD_PAIR("flags", JSON_BUILD_UNSIGNED(rr->nsec3.flags)),
- JSON_BUILD_PAIR("iterations", JSON_BUILD_UNSIGNED(rr->nsec3.iterations)),
- JSON_BUILD_PAIR("salt", JSON_BUILD_HEX(rr->nsec3.salt, rr->nsec3.salt_size)),
- JSON_BUILD_PAIR("hash", JSON_BUILD_BASE32HEX(rr->nsec3.next_hashed_name, rr->nsec3.next_hashed_name_size)),
- JSON_BUILD_PAIR("types", JSON_BUILD_VARIANT(bm))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("algorithm", SD_JSON_BUILD_UNSIGNED(rr->nsec3.algorithm)),
+ SD_JSON_BUILD_PAIR("flags", SD_JSON_BUILD_UNSIGNED(rr->nsec3.flags)),
+ SD_JSON_BUILD_PAIR("iterations", SD_JSON_BUILD_UNSIGNED(rr->nsec3.iterations)),
+ SD_JSON_BUILD_PAIR("salt", SD_JSON_BUILD_HEX(rr->nsec3.salt, rr->nsec3.salt_size)),
+ SD_JSON_BUILD_PAIR("hash", SD_JSON_BUILD_BASE32HEX(rr->nsec3.next_hashed_name, rr->nsec3.next_hashed_name_size)),
+ SD_JSON_BUILD_PAIR("types", SD_JSON_BUILD_VARIANT(bm))));
}
case DNS_TYPE_TLSA:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("certUsage", JSON_BUILD_UNSIGNED(rr->tlsa.cert_usage)),
- JSON_BUILD_PAIR("selector", JSON_BUILD_UNSIGNED(rr->tlsa.selector)),
- JSON_BUILD_PAIR("matchingType", JSON_BUILD_UNSIGNED(rr->tlsa.matching_type)),
- JSON_BUILD_PAIR("data", JSON_BUILD_HEX(rr->tlsa.data, rr->tlsa.data_size))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("certUsage", SD_JSON_BUILD_UNSIGNED(rr->tlsa.cert_usage)),
+ SD_JSON_BUILD_PAIR("selector", SD_JSON_BUILD_UNSIGNED(rr->tlsa.selector)),
+ SD_JSON_BUILD_PAIR("matchingType", SD_JSON_BUILD_UNSIGNED(rr->tlsa.matching_type)),
+ SD_JSON_BUILD_PAIR("data", SD_JSON_BUILD_HEX(rr->tlsa.data, rr->tlsa.data_size))));
case DNS_TYPE_SVCB:
case DNS_TYPE_HTTPS: {
- _cleanup_(json_variant_unrefp) JsonVariant *p = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *p = NULL;
r = svc_params_to_json(rr->svcb.params, &p);
if (r < 0)
return r;
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("priority", JSON_BUILD_UNSIGNED(rr->svcb.priority)),
- JSON_BUILD_PAIR("target", JSON_BUILD_STRING(rr->svcb.target_name)),
- JSON_BUILD_PAIR("params", JSON_BUILD_VARIANT(p))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("priority", SD_JSON_BUILD_UNSIGNED(rr->svcb.priority)),
+ SD_JSON_BUILD_PAIR("target", SD_JSON_BUILD_STRING(rr->svcb.target_name)),
+ SD_JSON_BUILD_PAIR("params", SD_JSON_BUILD_VARIANT(p))));
}
case DNS_TYPE_CAA:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("flags", JSON_BUILD_UNSIGNED(rr->caa.flags)),
- JSON_BUILD_PAIR("tag", JSON_BUILD_STRING(rr->caa.tag)),
- JSON_BUILD_PAIR("value", JSON_BUILD_OCTESCAPE(rr->caa.value, rr->caa.value_size))));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("flags", SD_JSON_BUILD_UNSIGNED(rr->caa.flags)),
+ SD_JSON_BUILD_PAIR("tag", SD_JSON_BUILD_STRING(rr->caa.tag)),
+ SD_JSON_BUILD_PAIR("value", SD_JSON_BUILD_OCTESCAPE(rr->caa.value, rr->caa.value_size))));
case DNS_TYPE_NAPTR:
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("key", JSON_BUILD_VARIANT(k)),
- JSON_BUILD_PAIR("order", JSON_BUILD_UNSIGNED(rr->naptr.order)),
- JSON_BUILD_PAIR("preference", JSON_BUILD_UNSIGNED(rr->naptr.preference)),
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_VARIANT(k)),
+ SD_JSON_BUILD_PAIR("order", SD_JSON_BUILD_UNSIGNED(rr->naptr.order)),
+ SD_JSON_BUILD_PAIR("preference", SD_JSON_BUILD_UNSIGNED(rr->naptr.preference)),
/* NB: we name this flags field here naptrFlags, because there's already another "flags" field (for example in CAA) which has a different type */
- JSON_BUILD_PAIR("naptrFlags", JSON_BUILD_STRING(rr->naptr.flags)),
- JSON_BUILD_PAIR("services", JSON_BUILD_STRING(rr->naptr.services)),
- JSON_BUILD_PAIR("regexp", JSON_BUILD_STRING(rr->naptr.regexp)),
- JSON_BUILD_PAIR("replacement", JSON_BUILD_STRING(rr->naptr.replacement))));
+ SD_JSON_BUILD_PAIR("naptrFlags", SD_JSON_BUILD_STRING(rr->naptr.flags)),
+ SD_JSON_BUILD_PAIR("services", SD_JSON_BUILD_STRING(rr->naptr.services)),
+ SD_JSON_BUILD_PAIR("regexp", SD_JSON_BUILD_STRING(rr->naptr.regexp)),
+ SD_JSON_BUILD_PAIR("replacement", SD_JSON_BUILD_STRING(rr->naptr.replacement))));
default:
/* Can't provide broken-down format */
diff --git a/src/resolve/resolved-dns-rr.h b/src/resolve/resolved-dns-rr.h
index 156fa01873..23bf2f66d4 100644
--- a/src/resolve/resolved-dns-rr.h
+++ b/src/resolve/resolved-dns-rr.h
@@ -3,12 +3,13 @@
#include <netinet/in.h>
+#include "sd-json.h"
+
#include "bitmap.h"
#include "dns-def.h"
#include "dns-type.h"
#include "hashmap.h"
#include "in-addr-util.h"
-#include "json.h"
#include "list.h"
#include "string-util.h"
#include "time-util.h"
@@ -404,9 +405,9 @@ DnsSvcParam *dns_svc_params_copy(DnsSvcParam *first);
int dns_resource_record_new_from_raw(DnsResourceRecord **ret, const void *data, size_t size);
-int dns_resource_key_to_json(DnsResourceKey *key, JsonVariant **ret);
-int dns_resource_key_from_json(JsonVariant *v, DnsResourceKey **ret);
-int dns_resource_record_to_json(DnsResourceRecord *rr, JsonVariant **ret);
+int dns_resource_key_to_json(DnsResourceKey *key, sd_json_variant **ret);
+int dns_resource_key_from_json(sd_json_variant *v, DnsResourceKey **ret);
+int dns_resource_record_to_json(DnsResourceRecord *rr, sd_json_variant **ret);
void dns_resource_record_hash_func(const DnsResourceRecord *i, struct siphash *state);
int dns_resource_record_compare_func(const DnsResourceRecord *x, const DnsResourceRecord *y);
diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c
index 17bc823196..a2756c1162 100644
--- a/src/resolve/resolved-dns-scope.c
+++ b/src/resolve/resolved-dns-scope.c
@@ -1715,8 +1715,8 @@ bool dns_scope_is_default_route(DnsScope *scope) {
return !dns_scope_has_route_only_domains(scope);
}
-int dns_scope_dump_cache_to_json(DnsScope *scope, JsonVariant **ret) {
- _cleanup_(json_variant_unrefp) JsonVariant *cache = NULL;
+int dns_scope_dump_cache_to_json(DnsScope *scope, sd_json_variant **ret) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *cache = NULL;
int r;
assert(scope);
@@ -1726,13 +1726,13 @@ int dns_scope_dump_cache_to_json(DnsScope *scope, JsonVariant **ret) {
if (r < 0)
return r;
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_STRING("protocol", dns_protocol_to_string(scope->protocol)),
- JSON_BUILD_PAIR_CONDITION(scope->family != AF_UNSPEC, "family", JSON_BUILD_INTEGER(scope->family)),
- JSON_BUILD_PAIR_CONDITION(scope->link, "ifindex", JSON_BUILD_INTEGER(scope->link ? scope->link->ifindex : 0)),
- JSON_BUILD_PAIR_CONDITION(scope->link, "ifname", JSON_BUILD_STRING(scope->link ? scope->link->ifname : NULL)),
- JSON_BUILD_PAIR_VARIANT("cache", cache)));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_STRING("protocol", dns_protocol_to_string(scope->protocol)),
+ SD_JSON_BUILD_PAIR_CONDITION(scope->family != AF_UNSPEC, "family", SD_JSON_BUILD_INTEGER(scope->family)),
+ SD_JSON_BUILD_PAIR_CONDITION(!!scope->link, "ifindex", SD_JSON_BUILD_INTEGER(scope->link ? scope->link->ifindex : 0)),
+ SD_JSON_BUILD_PAIR_CONDITION(!!scope->link, "ifname", SD_JSON_BUILD_STRING(scope->link ? scope->link->ifname : NULL)),
+ SD_JSON_BUILD_PAIR_VARIANT("cache", cache)));
}
int dns_type_suitable_for_protocol(uint16_t type, DnsProtocol protocol) {
diff --git a/src/resolve/resolved-dns-scope.h b/src/resolve/resolved-dns-scope.h
index 23f147b8bd..872bc2abe7 100644
--- a/src/resolve/resolved-dns-scope.h
+++ b/src/resolve/resolved-dns-scope.h
@@ -114,7 +114,7 @@ int dns_scope_remove_dnssd_services(DnsScope *scope);
bool dns_scope_is_default_route(DnsScope *scope);
-int dns_scope_dump_cache_to_json(DnsScope *scope, JsonVariant **ret);
+int dns_scope_dump_cache_to_json(DnsScope *scope, sd_json_variant **ret);
int dns_type_suitable_for_protocol(uint16_t type, DnsProtocol protocol);
int dns_question_types_suitable_for_protocol(DnsQuestion *q, DnsProtocol protocol);
diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c
index b37f541c7f..c092bb1189 100644
--- a/src/resolve/resolved-dns-server.c
+++ b/src/resolve/resolved-dns-server.c
@@ -1106,27 +1106,27 @@ static const char* const dns_server_feature_level_table[_DNS_SERVER_FEATURE_LEVE
};
DEFINE_STRING_TABLE_LOOKUP(dns_server_feature_level, DnsServerFeatureLevel);
-int dns_server_dump_state_to_json(DnsServer *server, JsonVariant **ret) {
+int dns_server_dump_state_to_json(DnsServer *server, sd_json_variant **ret) {
assert(server);
assert(ret);
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_STRING("Server", strna(dns_server_string_full(server))),
- JSON_BUILD_PAIR_STRING("Type", strna(dns_server_type_to_string(server->type))),
- JSON_BUILD_PAIR_CONDITION(server->type == DNS_SERVER_LINK, "Interface", JSON_BUILD_STRING(server->link ? server->link->ifname : NULL)),
- JSON_BUILD_PAIR_CONDITION(server->type == DNS_SERVER_LINK, "InterfaceIndex", JSON_BUILD_UNSIGNED(server->link ? server->link->ifindex : 0)),
- JSON_BUILD_PAIR_STRING("VerifiedFeatureLevel", strna(dns_server_feature_level_to_string(server->verified_feature_level))),
- JSON_BUILD_PAIR_STRING("PossibleFeatureLevel", strna(dns_server_feature_level_to_string(server->possible_feature_level))),
- JSON_BUILD_PAIR_STRING("DNSSECMode", strna(dnssec_mode_to_string(dns_server_get_dnssec_mode(server)))),
- JSON_BUILD_PAIR_BOOLEAN("DNSSECSupported", dns_server_dnssec_supported(server)),
- JSON_BUILD_PAIR_UNSIGNED("ReceivedUDPFragmentMax", server->received_udp_fragment_max),
- JSON_BUILD_PAIR_UNSIGNED("FailedUDPAttempts", server->n_failed_udp),
- JSON_BUILD_PAIR_UNSIGNED("FailedTCPAttempts", server->n_failed_tcp),
- JSON_BUILD_PAIR_BOOLEAN("PacketTruncated", server->packet_truncated),
- JSON_BUILD_PAIR_BOOLEAN("PacketBadOpt", server->packet_bad_opt),
- JSON_BUILD_PAIR_BOOLEAN("PacketRRSIGMissing", server->packet_rrsig_missing),
- JSON_BUILD_PAIR_BOOLEAN("PacketInvalid", server->packet_invalid),
- JSON_BUILD_PAIR_BOOLEAN("PacketDoOff", server->packet_do_off)));
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_STRING("Server", strna(dns_server_string_full(server))),
+ SD_JSON_BUILD_PAIR_STRING("Type", strna(dns_server_type_to_string(server->type))),
+ SD_JSON_BUILD_PAIR_CONDITION(server->type == DNS_SERVER_LINK, "Interface", SD_JSON_BUILD_STRING(server->link ? server->link->ifname : NULL)),
+ SD_JSON_BUILD_PAIR_CONDITION(server->type == DNS_SERVER_LINK, "InterfaceIndex", SD_JSON_BUILD_UNSIGNED(server->link ? server->link->ifindex : 0)),
+ SD_JSON_BUILD_PAIR_STRING("VerifiedFeatureLevel", strna(dns_server_feature_level_to_string(server->verified_feature_level))),
+ SD_JSON_BUILD_PAIR_STRING("PossibleFeatureLevel", strna(dns_server_feature_level_to_string(server->possible_feature_level))),
+ SD_JSON_BUILD_PAIR_STRING("DNSSECMode", strna(dnssec_mode_to_string(dns_server_get_dnssec_mode(server)))),
+ SD_JSON_BUILD_PAIR_BOOLEAN("DNSSECSupported", dns_server_dnssec_supported(server)),
+ SD_JSON_BUILD_PAIR_UNSIGNED("ReceivedUDPFragmentMax", server->received_udp_fragment_max),
+ SD_JSON_BUILD_PAIR_UNSIGNED("FailedUDPAttempts", server->n_failed_udp),
+ SD_JSON_BUILD_PAIR_UNSIGNED("FailedTCPAttempts", server->n_failed_tcp),
+ SD_JSON_BUILD_PAIR_BOOLEAN("PacketTruncated", server->packet_truncated),
+ SD_JSON_BUILD_PAIR_BOOLEAN("PacketBadOpt", server->packet_bad_opt),
+ SD_JSON_BUILD_PAIR_BOOLEAN("PacketRRSIGMissing", server->packet_rrsig_missing),
+ SD_JSON_BUILD_PAIR_BOOLEAN("PacketInvalid", server->packet_invalid),
+ SD_JSON_BUILD_PAIR_BOOLEAN("PacketDoOff", server->packet_do_off)));
}
diff --git a/src/resolve/resolved-dns-server.h b/src/resolve/resolved-dns-server.h
index ef76bbc878..157c908548 100644
--- a/src/resolve/resolved-dns-server.h
+++ b/src/resolve/resolved-dns-server.h
@@ -1,8 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
+#include "sd-json.h"
+
#include "in-addr-util.h"
-#include "json.h"
#include "list.h"
#include "resolve-util.h"
#include "time-util.h"
@@ -181,4 +182,4 @@ void dns_server_unref_stream(DnsServer *s);
DnsScope *dns_server_scope(DnsServer *s);
-int dns_server_dump_state_to_json(DnsServer *server, JsonVariant **ret);
+int dns_server_dump_state_to_json(DnsServer *server, sd_json_variant **ret);
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 99787f7822..5959546dbb 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -1139,21 +1139,21 @@ static int manager_ipv6_send(
return sendmsg_loop(fd, &mh, 0);
}
-static int dns_question_to_json(DnsQuestion *q, JsonVariant **ret) {
- _cleanup_(json_variant_unrefp) JsonVariant *l = NULL;
+static int dns_question_to_json(DnsQuestion *q, sd_json_variant **ret) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *l = NULL;
DnsResourceKey *key;
int r;
assert(ret);
DNS_QUESTION_FOREACH(key, q) {
- _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
r = dns_resource_key_to_json(key, &v);
if (r < 0)
return r;
- r = json_variant_append_array(&l, v);
+ r = sd_json_variant_append_array(&l, v);
if (r < 0)
return r;
}
@@ -1163,7 +1163,7 @@ static int dns_question_to_json(DnsQuestion *q, JsonVariant **ret) {
}
int manager_monitor_send(Manager *m, DnsQuery *q) {
- _cleanup_(json_variant_unrefp) JsonVariant *jquestion = NULL, *jcollected_questions = NULL, *janswer = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *jquestion = NULL, *jcollected_questions = NULL, *janswer = NULL;
_cleanup_(dns_question_unrefp) DnsQuestion *merged = NULL;
Varlink *connection;
DnsAnswerItem *rri;
@@ -1201,7 +1201,7 @@ int manager_monitor_send(Manager *m, DnsQuery *q) {
return log_error_errno(r, "Failed to convert question to JSON: %m");
DNS_ANSWER_FOREACH_ITEM(rri, q->answer) {
- _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
r = dns_resource_record_to_json(rri->rr, &v);
if (r < 0)
@@ -1211,40 +1211,40 @@ int manager_monitor_send(Manager *m, DnsQuery *q) {
if (r < 0)
return log_error_errno(r, "Failed to generate RR wire format: %m");
- r = json_variant_append_arrayb(
+ r = sd_json_variant_append_arrayb(
&janswer,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_CONDITION(v, "rr", JSON_BUILD_VARIANT(v)),
- JSON_BUILD_PAIR("raw", JSON_BUILD_BASE64(rri->rr->wire_format, rri->rr->wire_format_size)),
- JSON_BUILD_PAIR_CONDITION(rri->ifindex > 0, "ifindex", JSON_BUILD_INTEGER(rri->ifindex))));
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_CONDITION(!!v, "rr", SD_JSON_BUILD_VARIANT(v)),
+ SD_JSON_BUILD_PAIR("raw", SD_JSON_BUILD_BASE64(rri->rr->wire_format, rri->rr->wire_format_size)),
+ SD_JSON_BUILD_PAIR_CONDITION(rri->ifindex > 0, "ifindex", SD_JSON_BUILD_INTEGER(rri->ifindex))));
if (r < 0)
return log_debug_errno(r, "Failed to append notification entry to array: %m");
}
SET_FOREACH(connection, m->varlink_subscription) {
r = varlink_notifyb(connection,
- JSON_BUILD_OBJECT(JSON_BUILD_PAIR("state", JSON_BUILD_STRING(dns_transaction_state_to_string(q->state))),
- JSON_BUILD_PAIR_CONDITION(q->state == DNS_TRANSACTION_DNSSEC_FAILED,
- "result", JSON_BUILD_STRING(dnssec_result_to_string(q->answer_dnssec_result))),
- JSON_BUILD_PAIR_CONDITION(q->state == DNS_TRANSACTION_RCODE_FAILURE,
- "rcode", JSON_BUILD_INTEGER(q->answer_rcode)),
- JSON_BUILD_PAIR_CONDITION(q->state == DNS_TRANSACTION_ERRNO,
- "errno", JSON_BUILD_INTEGER(q->answer_errno)),
- JSON_BUILD_PAIR_CONDITION(IN_SET(q->state,
+ SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("state", SD_JSON_BUILD_STRING(dns_transaction_state_to_string(q->state))),
+ SD_JSON_BUILD_PAIR_CONDITION(q->state == DNS_TRANSACTION_DNSSEC_FAILED,
+ "result", SD_JSON_BUILD_STRING(dnssec_result_to_string(q->answer_dnssec_result))),
+ SD_JSON_BUILD_PAIR_CONDITION(q->state == DNS_TRANSACTION_RCODE_FAILURE,
+ "rcode", SD_JSON_BUILD_INTEGER(q->answer_rcode)),
+ SD_JSON_BUILD_PAIR_CONDITION(q->state == DNS_TRANSACTION_ERRNO,
+ "errno", SD_JSON_BUILD_INTEGER(q->answer_errno)),
+ SD_JSON_BUILD_PAIR_CONDITION(IN_SET(q->state,
DNS_TRANSACTION_DNSSEC_FAILED,
DNS_TRANSACTION_RCODE_FAILURE) &&
q->answer_ede_rcode >= 0,
- "extendedDNSErrorCode", JSON_BUILD_INTEGER(q->answer_ede_rcode)),
- JSON_BUILD_PAIR_CONDITION(IN_SET(q->state,
+ "extendedDNSErrorCode", SD_JSON_BUILD_INTEGER(q->answer_ede_rcode)),
+ SD_JSON_BUILD_PAIR_CONDITION(IN_SET(q->state,
DNS_TRANSACTION_DNSSEC_FAILED,
DNS_TRANSACTION_RCODE_FAILURE) &&
q->answer_ede_rcode >= 0 && !isempty(q->answer_ede_msg),
- "extendedDNSErrorMessage", JSON_BUILD_STRING(q->answer_ede_msg)),
- JSON_BUILD_PAIR("question", JSON_BUILD_VARIANT(jquestion)),
- JSON_BUILD_PAIR_CONDITION(jcollected_questions,
- "collectedQuestions", JSON_BUILD_VARIANT(jcollected_questions)),
- JSON_BUILD_PAIR_CONDITION(janswer,
- "answer", JSON_BUILD_VARIANT(janswer))));
+ "extendedDNSErrorMessage", SD_JSON_BUILD_STRING(q->answer_ede_msg)),
+ SD_JSON_BUILD_PAIR("question", SD_JSON_BUILD_VARIANT(jquestion)),
+ SD_JSON_BUILD_PAIR_CONDITION(!!jcollected_questions,
+ "collectedQuestions", SD_JSON_BUILD_VARIANT(jcollected_questions)),
+ SD_JSON_BUILD_PAIR_CONDITION(!!janswer,
+ "answer", SD_JSON_BUILD_VARIANT(janswer))));
if (r < 0)
log_debug_errno(r, "Failed to send monitor event, ignoring: %m");
}
@@ -1879,7 +1879,7 @@ int socket_disable_pmtud(int fd, int af) {
}
}
-int dns_manager_dump_statistics_json(Manager *m, JsonVariant **ret) {
+int dns_manager_dump_statistics_json(Manager *m, sd_json_variant **ret) {
uint64_t size = 0, hit = 0, miss = 0;
assert(m);
@@ -1891,26 +1891,26 @@ int dns_manager_dump_statistics_json(Manager *m, JsonVariant **ret) {
miss += s->cache.n_miss;
}
- return json_build(ret,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("transactions", JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_UNSIGNED("currentTransactions", hashmap_size(m->dns_transactions)),
- JSON_BUILD_PAIR_UNSIGNED("totalTransactions", m->n_transactions_total),
- JSON_BUILD_PAIR_UNSIGNED("totalTimeouts", m->n_timeouts_total),
- JSON_BUILD_PAIR_UNSIGNED("totalTimeoutsServedStale", m->n_timeouts_served_stale_total),
- JSON_BUILD_PAIR_UNSIGNED("totalFailedResponses", m->n_failure_responses_total),
- JSON_BUILD_PAIR_UNSIGNED("totalFailedResponsesServedStale", m->n_failure_responses_served_stale_total)
+ return sd_json_build(ret,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("transactions", SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_UNSIGNED("currentTransactions", hashmap_size(m->dns_transactions)),
+ SD_JSON_BUILD_PAIR_UNSIGNED("totalTransactions", m->n_transactions_total),
+ SD_JSON_BUILD_PAIR_UNSIGNED("totalTimeouts", m->n_timeouts_total),
+ SD_JSON_BUILD_PAIR_UNSIGNED("totalTimeoutsServedStale", m->n_timeouts_served_stale_total),
+ SD_JSON_BUILD_PAIR_UNSIGNED("totalFailedResponses", m->n_failure_responses_total),
+ SD_JSON_BUILD_PAIR_UNSIGNED("totalFailedResponsesServedStale", m->n_failure_responses_served_stale_total)
)),
- JSON_BUILD_PAIR("cache", JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_UNSIGNED("size", size),
- JSON_BUILD_PAIR_UNSIGNED("hits", hit),
- JSON_BUILD_PAIR_UNSIGNED("misses", miss)
+ SD_JSON_BUILD_PAIR("cache", SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_UNSIGNED("size", size),
+ SD_JSON_BUILD_PAIR_UNSIGNED("hits", hit),
+ SD_JSON_BUILD_PAIR_UNSIGNED("misses", miss)
)),
- JSON_BUILD_PAIR("dnssec", JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_UNSIGNED("secure", m->n_dnssec_verdict[DNSSEC_SECURE]),
- JSON_BUILD_PAIR_UNSIGNED("insecure", m->n_dnssec_verdict[DNSSEC_INSECURE]),
- JSON_BUILD_PAIR_UNSIGNED("bogus", m->n_dnssec_verdict[DNSSEC_BOGUS]),
- JSON_BUILD_PAIR_UNSIGNED("indeterminate", m->n_dnssec_verdict[DNSSEC_INDETERMINATE])
+ SD_JSON_BUILD_PAIR("dnssec", SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_UNSIGNED("secure", m->n_dnssec_verdict[DNSSEC_SECURE]),
+ SD_JSON_BUILD_PAIR_UNSIGNED("insecure", m->n_dnssec_verdict[DNSSEC_INSECURE]),
+ SD_JSON_BUILD_PAIR_UNSIGNED("bogus", m->n_dnssec_verdict[DNSSEC_BOGUS]),
+ SD_JSON_BUILD_PAIR_UNSIGNED("indeterminate", m->n_dnssec_verdict[DNSSEC_INDETERMINATE])
))));
}
diff --git a/src/resolve/resolved-manager.h b/src/resolve/resolved-manager.h
index bd0e0532e7..b4a2954b03 100644
--- a/src/resolve/resolved-manager.h
+++ b/src/resolve/resolved-manager.h
@@ -226,6 +226,6 @@ bool manager_server_is_stub(Manager *m, DnsServer *s);
int socket_disable_pmtud(int fd, int af);
-int dns_manager_dump_statistics_json(Manager *m, JsonVariant **ret);
+int dns_manager_dump_statistics_json(Manager *m, sd_json_variant **ret);
void dns_manager_reset_statistics(Manager *m);
diff --git a/src/resolve/resolved-varlink.c b/src/resolve/resolved-varlink.c
index 25f85d8233..d0da67c78b 100644
--- a/src/resolve/resolved-varlink.c
+++ b/src/resolve/resolved-varlink.c
@@ -2,6 +2,7 @@
#include "glyph-util.h"
#include "in-addr-util.h"
+#include "json-util.h"
#include "resolved-dns-synthesize.h"
#include "resolved-varlink.h"
#include "socket-netlink.h"
@@ -60,11 +61,11 @@ static int reply_query_state(DnsQuery *q) {
case DNS_TRANSACTION_DNSSEC_FAILED:
return varlink_errorb(q->varlink_request, "io.systemd.Resolve.DNSSECValidationFailed",
- JSON_BUILD_OBJECT(JSON_BUILD_PAIR("result", JSON_BUILD_STRING(dnssec_result_to_string(q->answer_dnssec_result))),
- JSON_BUILD_PAIR_CONDITION(q->answer_ede_rcode >= 0,
- "extendedDNSErrorCode", JSON_BUILD_INTEGER(q->answer_ede_rcode)),
- JSON_BUILD_PAIR_CONDITION(q->answer_ede_rcode >= 0 && !isempty(q->answer_ede_msg),
- "extendedDNSErrorMessage", JSON_BUILD_STRING(q->answer_ede_msg))));
+ SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("result", SD_JSON_BUILD_STRING(dnssec_result_to_string(q->answer_dnssec_result))),
+ SD_JSON_BUILD_PAIR_CONDITION(q->answer_ede_rcode >= 0,
+ "extendedDNSErrorCode", SD_JSON_BUILD_INTEGER(q->answer_ede_rcode)),
+ SD_JSON_BUILD_PAIR_CONDITION(q->answer_ede_rcode >= 0 && !isempty(q->answer_ede_msg),
+ "extendedDNSErrorMessage", SD_JSON_BUILD_STRING(q->answer_ede_msg))));
case DNS_TRANSACTION_NO_TRUST_ANCHOR:
return varlink_error(q->varlink_request, "io.systemd.Resolve.NoTrustAnchor", NULL);
@@ -85,15 +86,15 @@ static int reply_query_state(DnsQuery *q) {
/* We return this as NXDOMAIN. This is only generated when a host doesn't implement LLMNR/TCP, and we
* thus quickly know that we cannot resolve an in-addr.arpa or ip6.arpa address. */
return varlink_errorb(q->varlink_request, "io.systemd.Resolve.DNSError",
- JSON_BUILD_OBJECT(JSON_BUILD_PAIR("rcode", JSON_BUILD_INTEGER(DNS_RCODE_NXDOMAIN))));
+ SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("rcode", SD_JSON_BUILD_INTEGER(DNS_RCODE_NXDOMAIN))));
case DNS_TRANSACTION_RCODE_FAILURE:
return varlink_errorb(q->varlink_request, "io.systemd.Resolve.DNSError",
- JSON_BUILD_OBJECT(JSON_BUILD_PAIR("rcode", JSON_BUILD_INTEGER(q->answer_rcode)),
- JSON_BUILD_PAIR_CONDITION(q->answer_ede_rcode >= 0,
- "extendedDNSErrorCode", JSON_BUILD_INTEGER(q->answer_ede_rcode)),
- JSON_BUILD_PAIR_CONDITION(q->answer_ede_rcode >= 0 && !isempty(q->answer_ede_msg),
- "extendedDNSErrorMessage", JSON_BUILD_STRING(q->answer_ede_msg))));
+ SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("rcode", SD_JSON_BUILD_INTEGER(q->answer_rcode)),
+ SD_JSON_BUILD_PAIR_CONDITION(q->answer_ede_rcode >= 0,
+ "extendedDNSErrorCode", SD_JSON_BUILD_INTEGER(q->answer_ede_rcode)),
+ SD_JSON_BUILD_PAIR_CONDITION(q->answer_ede_rcode >= 0 && !isempty(q->answer_ede_msg),
+ "extendedDNSErrorMessage", SD_JSON_BUILD_STRING(q->answer_ede_msg))));
case DNS_TRANSACTION_NULL:
case DNS_TRANSACTION_PENDING:
@@ -181,7 +182,7 @@ static bool validate_and_mangle_flags(
}
static int find_addr_records(
- JsonVariant **array,
+ sd_json_variant **array,
DnsQuestion *question,
DnsQuery *q,
DnsResourceRecord **canonical,
@@ -190,7 +191,7 @@ static int find_addr_records(
int ifindex, r;
DNS_ANSWER_FOREACH_IFINDEX(rr, ifindex, q->answer) {
- _cleanup_(json_variant_unrefp) JsonVariant *entry = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *entry = NULL;
int family;
const void *p;
@@ -210,15 +211,15 @@ static int find_addr_records(
return -EAFNOSUPPORT;
}
- r = json_build(&entry,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_CONDITION(ifindex > 0, "ifindex", JSON_BUILD_INTEGER(ifindex)),
- JSON_BUILD_PAIR("family", JSON_BUILD_INTEGER(family)),
- JSON_BUILD_PAIR("address", JSON_BUILD_BYTE_ARRAY(p, FAMILY_ADDRESS_SIZE(family)))));
+ r = sd_json_build(&entry,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_CONDITION(ifindex > 0, "ifindex", SD_JSON_BUILD_INTEGER(ifindex)),
+ SD_JSON_BUILD_PAIR("family", SD_JSON_BUILD_INTEGER(family)),
+ SD_JSON_BUILD_PAIR("address", SD_JSON_BUILD_BYTE_ARRAY(p, FAMILY_ADDRESS_SIZE(family)))));
if (r < 0)
return r;
- r = json_variant_append_array(array, entry);
+ r = sd_json_variant_append_array(array, entry);
if (r < 0)
return r;
@@ -231,7 +232,7 @@ static int find_addr_records(
static void vl_method_resolve_hostname_complete(DnsQuery *query) {
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *canonical = NULL;
- _cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
_cleanup_(dns_query_freep) DnsQuery *q = query;
_cleanup_free_ char *normalized = NULL;
DnsQuestion *question;
@@ -263,7 +264,7 @@ static void vl_method_resolve_hostname_complete(DnsQuery *query) {
if (r < 0)
goto finish;
- if (json_variant_is_blank_object(array)) {
+ if (sd_json_variant_is_blank_object(array)) {
r = varlink_error(q->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL);
goto finish;
}
@@ -274,10 +275,10 @@ static void vl_method_resolve_hostname_complete(DnsQuery *query) {
goto finish;
r = varlink_replyb(q->varlink_request,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("addresses", JSON_BUILD_VARIANT(array)),
- JSON_BUILD_PAIR("name", JSON_BUILD_STRING(normalized)),
- JSON_BUILD_PAIR("flags", JSON_BUILD_INTEGER(dns_query_reply_flags_make(q)))));
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("addresses", SD_JSON_BUILD_VARIANT(array)),
+ SD_JSON_BUILD_PAIR("name", SD_JSON_BUILD_STRING(normalized)),
+ SD_JSON_BUILD_PAIR("flags", SD_JSON_BUILD_INTEGER(dns_query_reply_flags_make(q)))));
finish:
if (r < 0) {
log_full_errno(ERRNO_IS_DISCONNECT(r) ? LOG_DEBUG : LOG_ERR, r, "Failed to send hostname reply: %m");
@@ -312,24 +313,24 @@ static int parse_as_address(Varlink *link, LookupParameters *p) {
return varlink_replyb(
link,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("addresses",
- JSON_BUILD_ARRAY(
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_CONDITION(ifindex > 0, "ifindex", JSON_BUILD_INTEGER(ifindex)),
- JSON_BUILD_PAIR("family", JSON_BUILD_INTEGER(ff)),
- JSON_BUILD_PAIR("address", JSON_BUILD_BYTE_ARRAY(&parsed, FAMILY_ADDRESS_SIZE(ff)))))),
- JSON_BUILD_PAIR("name", JSON_BUILD_STRING(canonical)),
- JSON_BUILD_PAIR("flags", JSON_BUILD_INTEGER(SD_RESOLVED_FLAGS_MAKE(dns_synthesize_protocol(p->flags), ff, true, true)|
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("addresses",
+ SD_JSON_BUILD_ARRAY(
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_CONDITION(ifindex > 0, "ifindex", SD_JSON_BUILD_INTEGER(ifindex)),
+ SD_JSON_BUILD_PAIR("family", SD_JSON_BUILD_INTEGER(ff)),
+ SD_JSON_BUILD_PAIR("address", SD_JSON_BUILD_BYTE_ARRAY(&parsed, FAMILY_ADDRESS_SIZE(ff)))))),
+ SD_JSON_BUILD_PAIR("name", SD_JSON_BUILD_STRING(canonical)),
+ SD_JSON_BUILD_PAIR("flags", SD_JSON_BUILD_INTEGER(SD_RESOLVED_FLAGS_MAKE(dns_synthesize_protocol(p->flags), ff, true, true)|
SD_RESOLVED_SYNTHETIC))));
}
-static int vl_method_resolve_hostname(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
- static const JsonDispatch dispatch_table[] = {
- { "ifindex", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(LookupParameters, ifindex), 0 },
- { "name", JSON_VARIANT_STRING, json_dispatch_string, offsetof(LookupParameters, name), JSON_MANDATORY },
- { "family", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(LookupParameters, family), 0 },
- { "flags", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(LookupParameters, flags), 0 },
+static int vl_method_resolve_hostname(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
+ static const sd_json_dispatch_field dispatch_table[] = {
+ { "ifindex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(LookupParameters, ifindex), 0 },
+ { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(LookupParameters, name), SD_JSON_MANDATORY },
+ { "family", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(LookupParameters, family), 0 },
+ { "flags", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(LookupParameters, flags), 0 },
{}
};
@@ -397,28 +398,28 @@ static int vl_method_resolve_hostname(Varlink *link, JsonVariant *parameters, Va
return 1;
}
-static int json_dispatch_address(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
+static int json_dispatch_address(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
LookupParameters *p = ASSERT_PTR(userdata);
union in_addr_union buf = {};
- JsonVariant *i;
+ sd_json_variant *i;
size_t n, 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 = json_variant_elements(variant);
+ n = sd_json_variant_elements(variant);
if (!IN_SET(n, 4, 16))
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is array of unexpected size.", strna(name));
JSON_VARIANT_ARRAY_FOREACH(i, variant) {
int64_t b;
- if (!json_variant_is_integer(i))
+ if (!sd_json_variant_is_integer(i))
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Element %zu of JSON field '%s' is not an integer.", k, strna(name));
- b = json_variant_integer(i);
+ b = sd_json_variant_integer(i);
if (b < 0 || b > 0xff)
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL),
"Element %zu of JSON field '%s' is out of range 0%s255.",
@@ -434,7 +435,7 @@ static int json_dispatch_address(const char *name, JsonVariant *variant, JsonDis
}
static void vl_method_resolve_address_complete(DnsQuery *query) {
- _cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
_cleanup_(dns_query_freep) DnsQuery *q = query;
DnsQuestion *question;
DnsResourceRecord *rr;
@@ -475,24 +476,24 @@ static void vl_method_resolve_address_complete(DnsQuery *query) {
if (r < 0)
goto finish;
- r = json_variant_append_arrayb(
+ r = sd_json_variant_append_arrayb(
&array,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_CONDITION(ifindex > 0, "ifindex", JSON_BUILD_INTEGER(ifindex)),
- JSON_BUILD_PAIR("name", JSON_BUILD_STRING(normalized))));
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_CONDITION(ifindex > 0, "ifindex", SD_JSON_BUILD_INTEGER(ifindex)),
+ SD_JSON_BUILD_PAIR("name", SD_JSON_BUILD_STRING(normalized))));
if (r < 0)
goto finish;
}
- if (json_variant_is_blank_object(array)) {
+ if (sd_json_variant_is_blank_object(array)) {
r = varlink_error(q->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL);
goto finish;
}
r = varlink_replyb(q->varlink_request,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("names", JSON_BUILD_VARIANT(array)),
- JSON_BUILD_PAIR("flags", JSON_BUILD_INTEGER(dns_query_reply_flags_make(q)))));
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("names", SD_JSON_BUILD_VARIANT(array)),
+ SD_JSON_BUILD_PAIR("flags", SD_JSON_BUILD_INTEGER(dns_query_reply_flags_make(q)))));
finish:
if (r < 0) {
log_full_errno(ERRNO_IS_DISCONNECT(r) ? LOG_DEBUG : LOG_ERR, r, "Failed to send address reply: %m");
@@ -500,12 +501,12 @@ finish:
}
}
-static int vl_method_resolve_address(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
- static const JsonDispatch dispatch_table[] = {
- { "ifindex", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(LookupParameters, ifindex), 0 },
- { "family", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(LookupParameters, family), JSON_MANDATORY },
- { "address", JSON_VARIANT_ARRAY, json_dispatch_address, 0, JSON_MANDATORY },
- { "flags", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(LookupParameters, flags), 0 },
+static int vl_method_resolve_address(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
+ static const sd_json_dispatch_field dispatch_table[] = {
+ { "ifindex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(LookupParameters, ifindex), 0 },
+ { "family", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(LookupParameters, family), SD_JSON_MANDATORY },
+ { "address", SD_JSON_VARIANT_ARRAY, json_dispatch_address, 0, SD_JSON_MANDATORY },
+ { "flags", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(LookupParameters, flags), 0 },
{}
};
@@ -564,7 +565,7 @@ static int vl_method_resolve_address(Varlink *link, JsonVariant *parameters, Var
return 1;
}
-static int append_txt(JsonVariant **txt, DnsResourceRecord *rr) {
+static int append_txt(sd_json_variant **txt, DnsResourceRecord *rr) {
int r;
assert(txt);
@@ -575,16 +576,16 @@ static int append_txt(JsonVariant **txt, DnsResourceRecord *rr) {
return 0;
LIST_FOREACH(items, i, rr->txt.items) {
- _cleanup_(json_variant_unrefp) JsonVariant *entry = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *entry = NULL;
if (i->length <= 0)
continue;
- r = json_variant_new_octescape(&entry, i->data, i->length);
+ r = sd_json_variant_new_octescape(&entry, i->data, i->length);
if (r < 0)
return r;
- r = json_variant_append_array(txt, entry);
+ r = sd_json_variant_append_array(txt, entry);
if (r < 0)
return r;
}
@@ -595,10 +596,10 @@ static int append_txt(JsonVariant **txt, DnsResourceRecord *rr) {
static int append_srv(
DnsQuery *q,
DnsResourceRecord *rr,
- JsonVariant **array) {
+ sd_json_variant **array) {
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *canonical = NULL;
- _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
_cleanup_free_ char *normalized = NULL;
int r;
@@ -654,12 +655,12 @@ static int append_srv(
if (r < 0)
return r;
- r = json_build(&v,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("priority", JSON_BUILD_UNSIGNED(rr->srv.priority)),
- JSON_BUILD_PAIR("weight", JSON_BUILD_UNSIGNED(rr->srv.weight)),
- JSON_BUILD_PAIR("port", JSON_BUILD_UNSIGNED(rr->srv.port)),
- JSON_BUILD_PAIR("hostname", JSON_BUILD_STRING(normalized))));
+ r = sd_json_build(&v,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("priority", SD_JSON_BUILD_UNSIGNED(rr->srv.priority)),
+ SD_JSON_BUILD_PAIR("weight", SD_JSON_BUILD_UNSIGNED(rr->srv.weight)),
+ SD_JSON_BUILD_PAIR("port", SD_JSON_BUILD_UNSIGNED(rr->srv.port)),
+ SD_JSON_BUILD_PAIR("hostname", SD_JSON_BUILD_STRING(normalized))));
if (r < 0)
return r;
@@ -670,13 +671,13 @@ static int append_srv(
if (r < 0)
return r;
- r = json_variant_set_field_string(&v, "canonicalName", normalized);
+ r = sd_json_variant_set_field_string(&v, "canonicalName", normalized);
if (r < 0)
return r;
}
if ((q->flags & SD_RESOLVED_NO_ADDRESS) == 0) {
- _cleanup_(json_variant_unrefp) JsonVariant *addresses = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *addresses = NULL;
LIST_FOREACH(auxiliary_queries, aux, q->auxiliary_queries) {
DnsQuestion *question;
@@ -699,12 +700,12 @@ static int append_srv(
return r;
}
- r = json_variant_set_field(&v, "addresses", addresses);
+ r = sd_json_variant_set_field(&v, "addresses", addresses);
if (r < 0)
return r;
}
- r = json_variant_append_array(array, v);
+ r = sd_json_variant_append_array(array, v);
if (r < 0)
return r;
@@ -723,7 +724,7 @@ static Varlink *get_vl_link_aux_query(DnsQuery *aux) {
static void resolve_service_all_complete(DnsQuery *query) {
_cleanup_(dns_query_freep) DnsQuery *q = query;
- _cleanup_(json_variant_unrefp) JsonVariant *srv = NULL, *txt = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *srv = NULL, *txt = NULL;
_cleanup_free_ char *name = NULL, *type = NULL, *domain = NULL;
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *canonical = NULL;
DnsQuestion *question;
@@ -804,7 +805,7 @@ static void resolve_service_all_complete(DnsQuery *query) {
canonical = dns_resource_record_ref(rr);
}
- if (json_variant_is_blank_object(srv)) {
+ if (sd_json_variant_is_blank_object(srv)) {
r = varlink_error(query->varlink_request, "io.systemd.Resolve.NoSuchResourceRecord", NULL);
goto finish;
}
@@ -829,14 +830,14 @@ static void resolve_service_all_complete(DnsQuery *query) {
if (r < 0)
goto finish;
- r = varlink_replyb(query->varlink_request, JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("services", JSON_BUILD_VARIANT(srv)),
- JSON_BUILD_PAIR_CONDITION(!json_variant_is_blank_object(txt), "txt", JSON_BUILD_VARIANT(txt)),
- JSON_BUILD_PAIR("canonical", JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("name", JSON_BUILD_STRING(name)),
- JSON_BUILD_PAIR("type", JSON_BUILD_STRING(type)),
- JSON_BUILD_PAIR("domain", JSON_BUILD_STRING(domain)))),
- JSON_BUILD_PAIR("flags", JSON_BUILD_UNSIGNED(dns_query_reply_flags_make(query)))));
+ r = varlink_replyb(query->varlink_request, SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("services", SD_JSON_BUILD_VARIANT(srv)),
+ SD_JSON_BUILD_PAIR_CONDITION(!sd_json_variant_is_blank_object(txt), "txt", SD_JSON_BUILD_VARIANT(txt)),
+ SD_JSON_BUILD_PAIR("canonical", SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("name", SD_JSON_BUILD_STRING(name)),
+ SD_JSON_BUILD_PAIR("type", SD_JSON_BUILD_STRING(type)),
+ SD_JSON_BUILD_PAIR("domain", SD_JSON_BUILD_STRING(domain)))),
+ SD_JSON_BUILD_PAIR("flags", SD_JSON_BUILD_UNSIGNED(dns_query_reply_flags_make(query)))));
finish:
if (r < 0) {
@@ -990,14 +991,14 @@ finish:
}
}
-static int vl_method_resolve_service(Varlink* link, JsonVariant* parameters, VarlinkMethodFlags flags, void* userdata) {
- static const JsonDispatch dispatch_table[] = {
- { "name", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParametersResolveService, name), 0 },
- { "type", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParametersResolveService, type), 0 },
- { "domain", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParametersResolveService, domain), JSON_MANDATORY },
- { "ifindex", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(LookupParametersResolveService, ifindex), 0 },
- { "family", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(LookupParametersResolveService, family), 0 },
- { "flags", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(LookupParametersResolveService, flags), 0 },
+static int vl_method_resolve_service(Varlink* link, sd_json_variant* parameters, VarlinkMethodFlags flags, void* userdata) {
+ static const sd_json_dispatch_field dispatch_table[] = {
+ { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParametersResolveService, name), 0 },
+ { "type", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParametersResolveService, type), 0 },
+ { "domain", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParametersResolveService, domain), SD_JSON_MANDATORY },
+ { "ifindex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(LookupParametersResolveService, ifindex), 0 },
+ { "family", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(LookupParametersResolveService, family), 0 },
+ { "flags", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(LookupParametersResolveService, flags), 0 },
{}
};
@@ -1077,7 +1078,7 @@ static int vl_method_resolve_service(Varlink* link, JsonVariant* parameters, Var
}
static void vl_method_resolve_record_complete(DnsQuery *query) {
- _cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
_cleanup_(dns_query_freep) DnsQuery *q = query;
DnsQuestion *question;
int r;
@@ -1108,7 +1109,7 @@ static void vl_method_resolve_record_complete(DnsQuery *query) {
int ifindex;
DnsResourceRecord *rr;
DNS_ANSWER_FOREACH_IFINDEX(rr, ifindex, q->answer) {
- _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
r = dns_question_matches_rr(question, rr, NULL);
if (r < 0)
@@ -1124,11 +1125,11 @@ static void vl_method_resolve_record_complete(DnsQuery *query) {
if (r < 0)
goto finish;
- r = json_variant_append_arrayb(
+ r = sd_json_variant_append_arrayb(
&array,
- JSON_BUILD_OBJECT(JSON_BUILD_PAIR_CONDITION(ifindex > 0, "ifindex", JSON_BUILD_INTEGER(ifindex)),
- JSON_BUILD_PAIR_CONDITION(v, "rr", JSON_BUILD_VARIANT(v)),
- JSON_BUILD_PAIR("raw", JSON_BUILD_BASE64(rr->wire_format, rr->wire_format_size))));
+ SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_CONDITION(ifindex > 0, "ifindex", SD_JSON_BUILD_INTEGER(ifindex)),
+ SD_JSON_BUILD_PAIR_CONDITION(!!v, "rr", SD_JSON_BUILD_VARIANT(v)),
+ SD_JSON_BUILD_PAIR("raw", SD_JSON_BUILD_BASE64(rr->wire_format, rr->wire_format_size))));
if (r < 0)
goto finish;
@@ -1141,9 +1142,9 @@ static void vl_method_resolve_record_complete(DnsQuery *query) {
}
r = varlink_replyb(q->varlink_request,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("rrs", JSON_BUILD_VARIANT(array)),
- JSON_BUILD_PAIR("flags", JSON_BUILD_INTEGER(dns_query_reply_flags_make(q)))));
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("rrs", SD_JSON_BUILD_VARIANT(array)),
+ SD_JSON_BUILD_PAIR("flags", SD_JSON_BUILD_INTEGER(dns_query_reply_flags_make(q)))));
finish:
if (r < 0) {
log_full_errno(ERRNO_IS_DISCONNECT(r) ? LOG_DEBUG : LOG_ERR, r, "Failed to send record reply: %m");
@@ -1151,13 +1152,13 @@ finish:
}
}
-static int vl_method_resolve_record(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
- static const JsonDispatch dispatch_table[] = {
- { "ifindex", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(LookupParameters, ifindex), 0 },
- { "name", JSON_VARIANT_STRING, json_dispatch_string, offsetof(LookupParameters, name), JSON_MANDATORY },
- { "class", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint16, offsetof(LookupParameters, class), 0 },
- { "type", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint16, offsetof(LookupParameters, type), JSON_MANDATORY },
- { "flags", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(LookupParameters, flags), 0 },
+static int vl_method_resolve_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
+ static const sd_json_dispatch_field dispatch_table[] = {
+ { "ifindex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(LookupParameters, ifindex), 0 },
+ { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(LookupParameters, name), SD_JSON_MANDATORY },
+ { "class", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, offsetof(LookupParameters, class), 0 },
+ { "type", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, offsetof(LookupParameters, type), SD_JSON_MANDATORY },
+ { "flags", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(LookupParameters, flags), 0 },
{}
};
@@ -1228,7 +1229,7 @@ static int vl_method_resolve_record(Varlink *link, JsonVariant *parameters, Varl
return 1;
}
-static int vl_method_subscribe_query_results(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
+static int vl_method_subscribe_query_results(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
Manager *m;
int r;
@@ -1240,13 +1241,13 @@ static int vl_method_subscribe_query_results(Varlink *link, JsonVariant *paramet
if (!FLAGS_SET(flags, VARLINK_METHOD_MORE))
return varlink_error(link, VARLINK_ERROR_EXPECTED_MORE, NULL);
- if (json_variant_elements(parameters) > 0)
+ if (sd_json_variant_elements(parameters) > 0)
return varlink_error_invalid_parameter(link, parameters);
/* Send a ready message to the connecting client, to indicate that we are now listinening, and all
* queries issued after the point the client sees this will also be reported to the client. */
r = varlink_notifyb(link,
- JSON_BUILD_OBJECT(JSON_BUILD_PAIR("ready", JSON_BUILD_BOOLEAN(true))));
+ SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("ready", SD_JSON_BUILD_BOOLEAN(true))));
if (r < 0)
return log_error_errno(r, "Failed to report monitor to be established: %m");
@@ -1260,42 +1261,42 @@ static int vl_method_subscribe_query_results(Varlink *link, JsonVariant *paramet
return 1;
}
-static int vl_method_dump_cache(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
- _cleanup_(json_variant_unrefp) JsonVariant *list = NULL;
+static int vl_method_dump_cache(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *list = NULL;
Manager *m;
int r;
assert(link);
- if (json_variant_elements(parameters) > 0)
+ if (sd_json_variant_elements(parameters) > 0)
return varlink_error_invalid_parameter(link, parameters);
m = ASSERT_PTR(varlink_server_get_userdata(varlink_get_server(link)));
LIST_FOREACH(scopes, s, m->dns_scopes) {
- _cleanup_(json_variant_unrefp) JsonVariant *j = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL;
r = dns_scope_dump_cache_to_json(s, &j);
if (r < 0)
return r;
- r = json_variant_append_array(&list, j);
+ r = sd_json_variant_append_array(&list, j);
if (r < 0)
return r;
}
if (!list) {
- r = json_variant_new_array(&list, NULL, 0);
+ r = sd_json_variant_new_array(&list, NULL, 0);
if (r < 0)
return r;
}
- return varlink_replyb(link, JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("dump", JSON_BUILD_VARIANT(list))));
+ return varlink_replyb(link, SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("dump", SD_JSON_BUILD_VARIANT(list))));
}
-static int dns_server_dump_state_to_json_list(DnsServer *server, JsonVariant **list) {
- _cleanup_(json_variant_unrefp) JsonVariant *j = NULL;
+static int dns_server_dump_state_to_json_list(DnsServer *server, sd_json_variant **list) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL;
int r;
assert(list);
@@ -1305,18 +1306,18 @@ static int dns_server_dump_state_to_json_list(DnsServer *server, JsonVariant **l
if (r < 0)
return r;
- return json_variant_append_array(list, j);
+ return sd_json_variant_append_array(list, j);
}
-static int vl_method_dump_server_state(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
- _cleanup_(json_variant_unrefp) JsonVariant *list = NULL;
+static int vl_method_dump_server_state(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *list = NULL;
Manager *m;
int r;
Link *l;
assert(link);
- if (json_variant_elements(parameters) > 0)
+ if (sd_json_variant_elements(parameters) > 0)
return varlink_error_invalid_parameter(link, parameters);
m = ASSERT_PTR(varlink_server_get_userdata(varlink_get_server(link)));
@@ -1341,23 +1342,23 @@ static int vl_method_dump_server_state(Varlink *link, JsonVariant *parameters, V
}
if (!list) {
- r = json_variant_new_array(&list, NULL, 0);
+ r = sd_json_variant_new_array(&list, NULL, 0);
if (r < 0)
return r;
}
- return varlink_replyb(link, JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR("dump", JSON_BUILD_VARIANT(list))));
+ return varlink_replyb(link, SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR("dump", SD_JSON_BUILD_VARIANT(list))));
}
-static int vl_method_dump_statistics(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
- _cleanup_(json_variant_unrefp) JsonVariant *j = NULL;
+static int vl_method_dump_statistics(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL;
Manager *m;
int r;
assert(link);
- if (json_variant_elements(parameters) > 0)
+ if (sd_json_variant_elements(parameters) > 0)
return varlink_error_invalid_parameter(link, parameters);
m = ASSERT_PTR(varlink_server_get_userdata(varlink_get_server(link)));
@@ -1366,22 +1367,22 @@ static int vl_method_dump_statistics(Varlink *link, JsonVariant *parameters, Var
if (r < 0)
return r;
- return varlink_replyb(link, JSON_BUILD_VARIANT(j));
+ return varlink_replyb(link, SD_JSON_BUILD_VARIANT(j));
}
-static int vl_method_reset_statistics(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
+static int vl_method_reset_statistics(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
Manager *m;
assert(link);
- if (json_variant_elements(parameters) > 0)
+ if (sd_json_variant_elements(parameters) > 0)
return varlink_error_invalid_parameter(link, parameters);
m = ASSERT_PTR(varlink_server_get_userdata(varlink_get_server(link)));
dns_manager_reset_statistics(m);
- return varlink_replyb(link, JSON_BUILD_EMPTY_OBJECT);
+ return varlink_replyb(link, SD_JSON_BUILD_EMPTY_OBJECT);
}
static int varlink_monitor_server_init(Manager *m) {
diff --git a/src/resolve/test-resolved-packet.c b/src/resolve/test-resolved-packet.c
index 8a65ea0f5e..cccbf54d46 100644
--- a/src/resolve/test-resolved-packet.c
+++ b/src/resolve/test-resolved-packet.c
@@ -185,7 +185,7 @@ TEST(naptr) {
assert_se(dns_packet_extract(p) >= 0);
- _cleanup_(json_variant_unrefp) JsonVariant *a = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *a = NULL;
_cleanup_free_ char *joined = NULL;
DnsResourceRecord *rr;
DNS_ANSWER_FOREACH(rr, p->answer) {
@@ -196,18 +196,18 @@ TEST(naptr) {
assert_se(strextend(&joined, s, "\n"));
- _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
assert_se(dns_resource_record_to_json(rr, &v) >= 0);
- assert_se(json_variant_append_array(&a, v) >= 0);
+ assert_se(sd_json_variant_append_array(&a, v) >= 0);
}
assert(streq(joined, twilio_reply_string));
- _cleanup_(json_variant_unrefp) JsonVariant *parsed = NULL;
- assert_se(json_parse(twilio_reply_json, /* flags= */ 0, &parsed, /* ret_line= */ NULL, /* ret_column= */ NULL) >= 0);
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *parsed = NULL;
+ assert_se(sd_json_parse(twilio_reply_json, /* flags= */ 0, &parsed, /* ret_line= */ NULL, /* ret_column= */ NULL) >= 0);
- assert_se(json_variant_equal(parsed, a));
+ assert_se(sd_json_variant_equal(parsed, a));
}
DEFINE_TEST_MAIN(LOG_DEBUG);