summaryrefslogtreecommitdiffstats
path: root/src/resolve/resolved-dns-rr.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-06-12 16:44:40 +0200
committerLennart Poettering <lennart@poettering.net>2023-06-12 22:21:26 +0200
commitce74fb09050831b6e76e134620f5caadff3b25ef (patch)
tree3921a4a4477b722c232543166908218235e4cb06 /src/resolve/resolved-dns-rr.c
parentresolved: add DumpCache varlink call for acquiring a complete dump of all of ... (diff)
downloadsystemd-ce74fb09050831b6e76e134620f5caadff3b25ef.tar.xz
systemd-ce74fb09050831b6e76e134620f5caadff3b25ef.zip
resolved: add dns_resource_key_from_json() helper
It reverse what dns_resource_key_to_json(), i.e. turns JSON data into a parsed DnsResourceKey object. Ultimately this just moves a client-side local wrapper into generic code. Nothing truly new here.
Diffstat (limited to 'src/resolve/resolved-dns-rr.c')
-rw-r--r--src/resolve/resolved-dns-rr.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c
index 603bb1a10d..f6344542d6 100644
--- a/src/resolve/resolved-dns-rr.c
+++ b/src/resolve/resolved-dns-rr.c
@@ -1853,6 +1853,34 @@ int dns_resource_key_to_json(DnsResourceKey *key, JsonVariant **ret) {
JSON_BUILD_PAIR("name", JSON_BUILD_STRING(dns_resource_key_name(key)))));
}
+int dns_resource_key_from_json(JsonVariant *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_INTEGER, json_dispatch_uint16, PTR_TO_SIZE(&class), JSON_MANDATORY },
+ { "type", JSON_VARIANT_INTEGER, json_dispatch_uint16, PTR_TO_SIZE(&type), JSON_MANDATORY },
+ { "name", JSON_VARIANT_STRING, json_dispatch_const_string, PTR_TO_SIZE(&name), JSON_MANDATORY },
+ {}
+ };
+
+ assert(v);
+ assert(ret);
+
+ r = json_dispatch(v, dispatch_table, NULL, 0, NULL);
+ if (r < 0)
+ return r;
+
+ key = dns_resource_key_new(class, type, name);
+ if (!key)
+ return -ENOMEM;
+
+ *ret = TAKE_PTR(key);
+ return 0;
+}
+
static int type_bitmap_to_json(Bitmap *b, JsonVariant **ret) {
_cleanup_(json_variant_unrefp) JsonVariant *l = NULL;
unsigned t;