X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Flibsystemd-bus%2Fbus-message.c;h=437f6dfd49d89840e1fbe716d7409eb0e7afeac0;hb=cd6f997f71c3aba16aa08226d423d14cbc787f82;hp=dcdb3a71873a4c787007a91a03c6b9b8a1da649f;hpb=9d6c7c821cbf6655ecde62d2e283a6c94021f781;p=elogind.git diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c index dcdb3a718..437f6dfd4 100644 --- a/src/libsystemd-bus/bus-message.c +++ b/src/libsystemd-bus/bus-message.c @@ -1347,14 +1347,29 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void switch (type) { case SD_BUS_TYPE_STRING: + /* To make things easy we'll serialize a NULL string + * into the empty string */ + p = strempty(p); + + /* Fall through... */ case SD_BUS_TYPE_OBJECT_PATH: + if (!p) { + r = -EINVAL; + goto fail; + } + align = 4; sz = 4 + strlen(p) + 1; break; case SD_BUS_TYPE_SIGNATURE: + if (!p) { + r = -EINVAL; + goto fail; + } + align = 1; sz = 1 + strlen(p) + 1; break; @@ -2366,6 +2381,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 +2402,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 +2564,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 +2940,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 +3038,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 +3145,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;