]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd/sd-bus/bus-introspect.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / libsystemd / sd-bus / bus-introspect.c
index 582e723e2e0825c3e9db62861b743e577e2ea79d..bde97483e83caa30f86e543902516eb88cabfad4 100644 (file)
@@ -1,11 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-***/
 
 #include <stdio_ext.h>
 
 #include "bus-internal.h"
 #include "bus-introspect.h"
+#include "bus-objects.h"
 #include "bus-protocol.h"
 #include "bus-signature.h"
 #include "fd-util.h"
@@ -88,7 +87,9 @@ static void introspect_write_flags(struct introspect *i, int type, uint64_t flag
                 fputs("   <annotation name=\"org.freedesktop.systemd1.Privileged\" value=\"true\"/>\n", i->f);
 }
 
-static int introspect_write_arguments(struct introspect *i, const char *signature, const char *direction) {
+/* Note that "names" is both an input and an output parameter. It initially points to the first argument name in a
+   NULL-separated list of strings, and is then advanced with each argument, and the resulting pointer is returned. */
+static int introspect_write_arguments(struct introspect *i, const char *signature, const char **names, const char *direction) {
         int r;
 
         for (;;) {
@@ -103,6 +104,11 @@ static int introspect_write_arguments(struct introspect *i, const char *signatur
 
                 fprintf(i->f, "   <arg type=\"%.*s\"", (int) l, signature);
 
+                if (**names != '\0') {
+                        fprintf(i->f, " name=\"%s\"", *names);
+                        *names += strlen(*names) + 1;
+                }
+
                 if (direction)
                         fprintf(i->f, " direction=\"%s\"/>\n", direction);
                 else
@@ -113,10 +119,13 @@ static int introspect_write_arguments(struct introspect *i, const char *signatur
 }
 
 int introspect_write_interface(struct introspect *i, const sd_bus_vtable *v) {
+        const sd_bus_vtable *vtable = v;
+        const char *names = "";
+
         assert(i);
         assert(v);
 
-        for (; v->type != _SD_BUS_VTABLE_END; v++) {
+        for (; v->type != _SD_BUS_VTABLE_END; v = bus_vtable_next(vtable, v)) {
 
                 /* Ignore methods, signals and properties that are
                  * marked "hidden", but do show the interface
@@ -134,8 +143,10 @@ int introspect_write_interface(struct introspect *i, const sd_bus_vtable *v) {
 
                 case _SD_BUS_VTABLE_METHOD:
                         fprintf(i->f, "  <method name=\"%s\">\n", v->x.method.member);
-                        introspect_write_arguments(i, strempty(v->x.method.signature), "in");
-                        introspect_write_arguments(i, strempty(v->x.method.result), "out");
+                        if (bus_vtable_has_names(vtable))
+                                names = strempty(v->x.method.names);
+                        introspect_write_arguments(i, strempty(v->x.method.signature), &names, "in");
+                        introspect_write_arguments(i, strempty(v->x.method.result), &names, "out");
                         introspect_write_flags(i, v->type, v->flags);
                         fputs("  </method>\n", i->f);
                         break;
@@ -152,7 +163,9 @@ int introspect_write_interface(struct introspect *i, const sd_bus_vtable *v) {
 
                 case _SD_BUS_VTABLE_SIGNAL:
                         fprintf(i->f, "  <signal name=\"%s\">\n", v->x.signal.member);
-                        introspect_write_arguments(i, strempty(v->x.signal.signature), NULL);
+                        if (bus_vtable_has_names(vtable))
+                                names = strempty(v->x.method.names);
+                        introspect_write_arguments(i, strempty(v->x.signal.signature), &names, NULL);
                         introspect_write_flags(i, v->type, v->flags);
                         fputs("  </signal>\n", i->f);
                         break;