mirror of
https://github.com/systemd/systemd.git
synced 2025-01-26 14:04:03 +03:00
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.
This commit is contained in:
parent
e0930aa6ff
commit
ce74fb0905
@ -2586,34 +2586,6 @@ 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);
|
return verb_log_control_common(bus, "org.freedesktop.resolve1", argv[0], argc == 2 ? argv[1] : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int monitor_rkey_from_json(JsonVariant *v, DnsResourceKey **ret_key) {
|
|
||||||
_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_key);
|
|
||||||
|
|
||||||
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_key = TAKE_PTR(key);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int print_question(char prefix, const char *color, JsonVariant *question) {
|
static int print_question(char prefix, const char *color, JsonVariant *question) {
|
||||||
JsonVariant *q = NULL;
|
JsonVariant *q = NULL;
|
||||||
int r;
|
int r;
|
||||||
@ -2624,7 +2596,7 @@ static int print_question(char prefix, const char *color, JsonVariant *question)
|
|||||||
_cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
|
_cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
|
||||||
char buf[DNS_RESOURCE_KEY_STRING_MAX];
|
char buf[DNS_RESOURCE_KEY_STRING_MAX];
|
||||||
|
|
||||||
r = monitor_rkey_from_json(q, &key);
|
r = dns_resource_key_from_json(q, &key);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_warning_errno(r, "Received monitor message with invalid question key, ignoring: %m");
|
log_warning_errno(r, "Received monitor message with invalid question key, ignoring: %m");
|
||||||
continue;
|
continue;
|
||||||
|
@ -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)))));
|
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) {
|
static int type_bitmap_to_json(Bitmap *b, JsonVariant **ret) {
|
||||||
_cleanup_(json_variant_unrefp) JsonVariant *l = NULL;
|
_cleanup_(json_variant_unrefp) JsonVariant *l = NULL;
|
||||||
unsigned t;
|
unsigned t;
|
||||||
|
@ -368,6 +368,7 @@ int dns_txt_item_new_empty(DnsTxtItem **ret);
|
|||||||
int dns_resource_record_new_from_raw(DnsResourceRecord **ret, const void *data, size_t size);
|
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_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_record_to_json(DnsResourceRecord *rr, JsonVariant **ret);
|
||||||
|
|
||||||
void dns_resource_record_hash_func(const DnsResourceRecord *i, struct siphash *state);
|
void dns_resource_record_hash_func(const DnsResourceRecord *i, struct siphash *state);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user