chiark / gitweb /
bus: support entering containers without specifying the type
authorLennart Poettering <lennart@poettering.net>
Tue, 5 Nov 2013 01:54:08 +0000 (02:54 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 5 Nov 2013 02:07:39 +0000 (03:07 +0100)
On request om Tom Gundersen...

src/libsystemd-bus/bus-message.c
src/libsystemd-bus/test-bus-marshal.c

index 78adf11..7a4c65d 100644 (file)
@@ -2982,12 +2982,28 @@ int sd_bus_message_enter_container(sd_bus_message *m, char type, const char *con
         size_t before;
         int r;
 
-        if (!m)
-                return -EINVAL;
-        if (!m->sealed)
-                return -EPERM;
-        if (!contents)
-                return -EINVAL;
+        assert_return(m, -EINVAL);
+        assert_return(m->sealed, -EPERM);
+        assert_return(type != 0 || !contents, -EINVAL);
+
+        if (type == 0 || !contents) {
+                const char *cc;
+                char tt;
+
+                /* Allow entering into anonymous containers */
+                r = sd_bus_message_peek_type(m, &tt, &cc);
+                if (r <= 0)
+                        return r;
+
+                if (type != 0 && type != tt)
+                        return -ENXIO;
+
+                if (contents && !streq(contents, cc))
+                        return -ENXIO;
+
+                type = tt;
+                contents = cc;
+        }
 
         /*
          * We enforce a global limit on container depth, that is much
index 8f27089..2a27e62 100644 (file)
@@ -252,9 +252,28 @@ int main(int argc, char *argv[]) {
 
         assert_se(sd_bus_message_verify_type(m, 'b', NULL) > 0);
 
-        r = sd_bus_message_read(m, "ba(ss)", &boolean, 3, &x, &y, &a, &b, &c, &d);
+        r = sd_bus_message_read(m, "b", &boolean);
         assert_se(r > 0);
         assert_se(boolean);
+
+        r = sd_bus_message_enter_container(m, 0, NULL);
+        assert_se(r > 0);
+
+        r = sd_bus_message_read(m, "(ss)", &x, &y);
+        assert_se(r > 0);
+
+        r = sd_bus_message_read(m, "(ss)", &a, &b);
+        assert_se(r > 0);
+
+        r = sd_bus_message_read(m, "(ss)", &c, &d);
+        assert_se(r > 0);
+
+        r = sd_bus_message_read(m, "(ss)", &x, &y);
+        assert_se(r == 0);
+
+        r = sd_bus_message_exit_container(m);
+        assert_se(r >= 0);
+
         assert_se(streq(x, "aaa"));
         assert_se(streq(y, "1"));
         assert_se(streq(a, "bbb"));