chiark / gitweb /
bus: parse matches locally and allow registration of callbacks for them
[elogind.git] / src / libsystemd-bus / bus-message.c
index 416eedc2ae1606f10ab8c1ff3632c8f09a20f96a..85b9cbaae01ec1e8a49e2ef9f7d4a8e958de629f 100644 (file)
@@ -789,7 +789,7 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
         void *a;
         char *e = NULL;
         int fd = -1;
-        uint32_t fdi;
+        uint32_t fdi = 0;
         int r;
 
         if (!m)
@@ -3002,3 +3002,38 @@ int bus_message_read_strv_extend(sd_bus_message *m, char ***l) {
 
         return 0;
 }
+
+const char* bus_message_get_arg(sd_bus_message *m, unsigned i) {
+        int r;
+        const char *t;
+        char type;
+
+        assert(m);
+
+        r = sd_bus_message_rewind(m, true);
+        if (r < 0)
+                return NULL;
+
+        while (i > 0) {
+                r = sd_bus_message_peek_type(m, &type, NULL);
+                if (r < 0)
+                        return NULL;
+
+                if (type != SD_BUS_TYPE_STRING &&
+                    type != SD_BUS_TYPE_OBJECT_PATH &&
+                    type != SD_BUS_TYPE_SIGNATURE)
+                        return NULL;
+
+                r = sd_bus_message_read_basic(m, type, &t);
+                if (r < 0)
+                        return NULL;
+
+                i--;
+        }
+
+        r = sd_bus_message_rewind(m, true);
+        if (r < 0)
+                return NULL;
+
+        return t;
+}