diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-05 19:36:05 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-05 19:36:05 +0100 |
commit | 7b05894275bc1158d752098581295377f13e7c60 (patch) | |
tree | d9b2431afd79d23a9d50812c960f8a6866677ecf | |
parent | 9d6c7c821cbf6655ecde62d2e283a6c94021f781 (diff) |
bus: add new bus API call sd_bus_message_at_end()
This may be used to determine whether we are at the end of a container
ot the entire message.
-rw-r--r-- | src/libsystemd-bus/bus-message.c | 44 | ||||
-rw-r--r-- | src/systemd/sd-bus.h | 1 |
2 files changed, 35 insertions, 10 deletions
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c index dcdb3a7187..e68b43bbae 100644 --- a/src/libsystemd-bus/bus-message.c +++ b/src/libsystemd-bus/bus-message.c @@ -2366,6 +2366,15 @@ static int buffer_peek(const void *p, uint32_t sz, size_t *rindex, size_t align, return 1; } +static bool message_end_of_signature(sd_bus_message *m) { + struct bus_container *c; + + assert(m); + + c = message_get_container(m); + return !c->signature || c->signature[c->index] == 0; +} + static bool message_end_of_array(sd_bus_message *m, size_t index) { struct bus_container *c; @@ -2378,6 +2387,22 @@ static bool message_end_of_array(sd_bus_message *m, size_t index) { return index >= c->begin + BUS_MESSAGE_BSWAP32(m, *c->array_size); } +int sd_bus_message_at_end(sd_bus_message *m, int complete) { + assert_return(m, -EINVAL); + assert_return(m->sealed, -EPERM); + + if (complete && m->n_containers > 0) + return false; + + if (message_end_of_signature(m)) + return true; + + if (message_end_of_array(m, m->rindex)) + return true; + + return false; +} + static struct bus_body_part* find_part(sd_bus_message *m, size_t index, size_t sz, void **p) { struct bus_body_part *part; size_t begin; @@ -2524,14 +2549,13 @@ int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p) { assert_return(m->sealed, -EPERM); assert_return(bus_type_is_basic(type), -EINVAL); - c = message_get_container(m); - - if (!c->signature || c->signature[c->index] == 0) + if (message_end_of_signature(m)) return -ENXIO; if (message_end_of_array(m, m->rindex)) return 0; + c = message_get_container(m); if (c->signature[c->index] != type) return -ENXIO; @@ -2901,14 +2925,14 @@ int sd_bus_message_enter_container(sd_bus_message *m, char type, const char *con return -ENOMEM; m->containers = w; - c = message_get_container(m); - - if (!c->signature || c->signature[c->index] == 0) + if (message_end_of_signature(m)) return -ENXIO; if (message_end_of_array(m, m->rindex)) return 0; + c = message_get_container(m); + signature = strdup(contents); if (!signature) return -ENOMEM; @@ -2999,14 +3023,14 @@ int sd_bus_message_peek_type(sd_bus_message *m, char *type, const char **content assert_return(m, -EINVAL); assert_return(m->sealed, -EPERM); - c = message_get_container(m); - - if (!c->signature || c->signature[c->index] == 0) + if (message_end_of_signature(m)) goto eof; if (message_end_of_array(m, m->rindex)) goto eof; + c = message_get_container(m); + if (bus_type_is_basic(c->signature[c->index])) { if (contents) *contents = NULL; @@ -3106,7 +3130,7 @@ int sd_bus_message_peek_type(sd_bus_message *m, char *type, const char **content eof: if (type) - *type = c->enclosing; + *type = 0; if (contents) *contents = NULL; return 0; diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h index c6f940904c..6b43a23d00 100644 --- a/src/systemd/sd-bus.h +++ b/src/systemd/sd-bus.h @@ -203,6 +203,7 @@ int sd_bus_message_enter_container(sd_bus_message *m, char type, const char *con int sd_bus_message_exit_container(sd_bus_message *m); int sd_bus_message_peek_type(sd_bus_message *m, char *type, const char **contents); int sd_bus_message_verify_type(sd_bus_message *m, char type, const char *contents); +int sd_bus_message_at_end(sd_bus_message *m, int complete); int sd_bus_message_rewind(sd_bus_message *m, int complete); /* Convenience calls */ |