diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-11 16:26:12 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-11 16:26:12 +0100 |
commit | 938bcbab125298b9c49946ca0bd0b47890e4d140 (patch) | |
tree | 1d2af2f4a77c544ec957606fb859d9e86c9c4903 | |
parent | cbb76c29ccd1a639ada00425fa7cc408507f171d (diff) |
bus: add APIs for adding iovecs to messages as string or arrays
-rw-r--r-- | src/libsystemd-bus/bus-message.c | 76 | ||||
-rw-r--r-- | src/libsystemd-bus/libsystemd-bus.sym | 2 | ||||
-rw-r--r-- | src/systemd/sd-bus.h | 3 |
3 files changed, 80 insertions, 1 deletions
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c index 1a50226b01..b26d446578 100644 --- a/src/libsystemd-bus/bus-message.c +++ b/src/libsystemd-bus/bus-message.c @@ -1498,7 +1498,11 @@ _public_ int sd_bus_message_append_basic(sd_bus_message *m, char type, const voi return message_append_basic(m, type, p, NULL); } -_public_ int sd_bus_message_append_string_space(sd_bus_message *m, size_t size, char **s) { +_public_ int sd_bus_message_append_string_space( + sd_bus_message *m, + size_t size, + char **s) { + struct bus_container *c; void *a; @@ -1543,6 +1547,40 @@ _public_ int sd_bus_message_append_string_space(sd_bus_message *m, size_t size, return 0; } +_public_ int sd_bus_message_append_string_iovec( + sd_bus_message *m, + const struct iovec *iov, + unsigned n) { + + size_t size; + unsigned i; + char *p; + int r; + + assert_return(m, -EINVAL); + assert_return(!m->sealed, -EPERM); + assert_return(iov || n == 0, -EINVAL); + assert_return(!m->poisoned, -ESTALE); + + size = IOVEC_TOTAL_SIZE(iov, n); + + r = sd_bus_message_append_string_space(m, size, &p); + if (r < 0) + return r; + + for (i = 0; i < n; i++) { + + if (iov[i].iov_base) + memcpy(p, iov[i].iov_base, iov[i].iov_len); + else + memset(p, ' ', iov[i].iov_len); + + p += iov[i].iov_len; + } + + return 0; +} + static int bus_message_open_array( sd_bus_message *m, struct bus_container *c, @@ -2159,6 +2197,42 @@ _public_ int sd_bus_message_append_array(sd_bus_message *m, return 0; } +_public_ int sd_bus_message_append_array_iovec( + sd_bus_message *m, + char type, + const struct iovec *iov, + unsigned n) { + + size_t size; + unsigned i; + void *p; + int r; + + assert_return(m, -EINVAL); + assert_return(!m->sealed, -EPERM); + assert_return(bus_type_is_trivial(type), -EINVAL); + assert_return(iov || n == 0, -EINVAL); + assert_return(!m->poisoned, -ESTALE); + + size = IOVEC_TOTAL_SIZE(iov, n); + + r = sd_bus_message_append_array_space(m, type, size, &p); + if (r < 0) + return r; + + for (i = 0; i < n; i++) { + + if (iov[i].iov_base) + memcpy(p, iov[i].iov_base, iov[i].iov_len); + else + memset(p, 0, iov[i].iov_len); + + p = (uint8_t*) p + iov[i].iov_len; + } + + return 0; +} + _public_ int sd_bus_message_append_array_memfd(sd_bus_message *m, char type, sd_memfd *memfd) { diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym index 4924cf1652..2c4f07d753 100644 --- a/src/libsystemd-bus/libsystemd-bus.sym +++ b/src/libsystemd-bus/libsystemd-bus.sym @@ -119,8 +119,10 @@ global: sd_bus_message_append_basic; sd_bus_message_append_array; sd_bus_message_append_array_space; + sd_bus_message_append_array_iovec; sd_bus_message_append_array_memfd; sd_bus_message_append_string_space; + sd_bus_message_append_string_iovec; sd_bus_message_append_string_memfd; sd_bus_message_append_strv; sd_bus_message_open_container; diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h index f843c778cb..6202acb659 100644 --- a/src/systemd/sd-bus.h +++ b/src/systemd/sd-bus.h @@ -24,6 +24,7 @@ #include <inttypes.h> #include <sys/types.h> +#include <sys/uio.h> #include "sd-id128.h" #include "sd-event.h" @@ -186,8 +187,10 @@ int sd_bus_message_append(sd_bus_message *m, const char *types, ...); int sd_bus_message_append_basic(sd_bus_message *m, char type, const void *p); int sd_bus_message_append_array(sd_bus_message *m, char type, const void *ptr, size_t size); int sd_bus_message_append_array_space(sd_bus_message *m, char type, size_t size, void **ptr); +int sd_bus_message_append_array_iovec(sd_bus_message *m, char type, const struct iovec *iov, unsigned n); int sd_bus_message_append_array_memfd(sd_bus_message *m, char type, sd_memfd *memfd); int sd_bus_message_append_string_space(sd_bus_message *m, size_t size, char **s); +int sd_bus_message_append_string_iovec(sd_bus_message *m, const struct iovec *iov, unsigned n); int sd_bus_message_append_string_memfd(sd_bus_message *m, sd_memfd* memfd); int sd_bus_message_append_strv(sd_bus_message *m, char **l); int sd_bus_message_open_container(sd_bus_message *m, char type, const char *contents); |