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;
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;
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;
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;
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;
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;
eof:
if (type)
- *type = c->enclosing;
+ *type = 0;
if (contents)
*contents = NULL;
return 0;