mirror of
https://github.com/systemd/systemd.git
synced 2024-10-28 20:25:38 +03:00
bus-util: add bus_message_append_string_set() helper
This new helper adds all strings from a Set object as a string array to a message. Various places where we have similar code are then ported over to this.
This commit is contained in:
parent
2824385c4e
commit
9298af8dd3
@ -7,6 +7,7 @@
|
|||||||
#include "bpf-firewall.h"
|
#include "bpf-firewall.h"
|
||||||
#include "bpf-foreign.h"
|
#include "bpf-foreign.h"
|
||||||
#include "bus-get-properties.h"
|
#include "bus-get-properties.h"
|
||||||
|
#include "bus-util.h"
|
||||||
#include "cgroup-util.h"
|
#include "cgroup-util.h"
|
||||||
#include "cgroup.h"
|
#include "cgroup.h"
|
||||||
#include "core-varlink.h"
|
#include "core-varlink.h"
|
||||||
@ -400,9 +401,9 @@ static int property_get_restrict_network_interfaces(
|
|||||||
sd_bus_message *reply,
|
sd_bus_message *reply,
|
||||||
void *userdata,
|
void *userdata,
|
||||||
sd_bus_error *error) {
|
sd_bus_error *error) {
|
||||||
int r;
|
|
||||||
CGroupContext *c = ASSERT_PTR(userdata);
|
CGroupContext *c = ASSERT_PTR(userdata);
|
||||||
char *iface;
|
int r;
|
||||||
|
|
||||||
assert(bus);
|
assert(bus);
|
||||||
assert(reply);
|
assert(reply);
|
||||||
@ -415,17 +416,7 @@ static int property_get_restrict_network_interfaces(
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = sd_bus_message_open_container(reply, 'a', "s");
|
r = bus_message_append_string_set(reply, c->restrict_network_interfaces);
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
SET_FOREACH(iface, c->restrict_network_interfaces) {
|
|
||||||
r = sd_bus_message_append(reply, "s", iface);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = sd_bus_message_close_container(reply);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "af-list.h"
|
#include "af-list.h"
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "bus-get-properties.h"
|
#include "bus-get-properties.h"
|
||||||
|
#include "bus-util.h"
|
||||||
#include "cap-list.h"
|
#include "cap-list.h"
|
||||||
#include "capability-util.h"
|
#include "capability-util.h"
|
||||||
#include "cpu-set-util.h"
|
#include "cpu-set-util.h"
|
||||||
@ -939,24 +940,12 @@ static int property_get_import_credential(
|
|||||||
sd_bus_error *error) {
|
sd_bus_error *error) {
|
||||||
|
|
||||||
ExecContext *c = ASSERT_PTR(userdata);
|
ExecContext *c = ASSERT_PTR(userdata);
|
||||||
const char *s;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(bus);
|
assert(bus);
|
||||||
assert(property);
|
assert(property);
|
||||||
assert(reply);
|
assert(reply);
|
||||||
|
|
||||||
r = sd_bus_message_open_container(reply, 'a', "s");
|
return bus_message_append_string_set(reply, c->import_credentials);
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
SET_FOREACH(s, c->import_credentials) {
|
|
||||||
r = sd_bus_message_append(reply, "s", s);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sd_bus_message_close_container(reply);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int property_get_root_hash(
|
static int property_get_root_hash(
|
||||||
|
@ -1687,22 +1687,10 @@ static int bus_property_get_ntas(
|
|||||||
sd_bus_error *error) {
|
sd_bus_error *error) {
|
||||||
|
|
||||||
Manager *m = ASSERT_PTR(userdata);
|
Manager *m = ASSERT_PTR(userdata);
|
||||||
const char *domain;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(reply);
|
assert(reply);
|
||||||
|
|
||||||
r = sd_bus_message_open_container(reply, 'a', "s");
|
return bus_message_append_string_set(reply, m->trust_anchor.negative_by_name);
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
SET_FOREACH(domain, m->trust_anchor.negative_by_name) {
|
|
||||||
r = sd_bus_message_append(reply, "s", domain);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sd_bus_message_close_container(reply);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_dns_stub_listener_mode, dns_stub_listener_mode, DnsStubListenerMode);
|
static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_dns_stub_listener_mode, dns_stub_listener_mode, DnsStubListenerMode);
|
||||||
|
@ -217,22 +217,10 @@ static int property_get_ntas(
|
|||||||
sd_bus_error *error) {
|
sd_bus_error *error) {
|
||||||
|
|
||||||
Link *l = ASSERT_PTR(userdata);
|
Link *l = ASSERT_PTR(userdata);
|
||||||
const char *name;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(reply);
|
assert(reply);
|
||||||
|
|
||||||
r = sd_bus_message_open_container(reply, 'a', "s");
|
return bus_message_append_string_set(reply, l->dnssec_negative_trust_anchors);
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
SET_FOREACH(name, l->dnssec_negative_trust_anchors) {
|
|
||||||
r = sd_bus_message_append(reply, "s", name);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sd_bus_message_close_container(reply);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int verify_unmanaged_link(Link *l, sd_bus_error *error) {
|
static int verify_unmanaged_link(Link *l, sd_bus_error *error) {
|
||||||
|
@ -678,3 +678,22 @@ const struct hash_ops bus_message_hash_ops = {
|
|||||||
.compare = trivial_compare_func,
|
.compare = trivial_compare_func,
|
||||||
.free_value = bus_message_unref_wrapper,
|
.free_value = bus_message_unref_wrapper,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int bus_message_append_string_set(sd_bus_message *m, Set *set) {
|
||||||
|
const char *s;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(m);
|
||||||
|
|
||||||
|
r = sd_bus_message_open_container(m, 'a', "s");
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
SET_FOREACH(s, set) {
|
||||||
|
r = sd_bus_message_append(m, "s", s);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sd_bus_message_close_container(m);
|
||||||
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "errno-util.h"
|
#include "errno-util.h"
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
#include "runtime-scope.h"
|
#include "runtime-scope.h"
|
||||||
|
#include "set.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
#include "time-util.h"
|
#include "time-util.h"
|
||||||
|
|
||||||
@ -68,3 +69,5 @@ int bus_reply_pair_array(sd_bus_message *m, char **l);
|
|||||||
int bus_register_malloc_status(sd_bus *bus, const char *destination);
|
int bus_register_malloc_status(sd_bus *bus, const char *destination);
|
||||||
|
|
||||||
extern const struct hash_ops bus_message_hash_ops;
|
extern const struct hash_ops bus_message_hash_ops;
|
||||||
|
|
||||||
|
int bus_message_append_string_set(sd_bus_message *m, Set *s);
|
||||||
|
Loading…
Reference in New Issue
Block a user