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 /src/libsystemd-bus/bus-message.c | |
parent | cbb76c29ccd1a639ada00425fa7cc408507f171d (diff) |
bus: add APIs for adding iovecs to messages as string or arrays
Diffstat (limited to 'src/libsystemd-bus/bus-message.c')
-rw-r--r-- | src/libsystemd-bus/bus-message.c | 76 |
1 files changed, 75 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) { |