diff options
author | Ronan Pigott <ronan@rjp.ie> | 2024-07-18 01:30:19 +0200 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2024-07-24 09:18:47 +0200 |
commit | ddec3537495f4b588dc28cae1bc9cc06104a894c (patch) | |
tree | c6ee95c7d00c16a42cb5a3ffc8fd5badd0a09880 | |
parent | Merge pull request #33810 from YHNdnzj/find-executable-simplify (diff) | |
download | systemd-ddec3537495f4b588dc28cae1bc9cc06104a894c.tar.xz systemd-ddec3537495f4b588dc28cae1bc9cc06104a894c.zip |
resolved: report svc params as a json object
This representation is significantly more useful. The previous array
format omitted the svc param key, which is not very useful.
-rw-r--r-- | src/resolve/resolved-dns-rr.c | 25 | ||||
-rw-r--r-- | src/shared/varlink-io.systemd.Resolve.c | 4 |
2 files changed, 13 insertions, 16 deletions
diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c index e9d667f7d5..d04af90cbc 100644 --- a/src/resolve/resolved-dns-rr.c +++ b/src/resolve/resolved-dns-rr.c @@ -2224,29 +2224,24 @@ finalize: } static int svc_params_to_json(DnsSvcParam *params, sd_json_variant **ret) { - sd_json_variant **elements = NULL; - size_t n = 0; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL; int r; assert(ret); LIST_FOREACH(params, i, params) { - if (!GREEDY_REALLOC(elements, n + 1)) { - r = -ENOMEM; - goto finalize; - } - - r = sd_json_variant_new_base64(elements + n, i->value, i->length); + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; + r = sd_json_variant_new_base64(&v, i->value, i->length); if (r < 0) - goto finalize; + return r; - n++; + r = sd_json_variant_set_field(&w, FORMAT_DNS_SVC_PARAM_KEY(i->key), v); + if (r < 0) + return r; } - r = sd_json_variant_new_array(ret, elements, n); -finalize: - sd_json_variant_unref_many(elements, n); - return r; + *ret = TAKE_PTR(w); + return 0; } int dns_resource_record_to_json(DnsResourceRecord *rr, sd_json_variant **ret) { @@ -2436,7 +2431,7 @@ int dns_resource_record_to_json(DnsResourceRecord *rr, sd_json_variant **ret) { 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))); + SD_JSON_BUILD_PAIR("svcparams", SD_JSON_BUILD_VARIANT(p))); } case DNS_TYPE_CAA: diff --git a/src/shared/varlink-io.systemd.Resolve.c b/src/shared/varlink-io.systemd.Resolve.c index 83c68321c4..0515b1ae3d 100644 --- a/src/shared/varlink-io.systemd.Resolve.c +++ b/src/shared/varlink-io.systemd.Resolve.c @@ -61,7 +61,9 @@ SD_VARLINK_DEFINE_STRUCT_TYPE( SD_VARLINK_DEFINE_FIELD(tag, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), SD_VARLINK_DEFINE_FIELD(value, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), SD_VARLINK_DEFINE_FIELD(target, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), - SD_VARLINK_DEFINE_FIELD(params, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), + /* This field is retired */ + /* SD_VARLINK_DEFINE_FIELD(params, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY), */ + SD_VARLINK_DEFINE_FIELD(svcparams, SD_VARLINK_OBJECT, SD_VARLINK_NULLABLE), SD_VARLINK_DEFINE_FIELD(order, SD_VARLINK_INT, SD_VARLINK_NULLABLE), SD_VARLINK_DEFINE_FIELD(preference, SD_VARLINK_INT, SD_VARLINK_NULLABLE), SD_VARLINK_DEFINE_FIELD(naptrFlags, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), |