-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
+/* SPDX-License-Identifier: LGPL-2.1+ */
#include "bus-internal.h"
#include "bus-introspect.h"
+#include "bus-objects.h"
#include "bus-protocol.h"
#include "bus-signature.h"
#include "fd-util.h"
+#include "fileio.h"
+#include "memory-util.h"
#include "string-util.h"
-#include "util.h"
int introspect_begin(struct introspect *i, bool trusted) {
assert(i);
zero(*i);
i->trusted = trusted;
- i->f = open_memstream(&i->introspection, &i->size);
+ i->f = open_memstream_unlocked(&i->introspection, &i->size);
if (!i->f)
return -ENOMEM;
return 0;
}
-static void introspect_write_flags(struct introspect *i, int type, int flags) {
+static void introspect_write_flags(struct introspect *i, int type, uint64_t flags) {
if (flags & SD_BUS_VTABLE_DEPRECATED)
fputs(" <annotation name=\"org.freedesktop.DBus.Deprecated\" value=\"true\"/>\n", i->f);
if (type == _SD_BUS_VTABLE_METHOD && (flags & SD_BUS_VTABLE_METHOD_NO_REPLY))
fputs(" <annotation name=\"org.freedesktop.DBus.Method.NoReply\" value=\"true\"/>\n", i->f);
- if (type == _SD_BUS_VTABLE_PROPERTY || type == _SD_BUS_VTABLE_WRITABLE_PROPERTY) {
+ if (IN_SET(type, _SD_BUS_VTABLE_PROPERTY, _SD_BUS_VTABLE_WRITABLE_PROPERTY)) {
if (flags & SD_BUS_VTABLE_PROPERTY_EXPLICIT)
fputs(" <annotation name=\"org.freedesktop.systemd1.Explicit\" value=\"true\"/>\n", i->f);
}
if (!i->trusted &&
- (type == _SD_BUS_VTABLE_METHOD || type == _SD_BUS_VTABLE_WRITABLE_PROPERTY) &&
+ IN_SET(type, _SD_BUS_VTABLE_METHOD, _SD_BUS_VTABLE_WRITABLE_PROPERTY) &&
!(flags & SD_BUS_VTABLE_UNPRIVILEGED))
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 (;;) {
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
}
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
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;
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;